Пример #1
0
 /**
  * Runs the test cases.
  *
  * @public
  * @return @c true on success @c false on failure.
  */
 function test()
 {
     //Danish primer: lr is short for saturday (as sat) in danish.
     $legacyDate = "lr d. 24/9-2005 kl. 12:32";
     $legacyDateUnixtime = 1127557920;
     $closeDateFormat = "\\l\\r \\d. j/n-Y \\k\\l. G:i";
     $lp = new LegacyDateParser();
     if ($lp->attemptParse($legacyDate) === FALSE) {
         echo "Valid date ({$legacyDate}) did not parse.";
         return false;
     }
     if ($lp->parsedDate < 0) {
         echo "Stated that ({$legacyDate}) was parsed, but it was not.";
         return false;
     }
     $res = $lp->getParsedDate();
     if ($res != $legacyDateUnixtime) {
         echo "Parsed date ({$legacyDate}) but got ({$res}) and not the expected time ({$legacyDateUnixtime}).";
         return false;
     }
     $newDate = date($closeDateFormat, $res);
     if ($legacyDate !== $newDate) {
         echo "Expected ({$legacyDate}) but got ({$newDate}).";
         return false;
     }
     $badDate = "some date/foo bar";
     if ($lp->attemptParse($badDate) !== FALSE) {
         echo "Said OK for a date it should not be able to parse.";
         return false;
     }
     if ($lp->parsedDate >= 0) {
         echo "Said it could not parse a date, but saved it internally.";
         return false;
     }
     if ($lp->parseToView($badDate, $closeDateFormat) !== $badDate) {
         echo "Parsed a bad date to view, but did not return it again.";
         return false;
     }
     if ($lp->parseToView($legacyDate, "dummy format") == $legacyDate) {
         echo "Parsed a OK date to view ({$legacyDate}), but returned it again.";
         return false;
     }
     $res = $lp->parseToView($legacyDate, $closeDateFormat);
     if ($res !== $newDate) {
         echo "Parsed a OK date to view ({$legacyDate}), did not return the expected ({$newDate}).";
         return false;
     }
     return true;
 }
Пример #2
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;
 }