Example #1
0
 /**
  * Static method to get current site
  *
  * @param  int $id
  * @return \ArrayObject
  */
 public static function getSite($id = null)
 {
     $siteAry = array();
     if (null !== $id) {
         $site = (int) $id > 0 ? static::findById((int) $id) : static::findBy(array('document_root' => $_SERVER['DOCUMENT_ROOT']));
     } else {
         $site = static::findBy(array('document_root' => $_SERVER['DOCUMENT_ROOT']));
     }
     if (isset($site->id)) {
         $siteAry['id'] = $site->id;
         $siteAry['domain'] = $site->domain;
         $siteAry['document_root'] = $site->document_root;
         $siteAry['base_path'] = $site->base_path;
         $siteAry['force_ssl'] = $site->force_ssl;
         $siteAry['live'] = $site->live;
     } else {
         $siteAry['id'] = 0;
         $siteAry['domain'] = $_SERVER['HTTP_HOST'];
         $siteAry['document_root'] = $_SERVER['DOCUMENT_ROOT'];
         $siteAry['base_path'] = BASE_PATH;
         $siteAry['force_ssl'] = (int) \Phire\Table\Config::findById('force_ssl')->value;
         $siteAry['live'] = (int) \Phire\Table\Config::findById('live')->value;
     }
     return new \ArrayObject($siteAry, \ArrayObject::ARRAY_AS_PROPS);
 }
Example #2
0
 /**
  * Initialize the application
  *
  * @param  Application $application
  * @throws Exception
  * @return Module
  */
 public function register(Application $application)
 {
     parent::register($application);
     // Set the database
     if ($this->application->services()->isAvailable('database')) {
         Record::setDb($this->application->getService('database'));
         $db = count($this->application->getService('database')->getTables()) > 0;
     } else {
         $db = false;
     }
     $this->application->mergeConfig(['db' => $db]);
     // Load assets, if they haven't been loaded already
     $this->loadAssets(__DIR__ . '/../data/assets', 'phire');
     if ($db) {
         $systemTheme = Table\Config::findById('system_theme')->value;
         if (file_exists(CONTENT_ABS_PATH . '/phire/themes/' . $systemTheme)) {
             $this->loadAssets(CONTENT_ABS_PATH . '/phire/themes/' . $systemTheme, $systemTheme);
         } else {
             if (file_exists(__DIR__ . '/../data/themes/' . $systemTheme)) {
                 $this->loadAssets(__DIR__ . '/../data/themes/' . $systemTheme, $systemTheme);
             }
         }
     } else {
         $this->loadAssets(__DIR__ . '/../data/themes/default', 'default');
     }
     sort($this->assets['js']);
     sort($this->assets['css']['link']);
     sort($this->assets['css']['import']);
     // Load any custom/override assets
     $this->loadAssets(CONTENT_ABS_PATH . '/phire/assets', 'phire-custom', true);
     // Check PHP version
     if (version_compare(PHP_VERSION, '5.4.0') < 0) {
         throw new Exception('Error: Phire CMS requires PHP 5.4.0 or greater.');
     }
     // Add route params for the controllers
     if (null !== $this->application->router()) {
         $this->application->router()->addControllerParams('*', ['application' => $this->application, 'request' => new Request(), 'response' => new Response()]);
     }
     // Set up triggers to check the application session
     $this->application->on('app.route.pre', 'Phire\\Event\\Ssl::check', 1000)->on('app.route.post', 'Phire\\Event\\Db::check', 1000)->on('app.dispatch.pre', 'Phire\\Event\\Session::check', 1001)->on('app.dispatch.pre', 'Phire\\Event\\Acl::check', 1000);
     // Add roles to user nav
     $this->addRoles();
     // Register modules
     $this->registerModules();
     return $this;
 }
