저자: Nick Sagona, III (dev@nolainteractive.com)
상속: implements ArrayAccess
예제 #1
0
 /**
  * Bootstrap the module
  *
  * @param  Application $application
  * @return void
  */
 public static function bootstrap(Application $application)
 {
     $path = BASE_PATH . APP_URI;
     if ($path == '') {
         $path = '/';
     }
     $cookie = Cookie::getInstance(['path' => $path]);
     if (isset($cookie->phire)) {
         $phire = (array) $cookie->phire;
         if (!isset($phire['fields_media_library'])) {
             $phire['fields_media_library'] = $application->module('phire-fields')->config()['media_library'];
         }
         $cookie->set('phire', $phire);
     }
     $modules = $application->modules();
     $roles = \Phire\Table\Roles::findAll();
     foreach ($roles->rows() as $role) {
         if (isset($modules['phire-fields']) && isset($modules['phire-fields']->config()['models']) && isset($modules['phire-fields']->config()['models']['Phire\\Model\\User']) && isset($modules['phire-fields']->config()['models']['Phire\\Model\\Role'])) {
             $models = $modules['phire-fields']->config()['models'];
             $models['Phire\\Model\\User'][] = ['type_field' => 'role_id', 'type_value' => $role->id, 'type_name' => $role->name];
             $models['Phire\\Model\\Role'][] = ['type_field' => 'id', 'type_value' => $role->id, 'type_name' => $role->name];
             $application->module('phire-fields')->mergeConfig(['models' => $models]);
         }
     }
     foreach ($modules as $module => $config) {
         if ($module != 'phire-fields' && isset($config['models'])) {
             $application->module('phire-fields')->mergeConfig(['models' => $config['models']]);
         }
     }
 }
예제 #2
0
<?php

require_once '../../bootstrap.php';
use Pop\Web\Cookie;
try {
    $ary = array('foo' => 'bar', 'baz' => array('some' => 'thing else'));
    $cookie = Cookie::getInstance();
    $cookie->set('username', 'yourname')->set('email', '*****@*****.**')->set('myary', $ary);
    print_r($cookie);
    print_r($_COOKIE);
    echo $cookie->username . PHP_EOL . PHP_EOL;
    print_r($cookie->myary);
    // Quickly unset a cookie
    // unset($cookie->email);
    // Specifically delete a cookie, with options
    //$cookie->delete('username', array('path' => '/'));
    // Clear all cookies, with options
    //$cookie->clear(array('path' => '/'));
} catch (\Exception $e) {
    echo $e->getMessage() . PHP_EOL . PHP_EOL;
}
예제 #3
0
 /**
  * Process themes method
  *
  * @param  array $post
  * @return void
  */
 public function processModules($post)
 {
     foreach ($post as $key => $value) {
         if (strpos($key, 'module_active_') !== false) {
             $id = substr($key, strrpos($key, '_') + 1);
             $ext = Table\Extensions::findById($id);
             if (isset($ext->id)) {
                 $ext->active = (int) $value;
                 $ext->save();
             }
         }
     }
     $path = BASE_PATH . APP_URI;
     if ($path == '') {
         $path = '/';
     }
     $modulePath1 = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH . '/extensions/modules';
     $modulePath2 = __DIR__ . '/../../../../../module';
     $phireCookie = null;
     if (php_sapi_name() != 'cli') {
         $cookie = Cookie::getInstance(array('path' => $path));
         if (isset($cookie->phire)) {
             if (null === $phireCookie) {
                 $phireCookie = $cookie->phire;
             }
         }
     }
     if (isset($post['remove_modules'])) {
         foreach ($post['remove_modules'] as $id) {
             $ext = Table\Extensions::findById($id);
             if (isset($ext->id)) {
                 $modPath = file_exists($modulePath1 . '/' . $ext->file) ? $modulePath1 : $modulePath2;
                 $assets = unserialize($ext->assets);
                 if (count($assets['tables']) > 0) {
                     $db = Table\Extensions::getDb();
                     if (DB_INTERFACE == 'Mysqli' || DB_TYPE == 'mysql') {
                         $db->adapter()->query('SET foreign_key_checks = 0;');
                         foreach ($assets['tables'] as $table) {
                             $db->adapter()->query('DROP TABLE ' . $table);
                         }
                         $db->adapter()->query('SET foreign_key_checks = 1;');
                     } else {
                         if (DB_INTERFACE == 'Pgsql' || DB_TYPE == 'pgsql') {
                             foreach ($assets['tables'] as $table) {
                                 $db->adapter()->query('DROP TABLE ' . $table . ' CASCADE');
                             }
                         } else {
                             foreach ($assets['tables'] as $table) {
                                 $db->adapter()->query('DROP TABLE ' . $table);
                             }
                         }
                     }
                 }
                 $contentPath = $_SERVER['DOCUMENT_ROOT'] . BASE_PATH . CONTENT_PATH;
                 $exts = array('.zip', '.tar.gz', '.tar.bz2', '.tgz', '.tbz', '.tbz2');
                 // Check for a config and remove function
                 if (file_exists($modPath . '/' . $ext->name . '/config') && file_exists($modPath . '/' . $ext->name . '/config/module.php')) {
                     $config = (include $modPath . '/' . $ext->name . '/config/module.php');
                     if (null !== $config[$ext->name]->remove) {
                         $removeFunc = $config[$ext->name]->remove;
                         $removeFunc();
                     }
                 }
                 if (file_exists($contentPath . '/extensions/modules/' . $ext->name)) {
                     $dir = new Dir($contentPath . '/extensions/modules/' . $ext->name);
                     $dir->emptyDir(null, true);
                 }
                 foreach ($exts as $e) {
                     if (file_exists($contentPath . '/extensions/modules/' . $ext->name . $e) && is_writable($contentPath . '/extensions/modules/' . $ext->name . $e)) {
                         unlink($contentPath . '/extensions/modules/' . $ext->name . $e);
                     }
                 }
                 if (file_exists(__DIR__ . '/../../../../../module/' . $ext->name)) {
                     $dir = new Dir(__DIR__ . '/../../../../../module/' . $ext->name);
                     $dir->emptyDir(null, true);
                 }
                 foreach ($exts as $e) {
                     if (file_exists(__DIR__ . '/../../../../../module/' . $ext->name . $e) && is_writable(__DIR__ . '/../../../../../module/' . $ext->name . $e)) {
                         unlink(__DIR__ . '/../../../../../module/' . $ext->name . $e);
                     }
                 }
                 if (file_exists($contentPath . '/assets/' . strtolower($ext->name))) {
                     $dir = new Dir($contentPath . '/assets/' . strtolower($ext->name));
                     $dir->emptyDir(null, true);
                 }
                 if (null !== $phireCookie) {
                     foreach ($phireCookie->modules as $key => $value) {
                         if ($value->name == $ext->name) {
                             $modules = (array) $phireCookie->modules;
                             unset($modules[$key]);
                             $phireCookie->modules = $modules;
                         }
                     }
                 }
                 $ext->delete();
             }
         }
     }
     if (null !== $phireCookie) {
         $cookie = Cookie::getInstance(array('path' => $path));
         $cookie->set('phire', $phireCookie);
     }
 }
