/**
  * Initialize
  *
  * @access public
  * @return void
  */
 public function init()
 {
     // execute parent method
     parent::init();
     // declare global
     global $wp_version;
     // add options
     $this->addOption('LinkToMainSite', '1', 'checkbox', __('Display link to main site', 'kocuj-sitemap'));
     if (version_compare($wp_version, '3.0.0', '>=')) {
         $this->addOption('DisplayMenus', '1', 'checkbox', __('Display menus', 'kocuj-sitemap'));
     }
     $this->addOption('DisplayPages', '1', 'checkbox', __('Display pages', 'kocuj-sitemap'));
     $this->addOption('DisplayPosts', '1', 'checkbox', __('Display posts', 'kocuj-sitemap'));
     if (version_compare($wp_version, '3.0.0', '>=')) {
         $def = 'MGP';
     } else {
         $def = 'GP';
     }
     $this->addOption('Order', $def, 'string', __('Order of elements in the sitemap', 'kocuj-sitemap'));
     if (version_compare($wp_version, '3.0.0', '>=')) {
         $this->addOption('Menus', '', 'numeric', __('Menus list', 'kocuj-sitemap'), true, array('allowreorganize' => true, 'addonlastnotempty' => true, 'removeonempty' => true, 'addbutton' => false));
     }
     $this->addOption('UseHTML5', '0', 'checkbox', __('Use HTML 5 `nav` tag', 'kocuj-sitemap'));
     $this->addOption('PoweredBy', '0', 'checkbox', __('Display `powered by` information below sitemap', 'kocuj-sitemap'));
     // set option name
     $this->optionName = 'kocujsitemap_options';
     // add multi-language plugins options
     $multiLangData = KocujSitemapPluginMultiLang::getInstance()->getData();
     if (!empty($multiLangData)) {
         foreach ($multiLangData as $data) {
             $this->addOption($data['admin_id'], '1', 'checkbox', $data['admin_label']);
         }
     }
 }
 /**
  * Get singleton instance
  *
  * @access public
  * @return object Singleton instance
  */
 public static function getInstance()
 {
     // optionally create new instance
     if (!self::$instance) {
         self::$instance = new KocujSitemapPluginMultiLang();
     }
     // exit
     return self::$instance;
 }
 /**
  * Get sitemap to display
  *
  * @access public
  * @param string $title Sitemap title - default: empty
  * @param string $class Sitemap class - default: empty
  * @return string Sitemap to display
  */
 public function getSitemap($title = '', $class = '')
 {
     // declare global
     global $classKocujSitemapAdmin;
     // get arguments
     if (empty($title)) {
         KocujSitemapPluginMultiLang::getInstance()->beforeGetBlogName();
         $title = apply_filters('kocujsitemap_defaulttitle', KocujSitemapPluginMultiLang::getInstance()->getTranslatedBlogName(), get_locale());
         KocujSitemapPluginMultiLang::getInstance()->afterGetBlogName();
     }
     if (empty($class)) {
         $class = apply_filters('kocujsitemap_defaultclass', '');
     }
     $title = apply_filters('kocujsitemap_linktitle', $title, 0, 'home', get_locale());
     // initialize
     $output = '';
     // load cache
     if (!KocujSitemapPluginCache::getInstance()->loadCache($title, $output, get_locale())) {
         KocujSitemapPluginCache::getInstance()->createCache();
         if (!KocujSitemapPluginCache::getInstance()->loadCache($title, $output, get_locale())) {
             return '';
         }
     }
     // optionally set footer
     $footer = '';
     $value = $classKocujSitemapAdmin->getConfigClass()->getOption('PoweredBy');
     if (!empty($value)) {
         $footer = '<div class="kocujsitemapfooter">' . sprintf(__('Powered by %s plugin', 'kocuj-sitemap'), '<a href="http://kocujsitemap.wpplugin.kocuj.pl/" rel="external">Kocuj Sitemap</a>') . '</div>';
     }
     // show begin and end
     if (!empty($output)) {
         $classText = '';
         if (!empty($class)) {
             $classText = ' ' . $class;
         }
         $html5 = $classKocujSitemapAdmin->getConfigClass()->getOption('UseHTML5');
         if (!empty($html5)) {
             $tagBegin = KocujSitemapPluginHTML5::getInstance()->getTagNavBegin('', 'kocujsitemap' . $classText);
             $tagEnd = KocujSitemapPluginHTML5::getInstance()->getTagNavEnd();
         } else {
             $tagBegin = '<div class="kocujsitemap' . $classText . '">';
             $tagEnd = '</div>';
         }
         $output = $tagBegin . $output . $footer . $tagEnd;
     }
     // exit
     return $output;
 }
 /**
  * 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;
 }