Пример #1
0
 public function parse_readme($lca, $expire_secs = 86400)
 {
     if ($this->p->debug->enabled) {
         $this->p->debug->args(array('lca' => $lca, 'expire_secs' => $expire_secs));
     }
     $plugin_info = array();
     if (!defined(strtoupper($lca) . '_PLUGINDIR')) {
         if ($this->p->debug->enabled) {
             $this->p->debug->log(strtoupper($lca) . '_PLUGINDIR is undefined and required for readme.txt path');
         }
         return $plugin_info;
     }
     $readme_txt = constant(strtoupper($lca) . '_PLUGINDIR') . 'readme.txt';
     $readme_url = isset($this->p->cf['plugin'][$lca]['url']['readme']) ? $this->p->cf['plugin'][$lca]['url']['readme'] : '';
     $get_remote = empty($readme_url) ? false : true;
     // fetch readme from wordpress.org by default
     $content = '';
     if ($this->p->is_avail['cache']['transient']) {
         $cache_salt = __METHOD__ . '(url:' . $readme_url . '_txt:' . $readme_txt . ')';
         $cache_id = $lca . '_' . md5($cache_salt);
         $cache_type = 'object cache';
         if ($this->p->debug->enabled) {
             $this->p->debug->log($cache_type . ': transient salt ' . $cache_salt);
         }
         $plugin_info = get_transient($cache_id);
         if (is_array($plugin_info)) {
             if ($this->p->debug->enabled) {
                 $this->p->debug->log($cache_type . ': plugin_info retrieved from transient ' . $cache_id);
             }
             return $plugin_info;
         }
     } else {
         $get_remote = false;
     }
     // use local if transient cache is disabled
     // get remote readme.txt file
     if ($get_remote === true && $expire_secs > 0) {
         $content = $this->p->cache->get($readme_url, 'raw', 'file', $expire_secs);
     }
     // fallback to local readme.txt file
     if (empty($content) && ($fh = @fopen($readme_txt, 'rb'))) {
         $get_remote = false;
         $content = fread($fh, filesize($readme_txt));
         fclose($fh);
     }
     if (!empty($content)) {
         $parser = new SuextParseReadme($this->p->debug);
         $plugin_info = $parser->parse_readme_contents($content);
         // remove possibly inaccurate information from local file
         if ($get_remote !== true) {
             foreach (array('stable_tag', 'upgrade_notice') as $key) {
                 if (array_key_exists($key, $plugin_info)) {
                     unset($plugin_info[$key]);
                 }
             }
         }
     }
     // save the parsed readme (aka $plugin_info) to the transient cache
     if ($this->p->is_avail['cache']['transient']) {
         set_transient($cache_id, $plugin_info, $this->p->options['plugin_object_cache_exp']);
         if ($this->p->debug->enabled) {
             $this->p->debug->log($cache_type . ': plugin_info saved to transient ' . $cache_id . ' (' . $this->p->options['plugin_object_cache_exp'] . ' seconds)');
         }
     }
     return $plugin_info;
 }
Пример #2
0
 public function parse_readme($expire_secs)
 {
     $this->p->debug->args(array('expire_secs' => $expire_secs));
     $readme = '';
     $get_remote = true;
     // fetch readme from wordpress.org by default
     $plugin_info = array();
     if ($this->p->is_avail['cache']['transient']) {
         $cache_salt = __METHOD__ . '(file:' . $this->p->cf['url']['readme'] . ')';
         $cache_id = $this->p->cf['lca'] . '_' . md5($cache_salt);
         $cache_type = 'object cache';
         $this->p->debug->log($cache_type . ': transient salt ' . $cache_salt);
         $plugin_info = get_transient($cache_id);
         if (is_array($plugin_info)) {
             $this->p->debug->log($cache_type . ': plugin_info retrieved from transient ' . $cache_id);
             return $plugin_info;
         }
     } else {
         $get_remote = false;
     }
     // use local if transient cache is disabled
     // get remote readme.txt file
     if ($get_remote === true && $expire_secs > 0) {
         $readme = $this->p->cache->get($this->p->cf['url']['readme'], 'raw', 'file', $expire_secs);
     }
     // fallback to local readme.txt file
     if (empty($readme) && ($fh = @fopen(constant($this->p->cf['uca'] . '_PLUGINDIR') . 'readme.txt', 'rb'))) {
         $get_remote = false;
         $readme = fread($fh, filesize(constant($this->p->cf['uca'] . '_PLUGINDIR') . 'readme.txt'));
         fclose($fh);
     }
     if (!empty($readme)) {
         $parser = new SuextParseReadme($this->p->debug);
         $plugin_info = $parser->parse_readme_contents($readme);
         // remove possibly inaccurate information from local file
         if ($get_remote !== true) {
             foreach (array('stable_tag', 'upgrade_notice') as $key) {
                 if (array_key_exists($key, $plugin_info)) {
                     unset($plugin_info[$key]);
                 }
             }
         }
     }
     // save the parsed readme (aka $plugin_info) to the transient cache
     if ($this->p->is_avail['cache']['transient']) {
         set_transient($cache_id, $plugin_info, $this->p->cache->object_expire);
         $this->p->debug->log($cache_type . ': plugin_info saved to transient ' . $cache_id . ' (' . $this->p->cache->object_expire . ' seconds)');
     }
     return $plugin_info;
 }