public function control_panel__post_publish($publish_data)
 {
     // check that caching is turned on
     if (!$this->core->isEnabled()) {
         return;
     }
     // we only need one key from the hook's value
     $file = $publish_data['file'];
     // update the cache
     _Cache::update();
     ContentService::loadCache(true);
     // grab data
     $triggers = $this->fetchConfig('publish_invalidation', array(), 'is_array', false, false);
     $content = Content::find(Path::tidy(str_replace(Config::getContentRoot(), '/', $file)));
     if ($triggers && $content) {
         foreach ($triggers as $trigger) {
             $folders = Parse::pipeList(array_get($trigger, 'folder', null));
             $key = array_get($trigger, 'key', null);
             if (!$folders || !$key) {
                 // not checking this
                 continue;
             }
             // check
             $invalidate = false;
             foreach ($folders as $folder) {
                 if ($folder === "*" || $folder === "/*") {
                     // include all
                     $invalidate = true;
                     break;
                 } elseif (substr($folder, -1) === "*") {
                     // wildcard check
                     if (strpos($content['_folder'], substr($folder, 0, -1)) === 0) {
                         $invalidate = true;
                         break;
                     }
                 } else {
                     // plain check
                     if ($folder == $content['_folder']) {
                         $invalidate = true;
                         break;
                     }
                 }
             }
             // invalidate if needed
             if ($invalidate) {
                 $this->core->deleteByKey(Parse::pipeList($key));
             }
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * Finds content by path
  * 
  * @param string  $path  Path to use to look for content
  * @return array|false
  */
 public static function find($path)
 {
     $hash = Debug::markStart('content', 'finding');
     // ensure it starts with /
     $path = Path::tidy('/' . $path);
     ContentService::loadCache();
     $urls = ContentService::$cache['urls'];
     foreach ($urls as $url => $data) {
         if ($data['path'] === $path) {
             return Content::get($url, false, false);
         }
     }
     Debug::markEnd($hash);
     return false;
 }