Example #1
0
 function testPlugins()
 {
     $modelWysija = new WYSIJA_model();
     $possibleImport = array();
     foreach ($this->getPluginsInfo() as $tableName => $pluginInfos) {
         $result = $modelWysija->query("SHOW TABLES like '" . $modelWysija->wpprefix . $tableName . "';");
         if ($result) {
             $where = $this->generateWhere($pluginInfos['where']);
             $result = $modelWysija->query("get_row", "SELECT COUNT(`" . $pluginInfos['pk'] . "`) as total FROM `" . $modelWysija->wpprefix . $tableName . "` " . $where . " ;", ARRAY_A);
             $pluginInfosSave = array();
             if ((int) $result['total'] > 0) {
                 $pluginInfosSave['total'] = (int) $result['total'];
                 if (isset($pluginInfos['list'])) {
                     $resultlist = $modelWysija->query("SHOW TABLES like '" . $modelWysija->wpprefix . $pluginInfos['list']['list']['table'] . "';");
                     if ($resultlist) {
                         $where = "";
                         $queryLists = "SELECT COUNT(`" . $pluginInfos['list']['list']['pk'] . "`) as total FROM `" . $modelWysija->wpprefix . $pluginInfos['list']['list']['table'] . "` " . $where . " ;";
                         $resultlist = $modelWysija->query("get_row", $queryLists, ARRAY_A);
                         if ((int) $resultlist['total'] > 0) {
                             $pluginInfosSave['total_lists'] = (int) $resultlist['total'];
                         }
                     }
                 }
                 if (!isset($pluginInfosSave['total_lists'])) {
                     $pluginInfosSave['total_lists'] = 1;
                 }
                 $possibleImport[$tableName] = $pluginInfosSave;
             }
         }
     }
     if ($possibleImport) {
         $modelConfig =& WYSIJA::get("config", "model");
         $modelConfig->save(array("pluginsImportableEgg" => $possibleImport));
     }
 }
Example #2
0
 function removeProcess()
 {
     if (is_admin()) {
         $filename = dirname(__FILE__) . DS . 'uninstall.sql';
         $handle = fopen($filename, 'r');
         $query = fread($handle, filesize($filename));
         fclose($handle);
         $modelObj =& WYSIJA::get('user', 'model');
         $queries = str_replace('DROP TABLE `', 'DROP TABLE `[wysija]', $query);
         $queries = explode('-- QUERY ---', $queries);
         $modelWysija = new WYSIJA_model();
         global $wpdb;
         foreach ($queries as $query) {
             $modelWysija->query($query);
         }
         delete_option('wysija');
         WYSIJA::update_option('wysija_reinstall', 1);
         global $wp_roles;
         foreach ($wp_roles->roles as $rolek => $roled) {
             if ($rolek == 'administrator') {
                 continue;
             }
             $role = get_role($rolek);
             $arr = array('wysija_newsletters', 'wysija_subscribers', 'wysija_subscriwidget', 'wysija_config');
             foreach ($arr as $arrkey) {
                 $role->remove_cap($arrkey);
             }
         }
         return true;
     }
     return false;
 }
 /**
  * this function is run only once at install to test which plugins are possible to import
  * @global type $wpdb
  */
 function testPlugins()
 {
     $modelWysija = new WYSIJA_model();
     $possibleImport = array();
     foreach ($this->getPluginsInfo() as $tableName => $pluginInfos) {
         /*if the plugin's subscribers table exists*/
         $result = $modelWysija->query("SHOW TABLES like '" . $modelWysija->wpprefix . $tableName . "';");
         if ($result) {
             /*select total of users*/
             $where = $this->generateWhere($pluginInfos['where']);
             $result = $modelWysija->query("get_row", "SELECT COUNT(`" . $pluginInfos['pk'] . "`) as total FROM `" . $modelWysija->wpprefix . $tableName . "` " . $where . " ;", ARRAY_A);
             $pluginInfosSave = array();
             if ((int) $result['total'] > 0) {
                 /* there is a possible import to do */
                 $pluginInfosSave['total'] = (int) $result['total'];
                 /*if the plugin's lists table exists*/
                 if (isset($pluginInfos['list'])) {
                     $resultlist = $modelWysija->query("SHOW TABLES like '" . $modelWysija->wpprefix . $pluginInfos['list']['list']['table'] . "';");
                     if ($resultlist) {
                         /*select total of users*/
                         /*$where=$this->generateWhere($pluginInfos);*/
                         $where = "";
                         $queryLists = "SELECT COUNT(`" . $pluginInfos['list']['list']['pk'] . "`) as total FROM `" . $modelWysija->wpprefix . $pluginInfos['list']['list']['table'] . "` " . $where . " ;";
                         $resultlist = $modelWysija->query("get_row", $queryLists, ARRAY_A);
                         if ((int) $resultlist['total'] > 0) {
                             /* there is a possible import to do */
                             $pluginInfosSave['total_lists'] = (int) $resultlist['total'];
                         }
                     }
                 }
                 if (!isset($pluginInfosSave['total_lists'])) {
                     $pluginInfosSave['total_lists'] = 1;
                 }
                 $possibleImport[$tableName] = $pluginInfosSave;
             }
         }
     }
     /* if we found some plugins to import from we just save their details in the config */
     if ($possibleImport) {
         $modelConfig = WYSIJA::get("config", "model");
         $modelConfig->save(array("pluginsImportableEgg" => $possibleImport));
     }
 }
