Пример #1
0
 /**
  * Check if the application requires an SSL connection
  *
  * @param  Application $application
  * @return void
  */
 public static function check(Application $application)
 {
     if ($application->config()['force_ssl'] && $_SERVER['SERVER_PORT'] != '443') {
         Response::redirect('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']);
         exit;
     }
 }
Пример #2
0
 /**
  * Check for the user session
  *
  * @param  Application $application
  * @return void
  */
 public static function check(Application $application)
 {
     $sess = $application->getService('session');
     $action = $application->router()->getRouteMatch()->getAction();
     $route = $application->router()->getRouteMatch()->getRoute();
     $isInstall = substr($route, 0, strlen(APP_URI . '/install')) == APP_URI . '/install';
     // Special install check
     if (isset($sess->app_uri) && strpos($_SERVER['REQUEST_URI'], 'install/config') !== false) {
         if (BASE_PATH . APP_URI == BASE_PATH . $sess->app_uri && $application->config()['db']) {
             Response::redirect(BASE_PATH . APP_URI . '/install/user');
             exit;
         }
     }
     // If logged in, and a system URL, redirect to dashboard
     if (isset($sess->user) && ($action == 'login' || $action == 'register' || $action == 'verify' || $action == 'forgot' || $isInstall)) {
         Response::redirect(BASE_PATH . (APP_URI != '' ? APP_URI : '/'));
         exit;
         // Else, if NOT logged in and NOT a system URL, redirect to login
     } else {
         if (!isset($sess->user) && ($action != 'login' && $action != 'register' && !$isInstall && $action != 'unsubscribe' && $action != 'verify' && $action != 'forgot' && null !== $action) && substr($route, 0, strlen(APP_URI)) == APP_URI) {
             Response::redirect(BASE_PATH . APP_URI . '/login');
             exit;
         }
     }
 }
Пример #3
0
 /**
  * Method to parse Youtube Atom feed object
  *
  * @return void
  */
 public function parse()
 {
     parent::parse();
     $items = $this->feed['items'];
     foreach ($items as $key => $item) {
         if ($items[$key]['content'] == '') {
             $items[$key]['content'] = $item['title'];
         }
         $id = substr($item['link'], strpos($item['link'], 'v=') + 2);
         if (strpos($id, '&') !== false) {
             $id = substr($id, 0, strpos($id, '&'));
         }
         $items[$key]['id'] = $id;
         $youtube = \Pop\Http\Response::parse('http://gdata.youtube.com/feeds/api/videos/' . $id . '?v=2&alt=json');
         if (!$youtube->isError()) {
             $info = json_decode($youtube->getBody(), true);
             $items[$key]['views'] = $info['entry']['yt$statistics']['viewCount'];
             $items[$key]['likes'] = $info['entry']['yt$rating']['numLikes'];
             $items[$key]['duration'] = $info['entry']['media$group']['yt$duration']['seconds'];
             $items[$key]['image_thumb'] = 'http://i.ytimg.com/vi/' . $id . '/default.jpg';
             $items[$key]['image_medium'] = 'http://i.ytimg.com/vi/' . $id . '/mqdefault.jpg';
             $items[$key]['image_large'] = 'http://i.ytimg.com/vi/' . $id . '/hqdefault.jpg';
             foreach ($info as $k => $v) {
                 if ($v != '') {
                     $items[$key][$k] = $v;
                 }
             }
         }
     }
     $this->feed['items'] = $items;
 }
Пример #4
0
 /**
  * Method to parse a Vimeo RSS feed object
  *
  * @return void
  */
 public function parse()
 {
     parent::parse();
     if (null === $this->feed['author']) {
         $this->feed['author'] = str_replace('Vimeo / ', null, $this->feed['title']);
     }
     $items = $this->feed['items'];
     foreach ($items as $key => $item) {
         $id = substr($item['link'], strrpos($item['link'], '/') + 1);
         $items[$key]['id'] = $id;
         $vimeo = \Pop\Http\Response::parse('http://vimeo.com/api/v2/video/' . $id . '.php');
         if (!$vimeo->isError()) {
             $info = unserialize($vimeo->getBody());
             if (isset($info[0]) && is_array($info[0])) {
                 $items[$key]['views'] = isset($info[0]['stats_number_of_plays']) ? $info[0]['stats_number_of_plays'] : null;
                 $items[$key]['likes'] = isset($info[0]['stats_number_of_likes']) ? $info[0]['stats_number_of_likes'] : null;
                 $items[$key]['duration'] = $info[0]['duration'];
                 $items[$key]['image_thumb'] = $info[0]['thumbnail_small'];
                 $items[$key]['image_medium'] = $info[0]['thumbnail_medium'];
                 $items[$key]['image_large'] = $info[0]['thumbnail_large'];
                 foreach ($info[0] as $k => $v) {
                     if ($v != '') {
                         $items[$key][$k] = $v;
                     }
                 }
             }
         }
     }
     $this->feed['items'] = $items;
 }
 /**
  * Session remove method
  *
  * @return void
  */
 public function remove()
 {
     if ($this->request->isPost()) {
         $session = new Model\UserSession();
         $session->remove($this->request->getPost());
     }
     Response::redirect($this->request->getBasePath() . '?removed=' . time());
 }
