Ejemplo n.º 1
0
 function __autoload($className)
 {
     Log::timingplus('autoload');
     require_once $className . '.php';
     Log::timingplus('autoload');
     Log::logHtml('class loaded [' . $className . ']');
 }
Ejemplo n.º 2
0
 public static function query($query)
 {
     Log::timingplus('query:' . $query);
     if (!($r = self::getInstance()->query($query, PDO::FETCH_ASSOC))) {
         throw new Exception($query . ' ', Error::E_QUERY);
     }
     Log::timingplus('query:' . $query);
     return $r;
 }
Ejemplo n.º 3
0
	public static function query($query, $throwError = true) {
		Log::timingplus('query:' . $query);
		if (!$r = self::getInstance()->query($query, PDO::FETCH_ASSOC))
			if ($throwError)
				throw new Exception($query . ' ', Error::E_QUERY);
			else
				return false;
		Log::timingplus('query:' . $query);
		return $r;
	}
Ejemplo n.º 4
0
	public function getHTML($xml) {
		global $current_user;
		Log::timingplus('XSLTProcessor');
		$xslTemplate = new DOMDocument();
		$xslProcessor = new XSLTProcessor();
		$filename = Config::need('xslt_files_path') . DIRECTORY_SEPARATOR . $current_user->getTheme() . DIRECTORY_SEPARATOR . $this->xsltFileName;
		$xslTemplate->load($filename, LIBXML_NOENT | LIBXML_DTDLOAD);
		$xslProcessor->importStyleSheet($xslTemplate);
		$html = $xslProcessor->transformToXML($xml);
		Log::timingplus('XSLTProcessor');
		return $html;
	}
Ejemplo n.º 5
0
 public static function query($query, $throwError = true)
 {
     Log::timingplus('query:' . $query);
     if (!($r = self::getInstance()->query($query, PDO::FETCH_ASSOC))) {
         if ($throwError) {
             throw new Exception($query . "\n" . print_r(self::getInstance()->errorInfo(), 1));
         } else {
             return false;
         }
     }
     Log::timingplus('query:' . $query);
     return $r;
 }
Ejemplo n.º 6
0
 public function getResultXML()
 {
     if ($this->xmlPart !== false) {
         return $this->xmlPart;
     }
     $this->xmlPart = XMLClass::createNodeFromObject(array('data' => $this->data, 'settings' => $this->settings), false, 'module');
     if ($this->xHTMLCachingEnabled) {
         Log::timingplus('BaseModule:xHTML generating #' . $this->moduleName);
         // процессим кусок XML с шаблоном, чтобы получить xHTML
         // шаблон, который отпроцессит только наш модуль - null.xsl
         $XSLClass = new XSLClass(LibPages::$pages[Request::$pageName]['xslt'], $xHTML = true);
         $arr = array($this->moduleName => $this->getXSLTFileName(true));
         // и шаблон модуля
         $XSLClass->setTemplates($arr);
         // создаем документ
         $xml = new DOMDocument('1.0', 'UTF-8');
         $xml->loadXML("<xml version=\"1.0\" encoding=\"utf-8\" >" . "<root></root></xml>");
         $rootNode = $xml->getElementsByTagName("root")->item(0);
         // нода page также нужна для корректной обработки шаблонаы
         $pageNode = $xml->importNode(XMLClass::$pageNode);
         $rootNode->appendChild($pageNode);
         // вставляем в него ноду с данными модуля
         $xHTMLnode = $xml->importNode($this->xmlPart, true);
         $rootNode->appendChild($xHTMLnode);
         $xHTMLnode->setAttribute('name', $this->moduleName);
         // теперь полученный xml процессим с шаблоном
         $xHTML = $XSLClass->getHTML($xml);
         // полученный xHTML нужно вбить в XML ноду "module"
         $xHTMLdoc = new DOMDocument('1.0', 'UTF-8');
         $xHTMLdoc->loadHTML($xHTML);
         $xpath = new DOMXPath($xHTMLdoc);
         $part = $xpath->query('body')->item(0);
         $part = $xHTMLdoc->importNode($part, true);
         // в part лежит HTML код
         // копируем его в новую ноду
         $NewElement = XMLClass::$xml->createElement('module');
         // Clone the attributes:
         foreach ($part->attributes as $attribute) {
             $NewElement->setAttribute($attribute->name, $attribute->value);
         }
         foreach ($part->childNodes as $child) {
             $NewElement->appendChild(XMLClass::$xml->importNode($child, true));
         }
         $this->xmlPart = $NewElement;
         Log::timingplus('BaseModule:xHTML generating #' . $this->moduleName);
     }
     $this->putInCache();
     return $this->xmlPart;
 }
