1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @package net.nehmer.blog |
4
|
|
|
* @author The Midgard Project, http://www.midgard-project.org |
5
|
|
|
* @copyright The Midgard Project, http://www.midgard-project.org |
6
|
|
|
* @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
use midcom\datamanager\datamanager; |
10
|
|
|
use midcom\datamanager\schemadb; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Blog site interface class |
14
|
|
|
* |
15
|
|
|
* @package net.nehmer.blog |
16
|
|
|
*/ |
17
|
|
|
class net_nehmer_blog_viewer extends midcom_baseclasses_components_viewer |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Initialize the request switch and the content topic. |
21
|
|
|
*/ |
22
|
22 |
|
public function _on_initialize() |
23
|
|
|
{ |
24
|
22 |
|
if ($this->_config->get('view_in_url')) { |
25
|
|
|
$this->_request_switch['view-raw'] = [ |
26
|
|
|
'handler' => [net_nehmer_blog_handler_view::class, 'view'], |
27
|
|
|
'fixed_args' => ['view', 'raw'], |
28
|
|
|
'variable_args' => 1, |
29
|
|
|
]; |
30
|
|
|
$this->_request_switch['view'] = [ |
31
|
|
|
'handler' => [net_nehmer_blog_handler_view::class, 'view'], |
32
|
|
|
'fixed_args' => 'view', |
33
|
|
|
'variable_args' => 1, |
34
|
|
|
]; |
35
|
|
|
} |
36
|
|
|
|
37
|
22 |
|
if ($this->_config->get('rss_subscription_enable')) { |
38
|
5 |
|
net_nemein_rss_manage::register_plugin($this); |
39
|
|
|
} |
40
|
22 |
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Adds the RSS Feed LINK head elements. |
44
|
|
|
*/ |
45
|
16 |
|
private function _add_link_head() |
46
|
|
|
{ |
47
|
16 |
|
if ($this->_config->get('rss_enable')) { |
48
|
16 |
|
midcom::get()->head->add_link_head([ |
49
|
16 |
|
'rel' => 'alternate', |
50
|
16 |
|
'type' => 'application/rss+xml', |
51
|
16 |
|
'title' => $this->_l10n->get('rss 2.0 feed'), |
52
|
16 |
|
'href' => midcom::get()->get_host_name() . midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX) . 'rss.xml', |
|
|
|
|
53
|
|
|
]); |
54
|
16 |
|
midcom::get()->head->add_link_head([ |
55
|
16 |
|
'rel' => 'alternate', |
56
|
16 |
|
'type' => 'application/atom+xml', |
57
|
16 |
|
'title' => $this->_l10n->get('atom feed'), |
58
|
16 |
|
'href' => midcom::get()->get_host_name() . midcom_core_context::get()->get_key(MIDCOM_CONTEXT_ANCHORPREFIX) . 'atom.xml', |
59
|
|
|
]); |
60
|
|
|
} |
61
|
16 |
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Populates the node toolbar depending on the user's rights. |
65
|
|
|
*/ |
66
|
16 |
|
private function _populate_node_toolbar() |
67
|
|
|
{ |
68
|
16 |
|
$buttons = []; |
69
|
16 |
|
$workflow = $this->get_workflow('datamanager'); |
70
|
16 |
|
if ($this->_topic->can_do('midgard:create')) { |
71
|
14 |
|
foreach ($this->_request_data['schemadb']->all() as $name => $schema) { |
72
|
14 |
|
$buttons[] = $workflow->get_button("create/{$name}/", [ |
73
|
14 |
|
MIDCOM_TOOLBAR_LABEL => sprintf( |
74
|
14 |
|
$this->_l10n_midcom->get('create %s'), |
75
|
14 |
|
$this->_l10n->get($schema->get('description')) |
76
|
|
|
), |
77
|
14 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'file-o', |
78
|
14 |
|
MIDCOM_TOOLBAR_ACCESSKEY => 'n', |
79
|
|
|
]); |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
16 |
|
if ($this->_config->get('rss_subscription_enable')) { |
84
|
|
|
net_nemein_rss_manage::add_toolbar_buttons($this->_node_toolbar, $this->_topic->can_do('midgard:create')); |
85
|
|
|
} |
86
|
|
|
|
87
|
16 |
|
if ( $this->_topic->can_do('midgard:update') |
88
|
16 |
|
&& $this->_topic->can_do('midcom:component_config')) { |
89
|
14 |
|
$buttons[] = $workflow->get_button('config/', [ |
90
|
14 |
|
MIDCOM_TOOLBAR_LABEL => $this->_l10n_midcom->get('component configuration'), |
91
|
14 |
|
MIDCOM_TOOLBAR_HELPTEXT => $this->_l10n_midcom->get('component configuration helptext'), |
92
|
14 |
|
MIDCOM_TOOLBAR_GLYPHICON => 'wrench', |
93
|
|
|
]); |
94
|
|
|
} |
95
|
16 |
|
$this->_node_toolbar->add_items($buttons); |
96
|
16 |
|
} |
97
|
|
|
|
98
|
16 |
|
public function _on_handle($handler, array $args) |
99
|
|
|
{ |
100
|
16 |
|
$this->_request_data['schemadb'] = schemadb::from_path($this->_config->get('schemadb')); |
|
|
|
|
101
|
16 |
|
$this->_add_categories(); |
102
|
|
|
|
103
|
16 |
|
$this->_add_link_head(); |
104
|
16 |
|
$this->_populate_node_toolbar(); |
105
|
16 |
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Populate the categories configured for the topic into the schemas |
109
|
|
|
*/ |
110
|
16 |
|
private function _add_categories() |
111
|
|
|
{ |
112
|
16 |
|
$this->_request_data['categories'] = []; |
113
|
16 |
|
if ($this->_config->get('categories') != '') { |
114
|
|
|
$this->_request_data['categories'] = explode(',', $this->_config->get('categories')); |
|
|
|
|
115
|
|
|
|
116
|
|
|
foreach ($this->_request_data['schemadb']->all() as $schema) { |
117
|
|
|
if ( $schema->has_field('categories') |
118
|
|
|
&& $schema->get_field('categories')['type'] == 'select') { |
119
|
|
|
// TODO: Merge schema local and component config categories? |
120
|
|
|
$options = array_combine($this->_request_data['categories'], $this->_request_data['categories']); |
121
|
|
|
$schema->get_field('categories')['type_config']['options'] = $options; |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
} |
125
|
16 |
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Indexes an article. |
129
|
|
|
* |
130
|
|
|
* @param midcom_db_topic|midcom_core_dbaproxy $topic The topic which we are bound to. If this is not an object, the code |
131
|
|
|
* tries to load a new topic instance from the database identified by this parameter. |
132
|
|
|
*/ |
133
|
1 |
|
public static function index(datamanager $dm, midcom_services_indexer $indexer, $topic) |
134
|
|
|
{ |
135
|
1 |
|
$config = new midcom_helper_configuration($topic, 'net.nehmer.blog'); |
136
|
|
|
|
137
|
1 |
|
if ($config->get('disable_indexing')) { |
138
|
|
|
return; |
139
|
|
|
} |
140
|
|
|
|
141
|
1 |
|
$nav = new midcom_helper_nav(); |
142
|
1 |
|
$node = $nav->get_node($topic->id); |
143
|
|
|
|
144
|
1 |
|
$document = $indexer->new_document($dm); |
145
|
1 |
|
$document->topic_guid = $topic->guid; |
146
|
1 |
|
$document->component = $topic->component; |
|
|
|
|
147
|
1 |
|
$document->topic_url = $node[MIDCOM_NAV_FULLURL]; |
148
|
1 |
|
$indexer->index($document); |
149
|
1 |
|
} |
150
|
|
|
} |
151
|
|
|
|