예제 #1
0
 public function defaultDisplay()
 {
     if (!WYSIJA::current_user_can('wysija_stats_dashboard')) {
         die('Action is forbidden.');
     }
     $this->pre_defined_dates = $this->get_pre_defined_dates();
     // Define view
     $this->viewShow = $this->action = 'main';
     $this->js['jquery.core'] = 'jquery/ui/jquery.ui.core';
     $this->js['jquery.datepicker'] = 'jquery/ui/jquery.ui.datepicker';
     $this->js['wysijalazyload'] = 'wysija-lazyload';
     $this->js['admin-statistics-filter'] = 'admin-statistics-filter';
     wp_enqueue_style('jquery.core', WYSIJA_URL . 'css/jquery/ui/themes/base/jquery.ui.core.min.css', array(), WYSIJA::get_version());
     wp_enqueue_style('jquery.core', WYSIJA_URL . 'css/jquery/ui/themes/base/jquery.ui.theme.min.css', array(), WYSIJA::get_version());
     // date filter
     $default_duration = $this->get_default_duration();
     if (function_exists('date_diff')) {
         $this->data['date_interval'] = date_diff(date_create($default_duration->from), date_create($default_duration->to));
     } else {
         $duration = strtotime($default_duration->to) - strtotime($default_duration->from);
         $helper_toolbox = WYSIJA::get('toolbox', 'helper');
         $this->data['date_interval'] = (object) $helper_toolbox->convert_seconds_to_array($duration, false);
     }
     $this->data['custom_dates'] = $this->pre_defined_dates;
     $this->data['default_duration'] = $default_duration;
     $this->data['js_date_format'] = $this->js_date_format;
     // Process and push data into view
     $this->data['lazy_load'] = $this->lazy_load;
     $hook_name = 'hook_stats';
     $hook_params = array();
     $hook_params['top'] = WYSIJA_module_statistics::DEFAULT_TOP_RECORDS;
     $hook_params['from'] = !empty($_REQUEST['filter']['from']) ? $_REQUEST['filter']['from'] : $default_duration->from;
     $hook_params['to'] = !empty($_REQUEST['filter']['to']) ? $_REQUEST['filter']['to'] : $default_duration->to;
     $hook_params['group_by'] = $this->data['date_interval']->days == 0 || $this->data['date_interval']->days > WYSIJA_module_statistics::SWITCHING_DATE_TO_MONTH_THRESHOLD ? WYSIJA_module_statistics::GROUP_BY_MONTH : WYSIJA_module_statistics::GROUP_BY_DATE;
     // $this->data['date_interval']->days == 0, means, no begin date, no end date
     // Hack!
     $_REQUEST['limit_pp'] = $hook_params['top'];
     // Pagination, mark current selected value
     // Modify TO date to make sure we always count 23:59:59 of that day
     $to = new DateTime($hook_params['to']);
     $to->modify('+1 day');
     $hook_params['to'] = $to->format($this->date_format);
     $modules = WYSIJA_module::get_modules_from_hook($hook_name);
     $this->data['modules'] = $modules;
     $this->data['lazy_load_modules'] = array();
     $this->data['first_module'] = '';
     if (!$this->lazy_load) {
         $this->data['hooks'][$hook_name] = apply_filters('hook_stats', '', $hook_params);
     } else {
         if (!empty($modules)) {
             $first_module = array_shift($modules);
             // List of lazy loaded modules
             $this->data['lazy_load_modules'] = $modules;
             // Evenly we are lazy loading, we always load the first module by default
             $this->data['first_module'] = apply_filters('custom_module_hook', '', $first_module, $hook_name, $hook_params);
         }
     }
 }
