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; }
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)); } }
function insert($subid, $action, $data = array(), $mailid = 0) { $current_user = WYSIJA::wp_get_userdata(); /*dbg($current_user,0); $current_user=wp_get_current_user();*/ if (!empty($current_user->ID)) { $data[] = 'EXECUTED_BY::' . $current_user->ID . ' ( ' . $current_user->user_login . ' )'; } $history = null; $history['user_id'] = intval($subid); $history['type'] = strip_tags($action); $history['details'] = implode("\n", $data); $history['executed_at'] = time(); $history['email_id'] = $mailid; $userHelper =& WYSIJA::get("user", "helper"); $history['executed_by'] = $userHelper->getIP(); if (!empty($_SERVER)) { $source = array(); $vars = array('HTTP_REFERER', 'HTTP_USER_AGENT', 'HTTP_HOST', 'SERVER_ADDR', 'REMOTE_ADDR', 'REQUEST_URI', 'QUERY_STRING'); foreach ($vars as $oneVar) { if (!empty($_SERVER[$oneVar])) { $source[] = $oneVar . '::' . strip_tags($_SERVER[$oneVar]); } } $history['source'] = implode("\n", $source); } return parent::insert($history); }
function __construct() { $this->columns['name']['label'] = __('Name', WYSIJA); $this->columns['description']['label'] = __('Description', WYSIJA); $this->columns['is_enabled']['label'] = __('Enabled', WYSIJA); $this->columns['ordering']['label'] = __('Ordering', WYSIJA); parent::__construct(); }
/** * 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)); } }
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; }
function __construct() { $this->defaults = array('email' => __('Email', WYSIJA), 'firstname' => __('First name', WYSIJA), 'lastname' => __('Last name', WYSIJA), 'ip' => __('IP address', WYSIJA), 'status' => __('Status', WYSIJA), 'created_at' => __('Subscription date', WYSIJA)); parent::__construct(); }
/** * * @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; }
function __construct() { parent::__construct(); $this->table_prefix = ''; }
/** * special get overriding the model class in order to load the params of the email * @param array $columns * @param array $conditions * @return type */ function get($columns = array(), $conditions = array()) { $results = parent::get($columns, $conditions); if (is_array($results) && !isset($results['params'])) { foreach ($results as &$result) { $this->getParams($result); } } else { $this->getParams($results); } return $results; }
function create_post_type() { //$modelC=&WYSIJA::get('config','model'); //$rewritewysijap=array("slug"=>"wysijap"); //by default there is url rewriteing on wysijap custom post, though in one client case I had to deactivate it. //as this is rare we just need to set this setting to activate it //if($modelC->getValue('no_rewrite_wysijap'))$rewritewysijap=false; //by default let's deactivate the url rewriting of the wysijap confirmation page because it is breaking in some case. $rewritewysijap = false; register_post_type('wysijap', array('labels' => array('name' => __('Wysija page'), 'singular_name' => __('Wysija page')), 'public' => true, 'has_archive' => false, 'show_ui' => false, 'show_in_menu' => false, 'rewrite' => $rewritewysijap, 'show_in_nav_menus' => false, 'can_export' => false, 'publicly_queryable' => true, 'exclude_from_search' => true)); if (!get_option('wysija_post_type_updated')) { $modelPosts = new WYSIJA_model(); $modelPosts->tableWP = true; $modelPosts->table_prefix = ''; $modelPosts->table_name = 'posts'; $modelPosts->noCheck = true; $modelPosts->pk = 'ID'; if ($modelPosts->exists(array('post_type' => 'wysijapage'))) { $modelPosts->update(array('post_type' => 'wysijap'), array('post_type' => 'wysijapage')); flush_rewrite_rules(false); } WYSIJA::update_option('wysija_post_type_updated', time()); } if (!get_option('wysija_post_type_created')) { flush_rewrite_rules(false); WYSIJA::update_option('wysija_post_type_created', time()); } /* $rewritewysija=array('slug'=>'wysija'); register_post_type( 'wysija', array( 'labels' => array( 'name' => 'Wysija Archives', 'singular_name' => 'Wysija archives' ), 'public' => true, 'has_archive' => false, 'show_ui' =>false, 'show_in_menu' =>false, 'rewrite' => $rewritewysija, 'show_in_nav_menus'=>false, 'can_export'=>false, 'publicly_queryable'=>true, 'exclude_from_search'=>true, ) ); if(!get_option('wysija_post_type2_created')) { flush_rewrite_rules( false ); WYSIJA::update_option('wysija_post_type2_created',time()); }*/ }
/** * custom post type for wysija is call wysijap as in wysija's post */ public static function create_post_type() { //by default there is url rewriteing on wysijap custom post, though in one client case I had to deactivate it. //as this is rare we just need to set this setting to activate it //by default let's deactivate the url rewriting of the wysijap confirmation page because it is breaking in some case. $show_interface = false; if (defined('WYSIJA_DBG') && WYSIJA_DBG > 1) { $show_interface = true; } register_post_type('wysijap', array('labels' => array('name' => __('Wysija page'), 'singular_name' => __('Wysija page')), 'public' => true, 'has_archive' => false, 'show_ui' => $show_interface, 'show_in_menu' => $show_interface, 'rewrite' => false, 'show_in_nav_menus' => false, 'can_export' => false, 'publicly_queryable' => true, 'exclude_from_search' => true)); if (!get_option('wysija_post_type_updated')) { $modelPosts = new WYSIJA_model(); $modelPosts->tableWP = true; $modelPosts->table_prefix = ''; $modelPosts->table_name = 'posts'; $modelPosts->noCheck = true; $modelPosts->pk = 'ID'; if ($modelPosts->exists(array('post_type' => 'wysijapage'))) { $modelPosts->update(array('post_type' => 'wysijap'), array('post_type' => 'wysijapage')); flush_rewrite_rules(false); } WYSIJA::update_option('wysija_post_type_updated', time()); } if (!get_option('wysija_post_type_created')) { flush_rewrite_rules(false); WYSIJA::update_option('wysija_post_type_created', time()); } }
function __construct() { $this->columns['status']['label'] = __('Status', WYSIJA); $this->columns['created_at']['label'] = __('Created on', WYSIJA); parent::__construct(); }
public function __construct() { parent::WYSIJA_model(); $this->clean_up_out_of_date_tables(); }
/** * 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(); }
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; }
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; }
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; }
function __construct() { parent::__construct(); }
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; }