/**
  * Hook on the page render, use this to look for generic metadata and map those over to opengraph data.
  *
  * @param View $view
  */
 public static function HookRenderPage(View $view)
 {
     if (!isset($view->meta['og:type'])) {
         $view->meta['og:type'] = 'website';
     }
     if (!isset($view->meta['og:title'])) {
         $view->meta['og:title'] = $view->title;
     }
     if ($view->canonicalurl) {
         $view->meta['og:url'] = $view->canonicalurl;
     }
     if (isset($view->meta['description'])) {
         $view->meta['og:description'] = str_replace(array("\r\n", "\r", "\n"), ' ', $view->meta['description']);
     }
     // Articles can have some specific information.
     if ($view->meta['og:type'] == 'article') {
         $view->meta['og:article:modified_time'] = Time::FormatGMT($view->updated, Time::TIMEZONE_GMT, 'r');
         if (isset($view->meta['author'])) {
             $view->meta['og:article:author'] = $view->meta['author'];
         }
     }
     if (FACEBOOK_APP_ID) {
         $view->meta['fb:app_id'] = FACEBOOK_APP_ID;
     }
     /*
      * other article tags:
     article:published_time - datetime - When the article was first published.
     article:modified_time - datetime - When the article was last changed.
     article:expiration_time - datetime - When the article is out of date after.
     article:author - profile array - Writers of the article.
     article:section - string - A high-level section name. E.g. Technology
     article:tag - string array - Tag words associated with this article.
     */
 }
예제 #2
0
 /**
  * Execute the monthly cron
  */
 public function monthly()
 {
     $request = $this->getPageRequest();
     $view = $this->getView();
     $view->mode = View::MODE_NOOUTPUT;
     // Check and see if I need to run this cron already, ie: don't run an hourly log twice in the same hour.
     $last = CronLogModel::Find(array('cron' => 'monthly'), 1, 'created DESC');
     if ($last && Time::GetCurrentGMT('Ym') == Time::FormatGMT($last->get('created'), Time::TIMEZONE_GMT, 'Ym')) {
         // No run needed, already ran this month.
         // Report this.
         $timelast = floor((Time::GetCurrentGMT() - $last->get('created')) / 60);
         if ($timelast >= 3600 * 48) {
             $timelast = floor((Time::GetCurrentGMT() - $last->get('created')) / 3600 * 24) . ' days';
         } elseif ($timelast >= 120) {
             $timelast = floor((Time::GetCurrentGMT() - $last->get('created')) / 3600) . ' hours';
         } else {
             $timelast .= ' minutes';
         }
         $logmsg = "Not re-running, already executed monthly cron " . $timelast . ' ago';
         SystemLogModel::LogInfoEvent('/cron/monthly', $logmsg);
         return;
     }
     $log = $this->_performcron('monthly');
     if ($log->get('status') != 'pass') {
         echo 'failed, check the logs';
     }
 }
예제 #3
0
	public function testTimeFormatGMT(){
		$ref = new DateTime(null, new DateTimeZone('UTC'));
		$localref = new DateTime(null, new DateTimeZone(date_default_timezone_get()));

		$this->assertEquals($localref->format('U'), \Time::FormatGMT($ref->format('U'), date_default_timezone_get()));
	}
