CMS  Version 3.9
blog_view.inc
Go to the documentation of this file.
1 <?php
7 /**************************************************************
8 
9  Copyright (c) 2010 Sonjara, Inc
10 
11  Permission is hereby granted, free of charge, to any person
12  obtaining a copy of this software and associated documentation
13  files (the "Software"), to deal in the Software without
14  restriction, including without limitation the rights to use,
15  copy, modify, merge, publish, distribute, sublicense, and/or sell
16  copies of the Software, and to permit persons to whom the
17  Software is furnished to do so, subject to the following
18  conditions:
19 
20  The above copyright notice and this permission notice shall be
21  included in all copies or substantial portions of the Software.
22 
23  Except as contained in this notice, the name(s) of the above
24  copyright holders shall not be used in advertising or otherwise
25  to promote the sale, use or other dealings in this Software
26  without prior written authorization.
27 
28  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
30  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
32  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
33  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
34  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35  OTHER DEALINGS IN THE SOFTWARE.
36 
37 *****************************************************************/
38 
39 Fakoli::using("user", "blog", "article", "comment", "component");
40 Fakoli::usingFeature("paged_list");
41 
48 {
54 
61 }
62 
63 
64 
71 {
73  {
74  }
75 
76  static function register($view)
77  {
78  $view->registerHandler("Standard", new DefaultBlogViewHandler());
79  return $view;
80  }
81 
82  function drawArticleList($blog, $year = false, $month = false, $term_id = null)
83  {
84  global $page;
85  global $script;
86 
87  $this->blog = $blog;
88 
89  $page->page_title = $blog->title;
90 
91  if ($year)
92  {
93  $constraint = " AND YEAR(publish_date)=$year";
94 
95  if ($month)
96  {
97  $constraint .= " AND MONTH(publish_date) = $month";
98  }
99 
100  }
101 
102  if ($term_id)
103  {
104  $constraint .= " AND article_id IN (SELECT id FROM taxonomy_term_association where class='Article' AND term_id=$term_id)";
105  }
106 
107  $articles = $blog->Articles("WHERE published=1 AND publish_date <= curdate()" . $constraint);
108 
109  echo "<div id='blog_description' class='Standard'>{$blog->description}</div>";
110 
112 
113  $list = new ServerPagedList($articles, "article_list", array($this, formatArticle));
114  $list->CSSclass = "Standard";
115  $list->styles = "clear: both";
116 
117  if ($blog->articles_per_page)
118  {
119  $list->pageSize = $blog->articles_per_page;
120  }
121  else
122  {
123  $list->pageSize = 5;
124  }
125 
126  $script .= $list->writeScript();
127  $list->drawList();
128  }
129 
131  {
132  $out = "<div class='article_summary'>";
133 
134  if ($article->image_id)
135  {
136  $image = $article->Image();
137  $out .= "<img src='/action/image/iconize?image_id={$article->image_id}&size=120' alt='{$image->ALT_tag}' align='left'/>";
138  }
139 
140  $out .= "<h4><a href='{$this->blog->identifier}?article_id={$article->article_id}'>";
141  $out .= "{$article->title}</a></h4>";
142 
143  if ($article->teaser) $out .= $article->teaser;
144  $out .= "<div class='blog_timestamp'>";
145  $out .= "By " . $article->author . ", posted on " . $article->formatPostDate();
146  $out .= "</div>";
147  $out .= "</div>";
148  return $out;
149  }
150 
152  {
153  global $page;
155  $page->page_title = $article->title;
156 
157  echo $article->message;
158  echo "<div class='blog_timestamp'>";
159  echo "By " . $article->author . ", posted on " .$article->formatPostDate();
160  echo "</div>";
161  if ($article->tags)
162  {
163  echo "<div class='blog_tags'>" . $article->tags . "</div>";
164  }
165  }
166 }
167 
168 
169 
170 
177 {
179  {
180  }
181 
182  static function register($view)
183  {
184  $view->registerHandler("News", new NewsBlogViewHandler());
185  return $view;
186  }
187 
188  function drawArticleList($blog, $year = false, $month = false, $term = null)
189  {
190  global $page;
191  global $script;
192 
193  $this->blog = $blog;
194 
195  $page->page_title = $blog->title;
196 
197  if ($year)
198  {
199  $constraint = " AND YEAR(publish_date) = $year";
200 
201  if ($month)
202  {
203  $constraint .= " AND MONTH(publish_date) = $month";
204  }
205 
206  }
207 
208  if ($term_id)
209  {
210  $constraint .= " AND article_id IN (SELECT id FROM taxonomy_term_association where class='Article' AND term_id=$term_id)";
211  }
212 
213  $articles = $blog->Articles("WHERE published=1 AND publish_date <= curdate()" . $constraint);
214 
215  echo "<div id='blog_description' class='Standard'>{$blog->description}</div>";
216 
218 
219  $list = new ServerPagedList($articles, "article_list", array($this, formatArticle));
220  $list->CSSclass = "Standard";
221  $list->styles = "clear: both";
222  $list->pageSize = $blog->articles_per_page;
223 
224  $script .= $list->writeScript();
225  $list->drawList();
226  }
227 
229  {
230 
231  $out = "<div class='article_summary'>";
232 
233  if ($article->image_id)
234  {
235  $image = $article->Image();
236  $out .= "<img src='/action/image/iconize?image_id={$article->image_id}&size=120' alt='{$image->ALT_tag}' align='left'/>";
237  }
238 
239  $out .= "<h4><a href='{$this->blog->identifier}?article_id={$article->article_id}'>";
240  $out .= "{$article->title}</a></h4>";
241  $out .= $article->format("<strong>{formatPostDate()}</strong>");
242  if ($article->teaser) $out .= " - ".$article->teaser;
243  $out .= "<br/><a href='{$this->blog->identifier}?article_id={$article->article_id}'>Read More &raquo;</a></div>";
244  return $out;
245  }
246 
248  {
249  global $page;
251  $page->page_title = $article->title;
252 
253  echo $article->message;
254 
255 ?><br/><a class="button" href="/<?echo $blog->identifier?>">&laquo; Back to <?echo $blog->title?></a><?
256  }
257 }
258 
259 
261 {
263  {
264  }
265 
266  static function register($view)
267  {
268  $view->registerHandler("Book", new BookBlogViewHandler());
269  return $view;
270  }
271 
272  function drawArticleList($blog, $year = false, $month = false, $term_id = null)
273  {
274  global $page;
275  global $script;
276 
277  $this->blog = $blog;
278 
279  $page->page_title = $blog->title;
280 
281  if ($year)
282  {
283  $constraint = " AND YEAR(publish_date) = $year";
284 
285  if ($month)
286  {
287  $constraint .= " AND MONTH(publish_date) = $month";
288  }
289  }
290 
291  if ($term_id)
292  {
293  $constraint .= " AND article_id IN (SELECT id FROM taxonomy_term_association where class='Article' AND term_id=$term_id)";
294  }
295 
296 
297  $articles = $blog->Articles("WHERE published=1 AND publish_date <= curdate()" . $constraint);
298 
299  echo "<div id='blog_description' class='Book'>{$blog->description}</div>";
300 
302 
303  $list = new PagedList($articles, "article_list", array($this, formatArticle));
304  $list->CSSclass = "Standard";
305  $list->styles = "clear: both; width: 100%";
306  $list->pageSize = $blog->articles_per_page;
307 
308  $script .= $list->writeScript();
309  $list->drawList();
310  }
311 
313  {
314  $out = "<div class='article_summary'>";
315 
316  if ($article->image_id)
317  {
318  $image = $article->Image();
319  $out .= "<img src='/action/image/iconize?image_id={$article->image_id}&size=120' alt='{$image->ALT_tag}' align='left'/>";
320  }
321 
322  $out .= "<h4><a href='{$this->blog->identifier}?article_id={$article->article_id}'>";
323  $out .= "{$article->title}</a></h4>";
324 
325  if ($article->teaser) $out .= $article->teaser;
326  $out .= "</div>";
327  return $out;
328  }
329 
331  {
332  global $page;
334  $page->page_title = $article->title;
335 
336  echo "<div class='chapter'>\n";
337 
338  echo $article->message;
339 
340  $articles = $blog->Articles("WHERE published=1");
341 
342  $idx = findItemIndex($articles, "article_id", $article->article_id);
343 
344  echo "<br/>";
345 
346  if ($idx < count($articles) - 1)
347  {
348 ?>
349 <a href="<?echo $blog->identifier?>?article_id=<?echo $articles[$idx+1]->article_id?>" class="button" style="float: right"><?echo ellipsis($articles[$idx+1]->title, 60, true)?> &raquo;</a>
350 <?
351  }
352 
353  if ($idx > 0)
354  {
355 ?>
356 <a href="<?echo $blog->identifier?>?article_id=<?echo $articles[$idx-1]->article_id?>" class="button" style="float: left">&laquo; <?echo ellipsis($articles[$idx-1]->title, 60, true)?></a>
357 <?
358  }
359  else
360  {
361 ?>
362 <a href="<?echo $blog->identifier?>" class="button" style="float: left">&laquo; Back to Contents Page</a>
363 <?
364  }
365 
366  echo "<div style='clear:both'>&nbsp;</div></div>";
367  }
368 }
369 
370 class BlogView
371 {
372  var $blog;
374 
375  function BlogView($blog)
376  {
377  $this->blog = $blog;
378  ComponentManager::fireEvent("RegisterBlogViewHandlers", $this);
379  }
380 
382  {
383  $this->handlers[$type] = $handler;
384  }
385 
387  {
388  if (!Settings::getValue("blog", "allow_subscription_options")) return;
389 
390  if ($this->blog->allow_subscriptions)
391  {
392  $buttonFormat = Settings::getValue("blog", "subscribe_button_format");
393 
394  echo $this->blog->format("<a id='blog_subscription_button' class='button' href='#' onclick='new BlogManager().showSubscriptionDialog({blog_id},\"{title:jsSafe}\"); return false;'>$buttonFormat</a>");
395  }
396  }
397 
398  function drawArticleList($year = false, $month = false, $term_id = null)
399  {
400  $type = $this->blog->blog_type;
401  if (!array_key_exists($type, $this->handlers)) $type = "Standard";
402 
403  trace ("Month is " . $month, 3);
404 
405  $this->drawSubscribeButton();
406 
407  $this->handlers[$type]->drawArticleList($this->blog, $year, $month, $term_id);
408  }
409 
411  {
412  global $script;
413  global $method;
414  global $user;
415 
416  $type = $this->blog->blog_type;
417  if (!array_key_exists($type, $this->handlers)) $type = "Standard";
418 
419  trace("** Rendering article for blog '{$this->blog->identifier}' with blog view handler '{$type}'", 3);
420 
421  $this->handlers[$type]->drawArticle($this->blog, $article_id);
422 
423  if (Settings::getValue("settings", "enable_inline_editing") && Settings::checkPermission("settings", "editor_roles"))
424  {
426 
428 
429  $versioningControls = ComponentManager::fireEvent("RenderVersioningControls", $article);
430  echo "<p id='inline_editing' class='inline_editor_toolbar'><a href='#' class='edit' onclick='new ArticleManager().editArticle({$article_id}, {$this->blog->blog_id}); return false;'>Edit</a>$versioningControls</p>";
431  }
432 
433  $this->drawSubscribeButton();
434 
435  if ($this->blog->allow_comments && $article_id)
436  {
438  }
439  }
440 
442  {
443  $view->registerHandler("Standard", new DefaultBlogViewHandler());
444  $view->registerHandler("News", new NewsBlogViewHandler());
445  $view->registerHandler("Book", new BookBlogViewHandler());
446 
447  return $view;
448  }
449 }
450 
452 {
453  var $table;
454 
455  function BlogListView()
456  {
457  $blogs = Query::create(Blog, "ORDER BY title")->execute();
458 
459  $this->table = $this->buildTable($blogs);
460  }
461 
462  function buildTable($blogs)
463  {
464  $table = new DataListView($blogs, "blogs");
465  $table->column("Title", array($this, formatTitleLink), true, "width: 40%")
466  ->column("Identifier", "{identifier}", true, "width: 30%")
467  ->column("Owner", "{getOwnerName()}", true, "width: 20%")
468  ->column("# Articles", "{countArticles()}", true, "width: 10%; text-align: center")
469  ->column("Published", array($this, showPublished), true, "width: 10%; text-align: center");
470 
471  $table->sortable = true;
472  $table->filter = true;
473  $table->pageSize = 15;
474  $table->emptyMessage = "No blogs have been created yet.";
475 
476  return $table;
477  }
478 
479  function writeScript()
480  {
481  return $this->table->writeScript();
482  }
483 
484  function drawView()
485  {
486  $this->table->drawView();
487  }
488 
490  {
491  return $blog->format("<a href='blog_form?blog_id={blog_id}'>{title}</a>");
492  }
493 
495  {
496  $img = $blog->published ? "on.png" : "off.png";
497  $alt = $blog->published ? "Published" : "Unpublished";
498 
499 
500  return "<img src='/fakoli/images/$img' alt='$alt' onclick='toggleBlogPublished(this, {$blog->blog_id})' style='display: inline-block; vertical-align: middle; border: none; cursor: pointer'/>";
501  }
502 }
503 
505 {
506  function AdminBlogListView()
507  {
508  parent::BlogListView();
509  }
510 
512  {
513  return $blog->format("<a href='/admin/blog_form?blog_id={blog_id}'>{title}</a>");
514  }
515 }
516 
518 {
519  var $blog;
520  var $table;
521 
523  {
524  $this->blog = $blog;
525 
526  $articles = $blog->Articles();
527 
528  $this->table = $this->buildTable($articles);
529  }
530 
532  {
533  $table = new DataListView($articles, "articles");
534  $table->column("Title", array($this, formatTitle), true)
535  ->column("Author", "{getAuthorName()}", true)
536  ->column("Date Published", "{publish_date}", true)
537  ->column("Published", array($this, showPublished), false, "text-align: center");
538 
539  $table->sortable = true;
540  $table->filter = true;
541  $table->excelFile = "articles.xls";
542  $table->pageSize = 20;
543  $table->emptyMessage = "No articles have been created yet.";
544 
545  return $table;
546  }
547 
548  function writeScript()
549  {
550  return $this->table->writeScript();
551  }
552 
553  function drawView()
554  {
555  $this->table->drawView();
556  }
557 
559  {
560  $img = $article->published ? "on.png" : "off.png";
561  $alt = $article->published ? "Published" : "Unpublished";
562 
563  return "<img src='/fakoli/images/$img' alt='$alt' onclick='toggleArticlePublished(this, {$article->article_id})' style='display: inline-block; vertical-align: middle; border: none; cursor: pointer'/>";
564  }
565 
566 
567  function formatTitle($item)
568  {
569  global $blog;
570  return "<a title=\"{$item->title}\" href=\"blog_article_form?blog_id={$blog->blog_id}&article_id={$item->article_id}\">". ellipsis($item->title, 80) ."</a>";
571  }
572 
573  function drawAddButton()
574  {
575  echo "<br/>\n<a class='button' href=\"blog_article_form?blog_id={$this->blog->blog_id}\">Add an Article</a>\n<br/>\n";
576  }
577 }
578 
580 {
582  {
583  parent::BlogArticlesView($blog);
584  }
585 
587  {
588  $table = parent::buildTable($articles);
589  if ($this->blog->default_article_order == "SORT")
590  {
591  $table->enableDragReorder("/action/blog/reorder_articles?blog_id={$this->blog->blog_id}");
592  $table->dragText = "<span style='font-size: 10px'>Click and drag to change the order of the articles</span>";
593  }
594 
595  return $table;
596  }
597 
598  function formatTitle($item)
599  {
600  global $blog;
601  return "<a title=\"{$item->title}\" href=\"/admin/blog_article_form?blog_id={$blog->blog_id}&article_id={$item->article_id}\">". ellipsis($item->title, 80) ."</a>";
602  }
603 
604  function drawAddButton()
605  {
606  echo "<p>\n<a class='button' href=\"/admin/blog_article_form?blog_id={$this->blog->blog_id}\">Add an Article</a>\n</p>\n";
607  }
608 }
609 
611 {
612  var $blog;
613  var $table;
614 
616  {
617  $blog = new Blog ($blog_id);
618 
619  $constraint = " WHERE blog_id = {$blog_id}";
620 
621  $blog_subscribers = query(BlogSubscriber, $constraint);
622 
623  $this->table = new DataListView($blog_subscribers, "blogSubscribers");
624  $this->table->column("Subscriber Email", "{subscriber_email}", true);
625 
626  if (Settings::getValue("blog", "enable_extended_subscription_fields"))
627  {
628  $this->table->column("First Name", "{first_name}", true);
629  $this->table->column("Last Name", "{last_name}", true);
630  $this->table->column("Organization", "{organization}", true);
631  }
632 
633  $this->table->column("Remove", array(BlogSubscriberListView, formatUnsubscribeLink), true, "width: 40%; text-align: center");
634 
635  $this->table->filter = true;
636  $this->table->sortable = true;
637  $this->table->excelFile = "blog_subscribers.xls";
638  $this->table->emptyMessage = "Currently there are no subscribers to this blog.";
639  $this->table->zebra = 1;
640  }
641 
642  function formatUnsubscribeLink($blog_subscriber)
643  {
644  $blog_id = $blog_subscriber->blog_id;
645  $blog_subscriber_id = $blog_subscriber->blog_subscriber_id;
646 
647  $unsubscribeLink = "<a href='/action/blog/unsubscribe?blog_id={$blog_id}&blog_subscriber_id={$blog_subscriber_id}'>Remove</a>";
648  return $unsubscribeLink ;
649  }
650 
651  function drawView()
652  {
653  global $script;
654  $script .= $this->table->writeScript();
655 
656  $this->table->drawView();
657  }
658 }?>
$constraint
$article
$article_id
$blog
$handler
Definition: event_form.inc:62
$page
Definition: help.inc:39
$view
Definition: help.inc:42
$out
Definition: page.inc:66
$helpTree style
Definition: tree.inc:46
$image
Definition: image_form.inc:46
$blog_id
Definition: edit.inc:45
$bookmark title
buildTable($articles)
Definition: blog_view.inc:586
AdminBlogArticlesView($blog)
Definition: blog_view.inc:581
formatTitleLink($blog)
Definition: blog_view.inc:511
Defines the Article class.
Definition: article.inc:45
buildTable($articles)
Definition: blog_view.inc:531
showPublished($article)
Definition: blog_view.inc:558
BlogArticlesView($blog)
Definition: blog_view.inc:522
formatTitle($item)
Definition: blog_view.inc:567
Definition: blog.inc:41
showPublished($blog)
Definition: blog_view.inc:494
buildTable($blogs)
Definition: blog_view.inc:462
formatTitleLink($blog)
Definition: blog_view.inc:489
static inlineEditingControls($blog)
BlogSubscriberListView($blog_id)
Definition: blog_view.inc:615
formatUnsubscribeLink($blog_subscriber)
Definition: blog_view.inc:642
BlogView($blog)
Definition: blog_view.inc:375
registerHandler($type, $handler)
Definition: blog_view.inc:381
static registerStandardHandlers($view)
Definition: blog_view.inc:441
drawArticleList($year=false, $month=false, $term_id=null)
Definition: blog_view.inc:398
drawSubscribeButton()
Definition: blog_view.inc:386
drawArticle($article_id)
Definition: blog_view.inc:410
drawArticle($blog, $article_id)
Draw the specific article in the blog.
Definition: blog_view.inc:330
formatArticle($article)
Definition: blog_view.inc:312
drawArticleList($blog, $year=false, $month=false, $term_id=null)
Definition: blog_view.inc:272
static addCommentPanel($qs=null)
static fireEvent($event, $parameter=null, $mustBeConsumed=false)
Fire an event to all subscribers as detailed in their manifests.
DefaultBlogViewHandler provides a standard, no-frills display for blog entries.
Definition: blog_view.inc:71
drawArticleList($blog, $year=false, $month=false, $term_id=null)
Definition: blog_view.inc:82
drawArticle($blog, $article_id)
Draw the specific article in the blog.
Definition: blog_view.inc:151
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
static using()
Import the datamodels, views and manifest for the specified component(s).
Definition: core.inc:116
NewsBlogViewHandler provides a simple blog view tailored displaying news articles.
Definition: blog_view.inc:177
formatArticle($article)
Definition: blog_view.inc:228
drawArticle($blog, $article_id)
Draw the specific article in the blog.
Definition: blog_view.inc:247
drawArticleList($blog, $year=false, $month=false, $term=null)
Definition: blog_view.inc:188
Definition: page.inc:43
static getValue($component, $name)
Retrieve the value of the specified Setting.
Definition: settings.inc:104
static checkPermission($component, $name, $account=null)
Check whether a user has a specific permission.
Definition: settings.inc:241
static selectDisplayVersion($target, $param="version")
global $user
$method
Pull out a simple reference to the request method.
Definition: core.inc:1573
$forumRequest to
IBlogViewHandler defines the interface that BlogViewHandlers must provide.
Definition: blog_view.inc:48
drawArticleList($blog)
Draw the list of articles for the specified blog.
drawArticle($blog, $article_id)
Draw the specific article in the blog.
$list
Definition: list_images.inc:41
$term_id
Definition: blog.inc:40
$month
Definition: blog.inc:39
$year
Definition: blog.inc:38
$articles
Definition: rss.inc:62
$term
Definition: term_dialog.inc:46
$blog_subscriber_id
Definition: unsubscribe.inc:39