예제 #2
0
 /**
  * Dispatcher of module
  */
 public function init()
 {
     if (empty($_REQUEST['module']) || empty($_REQUEST['hook'])) {
         wp_redirect(home_url());
         exit;
     }
     $module_name = $_REQUEST['module'];
     $hook = $_REQUEST['hook'];
     $extension = !empty($_REQUEST['extension']) ? in_array($_REQUEST['extension'], array(WYSIJA, WYSIJANLP)) ? $_REQUEST['extension'] : WYSIJA : WYSIJA;
     $hook_params = array_merge($_REQUEST, array('controller_object' => $this));
     $this->subtitle = WYSIJA_module::get_instance_by_name($module_name, $extension)->{'hook_' . $hook}($hook_params);
 }
예제 #3
0
 function save()
 {
     $_REQUEST = stripslashes_deep($_REQUEST);
     $_POST = stripslashes_deep($_POST);
     $this->requireSecurity();
     $hook_settings_before_save = array('REQUEST' => &$_REQUEST);
     apply_filters('hook_settings_before_save', WYSIJA_module::execute_hook('hook_settings_before_save', $hook_settings_before_save), $hook_settings_before_save);
     $this->modelObj->save($_REQUEST['wysija']['config'], true);
     $hook_settings_super_advanced_params = array();
     $this->data['hooks']['hook_settings_super_advanced'] = apply_filters('hook_settings_super_advanced', WYSIJA_module::execute_hook('hook_settings_super_advanced', $hook_settings_super_advanced_params), $hook_settings_super_advanced_params);
     // redirect so that javascript values get updated
     wp_redirect('admin.php?page=wysija_config' . $_REQUEST['redirecttab']);
 }
예제 #4
0
 function edit($id = false)
 {
     if (empty($_REQUEST['id']) && empty($id)) {
         $this->error('Cannot edit element primary key is missing : ' . get_class($this));
         return;
     }
     if (!$id) {
         $id = $_REQUEST['id'];
     }
     // get detail info of current user
     $this->data['user'] = $this->modelObj->getDetails(array('user_id' => $id));
     if (!$this->data['user']) {
         $this->notice(__('No subscriber found, most probably because he was deleted.', WYSIJA));
         return $this->redirect();
     }
     // get list info
     $model_list = WYSIJA::get('list', 'model');
     $model_list->limitON = false;
     $model_list->orderBy('is_enabled', 'DESC');
     $this->data['list'] = $model_list->get(false, array('greater' => array('is_enabled' => '-1')));
     $this->viewObj->title = __('Edit', WYSIJA) . ' ' . $this->data['user']['details']['email'];
     // execute hooks
     $hook_params = array('user_id' => $id);
     $this->data['hooks']['hook_subscriber_left'] = apply_filters('hook_subscriber_left', WYSIJA_module::execute_hook('hook_subscriber_left', $hook_params), $hook_params);
     $this->data['hooks']['hook_subscriber_right'] = apply_filters('hook_subscriber_right', WYSIJA_module::execute_hook('hook_subscriber_right', $hook_params), $hook_params);
     $this->data['hooks']['hook_subscriber_bottom'] = apply_filters('hook_subscriber_bottom', WYSIJA_module::execute_hook('hook_subscriber_bottom', $hook_params), $hook_params);
     // prepare js, for rendering
     $this->js[] = 'wysija-validator';
 }
