示例#1
0
 public static function getTags()
 {
     $ssArr = array();
     $tagsCacheFile = self::$options['XML_ROOT'] . self::$options['tags.xml'];
     $xmlStr = file_exists($tagsCacheFile) ? file_get_contents($tagsCacheFile) : '';
     if ($xmlStr) {
         $xmlFeed = Array_XML::xml2array($xmlStr, 'sections', true);
         if (isset($xmlFeed['section']) && is_array($xmlFeed['section'])) {
             Array_XML::makeListIfNotList($xmlFeed['section']);
             foreach ($xmlFeed['section'] as $section) {
                 $name = !empty($section['@attributes']['name']) ? $section['@attributes']['name'] : false;
                 if ($name && isset($section['tag']) && is_array($section['tag'])) {
                     Array_XML::makeListIfNotList($section['tag']);
                     $ssArr[$name] = array();
                     foreach ($section['tag'] as $subSection) {
                         if (!empty($subSection['@attributes']['name']) && !empty($subSection['value'])) {
                             $ssArr[$name][$subSection['@attributes']['name']] = array('title' => $subSection['value'], 'entry_count' => !empty($subSection['@attributes']['entry_count']) ? $subSection['@attributes']['entry_count'] : 0);
                         }
                     }
                 }
             }
         }
     }
     return $ssArr;
 }
示例#2
0
 function load()
 {
     if (file_exists(BertaBase::$options['XML_ROOT'] . $this->fileName)) {
         if ($xml = file_get_contents(BertaBase::$options['XML_ROOT'] . $this->fileName)) {
             $this->settings = Array_XML::xml2array($xml, 'settings');
             return $this->settings;
         }
     }
     return false;
 }
示例#3
0
 public static function getRemoteFile($url, $type, $timeout = 7, $redirects = 2)
 {
     $o = self::$options;
     $streamOptions = array('http' => array('header' => "Content-Type: text/xml\r\n" . "Berta-User-Agent: {$_SERVER['HTTP_USER_AGENT']}\r\n" . "Berta-Version: Berta {$o['version']}\r\n" . "Berta-URI: {$o['SITE_HOST_ADDRESS']}{$o['SITE_ABS_ROOT']}\r\n" . "Berta-Content: {$type}\r\n", 'max_redirects' => $redirects, 'timeout' => $timeout));
     $context = stream_context_create($streamOptions);
     $page = @file_get_contents($url, false, $context);
     $result = array();
     if ($page && $type == 'newsticker') {
         $pContent = Array_XML::xml2array($page);
         $pContent = $pContent['messages'];
         if (self::updateBertaVersion($pContent['version'], $o['version'])) {
             $result['content'] = $pContent['update'];
         } elseif (!isset($_COOKIE['_berta_newsticker_news']) || $pContent['news'] != $_COOKIE['_berta_newsticker_news']) {
             setcookie('_berta_newsticker_news', $pContent['news'], time() + 60 * 60 * 12, '/');
             $result['content'] = $pContent['news'];
         } else {
             $result['content'] = $pContent['tips']['tip'][rand(0, sizeof($pContent['tips']['tip']) - 1)];
         }
     } else {
         if ($page && $type == 'videos') {
             $pContent = Array_XML::xml2array($page);
             $result['content'] = $pContent['videos'];
         } elseif (!isset($http_response_header)) {
             return null;
         }
     }
     // Bad url, timeout
     // Save the header
     $result['header'] = $http_response_header;
     // Get the *last* HTTP status code
     $nLines = count($http_response_header);
     for ($i = $nLines - 1; $i >= 0; $i--) {
         $line = $http_response_header[$i];
         if (strncasecmp("HTTP", $line, 4) == 0) {
             $response = explode(' ', $line);
             $result['http_code'] = $response[1];
             break;
         }
     }
     return $result;
 }