/** * Running installation queries and initializing WPL * @author Howard <*****@*****.**> * @return void */ public function activate_wpl() { if (wpl_folder::exists(WPL_ABSPATH . 'assets' . DS . 'install' . DS . 'files')) { /** copy files **/ $res = wpl_folder::copy(WPL_ABSPATH . 'assets' . DS . 'install' . DS . 'files', ABSPATH, '', true); /** delete files **/ wpl_folder::delete(WPL_ABSPATH . 'assets' . DS . 'install' . DS . 'files'); } /** run queries **/ $query_file = WPL_ABSPATH . 'assets' . DS . 'install' . DS . 'queries.sql'; if (wpl_file::exists($query_file)) { $queries = wpl_file::read($query_file); $queries = str_replace(";\r\n", "-=++=-", $queries); $queries = str_replace(";\r", "-=++=-", $queries); $queries = str_replace(";\n", "-=++=-", $queries); $sqls = explode("-=++=-", $queries); if (function_exists('is_multisite') and is_multisite() and wpl_global::check_addon('multisite')) { $original_blog_id = wpl_global::get_current_blog_id(); // Get all blogs $blogs = wpl_db::select("SELECT `blog_id` FROM `#__blogs`", 'loadColumn'); foreach ($blogs as $blog) { if (!isset($blog->blog_id)) { continue; } switch_to_blog($blog->blog_id); foreach ($sqls as $sql) { try { wpl_db::q($sql); } catch (Exception $e) { } } } /** delete query file **/ wpl_file::delete($query_file); switch_to_blog($original_blog_id); } else { foreach ($sqls as $sql) { try { wpl_db::q($sql); } catch (Exception $e) { } } /** delete query file **/ wpl_file::delete($query_file); } } /** run script **/ $script_file = WPL_ABSPATH . 'assets' . DS . 'install' . DS . 'script.php'; if (wpl_file::exists($script_file)) { include $script_file; /** delete script file **/ wpl_file::delete($script_file); } if (function_exists('is_multisite') and is_multisite() and wpl_global::check_addon('multisite')) { $original_blog_id = wpl_global::get_current_blog_id(); // Get all blogs $blogs = wpl_db::select("SELECT `blog_id` FROM `#__blogs`", 'loadColumn'); foreach ($blogs as $blog) { if (!isset($blog->blog_id)) { continue; } switch_to_blog($blog->blog_id); /** create propertylisting page **/ $pages = array('Properties' => '[WPL]', 'For Sale' => '[WPL sf_select_listing="9"]', 'For Rent' => '[WPL sf_select_listing="10"]', 'Vacation Rental' => '[WPL sf_select_listing="12"]'); foreach ($pages as $title => $content) { if (wpl_db::select("SELECT COUNT(post_content) FROM `#__posts` WHERE `post_content` LIKE '%{$content}%' AND `post_status` IN ('publish', 'private')", 'loadResult') != 0) { continue; } $post = array('post_title' => $title, 'post_content' => $content, 'post_type' => 'page', 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => 1); $post_id = wp_insert_post($post); if ($content == '[WPL]') { _wpl_import('libraries.settings'); wpl_settings::save_setting('main_permalink', $post_id); } } /** Add admin user to WPL **/ wpl_users::add_user_to_wpl(1); } switch_to_blog($original_blog_id); } else { /** create propertylisting page **/ $pages = array('Properties' => '[WPL]', 'For Sale' => '[WPL sf_select_listing="9"]', 'For Rent' => '[WPL sf_select_listing="10"]', 'Vacation Rental' => '[WPL sf_select_listing="12"]'); foreach ($pages as $title => $content) { if (wpl_db::select("SELECT COUNT(post_content) FROM `#__posts` WHERE `post_content` LIKE '%{$content}%' AND `post_status` IN ('publish', 'private')", 'loadResult') != 0) { continue; } $post = array('post_title' => $title, 'post_content' => $content, 'post_type' => 'page', 'post_status' => 'publish', 'comment_status' => 'closed', 'ping_status' => 'closed', 'post_author' => 1); $post_id = wp_insert_post($post); if ($content == '[WPL]') { _wpl_import('libraries.settings'); wpl_settings::save_setting('main_permalink', $post_id); } } /** Add admin user to WPL **/ wpl_users::add_user_to_wpl(1); } /** upgrade WPL **/ self::upgrade_wpl(); }
/** * Checks Realtyna billing credentials * @author Howard <*****@*****.**> * @static * @return array */ public static function check_realtyna_credentials() { /** import settings library **/ _wpl_import('libraries.settings'); $current_url = wpl_global::get_full_url(); $domain = wpl_global::domain($current_url); $settings = wpl_global::get_settings(); $phpver = phpversion(); $wplversion = wpl_global::wpl_version(); $wpversion = wpl_global::wp_version(); $username = $settings['realtyna_username']; $password = $settings['realtyna_password']; $POST = array('domain' => $domain, 'wpversion' => $wpversion, 'wplversion' => $wplversion, 'phpver' => $phpver, 'username' => urlencode($username), 'password' => urlencode($password), 'command' => 'check_credentials', 'format' => 'json'); $io_handler = 'http://billing.realtyna.com/io/io.php'; $result = wpl_global::get_web_page($io_handler, $POST); $answer = json_decode($result, true); /** saving status **/ $status = isset($answer['status']) ? $answer['status'] : 0; wpl_settings::save_setting('realtyna_verified', $status, 1); $message = $status ? __('Credentials verified.', WPL_TEXTDOMAIN) : __('Invalid credentials!', WPL_TEXTDOMAIN); $success = 1; return array('success' => $success, 'message' => $message, 'status' => $status); }
private function save_realtyna_credentials() { /** import settings library **/ _wpl_import('libraries.settings'); $username = wpl_request::getVar('username'); $password = wpl_request::getVar('password'); wpl_settings::save_setting('realtyna_username', $username, 1); wpl_settings::save_setting('realtyna_password', $password, 1); $response = wpl_global::check_realtyna_credentials(); $this->response($response); }
private function uploader() { $settings_key = wpl_request::getVar('settings_key', ''); $file = wpl_request::getVar($settings_key, NULL, 'FILES'); $filename = wpl_global::normalize_string($file['name']); $ext_array = array('jpg', 'png', 'gif', 'jpeg'); $error = ''; $message = ''; if (!empty($file['error']) or (empty($file['tmp_name']) or $file['tmp_name'] == 'none')) { $error = __('An error ocurred uploading your file.', WPL_TEXTDOMAIN); } else { // check the extention $extention = strtolower(wpl_file::getExt($file['name'])); if (!in_array($extention, $ext_array)) { $error = __('File extension should be jpg, png or gif.', WPL_TEXTDOMAIN); } if ($error == '') { $dest = WPL_ABSPATH . 'assets' . DS . 'img' . DS . 'system' . DS . $filename; wpl_file::upload($file['tmp_name'], $dest); wpl_settings::save_setting($settings_key, $filename); } } $response = array('error' => $error, 'message' => $message); echo json_encode($response); exit; }
private function save_languages() { $raws = wpl_request::getVar('wpllangs', array()); $langs = array(); $lang_options = array(); foreach ($raws as $key => $raw) { if (!trim($raw['full_code'])) { continue; } $langs[$key] = $raw['full_code']; $lang_options[$key] = $raw; } wpl_settings::save_setting('lang_options', json_encode($lang_options)); wpl_addon_pro::save_languages($langs); $res = 1; $message = $res ? __('Saved.', WPL_TEXTDOMAIN) : __('Error Occured.', WPL_TEXTDOMAIN); $data = NULL; $response = array('success' => $res, 'message' => $message, 'data' => $data); echo json_encode($response); exit; }