merge with branch01

This commit is contained in:
ruben- 2014-08-08 20:22:25 +02:00
parent 9a13d72a52
commit 7def43f4cf
3 changed files with 96 additions and 51 deletions

View file

@ -404,12 +404,13 @@ class MainWPChildBranding
$content = nl2br(stripslashes($_POST['mainwp_branding_contact_message_content']));
if (!empty($_POST['mainwp_branding_contact_message_content']) && !empty($email))
{
global $current_user;
$mail = '<p>Support Email from: <a href="' . site_url() . '">' . site_url() . '</a></p>';
$mail .= '<p>Sent from WordPress page: ' . (!empty($_POST['mainwp_branding_send_from_page']) ? '<a href="' . $_POST['mainwp_branding_send_from_page'] . '">' . $_POST['mainwp_branding_send_from_page'] . '</a></p>' : "");
$mail .= '<p>Admin email: ' . get_option('admin_email') . ' </p>';
$mail .= '<p>Client Email: ' . $current_user->user_email . ' </p>';
$mail .= '<p>Support Text:</p>';
$mail .= '<p>' . $content . '</p>';
if (wp_mail($email, 'MainWP - Support Contact', $mail, array('From: "' . get_option('admin_email') . '" <' . get_option('admin_email') . '>', 'content-type: text/html'))) ;
if (wp_mail($email, 'MainWP - Support Contact', $mail, array('From: "' . $current_user->user_email . '" <' . $current_user->user_email . '>', 'content-type: text/html'))) ;
return true;
}
return false;

View file

@ -249,11 +249,11 @@ class MainWPHelper
if (!$seo_ext_activated) {
// if Wordpress SEO plugin is not activated do not save yoast post meta
if(strpos($meta_key, "_yoast_wpseo_") !== false)
if(strpos($meta_key, "_yoast_wpseo_") === false)
add_post_meta($new_post_id, $meta_key, $meta_value);
} else {
} else {
add_post_meta($new_post_id, $meta_key, $meta_value);
}
}
}
}
else if ($meta_key == '_sticky')

View file

