/** * @author Inez Korczynski <*****@*****.**> */ private function getWikiaFooterLinks() { wfProfileIn( __METHOD__ ); global $wgCityId; $catId = WikiFactoryHub::getInstance()->getCategoryId( $wgCityId ); $message_key = 'shared-Oasis-footer-wikia-links'; $nodes = array(); if ( !isset( $catId ) || null == ( $lines = getMessageAsArray( $message_key . '-' . $catId ) ) ) { if ( null == ( $lines = getMessageAsArray( $message_key ) ) ) { wfProfileOut( __METHOD__ ); return $nodes; } } foreach( $lines as $line ) { $depth = strrpos( $line, '*' ); if( $depth === 0 ) { $nodes[] = parseItem( $line ); } } wfProfileOut( __METHOD__ ); return $nodes; }
private function getGlobalFooterLinks() { global $wgCityId, $wgContLang, $wgLang, $wgMemc; wfProfileIn(__METHOD__); $verticalId = WikiFactoryHub::getInstance()->getVerticalId($wgCityId); $memcKey = wfSharedMemcKey(self::MEMC_KEY_GLOBAL_FOOTER_LINKS, $wgContLang->getCode(), $wgLang->getCode(), $verticalId, self::MEMC_KEY_GLOBAL_FOOTER_VERSION); $globalFooterLinks = $wgMemc->get($memcKey); if (!empty($globalFooterLinks)) { wfProfileOut(__METHOD__); return $globalFooterLinks; } if (is_null($globalFooterLinks = getMessageAsArray(self::MESSAGE_KEY_GLOBAL_FOOTER_LINKS . '-' . $verticalId))) { if (is_null($globalFooterLinks = getMessageAsArray(self::MESSAGE_KEY_GLOBAL_FOOTER_LINKS))) { wfProfileOut(__METHOD__); WikiaLogger::instance()->error("Global Footer's links not found in messages", ['exception' => new Exception()]); return []; } } $parsedLinks = []; foreach ($globalFooterLinks as $link) { $link = trim($link); if (strpos($link, '*') === 0) { $parsedLink = parseItem($link); if (strpos($parsedLink['text'], 'LICENSE') !== false || $parsedLink['text'] == 'GFDL') { $parsedLink['isLicense'] = true; } else { $parsedLink['isLicense'] = false; } $parsedLinks[] = $parsedLink; } } $wgMemc->set($memcKey, $parsedLinks, self::MEMC_EXPIRY); wfProfileOut(__METHOD__); return $parsedLinks; }
function getNews($n_items = 0) { if (file_exists("news/news.xml")) { $newsfile = "news/news.xml"; } else { $newsfile = "news/skeleton.xml"; } $raw_data = implode("", file($newsfile)); $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); xml_parse_into_struct($parser, $raw_data, $values, $tags); xml_parser_free($parser); # Loop through the items foreach ($tags as $key => $val) { if ($key != "item") { continue; } else { # Get the array of "item" instances $items = $val; # Each "item" should have both open and close pairs for ($i = 0; $i < count($items) && ($n_items == 0 || $i < 2 * $n_items); $i += 2) { # Get the position and length of the tags inside the item $data_begin = $items[$i] + 1; $length = $items[$i + 1] - $data_begin; # Process the item $item_data = array_slice($values, $data_begin, $length); $parsed_items[] = parseItem($item_data); } # We have everything with the "item" tag return $parsed_items; } } }
define('SF_DEBUG', false); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; $databaseManager = new sfDatabaseManager(); $databaseManager->initialize(); $blogs = BlogPeer::getApproved(); logmsg('Skrypt odswiezajacy'); logmsg('Feedow do sprawdzenia: %d', count($blogs)); logmsg(str_repeat('-', 80)); foreach ($blogs as $blog) { logmsg('Parsowanie feedu %s', $blog->getFeed()); try { $items = FeedParser::parse($blog->getFeed()); $ts = PostPeer::getNewestTimestamp($blog); logmsg('Najnowszy wpis (timestamp): %d', $ts); foreach ($items as $item) { if (!parseItem($blog, $item, $ts)) { break; } } } catch (Exception $e) { logmsg('Blad: %s', $e->getMessage()); } logmsg(str_repeat('-', 80) . "\n"); } logmsg('Odswiezanie zakonczone.'); function parseItem($blog, $item, $ts) { if ($ts != 0 && $item->pubdate <= $ts) { logmsg('Zatrzymanie na wpisie: %s', StringUtils::removeAccents($item->title)); return false; }
/** * @author Inez Korczynski <*****@*****.**> */ private function getRelatedCommunitiesLinks() { $lines = $this->getLines('Monaco-related-communities'); $nodes = array(); if(is_array($lines) && count($lines) > 0) { foreach($lines as $line) { $depth = strrpos($line, '*'); if($depth === 0) { $nodes[] = parseItem($line); } } } return $nodes; }
/** * @author Inez Korczynski <*****@*****.**> */ public static function getCategoryList() { wfProfileIn(__METHOD__); global $wgCat; $cat['text'] = isset($wgCat['name']) ? $wgCat['name'] : ''; $cat['href'] = isset($wgCat['url']) ? $wgCat['url'] : ''; $message_key = 'shared-Monaco-category-list'; $nodes = array(); if (!isset($wgCat['id']) || null == ($lines = getMessageForContentAsArray($message_key . '-' . $wgCat['id']))) { wfDebugLog('monaco', $message_key . '-' . $wgCat['id'] . ' - seems to be empty'); if (null == ($lines = getMessageForContentAsArray($message_key))) { wfDebugLog('monaco', $message_key . ' - seems to be empty'); wfProfileOut(__METHOD__); return $nodes; } } foreach ($lines as $line) { $depth = strrpos($line, '*'); if ($depth === 0) { $cat = parseItem($line); } else { if ($depth === 1) { $nodes[] = parseItem($line); } } } wfProfileOut(__METHOD__); return array('nodes' => $nodes, 'cat' => $cat); }
function handleInstanceReq($rootDoc, $req, $name) { $xPath = new DOMXPath($rootDoc); $items = $xPath->query("item[settings/name = '{$name}']"); $item = $items->length > 0 ? $items->item(0) : false; if ($item !== false) { // if(isset($_REQUEST['ajax'])) // { // echo "ajax!"; // die(); // we probably don't want to do this... but it works for now. // } // else // { $config = parseItem($item); $module = initModule($config); switch ($req) { case 'ajax': $module->setMode("ajax"); break; case 'page': $module->setMode("default"); break; default: die; break; } $moduleXML = '<?xml version="1.0" encoding="utf-8" ?>' . "\n" . $module->getXML(); // echo "---1---\n"; // var_dump($config); // echo "---2---\n"; // var_dump($module); // echo "---3---\n"; // var_dump($moduleXML); // echo "---END---\n"; $moduleDoc = new DOMDocument(); $moduleDoc->loadXML($moduleXML); $moduleElem = $moduleDoc->documentElement; $outDoc = new DOMDocument(); $outDoc->loadXML('<?xml version="1.0" encoding="utf-8"?><root />'); $title = $xPath->query("/root/title")->item(0); $titleNode = $outDoc->importNode($title, true); $outDoc->documentElement->appendChild($titleNode); $moduleNode = $outDoc->importNode($moduleElem, true); $outDoc->documentElement->appendChild($moduleNode); // echo "---outDoc XML---\n"; // echo $outDoc->saveXML()."\n"; $rootStylesheet = new DOMDocument(); $rootStylesheet->load(CONFIG_DIR . 'root.xsl'); $transformer = new XSLTProcessor(); $transformer->importStylesheet($rootStylesheet); echo $transformer->transformToXML($outDoc); ob_end_flush(); flush(); die; // } } else { // FIXME: Do something to handle that there was no module with that name } }
$rootItems = $rootDoc->hasChildNodes() ? $rootDoc->getElementsByTagName('item') : false; if ($rootItems) { // We have to do this in an ugly way since DOMNodeLists that are returned // from DOMDocument::getElementsByTagName() seem to differ from those // returned from DOMNode->childNodes. Magic. $itemCount = $rootItems->length; $i = 0; while ($i < $itemCount) { // This SHOULDN'T work, but it seems that item(0) moves some internal // pointer one step forward. This issue has 1-3 Crazy Hours $rootItem = $rootItems->item(0); $i++; // echo "inspecting $rootItem->nodeName: $rootItem->nodeValue\n"; // The node is a text node, skip it. // Do The Right Thing™ with the node. $itemConfig = parseItem($rootItem); $module = initModule($itemConfig); $moduleXML = '<?xml version="1.0" encoding="utf-8"?>' . "\n" . $module->getXML(); // echo "---module XML---\n"; // echo "$moduleXML\n"; $moduleDoc = new DOMDocument(); $moduleDoc->loadXML($moduleXML); // echo "---moduleDoc XML---\n"; // echo $moduleDoc->saveXML()."\n"; $moduleElem = $moduleDoc->documentElement; $moduleNode = $rootDoc->importNode($moduleElem, true); $parent = $rootItem->parentNode; $parent->removeChild($rootItem); $parent->appendChild($moduleNode); } // echo "---altered rootDoc xml---\n";