Example #4
0
 function removeProcess()
 {
     // Remove the wysija folder in uploads.
     $helper_file = WYSIJA::get('file', 'helper');
     $upload_dir = $helper_file->getUploadDir();
     $is_writable = is_writable($upload_dir);
     if ($is_writable) {
         $helper_file->rrmdir($upload_dir);
     } elseif ($upload_dir != false) {
         return false;
     }
     $file_name = WYSIJA_DIR . 'sql' . DS . 'uninstall.sql';
     $handle = fopen($file_name, 'r');
     $query = fread($handle, filesize($file_name));
     fclose($handle);
     $queries = str_replace('DROP TABLE `', 'DROP TABLE `[wysija]', $query);
     $queries = explode('-- QUERY ---', $queries);
     $modelWysija = new WYSIJA_model();
     global $wpdb;
     foreach ($queries as $query) {
         $modelWysija->query($query);
     }
     //wysija_last_php_cron_call
     foreach ($this->options_delete as $option_key) {
         delete_option($option_key);
     }
     WYSIJA::update_option('wysija_reinstall', 1);
     global $wp_roles;
     foreach ($wp_roles->roles as $rolek => $roled) {
         if ($rolek == 'administrator') {
             continue;
         }
         $role = get_role($rolek);
         //remove wysija's cap
         $arr = array('wysija_newsletters', 'wysija_subscribers', 'wysija_config');
         foreach ($arr as $arrkey) {
             $role->remove_cap($arrkey);
         }
     }
     return true;
 }
Example #5
0
 function createTables()
 {
     $haserrors = false;
     $filename = dirname(__FILE__) . DS . 'install.sql';
     $handle = fopen($filename, 'r');
     $query = fread($handle, filesize($filename));
     fclose($handle);
     $modelObj =& WYSIJA::get('user', 'model');
     $query = str_replace('CREATE TABLE IF NOT EXISTS `', 'CREATE TABLE IF NOT EXISTS `' . $modelObj->getPrefix(), $query);
     $queries = explode('-- QUERY ---', $query);
     global $wpdb;
     foreach ($queries as $qry) {
         $wpdb->query($qry);
         $error = mysql_error($wpdb->dbh);
         if ($error) {
             $this->notice(mysql_error());
             $haserrors = true;
         }
     }
     $arraytables = array('user_list', 'user', 'list', 'campaign', 'campaign_list', 'email', 'user_field', 'queue', 'user_history', 'email_user_stat', 'url', 'email_user_url', 'url_mail');
     $modelWysija = new WYSIJA_model();
     $missingtables = array();
     foreach ($arraytables as $tablename) {
         if (!$modelWysija->query("SHOW TABLES like '" . $modelWysija->getPrefix() . $tablename . "';")) {
             $missingtables[] = $modelWysija->getPrefix() . $tablename;
         }
     }
     if ($missingtables) {
         $this->error(sprintf(__('These tables could not be created on installation: %1$s', WYSIJA), implode(', ', $missingtables)), 1);
         $haserrors = true;
     }
     if ($haserrors) {
         return false;
     }
     return true;
 }
