Plugin Directory

Changeset 1424915


Ignore:
Timestamp:
05/26/2016 06:11:56 PM (10 years ago)
Author:
TheGP
Message:

3.1.4 work on page new version

Location:
jumpout/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • jumpout/trunk/class.php

    r1408951 r1424915  
    3333    private
    3434        $settings, $settings_default, $jo_url, $popupfiles_domain,
    35         $version = '3.1.3';
     35        $version = '3.1.4';
    3636
    3737    function JumpOut()
     
    274274        if (isset($settings['list']) && 0 != count($settings['list'])) {
    275275            foreach ($settings['list'] as $key => $item) if (in_array($item['id'], $settings['activated'])) {
    276                
    277                 $display_code = FALSE;
    278276
    279277                if (!is_array($item['work_on_page'])) {
     
    286284
    287285                // если есть хотя бы один "работать на всех страницах"
    288                 if (FALSE !== array_search('', $item['work_on_page']))
     286                if (FALSE !== array_search('', $item['work_on_page'])) {
    289287                    $display_code = TRUE;
    290 
    291                 foreach ($item['work_on_page'] as $work_on_page) if (FALSE === $display_code) {
    292                     if ('' == trim($work_on_page) || 0 === strpos($REQUEST_URI, $work_on_page)) {
     288                } else {
     289
     290                    $restricted_rules_exists = FALSE;
     291
     292                    foreach ($item['work_on_page'] as $work_on_page) {
     293
     294                        $res = $this->pageMatchUrl($REQUEST_URI, $this->prepageWorkOnPageRule($work_on_page));
     295
     296                        if ($res[0] && !$res[1]) {
     297                            /* if its not an exception rule */
     298                            $work_allowed = TRUE;
     299                        } else if ($res[0] && $res[1]) {
     300                            /* if even one !restricted rule has met - turn off script */
     301                            $restricted_rules_applied = TRUE;
     302                        }
     303
     304                        if ($res[1]) {
     305                            $restricted_rules_exists = TRUE;
     306                        }
     307
     308                        //if ('~/testtest[0-9]?/' == $work_on_page)
     309                        //$code .= $REQUEST_URI . ':' . $work_on_page . ':' . $this->prepageWorkOnPageRule($work_on_page);
     310                    }
     311
     312
     313                    /* if no allowing rules and no restricted rules has met(BUT restricted rules exists) - allowing anyway */
     314                    if (!isset($work_allowed) && $restricted_rules_exists && !$restricted_rules_applied) {
     315                        $work_allowed = TRUE;
     316                        $restricted_rules_applied = FALSE;
     317                    }
     318
     319                    if (!$work_allowed || $restricted_rules_applied) {
     320                        $display_code = FALSE;
     321                    } else {
    293322                        $display_code = TRUE;
    294323                    }
    295                 }
     324
     325                }
     326
    296327
    297328                if ($display_code) {
     
    325356        return $code;
    326357    }
     358
     359    // the same function in the wp plugin and in jo model
     360    private function prepageWorkOnPageRule($page) {
     361        $rules = array('!', '~');
     362
     363        // remove ?
     364        if (FALSE !== strpos($page, '?')) {
     365            $page = strstr($page, '?', TRUE);
     366        }
     367        // remove slash from the end (if * at the end to check / before it)
     368        $indent = ('*' == substr($page, -1)) ? -1 : 0;
     369        $clean_url = $page;
     370        foreach ($rules as $rule) {
     371            if (in_array($clean_url[0], $rules)) {
     372                $clean_url = substr($clean_url, 1);
     373            }
     374        }
     375        if ('/' != $clean_url && '/' == substr($page, (-1 + $indent), 1)) {
     376            $page = substr($page, 0, (-1 + $indent));
     377            if (-1 == $indent) $page .= '*';
     378        }
     379        // if exception and then regex - flip sides !~ => ~!
     380        $page = str_replace('!~', '~!', $page);
     381        // if not regex(starts with ~) and has * - replace on regex (add ~ and * => .*)
     382
     383        if ('~' != substr($page, 0, 1) && FALSE !== strpos($page, '*')) {
     384            $page = '~' . str_replace('*', '.*', $page);
     385        }
     386        // if regex - add ^ and $ and replace / => \/
     387        if ('~' == substr($page, 0, 1)) {
     388            $page = str_replace('/', '\/', $page) . '$';
     389            $indent = 1; // ~
     390            if (FALSE !== strpos(substr($page, 0, 4), '!')) {
     391                $indent++; // !
     392            }
     393            $page = substr_replace($page, '^', $indent, 0);
     394        }
     395
     396        return $page;
     397    }
     398
     399
     400
    327401
    328402    private function generateCode($id, $uid) {
     
    441515                    }
    442516
    443                     ob_end_clean();
     517                    //ob_end_clean();
    444518                    //wp_send_json($data); // Since: 3.5.0
    445519
     
    619693        return $data;
    620694    }
     695
     696
     697    private function pageMatchUrl($current_url, $work_on_page) {
     698
     699
     700        $regex = FALSE;
     701        $exception = FALSE;
     702
     703        $work_on_page = mb_strtolower($work_on_page, 'UTF-8');
     704
     705        // checking for regex
     706        if (0 === strpos($work_on_page, '~')) {
     707            $regex = TRUE;
     708            $work_on_page = substr($work_on_page, 1);
     709        }
     710        // checking for exception
     711        if (0 === strpos($work_on_page, '!')) {
     712            $exception = TRUE;
     713            $work_on_page = substr($work_on_page, 1);
     714        }
     715
     716        /* cutting the last slash */
     717        if ('/' != $current_url)
     718            $current_url = ('/' == substr($current_url, -1)) ? substr($current_url, 0, -1) : $current_url;
     719
     720        if ($regex) {
     721            $res = $this->wopRegex($current_url, $work_on_page);
     722        } else {
     723            $res = ($work_on_page == $current_url);
     724        }
     725
     726        // if exception - returning mirrored results
     727        return ($exception) ? array($res, TRUE) : array($res, FALSE);
     728    }
     729
     730
     731
     732    private function wopRegex($current_url, $work_on_page) {
     733        //console.log('RegExp', work_on_page, 'current_url', current_url);
     734        preg_match('/' . $work_on_page . '/i', $current_url, $matches);
     735
     736        if (0 != count($matches)) {
     737            return TRUE;
     738        } else {
     739            return FALSE;
     740        }
     741    }
    621742}
    622 
    623 
    624 
    625 
    626 
    627 
    628743
    629744
  • jumpout/trunk/launch.php

    r1408951 r1424915  
    44Plugin URI: http://makedreamprofits.ru/jo/
    55Description: Устанавливайте JumpOut попапы в один клик с нашим плагином для Вордпресс!
    6 Version: 3.1.3
     6Version: 3.1.4
    77Author: MakeDreamProfits
    88Author URI: http://makedreamprofits.ru
Note: See TracChangeset for help on using the changeset viewer.