コード例 #1
0
ファイル: Search.php プロジェクト: phirecms/phire-search
 /**
  * Execute search
  *
  * @param  array               $fields
  * @params \Pop\Module\Manager $modules
  * @return array
  */
 public function search($fields, \Pop\Module\Manager $modules)
 {
     $title = strip_tags($fields['title']);
     $selectFields = ['id' => DB_PREFIX . 'content.id', 'type_id' => DB_PREFIX . 'content.type_id', 'parent_id' => DB_PREFIX . 'content.parent_id', 'title' => DB_PREFIX . 'content.title', 'uri' => DB_PREFIX . 'content.uri', 'slug' => DB_PREFIX . 'content.slug', 'status' => DB_PREFIX . 'content.status', 'roles' => DB_PREFIX . 'content.roles', 'order' => DB_PREFIX . 'content.order', 'publish' => DB_PREFIX . 'content.publish', 'expire' => DB_PREFIX . 'content.expire'];
     $sql = Table\Content::sql();
     $sql->select($selectFields);
     $sql->select()->where('status = :status');
     $params = ['status' => 1];
     if (isset($fields['type_id'])) {
         $sql->select()->where('type_id = :type_id');
         $params['type_id'] = $fields['type_id'];
     }
     $sql->select()->where('title LIKE :title');
     $params['title'] = '%' . $title . '%';
     $sql->select()->orderBy('title', 'ASC');
     $results = Table\Content::execute((string) $sql, $params)->rows();
     foreach ($results as $i => $row) {
         $roles = unserialize($row->roles);
         if (count($roles) > 0 && !in_array($this->user_role_id, $roles)) {
             unset($results[$i]);
         } else {
             if ($modules->isRegistered('phire-fields')) {
                 $item = \Phire\Fields\Model\FieldValue::getModelObject('Phire\\Content\\Model\\Content', ['id' => $row->id], 'getById', $this->filters);
                 $results[$i] = new \ArrayObject($item->toArray(), \ArrayObject::ARRAY_AS_PROPS);
             }
         }
     }
     $log = new Searches(['keywords' => $title, 'results' => count($results), 'method' => $_POST ? 'post' : 'get', 'timestamp' => time()]);
     $log->save();
     return $results;
 }
コード例 #2
0
ファイル: Content.php プロジェクト: phirecms/phire-content
 /**
  * Set the field values
  *
  * @param  array $values
  * @return Content
  */
 public function setFieldValues(array $values = null)
 {
     parent::setFieldValues($values);
     if ($_POST && null !== $this->uri) {
         // Check for dupe name
         $content = Table\Content::findBy(['uri' => $this->uri]);
         if (isset($content->id) && $this->id != $content->id) {
             $this->getElement('uri')->addValidator(new Validator\NotEqual($this->uri, 'That URI already exists.'));
         }
     }
     return $this;
 }
コード例 #3
0
 /**
  * Get category view content
  *
  * @param  mixed $id
  * @return array
  */
 public function getCategoryViewItems($id)
 {
     $items = [];
     $catItems = Table\CategoryItems::findBy(['category_id' => $id], ['order' => 'order ASC']);
     if ($catItems->hasRows()) {
         foreach ($catItems->rows() as $c) {
             if ($c->media_id != 0) {
                 $media = \Phire\Media\Table\Media::findById($c->media_id);
                 $title = isset($media->id) ? $media->title : '[N/A]';
                 $item_id = $c->media_id;
                 $type = 'media';
             } else {
                 $content = \Phire\Content\Table\Content::findById($c->content_id);
                 $title = isset($content->id) ? $content->title : '[N/A]';
                 $item_id = $c->content_id;
                 $type = 'content';
             }
             $items[] = ['title' => $title, 'item_id' => $item_id, 'type' => $type, 'order' => $c->order];
         }
     }
     return $items;
 }