Пример #6
0
 public function post()
 {
     $view = new View($this->viewPath . '/post.phtml');
     $view->title = 'Post Comment';
     $view->form = new Form\Post();
     if ($this->request->isPost()) {
         $view->form->addFilter('strip_tags')->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($this->request->getPost());
         if ($view->form->isValid()) {
             $view->form->clearFilters()->addFilter('html_entity_decode', [ENT_QUOTES, 'UTF-8']);
             $post = new Model\Post();
             $post->save($view->form->getFields());
             Response::redirect('/');
             exit;
         }
     }
     $this->response->setBody($view->render());
     $this->response->send();
 }
Пример #7
0
 /**
  * Check if the user session is allowed with the ACL service
  *
  * @param  Application $application
  * @return void
  */
 public static function check(Application $application)
 {
     $application->module('app')->initAcl();
     $sess = $application->getService('session');
     $acl = $application->getService('acl');
     if (isset($sess->user) && isset($sess->user->role) && $acl->hasRole($sess->user->role)) {
         // Get routes with slash options
         $route = $application->router()->getRouteMatch()->getRoute();
         $routes = $application->router()->getRouteMatch()->getRoutes();
         if (isset($routes[$route]) && isset($routes[$route]['acl']) && isset($routes[$route]['acl']['resource'])) {
             $resource = $routes[$route]['acl']['resource'];
             $permission = isset($routes[$route]['acl']['permission']) ? $routes[$route]['acl']['permission'] : null;
             if (!$acl->isAllowed($sess->user->role, $resource, $permission)) {
                 Response::redirect('/');
                 exit;
             }
         }
     }
 }
Пример #8
0
 /**
  * Check for the member session
  *
  * @param  Application $application
  * @return void
  */
 public static function sessionCheck(Application $application)
 {
     if (null !== $application->router()->getController() && $application->router()->getController() instanceof \Phire\Members\Controller\IndexController) {
         $sess = $application->getService('session');
         $action = $application->router()->getRouteMatch()->getAction();
         $route = $application->router()->getRouteMatch()->getRoute();
         $memberUri = $application->router()->getController()->getMemberUri();
         // If logged in, and a member URL, redirect to dashboard
         if (isset($sess->member) && ($action == 'login' || $action == 'register' || $action == 'verify' || $action == 'forgot')) {
             Response::redirect(BASE_PATH . $memberUri);
             exit;
             // Else, if NOT logged in and NOT a system URL, redirect to login
         } else {
             if (!isset($sess->member) && ($action != 'login' && $action != 'register' && $action != 'unsubscribe' && $action != 'verify' && $action != 'forgot' && null !== $action) && substr($route, 0, strlen($memberUri)) == $memberUri) {
                 Response::redirect(BASE_PATH . $memberUri . '/login');
                 exit;
             }
         }
     }
 }
Пример #9
0
 /**
  * Check for the user session
  *
  * @param  Application $application
  * @return void
  */
 public static function check(Application $application)
 {
     $sess = $application->getService('session');
     $action = $application->router()->getRouteMatch()->getAction();
     if (isset($sess->user) && isset($sess->user->sess_id) && !isset(Table\UserSessions::findById($sess->user->sess_id)->id)) {
         $user = new Model\User();
         $user->logout($sess);
         unset($sess->user);
         $sess->setRequestValue('expired', true);
         Response::redirect('/login');
         exit;
     } else {
         if (isset($sess->user) && ($action == 'login' || $action == 'forgot' || $action == 'verify')) {
             Response::redirect('/');
             exit;
         } else {
             if (!isset($sess->user) && $action != 'login' && $action != 'forgot' && $action != 'verify') {
                 Response::redirect('/login');
                 exit;
             }
         }
     }
 }