Example #6
0
 /**
  *
  * @global type $wpdb
  * @param type $time_now
  * @return type
  */
 private function _import_new_users_into_lists($time_now)
 {
     global $wpdb;
     $wpdb->rows_affected = 0;
     $model_wysija = new WYSIJA_model();
     $user_ids = $this->_get_imported_user_ids();
     // insert query per list
     $query = 'INSERT IGNORE INTO [wysija]user_list (`list_id` ,`user_id`,`sub_date`) VALUES ';
     foreach ($_REQUEST['wysija']['user_list']['list'] as $keyl => $list_id) {
         if (empty($list_id)) {
             continue;
         }
         // for each list pre selected go through that process
         foreach ($user_ids as $key => $user_data) {
             // inserting each user id to this list
             $query .= '(' . $list_id . ' , ' . $user_data['user_id'] . ' , ' . $time_now . ')';
             // if this is not the last row we put a comma for the next row
             if (count($user_ids) > $key + 1) {
                 $query .= ' , ';
             }
         }
         // if this is not the last row we put a comma for the next row
         if (count($_REQUEST['wysija']['user_list']['list']) > $keyl + 1) {
             $query .= ',';
         }
     }
     $result_query = $model_wysija->query($query);
     $this->_data_numbers['list_added'] += $wpdb->rows_affected;
     $this->_data_numbers['list_user_ids'] += count($user_ids);
     return $result_query;
 }
Example #7
0
 function _importRows($query, $csvArr, $count, $datatoinsert, $emailKey, &$dataNumbers)
 {
     $allEmails = array();
     $time = time();
     $linescount = count($csvArr);
     $nbfields = count($datatoinsert);
     foreach ($csvArr as $k => $line) {
         if (!(count($line) >= count($datatoinsert) - 1)) {
             unset($csvArr[$k]);
             $linescount--;
         }
     }
     $outof = 0;
     $j = 1;
     $helperUser =& WYSIJA::get('user', 'helper');
     global $wpdb;
     foreach ($csvArr as $kline => $line) {
         //dbg($csvArr,0);
         if (!isset($_POST['firstrowisdata']) && $j == 1 && $count == 0) {
             $j++;
             continue;
         }
         $i = 1;
         $values = '';
         if (isset($datatoinsert['status'])) {
             $line['status'] = 1;
         }
         foreach ($line as $kl => &$vl) {
             if (isset($datatoinsert[$kl])) {
                 if ($emailKey === $kl) {
                     $vl = trim($vl);
                     if ($helperUser->validEmail($vl)) {
                         $allEmails[] = $vl;
                         $outof++;
                     } else {
                         $dataNumbers['invalid'][] = $vl;
                         unset($csvArr[$kline]);
                         $linescount--;
                         continue 2;
                     }
                 }
                 $values .= "'" . mysql_real_escape_string($vl, $wpdb->dbh) . "'";
                 if ($nbfields > $i) {
                     $values .= ',';
                 } else {
                     $values .= ',' . $time;
                 }
                 $i++;
             }
         }
         $query .= " ({$values}) ";
         if ($linescount > $j) {
             $query .= ',';
         }
         $j++;
     }
     //replace query to import the subscribers
     $modelWysija = new WYSIJA_model();
     $resultqry = $modelWysija->query($query);
     //$outof=$linescount;
     global $wpdb;
     $linescount = $wpdb->rows_affected;
     $dataNumbers['inserted'] += $wpdb->rows_affected;
     $dataNumbers['outof'] += $outof;
     if ($resultqry === false) {
         $this->error(__('Error when inserting emails.', WYSIJA), true);
         return false;
     }
     //select query to get all of there ids
     $user_ids = $this->modelObj->get(array('user_id'), array('email' => $allEmails));
     $wpdb->rows_affected = 0;
     $modelUL =& WYSIJA::get('user_list', 'model');
     //insert query per list
     $query = 'INSERT IGNORE INTO [wysija]user_list (`list_id` ,`user_id`,`sub_date`) VALUES ';
     $helper_email =& WYSIJA::get('email', 'helper');
     $follow_ups_per_list = $helper_email->get_active_follow_ups(array('email_id', 'params'), true);
     if (!empty($follow_ups_per_list)) {
         //insert query per active followup
         $query_queue = 'INSERT IGNORE INTO [wysija]queue (`email_id` ,`user_id`,`send_at`) VALUES ';
     }
     $time_now = time();
     foreach ($_REQUEST['wysija']['user_list']['list'] as $keyl => $list_id) {
         //for each list pre selected go through that process
         foreach ($user_ids as $key => $userid) {
             //inserting each user id to this list
             $query .= "({$list_id}," . $userid['user_id'] . ', ' . $time_now . ')';
             //checking if this list has a list of follow ups
             if (isset($follow_ups_per_list[$list_id])) {
                 //for each follow up of that list we queu an email
                 foreach ($follow_ups_per_list[$list_id] as $key_queue => $follow_up) {
                     $query_queue .= '(' . $follow_up['email_id'] . ' ,' . $userid['user_id'] . ', ' . ($time_now + $follow_up['delay']) . ')';
                     //if this is not the last row we put a comma for the next row
                     if (count($follow_ups_per_list[$list_id]) > $key_queue + 1) {
                         $query_queue .= ',';
                     }
                 }
             }
             //if this is not the last row we put a comma for the next row
             if (count($user_ids) > $key + 1) {
                 $query .= ',';
                 $query_queue .= ',';
             }
         }
         //if this is not the last row we put a comma for the next row
         if (count($_REQUEST['wysija']['user_list']['list']) > $keyl + 1) {
             $query .= ',';
             $query_queue .= ',';
         }
     }
     $resultqry2 = $modelWysija->query($query);
     $dataNumbers['list_added'] += $wpdb->rows_affected;
     $dataNumbers['list_user_ids'] += count($user_ids);
     if (!empty($follow_ups_per_list)) {
         $resultqry3 = $modelWysija->query($query_queue);
         $dataNumbers['emails_queued'] += $wpdb->rows_affected;
     }
     if ($resultqry2 === false) {
         $this->error(__('Error when inserting list.', WYSIJA), true);
         return false;
     }
     if ($resultqry == 0) {
         return '0';
     }
     return $linescount;
 }