コード例 #4
0
 /**
  * Browser action method
  *
  * @param  int $lid
  * @return void
  */
 public function browser($lid = null)
 {
     if (null !== $this->request->getQuery('editor') && null !== $this->request->getQuery('type')) {
         $this->prepareView('media/browser.phtml');
         $this->view->title = 'Media Browser';
         if ($this->request->isPost()) {
             $library = new Model\MediaLibrary();
             $library->getById($lid);
             $settings = $library->getSettings();
             if (count($settings) == 4) {
                 $upload = new \Pop\File\Upload($settings['folder'], $settings['max_filesize'], $settings['disallowed_types'], $settings['allowed_types']);
                 if ($upload->test($_FILES['file'])) {
                     $media = new Model\Media();
                     $media->save($_FILES['file'], $this->request->getPost());
                     $this->sess->setRequestValue('saved', true);
                     $this->redirect(str_replace('&error=1', '', $_SERVER['REQUEST_URI']));
                 } else {
                     $this->redirect(str_replace('&error=1', '', $_SERVER['REQUEST_URI']) . '&error=1');
                 }
             }
         }
         if (null !== $lid && null !== $this->request->getQuery('asset') && null !== $this->request->getQuery('asset_type')) {
             $assets = [];
             $limit = $this->config->pagination;
             $page = $this->request->getQuery('page');
             $pages = null;
             $library = new Model\MediaLibrary();
             if ($this->request->getQuery('asset_type') == 'content' && $this->application->isRegistered('phire-content')) {
                 $type = \Phire\Content\Table\ContentTypes::findById($lid);
                 $content = \Phire\Content\Table\Content::findBy(['type_id' => $lid], ['order' => 'order, id ASC']);
                 foreach ($content->rows() as $c) {
                     $assets[] = ['id' => $c->id, 'title' => $c->title, 'uri' => BASE_PATH . $c->uri];
                 }
                 if (isset($type->id)) {
                     $this->view->assetType = $type->name;
                 }
             } else {
                 if ($this->request->getQuery('asset_type') == 'media') {
                     $library->getById($lid);
                     $media = new Model\Media(['lid' => $lid]);
                     if ($this->request->getQuery('asset') == 'file') {
                         $assets = $media->getAll();
                     } else {
                         if ($this->request->getQuery('asset') == 'image') {
                             $assets = $media->getAllImages();
                         }
                     }
                     $this->view->assetType = $library->name;
                 }
             }
             if (count($assets) > $limit) {
                 $pages = new Paginator(count($assets), $limit);
                 $pages->useInput(true);
                 $offset = null !== $page && (int) $page > 1 ? $page * $limit - $limit : 0;
                 $assets = array_slice($assets, $offset, $limit, true);
             }
             $this->view->title = 'Media' . (null !== $this->view->assetType ? ' : ' . $this->view->assetType : null);
             $this->view->lid = $lid;
             $this->view->folder = $library->folder;
             $this->view->sizes = null !== $library->actions ? array_keys($library->actions) : [];
             $this->view->pages = $pages;
             $this->view->browserAssets = $assets;
         } else {
             $libraries = [];
             $limit = null;
             $pages = null;
             if ($this->request->getQuery('type') == 'file' && $this->application->isRegistered('phire-content')) {
                 $types = \Phire\Content\Table\ContentTypes::findAll(['order' => 'order ASC']);
                 if ($types->hasRows()) {
                     $libraries['Content'] = [];
                     foreach ($types->rows() as $type) {
                         $libraries['Content'][$type->id] = $type->name;
                     }
                 }
             }
             $libraries['Media'] = [];
             $library = new Model\MediaLibrary();
             $libs = $library->getAll();
             foreach ($libs as $lib) {
                 $libraries['Media'][$lib->id] = $lib->name;
             }
             $this->view->title = 'Media';
             $this->view->pages = $pages;
             $this->view->lid = $lid;
             $this->view->libraries = $libraries;
         }
         $this->send();
     } else {
         $this->redirect(BASE_PATH . APP_URI . '/media');
     }
 }
コード例 #5
0
 /**
  * Create navigation children
  *
  * @param  int     $parentId
  * @param  int     $navId
  * @param  mixed   $content
  * @param  int     $depth
  * @param  boolean $cat
  * @return void
  */
 protected function createNavChildren($parentId, $navId, $content, $depth = 0, $cat = false)
 {
     $child = $cat ? \Phire\Categories\Table\Categories::findBy(['parent_id' => $content->id], ['order' => 'order ASC']) : \Phire\Content\Table\Content::findBy(['parent_id' => $content->id], ['order' => 'order ASC']);
     if ($child->hasRows()) {
         foreach ($child->rows() as $c) {
             if (isset($c->status) && $c->status == 1 || !isset($c->status)) {
                 $item = new Table\NavigationItems(['navigation_id' => $navId, 'parent_id' => $parentId, 'item_id' => $c->id, 'type' => $cat ? 'category' : 'content', 'name' => $c->title, 'href' => $cat ? '/category' . $c->uri : $c->uri, 'order' => 0]);
                 $item->save();
                 $this->createNavChildren($item->id, $navId, $c, $depth + 1, $cat);
             }
         }
     }
 }