예제 #4
0
	/**
	 * Get a string to represent the relative time from right now.
	 * Will return something similar to 'Yesterday at 5:40p' or 'Today at 4:20a', etc...
	 *
	 * @param $time int The time, (in GMT), to get the relative from now.
	 * @param $timezone int The timezone to display the result as.
	 * @param $accuracy int The level of accuracy,
	 *                      2 will return today|yesterday|tomorrow,
	 *                      3 will return up to a week, ie: Monday at 4:40pm
	 * @param $timeformat string The formatting to use for times.
	 * @param $dateformat string The formatting to use for dates.
	 *
	 * @return string
	 */
	public static function GetRelativeAsString($time, $timezone = Time::TIMEZONE_GMT, $accuracy = 3, $timeformat = 'g:ia', $dateformat = 'M j, Y') {
		// First, get the day of now and the time that's being compared.
		// They will form an int in the format of YYYYMMDD.
		$nowStamp = Time::GetCurrent($timezone, 'Ymd');
		$cStamp   = Time::FormatGMT($time, $timezone, 'Ymd');

		// The first couple days will always be converted, today and tomorrow/yesterday.
		if ($nowStamp - $cStamp == 0) return 'Today at ' . Time::FormatGMT($time, $timezone, $timeformat);
		elseif ($nowStamp - $cStamp == 1) return 'Yesterday at ' . Time::FormatGMT($time, $timezone, $timeformat);
		elseif ($nowStamp - $cStamp == -1) return 'Tomorrow at ' . Time::FormatGMT($time, $timezone, $timeformat);

		// If accuracy is the minimum and neither today/tomorrow/yesterday, simply return the date.
		if ($accuracy <= 2) return Time::FormatGMT($time, $timezone, $dateformat);

		// If it's too high/low from a week, just return the date.
		if (abs($nowStamp - $cStamp) > 6) return Time::FormatGMT($time, $timezone, $dateformat);

		// Else, return the day of the week, followed by the time.
		return Time::FormatGMT($time, $timezone, 'l \a\t ' . $timeformat);
	}
예제 #5
0
	/**
	 * Get the content to be inserted into the <head> tag for this view.
	 *
	 * @return string
	 */
	public function getHeadContent(){
		$minified = ConfigHandler::Get('/core/markup/minified');

		// First, the basic ones.
		if($minified){
			$data = array_merge($this->stylesheets, $this->head, $this->scripts['head']);
		}
		else{
			$data = array_merge(
				['<!-- BEGIN STYLESHEET INSERTIONS -->'],
				$this->stylesheets,
				['<!-- END STYLESHEET INSERTIONS -->'],
				['<!-- BEGIN HEAD CONTENT INSERTIONS -->'],
				$this->head,
				['<!-- END HEAD CONTENT INSERTIONS -->'],
				['<!-- BEGIN JAVASCRIPT INSERTIONS -->'],
				$this->scripts['head'],
				['<!-- END JAVASCRIPT INSERTIONS -->']
			);
		}


		// Some of the automatic settings only get set if no errors.
		if($this->error == View::ERROR_NOERROR){

			// Custom meta tag :: http-equiv="last-modified"
			if($this->updated !== null){
				// last-modified is no longer a valid attribute in HTML5
				//$data[] = '<meta http-equiv="last-modified" content="' . Time::FormatGMT($this->updated, Time::TIMEZONE_GMT, Time::FORMAT_RFC2822) . '" />';
				$this->meta['article:modified_time'] = Time::FormatGMT($this->updated, Time::TIMEZONE_GMT, Time::FORMAT_ISO8601);
			}

			// Set the generator metatag, (this is handled internally within the tag)
			$this->meta['generator'] = true;

			// Some standard tags that also have og equivalents.
			if(!isset($this->meta['og:title'])){
				$this->meta['og:title'] = $this->title;
			}

			// Set the canonical url if not set.
			if($this->canonicalurl === null){
				$this->canonicalurl = \Core\resolve_link($this->baseurl);
			}

			// Set the canonical URL in the necessary spots (if it's not in error)
			if($this->canonicalurl !== false){
				$this->meta['canonical'] = $this->canonicalurl;
			}

			$this->meta['og:site_name'] = SITENAME;
		}

		// Merge in the standard meta names and properties now.
		$data = array_merge($data, $this->meta->fetch());


		if ($minified) {
			$out = implode('', $data);
		}
		else {
			$out = '<!-- BEGIN Automatic HEAD generation -->' . "\n\n" . implode("\n", $data) . "\n\n" . '<!-- END Automatic HEAD generation -->';
		}

		return trim($out);
	}