Пример #1
0
 /**
  * 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
 /**
  * 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();
         }
     }
 }
Пример #3
0
 /**
  * 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;
 }
Пример #4
0
 /**
  * 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;
 }