コード例 #6
0
 /**
  * Check tree for status
  *
  * @param  array  $tree
  * @param  int    $roleId
  * @param  int    $depth
  * @return void
  */
 public static function checkTreeStatus(&$tree, $roleId = null, $depth = 0)
 {
     foreach ($tree as $i => &$branch) {
         if (isset($branch['item_id']) && isset($branch['type']) && $branch['type'] == 'content') {
             $content = \Phire\Content\Table\Content::findById($branch['item_id']);
             $allowed = true;
             if (null !== $content->roles) {
                 $roles = unserialize($content->roles);
                 if (count($roles) > 0 && (null === $roleId || !in_array($roleId, $roles))) {
                     $allowed = false;
                 }
             }
             if (isset($content->id) && ((int) $content->status != 1 || !$allowed)) {
                 unset($tree[$i]);
             }
         }
         if (isset($branch['children']) && count($branch['children']) > 0) {
             self::checkTreeStatus($branch['children'], $roleId, $depth + 1);
         }
     }
 }
コード例 #7
0
 /**
  * Get navigation children
  *
  * @param  \ArrayObject|array $content
  * @param  int                $depth
  * @param  boolean            $cat
  * @return array
  */
 protected function getNavChildren($content, $depth = 0, $cat = false)
 {
     $children = [];
     $child = $cat ? \Phire\Categories\Table\Categories::findBy(['parent_id' => $content->id], ['order' => 'order ASC']) : \Phire\Content\Table\Content::findBy(['parent_id' => $content->id], ['order' => 'order ASC']);
     if ($child->hasRows()) {
         foreach ($child->rows() as $c) {
             $branch = ['id' => $c->id, 'type' => $cat ? 'category' : 'content', 'name' => $c->title, 'href' => $c->uri, 'children' => isset($c->status) && $c->status == 1 || !isset($c->status) ? $this->getNavChildren($c, $depth + 1) : []];
             if (isset($c->roles)) {
                 $roles = unserialize($c->roles);
                 if (count($roles) > 0) {
                     $branch['acl'] = ['resource' => 'content-' . $c->id];
                 }
             }
             if (isset($c->status) && $c->status == 1 || !isset($c->status)) {
                 $children[] = $branch;
             }
         }
     }
     return $children;
 }
コード例 #8
0
 /**
  * Check tree for status
  *
  * @param  array  $tree
  * @param  int    $depth
  * @return void
  */
 public static function checkTreeStatus(&$tree, $depth = 0)
 {
     foreach ($tree as $i => &$branch) {
         if (isset($branch['id']) && isset($branch['type']) && $branch['type'] == 'content') {
             $content = \Phire\Content\Table\Content::findById($branch['id']);
             if (isset($content->id) && (int) $content->status != 1) {
                 unset($tree[$i]);
             }
         }
         if (isset($branch['children']) && count($branch['children']) > 0) {
             self::checkTreeStatus($branch['children'], $depth + 1);
         }
     }
 }
