$value) { $this->$key = $value; } $this->slug = $pageSlug; } } function write() { $filePath = getPageJSONPath($this->slug); // Remove attributes that should be serialized $slug = $this->slug; unset($this->slug); $file = fopen($filePath, 'w'); fwrite($file, json_encode($this)); fclose($file); // Add them back $this->slug = $slug; } function delete() { $filePath = getPageJSONPath($this->slug); if (file_exists($filePath)) { unlink($filePath); } } function rename($newSlug) { rename(getPageJSONPath($this->slug), getPageJSONPath($newSlug)); $this->slug = $newSlug; } function parse() { require_once($_SERVER["DOCUMENT_ROOT"] . "/../Parsedown.php"); $parsedown = new Parsedown(); $parsedown->setSafeMode(true); return $parsedown->text($this->content); } } function getListSlugPages() { global $pagesFolder; $pages = scandir($pagesFolder); $pages = array_slice($pages, 2); $result = array(); foreach ($pages as $page) { if (substr($page, -5, 5) == '.json') { array_push($result, substr($page, 0, -5)); } } return $result; } function existPage($pageSlug) { return file_exists(getPageJSONPath($pageSlug)); } function getPageJSONPath($pageSlug) { global $pagesFolder; return $pagesFolder . $pageSlug . '.json'; } function unixToDate($unixTime) { return date('Y-m-d', $unixTime); } function sluggify($string) { $string = strtolower($string); $string = str_replace(' ', '-', $string); $string = str_split($string); $result = ""; $slugAcceptable = "abcdefghijklmnopqrstuvwxyz0123456789-"; foreach ($string as $c) { if (stripos($slugAcceptable, $c) !== false) $result .= $c; } $result = trim($result, "-"); return $result; } } ?>