Пример #10
0
 /**
  * Install initial user method
  *
  * @return void
  */
 public function user()
 {
     // If the system is installed
     if (DB_INTERFACE != '' && DB_NAME != '' && !isset($this->sess->config)) {
         Response::redirect(BASE_PATH . APP_URI);
         // Else, if the initial install screen or config isn't complete
     } else {
         if (DB_INTERFACE == '' && DB_NAME == '') {
             if (isset($this->sess->config)) {
                 Response::redirect(BASE_PATH . (isset($this->sess->app_uri) ? $this->sess->app_uri : APP_URI) . '/install/config?lang=' . $_GET['lang']);
             } else {
                 Response::redirect(BASE_PATH . (isset($this->sess->app_uri) ? $this->sess->app_uri : APP_URI) . '/install?lang=' . $_GET['lang']);
             }
             // Else, install the first system user
         } else {
             $user = new Model\User(array('title' => $this->i18n->__('User Setup')));
             $form = new Form\User($this->request->getBasePath() . $this->request->getRequestUri() . '?lang=' . $this->i18n->getLanguage() . '_' . $this->i18n->getLocale(), 'post', 2001, true);
             if ($this->request->isPost()) {
                 $form->setFieldValues($this->request->getPost(), array('strip_tags' => null, 'htmlentities' => array(ENT_QUOTES, 'UTF-8')));
                 if ($form->isValid()) {
                     $user->save($form, $this->project->module('Phire'));
                     $newUser = Table\Users::findById($user->id);
                     if (isset($newUser->id)) {
                         $newUser->site_ids = serialize(array(0));
                         $newUser->created = date('Y-m-d H:i:s');
                         $newUser->update();
                     }
                     $ext = new Model\Extension(array('acl' => $this->project->getService('acl')));
                     $ext->getModules($this->project);
                     if (count($ext->new) > 0) {
                         $ext->installModules();
                     }
                     $user->set('form', '        <p style="text-align: center; margin: 50px 0 0 0; line-height: 1.8em; font-size: 1.2em;">' . $this->i18n->__('Thank you. The system has been successfully installed.') . '<br />' . $this->i18n->__('You can now log in %1here%2 or view the home page %3here%4.', array('<a href="' . BASE_PATH . APP_URI . '/login">', '</a>', '<a href="' . BASE_PATH . '/" target="_blank">', '</a>')) . '</p>' . PHP_EOL);
                     Model\Install::send($form);
                     unset($this->sess->config);
                     unset($this->sess->app_uri);
                     $this->view = View::factory($this->viewPath . '/user.phtml', $user->getData());
                     $this->view->set('i18n', $this->i18n);
                     $this->send();
                 } else {
                     $user->set('form', $form);
                     $this->view = View::factory($this->viewPath . '/user.phtml', $user->getData());
                     $this->view->set('i18n', $this->i18n);
                     $this->send();
                 }
             } else {
                 $user->set('form', $form);
                 $this->view = View::factory($this->viewPath . '/user.phtml', $user->getData());
                 $this->view->set('i18n', $this->i18n);
                 $this->send();
             }
         }
     }
 }
Пример #11
0
 /**
  * Method to get date format
  *
  * @return void
  */
 public function json()
 {
     if (null !== $this->request->getPath(1)) {
         $format = str_replace('_', '/', urldecode($this->request->getPath(1)));
         // Build the response and send it
         $response = new Response();
         $response->setHeader('Content-Type', 'application/json')->setBody(json_encode(array('format' => date($format))));
         $response->send();
     }
 }
