Example #1
0
 /**
  * Saves data into the file
  *
  * @access  public
  * @param   string  $cache_file
  * @param   string  $data
  * @return  mixed   True on success and PEAR error on failure
  */
 function saveFile($cache_file, $data)
 {
     if (!Jaws_Utils::file_put_contents($cache_file, serialize($data))) {
         return PEAR::raiseError("Fail to save stream with file_put_contents('{$cache_file}',...).");
     }
     return true;
 }
Example #2
0
 /**
  * Store cache of given component/section
  *
  * @access  public
  */
 function set($component, $section, $params, &$data, $lifetime = 0)
 {
     if (!is_null($params)) {
         $params = is_array($params) ? implode('_', $params) : $params;
     } else {
         $params = '';
     }
     $file = $this->_path . $component . '.' . $section . (empty($params) ? '' : '.' . $params);
     return (bool) Jaws_Utils::file_put_contents($file, $data);
 }
Example #3
0
 /**
  * Save language data into file
  *
  * @access  public
  * @param   string  $module
  * @param   string  $type
  * @param   string  $langTo
  * @param   array   $data
  * @return  bool    True on Success or False on failure
  */
 function SetLangData($module, $type, $langTo, $data = null)
 {
     $module_name = $module;
     switch ($type) {
         case JAWS_COMPONENT_GADGET:
             if ($langTo == 'en') {
                 $orig_file = JAWS_PATH . "gadgets/{$module}/Resources/translates.ini";
             } else {
                 $orig_file = JAWS_PATH . "languages/{$langTo}/gadgets/{$module}.ini";
             }
             $data_file = JAWS_DATA . "languages/{$langTo}/gadgets/{$module}.ini";
             break;
         case JAWS_COMPONENT_PLUGIN:
             if ($langTo == 'en') {
                 $orig_file = JAWS_PATH . "plugins/{$module}/Resources/translates.ini";
             } else {
                 $orig_file = JAWS_PATH . "languages/{$langTo}/plugins/{$module}.ini";
             }
             $data_file = JAWS_DATA . "languages/{$langTo}/plugins/{$module}.ini";
             $from_file = JAWS_PATH . "plugins/{$module}/Resources/translates.ini";
             $module_name = 'Plugins_' . $module;
             break;
         case JAWS_COMPONENT_INSTALL:
             if ($langTo == 'en') {
                 $orig_file = JAWS_PATH . "install/Resources/translates.ini";
             } else {
                 $orig_file = JAWS_PATH . "languages/{$langTo}/Install.ini";
             }
             $data_file = JAWS_DATA . "languages/{$langTo}/Install.ini";
             break;
         case JAWS_COMPONENT_UPGRADE:
             if ($langTo == 'en') {
                 $orig_file = JAWS_PATH . "upgrade/Resources/translates.ini";
             } else {
                 $orig_file = JAWS_PATH . "languages/{$langTo}/Upgrade.ini";
             }
             $data_file = JAWS_DATA . "languages/{$langTo}/Upgrade.ini";
             break;
         default:
             if ($langTo == 'en') {
                 $orig_file = JAWS_PATH . "include/Jaws/Resources/translates.ini";
             } else {
                 $orig_file = JAWS_PATH . "languages/{$langTo}/Global.ini";
             }
             $data_file = JAWS_DATA . "languages/{$langTo}/Global.ini";
     }
     $update_default_lang = $this->gadget->registry->fetch('update_default_lang') == 'true';
     $strings = array();
     if (file_exists($orig_file)) {
         $strings = parse_ini_file($orig_file, false, INI_SCANNER_RAW);
     }
     // user translation
     $tpl = $this->gadget->template->loadAdmin('FileTemplate.html');
     $tpl->SetBlock('template');
     $tpl->SetVariable('project', $module_name);
     $tpl->SetVariable('language', strtoupper($langTo));
     // orig translation
     $tpl2 = $this->gadget->template->loadAdmin('FileTemplate.html');
     $tpl2->SetBlock('template');
     $tpl2->SetVariable('project', $module_name);
     $tpl2->SetVariable('language', strtoupper($langTo));
     // Meta
     foreach ($data['meta'] as $k => $v) {
         // user translation
         $tpl->SetBlock('template/meta');
         $tpl->SetVariable('key', $k);
         $tpl->SetVariable('value', $v);
         $tpl->ParseBlock('template/meta');
         // orig translation
         $tpl2->SetBlock('template/meta');
         $tpl2->SetVariable('key', $k);
         $tpl2->SetVariable('value', $v);
         $tpl2->ParseBlock('template/meta');
     }
     // Strings
     $change_detected = false;
     foreach ($data['strings'] as $k => $v) {
         if ($v == '') {
             continue;
         } elseif ($v === $this->_EMPTY_STRING) {
             $v = '';
         }
         $v = preg_replace("\$\r\n|\n\$", '\\n', $v);
         $changed = !isset($strings[$k]) || $strings[$k] !== $v;
         if ($changed) {
             $change_detected = true;
             $tpl->SetBlock('template/string');
             $tpl->SetVariable('key', $k);
             $tpl->SetVariable('value', $v);
             $tpl->ParseBlock('template/string');
         }
         // orig translation
         $tpl2->SetBlock('template/string');
         $tpl2->SetVariable('key', $k);
         $tpl2->SetVariable('value', $v);
         $tpl2->ParseBlock('template/string');
     }
     $tpl->ParseBlock('template');
     $tpl2->ParseBlock('template');
     // update original translation
     if ($update_default_lang) {
         // update default language translation,
         // so we can delete customized language's file
         if (Jaws_Utils::file_put_contents($orig_file, $tpl2->Get())) {
             $change_detected = false;
         }
     }
     // Writable
     if (file_exists($data_file)) {
         $writeable = Jaws_Utils::is_writable($data_file);
     } else {
         Jaws_Utils::mkdir(dirname($data_file), 3);
         $writeable = Jaws_Utils::is_writable(dirname($data_file));
     }
     if (!$writeable) {
         $GLOBALS['app']->Session->PushLastResponse(_t('LANGUAGES_NOT_PERMISSION'), RESPONSE_ERROR);
         return false;
     }
     if ($change_detected) {
         if (Jaws_Utils::file_put_contents($data_file, $tpl->Get())) {
             $GLOBALS['app']->Session->PushLastResponse(_t('LANGUAGES_UPDATED', $module), RESPONSE_NOTICE);
             return true;
         } else {
             $GLOBALS['app']->Session->PushLastResponse(_t('LANGUAGES_NOT_UPDATED', $module), RESPONSE_ERROR);
             return false;
         }
     } else {
         Jaws_Utils::Delete($data_file);
         $GLOBALS['app']->Session->PushLastResponse(_t('LANGUAGES_UPDATED', $module), RESPONSE_NOTICE);
         return true;
     }
 }
