Example #1
0
 /**
  * Checks whether the API can be called
  *
  * Returns false if the API was called less than a minute ago (which gets over 15 requests in
  * 15 minute on Twitter API rate limiting)
  *
  * @return bool
  */
 public static function canCallAPI()
 {
     $lastCall = Setting::get('twitter', 'last_api_call');
     if ($lastCall == null) {
         return true;
     } else {
         $lastCall = new \DateTime($lastCall);
     }
     $now = new \DateTime();
     $interval = $lastCall->diff($now);
     // Are we at least one minute ago?
     if ($interval->i >= 1) {
         return true;
     } else {
         return false;
     }
 }
 public function settings()
 {
     $this->setTitle('Google Identity');
     $values = Setting::getForScope('google-identity');
     $form = $this->settingsForm($values);
     if ($this->request->getMethod() == 'POST') {
         $params = $this->getParams();
         $form->setValues($params);
         Setting::setForScope('google-identity', $form->getValues());
         $this->successMessage('Settings saved successfully.');
     } else {
         $form->setValues($values);
     }
     $scopes = [];
     Event::trigger('Octo.GoogleIdentity.GetScopes', $scopes);
     $this->template->scopes = implode(' ', array_unique($scopes));
     $this->template->form = $form;
 }
Example #3
0
 public function adminTemplateFunctions(AdminTemplate &$template)
 {
     $template->addFunction('canAccess', function ($args) {
         return $_SESSION['user']->canAccess($args['uri']);
     });
     $config = Config::getInstance();
     $template->addFunction('date_format', function ($args) {
         $date = $args['date'];
         $format = null;
         if (isset($args['format'])) {
             $format = $args['format'];
         }
         if (!$date instanceof \DateTime) {
             return '';
         }
         switch ($format) {
             case 'friendly':
                 return $this->friendlyDate($date);
             case 'short':
                 $format = 'd/m/Y g:ia';
                 break;
             case 'long_date':
                 $format = 'jS F Y';
                 break;
             case 'date':
                 $format = 'd/m/Y';
                 break;
             case 'time':
                 $format = 'g:ia';
                 break;
             case 'system_date':
                 $format = 'Y-m-d';
                 break;
             case 'system_datetime':
                 $format = 'Y-m-d H:i:s';
                 break;
             default:
                 $format = 'jS F Y, g:ia';
                 break;
         }
         return $date->format($format);
     });
     $template->set('date_now', new \DateTime());
     $template->set('adminUri', $config->get('site.full_admin_url'));
     $template->set('config', $config);
     $template->set('settings', Setting::getAllAsArray());
     $template->set('GET', $_GET);
     $template->addFunction('pagination', array($this, 'handlePagination'));
     $template->addFunction('var_dump', function ($args) {
         ob_start();
         var_dump($args['variable']);
         $rtn = ob_get_contents();
         ob_end_clean();
         return $rtn;
     });
     $template->addFunction('is_mobile', function () {
         if (class_exists('\\Mobile_Detect')) {
             $mobileDetect = new \Mobile_Detect();
             return $mobileDetect->isMobile();
         }
         return false;
     });
     $theme = 'blue';
     if (!is_null($config->get('site.admin_theme', null))) {
         $theme = $config->get('site.admin_theme');
     }
     $template->set('theme', $theme);
 }