Пример #12
0
 /**
  * Error handler
  *
  * @param  \Exception $exception
  * @return void
  */
 public function error(\Exception $exception)
 {
     if ($exception instanceof \Phire\Exception && $exception->isInstallError()) {
         Response::redirect(BASE_PATH . APP_URI . '/install');
         exit;
     }
     // Load assets, if they haven't been loaded already
     $this->loadAssets($_SERVER['DOCUMENT_ROOT'] . APP_PATH . '/data/themes/default', 'default');
     $this->loadAssets(__DIR__ . '/../data/assets', 'phire');
     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);
     $view = new View(__DIR__ . '/../view/phire/exception.phtml');
     $view->title = 'Application Error';
     $view->systemTitle = 'Phire CMS';
     $view->assets = $this->assets;
     $view->phireUri = BASE_PATH . APP_URI;
     $view->basePath = BASE_PATH;
     $view->base_path = BASE_PATH;
     $view->contentPath = BASE_PATH . CONTENT_PATH;
     $view->content_path = BASE_PATH . CONTENT_PATH;
     $view->message = htmlentities(strip_tags($exception->getMessage()), ENT_QUOTES, 'UTF-8');
     $response = new Response();
     $response->setBody((string) $view);
     $response->send();
 }
Пример #13
0
 /**
  * Custom error handler method
  *
  * @param  \Exception $exception
  * @return void
  */
 public function error(\Exception $exception)
 {
     $view = new View(__DIR__ . '/../view/exception.phtml');
     $view->title = 'Application Error';
     $view->message = htmlentities(strip_tags($exception->getMessage()), ENT_QUOTES, 'UTF-8');
     if (file_exists(__DIR__ . '/../config/application.php')) {
         $config = (include __DIR__ . '/../config/application.php');
         $view->application_title = $config['application_title'];
     } else {
         $view->application_title = '';
     }
     $response = new Response();
     $response->setBody((string) $view);
     $response->send(500);
 }
Пример #14
0
 public function testEncodeAndDecode()
 {
     $e = Response::encodeBody('This is a test.');
     $this->assertEquals('This is a test.', Response::decodeBody($e));
     $e = Response::encodeBody('This is a test.', 'deflate');
     $this->assertEquals('This is a test.', Response::decodeBody($e, 'deflate'));
 }
Пример #15
0
 /**
  * Redirect response
  *
  * @param  string $url
  * @param  string $code
  * @param  string $version
  * @return void
  */
 public function redirect($url, $code = '302', $version = '1.1')
 {
     $this->application->trigger('app.send.pre', ['controller' => $this]);
     $this->application->trigger('app.send.post', ['controller' => $this]);
     Response::redirect($url, $code, $version);
     exit;
 }
Пример #16
0
 public function error()
 {
     $this->response->setBody(json_encode(['error' => 'Resource not found'], JSON_PRETTY_PRINT));
     $this->response->send(404);
 }
Пример #17
0
 /**
  * Site remove method
  *
  * @return void
  */
 public function remove()
 {
     // Loop through and delete the fields
     if ($this->request->isPost()) {
         $site = new Model\Site();
         $site->remove($this->request->getPost());
     }
     Response::redirect($this->request->getBasePath() . '?removed=' . time());
 }
