Find this useful? Enter your email to receive occasional updates for securing PHP code.

Signing you up...

Thank you for signing up!

PHP Decode

<?php namespace Piwik\Period; use Exception; use Piwik\Cache; use Piwik\Common; use Piwik..

Decoded Output download

<?php
 namespace Piwik\Period; use Exception; use Piwik\Cache; use Piwik\Common; use Piwik\Container\StaticContainer; use Piwik\Date; use Piwik\Period; class Range extends Period { const PERIOD_ID = 5; protected $label = "range"; protected $today; protected $defaultEndDate; protected $strPeriod; protected $strDate; protected $timezone; public function __construct($strPeriod, $strDate, $timezone = "UTC", $today = false) { $this->strPeriod = $strPeriod; $this->strDate = $strDate; $this->timezone = $timezone; $this->defaultEndDate = null; if ($today === false) { $today = Date::factory("now", $this->timezone); } $this->today = $today; $this->translator = StaticContainer::get("Piwik\Translation\Translator"); } public function __sleep() { return array("strPeriod", "strDate", "timezone", "defaultEndDate", "today"); } public function __wakeup() { $this->translator = StaticContainer::get("Piwik\Translation\Translator"); } private function getCache() { return Cache::getTransientCache(); } private function getCacheId() { $end = ''; if ($this->defaultEndDate) { $end = $this->defaultEndDate->getTimestamp(); } $today = $this->today->getTimestamp(); return "range" . $this->strPeriod . $this->strDate . $this->timezone . $end . $today; } private function loadAllFromCache() { $range = $this->getCache()->fetch($this->getCacheId()); if (!empty($range)) { foreach ($range as $key => $val) { $this->{$key} = $val; } } } private function cacheAll() { $props = get_object_vars($this); $this->getCache()->save($this->getCacheId(), $props); } public function getLocalizedShortString() { return $this->getTranslatedRange($this->getRangeFormat(true)); } public function getLocalizedLongString() { return $this->getTranslatedRange($this->getRangeFormat()); } public function getDateStart() { $dateStart = parent::getDateStart(); if (empty($dateStart)) { throw new Exception("Specified date range is invalid."); } return $dateStart; } public function getPrettyString() { $out = $this->translator->translate("General_DateRangeFromTo", array($this->getDateStart()->toString(), $this->getDateEnd()->toString())); return $out; } protected function getMaxN(int $lastN) : int { switch ($this->strPeriod) { case "day": $lastN = min($lastN, 5 * 365); break; case "week": $lastN = min($lastN, 10 * 52); break; case "month": $lastN = min($lastN, 10 * 12); break; case "year": $lastN = min($lastN, 10); break; } return $lastN; } public function setDefaultEndDate(Date $oDate) { $this->defaultEndDate = $oDate; } protected function generate() { if ($this->subperiodsProcessed) { return; } $this->loadAllFromCache(); if ($this->subperiodsProcessed) { return; } parent::generate(); if (preg_match("/^(last|previous)([0-9]*)$/", $this->strDate, $regs)) { $lastN = $regs[2]; $lastOrPrevious = $regs[1]; if (!is_null($this->defaultEndDate)) { $defaultEndDate = $this->defaultEndDate; } else { $defaultEndDate = $this->today; } $period = $this->strPeriod; if ($period == "range") { $period = "day"; } if ($lastOrPrevious == "last") { $endDate = $defaultEndDate; } elseif ($lastOrPrevious == "previous") { if ("month" == $period) { $endDate = $defaultEndDate->subMonth(1); } else { $endDate = $defaultEndDate->subPeriod(1, $period); } } $lastN = $this->getMaxN((int) $lastN); $lastN--; if ($lastN < 0) { $lastN = 0; } $startDate = $endDate->addPeriod(-1 * $lastN, $period); } elseif ($dateRange = Range::parseDateRange($this->strDate)) { $strDateStart = $dateRange[1]; $strDateEnd = $dateRange[2]; $startDate = Date::factory($strDateStart); $timezone = null; if (strpos($strDateEnd, "-") === false) { $timezone = $this->timezone; } $endDate = Date::factory($strDateEnd, $timezone)->setTime("00:00:00"); } else { throw new Exception($this->translator->translate("General_ExceptionInvalidDateRange", array($this->strDate, " 'lastN', 'previousN', 'YYYY-MM-DD,YYYY-MM-DD'"))); } if ($this->strPeriod != "range") { $this->fillArraySubPeriods($startDate, $endDate, $this->strPeriod); $this->cacheAll(); return; } $this->processOptimalSubperiods($startDate, $endDate); $this->endDate = $endDate; $this->cacheAll(); } public static function parseDateRange($dateString) { $matched = preg_match("/^((?:[0-9]{4}-[0-9]{1,2}-[0-9]{1,2})|last[ -]?(?:week|month|year)),((?:[0-9]{4}-[0-9]{1,2}-[0-9]{1,2})|today|now|yesterday|last[ -]?(?:week|month|year))$/Di", trim($dateString), $regs); if (empty($matched)) { return false; } return $regs; } protected $endDate = null; public function getDateEnd() { if (!is_null($this->endDate)) { return $this->endDate; } return parent::getDateEnd(); } protected function processOptimalSubperiods($startDate, $endDate) { while ($startDate->isEarlier($endDate) || $startDate == $endDate) { $endOfPeriod = null; $month = new Month($startDate); $endOfMonth = $month->getDateEnd(); $startOfMonth = $month->getDateStart(); $year = new Year($startDate); $endOfYear = $year->getDateEnd(); $startOfYear = $year->getDateStart(); if ($startDate == $startOfYear && ($endOfYear->isEarlier($endDate) || $endOfYear == $endDate || $endOfYear->isLater($this->today)) && !($endDate->isEarlier($this->today) && $this->today->toString("Y") == $endOfYear->toString("Y") && $this->today->compareYear($endOfYear) == 0)) { $this->addSubperiod($year); $endOfPeriod = $endOfYear; } elseif ($startDate == $startOfMonth && ($endOfMonth->isEarlier($endDate) || $endOfMonth == $endDate || $endOfMonth->isLater($this->today)) && !($endDate->isEarlier($this->today) && $this->today->toString("Y") == $endOfMonth->toString("Y") && $this->today->compareMonth($endOfMonth) == 0)) { $this->addSubperiod($month); $endOfPeriod = $endOfMonth; } else { $week = new Week($startDate); $startOfWeek = $week->getDateStart(); $endOfWeek = $week->getDateEnd(); $firstDayNextMonth = $startDate->addPeriod(2, "month")->setDay(1); $useMonthsNextIteration = $firstDayNextMonth->isEarlier($endDate); if ($useMonthsNextIteration && $endOfWeek->isLater($endOfMonth)) { $this->fillArraySubPeriods($startDate, $endOfMonth, "day"); $endOfPeriod = $endOfMonth; } elseif ($this->isEndOfWeekLaterThanEndDate($endDate, $endOfWeek) && ($endOfWeek->isEarlier($this->today) || $startOfWeek->toString() != $startDate->toString() || $endDate->isEarlier($this->today))) { $this->fillArraySubPeriods($startDate, $endDate, "day"); break 1; } elseif ($startOfWeek->isEarlier($startDate) && $endOfWeek->isEarlier($this->today)) { $this->fillArraySubPeriods($startDate, $endOfWeek, "day"); $endOfPeriod = $endOfWeek; } else { $this->addSubperiod($week); $endOfPeriod = $endOfWeek; } } $startDate = $endOfPeriod->addDay(1); } } protected function fillArraySubPeriods($startDate, $endDate, $period) { $arrayPeriods = array(); $endSubperiod = Period\Factory::build($period, $endDate); $arrayPeriods[] = $endSubperiod; $endDate = $endSubperiod->getDateStart(); while ($endDate->isLater($startDate)) { $endDate = $endDate->addPeriod(-1, $period); $subPeriod = Period\Factory::build($period, $endDate); $arrayPeriods[] = $subPeriod; } $arrayPeriods = array_reverse($arrayPeriods); foreach ($arrayPeriods as $period) { $this->addSubperiod($period); } } public static function getLastDate($date = false, $period = false) { return self::getDateXPeriodsAgo(1, $date, $period); } public static function getDateXPeriodsAgo($subXPeriods, $date = false, $period = false) { if ($date === false) { $date = Common::getRequestVar("date"); } if ($period === false) { $period = Common::getRequestVar("period"); } if (365 == $subXPeriods && "day" == $period && Date::factory($date)->isLeapYear()) { $subXPeriods = 366; } if ($period === "range") { $rangePeriod = new Range($period, $date); $daysDifference = self::getNumDaysDifference($rangePeriod->getDateStart(), $rangePeriod->getDateEnd()); $end = $rangePeriod->getDateStart()->subDay(1); $from = $end->subDay($daysDifference); return array("{$from},{$end}", false); } $strLastDate = false; $lastPeriod = false; if (!preg_match("/(last|previous)([0-9]*)/", $date, $regs)) { if (strpos($date, ",")) { $rangePeriod = new Range($period, $date); $lastStartDate = $rangePeriod->getDateStart()->subPeriod($subXPeriods, $period); $lastEndDate = $rangePeriod->getDateEnd()->subPeriod($subXPeriods, $period); $strLastDate = "{$lastStartDate},{$lastEndDate}"; } else { $lastPeriod = Date::factory($date)->subPeriod($subXPeriods, $period); $strLastDate = $lastPeriod->toString(); } } return array($strLastDate, $lastPeriod); } public function getDayCount() { return self::getNumDaysDifference($this->getDateStart(), $this->getDateEnd()) + 1; } private static function getNumDaysDifference(Date $date1, Date $date2) { $days = abs($date1->getTimestamp() - $date2->getTimestamp()) / 60 / 60 / 24; return (int) round($days); } public static function getRelativeToEndDate($period, $lastN, $endDate, $site) { $timezone = $site->getTimezone(); $last30Relative = new Range($period, $lastN, $timezone); if (strpos($endDate, "-") === false) { $endDate = Date::factoryInTimezone($endDate, $timezone); } else { $endDate = Date::factory($endDate); } $last30Relative->setDefaultEndDate($endDate); $date = $last30Relative->getDateStart()->toString() . "," . $last30Relative->getDateEnd()->toString(); return $date; } private function isEndOfWeekLaterThanEndDate($endDate, $endOfWeek) { $isEndOfWeekLaterThanEndDate = $endOfWeek->isLater($endDate); $isEndDateAlsoEndOfWeek = $endOfWeek->toString() == $endDate->toString(); $isEndOfWeekLaterThanEndDate = $isEndOfWeekLaterThanEndDate || $isEndDateAlsoEndOfWeek && $endDate->isLater($this->today); return $isEndOfWeekLaterThanEndDate; } public function getRangeString() { $dateStart = $this->getDateStart(); $dateEnd = $this->getDateEnd(); return $dateStart->toString("Y-m-d") . "," . $dateEnd->toString("Y-m-d"); } public function getImmediateChildPeriodLabel() { $subperiods = $this->getSubperiods(); return reset($subperiods)->getImmediateChildPeriodLabel(); } public function getParentPeriodLabel() { return null; } } ?>

