Ejemplo n.º 1
0
 /**
  * Get singleton instance
  *
  * @access public
  * @return object Singleton instance
  */
 public static function getInstance()
 {
     // optionally create new instance
     if (!self::$instance) {
         self::$instance = new KocujSitemapPluginSitemap();
     }
     // exit
     return self::$instance;
 }
Ejemplo n.º 2
0
 /**
  * Constructor
  *
  * @access private
  * @return void
  */
 private function __construct()
 {
     // get plugin directory
     $this->pluginDir = dirname(__FILE__);
     $this->pluginUrl = plugins_url('kocuj-sitemap');
     // initialize classes
     global $classKocujSitemapAdmin;
     $classKocujSitemapConfig = new KocujSitemapPluginConfig();
     $classKocujSitemapAdmin = new KocujSitemapPluginAdmin($classKocujSitemapConfig, dirname(__FILE__) . '/languages', __FILE__, 'kocuj-sitemap', dirname(plugin_basename(__FILE__)) . '/languages', $this->getVersion());
     KocujSitemapPluginCache::getInstance();
     KocujSitemapPluginSitemap::getInstance();
     // add initialize
     add_action('init', array($this, 'init'));
 }
Ejemplo n.º 3
0
 /**
  * Create cache
  *
  * @access public
  * @return bool Status - true or false
  */
 public function createCache()
 {
     // remove all cache files
     $cacheDir = $this->getCacheDirectory();
     $dir = opendir($cacheDir);
     while ($item = readdir($dir)) {
         if (is_file($cacheDir . '/' . $item) && substr($item, strlen($item) - 4, 4) == '.dat') {
             @unlink($cacheDir . '/' . $item);
         }
     }
     // get all languages
     $langs = KocujSitemapPluginMultiLang::getInstance()->getLanguages();
     // create cached sitemap for each language
     $this->cacheContent = array();
     if (!empty($langs)) {
         foreach ($langs as $lang) {
             // create sitemap
             $array = KocujSitemapPluginSitemap::getInstance()->createSitemap($lang);
             // set cache content in memory
             $this->cacheContent[$lang] = $array;
             // check if cache directory is writable
             if (!$this->checkWritable()) {
                 return false;
             }
             // set filename
             $filename = $this->getCacheFilename($lang);
             if (empty($filename)) {
                 return false;
             }
             // save cache
             @unlink($filename);
             $file = @fopen($filename, 'w');
             @flock($file, LOCK_EX);
             if (empty($file)) {
                 @flock($file, LOCK_UN);
                 @fclose($file);
                 return false;
             }
             if (fwrite($file, maybe_serialize($array)) === false) {
                 @flock($file, LOCK_UN);
                 @fclose($file);
                 return false;
             }
             @flock($file, LOCK_UN);
             if (@fclose($file) === false) {
                 return false;
             }
         }
     }
     // exit
     return true;
 }