Exemplo n.º 1
0
 /**
  * initialize plugin
  *
  * try to keep all initialization in one method to have a clean class
  * for the plugin-user
  *
  * @param string $pluginKey
  * @deprecated since 2015-04-24; will be declared 'final'
  */
 public function initializePlugin($pluginKey)
 {
     /**
      * init $plugin property
      */
     $this->plugin['key'] = $pluginKey;
     list($vendor, $name) = explode('\\', $this->plugin['key']);
     $DS = DIRECTORY_SEPARATOR;
     $this->plugin['dir'] = PLUGINS_DIR . $vendor . $DS . $name . $DS;
     /**
      * init events
      */
     foreach ($this->events as $event => $method) {
         Event::registerEvent($event, $this);
     }
     /**
      * init plugin settings
      */
     $defaults = Utility::load($this->getPluginPath('config.php'));
     if (empty($defaults) || !is_array($defaults)) {
         $defaults = [];
     }
     $globals = Registry::get('Phile_Settings');
     if (!isset($globals['plugins'][$pluginKey])) {
         $globals['plugins'][$pluginKey] = [];
     }
     // settings precedence: global > default > class
     $this->settings = array_replace_recursive($this->settings, $defaults, $globals['plugins'][$pluginKey]);
     // backwards compatibility to Phile 1.4
     $this->injectSettings($this->settings);
     $globals['plugins'][$pluginKey]['settings'] = $this->settings;
     Registry::set('Phile_Settings', $globals);
 }
Exemplo n.º 2
0
 /**
  * get formatted date
  *
  * @return bool|null|string
  */
 public function getFormattedDate()
 {
     $config = Registry::get('Phile_Settings');
     if (isset($this->data['date'])) {
         return date($config['date_format'], strtotime($this->data['date']));
     }
     return null;
 }
Exemplo n.º 3
0
 /**
  * the constructor
  */
 public function __construct($settings = null)
 {
     if ($settings === null) {
         $settings = Registry::get('Phile_Settings');
     }
     $this->settings = $settings;
     if (ServiceLocator::hasService('Phile_Cache')) {
         $this->cache = ServiceLocator::getService('Phile_Cache');
     }
 }
Exemplo n.º 4
0
 /**
  * get formatted date
  *
  * @return bool|null|string
  */
 public function getFormattedDate()
 {
     $config = Registry::get('Phile_Settings');
     if (!isset($this->data['date'])) {
         return null;
     }
     $date = $this->data['date'];
     if (!is_numeric($date)) {
         $date = strtotime($date);
     }
     return date($config['date_format'], $date);
 }
Exemplo n.º 5
0
 /**
  * get template vars
  *
  * @return array|mixed
  * @throws \Exception
  */
 protected function getTemplateVars()
 {
     $repository = new Repository($this->settings);
     $defaults = ['content' => $this->page->getContent(), 'meta' => $this->page->getMeta(), 'current_page' => $this->page, 'base_dir' => rtrim(ROOT_DIR, '/'), 'base_url' => $this->settings['base_url'], 'config' => $this->settings, 'content_dir' => CONTENT_DIR, 'content_url' => $this->settings['base_url'] . '/' . basename(CONTENT_DIR), 'pages' => $repository->findAll(), 'site_title' => $this->settings['site_title'], 'theme_dir' => THEMES_DIR . $this->settings['theme'], 'theme_url' => $this->settings['base_url'] . '/' . basename(THEMES_DIR) . '/' . $this->settings['theme']];
     /** @var array $templateVars */
     $templateVars = Registry::get('templateVars');
     $templateVars += $defaults;
     return $templateVars;
 }