1: <?php
2: 3: 4: 5: 6:
7:
8: if (!defined('JONAH_BASE')) {
9: define('JONAH_BASE', dirname(__FILE__). '/..');
10: }
11:
12: if (!defined('HORDE_BASE')) {
13: 14:
15: if (file_exists(JONAH_BASE. '/config/horde.local.php')) {
16: include JONAH_BASE . '/config/horde.local.php';
17: } else {
18: define('HORDE_BASE', JONAH_BASE . '/..');
19: }
20: }
21:
22: 23:
24: require_once HORDE_BASE . '/lib/core.php';
25:
26: class Jonah_Application extends Horde_Registry_Application
27: {
28: public $version = 'H4 (1.0-git)';
29:
30: 31: 32: 33:
34: protected function _init()
35: {
36: $GLOBALS['injector']->bindFactory('Jonah_Driver', 'Jonah_Factory_Driver', 'create');
37:
38: if ($channel_id = Horde_Util::getFormData('channel_id')) {
39: $url = Horde::url('delivery/rss.php', true, -1)
40: ->add('channel_id', $channel_id);
41: if ($tag_id = Horde_Util::getFormData('tag_id')) {
42: $url->add('tag_id', $tag_id);
43: }
44: $GLOBALS['linkTags'] = array('<link rel="alternate" type="application/rss+xml" title="RSS 0.91" href="' . $url . '" />');
45: }
46: }
47:
48: 49:
50: public function perms()
51: {
52: $perms = array(
53: 'admin' => array(
54: 'title' => _("Administrator")
55: ),
56: 'news' => array(
57: 'title' => _("News")
58: ),
59: 'news:channels' => array(
60: 'title' => _("Channels")
61: )
62: );
63:
64: 65:
66: $channels = $GLOBALS['injector']->getInstance('Jonah_Driver')->getChannels();
67:
68: foreach ($channels as $channel) {
69: $perms['news:channels:' . $channel['channel_id']] = array(
70: 'title' => $channel['channel_name']
71: );
72: }
73:
74: return $perms;
75: }
76:
77: 78:
79: public function ($menu)
80: {
81:
82: if (Jonah::checkPermissions('jonah:news', Horde_Perms::EDIT)) {
83: $menu->addArray(array(
84: 'icon' => 'jonah.png',
85: 'text' => _("_Feeds"),
86: 'url' => Horde::url('channels/index.php')
87: ));
88: }
89: foreach ($GLOBALS['conf']['news']['enable'] as $channel_type) {
90: if (Jonah::checkPermissions($channel_type, Horde_Perms::EDIT)) {
91: $menu->addArray(array(
92: 'icon' => 'new.png',
93: 'text' => _("New Feed"),
94: 'url' => Horde::url('channels/edit.php')
95: ));
96: break;
97: }
98: }
99: if ($channel_id = Horde_Util::getFormData('channel_id')) {
100: $news = $GLOBALS['injector']->getInstance('Jonah_Driver');
101: $channel = $news->getChannel($channel_id);
102: if ($channel['channel_type'] == Jonah::INTERNAL_CHANNEL &&
103: Jonah::checkPermissions(Jonah::typeToPermName($channel['channel_type']), Horde_Perms::EDIT, $channel_id)) {
104: $menu->addArray(array(
105: 'icon' => 'new.png',
106: 'text' => _("_New Story"),
107: 'url' => Horde::url('stories/edit.php')->add('channel_id', (int)$channel_id)
108: ));
109: }
110: }
111: }
112:
113:
114:
115: 116:
117: public function (Horde_Tree_Base $tree, $parent = null,
118: array $params = array())
119: {
120: if (!Jonah::checkPermissions('jonah:news', Horde_Perms::EDIT) ||
121: !in_array('internal', $GLOBALS['conf']['news']['enable'])) {
122: return;
123: }
124:
125: $url = Horde::url('stories/');
126: $driver = $GLOBALS['injector']->getInstance('Jonah_Driver');
127:
128: try {
129: $channels = $driver->getChannels('internal');
130: } catch (Jonah_Exception $e) {
131: var_dump($e);
132: return;
133: }
134:
135: $channels = Jonah::checkPermissions('channels', Horde_Perms::SHOW, $channels);
136: $story_img = Horde_Themes::img('editstory.png');
137:
138: foreach ($channels as $channel) {
139: $tree->addNode(
140: $parent . $channel['channel_id'],
141: $parent,
142: $channel['channel_name'],
143: 1,
144: false,
145: array(
146: 'icon' => $story_img,
147: 'url' => $url->add('channel_id', $channel['channel_id'])
148: )
149: );
150: }
151: }
152:
153: }
154: