dispatch("annotations.gatherStart"); // set-up the comments store self::$store["comments"] = array(); // create the annotations dir if it doesn't exist if (!is_dir($annotationsDir)) { mkdir($annotationsDir); } // find the markdown-based annotations $finder = new Finder(); $finder->files()->name("*.md")->in($annotationsDir); $finder->sortByName(); foreach ($finder as $name => $file) { $data = array(); $data[0] = array(); $text = file_get_contents($file->getPathname()); $matches = (strpos($text,PHP_EOL."~*~".PHP_EOL) !== false) ? explode(PHP_EOL."~*~".PHP_EOL,$text) : array($text); foreach ($matches as $match) { list($yaml,$markdown) = Documentation::parse($match); if (isset($yaml["el"]) || isset($yaml["selector"])) { $data[0]["el"] = (isset($yaml["el"])) ? $yaml["el"] : $yaml["selector"]; } else { $data[0]["el"] = "#someimpossibleselector"; } $data[0]["title"] = isset($yaml["title"]) ? $yaml["title"] : ""; $data[0]["comment"] = $markdown; self::$store["comments"] = array_merge(self::$store["comments"],$data); } } // read in the old style annotations.js, modify the data and generate JSON array to merge $data = array(); $oldStyleAnnotationsPath = $annotationsDir.DIRECTORY_SEPARATOR."annotations.js"; if (file_exists($oldStyleAnnotationsPath)) { $text = trim(file_get_contents($oldStyleAnnotationsPath)); $text = str_replace("var comments = ","",$text); if ($text[strlen($text)-1] == ";") { $text = rtrim($text,";"); } $data = json_decode($text,true); if ($jsonErrorMessage = JSON::hasError()) { JSON::lastErrorMsg(Console::getHumanReadablePath($oldStyleAnnotationsPath),$jsonErrorMessage,$data); } } // merge in any data from the old file if the json decode was successful if (is_array($data) && isset($data["comments"])) { self::$store["comments"] = array_merge(self::$store["comments"],$data["comments"]); } $dispatcherInstance->dispatch("annotations.gatherEnd"); } /** * Get the data in the store */ public static function get() { return self::$store; } }