Ejemplo n.º 1
0
 function build_autos($items, $data, $user)
 {
     foreach ($items as $index => &$item) {
         if (isset($item['auto'])) {
             if (isset($data['urls'][$item['auto']])) {
                 $item['path'] = $data['urls'][$item['auto']];
             } else {
                 if ($item['auto'] === 'set') {
                     $item['path'] = '';
                 }
             }
             if ($item['auto'] === 'profile') {
                 switch ($item['id']) {
                     case 'twitter':
                         $item['path'] = 'https://twitter.com/' . $user->twitter;
                         break;
                     default:
                         $item['path'] = $user->{$item['id']};
                         if (empty($item['path'])) {
                             unset($items[$index]);
                             continue;
                         }
                         break;
                 }
                 if (!isset($item['label']) || empty($item['label'])) {
                     $item['label'] = ucwords($item['id']) . ($item['id'] === 'google' ? '+' : '');
                 }
             } else {
                 if ($item['auto'] === 'rss') {
                     $item['path'] = '/feed/' . $item['id'] . ($item['id'] === 'essay' ? 's' : '') . '/recent.rss';
                     if (!isset($item['label'])) {
                         $item['label'] = $data['url_data'][$item['id']]['plural'] . ' RSS';
                     }
                 } else {
                     if (preg_match('/s$/', $item['auto']) || $item['auto'] === 'timeline') {
                         if ($item['auto'] === 'timeline' && isset($item['year'])) {
                             $item['path'] .= $item['year'] . '/';
                             if (isset($item['month']) && $item['month'] !== false && $item['month'] !== 'any') {
                                 $m = str_pad($item['month'], 2, '0', STR_PAD_LEFT);
                                 $item['path'] .= $m . '/';
                             }
                         }
                         if (strpos($item['auto'], '_') !== false) {
                             foreach (array('id', 'slug', 'month', 'year', 'day') as $id) {
                                 if ($id === 'month') {
                                     if (!isset($item['month']) || $item['month'] === 'any' || $item['month'] === false) {
                                         $item['month'] = '';
                                     } else {
                                         $item['month'] = str_pad($item['month'], 2, '0', STR_PAD_LEFT);
                                     }
                                 }
                                 if ($id === 'day' && !isset($item['day'])) {
                                     $item['day'] = '';
                                 }
                                 if ($id === 'slug' && !isset($item['slug']) && isset($item['id'])) {
                                     if (strpos($item['auto'], 'tag_') === 0) {
                                         $item['slug'] = $item['id'];
                                     } else {
                                         $c = new Category();
                                         if (is_numeric($item['id'])) {
                                             $c->select('slug')->get_by_id($item['id']);
                                             $item['slug'] = $c->slug;
                                         } else {
                                             $item['slug'] = $item['id'];
                                         }
                                     }
                                 }
                                 if (isset($item[$id])) {
                                     $item['path'] = str_replace(":{$id}", $item[$id], $item['path']);
                                 }
                             }
                         } else {
                             if (!isset($item['label'])) {
                                 $item['label'] = $data['url_data'][$item['auto'] === 'categories' ? 'category' : rtrim($item['auto'], 's')]['plural'];
                             }
                         }
                     } else {
                         if ($item['auto'] === 'home') {
                             if (!isset($item['label'])) {
                                 $item['label'] = $data['url_data']['home'];
                             }
                             $item['path'] = '/home/';
                         } else {
                             if ($item['auto'] === 'album' || $item['auto'] === 'set') {
                                 $a = new Album();
                                 $a->select('id,slug,created_on,title');
                                 if (is_numeric($item['id'])) {
                                     $a->where('id', $item['id']);
                                 } else {
                                     $a->where('slug', $item['id'])->or_where('internal_id', $item['id']);
                                 }
                                 $a->get();
                                 if (!$a->exists()) {
                                     unset($items[$index]);
                                     continue;
                                 }
                                 $item['path'] = str_replace(':id', $a->id, $item['path']);
                                 $item['path'] = str_replace(':slug', $a->slug, $item['path']);
                                 $item['path'] = str_replace(':year', date('Y', $a->created_on), $item['path']);
                                 $item['path'] = str_replace(':month', date('m', $a->created_on), $item['path']);
                                 $item['path'] = str_replace(':day', date('d', $a->created_on), $item['path']);
                                 if (!isset($item['label'])) {
                                     $item['label'] = $a->title;
                                 }
                             } else {
                                 if ($item['auto'] === 'page' || $item['auto'] === 'essay') {
                                     $t = new Text();
                                     $t->select('id,slug,published_on,title');
                                     if (is_numeric($item['id'])) {
                                         $t->where('id', $item['id']);
                                     } else {
                                         $t->where('slug', $item['id']);
                                     }
                                     $t->get();
                                     if (!$t->exists()) {
                                         unset($items[$index]);
                                         continue;
                                     }
                                     $item['path'] = str_replace(':id', $t->id, $item['path']);
                                     $item['path'] = str_replace(':slug', $t->slug, $item['path']);
                                     $item['path'] = str_replace(':year', date('Y', $t->published_on), $item['path']);
                                     $item['path'] = str_replace(':month', date('m', $t->published_on), $item['path']);
                                     $item['path'] = str_replace(':day', date('d', $t->published_on), $item['path']);
                                     if (!isset($item['label'])) {
                                         $item['label'] = $t->title;
                                     }
                                 } else {
                                     if ($item['auto'] === 'content') {
                                         $c = new Content();
                                         $c->select('id,slug,captured_on,title');
                                         if (isset($item['album_id'])) {
                                             $item['path'] = preg_replace('/:(id|slug)/', ':album_$1', $data['urls']['album']) . substr(str_replace(':year/:month/', '', $data['urls']['content']), 1);
                                             $a = new Album();
                                             $a->select('id,slug,created_on,title');
                                             if (is_numeric($item['album_id'])) {
                                                 $a->where('id', $item['album_id']);
                                             } else {
                                                 $a->where('slug', $item['album_id'])->or_where('internal_id', $item['album_id']);
                                             }
                                             $a->get();
                                             if (!$a->exists()) {
                                                 unset($items[$index]);
                                                 continue;
                                             }
                                             $item['path'] = str_replace(':album_id', $a->id, $item['path']);
                                             $item['path'] = str_replace(':album_slug', $a->slug, $item['path']);
                                             $date = $a->created_on;
                                         } else {
                                             $date = $c->captured_on;
                                         }
                                         if (is_numeric($item['id'])) {
                                             $c->where('id', $item['id']);
                                         } else {
                                             $c->where('slug', $item['id'])->or_where('internal_id', $item['id']);
                                         }
                                         $c->get();
                                         if (!$c->exists()) {
                                             unset($items[$index]);
                                             continue;
                                         }
                                         $item['path'] = str_replace(':id', $c->id, $item['path']);
                                         $item['path'] = str_replace(':slug', $c->slug, $item['path']);
                                         $item['path'] = str_replace(':year', date('Y', $date), $item['path']);
                                         $item['path'] = str_replace(':month', date('m', $date), $item['path']);
                                         $item['path'] = str_replace(':day', date('d', $date), $item['path']);
                                         if (!isset($item['label'])) {
                                             $item['label'] = $c->title;
                                         }
                                         if (isset($item['lightbox']) && $item['lightbox']) {
                                             $item['path'] .= 'lightbox/';
                                         }
                                     } else {
                                         if ($item['auto'] === 'tag') {
                                             $item['path'] = str_replace(':slug', $item['id'], $item['path']);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
             if ($item['auto'] !== 'profile') {
                 $item['path'] = str_replace(array(':year', ':month'), '', $item['path']);
                 $item['path'] = preg_replace('/[\\(\\)\\?\\:]/', '', $item['path']);
                 $item['path'] = preg_replace('~[/]+~', '/', $item['path']);
             }
         }
     }
     return $items;
 }
Ejemplo n.º 2
0
 function listing($params)
 {
     $sort = $this->_get_site_order('essay');
     $options = array('page' => 1, 'order_by' => $sort['by'], 'order_direction' => $sort['direction'], 'tags' => false, 'tags_not' => false, 'match_all_tags' => false, 'limit' => 100, 'published' => 1, 'category' => false, 'category_not' => false, 'featured' => null, 'type' => false, 'state' => false, 'year' => false, 'year_not' => false, 'letter' => false, 'month' => false, 'month_not' => false, 'day' => false, 'day_not' => false, 'render' => true, 'tags' => false);
     $options = array_merge($options, $params);
     if (isset($params['order_by']) && !isset($params['order_direction'])) {
         $options['order_direction'] = in_array($params['order_by'], array('title')) ? 'ASC' : 'DESC';
     }
     if (!$options['auth']) {
         $options['state'] = 'published';
     }
     if ($options['featured'] == 1 && !isset($params['order_by'])) {
         $options['order_by'] = 'featured_on';
     }
     if (is_numeric($options['limit']) && $options['limit'] > 0) {
         $options['limit'] = min($options['limit'], 100);
     } else {
         $options['limit'] = 100;
     }
     if ($options['type']) {
         if ($options['type'] === 'essay') {
             $this->where('page_type', 0);
         } else {
             if ($options['type'] === 'page') {
                 $this->where('page_type', 1);
             }
         }
     }
     if ($options['auth'] && $options['type'] === 'page') {
         $options['state'] = false;
         $options['order_by'] = 'modified_on';
     }
     if ($options['state']) {
         if ($options['state'] === 'published') {
             $this->where('published', 1);
         } else {
             if ($options['state'] === 'draft' && $options['order_by'] !== 'published_on') {
                 $this->where('published', 0);
             }
         }
     }
     if ($options['order_by'] === 'published_on') {
         $this->where('published', 1);
     }
     if ($options['tags'] || $options['tags_not']) {
         $this->_do_tag_filtering($options);
     }
     if (!is_null($options['featured'])) {
         $this->where('featured', $options['featured']);
         if ($options['featured']) {
             $this->where('published', 1);
         }
     }
     if ($options['category']) {
         $this->where_related('category', 'id', $options['category']);
     } else {
         if ($options['category_not']) {
             $cat = new Text();
             $cat->select('id')->where_related('category', 'id', $options['category_not'])->get_iterated();
             $cids = array();
             foreach ($cat as $c) {
                 $cids[] = $c->id;
             }
             $this->where_not_in('id', $cids);
         }
     }
     if ($options['order_by'] === 'created_on' || $options['order_by'] === 'published_on' || $options['order_by'] === 'modified_on') {
         $bounds_order = $options['order_by'];
     } else {
         $bounds_order = 'published_on';
     }
     $s = new Setting();
     $s->where('name', 'site_timezone')->get();
     $tz = new DateTimeZone($s->value);
     $offset = $tz->getOffset(new DateTime('now', new DateTimeZone('UTC')));
     if ($offset === 0) {
         $shift = '';
     } else {
         $shift = ($offset < 0 ? '-' : '+') . abs($offset);
     }
     // Do this before date filters are applied, and only if sorted by created_on
     $bounds = $this->get_clone()->select('COUNT(DISTINCT ' . $this->table . '.id) as count, MONTH(FROM_UNIXTIME(' . $bounds_order . $shift . ')) as month, YEAR(FROM_UNIXTIME(' . $bounds_order . $shift . ')) as year')->group_by('month,year')->order_by('year')->get_iterated();
     $dates = array();
     foreach ($bounds as $b) {
         if (!isset($dates[$b->year])) {
             $dates[$b->year] = array();
         }
         $dates[$b->year][$b->month] = (int) $b->count;
     }
     if (in_array($options['order_by'], array('created_on', 'published_on', 'modified_on'))) {
         $date_col = $options['order_by'];
     } else {
         $date_col = 'published_on';
     }
     // So featured_image eager loading doesn't break this down (ambiguous column name)
     $date_col = $this->table . '.' . $date_col;
     if ($options['year'] || $options['year_not']) {
         if ($options['year_not']) {
             $options['year'] = $options['year_not'];
             $compare = ' !=';
         } else {
             $compare = '';
         }
         $this->where('YEAR(FROM_UNIXTIME(' . $date_col . $shift . '))' . $compare, $options['year']);
     }
     if ($options['month'] || $options['month_not']) {
         if ($options['month_not']) {
             $options['month'] = $options['month_not'];
             $compare = ' !=';
         } else {
             $compare = '';
         }
         $this->where('MONTH(FROM_UNIXTIME(' . $date_col . $shift . '))' . $compare, $options['month']);
     }
     if ($options['day'] || $options['day_not']) {
         if ($options['day_not']) {
             $options['day'] = $options['day_not'];
             $compare = ' !=';
         } else {
             $compare = '';
         }
         $this->where('DAY(FROM_UNIXTIME(' . $date_col . $shift . '))' . $compare, $options['day']);
     }
     if ($options['letter']) {
         if ($options['letter'] === 'num') {
             $this->where('title <', 'a');
         } else {
             $this->like('title', $options['letter'], 'after');
         }
     }
     $final = $this->paginate($options);
     $final['dates'] = $dates;
     $this->include_related('featured_image', null, true, true);
     $this->include_related_count('albums', null, array('visibility' => 0));
     $this->include_related_count('categories');
     $data = $this->order_by($options['order_by'] . ' ' . $options['order_direction'] . ', id ' . $options['order_direction'])->get_iterated();
     if (!$options['limit']) {
         $final['per_page'] = $data->result_count();
         $final['total'] = $data->result_count();
     }
     $final['counts'] = array('total' => $final['total']);
     $final['text'] = array();
     $final['sort'] = $sort;
     $tag_map = $this->_eager_load_tags($data);
     foreach ($data as $page) {
         $tags = isset($tag_map['c' . $page->id]) ? $tag_map['c' . $page->id] : array();
         $options['eager_tags'] = $tags;
         $final['text'][] = $page->to_array($options);
     }
     return $final;
 }
Ejemplo n.º 3
0
 public static function indexationBuild()
 {
     set_time_limit(0);
     /*         * ****** PAGE ******* */
     $pageSelect = new PagesIndex();
     $select = $pageSelect->select()->where('PI_Status = 1');
     $pageData = $pageSelect->fetchAll($select)->toArray();
     $cpt = count($pageData);
     for ($i = 0; $i < $cpt; $i++) {
         $indexData['action'] = "add";
         $indexData['pageID'] = $pageData[$i]['PI_PageID'];
         $indexData['moduleID'] = 0;
         $indexData['contentID'] = $pageData[$i]['PI_PageID'];
         $indexData['languageID'] = $pageData[$i]['PI_LanguageID'];
         $indexData['title'] = $pageData[$i]['PI_PageTitle'];
         $indexData['text'] = '';
         $indexData['link'] = '';
         $indexData['contents'] = $pageData[$i]['PI_PageTitle'];
         Cible_FunctionsIndexation::indexation($indexData);
     }
     /*         * ****** TEXT ******* */
     if (class_exists('Text', false)) {
         $textSelect = new Text();
         $select = $textSelect->select()->setIntegrityCheck(false)->from('TextData', array('ID' => 'TD_ID', 'LanguageID' => 'TD_LanguageID', 'Text' => 'TD_OnlineText'))->join('Blocks', 'B_ID = TD_BlockID', array('BlockID' => 'B_ID', 'ModuleID' => 'B_ModuleID'))->where('B_Online = 1')->join('PagesIndex', 'PI_PageID = B_PageID', array('PageID' => 'PI_PageID', 'Title' => 'PI_PageTitle'))->where('PI_Status = 1')->where('PI_LanguageID = TD_LanguageID');
         $textData = $textSelect->fetchAll($select)->toArray();
         $cpt = count($textData);
         for ($i = 0; $i < $cpt; $i++) {
             $indexData['action'] = "add";
             $indexData['pageID'] = $textData[$i]['PageID'];
             $indexData['moduleID'] = $textData[$i]['ModuleID'];
             $indexData['contentID'] = $textData[$i]['ID'];
             $indexData['languageID'] = $textData[$i]['LanguageID'];
             $indexData['title'] = $textData[$i]['Title'];
             $indexData['text'] = '';
             $indexData['link'] = '';
             $indexData['contents'] = $textData[$i]['Title'] . " " . $textData[$i]['Text'];
             Cible_FunctionsIndexation::indexation($indexData);
         }
     }
     /*         * ********************* */
     /*         * ****** NEWS ******* */
     if (class_exists('NewsData', false)) {
         $newsSelect = new NewsData();
         $select = $newsSelect->select()->setIntegrityCheck(false)->from('NewsData', array('NewsID' => 'ND_ID', 'CategoryID' => 'ND_CategoryID'))->join('NewsIndex', 'NI_NewsDataID = ND_ID', array('LanguageID' => 'NI_LanguageID', 'NewsTitle' => 'NI_Title', 'NewsBrief' => 'NI_Brief', 'NewsText' => 'NI_Text', 'NewsImageAlt' => 'NI_ImageAlt'))->where('NI_Status = 1');
         $newsData = $newsSelect->fetchAll($select);
         $cpt = count($newsData);
         for ($i = 0; $i < $cpt; $i++) {
             $indexData['action'] = "add";
             $indexData['pageID'] = $newsData[$i]['CategoryID'];
             $indexData['moduleID'] = 2;
             $indexData['contentID'] = $newsData[$i]['NewsID'];
             $indexData['languageID'] = $newsData[$i]['LanguageID'];
             $indexData['title'] = $newsData[$i]['NewsTitle'];
             $indexData['text'] = '';
             $indexData['link'] = '';
             $indexData['contents'] = $newsData[$i]['NewsTitle'] . " " . $newsData[$i]['NewsBrief'] . " " . $newsData[$i]['NewsText'] . " " . $newsData[$i]['NewsImageAlt'];
             Cible_FunctionsIndexation::indexation($indexData);
         }
     }
     /*         * ********************* */
     /*         * ****** EVENTS ******* */
     if (class_exists('EventsIndex', false)) {
         $eventsSelect = new EventsIndex();
         $select = $eventsSelect->select()->setIntegrityCheck(false)->from('EventsIndex', array('ID' => 'EI_EventsDataID', 'LanguageID' => 'EI_LanguageID', 'Title' => 'EI_Title', 'Brief' => 'EI_Brief', 'Text' => 'EI_Text', 'ImageAlt' => 'EI_ImageAlt'))->join('EventsData', 'ED_ID = EI_EventsDataID', array('CategoryID' => 'ED_CategoryID'))->where('EI_Status = 1');
         $eventsData = $eventsSelect->fetchAll($select)->toArray();
         $cpt = count($eventsData);
         for ($i = 0; $i < $cpt; $i++) {
             $indexData['action'] = "add";
             $indexData['pageID'] = $eventsData[$i]['CategoryID'];
             $indexData['moduleID'] = 7;
             $indexData['contentID'] = $eventsData[$i]['ID'];
             $indexData['languageID'] = $eventsData[$i]['LanguageID'];
             $indexData['title'] = $eventsData[$i]['Title'];
             $indexData['text'] = '';
             $indexData['link'] = '';
             $indexData['contents'] = $eventsData[$i]['Title'] . " " . $eventsData[$i]['Brief'] . " " . $eventsData[$i]['Text'] . " " . $eventsData[$i]['ImageAlt'];
             Cible_FunctionsIndexation::indexation($indexData);
         }
     }
     /*         * ********************* */
     /*         * ****** GALLERY ******* */
     if (class_exists('Galleries', false)) {
         $gallerySelect = new Galleries();
         $select = $gallerySelect->select()->setIntegrityCheck(false)->from('Galleries', array('ID' => 'G_ID', 'CategoryID' => 'G_CategoryID'))->where('G_Online = 1')->join('GalleriesIndex', 'GI_GalleryID = G_ID', array('LanguageID' => 'GI_LanguageID', 'Title' => 'GI_Title', 'Description' => 'GI_Description'))->join('ImagesIndex', 'II_ImageID = G_ImageID', array('ImageTitle' => 'II_Title', 'ImageDescription' => 'II_Description'))->where('II_LanguageID = GI_LanguageID');
         $galleryData = $gallerySelect->fetchAll($select);
         $cpt = count($galleryData);
         for ($i = 0; $i < $cpt; $i++) {
             $indexData['action'] = "add";
             $indexData['pageID'] = $galleryData[$i]['CategoryID'];
             $indexData['moduleID'] = 9;
             $indexData['contentID'] = $galleryData[$i]['ID'];
             $indexData['languageID'] = $galleryData[$i]['LanguageID'];
             $indexData['title'] = $galleryData[$i]['Title'];
             $indexData['text'] = '';
             $indexData['link'] = 'gallery';
             $indexData['contents'] = $galleryData[$i]['Title'] . " " . $galleryData[$i]['Description'] . " " . $galleryData[$i]['ImageTitle'] . " " . $galleryData[$i]['ImageDescription'];
             Cible_FunctionsIndexation::indexation($indexData);
             $imagesSelect = new GalleriesImages();
             $select = $imagesSelect->select()->setIntegrityCheck(false)->from('Galleries_Images', array('ID' => 'GI_ImageID'))->where('GI_GalleryID = ?', $galleryData[$i]['ID'])->where('GI_Online = 1')->join('ImagesIndex', 'II_ImageID = GI_ImageID', array('LanguageID' => 'II_LanguageID', 'Title' => 'II_Title', 'Description' => 'II_Description'));
             $imagesData = $imagesSelect->fetchAll($select);
             $cptImage = count($imagesData);
             for ($y = 0; $y < $cptImage; $y++) {
                 $indexData['action'] = "add";
                 $indexData['pageID'] = $galleryData[$i]['CategoryID'];
                 $indexData['moduleID'] = 9;
                 $indexData['contentID'] = $galleryData[$i]['ID'];
                 $indexData['languageID'] = $imagesData[$y]['LanguageID'];
                 $indexData['title'] = $imagesData[$y]['Title'];
                 $indexData['text'] = '';
                 $indexData['link'] = 'image';
                 $indexData['contents'] = $imagesData[$y]['Title'] . " " . $imagesData[$y]['Description'];
                 Cible_FunctionsIndexation::indexation($indexData);
             }
         }
     }
     /*         * ********************* */
     /*         * ****** NEWSLETTERS ******* */
     if (class_exists('NewsletterRelease', false)) {
         $newsletterSelect = new NewsletterReleases();
         $select = $newsletterSelect->select()->from('Newsletter_Releases', array('ID' => 'NR_ID', 'LanguageID' => 'NR_LanguageID', 'Title' => 'NR_Title'))->where('NR_Online = 1');
         $newsletterData = $newsletterSelect->fetchAll($select)->toArray();
         $cpt = count($newsletterData);
         for ($i = 0; $i < $cpt; $i++) {
             $indexData['action'] = "add";
             $indexData['pageID'] = $newsletterData[$i]['ID'];
             $indexData['moduleID'] = 8;
             $indexData['contentID'] = $newsletterData[$i]['ID'];
             $indexData['languageID'] = $newsletterData[$i]['LanguageID'];
             $indexData['title'] = $newsletterData[$i]['Title'];
             $indexData['text'] = '';
             $indexData['link'] = 'release';
             $indexData['contents'] = $newsletterData[$i]['Title'];
             Cible_FunctionsIndexation::indexation($indexData);
             $articlesSelect = new NewsletterArticles();
             $select = $articlesSelect->select()->from('Newsletter_Articles', array('ID' => 'NA_ID', 'Title' => 'NA_Title', 'Resume' => 'NA_Resume', 'Text' => 'NA_Text'))->where('NA_ReleaseID = ?', $newsletterData[$i]['ID']);
             $articlesData = $articlesSelect->fetchAll($select);
             $cptArticle = count($articlesData);
             for ($y = 0; $y < $cptArticle; $y++) {
                 $indexData['action'] = "add";
                 $indexData['pageID'] = $newsletterData[$i]['ID'];
                 $indexData['moduleID'] = 8;
                 $indexData['contentID'] = $articlesData[$y]['ID'];
                 $indexData['languageID'] = $newsletterData[$i]['LanguageID'];
                 $indexData['title'] = $articlesData[$y]['Title'];
                 $indexData['text'] = '';
                 $indexData['link'] = 'article';
                 $indexData['contents'] = $articlesData[$y]['Title'] . " " . $articlesData[$y]['Resume'] . " " . $articlesData[$y]['Text'];
                 Cible_FunctionsIndexation::indexation($indexData);
             }
         }
     }
     /*         * ********************* */
 }
Ejemplo n.º 4
0
 function aggregate($type, $options = array())
 {
     $options = array_merge(array('featured' => false), $options);
     $shared_params = array();
     if ($type === 'tag') {
         $shared_params['tags'] = $options['tag_slug'];
     } else {
         if ($type === 'category') {
             $shared_params['category'] = $options['category'];
         }
     }
     $album_params = $shared_params;
     $date_marker = false;
     if ($type === 'date') {
         $s = new Setting();
         $s->where('name', 'site_timezone')->get();
         $tz = new DateTimeZone($s->value);
         $offset = $tz->getOffset(new DateTime('now', new DateTimeZone('UTC')));
         if ($offset === 0) {
             $shift = '';
         } else {
             $shift = ($offset < 0 ? '-' : '+') . abs($offset);
         }
         // Need to - the offset here, as we need to shift this timestamp by the inverse of the offset to match DB UTC time.
         // For example. Midnight in user's time (say, CT -5) is UTC+5.
         $album_params['before'] = $date_marker = strtotime("{$options['year']}-{$options['month']}-{$options['day']} 23:59:59") - $offset;
     }
     $aggregate = $essay_ids = $album_ids = $content_ids = $updated_album_ids = $exclude_albums = $exclude_content = $sets = $range = array();
     $t = new Text();
     $t->select('id, featured, featured_image_id, published_on')->where('page_type', 0)->where('published', 1);
     if ($type === 'date') {
         $t->where("YEAR(FROM_UNIXTIME({$t->table}.published_on{$shift}))", $options['year'])->where("MONTH(FROM_UNIXTIME({$t->table}.published_on{$shift}))", $options['month'])->where("DAY(FROM_UNIXTIME({$t->table}.published_on{$shift}))", $options['day']);
     } else {
         if ($type === 'tag') {
             $t->where_related('tag', 'id', $options['tag']);
         } else {
             $t->where_related('category', 'id', $options['category']);
         }
     }
     if ($options['featured']) {
         $t->where('featured', 1);
     }
     $t->include_related('album', 'id')->order_by($t->table . '.published_on DESC')->get_iterated();
     foreach ($t as $essay) {
         $essay_ids[$essay->id] = $essay->published_on;
         $aggregate[] = array('type' => 'essay', 'id' => $essay->id, 'date' => $essay->published_on, 'featured' => $essay->featured);
         if ($essay->album_id) {
             $exclude_albums[] = $essay->album_id;
         }
         if (is_numeric($essay->featured_image_id)) {
             $exclude_content[] = $essay->featured_image_id;
         }
     }
     $a = new Album();
     $a->select('id, featured, published_on, left_id, right_id, level')->where('visibility', 0)->where('deleted', 0)->where('total_count >', 0);
     if ($type === 'date') {
         $a->where("YEAR(FROM_UNIXTIME({$a->table}.published_on{$shift}))", $options['year'])->where("MONTH(FROM_UNIXTIME({$a->table}.published_on{$shift}))", $options['month'])->where("DAY(FROM_UNIXTIME({$a->table}.published_on{$shift}))", $options['day']);
     } else {
         if ($type === 'tag') {
             $a->where_related('tag', 'id', $options['tag']);
         } else {
             $a->where_related('category', 'id', $options['category']);
         }
     }
     if ($options['featured']) {
         $a->where('featured', 1);
     }
     $a->include_related('content', 'id')->order_by($a->table . '.published_on DESC')->get_iterated();
     foreach ($a as $album) {
         if (is_numeric($album->content_id)) {
             $exclude_content[] = $album->content_id;
         }
         if (!array_key_exists($album->id, $album_ids) && !in_array($album->id, $exclude_albums)) {
             $album_ids[$album->id] = $album->published_on;
             $aggregate[] = array('type' => 'album', 'id' => $album->id, 'date' => $album->published_on, 'featured' => $album->featured);
         }
         if ($album->level < 2) {
             $range = array_merge($range, range($album->left_id, $album->right_id));
         }
         if ($album->level > 1) {
             $sets[$album->id] = $album->left_id;
         }
     }
     foreach ($sets as $id => $left) {
         if (in_array($left, $range)) {
             unset($album_ids[$id]);
             foreach ($aggregate as $i => $info) {
                 if ($info['type'] === 'album' && $info['id'] == $id) {
                     unset($aggregate[$i]);
                 }
             }
         }
     }
     $c = new Content();
     $c->select('id, published_on, featured');
     if (!empty($exclude_content)) {
         $c->where_not_in('id', $exclude_content);
     }
     $c->where('visibility', 0)->where('deleted', 0);
     if ($type === 'date') {
         $c->include_related('album')->where("YEAR(FROM_UNIXTIME({$c->table}.published_on{$shift}))", $options['year'])->where("MONTH(FROM_UNIXTIME({$c->table}.published_on{$shift}))", $options['month'])->where("DAY(FROM_UNIXTIME({$c->table}.published_on{$shift}))", $options['day'])->group_start()->where($a->table . '.id', null)->or_where($a->table . '.deleted', 0)->group_end();
     } else {
         if ($type === 'tag') {
             $c->where_related('tag', 'id', $options['tag']);
         } else {
             $c->where_related('category', 'id', $options['category']);
         }
     }
     if ($options['featured']) {
         $c->where('featured', 1);
     }
     $c->order_by($c->table . '.published_on DESC')->get_iterated();
     foreach ($c as $content) {
         if ($content->album_id && $content->album_visibility < 1 && $content->album_published_on <= $date_marker) {
             if (!isset($updated_album_ids[$content->album_id])) {
                 $updated_album_ids[$content->album_id] = array('items' => array($content->id), 'date' => $content->published_on, 'featured' => $content->album_featured);
             } else {
                 $updated_album_ids[$content->album_id]['items'][] = $content->id;
                 $updated_album_ids[$content->album_id]['date'] = max($content->published_on, $updated_album_ids[$content->album_id]['date']);
             }
         } else {
             if (!$content->album_id) {
                 $content_ids[$content->id] = $content->published_on;
                 $aggregate[] = array('type' => 'content', 'id' => $content->id, 'date' => $content->published_on, 'featured' => $content->featured);
             }
         }
     }
     foreach ($updated_album_ids as $id => $a) {
         $aggregate[] = array('type' => 'updated_album', 'id' => $id, 'date' => $a['date'], 'featured' => $a['featured']);
     }
     $total = count($aggregate);
     if (!function_exists('_sort')) {
         function _sort($one, $two)
         {
             if ($one['featured'] && !$two['featured']) {
                 return -1;
             } else {
                 if ($one['featured'] && $two['featured']) {
                     return $one['date'] < $two['date'] ? 1 : -1;
                 }
             }
             return $two['featured'] || $one['date'] < $two['date'] || $one['date'] === $two['date'] && $two['id'] > $one['id'] ? 1 : -1;
         }
     }
     usort($aggregate, '_sort');
     $stream = array('page' => (int) isset($options['page']) ? (int) $options['page'] : 1, 'pages' => (int) ceil($total / $options['limit']), 'per_page' => (int) min($options['limit'], $total), 'total' => (int) $total);
     $load = array_slice($aggregate, ($stream['page'] - 1) * $options['limit'], $options['limit']);
     $counts = array('essays' => count($essay_ids), 'albums' => count($album_ids), 'content' => count($content_ids));
     $counts['total'] = $counts['essays'] + $counts['albums'] + $counts['content'];
     $updated_album_ids_arr = $updated_album_ids;
     $essay_ids = $album_ids = $content_ids = $updated_album_ids = $final = $index = array();
     foreach ($load as $i => $item) {
         $index[$item['type'] . '-' . $item['id']] = $i;
         ${$item['type'] . '_ids'}[] = $item['id'];
     }
     if (!empty($essay_ids)) {
         $e = new Text();
         $e->where_in('id', $essay_ids)->get_iterated();
         foreach ($e as $essay) {
             $final[$index['essay-' . $essay->id]] = $essay->to_array($shared_params);
         }
     }
     if (!empty($album_ids)) {
         $a = new Album();
         $a->where_in('id', $album_ids)->get_iterated();
         foreach ($a as $album) {
             $final[$index['album-' . $album->id]] = $album->to_array($album_params);
         }
     }
     if (!empty($content_ids)) {
         $c = new Content();
         $c->where_in('id', $content_ids)->get_iterated();
         foreach ($c as $content) {
             $final[$index['content-' . $content->id]] = $content->to_array(array_merge($shared_params, array('order_by' => 'published_on')));
         }
     }
     if (!empty($updated_album_ids)) {
         $a = new Album();
         $a->where_in('id', $updated_album_ids)->get_iterated();
         foreach ($a as $album) {
             $arr = $album->to_array();
             $arr['event_type'] = 'album_update';
             $arr['content'] = array();
             $info = $updated_album_ids_arr[$album->id];
             $c = new Content();
             $c->where_in('id', $info['items'])->order_by('published_on DESC')->get_iterated();
             foreach ($c as $i => $content) {
                 $carr = $content->to_array(array('order_by' => 'published_on', 'in_album' => $album));
                 if ($i === 0) {
                     $arr['date'] = $carr['date'];
                 }
                 $arr['content'][] = $carr;
             }
             $final[$index['updated_album-' . $album->id]] = $arr;
         }
     }
     ksort($final);
     $stream['items'] = array_values($final);
     return array($stream, $counts);
 }
Ejemplo n.º 5
0
 function listing($params, $id = false)
 {
     $sort = $this->_get_site_order('content');
     $options = array('order_by' => $sort['by'], 'order_direction' => $sort['direction'], 'search' => false, 'search_filter' => false, 'tags' => false, 'tags_not' => false, 'page' => 1, 'match_all_tags' => false, 'limit' => 100, 'include_presets' => true, 'featured' => null, 'types' => false, 'auth' => false, 'favorites' => null, 'before' => false, 'after' => false, 'after_column' => 'uploaded_on', 'before_column' => 'uploaded_on', 'category' => false, 'category_not' => false, 'year' => false, 'year_not' => false, 'month' => false, 'month_not' => false, 'day' => false, 'day_not' => false, 'in_album' => false, 'reduce' => false, 'is_cover' => true, 'independent' => false);
     $options = array_merge($options, $params);
     if (isset($params['order_by']) && !isset($params['order_direction'])) {
         $options['order_direction'] = in_array($params['order_by'], array('title', 'filename')) ? 'ASC' : 'DESC';
     }
     Shutter::hook('content.listing', array($this, $options));
     if ($options['featured'] == 1 && !isset($params['order_by'])) {
         $options['order_by'] = 'featured_on';
     } else {
         if ($options['favorites'] == 1 && !isset($params['order_by'])) {
             $options['order_by'] = 'favorited_on';
         }
     }
     if ($options['auth']) {
         if (isset($options['visibility']) && $options['visibility'] !== 'album') {
             $values = array('public', 'unlisted', 'private');
             if (in_array($options['visibility'], $values)) {
                 $options['visibility'] = array_search($options['visibility'], $values);
             } else {
                 if ($options['visibility'] === 'any') {
                     $options['visibility'] = false;
                 } else {
                     $options['visibility'] = 0;
                 }
             }
         } else {
             if (!isset($options['visibility']) || $options['visibility'] !== 'album') {
                 $options['visibility'] = 0;
             }
         }
     } else {
         if ($options['in_album']) {
             $options['visibility'] = 'album';
         } else {
             $options['visibility'] = 0;
         }
     }
     if ($options['visibility'] > 0 && $options['order_by'] === 'published_on') {
         $options['order_by'] = 'captured_on';
     }
     if ($options['order_by'] == 'dimension') {
         $options['order_by'] = 'width * height';
     }
     if (is_numeric($options['limit']) && $options['limit'] > 0) {
         $options['limit'] = min($options['limit'], 100);
     } else {
         $options['limit'] = 100;
     }
     if ($options['independent']) {
         $this->where_related('album', 'id', null);
     }
     if ($options['types']) {
         $types = explode(',', str_replace(' ', '', $options['types']));
         $this->group_start();
         foreach ($types as $t) {
             switch ($t) {
                 case 'photo':
                     $this->or_where('file_type', 0);
                     break;
                 case 'video':
                     $this->or_where('file_type', 1);
                     break;
                 case 'audio':
                     $this->or_where('file_type', 2);
                     break;
             }
         }
         $this->group_end();
     }
     if ($options['search'] && $options['search_filter'] === 'tags') {
         $options['tags'] = $options['search'];
         $options['search'] = false;
     }
     if ($options['search']) {
         $term = urldecode($options['search']);
         if ($options['search_filter']) {
             if ($options['search_filter'] === 'category') {
                 $cat = new Category();
                 $cat->where('title', $term)->get();
                 if ($cat->exists()) {
                     $this->where_related('category', 'id', $cat->id);
                 } else {
                     $this->where_related('category', 'id', 0);
                 }
             } else {
                 $this->group_start();
                 $this->like($options['search_filter'], $term, 'both');
                 $this->group_end();
             }
         } else {
             $this->group_start();
             $this->like('title', $term, 'both');
             $this->or_like('caption', $term, 'both');
             $t = new Tag();
             $t->where('name', $term)->get();
             if ($t->exists()) {
                 $this->or_where_related('tag', 'id', $t->id);
             }
             $this->group_end();
         }
     } else {
         if ($options['tags'] || $options['tags_not']) {
             $this->_do_tag_filtering($options);
         }
     }
     if (!is_null($options['featured'])) {
         $this->where('featured', $options['featured']);
     }
     if (!is_null($options['favorites'])) {
         $this->where('favorite', $options['favorites']);
     }
     if ($options['category']) {
         $this->where_related('category', 'id', $options['category']);
     } else {
         if ($options['category_not']) {
             $cat = new Content();
             $cat->select('id')->where_related('category', 'id', $options['category_not'])->get_iterated();
             $cids = array();
             foreach ($cat as $c) {
                 $cids[] = $c->id;
             }
             $this->where_not_in('id', $cids);
         }
     }
     if ($options['after']) {
         $this->where($options['after_column'] . ' >=', $options['after']);
     }
     if ($options['before']) {
         $this->where($options['before_column'] . ' <=', $options['before']);
     }
     if ($options['visibility'] === 'album') {
         $this->where('visibility <', $options['in_album']->visibility + 1);
     } else {
         if ($options['visibility'] !== false) {
             $this->where('visibility', $options['visibility']);
         }
     }
     if ($id) {
         $sql_order = "ORDER BY FIELD(id,{$id})";
         $id = explode(',', $id);
         $this->where_in('id', $id);
     }
     if ($options['order_by'] === 'captured_on' || $options['order_by'] === 'uploaded_on' || $options['order_by'] === 'modified_on' || $options['order_by'] === 'published_on') {
         $bounds_order = $options['order_by'];
     } else {
         $bounds_order = 'published_on';
     }
     $s = new Setting();
     $s->where('name', 'site_timezone')->get();
     $tz = new DateTimeZone($s->value);
     $offset = $tz->getOffset(new DateTime('now', new DateTimeZone('UTC')));
     if ($offset === 0) {
         $shift = '';
     } else {
         $shift = ($offset < 0 ? '-' : '+') . abs($offset);
     }
     // Do this before date filters are applied
     $bounds = $this->get_clone()->select('COUNT(DISTINCT ' . $this->table . '.id) as count, MONTH(FROM_UNIXTIME(' . $bounds_order . $shift . ')) as month, YEAR(FROM_UNIXTIME(' . $bounds_order . $shift . ')) as year')->group_by('month,year')->order_by('year')->get_iterated();
     $dates = array();
     foreach ($bounds as $b) {
         if (!is_numeric($b->year)) {
             continue;
         }
         if (!isset($dates[$b->year])) {
             $dates[$b->year] = array();
         }
         $dates[$b->year][$b->month] = (int) $b->count;
     }
     if (in_array($options['order_by'], array('captured_on', 'uploaded_on', 'modified_on'))) {
         $date_col = $options['order_by'];
     } else {
         $date_col = 'published_on';
     }
     if ($options['year'] || $options['year_not']) {
         if ($options['year_not']) {
             $options['year'] = $options['year_not'];
             $compare = ' !=';
         } else {
             $compare = '';
         }
         $this->where('YEAR(FROM_UNIXTIME(' . $date_col . $shift . '))' . $compare, $options['year']);
     }
     if ($options['month'] || $options['month_not']) {
         if ($options['month_not']) {
             $options['month'] = $options['month_not'];
             $compare = ' !=';
         } else {
             $compare = '';
         }
         $this->where('MONTH(FROM_UNIXTIME(' . $date_col . $shift . '))' . $compare, $options['month']);
     }
     if ($options['day'] || $options['day_not']) {
         if ($options['day_not']) {
             $options['day'] = $options['day_not'];
             $compare = ' !=';
         } else {
             $compare = '';
         }
         $this->where('DAY(FROM_UNIXTIME(' . $date_col . $shift . '))' . $compare, $options['day']);
         if ($options['reduce']) {
             $a = new Album();
             $a->select('id')->where('deleted', 0)->where('visibility', 0)->where('YEAR(FROM_UNIXTIME(' . $a->table . '.published_on' . $shift . '))', $options['year'])->where('MONTH(FROM_UNIXTIME(' . $a->table . '.published_on' . $shift . '))', $options['month'])->where('DAY(FROM_UNIXTIME(' . $a->table . '.published_on' . $shift . '))', $options['day'])->include_related('content', 'id')->get_iterated();
             $ids = array();
             foreach ($a as $album) {
                 if ($album->content_id) {
                     $ids[] = $album->content_id;
                 }
             }
             $e = new Text();
             $e->select('featured_image_id')->where('page_type', 0)->where('published', 1)->where('featured_image_id >', 0)->where('YEAR(FROM_UNIXTIME(' . $e->table . '.published_on' . $shift . '))', $options['year'])->where('MONTH(FROM_UNIXTIME(' . $e->table . '.published_on' . $shift . '))', $options['month'])->where('DAY(FROM_UNIXTIME(' . $e->table . '.published_on' . $shift . '))', $options['day'])->get_iterated();
             foreach ($e as $essay) {
                 if ($essay->featured_image_id) {
                     $ids[] = $essay->featured_image_id;
                 }
             }
             if (!empty($ids)) {
                 $this->where_not_in('id', $ids);
             }
         }
     }
     $vid_count = $this->get_clone()->where('file_type', 1)->count();
     $aud_count = $this->get_clone()->where('file_type', 2)->count();
     $final = $this->paginate($options);
     $final['dates'] = $dates;
     $this->include_related_count('albums', NULL, array('visibility' => 0));
     $this->include_related_count('categories');
     if ($id && !isset($params['order_by'])) {
         $q = explode('LIMIT', $this->get_sql());
         $query = $q[0] . $sql_order . ' LIMIT ' . $q[1];
         $data = $this->query($query);
     } else {
         if ($options['order_by'] === 'title') {
             $q = explode('LIMIT', $this->get_sql());
             $query = preg_replace('/SELECT\\s(`[^`]+`\\.\\*)/', "SELECT COALESCE(NULLIF(title, ''), filename) as order_title, \$1", $q[0]);
             $query .= 'ORDER BY order_title ' . $options['order_direction'] . ' LIMIT ' . $q[1];
             $data = $this->query($query);
         } else {
             $data = $this->order_by($options['order_by'] . ' ' . $options['order_direction'] . ', id ' . $options['order_direction'])->get_iterated();
         }
     }
     if (!$options['limit']) {
         $final['per_page'] = $data->result_count();
         $final['total'] = $data->result_count();
     }
     $final['counts'] = array('videos' => $vid_count, 'audio' => $aud_count, 'images' => $final['total'] - $vid_count - $aud_count, 'total' => $final['total']);
     $final['content'] = array();
     $final['sort'] = $sort;
     $tag_map = $this->_eager_load_tags($data);
     foreach ($data as $content) {
         $tags = isset($tag_map['c' . $content->id]) ? $tag_map['c' . $content->id] : array();
         $options['eager_tags'] = $tags;
         $final['content'][] = $content->to_array($options);
     }
     return $final;
 }
Ejemplo n.º 6
0
 function listing($params)
 {
     $sort = $this->_get_site_order('album');
     $options = array('trash' => false, 'page' => 1, 'order_by' => $sort['by'], 'order_direction' => $sort['direction'], 'search' => false, 'search_filter' => false, 'tags' => false, 'tags_not' => false, 'match_all_tags' => false, 'limit' => false, 'include_empty' => true, 'types' => false, 'featured' => false, 'category' => false, 'category_not' => false, 'year' => false, 'year_not' => false, 'month' => false, 'month_not' => false, 'day' => false, 'day_not' => false, 'flat' => false, 'reduce' => false, 'id_not' => false, 'auth' => false);
     $options = array_merge($options, $params);
     if (isset($params['order_by']) && !isset($params['order_direction'])) {
         $options['order_direction'] = in_array($params['order_by'], array('created_on', 'modified_on', 'published_on', 'total_count', 'image_count', 'video_count')) ? 'DESC' : 'ASC';
     }
     $options = Shutter::filter('api.albums.listing.options', $options);
     Shutter::hook('albums.listing', array($this, $options));
     if ($options['order_by'] === 'manual') {
         $options['order_by'] = 'left_id';
         if (!isset($params['order_direction'])) {
             $options['order_direction'] = 'asc';
         }
     }
     if ($options['featured'] == 1 && !isset($params['order_by'])) {
         $options['order_by'] = 'featured_on';
     }
     if (!is_numeric($options['limit'])) {
         $options['limit'] = false;
     }
     if ($options['types']) {
         $types = explode(',', str_replace(' ', '', $options['types']));
         $this->group_start();
         foreach ($types as $t) {
             switch ($t) {
                 case 'set':
                     $this->or_where('album_type', 2);
                     break;
                 case 'smart':
                     $this->or_where('album_type', 1);
                     break;
                 case 'standard':
                     $this->or_where('album_type', 0);
                     break;
             }
         }
         $this->group_end();
     }
     if ($options['search'] && $options['search_filter'] === 'tags') {
         $options['tags'] = $options['search'];
         $options['search'] = false;
     }
     if ($options['search']) {
         $term = urldecode($options['search']);
         if ($options['search_filter']) {
             if ($options['search_filter'] === 'category') {
                 $cat = new Category();
                 $cat->where('title', $term)->get();
                 if ($cat->exists()) {
                     $this->where_related('category', 'id', $cat->id);
                 } else {
                     $this->where_related('category', 'id', 0);
                 }
             } else {
                 $this->group_start();
                 $this->like($options['search_filter'], $term, 'both');
                 $this->group_end();
             }
         } else {
             $this->group_start();
             $this->like('title', $term, 'both');
             $this->or_like('description', $term, 'both');
             $t = new Tag();
             $t->where('name', $term)->get();
             if ($t->exists()) {
                 $this->or_where_related('tag', 'id', $t->id);
             }
             $this->group_end();
         }
     } else {
         if ($options['tags'] || $options['tags_not']) {
             $this->_do_tag_filtering($options);
         }
     }
     if ($options['id_not']) {
         $this->where_not_in('id', explode(',', $options['id_not']));
     }
     $sub_list = false;
     if ($this->exists()) {
         $sub_list = true;
         $this->where('left_id >', $this->left_id)->where('right_id <', $this->right_id)->where('level', $this->level + 1)->where('visibility', $this->visibility);
         $options['visibility'] = $this->visibility;
     } else {
         if ($options['auth']) {
             if (isset($options['visibility'])) {
                 $values = array('public', 'unlisted', 'private');
                 if (in_array($options['visibility'], $values)) {
                     $options['visibility'] = array_search($options['visibility'], $values);
                 } else {
                     $options['visibility'] = 0;
                 }
             } else {
                 $options['visibility'] = 0;
             }
         } else {
             $options['visibility'] = 0;
         }
     }
     $this->where('visibility', $options['visibility']);
     if ($options['visibility'] > 0 && ($options['order_by'] === 'manual' || $options['order_by'] === 'published_on')) {
         $options['order_by'] = 'title';
     }
     if (!$options['include_empty']) {
         $this->where('total_count >', 0);
     }
     if ($options['featured'] || $options['category'] || $options['category_not']) {
         if ($options['featured']) {
             $this->where('featured', 1);
         }
         if ($options['category']) {
             $this->where_related('category', 'id', $options['category']);
         } else {
             if ($options['category_not']) {
                 $cat = new Album();
                 $cat->select('id')->where_related('category', 'id', $options['category_not'])->get_iterated();
                 $cids = array();
                 foreach ($cat as $c) {
                     $cids[] = $c->id;
                 }
                 $this->where_not_in('id', $cids);
             }
         }
     } else {
         if ($options['featured'] !== false && (int) $options['featured'] === 0) {
             $this->where('featured', 0);
         } else {
             if (!$sub_list && !$options['category'] && !$options['tags'] && !$options['year'] && !$options['flat']) {
                 $this->where('level', 1);
             }
         }
     }
     if ($options['order_by'] === 'left_id' && ($options['tags'] || $options['year'])) {
         $options['order_by'] = 'title,id';
         $options['order_direction'] = 'asc';
     }
     if (in_array($options['order_by'], array('created_on', 'modified_on'))) {
         $date_col = $options['order_by'];
     } else {
         $date_col = 'published_on';
     }
     $s = new Setting();
     $s->where('name', 'site_timezone')->get();
     $tz = new DateTimeZone($s->value);
     $offset = $tz->getOffset(new DateTime('now', new DateTimeZone('UTC')));
     if ($offset === 0) {
         $shift = '';
     } else {
         $shift = ($offset < 0 ? '-' : '+') . abs($offset);
     }
     if ($options['year'] || $options['year_not']) {
         if ($options['year_not']) {
             $options['year'] = $options['year_not'];
             $compare = ' !=';
         } else {
             $compare = '';
         }
         $this->where('YEAR(FROM_UNIXTIME(' . $this->table . '.' . $date_col . $shift . '))' . $compare, $options['year']);
     }
     if ($options['month'] || $options['month_not']) {
         if ($options['month_not']) {
             $options['month'] = $options['month_not'];
             $compare = ' !=';
         } else {
             $compare = '';
         }
         $this->where('MONTH(FROM_UNIXTIME(' . $this->table . '.' . $date_col . $shift . '))' . $compare, $options['month']);
     }
     if ($options['day'] || $options['day_not']) {
         if ($options['day_not']) {
             $options['day'] = $options['day_not'];
             $compare = ' !=';
         } else {
             $compare = '';
         }
         $this->where('DAY(FROM_UNIXTIME(' . $this->table . '.' . $date_col . $shift . '))' . $compare, $options['day']);
         if ($options['reduce']) {
             $e = new Text();
             $e->select('id')->where('page_type', 0)->where('published', 1)->where('YEAR(FROM_UNIXTIME(' . $this->table . '.published_on' . $shift . '))', $options['year'])->where('MONTH(FROM_UNIXTIME(' . $this->table . '.published_on' . $shift . '))', $options['month'])->where('DAY(FROM_UNIXTIME(' . $this->table . '.published_on' . $shift . '))', $options['day'])->include_related('album', 'id')->get_iterated();
             $ids = array();
             foreach ($e as $essay) {
                 if ($essay->album_id) {
                     $ids[] = $essay->album_id;
                 }
             }
             if (!empty($ids)) {
                 $this->where_not_in('id', $ids);
             }
             $tops = $this->get_clone()->where('album_type', 2)->get_iterated();
             $lefts = array();
             foreach ($tops as $set) {
                 if ($set->right_id - $set->left_id > 1) {
                     $lefts = array_merge($lefts, range($set->left_id + 1, $set->right_id - 1));
                 }
             }
             if (!empty($lefts)) {
                 $this->where_not_in('left_id', $lefts);
             }
         }
     }
     $this->where('deleted', (int) $options['trash']);
     $set_count = $this->get_clone()->where('album_type', 2)->count();
     $final = $this->paginate($options);
     $this->include_related_count('text');
     $this->include_related_count('categories');
     if (preg_match('/_on$/', $options['order_by'])) {
         $options['order_by'] .= ' ' . $options['order_direction'] . ',id ' . $options['order_direction'];
     } else {
         $options['order_by'] .= ' ' . $options['order_direction'];
     }
     $data = $this->order_by($options['order_by'])->get_iterated();
     if (!$options['limit']) {
         $final['per_page'] = $data->result_count();
         $final['total'] = $data->result_count();
     }
     $final['counts'] = array('albums' => $final['total'] - $set_count, 'sets' => $set_count, 'total' => $final['total']);
     $final['albums'] = array();
     $final['sort'] = $sort;
     $tag_map = $this->_eager_load_tags($data);
     foreach ($data as $album) {
         $tags = isset($tag_map['c' . $album->id]) ? $tag_map['c' . $album->id] : array();
         $params['eager_tags'] = $tags;
         $params['include_parent'] = !$sub_list;
         $final['albums'][] = $album->to_array($params);
     }
     return $final;
 }
Ejemplo n.º 7
0
 function _all($params)
 {
     $s = new Setting();
     $s->where('name', 'site_timezone')->get();
     $tz = new DateTimeZone($s->value);
     $offset = $tz->getOffset(new DateTime('now', new DateTimeZone('UTC')));
     if ($offset === 0) {
         $shift = '';
     } else {
         $shift = ($offset < 0 ? '-' : '+') . abs($offset);
     }
     $content_col = $params['content_column'];
     $select = "COUNT(*) as count, YEAR(FROM_UNIXTIME({$content_col}{$shift})) as event_year";
     $group = 'event_year';
     $order = 'event_year DESC';
     if (!$params['scope'] || $params['scope'] !== 'year') {
         $select .= ", MONTH(FROM_UNIXTIME({$content_col}{$shift})) as event_month";
         $group .= ',event_month';
         $order .= ',event_month DESC';
     }
     if (!$params['limit_to'] && !$params['scope']) {
         $select .= ", DAY(FROM_UNIXTIME({$content_col}{$shift})) as event_day";
         $group .= ',event_day';
         $order .= ',event_day DESC';
     }
     $a = new Album();
     $c = new Content();
     $t = new Text();
     $c->select(str_replace($content_col, $c->table . '.' . $content_col, $select))->include_related('album', 'id')->where('visibility', 0)->where('deleted', 0);
     if (!$params['limit_to']) {
         $c->group_start()->where('album_id', null)->or_where($c->table . '.published_on > `' . $a->table . '`.`published_on`')->group_end();
     }
     $a->select(str_replace($content_col, 'published_on', $select))->where('visibility', 0)->where('deleted', 0)->where('total_count >', 0);
     $t->select(str_replace($content_col, 'published_on', $select))->where('page_type', 0)->where('published', 1);
     if ($params['featured']) {
         $c->where('featured', 1);
         $a->where('featured', 1);
         $t->where('featured', 1);
     }
     $c->group_by($group)->order_by($order);
     $t->group_by($group)->order_by($order);
     $a->group_by($group)->order_by($order);
     $dates = array();
     if (!$params['limit_to'] || $params['limit_to'] === 'content') {
         foreach ($c->get_iterated() as $content) {
             if ($params['scope'] === 'year') {
                 $key = "{$content->event_year}";
             } else {
                 if ($params['limit_to'] || $params['scope']) {
                     $key = "{$content->event_year}-{$content->event_month}";
                 } else {
                     $key = "{$content->event_year}-{$content->event_month}-{$content->event_day}";
                 }
             }
             $key = strtotime($key);
             if (is_numeric($content->event_year)) {
                 $dates[$key] = array('year' => (int) $content->event_year, 'month' => (int) $content->event_month, 'day' => (int) $content->event_day, 'counts' => array('content' => (int) $content->count, 'albums' => 0, 'essays' => 0));
             }
         }
     }
     if (!$params['limit_to'] || $params['limit_to'] === 'albums') {
         foreach ($a->get_iterated() as $album) {
             if ($params['scope'] === 'year') {
                 $key = "{$album->event_year}";
             } else {
                 if ($params['limit_to'] || $params['scope']) {
                     $key = "{$album->event_year}-{$album->event_month}";
                 } else {
                     $key = "{$album->event_year}-{$album->event_month}-{$album->event_day}";
                 }
             }
             $key = strtotime($key);
             if (is_numeric($album->event_year)) {
                 if (!isset($dates[$key])) {
                     $dates[$key] = array('year' => (int) $album->event_year, 'month' => (int) $album->event_month, 'day' => (int) $album->event_day, 'counts' => array('content' => 0, 'albums' => (int) $album->count, 'essays' => 0));
                 } else {
                     $dates[$key]['counts']['albums'] = (int) $album->count;
                 }
             }
         }
     }
     if (!$params['limit_to'] || $params['limit_to'] === 'essays') {
         foreach ($t->get_iterated() as $essay) {
             if ($params['scope'] === 'year') {
                 $key = "{$essay->event_year}";
             } else {
                 if ($params['limit_to'] || $params['scope']) {
                     $key = "{$essay->event_year}-{$essay->event_month}";
                 } else {
                     $key = "{$essay->event_year}-{$essay->event_month}-{$essay->event_day}";
                 }
             }
             $key = strtotime($key);
             if (is_numeric($essay->event_year)) {
                 if (!isset($dates[$key])) {
                     $dates[$key] = array('year' => (int) $essay->event_year, 'month' => (int) $essay->event_month, 'day' => (int) $essay->event_day, 'counts' => array('content' => 0, 'albums' => 0, 'essays' => (int) $essay->count));
                 } else {
                     $dates[$key]['counts']['essays'] = (int) $essay->count;
                 }
             }
         }
     }
     krsort($dates);
     return $dates;
 }
Ejemplo n.º 8
0
 public function editAction()
 {
     $this->view->title = "Modification d'un texte";
     if ($this->view->aclIsAllowed('text', 'edit', true)) {
         $_blockID = $this->_getParam('blockID');
         $_pageid = $this->_getParam('pageID');
         $_id = $this->_getParam('ID');
         $base_dir = $this->getFrontController()->getBaseUrl();
         $blockText = new Text();
         $select = $blockText->select();
         $select->where('TD_BlockID = ?', $_blockID);
         $select->where('TD_LanguageID = ?', $this->_currentEditLanguage);
         $block = $blockText->fetchRow($select);
         $blockSelect = new Blocks();
         $selectBloc = $blockSelect->select()->setIntegrityCheck(false)->from('Blocks')->where('B_ID = ?', $_blockID)->join('PagesIndex', 'PI_PageID = B_PageID')->where('PI_LanguageID = ?', $block['TD_LanguageID']);
         // If block doesn't exist, creates it.
         if (empty($block)) {
             $block = $blockText->createRow(array('TD_BlockID' => $_blockID, 'TD_LanguageID' => $this->_currentEditLanguage));
             $block->save();
             // load it
             $block = $blockText->fetchRow($select);
         }
         if ($_id) {
             $returnLink = "{$base_dir}/text/index/list-approbation-request/";
         } else {
             $returnLink = "{$base_dir}/page/index/index/ID/{$_pageid}";
         }
         $form = new FormText(array('baseDir' => $base_dir, 'pageID' => $_pageid, 'cancelUrl' => $returnLink, 'toApprove' => $block["TD_ToApprove"]));
         if (!$this->_request->isPost()) {
             $block_data = empty($block) ? array() : $block->toArray();
             $blockData = $blockSelect->fetchRow($selectBloc);
             $block_data['PI_PageTitle'] = $blockData['PI_PageTitle'];
             $form->populate($block_data);
         } else {
             $formData = $this->_request->getPost();
             if ($form->isValid($formData)) {
                 if (isset($_POST['submitSaveSubmit'])) {
                     $block['TD_ToApprove'] = 1;
                     //header("location:".$returnLink);
                 } elseif (isset($_POST['submitSaveReturnWriting'])) {
                     $block['TD_ToApprove'] = 0;
                     //header("location:".$returnLink);
                 } elseif (isset($_POST['submitSaveOnline'])) {
                     $block['TD_OnlineTitle'] = $formData['TD_DraftTitle'];
                     $block['TD_OnlineText'] = $formData['TD_DraftText'];
                     $block['TD_ToApprove'] = 0;
                     //header("location:".$returnLink);
                     // index the new text if block online
                     $blockData = $blockSelect->fetchRow($selectBloc);
                     if ($blockData['B_Online'] == 1 && $blockData['PI_Status'] == 1) {
                         $indexData['pageID'] = $blockData['B_PageID'];
                         $indexData['moduleID'] = $blockData['B_ModuleID'];
                         $indexData['contentID'] = $block['TD_ID'];
                         $indexData['languageID'] = $block['TD_LanguageID'];
                         $indexData['title'] = $blockData['PI_PageTitle'];
                         $indexData['text'] = '';
                         $indexData['link'] = '';
                         $indexData['contents'] = $blockData['PI_PageTitle'] . " " . $block['TD_OnlineText'];
                         $indexData['action'] = 'update';
                         Cible_FunctionsIndexation::indexation($indexData);
                     }
                 } else {
                     $returnLink = "";
                 }
                 $block['TD_DraftTitle'] = $formData['TD_DraftTitle'];
                 $block['TD_DraftText'] = $formData['TD_DraftText'];
                 $block->save();
                 $oPage = new PagesObject();
                 $pageData['P_ID'] = $_pageid;
                 $pageData['PI_PageTitle'] = $formData['PI_PageTitle'];
                 $oPage->save($_pageid, $pageData, $this->_currentEditLanguage);
                 //if($returnLink <> "")
                 //$this->_redirect("/page/index/index/ID/$_pageid");
             }
         }
         $this->view->assign('form', $form);
         $this->view->assign('pageId', $_pageid);
         $this->view->assign('onlineTitle', isset($block['TD_OnlineTitle']) ? $block['TD_OnlineTitle'] : '');
         $this->view->assign('onlineText', isset($block['TD_OnlineText']) ? $block['TD_OnlineText'] : '');
     }
 }