|
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
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Blog index page handler |
|
13
|
|
|
* |
|
14
|
|
|
* @package net.nehmer.blog |
|
15
|
|
|
*/ |
|
16
|
|
|
class net_nehmer_blog_handler_view extends midcom_baseclasses_components_handler |
|
17
|
|
|
{ |
|
18
|
|
|
use net_nehmer_blog_handler; |
|
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* The article to display |
|
22
|
|
|
* |
|
23
|
|
|
* @var midcom_db_article |
|
24
|
|
|
*/ |
|
25
|
|
|
private $_article; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* The Datamanager of the article to display. |
|
29
|
|
|
* |
|
30
|
|
|
* @var datamanager |
|
31
|
|
|
*/ |
|
32
|
|
|
private $_datamanager; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* Simple helper which references all important members to the request data listing |
|
36
|
|
|
* for usage within the style listing. |
|
37
|
|
|
*/ |
|
38
|
1 |
|
private function _prepare_request_data() |
|
39
|
|
|
{ |
|
40
|
1 |
|
$this->_request_data['article'] = $this->_article; |
|
41
|
1 |
|
$this->_request_data['datamanager'] = $this->_datamanager; |
|
42
|
|
|
|
|
43
|
1 |
|
$buttons = []; |
|
44
|
1 |
|
$workflow = $this->get_workflow('datamanager'); |
|
45
|
1 |
|
if ($this->_article->can_do('midgard:update')) { |
|
46
|
1 |
|
$buttons[] = $workflow->get_button("edit/{$this->_article->guid}/", [ |
|
47
|
1 |
|
MIDCOM_TOOLBAR_ACCESSKEY => 'e', |
|
48
|
|
|
]); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
1 |
|
if ( $this->_article->topic === $this->_topic->id |
|
52
|
1 |
|
&& $this->_article->can_do('midgard:delete')) { |
|
53
|
1 |
|
$delete = $this->get_workflow('delete', ['object' => $this->_article]); |
|
54
|
1 |
|
$buttons[] = $delete->get_button("delete/{$this->_article->guid}/"); |
|
55
|
|
|
} |
|
56
|
1 |
|
$this->_view_toolbar->add_items($buttons); |
|
57
|
1 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Handle actual article display |
|
61
|
|
|
*/ |
|
62
|
1 |
|
public function _handler_view(string $handler_id, array $args, array &$data) |
|
63
|
|
|
{ |
|
64
|
1 |
|
$qb = midcom_db_article::new_query_builder(); |
|
65
|
1 |
|
$this->article_qb_constraints($qb); |
|
66
|
|
|
|
|
67
|
1 |
|
$qb->begin_group('OR'); |
|
68
|
1 |
|
$qb->add_constraint('name', '=', $args[0]); |
|
69
|
1 |
|
$qb->add_constraint('guid', '=', $args[0]); |
|
70
|
1 |
|
$qb->end_group(); |
|
71
|
1 |
|
$this->_article = $qb->get_result(0); |
|
|
|
|
|
|
72
|
1 |
|
if (!$this->_article) { |
|
73
|
|
|
throw new midcom_error_notfound('Could not find ' . $args[0]); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
1 |
|
if ($handler_id == 'view-raw') { |
|
77
|
|
|
midcom::get()->skip_page_style = true; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
1 |
|
$this->_datamanager = new datamanager($data['schemadb']); |
|
81
|
1 |
|
$this->_datamanager->set_storage($this->_article); |
|
82
|
|
|
|
|
83
|
1 |
|
if ($this->_config->get('comments_enable')) { |
|
84
|
|
|
if ($node = net_nehmer_comments_interface::get_node($this->_topic, $this->_config->get('comments_topic'))) { |
|
85
|
|
|
$this->_request_data['comments_url'] = $node[MIDCOM_NAV_RELATIVEURL] . "comment/{$this->_article->guid}"; |
|
86
|
|
|
if ( $this->_topic->can_do('midgard:update') |
|
87
|
|
|
&& $this->_topic->can_do('net.nehmer.comments:moderation')) { |
|
88
|
|
|
net_nehmer_comments_viewer::add_head_elements(); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
// TODO: Should we tell admin to create a net.nehmer.comments folder? |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
1 |
|
$this->add_breadcrumb($this->get_url($this->_article), $this->_article->title); |
|
95
|
|
|
|
|
96
|
1 |
|
$this->_prepare_request_data(); |
|
97
|
|
|
|
|
98
|
1 |
|
$this->bind_view_to_object($this->_article, $this->_datamanager->get_schema()->get_name()); |
|
99
|
1 |
|
midcom::get()->metadata->set_request_metadata($this->_article->metadata->revised, $this->_article->guid); |
|
100
|
1 |
|
midcom::get()->head->set_pagetitle("{$this->_topic->extra}: {$this->_article->title}"); |
|
101
|
1 |
|
$data['view_article'] = $this->_datamanager->get_content_html(); |
|
102
|
1 |
|
return $this->show('view'); |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|