Пример #18
0
 public function parse($baseUrl, $context, array $tags)
 {
     $dom = null;
     $contentType = null;
     $this->response = Response::parse($this->url, $context);
     if (null !== $this->response->getHeader('Content-type')) {
         $this->contentType = $this->response->getHeader('Content-type');
     } else {
         if (null !== $this->response->getHeader('Content-Type')) {
             $this->contentType = $this->response->getHeader('Content-Type');
         }
     }
     if (null !== $this->contentType && stripos($this->contentType, 'text/html') !== false) {
         if ($this->response->getCode() == 200) {
             $oldError = ini_get('error_reporting');
             error_reporting(0);
             $dom = new \DOMDocument();
             $dom->recover = true;
             $dom->strictErrorChecking = false;
             $dom->loadHTML($this->response->getBody());
             error_reporting($oldError);
         }
     }
     if (null !== $dom) {
         foreach ($tags as $tag) {
             switch ($tag) {
                 case 'title':
                     $title = $dom->getElementsByTagName('title');
                     $this->elements['title'] = null !== $title->item(0) ? trim($title->item(0)->nodeValue) : null;
                     break;
                 case 'meta':
                     $meta = $dom->getElementsByTagName('meta');
                     if (null !== $meta->item(0)) {
                         foreach ($meta as $m) {
                             if ($m->hasAttribute('name') && $m->hasAttribute('content')) {
                                 if (!isset($this->elements['meta'])) {
                                     $this->elements['meta'] = [];
                                 }
                                 $this->elements['meta'][] = ['name' => $m->getAttribute('name'), 'content' => $m->getAttribute('content')];
                             }
                         }
                     }
                     break;
                 case 'a':
                     $anchors = $dom->getElementsByTagName('a');
                     if (null !== $anchors->item(0)) {
                         foreach ($anchors as $a) {
                             if (!isset($this->elements['a'])) {
                                 $this->elements['a'] = [];
                             }
                             $href = $a->hasAttribute('href') ? $a->getAttribute('href') : null;
                             if (null !== $href && $this->isValidHref($href)) {
                                 if (substr($href, 0, strlen($baseUrl)) == $baseUrl) {
                                     $href = substr($href, strlen($baseUrl));
                                 }
                                 $url = substr($this->url, strlen($baseUrl));
                                 if (substr($href, 0, 1) == '/') {
                                     $href = $baseUrl . $href;
                                 } else {
                                     if (substr($href, 0, 2) == './') {
                                         $href = $baseUrl . $url . substr($href, 1);
                                     } else {
                                         if (strpos($href, '../') !== false) {
                                             $depth = substr_count($url, '/');
                                             $levels = substr_count($href, '../');
                                             if ($depth > $levels) {
                                                 for ($i = 0; $i < $levels; $i++) {
                                                     $url = substr($url, 0, strrpos($url, '/'));
                                                 }
                                                 $href = $baseUrl . $url . '/' . str_replace('../', '', $href);
                                             } else {
                                                 $href = $baseUrl . '/' . str_replace('../', '', $href);
                                             }
                                         }
                                     }
                                 }
                                 if (substr($href, 0, strlen($baseUrl)) == $baseUrl && !in_array($href, $this->children) && $this->url != $href) {
                                     $this->children[] = $href;
                                 }
                             }
                             if ($a->nodeValue != '') {
                                 $value = $a->nodeValue;
                             } else {
                                 $imgs = $a->getElementsByTagName('img');
                                 $value = null !== $imgs->item(0) ? '[image]' : null;
                             }
                             $this->elements['a'][] = array('href' => $href, 'value' => $value, 'title' => $a->hasAttribute('title') ? $a->getAttribute('title') : null, 'name' => $a->hasAttribute('name') ? $a->getAttribute('name') : null, 'rel' => $a->hasAttribute('rel') ? $a->getAttribute('rel') : null);
                         }
                     }
                     break;
                 case 'img':
                     $images = $dom->getElementsByTagName('img');
                     if (null !== $images->item(0)) {
                         foreach ($images as $image) {
                             if (!isset($this->elements['img'])) {
                                 $this->elements['img'] = [];
                             }
                             $this->elements['img'][] = ['src' => $image->hasAttribute('src') ? $image->getAttribute('src') : null, 'alt' => $image->hasAttribute('alt') ? $image->getAttribute('alt') : null, 'title' => $image->hasAttribute('title') ? $image->getAttribute('title') : null];
                         }
                     }
                     break;
                 default:
                     $element = $dom->getElementsByTagName($tag);
                     if (null !== $element->item(0)) {
                         foreach ($element as $e) {
                             $this->elements[$tag][] = $e->nodeValue;
                         }
                     }
             }
         }
     }
     return $this->elements;
 }
Пример #19
0
 /**
  * Decode the body
  *
  * @return void
  */
 public function decodeBody()
 {
     if (isset($this->headers['Transfer-Encoding']) && $this->headers['Transfer-Encoding'] == 'chunked') {
         $this->body = Response::decodeChunkedBody($this->body);
     }
     $this->body = Response::decodeBody($this->body, $this->headers['Content-Encoding']);
 }
Пример #20
0
 /**
  * Method to get other resource permissions via JS
  *
  * @return void
  */
 public function json()
 {
     if (null !== $this->request->getPath(1)) {
         $resources = \Phire\Model\UserRole::getResources($this->project->module('Phire'));
         $class = str_replace('_', '\\', urldecode($this->request->getPath(1)));
         $types = array();
         $actions = array();
         foreach ($resources as $key => $resource) {
             if ($key == $class) {
                 $types = $resource['types'];
                 $actions = $resource['actions'];
             }
         }
         $body = array('types' => $types, 'actions' => $actions);
         // Build the response and send it
         $response = new Response();
         $response->setHeader('Content-Type', 'application/json')->setBody(json_encode($body));
         $response->send();
     }
 }
