PluginProbe
Insert PHP Code Snippet / trunk
Insert PHP Code Snippet vtrunk
1.4.7 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 trunk 1.0 1.1 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3 All 27 releases
← All changes | xyz-functions.php +182 -11 1.2trunk View file →
@@ -1,6 +1,8 @@
1 1 <?php
2 -
2 +if ( ! defined( 'ABSPATH' ) )
3 + exit;
4 +
3 5 if(!function_exists('xyz_ips_plugin_get_version'))
4 6 {
5 7 function xyz_ips_plugin_get_version()
6 8 {
@@ -6,13 +8,71 @@
6 8 {
7 9 if ( ! function_exists( 'get_plugins' ) )
8 10 require_once( ABSPATH . 'wp-admin/includes/plugin.php' );
9 11 $plugin_folder = get_plugins( '/' . plugin_basename( dirname( XYZ_INSERT_PHP_PLUGIN_FILE ) ) );
10 - // print_r($plugin_folder);
11 12 return $plugin_folder['insert-php-code-snippet.php']['Version'];
12 13 }
13 14 }
15 +if(!function_exists('xyz_ips_run_upgrade_routines'))
16 +{
17 +function xyz_ips_run_upgrade_routines() {
18 + global $wpdb;
19 + if (is_multisite()) {
20 + $blog_ids = $wpdb->get_col("SELECT blog_id FROM $wpdb->blogs");
21 + foreach ($blog_ids as $blog_id) {
22 + switch_to_blog($blog_id);
23 + xyz_ips_install();
24 + //wp_cache_flush();
25 + restore_current_blog();
26 + }
27 + } else {
28 + xyz_ips_install();
29 + //wp_cache_flush();
30 + }
31 +}
32 +}
33 +if(!function_exists('xyz_ips_prepare_content_to_eval'))
34 +{
14 35
36 + function xyz_ips_prepare_content_to_eval($content_to_eval){
37 +$xyz_ips_content_start='<?php';
38 +$new_line="\r\n";
39 +$xyz_ips_content_end='?>';
40 +
41 +if (stripos($content_to_eval, '<?php') !== false)
42 + $tag_start_position=stripos($content_to_eval,'<?php');
43 +else
44 + $tag_start_position="-1";
45 +
46 +if (stripos($content_to_eval, '?>') !== false)
47 + $tag_end_position=stripos($content_to_eval,'?>');
48 +else
49 + $tag_end_position="-1";
50 +
51 +if(stripos($content_to_eval, '<?php') === false && stripos($content_to_eval, '?>') === false)
52 +{
53 + $content_to_eval=$xyz_ips_content_start.$new_line.$content_to_eval;
54 +}
55 +else if(stripos($content_to_eval, '<?php') !== false)
56 +{
57 + if($tag_start_position>=0 && $tag_end_position>=0 && $tag_start_position>$tag_end_position)
58 + {
59 + $content_to_eval=$xyz_ips_content_start.$new_line.$content_to_eval;
60 + }
61 +}
62 +else if(stripos($content_to_eval, '<?php') === false)
63 +{
64 + if (stripos($content_to_eval, '?>') !== false)
65 + {
66 + $content_to_eval=$xyz_ips_content_start.$new_line.$content_to_eval;
67 + }
68 +}
69 +
70 +
71 +return $content_to_eval='?>'.$content_to_eval;
72 +}
73 +
74 +}
15 75 if(!function_exists('xyz_trim_deep'))
16 76 {
17 77
18 78 function xyz_trim_deep($value) {
@@ -18,13 +78,14 @@
18 78 function xyz_trim_deep($value) {
19 79 if ( is_array($value) ) {
20 80 $value = array_map('xyz_trim_deep', $value);
21 81 } elseif ( is_object($value) ) {
22 - $vars = get_object_vars( $value );
23 - foreach ($vars as $key=>$data) {
82 +
83 + foreach (get_object_vars($value) as $key => $data) {
24 84 $value->{$key} = xyz_trim_deep( $data );
25 85 }
26 - } else {
86 +
87 + } elseif (is_string($value)) {
27 88 $value = trim($value);
28 89 }
29 90
30 91 return $value;
@@ -37,13 +98,13 @@
37 98 function xyz_ips_links($links, $file) {
38 99 $base = plugin_basename(XYZ_INSERT_PHP_PLUGIN_FILE);
39 100 if ($file == $base) {
40 101
41 - $links[] = '<a href="http://xyzscripts.com/support/" class="xyz_support" title="Support"></a>';
42 - $links[] = '<a href="http://twitter.com/xyzscripts" class="xyz_twitt" title="Follow us on Twitter"></a>';
43 - $links[] = '<a href="https://www.facebook.com/xyzscripts" class="xyz_fbook" title="Like us on Facebook"></a>';
44 - $links[] = '<a href="https://plus.google.com/+Xyzscripts/" class="xyz_gplus" title="+1 us on Google+"></a>';
45 - $links[] = '<a href="http://www.linkedin.com/company/xyzscripts" class="xyz_linkedin" title="Follow us on LinkedIn"></a>';
102 + $links[] = '<a href="https://xyzscripts.com/support/" class="xyz_ips_support" title="Support"></a>';
103 + $links[] = '<a href="https://twitter.com/xyzscripts" class="xyz_ips_twitt" title="Follow us on Twitter"></a>';
104 + $links[] = '<a href="https://www.facebook.com/xyzscripts" class="xyz_ips_fbook" title="Like us on Facebook"></a>';
105 + $links[] = '<a href="https://www.instagram.com/xyz_scripts/" class="xyz_ips_insta" title="Follow us on Instagram"></a>';
106 + $links[] = '<a href="https://www.linkedin.com/company/xyzscripts" class="xyz_ips_linkedin" title="Follow us on LinkedIn"></a>';
46 107 }
47 108 return $links;
48 109 }
49 110 }
@@ -48,5 +109,115 @@
48 109 }
49 110 }
50 111 add_filter( 'plugin_row_meta','xyz_ips_links',10,2);
51 112
52 -?>
113 +if (!function_exists('xyz_ips_page_exists_by_slug')) {
114 + function xyz_ips_page_exists_by_slug($slug) {
115 + global $wpdb;
116 + return (int) $wpdb->get_var($wpdb->prepare(
117 + "SELECT ID FROM {$wpdb->posts}
118 + WHERE post_name = %s
119 + AND post_type = 'page'
120 + LIMIT 1",
121 + $slug
122 + ));
123 +}
124 +}
125 +if(!function_exists('xyz_ips_get_link_by_slug'))
126 +{
127 +
128 +function xyz_ips_get_link_by_slug($slug, $type = 'page'){
129 + $post = get_page_by_path($slug, OBJECT, $type);
130 + return get_permalink($post->ID);
131 +}
132 +}
133 +
134 +function xyz_ips_preview_page( $content ) {
135 + if ( strcmp( 'xyz-ics-preview-page', get_post_field( 'post_name' ) ) === 0 ) {
136 +
137 + $xyz_ips_snippetId="";
138 + if(isset($_GET['snippetId']))
139 + $xyz_ips_snippetId=intval($_GET['snippetId']);
140 +
141 + if($xyz_ips_snippetId!="" && is_numeric($xyz_ips_snippetId))
142 + {
143 + global $wpdb;
144 +
145 + $snippetDetails = $wpdb->get_results($wpdb->prepare( 'SELECT * FROM '.$wpdb->prefix.'xyz_ips_short_code WHERE id=%d LIMIT 0,1',$xyz_ips_snippetId )) ;
146 + if(!empty($snippetDetails)) {
147 + $snippetDetails = $snippetDetails[0];
148 +
149 + $content = do_shortcode( '[xyz-ips snippet="'.esc_html($snippetDetails->title).'"]' );
150 + }
151 + }
152 + }
153 +
154 + return $content;
155 +}
156 +
157 +add_filter( 'the_content', 'xyz_ips_preview_page' );
158 +
159 +if(!function_exists('xyz_ips_get_insertion_location_label')){
160 +function xyz_ips_get_insertion_location_label($value) {
161 + $map = array_flip(XYZ_IPS_INSERTION_LOCATION);
162 + if (!isset($map[$value])) {
163 + return '';
164 + }
165 + // Convert constant-style key to readable text
166 + return ucwords(strtolower(str_replace('_', ' ', $map[$value])));
167 +}
168 +}
169 +if(!function_exists('xyz_ips_get_shortcode_usage_count')){
170 +// Get shortcode usage count (admin-only)
171 +function xyz_ips_get_shortcode_usage_count($snippet_title) {
172 + global $wpdb;
173 + $shortcode = '[xyz-ips snippet="' . esc_sql($snippet_title) . '"';
174 + $query = $wpdb->prepare(
175 + "SELECT COUNT(ID)
176 + FROM {$wpdb->posts}
177 + WHERE post_status = 'publish'
178 + AND post_content LIKE %s",
179 + '%' . $wpdb->esc_like($shortcode) . '%'
180 + );
181 + return (int) $wpdb->get_var($query);
182 +}
183 +}
184 +if(!function_exists('xyz_ips_update_usage_for_post')){
185 +// --- Tracking Logic ---
186 +function xyz_ips_update_usage_for_post($post_id, $content, $post_type = 'post') {
187 + global $wpdb;
188 + $table_name = $wpdb->prefix . 'xyz_ips_usage';
189 + if (strpos($content, '[xyz-ips') === false) {
190 + $wpdb->delete($table_name, ['post_id' => $post_id]);
191 + return;
192 + }
193 + $wpdb->delete($table_name, ['post_id' => $post_id]);
194 + preg_match_all('/\[xyz-ips([^\]]*)\]/', $content, $shortcodes);
195 + $titles = [];
196 + if (!empty($shortcodes[1])) {
197 + foreach ($shortcodes[1] as $attr_string) {
198 + $atts = shortcode_parse_atts($attr_string);
199 + // if (!empty($atts['snippet']))
200 + // PHP 8.3 Compliance Fix: Ensure $atts is an array before checking the 'snippet' key
201 + if (is_array($atts) && !empty($atts['snippet']))
202 + {
203 + $titles[] = $atts['snippet'];
204 + }
205 + }
206 + }
207 + $unique_snippets = array_unique($titles);
208 + foreach ($unique_snippets as $title) {
209 + $s_id = $wpdb->get_var($wpdb->prepare(
210 + "SELECT id FROM {$wpdb->prefix}xyz_ips_short_code WHERE title = %s",
211 + $title
212 + ));
213 + if ($s_id) {
214 + $wpdb->insert($table_name, [
215 + 'post_id' => $post_id,
216 + 'snippet_id' => $s_id,
217 + 'post_type' => $post_type
218 + ]);
219 + }
220 + }
221 +}
222 +}
223 +?>