-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBootgenie.php
178 lines (154 loc) · 6.33 KB
/
Bootgenie.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
namespace thebuggenie\modules\bootgenie;
use thebuggenie\core\framework;
/**
* Autogenerated module Bootgenie
*
* @author
* @version 0.1
* @license http://opensource.org/licenses/MPL-2.0 Mozilla Public License 2.0 (MPL 2.0)
* @package bootgenie
* @subpackage core
*
* @Table(name="\thebuggenie\core\entities\tables\Modules")
*/
class Bootgenie extends \thebuggenie\core\entities\Module
{
const VERSION = '0.1';
protected $_name = 'bootgenie';
protected $_longname = 'Bootgenie';
protected $_description = 'Bootgenie description here';
protected $_module_config_title = 'Bootgenie';
protected $_module_config_description = 'Set up the Bootgenie module from this section';
protected $_overridemap = ['components'=>[], 'actions'=>[]];
protected $debug = false;
protected function _initialize()
{
define('BOOTGENIE_PATH', THEBUGGENIE_PATH . 'modules/bootgenie/');
// Add override rules
$this->addOverride('main/index', 'bootgenie/main_index', 'action');
$this->addOverride('main/login', 'bootgenie/main_login', 'action');
$this->addOverride('main/loginregister', 'bootgenie/main_loginregister', 'component');
$this->addOverride('main/login', 'bootgenie/main_login', 'component');
$this->addOverride('main/menulinks', 'bootgenie/main_menulinks', 'component');
$this->addOverride('main/captcha', 'bootgenie/main_captcha', 'component');
$this->addOverride('main/openidbuttons', 'bootgenie/main_openidbuttons', 'component');
$this->addOverride('publish/showarticle', 'bootgenie/publish_showarticle', 'action');
// $this->addOverride('publish/showarticle', 'bootgenie/publish/showarticle', 'action');
$this->addOverride('publish/specialarticle', 'bootgenie/publish_specialarticle', 'action');
$this->addOverride('publish/articledisplay', 'bootgenie/publish_articledisplay', 'component');
// $this->addOverride('publish/articledisplay', 'bootgenie/publish/articledisplay', 'component');
$this->addOverride('publish/menustriplinks', 'bootgenie/publish_menustriplinks', 'component');
$this->addOverride('publish/whatlinkshere', 'bootgenie/publish_whatlinkshere', 'component');
$this->addOverride('publish/tools', 'bootgenie/publish_tools', 'component');
$this->addOverride('publish/latestArticles', 'bootgenie/publish_latestArticles', 'component');
$this->addOverride('project/projectinfolinks', 'bootgenie/project_projectinfolinks', 'component');
$this->addOverride('agile/headermenuprojectlinks', 'bootgenie/agile_headermenuprojectlinks', 'component');
// Disable for testing
// $this->_enabled = false;
}
protected function _addListeners()
{
if ( $this->_enabled == true ) {
// listen for renderTemplate (overwrite module action templates)
framework\Event::listen('core', 'self::performAction::renderTemplate', array($this, 'listen_renderTemplate'));
// listen for renderBegins (overwrite layout and components)
framework\Event::listen('core', '\thebuggenie\core\framework\Context::renderBegins', array($this, 'listen_renderBegins'));
}
}
protected function _install($scope)
{
}
protected function _loadFixtures($scope)
{
}
protected function _uninstall()
{
}
/**
* Return an instance of this module
*
* @return Bootgenie
*/
public static function getModule()
{
return framework\Context::getModule('bootgenie');
}
/**
* Add an override rule to the override map
*
* @return NULL
*/
public function addOverride($original, $override, $type='component')
{
// $new_array = [$original => $override];
if ( $type == 'component' ){
$this->_overridemap['components'][$original] = $override;
} elseif ( $type == 'action' ){
$this->_overridemap['actions'][$original] = $override;
}
}
/**
* Get an override map compatible with framework\Routing::setComponentOverrideMap
*
* @return array
*/
public function getComponentOverrideMap()
{
$return_array = [];
foreach($this->_overridemap['components'] as $key=>$value){
// enable multiple / separators for components
$a = explode('/', $value);
$module = array_shift($a);
$method = implode('/', $a);
$return_array[$key] = ['module'=>$module, 'method'=>$method];
}
return $return_array;
}
/**
* Get an override map containing all the actions
*
* @return array
*/
public function getActionOverrideMap()
{
$return_array = [];
foreach($this->_overridemap['actions'] as $key=>$value){
list($class, $action) = explode('/', $key);
$return_array[$key] = ['class'=>$class, 'action'=>$action, 'template'=>$value];
}
return $return_array;
}
/**
* Listen to the renderTemplate function and override any template
*
* @param framework\Event $event Event with the 'class' and 'action' parameters
*
* @return array
*/
public function listen_renderTemplate(framework\Event $event)
{
// set override map for components
framework\Context::getRouting()->setComponentOverrideMap( $this->getComponentOverrideMap() );
// set override map for actions
$actionmap = $this->getActionOverrideMap();
$template = framework\Context::getResponse()->getTemplate();
foreach( $actionmap as $value){
if ( stripos($event->getParameter('class'), $value['class']) !== FALSE && stripos($template, $value['action']) !== FALSE) {
framework\Context::getResponse()->setTemplate($value['template']);
}
}
$event->setProcessed();
}
public function listen_renderBegins(framework\Event $event)
{
// Set core layout path
framework\Context::getResponse()->setLayoutPath(BOOTGENIE_PATH . 'templates');
if ($this->debug) {
echo '<div class="alert alert-info" role="alert">';
echo '<p>page: '.framework\Context::getResponse()->getPage().'</p>';
echo '<p>template: '.framework\Context::getResponse()->getTemplate().'</p>';
echo '</div>';
}
}
}