1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350: 351: 352: 353: 354: 355: 356: 357: 358: 359: 360: 361: 362: 363: 364: 365: 366: 367: 368: 369: 370: 371: 372: 373: 374: 375: 376: 377: 378: 379: 380:
<?php
if (!function_exists('wpl_url_to_postid')) {
function wpl_url_to_postid($url) {
global $wp_rewrite;
$url = apply_filters('url_to_postid', $url);
$id = url_to_postid($url);
if (isset($id)&&$id>0){
return $id;
}
if ( preg_match('#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values) ) {
$id = absint($values[2]);
if ( $id ){
return $id;
}
}
$wordpress_url = get_bloginfo('url');
if (substr($wordpress_url, -1, -1)!='/') {
$wordpress_url = $wordpress_url."/";
}
if (str_replace('/','',$url)==str_replace('/','',$wordpress_url)) {
return get_option('page_on_front');
}
$rewrite = $wp_rewrite->wp_rewrite_rules();
if ( empty($rewrite) ){
return 0;
}
$url_split = explode('#', $url);
$url = $url_split[0];
$url_split = explode('?', $url);
$url = $url_split[0];
if ( false !== strpos(home_url(), '://www.') && false === strpos($url, '://www.') )
$url = str_replace('://', '://www.', $url);
if ( false === strpos(home_url(), '://www.') )
$url = str_replace('://www.', '://', $url);
if ( !$wp_rewrite->using_index_permalinks() )
$url = str_replace('index.php/', '', $url);
if ( false !== strpos($url, home_url()) ) {
$url = str_replace(home_url(), '', $url);
} else {
$home_path = parse_url(home_url());
$home_path = isset( $home_path['path'] ) ? $home_path['path'] : '' ;
$url = str_replace($home_path, '', $url);
}
$url = trim($url, '/');
$request = $url;
$request_match = $request;
foreach ( (array)$rewrite as $match => $query) {
if ( !empty($url) && ($url != $request) && (strpos($match, $url) === 0) ){
$request_match = $url . '/' . $request;
}
if ( preg_match("!^$match!", $request_match, $matches) ) {
$query = preg_replace("!^.+\?!", '', $query);
$query = addslashes(WP_MatchesMapRegex::apply($query, $matches));
global $wp;
parse_str($query, $query_vars);
$query = array();
foreach ( (array) $query_vars as $key => $value ) {
if ( in_array($key, $wp->public_query_vars) ){
$query[$key] = $value;
}
}
foreach ( $GLOBALS['wp_post_types'] as $post_type => $t )
if ( $t->query_var )
$post_type_query_vars[$t->query_var] = $post_type;
foreach ( $wp->public_query_vars as $wpvar ) {
if ( isset( $wp->extra_query_vars[$wpvar] ) ) {
$query[$wpvar] = $wp->extra_query_vars[$wpvar];
} elseif ( isset( $_POST[$wpvar] ) ){
$query[$wpvar] = sanitize_text_field($_POST[$wpvar]);
} elseif ( isset( $_GET[$wpvar] ) ){
$query[$wpvar] = sanitize_text_field($_GET[$wpvar]);
} elseif ( isset( $query_vars[$wpvar] ) ){
$query[$wpvar] = sanitize_text_field($query_vars[$wpvar]);
}
if ( !empty( $query[$wpvar] ) ) {
if ( ! is_array( $query[$wpvar] ) ) {
$query[$wpvar] = (string) $query[$wpvar];
} else {
foreach ( $query[$wpvar] as $vkey => $v ) {
if ( !is_object( $v ) ) {
$query[$wpvar][$vkey] = (string) $v;
}
}
}
if ( isset($post_type_query_vars[$wpvar] ) ) {
$query['post_type'] = $post_type_query_vars[$wpvar];
$query['name'] = $query[$wpvar];
}
}
}
$query = new WP_Query($query);
if ( !empty($query->posts) && $query->is_singular ) {
return $query->post->ID;
} else {
return 0;
}
}
}
return 0;
}
}
if (!function_exists('wp_leads_get_page_final_id')) {
function wp_leads_get_page_final_id(){
global $post;
if (!isset($post)) {
return;
}
$current_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$current_url = preg_replace('/\?.*/', '', $current_url);
$page_id = wpl_url_to_postid($current_url);
$site_url = get_option('siteurl');
$clean_current_url = rtrim($current_url,"/");
if($clean_current_url === $site_url){
$page_id = get_option('page_on_front');
}
if (is_category() || is_archive()) {
$cat = get_category_by_path(get_query_var('category_name'),false);
$page_id = "cat_" . $cat->cat_ID;
$post_type = "category";
}
if (is_tag()){
$page_id = "tag_" . get_query_var('tag_id');
}
if(is_home()) {
$page_id = get_option( 'page_for_posts' );
} elseif(is_front_page()){
$page_id = get_option('page_on_front');
}
if ($page_id === 0) {
$page_id = $post->ID;
}
return $page_id;
}
}
if (!function_exists('json_encode_fallback')) {
function json_encode_fallback($a=false) {
if (is_null($a)) {
return 'null';
}
if ($a === false) {
return 'false';
}
if ($a === true) {
return 'true';
}
if (is_scalar($a)) {
if (is_float($a)) {
return floatval(str_replace(",", ".", strval($a)));
}
if (is_string($a)) {
static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"'));
return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"';
} else {
return $a;
}
}
$isList = true;
for ($i = 0, reset($a); $i < count($a); $i++, next($a)) {
if (key($a) !== $i) {
$isList = false;
break;
}
}
$result = array();
if ($isList) {
foreach ($a as $v) {
$result[] = json_encode($v);
}
return '[' . join(',', $result) . ']';
} else {
foreach ($a as $k => $v){
$result[] = json_encode($k).':'.json_encode($v);
}
return '{' . join(',', $result) . '}';
}
}
}
if (!function_exists('wpleads_add_lead_to_list')) {
function wpleads_add_lead_to_list( $list_id, $lead_id ) {
wp_set_post_terms( $lead_id, intval($list_id), 'wplead_list_category', true);
do_action('post_add_lead_to_lead_list' , $lead_id , $list_id );
}
}
if (!function_exists('wpleads_get_lead_lists_as_array')) {
function wpleads_get_lead_lists_as_array() {
$array = array();
$args = array(
'hide_empty' => false,
);
$terms = get_terms('wplead_list_category', $args);
foreach ( $terms as $term ) {
$array[$term->term_id] = $term->name;
}
return $array;
}
}
if (!function_exists('inbound_Hex_2_RGB')) {
function inbound_Hex_2_RGB($hex) {
$hex = preg_replace("/#/", "", $hex);
$color = array();
if(strlen($hex) == 3) {
$color['r'] = hexdec(substr($hex, 0, 1) . $r);
$color['g'] = hexdec(substr($hex, 1, 1) . $g);
$color['b'] = hexdec(substr($hex, 2, 1) . $b);
}
else if(strlen($hex) == 6) {
$color['r'] = hexdec(substr($hex, 0, 2));
$color['g'] = hexdec(substr($hex, 2, 2));
$color['b'] = hexdec(substr($hex, 4, 2));
}
return $color;
}
}
if (!function_exists('inbound_color_scheme')) {
function inbound_color_scheme($hex_color, $format = 'hex' ){
if (strpos($hex_color,'#') !== false) {
$input = $hex_color;
} else {
$input = "#" . $hex_color;
}
$col = Array(
hexdec(substr($input,1,2)),
hexdec(substr($input,3,2)),
hexdec(substr($input,5,2))
);
$color_scheme_array =
array(
100 => array( $col[0]/4, $col[1]/4, $col[2]/4),
95 => array( $col[0]/3, $col[1]/3, $col[2]/3),
90 => array( $col[0]/2.7, $col[1]/2.7, $col[2]/2.7),
85 => array( $col[0]/2.5, $col[1]/2.5, $col[2]/2.5),
80 => array( $col[0]/2.2, $col[1]/2.2, $col[2]/2.2),
75 => array( $col[0]/2, $col[1]/2, $col[2]/2),
70 => array( $col[0]/1.7, $col[1]/1.7, $col[2]/1.7),
65 => array( $col[0]/1.5, $col[1]/1.5, $col[2]/1.5),
60 => array( $col[0]/1.3,$col[1]/1.3,$col[2]/1.3),
55 => array( $col[0]/1.1,$col[1]/1.1,$col[2]/1.1),
50 => array( $col[0],$col[1],$col[2]),
45 => array( 255-(255-$col[0])/1.1, 255-(255-$col[1])/1.1, 255-(255-$col[2])/1.1),
40 => array( 255-(255-$col[0])/1.3, 255-(255-$col[1])/1.3, 255-(255-$col[2])/1.3),
35 => array( 255-(255-$col[0])/1.5, 255-(255-$col[1])/1.5, 255-(255-$col[2])/1.5),
30 => array( 255-(255-$col[0])/1.7, 255-(255-$col[1])/1.7, 255-(255-$col[2])/1.7),
25 => array( 255-(255-$col[0])/2, 255-(255-$col[1])/2, 255-(255-$col[2])/2),
20 => array( 255-(255-$col[0])/2.2, 255-(255-$col[1])/2.2, 255-(255-$col[2])/2.2),
15 => array( 255-(255-$col[0])/3, 255-(255-$col[1])/2.7, 255-(255-$col[2])/3),
10 => array(255-(255-$col[0])/5, 255-(255-$col[1])/5, 255-(255-$col[2])/5),
5 => array(255-(255-$col[0])/10, 255-(255-$col[1])/10, 255-(255-$col[2])/10),
0 => array(255-(255-$col[0])/15, 255-(255-$col[1])/15, 255-(255-$col[2])/15)
);
($format === 'hex') ? $sign = "#" : $sign = '';
$return_scheme = array();
foreach ($color_scheme_array as $key => $val) {
$each_color_return = $sign.sprintf("%02X%02X%02X", $val[0], $val[1], $val[2]);
$return_scheme[$key] = $each_color_return;
}
if(isset($_GET['color_scheme'])) {
foreach ($return_scheme as $key => $hex_value) {
echo "<div style='background:$hex_value; display:block; width:100%;'>$key</div>";
}
}
return $return_scheme;
}
}
if (!function_exists('inbound_color')) {
function inbound_color($color_scheme_array, $value) {
foreach ($color_scheme_array as $key => $val) {
$closest[$key] = abs($key - $value);
}
asort($closest);
$return_hex_val = key($closest);
$color = $color_scheme_array[$return_hex_val];
return $color;
}
}
?>