Пример #21
0
 /**
  * Event-based auth check
  *
  * @param  \Pop\Mvc\Router $router
  * @return mixed
  */
 public static function auth($router)
 {
     $sess = Session::getInstance();
     $site = Sites::getSite();
     $basePath = $site->base_path;
     $resource = $router->getControllerClass();
     $permission = $router->getAction();
     $isFrontController = substr_count($resource, '\\') == 2;
     // Check for the resource and permission
     if (!$isFrontController && $resource != 'Phire\\Controller\\Phire\\Install\\IndexController') {
         if (null === $router->project()->getService('acl')->getResource($resource)) {
             if ($resource != 'Phire\\Controller\\Phire\\IndexController') {
                 $router->project()->getService('acl')->addResource($resource);
             } else {
                 $resource = null;
                 $permission = null;
             }
         }
         if (null !== $permission && null !== $resource && !method_exists($resource, $permission)) {
             $permission = 'error';
         }
         if ($router->controller()->getRequest()->getPath(0) == 'index' || $router->controller()->getRequest()->getPath(0) == 'add') {
             $permId = $router->controller()->getRequest()->getPath(1);
             if (null !== $permId && is_numeric($permId)) {
                 $permission .= '_' . $permId;
             }
         }
         // Get the user URI
         $uri = APP_URI == '' || strtolower($router->project()->getService('acl')->getType()->type) == 'user' ? APP_URI : '/' . strtolower($router->project()->getService('acl')->getType()->type);
         // If reset password flag is set
         if (isset($sess->reset_pwd) && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/profile' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/login' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/logout') {
             \Pop\Http\Response::redirect($basePath . $uri . '/profile');
             return \Pop\Event\Manager::KILL;
             // If not logged in for unsubscribe and required, redirect to the system login
         } else {
             if ($_SERVER['REQUEST_URI'] == $basePath . $uri . '/unsubscribe' && $router->project()->getService('acl')->getType()->unsubscribe_login && !$router->project()->getService('acl')->isAuth($resource, $permission)) {
                 \Pop\Http\Response::redirect($basePath . $uri . '/login');
                 return \Pop\Event\Manager::KILL;
                 // Else, if not logged in or allowed, redirect to the system login
             } else {
                 if ($_SERVER['REQUEST_URI'] != $basePath . $uri . '/login' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/register' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/forgot' && $_SERVER['REQUEST_URI'] != $basePath . $uri . '/unsubscribe' && substr($_SERVER['REQUEST_URI'], 0, strlen($basePath . $uri . '/json')) != $basePath . $uri . '/json' && strpos($_SERVER['REQUEST_URI'], $basePath . $uri . '/verify') === false && !$router->project()->getService('acl')->isAuth($resource, $permission)) {
                     \Pop\Http\Response::redirect($basePath . $uri . '/login');
                     return \Pop\Event\Manager::KILL;
                     // Else, if logged in and allowed, and a system access URI, redirect back to the system
                 } else {
                     if (($_SERVER['REQUEST_URI'] == $basePath . $uri . '/login' || $_SERVER['REQUEST_URI'] == $basePath . $uri . '/register' || $_SERVER['REQUEST_URI'] == $basePath . $uri . '/forgot') && $router->project()->getService('acl')->isAuth($resource, $permission)) {
                         \Pop\Http\Response::redirect($basePath . ($uri == '' ? '/' : $uri));
                         return \Pop\Event\Manager::KILL;
                     }
                 }
             }
         }
     }
 }
Пример #22
0
 /**
  * Modules method
  *
  * @return void
  */
 public function modules()
 {
     $this->prepareView('modules.phtml', array('assets' => $this->project->getAssets(), 'acl' => $this->project->getService('acl'), 'phireNav' => $this->project->getService('phireNav')));
     $ext = new Model\Extension(array('acl' => $this->project->getService('acl')));
     $ext->getModules($this->project);
     if (null === $this->request->getPath(1)) {
         $this->view->set('title', $this->view->i18n->__('Extensions') . ' ' . $this->view->separator . ' ' . $this->view->i18n->__('Modules'));
         $this->view->merge($ext->getData());
         $this->send();
     } else {
         if (null !== $this->request->getPath(1) && $this->request->getPath(1) == 'install' && count($ext->new) > 0) {
             $ext->installModules();
             if (null !== $ext->error) {
                 $this->view->set('title', $this->view->i18n->__('Extensions') . ' ' . $this->view->separator . ' ' . $this->view->i18n->__('Modules') . ' ' . $this->view->separator . ' ' . $this->view->i18n->__('Installation Error'));
                 $this->view->merge($ext->getData());
                 $this->send();
             } else {
                 Response::redirect($this->request->getBasePath() . '/modules?saved=' . time());
             }
         } else {
             if ($this->request->isPost() && null !== $this->request->getPath(1) && $this->request->getPath(1) == 'process') {
                 $ext->processModules($this->request->getPost());
                 Response::redirect($this->request->getBasePath() . '/modules?saved=' . time());
             } else {
                 Response::redirect($this->request->getBasePath() . '/modules');
             }
         }
     }
 }
