All pastes #1515293 Raw Edit

Anonymous

public php v1 · immutable
#1515293 ·published 2009-08-02 00:08 UTC
rendered paste body
<?php/* * Funky Cache - Frog CMS caching plugin * * Copyright (c) 2008-2009 Mika Tuupola * * Licensed under the MIT license: *   http://www.opensource.org/licenses/mit-license.php * * Project home: *   http://www.appelsiini.net/projects/funky_cache * */if (!class_exists('Record')) {    require_once dirname(__FILE__) . '/Record.php';    }class FunkyCachePage extends Record {    const TABLE_NAME = 'funky_cache_page';        public  $url;    public  $created_on;    public  $page;    public function getColumns()    {        return array('url', 'created_on');    }        public function publicUrl() {        $folder = Setting::get('funky_cache_folder') . '/';    	$folder = preg_replace('#//*#', '/', $folder);    	$folder = preg_replace('#^/#', '', $folder);    	return str_replace($folder, '', $this->url);    }            public function beforeSave()    {        $this->created_on = date('Y-m-d H:i:s');        /* If directories do not exist create them. */        $parts = explode('/', $this->path());        /* If deep link create directories when needed. */        $dir = '';        foreach($parts as $part) {            if(!is_dir($dir .= "/$part")) {                mkdir($dir);            }        }        /* Fix case when articles.html is created before articles/ */        /* TODO This still creates on extra directory in the end.  */        /* if (('archive' == $this->page->behavior_id) || ($this->page instanceof PageArchive)) {            $dir .= '/' . basename($file, funky_cache_suffix());            if(!is_dir($dir)) {                mkdir($dir);            }        } */        return file_put_contents($this->path() . "/index.html", $this->content(), LOCK_EX);    }    public function beforeDelete()    {        return unlink($this->path() . "/index.html");    }        public function path() {		$filename = $_SERVER['SCRIPT_FILENAME'];		$filename = preg_replace('/admin\//', '', $filename);		$filename = preg_replace('/index\.php$/', '', $filename);		return $filename . $this->url;    }        public function content() {        ob_start();        $this->page->_executeLayout();        $output = ob_get_contents();        ob_end_clean();        return $output;    }    }