예제 #4
0
 /**
  * Logout action method
  *
  * @return void
  */
 public function logout()
 {
     $this->sess->kill();
     $path = BASE_PATH . APP_URI;
     if ($path == '') {
         $path = '/';
     }
     $cookie = Cookie::getInstance(['path' => $path]);
     $cookie->delete('phire');
     $this->redirect(BASE_PATH . APP_URI . '/login');
 }
예제 #5
0
<?php

/**
 * Module Name: phire-sessions
 * Author: Nick Sagona
 * Description: This is the sessions module for Phire CMS 2
 * Version: 1.0
 */
return ['phire-sessions' => ['prefix' => 'Phire\\Sessions\\', 'src' => __DIR__ . '/../src', 'routes' => include 'routes.php', 'resources' => include 'resources.php', 'forms' => include 'forms.php', 'nav.phire' => ['sessions' => ['name' => 'Sessions', 'href' => '/sessions', 'acl' => ['resource' => 'sessions', 'permission' => 'index'], 'attributes' => ['class' => 'sessions-nav-icon'], 'children' => ['logins' => ['name' => 'Logins', 'href' => 'logins', 'acl' => ['resource' => 'sessions', 'permission' => 'logins']]]]], 'nav.module' => ['name' => 'Sessions Config', 'href' => '/sessions/config', 'acl' => ['resource' => 'sessions-config', 'permission' => 'index']], 'events' => [['name' => 'app.send.pre', 'action' => 'Phire\\Sessions\\Event\\UserSession::login'], ['name' => 'app.send.pre', 'action' => 'Phire\\Sessions\\Event\\UserSession::dashboard'], ['name' => 'app.dispatch.pre', 'action' => 'Phire\\Sessions\\Event\\UserSession::logout']], 'uninstall' => function () {
    if (isset($_SERVER['REMOTE_ADDR'])) {
        $path = BASE_PATH . APP_URI;
        if ($path == '') {
            $path = '/';
        }
        $cookie = \Pop\Web\Cookie::getInstance(['path' => $path]);
        $cookie->delete('phire_session_timeout');
        $cookie->delete('phire_session_path');
        $sess = \Pop\Web\Session::getInstance();
        if (isset($sess->user) && isset($sess->user->session)) {
            unset($sess->user->session);
        }
    }
}, 'header' => __DIR__ . '/../view/phire/header.phtml', 'footer' => __DIR__ . '/../view/phire/footer.phtml', 'clear_sessions' => 86400, 'multiple_session_warning' => false, 'login_limit' => 500]];
예제 #6
0
 /**
  * Logout method
  *
  * @param  boolean $redirect
  * @return void
  */
 public function logout($redirect = true)
 {
     // Destroy the session database entry
     if (null !== $this->sess->user->sess_id) {
         $session = Table\UserSessions::findById($this->sess->user->sess_id);
         if (isset($session->id)) {
             $session->delete();
         }
     }
     // Destroy the session object.
     unset($this->sess->user);
     // Delete the phire cookie
     $path = BASE_PATH . APP_URI;
     if ($path == '') {
         $path = '/';
     }
     $cookie = Cookie::getInstance(array('path' => $path));
     $cookie->delete('phire');
     if ($redirect) {
         $uri = $this->basePath == '' ? '/' : $this->basePath;
         \Pop\Http\Response::redirect($uri);
     }
 }