Пример #23
0
 /**
  * Verify method
  *
  * @param  string $redirect
  * @return void
  */
 public function verify($redirect = null)
 {
     // If the required user ID and hash is submitted
     if (null !== $this->request->getPath(1) && null !== $this->request->getPath(2)) {
         $this->prepareView('verify.phtml', array('assets' => $this->project->getAssets(), 'acl' => $this->project->getService('acl'), 'phireNav' => $this->project->getService('phireNav'), 'phire' => new Model\Phire(), 'title' => 'Verify'));
         $this->view->set('title', $this->view->i18n->__('Verify'));
         $user = new Model\User();
         $user->getById($this->request->getPath(1));
         // If the user was found, verify and save
         if (isset($user->id) && sha1($user->email) == $this->request->getPath(2)) {
             $user->verify();
             $message = 'Thank you. Your email has been verified.';
             // Else, render failure message
         } else {
             $message = 'Sorry. That email could not be verified.';
         }
         if (null !== $redirect) {
             Response::redirect($redirect);
         } else {
             $this->view->set('message', $this->view->i18n->__($message));
             $this->send();
         }
         // Else, redirect
     } else {
         Response::redirect($this->request->getBasePath());
     }
 }
Пример #24
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);
     }
 }
 /**
  * Method to get model types
  *
  * @return void
  */
 public function json()
 {
     $body = '';
     if (null !== $this->request->getPath(1)) {
         // Get the selected field history value
         if ($this->request->getPath(1) == 'history' && null !== $this->request->getPath(2) && is_numeric($this->request->getPath(2)) && null !== $this->request->getPath(3) && is_numeric($this->request->getPath(3)) && null !== $this->request->getPath(4) && is_numeric($this->request->getPath(4))) {
             $modelId = $this->request->getPath(2);
             $fieldId = $this->request->getPath(3);
             $time = $this->request->getPath(4);
             $value = '';
             $encOptions = $this->project->module('Phire')->encryptionOptions->asArray();
             $fv = Table\FieldValues::findById(array($fieldId, $modelId));
             if (isset($fv->field_id) && null !== $fv->history) {
                 $history = json_decode($fv->history, true);
                 if (isset($history[$time])) {
                     $value = $history[$time];
                     $f = Table\Fields::findById($fieldId);
                     $value = Model\FieldValue::decrypt($value, $f->encryption, $encOptions);
                 }
             }
             $body = array('fieldId' => $fieldId, 'modelId' => $modelId, 'value' => html_entity_decode($value, ENT_QUOTES, 'UTF-8'));
             // Get the field history timestamps
         } else {
             if ($this->request->getPath(1) == 'history' && null !== $this->request->getPath(2) && is_numeric($this->request->getPath(2)) && null !== $this->request->getPath(3) && is_numeric($this->request->getPath(3))) {
                 $modelId = $this->request->getPath(2);
                 $fieldId = $this->request->getPath(3);
                 $fv = Table\FieldValues::findById(array($fieldId, $modelId));
                 if (isset($fv->field_id) && null !== $fv->history) {
                     $body = array_keys(json_decode($fv->history, true));
                     rsort($body);
                 }
                 // Get the model types
             } else {
                 $clsAry = $this->request->getPath();
                 unset($clsAry[0]);
                 $cls = implode('_', $clsAry);
                 $types = \Phire\Project::getModelTypes($cls);
                 $body = array('types' => $types);
             }
         }
         // Build the response and send it
         $response = new Response();
         $response->setHeader('Content-Type', 'application/json; charset=utf-8')->setBody(json_encode($body));
         $response->send();
     }
 }