예제 #5
0
 function viewstats()
 {
     $this->js[] = 'wysija-admin-list';
     $this->js[] = 'wysija-charts';
     $this->viewShow = 'viewstats';
     $this->modelObj = WYSIJA::get("email", "model");
     $this->modelObj->limitON = false;
     $email_object = $this->modelObj->getOne(false, array("email_id" => $_REQUEST['id']));
     if (empty($email_object)) {
         $this->redirect('admin.php?page=wysija_campaigns');
         return;
     }
     $this->viewObj->model = $this->modelObj;
     $this->viewObj->namecampaign = $email_object['subject'];
     $this->viewObj->title = sprintf(__('Stats : %1$s', WYSIJA), $email_object['subject']);
     $modelObjCamp = WYSIJA::get("campaign", "model");
     $limit_pp = false;
     if (isset($modelObjCamp->limit_pp)) {
         $limit_pp = $modelObjCamp->limit_pp;
     }
     $modelObjCamp->limitON = false;
     $campaign = $modelObjCamp->getOne(false, array("campaign_id" => $email_object['campaign_id']));
     $this->setviewStatsfilter();
     $this->modelObj->reset();
     $this->modelObj->noCheck = true;
     // 0 - counting request
     $queryCmmonStart = 'SELECT count(distinct B.user_id) as users FROM `[wysija]user` as A';
     $queryCmmonStart .= ' LEFT JOIN `[wysija]' . $this->tableQuery . '` as B on A.user_id=B.user_id';
     // all the counts query
     $query = "SELECT count(user_id) as users, status FROM `[wysija]email_user_stat` as A\n\t\t\tWHERE A.email_id=" . $email_object['email_id'] . " GROUP BY status";
     $countss = $this->modelObj->query("get_res", $query, ARRAY_A);
     // we also count what is in the queue
     $query = "SELECT count(user_id) as users FROM `[wysija]queue` as A\n\t\t\tWHERE A.email_id=" . $email_object['email_id'];
     $countss[-2]['status'] = -3;
     $countss[-2]['users'] = $this->modelObj->count($query, 'users');
     $counts = array();
     $truetotal = $total = 0;
     foreach ($countss as $count) {
         switch ($count['status']) {
             case "-3":
                 $type = 'inqueue';
                 break;
             case "-2":
                 $type = 'notsent';
                 break;
             case "-1":
                 $type = 'bounced';
                 break;
             case "0":
                 $type = 'sent';
                 break;
             case "1":
                 $type = 'opened';
                 break;
             case "2":
                 $type = 'clicked';
                 break;
             case "3":
                 $type = 'unsubscribe';
                 break;
         }
         if ($count['status'] != "-2") {
             $total = $total + $count['users'];
         }
         $truetotal = $truetotal + $count['users'];
         $counts[$type] = $count['users'];
     }
     $counts['allsent'] = $total;
     $counts['all'] = $truetotal;
     $this->modelObj->reset();
     $this->filters['equal']["B.email_id"] = $email_object['email_id'];
     $this->modelObj->noCheck = true;
     if ($this->filters) {
         $this->modelObj->setConditions($this->filters);
     }
     // 1 - subscriber request
     $query = 'SELECT A.user_id, A.firstname, A.lastname,A.status as ustatus,' . $this->statusemail . ' , A.email, B.* FROM `[wysija]user` as A';
     $query .= ' LEFT JOIN `[wysija]' . $this->tableQuery . '` as B on A.user_id=B.user_id';
     $queryFinal = $this->modelObj->makeWhere();
     // without filter we already have the total number of subscribers
     if ($this->filters) {
         $this->modelObj->countRows = $this->modelObj->count($queryCmmonStart . $queryFinal, 'users');
     } else {
         $this->modelObj->countRows = $counts['all'];
     }
     $orderby = '';
     /**
      * Until now, we have
      * - 3 possible values of $this->tableQuery (queue, email_user_url, email_user_stat), set by $this->setviewStatsfilter()
      * - 2 possible values of $_REQUEST['orderby']
      * => 3x2 = 6 cases
      */
     if (isset($_REQUEST['orderby'])) {
         switch ($this->tableQuery) {
             case 'email_user_url':
             case 'email_user_stat':
                 if (!is_string($_REQUEST['orderby']) or preg_match('|[^a-z0-9#_.-]|i', $_REQUEST['orderby']) !== 0) {
                     $_REQUEST['orderby'] = '';
                     break;
                 }
                 if (!in_array(strtoupper($_REQUEST['ordert']), array('DESC', 'ASC'))) {
                     $_REQUEST['ordert'] = 'DESC';
                 }
                 $orderby = ' ORDER BY ' . $_REQUEST['orderby'] . ' ' . $_REQUEST['ordert'];
                 break;
             case 'queue':
             default:
                 $orderby .= ' ORDER BY A.user_id DESC';
                 break;
         }
     } else {
         switch ($this->tableQuery) {
             case 'email_user_url':
                 $orderby = ' ORDER BY B.clicked_at DESC, B.number_clicked DESC';
                 // by default, sort by last clicked and biggest hit
                 break;
             case 'email_user_stat':
                 $orderby = ' ORDER BY B.opened_at DESC, B.status DESC';
                 // by default, sort by last open and its staus value
                 break;
             case 'queue':
             default:
                 $orderby = ' ORDER BY A.user_id DESC';
                 break;
         }
     }
     $this->data['tableQuery'] = $this->tableQuery;
     $this->modelObj->limitON = true;
     $subscribers = array();
     $hook_params = array('email_id' => $email_object['email_id'], 'url_id' => isset($_REQUEST['url_id']) && $_REQUEST['url_id'] ? $_REQUEST['url_id'] : false, 'subscribers' => &$subscribers, 'id' => $email_object['campaign_id']);
     $this->data['subscribers'] = $this->modelObj->getResults($query . $queryFinal . " GROUP BY A.user_id" . $orderby . $this->modelObj->setLimit(0, (int) $limit_pp));
     $this->modelObj->reset();
     // make the data object for the listing view
     $modelList = WYSIJA::get("list", "model");
     // 2 - list request
     $query = "SELECT A.list_id, A.name,A.is_enabled, count( B.user_id ) AS users FROM `[wysija]" . $modelList->table_name . "` as A";
     $query .= " LEFT JOIN `[wysija]user_list` as B on A.list_id = B.list_id";
     $query .= " GROUP BY A.list_id";
     $listsDB = $modelList->getResults($query);
     $lists = array();
     foreach ($listsDB as $listobj) {
         $lists[$listobj["list_id"]] = $listobj;
     }
     $listsDB = null;
     $user_ids = array();
     foreach ($this->data['subscribers'] as $subscriber) {
         $user_ids[] = $subscriber['user_id'];
     }
     // 3 - user_list request
     if ($user_ids) {
         $modeluList = WYSIJA::get("user_list", "model");
         $userlists = $modeluList->get(array("list_id", "user_id"), array("user_id" => $user_ids));
     }
     $this->data['lists'] = $lists;
     $this->data['counts'] = array_reverse($counts);
     // regrouping all the data in the same array
     foreach ($this->data['subscribers'] as $keysus => $subscriber) {
         // default key while we don't have the data
         //TODO add data for stats about emails opened clicked etc
         $this->data['subscribers'][$keysus]["emails"] = 0;
         $this->data['subscribers'][$keysus]["opened"] = 0;
         $this->data['subscribers'][$keysus]["clicked"] = 0;
         if ($userlists) {
             foreach ($userlists as $key => $userlist) {
                 if ($subscriber["user_id"] == $userlist["user_id"] && isset($lists[$userlist["list_id"]])) {
                     if (!isset($this->data['subscribers'][$keysus]["lists"])) {
                         $this->data['subscribers'][$keysus]["lists"] = $lists[$userlist["list_id"]]["name"];
                     } else {
                         $this->data['subscribers'][$keysus]["lists"] .= ", " . $lists[$userlist["list_id"]]["name"];
                     }
                 }
             }
         }
     }
     $this->data['email'] = $email_object;
     if (!$this->data['subscribers']) {
         $this->notice(__("Your request can't retrieve any subscribers. Change your filters!", WYSIJA));
     }
     // execute hooks
     $hook_params = array('email_id' => $_REQUEST['id'], 'email_object' => $email_object, 'url_id' => !empty($_REQUEST['url_id']) ? (int) $_REQUEST['url_id'] : null, 'id' => $email_object['campaign_id']);
     $this->data['hooks']['hook_newsletter_top'] = apply_filters('hook_newsletter_top', WYSIJA_module::execute_hook('hook_newsletter_top', $hook_params), $hook_params);
     $this->data['hooks']['hook_newsletter_bottom'] = apply_filters('hook_newsletter_bottom', WYSIJA_module::execute_hook('hook_newsletter_bottom', $hook_params), $hook_params);
 }
