WJ_Analytics

Class Analytics.

Defined (1)

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

/classes/WJ_Analytics.php  
  1. class WJ_Analytics { 
  2.  
  3. // All analytics data to be sent to JS. 
  4. private $analytics_data = array( 
  5. 'php_version' => array( 
  6. 'label' => 'PHP version',  
  7. 'value' => '' 
  8. ),  
  9. 'monthly_emails_sent' => array( 
  10. 'label' => 'Monthly emails sent',  
  11. 'value' => '' 
  12. ),  
  13. 'lists_with_more_than_25' => array( 
  14. 'label' => 'Lists with more than 25 subscribers',  
  15. 'value' => '' 
  16. ),  
  17. 'confirmed_subscribers' => array( 
  18. 'label' => 'Confirmed subscribers',  
  19. 'value' => '' 
  20. ),  
  21. 'range_confirmed_subscribers' => array( 
  22. 'label' => 'Range Confirmed subscribers',  
  23. 'value' => '' 
  24. ),  
  25. 'unconfirmed_subscribers' => array( 
  26. 'label' => 'Unconfirmed subscribers',  
  27. 'value' => '' 
  28. ),  
  29. 'standard_newsletters' => array( 
  30. 'label' => 'Standard newsletters',  
  31. 'value' => '' 
  32. ),  
  33. 'auto_newsletters' => array( 
  34. 'label' => 'Auto newsletters',  
  35. 'value' => '' 
  36. ),  
  37. 'wordpress_version' => array( 
  38. 'label' => 'WordPress Version',  
  39. 'value' => '' 
  40. ),  
  41. 'plugin_version' => array( 
  42. 'label' => 'Plugin Version',  
  43. 'value' => '' 
  44. ),  
  45. 'license_type' => array( 
  46. 'label' => 'License type',  
  47. 'value' => '' 
  48. ),  
  49. 'sending_method' => array( 
  50. 'label' => 'Sending method',  
  51. 'value' => '' 
  52. ),  
  53. 'smtp_hostname' => array( 
  54. 'label' => 'Smtp hostname',  
  55. 'value' => '' 
  56. ),  
  57. 'activation_email_status' => array( 
  58. 'label' => 'Activation Email',  
  59. 'value' => '' 
  60. ),  
  61. 'average_open_rate' => array( 
  62. 'label' => 'Open rate',  
  63. 'value' => '' 
  64. ),  
  65. 'average_click_rate' => array( 
  66. 'label' => 'Click rate',  
  67. 'value' => '' 
  68. ),  
  69. 'industry' => array( 
  70. 'label' => 'Industry',  
  71. 'value' => '' 
  72. ),  
  73. 'wordpress_language' => array( 
  74. 'label' => 'WordPress Language',  
  75. 'value' => '' 
  76. ),  
  77. 'rtl' => array( 
  78. 'label' => 'Rtl',  
  79. 'value' => '' 
  80. ),  
  81. 'beta' => array( 
  82. 'label' => 'Beta',  
  83. 'value' => '' 
  84. ),  
  85. 'archive_page' => array( 
  86. 'label' => 'Archive Page',  
  87. 'value' => '' 
  88. ),  
  89. 'dkim_status' => array( 
  90. 'label' => 'DKIM Active',  
  91. 'value' => '' 
  92. ),  
  93. 'subscribe_in_comments' => array( 
  94. 'label' => 'Subscribe in comments',  
  95. 'value' => '' 
  96. ),  
  97. 'subscribe_on_register' => array( 
  98. 'label' => 'Subscribe on registration',  
  99. 'value' => '' 
  100. ),  
  101. 'browser_link' => array( 
  102. 'label' => 'View in browser link',  
  103. 'value' => '' 
  104. ),  
  105. 'profile_edit'=> array( 
  106. 'label' => 'Subcsribers can edit profile',  
  107. 'value' => '' 
  108. ),  
  109. 'html_edit' => array( 
  110. 'label' => 'Allow HTML edit',  
  111. 'value' => '' 
  112. ),  
  113. 'mailpoet_cron' => array( 
  114. 'label' => 'MailPoet Cron Enabled',  
  115. 'value' => '' 
  116. ),  
  117. 'forms_number' => array( 
  118. 'label' => 'Total number of forms',  
  119. 'value' => '' 
  120. ),  
  121. 'using_custom_fields' => array( 
  122. 'label' => 'Using custom fields',  
  123. 'value' => '' 
  124. ),  
  125. 'custom_fields_input' => array( 
  126. 'label' => 'Custom Fields: Input field',  
  127. 'value' => '' 
  128. ),  
  129. 'custom_fields_textarea' => array( 
  130. 'label' => 'Custom Fields: Textarea',  
  131. 'value' => '' 
  132. ),  
  133. 'custom_fields_select' => array( 
  134. 'label' => 'Custom Fields: Select',  
  135. 'value' => '' 
  136. ),  
  137. 'custom_fields_checkbox' => array( 
  138. 'label' => 'Custom Fields: Checkbox',  
  139. 'value' => '' 
  140. ),  
  141. 'custom_fields_radio' => array( 
  142. 'label' => 'Custom Fields: Radio',  
  143. 'value' => '' 
  144. ),  
  145. 'active_last_week' => array( 
  146. 'label' => 'Active last week',  
  147. 'value' => '' 
  148. ),  
  149. 'is_multisite' => array( 
  150. 'label' => 'Using Multisite',  
  151. 'value' => '' 
  152. ),  
  153. 'bounce_enabled' => array( 
  154. 'label' => 'Using bounce',  
  155. 'value' => '' 
  156. ); 
  157.  
  158. function __construct() { 
  159.  
  160. /** 
  161. * Send data to Mixpanel by enqueuing the analytics JS file. 
  162. * @return 
  163. */ 
  164. public function send() { 
  165.  
  166. // Enqueue analytics Javascript. 
  167. wp_enqueue_script('analytics', WYSIJA_URL . 'js/analytics.js', array(), WYSIJA::get_version()); 
  168. // Make analytics data available in JS. 
  169. wp_localize_script('analytics', 'analytics_data', $this->analytics_data); 
  170.  
  171. /** 
  172. * Generate fresh data and store it in the $analytics_data Class property. 
  173. * @return 
  174. */ 
  175. public function generate_data() { 
  176.  
  177. foreach ($this->analytics_data as $key => $data) { 
  178. $method = $key; 
  179. $this->analytics_data[$key]['value'] = call_user_func(array($this, $method)); 
  180.  
  181.  
  182. /** 
  183. * Calculate Emails sent in the last 30 days. 
  184. * @return Int 
  185. */ 
  186. private function monthly_emails_sent() { 
  187.  
  188. $model_email_user_stat = WYSIJA::get('email_user_stat', 'model'); 
  189. $query = 'SELECT COUNT(*) as total_emails 
  190. FROM ' . '[wysija]' . $model_email_user_stat->table_name . ' 
  191. WHERE DATE_SUB(CURDATE(), INTERVAL 30 DAY) <= sent_at'; 
  192. $result = $model_email_user_stat->query('get_res', $query); 
  193.  
  194. $total_emails = $result[0]['total_emails']; 
  195. switch (true) { 
  196. case ($total_emails <= 1000): 
  197. $track = 'Less than 1000'; 
  198. break; 
  199. case ((1001 <= $total_emails) && ($total_emails <= 2500)): 
  200. $track = '1001 to 2500'; 
  201. break; 
  202. case ((2501 <= $total_emails) && ($total_emails <= 5000)): 
  203. $track = '2501 to 5000'; 
  204. break; 
  205. case ((5001 <= $total_emails) && ($total_emails <= 10000)): 
  206. $track = '5001 to 10000'; 
  207. break; 
  208. case ((10001 <= $total_emails) && ($total_emails <= 25000)): 
  209. $track = '10001 to 25000'; 
  210. break; 
  211. case ((25001 <= $total_emails) && ($total_emails <= 50000)): 
  212. $track = '25001 to 50000'; 
  213. break; 
  214. case ((50001 <= $total_emails) && ($total_emails <= 100000)): 
  215. $track = '50001 to 100000'; 
  216. break; 
  217. case (100001 <= $total_emails): 
  218. $track = 'More than 100001'; 
  219. break; 
  220. default: 
  221. $track = 'No emails sent'; 
  222. break; 
  223.  
  224. return $track; 
  225.  
  226.  
  227. /** 
  228. Pass through the WordPress version. 
  229. */ 
  230. private function wordpress_version() { 
  231. return get_bloginfo('version'); 
  232.  
  233. /** 
  234. Pass through the WordPress language. 
  235. */ 
  236. private function wordpress_language() { 
  237. return get_bloginfo('language'); 
  238.  
  239. /** 
  240. The plugin version. 
  241. */ 
  242. private function plugin_version() { 
  243. return WYSIJA::get_version(); 
  244.  
  245. /** 
  246. * Calculate lists with more than 25 subscribers. 
  247. * @return Int 
  248. */ 
  249. private function lists_with_more_than_25() { 
  250.  
  251. $model_user_list = WYSIJA::get('user_list', 'model'); 
  252. $query = 'SELECT list_id, COUNT(*) as count 
  253. FROM ' . '[wysija]' . $model_user_list->table_name . ' 
  254. GROUP BY list_id 
  255. HAVING COUNT(*) >= 25'; 
  256. $result = $model_user_list->query('get_res', $query); 
  257. $lists_count = count($result); 
  258.  
  259. return $lists_count; 
  260.  
  261. /** 
  262. * Calculate total subscribers. 
  263. * @return Int 
  264. */ 
  265. private function total_subcsribers() { 
  266.  
  267. $model_user = WYSIJA::get('user', 'model'); 
  268. $query = 'SELECT COUNT(*) as total_subscribers 
  269. FROM ' . '[wysija]' . $model_user->table_name; 
  270. $result = $model_user->query('get_res', $query); 
  271.  
  272. return $result[0]['total_subscribers']; 
  273.  
  274. /** 
  275. * Calculate confirmed subscribers. 
  276. * @return Int 
  277. */ 
  278. private function confirmed_subscribers() { 
  279.  
  280. $model_user = WYSIJA::get('user', 'model'); 
  281. $query = 'SELECT COUNT(*) as confirmed_subscribers 
  282. FROM ' . '[wysija]' . $model_user->table_name . ' 
  283. WHERE status = 1'; 
  284. $result = $model_user->query('get_res', $query); 
  285.  
  286. $confirmed_subscribers = $result[0]['confirmed_subscribers']; 
  287. $total_subscribers = $this->total_subcsribers(); 
  288. $confirmed_percentage = round(($confirmed_subscribers * 100) / $total_subscribers); 
  289.  
  290. return $confirmed_percentage; 
  291.  
  292. /** 
  293. * @return string range eg: 0-100 101-200 2001-500 
  294. */ 
  295. private function range_confirmed_subscribers() { 
  296. $model_user = WYSIJA::get('user', 'model'); 
  297. $query = 'SELECT COUNT(*) as confirmed_subscribers 
  298. FROM ' . '[wysija]' . $model_user->table_name . ' 
  299. WHERE status = 1'; 
  300. $result = $model_user->query('get_res', $query); 
  301.  
  302. $confirmed_subscribers = (int) $result[0]['confirmed_subscribers']; 
  303.  
  304. $ranges_increment = array( 2000 => 100, 10000 => 500, 20000 => 1000, 40000 => 2000, 100000 => 5000, 200000 => 10000, 500000 => 25000, 1000000 => 50000); 
  305.  
  306. $found_range = $this->range_finder( $confirmed_subscribers, $ranges_increment ); 
  307.  
  308. return $found_range['lower'].' - '.$found_range['upper']; 
  309.  
  310. private function range_finder($value, $ranges_increment) { 
  311.  
  312. $limit_max = 0; 
  313. foreach( $ranges_increment as $limit => $range_increment ) { 
  314. $small_limit = $limit_max + $range_increment; 
  315. $limit_max = $limit; 
  316.  
  317. if( $value > $limit_max) { 
  318. continue; 
  319.  
  320. while( $value >= $small_limit && $small_limit <= $limit_max ) { 
  321.  
  322. if( $value > $small_limit ) { 
  323. $min_value = $small_limit - $range_increment + 1; 
  324. if( $value == $small_limit ) { 
  325. break; 
  326. $small_limit += $range_increment; 
  327.  
  328. if( $value <= $small_limit) { 
  329. break; 
  330.  
  331. if( $value > $limit_max) { 
  332. return array( 'lower' => $limit_max , 'upper' => 'above' ); 
  333. }else{ 
  334. if( $value < 1 ) { 
  335. return array( 'lower' => 0 , 'upper' => 'or undefined' ); 
  336. }else{ 
  337. $min_value = $small_limit - $range_increment + 1; 
  338. return array( 'lower' => $min_value , 'upper' => $small_limit ); 
  339.  
  340.  
  341. /** 
  342. * Calculate unconfirmed subscribers. 
  343. * @return Int 
  344. */ 
  345. public function unconfirmed_subscribers() { 
  346.  
  347. $model_user = WYSIJA::get('user', 'model'); 
  348. $query = 'SELECT COUNT(*) as unconfirmed_subscribers 
  349. FROM ' . '[wysija]' . $model_user->table_name . ' 
  350. WHERE status = 0'; 
  351. $result = $model_user->query('get_res', $query); 
  352.  
  353. return $result[0]['unconfirmed_subscribers']; 
  354.  
  355. /** 
  356. * Calculate standard newsletters total. 
  357. * @return Int 
  358. */ 
  359. private function standard_newsletters() { 
  360.  
  361. $model_email = WYSIJA::get('email', 'model'); 
  362. $query = 'SELECT COUNT(*) as standard_newsletters 
  363. FROM ' . '[wysija]' . $model_email->table_name . ' 
  364. WHERE type = 1 
  365. AND status = 2'; 
  366. $result = $model_email->query('get_res', $query); 
  367.  
  368. return $result[0]['standard_newsletters']; 
  369.  
  370. /** 
  371. * Calculate auto newsletters total. 
  372. * @return Int 
  373. */ 
  374. private function auto_newsletters() { 
  375.  
  376. $model_email = WYSIJA::get('email', 'model'); 
  377. $query = 'SELECT COUNT(*) as auto_newsletters 
  378. FROM ' . '[wysija]' . $model_email->table_name . ' 
  379. WHERE type = 2'; 
  380. $result = $model_email->query('get_res', $query); 
  381.  
  382. return $result[0]['auto_newsletters']; 
  383.  
  384. /** 
  385. * Check license type in use. 
  386. * @return String Free | Premium 
  387. */ 
  388. private function license_type() { 
  389.  
  390. $model_config = WYSIJA::get('config', 'model'); 
  391. $is_premium = $model_config->getValue('premium_key'); 
  392.  
  393. if ($is_premium) { 
  394. $license_type = 'Premium'; 
  395. } else { 
  396. $license_type = 'Free'; 
  397.  
  398. return $license_type; 
  399.  
  400. /** 
  401. * Get sending method in use. 
  402. * @return String 
  403. */ 
  404. private function sending_method() { 
  405.  
  406. $model_config = WYSIJA::get('config', 'model'); 
  407. return $model_config->getValue('sending_method'); 
  408.  
  409. /** 
  410. * Get smtp hostname in use. 
  411. * @return String 
  412. */ 
  413. private function smtp_hostname() { 
  414.  
  415. $model_config = WYSIJA::get('config', 'model'); 
  416. return $model_config->getValue('smtp_host'); 
  417.  
  418. /** 
  419. * Get activation email status. 
  420. * @return String On | Off 
  421. */ 
  422. private function activation_email_status() { 
  423.  
  424. $model_config = WYSIJA::get('config', 'model'); 
  425. $activation_email_status = $model_config->getValue('confirm_dbleoptin'); 
  426.  
  427. if ($activation_email_status === 1) { 
  428. $result = 'On'; 
  429. } else { 
  430. $result = 'Off'; 
  431.  
  432. return $result; 
  433.  
  434. /** 
  435. * Get DKIM status. 
  436. * @return String Yes | No 
  437. */ 
  438. private function dkim_status() { 
  439. $model_config = WYSIJA::get('config', 'model'); 
  440. $dkim_status = $model_config->getValue('dkim_active'); 
  441. if ($dkim_status === 1) { 
  442. $result = 'Yes'; 
  443. } else { 
  444. $result = 'No'; 
  445. return $result; 
  446.  
  447. /** 
  448. * Get subscribe in comments. 
  449. * @return String Yes | No 
  450. */ 
  451. private function subscribe_in_comments() { 
  452. $model_config = WYSIJA::get('config', 'model'); 
  453. $subscribe_in_comments = $model_config->getValue('commentform'); 
  454. if ($subscribe_in_comments == 1) { 
  455. $result = 'Yes'; 
  456. } else { 
  457. $result = 'No'; 
  458. return $result; 
  459.  
  460. /** 
  461. * Get subscribe during registration option. 
  462. * @return String Yes | No 
  463. */ 
  464. private function subscribe_on_register() { 
  465. $model_config = WYSIJA::get('config', 'model'); 
  466. $subscribe_on_register = $model_config->getValue('registerform'); 
  467. if ($subscribe_on_register == 1) { 
  468. $result = 'Yes'; 
  469. } else { 
  470. $result = 'No'; 
  471. return $result; 
  472.  
  473. /** 
  474. * Get view in browser option. 
  475. * @return String Yes | No 
  476. */ 
  477. private function browser_link() { 
  478. $model_config = WYSIJA::get('config', 'model'); 
  479. $browser_link = $model_config->getValue('viewinbrowser'); 
  480. if ($browser_link == 1) { 
  481. $result = 'Yes'; 
  482. } else { 
  483. $result = 'No'; 
  484. return $result; 
  485.  
  486. /** 
  487. * Get profile edit option. 
  488. * @return String Yes | No 
  489. */ 
  490. private function profile_edit() { 
  491. $model_config = WYSIJA::get('config', 'model'); 
  492. $profile_edit = $model_config->getValue('manage_subscriptions'); 
  493. if ($profile_edit == 1) { 
  494. $result = 'Yes'; 
  495. } else { 
  496. $result = 'No'; 
  497. return $result; 
  498.  
  499. /** 
  500. * Get html edit in newsletter option. 
  501. * @return String Yes | No 
  502. */ 
  503. private function html_edit() { 
  504. $model_config = WYSIJA::get('config', 'model'); 
  505. $html_edit = $model_config->getValue('html_source'); 
  506. if ($html_edit == 1) { 
  507. $result = 'Yes'; 
  508. } else { 
  509. $result = 'No'; 
  510. return $result; 
  511.  
  512. /** 
  513. * Get mailpoet cron option. 
  514. * @return String Yes | No 
  515. */ 
  516. private function mailpoet_cron() { 
  517. $model_config = WYSIJA::get('config', 'model'); 
  518. $cron_option = $model_config->getValue('cron_manual'); 
  519. if ($cron_option == 1) { 
  520. $result = 'Yes'; 
  521. } else { 
  522. $result = 'No'; 
  523. return $result; 
  524.  
  525. /** 
  526. * Calculate average open rate. 
  527. * @return Int 
  528. */ 
  529. private function average_open_rate() { 
  530.  
  531. $model_email_user_stat = WYSIJA::get('email_user_stat', 'model'); 
  532. $query = 'SELECT COUNT(*) as opened_emails 
  533. FROM ' . '[wysija]' . $model_email_user_stat->table_name . ' 
  534. WHERE status = 1'; 
  535. $result = $model_email_user_stat->query('get_res', $query); 
  536.  
  537. $opened_emails = $result[0]['opened_emails']; 
  538. $total_emails = $this->total_emails_sent(); 
  539.  
  540. if ($total_emails == 0) { 
  541. $average_open_rate = 0; 
  542. } else { 
  543. $average_open_rate = round(($opened_emails * 100) / $total_emails); 
  544.  
  545. return $average_open_rate; 
  546.  
  547. /** 
  548. * Calculate average click rate. 
  549. * @return String opened/total 
  550. */ 
  551. private function average_click_rate() { 
  552.  
  553. $model_email_user_stat = WYSIJA::get('email_user_stat', 'model'); 
  554. $query = 'SELECT COUNT(*) as clicked_emails 
  555. FROM ' . '[wysija]' . $model_email_user_stat->table_name . ' 
  556. WHERE status = 2'; 
  557. $result = $model_email_user_stat->query('get_res', $query); 
  558.  
  559. $clicked_emails = $result[0]['clicked_emails']; 
  560. $total_emails = $this->total_emails_sent(); 
  561.  
  562. if ($total_emails == 0) { 
  563. $average_click_rate = 0; 
  564. } else { 
  565. $average_click_rate = round(($clicked_emails * 100) / $total_emails); 
  566.  
  567. return $average_click_rate; 
  568.  
  569. /** 
  570. * Get all emails sent. 
  571. * @return Int 
  572. */ 
  573. private function total_emails_sent() { 
  574.  
  575. $model_email_user_stat = WYSIJA::get('email_user_stat', 'model'); 
  576. $query = 'SELECT COUNT(*) as all_emails 
  577. FROM ' . '[wysija]' . $model_email_user_stat->table_name . ''; 
  578. $result = $model_email_user_stat->query('get_res', $query); 
  579.  
  580. return $result[0]['all_emails']; 
  581.  
  582. /** 
  583. * Get total number of forms. 
  584. * @return Int 
  585. */ 
  586. private function forms_number() { 
  587.  
  588. $model_form = WYSIJA::get('forms', 'model'); 
  589. $query = 'SELECT COUNT(*) as forms_number 
  590. FROM ' . '[wysija]' . $model_form->table_name . ''; 
  591. $result = $model_form->query('get_res', $query); 
  592.  
  593. return $result[0]['forms_number']; 
  594.  
  595. /** 
  596. * Get Industry specified in the settings page. 
  597. * @return String 
  598. */ 
  599. public function industry() { 
  600. $model_config = WYSIJA::get('config', 'model'); 
  601. return $model_config->getValue('industry'); 
  602.  
  603. /** 
  604. * Get if is using right to left language. 
  605. * @return String 
  606. */ 
  607. private function rtl() { 
  608.  
  609. if (is_rtl()) { 
  610. $is_rtl = 'Yes'; 
  611. } else { 
  612. $is_rtl = 'No'; 
  613.  
  614. return $is_rtl; 
  615.  
  616. /** 
  617. * Check if it's multisite. 
  618. * @return String 
  619. */ 
  620. private function is_multisite() { 
  621.  
  622. if (is_multisite()) { 
  623. $is_multisite = 'Yes'; 
  624. } else { 
  625. $is_multisite = 'No'; 
  626.  
  627. return $is_multisite; 
  628.  
  629. /** 
  630. * Get if is using beta mode 
  631. * @return String 
  632. */ 
  633. private function beta() { 
  634.  
  635. $model_config = WYSIJA::get('config', 'model'); 
  636.  
  637. if ($model_config->getValue('beta_mode')) { 
  638. $is_beta = 'Yes'; 
  639. } else { 
  640. $is_beta = 'No'; 
  641.  
  642. return $is_beta; 
  643.  
  644. /** 
  645. * Checks if user used the archive page feature. 
  646. * @return String true | false 
  647. */ 
  648. private function archive_page() { 
  649.  
  650. $model_config = WYSIJA::get('config', 'model'); 
  651. $archive_lists = $model_config->getValue('archive_lists'); 
  652.  
  653. if (!empty($archive_lists)) { 
  654. $used_archive = 'true'; 
  655. } else { 
  656. $used_archive = 'false'; 
  657.  
  658. return $used_archive; 
  659.  
  660. /** 
  661. Check if user is using custom fields or not. 
  662. # => Yes | No 
  663. */ 
  664. private function using_custom_fields() { 
  665. $fields = WJ_Field::get_all(); 
  666. if ($fields != null) { 
  667. $result = 'Yes'; 
  668. } else { 
  669. $result = 'No'; 
  670. return $result; 
  671.  
  672. /** 
  673. How many input custom fields are in use. 
  674. # => int | null 
  675. */ 
  676. private function custom_fields_input() { 
  677. global $wpdb; 
  678. $field = new WJ_Field(); 
  679. $table_name = $field->get_table_name(); 
  680. $result = $wpdb->get_var( 
  681. "SELECT COUNT(*) as inputs 
  682. FROM $table_name 
  683. WHERE type = 'input'" 
  684. ); 
  685. if ($result == null) { 
  686. $result = '0'; 
  687. return $result; 
  688.  
  689. /** 
  690. How many textarea custom fields are in use. 
  691. # => int | null 
  692. */ 
  693. private function custom_fields_textarea() { 
  694. global $wpdb; 
  695. $field = new WJ_Field(); 
  696. $table_name = $field->get_table_name(); 
  697. $result = $wpdb->get_var( 
  698. "SELECT COUNT(*) as textareas 
  699. FROM $table_name 
  700. WHERE type = 'textarea'" 
  701. ); 
  702. if ($result == null) { 
  703. $result = '0'; 
  704. return $result; 
  705.  
  706. /** 
  707. How many select custom fields are in use. 
  708. # => int | null 
  709. */ 
  710. private function custom_fields_select() { 
  711. global $wpdb; 
  712. $field = new WJ_Field(); 
  713. $table_name = $field->get_table_name(); 
  714. $result = $wpdb->get_var( 
  715. "SELECT COUNT(*) as selects 
  716. FROM $table_name 
  717. WHERE type = 'select'" 
  718. ); 
  719. if ($result == null) { 
  720. $result = '0'; 
  721. return $result; 
  722.  
  723. /** 
  724. How many checkbox custom fields are in use. 
  725. # => int | null 
  726. */ 
  727. private function custom_fields_checkbox() { 
  728. global $wpdb; 
  729. $field = new WJ_Field(); 
  730. $table_name = $field->get_table_name(); 
  731. $result = $wpdb->get_var( 
  732. "SELECT COUNT(*) as checkboxes 
  733. FROM $table_name 
  734. WHERE type = 'checkbox'" 
  735. ); 
  736. if ($result == null) { 
  737. $result = '0'; 
  738. return $result; 
  739.  
  740. /** 
  741. How many checkbox custom fields are in use. 
  742. # => int | null 
  743. */ 
  744. private function custom_fields_radio() { 
  745. global $wpdb; 
  746. $field = new WJ_Field(); 
  747. $table_name = $field->get_table_name(); 
  748. $result = $wpdb->get_var( 
  749. "SELECT COUNT(*) as radios 
  750. FROM $table_name 
  751. WHERE type = 'radio'" 
  752. ); 
  753. if ($result == null) { 
  754. $result = '0'; 
  755. return $result; 
  756.  
  757. /** 
  758. Check if user has been active in the last week. 
  759. This means he sent at least one email. 
  760. # => Yes | No 
  761. */ 
  762. private function active_last_week() { 
  763. global $wpdb; 
  764. $model_stats = WYSIJA::get('email_user_stat', 'model'); 
  765. $table_name = '[wysija]' . $model_stats->table_name; 
  766.  
  767. $query = 'SELECT COUNT(*) as activities 
  768. FROM ' . $table_name . 
  769. ' WHERE sent_at > UNIX_TIMESTAMP(date_sub(now(), interval 1 week))'; 
  770.  
  771. $result = $model_stats->query('get_res', $query); 
  772. $result = $result[0]['activities']; 
  773.  
  774. if ($result > 0) { 
  775. return 'Yes'; 
  776. return 'No'; 
  777.  
  778. /** 
  779. * Check PHP versions 
  780. * @return string 
  781. */ 
  782. private function php_version() { 
  783. $php_version_factors = explode('.', phpversion()); 
  784. $main_version = (int)$php_version_factors[0]; 
  785. $sub_version = isset($php_version_factors[1]) ? (int)$php_version_factors[1] : null; 
  786.  
  787. $php_version = 'others'; 
  788. if ($sub_version !== null) { 
  789. if ($main_version == 4) { 
  790. $php_version = '4.x'; 
  791. } elseif ($main_version >= 5) { 
  792. $php_version = implode('.', array( $main_version, $sub_version )); 
  793. return $php_version; 
  794.  
  795.  
  796. /** 
  797. * Check if bounce is enabled 
  798. * @return string 
  799. */ 
  800. private function bounce_enabled() { 
  801. $multisite_prefix = ''; 
  802. if ( is_multisite() ) { 
  803. $multisite_prefix = 'ms_'; 
  804. $model_config = WYSIJA::get('config', 'model'); 
  805. return ($model_config->getValue( 
  806. $multisite_prefix . 'bounce_process_auto') 
  807. ) ? "Yes" : "No";