Пример #26
0
 /**
  * Export method
  *
  * @return void
  */
 public function export()
 {
     $user = new Model\User();
     $user->getExport($this->request->getPath(1), $this->request->getQuery('sort'), $this->request->getQuery('page'));
     if (isset($user->userRows[0])) {
         $userRows = $user->userRows;
         foreach ($userRows as $key => $value) {
             foreach ($value as $k => $v) {
                 if (is_array($v)) {
                     $userRows[$key]->{$k} = implode('|', $v);
                 }
             }
         }
         \Pop\Data\Data::factory($userRows)->writeData($_SERVER['HTTP_HOST'] . '_' . $user->userType . '_' . date('Y-m-d') . '.csv', true, true);
     } else {
         Response::redirect($this->request->getBasePath() . '/index/' . $this->request->getPath(1));
     }
 }
Пример #27
0
 /**
  * Redirect response
  *
  * @param  string $url
  * @param  string $code
  * @param  string $version
  * @return void
  */
 public function redirect($url, $code = '302', $version = '1.1')
 {
     Response::redirect($url, $code, $version);
     exit;
 }
Пример #28
0
 /**
  * Method to parse Youtube JSON feed object
  *
  * @return void
  */
 public function parse()
 {
     parent::parse();
     $this->feed['title'] = $this->feed['title']['$t'];
     $this->feed['url'] = $this->feed['url'][0]['href'];
     $this->feed['description'] = $this->feed['title'];
     $this->feed['date'] = $this->feed['date']['$t'];
     $this->feed['generator'] = $this->feed['generator']['$t'];
     $this->feed['author'] = $this->feed['author'][0]['name']['$t'];
     $items = $this->feed['items'];
     foreach ($items as $key => $item) {
         if (isset($this->obj['feed']['entry'][$key]['content']['$t'])) {
             $content = html_entity_decode($this->obj['feed']['entry'][$key]['content']['$t'], ENT_QUOTES, 'UTF-8');
         } else {
             $content = $this->obj['feed']['entry'][$key]['title']['$t'];
         }
         $items[$key]['title'] = $this->obj['feed']['entry'][$key]['title']['$t'];
         $items[$key]['content'] = $content;
         $items[$key]['link'] = $items[$key]['link'][0]['href'];
         $items[$key]['published'] = $this->obj['feed']['entry'][$key]['published']['$t'];
         $items[$key]['time'] = self::calculateTime($this->obj['feed']['entry'][$key]['published']['$t']);
         $id = substr($items[$key]['link'], strpos($items[$key]['link'], 'v=') + 2);
         if (strpos($id, '&') !== false) {
             $id = substr($id, 0, strpos($id, '&'));
         }
         $items[$key]['id'] = $id;
         $youtube = \Pop\Http\Response::parse('http://gdata.youtube.com/feeds/api/videos/' . $id . '?v=2&alt=json');
         if (!$youtube->isError()) {
             $info = json_decode($youtube->getBody(), true);
             $items[$key]['views'] = $info['entry']['yt$statistics']['viewCount'];
             $items[$key]['likes'] = $info['entry']['yt$rating']['numLikes'];
             $items[$key]['duration'] = $info['entry']['media$group']['yt$duration']['seconds'];
             $items[$key]['image_thumb'] = 'http://i.ytimg.com/vi/' . $id . '/default.jpg';
             $items[$key]['image_medium'] = 'http://i.ytimg.com/vi/' . $id . '/mqdefault.jpg';
             $items[$key]['image_large'] = 'http://i.ytimg.com/vi/' . $id . '/hqdefault.jpg';
             foreach ($info as $k => $v) {
                 if ($v != '') {
                     $items[$key][$k] = $v;
                 }
             }
         }
     }
     $this->feed['items'] = $items;
 }
 /**
  * Group remove method
  *
  * @return void
  */
 public function remove()
 {
     // Loop through and delete the groups
     if ($this->request->isPost()) {
         $group = new Model\FieldGroup();
         $group->remove($this->request->getPost());
     }
     Response::redirect($this->request->getBasePath() . '?removed=' . time());
 }
Пример #30
0
 /**
  * Process action method
  *
  * @return void
  */
 public function process()
 {
     $module = new Model\Module();
     $module->process($this->request->getPost(), $this->services);
     if (null !== $this->request->getPost('rm_modules')) {
         $this->sess->setRequestValue('removed', true);
     } else {
         $this->sess->setRequestValue('saved', true);
     }
     \Pop\Http\Response::redirect(BASE_PATH . APP_URI . '/modules');
     exit;
 }