|
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
|
|
|
/** |
|
10
|
|
|
* n.n.blog link handler |
|
11
|
|
|
* |
|
12
|
|
|
* @package net.nehmer.blog |
|
13
|
|
|
*/ |
|
14
|
|
|
class net_nehmer_blog_handler_link extends midcom_baseclasses_components_handler |
|
|
|
|
|
|
15
|
|
|
implements midcom_helper_datamanager2_interfaces_create |
|
|
|
|
|
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* The content topic to use |
|
19
|
|
|
* |
|
20
|
|
|
* @var midcom_db_topic |
|
21
|
|
|
*/ |
|
22
|
|
|
private $_content_topic = null; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* The article link which has been created |
|
26
|
|
|
* |
|
27
|
|
|
* @var net_nehmer_blog_link_dba |
|
28
|
|
|
*/ |
|
29
|
|
|
private $_link = null; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Maps the content topic from the request data to local member variables. |
|
33
|
|
|
*/ |
|
34
|
|
|
public function _on_initialize() |
|
35
|
|
|
{ |
|
36
|
|
|
$this->_content_topic = $this->_request_data['content_topic']; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function load_schemadb() |
|
40
|
|
|
{ |
|
41
|
|
|
return midcom_helper_datamanager2_schema::load_database($this->_config->get('schemadb_link')); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
public function get_schema_name() |
|
45
|
|
|
{ |
|
46
|
|
|
return 'link'; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
View Code Duplication |
public function get_schema_defaults() |
|
|
|
|
|
|
50
|
|
|
{ |
|
51
|
|
|
$defaults = array(); |
|
52
|
|
|
if (isset($_GET['article'])) |
|
53
|
|
|
{ |
|
54
|
|
|
$defaults['article'] = $_GET['article']; |
|
55
|
|
|
} |
|
56
|
|
|
else |
|
57
|
|
|
{ |
|
58
|
|
|
$defaults['topic'] = $this->_topic->id; |
|
59
|
|
|
} |
|
60
|
|
|
return $defaults; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* DM2 creation callback, binds to the current content topic. |
|
65
|
|
|
*/ |
|
66
|
|
View Code Duplication |
public function &dm2_create_callback (&$controller) |
|
|
|
|
|
|
67
|
|
|
{ |
|
68
|
|
|
$this->_link = new net_nehmer_blog_link_dba(); |
|
69
|
|
|
$this->_link->topic = $this->_topic->id; |
|
70
|
|
|
|
|
71
|
|
|
if (!$this->_link->create()) |
|
72
|
|
|
{ |
|
73
|
|
|
debug_print_r('We operated on this object:', $this->_link); |
|
74
|
|
|
throw new midcom_error('Failed to create a new article. Last Midgard error was: '. midcom_connection::get_error_string()); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
return $this->_link; |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Displays an article edit view. |
|
82
|
|
|
* |
|
83
|
|
|
* @param mixed $handler_id The ID of the handler. |
|
84
|
|
|
* @param array $args The argument list. |
|
85
|
|
|
* @param array &$data The local request data. |
|
86
|
|
|
*/ |
|
87
|
|
View Code Duplication |
public function _handler_create($handler_id, array $args, array &$data) |
|
|
|
|
|
|
88
|
|
|
{ |
|
89
|
|
|
$this->_content_topic->require_do('midgard:create'); |
|
90
|
|
|
|
|
91
|
|
|
if (!$this->_config->get('enable_article_links')) |
|
92
|
|
|
{ |
|
93
|
|
|
throw new midcom_error_notfound('Article linking disabled'); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
$workflow = $this->get_workflow('datamanager2', array |
|
97
|
|
|
( |
|
98
|
|
|
'controller' => $this->get_controller('create'), |
|
99
|
|
|
'save_callback' => array($this, 'save_callback') |
|
100
|
|
|
)); |
|
101
|
|
|
|
|
102
|
|
|
midcom::get()->head->set_pagetitle(sprintf($this->_l10n_midcom->get('create %s'), $this->_l10n->get('article link'))); |
|
103
|
|
|
|
|
104
|
|
|
return $workflow->run(); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function save_callback(midcom_helper_datamanager2_controller $controller) |
|
108
|
|
|
{ |
|
109
|
|
|
// Reindex the article |
|
110
|
|
|
$indexer = midcom::get()->indexer; |
|
111
|
|
|
net_nehmer_blog_viewer::index($controller->datamanager, $indexer, $this->_content_topic); |
|
112
|
|
|
$article = new midcom_db_article($this->_link->article); |
|
113
|
|
|
return $article->name . '/'; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/** |
|
117
|
|
|
* Displays article link delete confirmation |
|
118
|
|
|
* |
|
119
|
|
|
* @param mixed $handler_id The ID of the handler. |
|
120
|
|
|
* @param array $args The argument list. |
|
121
|
|
|
* @param array &$data The local request data. |
|
122
|
|
|
*/ |
|
123
|
|
View Code Duplication |
public function _handler_delete($handler_id, array $args, array &$data) |
|
|
|
|
|
|
124
|
|
|
{ |
|
125
|
|
|
$article = new midcom_db_article($args[0]); |
|
126
|
|
|
|
|
127
|
|
|
$qb = net_nehmer_blog_link_dba::new_query_builder(); |
|
128
|
|
|
$qb->add_constraint('topic', '=', $this->_content_topic->id); |
|
129
|
|
|
$qb->add_constraint('article', '=', $article->id); |
|
130
|
|
|
|
|
131
|
|
|
if ($qb->count() === 0) |
|
132
|
|
|
{ |
|
133
|
|
|
throw new midcom_error_notfound('No links were found'); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
// Get the link |
|
137
|
|
|
$results = $qb->execute_unchecked(); |
|
138
|
|
|
$this->_link = $results[0]; |
|
139
|
|
|
$this->_link->require_do('midgard:delete'); |
|
140
|
|
|
|
|
141
|
|
|
$workflow = $this->get_workflow('delete', array |
|
142
|
|
|
( |
|
143
|
|
|
'object' => $this->_link, |
|
144
|
|
|
'label' => $this->_l10n->get('article link') |
|
145
|
|
|
)); |
|
146
|
|
|
return $workflow->run(); |
|
147
|
|
|
} |
|
148
|
|
|
} |
|
149
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.