Changeset 1460432
- Timestamp:
- 07/25/2016 08:38:37 PM (10 years ago)
- Location:
- marketpowerwp/trunk
- Files:
-
- 5 edited
-
leplugin.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
src/LePlugin/Core/Utils.php (modified) (10 diffs)
-
src/Multisoft/MPP/Replication/ReplicationController.php (modified) (4 diffs)
-
src/Multisoft/MPP/Replication/ReplicationGateway.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
marketpowerwp/trunk/leplugin.php
r1456506 r1460432 4 4 * Plugin Name: Multisoft MarketPowerPRO Tools 5 5 * Description: Integration of Market Power Pro to wordpress 6 * Version: 2.1 6 * Version: 2.1.1 7 7 * Author: Rodine Mark Paul L. Villar, Dexter John Campos 8 8 * Author URI: mailto:dean.villar@gmail.com?subject= Multisoft MPP Tools 9 9 */ 10 define('MPP_DEBUG', true);10 define('MPP_DEBUG', false || WP_DEBUG); 11 11 12 12 if (!function_exists('is_plugin_active')) { -
marketpowerwp/trunk/readme.txt
r1456481 r1460432 1 === MarketPowerWP ===1 === MarketPowerWP === 2 2 Contributors: dean.villar@gmail.com 3 3 Tags: marketpowerpro, multisoft 4 4 Requires at least: 3.4+ 5 Stable tag: 2.1 5 Stable tag: 2.1.1 6 6 License: Commercial 7 7 … … 90 90 == Installation == 91 91 92 1. Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from Plugins page.92 1. Add 93 93 94 2. Login to your administrator page yourwordpressblog.com/wp-admin.94 2. Extract the zip file and just drop the contents in the wp-content/plugins/ directory of your WordPress installation and then activate the Plugin from Plugins page. 95 95 96 3. Go to MarketPowerPRO.96 3. Login to your administrator page yourwordpressblog.com/wp-admin. 97 97 98 4. Set your Base MPPE Web address, where your MarketPowerPRO system is located.98 4. Go to MarketPowerPRO. 99 99 100 5. Contact a MarketPowerPRO technical assistant to know your applicationID and set it to the applicationID field.100 5. Set your Base MPPE Web address, where your MarketPowerPRO system is located. 101 101 102 6. C heck "Enable auto-prefix replicationSiteName to URLs" option102 6. Contact a MarketPowerPRO technical assistant to know your applicationID and set it to the applicationID field. 103 103 104 7. Go to Settings > Permalinks then set your URL Structure to Post Name then click Save Changes 104 7. Check "Enable auto-prefix replicationSiteName to URLs" option 105 106 8. Go to Settings > Permalinks then set your URL Structure to Post Name then click Save Changes 105 107 106 108 ==Readme Generator== -
marketpowerwp/trunk/src/LePlugin/Core/Utils.php
r1445352 r1460432 7 7 /** 8 8 * @author Dexter John R. Campos <dexterjohncampos@gmail.com> 9 @copyright Les Coders9 * @copyright Les Coders 10 10 * Utility class that contains common methods that is unclassified as of the moment. 11 11 */ 12 class Utils { 12 class Utils 13 { 13 14 14 15 private static $encryption_key = 'kQ@DotLg!isQp#9&UHX7*&%AvHvG6&'; 15 16 16 public static function encrypt($value, $key = null) { 17 public static function encrypt($value, $key = null) 18 { 17 19 if ($key === null) { 18 20 $key = self::$encryption_key; 19 21 } 20 22 return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, md5($key), $value, MCRYPT_MODE_CBC, 21 md5(md5($key)))); 22 } 23 24 public static function decrypt($enc_value, $key = null) { 23 md5(md5($key)))); 24 } 25 26 public static function decrypt($enc_value, $key = null) 27 { 25 28 if ($key === null) { 26 29 $key = self::$encryption_key; 27 30 } 28 31 return rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_256, md5($key), base64_decode($enc_value), 29 MCRYPT_MODE_CBC, md5(md5($key))), "\0"); 30 } 31 32 public static function getMainDomain($host_only = false) { 32 MCRYPT_MODE_CBC, md5(md5($key))), "\0"); 33 } 34 35 public static function getMainDomain($host_only = false) 36 { 33 37 $url = parse_url(site_url()); 34 38 $domain = explode('.', $url['host']); … … 42 46 } 43 47 44 public static function getSubDomain($subdomain, $host_only = false) { 45 $url = parse_url(site_url()); 46 $domain = explode('.', $url['host']); 47 if (count($domain) < 2) { 48 return false; 49 } 50 if ($host_only) { 51 return $subdomain . '.' . $domain[count($domain) - 2] . '.' . $domain[count($domain) - 1]; 52 } 53 return $url['scheme'] . '://' . $subdomain . '.' . $domain[count($domain) - 2] . '.' . $domain[count($domain) - 1]; 54 } 55 56 public static function recurseCopy($src, $dst) { 48 public static function get_domain($domain, $debug = false) 49 { 50 $original = $domain = strtolower($domain); 51 if (filter_var($domain, FILTER_VALIDATE_IP)) { 52 return $domain; 53 } 54 $arr = array_slice(array_filter(explode('.', $domain, 4), function ($value) { 55 return $value !== 'www'; 56 }), 0); //rebuild array indexes 57 if (count($arr) > 2) { 58 $count = count($arr); 59 $_sub = explode('.', $count === 4 ? $arr[3] : $arr[2]); 60 if (count($_sub) === 2) // two level TLD 61 { 62 $removed = array_shift($arr); 63 if ($count === 4) // got a subdomain acting as a domain 64 { 65 $removed = array_shift($arr); 66 } 67 } elseif (count($_sub) === 1) // one level TLD 68 { 69 $removed = array_shift($arr); //remove the subdomain 70 if (strlen($_sub[0]) === 2 && $count === 3) // TLD domain must be 2 letters 71 { 72 array_unshift($arr, $removed); 73 } else { 74 // non country TLD according to IANA 75 $tlds = array( 76 'aero', 77 'arpa', 78 'asia', 79 'biz', 80 'cat', 81 'com', 82 'coop', 83 'edu', 84 'gov', 85 'info', 86 'jobs', 87 'mil', 88 'mobi', 89 'museum', 90 'name', 91 'net', 92 'org', 93 'post', 94 'pro', 95 'tel', 96 'travel', 97 'xxx', 98 ); 99 if (count($arr) > 2 && in_array($_sub[0], $tlds) !== false) //special TLD don't have a country 100 { 101 array_shift($arr); 102 } 103 } 104 } else // more than 3 levels, something is wrong 105 { 106 for ($i = count($_sub); $i > 1; $i--) { 107 $removed = array_shift($arr); 108 } 109 } 110 } elseif (count($arr) === 2) { 111 $arr0 = array_shift($arr); 112 if (strpos(join('.', $arr), '.') === false 113 && in_array($arr[0], array('localhost', 'test', 'invalid')) === false 114 ) // not a reserved domain 115 { 116 // seems invalid domain, restore it 117 array_unshift($arr, $arr0); 118 } 119 } 120 return join('.', $arr); 121 } 122 123 public static function str_replace_first($search, $replace, $subject) 124 { 125 $pos = strpos($subject, $search); 126 if ($pos !== false) { 127 return substr_replace($subject, $replace, $pos, strlen($search)); 128 } 129 return $subject; 130 } 131 132 public static function recurseCopy($src, $dst) 133 { 57 134 $dir = opendir($src); 58 135 @mkdir($dst); … … 69 146 } 70 147 71 public static function utc_date($format, $time = null) { 148 public static function utc_date($format, $time = null) 149 { 72 150 return self::tz_date('UTC', $format, $time); 73 151 } 74 152 75 public static function tz_date($tz, $format, $time = null) { 153 public static function tz_date($tz, $format, $time = null) 154 { 76 155 $old_tz = date_default_timezone_get(); 77 156 date_default_timezone_set($tz); … … 86 165 } 87 166 88 public static function utc_strtotime($str, $time = null) { 167 public static function utc_strtotime($str, $time = null) 168 { 89 169 return self::tz_strtotime('UTC', $str, $time); 90 170 } 91 171 92 public static function tz_strtotime($tz, $str, $time = null) { 172 public static function tz_strtotime($tz, $str, $time = null) 173 { 93 174 $old_tz = date_default_timezone_get(); 94 175 date_default_timezone_set($tz); … … 103 184 } 104 185 105 public static function parseCustomFields($custom) { 186 public static function parseCustomFields($custom) 187 { 106 188 $returnUrlParts = parse_url("?" . $custom); 107 189 $params = []; … … 110 192 } 111 193 112 public static function buildNotice($message, $type = 'updated', $inline = true) { 194 public static function buildNotice($message, $type = 'updated', $inline = true) 195 { 113 196 114 197 $notice = '<div class="' . $type . ' notice is-dismissible ' . ($inline ? 'inline' : '') . '">' 115 . '<p><strong>' . $message . '</strong></p>'116 . '</div>';198 . '<p><strong>' . $message . '</strong></p>' 199 . '</div>'; 117 200 return $notice; 118 201 } 119 202 120 public static function buildTimezoneDropdown($name, $selected = '', array $otherAttrs = []) { 203 public static function buildTimezoneDropdown($name, $selected = '', array $otherAttrs = []) 204 { 121 205 $otherAttrsFlat = ''; 122 206 if (count($otherAttrs) > 0) { 123 207 foreach ($otherAttrs as $key => $value) { 124 $otherAttrsFlat .= ' ' . $key . '="' . $value . '" ';208 $otherAttrsFlat .= ' ' . $key . '="' . $value . '" '; 125 209 } 126 210 } … … 136 220 $select .= '<option ' . $selectedAttr . ' value="' . $zone . '">' . $zone . '</option>'; 137 221 } 138 $select .= '</select>';222 $select .= '</select>'; 139 223 return $select; 140 224 } 141 225 142 public static function buildUtcTimezoneDropdown($name, $selected = '', array $otherAttrs = []) { 226 public static function buildUtcTimezoneDropdown($name, $selected = '', array $otherAttrs = []) 227 { 143 228 $otherAttrsFlat = ''; 144 229 if (count($otherAttrs) > 0) { 145 230 foreach ($otherAttrs as $key => $value) { 146 $otherAttrsFlat .= ' ' . $key . '="' . $value . '" ';231 $otherAttrsFlat .= ' ' . $key . '="' . $value . '" '; 147 232 } 148 233 } … … 160 245 } 161 246 $offset_name = 'UTC' . str_replace(['.25', '.5', '.75'], [':25', ':30', ':45'], 162 $offset_name);247 $offset_name); 163 248 164 249 if ($selected !== '' && $selected !== null && $selected == $offset) { … … 171 256 } 172 257 173 $select .= '</select>';258 $select .= '</select>'; 174 259 return $select; 175 260 } 176 261 177 public static function buildCountryDropDown($name, $selected = '', array $otherAttrs = []) { 262 public static function buildCountryDropDown($name, $selected = '', array $otherAttrs = []) 263 { 178 264 $otherAttrsFlat = ''; 179 265 if (count($otherAttrs) > 0) { 180 266 foreach ($otherAttrs as $key => $value) { 181 $otherAttrsFlat .= ' ' . $key . '="' . $value . '" ';267 $otherAttrsFlat .= ' ' . $key . '="' . $value . '" '; 182 268 } 183 269 } … … 190 276 $selectedAttr = ''; 191 277 } 192 $select .='<option value="' . $code . '" ' . $selectedAttr . '>' . $country . '</option>';193 } 194 $select .= '</select>';278 $select .= '<option value="' . $code . '" ' . $selectedAttr . '>' . $country . '</option>'; 279 } 280 $select .= '</select>'; 195 281 return $select; 196 282 } -
marketpowerwp/trunk/src/Multisoft/MPP/Replication/ReplicationController.php
r1445352 r1460432 12 12 use Multisoft\MPP\Settings\SettingsGateway; 13 13 use LePlugin\Core\View; 14 use LePlugin\Core\Utils; 14 15 use Katzgrau\KLogger\Logger; 15 16 use Psr\Log\LogLevel; … … 36 37 $this->add_action('admin_notices', 'mppe_replication_message'); 37 38 $this->add_shortcode('mppe', 'mppe_replication_info'); 39 $this->add_filter('option_siteurl', 'replication_site_url'); 40 $this->add_filter('option_home', 'replication_home_url'); 38 41 39 42 if (MPP_DEBUG) { … … 59 62 ); 60 63 61 /* @var $settingsGateway SettingsGateway */ 62 $settingsGateway = SettingsGateway::getInstance(); 63 $autoprefix = $settingsGateway->get(self::OPTION_AUTOPREFIX); 64 if ($autoprefix && !is_admin()) { 65 ob_start(); 66 add_action('shutdown', function () { 67 $final = ''; 68 $levels = ob_get_level(); 69 70 for ($i = 0; $i < $levels; $i++) { 71 $final .= ob_get_clean(); 72 } 73 echo apply_filters('final_output', $final); 74 }, 0); 75 $this->add_filter('final_output', 'mppe_autoprefix_content'); 76 } 64 ob_start(); 65 add_action('shutdown', function () { 66 $final = ''; 67 $levels = ob_get_level(); 68 69 for ($i = 0; $i < $levels; $i++) { 70 $final .= ob_get_clean(); 71 } 72 echo apply_filters('final_output', $final); 73 }, 0); 74 $this->add_filter('final_output', 'mppe_autoprefix_content'); 75 77 76 } 78 77 … … 173 172 } 174 173 174 public function replication_site_url($url) 175 { 176 if (is_admin()) { 177 return $url; 178 } 179 return 'http://' . $_SERVER['HTTP_HOST']; 180 } 181 182 public function replication_home_url($url) 183 { 184 if (is_admin()) { 185 return $url; 186 } 187 return 'http://' . $_SERVER['HTTP_HOST']; 188 } 189 175 190 public function mppe_autoprefix_content($output) 176 191 { 177 192 require_once $this->_plugin_dir . '/src/Multisoft/MPP/Replication/simple_html_dom.php'; 178 193 /* @var $replicationGateway ReplicationGateway */ 194 /* @var $settingsGateway SettingsGateway */ 179 195 $replicationGateway = $this->replicationGateway; 196 $settingsGateway = SettingsGateway::getInstance(); 197 $autoprefix = $settingsGateway->get(self::OPTION_AUTOPREFIX); 180 198 181 199 $xxx = $replicationGateway->get_replication_site_name(); 182 $host = $replicationGateway->parse_domain(site_url()); 200 $host = Utils::get_domain(site_url()); 201 $web_address_host = Utils::get_domain($settingsGateway->get(CoreController::OPTION_WEB_ADDRESS)); 183 202 $html = str_get_html($output); 184 foreach ($html->find('a') as $element) { 185 $element_host = $replicationGateway->parse_domain($element->href); 186 if ($element_host == $host) { 203 if ($html) { 204 foreach ($html->find('a') as $element) { 187 205 $href = parse_url($element->href); 188 if (substr($href['host'], 0, 1) !== $xxx) { 189 $new_href = $href['scheme'] . '://' . $xxx . '.' . str_replace($href['scheme'] . '://', '', $element->href); 190 $element->href = $new_href; 206 $element_host = Utils::get_domain($href['host']); 207 208 if ($element_host == $host || $element_host == $web_address_host) { 209 $url_splice = explode('.', $href['host']); 210 if ($autoprefix && $url_splice[0] !== $xxx) { 211 $new_href = $href['scheme'] . '://' . $xxx . '.' . 212 Utils::str_replace_first($href['scheme'] . '://', '', $element->href); 213 $element->href = $new_href; 214 } else if (!$autoprefix && $url_splice[0] === $xxx) { 215 $new_href = Utils::str_replace_first($xxx . '.', '', $element->href); 216 $element->href = $new_href; 217 } 191 218 } 192 219 } 193 220 } 194 221 return $html; 195 196 222 } 197 223 -
marketpowerwp/trunk/src/Multisoft/MPP/Replication/ReplicationGateway.php
r1456501 r1460432 9 9 10 10 use LePlugin\Core\GatewayInterface; 11 use LePlugin\Core\Utils; 11 12 use Multisoft\MPP\Core\CoreGateway; 12 13 use Multisoft\MPP\Settings\SettingsGateway; … … 39 40 public function get_replication_site_name() 40 41 { 41 $site_url = str_replace('https://', '', str_replace('http://', '', site_url())); 42 $xxx = str_replace('.', '', str_replace($site_url, '', $_SERVER["SERVER_NAME"])); 42 $domain = Utils::str_replace_first('https://', '', Utils::str_replace_first('http://', '', site_url())); 43 $site_url = Utils::get_domain($domain); 44 $xxx = str_replace('.', '', Utils::str_replace_first($site_url, '', $_SERVER["SERVER_NAME"])); 43 45 if (!strlen($xxx) || $xxx === 'localhost' || $xxx === 'www') { 44 46 $xxx = "admin"; 45 47 } 46 48 return $xxx; 47 }48 49 public function parse_domain($url)50 {51 $pieces = parse_url($url);52 $domain = isset($pieces['host']) ? $pieces['host'] : '';53 if (preg_match('/(?P<domain>[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', $domain, $regs)) {54 return $regs['domain'];55 }56 return false;57 }58 59 public function get_replication_info($force_new = false)60 {61 /* @var $settingsGateway SettingsGateway */62 /* @var $coreGateway CoreGateway */63 $settingsGateway = SettingsGateway::getInstance();64 $coreGateway = CoreGateway::getInstance();65 66 $mppe_domain = $settingsGateway->get(CoreController::OPTION_WEB_ADDRESS);67 $mppe_application_id = $settingsGateway->get(CoreController::OPTION_APPLICATION_ID);68 $mppe_web_path = $settingsGateway->get(CoreController::OPTION_WEB_PATH);69 $mppe_replication_path = $settingsGateway->get(ReplicationController::OPTION_REPLICATION_PATH);70 $mppe_replication_query_format = $settingsGateway->get(ReplicationController::OPTION_REPLICATION_PATH_QUERY_FORMAT);71 /* @var $logger \Katzgrau\KLogger\Logger */72 $logger = $this->logger;73 $logger->debug('Get Replication Info: ',74 array(75 'mppe_domain' => $mppe_domain,76 'mppe_application_id' => $mppe_application_id,77 'mppe_web_path' => $mppe_web_path,78 'mppe_replication_path' => $mppe_replication_path,79 'mppe_replication_query_format' => $mppe_replication_query_format80 )81 );82 83 $replication_info = array();84 85 if ($mppe_domain && $mppe_application_id && $mppe_web_path && $mppe_replication_path) {86 $subdomain = $this->get_replication_site_name();87 $replication_pulled = $coreGateway->isset_transient(self::TRANS_REPLICATION_KEY, $subdomain);88 if (!$replication_pulled || $force_new) {89 try {90 $q_str = sprintf($mppe_replication_query_format, $mppe_application_id, $subdomain);91 parse_str($q_str, $post_fields);92 $url = $mppe_domain . $mppe_web_path . $mppe_replication_path;93 $logger->info('Pulling replication info from: ' . $url);94 $logger->debug('Post fields: ', $post_fields);95 $data = wp_remote_post($url, array(96 'method' => 'POST',97 'timeout' => 45,98 'redirection' => 5,99 'httpversion' => '1.0',100 'blocking' => true,101 'headers' => array(),102 'body' => $post_fields,103 'cookies' => array()104 ));105 if (is_wp_error($data)) {106 $error_message = $data->get_error_message();107 $logger->critical($error_message);108 $replication_info = $data;109 } else {110 if ($data['response']['code'] == '200') {111 $logger->info("Successfully pulled replication info. Parsing replication data...");112 $logger->debug("Received data: " . PHP_EOL . $data['body']);113 $parser = xml_parser_create();114 xml_parse_into_struct($parser, $data['body'], $values, $index);115 xml_parser_free($parser);116 $parsed_replication_info = array();117 foreach ($values as $xml_child) {118 if ($xml_child["level"] == 2) {119 $parsed_replication_info[$xml_child["tag"]] =120 isset($xml_child["value"]) ? $xml_child["value"] : "";121 }122 }123 $logger->debug('Parsed replication info:', $parsed_replication_info);124 if ($parsed_replication_info["DISTRIBUTORID"] != "00000000-0000-0000-0000-000000000000") {125 $replication_info = $parsed_replication_info;126 $coreGateway->set_transient(self::TRANS_REPLICATION_KEY, $replication_info, $subdomain);127 $logger->info('Successfully set replication info in mpp transient.');128 } else {129 $logger->error('Retrieved DISTRIBUTORID is invalid . Replication info not set!');130 $replication_info = new \WP_Error('mpp_invalid_distributor_id',131 'Retrieved DISTRIBUTORID is invalid ');132 }133 } else {134 $logger->error("HTTP Error: ", $data['response']);135 $replication_info = new \WP_Error($data['response']['code'], $data['response']['message']);136 }137 }138 } catch (\Exception $e) {139 $logger->critical($e->getMessage());140 $logger->debug($e->getTraceAsString());141 $replication_info = new \WP_Error($e->getCode(), $e->getMessage());142 }143 } else {144 $replication_info = $coreGateway->get_transient(self::TRANS_REPLICATION_KEY, $subdomain);145 $logger->debug("Replication info already in transient.", array($subdomain, $replication_info));146 }147 } else {148 $logger->warning("MPP Web Address or Application ID or replication settings not set!");149 $replication_info = new \WP_Error("NOT_SET", "MPP Web Address or Application ID or replication settings not set.");150 }151 return $replication_info;152 49 } 153 50
Note: See TracChangeset
for help on using the changeset viewer.