예제 #6
0
 function __construct()
 {
     parent::__construct();
     // wysija form shortcode
     add_shortcode('wysija_form', array($this, 'scan_form_shortcode'));
     // wysija total of subscribers shortcode
     add_shortcode('wysija_subscribers_count', array($this, 'scan_subscribers_count_shortcode'));
     // init shortcode [wysija_archive]
     require_once WYSIJA_CORE . 'controller.php';
     require_once WYSIJA_CORE . 'module' . DS . 'module.php';
     // @todo: move to autoloader
     $archive_std = WYSIJA_module::get_instance_by_name('archive_std');
     // implement hook "wysija_front_init()
     if (!empty($archive_std) && is_a($archive_std, 'WYSIJA_module')) {
         $archive_std->front_init();
     }
     /* We try to process the least possible code */
     if (isset($_REQUEST['wysija-page']) || isset($_REQUEST['wysija-launch'])) {
         if (defined('DOING_AJAX')) {
             add_action('wp_ajax_nopriv_wysija_ajax', array($this, 'ajax'));
         } else {
             $paramscontroller = $_REQUEST['controller'];
             //this is an exception on one server this params stats was not accepted
             if ($paramscontroller == 'stat') {
                 $paramscontroller = 'stats';
             }
             $this->controller = WYSIJA::get($paramscontroller, 'controller');
             if (isset($_REQUEST['action']) && method_exists($this->controller, $_REQUEST['action'])) {
                 add_action('init', array($this->controller, $_REQUEST['action']));
                 //$this->controller->$_REQUEST['action']();
             } else {
                 $this->error('Action does not exist.');
             }
             if (isset($_REQUEST['wysija-page'])) {
                 /* set the content filter to replace the shortcode */
                 add_filter('wp_title', array($this, 'meta_page_title'));
                 add_filter('the_title', array($this, 'scan_title'));
                 add_filter('the_content', array($this, 'scan_content'), 98);
                 if (isset($_REQUEST['message_success'])) {
                     add_filter('the_content', array($this, 'scan_content_NLform'), 99);
                 }
             }
         }
     } else {
         add_filter('the_content', array($this, 'scan_content_NLform'), 99);
         //if the comment form checkbox option is activated we add some hooks to process it
         $model_config = WYSIJA::get('config', 'model');
         if ($model_config->getValue('commentform')) {
             add_action('comment_form', array($this, 'comment_form_extend'));
             add_action('comment_post', array($this, 'comment_posted'), 60, 2);
         }
         // if the register form checkbox option is activated we add some hooks to process it
         if ($model_config->getValue('registerform')) {
             if (is_multisite()) {
                 add_action('signup_extra_fields', array($this, 'register_form_extend'));
                 // we need this condition otherwise we will send two confirmation emails when on ms with buddypress
                 if (!WYSIJA::is_plugin_active('buddypress/bp-loader.php')) {
                     add_filter('wpmu_validate_user_signup', array($this, 'registerms_posted'), 60, 3);
                 }
             } else {
                 add_action('register_form', array($this, 'register_form_extend'));
                 add_action('register_post', array($this, 'register_posted'), 60, 3);
             }
             // special case when buddypress is activated
             if (WYSIJA::is_plugin_active('buddypress/bp-loader.php')) {
                 add_action('bp_after_signup_profile_fields', array($this, 'register_form_bp_extend'));
                 add_action('bp_signup_validate', array($this, 'register_bp'), 60, 3);
                 // we can have just one confirmation email for the wp user and the wysija confirmation when bp and multisite are activated
                 if (is_multisite()) {
                     add_action('wpmu_activate_user', array($this, 'wpmu_activate_user'));
                 }
             }
         }
     }
 }
예제 #7
0
 public function __construct()
 {
     parent::__construct();
     $this->data['messages'] = $this->init_messages();
 }