1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: class Jonah_View_StoryView extends Jonah_View_Base
15: {
16: 17: 18: 19: 20: 21: 22: 23: 24:
25: public function run()
26: {
27: extract($this->_params, EXTR_REFS);
28:
29: Horde::addScriptFile('syntaxhighlighter/scripts/shCore.js', 'horde');
30: Horde::addScriptFile('syntaxhighlighter/scripts/shAutoloader.js', 'horde');
31: $path = $GLOBALS['registry']->get('jsuri', 'horde') . '/syntaxhighlighter/scripts/';
32: $brushes = <<<EOT
33: SyntaxHighlighter.autoloader(
34: 'applescript {$path}shBrushAppleScript.js',
35: 'actionscript3 as3 {$path}shBrushAS3.js',
36: 'bash shell {$path}shBrushBash.js',
37: 'coldfusion cf {$path}shBrushColdFusion.js',
38: 'cpp c {$path}shBrushCpp.js',
39: 'c# c-sharp csharp {$path}shBrushCSharp.js',
40: 'css {$path}shBrushCss.js',
41: 'delphi pascal {$path}shBrushDelphi.js',
42: 'diff patch pas {$path}shBrushDiff.js',
43: 'erl erlang {$path}shBrushErlang.js',
44: 'groovy {$path}shBrushGroovy.js',
45: 'java {$path}shBrushJava.js',
46: 'jfx javafx {$path}shBrushJavaFX.js',
47: 'js jscript javascript {$path}shBrushJScript.js',
48: 'perl pl {$path}shBrushPerl.js',
49: 'php {$path}shBrushPhp.js',
50: 'text plain {$path}shBrushPlain.js',
51: 'py python {$path}shBrushPython.js',
52: 'ruby rails ror rb {$path}shBrushRuby.js',
53: 'sass scss {$path}shBrushSass.js',
54: 'scala {$path}shBrushScala.js',
55: 'sql {$path}shBrushSql.js',
56: 'vb vbnet {$path}shBrushVb.js',
57: 'xml xhtml xslt html {$path}shBrushXml.js'
58: );
59: EOT;
60: Horde::addInlineScript(array(
61: $brushes,
62: 'SyntaxHighlighter.defaults[\'toolbar\'] = false',
63: 'SyntaxHighlighter.all()'
64: ), 'dom');
65:
66: $sh_js_fs = $GLOBALS['registry']->get('jsfs', 'horde') . '/syntaxhighlighter/styles/';
67: $sh_js_uri = Horde::url($GLOBALS['registry']->get('jsuri', 'horde'), false, -1) . '/syntaxhighlighter/styles/';
68:
69: $css = $GLOBALS['injector']->getInstance('Horde_Themes_Css');
70: $css->addStylesheet($sh_js_fs . 'shCoreEclipse.css', $sh_js_uri . 'shCoreEclipse.css');
71: $css->addStylesheet($sh_js_fs . 'shThemeEclipse.css', $sh_js_uri . 'shThemeEclipse.css');
72:
73: $driver = $GLOBALS['injector']->getInstance('Jonah_Driver');
74: try {
75: $story = $driver->getStory($channel_id, $story_id, !$browser->isRobot());
76: } catch (Exception $e) {
77: $notification->push(sprintf(_("Error fetching story: %s"), $e->getMessage()), 'horde.warning');
78: require $registry->get('templates', 'horde') . '/common-header.inc';
79: require JONAH_TEMPLATES . '/menu.inc';
80: require $registry->get('templates', 'horde') . '/common-footer.inc';
81: exit;
82: }
83:
84:
85: $cloud = new Horde_Core_Ui_TagCloud();
86: $allTags = $driver->listTagInfo(array(), $channel_id);
87: foreach ($allTags as $tag_id => $taginfo) {
88: $cloud->addElement($taginfo['tag_name'], Horde::url('stories/results.php')->add(array('tag_id' => $tag_id, 'channel_id' => $channel_id)), $taginfo['total']);
89: }
90:
91:
92:
93: $tag_html = array();
94: $tag_link = Horde::url('stories/results.php')->add('channel_id', $channel_id);
95: foreach ($story['tags'] as $id => $tag) {
96: $link = $tag_link->copy()->add('tag_id', $id);
97: $tag_html[] = $link->link() . $tag . '</a>';
98: }
99:
100:
101: if (!empty($story['body_type']) && $story['body_type'] == 'text') {
102: $story['body'] = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($story['body'], 'text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO));
103: }
104:
105:
106: if (!empty($story['url'])) {
107: $story['body'] .= Horde::link(Horde::externalUrl($story['url'])) . htmlspecialchars($story['url']) . '</a></p>';
108: }
109:
110: if (empty($story['published_date'])) {
111: $story['published_date'] = false;
112: }
113:
114: $view = new Horde_View(array('templatePath' => array(JONAH_TEMPLATES . '/stories',
115: JONAH_TEMPLATES . '/stories/partial',
116: JONAH_TEMPLATES . '/stories/layout')));
117: $view->addHelper('Tag');
118: $view->addHelper('Text');
119: $view->tagcloud = $cloud->buildHTML();
120: $view->story = $story;
121:
122:
123: if ($conf['sharing']['allow']) {
124: $url = Horde::url('stories/share.php')->add(array('id' => $story['id'], 'channel_id' => $channel_id));
125: $view->sharelink = $url->link() . _("Share this story") . '</a>';
126: }
127:
128:
129: if ($conf['comments']['allow']) {
130: if (!$registry->hasMethod('forums/doComments')) {
131: $err = 'User comments are enabled but the forums API is not available.';
132: Horde::logMessage($err, 'ERR');
133: } else {
134: try {
135: $comments = $registry->call('forums/doComments', array('jonah', $story_id, 'commentCallback'));
136: } catch (Exception $e) {
137: Horde::logMessage($e, 'ERR');
138: $comments = array('threads' => '', 'comments' => '');
139: }
140: $view->comments = $comments;
141: }
142: }
143:
144: require $registry->get('templates', 'horde') . '/common-header.inc';
145: require JONAH_TEMPLATES . '/menu.inc';
146: echo $view->render('view');
147: require $registry->get('templates', 'horde') . '/common-footer.inc';
148: }
149:
150: }
151: