예제 #1
0
 public function validate()
 {
     $diff = $this->expires - time();
     if ($diff > 0) {
         // it's still valid
         return true;
     } else {
         // invalidate and kill this record.
         $cache = PageCache::getLibrary();
         $cache->purgeByRecord($this);
     }
 }
예제 #2
0
 /** 
  * Completely flushes the cache
  */
 public function flush()
 {
     $db = Loader::db();
     $r = $db->MetaTables();
     // flush the CSS cache
     if (is_dir(DIR_FILES_CACHE . '/' . DIRNAME_CSS)) {
         $fh = Loader::helper("file");
         $fh->removeAll(DIR_FILES_CACHE . '/' . DIRNAME_CSS);
     }
     $pageCache = PageCache::getLibrary();
     if (is_object($pageCache)) {
         $pageCache->flush();
     }
     if (in_array('Config', $r)) {
         // clear the environment overrides cache
         $env = Environment::get();
         $env->clearOverrideCache();
         if (in_array('btCachedBlockRecord', $db->MetaColumnNames('Blocks'))) {
             $db->Execute('update Blocks set btCachedBlockRecord = null');
         }
         if (in_array('CollectionVersionBlocksOutputCache', $r)) {
             $db->Execute('truncate table CollectionVersionBlocksOutputCache');
         }
     }
     $loc = CacheLocal::get();
     $loc->cache = array();
     $cache = Cache::getLibrary();
     if ($cache) {
         $cache->setOption('caching', true);
         $cache->clean(Zend_Cache::CLEANING_MODE_ALL);
     }
     if (function_exists('apc_clear_cache')) {
         apc_clear_cache();
     }
     Events::fire('on_cache_flush', $cache);
     return true;
 }
예제 #3
0
 function delete()
 {
     Loader::model('page_statistics');
     $cID = $this->getCollectionID();
     if ($cID <= 1) {
         return false;
     }
     $db = Loader::db();
     // run any internal event we have for page deletion
     $ret = Events::fire('on_page_delete', $this);
     if ($ret < 0) {
         return false;
     }
     Log::addEntry(t('Page "%s" at path "%s" deleted', $this->getCollectionName(), $this->getCollectionPath()), t('Page Action'));
     if ($this->isAlias() && $this->getCollectionPointerExternalLink() == '') {
         $this->removeThisAlias();
     } else {
         parent::delete();
         $cID = $this->getCollectionID();
         $cParentID = $this->getCollectionParentID();
         // Now that all versions are gone, we can delete the collection information
         $q = "delete from PagePaths where cID = '{$cID}'";
         $r = $db->query($q);
         // remove all pages where the pointer is this cID
         $r = $db->query("select cID from Pages where cPointerID = ?", array($cID));
         while ($row = $r->fetchRow()) {
             PageStatistics::decrementParents($row['cID']);
             $db->Execute('DELETE FROM PagePaths WHERE cID=?', array($row['cID']));
         }
         // Update cChildren for cParentID
         PageStatistics::decrementParents($cID);
         $q = "delete from PagePermissionAssignments where cID = '{$cID}'";
         $r = $db->query($q);
         $q = "delete from Pages where cID = '{$cID}'";
         $r = $db->query($q);
         $q = "delete from Pages where cPointerID = '{$cID}'";
         $r = $db->query($q);
         $q = "delete from Areas WHERE cID = '{$cID}'";
         $r = $db->query($q);
         $q = "delete from ComposerDrafts WHERE cID = '{$cID}'";
         $r = $db->query($q);
         $db->query('delete from PageSearchIndex where cID = ?', array($cID));
         $q = "select cID from Pages where cParentID = '{$cID}'";
         $r = $db->query($q);
         if ($r) {
             while ($row = $r->fetchRow()) {
                 if ($row['cID'] > 0) {
                     $nc = Page::getByID($row['cID']);
                     if ($nc->isAlias()) {
                         $nc->removeThisAlias();
                     } else {
                         $nc->delete();
                     }
                 }
             }
         }
     }
     $cache = PageCache::getLibrary();
     $cache->purge($this);
 }
