コード例 #1
0
ファイル: View.php プロジェクト: phirecms/phire-views
 /**
  * Parse view object
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function parseViews(AbstractController $controller, Application $application)
 {
     if (!$controller instanceof \Phire\Content\Controller\ContentController && !$controller instanceof \Phire\Templates\Controller\IndexController && $controller->hasView()) {
         $body = $controller->response()->getBody();
         if (strpos($body, '[{view_') !== false) {
             // Parse any view placeholders
             $groupIds = [];
             $singleIds = [];
             $modelId = null;
             $views = [];
             $viewModel = new Model\View(['pagination' => $controller->config()->pagination]);
             preg_match_all('/\\[\\{view.*\\}\\]/', $body, $views);
             if (isset($views[0]) && isset($views[0][0])) {
                 foreach ($views[0] as $view) {
                     $id = substr($view, strpos($view, 'view_') + 5);
                     $id = str_replace('}]', '', $id);
                     if (strpos($id, '_') !== false) {
                         $idAry = explode('_', $id);
                         if (!empty($idAry[1])) {
                             $modelId = $idAry[1];
                         } else {
                             if (!empty($controller->view()->id)) {
                                 $modelId = $controller->view()->id;
                             }
                         }
                         $singleIds[] = ['view_id' => $idAry[0], 'model_id' => $modelId];
                     } else {
                         $groupIds[] = $id;
                     }
                 }
             }
             if (count($groupIds) > 0) {
                 foreach ($groupIds as $id) {
                     $body = str_replace('[{view_' . $id . '}]', $viewModel->renderPages($id) . PHP_EOL . $viewModel->render($id), $body);
                 }
             }
             if (count($singleIds) > 0) {
                 foreach ($singleIds as $id) {
                     if (null !== $id['model_id']) {
                         $body = str_replace('[{view_' . $id['view_id'] . '_' . $id['model_id'] . '}]', $viewModel->renderSingle($id['view_id'], $id['model_id']), $body);
                         $body = str_replace('[{view_' . $id['view_id'] . '_}]', $viewModel->renderSingle($id['view_id'], $id['model_id']), $body);
                     }
                 }
             }
             $controller->response()->setBody($body);
         }
     }
 }
コード例 #2
0
ファイル: Content.php プロジェクト: phirecms/phire-content
 /**
  * Initialize page editor
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function initPageEditor(AbstractController $controller, Application $application)
 {
     if ($controller instanceof \Phire\Content\Controller\IndexController && $controller->hasView() && $controller->response()->getCode() == 200) {
         $sess = $application->services()->get('session');
         $acl = $application->services()->get('acl');
         if (isset($sess->user) && $acl->isAllowed($sess->user->role, 'content', 'in-edit') && $acl->isAllowed($sess->user->role, 'content', 'edit')) {
             $body = $controller->response()->getBody();
             $head = substr($body, strpos($body, '<head>'));
             $head = substr($head, 0, strpos($head, '</head>') + 7);
             $newHead = $head;
             $assets = '    <link type="text/css" rel="stylesheet" href="' . BASE_PATH . CONTENT_PATH . '/assets/' . $controller->config()->system_theme . '/css/font-awesome.min.css" />' . PHP_EOL;
             $assets .= '    <link type="text/css" rel="stylesheet" href="' . BASE_PATH . CONTENT_PATH . '/assets/phire-content/css/phire.content.edit.css" />' . PHP_EOL . PHP_EOL;
             if (strpos($newHead, 'jax.4.0.0.min.js') === false && strpos($newHead, 'jax.4.0.0.js') === false) {
                 if (strpos($newHead, '<script') !== false) {
                     $newHead1 = substr($newHead, 0, strpos($newHead, '<script'));
                     $newHead2 = substr($newHead, strpos($newHead, '<script'));
                     $newHead1 .= '<script type="text/javascript" src="' . BASE_PATH . CONTENT_PATH . '/assets/phire/js/jax.4.0.0.min.js"></script>' . PHP_EOL;
                     $newHead1 .= '    <script type="text/javascript">' . PHP_EOL;
                     $newHead1 .= '        jax.noConflict();' . PHP_EOL;
                     $newHead1 .= '    </script>' . PHP_EOL . '    ';
                     $newHead = $newHead1 . $newHead2;
                 } else {
                     $assets .= '    <script type="text/javascript" src="' . BASE_PATH . CONTENT_PATH . '/assets/phire/js/jax.4.0.0.min.js"></script>' . PHP_EOL;
                     $assets .= '    <script type="text/javascript">' . PHP_EOL;
                     $assets .= '        jax.noConflict();' . PHP_EOL;
                     $assets .= '    </script>' . PHP_EOL;
                 }
             }
             $assets .= '    <script type="text/javascript" src="' . BASE_PATH . CONTENT_PATH . '/assets/phire/js/phire.js"></script>' . PHP_EOL;
             $assets .= '    <script type="text/javascript" src="' . BASE_PATH . CONTENT_PATH . '/assets/phire-content/js/phire.content.edit.js"></script>' . PHP_EOL . PHP_EOL;
             $assets .= '</head>';
             $systemUri = BASE_PATH . APP_URI;
             if ($systemUri == '') {
                 $systemUri = '/';
             }
             $contentUri = BASE_PATH . APP_URI . '/content/edit/' . $controller->view()->type_id . '/' . $controller->view()->id . '?in_edit=1';
             $nav = PHP_EOL . '<nav id="phire-in-edit-nav">' . PHP_EOL;
             $nav .= '    <a href="' . $contentUri . '" title="Edit Page" onclick="phire.launchPageEditor(this.href); return false;"><span>Edit</span></a>' . PHP_EOL;
             $nav .= '    <a href="' . $systemUri . '" title="Dashboard"><span>Dashboard</span></a>' . PHP_EOL;
             $nav .= '</nav>' . PHP_EOL . PHP_EOL;
             $nav .= '</body>';
             $newHead = str_replace('</head>', $assets, $newHead);
             $body = str_replace($head, $newHead, $body);
             $body = str_replace('</body>', $nav, $body);
             $controller->response()->setBody($body);
         }
     }
 }