Beispiel #1
0
 public function Items()
 {
     $this->Pages = Versioned::get_by_stage('SiteTree', 'Live');
     $newPages = new DataObjectSet();
     foreach ($this->Pages as $page) {
         // Only include pages from this host and pages which are not an instance of ErrorPage
         // We prefix $_SERVER['HTTP_HOST'] with 'http://' so that parse_url to help parse_url identify the host name component; we could use another protocol (like
         // 'ftp://' as the prefix and the code would work the same.
         if (parse_url($page->AbsoluteLink(), PHP_URL_HOST) == parse_url('http://' . $_SERVER['HTTP_HOST'], PHP_URL_HOST) && !$page instanceof ErrorPage) {
             // If the page has been set to 0 priority, we set a flag so it won't be included
             if ($page->canView() && (!isset($page->Priority) || $page->Priority > 0)) {
                 // The one field that isn't easy to deal with in the template is
                 // Change frequency, so we set that here.
                 $properties = $page->toMap();
                 $created = new SSDatetime();
                 $created->value = $properties['Created'];
                 $now = new SSDatetime();
                 $now->value = date('Y-m-d H:i:s');
                 $versions = $properties['Version'];
                 $timediff = $now->format('U') - $created->format('U');
                 // Check how many revisions have been made over the lifetime of the
                 // Page for a rough estimate of it's changing frequency.
                 $period = $timediff / ($versions + 1);
                 if ($period > 60 * 60 * 24 * 365) {
                     // > 1 year
                     $page->ChangeFreq = 'yearly';
                 } elseif ($period > 60 * 60 * 24 * 30) {
                     // > ~1 month
                     $page->ChangeFreq = 'monthly';
                 } elseif ($period > 60 * 60 * 24 * 7) {
                     // > 1 week
                     $page->ChangeFreq = 'weekly';
                 } elseif ($period > 60 * 60 * 24) {
                     // > 1 day
                     $page->ChangeFreq = 'daily';
                 } elseif ($period > 60 * 60) {
                     // > 1 hour
                     $page->ChangeFreq = 'hourly';
                 } else {
                     // < 1 hour
                     $page->ChangeFreq = 'always';
                 }
                 $newPages->push($page);
             }
         }
     }
     return $newPages;
 }
 /**
  * @param SS_HTTPRequest $request
  */
 public function run($request)
 {
     $compatibility = ContentReviewCompatability::start();
     $now = class_exists("SS_Datetime") ? SS_Datetime::now()->URLDate() : SSDatetime::now()->URLDate();
     // First grab all the pages with a custom setting
     $pages = Page::get("Page")->where("\"SiteTree\".\"NextReviewDate\" <= '{$now}'");
     $overduePages = $this->getOverduePagesForOwners($pages);
     // Lets send one email to one owner with all the pages in there instead of no of pages
     // of emails.
     foreach ($overduePages as $memberID => $pages) {
         $this->notifyOwner($memberID, $pages);
     }
     ContentReviewCompatability::done($compatibility);
 }
Beispiel #3
0
    static function trend_chart($table, $filter = "day", $name, $type, $color)
    {
        $trendstrl = _t('Statistics.TRENDS', 'Trends');
        $legendtrl = _t('Statistics.LEGEND', 'Legend');
        $top = <<<HTML
<div id="trendchart" style="display: none">
<h2>{$trendstrl}</h2>
<div><canvas id="chart" height="400" width="700"></canvas></div>
<div id="chart_legend"><legend>{$legendtrl}</legend></div>
</div>
\t\t<script type="text/javascript">

HTML;
        $bot = <<<HTML
var chart = new Plotr.{$type}Chart('chart',options);

\t\tchart.addDataset(chartdata);


\t\tchart.render();

\t\tchart.addLegend(\$('chart_legend'));

\t\t</script>
HTML;
        $ds = "var chartdata = { \n";
        foreach ($table as $class) {
            $record = DataObject::get($class, "", $class . ".Created DESC");
            $total = $record->TotalItems();
            $props = $record->toArray();
            $props = $props[0]->toMap();
            $startyear = new SSDatetime($props['Created']);
            $startyear = $startyear->Format('Y');
            $startmonth = new SSDatetime($props['Created']);
            $startmonth = $startmonth->Format('m');
            if ($filter == "day") {
                $days = new SSDatetime($props['Created']);
                $days = $days->Format('t');
                $sum = 0;
                $ds .= "{$class}: [";
                for ($i = 1; $i <= $days; $i++) {
                    foreach ($record as $v) {
                        $props = $v->toMap();
                        $currdate = new SSDatetime($props['Created']);
                        $curryear = $currdate->Format('Y');
                        $currmonth = $currdate->Format('m');
                        $currday = $currdate->Format('j');
                        if ($curryear == $startyear && $currmonth == $startmonth && $currday == $i) {
                            $sum++;
                        }
                    }
                    $ds .= "[" . ($i - 1) . ", {$sum}], ";
                }
                $ds .= "[]],\n";
            } else {
                if ($filter == "month") {
                    $sum = 0;
                    $ds .= "{$class}Set: [";
                    for ($i = 0; $i <= 11; $i++) {
                        $imonth = date('F', mktime(0, 0, 0, $i + 1, 1, 1));
                        foreach ($record as $v) {
                            $props = $v->toMap();
                            $currdate = new SSDatetime($props['Created']);
                            $curryear = $currdate->Format('Y');
                            $currmonth = $currdate->Format('m');
                            $currday = $currdate->Format('j');
                            if ($curryear == $startyear && $currmonth == $i) {
                                $sum++;
                            }
                        }
                        $ds .= "[{$i}, {$sum}], ";
                    }
                    $ds .= "[]],\n";
                }
            }
        }
        $xt = "xTicks: [";
        if ($filter == "month") {
            for ($i = 0; $i <= 11; $i++) {
                $imonth = date('F', mktime(0, 0, 0, $i + 1, 1, 1));
                $xt .= "{v:{$i}, label:'{$imonth}'}, ";
            }
        } else {
            if ($filter == "day") {
                for ($i = 1; $i <= $days; $i++) {
                    $xt .= "{v:" . ($i - 1) . ", label:'{$i}'}, ";
                }
            }
        }
        $opts = <<<HTML
var options = {

\taxisLabelFontSize:\t\t10,

\tpadding: {left: 30, right: 0, top: 10, bottom: 30},

\tbackgroundColor: '#cccccc',

\tcolorScheme: '{$color}',



HTML;
        $opts .= $xt . "]\n};";
        return $top . $ds . "\n};\n\n" . $opts . "\n\n" . $bot;
    }