function generate_pages() { //Get all page saved in the pages folder echo THEME . '/pages <br>'; $location = THEME . '/pages'; $pages = Mvc_Functions::directoryToArray($location, true); foreach ($pages as $page) { if (Mvc_Functions::get_extension($page) != 'twig') { continue; } //Determine page slug $new_loc = str_replace($location . '/', THEME . '/templates/', $page); $file = str_replace($location . '/', '', $page); $slug = str_replace('.twig', '', $file); $template = "templates/{$file}"; // Determine the page Title $title = str_replace('/', ' | ', $slug); $title = ucwords(str_replace('-', ' ', $title)); echo "NEW LOCATION: {$new_loc} | FILE: {$file} | TEMPLATE: {$template} | SLUG: {$slug} | TITLE: {$title} <br>"; //Copy the file to the layouts location if (!is_dir(dirname($new_loc))) { mkdir(dirname($new_loc), 0777, true); } copy($page, $new_loc); //Create Page Bean $page = current(R::findOrDispense('page', 'slug = :slug', ['slug' => $slug])); $page->slug = $slug; $page->title = "{$title} | Durbanville Hills"; $page->template = $template; $page->layout = "layouts/default.twig"; R::store($page); } }
/** * Handles all resource request that are not js or css * * @param type $args * @throws Exception */ function index($args) { //Determine the current theme location $theme_location = $this->theme_location; $file_location = $theme_location . '/static/' . implode('/', $args); if (file_exists($file_location)) { $extension = Mvc_Functions::get_extension($file_location); $func = "{$extension}_mime"; if (method_exists($this, $func)) { $this->{$func}($file_location); } else { $mimepath = '/usr/share/magic'; // may differ depending on your machine // try /usr/share/file/magic if it doesn't work $mime = finfo_open(FILEINFO_MIME); if ($mime === FALSE) { throw new Exception('Unable to open finfo'); } $filetype = finfo_file($mime, $file_location); finfo_close($mime); if ($filetype === FALSE) { throw new Exception('Unable to recognise filetype'); } header("Content-Type: {$filetype}"); // header("X-Content-Type-Options: nosniff"); header("Access-Control-Allow-Origin:*"); header('Cache-Control:public, max-age=30672000'); } echo file_get_contents($file_location); die; } else { $this->_404(); die; } }
function store_file() { $value = $this->value; //Save the file inside the database $file = R::dispense('file'); $filename = $value[G2_FormMagic::FILE_NAME]; $filename = preg_replace("([^\\w\\s\\d\\-_~,;:\\[\\]\\(\\).])", '', $filename); // Remove any runs of periods (thanks falstro!) $filename = preg_replace("([\\.]{2,})", '', $filename); //Move the file to an upload directory; $directory = "uploads/"; //check if the current file exist. If it does update the name $count = 1; $start_looking = $filename; while (file_exists($directory . $start_looking)) { $start_looking = str_replace('.' . Mvc_Functions::get_extension($filename), '', $filename) . "_{$count}" . '.' . Mvc_Functions::get_extension($filename); $count++; } $filename = $start_looking; $full_uri = $directory . $start_looking; if (!is_dir(dirname($full_uri))) { mkdir(dirname($full_uri), 0777, true); } if (!file_exists($value[G2_FormMagic::FILE_URI])) { return; } move_uploaded_file($value[G2_FormMagic::FILE_URI], $full_uri); //Save the file to database $file->name = $filename; $file->uri = $full_uri; R::store($file); $this->area->file = $file; }
function get_templates() { //Check in the theme folder fot all layouts $templates = Mvc_Functions::directoryToArray($this->theme . '/templates', true); foreach ($templates as $key => &$temp) { if (Mvc_Functions::get_extension($temp) == 'twig') { $temp = str_replace($this->theme . '/', '', $temp); } else { unset($templates[$key]); } } return $templates; }