Autodoc
  • Namespace
  • Class
  • Tree

Namespaces

  • BlueTihi
    • Context
  • Brickrouge
    • Element
      • Nodes
    • Renderer
    • Widget
  • ICanBoogie
    • ActiveRecord
    • AutoConfig
    • CLDR
    • Composer
    • Core
    • Event
    • Exception
    • HTTP
      • Dispatcher
      • Request
    • I18n
      • Translator
    • Mailer
    • Modules
      • Taxonomy
        • Support
      • Thumbnailer
        • Versions
    • Object
    • Operation
      • Dispatcher
    • Prototype
    • Routes
    • Routing
      • Dispatcher
    • Session
  • Icybee
    • ActiveRecord
      • Model
    • ConfigOperation
    • Document
    • EditBlock
    • Element
      • ActionbarContextual
      • ActionbarSearch
      • ActionbarToolbar
    • FormBlock
    • Installer
    • ManageBlock
    • Modules
      • Articles
      • Cache
        • Collection
        • ManageBlock
      • Comments
        • ManageBlock
      • Contents
        • ManageBlock
      • Dashboard
      • Editor
        • Collection
      • Files
        • File
        • ManageBlock
      • Forms
        • Form
        • ManageBlock
      • I18n
      • Images
        • ManageBlock
      • Members
      • Modules
        • ManageBlock
      • Nodes
        • ManageBlock
        • Module
      • Pages
        • BreadcrumbElement
        • LanguagesElement
        • ManageBlock
        • NavigationBranchElement
        • NavigationElement
        • Page
        • PageController
      • Registry
      • Search
      • Seo
      • Sites
        • ManageBlock
      • Taxonomy
        • Terms
          • ManageBlock
        • Vocabulary
          • ManageBlock
      • Users
        • ManageBlock
        • NonceLogin
        • Roles
      • Views
        • ActiveRecordProvider
        • Collection
        • View
    • Operation
      • ActiveRecord
      • Constructor
      • Module
      • Widget
    • Rendering
  • None
  • Patron
  • PHP