Example #4
0
 /**
  * Get Sitemap XML content
  *
  * @access  public
  * @return  XML   content of sitemap
  */
 function GetSitemapXML()
 {
     $xml_file = JAWS_DATA . 'sitemap/sitemap.xml';
     if (file_exists($xml_file)) {
         if (false === ($data = @file_get_contents($xml_file))) {
             return false;
         }
         return $data;
     }
     $tpl = $this->gadget->template->load('SitemapXML.html');
     $tpl->SetBlock('xml');
     $date = Jaws_Date::getInstance();
     $gadgets = $this->GetAvailableSitemapGadgets();
     foreach ($gadgets as $gadget) {
         $gadget_xml_file = JAWS_DATA . 'sitemap/' . strtolower($gadget['name']) . '/sitemap.xml';
         if (file_exists($gadget_xml_file)) {
             $tpl->SetBlock('xml/item');
             $tpl->SetVariable('loc', $this->gadget->urlMap('SitemapXML', array('gname' => strtolower($gadget['name'])), true));
             $tpl->SetVariable('lastmod', $date->ToISO(filemtime($gadget_xml_file)));
             $tpl->ParseBlock('xml/item');
         }
     }
     $tpl->ParseBlock('xml');
     $xmlContent = $tpl->Get();
     if (!Jaws_Utils::file_put_contents($xml_file, $xmlContent)) {
         return false;
     }
     return $xmlContent;
 }
Example #5
0
 /**
  * Sync sitemap data files
  *
  * @access  public
  * @param   string  $gadget  Gadget name
  * @return  mixed   Array of Tag info or Jaws_Error on failure
  */
 function SyncSitemapData($gadget)
 {
     $objGadget = Jaws_Gadget::getInstance($gadget);
     if (Jaws_Error::IsError($objGadget)) {
         return '';
     }
     $objHook = $objGadget->hook->load('Sitemap');
     if (Jaws_Error::IsError($objHook)) {
         return '';
     }
     $result[$gadget] = array();
     $gResult = $objHook->Execute(1);
     if (Jaws_Error::IsError($gResult) || empty($gResult)) {
         return '';
     }
     // Check gadget directory in sitemap
     $gadget_dir = JAWS_DATA . 'sitemap/' . strtolower($gadget);
     if (!Jaws_Utils::mkdir($gadget_dir, 1)) {
         return new Jaws_Error(_t('GLOBAL_ERROR_FAILED_CREATING_DIR', $gadget_dir));
     }
     $cache_file = $gadget_dir . '/sitemap.bin';
     if (!Jaws_Utils::file_put_contents($cache_file, serialize($gResult))) {
         return false;
     }
     return true;
 }
Example #6
0
 /**
  * Saves data into the file
  *
  * @access  public
  * @param   string  $cache_file    Filename
  * @return  mixed   True on success or error on failure
  */
 function saveFile($cache_file)
 {
     if (!isset($this->feed)) {
         return false;
     }
     $serialized = serialize($this->ex_array_map('base64_encode', $this->feed));
     if (Jaws_Utils::file_put_contents($cache_file, $serialized)) {
         return true;
     } else {
         return $this->raiseError("Fail to save stream with file_put_contents('{$cache_file}',...).");
     }
 }