コード例 #9
0
 /**
  * Browser action
  *
  * @return void
  */
 public function browser()
 {
     if (null !== $this->request->getQuery('editor') && null !== $this->request->getQuery('type')) {
         $this->prepareView('fields/browser.phtml');
         $this->view->title = 'File Browser';
         if (null === $this->request->getQuery('asset')) {
             if ($this->request->getQuery('type') == 'image') {
                 $this->view->pages = null;
                 $this->view->libraries = ['Assets' => ['images' => 'Images']];
             } else {
                 $libraries = [];
                 if ($this->application->isRegistered('phire-content')) {
                     $types = \Phire\Content\Table\ContentTypes::findAll(['order' => 'order ASC']);
                     if ($types->hasRows()) {
                         $libraries['Assets'] = [];
                         foreach ($types->rows() as $type) {
                             $libraries['Assets'][$type->id] = $type->name;
                         }
                     }
                 }
                 $libraries['Assets']['files'] = 'Files';
                 $libraries['Assets']['images'] = 'Images';
                 $this->view->pages = null;
                 $this->view->libraries = $libraries;
             }
         } else {
             $asset = $this->request->getQuery('asset');
             $assets = [];
             $limit = $this->config->pagination;
             $page = $this->request->getQuery('page');
             $pages = null;
             $field = new Model\Field();
             $uploadFolder = BASE_PATH . CONTENT_PATH . '/files';
             switch ($asset) {
                 case 'files':
                     $assets = $field->getAllFiles($uploadFolder);
                     $this->view->assetType = 'Files';
                     break;
                 case 'images':
                     $assets = $field->getAllImages($uploadFolder);
                     $this->view->assetType = 'Images';
                     break;
                 default:
                     if (is_numeric($asset) && $this->application->isRegistered('phire-content')) {
                         $type = \Phire\Content\Table\ContentTypes::findById($asset);
                         $content = \Phire\Content\Table\Content::findBy(['type_id' => $asset], ['order' => 'order, id ASC']);
                         foreach ($content->rows() as $c) {
                             $assets[BASE_PATH . $c->uri] = $c->title;
                         }
                         if (isset($type->id)) {
                             $this->view->assetType = $type->name;
                         }
                     }
                     break;
             }
             if (count($assets) > $limit) {
                 $pages = new Paginator(count($assets), $limit);
                 $pages->useInput(true);
                 $offset = null !== $page && (int) $page > 1 ? $page * $limit - $limit : 0;
                 $assets = array_slice($assets, $offset, $limit, true);
             }
             $this->view->pages = $pages;
             $this->view->browserAssets = $assets;
         }
         $this->send();
     }
 }
コード例 #10
0
ファイル: Content.php プロジェクト: phirecms/phire-content
 /**
  * Set the dashboard
  *
  * @param  AbstractController $controller
  * @param  Application        $application
  * @return void
  */
 public static function setDashboard(AbstractController $controller, Application $application)
 {
     if ($controller instanceof \Phire\Controller\IndexController && $controller->hasView()) {
         if (substr($controller->view()->getTemplate()->getTemplate(), -17) == 'phire/index.phtml') {
             $sql = Table\Content::sql();
             $sql->select(['id' => DB_PREFIX . 'content.id', 'type_id' => DB_PREFIX . 'content.type_id', 'title' => DB_PREFIX . 'content.title', 'uri' => DB_PREFIX . 'content.uri', 'status' => DB_PREFIX . 'content.status', 'publish' => DB_PREFIX . 'content.publish', 'expire' => DB_PREFIX . 'content.expire', 'created_by' => DB_PREFIX . 'content.created_by', 'content_type_id' => DB_PREFIX . 'content_types.id', 'content_type_name' => DB_PREFIX . 'content_types.name', 'open_authoring' => DB_PREFIX . 'content_types.open_authoring'])->join(DB_PREFIX . 'content_types', [DB_PREFIX . 'content.type_id' => DB_PREFIX . 'content_types.id']);
             $sql->select()->where('status >= -1');
             $sql->select()->orderBy('id', 'DESC');
             $sql->select()->limit(10);
             $controller->view()->recent = Table\Content::query((string) $sql)->rows();
         }
     }
 }