예제 #7
0
 /**
  * Register and load any other modules
  *
  * @param  \Pop\Loader\Autoloader $autoloader
  * @param  boolean                $site
  * @throws Exception
  * @return self
  */
 public function load($autoloader, $site = false)
 {
     if ($site) {
         $s = Table\Sites::getSite();
         $docRoot = $s->document_root;
         $basePath = $s->base_path;
     } else {
         $docRoot = $_SERVER['DOCUMENT_ROOT'];
         $basePath = BASE_PATH;
     }
     $events = array();
     // Load Phire any overriding Phire configuration
     if (!$site) {
         $this->loadAssets(__DIR__ . '/../../../Phire/data', 'Phire', $docRoot);
     }
     // Check if Phire is installed
     self::isInstalled();
     $sess = Session::getInstance();
     $errors = self::checkDirsQuick($docRoot . $basePath . CONTENT_PATH, true, $docRoot);
     if (count($errors) > 0) {
         $sess->errors = '            ' . implode('<br />' . PHP_EOL . '            ', $errors) . PHP_EOL;
     } else {
         unset($sess->errors);
     }
     $modulesAry = array();
     $modulesDirs = array(__DIR__ . '/../../../', __DIR__ . '/../../../../module/', __DIR__ . '/../../../../..' . CONTENT_PATH . '/extensions/modules/');
     // Check for overriding Phire config
     if (file_exists($docRoot . BASE_PATH . CONTENT_PATH . '/extensions/modules/config/phire.php')) {
         $phireCfg = (include $docRoot . BASE_PATH . CONTENT_PATH . '/extensions/modules/config/phire.php');
         if (isset($phireCfg['Phire'])) {
             // If the overriding config is set to allow changes, merge new nav with the original nav
             // else, the entire original nav will be overwritten with the new nav.
             if (isset($phireCfg['Phire']->nav) && $phireCfg['Phire']->changesAllowed()) {
                 $nav = array_merge($phireCfg['Phire']->nav->asArray(), $this->module('Phire')->nav->asArray());
                 $phireCfg['Phire']->nav = new \Pop\Config($nav);
             }
             $this->module('Phire')->merge($phireCfg['Phire']);
             // Get any Phire event
             if (null !== $this->module('Phire')->events) {
                 $events['Phire'] = $this->module('Phire')->events->asArray();
             }
         }
     }
     // Register and load any other modules
     foreach ($modulesDirs as $directory) {
         if (file_exists($directory) && is_dir($directory)) {
             $dir = new Dir($directory);
             $dirs = $dir->getFiles();
             sort($dirs);
             foreach ($dirs as $d) {
                 $moduleCfg = null;
                 if ($d != 'PopPHPFramework' && $d != 'Phire' && $d != 'config' && $d != 'vendor' && is_dir($directory . $d)) {
                     $ext = Table\Extensions::findBy(array('name' => $d));
                     if (!isset($ext->id) || isset($ext->id) && $ext->active) {
                         $modulesAry[] = $d;
                         // Load assets
                         if (!$site) {
                             $this->loadAssets($directory . $d . '/data', $d, $docRoot);
                         }
                         // Get module config
                         if (file_exists($directory . $d . '/config/module.php')) {
                             $moduleCfg = (include $directory . $d . '/config/module.php');
                         }
                         // Check for any module config overrides
                         if (file_exists($directory . '/config/' . strtolower($d) . '.php')) {
                             $override = (include $directory . '/config/' . strtolower($d) . '.php');
                             if (isset($override[$d]) && null !== $moduleCfg) {
                                 $moduleCfg[$d]->merge($override[$d]);
                             }
                         }
                         // Load module configs
                         if (null !== $moduleCfg) {
                             // Register the module source
                             if (file_exists($moduleCfg[$d]->src)) {
                                 $autoloader->register($d, $moduleCfg[$d]->src);
                             }
                             // Get any module events
                             if (null !== $moduleCfg[$d]->events) {
                                 $events[$d] = $moduleCfg[$d]->events->asArray();
                             }
                             $this->loadModule($moduleCfg);
                         }
                     }
                 }
             }
         }
     }
     // Attach any event hooks
     if (count($events) > 0) {
         foreach ($events as $module => $evts) {
             foreach ($evts as $event => $action) {
                 $act = null;
                 $priority = 0;
                 if (is_array($action)) {
                     if (!isset($action['action'])) {
                         throw new Exception("The 'action' parameter is not set for the '" . $event . "' event within the " . $module . " module configuration file.");
                     }
                     $act = $action['action'];
                     $priority = isset($action['priority']) ? $action['priority'] : 0;
                 } else {
                     $act = $action;
                 }
                 if (null !== $act) {
                     $this->attachEvent($event, $act, $priority);
                 }
             }
         }
     }
     // Add Phire CSS override file if it exists
     if (file_exists($docRoot . BASE_PATH . CONTENT_PATH . '/extensions/themes/phire/css/phire.css')) {
         $this->assets['css'] .= '    <style type="text/css">@import "' . BASE_PATH . CONTENT_PATH . '/extensions/themes/phire/css/phire.css";</style>' . PHP_EOL;
     }
     // If logged in, set Phire path cookie
     if (!$site && isset($sess->user)) {
         $path = BASE_PATH . APP_URI;
         if ($path == '') {
             $path = '/';
         }
         $cookie = Cookie::getInstance(array('path' => $path));
         if (!isset($cookie->phire)) {
             $modsAry = array();
             foreach ($modulesAry as $modName) {
                 $i18n = file_exists($docRoot . BASE_PATH . CONTENT_PATH . '/assets/' . strtolower($modName) . '/i18n');
                 $modsAry[] = array('name' => $modName, 'i18n' => $i18n);
             }
             $cookie->set('phire', array('base_path' => BASE_PATH, 'app_path' => APP_PATH, 'content_path' => CONTENT_PATH, 'app_uri' => APP_URI, 'server_tz_offset' => abs(date('Z')) / 60, 'modules' => $modsAry));
         }
     }
     // Initiate the router object
     $this->loadRouter(new \Pop\Mvc\Router(array(), new \Pop\Http\Request(null, BASE_PATH)));
     return $this;
 }
