WYSIJA_module

The MailPoet Newsletters WYSIJA module class.

Defined (1)

The class is defined in the following location(s).

/core/module/module.php  
  1. class WYSIJA_module extends WYSIJA_control{ 
  2.  
  3. /** 
  4. * ID of module 
  5. * @var string 
  6. */ 
  7. protected $name; 
  8.  
  9. /** 
  10. * view class of module 
  11. * @var string 
  12. */ 
  13. public $view; 
  14.  
  15. /** 
  16. * instance of view class of module 
  17. * @var string 
  18. */ 
  19. protected $view_obj; 
  20.  
  21.  
  22. /** 
  23. * action/view of a hook 
  24. * @var string 
  25. */ 
  26.  
  27. protected $view_show; 
  28.  
  29. /** 
  30. * data which view class will pull from 
  31. * @var array 
  32. */ 
  33. protected $data; 
  34.  
  35. protected $extended_plugin='wysija-newsletters'; 
  36.  
  37.  
  38.  
  39. /** 
  40. * Define hook name and list of modules of each hook 
  41. * @var Array 
  42. * @todo: implement hook management which allows to manage hooks from admin side 
  43. */ 
  44.  
  45. protected $is_premium = false; 
  46.  
  47. public static $hooks = array( 
  48. 'hook_stats' => array( 
  49. 'stats_top_newsletters',  
  50. 'stats_top_subscribers',  
  51. 'stats_top_links',  
  52. 'stats_new_subscribers',  
  53. 'stats_subscriptions',  
  54. 'stats_top_domains' 
  55. ),  
  56.  
  57. // the left block in the page "subscriber detail" 
  58. 'hook_subscriber_left' => array( 
  59. ),  
  60.  
  61. // the righ block in the page "subscriber detail" 
  62. 'hook_subscriber_right' => array( 
  63. 'stats_subscriber' 
  64. ),  
  65. 'hook_subscriber_bottom' => array( 
  66. 'stats_subscribers_std',  
  67. ),  
  68. // top of newsletter (viewstats) page 
  69. 'hook_newsletter_top' => array( 
  70.  
  71. 'stats_newsletter_std',  
  72. 'stats_newsletter',  
  73. ),  
  74.  
  75. // Newsletters >> Newsletter detail: bottom block 
  76. 'hook_newsletter_bottom' => array( 
  77. //'stats_newsletter_std',  
  78. ),  
  79.  
  80. // the block "super advanced" in Settings >> Advanced tab 
  81. 'hook_settings_super_advanced' => array( 
  82. 'archive_std' 
  83. ),  
  84.  
  85. // event: before saving settings (Admin) 
  86. 'hook_settings_before_save' => array( 
  87. 'archive_std' 
  88. ); 
  89. /** 
  90. * Constructor 
  91. * This is neccessary to override default action of WYSIJA_control::WYSIJA_control(),  
  92. * which always tries to load a default view object 
  93. */ 
  94. public function __construct() { 
  95. if (!empty($this->model)) { 
  96. $class_name = $this->model; 
  97. $this->model_obj = new $class_name(); 
  98. $this->model_obj->limit = 0; // quickfix "Undefined property: WYSIJA_model_statistics::$limit in views\back.php::limitPerPage()" 
  99. $this->get_view_obj($this->extended_plugin); 
  100. if (!empty($this->view_obj) && !empty($this->model_obj)) { 
  101. $this->view_obj->model = $this->model_obj; 
  102.  
  103. $this->data['module_name'] = $this->name; 
  104.  
  105.  
  106. $model_config=WYSIJA::get('config', 'model'); 
  107. if($model_config->getValue('premium_key')) 
  108. $this->is_premium = true; 
  109. $this->data['is_premium'] = $this->is_premium; 
  110.  
  111. /** 
  112. * get name of module 
  113. * @return string 
  114. */ 
  115. public function get_name() { 
  116. return $this->name; 
  117.  
  118. /** 
  119. * Get unique link to the module and hook. This link will be displayed as an independent page and actually it renders [wysijap] postype 
  120. * @param string $module_name 
  121. * @param string $hook_name 
  122. * @param array $params (key => value, key => value) 
  123. * @return type 
  124. */ 
  125. public static function get_module_link($module_name, $hook_name, $extended_plugin='wysija-newsletters', Array $params = array()) { 
  126. $model_config=WYSIJA::get('config', 'model'); 
  127. $params = array_merge($params, array( 
  128. 'wysija-page' => 1,  
  129. 'controller'=>'module',  
  130. 'action' => 'init',  
  131. 'module' => $module_name,  
  132. 'extension' => $extended_plugin,  
  133. 'hook' => $hook_name 
  134. )); 
  135. return WYSIJA::get_permalink($model_config->getValue('confirm_email_link'), $params); 
  136.  
  137. /** 
  138. * Return Hooks List 
  139. * @param string $hook_name name of hook 
  140. * @module_name string $module_name name of a specific module 
  141. * @return Array list of modules 
  142. */ 
  143. public static function get_modules_from_hook($hook_name, $module_name = null) { 
  144. $module_list = self::get_hook_module_list(); 
  145. $modules = !empty($module_list[$hook_name]) ? $module_list[$hook_name] : array(); 
  146. if ($module_name) 
  147. return isset($modules[$module_name]) ? array($modules[$module_name]) : array(); 
  148. return $modules; 
  149.  
  150. /** 
  151. * Get all registered hooks and modules 
  152. * @return Array 
  153. */ 
  154. public static function get_hook_module_list() { 
  155. return self::$hooks; 
  156.  
  157. /** 
  158. * Execute a hook, module by module, from first one to last one 
  159. * @param string $hook_name 
  160. * @param string $params 
  161. * @param string $extended_plugin 
  162. * @todo Performance factor: 
  163. * We are calling the same method for free / Premium version. 
  164. * Some modules don't exist at free side. 
  165. * Some modules don't exist at Premium side. 
  166. * This fact leads to an other fact: we have to check_exist() in both cases. 
  167. * Solution 1: cache by using a static attribute, within this class 
  168. * Solution 2: populate data to an external file (xml), and load that file into this static attribute (with solution 1) 
  169. */ 
  170. public static function execute_hook($hook_name, $params, $extended_plugin='wysija-newsletters') { 
  171. $hook_output = ''; 
  172. if (!empty(self::$hooks[$hook_name])) { 
  173. foreach (self::$hooks[$hook_name] as $module_name) { 
  174. $module = WYSIJA::get($module_name, 'module', false, $extended_plugin); 
  175. if(!empty($module) && method_exists($module, $hook_name)) 
  176. $hook_output .= $module->$hook_name($params); 
  177. return $hook_output; 
  178.  
  179. /** 
  180. * get an instance of a module class 
  181. * @param string $module_name module to be loaded 
  182. * @param type $extended_plugin : used only when calling the url from a different plugin it is used watch those files : 
  183. * -core/controller.php line 21, 23 , 24 
  184. * @return an instance of WYSIJA_module or its derived classes 
  185. */ 
  186. public static function get_instance_by_name($module_name, $extended_plugin='wysija-newsletters') { 
  187. return WYSIJA::get($module_name, 'module', false, $extended_plugin); 
  188.  
  189. /** 
  190. * Render a view/action 
  191. * @return string 
  192. */ 
  193. public function render($buffering_output = true) { 
  194. if (!empty($this->view)) 
  195. if ($buffering_output) 
  196. ob_start(); 
  197. if (!$buffering_output) 
  198. return $this->get_view_obj()->render($this->view_show, $this->data, true); 
  199. else{ 
  200. $this->get_view_obj()->render($this->view_show, $this->data, true); 
  201. $view = ob_get_contents(); 
  202. ob_end_clean(); 
  203. return $view; 
  204.  
  205. /** 
  206. * initialize WYSIJA_view instance 
  207. * @return WYSIJA_view 
  208. */ 
  209. protected function get_view_obj() { 
  210. require_once(WYSIJA_CORE.'view.php'); 
  211. require_once(WYSIJA_VIEWS.WYSIJA_SIDE.'.php'); 
  212. if (empty($this->view_obj)) { 
  213.  
  214. $view_dir=WYSIJA_PLG_DIR.$this->extended_plugin.DS.'modules'.DS.$this->name; // quickfix, @todo 
  215. $class_path=$view_dir.DS.$this->view.'.php';// @todo: check exists 
  216. $class_name = strtoupper('wysija').'_module_view_'.$this->view; 
  217. require_once(WYSIJA_CORE.'view.php'); 
  218. require_once($class_path); 
  219. $this->view_obj = new $class_name(); 
  220. return $this->view_obj;