コード例 #11
0
ファイル: Calendar.php プロジェクト: phirecms/phire-calendar
 /**
  * Get calendar by content type ID
  *
  * @param  int     $tid
  * @param  boolean $time
  * @return View
  */
 public function getById($tid, $time = false)
 {
     if ($this->force_list || Mobile::isMobileDevice() && $this->force_list_mobile) {
         $calendar = new View(__DIR__ . '/../../view/calendar-list.phtml');
     } else {
         $calendar = new View(__DIR__ . '/../../view/calendar.phtml');
     }
     $sql = Table\Content::sql();
     $sql2 = clone $sql;
     $sql->select(['id' => DB_PREFIX . 'content.id', 'type_id' => DB_PREFIX . 'content.type_id', 'title' => DB_PREFIX . 'content.title', 'uri' => DB_PREFIX . 'content.uri', 'slug' => DB_PREFIX . 'content.slug', 'status' => DB_PREFIX . 'content.status', 'roles' => DB_PREFIX . 'content.roles', 'publish' => DB_PREFIX . 'content.publish', 'expire' => DB_PREFIX . 'content.expire']);
     $sql2->select(['id' => DB_PREFIX . 'content.id', 'type_id' => DB_PREFIX . 'content.type_id', 'title' => DB_PREFIX . 'content.title', 'uri' => DB_PREFIX . 'content.uri', 'slug' => DB_PREFIX . 'content.slug', 'status' => DB_PREFIX . 'content.status', 'roles' => DB_PREFIX . 'content.roles', 'publish' => DB_PREFIX . 'content.publish', 'expire' => DB_PREFIX . 'content.expire']);
     // YYYY-MM
     if (null !== $this->date && strlen($this->date) == 7 && strpos($this->date, '-') !== false) {
         $dateAry = explode('-', $this->date);
         $start = $dateAry[0] . '-' . $dateAry[1] . '-01 00:00:00';
         $end = $dateAry[0] . '-' . $dateAry[1] . '-' . date('t', strtotime($dateAry[0] . '-' . $dateAry[1] . '-01')) . ' 23:59:59';
     } else {
         $y = date('Y');
         $m = date('m');
         $this->date = $y . '-' . $m;
         $start = $y . '-' . $m . '-01 00:00:00';
         $end = $y . '-' . $m . '-' . date('t', strtotime($y . '-' . $m . '-01')) . ' 23:59:59';
     }
     $sql->select()->where('type_id = :type_id')->where('status = :status')->where('publish >= :publish1')->where('publish <= :publish2');
     $sql->select()->orderBy('publish', 'ASC');
     $sql2->select()->where('type_id = :type_id')->where('status = :status');
     $sql2->select()->orderBy('publish', 'ASC');
     $params = ['type_id' => $tid, 'status' => 1, 'publish' => [$start, $end]];
     $params2 = ['type_id' => $tid, 'status' => 1];
     $monthOptions = $this->getMonthOptions();
     $content = Table\Content::execute((string) $sql, $params)->rows();
     $allContent = Table\Content::execute((string) $sql2, $params2)->rows();
     $events = [];
     $months = [];
     foreach ($content as $c) {
         $day = substr($c->publish, 0, strpos($c->publish, ' '));
         $mon = substr($day, 0, strrpos($day, '-'));
         if (!isset($events[$day])) {
             $events[$day] = [];
         }
         if (!in_array($mon, $monthOptions)) {
             $months[] = $mon;
         }
         $roles = unserialize($c->roles);
         if (count($roles) == 0 || null !== $this->user_role_id && in_array($this->user_role_id, $roles)) {
             $events[$day][] = $c;
         }
         if (null !== $c->expire) {
             $start = (int) substr($day, strrpos($day, '-') + 1) + 1;
             $expireDay = substr($c->expire, 0, strpos($c->expire, ' '));
             $expireTime = substr($c->expire, strpos($c->expire, ' ') + 1);
             $end = (int) substr($expireDay, strrpos($expireDay, '-') + 1);
             $expireMonth = substr($expireDay, 0, strrpos($expireDay, '-'));
             $daysBetween = strtotime($expireDay) - strtotime($day);
             $hoursBetween = strtotime($expireTime) - strtotime('00:00:00');
             if ($daysBetween > 86400 || $daysBetween == 86400 && $hoursBetween >= 21600) {
                 if (!in_array($expireMonth, $monthOptions)) {
                     $months[] = $expireMonth;
                 }
                 for ($i = $start; $i <= $end; $i++) {
                     if ($i <= $calendar->numOfDays) {
                         $expDay = $calendar->date . '-' . (strlen($i) == 1 ? '0' . $i : $i);
                         if (!isset($events[$expDay])) {
                             $events[$expDay] = [];
                         }
                         if (count($roles) == 0 || null !== $this->user_role_id && in_array($this->user_role_id, $roles)) {
                             $events[$expDay][] = $c;
                         }
                     }
                 }
             }
         }
     }
     foreach ($allContent as $c) {
         $day = substr($c->publish, 0, strpos($c->publish, ' '));
         $mon = substr($day, 0, strrpos($day, '-'));
         if (!in_array($mon, $monthOptions)) {
             $months[] = $mon;
         }
         if (null !== $c->expire) {
             $expireDay = substr($c->expire, 0, strpos($c->expire, ' '));
             $expireTime = substr($c->expire, strpos($c->expire, ' ') + 1);
             $expireMonth = substr($expireDay, 0, strrpos($expireDay, '-'));
             $daysBetween = strtotime($expireDay) - strtotime($day);
             $hoursBetween = strtotime($expireTime) - strtotime('00:00:00');
             if ($daysBetween > 86400 || $daysBetween == 86400 && $hoursBetween >= 21600) {
                 if (!in_array($expireMonth, $monthOptions)) {
                     $months[] = $expireMonth;
                 }
             }
         }
     }
     if (!$this->show_all) {
         foreach ($monthOptions as $month => $option) {
             if (!in_array($month, $months)) {
                 unset($monthOptions[$month]);
             }
         }
     }
     if (!array_key_exists($this->date, $monthOptions)) {
         reset($monthOptions);
         $this->date = key($monthOptions);
         $sql = Table\Content::sql();
         $sql->select(['id' => DB_PREFIX . 'content.id', 'type_id' => DB_PREFIX . 'content.type_id', 'title' => DB_PREFIX . 'content.title', 'uri' => DB_PREFIX . 'content.uri', 'slug' => DB_PREFIX . 'content.slug', 'status' => DB_PREFIX . 'content.status', 'roles' => DB_PREFIX . 'content.roles', 'publish' => DB_PREFIX . 'content.publish', 'expire' => DB_PREFIX . 'content.expire']);
         $dateAry = explode('-', $this->date);
         $start = $dateAry[0] . '-' . $dateAry[1] . '-01 00:00:00';
         $end = $dateAry[0] . '-' . $dateAry[1] . '-' . date('t', strtotime($dateAry[0] . '-' . $dateAry[1] . '-01')) . ' 23:59:59';
         $sql->select()->where('type_id = :type_id')->where('status = :status')->where('publish >= :publish1')->where('publish <= :publish2');
         $sql->select()->orderBy('publish', 'ASC');
         $params = ['type_id' => $tid, 'status' => 1, 'publish' => [$start, $end]];
         $content = Table\Content::execute((string) $sql, $params)->rows();
         $events = [];
         foreach ($content as $c) {
             $day = substr($c->publish, 0, strpos($c->publish, ' '));
             $mon = substr($day, 0, strrpos($day, '-'));
             if (!isset($events[$day])) {
                 $events[$day] = [];
             }
             $roles = unserialize($c->roles);
             if (count($roles) == 0 || null !== $this->user_role_id && in_array($this->user_role_id, $roles)) {
                 $events[$day][] = $c;
             }
             if (null !== $c->expire) {
                 $start = (int) substr($day, strrpos($day, '-') + 1) + 1;
                 $expireDay = substr($c->expire, 0, strpos($c->expire, ' '));
                 $expireTime = substr($c->expire, strpos($c->expire, ' ') + 1);
                 $end = (int) substr($expireDay, strrpos($expireDay, '-') + 1);
                 $expireMonth = substr($expireDay, 0, strrpos($expireDay, '-'));
                 $daysBetween = strtotime($expireDay) - strtotime($day);
                 $hoursBetween = strtotime($expireTime) - strtotime('00:00:00');
                 if ($daysBetween > 86400 || $daysBetween == 86400 && $hoursBetween >= 21600) {
                     for ($i = $start; $i <= $end; $i++) {
                         if ($i <= $calendar->numOfDays) {
                             $expDay = $calendar->date . '-' . (strlen($i) == 1 ? '0' . $i : $i);
                             if (!isset($events[$expDay])) {
                                 $events[$expDay] = [];
                             }
                             if (count($roles) == 0 || null !== $this->user_role_id && in_array($this->user_role_id, $roles)) {
                                 $events[$expDay][] = $c;
                             }
                         }
                     }
                 }
             }
         }
     }
     $calendar->date = $this->date;
     $calendar->time = $time;
     $calendar->weekdays = $this->weekdays;
     $calendar->day_format = $this->day_format;
     $calendar->numOfWeeks = $this->getNumberOfWeeks();
     $calendar->startDay = date('D', strtotime($this->date));
     $calendar->numOfDays = date('t', strtotime($this->date));
     $calendar->monthOptions = $monthOptions;
     $calendar->events = $events;
     return $calendar;
 }
