PageRenderTime 37ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://bitbucket.org/antonyravel/cape-resorts
PHP | 302 lines | 227 code | 51 blank | 24 comment | 46 complexity | 8d88b534909854378fa65b2628bdf193 MD5 | raw file
  1. <?php
  2. define("ZING_PHPLIST_URL",'http://eu1.ml.clientcentral.info'); //URL end point for web services stored on Zingiri servers
  3. if (!get_option('zing_mailz_key')) update_option('zing_mailz_key',md5(time().sprintf(mt_rand(),'%10d')));
  4. $zing_mailz_options[]=array( "name" => "Remote settings",
  5. "type" => "heading",
  6. "desc" => "This section manages the Mailing List settings.");
  7. $zing_mailz_options[]=array( "name" => "API key",
  8. "desc" => "This plugin uses remote web services to provide mailing list functionality. This API key has been automatically generated for you. Once you click on Install, the API key, in combination with your web site address <strong>".home_url()."</strong> will create an account on our servers allowing the plugin to access the remote web services.<br />The combination of API key and your web site address uniquely identifes you so please make sure to keep it in a safe place. ",
  9. "id" => "zing_mailz_key",
  10. "type" => "text");
  11. $zing_mailz_options[]=array( "name" => "License key",
  12. "desc" => "If you wish to activate the Pro features of Mailing List, enter your license key here. You can purchase a license key <a href=\"http://www.zingiri.com/plugins-and-addons/mailing-list\" target=\"_blank\">here</a>.",
  13. "id" => "zing_mailz_lic",
  14. "type" => "text");
  15. $zing_mailz_options[]=array( "name" => "Show footer",
  16. "desc" => "Show your support by enabling our page footer.",
  17. "id" => "zing_mailz_footer",
  18. "type" => "checkbox");
  19. $zing_mailz_options[]=array( "name" => "Before you install",
  20. "type" => "heading",
  21. "desc" => '<div style="text-decoration:underline;display:inline;font-weight:bold">IMPORTANT:</div> Mailing List uses web services stored on Zingiri\'s servers. In doing so, personal data is collected and stored on our servers.
  22. This data includes amongst others your admin email address as this is used, together with the API key as a unique identifier for your account on Zingiri\'s servers.
  23. We have a very strict <a href="http://www.zingiri.com/privacy-policy/" target="_blank">privacy policy</a> as well as <a href="http://www.zingiri.com/terms/" target="_blank">terms & conditions</a> governing data stored on our servers.
  24. <div style="font-weight:bold;display:inline">By installing this plugin you accept these terms & conditions.</div>');
  25. function zing_mailz_http($module,$to_include="index",$get=array()) {
  26. global $wpdb,$current_user;
  27. $vars="";
  28. if (!$to_include || $to_include==".php") $to_include="index";
  29. $t=explode('/',$to_include);
  30. if (count($t)==2) {
  31. $http=ZING_PHPLIST_URL.'/'.$t[0].'/api.php';
  32. } else {
  33. $http=ZING_PHPLIST_URL.'/api.php';
  34. }
  35. $and="&";
  36. $vars="pg=".urlencode($to_include);
  37. $unload=array("_wpnonce","zlist","zpage","page_id","zscp","zlistpage","page","action","plugin");
  38. $get=array_merge($_GET,$get);
  39. if (count($get) > 0) {
  40. foreach ($get as $n => $v) {
  41. if (!in_array($n,$unload)) {
  42. $vars.= $and.$n.'='.zing_urlencode($v);
  43. $and="&";
  44. } elseif ($n=="zlistpage" && $v !== null) {
  45. $vars.= $and.'page'.'='.zing_urlencode($v);
  46. $and="&";
  47. }
  48. }
  49. }
  50. $wp=array();
  51. if (is_user_logged_in()) {
  52. $wp['login']=$current_user->data->user_login;
  53. $wp['email']=$current_user->data->user_email;
  54. $wp['first_name']=isset($current_user->data->first_name) ? $current_user->data->first_name: $current_user->data->display_name;
  55. $wp['last_name']=isset($current_user->data->last_name) ? $current_user->data->last_name : $current_user->data->display_name;
  56. $wp['roles']=$current_user->roles;
  57. }
  58. $wp['default_page']=zing_mailz_default_page();
  59. $wp['lic']=get_option('zing_mailz_lic');
  60. $wp['gmt_offset']=get_option('gmt_offset');
  61. $wp['siteurl']=home_url();
  62. $wp['sitename']=get_bloginfo('name');
  63. $wp['pluginurl']=ZING_MAILZ_URL;
  64. if (is_admin()) {
  65. $wp['mode']='b';
  66. $wp['pageurl']=get_admin_url().'admin.php?page=bookings&';
  67. } else {
  68. $wp['mode']='f';
  69. $wp['pageurl']=zing_mailz_home();
  70. }
  71. $wp['time_format']=get_option('time_format');
  72. $wp['admin_email']=get_option('admin_email');
  73. $wp['key']=get_option('zing_mailz_key');
  74. $wp['lang']=get_option('zing_mailz_lang'); //get_bloginfo('language');
  75. $wp['client_version']=ZING_MAILZ_VERSION;
  76. $vars.='&wp='.urlencode(base64_encode(json_encode($wp)));
  77. if ($vars) $http.='?'.$vars;
  78. //echo '<br /><br /><br />'.$http;
  79. return $http;
  80. }
  81. /**
  82. * Activation: creation of database tables & set up of pages
  83. * @return unknown_type
  84. */
  85. function zing_mailz_install_db() {
  86. global $wpdb;
  87. global $current_user;
  88. global $zing_mailz_options;
  89. if (isset($_REQUEST['action']) && ($_REQUEST['action']=='error_scrape')) {
  90. echo get_option('activation-output');
  91. return;
  92. }
  93. delete_option('activation-output');
  94. $zing_mailz_version=get_option("zing_mailz_version");
  95. //create standard pages
  96. if (!$zing_mailz_version) {
  97. $pages=array();
  98. $pages[]=array("Mailing list","mailz","*",0);
  99. $ids="";
  100. foreach ($pages as $i =>$p)
  101. {
  102. $my_post = array();
  103. $my_post['post_title'] = $p['0'];
  104. $my_post['post_content'] = '';
  105. $my_post['post_status'] = 'publish';
  106. $my_post['post_author'] = 1;
  107. $my_post['post_type'] = 'page';
  108. $my_post['comment_status'] = 'closed';
  109. $my_post['menu_order'] = 100+$i;
  110. $id=wp_insert_post( $my_post );
  111. if (empty($ids)) { $ids.=$id; } else { $ids.=",".$id; }
  112. if (!empty($p[1])) add_post_meta($id,'zing_mailz_page',$p[1]);
  113. }
  114. update_option("zing_mailz_pages",$ids);
  115. }
  116. //setup
  117. if (!$zing_mailz_version) {
  118. $http=zing_mailz_http('mailz','admin/index.php',array('zlistpage'=>'initialise','firstintall'=>1));
  119. $news = new zHttpRequest($http,'mailz');
  120. if ($news->live()) {
  121. $output=$news->DownloadToString();
  122. //echo $output;die();
  123. }
  124. }
  125. //default options
  126. if (count($zing_mailz_options) > 0) {
  127. foreach ($zing_mailz_options as $value) {
  128. if ( !empty($value['id']) && !get_option($value['id']) ) update_option( $value['id'], $value['std'] );
  129. }
  130. }
  131. update_option("zing_mailz_version",ZING_MAILZ_VERSION);
  132. }
  133. /**
  134. * Uninstallation: removal of database tables
  135. * @return void
  136. */
  137. function zing_mailz_uninstall() {
  138. global $wpdb;
  139. $http=zing_mailz_http('mailz','deactivate.php');
  140. $news = new zHttpRequest($http,'mailz');
  141. if ($news->live()) {
  142. $output=$news->DownloadToString();
  143. }
  144. $ids=get_option("zing_mailz_pages");
  145. $ida=explode(",",$ids);
  146. foreach ($ida as $id) {
  147. wp_delete_post($id);
  148. }
  149. delete_option("zing_mailz_key");
  150. delete_option("zing_mailz_mode");
  151. delete_option("zing_mailz_version");
  152. delete_option("zing_mailz_pages");
  153. delete_option("zing_mailz_news");
  154. delete_option("zing_mailz_news_time");
  155. }
  156. function zing_mailz_login() {
  157. global $current_user,$wpdb;
  158. return true;
  159. $loggedin=false;
  160. if (!isset($_SESSION['zing']['mailz']['loggedin'])) $_SESSION['zing']['mailz']['loggedin']=0;
  161. if (!current_user_can('edit_plugins') && $_SESSION['zing']['mailz']['loggedin'] > 0) {
  162. zing_mailz_logout();
  163. }
  164. if (!is_admin()) {
  165. $loggedin=true;
  166. } elseif (is_admin() && current_user_can('edit_plugins') && time()-$_SESSION['zing']['mailz']['loggedin'] > 60) { //We relogin every minute to avoid time outs
  167. }
  168. elseif (isset($_SESSION['zing']['mailz']['loggedin'])) $loggedin=true;
  169. return $loggedin;
  170. }
  171. function zing_mailz_logout() {
  172. return true;
  173. $_GET['zlistpage']='logout';
  174. $http=zing_mailz_http('mailz','admin/index.php',array('zlistpage' => null));
  175. $news = new zHttpRequest($http,'mailz');
  176. if ($news->live()) {
  177. $output=$news->DownloadToString(true);
  178. unset($_SESSION['zing']['mailz']['loggedin']);
  179. }
  180. }
  181. /*
  182. function zing_mailz_more_reccurences() {
  183. return array(
  184. 'minute' => array('interval' => 60, 'display' => 'Every minute'),
  185. 'weekly' => array('interval' => 604800, 'display' => 'Once Weekly'),
  186. 'fortnightly' => array('interval' => 1209600, 'display' => 'Once Fortnightly'),
  187. );
  188. }
  189. add_filter('cron_schedules', 'zing_mailz_more_reccurences');
  190. */
  191. function zing_mailz_cron() {
  192. $msg=time();
  193. $post['login']='admin';
  194. $post['password']=get_option('zing_mailz_password');
  195. $http=zing_mailz_http('mailz','admin/index.php',array('zlistpage'=>'processqueue','user'=>'admin','password'=>get_option('zing_mailz_password')));
  196. $news = new zHttpRequest($http,'mailz');
  197. $news->post=$post;
  198. if ($news->live()) {
  199. $output=$news->DownloadToString();
  200. $msg.='ok';
  201. } else {
  202. $msg.='failed';
  203. }
  204. update_option('zing_mailz_cron',$msg);
  205. }
  206. if (!wp_next_scheduled('zing_mailz_cron_hook')) {
  207. wp_schedule_event( time(), 'hourly', 'zing_mailz_cron_hook' );
  208. }
  209. //add_action('zing_mailz_cron_hook','zing_mailz_cron');
  210. function zing_mailz_default_page() {
  211. $pageID=zing_mailz_mainpage();
  212. if (get_option('permalink_structure')){
  213. $homePage = get_option('home');
  214. $wordpressPageName = get_permalink($pageID);
  215. $wordpressPageName = str_replace($homePage,"",$wordpressPageName);
  216. $home=$homePage.$wordpressPageName;
  217. if (substr($home,-1) != '/') $home.='/';
  218. $and='?';
  219. }else{
  220. $home=get_option('home').'/?page_id='.$pageID;
  221. $and='&';
  222. }
  223. return $home.$and;
  224. }
  225. function zing_mailz_home() {
  226. global $post,$page_id;
  227. $pageID = $page_id;
  228. if (get_option('permalink_structure')){
  229. $homePage = get_option('home');
  230. $wordpressPageName = get_permalink($pageID);
  231. $wordpressPageName = str_replace($homePage,"",$wordpressPageName);
  232. $home=$homePage.$wordpressPageName;
  233. if (substr($home,-1) != '/') $home.='/';
  234. $home.='?';
  235. }else{
  236. $home=get_option('home').'/?page_id='.$pageID.'&';
  237. }
  238. return $home;
  239. }
  240. function zing_mailz_footer() {
  241. $bail_out = ( ( defined( 'WP_ADMIN' ) && WP_ADMIN == true ) || ( strpos( $_SERVER[ 'PHP_SELF' ], 'wp-admin' ) !== false ) );
  242. if ( $bail_out ) return $footer;
  243. $f='';
  244. if (get_option('zing_mailz_footer')) {
  245. $f='<div style="clear:both"></div>';
  246. $f.='<center style="margin-top:0px;font-size:x-small">';
  247. $f.='Wordpress and <a href ="http://www.phplist.com/" target="_blank">phpList</a> integration by <a href="http://www.zingiri.com" target="_blank">Zingiri</a>';
  248. $f.='</center>';
  249. }
  250. return $f;
  251. }