Example #8
0
 /**
  * find out what is the db version based on the existing columns of some tables
  */
 private function _find_db_version()
 {
     $model_wysija = new WYSIJA_model();
     // test against 2.0 and set it to 1.1 if true
     $test = $model_wysija->query('get_res', "SHOW COLUMNS FROM `[wysija]email` like 'modified_at';");
     if (empty($test)) {
         return '1.1';
     }
     // test against 2.4 and set it to 2.3.4 if true
     $test = $model_wysija->query('get_res', "SHOW COLUMNS FROM `[wysija]form`;");
     if (empty($test)) {
         return '2.3.4';
     }
     // test against 2.5.9.6 and set it to 2.5.5 if true
     $test = $model_wysija->query('get_res', "SHOW COLUMNS FROM `[wysija]user` like 'domain';");
     if (empty($test)) {
         return '2.5.5';
     }
     // test against 2.5.9.7 and set it to 2.5.9.6 if true
     $test = $model_wysija->query('get_res', "SHOW COLUMNS FROM `[wysija]user` like 'last_opened';");
     if (empty($test)) {
         return '2.5.9.6';
     }
     return WYSIJA::get_version();
 }
Example #9
0
 function createTables()
 {
     $filename = dirname(__FILE__) . DS . "install.sql";
     $handle = fopen($filename, "r");
     $query = fread($handle, filesize($filename));
     fclose($handle);
     $modelObj =& WYSIJA::get("user", "model");
     $query = str_replace("CREATE TABLE IF NOT EXISTS `", "CREATE TABLE IF NOT EXISTS `" . $modelObj->getPrefix(), $query);
     $queries = explode("-- QUERY ---", $query);
     $con = @mysql_connect(DB_HOST, DB_USER, DB_PASSWORD, true);
     $haserrors = false;
     if (!$con) {
         die('Could not connect: ' . mysql_error());
         $haserrors = true;
     } else {
         @mysql_select_db(DB_NAME, $con);
         foreach ($queries as $qry) {
             if (!mysql_query($qry, $con)) {
                 $this->notice(mysql_error());
                 $haserrors = true;
             }
         }
     }
     $arraytables = array("user_list", "user", "list", "campaign", "campaign_list", "email", "user_field", "queue", "user_history", "email_user_stat", "url", "email_user_url", "url_mail");
     $modelWysija = new WYSIJA_model();
     $missingtables = array();
     foreach ($arraytables as $tablename) {
         if (!$modelWysija->query("SHOW TABLES like '" . $modelWysija->getPrefix() . $tablename . "';")) {
             $missingtables[] = $modelWysija->getPrefix() . $tablename;
         }
     }
     mysql_close($con);
     if ($missingtables) {
         $this->error(sprintf(__('These tables could not be created on installation: %1$s', WYSIJA), implode(', ', $missingtables)), 1);
         $haserrors = true;
     }
     if ($haserrors) {
         return false;
     }
     return true;
 }
