PageRenderTime 27ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/wp-content/plugins/mailz/mailz.php

https://bitbucket.org/antonyravel/cape-resorts
PHP | 374 lines | 288 code | 52 blank | 34 comment | 85 complexity | 2079587b877eaeb9df9b9a39729885ac MD5 | raw file
  1. <?php
  2. /*
  3. Plugin Name: Mailing List
  4. Plugin URI: http://www.zingiri.com/plugins-and-addons/mailing-list
  5. Description: This plugin provides easy to use mailing list functionality to your Wordpress site
  6. Author: Zingiri
  7. Version: 2.3.1
  8. Author URI: http://www.zingiri.com/
  9. */
  10. define("ZING_MAILZ_VERSION","2.3.1");
  11. define("ZING_MAILZ_PREFIX","zing_");
  12. if (isset($wpdb)) $dbtablesprefix=$wpdb->prefix.ZING_MAILZ_PREFIX;
  13. // Pre-2.6 compatibility for wp-content folder location
  14. if (!defined("WP_CONTENT_URL")) {
  15. define("WP_CONTENT_URL", get_option("siteurl") . "/wp-content");
  16. }
  17. if (!defined("WP_CONTENT_DIR")) {
  18. define("WP_CONTENT_DIR", ABSPATH . "wp-content");
  19. }
  20. if (!defined("ZING_MAILZ_PLUGIN")) {
  21. $zing_mailz_plugin=substr(dirname(__FILE__),strlen(WP_CONTENT_DIR)+9,strlen(dirname(__FILE__))-strlen(WP_CONTENT_DIR)-9);
  22. define("ZING_MAILZ_PLUGIN", $zing_mailz_plugin);
  23. }
  24. if (!defined("ZING_MAILZ_DIR")) {
  25. define("ZING_MAILZ_DIR", WP_CONTENT_DIR . "/plugins/".ZING_MAILZ_PLUGIN."/lists/");
  26. }
  27. if (!defined("ZING_MAILZ_LOC")) {
  28. define("ZING_MAILZ_LOC", WP_CONTENT_DIR . "/plugins/".ZING_MAILZ_PLUGIN."/");
  29. }
  30. if (!defined("ZING_MAILZ_URL")) {
  31. define("ZING_MAILZ_URL", WP_CONTENT_URL . "/plugins/".ZING_MAILZ_PLUGIN."/");
  32. }
  33. if (!defined("ZING_MAILZ_LOGIN")) {
  34. define("ZING_MAILZ_LOGIN", get_option("zing_mailz_login"));
  35. }
  36. if (!defined("BLOGUPLOADDIR")) {
  37. $upload=wp_upload_dir();
  38. define("BLOGUPLOADDIR",$upload['path']);
  39. }
  40. $zing_mailz_version=get_option("zing_mailz_version");
  41. if ($zing_mailz_version) {
  42. add_action("init","zing_mailz_init");
  43. add_filter('the_content', 'zing_mailz_content', 10, 3);
  44. add_action('wp_head','zing_mailz_head');
  45. add_action('wp_head','zing_mailz_header');
  46. add_action('admin_notices','zing_mailz_notices');
  47. }
  48. add_action('admin_head','zing_mailz_admin_head');
  49. register_activation_hook(__FILE__,'zing_mailz_activate');
  50. register_deactivation_hook(__FILE__,'zing_mailz_deactivate');
  51. if (!zing_mailz_mode()) require_once(dirname(__FILE__) . '/includes/options.inc.php');
  52. elseif (zing_mailz_mode()=='remote') require_once(dirname(__FILE__) . '/includes/misc2.php');
  53. elseif (zing_mailz_mode()=='local') require_once(dirname(__FILE__) . '/includes/misc1.php');
  54. require_once(dirname(__FILE__) . '/includes/index.php');
  55. require_once(dirname(__FILE__) . '/classes/index.php');
  56. require_once(dirname(__FILE__) . '/mailz_cp.php');
  57. function zing_mailz_notices() {
  58. $zing_mailz_version=get_option("zing_mailz_version");
  59. $warnings=array();
  60. if (($ssp=session_save_path()) && !is_writable($ssp)) $warnings[]='PHP sessions are not properly configured on your server, the sessions save path '.$ssp.' is not writable.';
  61. if (phpversion() < '5') $warnings[]="You are running PHP version ".phpversion().". You require PHP version 5.2 or higher for this plugin, with version 5.3 recommended.";
  62. if (!function_exists('curl_init')) $warnings[]="You need to have cURL installed. Contact your hosting provider to do so.";
  63. $upload=wp_upload_dir();
  64. if ($upload['error']) $warnings[]=$upload['error'];
  65. if (empty($zing_mailz_version)) $warnings[]='Please proceed with a clean install or deactivate your plugin';
  66. elseif ($zing_mailz_version != ZING_MAILZ_VERSION) $warnings[]='You downloaded version '.ZING_MAILZ_VERSION.'. Please verify and <a href="admin.php?page=mailz_setup">update</a> your settings (currently at version '.$zing_mailz_version.').';
  67. if (get_option('activation-output')) {
  68. // $warnings[]='An error occured during activation:<br /><div style="background-color:white">'.get_option('activation-output').'</div>';
  69. }
  70. if (count($warnings)>0) {
  71. echo "<div id='zing-warning' style='clear:both;background-color:greenyellow' class='updated fade'>";
  72. foreach ($warnings as $message) {
  73. echo "<p><strong>Mailing list: ".$message."</strong></p>";
  74. }
  75. echo "</div>";
  76. }
  77. }
  78. function zing_activation_output($buffer) {
  79. update_option('activation-output',$buffer);
  80. if ($buffer) die();
  81. }
  82. function zing_mailz_activate() {
  83. }
  84. /**
  85. * Deactivation
  86. * @return void
  87. */
  88. function zing_mailz_deactivate() {
  89. wp_clear_scheduled_hook('zing_mailz_cron_hook');
  90. }
  91. /**
  92. * Main function handling content
  93. * @param $process
  94. * @param $content
  95. * @return unknown_type
  96. */
  97. function zing_mailz_main($process,$content="") {
  98. global $zing_mailz_content;
  99. if ((!is_admin() || (is_admin() && strstr($_REQUEST['page'],'mailz'))) && $zing_mailz_content) {
  100. $content='<div id="phplist">'.$zing_mailz_content.'</div>';
  101. $content.=zing_mailz_footer();
  102. }
  103. return $content;
  104. }
  105. function zing_mailz_output($process) {
  106. global $post;
  107. global $wpdb;
  108. global $cfg;
  109. global $thisuser;
  110. global $nav;
  111. global $zing_mailz_loaded,$zing_mailz_mode;
  112. $content="";
  113. switch ($process)
  114. {
  115. case "content":
  116. if (isset($_POST['zname'])) {
  117. $_POST['name']=$_POST['zname'];
  118. unset($_POST['zname']);
  119. }
  120. if (isset($post)) $cf=get_post_custom($post->ID);
  121. if (isset($_GET['zlist'])) {
  122. if (isset($_GET['page']) && ($_GET['page']=='mailz_cp')) $to_include='admin/index';
  123. elseif (isset($_GET['page'])) $to_include='admin/index';
  124. else $to_include=$_GET['zlist'];
  125. $zing_mailz_mode="client";
  126. }
  127. elseif (isset($_GET['zscp']))
  128. {
  129. $to_include="index";
  130. $zing_mailz_mode="admin";
  131. }
  132. elseif (isset($_GET['zsetup']))
  133. {
  134. $to_include="setup/".$_GET['zscp'];
  135. $zing_mailz_mode="setup";
  136. }
  137. elseif (isset($cf['zing_mailz_page']) && ($cf['zing_mailz_page'][0]=='mailz'))
  138. {
  139. $to_include="index";
  140. }
  141. elseif (isset($cf['zing_mailz_page']) && ($cf['zing_mailz_page'][0]=='admin'))
  142. {
  143. $to_include="index.php";
  144. $zing_mailz_mode="admin";
  145. }
  146. else
  147. {
  148. return $content;
  149. }
  150. if (isset($cf['cat'])) {
  151. $_GET['cat']=$cf['cat'][0];
  152. }
  153. break;
  154. default:
  155. return $content;
  156. break;
  157. }
  158. if (zing_mailz_login()) {
  159. $http=zing_mailz_http('mailz',$to_include.'.php');
  160. $news = new zHttpRequest($http,'mailz');
  161. if ($news->live()) {
  162. $output=$news->DownloadToString();
  163. if ($news->type=='application/csv') {
  164. ob_end_clean();
  165. header( "Content-type: ".$news->type );
  166. header('Content-Disposition: attachment; filename="download.csv"');
  167. echo $output;
  168. die();
  169. } else {
  170. if ($to_include=='admin/help/index') die($output);
  171. $output=stripslashes($output);
  172. $content.=zing_mailz_ob($output);
  173. }
  174. return $content;
  175. }
  176. }
  177. }
  178. function zing_mailz_mainpage() {
  179. $ids=get_option("zing_mailz_pages");
  180. $ida=explode(",",$ids);
  181. return $ida[0];
  182. }
  183. function zing_mailz_ob($buffer) {
  184. global $current_user,$zing_mailz_mode,$wpdb,$wp_version;
  185. $prefix=$wpdb->prefix.ZING_MAILZ_PREFIX;
  186. $home=get_option('home');
  187. $admin=get_option('siteurl').'/wp-admin/';
  188. $pid=zing_mailz_mainpage();
  189. $buffer=str_replace('page=','zlistpage=',$buffer);
  190. if (is_admin()) {
  191. $buffer=str_replace('<span class="menulinkleft"><a href="./?zlistpage=logout">logout</a><br /></span>','',$buffer);
  192. $buffer=str_replace('<a href="./?zlistpage=logout">logout</a>','',$buffer);
  193. $buffer=str_replace('./?','admin.php?'.'page=mailz_cp&zlist=index&',$buffer);
  194. if (isset($_GET['zlistpage'])) $buffer=str_replace('<form method=post >','<form method=post action="'.$admin.'admin.php?page=mailz_cp&zlist=index&zlistpage='.$_GET['zlistpage'].'">',$buffer);
  195. $buffer=str_replace('name="page"','name="zlistpage"',$buffer);
  196. $buffer=str_replace('<form method="get" name="listcontrol" action="">','<form method="get" name="listcontrol" action="admin.php"><input type="hidden" value="mailz-users" name="page"/>',$buffer);
  197. $buffer=str_replace('<form method="get" name="listcontrol">','<form method="get" name="listcontrol" action="admin.php"><input type="hidden" value="mailz-users" name="page"/>',$buffer);
  198. if (isset($_GET['zlistpage'])) $buffer=str_replace('<form method=get>','<form method=get><input type="hidden" name="page" value="mailz_cp" /><input type="hidden" name="zlist" value="index" /><input type="hidden" name="zlistpage" value="'.$_GET['zlistpage'].'" />',$buffer);
  199. if (isset($_GET['zlistpage'])) $buffer=str_replace('<form method="post" action="">','<form method=post action="'.$admin.'admin.php?page=mailz_cp&zlist=index&zlistpage='.$_GET['zlistpage'].'">',$buffer);
  200. $buffer=str_replace(ZING_PHPLIST_URL.'/?',$admin.'admin.php?page=mailz_cp&zlist=index&',$buffer);
  201. $buffer=str_replace('./FCKeditor',ZING_PHPLIST_URL.'/admin/FCKeditor',$buffer);
  202. $buffer=str_replace('src="images/','src="'.ZING_PHPLIST_URL.'/admin/images/',$buffer);
  203. $buffer=str_replace('src="js/jslib.js"','src="'.ZING_PHPLIST_URL.'/js/jslib.js"',$buffer);
  204. $buffer=str_replace('url( styles/tabs.css )','url( '.ZING_PHPLIST_URL.'/admin/styles/tabs.css )',$buffer);
  205. if ($wp_version >= '3.3') {
  206. //$f[]='/<textarea.id\="message".*class\="theEditor".*>((.|\s)*?)<\/textarea>/';
  207. $f[]='/<textarea id="message" class="theEditor" name=message cols=65 rows=20>((.|\s)*?)<\/textarea>/';
  208. $buffer=preg_replace_callback($f,'zingiri_mailz_editor_replace',$buffer);
  209. }
  210. } else {
  211. $buffer=str_replace('/lists/admin',$admin.'admin.php?page=mailz_cp&zlist=index&',$buffer); //go to admin page
  212. $buffer=str_replace('./?',$home.'/?page_id='.$pid.'&zlist=index&',$buffer);
  213. $buffer=str_replace(ZING_PHPLIST_URL.'/?',$home.'/?page_id='.$pid.'&zlist=index&',$buffer);
  214. if (isset($_GET['p']) && $_GET['p']=='subscribe' && isset($current_user->data->user_email)) {
  215. $buffer=str_replace('name=email value=""','name=email value="'.$current_user->data->user_email.'"',$buffer);
  216. $buffer=str_replace('name=emailconfirm value=""','name=emailconfirm value="'.$current_user->data->user_email.'"',$buffer);
  217. }
  218. if (isset($_GET['p']) && $_GET['p']=='unsubscribe' && isset($current_user) && isset($current_user->data->user_email)) {
  219. $query="select uniqid from ".$prefix."phplist_user where email='".$current_user->data->user_email."'";
  220. $uid=$wpdb->get_var($query);
  221. $buffer=str_replace('name="unsubscribeemail" value=""','name="unsubscribeemail" value="'.$current_user->data->user_email.'"',$buffer);
  222. $buffer=str_replace('uid="','uid='.$uid.'"',$buffer);
  223. }
  224. if (isset($_GET['p']) && $_GET['p']=='preferences' && isset($current_user->data->user_email)) {
  225. $buffer=str_replace('name=email value=""','name=email value="'.$current_user->data->user_email.'"',$buffer);
  226. $buffer=str_replace('name=emailconfirm value=""','name=emailconfirm value="'.$current_user->data->user_email.'"',$buffer);
  227. }
  228. }
  229. return '<!--buffer:start-->'.$buffer.'<!--buffer:end-->';
  230. }
  231. function zingiri_mailz_editor_replace($match) {
  232. $id='message';
  233. $content=html_entity_decode($match[1]);
  234. ob_start();
  235. wp_editor($content,$id);
  236. return ob_get_clean();
  237. }
  238. /**
  239. * Page content filter
  240. * @param $content
  241. * @return unknown_type
  242. */
  243. function zing_mailz_content($content) {
  244. return zing_mailz_main("content",$content);
  245. }
  246. /**
  247. * Header hook: loads FWS addons and css files
  248. * @return unknown_type
  249. */
  250. function zing_mailz_header()
  251. {
  252. global $zing_mailz_content;
  253. global $zing_mailz_menu;
  254. global $zing_mailz_post;
  255. if (isset($_POST) && isset($zing_mailz_post)) {
  256. $_POST=array_merge($_POST,$zing_mailz_post);
  257. }
  258. $output=zing_mailz_output("content");
  259. $menu1=zing_integrator_cut($output,'<div class="menutableright">','</div>');
  260. if ($menu1) {
  261. $menu1=str_replace('<span','<li><span',$menu1);
  262. $menu1=str_replace('</span>','</span></li>',$menu1);
  263. $menu1='<ul>'.$menu1.'</ul>';
  264. $menu1=str_replace('menulinkleft','xmenulinkleft',$menu1);
  265. $menu1=str_replace('<hr>','',$menu1);
  266. }
  267. $zing_mailz_menu=$menu1;
  268. if ($zing_mailz_menu) $_SESSION['mailz_menu']=$zing_mailz_menu;
  269. $body=zing_integrator_cut($output,'<body','</body>',true);
  270. $body=strchr($body,'>');
  271. $zing_mailz_content=trim(substr($body,1));
  272. }
  273. function zing_mailz_admin_head() {
  274. global $wp_version;
  275. if (isset($_REQUEST['page']) && (strstr($_REQUEST['page'],'mailz_') || strstr($_REQUEST['page'],'mailz-'))) {
  276. echo '<link rel="stylesheet" type="text/css" href="' . ZING_MAILZ_URL . 'lists/admin/styles/phplist.css" media="screen" />';
  277. echo '<link rel="stylesheet" type="text/css" href="' . ZING_MAILZ_URL . 'zing.css" media="screen" />';
  278. }
  279. if (($wp_version < '3.3') && ((isset($_REQUEST['zlistpage']) && ($_REQUEST['zlistpage']=='templatee' || $_REQUEST['zlistpage']=='send')) || (isset($_REQUEST['page']) && ($_REQUEST['page']=='mailz-send')))) {
  280. wp_tiny_mce( false, array( 'editor_selector' => 'theEditor' ) );
  281. }
  282. }
  283. function zing_mailz_head() {
  284. echo '<link rel="stylesheet" type="text/css" href="' . ZING_MAILZ_URL . 'lists/styles/phplist.css" media="screen" />';
  285. echo '<link rel="stylesheet" type="text/css" href="' . ZING_MAILZ_URL . 'zing.css" media="screen" />';
  286. }
  287. /**
  288. * Initialization of page, action & page_id arrays
  289. * @return unknown_type
  290. */
  291. function zing_mailz_init() {
  292. global $wp_version;
  293. ob_start();
  294. if (!session_id()) @session_start();
  295. if (is_admin() && ((isset($_REQUEST['zlistpage']) && ($_REQUEST['zlistpage']=='templatee' || $_REQUEST['zlistpage']=='send')) || (isset($_REQUEST['page']) && $_REQUEST['page']=='mailz-send'))) {
  296. wp_enqueue_script(array('jquery'));
  297. if ($wp_version < '3.3') wp_enqueue_script(array('editor', 'thickbox', 'media-upload'));
  298. }
  299. }
  300. function mailz_log($type=0,$msg='',$filename="",$linenum=0) {
  301. if (get_option('mailz_debug')) {
  302. if (is_array($msg)) $msg=print_r($msg,true);
  303. $v=get_option('mailz_debug_log');
  304. if (!is_array($v)) $v=array();
  305. array_unshift($v,array(time(),$type,$msg));
  306. update_option('mailz_debug_log',$v);
  307. }
  308. }
  309. function zing_mailz_mode() {
  310. if (!get_option('zing_mailz_mode')) {
  311. if (zing_mailz_has_local_database()) update_option('zing_mailz_mode','local');
  312. elseif (get_option('zing_mailz_key')) update_option('zing_mailz_mode','remote');
  313. }
  314. return get_option('zing_mailz_mode');
  315. }
  316. function zing_mailz_has_local_database() {
  317. global $wpdb;
  318. $query="show tables like '".$wpdb->prefix.ZING_MAILZ_PREFIX."phplist_config'";
  319. $rows=$wpdb->get_results($query);
  320. if (count($rows) > 0) return true;
  321. else return false;
  322. }