Did this file decode correctly?

Original Code

<?php
 namespace Piwik\Period; use Exception; use Piwik\Cache; use Piwik\Common; use Piwik\Container\StaticContainer; use Piwik\Date; use Piwik\Period; class Range extends Period { const PERIOD_ID = 5; protected $label = "\x72\x61\156\x67\x65"; protected $today; protected $defaultEndDate; protected $strPeriod; protected $strDate; protected $timezone; public function __construct($strPeriod, $strDate, $timezone = "\x55\x54\x43", $today = false) { $this->strPeriod = $strPeriod; $this->strDate = $strDate; $this->timezone = $timezone; $this->defaultEndDate = null; if ($today === false) { $today = Date::factory("\156\157\x77", $this->timezone); } $this->today = $today; $this->translator = StaticContainer::get("\x50\151\x77\x69\153\134\124\162\x61\x6e\163\x6c\141\164\151\x6f\x6e\134\x54\162\141\156\163\154\141\164\157\162"); } public function __sleep() { return array("\x73\164\162\x50\145\162\151\x6f\x64", "\163\164\162\104\x61\164\x65", "\164\151\x6d\x65\172\157\x6e\145", "\x64\x65\146\x61\x75\154\x74\105\x6e\144\104\x61\164\145", "\164\157\144\x61\x79"); } public function __wakeup() { $this->translator = StaticContainer::get("\120\151\167\x69\153\x5c\x54\162\x61\156\x73\x6c\141\164\151\157\156\134\124\x72\x61\x6e\163\154\141\x74\x6f\162"); } private function getCache() { return Cache::getTransientCache(); } private function getCacheId() { $end = ''; if ($this->defaultEndDate) { $end = $this->defaultEndDate->getTimestamp(); } $today = $this->today->getTimestamp(); return "\x72\141\156\x67\145" . $this->strPeriod . $this->strDate . $this->timezone . $end . $today; } private function loadAllFromCache() { $range = $this->getCache()->fetch($this->getCacheId()); if (!empty($range)) { foreach ($range as $key => $val) { $this->{$key} = $val; } } } private function cacheAll() { $props = get_object_vars($this); $this->getCache()->save($this->getCacheId(), $props); } public function getLocalizedShortString() { return $this->getTranslatedRange($this->getRangeFormat(true)); } public function getLocalizedLongString() { return $this->getTranslatedRange($this->getRangeFormat()); } public function getDateStart() { $dateStart = parent::getDateStart(); if (empty($dateStart)) { throw new Exception("\123\x70\145\x63\151\x66\151\145\144\40\144\141\164\145\x20\162\x61\156\x67\x65\40\x69\x73\40\x69\156\166\141\x6c\151\144\56"); } return $dateStart; } public function getPrettyString() { $out = $this->translator->translate("\107\x65\156\x65\x72\x61\x6c\137\104\141\x74\x65\x52\x61\x6e\147\x65\x46\162\157\155\x54\157", array($this->getDateStart()->toString(), $this->getDateEnd()->toString())); return $out; } protected function getMaxN(int $lastN) : int { switch ($this->strPeriod) { case "\x64\x61\171": $lastN = min($lastN, 5 * 365); break; case "\167\x65\145\153": $lastN = min($lastN, 10 * 52); break; case "\155\157\156\x74\x68": $lastN = min($lastN, 10 * 12); break; case "\x79\x65\141\162": $lastN = min($lastN, 10); break; } return $lastN; } public function setDefaultEndDate(Date $oDate) { $this->defaultEndDate = $oDate; } protected function generate() { if ($this->subperiodsProcessed) { return; } $this->loadAllFromCache(); if ($this->subperiodsProcessed) { return; } parent::generate(); if (preg_match("\57\x5e\50\x6c\x61\163\164\x7c\160\162\145\x76\x69\x6f\165\x73\x29\x28\133\x30\55\71\135\52\x29\x24\x2f", $this->strDate, $regs)) { $lastN = $regs[2]; $lastOrPrevious = $regs[1]; if (!is_null($this->defaultEndDate)) { $defaultEndDate = $this->defaultEndDate; } else { $defaultEndDate = $this->today; } $period = $this->strPeriod; if ($period == "\162\141\x6e\147\x65") { $period = "\x64\x61\171"; } if ($lastOrPrevious == "\x6c\x61\163\x74") { $endDate = $defaultEndDate; } elseif ($lastOrPrevious == "\x70\x72\x65\x76\151\x6f\165\x73") { if ("\155\157\x6e\x74\x68" == $period) { $endDate = $defaultEndDate->subMonth(1); } else { $endDate = $defaultEndDate->subPeriod(1, $period); } } $lastN = $this->getMaxN((int) $lastN); $lastN--; if ($lastN < 0) { $lastN = 0; } $startDate = $endDate->addPeriod(-1 * $lastN, $period); } elseif ($dateRange = Range::parseDateRange($this->strDate)) { $strDateStart = $dateRange[1]; $strDateEnd = $dateRange[2]; $startDate = Date::factory($strDateStart); $timezone = null; if (strpos($strDateEnd, "\55") === false) { $timezone = $this->timezone; } $endDate = Date::factory($strDateEnd, $timezone)->setTime("\60\x30\x3a\x30\60\x3a\60\x30"); } else { throw new Exception($this->translator->translate("\x47\145\156\145\x72\141\x6c\x5f\105\x78\x63\x65\160\x74\x69\x6f\156\111\156\x76\x61\x6c\x69\x64\x44\141\164\x65\x52\x61\156\147\x65", array($this->strDate, "\40\47\x6c\x61\163\x74\116\x27\x2c\x20\47\160\x72\145\166\x69\157\x75\x73\x4e\x27\54\x20\x27\x59\131\131\x59\x2d\x4d\x4d\x2d\x44\104\x2c\131\x59\131\x59\55\115\115\55\x44\104\47"))); } if ($this->strPeriod != "\x72\x61\x6e\x67\145") { $this->fillArraySubPeriods($startDate, $endDate, $this->strPeriod); $this->cacheAll(); return; } $this->processOptimalSubperiods($startDate, $endDate); $this->endDate = $endDate; $this->cacheAll(); } public static function parseDateRange($dateString) { $matched = preg_match("\x2f\136\x28\x28\77\72\x5b\60\55\x39\x5d\173\64\x7d\55\x5b\60\x2d\x39\135\173\61\x2c\x32\x7d\55\x5b\x30\55\71\x5d\173\x31\x2c\x32\x7d\x29\x7c\x6c\x61\163\x74\x5b\40\55\135\x3f\50\x3f\72\x77\x65\145\153\x7c\x6d\x6f\x6e\x74\150\174\x79\145\141\162\51\51\x2c\x28\x28\x3f\x3a\133\60\x2d\71\x5d\x7b\x34\x7d\x2d\133\x30\x2d\x39\x5d\173\61\x2c\62\175\x2d\x5b\x30\55\71\x5d\173\x31\54\62\x7d\51\174\164\x6f\144\141\171\174\156\157\x77\174\171\145\x73\164\145\x72\144\x61\171\174\x6c\141\163\x74\x5b\x20\x2d\x5d\77\x28\x3f\72\167\145\x65\153\174\155\x6f\x6e\164\x68\x7c\171\145\141\162\x29\x29\44\x2f\104\151", trim($dateString), $regs); if (empty($matched)) { return false; } return $regs; } protected $endDate = null; public function getDateEnd() { if (!is_null($this->endDate)) { return $this->endDate; } return parent::getDateEnd(); } protected function processOptimalSubperiods($startDate, $endDate) { while ($startDate->isEarlier($endDate) || $startDate == $endDate) { $endOfPeriod = null; $month = new Month($startDate); $endOfMonth = $month->getDateEnd(); $startOfMonth = $month->getDateStart(); $year = new Year($startDate); $endOfYear = $year->getDateEnd(); $startOfYear = $year->getDateStart(); if ($startDate == $startOfYear && ($endOfYear->isEarlier($endDate) || $endOfYear == $endDate || $endOfYear->isLater($this->today)) && !($endDate->isEarlier($this->today) && $this->today->toString("\131") == $endOfYear->toString("\131") && $this->today->compareYear($endOfYear) == 0)) { $this->addSubperiod($year); $endOfPeriod = $endOfYear; } elseif ($startDate == $startOfMonth && ($endOfMonth->isEarlier($endDate) || $endOfMonth == $endDate || $endOfMonth->isLater($this->today)) && !($endDate->isEarlier($this->today) && $this->today->toString("\131") == $endOfMonth->toString("\131") && $this->today->compareMonth($endOfMonth) == 0)) { $this->addSubperiod($month); $endOfPeriod = $endOfMonth; } else { $week = new Week($startDate); $startOfWeek = $week->getDateStart(); $endOfWeek = $week->getDateEnd(); $firstDayNextMonth = $startDate->addPeriod(2, "\x6d\x6f\x6e\x74\x68")->setDay(1); $useMonthsNextIteration = $firstDayNextMonth->isEarlier($endDate); if ($useMonthsNextIteration && $endOfWeek->isLater($endOfMonth)) { $this->fillArraySubPeriods($startDate, $endOfMonth, "\144\x61\x79"); $endOfPeriod = $endOfMonth; } elseif ($this->isEndOfWeekLaterThanEndDate($endDate, $endOfWeek) && ($endOfWeek->isEarlier($this->today) || $startOfWeek->toString() != $startDate->toString() || $endDate->isEarlier($this->today))) { $this->fillArraySubPeriods($startDate, $endDate, "\144\141\171"); break 1; } elseif ($startOfWeek->isEarlier($startDate) && $endOfWeek->isEarlier($this->today)) { $this->fillArraySubPeriods($startDate, $endOfWeek, "\144\141\171"); $endOfPeriod = $endOfWeek; } else { $this->addSubperiod($week); $endOfPeriod = $endOfWeek; } } $startDate = $endOfPeriod->addDay(1); } } protected function fillArraySubPeriods($startDate, $endDate, $period) { $arrayPeriods = array(); $endSubperiod = Period\Factory::build($period, $endDate); $arrayPeriods[] = $endSubperiod; $endDate = $endSubperiod->getDateStart(); while ($endDate->isLater($startDate)) { $endDate = $endDate->addPeriod(-1, $period); $subPeriod = Period\Factory::build($period, $endDate); $arrayPeriods[] = $subPeriod; } $arrayPeriods = array_reverse($arrayPeriods); foreach ($arrayPeriods as $period) { $this->addSubperiod($period); } } public static function getLastDate($date = false, $period = false) { return self::getDateXPeriodsAgo(1, $date, $period); } public static function getDateXPeriodsAgo($subXPeriods, $date = false, $period = false) { if ($date === false) { $date = Common::getRequestVar("\x64\141\x74\x65"); } if ($period === false) { $period = Common::getRequestVar("\x70\145\162\x69\x6f\x64"); } if (365 == $subXPeriods && "\144\141\171" == $period && Date::factory($date)->isLeapYear()) { $subXPeriods = 366; } if ($period === "\162\x61\x6e\147\x65") { $rangePeriod = new Range($period, $date); $daysDifference = self::getNumDaysDifference($rangePeriod->getDateStart(), $rangePeriod->getDateEnd()); $end = $rangePeriod->getDateStart()->subDay(1); $from = $end->subDay($daysDifference); return array("{$from}\x2c{$end}", false); } $strLastDate = false; $lastPeriod = false; if (!preg_match("\x2f\x28\x6c\x61\163\164\174\x70\162\145\x76\151\x6f\x75\x73\x29\x28\x5b\60\x2d\71\x5d\x2a\x29\57", $date, $regs)) { if (strpos($date, "\x2c")) { $rangePeriod = new Range($period, $date); $lastStartDate = $rangePeriod->getDateStart()->subPeriod($subXPeriods, $period); $lastEndDate = $rangePeriod->getDateEnd()->subPeriod($subXPeriods, $period); $strLastDate = "{$lastStartDate}\x2c{$lastEndDate}"; } else { $lastPeriod = Date::factory($date)->subPeriod($subXPeriods, $period); $strLastDate = $lastPeriod->toString(); } } return array($strLastDate, $lastPeriod); } public function getDayCount() { return self::getNumDaysDifference($this->getDateStart(), $this->getDateEnd()) + 1; } private static function getNumDaysDifference(Date $date1, Date $date2) { $days = abs($date1->getTimestamp() - $date2->getTimestamp()) / 60 / 60 / 24; return (int) round($days); } public static function getRelativeToEndDate($period, $lastN, $endDate, $site) { $timezone = $site->getTimezone(); $last30Relative = new Range($period, $lastN, $timezone); if (strpos($endDate, "\x2d") === false) { $endDate = Date::factoryInTimezone($endDate, $timezone); } else { $endDate = Date::factory($endDate); } $last30Relative->setDefaultEndDate($endDate); $date = $last30Relative->getDateStart()->toString() . "\54" . $last30Relative->getDateEnd()->toString(); return $date; } private function isEndOfWeekLaterThanEndDate($endDate, $endOfWeek) { $isEndOfWeekLaterThanEndDate = $endOfWeek->isLater($endDate); $isEndDateAlsoEndOfWeek = $endOfWeek->toString() == $endDate->toString(); $isEndOfWeekLaterThanEndDate = $isEndOfWeekLaterThanEndDate || $isEndDateAlsoEndOfWeek && $endDate->isLater($this->today); return $isEndOfWeekLaterThanEndDate; } public function getRangeString() { $dateStart = $this->getDateStart(); $dateEnd = $this->getDateEnd(); return $dateStart->toString("\x59\x2d\x6d\55\144") . "\54" . $dateEnd->toString("\x59\x2d\155\x2d\144"); } public function getImmediateChildPeriodLabel() { $subperiods = $this->getSubperiods(); return reset($subperiods)->getImmediateChildPeriodLabel(); } public function getParentPeriodLabel() { return null; } }

Function Calls

None

Variables

None

Stats

MD5 4cdace2a7b24b9b6730ebbd26f3007ea
Eval Count 0
Decode Time 88 ms