Ejemplo n.º 7
0
 protected function getFromCache()
 {
     if (!$this->cache_enabled) {
         return false;
     }
     $cache_sec = isset($this->params['cache']) ? max(0, (int) $this->params['cache']) : 0;
     if (!$cache_sec) {
         return false;
     }
     if ($data = Cache::get($this->xml_cache_name, Cache::DATA_TYPE_XML, $cache_sec)) {
         Log::timingplus($this->moduleName . ' : XML from cache');
         $doc = new DOMDocument();
         $doc->loadXML($data);
         // говорим нашему дереву что этот кусок из кеша будет вставлен
         $part = $doc->getElementsByTagName("module")->item(0);
         $this->xmlPart = XMLClass::$xml->importNode($part, true);
         Log::timingplus($this->moduleName . ' : XML from cache');
         return $this->xmlPart;
     }
     return false;
 }
Ejemplo n.º 8
0
 public static function set($name, $value, $cache_seconds = false, $datatype = self::DATA_TYPE_VAR)
 {
     self::init();
     Log::timingplus('cache:set');
     if (!$cache_seconds) {
         $cache_seconds = self::$max_cache_sec;
     }
     switch (self::$cacheType) {
         case self::CACHE_TYPE_XCACHE:
             self::set_xcache($name, $value, $datatype, $cache_seconds);
             break;
         case self::CACHE_TYPE_MEMCACHE:
             break;
         case self::CACHE_TYPE_FILE:
             self::set_file($name, $value, $datatype);
             break;
     }
     Log::timingplus('cache:set');
 }
Ejemplo n.º 9
0
 public function getHTML($xml, $xslt = false)
 {
     Log::timingplus('XSLTProcessor');
     $xslTemplate = new DOMDocument();
     $xslProcessor = new XSLTProcessor();
     $xslTemplate->loadXML($xslt ? $xslt : $this->getSplitedTemplate(), LIBXML_NOENT | LIBXML_DTDLOAD);
     $xslProcessor->importStyleSheet($xslTemplate);
     // кладем в кеш xslt
     $html = $xslProcessor->transformToXML($xml);
     Log::timingplus('XSLTProcessor');
     return $html;
 }
Ejemplo n.º 10
0
 public function searchSeriesByString($string, $offset = 0, $limit = 100)
 {
     if (Config::need('disable_solr')) {
         $foundids = array_keys(Database::sql2array('SELECT `id` FROM `series` WHERE `title` LIKE \'%' . $string . '%\' LIMIT ' . $offset . ',' . $limit, 'id'));
         $foundcnt = count($foundids);
         return array($foundids, $foundcnt, array());
     }
     Log::timingplus('solr searchSeriesByString');
     $series = self::$series;
     $ids = array();
     $count = 0;
     /* @var $books Apache_Solr_Service */
     // @text field - for bio including, @name- for 1,2,3name
     $string = $string ? $string : '*';
     $query = $string == '*' ? '*:*' : 'text:' . $series->escape($string);
     // дубликаты убираем
     $query .= ' AND books_count:true';
     // удаленные убираем
     $query .= ' AND is_s_duplicate:false';
     $query .= ' AND is_deleted:false';
     $res = $series->search($query, $offset, $limit, array('fl' => 'id', 'hl' => 'true', 'hl.fl' => '*', 'usePhraseHighlighter' => 'true'));
     /* @var $res Apache_Solr_Response */
     foreach ($res->response->docs as $document) {
         $ids[$document->id] = $document->id;
     }
     $count = $res->response->numFound;
     Log::timingplus('solr searchSeriesByString');
     return array($ids, $count, $this->getHighlighted($res));
 }
Ejemplo n.º 11
0
 public function getHTML($xml, $xslt = false)
 {
     $doc = new DOMDocument();
     $xsl = new XSLTProcessor();
     $doc->loadXML($xslt ? $xslt : $this->getSplitedTemplate());
     $xsl->importStyleSheet($doc);
     // кладем в кеш xslt
     Log::timingplus('XSLTProcessor');
     $res = $xsl->transformToXML($xml);
     Log::timingplus('XSLTProcessor');
     return $res;
 }