WYSIJA_view

The MailPoet Newsletters WYSIJA view class.

Defined (1)

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

/core/view.php  
  1. class WYSIJA_view extends WYSIJA_object { 
  2.  
  3. var $title = "DEFAULT TITLE"; 
  4.  
  5. var $icon = "icon-edit"; 
  6.  
  7. var $links = array( ); 
  8.  
  9. var $search = array( ); 
  10.  
  11. var $cols_nks = array( ); //correspondance between user_id and user-id once processed 
  12.  
  13. static $color_coordinates = array( ); 
  14.  
  15. static $cache_color_schemes = array( ); 
  16.  
  17. /** 
  18. * Color schemes of MailPoet 
  19. * @var array 
  20. */ 
  21. var $color_schemes = array( 
  22. array( '#21759b', '#6697BF', '#487192', '#284c69', '#000333' ), // like blue 
  23. array( '#388e71', '#2c6f58', '#16523d', '#0d3c2c', '#092e21' ), // like green 
  24. array( '#c97575', '#a76262', '#854f4f', '#743a3a', '#5a2a2a' ), // like red 
  25. array( '#00CC00', '#269926', '#008500', '#39E639', '#67E667' ), // http://colorschemedesigner.com/#2P11Tw0w0w0w0 // green 
  26. array( '#FF0000', '#BF3030', '#A60000', '#FF4040', '#FF7373' ) // http://colorschemedesigner.com/#0011Tw0w0w0w0 // red 
  27. ); 
  28.  
  29. /** 
  30. * Default font family 
  31. * @var type 
  32. */ 
  33. var $font_family = array( 'Arial' ); 
  34.  
  35. /** 
  36. * Default font size in pixel 
  37. * @var int 
  38. */ 
  39. var $font_size = 12; 
  40.  
  41. function __construct() { 
  42. parent::__construct(); 
  43.  
  44. /** 
  45. * Swap color schemes, to make sure, we don't use 2 colors in a same scheme continously 
  46. * @return array() 
  47. */ 
  48. protected function swap_color_schemes() { 
  49. if (empty(self::$cache_color_schemes)) { 
  50. // swap colors from axis X => Y, Y => X 
  51. $x = count($this->color_schemes[0][0]); 
  52. $y = count($this->color_schemes[0]); 
  53. $tmp = array( ); 
  54. foreach ($this->color_schemes as $y => $colors) { 
  55. foreach ($colors as $x => $color) { 
  56. $tmp[$x][$y] = $color; 
  57. self::$cache_color_schemes = $tmp; 
  58. return self::$cache_color_schemes; 
  59.  
  60. /** 
  61. * Get one random color from schemes 
  62. * @return type 
  63. * Depreciated 
  64. */ 
  65. public function get_random_color() { 
  66. return $this->get_next_color(); 
  67.  
  68. /** 
  69. * Reset color to default 
  70. */ 
  71. public function reset_color() { 
  72. $class_name = get_class($this); 
  73. self::$color_coordinates[$class_name] = array( ); 
  74.  
  75. public function get_next_color() { 
  76.  
  77. $color_schemes = $this->swap_color_schemes(); 
  78.  
  79. $class_name = get_class($this); 
  80. if (empty(self::$color_coordinates[$class_name])) 
  81. self::$color_coordinates[$class_name] = array( 'x' => 0, 'y' => 0 ); 
  82.  
  83. $current_color = $color_schemes[self::$color_coordinates[$class_name]['x']][self::$color_coordinates[$class_name]['y']]; 
  84.  
  85. // find out and set a next color 
  86. $flag = false; 
  87. $detected_new_color = false; 
  88. foreach ($color_schemes as $x => $colors) { 
  89. if ($detected_new_color) 
  90. break; 
  91. foreach ($colors as $y => $color) { 
  92. if ($flag) { 
  93. self::$color_coordinates[$class_name]['x'] = $x; 
  94. self::$color_coordinates[$class_name]['y'] = $y; 
  95. $detected_new_color = true; 
  96. break; 
  97. if ($x == self::$color_coordinates[$class_name]['x'] && $y == self::$color_coordinates[$class_name]['y']) 
  98. $flag = true; 
  99. if (!$detected_new_color) { 
  100. self::$color_coordinates[$class_name]['x'] = 0; 
  101. self::$color_coordinates[$class_name]['y'] = 0; 
  102. return $current_color; 
  103.  
  104. /** 
  105. * Get all colors from schemes 
  106. * @return type 
  107. */ 
  108. function get_all_colors() { 
  109. $color_schemes = $this->swap_color_schemes(); // this one, to make sure, we don't put same color tone continously 
  110.  
  111. $tmp = array( ); 
  112. foreach ($color_schemes as $colors) { 
  113. $tmp = array_merge($tmp, $colors); 
  114. return $tmp; 
  115.  
  116. function renderErrorInstall() { 
  117. $this->title = __("Your server's configuration doesn't allow us to complete MailPoet's Installation!", WYSIJA); 
  118. $this->header(); 
  119. $this->footer(); 
  120.  
  121. /** 
  122. * @param type $type 
  123. * @param type $data 
  124. * @param bool $is_module is rendering a module view 
  125. */ 
  126. function render($type, $data, $is_module = false) { 
  127. $this->action = $type; 
  128. if (!$is_module) { 
  129. $this->header($data); 
  130. if ($type !== NULL) { 
  131. $this->$type($data); 
  132. if (!$is_module) { 
  133. $this->footer(); 
  134.  
  135. /** 
  136. * display all the messages that have queued 
  137. * @global type $wysija_msg 
  138. */ 
  139. function messages($noglobal = false) { 
  140. $wysija_msg = $this->getMsgs(); 
  141.  
  142. if (isset($wysija_msg['g-updated'])) { 
  143. if (!$noglobal) { 
  144. if (isset($wysija_msg['updated'])) 
  145. $wysija_msg['updated'] = array_merge((array)$wysija_msg['updated'], $wysija_msg['g-updated']); 
  146. else 
  147. $wysija_msg['updated'] = $wysija_msg['g-updated']; 
  148. unset($wysija_msg['g-updated']); 
  149. if (isset($wysija_msg['g-error'])) { 
  150. if (!$noglobal) { 
  151. if (isset($wysija_msg['error'])) 
  152. $wysija_msg['error'] = array_merge((array)$wysija_msg['error'], $wysija_msg['g-error']); 
  153. else 
  154. $wysija_msg['error'] = $wysija_msg['g-error']; 
  155. unset($wysija_msg['g-error']); 
  156. $wpnonce = '<input type="hidden" value="'.wp_create_nonce("wysija_ajax").'" id="wysijax" />'; 
  157. if (!$wysija_msg) 
  158. return '<div class="wysija-msg ajax"></div>'.$wpnonce; 
  159. $html = '<div class="wysija-msg">'; 
  160. foreach ($wysija_msg as $level => $messages) { 
  161. $msg_class = ''; 
  162. switch ($level) { 
  163. case 'updated': 
  164. $msg_class = 'notice-msg updated'; 
  165. break; 
  166. case 'error': 
  167. $msg_class = 'error-msg error'; 
  168. break; 
  169. case 'xdetailed-updated': 
  170. $msg_class = 'xdetailed-updated'; 
  171. break; 
  172. case 'xdetailed-errors': 
  173. $msg_class = 'xdetailed-errors'; 
  174. break; 
  175.  
  176. $html.='<div class="'.$msg_class.'">'; 
  177. $html.='<ul>'; 
  178.  
  179. if (count($messages) > 0) { 
  180. foreach ($messages as $msg) { 
  181. // check type of msg variable 
  182. if (is_array($msg)) { 
  183. $msg = var_export($msg, true); 
  184.  
  185. // display message 
  186. $html.='<li>'.$msg.'</li>'; 
  187.  
  188.  
  189. $html.='</ul>'; 
  190. $html.='</div>'; 
  191. $html.='</div><div class="wysija-msg ajax"></div>'.$wpnonce; 
  192.  
  193. return $html; 
  194.  
  195. /** 
  196. * this function let us generate a nonce which is an encrypted unique word based n the user info and some other stuff. 
  197. * by default it will create an hidden input nonce field 
  198. * @param type $params 
  199. * @param type $get 
  200. * @return type 
  201. */ 
  202. static function secure($params = array( ), $get = false, $echo = true) { 
  203. $controller = ''; 
  204. if (!is_array($params)) 
  205. $action = $params; 
  206. else { 
  207. $action = $params['action']; 
  208. if (isset($params['controller'])) 
  209. $controller = $params['controller']; 
  210. elseif (isset($_REQUEST['page'])) 
  211. $controller = $_REQUEST['page']; 
  212. $nonceaction = $controller.'-action_'.$action; 
  213.  
  214. if (is_array($params) && isset($params['id']) && $params['id']) 
  215. $nonceaction.='-id_'.$params['id']; 
  216.  
  217. if ($get) { 
  218. return wp_create_nonce($nonceaction); 
  219. else { 
  220. return wp_nonce_field($nonceaction, '_wpnonce', true, $echo); 
  221.  
  222. /** 
  223. * this allows us to get a field class to be validated by when making a form field 
  224. * @param type $params 
  225. * @param string $prefixclass 
  226. * @return string 
  227. */ 
  228. function getClassValidate($params, $returnAttr = false, $prefixclass = "") { 
  229. $class_validate = ''; 
  230. $recognised_types = array( 'email', 'url' ); 
  231.  
  232. if (isset($params['req'])) { 
  233. $class_validate = 'required'; 
  234. if (isset($params['type']) && in_array($params['type'], $recognised_types)) { 
  235. $class_validate.=', custom['.$params['type'].']'; 
  236. else { 
  237. if (isset($params['type']) && in_array($params['type'], $recognised_types)) { 
  238. $class_validate.='custom['.$params['type'].']'; 
  239.  
  240. if ($prefixclass) 
  241. $prefixclass.=' '; 
  242. if ($class_validate) 
  243. $class_validate = 'validate['.$class_validate.']'; 
  244. if (!$returnAttr && $class_validate) 
  245. $class_validate = ' class="'.$prefixclass.$class_validate.'" '; 
  246.  
  247. return $class_validate; 
  248.  
  249. /** 
  250. * central function to return a translated formated date 
  251. * @param type $val 
  252. * @param type $format 
  253. * @return string 
  254. */ 
  255. function fieldListHTML_created_at($val, $format = '') { 
  256. if (!$val) 
  257. return '---'; 
  258.  
  259. //offset the time to the time of the WP site not the server 
  260. $helper_toolbox = WYSIJA::get('toolbox', 'helper'); 
  261. // get current time taking timezone into account. 
  262.  
  263. $val = $helper_toolbox->servertime_to_localtime($val); 
  264.  
  265. if ($format) 
  266. return date_i18n($format, $val); 
  267. else 
  268. return date_i18n(get_option('date_format'), $val); 
  269.  
  270. function fieldListHTML_created_at_time($val) { 
  271. return $this->fieldListHTML_created_at($val, get_option('date_format').', '.get_option('time_format')); 
  272.