Exemple #1
0
 /**
  * Создаёт базовую rss со всеми настройками
  * @static
  * @param bool $ignoreCache
  * @return rss
  */
 public static function make($ignoreCache = false)
 {
     $rss = new self();
     $rss->getSettings();
     if ($rss->settings['onLine'] == 0) {
         return false;
     }
     // проверяем кэш
     $cachedRss = $rss->getCache();
     if (!empty($cachedRss) && !$ignoreCache) {
         $rss->xml = $cachedRss;
         $rss->cached = true;
         return $rss;
     }
     $rss->rssDoc = new \DOMDocument();
     $rss->rssDoc->formatOutput = true;
     $rss->rssDoc->encoding = 'utf-8';
     $rss->rss = $rss->rssDoc->appendChild($rss->rssDoc->createElement('rss'));
     $rss->rss->setAttribute('version', '2.0');
     $rss->channel = $rss->rss->appendChild($rss->rssDoc->createElement('channel'));
     $rss->channel->appendChild($rss->rssDoc->createElement('title', $rss->settings['title']));
     $rss->channel->appendChild($rss->rssDoc->createElement('link', $rss->settings['link']));
     $rss->channel->appendChild($rss->rssDoc->createElement('language', Envi\Setup::getLocale()));
     if (!empty($rss->settings['description'])) {
         $rss->channel->appendChild($rss->rssDoc->createElement('description', $rss->settings['description']));
     }
     $rss->channel->appendChild($rss->rssDoc->createElement('ttl', $rss->settings['ttl']));
     if (!empty($rss->settings['copyright'])) {
         $copyRight = 'Copyright ' . date('Y') . ', ' . $rss->settings['copyright'];
         $rss->channel->appendChild($rss->rssDoc->createElement('copyright', $copyRight));
     }
     $pubDate = date('r');
     $rss->channel->appendChild($rss->rssDoc->createElement('pubDate', $pubDate));
     $rss->rssImage();
     return $rss;
 }
Exemple #2
0
 /**
  * Fill output XML with some common data
  * @param \DOMDocument|null $xml
  * @param null $instance
  */
 public static function fillXML(&$xml = null, $instance = null)
 {
     $controller = Controller::getInstance();
     if (is_null($xml)) {
         $xml = $controller->xml;
         $node = $controller->realRoot;
     } else {
         $node = $xml->documentElement;
     }
     Debugger::addLine('Filling XML data for render: Started');
     // TODO: sync this with Envi::getState()
     $node->setAttribute('lang', Envi\Setup::getLocale());
     $node->setAttribute('site', Envi::getSubsite());
     $node->setAttribute('host', $host = Envi::getHost());
     $node->setAttribute('mainhost', $mainhost = Envi::getHost(true));
     $node->setAttribute('protocol', Envi::getProtocol());
     $node->setAttribute('fullhost', Envi::getURLPrefix());
     $node->setAttribute('instance', $instance ? $instance : View::$instance);
     $node->setAttribute('uri', Envi::getUri());
     $node->setAttribute('controllerUri', Action::getControllerUri());
     if ($host != $mainhost) {
         $node->setAttribute('urlprefix', Envi::getURLPrefix(true));
     }
     // get user agent
     Envi\UserAgent::getUserAgentXML($node);
     // ajax flag
     $node->setAttribute('ajax', (Request::isAjax() or isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'SwitchPage') ? '1' : '0');
     $node->setAttribute('switcher', (!$controller->cache and isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'SwitchPage') ? '1' : '0');
     // build and version number
     $node->setAttribute('build', Version::getBuild());
     $node->setAttribute('framework', Version::getFrameworkVersion(false));
     $node->setAttribute('frameworkLong', Version::getFrameworkVersion(true));
     // date
     /** @var $dateNode \DOMElement */
     $dateNode = $node->appendChild($xml->createElement('date'));
     $dateKeys = ['d', 'e', 'A', 'a', 'm', 'B', 'b', 'Y', 'y', 'c', 'x', 'H', 'M', 'S'];
     $dateValues = explode('|', strftime('%' . implode('|%', $dateKeys)));
     $dateCombined = array_combine($dateKeys, $dateValues);
     $dateNode->setAttribute('ts', time());
     foreach ($dateCombined as $k => $v) {
         $dateNode->setAttribute($k, $v);
     }
     // debug flag
     $node->setAttribute('debug', Debugger::isEnabled() ? '1' : '0');
     // config values (for js variable)
     $configNode = $node->appendChild($xml->createElement('config'));
     Envi::getStateXML($configNode);
     // menu
     if ($menuResource = Resourcer::getInstance('menu')->compile(View::$instance)) {
         $menuXML = new \DOMDocument();
         $menuXML->loadXML($menuResource);
         $node->appendChild($xml->importNode($menuXML->documentElement, true));
     }
     // auth
     Auth::getInstance()->getAuthXML($node);
     // locale
     Locales::getInstance()->getLocaleXML($node);
     // Add config js object
     $config = Envi::getState();
     $confJS = '';
     foreach ($config as $k => $v) {
         $confJS .= "config.{$k}='" . addslashes($v) . "';";
     }
     $node->setAttribute('jsConfig', $confJS);
     Debugger::addLine('Filling XML data for render: Done');
     Debugger::debugXML($node);
 }
Exemple #3
0
 /**
  * Factory
  * @param string $locale
  * @return Wordforms\Common
  */
 public static function getInstance($locale = null)
 {
     if (!$locale) {
         $locale = Setup::getLocale();
     }
     if (isset(self::$objects[$locale])) {
         return self::$objects[$locale];
     }
     if (class_exists(__NAMESPACE__ . '\\Wordforms\\' . $locale)) {
         return self::$objects[$locale] = call_user_func([__NAMESPACE__ . '\\Wordforms\\' . $locale, 'getInstance']);
     } else {
         return self::$objects[$locale] = call_user_func([__NAMESPACE__ . '\\Wordforms\\Common', 'getInstance']);
     }
 }