コード例 #12
0
ファイル: Seo.php プロジェクト: phirecms/phire-seo
 /**
  * Process and save seo config
  *
  * @param  array $exclude
  * @return void
  */
 public function saveAnalysis(array $exclude = [])
 {
     $config = Table\Config::findById('seo_config');
     $cfg = isset($config->value) && !empty($config->value) && $config->value != '' ? unserialize($config->value) : [];
     $analysis = ['tracking' => false, 'sitemap' => false, 'robots' => false, 'caching' => false, 'site-verify' => false, 'content' => ['good' => [], 'bad' => []]];
     if (!empty($cfg['tracking']) && $cfg['tracking'] != '') {
         $analysis['tracking'] = true;
     }
     $sitemap = \Phire\Table\Modules::findBy(['name' => 'phire-sitemap']);
     if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . '/sitemap.xml') || isset($sitemap->id) && $sitemap->active) {
         $analysis['sitemap'] = true;
     }
     if (file_exists($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . '/robots.txt') || isset($cfg['robots']) && !empty($cfg['robots']) && $cfg['robots'] != '') {
         $analysis['robots'] = true;
     }
     $cacheDetect = false;
     $curl = new Curl('http://' . $_SERVER['HTTP_HOST'] . BASE_PATH);
     if ($curl->getCode() == 200 && null !== $curl->getHeader('Cache-Control') && null !== $curl->getHeader('Expires') && null !== $curl->getHeader('Last-Modified') && null !== $curl->getHeader('Etag')) {
         $cacheDetect = true;
     }
     $cache = \Phire\Table\Modules::findBy(['name' => 'phire-cache']);
     if ($cacheDetect || isset($cache->id) && $cache->active) {
         $analysis['caching'] = true;
     }
     $dir = new Dir($_SERVER['DOCUMENT_ROOT'] . BASE_PATH, ['relative' => true, 'filesOnly' => true]);
     $googleFileDetect = false;
     foreach ($dir->getFiles() as $file) {
         if (substr($file, 0, 6) == 'google' && strpos(file_get_contents($_SERVER['DOCUMENT_ROOT'] . BASE_PATH . '/' . $file), 'google-site-verification') !== false) {
             $googleFileDetect = true;
         }
     }
     $googleMetaDetect = false;
     if (isset($cfg['meta'])) {
         foreach ($cfg['meta'] as $meta) {
             if ($meta['name'] == 'google-site-verification') {
                 $googleMetaDetect = true;
             }
         }
     }
     if ($googleFileDetect || $googleMetaDetect) {
         $analysis['site-verify'] = true;
     } else {
         if (function_exists('dns_get_record') && $_SERVER['HTTP_HOST'] != 'localhost') {
             $dns = dns_get_record($_SERVER['HTTP_HOST'], DNS_TXT);
             if (count($dns) > 0) {
                 foreach ($dns as $record) {
                     if (isset($record['txt']) && strpos($record['txt'], 'google-site-verification') !== false) {
                         $analysis['site-verify'] = true;
                     }
                 }
             }
         }
     }
     $fields = ['seo_title' => '', 'description' => '', 'keywords' => ''];
     $seoTitle = \Phire\Fields\Table\Fields::findBy(['name' => 'seo_title']);
     $description = \Phire\Fields\Table\Fields::findBy(['name' => 'description']);
     $keywords = \Phire\Fields\Table\Fields::findBy(['name' => 'keywords']);
     if (isset($seoTitle->id)) {
         $fields['seo_title'] = $seoTitle->id;
     }
     if (isset($description->id)) {
         $fields['description'] = $description->id;
     }
     if (isset($keywords->id)) {
         $fields['keywords'] = $keywords->id;
     }
     $content = \Phire\Content\Table\Content::findAll();
     foreach ($content->rows() as $c) {
         if (!in_array($c->type_id, $exclude)) {
             $seoTitle = '';
             $metaDesc = '';
             $metaKeys = '';
             if ($fields['seo_title'] != '') {
                 $seoTitleField = \Phire\Fields\Table\FieldValues::findById([$fields['seo_title'], $c->id, "Phire\\Content\\Model\\Content"]);
                 if (isset($seoTitleField->field_id)) {
                     $seoTitle = json_decode($seoTitleField->value);
                 }
             }
             if ($fields['description'] != '') {
                 $descriptionField = \Phire\Fields\Table\FieldValues::findById([$fields['description'], $c->id, "Phire\\Content\\Model\\Content"]);
                 if (isset($descriptionField->field_id)) {
                     $metaDesc = json_decode($descriptionField->value);
                 }
             }
             if ($fields['keywords'] != '') {
                 $keywordsField = \Phire\Fields\Table\FieldValues::findById([$fields['keywords'], $c->id, "Phire\\Content\\Model\\Content"]);
                 if (isset($keywordsField->field_id)) {
                     $metaKeys = json_decode($keywordsField->value);
                 }
             }
             if (strlen($seoTitle) > 0 && strlen($seoTitle) <= 60 && strlen($metaDesc) > 0 && strlen($metaDesc) <= 160 && strlen($metaKeys) > 0 && strlen($metaKeys) <= 255) {
                 $analysis['content']['good'][$c->id] = ['title' => $c->title, 'uri' => $c->uri];
             } else {
                 $analysis['content']['bad'][$c->id] = ['title' => $c->title, 'type_id' => $c->type_id, 'uri' => $c->uri, 'issues' => []];
                 if (strlen($seoTitle) == 0) {
                     $analysis['content']['bad'][$c->id]['issues'][] = 'No SEO Title';
                 } else {
                     if (strlen($seoTitle) > 60) {
                         $analysis['content']['bad'][$c->id]['issues'][] = 'SEO Title is too long';
                     }
                 }
                 if (strlen($metaDesc) == 0) {
                     $analysis['content']['bad'][$c->id]['issues'][] = 'No description meta tag';
                 } else {
                     if (strlen($metaDesc) > 160) {
                         $analysis['content']['bad'][$c->id]['issues'][] = 'Description meta tag is too long';
                     }
                 }
                 if (strlen($metaKeys) == 0) {
                     $analysis['content']['bad'][$c->id]['issues'][] = 'No keywords meta tag';
                 } else {
                     if (strlen($metaKeys) > 255) {
                         $analysis['content']['bad'][$c->id]['issues'][] = 'Keywords meta tag is too long';
                     }
                 }
             }
         }
     }
     $config = Table\Config::findById('seo_analysis');
     $config->value = serialize($analysis);
     $config->save();
 }