Classes

  • ArchivesView
  • Article
  • EditBlock
  • Hooks
  • Model
  • Module
  1 <?php
  2 
  3 /*
  4  * This file is part of the Icybee package.
  5  *
  6  * (c) Olivier Laviale <olivier.laviale@gmail.com>
  7  *
  8  * For the full copyright and license information, please view the LICENSE
  9  * file that was distributed with this source code.
 10  */
 11 
 12 namespace Icybee\Modules\Articles;
 13 
 14 use ICanBoogie\Event;
 15 
 16 // TODO-20101116: move this code to the "contents" module.
 17 
 18 class Hooks
 19 {
 20     static public function markup_articles(array $args, \Patron\Engine $engine, $template)
 21     {
 22         global $core;
 23 
 24         extract($args, EXTR_PREFIX_ALL, 'attr');
 25 
 26         #
 27         #
 28         #
 29 
 30         // TODO-20090121: ajouter l'atribut group="username" grouporder="asc"
 31         // on pourra peut ĂȘtre se dĂ©barasser de month, categories, user...
 32 
 33         $options = $args;
 34 
 35         #
 36         # build query
 37         #
 38 
 39         $where = array();
 40         $params = array();
 41 
 42         if ($attr_author)
 43         {
 44             $where[] = '(SELECT username FROM {prefix}user_users WHERE uid = node.uid) = ?';
 45             $params[] = $attr_author;
 46         }
 47 
 48         if ($attr_date)
 49         {
 50             $names = array('YEAR', 'MONTH', 'DAY');
 51 
 52             if (preg_match('#(\d{4})?-(\d{2})?#', $attr_date, $match))
 53             {
 54 //              echo l('date: \1, match: \2', $attr_date, $match);
 55 
 56                 array_shift($match);
 57 
 58                 foreach ($match as $key => $value)
 59                 {
 60                     $where[] = $names[$key] . '(`date`) = ?';
 61                     $params[] = $value;
 62                 }
 63             }
 64         }
 65 
 66         $where[] = 'is_online = 1';
 67 
 68         #
 69         # build query
 70         #
 71 
 72         $arq = $core->models['articles']->where(implode(' AND ', $where), $params);
 73 
 74         $count = $arq->count;
 75 
 76         $options['count'] = $count;
 77         $options['pages'] = $attr_limit ? ceil($count / $attr_limit) : 1;
 78 
 79         /*
 80          * FIXME-20100702: this is disabled because the markup might be used multiple time on
 81          * the same page. (e.g. list, recent...)
 82          *
 83         if ($attr_limit && $attr_page === null && isset($_GET['page']))
 84         {
 85             $attr_page = $_GET['page'];
 86         }
 87         */
 88 
 89         #
 90         # load entries
 91         #
 92 
 93         if ($attr_order == 'random')
 94         {
 95             $arq->order('rand()');
 96         }
 97         else if ($attr_by)
 98         {
 99             $arq->order("$attr_by $attr_order");
100         }
101 
102         if ($attr_limit)
103         {
104             $arq->limit($attr_page * $attr_limit, $attr_limit);
105         }
106 
107         $entries = $arq->all;
108 
109         new \BlueTihi\Context\LoadedNodesEvent($engine->context, $entries);
110 
111         #
112         # save options, they'll be used to handle pages
113         #
114 
115         $engine->context['self']['range'] = array
116         (
117             'count' => $count,
118             'limit' => $attr_limit,
119             'page' => $attr_page
120         );
121 
122         return $engine($template, $entries);
123     }
124 
125     static public function markup_articles_read(array $args, \Patron\Engine $patron, $template)
126     {
127         global $core;
128 
129         $limit = $args['limit'];
130         $constructor = 'articles';
131 
132         $hits = $core->models['feedback.hits']->query
133         (
134             'SELECT hit.*, (hits / (TO_DAYS(CURRENT_DATE) - TO_DAYS(first))) AS perday
135             FROM {self} as hit
136             INNER JOIN {prefix}nodes USING(nid)
137             WHERE is_online = 1 AND constructor = ?
138             ORDER BY hits DESC LIMIT ' . $limit, array
139             (
140                 $constructor
141             )
142         )
143         ->fetchAll(\PDO::FETCH_OBJ);
144 
145         $nids = array();
146 
147         foreach ($hits as $hit)
148         {
149             $nids[$hit->nid] = $hit;
150         }
151 
152         $entries = $core->models[$constructor]->find(array_keys($nids));
153 
154         foreach ($entries as $entry)
155         {
156             $nids[$entry->nid]->node = $entry;
157         }
158 
159         return $patron($template, array_values($nids));
160     }
161 
162     // TODO-20110627: should move this to the "contents" model.
163 
164     static public function markup_by_date(array $args, \Patron\Engine $patron, $template)
165     {
166         global $core;
167 
168         extract($args, EXTR_PREFIX_ALL, 'p');
169 
170         $query = 'node.*, article.* FROM {prefix}nodes node
171         INNER JOIN {prefix}contents article USING(nid) WHERE is_online = 1';
172         $params = array();
173 
174         if ($p_group)
175         {
176             $query = 'DATE_FORMAT(`date`, ?), ' . $query;
177             $params[] = $p_group;
178         }
179 
180         $query .= ' ORDER BY `date` ' . $p_order;
181 
182         if ($p_limit)
183         {
184             $query .= " LIMIT $p_start, $p_limit";
185         }
186         else if ($p_start)
187         {
188             $query .= " LIMIT $p_start";
189         }
190 
191         $model = $core->models['articles'];
192 
193         $entries = $model->query('SELECT ' . $query, $params)
194         ->fetchAll($p_group ? \PDO::FETCH_GROUP | \PDO::FETCH_CLASS : \PDO::FETCH_CLASS, __NAMESPACE__ . '\Article', array($model));
195 
196         return $patron($template, $entries);
197     }
198 
199     // TODO-20110627: should move this to the "contents" model.
200     // TODO-20121005: should be a view.
201 
202     static public function markup_by_author(array $args, \Patron\Engine $patron, $template)
203     {
204         global $core;
205 
206         $model = $core->models['articles'];
207 
208         $entries = $model->query
209         (
210             'SELECT username, node.*, article.*
211             FROM {prefix}nodes node
212             INNER JOIN {self} article USING(nid)
213             INNER JOIN {prefix}users USING(uid)
214             WHERE is_online = 1 ORDER BY `username`, `date` DESC'
215         )
216         ->fetchAll(\PDO::FETCH_GROUP | \PDO::FETCH_CLASS, __NAMESPACE__ . '\Article', array($model));
217 
218         return $patron($template, $entries);
219     }
220 }
Autodoc API documentation generated by ApiGen 2.8.0