Example #3
0
 /**
  * Send install notification email to user
  *
  * @param  \Phire\Form\User $form
  * @return void
  */
 public static function send(\Phire\Form\User $form)
 {
     $i18n = Table\Config::getI18n();
     // Get the domain
     $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
     // Set the recipient
     $rcpt = array('name' => $form->username, 'email' => $form->email1, 'url' => 'http://' . $_SERVER['HTTP_HOST'] . BASE_PATH, 'login' => 'http://' . $_SERVER['HTTP_HOST'] . BASE_PATH . APP_URI, 'domain' => $domain);
     $config = \Phire\Table\Config::findById('system_email');
     $config->value = $form->email1;
     $config->update();
     $config = \Phire\Table\Config::findById('reply_email');
     $config->value = 'noreply@' . $domain;
     $config->update();
     if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/themes/phire/mail')) {
         $mailTmpl = file_get_contents($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/themes/phire/mail/install.txt');
     } else {
         $mailTmpl = file_get_contents(__DIR__ . '/../../../view/phire/mail/install.txt');
     }
     $mailTmpl = str_replace(array('Dear', 'Thank you for installing Phire CMS for', 'The website will be viewable here:', 'To manage the website, you can login to Phire here:', 'Thank You'), array($i18n->__('Dear'), $i18n->__('Thank you for installing Phire CMS for'), $i18n->__('The website will be viewable here:'), $i18n->__('To manage the website, you can login to Phire here:'), $i18n->__('Thank You')), $mailTmpl);
     // Send email verification
     $mail = new Mail($domain . ' - ' . $i18n->__('Phire CMS Installation'), $rcpt);
     $mail->from('noreply@' . $domain);
     $mail->setText($mailTmpl);
     $mail->send();
 }