예제 #4
0
 /**
  * render takes one argument - the item being rendered - and it can either be a path or a page object
  * @access public
  * @param string $view
  * @param array $args
  * @return void
  */
 public function render($view, $args = null)
 {
     if (is_array($args)) {
         extract($args);
     }
     // strip off a slash if there is one at the end
     if (is_string($view)) {
         if (substr($view, strlen($view) - 1) == '/') {
             $view = substr($view, 0, strlen($view) - 1);
         }
     }
     $dsh = Loader::helper('concrete/dashboard');
     $wrapTemplateInTheme = false;
     $this->checkMobileView();
     if (defined('DB_DATABASE') && $view !== '/upgrade') {
         Events::fire('on_start', $this);
     }
     // Extract controller information from the view, and put it in the current context
     if (!isset($this->controller)) {
         $this->controller = Loader::controller($view);
         $this->controller->setupAndRun();
     }
     if ($this->controller->getRenderOverride() != '') {
         $view = $this->controller->getRenderOverride();
     }
     // Determine which inner item to load, load it, and stick it in $innerContent
     $content = false;
     ob_start();
     if ($view instanceof Page) {
         $_pageBlocks = $view->getBlocks();
         if (!$dsh->inDashboard()) {
             $_pageBlocksGlobal = $view->getGlobalBlocks();
             $_pageBlocks = array_merge($_pageBlocks, $_pageBlocksGlobal);
         }
         // do we have any custom menu plugins?
         $cp = new Permissions($view);
         if ($cp->canViewToolbar()) {
             $ih = Loader::helper('concrete/interface/menu');
             $_interfaceItems = $ih->getPageHeaderMenuItems();
             foreach ($_interfaceItems as $_im) {
                 $_controller = $_im->getController();
                 $_controller->outputAutoHeaderItems();
             }
             unset($_interfaceItems);
             unset($_im);
             unset($_controller);
         }
         unset($_interfaceItems);
         unset($_im);
         unset($_controller);
         // now, we output all the custom style records for the design tab in blocks/areas on the page
         $c = $this->getCollectionObject();
         $view->outputCustomStyleHeaderItems();
         $viewPath = $view->getCollectionPath();
         $this->viewPath = $viewPath;
         $cFilename = $view->getCollectionFilename();
         $ctHandle = $view->getCollectionTypeHandle();
         $editMode = $view->isEditMode();
         $c = $view;
         $this->c = $c;
         $env = Environment::get();
         // $view is a page. It can either be a SinglePage or just a Page, but we're not sure at this point, unfortunately
         if ($view->getCollectionTypeID() == 0 && $cFilename) {
             $wrapTemplateInTheme = true;
             $cFilename = trim($cFilename, '/');
             $content = $env->getPath(DIRNAME_PAGES . '/' . $cFilename, $view->getPackageHandle());
             $themeFilename = $c->getCollectionHandle() . '.php';
         } else {
             $rec = $env->getRecord(DIRNAME_PAGE_TYPES . '/' . $ctHandle . '.php', $view->getPackageHandle());
             if ($rec->exists()) {
                 $wrapTemplateInTheme = true;
                 $content = $rec->file;
             }
             $themeFilename = $ctHandle . '.php';
         }
     } else {
         if (is_string($view)) {
             // if we're passing a view but our render override is not null, that means that we're passing
             // a new view from within a controller. If that's the case, then we DON'T override the viewPath, we want to keep it
             // In order to enable editable 404 pages, other editable pages that we render without actually visiting
             if (defined('DB_DATABASE') && $view == '/page_not_found') {
                 $pp = Page::getByPath($view);
                 if (!$pp->isError()) {
                     $this->c = $pp;
                 }
             }
             $viewPath = $view;
             if ($this->controller->getRenderOverride() != '' && $this->getCollectionObject() != null) {
                 // we are INSIDE a collection renderring a view. Which means we want to keep the viewPath that of the collection
                 $this->viewPath = $this->getCollectionObject()->getCollectionPath();
             }
             // we're just passing something like "/login" or whatever. This will typically just be
             // internal Concrete stuff, but we also prepare for potentially having something in DIR_FILES_CONTENT (ie: the webroot)
             if (file_exists(DIR_FILES_CONTENT . "/{$view}/" . FILENAME_COLLECTION_VIEW)) {
                 $content = DIR_FILES_CONTENT . "/{$view}/" . FILENAME_COLLECTION_VIEW;
             } else {
                 if (file_exists(DIR_FILES_CONTENT . "/{$view}.php")) {
                     $content = DIR_FILES_CONTENT . "/{$view}.php";
                 } else {
                     if (file_exists(DIR_FILES_CONTENT_REQUIRED . "/{$view}/" . FILENAME_COLLECTION_VIEW)) {
                         $content = DIR_FILES_CONTENT_REQUIRED . "/{$view}/" . FILENAME_COLLECTION_VIEW;
                     } else {
                         if (file_exists(DIR_FILES_CONTENT_REQUIRED . "/{$view}.php")) {
                             $content = DIR_FILES_CONTENT_REQUIRED . "/{$view}.php";
                         } else {
                             if ($this->getCollectionObject() != null && $this->getCollectionObject()->isGeneratedCollection() && $this->getCollectionObject()->getPackageID() > 0) {
                                 //This is a single_page associated with a package, so check the package views as well
                                 $pagePkgPath = Package::getByID($this->getCollectionObject()->getPackageID())->getPackagePath();
                                 if (file_exists($pagePkgPath . "/single_pages/{$view}/" . FILENAME_COLLECTION_VIEW)) {
                                     $content = $pagePkgPath . "/single_pages/{$view}/" . FILENAME_COLLECTION_VIEW;
                                 } else {
                                     if (file_exists($pagePkgPath . "/single_pages/{$view}.php")) {
                                         $content = $pagePkgPath . "/single_pages/{$view}.php";
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             $wrapTemplateInTheme = true;
             $themeFilename = $view . '.php';
         }
     }
     if (is_object($this->c)) {
         $c = $this->c;
         if (defined('DB_DATABASE') && ($view == '/page_not_found' || $view == '/login')) {
             $view = $c;
             $req = Request::get();
             $req->setCurrentPage($c);
             $_pageBlocks = $view->getBlocks();
             $_pageBlocksGlobal = $view->getGlobalBlocks();
             $_pageBlocks = array_merge($_pageBlocks, $_pageBlocksGlobal);
         }
     }
     if (is_array($_pageBlocks)) {
         foreach ($_pageBlocks as $b1) {
             $b1p = new Permissions($b1);
             if ($b1p->canRead()) {
                 $btc = $b1->getInstance();
                 // now we inject any custom template CSS and JavaScript into the header
                 if ('Controller' != get_class($btc)) {
                     $btc->outputAutoHeaderItems();
                 }
                 $btc->runTask('on_page_view', array($view));
             }
         }
     }
     // Determine which outer item/theme to load
     // obtain theme information for this collection
     if (isset($this->themeOverride)) {
         $theme = $this->themeOverride;
     } else {
         if ($this->controller->theme != false) {
             $theme = $this->controller->theme;
         } else {
             if (($tmpTheme = $this->getThemeFromPath($viewPath)) != false) {
                 $theme = $tmpTheme;
             } else {
                 if (is_object($this->c) && ($tmpTheme = $this->c->getCollectionThemeObject()) != false) {
                     $theme = $tmpTheme;
                 } else {
                     $theme = FILENAME_COLLECTION_DEFAULT_THEME;
                 }
             }
         }
     }
     $this->setThemeForView($theme, $themeFilename, $wrapTemplateInTheme);
     // finally, we include the theme (which was set by setTheme and will automatically include innerContent)
     // disconnect from our db and exit
     $this->controller->on_before_render();
     extract($this->controller->getSets());
     extract($this->controller->getHelperObjects());
     if ($content != false && !$this->disableContentInclude) {
         include $content;
     }
     $innerContent = ob_get_contents();
     if (ob_get_level() > OB_INITIAL_LEVEL) {
         ob_end_clean();
     }
     if (defined('DB_DATABASE') && $view !== '/upgrade') {
         Events::fire('on_before_render', $this);
     }
     if (defined('APP_CHARSET')) {
         header("Content-Type: text/html; charset=" . APP_CHARSET);
     }
     if (file_exists($this->theme)) {
         $cache = PageCache::getLibrary();
         $shouldAddToCache = $cache->shouldAddToCache($this);
         if ($shouldAddToCache) {
             $cache->outputCacheHeaders($c);
         }
         ob_start();
         include $this->theme;
         $pageContent = ob_get_contents();
         ob_end_clean();
         $ret = Events::fire('on_page_output', $pageContent);
         if ($ret != '') {
             print $ret;
             $pageContent = $ret;
         } else {
             print $pageContent;
         }
         $cache = PageCache::getLibrary();
         if ($shouldAddToCache) {
             $cache->set($c, $pageContent);
         }
     } else {
         throw new Exception(t('File %s not found. All themes need default.php and view.php files in them. Consult concrete5 documentation on how to create these files.', $this->theme));
     }
     if (defined('DB_DATABASE') && $view !== '/upgrade') {
         Events::fire('on_render_complete', $this);
     }
     if (ob_get_level() == OB_INITIAL_LEVEL) {
         require DIR_BASE_CORE . '/startup/jobs.php';
         require DIR_BASE_CORE . '/startup/shutdown.php';
         exit;
     }
 }
예제 #5
0
?>
 <?php 
echo t('minutes');
?>
</div>

		</div>

		<hr/>
		<p class="lead"><?php 
echo t('Cache Status');
?>
</p>

		<?php 
$cache = PageCache::getLibrary();
$rec = $cache->getRecord($c);
if ($rec instanceof \Concrete\Core\Cache\Page\PageCacheRecord) {
    ?>
			<div class="alert alert-success">
				<?php 
    echo t('This page currently exists in the full page cache. It expires %s.', Loader::helper('date')->date('m/d/Y g:i a', $rec->getCacheRecordExpiration()));
    ?>
				&nbsp;&nbsp;<button type="button" class="btn btn-xs btn-default pull-right" id="ccm-button-remove-page-from-cache"><?php 
    echo t('Purge');
    ?>
</button>
			</div>
		<?php 
} else {
    if ($rec instanceof \Concrete\Core\Cache\Page\UnknownPageCacheRecord) {
예제 #6
0
 public function change_doc_part_name_desc()
 {
     $project_id = $this->post('projectID');
     $domain_handle = $this->post('itemDomain');
     $volume_handle = $this->post('itemVolume');
     $part_handle = $this->post('itemPart');
     $item_type = $this->post('itemType');
     $item_value = $this->post('itemValue');
     $json = Loader::helper('json');
     $pas = new PageActionStatus();
     $pas->action = t('Change Volume/Part Name/Desc');
     $pas->status = t('Unkown error');
     $pas->time = time();
     if (!fse_try_to_login()) {
         $pas->message = t('You do not sign in or session expired.');
         echo $json->encode($pas);
         exit(0);
     }
     if (!in_array($domain_handle, $this->mDomainList)) {
         $pas->status = "error";
         $pas->message = "Invalid doc domain: {$domain_handle}!";
         echo $json->encode($pas);
         exit(0);
     }
     if (!preg_match("/^[a-z0-9_\\-]{4,64}\$/", $project_id)) {
         $pas->status = "error";
         $pas->message = "Invalid given project ID: {$project_id}!";
         echo $json->encode($pas);
         exit(0);
     }
     $project_home_page = ProjectInfo::getProjectPage($project_id, 'home');
     if ($project_home_page == false) {
         $pas->status = "error";
         $pas->message = "No such project: {$project_id}!";
         echo $json->encode($pas);
         exit(0);
     }
     if ($item_type == 'name') {
         if (!preg_match("/^.{1,64}\$/", $item_value)) {
             $pas->status = "error";
             $pas->message = "Bad volume/part name: {$item_value}!";
             echo $json->encode($pas);
             exit(0);
         }
         $page_property = 'cName';
     } else {
         if ($item_type == 'desc') {
             if (!preg_match("/^.{2,255}\$/", $item_value)) {
                 $pas->status = "error";
                 $pas->message = "Bad volume/part desc: {$item_value}!";
                 echo $json->encode($pas);
                 exit(0);
             }
             $page_property = 'cDescription';
         } else {
             $pas->status = "error";
             $pas->message = "Bad item type: {$item_type}!";
             echo $json->encode($pas);
             exit(0);
         }
     }
     $project_info = ProjectInfo::getBasicInfo($project_id);
     if ($project_info['fse_id'] != $_SESSION['FSEInfo']['fse_id']) {
         $pas->status = "error";
         $pas->message = "You are not the owner of {$project_id}!";
         echo $json->encode($pas);
         exit(0);
     }
     $db = Loader::db();
     if (preg_match("/^[a-z0-9\\-]{3,16}\$/", $part_handle)) {
         $res = $db->Execute("UPDATE fsen_project_doc_volume_parts SET part_{$item_type}=?\n\tWHERE project_id=? AND domain_handle=? AND volume_handle=? AND part_handle=?", array($item_value, $project_id, $domain_handle, $volume_handle, $part_handle));
         ProjectInfo::onUpdateProjectPartInfo($project_id, $domain_handle, $volume_handle, $part_handle);
     } else {
         $res = $db->Execute("UPDATE fsen_project_doc_volumes SET volume_{$item_type}=?\n\tWHERE project_id=? AND domain_handle=? AND volume_handle=?", array($item_value, $project_id, $domain_handle, $volume_handle));
         ProjectInfo::onUpdateProjectVolumeInfo($project_id, $domain_handle, $volume_handle);
     }
     if ($db->Affected_Rows() == 0) {
         $pas->status = "error";
         $pas->message = "Nothing changed!";
         echo $json->encode($pas);
         exit(0);
     }
     $cache = PageCache::getLibrary();
     /* update page attributes and refresh block caches */
     if (preg_match("/^[a-z0-9\\-]{3,16}\$/", $part_handle)) {
         $page = ProjectInfo::getProjectPage($project_id, $domain_handle, $volume_handle, $part_handle);
         if ($page != false) {
             $page->update(array($page_property => $item_value));
             $cache->purge($page);
         }
     } else {
         $page = ProjectInfo::getProjectPage($project_id, $domain_handle, $volume_handle);
         if ($page != false) {
             $page->update(array($page_property => $item_value));
             $cache->purge($page);
         }
         $cache->purge($project_home_page);
     }
     $pas->status = "success";
     $pas->message = "Item changed!";
     echo $json->encode($pas);
     exit(0);
 }
<?php

defined('C5_EXECUTE') or die("Access Denied.");
$request = Request::get();
$library = PageCache::getLibrary();
if ($library->shouldCheckCache($request)) {
    $record = $library->getRecord($request);
    if ($record instanceof PageCacheRecord) {
        if ($record->validate()) {
            $library->deliver($record);
            if (ob_get_level() == OB_INITIAL_LEVEL) {
                require DIR_BASE_CORE . '/startup/shutdown.php';
                exit;
            }
            exit;
        }
    }
}
예제 #8
0
 public static function onUpdateBlogInfo($project_id, $domain_handle, $volume_handle, $part_handle, $chapter_handle)
 {
     /* we only flush the cache of the blog and the blog page */
     Cache::delete('BlogInfo', $chapter_handle);
     $cache = PageCache::getLibrary();
     $page = Page::getByPath(self::assemblePath($project_id, $domain_handle, $volume_handle, $part_handle, $chapter_handle));
     $cache->purge($page);
 }
예제 #9
0
 public function deleteSection($project_id, $domain_handle, $section_id)
 {
     if (!in_array($domain_handle, $this->mDomainList)) {
         return self::EC_BAD_DOMAIN;
     }
     $db = Loader::db();
     $doc_lang = substr($project_id, -2);
     $section_row = $db->getRow("SELECT page_id, area_handle, block_id, max_ver_code\n\tFROM fsen_document_sections_{$doc_lang} WHERE id=?", array($section_id));
     if (count($section_row) == 0) {
         return self::EC_NO_SUCH_ENTRY;
     }
     $res = $db->Execute("DELETE FROM fsen_document_sections_{$doc_lang} WHERE id=?", array($section_id));
     $page = Page::getByID($section_row['page_id']);
     $area = Area::get($page, $section_row['area_handle']);
     if (!is_object($area)) {
         return self::EC_BAD_PAGEAREA;
     }
     $block = Block::getByID($section_row['block_id'], $page, $section_row['area_handle']);
     if (!$block instanceof Block) {
         return self::EC_NO_SUCH_OBJ;
     }
     $block->delete();
     /* purge the full page cache */
     $page_cache = PageCache::getLibrary();
     $page_cache->purge($page);
     return self::EC_OK;
 }
예제 #10
0
		public function reindex($index = false, $actuallyDoReindex = true) {
			if ($this->isAlias()) {
				return false;
			}
			if ($actuallyDoReindex || ENABLE_PROGRESSIVE_PAGE_REINDEX == false) { 
				$db = Loader::db();
				
				Loader::model('attribute/categories/collection');
				$attribs = CollectionAttributeKey::getAttributes($this->getCollectionID(), $this->getVersionID(), 'getSearchIndexValue');
		
				$db->Execute('delete from CollectionSearchIndexAttributes where cID = ?', array($this->getCollectionID()));
				$searchableAttributes = array('cID' => $this->getCollectionID());
				$rs = $db->Execute('select * from CollectionSearchIndexAttributes where cID = -1');
				AttributeKey::reindex('CollectionSearchIndexAttributes', $searchableAttributes, $attribs, $rs);
				
				if ($index == false) {
					Loader::library('database_indexed_search');
					$index = new IndexedSearch();
				}
				
				$index->reindexPage($this);
				$db->Replace('PageSearchIndex', array('cID' => $this->getCollectionID(), 'cRequiresReindex' => 0), array('cID'), false);

				$cache = PageCache::getLibrary();
				$cache->purge($this);

			} else { 			
				$db = Loader::db();
				Config::save('DO_PAGE_REINDEX_CHECK', true);
				$db->Replace('PageSearchIndex', array('cID' => $this->getCollectionID(), 'cRequiresReindex' => 1), array('cID'), false);
			}
		}
예제 #11
0
 /**
  * Observes the updates of walk pages, to clear its cache
  */
 public function on_page_update(Page $self)
 {
     // Clear out the parent cache entry
     $parent = Page::getByID($self->getCollectionParentID());
     Cache::delete('page_' . $parent->getCollectionTypeHandle(), $parent->getCollectionId());
     // Clear out the parent full-page cache
     $pageCache = PageCache::getLibrary();
     $pageCache->purge($parent);
 }
예제 #12
0
파일: FSEInfo.php 프로젝트: rratcliffe/fsen
 static function onUpdateProfile($fse_info, $doc_lang)
 {
     Cache::delete('FSENameInfo', $fse_info['fse_id']);
     Cache::delete('FSEBasicProfile', $fse_info['user_name']);
     $page = Page::getByPath("/{$doc_lang}/engineer/" . $fse_info['user_name']);
     if ($page->getCollectionID() == false) {
         return;
     }
     /* refresh related blocks */
     $blocks = $page->getBlocks('Side Bar');
     foreach ($blocks as $block) {
         $block->refreshBlockOutputCache();
     }
     $cache = PageCache::getLibrary();
     $cache->purge($page);
 }