PageRenderTime 52ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/jonah/lib/View/StoryList.php

https://github.com/wrobel/horde
PHP | 117 lines | 70 code | 14 blank | 33 comment | 14 complexity | 7bd4b19976906f82d1d9f51eef3342fe MD5 | raw file
Possible License(s): BSD-2-Clause, AGPL-1.0, LGPL-2.1, LGPL-3.0, BSD-3-Clause, LGPL-2.0, GPL-2.0
  1. <?php
  2. /**
  3. * Turba_View_StoryList:: A view to handle displaying a list of stories in a
  4. * channel.
  5. *
  6. * Copyright 2003-2012 Horde LLC (http://www.horde.org/)
  7. *
  8. * See the enclosed file LICENSE for license information (BSD). If you
  9. * did not receive this file, see http://cvs.horde.org/co.php/jonah/LICENSE.
  10. *
  11. * @author Chuck Hagenbuch <chuck@horde.org>
  12. * @author Marko Djukic <marko@oblo.com>
  13. * @author Michael J. Rubinsky <mrubinsk@horde.org>
  14. * @package Jonah
  15. */
  16. class Jonah_View_StoryList extends Jonah_View_Base
  17. {
  18. /**
  19. * expects
  20. * $registry
  21. * $notification
  22. * $prefs
  23. * $conf
  24. * $channel_id
  25. */
  26. public function run()
  27. {
  28. extract($this->_params, EXTR_REFS);
  29. $channel = $GLOBALS['injector']->getInstance('Jonah_Driver')->getChannel($channel_id);
  30. if (!Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::EDIT, $channel_id)) {
  31. $notification->push(_("You are not authorised for this action."), 'horde.warning');
  32. $registry->authenticateFailure();
  33. }
  34. /* Check if a URL has been passed. */
  35. $url = Horde_Util::getFormData('url');
  36. if ($url) {
  37. $url = new Horde_Url($url);
  38. }
  39. try {
  40. $stories = $GLOBALS['injector']->getInstance('Jonah_Driver')->getStories(array('channel_id' => $channel_id));
  41. } catch (Exception $e) {
  42. $notification->push(sprintf(_("Invalid channel requested. %s"), $e->getMessage()), 'horde.error');
  43. Horde::url('channels/index.php', true)->redirect();
  44. exit;
  45. }
  46. /* Do some state tests. */
  47. if (empty($stories)) {
  48. $notification->push(_("No available stories."), 'horde.warning');
  49. }
  50. if (!empty($refresh)) {
  51. $notification->push(_("Channel refreshed."), 'horde.success');
  52. }
  53. if (!empty($url)) {
  54. $url->redirect();
  55. exit;
  56. }
  57. /* Get channel details, for title, etc. */
  58. $allow_delete = Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::DELETE, $channel_id);
  59. /* Build story specific fields. */
  60. foreach ($stories as $key => $story) {
  61. /* published is the publication/release date, updated is the last change date. */
  62. if (!empty($stories[$key]['published'])) {
  63. $stories[$key]['published_date'] = strftime($prefs->getValue('date_format') . ', ' . ($prefs->getValue('twentyFour') ? '%H:%M' : '%I:%M%p'), $stories[$key]['published']);
  64. } else {
  65. $stories[$key]['published_date'] = '';
  66. }
  67. /* Default to no links. */
  68. $stories[$key]['pdf_link'] = '';
  69. $stories[$key]['edit_link'] = '';
  70. $stories[$key]['delete_link'] = '';
  71. $stories[$key]['view_link'] = Horde::link($GLOBALS['injector']->getInstance('Jonah_Driver')->getStoryLink($channel, $story), $story['description']) . htmlspecialchars($story['title']) . '</a>';
  72. /* PDF link. */
  73. $url = Horde::url('stories/pdf.php')->add(array('id' => $story['id'], 'channel_id' => $channel_id));
  74. $stories[$key]['pdf_link'] = $url->link(array('title' => _("PDF version"))) . Horde::img('mime/pdf.png') . '</a>';
  75. /* Edit story link. */
  76. $url = Horde::url('stories/edit.php')->add(array('id' => $story['id'], 'channel_id' => $channel_id));
  77. $stories[$key]['edit_link'] = $url->link(array('title' => _("Edit story"))) . Horde::img('edit.png') . '</a>';
  78. /* Delete story link. */
  79. if ($allow_delete) {
  80. $url = Horde::url('stories/delete.php')->add(array('id' => $story['id'], 'channel_id' => $channel_id));
  81. $stories[$key]['delete_link'] = $url->link(array('title' => _("Delete story"))) . Horde::img('delete.png') . '</a>';
  82. }
  83. /* Comment counter. */
  84. if ($conf['comments']['allow'] &&
  85. $registry->hasMethod('forums/numMessages')) {
  86. $comments = $registry->call('forums/numMessages', array($stories[$key]['id'], 'jonah'));
  87. if (!is_a($comments, 'PEAR_Error')) {
  88. $stories[$key]['comments'] = $comments;
  89. }
  90. }
  91. }
  92. /* Render page */
  93. $title = $channel['channel_name'];
  94. $view = new Horde_View(array('templatePath' => JONAH_TEMPLATES . '/stories'));
  95. $view->stories = $stories;
  96. $view->read = true;
  97. $view->comments = $conf['comments']['allow'] && $registry->hasMethod('forums/numMessages') && $channel['channel_type'] == Jonah::INTERNAL_CHANNEL;
  98. require $registry->get('templates', 'horde') . '/common-header.inc';
  99. require JONAH_TEMPLATES . '/menu.inc';
  100. echo $view->render('index');
  101. require $registry->get('templates', 'horde') . '/common-footer.inc';
  102. }
  103. }