예제 #8
0
 /**
  * Record logout/session end
  *
  * @param  \Pop\Application $application
  * @return void
  */
 public static function logout(Application $application)
 {
     $sess = $application->getService('session');
     $userUri = APP_URI;
     $key = 'user';
     if (isset($sess->member) && $application->isRegistered('phire-members')) {
         $key = 'member';
         $memberAdmin = new \Phire\Members\Model\MembersAdmin();
         $memberAdmin->getByRoleId($sess->member->role_id);
         if (isset($memberAdmin->uri)) {
             $userUri = $memberAdmin->uri;
         }
     }
     if ($application->router()->getRouteMatch()->getRoute() == $userUri . '/logout') {
         $path = BASE_PATH . APP_URI;
         if ($path == '') {
             $path = '/';
         }
         $cookie = Cookie::getInstance(['path' => $path]);
         $cookie->delete('phire_session_timeout');
         $cookie->delete('phire_session_path');
         $cookie->delete('phire_session_warning_dismiss');
         $sess = $application->getService('session');
         if (isset($sess[$key]) && isset($sess[$key]->session)) {
             $session = Table\UserSessions::findById((int) $sess[$key]->session->id);
             if (isset($session->id)) {
                 $session->delete();
             }
         }
     }
 }
예제 #9
0
 function __construct()
 {
     $this->cookie = C::getInstance();
 }