public function testFormattingDatesBasedOnCOnfigTwo()
 {
     $stub = $this->getMock("COnfig");
     $stub->expects($this->any())->method('get')->with('date.format')->will($this->returnValue('c'));
     $formatter = new DateFormatter($stub);
     $this->assertEquals($formatter->getFormattedDate(0), '1970-01-01T00:00:00+00:00');
 }
Пример #2
0
 function test_changeDate_getInput()
 {
     //Arrange
     $test_DateFormatter = new DateFormatter();
     $start_date = "Jan";
     $end_date = "Feb";
     //Act
     $result = $test_DateFormatter->changeDate($start_date, $end_date);
     //Assert
     $this->assertEquals("Jan Feb", $result);
 }
Пример #3
0
 protected function valueForType($type, $value)
 {
     $valueForType = $value;
     switch ($type) {
         case 'datetime':
             $valueForType = DateFormatter::formatDateRange($value, DateFormatter::LONG_STYLE, DateFormatter::NO_STYLE);
             if ($value instanceof TimeRange) {
                 $timeString = DateFormatter::formatDateRange($value, DateFormatter::NO_STYLE, DateFormatter::MEDIUM_STYLE);
                 $valueForType .= "<br />\n" . $timeString;
             }
             break;
         case 'url':
             $valueForType = str_replace("http://*****:*****@', '@&shy;', $value);
             break;
         case 'category':
             $valueForType = $this->ucname($value);
             break;
     }
     return $valueForType;
 }
Пример #4
0
 public static function timeText($event, $timeOnly = false)
 {
     if ($timeOnly) {
         if ($event->getEnd() - $event->getStart() == -1) {
             return DateFormatter::formatDate($event->getStart(), DateFormatter::NO_STYLE, DateFormatter::SHORT_STYLE);
         } else {
             return DateFormatter::formatDateRange($event->getRange(), DateFormatter::NO_STYLE, DateFormatter::SHORT_STYLE);
         }
     } else {
         return DateFormatter::formatDateRange($event->getRange(), DateFormatter::SHORT_STYLE, DateFormatter::SHORT_STYLE);
     }
 }
Пример #5
0
 /**
  * @param Parser $parser
  * @param string $date
  * @param string $defaultPref
  *
  * @return string
  */
 public static function formatDate($parser, $date, $defaultPref = null)
 {
     $lang = $parser->getFunctionLang();
     $df = DateFormatter::getInstance($lang);
     $date = trim($date);
     $pref = $parser->getOptions()->getDateFormat();
     // Specify a different default date format other than the normal default
     // if the user has 'default' for their setting
     if ($pref == 'default' && $defaultPref) {
         $pref = $defaultPref;
     }
     $date = $df->reformat($pref, $date, array('match-whole'));
     return $date;
 }
Пример #6
0
 public function getAllEmergencyNotices()
 {
     if ($this->emergencyNotices === NULL) {
         $now = time();
         $this->emergencyNotices = array();
         $items = $this->getData();
         foreach ($items as $item) {
             if ($this->NOTICE_EXPIRATION && $now - $item->getPubTimestamp() > $this->NOTICE_EXPIRATION) {
                 break;
                 // items too old
             }
             $this->emergencyNotices[] = array('title' => $item->getTitle(), 'text' => $item->getDescription(), 'date' => DateFormatter::formatDate($item->getPubDate(), DateFormatter::MEDIUM_STYLE, DateFormatter::MEDIUM_STYLE), 'unixtime' => $item->getPubTimestamp());
             if (isset($this->NOTICE_MAX_COUNT) && count($this->emergencyNotices) >= $this->NOTICE_MAX_COUNT) {
                 break;
                 // hit max count
             }
         }
     }
     return $this->emergencyNotices;
 }
Пример #7
0
 /**
  * Tests the class DateFormatter.
  *
  * @public
  * @return @c true on success @c false on failure.
  */
 function test()
 {
     $df = new DateFormatter("d-m Y");
     $df->disableCurrentYear();
     if (date("d-m Y") != $df->format(time())) {
         echo "Failed format d-m Y";
         return false;
     }
     $df->setCurrentYear(date("Y"), "d-m");
     if (date("d-m") != $df->format(time())) {
         echo "Failed format d-m";
         return false;
     }
     //Now it is last year
     $lastYear = time() - 366 * 24 * 3600;
     if (date("d-m Y", $lastYear) != $df->format($lastYear)) {
         echo "Failed format d-m Y using current year";
         return false;
     }
     return true;
 }
Пример #8
0
 protected function timeText(AthleticEvent $event, $timeOnly = false)
 {
     return DateFormatter::formatDateRange($event->getRange(), DateFormatter::SHORT_STYLE, DateFormatter::SHORT_STYLE);
 }
 protected function initializeForPage()
 {
     switch ($this->page) {
         case 'news':
             $start = $this->getArg('start', 0);
             $section = $this->getArg('section');
             $newsFeed = $this->getNewsFeed($section);
             $newsFeed->setStart($start);
             $newsFeed->setLimit($this->maxPerPage);
             $items = $newsFeed->items();
             $totalItems = $newsFeed->getTotalItems();
             $this->setLogData($section, $newsFeed->getTitle());
             $previousURL = null;
             $nextURL = null;
             if ($totalItems > $this->maxPerPage) {
                 $args = $this->args;
                 if ($start > 0) {
                     $args['start'] = $start - $this->maxPerPage;
                     $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                 }
                 if ($totalItems - $start > $this->maxPerPage) {
                     $args['start'] = $start + $this->maxPerPage;
                     $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                 }
             }
             $options = array('section' => $section);
             $stories = array();
             foreach ($items as $story) {
                 $stories[] = $this->linkForNewsItem($story, $options);
             }
             $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
             $this->addOnLoad('setupNewsListing();');
             $this->assign('maxPerPage', $this->maxPerPage);
             $this->assign('stories', $stories);
             $this->assign('previousURL', $previousURL);
             $this->assign('nextURL', $nextURL);
             $this->assign('showImages', $this->showImages);
             $this->assign('showPubDate', $this->showPubDate);
             $this->assign('showAuthor', $this->showAuthor);
             break;
         case 'news_detail':
             $section = $this->getArg('section');
             $gender = $this->getArg('gender');
             $storyID = $this->getArg('storyID', false);
             $storyPage = $this->getArg('storyPage', '0');
             $feed = $this->getNewsFeed($section, $gender);
             $showBodyThumbnail = $this->getOptionalModuleVar('SHOW_BODY_THUMBNAIL', $this->showBodyThumbnail, $section, 'feeds');
             if (!($story = $feed->getItem($storyID))) {
                 throw new KurogoUserException($this->getLocalizedString('ERROR_STORY_NOT_FOUND', $storyID));
             }
             $this->setLogData($storyID, $story->getTitle());
             if (!($content = $this->cleanContent($story->getContent()))) {
                 if ($url = $story->getLink()) {
                     Kurogo::redirectToURL($url);
                 } else {
                     throw new KurogoDataException($this->getLocalizedString('ERROR_CONTENT_NOT_FOUND', $storyID));
                 }
             }
             if ($this->getOptionalModuleVar('SHARING_ENABLED', 1)) {
                 $body = Sanitizer::sanitizeAndTruncateHTML($story->getDescription(), $truncated, $this->getOptionalModuleVar('SHARE_EMAIL_DESC_MAX_LENGTH', 500), $this->getOptionalModuleVar('SHARE_EMAIL_DESC_MAX_LENGTH_MARGIN', 50), $this->getOptionalModuleVar('SHARE_EMAIL_DESC_MIN_LINE_LENGTH', 50), '') . "\n\n" . $story->getLink();
                 $shareEmailURL = $this->buildMailToLink("", $story->getTitle(), $body);
                 $this->assign('shareTitle', $this->getLocalizedString('SHARE_THIS_STORY'));
                 $this->assign('shareEmailURL', $shareEmailURL);
                 $this->assign('shareRemark', $story->getTitle());
                 $this->assign('storyURL', $story->getLink());
             }
             if ($pubDate = $story->getPubDate()) {
                 $date = DateFormatter::formatDate($pubDate, DateFormatter::MEDIUM_STYLE, DateFormatter::NO_STYLE);
             } else {
                 $date = "";
             }
             $this->enablePager($content, $this->newsFeed->getEncoding(), $storyPage);
             $this->assign('date', $date);
             $this->assign('title', $this->htmlEncodeFeedString($story->getTitle()));
             $this->assign('author', $this->htmlEncodeFeedString($story->getAuthor()));
             $this->assign('image', $this->getImageForStory($story));
             $this->assign('thumbnail', $this->getThumbnailForStory($story));
             $this->assign('showBodyThumbnail', $showBodyThumbnail);
             $this->assign('link', $story->getLink());
             $this->assign('showLink', $this->showLink);
             break;
         case 'search':
             $searchTerms = $this->getArg('filter');
             $start = $this->getArg('start', 0);
             $section = $this->getArg('section', 'topnews');
             if ($searchTerms) {
                 $newsFeed = $this->getNewsFeed($section);
                 $newsFeed->setStart($start);
                 $newsFeed->setLimit($this->maxPerPage);
                 $items = $newsFeed->search($searchTerms);
                 $this->setLogData($searchTerms);
                 $totalItems = $newsFeed->getTotalItems();
                 $stories = array();
                 $options = array('start' => $start, 'filter' => $searchTerms, 'section' => $section);
                 foreach ($items as $story) {
                     $stories[] = $this->linkForNewsItem($story, $options);
                 }
                 $previousURL = '';
                 $nextURL = '';
                 if ($totalItems > $this->maxPerPage) {
                     $args = $this->args;
                     if ($start > 0) {
                         $args['start'] = $start - $this->maxPerPage;
                         $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                     if ($totalItems - $start > $this->maxPerPage) {
                         $args['start'] = $start + $this->maxPerPage;
                         $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                 }
                 $extraArgs = array('section' => $section);
                 $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
                 $this->addOnLoad('setupNewsListing();');
                 $this->assign('maxPerPage', $this->maxPerPage);
                 $this->assign('extraArgs', $extraArgs);
                 $this->assign('searchTerms', $searchTerms);
                 $this->assign('stories', $stories);
                 $this->assign('previousURL', $previousURL);
                 $this->assign('nextURL', $nextURL);
                 $this->assign('showImages', $this->showImages);
                 $this->assign('showPubDate', $this->showPubDate);
                 $this->assign('showAuthor', $this->showAuthor);
             } else {
                 $this->redirectTo('index');
                 // search was blank
             }
             break;
         case 'schedule':
             $sport = $this->getArg('sport', '');
             $sportData = $this->getSportData($sport);
             if ($scheduleFeed = $this->getScheduleFeed($sport)) {
                 $scheduleItems = array();
                 $options = array('sport' => $sport);
                 if ($events = $scheduleFeed->items()) {
                     foreach ($events as $event) {
                         $scheduleItems[] = $this->linkForScheduleItem($event, $options);
                     }
                 }
                 $this->assign('scheduleItems', $scheduleItems);
             }
             break;
         case 'schedule_detail':
             $sport = $this->getArg('sport', '');
             if ($sport == '') {
                 $sport = 'allschedule';
             }
             $id = $this->getArg('id', '');
             // $sportData = $this->getSportData($sport);
             $scheduleFeed = $this->getScheduleFeed($sport);
             if ($schedule = $scheduleFeed->getItem($id)) {
                 $this->assign('schedule', $schedule);
             } else {
                 throw new KurogoDataException($this->getLocalizedString('ERROR_EVENT_NOT_FOUND'));
             }
             $this->setLogData($sport . ':' . $schedule->getID(), $schedule->getSport());
             $fields = $this->formatScheduleDetail($schedule);
             $schedule = $this->getFieldsForSchedule($schedule);
             $this->assign('schedule', $schedule);
             $this->assign('fields', $fields);
             break;
         case 'sport':
             $sport = $this->getArg('sport', '');
             $previous = array();
             $next = array();
             $sportData = $this->getSportData($sport);
             $this->assign('sportTitle', $sportData['GENDER_TITLE']);
             $this->setPageTitles($sportData['GENDER_TITLE']);
             if ($scheduleFeed = $this->getScheduleFeed($sport)) {
                 $scheduleItems = array();
                 if ($previousEvent = $scheduleFeed->getPreviousEvent()) {
                     $previous = $this->linkForScheduleItem($previousEvent, array('sport' => $sport));
                     $scheduleItems[] = $previous;
                 }
                 if ($nextEvent = $scheduleFeed->getNextEvent()) {
                     $next = $this->linkForScheduleItem($nextEvent, array('sport' => $sport));
                     $this->assign('next', $next);
                     $scheduleItems[] = $next;
                 }
                 $scheduleItems[] = array('title' => $this->getLocalizedString('FULL_SCHEDULE_TEXT'), 'url' => $this->buildBreadcrumbURL('schedule', array('sport' => $sport), true));
                 $this->assign('scheduleItems', $scheduleItems);
             }
             if ($newsFeed = $this->getNewsFeed($sport)) {
                 $start = $this->getArg('start', 0);
                 $newsFeed->setStart($start);
                 $newsFeed->setLimit($this->maxPerPage);
                 $items = $newsFeed->items();
                 $totalItems = $newsFeed->getTotalItems();
                 $this->setLogData($sport, $newsFeed->getTitle());
                 $previousURL = null;
                 $nextURL = null;
                 if ($totalItems > $this->maxPerPage) {
                     $args = $this->args;
                     if ($start > 0) {
                         $args['start'] = $start - $this->maxPerPage;
                         $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                     if ($totalItems - $start > $this->maxPerPage) {
                         $args['start'] = $start + $this->maxPerPage;
                         $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                 }
                 $options = array('section' => $sport);
                 $newsItems = array();
                 foreach ($items as $story) {
                     $newsItems[] = $this->linkForNewsItem($story, $options);
                 }
                 $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
                 $this->addOnLoad('setupNewsListing();');
                 $this->assign('newsItems', $newsItems);
                 $this->assign('maxPerPage', $this->maxPerPage);
                 $this->assign('previousURL', $previousURL);
                 $this->assign('nextURL', $nextURL);
                 $this->assign('showImages', $this->showImages);
                 $this->assign('showPubDate', $this->showPubDate);
                 $this->assign('showAuthor', $this->showAuthor);
             }
             // Bookmark
             if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 $cookieParams = array('sport' => $sport);
                 $cookieID = http_build_query($cookieParams);
                 $this->generateBookmarkOptions($cookieID);
             }
             break;
         case "index":
             $tabs = array();
             $latestSubTab = $this->getArg('newsTab', 'topnews');
             // used to distinguish between top news and schedule
             $latestSubTabLinks = array();
             // will add 'Latest' subTab items to this array
             //get top news
             if ($newsFeedData = $this->getNavData('topnews')) {
                 $start = $this->getArg('start', 0);
                 $newsFeed = $this->getNewsFeed('topnews');
                 $newsFeed->setStart($start);
                 $newsFeed->setLimit($this->maxPerPage);
                 $newsTab = array('id' => 'topnews', 'title' => $this->getLocalizedString('TOP_NEWS'), 'url' => $this->buildBreadcrumbURL('index', array('newsTab' => 'topnews'), false), 'ajaxUrl' => $this->buildAjaxBreadcrumbURL('index', array('newsTab' => 'topnews'), false));
                 $latestSubTabLinks[] = $newsTab;
                 $newsItems = $newsFeed->items();
                 $totalItems = $newsFeed->getTotalItems();
                 $this->setLogData('topnews', $newsFeed->getTitle());
                 $previousURL = null;
                 $nextURL = null;
                 if ($totalItems > $this->maxPerPage) {
                     //$args = $this->args;
                     $args = array();
                     if ($start > 0) {
                         $args['start'] = $start - $this->maxPerPage;
                         $previousURL = $this->buildURL('index', $args);
                     }
                     if ($totalItems - $start > $this->maxPerPage) {
                         $args['start'] = $start + $this->maxPerPage;
                         $nextURL = $this->buildURL('index', $args);
                     }
                 }
                 $topNews = array();
                 $options = array('section' => 'topnews');
                 foreach ($newsItems as $story) {
                     $topNews[] = $this->linkForNewsItem($story, $options);
                 }
                 $extraArgs = array('section' => 'topnews');
                 $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
                 $this->addOnLoad('setupNewsListing();');
                 // KurogoDebug::debug($newsFeedData['TITLE'], true);
                 $this->assign('topNewsTitle', $newsFeedData['TITLE']);
                 $this->assign('topNews', $topNews);
                 $this->assign('extraArgs', $extraArgs);
                 $this->assign('maxPerPage', $this->maxPerPage);
                 $this->assign('previousURL', $previousURL);
                 $this->assign('nextURL', $nextURL);
                 $this->assign('showImages', $this->showImages);
                 $this->assign('showPubDate', $this->showPubDate);
                 $this->assign('showAuthor', $this->showAuthor);
             }
             // get all sports schedule
             if ($scheduleFeedData = $this->getNavData('allschedule')) {
                 // KurogoDebug::debug($scheduleFeed, true);
                 $scheduleFeed = $this->getScheduleFeed('allschedule');
                 $athleticEvents = $scheduleFeed->items();
                 $scheduleItems = array();
                 foreach ($athleticEvents as $event) {
                     $scheduleItems[] = $this->linkForScheduleItem($event);
                 }
                 if ($limit = Kurogo::arrayVal($scheduleFeedData, 'LIMIT')) {
                     $scheduleItems = array_slice($scheduleItems, 0, $limit);
                 }
                 $scheduleTab = array('id' => 'allschedule', 'title' => $this->getLocalizedString('ALL_SCHEDULE'), 'url' => $this->buildBreadcrumbURL('index', array('newsTab' => 'allschedule'), false), 'ajaxUrl' => $this->buildAjaxBreadcrumbURL('index', array('newsTab' => 'allschedule'), false));
                 $latestSubTabLinks[] = $scheduleTab;
                 $this->assign('scheduleItems', $scheduleItems);
             }
             // make sure we are displaying tabs correctly
             if (count($latestSubTabLinks) > 0) {
                 // if we have topnews to show
                 $tabs[] = 'topnews';
                 if (count($latestSubTabLinks) == 1) {
                     $latestSubTab = $latestSubTabLinks[0]['id'];
                 }
             }
             $this->assign('latestSubTabLinks', $latestSubTabLinks);
             $this->assign('latestSubTab', $latestSubTab);
             //get sports for each gender
             foreach (array('men', 'women', 'coed') as $gender) {
                 $sportsData = $this->getNavData($gender);
                 if ($sportsData) {
                     if ($sportsConfig = $this->getSportsForGender($gender)) {
                         $sports = array();
                         foreach ($sportsConfig as $key => $sportData) {
                             $image = "modules/{$this->id}/images/" . (isset($sportData['ICON']) ? $sportData['ICON'] : strtolower($sportData['TITLE'])) . $this->imageExt;
                             $sport = array('title' => $sportData['TITLE'], 'img' => $image, 'url' => $this->buildURL('sport', array('sport' => $key)));
                             $sports[] = $sport;
                         }
                         $tabs[] = $gender;
                         $this->assign($gender . 'SportsTitle', $sportsData['TITLE']);
                         $this->assign($gender . 'Sports', $sports);
                     }
                 }
             }
             $bookmarkData = $this->getNavData('bookmarks');
             //get bookmarks
             $bookmarks = array();
             if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 $bookmarksData = $this->getBookmarks();
                 foreach ($bookmarksData as $bookmark) {
                     parse_str(stripslashes($bookmark), $params);
                     if (isset($params['sport']) && ($sportData = $this->getSportData($params['sport']))) {
                         $image = "modules/{$this->id}/images/" . (isset($sportData['ICON']) ? $sportData['ICON'] : strtolower($sportData['TITLE'])) . $this->imageExt;
                         $bookmarks[] = array('title' => $sportData['GENDER_TITLE'], 'img' => $image, 'url' => $this->buildURL('sport', array('sport' => $params['sport'])));
                     }
                 }
                 $tabs[] = 'bookmarks';
             }
             $this->assign('placeholder', $this->getLocalizedString('SEARCH_TEXT'));
             $this->assign('bookmarksTitle', $bookmarkData['TITLE']);
             $this->assign('bookmarks', $bookmarks);
             $this->assign('tabs', $tabs);
             $this->enableTabs($tabs);
             break;
         case 'pane':
             if ($this->ajaxContentLoad) {
                 $section = 'topnews';
                 $newsFeed = $this->getNewsFeed($section);
                 $newsFeed->setStart(0);
                 $newsFeed->setLimit($this->maxPerPane);
                 $items = $newsFeed->items();
                 $this->setLogData($section, $newsFeed->getTitle());
                 $stories = array();
                 $options = array('section' => $section, 'addBreadcrumb' => false);
                 foreach ($items as $story) {
                     $stories[] = $this->linkForItem($story, $options);
                 }
                 $this->assign('showImages', $this->showImages);
                 $this->assign('stories', $stories);
             }
             $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
             $this->addInternalJavascript('/common/javascript/lib/paneStories.js');
             break;
     }
 }
Пример #10
0
 public function __toString()
 {
     return DateFormatter::formatDateRange($this, DateFormatter::MEDIUM_STYLE, DateFormatter::NO_STYLE);
 }
Пример #11
0
 protected function timeText($photo, $timeOnly = false)
 {
     includePackage('Calendar');
     return DateFormatter::formatDate($photo->getPublished(), DateFormatter::SHORT_STYLE, DateFormatter::SHORT_STYLE);
 }
Пример #12
0
 /**
  * Fills in the {@link SiteGenerator} so it is ready to generate
  * code.
  *
  * @protected
  * @version 0.0.1
  * @since 0.0.1
  * @return SiteElement
  */
 function generateStat()
 {
     if (strtolower($this->siteGenerator->getParentClass()) != "sitegenerator") {
         /*It's not a SiteGenerator*/
         echo "<b>Error:</b> The class <code>HitsVotes</code> only acepts instances of <code>SiteGenerator</code>.<br>";
         exit;
     }
     //Get the locale object
     $dataSource =& $this->dataSource;
     $locale =& $this->locale;
     //Create the table
     $table =& $this->siteGenerator->newElement("table");
     $table->setHeadersAre(1);
     /*The top row is headers.*/
     $table->setHeaderClass('sinfo');
     //Create headline and description
     $headline =& $this->siteGenerator->newElement("headline");
     $headline->setSize(2);
     $headline->setHeadline($locale->getLocale('sgLatestStat'));
     $table->addHeadElement($headline);
     $desc =& $this->siteGenerator->newElement("text");
     $desc->setParagraph(1);
     $desc->setText($locale->getLocale('sgLatestDesc'));
     $table->addHeadElement($desc);
     $table->setElementName($this->getName());
     $table->setElementClass('stattabel');
     //Create the headlines for the columns
     //column, row
     $tableContent[0][0] = $locale->getLocale('sgLatestTime');
     $tableContent[0][1] = $locale->getLocale('sgLatestBrowser');
     $tableContent[0][2] = $locale->getLocale('sgLatestOs');
     $tableContent[0][3] = $locale->getLocale('sgLatestRes');
     $tableContent[0][4] = $locale->getLocale('sgLatestColours');
     $tableContent[0][5] = $locale->getLocale('sgLatestLang');
     $tableContent[0][6] = $locale->getLocale('sgLatestPage');
     $tableContent[0][7] = $locale->getLocale('sgLatestRefpage');
     $tableContent[0][8] = $locale->getLocale('sgLatestDomain');
     $tableContent[0][9] = $locale->getLocale('sgLatestIp');
     //Set the class name for the columns
     $columnClass = array_fill(0, sizeof($tableContent[0]), 'sinfo');
     /*		for ($i = 0; $i < sizeof($tableContent); $i++)
     			$columnClass[] = 'sinfo';
     */
     $table->setColumnClassArray($columnClass);
     //Fill in the data
     /*Line 28:
     			Each row separated by ::
     			Each pice of data separated by ;;
     			Order of pices:
     			0: Browser
     			1: Os
     			2: IP-adr
     			3: Domain
     			4: Time
     			5: Screen resolution
     			6: Screen color depth (in bits)
     			7: Language (iso code)
     			8: Url of page with hit
     			9: Referer url
     
     			Display in the order:
     			4, 0, 1, 2, 3, 5, 6, 7, 8, 9
     		*/
     $displayOrder = array(4, 0, 1, 5, 6, 7, 8, 9, 3, 2);
     $rows = $dataSource->getLineAsArray(28);
     $urlCutWrapper = new UrlCutWrapper($this->siteContext);
     $urlCutWrapper->setMaxLength(25);
     $urlCutWrapper->setCutProtocol(0);
     $urlCutWrapper->setCutWww(2);
     $urlCutWrapper->setCutSearch(2);
     $urlCutWrapper->setCutUrl(2);
     $text =& $this->siteGenerator->newElement("text");
     $text->setParagraph(0);
     /*Don't put the text in a paragraph*/
     $urlWrapper =& $this->siteGenerator->newElement("urlWrapper");
     $urlWrapper->setWrapped($urlCutWrapper);
     $urlCutWrapper->setWrapped($text);
     //Set up cutting and presentation of domain
     $domainCutWrapper = new CutWrapper($this->siteContext);
     $domainCutWrapper->setMaxLength(15);
     $domainText =& $this->siteGenerator->newElement("text");
     $domainText->setParagraph(0);
     $domainLabel =& $this->siteGenerator->newElement("text");
     $domainLabel->setParagraph(-1);
     $domainCutWrapper->setWrapped($domainText);
     $domainCutWrapper->setCutFrom(1);
     //Set up parser for converting dates
     $dateParser = new LegacyDateParser();
     $dateFormatter = new DateFormatter($locale->getLocale('dateShort'));
     $dateFormatter->setCurrentYear(date("Y"), $locale->getLocale('dateReallyShort'));
     $urlForViewing = $this->siteGenerator->isUrlsForViewing();
     $rows = array_reverse($rows);
     for ($i = 0; $i < sizeof($rows); $i++) {
         $column = explode(",,", $rows[$i]);
         //Handle non existing data
         if (!isset($column[0]) or $column[0] === "Andre browsere") {
             $column[0] = $locale->getLocale('sgLatestNA');
         }
         if (!$urlForViewing) {
             //For cutting
             $domainText->setText($column[3]);
             //For label
             $domainLabel->setLabel($column[3]);
             $domainLabel->setText($domainCutWrapper->getCode());
             $column[3] = $domainLabel->getCode();
         }
         $column[4] = $dateParser->parseToView($column[4], $dateFormatter);
         $column[1] = str_replace("Windows", "Win", $column[1]);
         if (!isset($column[1]) or $column[1] === "Andre styresystemer") {
             $column[1] = $locale->getLocale('sgLatestNA');
         }
         if (!isset($column[6]) or $column[6] === "Andre bit") {
             $column[6] = $locale->getLocale('sgLatestNA');
         }
         if (!isset($column[7]) or $column[7] === "Andet (Andre)") {
             $column[7] = $locale->getLocale('sgLatestNA');
         }
         if (isset($column[6]) and $column[6] !== "") {
             $column[6] .= " " . $locale->getLocale('sgLatestBit');
         }
         for ($m = 8; $m <= 9; $m++) {
             if (strlen($column[$m]) > 0) {
                 //Convert urls to links
                 if ($this->lib->okUrl($column[$m])) {
                     $text->setText($column[$m]);
                     $urlWrapper->setTitle($column[$m]);
                     if (!$urlForViewing) {
                         $url = "redir.php?url=" . urlencode($column[$m]);
                     } else {
                         $url = $column[$m];
                     }
                     $urlWrapper->setUrl($url);
                     $column[$m] = $urlWrapper->getCode();
                 }
             } else {
                 $column[$m] = $locale->getLocale('sgLatestNA');
             }
         }
         /*End for $m = 8*/
         //Translate the language, if known
         $languages = $locale->getLocale('languages');
         if (isset($languages[$column[7]]) and strlen($languages[$column[7]]) > 0) {
             $column[7] = $languages[$column[7]];
         } else {
             $column[7] = $locale->getLocale('sgLatestOthers') . " (" . $column[7] . ")";
         }
         //Map between place in data and display
         for ($j = 0; $j < sizeof($displayOrder); $j++) {
             $tableContent[$i + 1][$j] = $column[$displayOrder[$j]];
         }
     }
     /*End for $i*/
     $table->setTableContent($tableContent);
     return $table;
 }
Пример #13
0
 protected function initializeForPage()
 {
     if (!Kurogo::getOptionalSiteVar('STATS_ENABLED', true)) {
         throw new KurogoException($this->getLocalizedString('STATS_DISABLED'));
     }
     if ($this->page == 'updateStats') {
         KurogoStats::exportStatsData();
         $this->redirectTo('index');
     }
     if ($this->getOptionalModuleVar('AUTO_UPDATE_STATS')) {
         KurogoStats::exportStatsData();
     }
     $serviceTypes = $this->getServiceTypes();
     $service = $this->getArg('service', 'web');
     if (!array_key_exists($service, $serviceTypes)) {
         $service = 'web';
     }
     $interval_types = $this->getIntervalTypes();
     $interval = $this->getArg('interval', 'day');
     if (!array_key_exists($interval, $interval_types)) {
         $interval = 'day';
     }
     if ($interval == 'custom') {
         $start = $this->getArg('start');
         $startTime = $start ? mktime(0, 0, 0, $start['Month'], $start['Day'], $start['Year']) : mktime(0, 0, 0);
         $end = $this->getArg('end', array());
         $endTime = $end ? mktime(23, 59, 59, $end['Month'], $end['Day'], $end['Year']) : mktime(23, 59, 59);
         if ($endTime < $startTime) {
             $endTime = $startTime;
         }
     } else {
         $times = $this->getTimesForInterval($interval, $interval_types[$interval]['duration']);
         $startTime = $times['start'];
         $endTime = $times['end'];
     }
     $intervalOptions = array();
     $args = $this->args;
     $args['service'] = $service;
     $args['interval'] = $interval;
     foreach ($interval_types as $interval_type => $type) {
         $args['interval'] = $interval_type;
         $intervalOptions[$interval_type] = array('title' => $type['title'], 'selected' => $interval_type == $interval, 'url' => $this->buildbreadcrumbURL($this->page, $args, false));
     }
     $args = $this->args;
     $args['service'] = $service;
     $args['interval'] = $interval;
     foreach ($serviceTypes as $serviceType => $serviceTypeTitle) {
         $args['service'] = $serviceType;
         $serviceOptions[$serviceType] = array('title' => $serviceTypeTitle, 'selected' => $service == $serviceType, 'url' => $this->buildbreadcrumbURL($this->page, $args, false));
     }
     $this->assign('starttime', $startTime);
     $this->assign('endtime', $endTime);
     $this->assign('statsService', $service);
     $this->assign('interval', $interval);
     $this->assign('intervalOptions', $intervalOptions);
     $this->assign('serviceOptions', $serviceOptions);
     $this->assign('intervalTabclass', count($interval_types) == 4 ? 'fourtabs' : 'threetabs');
     $this->assign('serviceTabclass', 'twotabs');
     $commonData = array('service' => $service, 'start' => $startTime, 'end' => $endTime);
     if ($date = KurogoStats::getLastDateFromSummary()) {
         includePackage('DateTime');
         $date = new DateTime($date);
         $this->assign('lastUpdated', DateFormatter::formatDate($date, DateFormatter::LONG_STYLE, DateFormatter::NO_STYLE));
     }
     switch ($this->page) {
         case 'index':
             //get config
             $chartsConfig = $this->getModuleSections('stats-index');
             $charts = array();
             foreach ($chartsConfig as $chartIndex => $chartData) {
                 try {
                     $charts[] = $this->prepareChart(array_merge($chartData, $commonData), $interval);
                 } catch (KurogoStatsConfigurationException $e) {
                     $this->redirectTo('statsconfigerror', array('chart' => $chartData['title']));
                 }
             }
             $this->assign('charts', $charts);
             break;
         case 'detail':
             if (!($group = $this->getArg('group'))) {
                 $this->redirectTo('index');
             }
             if (!(${$group} = $this->getArg($group))) {
                 $this->redirectTo('index');
             }
             if (!($chartsConfig = $this->getChartsConfig($group, ${$group}))) {
                 $this->redirectTo('index');
             }
             $charts = array();
             $commonData[$group] = ${$group};
             foreach ($chartsConfig as $chartIndex => $chartData) {
                 try {
                     $charts[] = $this->prepareChart(array_merge($chartData, $commonData), $interval);
                 } catch (KurogoStatsConfigurationException $e) {
                     $this->redirectTo('statsconfigerror', array('chart' => $chartData['title']));
                 }
             }
             $this->setPageTitle(sprintf("Stats for %s", ${$group}));
             $this->assign('charts', $charts);
             break;
         case 'statsconfigerror':
             $this->assign('chart', $this->getArg('chart'));
             break;
     }
 }
Пример #14
0
/**
 * @todo document
 */
function wfMainDateReplace($matches)
{
    $df =& DateFormatter::getInstance();
    return $df->replace($matches);
}
Пример #15
0
 /**
  * Helper function for parse() that transforms wiki markup into
  * HTML. Only called for $mOutputType == OT_HTML.
  *
  * @private
  */
 function internalParse($text)
 {
     $args = array();
     $isMain = true;
     $fname = 'Parser::internalParse';
     wfProfileIn($fname);
     # Hook to suspend the parser in this state
     if (!wfRunHooks('ParserBeforeInternalParse', array(&$this, &$text, &$this->mStripState))) {
         wfProfileOut($fname);
         return $text;
     }
     # Remove <noinclude> tags and <includeonly> sections
     $text = strtr($text, array('<onlyinclude>' => '', '</onlyinclude>' => ''));
     $text = strtr($text, array('<noinclude>' => '', '</noinclude>' => ''));
     $text = StringUtils::delimiterReplace('<includeonly>', '</includeonly>', '', $text);
     $text = Sanitizer::removeHTMLtags($text, array(&$this, 'attributeStripCallback'), array(), array_keys($this->mTransparentTagHooks));
     $text = $this->replaceVariables($text, $args);
     wfRunHooks('InternalParseBeforeLinks', array(&$this, &$text, &$this->mStripState));
     // Tables need to come after variable replacement for things to work
     // properly; putting them before other transformations should keep
     // exciting things like link expansions from showing up in surprising
     // places.
     $text = $this->doTableStuff($text);
     $text = preg_replace('/(^|\\n)-----*/', '\\1<hr />', $text);
     $text = $this->stripToc($text);
     $this->stripNoGallery($text);
     $text = $this->doHeadings($text);
     if ($this->mOptions->getUseDynamicDates()) {
         $df =& DateFormatter::getInstance();
         $text = $df->reformat($this->mOptions->getDateFormat(), $text);
     }
     $text = $this->doAllQuotes($text);
     $text = $this->replaceInternalLinks($text);
     $text = $this->replaceExternalLinks($text);
     # replaceInternalLinks may sometimes leave behind
     # absolute URLs, which have to be masked to hide them from replaceExternalLinks
     $text = str_replace($this->mUniqPrefix . "NOPARSE", "", $text);
     $text = $this->doMagicLinks($text);
     $text = $this->formatHeadings($text, $isMain);
     wfProfileOut($fname);
     return $text;
 }
Пример #16
0
 public function formatDateUpdate()
 {
     return DateFormatter::format($this->date_update);
 }
 public function getScheduleLinks($timeRange, $data = null)
 {
     $events = $this->getEvents($timeRange);
     $scheduleLinks = array();
     foreach ($events as $event) {
         $subtitle = DateFormatter::formatDateRange($event, DateFormatter::NO_STYLE, DateFormatter::SHORT_STYLE);
         $options = array('id' => $this->getID(), 'time' => $event->get_start());
         if (isset($data['section'])) {
             $options['section'] = $data['section'];
         }
         if (isset($data['groupID'])) {
             $options['groupID'] = $data['groupID'];
         }
         $class = '';
         if ($data['showDetail']) {
             $url = $this->buildBreadcrumbURL('schedule', $options, true);
         } else {
             $url = false;
         }
         if ($event->contains(new TimeRange(time()))) {
             $class = 'open';
         } else {
             $class = 'closed';
         }
         $scheduleLinks[] = array('title' => $class, 'subtitle' => $subtitle, 'url' => $url, 'listclass' => $class);
     }
     return $scheduleLinks;
 }
Пример #18
0
 protected function initializeForPage()
 {
     switch ($this->page) {
         case 'news':
             $start = $this->getArg('start', 0);
             $section = $this->getArg('section');
             $newsFeed = $this->getNewsFeed($section);
             $newsFeed->setStart($start);
             $newsFeed->setLimit($this->maxPerPage);
             $items = $newsFeed->items();
             $totalItems = $newsFeed->getTotalItems();
             $this->setLogData($section, $newsFeed->getTitle());
             $previousURL = null;
             $nextURL = null;
             if ($totalItems > $this->maxPerPage) {
                 $args = $this->args;
                 if ($start > 0) {
                     $args['start'] = $start - $this->maxPerPage;
                     $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                 }
                 if ($totalItems - $start > $this->maxPerPage) {
                     $args['start'] = $start + $this->maxPerPage;
                     $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                 }
             }
             $options = array('section' => $section);
             $stories = array();
             foreach ($items as $story) {
                 $stories[] = $this->linkForNewsItem($story, $options);
             }
             $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
             $this->addOnLoad('setupNewsListing();');
             $this->assign('maxPerPage', $this->maxPerPage);
             $this->assign('stories', $stories);
             $this->assign('previousURL', $previousURL);
             $this->assign('nextURL', $nextURL);
             $this->assign('showImages', $this->showImages);
             $this->assign('showPubDate', $this->showPubDate);
             $this->assign('showAuthor', $this->showAuthor);
             break;
         case 'news_detail':
             $section = $this->getArg('section');
             $gender = $this->getArg('gender');
             $storyID = $this->getArg('storyID', false);
             $storyPage = $this->getArg('storyPage', '0');
             $feed = $this->getNewsFeed($section, $gender);
             if (!($story = $feed->getItem($storyID))) {
                 throw new KurogoUserException($this->getLocalizedString('ERROR_STORY_NOT_FOUND', $storyID));
             }
             $this->setLogData($storyID, $story->getTitle());
             if (!($content = $this->cleanContent($story->getContent()))) {
                 if ($url = $story->getLink()) {
                     Kurogo::redirectToURL($url);
                 } else {
                     throw new KurogoDataException($this->getLocalizedString('ERROR_CONTENT_NOT_FOUND', $storyID));
                 }
             }
             if ($this->getOptionalModuleVar('SHARING_ENABLED', 1)) {
                 $body = $story->getDescription() . "\n\n" . $story->getLink();
                 $shareEmailURL = $this->buildMailToLink("", $story->getTitle(), $body);
                 $this->assign('shareTitle', $this->getLocalizedString('SHARE_THIS_STORY'));
                 $this->assign('shareEmailURL', $shareEmailURL);
                 $this->assign('shareRemark', $story->getTitle());
                 $this->assign('storyURL', $story->getLink());
             }
             if ($pubDate = $story->getPubDate()) {
                 $date = DateFormatter::formatDate($pubDate, DateFormatter::MEDIUM_STYLE, DateFormatter::NO_STYLE);
             } else {
                 $date = "";
             }
             $this->enablePager($content, $this->newsFeed->getEncoding(), $storyPage);
             $this->assign('date', $date);
             $this->assign('title', $this->htmlEncodeFeedString($story->getTitle()));
             $this->assign('author', $this->htmlEncodeFeedString($story->getAuthor()));
             $this->assign('image', $this->getImageForStory($story));
             $this->assign('link', $story->getLink());
             $this->assign('showLink', $this->showLink);
             break;
         case 'search':
             $searchTerms = $this->getArg('filter');
             $start = $this->getArg('start', 0);
             $section = $this->getArg('section');
             if ($searchTerms) {
                 $newsFeed = $this->getNewsFeed($section);
                 $newsFeed->setStart($start);
                 $newsFeed->setLimit($this->maxPerPage);
                 $items = $newsFeed->search($searchTerms);
                 $this->setLogData($searchTerms);
                 $totalItems = $newsFeed->getTotalItems();
                 $stories = array();
                 $options = array('start' => $start, 'filter' => $searchTerms, 'section' => $section);
                 foreach ($items as $story) {
                     $stories[] = $this->linkForNewsItem($story, $options);
                 }
                 $previousURL = '';
                 $nextURL = '';
                 if ($totalItems > $this->maxPerPage) {
                     $args = $this->args;
                     if ($start > 0) {
                         $args['start'] = $start - $this->maxPerPage;
                         $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                     if ($totalItems - $start > $this->maxPerPage) {
                         $args['start'] = $start + $this->maxPerPage;
                         $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                 }
                 $extraArgs = array('section' => $section);
                 $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
                 $this->addOnLoad('setupNewsListing();');
                 $this->assign('maxPerPage', $this->maxPerPage);
                 $this->assign('extraArgs', $extraArgs);
                 $this->assign('searchTerms', $searchTerms);
                 $this->assign('stories', $stories);
                 $this->assign('previousURL', $previousURL);
                 $this->assign('nextURL', $nextURL);
                 $this->assign('showImages', $this->showImages);
                 $this->assign('showPubDate', $this->showPubDate);
                 $this->assign('showAuthor', $this->showAuthor);
             } else {
                 $this->redirectTo('index');
                 // search was blank
             }
             break;
         case 'schedule':
             $sport = $this->getArg('sport', '');
             $sportData = $this->getSportData($sport);
             if ($scheduleFeed = $this->getScheduleFeed($sport)) {
                 $scheduleItems = array();
                 $options = array('sport' => $sport);
                 if ($events = $scheduleFeed->items()) {
                     foreach ($events as $event) {
                         $scheduleItems[] = $this->linkForScheduleItem($event, $options);
                     }
                 }
                 $this->assign('scheduleItems', $scheduleItems);
             }
             break;
         case 'schedule_detail':
             $sport = $this->getArg('sport', '');
             $id = $this->getArg('id', '');
             $sportData = $this->getSportData($sport);
             $scheduleFeed = $this->getScheduleFeed($sport);
             if ($schedule = $scheduleFeed->getItem($id)) {
                 $this->assign('schedule', $schedule);
             } else {
                 throw new KurogoDataException($this->getLocalizedString('ERROR_EVENT_NOT_FOUND'));
             }
             $this->setLogData($sport . ':' . $schedule->getID(), $schedule->getSport());
             $fields = $this->formatScheduleDetail($schedule);
             $schedule = $this->getFieldsForSechedule($schedule);
             $this->assign('schedule', $schedule);
             $this->assign('fields', $fields);
             break;
         case 'sport':
             $sport = $this->getArg('sport', '');
             $previous = array();
             $next = array();
             $sportData = $this->getSportData($sport);
             $this->assign('sportTitle', $sportData['GENDER_TITLE']);
             $this->setPageTitles($sportData['GENDER_TITLE']);
             if ($scheduleFeed = $this->getScheduleFeed($sport)) {
                 $scheduleItems = array();
                 if ($previousEvent = $scheduleFeed->getPreviousEvent()) {
                     $previous = $this->linkForScheduleItem($previousEvent, array('sport' => $sport));
                     $scheduleItems[] = $previous;
                 }
                 if ($nextEvent = $scheduleFeed->getNextEvent()) {
                     $next = $this->linkForScheduleItem($nextEvent, array('sport' => $sport));
                     $this->assign('next', $next);
                     $scheduleItems[] = $next;
                 }
                 $scheduleItems[] = array('title' => $this->getLocalizedString('FULL_SCHEDULE_TEXT'), 'url' => $this->buildBreadcrumbURL('schedule', array('sport' => $sport), true));
                 $this->assign('scheduleItems', $scheduleItems);
             }
             if ($newsFeed = $this->getNewsFeed($sport)) {
                 $start = $this->getArg('start', 0);
                 $newsFeed->setStart($start);
                 $newsFeed->setLimit($this->maxPerPage);
                 $items = $newsFeed->items();
                 $totalItems = $newsFeed->getTotalItems();
                 $this->setLogData($sport, $newsFeed->getTitle());
                 $previousURL = null;
                 $nextURL = null;
                 if ($totalItems > $this->maxPerPage) {
                     $args = $this->args;
                     if ($start > 0) {
                         $args['start'] = $start - $this->maxPerPage;
                         $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                     if ($totalItems - $start > $this->maxPerPage) {
                         $args['start'] = $start + $this->maxPerPage;
                         $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                 }
                 $options = array('section' => $sport);
                 $newsItems = array();
                 foreach ($items as $story) {
                     $newsItems[] = $this->linkForNewsItem($story, $options);
                 }
                 $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
                 $this->addOnLoad('setupNewsListing();');
                 $this->assign('newsItems', $newsItems);
                 $this->assign('maxPerPage', $this->maxPerPage);
                 $this->assign('previousURL', $previousURL);
                 $this->assign('nextURL', $nextURL);
                 $this->assign('showImages', $this->showImages);
                 $this->assign('showPubDate', $this->showPubDate);
                 $this->assign('showAuthor', $this->showAuthor);
             }
             // Bookmark
             if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 $cookieParams = array('sport' => $sport);
                 $cookieID = http_build_query($cookieParams);
                 $this->generateBookmarkOptions($cookieID);
             }
             break;
         case "index":
             $tabs = array();
             //get top news
             if ($newsFeedData = $this->getNavData('topnews')) {
                 $start = $this->getArg('start', 0);
                 $newsFeed = $this->getNewsFeed('topnews');
                 $newsFeed->setStart($start);
                 $newsFeed->setLimit($this->maxPerPage);
                 $items = $newsFeed->items();
                 $totalItems = $newsFeed->getTotalItems();
                 $this->setLogData('topnews', $newsFeed->getTitle());
                 $previousURL = null;
                 $nextURL = null;
                 if ($totalItems > $this->maxPerPage) {
                     //$args = $this->args;
                     $args = array();
                     if ($start > 0) {
                         $args['start'] = $start - $this->maxPerPage;
                         $previousURL = $this->buildURL('index', $args);
                     }
                     if ($totalItems - $start > $this->maxPerPage) {
                         $args['start'] = $start + $this->maxPerPage;
                         $nextURL = $this->buildURL('index', $args);
                     }
                 }
                 $topNews = array();
                 $options = array('section' => 'topnews');
                 foreach ($items as $story) {
                     $topNews[] = $this->linkForNewsItem($story, $options);
                 }
                 $extraArgs = array('section' => 'topnews');
                 $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
                 $this->addOnLoad('setupNewsListing();');
                 $tabs[] = 'topnews';
                 $this->assign('topNewsTitle', $newsFeedData['TITLE']);
                 $this->assign('topNews', $topNews);
                 $this->assign('extraArgs', $extraArgs);
                 $this->assign('maxPerPage', $this->maxPerPage);
                 $this->assign('previousURL', $previousURL);
                 $this->assign('nextURL', $nextURL);
                 $this->assign('showImages', $this->showImages);
                 $this->assign('showPubDate', $this->showPubDate);
                 $this->assign('showAuthor', $this->showAuthor);
             }
             //get sports for each gender
             foreach (array('men', 'women', 'coed') as $gender) {
                 $sportsData = $this->getNavData($gender);
                 if ($sportsData) {
                     if ($sportsConfig = $this->getSportsForGender($gender)) {
                         $sports = array();
                         foreach ($sportsConfig as $key => $sportData) {
                             $image = "modules/{$this->configModule}/images/" . (isset($sportData['ICON']) ? $sportData['ICON'] : strtolower($sportData['TITLE'])) . $this->imageExt;
                             $sport = array('title' => $sportData['TITLE'], 'img' => $image, 'url' => $this->buildURL('sport', array('sport' => $key)));
                             $sports[] = $sport;
                         }
                         $tabs[] = $gender;
                         $this->assign($gender . 'SportsTitle', $sportsData['TITLE']);
                         $this->assign($gender . 'Sports', $sports);
                     }
                 }
             }
             $bookmarkData = $this->getNavData('bookmarks');
             //get bookmarks
             $bookmarks = array();
             if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 $bookmarksData = $this->getBookmarks();
                 foreach ($bookmarksData as $bookmark) {
                     parse_str(stripslashes($bookmark), $params);
                     if (isset($params['sport']) && ($sportData = $this->getSportData($params['sport']))) {
                         $bookmarks[] = array('title' => $sportData['GENDER_TITLE'], 'url' => $this->buildURL('sport', array('sport' => $params['sport'])));
                     }
                 }
                 $tabs[] = 'bookmarks';
             }
             $this->assign('placeholder', $this->getLocalizedString('SEARCH_TEXT'));
             $this->assign('bookmarksTitle', $bookmarkData['TITLE']);
             $this->assign('bookmarks', $bookmarks);
             $this->assign('tabs', $tabs);
             $this->enableTabs($tabs);
             break;
         case 'pane':
             if ($this->ajaxContentLoad) {
                 $section = 'topnews';
                 $newsFeed = $this->getNewsFeed($section);
                 $newsFeed->setStart(0);
                 $newsFeed->setLimit($this->maxPerPage);
                 $items = $newsFeed->items();
                 $this->setLogData($section, $newsFeed->getTitle());
                 $stories = array();
                 foreach ($items as $item) {
                     $stories[] = $this->linkForNewsItem($item, array('section' => $section));
                 }
                 $this->assign('stories', $stories);
             }
             $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
             $this->addInternalJavascript('/common/javascript/lib/paneStories.js');
             break;
     }
 }
Пример #19
0
    public function getFirstDate($return_mode = 'string') {
        if (!$dates = SeminarDB::getFirstDate($this->id)) {
            return false;
        }

        return DateFormatter::formatDateWithAllRooms(array('termin' => $dates), $return_mode);
    }
Пример #20
0
function renderDynamicPageList($input, $args, $mwParser)
{
    global $wgUser, $wgContLang;
    global $wgDisableCounters;
    // to determine if to allow sorting by #hits.
    global $wgDLPmaxCategories, $wgDLPMaxResultCount, $wgDLPMaxCacheTime;
    global $wgDLPAllowUnlimitedResults, $wgDLPAllowUnlimitedCategories;
    if ($wgDLPMaxCacheTime !== false) {
        $mwParser->getOutput()->updateCacheExpiry($wgDLPMaxCacheTime);
    }
    $countSet = false;
    $startList = '<ul>';
    $endList = '</ul>';
    $startItem = '<li>';
    $endItem = '</li>';
    $inlineMode = false;
    $useGallery = false;
    $galleryFileSize = false;
    $galleryFileName = true;
    $galleryImageHeight = 0;
    $galleryImageWidth = 0;
    $galleryNumbRows = 0;
    $galleryCaption = '';
    $gallery = null;
    $orderMethod = 'categoryadd';
    $order = 'descending';
    $redirects = 'exclude';
    $stable = $quality = 'include';
    $flaggedRevs = false;
    $namespaceFiltering = false;
    $namespaceIndex = 0;
    $offset = 0;
    $googleHack = false;
    $suppressErrors = false;
    $showNamespace = true;
    $addFirstCategoryDate = false;
    $dateFormat = '';
    $stripYear = false;
    $linkOptions = array();
    $categories = array();
    $excludeCategories = array();
    $parameters = explode("\n", $input);
    $parser = new Parser();
    $poptions = new ParserOptions();
    foreach ($parameters as $parameter) {
        $paramField = explode('=', $parameter, 2);
        if (count($paramField) < 2) {
            continue;
        }
        $type = trim($paramField[0]);
        $arg = trim($paramField[1]);
        switch ($type) {
            case 'category':
                $title = Title::makeTitleSafe(NS_CATEGORY, $parser->transformMsg($arg, $poptions));
                if (is_null($title)) {
                    continue;
                }
                $categories[] = $title;
                break;
            case 'notcategory':
                $title = Title::makeTitleSafe(NS_CATEGORY, $parser->transformMsg($arg, $poptions));
                if (is_null($title)) {
                    continue;
                }
                $excludeCategories[] = $title;
                break;
            case 'namespace':
                $ns = $wgContLang->getNsIndex($arg);
                if ($ns != null) {
                    $namespaceIndex = $ns;
                    $namespaceFiltering = true;
                } else {
                    // Note, since intval("some string") = 0
                    // this considers pretty much anything
                    // invalid here as the main namespace.
                    // This was probably originally a bug,
                    // but is now depended upon by people
                    // writing things like namespace=main
                    // so be careful when changing this code.
                    $namespaceIndex = intval($arg);
                    if ($namespaceIndex >= 0) {
                        $namespaceFiltering = true;
                    } else {
                        $namespaceFiltering = false;
                    }
                }
                break;
            case 'count':
                // ensure that $count is a number;
                $count = intval($arg);
                $countSet = true;
                break;
            case 'offset':
                $offset = intval($arg);
                break;
            case 'imagewidth':
                $galleryImageWidth = intval($arg);
                break;
            case 'imageheight':
                $galleryImageHeight = intval($arg);
                break;
            case 'imagesperrow':
                $galleryNumbRows = intval($arg);
                break;
            case 'mode':
                switch ($arg) {
                    case 'gallery':
                        $useGallery = true;
                        $gallery = new ImageGallery();
                        $startList = '';
                        $endList = '';
                        $startItem = '';
                        $endItem = '';
                        break;
                    case 'none':
                        $startList = '';
                        $endList = '';
                        $startItem = '';
                        $endItem = '<br />';
                        $inlineMode = false;
                        break;
                    case 'ordered':
                        $startList = '<ol>';
                        $endList = '</ol>';
                        $startItem = '<li>';
                        $endItem = '</li>';
                        $inlineMode = false;
                        break;
                    case 'inline':
                        // aka comma seperated list
                        $startList = '';
                        $endList = '';
                        $startItem = '';
                        $endItem = '';
                        $inlineMode = true;
                        break;
                    case 'unordered':
                    default:
                        $startList = '<ul>';
                        $endList = '</ul>';
                        $startItem = '<li>';
                        $endItem = '</li>';
                        $inlineMode = false;
                        break;
                }
                break;
            case 'gallerycaption':
                // Should perhaps actually parse caption instead
                // as links and what not in caption might be useful.
                $galleryCaption = $parser->transformMsg($arg, $poptions);
                break;
            case 'galleryshowfilesize':
                switch ($arg) {
                    case 'no':
                    case 'false':
                        $galleryFileSize = false;
                        break;
                    case 'true':
                    default:
                        $galleryFileSize = true;
                }
                break;
            case 'galleryshowfilename':
                switch ($arg) {
                    case 'no':
                    case 'false':
                        $galleryFileName = false;
                        break;
                    case 'true':
                    default:
                        $galleryFileName = true;
                        break;
                }
                break;
            case 'order':
                switch ($arg) {
                    case 'ascending':
                        $order = 'ascending';
                        break;
                    case 'descending':
                    default:
                        $order = 'descending';
                        break;
                }
                break;
            case 'ordermethod':
                switch ($arg) {
                    case 'lastedit':
                        $orderMethod = 'lastedit';
                        break;
                    case 'length':
                        $orderMethod = 'length';
                        break;
                    case 'created':
                        $orderMethod = 'created';
                        break;
                    case 'sortkey':
                    case 'categorysortkey':
                        $orderMethod = 'categorysortkey';
                        break;
                    case 'popularity':
                        if (!$wgDisableCounters) {
                            $orderMethod = 'popularity';
                        } else {
                            $orderMethod = 'categoyadd';
                            // default if hitcounter disabled.
                        }
                        break;
                    case 'categoryadd':
                    default:
                        $orderMethod = 'categoryadd';
                        break;
                }
                break;
            case 'redirects':
                switch ($arg) {
                    case 'include':
                        $redirects = 'include';
                        break;
                    case 'only':
                        $redirects = 'only';
                        break;
                    case 'exclude':
                    default:
                        $redirects = 'exclude';
                        break;
                }
                break;
            case 'stablepages':
                switch ($arg) {
                    case 'include':
                        $stable = 'include';
                        break;
                    case 'only':
                        $flaggedRevs = true;
                        $stable = 'only';
                        break;
                    case 'exclude':
                    default:
                        $flaggedRevs = true;
                        $stable = 'exclude';
                        break;
                }
                break;
            case 'qualitypages':
                switch ($arg) {
                    case 'include':
                        $quality = 'include';
                        break;
                    case 'only':
                        $flaggedRevs = true;
                        $quality = 'only';
                        break;
                    case 'exclude':
                    default:
                        $flaggedRevs = true;
                        $quality = 'exclude';
                        break;
                }
                break;
            case 'suppresserrors':
                if ($arg == 'true') {
                    $suppressErrors = true;
                } else {
                    $suppressErrors = false;
                }
                break;
            case 'addfirstcategorydate':
                if ($arg == 'true') {
                    $addFirstCategoryDate = true;
                } elseif (preg_match('/^(?:[ymd]{2,3}|ISO 8601)$/', $arg)) {
                    // if it more or less is valid dateformat.
                    $addFirstCategoryDate = true;
                    $dateFormat = $arg;
                    if (strlen($dateFormat) == 2) {
                        $dateFormat = $dateFormat . 'y';
                        # DateFormatter does not support no year. work around
                        $stripYear = true;
                    }
                } else {
                    $addFirstCategoryDate = false;
                }
                break;
            case 'shownamespace':
                if ('false' == $arg) {
                    $showNamespace = false;
                } else {
                    $showNamespace = true;
                }
                break;
            case 'googlehack':
                if ('false' == $arg) {
                    $googleHack = false;
                } else {
                    $googleHack = true;
                }
                break;
            case 'nofollow':
                # bug 6658
                if ('false' != $arg) {
                    $linkOptions['rel'] = 'nofollow';
                }
                break;
        }
        // end main switch()
    }
    // end foreach()
    $catCount = count($categories);
    $excludeCatCount = count($excludeCategories);
    $totalCatCount = $catCount + $excludeCatCount;
    if ($catCount < 1 && false == $namespaceFiltering) {
        if ($suppressErrors == false) {
            return htmlspecialchars(wfMsgForContent('intersection_noincludecats'));
            // "!!no included categories!!";
        } else {
            return '';
        }
    }
    if ($totalCatCount > $wgDLPmaxCategories && !$wgDLPAllowUnlimitedCategories) {
        if ($suppressErrors == false) {
            return htmlspecialchars(wfMsgForContent('intersection_toomanycats'));
            // "!!too many categories!!";
        } else {
            return '';
        }
    }
    if ($countSet) {
        if ($count < 1) {
            $count = 1;
        }
        if ($count > $wgDLPMaxResultCount) {
            $count = $wgDLPMaxResultCount;
        }
    } elseif (!$wgDLPAllowUnlimitedResults) {
        $count = $wgDLPMaxResultCount;
        $countSet = true;
    }
    // disallow showing date if the query doesn't have an inclusion category parameter
    if ($catCount < 1) {
        $addFirstCategoryDate = false;
        // don't sort by fields relating to categories if there are no categories.
        if ($orderMethod == 'categoryadd' || $orderMethod == 'categorysortkey') {
            $orderMethod = 'created';
        }
    }
    // build the SQL query
    $dbr = wfGetDB(DB_SLAVE);
    $tables = array('page');
    $fields = array('page_namespace', 'page_title');
    $where = array();
    $join = array();
    $options = array();
    if ($googleHack) {
        $fields[] = 'page_id';
    }
    if ($addFirstCategoryDate) {
        $fields[] = 'c1.cl_timestamp';
    }
    if ($namespaceFiltering == true) {
        $where['page_namespace'] = $namespaceIndex;
    }
    // Bug 14943 - Allow filtering based on FlaggedRevs stability.
    // Check if the extension actually exists before changing the query...
    if ($flaggedRevs && defined('FLAGGED_REVISIONS')) {
        $tables[] = 'flaggedpages';
        $join['flaggedpages'] = array('LEFT JOIN', 'page_id = fp_page_id');
        switch ($stable) {
            case 'only':
                $where[] = 'fp_stable IS NOT NULL';
                break;
            case 'exclude':
                $where['fp_stable'] = null;
                break;
        }
        switch ($quality) {
            case 'only':
                $where[] = 'fp_quality >= 1';
                break;
            case 'exclude':
                $where[] = 'fp_quality = 0 OR fp_quality IS NULL';
                break;
        }
    }
    switch ($redirects) {
        case 'only':
            $where['page_is_redirect'] = 1;
            break;
        case 'exclude':
            $where['page_is_redirect'] = 0;
            break;
    }
    $currentTableNumber = 1;
    $categorylinks = $dbr->tableName('categorylinks');
    for ($i = 0; $i < $catCount; $i++) {
        $join["{$categorylinks} AS c{$currentTableNumber}"] = array('INNER JOIN', array("page_id = c{$currentTableNumber}.cl_from", "c{$currentTableNumber}.cl_to={$dbr->addQuotes($categories[$i]->getDBKey())}"));
        $tables[] = "{$categorylinks} AS c{$currentTableNumber}";
        $currentTableNumber++;
    }
    for ($i = 0; $i < $excludeCatCount; $i++) {
        $join["{$categorylinks} AS c{$currentTableNumber}"] = array('LEFT OUTER JOIN', array("page_id = c{$currentTableNumber}.cl_from", "c{$currentTableNumber}.cl_to={$dbr->addQuotes($excludeCategories[$i]->getDBKey())}"));
        $tables[] = "{$categorylinks} AS c{$currentTableNumber}";
        $where["c{$currentTableNumber}.cl_to"] = null;
        $currentTableNumber++;
    }
    if ('descending' == $order) {
        $sqlOrder = 'DESC';
    } else {
        $sqlOrder = 'ASC';
    }
    switch ($orderMethod) {
        case 'lastedit':
            $sqlSort = 'page_touched';
            break;
        case 'length':
            $sqlSort = 'page_len';
            break;
        case 'created':
            $sqlSort = 'page_id';
            # Since they're never reused and increasing
            break;
        case 'categorysortkey':
            $sqlSort = "c1.cl_type {$sqlOrder}, c1.cl_sortkey";
            break;
        case 'popularity':
            $sqlSort = 'page_counter';
            break;
        case 'categoryadd':
        default:
            $sqlSort = 'c1.cl_timestamp';
            break;
    }
    $options['ORDER BY'] = "{$sqlSort} {$sqlOrder}";
    if ($countSet) {
        $options['LIMIT'] = $count;
    }
    if ($offset > 0) {
        $options['OFFSET'] = $offset;
    }
    // process the query
    $res = $dbr->select($tables, $fields, $where, __METHOD__, $options, $join);
    $sk = $wgUser->getSkin();
    if ($dbr->numRows($res) == 0) {
        if ($suppressErrors == false) {
            return htmlspecialchars(wfMsgForContent('intersection_noresults'));
        } else {
            return '';
        }
    }
    // start unordered list
    $output = $startList . "\n";
    $categoryDate = '';
    $df = null;
    if ($dateFormat != '' && $addFirstCategoryDate) {
        $df = DateFormatter::getInstance();
    }
    // process results of query, outputing equivalent of <li>[[Article]]</li>
    // for each result, or something similar if the list uses other
    // startlist/endlist
    $articleList = array();
    foreach ($res as $row) {
        $title = Title::makeTitle($row->page_namespace, $row->page_title);
        if (true == $addFirstCategoryDate) {
            if ($dateFormat != '') {
                # this is a tad ugly
                # use DateFormatter, and support disgarding year.
                $categoryDate = wfTimestamp(TS_ISO_8601, $row->cl_timestamp);
                if ($stripYear) {
                    $categoryDate = $wgContLang->getMonthName(substr($categoryDate, 5, 2)) . ' ' . substr($categoryDate, 8, 2);
                } else {
                    $categoryDate = substr($categoryDate, 0, 10);
                }
                $categoryDate = $df->reformat($dateFormat, $categoryDate, array('match-whole'));
            } else {
                $categoryDate = $wgContLang->date(wfTimestamp(TS_MW, $row->cl_timestamp));
            }
            if (!$useGallery) {
                $categoryDate .= wfMsgForContent('colon-separator');
            } else {
                $categoryDate .= ' ';
            }
        }
        $query = array();
        if ($googleHack == true) {
            $query['dpl_id'] = intval($row->page_id);
        }
        if ($showNamespace == true) {
            $titleText = $title->getPrefixedText();
        } else {
            $titleText = $title->getText();
        }
        if ($useGallery) {
            # Note, $categoryDate is treated as raw html
            # this is safe since the only html present
            # would come from the dateformatter <span>.
            $gallery->add($title, $categoryDate);
        } else {
            $articleList[] = $categoryDate . $sk->link($title, htmlspecialchars($titleText), $linkOptions, $query, array('forcearticlepath', 'known'));
        }
    }
    // end unordered list
    if ($useGallery) {
        $gallery->setHideBadImages();
        $gallery->setShowFilename($galleryFileName);
        $gallery->setShowBytes($galleryFileSize);
        if ($galleryImageHeight > 0) {
            $gallery->setHeights($galleryImageHeight);
        }
        if ($galleryImageWidth > 0) {
            $gallery->setWidths($galleryImageWidth);
        }
        if ($galleryNumbRows > 0) {
            $gallery->setPerRow($galleryNumbRows);
        }
        if ($galleryCaption != '') {
            $gallery->setCaption($galleryCaption);
            # gallery class escapes string
        }
        $output = $gallery->toHtml();
    } else {
        $output .= $startItem;
        if ($inlineMode) {
            $output .= $wgContLang->commaList($articleList);
        } else {
            $output .= implode("{$endItem} \n{$startItem}", $articleList);
        }
        $output .= $endItem;
        $output .= $endList . "\n";
    }
    return $output;
}
Пример #21
0
 /**
  * Formats a series of SingleDate objects into a nice format. The dates parameter is an array of dates.
  * The array has to have the key 'termin' with an array of SingleDate objects as value.
  * @static
  * @param  $dates an array with an array of SingleDate objects
  * @param string $return_mode expected values are 'int', 'string' and 'export'. The default value is 'string'.
  * @return string
  */
 public static function formatDateWithAllRooms($dates, $return_mode = 'string')
 {
     $dateFormatter = new DateFormatter($dates, $return_mode);
     return $dateFormatter->internalFormatDateWithAllRooms();
 }
Пример #22
0
 /**
  * Helper function for parse() that transforms wiki markup into
  * HTML. Only called for $mOutputType == self::OT_HTML.
  *
  * @private
  *
  * @param $text string
  * @param $isMain bool
  * @param $frame bool
  *
  * @return string
  */
 function internalParse($text, $isMain = true, $frame = false)
 {
     wfProfileIn(__METHOD__);
     $origText = $text;
     # Hook to suspend the parser in this state
     if (!wfRunHooks('ParserBeforeInternalParse', array(&$this, &$text, &$this->mStripState))) {
         wfProfileOut(__METHOD__);
         return $text;
     }
     # if $frame is provided, then use $frame for replacing any variables
     if ($frame) {
         # use frame depth to infer how include/noinclude tags should be handled
         # depth=0 means this is the top-level document; otherwise it's an included document
         if (!$frame->depth) {
             $flag = 0;
         } else {
             $flag = Parser::PTD_FOR_INCLUSION;
         }
         $dom = $this->preprocessToDom($text, $flag);
         $text = $frame->expand($dom);
     } else {
         # if $frame is not provided, then use old-style replaceVariables
         $text = $this->replaceVariables($text);
     }
     wfRunHooks('InternalParseBeforeSanitize', array(&$this, &$text, &$this->mStripState));
     $text = Sanitizer::removeHTMLtags($text, array(&$this, 'attributeStripCallback'), false, array_keys($this->mTransparentTagHooks));
     wfRunHooks('InternalParseBeforeLinks', array(&$this, &$text, &$this->mStripState));
     # Tables need to come after variable replacement for things to work
     # properly; putting them before other transformations should keep
     # exciting things like link expansions from showing up in surprising
     # places.
     $text = $this->doTableStuff($text);
     $text = preg_replace('/(^|\\n)-----*/', '\\1<hr />', $text);
     $text = $this->doDoubleUnderscore($text);
     $text = $this->doHeadings($text);
     if ($this->mOptions->getUseDynamicDates()) {
         $df = DateFormatter::getInstance();
         $text = $df->reformat($this->mOptions->getDateFormat(), $text);
     }
     $text = $this->replaceInternalLinks($text);
     $text = $this->doAllQuotes($text);
     $text = $this->replaceExternalLinks($text);
     # replaceInternalLinks may sometimes leave behind
     # absolute URLs, which have to be masked to hide them from replaceExternalLinks
     $text = str_replace($this->mUniqPrefix . 'NOPARSE', '', $text);
     $text = $this->doMagicLinks($text);
     $text = $this->formatHeadings($text, $origText, $isMain);
     wfProfileOut(__METHOD__);
     return $text;
 }
Пример #23
0
 protected function initializeForPage()
 {
     if (!$this->feed) {
         throw new KurogoConfigurationException($this->getLocalizedString('ERROR_NOT_CONFIGURED'));
     }
     switch ($this->page) {
         case 'story':
             $searchTerms = $this->getArg('filter', false);
             if ($searchTerms) {
                 $this->feed->setOption('search', $searchTerms);
             }
             $storyID = $this->getArg('storyID', false);
             $storyPage = $this->getArg('storyPage', '0');
             $story = $this->feed->getItem($storyID);
             if (!$story) {
                 throw new KurogoUserException($this->getLocalizedString('ERROR_STORY_NOT_FOUND', $storyID));
             }
             $this->setLogData($storyID, $story->getTitle());
             if (!($content = $this->cleanContent($story->getContent()))) {
                 if ($url = $story->getLink()) {
                     Kurogo::redirectToURL($url);
                 }
                 // no content or link. Attempt to get description
                 if (!($content = $story->getDescription())) {
                     throw new KurogoDataException($this->getLocalizedString('ERROR_CONTENT_NOT_FOUND', $storyID));
                 }
             }
             if ($this->getOptionalModuleVar('SHARING_ENABLED', 1)) {
                 $body = $story->getDescription() . "\n\n" . $story->getLink();
                 $shareEmailURL = $this->buildMailToLink("", $story->getTitle(), $body);
                 $this->assign('shareTitle', $this->getLocalizedString('SHARE_THIS_STORY'));
                 $this->assign('shareEmailURL', $shareEmailURL);
                 $this->assign('shareRemark', $story->getTitle());
                 $this->assign('storyURL', $story->getLink());
             }
             if ($pubDate = $story->getPubDate()) {
                 $date = DateFormatter::formatDate($pubDate, DateFormatter::LONG_STYLE, DateFormatter::NO_STYLE);
             } else {
                 $date = "";
             }
             $this->enablePager($content, $this->feed->getEncoding(), $storyPage);
             $this->assign('date', $date);
             $this->assign('title', $this->htmlEncodeFeedString($story->getTitle()));
             $this->assign('author', $this->htmlEncodeFeedString($story->getAuthor()));
             $this->assign('image', $this->getImageForStory($story));
             $this->assign('link', $story->getLink());
             $this->assign('ajax', $this->getArg('ajax'));
             $this->assign('showLink', $this->showLink);
             $this->assign('showBodyThumbnail', $this->showBodyThumbnail);
             break;
         case 'search':
             $searchTerms = $this->getArg('filter');
             $start = $this->getArg('start', 0);
             if ($searchTerms) {
                 $options = array('start' => $start);
                 $items = $this->searchItems($searchTerms, $this->maxPerPage, $options);
                 $this->setLogData($searchTerms);
                 $totalItems = $this->feed->getTotalItems();
                 $stories = array();
                 $options = array('filter' => $searchTerms, 'section' => $this->feedIndex);
                 foreach ($items as $story) {
                     $stories[] = $this->linkForItem($story, $options);
                 }
                 $previousURL = '';
                 $nextURL = '';
                 if ($totalItems > $this->maxPerPage) {
                     $args = $this->args;
                     if ($start > 0) {
                         $args['start'] = $start - $this->maxPerPage;
                         $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                     if ($totalItems - $start > $this->maxPerPage) {
                         $args['start'] = $start + $this->maxPerPage;
                         $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                     }
                 }
                 $extraArgs = array('section' => $this->feedIndex);
                 $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
                 $this->addOnLoad('setupNewsListing();');
                 $this->assign('maxPerPage', $this->maxPerPage);
                 $this->assign('extraArgs', $extraArgs);
                 $this->assign('searchTerms', $searchTerms);
                 $this->assign('stories', $stories);
                 $this->assign('previousURL', $previousURL);
                 $this->assign('nextURL', $nextURL);
                 $this->assign('showImages', $this->showImages);
                 $this->assign('showPubDate', $this->showPubDate);
                 $this->assign('showAuthor', $this->showAuthor);
             } else {
                 $this->redirectTo('index');
                 // search was blank
             }
             break;
         case 'pane':
             if ($this->ajaxContentLoad) {
                 $start = 0;
                 if ($this->legacyController) {
                     $items = $this->feed->items($start, $this->maxPerPane);
                 } else {
                     $this->feed->setStart(0);
                     $this->feed->setLimit($this->maxPerPane);
                     $items = $this->feed->items();
                 }
                 $stories = array();
                 $options = array('noBreadcrumbs' => true, 'section' => $this->feedIndex);
                 foreach ($items as $story) {
                     $stories[] = $this->linkForItem($story, $options);
                 }
                 foreach ($stories as $i => $story) {
                     $stories[$i]['url'] = $this->buildURL('index') . '#' . urlencode(FULL_URL_PREFIX . ltrim($story['url'], '/'));
                 }
                 $this->assign('stories', $stories);
             }
             $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
             $this->addInternalJavascript('/common/javascript/lib/paneStories.js');
             break;
         case 'index':
             $start = $this->getArg('start', 0);
             if ($this->legacyController) {
                 $items = $this->feed->items($start, $this->maxPerPage);
             } else {
                 $this->feed->setStart($start);
                 $this->feed->setLimit($this->maxPerPage);
                 $items = $this->feed->items();
             }
             $totalItems = $this->feed->getTotalItems();
             $this->setLogData($this->feedIndex, $this->feed->getTitle());
             $previousURL = null;
             $nextURL = null;
             if ($totalItems > $this->maxPerPage) {
                 $args = $this->args;
                 if ($start > 0) {
                     $args['start'] = $start - $this->maxPerPage;
                     $previousURL = $this->buildBreadcrumbURL($this->page, $args, false);
                 }
                 if ($totalItems - $start > $this->maxPerPage) {
                     $args['start'] = $start + $this->maxPerPage;
                     $nextURL = $this->buildBreadcrumbURL($this->page, $args, false);
                 }
             }
             $options = array('section' => $this->feedIndex);
             $stories = array();
             foreach ($items as $story) {
                 $stories[] = $this->linkForItem($story, $options);
             }
             $sections = array();
             foreach ($this->feeds as $index => $feedData) {
                 $sections[] = array('value' => $index, 'title' => $feedData['TITLE'], 'selected' => $this->feedIndex == $index, 'url' => $this->feedURL($index, false));
             }
             $hiddenArgs = array('section' => $this->feedIndex);
             $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
             $this->addOnLoad('setupNewsListing();');
             $this->assign('maxPerPage', $this->maxPerPage);
             $this->assign('hiddenArgs', $hiddenArgs);
             $this->assign('sections', $sections);
             $this->assign('currentSection', $sections[$this->feedIndex]);
             $this->assign('placeholder', $this->getLocalizedString('SEARCH_MODULE', $this->getModuleName()));
             $this->assign('stories', $stories);
             $this->assign('isHome', true);
             $this->assign('previousURL', $previousURL);
             $this->assign('nextURL', $nextURL);
             $this->assign('showImages', $this->showImages);
             $this->assign('showPubDate', $this->showPubDate);
             $this->assign('showAuthor', $this->showAuthor);
             break;
     }
 }
Пример #24
0
 /**
  * Helper function for parse() that transforms wiki markup into
  * HTML. Only called for $mOutputType == self::OT_HTML.
  *
  * @private
  */
 function internalParse($text)
 {
     $isMain = true;
     wfProfileIn(__METHOD__);
     # Hook to suspend the parser in this state
     if (!wfRunHooks('ParserBeforeInternalParse', array(&$this, &$text, &$this->mStripState))) {
         wfProfileOut(__METHOD__);
         return $text;
     }
     $text = $this->replaceVariables($text);
     $text = Sanitizer::removeHTMLtags($text, array(&$this, 'attributeStripCallback'), false, array_keys($this->mTransparentTagHooks));
     wfRunHooks('InternalParseBeforeLinks', array(&$this, &$text, &$this->mStripState));
     // Tables need to come after variable replacement for things to work
     // properly; putting them before other transformations should keep
     // exciting things like link expansions from showing up in surprising
     // places.
     $text = $this->doTableStuff($text);
     $text = preg_replace('/(^|\\n)-----*/', '\\1<hr />', $text);
     $text = $this->doDoubleUnderscore($text);
     $text = $this->doHeadings($text);
     if ($this->mOptions->getUseDynamicDates()) {
         $df = DateFormatter::getInstance();
         $text = $df->reformat($this->mOptions->getDateFormat(), $text);
     }
     $text = $this->doAllQuotes($text);
     $text = $this->replaceInternalLinks($text);
     $text = $this->replaceExternalLinks($text);
     # replaceInternalLinks may sometimes leave behind
     # absolute URLs, which have to be masked to hide them from replaceExternalLinks
     $text = str_replace($this->mUniqPrefix . 'NOPARSE', '', $text);
     $text = $this->doMagicLinks($text);
     $text = $this->formatHeadings($text, $isMain);
     wfProfileOut(__METHOD__);
     return $text;
 }
Пример #25
0
 protected function elapsedTime($timestamp)
 {
     $now = time();
     $diff = $now - $timestamp;
     $today = mktime(0, 0, 0);
     $today_timestamp = mktime(0, 0, 0, date('m', $timestamp), date('d', $timestamp), date('Y', $timestamp));
     $date = new DateTime("@" . $timestamp);
     Kurogo::includePackage('DateTime');
     if ($diff > 0) {
         // more than 6 days
         if ($today - $today_timestamp > 518400) {
             return DateFormatter::formatDate($date, DateFormatter::MEDIUM_STYLE, DateFormatter::NO_STYLE);
         } elseif ($today - $today_timestamp > 86400) {
             // up to 6 days
             // @TODO localize
             return sprintf("%d days ago", $diff / 86400);
         } elseif ($today - $today_timestamp > 0) {
             // yesterday
             // @TODO localize
             return strftime('Yesterday @ %l:%M %p', $timestamp);
         } elseif ($diff > 3600) {
             // @TODO localize
             return sprintf("%d hour%s ago", $diff / 3600, intval($diff / 3600) > 1 ? 's' : '');
         } elseif ($diff > 60) {
             // @TODO localize
             return sprintf("%d minute%s ago", $diff / 60, intval($diff / 60) > 1 ? 's' : '');
         } else {
             // @TODO localize
             return sprintf("%d second%s ago", $diff, $diff > 1 ? 's' : '');
         }
     } else {
         return DateFormatter::formatDate($date, DateFormatter::MEDIUM_STYLE, DateFormatter::MEDIUM_STYLE);
     }
 }
 protected function initializeForPage()
 {
     switch ($this->page) {
         case 'index':
             $links = array(array('title' => 'Text', 'url' => $this->buildBreadcrumbURL('text', array())), array('title' => 'Navigation Lists', 'url' => $this->buildBreadcrumbURL('nav', array())), array('title' => 'Results Lists', 'url' => $this->buildBreadcrumbURL('results', array())), array('title' => 'Search', 'url' => $this->buildBreadcrumbURL('search', array())), array('title' => 'Detail', 'url' => $this->buildBreadcrumbURL('detail', array())), array('title' => 'Geolocation', 'url' => $this->buildBreadcrumbURL('location', array())), array('title' => 'HTML Truncation Form', 'url' => $this->buildBreadcrumbURL('truncate', array())), array('title' => 'Javascript API Call Test', 'url' => $this->buildBreadcrumbURL('apicall', array())));
             if ($this->browser == 'native') {
                 $appQLinks = array(array('title' => 'Dialogs', 'url' => $this->buildBreadcrumbURL('dialogs', array())), array('title' => 'Refresh Button', 'url' => $this->buildBreadcrumbURL('refresh', array())), array('title' => 'Auto Refresh', 'url' => $this->buildBreadcrumbURL('autorefresh', array())));
                 $this->assign('appQLinks', $appQLinks);
             }
             $this->assign('links', $links);
             break;
         case 'text':
             break;
         case 'apicall':
             break;
         case 'search':
             $formFields = $this->loadPageConfigArea($this->page, false);
             foreach ($formFields as $i => $formField) {
                 if (isset($formField['option_keys'])) {
                     $options = array();
                     foreach ($formField['option_keys'] as $j => $optionKey) {
                         $options[$optionKey] = $formField['option_values'][$j];
                     }
                     $formFields[$i]['options'] = $options;
                     unset($formFields[$i]['option_keys']);
                     unset($formFields[$i]['option_values']);
                 }
             }
             $this->assign('formFields', $formFields);
             break;
         case 'results':
             if ($title = $this->getArg('title')) {
                 $this->setPageTitles($title);
             }
             $this->assign('next', 'Next');
             $this->assign('prev', 'Prev');
             $this->assign('nextURL', $this->buildBreadcrumbURL($this->page, $this->args, false));
             $this->assign('prevURL', $this->buildBreadcrumbURL($this->page, $this->args, false));
             $this->assign('lists', $this->getListsForPage($this->page));
             break;
         case 'nav':
             if ($title = $this->getArg('title')) {
                 $this->setPageTitles($title);
             }
             $this->assign('lists', $this->getListsForPage($this->page));
             break;
         case 'pane':
             $this->assign('lists', $this->getListsForPage($this->page));
             break;
         case 'articles':
             $this->setWebBridgePageRefresh(true);
             $this->addInternalJavascript('/common/javascript/lib/ellipsizer.js');
             $this->addOnLoad('setupListing();');
             $this->assign('articles', $this->getListsForPage($this->page));
             break;
         case 'detail':
             $detailConfig = $this->loadPageConfigArea('detail', 'detailConfig');
             if ($this->getOptionalModuleVar('SHARING_ENABLED', 1)) {
                 $this->assign('shareTitle', $this->getLocalizedString('SHARE_THIS_ITEM'));
                 $this->assign('shareEmailURL', '*****@*****.**');
                 $this->assign('shareRemark', 'This is a share remark');
                 $this->assign('shareURL', 'This is a share URL');
             }
             if ($this->getOptionalModuleVar('BOOKMARKS_ENABLED', 1)) {
                 $this->generateBookmarkOptions('fakeid');
             }
             $this->enableTabs(array_keys($detailConfig['tabs']));
             break;
         case 'dialogs':
             $buttons = array();
             $configs = $this->loadPageConfigArea($this->page, false);
             foreach ($configs as $config) {
                 if (!isset($config['title'], $config['description'], $config['api'], $config['arguments'])) {
                     continue;
                 }
                 $buttons[] = array('title' => $config['title'], 'description' => $config['description'], 'javascript' => "kgoBridge.{$config['api']}(" . implode(', ', $config['arguments']) . ", null, function (error, params) { alert('You clicked button type \\''+params['button']+'\\''); }); return false;");
             }
             $this->assign('buttons', $buttons);
             break;
         case 'location':
             $links = array(array('title' => 'Watch Position Map Test', 'url' => $this->buildBreadcrumbURL('location_full', array())));
             $this->assign('links', $links);
             break;
         case 'location_full':
             $this->addExternalJavascript('http://maps.googleapis.com/maps/api/js?sensor=true');
             $this->addOnLoad('initMap();');
             $this->addInlineJavascript('var locationMarkerURL = "' . FULL_URL_PREFIX . 'common/images/map-location.png";');
             break;
         case 'truncate':
             $this->assign('action', $this->buildBreadcrumbURL('truncated', array()));
             break;
         case 'truncated':
             $length = $this->getArg('length', 0);
             $margin = $this->getArg('margin', 0);
             $minLineLength = $this->getArg('minLineLength', 40);
             $html = $this->getArg('html', '');
             if ($length && $margin && $html) {
                 $html = Sanitizer::sanitizeAndTruncateHTML($html, $truncated, $length, $margin, $minLineLength);
             }
             $this->assign('html', $html);
             break;
         case 'autorefresh':
             $links = array(array('title' => 'Detail', 'url' => $this->buildBreadcrumbURL('detail', array())));
             $this->assign('links', $links);
             // fallthrough
         // fallthrough
         case 'refresh':
             $now = new DateTime();
             $this->assign('lastUpdated', DateFormatter::formatDate($now, DateFormatter::MEDIUM_STYLE, DateFormatter::MEDIUM_STYLE));
             break;
     }
 }
Пример #27
0
<?php

require_once __DIR__ . "/../vendor/autoload.php";
require_once __DIR__ . "/../src/DateFormatter.php";
$app = new Silex\Application();
$app->register(new Silex\Provider\TwigServiceProvider(), array('twig.path' => __DIR__ . '/../views'));
$app->get("/", function () use($app) {
    return $app['twig']->render('form.html.twig');
});
$app->get("/view_date", function () use($app) {
    $date_to_format = new DateFormatter();
    $changed_date = $date_to_format->changeDate($_GET['start_date'], $_GET['end_date']);
    return $app['twig']->render('date.html.twig', array('result' => $changed_date));
});
return $app;