PluginProbe ʕ •ᴥ•ʔ
External Links – nofollow, noopener & new window / 2.66
External Links – nofollow, noopener & new window v2.66
2.66 0.31 0.32 0.33 0.34 0.35 1.01 1.02 1.03 1.10 1.20 1.21 1.30 1.31 1.40 1.41 1.50 1.51 1.52 1.53 1.54 1.55 1.56 1.60 1.61 1.62 1.70 1.80 1.81 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.0 2.1.1 2.1.2 2.1.3 2.2.0 2.3 2.32 2.35 2.40 2.42 2.43 2.45 2.46 2.47 2.48 2.50 2.51 2.55 2.56 2.57 2.58 2.59 2.60 2.61 2.62 2.63 2.64 2.65 trunk 0.10 0.11 0.12 0.20 0.21 0.30
wp-external-links / includes / class-wpel-front-ignore.php
wp-external-links / includes Last commit date
admin 2 months ago register-hooks 3 years ago class-wpel-front-ignore.php 3 years ago class-wpel-front.php 4 months ago class-wpel-link.php 3 years ago class-wpel-plugin.php 1 year ago class-wpel-register-scripts.php 2 months ago class-wpel-template-tags.php 3 years ago class-wpel-update.php 3 years ago index.php 6 years ago
class-wpel-front-ignore.php
185 lines
1 <?php
2 /**
3 * Class WPEL_Front_Ignore
4 *
5 * @package WPEL
6 * @category WordPress Plugin
7 * @version 2.3
8 * @link https://www.webfactoryltd.com/
9 * @license Dual licensed under the MIT and GPLv2+ licenses
10 */
11 final class WPEL_Front_Ignore extends WPRun_Base_1x0x0
12 {
13
14 /**
15 * @var array
16 */
17 private $content_placeholders = array();
18
19 /**
20 * @var WPEL_Settings_Page
21 */
22 private $settings_page = null;
23
24 /**
25 * Initialize
26 * @param WPEL_Settings_Page $settings_page
27 */
28 protected function init( WPEL_Settings_Page $settings_page )
29 {
30 $this->settings_page = $settings_page;
31 }
32
33 /**
34 * Get option value
35 * @param string $key
36 * @param string|null $type
37 * @return string
38 * @triggers E_USER_NOTICE Option value cannot be found
39 */
40 protected function opt( $key, $type = null )
41 {
42 return $this->settings_page->get_option_value( $key, $type );
43 }
44
45 /**
46 * Skip complete pages
47 * @return boolean
48 */
49 protected function filter_wpel_apply_settings()
50 {
51 if ( ! is_single() && ! is_page() ) {
52 return true;
53 }
54
55 $current_post_id = get_queried_object_id();
56 $skip_post_ids = $this->opt( 'skip_post_ids', 'exceptions' );
57 $skip_post_ids_arr = explode( ',', $skip_post_ids );
58
59 foreach ( $skip_post_ids_arr as $post_id ) {
60 if ( intval( $post_id ) === $current_post_id ) {
61 return false;
62 }
63 }
64
65 return true;
66 }
67
68 /**
69 * Action for "wpel_before_apply_link"
70 * @param WPEL_Link $link
71 */
72 protected function action_wpel_before_apply_link_10000000000( WPEL_Link $link )
73 {
74 // ignore mailto links
75 if ( $this->opt( 'ignore_mailto_links' ) && $link->is_mailto() ) {
76 $link->set_ignore();
77 }
78
79 // ignore WP Admin Bar Links
80 if ( $link->has_attr_value( 'class', 'ab-item' ) ) {
81 $link->set_ignore();
82 }
83
84 // ignore links containing ignored classes
85 if ( $this->has_ignore_class( $link ) ) {
86 $link->set_ignore();
87 }
88 }
89
90 private function has_ignore_class( WPEL_Link $link )
91 {
92 $ignore_classes = $this->opt( 'ignore_classes', 'exceptions' );
93 $ignore_classes_arr = explode( ',', $ignore_classes );
94
95 foreach ( $ignore_classes_arr as $ignore_class ) {
96 if ( $link->has_attr_value( 'class', trim( $ignore_class ) ) ) {
97 return true;
98 }
99 }
100
101 return false;
102 }
103
104 /**
105 * Filter for "_wpel_before_filter"
106 * @param string $content
107 * @return string
108 */
109 protected function filter__wpel_before_filter_10000000000( $content )
110 {
111 $ignore_tags = array( 'head' );
112
113 if ( $this->opt( 'ignore_script_tags' ) ) {
114 $ignore_tags[] = 'script';
115 }
116
117 foreach ( $ignore_tags as $tag_name ) {
118 $content = preg_replace_callback(
119 $this->get_tag_regexp( $tag_name )
120 , $this->get_callback( 'skip_tag' )
121 , $content
122 );
123 }
124
125 return $content;
126 }
127
128 /**
129 * Filter for "_wpel_after_filter"
130 * @param string $content
131 * @return string
132 */
133 protected function filter__wpel_after_filter_10000000000( $content )
134 {
135 return $this->restore_content_placeholders( $content );
136 }
137
138 /**
139 * @param type $tag_name
140 * @return type
141 */
142 protected function get_tag_regexp( $tag_name )
143 {
144 return '/<'. $tag_name .'[\s.*>|>](.*?)<\/'. $tag_name .'[\s+]*>/is';
145 }
146
147 /**
148 * Pregmatch callback
149 * @param array $matches
150 * @return string
151 */
152 protected function skip_tag( $matches )
153 {
154 $skip_content = $matches[ 0 ];
155 return $this->get_placeholder( $skip_content );
156 }
157
158 /**
159 * Return placeholder text for given content
160 * @param string $placeholding_content
161 * @return string
162 */
163 protected function get_placeholder( $placeholding_content )
164 {
165 $placeholder = '<!--- WPEL PLACEHOLDER '. count( $this->content_placeholders ) .' --->';
166 $this->content_placeholders[ $placeholder ] = $placeholding_content;
167 return $placeholder;
168 }
169
170 /**
171 * Restore placeholders with original content
172 * @param string $content
173 * @return string
174 */
175 protected function restore_content_placeholders( $content )
176 {
177 foreach ( $this->content_placeholders as $placeholder => $placeholding_content ) {
178 $content = str_replace( $placeholder, $placeholding_content, $content );
179 }
180
181 return $content;
182 }
183
184 }
185