Esempio n. 1
0
 /**
  * Load language variables into array.
  *
  * @return Recipe_Language
  */
 protected function getFromDB()
 {
     $whereclause = "";
     for ($i = 0; $i < count($this->grouplist); $i++) {
         $whereclause .= Core::getDB()->quoteInto("(pg.title = ? AND ", $this->grouplist[$i]);
         $whereclause .= Core::getDB()->quoteInto("p.languageid = ?)", $this->langid);
         if ($i < count($this->grouplist) - 1) {
             $whereclause .= " OR ";
         }
     }
     $select = array("p.title", "p.content");
     $result = Core::getQuery()->select("phrases AS p", $select, "LEFT JOIN " . PREFIX . "phrasesgroups AS pg ON (pg.phrasegroupid = p.phrasegroupid)", $whereclause);
     foreach ($result->fetchAll() as $row) {
         $compiler = new Recipe_Language_Compiler($row["content"], true);
         $row["content"] = $compiler->getPhrase();
         $compiler->shutdown();
         $this->setItem($row["title"], $row["content"]);
     }
     $result->closeCursor();
     return $this;
 }
Esempio n. 2
0
 /**
  * Caches only a group of language phrases.
  *
  * @param string $groupname	Phrase group
  * @param integer $langcode	Languageid
  * @param integer $lifetime	Life time [optional]
  *
  * @return Recipe_Cache
  */
 public function cachePhraseGroup($groupname, $langcode, $lifetime = self::DEFAULT_CACHE_LIFE_TIME)
 {
     if (!is_array($groupname)) {
         $groupname = explode(",", $groupname);
         $groupname = Arr::trim($groupname);
     }
     foreach ($groupname as $group) {
         $filename = $this->getLanguageCacheDir() . "lang." . $langcode . "." . $group . ".php";
         try {
             File::rmFile($filename);
         } catch (Exception $e) {
         }
         $cacheContent = $this->setCacheFileHeader("Language [" . $langcode . "] Cache File");
         $cacheContent .= "//### Variables for phrase group \"" . $group . "\" ###//\n";
         $cacheContent .= "\$lifetime=" . (TIME + $lifetime) . ";";
         $joins = "LEFT JOIN " . PREFIX . "languages l ON (l.languageid = p.languageid) ";
         $joins .= "LEFT JOIN " . PREFIX . "phrasesgroups pg ON (pg.phrasegroupid = p.phrasegroupid)";
         $where = Core::getDB()->quoteInto("l.langcode = ?", $langcode);
         $where .= Core::getDB()->quoteInto(" AND pg.title = ?", $group);
         $result = Core::getQuery()->select("phrases p", array("p.title AS phrasetitle", "p.content"), $joins, $where, "p.phrasegroupid ASC, p.title ASC");
         $compiler = new Recipe_Language_Compiler("");
         foreach ($result->fetchAll() as $row) {
             $compiler->setPhrase($row["content"]);
             $cacheContent .= "\$item[\"" . $group . "\"][\"" . $row["phrasetitle"] . "\"]=\"" . $compiler->getPhrase() . "\";";
         }
         $result->closeCursor();
         $compiler->shutdown();
         $cacheContent .= $this->cacheFileClose;
         try {
             $this->putCacheContent($filename, $cacheContent);
         } catch (Recipe_Exception_Generic $e) {
             $e->printError();
         }
     }
     return $this;
 }