Example #4
0
 /**
  * Perform update
  *
  * @param array   $post
  * @param boolean $cli
  * @return void
  */
 public function getUpdate($post = array(), $cli = false)
 {
     $docRoot = __DIR__ . '/../../../../../..';
     // If system is writable for updates
     if (!isset($post['submit'])) {
         switch ($post['type']) {
             case 'system':
                 $remoteFile = 'http://update.phirecms.org/system/latest.' . $post['format'];
                 break;
             case 'module':
                 $remoteFile = 'http://update.phirecms.org/modules/' . strtolower($post['name']) . '/latest.' . $post['format'];
                 break;
             case 'theme':
                 $remoteFile = 'http://update.phirecms.org/themes/' . strtolower($post['name']) . '/latest.' . $post['format'];
                 break;
         }
         $remoteContents = @file_get_contents($remoteFile);
         if ($remoteContents !== false) {
             $localFile = $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format'];
             file_put_contents($localFile, $remoteContents);
             $arc = new \Pop\Archive\Archive($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']);
             $arc->extract($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update');
             unlink($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']);
             $msg = null;
             if ($post['type'] == 'module') {
                 if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name'])) {
                     $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']);
                     $dir->emptyDir(null, true);
                     rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']);
                 }
                 $msg = $this->i18n->__('The %1 module has been updated.', $post['name']);
             } else {
                 if ($post['type'] == 'theme') {
                     if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name'])) {
                         $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']);
                         $dir->emptyDir(null, true);
                         rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']);
                     }
                     $msg = $this->i18n->__('The %1 theme has been updated.', $post['name']);
                 } else {
                     if ($post['type'] == 'system') {
                         if ($cli) {
                             rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms', $docRoot . DIRECTORY_SEPARATOR . 'phire-cms-new');
                             $config = Table\Config::findById('updated_on');
                             $config->value = date('Y-m-d H:i:s');
                             $config->update();
                             $msg = $this->i18n->__('The system has been updated.');
                         } else {
                             $time = time();
                             mkdir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time);
                             // Move old files into archive folder
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'config', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'config');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'module', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'module');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'script', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'script');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'vendor', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . $time . DIRECTORY_SEPARATOR . 'vendor');
                             // Move new files into main application path
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'config', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'config');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'module', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'module');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'script', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'script');
                             rename($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms' . DIRECTORY_SEPARATOR . 'vendor', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . APP_PATH . DIRECTORY_SEPARATOR . 'vendor');
                             $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'phire-cms');
                             $dir->emptyDir(null, true);
                             $config = Table\Config::findById('updated_on');
                             $config->value = date('Y-m-d H:i:s');
                             $config->update();
                             $msg = $this->i18n->__('The system has been updated.');
                         }
                     }
                 }
             }
             $this->data['msg'] = '<span style="color: #347703">' . $msg . '</span>';
         } else {
             $this->data['error'] = '<span style="color: #a00b0b">' . $this->i18n->__('The update file was not found.') . '</span>';
         }
         // Else use cURL/FTP
     } else {
         unset($post['submit']);
         $curl = new \Pop\Curl\Curl('http://update.phirecms.org/update.php');
         $curl->setPost(true);
         $curl->setFields($post);
         $curl->execute();
         $response = json_decode($curl->getBody());
         unset($curl);
         if ($response->error == 0) {
             $arc = new \Pop\Archive\Archive($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']);
             $arc->extract($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update');
             unlink($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update' . DIRECTORY_SEPARATOR . 'latest.' . $post['format']);
             if ($post['type'] == 'system') {
                 chmod($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/phire-cms', 0777);
             } else {
                 if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'])) {
                     chmod($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], 0777);
                 }
             }
             $post['complete'] = 1;
             $curl = new \Pop\Curl\Curl('http://update.phirecms.org/update.php');
             $curl->setPost(true);
             $curl->setFields($post);
             $curl->execute();
             $complete = json_decode($curl->getBody());
             if ($complete->error == 0) {
                 switch ($complete->type) {
                     case 'system':
                         $config = Table\Config::findById('updated_on');
                         $config->value = date('Y-m-d H:i:s');
                         $config->update();
                         $msg = $this->i18n->__('The system has been updated.');
                         chmod($docRoot . APP_PATH, 0755);
                         break;
                     case 'module':
                         if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name'])) {
                             $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']);
                             $dir->emptyDir(null, true);
                             rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'modules' . DIRECTORY_SEPARATOR . $post['name']);
                         }
                         $msg = $this->i18n->__('The %1 module has been updated.', $complete->name);
                         break;
                     case 'theme':
                         if (file_exists($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name'])) {
                             $dir = new Dir($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']);
                             $dir->emptyDir(null, true);
                             rename($docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'update/' . $post['name'], $docRoot . CONTENT_PATH . DIRECTORY_SEPARATOR . 'extensions' . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $post['name']);
                         }
                         $msg = $this->i18n->__('The %1 theme has been updated.', $complete->name);
                         break;
                 }
                 $this->data['msg'] = '<span style="color: #347703">' . $msg . '</span>';
             } else {
                 $this->data['error'] = '<span style="color: #a00b0b">' . $complete->message . '</span>';
             }
         } else {
             $this->data['error'] = '<span style="color: #a00b0b">' . $response->message . '</span>';
         }
     }
     $this->postUpdate($post);
 }
Example #5
0
 /**
  * Log a user login
  *
  * @param \Phire\Table\UserTypes $type
  * @param \Phire\Table\Users     $user
  * @return void
  */
 protected function log($type, $user)
 {
     $exclude = array();
     if ($type->log_exclude != '') {
         $exclude = explode(',', $type->log_exclude);
     }
     $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
     if (!in_array($_SERVER['REMOTE_ADDR'], $exclude)) {
         $emails = explode(',', $type->log_emails);
         $noreply = Table\Config::findById('reply_email')->value;
         $options = array('subject' => 'Phire CMS ' . ucfirst(strtolower($type->type)) . ' ' . $this->i18n->__('Login Notification') . ' (' . $domain . ')', 'headers' => array('From' => $noreply . ' <' . $noreply . '>', 'Reply-To' => $noreply . ' <' . $noreply . '>'));
         $msg = $this->i18n->__('Someone has logged in as a %1 from %2 using %3.', array(strtolower($type->type), $_SERVER['REMOTE_ADDR'], $user->username));
         $logger = new Log\Logger(new Log\Writer\Mail($emails));
         $logger->notice($msg, $options);
     }
 }
Example #6
0
<?php

/**
 * Module Name: phire-cache
 * Author: Nick Sagona
 * Description: This is the cache module for Phire CMS 2
 * Version: 1.0
 */
return ['phire-cache' => ['prefix' => 'Phire\\Cache\\', 'src' => __DIR__ . '/../src', 'routes' => include 'routes.php', 'resources' => include 'resources.php', 'nav.module' => ['name' => 'Cache Config', 'href' => '/cache', 'acl' => ['resource' => 'cache', 'permission' => 'index']], 'events' => [['name' => 'app.route.post', 'action' => 'Phire\\Cache\\Event\\Cache::load', 'priority' => 1000], ['name' => 'app.dispatch.post', 'action' => 'Phire\\Cache\\Event\\Cache::save', 'priority' => 1000]], 'install' => function () {
    mkdir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/cache');
    chmod($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/cache', 0777);
    copy($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/index.html', $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/cache/index.html');
    chmod($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/cache/index.html', 0777);
}, 'uninstall' => function () {
    $config = \Phire\Table\Config::findById('cache_adapter');
    if (isset($config->setting)) {
        $config->delete();
    }
    $config = \Phire\Table\Config::findById('cache_lifetime');
    if (isset($config->setting)) {
        $config->delete();
    }
    if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/cache')) {
        $dir = new \Pop\File\Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/cache');
        $dir->emptyDir(true);
    }
}, 'exclude' => []]];
Example #7
0
<?php

/**
 * Module Name: phire-seo
 * Author: Nick Sagona
 * Description: This is the SEO media module for Phire CMS 2
 * Version: 1.0
 */
return ['phire-seo' => ['prefix' => 'Phire\\Seo\\', 'src' => __DIR__ . '/../src', 'routes' => include 'routes.php', 'resources' => include 'resources.php', 'nav.module' => ['name' => 'SEO', 'href' => '/seo', 'acl' => ['resource' => 'seo', 'permission' => 'index']], 'events' => [['name' => 'app.route.pre', 'action' => 'Phire\\Seo\\Event\\Seo::bootstrap', 'priority' => 1000], ['name' => 'app.send.pre', 'action' => 'Phire\\Seo\\Event\\Seo::init', 'priority' => 1000], ['name' => 'app.send.post', 'action' => 'Phire\\Seo\\Event\\Seo::parse', 'priority' => 1000]], 'exclude' => [], 'install' => function () {
    $config = new \Phire\Table\Config(['setting' => 'seo_config', 'value' => '']);
    $config->save();
    $config = new \Phire\Table\Config(['setting' => 'seo_analysis', 'value' => '']);
    $config->save();
}, 'uninstall' => function () {
    $config = \Phire\Table\Config::findById('seo_config');
    if (isset($config->setting)) {
        $config->delete();
    }
    $config = \Phire\Table\Config::findById('seo_analysis');
    if (isset($config->setting)) {
        $config->delete();
    }
}]];
Example #8
0
 /**
  * Save the config data
  *
  * @param  array $post
  * @return void
  */
 public function save(array $post)
 {
     $config = Table\Config::findById('domain');
     if (isset($_SERVER['HTTP_HOST']) && $config->value != $_SERVER['HTTP_HOST']) {
         $config->value = $_SERVER['HTTP_HOST'];
         $config->save();
     }
     $config = Table\Config::findById('document_root');
     if (isset($_SERVER['DOCUMENT_ROOT']) && $config->value != $_SERVER['DOCUMENT_ROOT']) {
         $config->value = $_SERVER['DOCUMENT_ROOT'];
         $config->save();
     }
     if (!empty($post['datetime_format_custom']) && $post['datetime_format'] == 'custom') {
         $dateFormatValue = str_replace(['"', "'"], ['', ''], strip_tags($post['datetime_format_custom']));
     } else {
         if (!empty($post['datetime_format']) && $post['datetime_format'] != 'custom') {
             $dateFormatValue = $post['datetime_format'];
         } else {
             $dateFormatValue = 'M j Y';
         }
     }
     $config = Table\Config::findById('datetime_format');
     $config->value = $dateFormatValue;
     $config->save();
     $config = Table\Config::findById('pagination');
     $config->value = (int) $post['pagination'];
     $config->save();
     $config = Table\Config::findById('system_theme');
     $oldValue = $config->value;
     $config->value = $post['system_theme'];
     $config->save();
     if (isset($_SERVER['DOCUMENT_ROOT']) && file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $oldValue)) {
         $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/assets/' . $oldValue);
         $dir->emptyDir(true);
     }
 }
Example #9
0
 /**
  * Send installation confirmation
  *
  * @param  Table\Users
  * @return void
  */
 public function sendConfirmation($user)
 {
     $domain = str_replace('www.', '', $_SERVER['HTTP_HOST']);
     $schema = isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
     // Set the recipient
     $rcpt = ['name' => $user->username, 'email' => $user->email, 'login' => $schema . $_SERVER['HTTP_HOST'] . BASE_PATH . APP_URI . '/login', 'domain' => $domain];
     // Check for an override template
     $mailTemplate = file_exists(CONTENT_ABS_PATH . '/phire/view/phire/mail/install.txt') ? CONTENT_ABS_PATH . '/phire/view/phire/mail/install.txt' : __DIR__ . '/../../view/phire/mail/install.txt';
     // Send email verification
     $mail = new Mail($domain . ' - Phire CMS Installation', $rcpt);
     $mail->from('noreply@' . $domain);
     $mail->setText(file_get_contents($mailTemplate));
     $mail->send();
     // Save domain
     $config = Table\Config::findById('domain');
     $config->value = $_SERVER['HTTP_HOST'];
     $config->save();
     // Save document root
     $config = Table\Config::findById('document_root');
     $config->value = $_SERVER['DOCUMENT_ROOT'];
     $config->save();
     // Save install timestamp
     $config = Table\Config::findById('installed_on');
     $config->value = (string) date('Y-m-d H:i:s');
     $config->save();
     $this->sendStats();
 }
Example #10
0
 /**
  * Method for post update code for Phire or for a module,
  * usually for database modification or file cleanup
  *
  * @return void
  */
 public function runPost()
 {
     $i = count($this->previousUpdates) > 0 ? max($this->previousUpdates) + 1 : 1;
     $method = 'update' . $i;
     while (method_exists($this, $method)) {
         $this->{$method}();
         $this->previousUpdates[] = $i;
         $i++;
         $method = 'update' . $i;
     }
     if (null === $this->module) {
         $updates = Table\Config::findById('updates');
         $updates->value = implode('|', $this->previousUpdates);
         $updates->save();
         $updated = Table\Config::findById('updated_on');
         $updated->value = date('Y-m-d H:i:s');
         $updated->save();
     } else {
         $module = Table\Modules::findBy(['name' => $this->module]);
         if (isset($module->id)) {
             $module->updates = implode('|', $this->previousUpdates);
             $module->updated_on = date('Y-m-d H:i:s');
             $module->save();
         }
     }
 }
Example #11
0
 /**
  * Send user unsubscribe notification
  *
  * @param  Table\Users $user
  * @return void
  */
 protected function sendUnsubscribe(Table\Users $user)
 {
     $host = Table\Config::findById('domain')->value;
     $domain = str_replace('www.', '', $host);
     // Set the recipient
     $rcpt = ['name' => $user->username, 'email' => $user->email, 'domain' => $domain];
     // Check for an override template
     $mailTemplate = file_exists(CONTENT_ABS_PATH . '/phire/view/phire/mail/unsubscribe.txt') ? CONTENT_ABS_PATH . '/phire/view/phire/mail/unsubscribe.txt' : __DIR__ . '/../../view/phire/mail/unsubscribe.txt';
     // Send email verification
     $mail = new Mail($domain . ' - Unsubscribed', $rcpt);
     $mail->from('noreply@' . $domain);
     $mail->setText(file_get_contents($mailTemplate));
     $mail->send();
 }
Example #12
0
 /**
  * Build social nav
  *
  * @return mixed
  */
 public function buildNav()
 {
     $nav = null;
     $hasUrl = false;
     $config = Table\Config::findById('social_config');
     if (isset($config->value) && !empty($config->value) && $config->value != '') {
         $cfg = unserialize($config->value);
         $style = $cfg['style'];
         $this->data = array_merge($this->data, $cfg);
         switch ($cfg['size']) {
             case 'large':
                 $size = 64;
                 break;
             case 'medium':
                 $size = 48;
                 break;
             default:
                 $size = 32;
         }
         $nav = new Child('nav');
         $nav->setAttribute('class', 'social-media-' . $size);
         foreach ($cfg['order'] as $name) {
             if (!empty($cfg['urls'][$name]['url']) && $cfg['urls'][$name]['url'] != '') {
                 $a = new Child('a', ucfirst($name));
                 $a->setAttributes(['class' => $name . '-' . $size . '-' . $style, 'href' => $cfg['urls'][$name]['url']]);
                 if ($cfg['urls'][$name]['new']) {
                     $a->setAttribute('target', '_blank');
                 }
                 $nav->addChild($a);
                 $hasUrl = true;
             }
         }
         if (!$hasUrl) {
             $nav = null;
         }
     }
     return $nav;
 }
Example #13
0
 /**
  * Save cache config
  *
  * @param  array $post
  * @return void
  */
 public function save(array $post)
 {
     if (isset($post['cache_status'])) {
         $config = Table\Config::findById('cache_status');
         if (isset($config->value)) {
             $config->value = (int) $post['cache_status'];
         } else {
             $config = new Table\Config(['setting' => 'cache_status', 'value' => (int) $post['cache_status']]);
         }
         $config->save();
     }
     $oldAdapter = null;
     if (isset($post['cache_adapter']) && !empty($post['cache_adapter'])) {
         $config = Table\Config::findById('cache_adapter');
         if (isset($config->value)) {
             $oldAdapter = $config->value;
             $config->value = $post['cache_adapter'];
             if ($oldAdapter != $post['cache_adapter']) {
                 $this->clear();
             }
         } else {
             $config = new Table\Config(['setting' => 'cache_adapter', 'value' => $post['cache_adapter']]);
         }
         $config->save();
     }
     $lifetime = null;
     if (isset($post['cache_lifetime_value']) && !empty($post['cache_lifetime_value']) && isset($post['cache_lifetime_unit']) && !empty($post['cache_lifetime_unit'])) {
         switch ($post['cache_lifetime_unit']) {
             case 'Days':
                 $lifetime = round($post['cache_lifetime_value'] * 86400, 1);
                 break;
             case 'Hours':
                 $lifetime = round($post['cache_lifetime_value'] * 3600, 1);
                 break;
             case 'Minutes':
                 $lifetime = round($post['cache_lifetime_value'] * 60, 1);
                 break;
         }
     }
     if (null !== $lifetime) {
         $config = Table\Config::findById('cache_lifetime');
         if (isset($config->value)) {
             $config->value = $lifetime;
         } else {
             $config = new Table\Config(['setting' => 'cache_lifetime', 'value' => $lifetime]);
         }
         $config->save();
     }
     if (isset($post['cache_clear']) && $post['cache_clear']) {
         $this->clear();
     }
 }
Example #14
0
 /**
  * Build social nav
  *
  * @param  string $description
  * @param  string $keywords
  * @return mixed
  */
 public function buildMetaTags($description = null, $keywords = null)
 {
     $metas = null;
     $hasDesc = false;
     $hasKeys = false;
     $config = Table\Config::findById('seo_config');
     if (isset($config->value) && !empty($config->value) && $config->value != '') {
         $cfg = unserialize($config->value);
         if (count($cfg['meta']) > 0) {
             foreach ($cfg['meta'] as $meta) {
                 $content = $meta['content'];
                 if ($meta['name'] == 'description') {
                     $hasDesc = true;
                     if (null !== $description && $description != '') {
                         $content = $description;
                     }
                 }
                 if ($meta['name'] == 'keywords') {
                     $hasKeys = true;
                     if (null !== $keywords && $keywords != '') {
                         $content = $keywords;
                     }
                 }
                 $m = new Child('meta');
                 $m->setAttributes(['name' => $meta['name'], 'content' => htmlentities($content, ENT_QUOTES, 'UTF-8')]);
                 $metas .= '    ' . (string) $m;
             }
             if (!$hasDesc && null !== $description && $description != '') {
                 $m = new Child('meta');
                 $m->setAttributes(['name' => 'description', 'content' => htmlentities($description, ENT_QUOTES, 'UTF-8')]);
                 $metas .= '    ' . (string) $m;
             }
             if (!$hasKeys && null !== $keywords && $keywords != '') {
                 $m = new Child('meta');
                 $m->setAttributes(['name' => 'keywords', 'content' => htmlentities($keywords, ENT_QUOTES, 'UTF-8')]);
                 $metas .= '    ' . (string) $m;
             }
         }
     }
     if (null === $metas) {
         if (null !== $description && $description != '') {
             $m = new Child('meta');
             $m->setAttributes(['name' => 'description', 'content' => htmlentities($description, ENT_QUOTES, 'UTF-8')]);
             $metas .= '    ' . (string) $m;
         }
         if (null !== $keywords && $keywords != '') {
             $m = new Child('meta');
             $m->setAttributes(['name' => 'keywords', 'content' => htmlentities($keywords, ENT_QUOTES, 'UTF-8')]);
             $metas .= '    ' . (string) $m;
         }
     }
     return $metas;
 }
Example #15
0
<?php

/**
 * Module Name: phire-social
 * Author: Nick Sagona
 * Description: This is the social media module for Phire CMS 2
 * Version: 1.0
 */
return ['phire-social' => ['prefix' => 'Phire\\Social\\', 'src' => __DIR__ . '/../src', 'routes' => include 'routes.php', 'resources' => include 'resources.php', 'nav.module' => ['name' => 'Social Media', 'href' => '/social', 'acl' => ['resource' => 'social', 'permission' => 'index']], 'events' => [['name' => 'app.send.pre', 'action' => 'Phire\\Social\\Event\\Social::init', 'priority' => 1000], ['name' => 'app.send.post', 'action' => 'Phire\\Social\\Event\\Social::parse', 'priority' => 1000]], 'install' => function () {
    $config = new \Phire\Table\Config(['setting' => 'social_config', 'value' => '']);
    $config->save();
}, 'uninstall' => function () {
    $config = \Phire\Table\Config::findById('social_config');
    if (isset($config->setting)) {
        $config->delete();
    }
}]];