コード例 #13
0
ファイル: Content.php プロジェクト: phirecms/phire-content
 /**
  * Get content children
  *
  * @param  mixed   $content
  * @param  array   $selectFields
  * @param  array   $params
  * @param  boolean $trash
  * @param  string  $order
  * @param  int     $depth
  * @return array
  */
 protected function getChildren($content, $selectFields, $params, $trash, $order, $depth = 0)
 {
     $children = [];
     $sql = Table\Content::sql();
     $sql->select($selectFields)->join(DB_PREFIX . 'users', [DB_PREFIX . 'users.id' => DB_PREFIX . 'content.created_by']);
     $params = ['parent_id' => $content->id] + $params;
     $by = explode(' ', $order);
     $sql->select()->orderBy($by[0], $by[1]);
     $sql->select()->where('parent_id = :parent_id');
     if (isset($params['type_id'])) {
         $sql->select()->where('type_id = :type_id');
     }
     if ($trash) {
         $sql->select()->where('status = :status');
     } else {
         $sql->select()->where('status > :status');
     }
     if (isset($params[DB_PREFIX . 'content.title'])) {
         $sql->select()->where(DB_PREFIX . 'content.title LIKE :title');
     }
     $child = Table\Content::execute((string) $sql, $params);
     if ($child->hasRows()) {
         foreach ($child->rows() as $c) {
             $this->flatMap[] = new \ArrayObject(['id' => $c->id, 'type_id' => $c->type_id, 'parent_id' => $c->parent_id, 'title' => $c->title, 'uri' => $c->uri, 'slug' => $c->slug, 'status' => $c->status, 'roles' => $c->roles, 'order' => $c->order, 'publish' => $c->publish, 'expire' => $c->expire, 'created' => $c->created, 'updated' => $c->updated, 'created_by' => $c->created_by, 'updated_by' => $c->updated_by, 'created_by_username' => $c->created_by_username, 'depth' => $depth + 1], \ArrayObject::ARRAY_AS_PROPS);
             $c->depth = $depth + 1;
             $c->children = $this->getChildren($c, $selectFields, $params, $trash, $order, $depth + 1);
             $children[] = $c;
         }
     }
     return $children;
 }
コード例 #14
0
 /**
  * JSON action method
  *
  * @param  int $id
  * @return void
  */
 public function json($id)
 {
     $json = ['parent_uri' => ''];
     $content = Table\Content::findById($id);
     if (isset($content->id)) {
         $json['parent_uri'] = $content->uri;
     }
     $this->response->setBody(json_encode($json, JSON_PRETTY_PRINT));
     $this->send(200, ['Content-Type' => 'application/json']);
 }