Example #10
0
 function _importRows($query, $csvArr, $count, $datatoinsert, $emailKey, &$dataNumbers)
 {
     $allEmails = array();
     $time = time();
     $linescount = count($csvArr);
     $nbfields = count($datatoinsert);
     foreach ($csvArr as $k => $line) {
         if (!(count($line) >= count($datatoinsert) - 1)) {
             unset($csvArr[$k]);
             $linescount--;
         }
     }
     $outof = 0;
     $j = 1;
     $helperUser =& WYSIJA::get("user", "helper");
     global $wpdb;
     foreach ($csvArr as $kline => $line) {
         //dbg($csvArr,0);
         if (!isset($_POST['firstrowisdata']) && $j == 1 && $count == 0) {
             $j++;
             continue;
         }
         $i = 1;
         $values = '';
         if (isset($datatoinsert['status'])) {
             $line['status'] = 1;
         }
         foreach ($line as $kl => &$vl) {
             if (isset($datatoinsert[$kl])) {
                 if ($emailKey === $kl) {
                     $vl = trim($vl);
                     if ($helperUser->validEmail($vl)) {
                         $allEmails[] = $vl;
                         $outof++;
                     } else {
                         $dataNumbers['invalid'][] = $vl;
                         unset($csvArr[$kline]);
                         $linescount--;
                         continue 2;
                     }
                 }
                 $values .= "'" . mysql_real_escape_string($vl, $wpdb->dbh) . "'";
                 if ($nbfields > $i) {
                     $values .= ",";
                 } else {
                     $values .= "," . $time;
                 }
                 $i++;
             }
         }
         $query .= " ({$values}) ";
         if ($linescount > $j) {
             $query .= ",";
         }
         $j++;
     }
     /*replace query to import the subscribers*/
     $modelWysija = new WYSIJA_model();
     $resultqry = $modelWysija->query($query);
     //$outof=$linescount;
     global $wpdb;
     $linescount = $wpdb->rows_affected;
     $dataNumbers['inserted'] += $wpdb->rows_affected;
     $dataNumbers['outof'] += $outof;
     if ($resultqry === false) {
         $this->error(__("Error when inserting emails.", WYSIJA), true);
         return false;
     }
     /* select query to get all of there ids */
     $user_ids = $this->modelObj->get(array('user_id'), array('email' => $allEmails));
     $wpdb->rows_affected = 0;
     $modelUL =& WYSIJA::get('user_list', 'model');
     $query = "INSERT IGNORE INTO [wysija]user_list (`list_id` ,`user_id`,`sub_date`) VALUES ";
     $timenow = time();
     foreach ($_REQUEST['wysija']['user_list']['list'] as $keyl => $listid) {
         foreach ($user_ids as $key => $userid) {
             $query .= "({$listid}," . $userid['user_id'] . ", " . $timenow . ")";
             if (count($user_ids) > $key + 1) {
                 $query .= ",";
             }
         }
         if (count($_REQUEST['wysija']['user_list']['list']) > $keyl + 1) {
             $query .= ",";
         }
     }
     $resultqry2 = $modelWysija->query($query);
     $dataNumbers['list_added'] += $wpdb->rows_affected;
     $dataNumbers['list_user_ids'] += count($user_ids);
     if ($resultqry2 === false) {
         $this->error(__('Error when inserting list.', WYSIJA), true);
         return false;
     }
     if ($resultqry == 0) {
         return "0";
     }
     return $linescount;
 }