@ -10,6 +10,8 @@ class MainWPKeywordLinks
protected $link_temp;
protected $link_count_temp;
protected $link_count_each_temp;
protected $link_exact_match = 1;
protected $link_case_sensitive = 1;
static function Instance() {
if (MainWPKeywordLinks::$instance == null) {
@ -141,12 +143,16 @@ class MainWPKeywordLinks
return true;
} else if ('' == get_option( 'permalink_structure')) {
include_once(ABSPATH . '/wp-admin/includes/misc.php');
$redirection_folder = $this->get_option('redirection_folder', 'goto');
if (empty($redirection_folder))
$redirection_folder = "goto";
//Create rewrite ruler
$rules = $this->mod_rewrite_rules(array($redirection_folder.'/' => 'index.php'));
$redirection_folder = $this->get_option('redirection_folder', '');
if (empty($redirection_folder)) {
$rules = $this->get_cloak_rules();
$rules = $this->mod_rewrite_rules($rules);
//error_log(print_r($rules, true));
//self::clear_htaccess();
} else {
//Create rewrite ruler
$rules = $this->mod_rewrite_rules(array($redirection_folder.'/' => 'index.php'));
}
$home_path = ABSPATH;
$htaccess_file = $home_path . '.htaccess';
if (function_exists('save_mod_rewrite_rules'))
@ -164,6 +170,15 @@ class MainWPKeywordLinks
}
function get_cloak_rules() {
$cloak_rules = array();
foreach($this->keyword_links as $link) {
if (!empty($link->cloak_path)) {
$cloak_rules[$link->cloak_path] = "index.php";
}
}
return $cloak_rules;
}
public function saveClickCallback()
{
@ -282,15 +297,14 @@ class MainWPKeywordLinks
// save specific link
if ($post) {
$specific_link = get_post_meta($post->ID, '_mainwp_kwl_specific_link', true);
$specific_link = unserialize($specific_link);
$specific_link = unserialize(get_post_meta($post->ID, '_mainwp_kwl_specific_link', true));
if (is_array($specific_link) && count($specific_link) > 0) {
$specific_link = current($specific_link);
$specific_link->post_id = $post->ID;
//update_post_meta($post->ID, '_mainwp_kwl_specific_link_save', array($specific_link->id => $specific_link));
update_post_meta($post->ID, '_mainwp_kwl_specific_link_id', $specific_link->id);
if ($this->set_link($specific_link->id, $specific_link))
delete_post_meta($post->ID, '_mainwp_kwl_specific_link'); // delete the source meta
update_post_meta($post->ID, '_mainwp_kwl_specific_link', "<saved>");
}
}
@ -300,8 +314,11 @@ class MainWPKeywordLinks
$links = $this->get_available_links();
// print_r($this->keyword_links);
// echo "======";
// print_r($links);
// if ($post->ID == 751) {
// //print_r($links);
// $custom = get_post_custom($post->ID);
// print_r($custom);
// }
if (empty($links))
return $content;
@ -318,11 +335,17 @@ class MainWPKeywordLinks
global $current_user;
$link->exact_match = isset($link->exact_match) ? $link->exact_match : 1; // to remove warning
$link->case_sensitive = isset($link->case_sensitive) ? $link->case_sensitive : 1; // to remove warning
$this->link_temp = $link;
$this->link_count_each_temp = $replace_max_keyword;
//$keywords = explode(',', $link->keyword);
$this->link_exact_match = $link->exact_match;
$this->link_case_sensitive = $link->case_sensitive;
$keywords = $this->explode_multi($link->keyword);
usort($keywords, create_function('$a,$b', 'return strlen($a)<strlen($b);'));
usort($keywords, create_function('$a,$b', 'return strlen($a)<strlen($b);'));
$replace_cs = $link->case_sensitive ? "s" : "is";
//print_r($keywords);
foreach ($keywords as $keyword) {
$keyword = trim($keyword);
if (empty($keyword))
@ -330,21 +353,23 @@ class MainWPKeywordLinks
if (in_array(array("keyword" => $keyword, "link" => $link->destination_url), (array) $not_allow_keywords)) {
continue;
}
$keyword = preg_replace('/([$^\/?+.*\]\[)(}{])/is', '\\\\\1', $keyword);
$keyword = preg_replace('/([$^\/?+.*\]\[)(}{])/is', '\\\\\1', $keyword);
if (strpos($content, $keyword) !== false) {
//Replace keyword in H tag
if (($link->case_sensitive && strpos($content, $keyword) !== false) || (!$link->case_sensitive && stripos($content, $keyword) !== false)) {
//Replace keyword in H tag
if ($this->get_option('replace_keyword_in_h_tag')) {
//$content = preg_replace_callback('/(<a[^>]*>.*?'.$keyword.'.*?<\/a>|<[^>]*'.$keyword.'[^>]*>|\{[^}]*'.$keyword.'[^}]*\}|\w*('.$keyword.')\w*)/is', array(&$this, 'keyword_mark'), $content);
$content = preg_replace_callback("/(<a[^>]*>[^<]*?" . $keyword . "[^<]*?<\/a>|<[^>]*" . $keyword . "[^>]*>|\{[^\}]*" . $keyword . "[^\}]*\}|\w*(" . $keyword . ")\w*)/is", array(&$this, 'keyword_mark'), $content);
$content = preg_replace_callback("/(<a[^>]*>[^<]*?" . $keyword . "[^<]*?<\/a>|<[^>]*" . $keyword . "[^>]*>|\{[^\}]*" . $keyword . "[^\}]*\}|\w*(" . $keyword . ")\w*)/" . $replace_cs, array(&$this, 'keyword_mark'), $content);
} else {
//$content = preg_replace_callback('/(<h[123456][^>]*>.*?'.$keyword.'.*?<\/h[123456]>|<a[^>]*>.*?'.$keyword.'.*?<\/a>|<[^>]*'.$keyword.'[^>]*>|\{[^}]*'.$keyword.'[^}]*\}|\w*('.$keyword.')\w*)/is', array(&$this, 'keyword_mark'), $content);
$content = preg_replace_callback("/(<h[123456][^>]*>[^<]*?" . $keyword . "[^<]*?<\/h[123456]>|<a[^>]*>[^<]*?" . $keyword . "[^<]*?<\/a>|<[^>]*" . $keyword . "[^>]*>|\{[^\}]*" . $keyword . "[^\}]*\}|\w*(" . $keyword . ")\w*)/is", array(&$this, 'keyword_mark'), $content);
$content = preg_replace_callback("/(<h[123456][^>]*>[^<]*?" . $keyword . "[^<]*?<\/h[123456]>|<a[^>]*>[^<]*?" . $keyword . "[^<]*?<\/a>|<[^>]*" . $keyword . "[^>]*>|\{[^\}]*" . $keyword . "[^\}]*\}|\w*(" . $keyword . ")\w*)/" . $replace_cs, array(&$this, 'keyword_mark'), $content);
}
}
}
}
$content = preg_replace_callback('/\{MAINWP_LINK +HREF="(.*?)" +TARGET="(.*?)" +REL="(.*?)" +LINK-ID="(.*?)" +CLASS="(.*?)" +TEXT="(.*?)" *\}/is', array(&$this, 'keyword_replace'), $content);
//$content = preg_replace_callback('/\{MAINWP_LINK +HREF="(.*?)" +TARGET="(.*?)" +REL="(.*?)" +LINK-ID="(.*?)" +CLASS="(.*?)" +TEXT="(.*?)" *\}/is', array(&$this, 'keyword_replace'), $content);
$content = preg_replace_callback('/\{MAINWP_LINK +HREF="(.*?)" +TARGET="(.*?)" +REL="(.*?)" +LINK-ID="(.*?)" +CLASS="(.*?)" +TEXT="(.*?)" +FULL_TEXT="(.*?)" *\}/is', array(&$this, 'keyword_replace'), $content);
return $content;
}
@ -355,9 +380,11 @@ class MainWPKeywordLinks
if ($this->link_count_temp === 0 || $this->link_count_each_temp === 0)
return $matches[1];
if ($matches[1] != $matches[2])
return $matches[1];
if ($this->link_exact_match) {
if ($matches[1] != $matches[2])
return $matches[1];
}
if ($this->link_count_temp != -1)
$this->link_count_temp--;
@ -392,22 +419,19 @@ class MainWPKeywordLinks
$class = $this->link_temp->link_class;
else
$class = $this->get_option('default_link_class');
$redirection_folder = $this->get_option('redirection_folder', 'goto');
if (empty($redirection_folder))
$redirection_folder = "goto";
$redirection_folder = $this->get_option('redirection_folder', '');
if (!empty($redirection_folder))
$redirection_folder = "/" . $redirection_folder;
// if (empty($redirection_folder))
// $redirection_folder = 'goto';
$regular_link = false;
if (empty($this->link_temp->cloak_path)) {
$regular_link = true;
$class .= " kwl-regular-link";
}
return '{MAINWP_LINK HREF="' . ( $this->link_temp->cloak_path ? $this->siteurl . $redirection_folder . '/' . $this->link_temp->cloak_path : $this->link_temp->destination_url) . '" TARGET="' . $target . '" REL="' . $rel . '" LINK-ID="' . (isset($this->link_temp->id) ? $this->link_temp->id : 0) . '" CLASS="' . $class . '" TEXT="' . $matches[1] . '"}';
//return '{MAINWP_LINK HREF="' . ( $this->link_temp->cloak_path ? $this->siteurl . $redirection_folder . '/' . $this->link_temp->cloak_path : $this->link_temp->destination_url) . '" TARGET="' . $target . '" REL="' . $rel . '" LINK-ID="' . (isset($this->link_temp->id) ? $this->link_temp->id : 0) . '" CLASS="' . $class . '" TEXT="' . $matches[1] . '"}';
return '{MAINWP_LINK HREF="' . ( $this->link_temp->cloak_path ? $this->siteurl . $redirection_folder . '/' . $this->link_temp->cloak_path : $this->link_temp->destination_url) . '" TARGET="' . $target . '" REL="' . $rel . '" LINK-ID="' . (isset($this->link_temp->id) ? $this->link_temp->id : 0) . '" CLASS="' . $class . '" TEXT="' . $matches[2] . '" FULL_TEXT="' . $matches[1] . '"}';
}
public function keyword_replace( $matches )
@ -418,6 +442,12 @@ class MainWPKeywordLinks
$a .= ( $matches[4] ) ? ' link-id="'.$matches[4].'"' : '';
$a .= ( $matches[5] ) ? ' class="'.$matches[5].'"' : '';
$a .= '>'.$matches[6].'</a>';
if (!$this->link_exact_match) {
if ($matches[7] !== $matches[6])
$a = str_replace($matches[6], $a, $matches[7]);
}
return $a;
}
@ -465,13 +495,13 @@ class MainWPKeywordLinks
$post_timestamp = strtotime($post->post_date);
foreach($this->keyword_links as $link) {
if ($link->type == 1 || $link->type == 3) {
if ($link->check_post_date) {
if ($link->type == 1 || $link->type == 3) { // type: 1,3 is normal link and specific link
if (isset($link->check_post_date) && $link->check_post_date) {
if ($post_timestamp < $link->check_post_date)
$links[] = $link;
} else
$links[] = $link;
} else if ($spec_link_id && $spec_link_id == $link->id){
} else if ($spec_link_id && $spec_link_id == $link->id){ // type 2 is specific link
if ($link->check_post_date) {
if ($post_timestamp < $link->check_post_date)
$links[] = $link;
@ -537,7 +567,7 @@ class MainWPKeywordLinks
if ($this->get_option('mainwp_kwl_do_not_link_site_blocked', false))
return;
$request = $_SERVER['REQUEST_URI'];
// Check if the request is correct
if (!preg_match('|^[a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\\x80-\\xff]+$|i', $request))
@ -547,19 +577,18 @@ class MainWPKeywordLinks
$sitepath = ( isset($siteurl['path']) ) ? $siteurl['path'] : '';
$filter_request = preg_replace('|^' . $sitepath . '/?|i', '', $request);
$filter_request = preg_replace('|/?$|i', '', $filter_request);
$redirection_folder = $this->get_option('redirection_folder', 'goto');
$redirection_folder = empty($redirection_folder) ? "goto" : $redirection_folder;
//user use redirection_folder (or not set it - we use by default)
if ($redirection_folder != '') {
$redirection_folder = $this->get_option('redirection_folder', '');
if (!empty($redirection_folder)) {
//if the request doesn't' containt the redirection folder we will return immediately
if (strpos($filter_request, $redirection_folder . '/') === false) {
return;
}
$filter_request = str_replace($redirection_folder . '/', '', $filter_request);
}
$filter_request = str_replace($redirection_folder . '/', '', $filter_request);
if (empty($filter_request))
return;
@ -577,8 +606,8 @@ class MainWPKeywordLinks
}
if (!empty($destination_url)){
if (get_option('mainwp_kwl_enable_statistic'))
$this->add_statistic($link_id, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_REFERER']);
if (get_option('mainwp_kwl_enable_statistic'))
$this->add_statistic($link_id, $_SERVER['REMOTE_ADDR'], $_SERVER['HTTP_REFERER']);
wp_redirect($destination_url);
die();
}
@ -704,7 +733,16 @@ class MainWPKeywordLinks
}
return $return;
}
function update_htaccess_for_change_cloak_links($link) {
if (empty($link))
return;
$redirection_folder = $this->get_option('redirection_folder', '');
if (empty($redirection_folder)) {
$this->update_htaccess(true);
}
}
public function delete_link() {
$result = array();
if (!empty($_POST['link_id'])) {
@ -720,6 +758,7 @@ class MainWPKeywordLinks
$current->check_post_date = time();
$this->set_link($current->id, $current);
}
$this->update_htaccess_for_change_cloak_links($current);
}
else
$return['status'] = 'SUCCESS';
@ -738,7 +777,8 @@ class MainWPKeywordLinks
$cleared = $this->set_link($clear_link->id, $clear_link);
} else if ($clear_link->type == 1) {
$cleared = $this->set_link($clear_link->id, ''); // delete link
}
}
$this->update_htaccess_for_change_cloak_links($clear_link);
}
else
$cleared = true;
@ -775,6 +815,8 @@ class MainWPKeywordLinks
$link->link_rel = $_POST['link_rel']; // number or text
$link->link_class = sanitize_text_field($_POST['link_class']);
$link->type = intval($_POST['type']);
$link->exact_match = intval($_POST['exact_match']);
$link->case_sensitive = intval($_POST['case_sensitive']);
if ($link->type == 2 || $link->type == 3) {
if (intval($_POST['post_id'])) {
@ -787,8 +829,10 @@ class MainWPKeywordLinks
}
}
if ($this->set_link($link->id, $link))
$return['status'] = 'SUCCESS';
if ($this->set_link($link->id, $link)) {
$return['status'] = 'SUCCESS';
$this->update_htaccess_for_change_cloak_links($link);
}
}
MainWPHelper::update_option('mainwpKeywordLinks', 1); // enable extension functions
return $return;