SEO SQUIRRLY™ - Version 6.1.0

Version Description

  • Compatible with WP 4.6
  • Fixed the Front Page SEO to work with more WP themes
  • Fixed compatibility with PolyLang plugin
  • Fixed compatibility with Customizr theme
  • Fixed Squirrly SEO Snippet for arabic lang
Download this release

Release Info

Developer cifi
Plugin Icon 128x128 SEO SQUIRRLY™
Version 6.1.0
Comparing to
See all releases

Code changes from version 5.2.8 to 6.1.0

classes/SQ_Tools.php CHANGED
@@ -5,7 +5,8 @@
5
  *
6
  * @author Squirrly
7
  */
8
- class SQ_Tools extends SQ_FrontController {
 
9
 
10
  /** @var array Saved options in database */
11
  public static $options = array();
@@ -17,7 +18,8 @@ class SQ_Tools extends SQ_FrontController {
17
  private static $debug;
18
  private static $source_code;
19
 
20
- public function __construct() {
 
21
  parent::__construct();
22
 
23
  self::$options = $this->getOptions();
@@ -25,7 +27,8 @@ class SQ_Tools extends SQ_FrontController {
25
  $this->checkDebug(); //dev mode
26
  }
27
 
28
- public static function getUserID() {
 
29
  global $current_user;
30
  return $current_user->ID;
31
  }
@@ -35,7 +38,8 @@ class SQ_Tools extends SQ_FrontController {
35
  *
36
  * @return void
37
  */
38
- function hookInit() {
 
39
  //TinyMCE editor required
40
  //set_user_setting('editor', 'tinymce');
41
 
@@ -52,7 +56,8 @@ class SQ_Tools extends SQ_FrontController {
52
  * @param type $file
53
  * @return array
54
  */
55
- public function hookActionlink($links, $file) {
 
56
  if ($file == _SQ_PLUGIN_NAME_ . '/squirrly.php') {
57
  $link = '<a href="' . admin_url('admin.php?page=sq_dashboard') . '">' . __('Getting started', _SQ_PLUGIN_NAME_) . '</a>';
58
  array_unshift($links, $link);
@@ -66,7 +71,8 @@ class SQ_Tools extends SQ_FrontController {
66
  *
67
  * @return void
68
  */
69
- public static function getOptions() {
 
70
  $default = array(
71
  'sq_ver' => 0,
72
  'sq_api' => '',
@@ -79,6 +85,7 @@ class SQ_Tools extends SQ_FrontController {
79
  // --
80
  'sq_auto_canonical' => 1,
81
  'sq_auto_sitemap' => 0,
 
82
  'sq_auto_jsonld' => 0,
83
  'sq_jsonld_type' => 'Organization',
84
  'sq_jsonld' => array(
@@ -117,19 +124,19 @@ class SQ_Tools extends SQ_FrontController {
117
  'sitemap-custom-post' => array('sitemap-custom-posts.xml', 0),
118
  ),
119
  'sq_auto_robots' => 1,
120
- 'sq_robots_security' => array(
121
  'User-agent: *',
122
  'Disallow: */trackback/',
123
  'Disallow: */xmlrpc.php',
124
  'Disallow: /wp-*.php',
125
  'Disallow: /cgi-bin/',
126
  'Disallow: /wp-admin/',
127
- 'Disallow: /wp-includes/',
128
- 'Allow: */wp-content/uploads/'),
129
  'sq_auto_meta' => 1,
130
  'sq_auto_favicon' => 0,
131
  'favicon' => '',
132
  'sq_auto_twitter' => 0,
 
133
  'sq_auto_facebook' => 0,
134
  'sq_og_locale' => 'en_US',
135
  'sq_twitter_account' => '',
@@ -180,7 +187,8 @@ class SQ_Tools extends SQ_FrontController {
180
  return $default;
181
  }
182
 
183
- public static function getBriefOptions() {
 
184
  if ($pageId = get_option('page_on_front')) {
185
  $title = SQ_ObjController::getModel('SQ_Frontend')->getAdvancedMeta($pageId, 'title');
186
  $description = SQ_ObjController::getModel('SQ_Frontend')->getAdvancedMeta($pageId, 'description');
@@ -203,15 +211,15 @@ class SQ_Tools extends SQ_FrontController {
203
  'sq_auto_twitter' => SQ_Tools::$options['sq_auto_twitter'],
204
  'sq_auto_facebook' => SQ_Tools::$options['sq_auto_facebook'],
205
  'sq_auto_seo' => SQ_Tools::$options['sq_auto_seo'],
206
- 'sq_auto_title' => (int) (SQ_Tools::$options['sq_auto_title'] == 1 && $title <> ''),
207
- 'sq_auto_description' => (int) (SQ_Tools::$options['sq_auto_description'] == 1 && $description <> ''),
208
- 'sq_google_plus' => (int) (SQ_Tools::$options['sq_google_plus'] <> ''),
209
- 'sq_google_wt' => (int) (SQ_Tools::$options['sq_google_wt'] <> ''),
210
- 'sq_google_analytics' => (int) (SQ_Tools::$options['sq_google_analytics'] <> ''),
211
- 'sq_facebook_insights' => (int) (SQ_Tools::$options['sq_facebook_insights'] <> ''),
212
- 'sq_bing_wt' => (int) (SQ_Tools::$options['sq_bing_wt'] <> ''),
213
- 'sq_pinterest' => (int) (SQ_Tools::$options['sq_pinterest'] <> ''),
214
- 'sq_alexa' => (int) (SQ_Tools::$options['sq_alexa'] <> ''),
215
  'sq_keyword_help' => SQ_Tools::$options['sq_keyword_help'],
216
  'sq_keyword_information' => SQ_Tools::$options['sq_keyword_information'],
217
  'sq_google_country_strict' => SQ_Tools::$options['sq_google_country_strict'],
@@ -225,7 +233,8 @@ class SQ_Tools extends SQ_FrontController {
225
  *
226
  * @return void
227
  */
228
- public static function saveOptions($key = null, $value = '') {
 
229
  if (isset($key)) {
230
  self::$options[$key] = $value;
231
  }
@@ -237,7 +246,8 @@ class SQ_Tools extends SQ_FrontController {
237
  * Set the header type
238
  * @param type $type
239
  */
240
- public static function setHeader($type) {
 
241
  if (SQ_Tools::getValue('sq_debug') == 'on')
242
  return;
243
 
@@ -265,10 +275,11 @@ class SQ_Tools extends SQ_FrontController {
265
  * @param mixed $defaultValue (optional)
266
  * @return mixed Value
267
  */
268
- public static function getValue($key, $defaultValue = false, $withcode = false) {
269
- if (!isset($key) OR empty($key) OR ! is_string($key))
 
270
  return false;
271
- $ret = (isset($_POST[$key]) ? $_POST[$key] : (isset($_GET[$key]) ? (is_string($_GET[$key]) ? urldecode($_GET[$key]) : $_GET[$key]) : $defaultValue));
272
 
273
  if (is_string($ret) === true && $withcode === false) {
274
  $ret = sanitize_text_field($ret);
@@ -283,8 +294,9 @@ class SQ_Tools extends SQ_FrontController {
283
  * @param string $key
284
  * @return boolean
285
  */
286
- public static function getIsset($key) {
287
- if (!isset($key) OR empty($key) OR ! is_string($key))
 
288
  return false;
289
  return isset($_POST[$key]) ? true : (isset($_GET[$key]) ? true : false);
290
  }
@@ -294,10 +306,11 @@ class SQ_Tools extends SQ_FrontController {
294
  *
295
  * @return void
296
  */
297
- public static function showNotices($message, $type = 'sq_notices') {
 
298
  if (file_exists(_SQ_THEME_DIR_ . 'SQ_notices.php')) {
299
  ob_start();
300
- include (_SQ_THEME_DIR_ . 'SQ_notices.php');
301
  $message = ob_get_contents();
302
  ob_end_clean();
303
  }
@@ -308,7 +321,8 @@ class SQ_Tools extends SQ_FrontController {
308
  /**
309
  * Load the multilanguage support from .mo
310
  */
311
- private function loadMultilanguage() {
 
312
  if (!defined('WP_PLUGIN_DIR')) {
313
  load_plugin_textdomain(_SQ_PLUGIN_NAME_, _SQ_PLUGIN_NAME_ . '/languages/');
314
  } else {
@@ -319,24 +333,40 @@ class SQ_Tools extends SQ_FrontController {
319
  /**
320
  * Connect remote with CURL if exists
321
  */
322
- public static function sq_remote_get($url, $param = array(), $options = array()) {
 
323
  $parameters = '';
324
  $cookies = array();
325
  $cookie_string = '';
326
 
327
  $url_domain = parse_url($url);
328
- $url_domain = $url_domain['host'];
 
 
 
 
329
 
330
- if (isset($param))
331
  foreach ($param as $key => $value) {
332
- if (isset($key) && $key <> '' && $key <> 'timeout')
333
  $parameters .= ($parameters == "" ? "" : "&") . $key . "=" . $value;
 
334
  }
335
- if ($parameters <> '')
 
 
336
  $url .= ((strpos($url, "?") === false) ? "?" : "&") . $parameters;
 
337
 
338
  //send the cookie for preview
339
- if ($url_domain == $_SERVER['HTTP_HOST'] && strpos($url, 'preview=true') !== false) {
 
 
 
 
 
 
 
340
  foreach ($_COOKIE as $name => $value) {
341
  if (strpos($name, 'wordpress') !== false || strpos($name, 'wp') !== false || strpos($name, 'slimstat') !== false || strpos($name, 'sforum') !== false) {
342
  $cookies[] = new WP_Http_Cookie(array('name' => $name, 'value' => $value));
@@ -352,9 +382,70 @@ class SQ_Tools extends SQ_FrontController {
352
  }
353
  $options['sslverify'] = false;
354
 
355
- if (!$response = self::sq_wpcall($url, $options)) {
356
  if (function_exists('curl_init') && !ini_get('safe_mode') && !ini_get('open_basedir')) {
357
- $response = self::sq_curl($url, $options);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
358
  } else {
359
  return false;
360
  }
@@ -369,18 +460,29 @@ class SQ_Tools extends SQ_FrontController {
369
  * @param array $param
370
  * @return string
371
  */
372
- private static function sq_curl($url, $options) {
 
373
 
374
  $ch = curl_init();
375
  curl_setopt($ch, CURLOPT_URL, $url);
376
  curl_setopt($ch, CURLOPT_HEADER, false);
377
  //--
378
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
379
- curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
380
  //--
381
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
382
  curl_setopt($ch, CURLOPT_TIMEOUT, $options['timeout']);
383
 
 
 
 
 
 
 
 
 
 
 
384
  if (isset($options['followlocation'])) {
385
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
386
  curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
@@ -396,7 +498,7 @@ class SQ_Tools extends SQ_FrontController {
396
  $response = curl_exec($ch);
397
  $response = self::cleanResponce($response);
398
 
399
- self::dump('CURL', $url, $options, $ch, $response); //output debug
400
 
401
  if (curl_errno($ch) == 1 || $response === false) { //if protocol not supported
402
  if (curl_errno($ch)) {
@@ -417,22 +519,28 @@ class SQ_Tools extends SQ_FrontController {
417
  * @param array $param
418
  * @return string
419
  */
420
- private static function sq_wpcall($url, $options) {
421
- $response = wp_remote_get($url, $options);
 
 
 
 
 
422
  if (is_wp_error($response)) {
423
  self::dump($response);
424
  return false;
425
  }
426
 
427
  $response = self::cleanResponce(wp_remote_retrieve_body($response)); //clear and get the body
428
- self::dump('wp_remote_get', $url, $options, $response); //output debug
429
  return $response;
430
  }
431
 
432
  /**
433
  * Connect remote with CURL if exists
434
  */
435
- public static function sq_remote_head($url) {
 
436
  $response = array();
437
 
438
  if (function_exists('curl_exec')) {
@@ -458,7 +566,8 @@ class SQ_Tools extends SQ_FrontController {
458
  * @param string $response
459
  * @return string
460
  */
461
- private static function cleanResponce($response) {
 
462
 
463
  if (function_exists('substr_count'))
464
  if (substr_count($response, '(') > 1)
@@ -473,14 +582,15 @@ class SQ_Tools extends SQ_FrontController {
473
  /**
474
  * Check for SEO blog bad settings
475
  */
476
- public static function checkErrorSettings($count_only = false) {
 
477
  if (current_user_can('manage_options')) {
478
 
479
  $fixit = "<a href=\"javascript:void(0);\" onclick=\"%s jQuery(this).closest('div').fadeOut('slow'); if(parseInt(jQuery('.sq_count').html())>0) { var notif = (parseInt(jQuery('.sq_count').html()) - 1); if (notif > 0) {jQuery('.sq_count').html(notif); }else{ jQuery('.sq_count').html(notif); jQuery('.sq_count').hide(); } } jQuery.post(ajaxurl, { action: '%s', nonce: '" . wp_create_nonce(_SQ_NONCE_ID_) . "'});\" >" . __("Fix it for me!", _SQ_PLUGIN_NAME_) . "</a>";
480
 
481
  /* IF SEO INDEX IS OFF */
482
  if (self::getAutoSeoSquirrly()) {
483
- self::$errors_count ++;
484
  if (!$count_only) {
485
  SQ_Error::setError(__('Activate the Squirrly SEO for your blog (recommended)', _SQ_PLUGIN_NAME_) . " <br />" . sprintf($fixit, "jQuery('#sq_use_on').trigger('click');", "sq_fixautoseo") . "", 'settings', 'sq_fix_auto');
486
  }
@@ -491,7 +601,7 @@ class SQ_Tools extends SQ_FrontController {
491
  if (self::$source_code <> '') {
492
  /* IF TITLE DUPLICATES */
493
  if (self::getDuplicateTitle()) {
494
- self::$errors_count ++;
495
  if (!$count_only) {
496
  SQ_Error::setError(__('You have META Title Duplicates. Disable the Squirrly Title Optimization or disable the other SEO Plugins', _SQ_PLUGIN_NAME_) . " <br />" . sprintf($fixit, "jQuery('#sq_auto_title0').attr('checked', true); jQuery('#sq_automatically').attr('checked', true);", "sq_fix_titleduplicate") . "", 'settings', 'sq_fix_descduplicate');
497
  }
@@ -499,7 +609,7 @@ class SQ_Tools extends SQ_FrontController {
499
 
500
  /* IF DESCRIPTION DUPLICATES */
501
  if (self::getDuplicateDescription()) {
502
- self::$errors_count ++;
503
  if (!$count_only) {
504
  SQ_Error::setError(__('You have META Description Duplicates. Disable the Squirrly Description Optimization or disable the other SEO Plugins', _SQ_PLUGIN_NAME_) . " <br />" . sprintf($fixit, "jQuery('#sq_auto_description0').attr('checked', true); jQuery('#sq_automatically').attr('checked', true);", "sq_fix_descduplicate") . "", 'settings', 'sq_fix_descduplicate');
505
  }
@@ -507,7 +617,7 @@ class SQ_Tools extends SQ_FrontController {
507
 
508
  /* IF OG DUPLICATES */
509
  if (self::getDuplicateOG()) {
510
- self::$errors_count ++;
511
  if (!$count_only) {
512
  SQ_Error::setError(__('You have Open Graph META Duplicates. Disable the Squirrly SEO Open Graph or disable the other SEO Plugins', _SQ_PLUGIN_NAME_) . " <br />" . sprintf($fixit, "jQuery('#sq_auto_facebook0').attr('checked', true);", "sq_fix_ogduplicate") . "", 'settings', 'sq_fix_ogduplicate');
513
  }
@@ -515,7 +625,7 @@ class SQ_Tools extends SQ_FrontController {
515
 
516
  /* IF TWITTER CARD DUPLICATES */
517
  if (self::getDuplicateTC()) {
518
- self::$errors_count ++;
519
  if (!$count_only) {
520
  SQ_Error::setError(__('You have Twitter Card META Duplicates. Disable the Squirrly SEO Twitter Card or disable the other SEO Plugins', _SQ_PLUGIN_NAME_) . " <br />" . sprintf($fixit, "jQuery('#sq_auto_twitter0').attr('checked', true);", "sq_fix_tcduplicate") . "", 'settings', 'sq_fix_tcduplicate');
521
  }
@@ -550,9 +660,10 @@ class SQ_Tools extends SQ_FrontController {
550
  * Check if the automatically seo si active
551
  * @return bool
552
  */
553
- private static function getAutoSeoSquirrly() {
 
554
  if (isset(self::$options['sq_use']))
555
- return ((int) self::$options['sq_use'] == 0 );
556
 
557
  return true;
558
  }
@@ -561,7 +672,8 @@ class SQ_Tools extends SQ_FrontController {
561
  * Check for META duplicates
562
  * @return boolean
563
  */
564
- private static function getDuplicateOG() {
 
565
  if (!function_exists('preg_match_all')) {
566
  return false;
567
  }
@@ -583,7 +695,8 @@ class SQ_Tools extends SQ_FrontController {
583
  * Check for META duplicates
584
  * @return boolean
585
  */
586
- private static function getDuplicateTC() {
 
587
  if (!function_exists('preg_match_all')) {
588
  return false;
589
  }
@@ -605,7 +718,8 @@ class SQ_Tools extends SQ_FrontController {
605
  * Check for META duplicates
606
  * @return boolean
607
  */
608
- private static function getDuplicateDescription() {
 
609
  if (!function_exists('preg_match_all')) {
610
  return false;
611
  }
@@ -631,7 +745,8 @@ class SQ_Tools extends SQ_FrontController {
631
  * Check for META duplicates
632
  * @return boolean
633
  */
634
- private static function getDuplicateTitle() {
 
635
  if (!function_exists('preg_match_all')) {
636
  return false;
637
  }
@@ -657,15 +772,17 @@ class SQ_Tools extends SQ_FrontController {
657
  * Check if the blog is in private mode
658
  * @return bool
659
  */
660
- public static function getPrivateBlog() {
661
- return ((int) get_option('blog_public') == 0 );
 
662
  }
663
 
664
  /**
665
  * Check if the blog has a bad link structure
666
  * @return bool
667
  */
668
- private static function getBadLinkStructure() {
 
669
  global $wp_rewrite;
670
  if (function_exists('apache_get_modules')) {
671
  //Check if mod_rewrite is installed in apache
@@ -689,7 +806,8 @@ class SQ_Tools extends SQ_FrontController {
689
  * @param string $in
690
  * @return string $in localized
691
  */
692
- public static function i18n($in) {
 
693
  if (function_exists('langswitch_filter_langs_with_message')) {
694
  $in = langswitch_filter_langs_with_message($in);
695
  }
@@ -710,13 +828,15 @@ class SQ_Tools extends SQ_FrontController {
710
  * @param int $decimals Precision of the number of decimal places.
711
  * @return string Converted number in string format.
712
  */
713
- public static function i18n_number_format($number, $decimals = 0) {
 
714
  global $wp_locale;
715
  $formatted = number_format($number, absint($decimals), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep']);
716
  return apply_filters('number_format_i18n', $formatted);
717
  }
718
 
719
- public static function getBrowserInfo() {
 
720
  $ub = '';
721
  $u_agent = $_SERVER['HTTP_USER_AGENT'];
722
  $bname = 'Unknown';
@@ -781,44 +901,61 @@ class SQ_Tools extends SQ_FrontController {
781
  * @param string $url
782
  * @return array
783
  */
784
- public static function getSnippet($url) {
785
- if ($url == '' || !function_exists('preg_match'))
 
786
  return;
 
 
787
  $snippet = array();
788
- $length = array('title' => 66,
789
- 'description' => 240,
790
- 'url' => 45);
 
 
 
 
 
 
 
 
 
 
791
 
792
- self::$source_code = self::sq_remote_get($url, array(), array('timeout' => 10, 'followlocation' => true));
793
 
794
- $title_regex = "/<title[^>]*>([^<>]*)<\/title>/si";
795
- preg_match($title_regex, self::$source_code, $title);
796
 
797
- if (is_array($title) && count($title) > 0) {
798
- $snippet['title'] = $title[1];
799
- $snippet['title'] = self::i18n(trim(strip_tags($snippet['title'])));
800
- }
801
 
802
- $description_regex = '/<meta[^>]*(name|property)=["\']description["\'][^>]*content="([^"<>]+)"[^<>]*>/si';
803
- preg_match($description_regex, self::$source_code, $description);
804
- if (is_array($description) && count($description) > 0) {
805
- $snippet['description'] = self::i18n(trim(strip_tags($description[2])));
806
 
807
- if (strlen($snippet['description']) > $length['description'])
808
- $snippet['description'] = substr($snippet['description'], 0, ($length['description'] - 1)) . '...';
809
- }
810
 
811
- $snippet['url'] = $url;
812
- if (strlen($snippet['url']) > $length['url'])
813
- $snippet['url'] = substr($snippet['url'], 0, ($length['url'] - 1)) . '...';
 
 
814
 
815
  return $snippet;
 
816
  }
817
 
818
  /**
819
  * Check if debug is called
820
  */
821
- private function checkDebug() {
 
822
  //if debug is called
823
  if (self::getIsset('sq_debug')) {
824
  if (self::getValue('sq_debug') == self::$options['sq_api']) {
@@ -838,7 +975,8 @@ class SQ_Tools extends SQ_FrontController {
838
  /**
839
  * Store the debug for a later view
840
  */
841
- public static function dump() {
 
842
  if (self::getValue('sq_debug') !== 'on') {
843
  return;
844
  }
@@ -854,26 +992,26 @@ class SQ_Tools extends SQ_FrontController {
854
 
855
  $run_time = number_format(microtime(true) - REQUEST_TIME, 3);
856
  if (function_exists('debug_backtrace'))
857
- list( $callee ) = debug_backtrace();
858
 
859
  $output .= '<fieldset style="background: #FFFFFF; border: 1px #CCCCCC solid; padding: 5px; font-size: 9pt; margin: 0;">';
860
  $output .= '<legend style="background: #EEEEEE; padding: 2px; font-size: 8pt;">' . $callee['file'] . ' Time: ' . $run_time . ' @ line: ' . $callee['line']
861
- . '</legend><pre style="margin: 0; font-size: 8pt; text-align: left;">';
862
 
863
  $i = 0;
864
  foreach ($arguments as $argument) {
865
  if (count($arguments) > 1)
866
- $output .= "\n" . '<strong>#' . ( ++$i ) . ' of ' . $total_arguments . '</strong>: ';
867
 
868
  // if argument is boolean, false value does not display, so ...
869
  if (is_bool($argument))
870
- $argument = ( $argument ) ? 'TRUE' : 'FALSE';
871
  else
872
- if (is_object($argument) && function_exists('array_reverse') && function_exists('class_parents'))
873
- $output .= implode("\n" . '|' . "\n", array_reverse(class_parents($argument))) . "\n" . '|' . "\n";
874
 
875
  $output .= htmlspecialchars(print_r($argument, TRUE))
876
- . ( ( is_object($argument) && function_exists('spl_object_hash') ) ? spl_object_hash($argument) : '' );
877
  }
878
  $output .= "</pre>";
879
  $output .= "</fieldset>";
@@ -884,25 +1022,30 @@ class SQ_Tools extends SQ_FrontController {
884
  /**
885
  * Show the debug dump
886
  */
887
- public static function showDebug() {
 
 
888
  echo "Debug result: <br />" . '<div id="wpcontent">' . @implode('<br />', self::$debug) . '</div>';
889
 
890
  $run_time = number_format(microtime(true) - REQUEST_TIME, 3);
891
  $pps = number_format(1 / $run_time, 0);
892
  $memory_avail = ini_get('memory_limit');
893
- $memory_used = number_format(memory_get_usage(true) / ( 1024 * 1024 ), 2);
894
- $memory_peak = number_format(memory_get_peak_usage(true) / ( 1024 * 1024 ), 2);
895
 
896
  echo PHP_EOL . " Load: {$memory_avail} (avail) / {$memory_used}M (used) / {$memory_peak}M (peak)";
897
  echo " | Time: {$run_time}s | {$pps} req/sec";
 
898
  }
899
 
900
- public function sq_activate() {
 
901
  set_transient('sq_activate', true);
902
  set_transient('sq_rewrite', true);
903
  }
904
 
905
- public function sq_deactivate() {
 
906
  //clear the cron job
907
  wp_clear_scheduled_hook('sq_processCron');
908
 
@@ -910,12 +1053,13 @@ class SQ_Tools extends SQ_FrontController {
910
  $args['type'] = 'deact';
911
  SQ_Action::apiCall('sq/user/log', $args, 5);
912
 
913
- remove_filter('rewrite_rules_array', array(SQ_ObjController::getBlock('SQ_BlockSettingsSeo'), 'rewrite_rules'), 999, 1);
914
  global $wp_rewrite;
915
  $wp_rewrite->flush_rules();
916
  }
917
 
918
- public static function emptyCache($post_id = null) {
 
919
  if (function_exists('w3tc_pgcache_flush')) {
920
  w3tc_pgcache_flush();
921
  }
@@ -932,7 +1076,8 @@ class SQ_Tools extends SQ_FrontController {
932
  }
933
  }
934
 
935
- public static function checkUpgrade() {
 
936
  if (self::$options['sq_ver'] == 0 || self::$options['sq_ver'] < SQ_VERSION_ID) {
937
  //Delete the old versions table
938
  global $wpdb;
@@ -943,6 +1088,9 @@ class SQ_Tools extends SQ_FrontController {
943
  $wpdb->query("UPDATE " . $wpdb->postmeta . " SET `meta_key` = '_sq_post_keyword' WHERE `meta_key` = 'sq_post_keyword'");
944
 
945
  self::saveOptions('sq_ver', SQ_VERSION_ID);
 
 
 
946
  }
947
  }
948
 
5
  *
6
  * @author Squirrly
7
  */
8
+ class SQ_Tools extends SQ_FrontController
9
+ {
10
 
11
  /** @var array Saved options in database */
12
  public static $options = array();
18
  private static $debug;
19
  private static $source_code;
20
 
21
+ public function __construct()
22
+ {
23
  parent::__construct();
24
 
25
  self::$options = $this->getOptions();
27
  $this->checkDebug(); //dev mode
28
  }
29
 
30
+ public static function getUserID()
31
+ {
32
  global $current_user;
33
  return $current_user->ID;
34
  }
38
  *
39
  * @return void
40
  */
41
+ function hookInit()
42
+ {
43
  //TinyMCE editor required
44
  //set_user_setting('editor', 'tinymce');
45
 
56
  * @param type $file
57
  * @return array
58
  */
59
+ public function hookActionlink($links, $file)
60
+ {
61
  if ($file == _SQ_PLUGIN_NAME_ . '/squirrly.php') {
62
  $link = '<a href="' . admin_url('admin.php?page=sq_dashboard') . '">' . __('Getting started', _SQ_PLUGIN_NAME_) . '</a>';
63
  array_unshift($links, $link);
71
  *
72
  * @return void
73
  */
74
+ public static function getOptions()
75
+ {
76
  $default = array(
77
  'sq_ver' => 0,
78
  'sq_api' => '',
85
  // --
86
  'sq_auto_canonical' => 1,
87
  'sq_auto_sitemap' => 0,
88
+ 'sq_auto_feed' => 0,
89
  'sq_auto_jsonld' => 0,
90
  'sq_jsonld_type' => 'Organization',
91
  'sq_jsonld' => array(
124
  'sitemap-custom-post' => array('sitemap-custom-posts.xml', 0),
125
  ),
126
  'sq_auto_robots' => 1,
127
+ 'sq_robots_permission' => array(
128
  'User-agent: *',
129
  'Disallow: */trackback/',
130
  'Disallow: */xmlrpc.php',
131
  'Disallow: /wp-*.php',
132
  'Disallow: /cgi-bin/',
133
  'Disallow: /wp-admin/',
134
+ 'Allow: */wp-content/uploads/',),
 
135
  'sq_auto_meta' => 1,
136
  'sq_auto_favicon' => 0,
137
  'favicon' => '',
138
  'sq_auto_twitter' => 0,
139
+ 'sq_auto_twittersize' => 'summary',
140
  'sq_auto_facebook' => 0,
141
  'sq_og_locale' => 'en_US',
142
  'sq_twitter_account' => '',
187
  return $default;
188
  }
189
 
190
+ public static function getBriefOptions()
191
+ {
192
  if ($pageId = get_option('page_on_front')) {
193
  $title = SQ_ObjController::getModel('SQ_Frontend')->getAdvancedMeta($pageId, 'title');
194
  $description = SQ_ObjController::getModel('SQ_Frontend')->getAdvancedMeta($pageId, 'description');
211
  'sq_auto_twitter' => SQ_Tools::$options['sq_auto_twitter'],
212
  'sq_auto_facebook' => SQ_Tools::$options['sq_auto_facebook'],
213
  'sq_auto_seo' => SQ_Tools::$options['sq_auto_seo'],
214
+ 'sq_auto_title' => (int)(SQ_Tools::$options['sq_auto_title'] == 1 && $title <> ''),
215
+ 'sq_auto_description' => (int)(SQ_Tools::$options['sq_auto_description'] == 1 && $description <> ''),
216
+ 'sq_google_plus' => (int)(SQ_Tools::$options['sq_google_plus'] <> ''),
217
+ 'sq_google_wt' => (int)(SQ_Tools::$options['sq_google_wt'] <> ''),
218
+ 'sq_google_analytics' => (int)(SQ_Tools::$options['sq_google_analytics'] <> ''),
219
+ 'sq_facebook_insights' => (int)(SQ_Tools::$options['sq_facebook_insights'] <> ''),
220
+ 'sq_bing_wt' => (int)(SQ_Tools::$options['sq_bing_wt'] <> ''),
221
+ 'sq_pinterest' => (int)(SQ_Tools::$options['sq_pinterest'] <> ''),
222
+ 'sq_alexa' => (int)(SQ_Tools::$options['sq_alexa'] <> ''),
223
  'sq_keyword_help' => SQ_Tools::$options['sq_keyword_help'],
224
  'sq_keyword_information' => SQ_Tools::$options['sq_keyword_information'],
225
  'sq_google_country_strict' => SQ_Tools::$options['sq_google_country_strict'],
233
  *
234
  * @return void
235
  */
236
+ public static function saveOptions($key = null, $value = '')
237
+ {
238
  if (isset($key)) {
239
  self::$options[$key] = $value;
240
  }
246
  * Set the header type
247
  * @param type $type
248
  */
249
+ public static function setHeader($type)
250
+ {
251
  if (SQ_Tools::getValue('sq_debug') == 'on')
252
  return;
253
 
275
  * @param mixed $defaultValue (optional)
276
  * @return mixed Value
277
  */
278
+ public static function getValue($key, $defaultValue = false, $withcode = false)
279
+ {
280
+ if (!isset($key) OR empty($key) OR !is_string($key))
281
  return false;
282
+ $ret = (isset($_POST[$key]) ? (is_string($_POST[$key]) ? urldecode($_POST[$key]) : $_POST[$key]) : (isset($_GET[$key]) ? (is_string($_GET[$key]) ? urldecode($_GET[$key]) : $_GET[$key]) : $defaultValue));
283
 
284
  if (is_string($ret) === true && $withcode === false) {
285
  $ret = sanitize_text_field($ret);
294
  * @param string $key
295
  * @return boolean
296
  */
297
+ public static function getIsset($key)
298
+ {
299
+ if (!isset($key) OR empty($key) OR !is_string($key))
300
  return false;
301
  return isset($_POST[$key]) ? true : (isset($_GET[$key]) ? true : false);
302
  }
306
  *
307
  * @return void
308
  */
309
+ public static function showNotices($message, $type = 'sq_notices')
310
+ {
311
  if (file_exists(_SQ_THEME_DIR_ . 'SQ_notices.php')) {
312
  ob_start();
313
+ include(_SQ_THEME_DIR_ . 'SQ_notices.php');
314
  $message = ob_get_contents();
315
  ob_end_clean();
316
  }
321
  /**
322
  * Load the multilanguage support from .mo
323
  */
324
+ private function loadMultilanguage()
325
+ {
326
  if (!defined('WP_PLUGIN_DIR')) {
327
  load_plugin_textdomain(_SQ_PLUGIN_NAME_, _SQ_PLUGIN_NAME_ . '/languages/');
328
  } else {
333
  /**
334
  * Connect remote with CURL if exists
335
  */
336
+ public static function sq_remote_get($url, $param = array(), $options = array())
337
+ {
338
  $parameters = '';
339
  $cookies = array();
340
  $cookie_string = '';
341
 
342
  $url_domain = parse_url($url);
343
+ if (isset($url_domain['host'])) {
344
+ $url_domain = $url_domain['host'];
345
+ } else {
346
+ $url_domain = '';
347
+ }
348
 
349
+ if (isset($param)) {
350
  foreach ($param as $key => $value) {
351
+ if (isset($key) && $key <> '' && $key <> 'timeout') {
352
  $parameters .= ($parameters == "" ? "" : "&") . $key . "=" . $value;
353
+ }
354
  }
355
+ }
356
+
357
+ if ($parameters <> '') {
358
  $url .= ((strpos($url, "?") === false) ? "?" : "&") . $parameters;
359
+ }
360
 
361
  //send the cookie for preview
362
+ $server_domain = '';
363
+ if (isset($_SERVER['HTTP_HOST'])) {
364
+ $server_domain = $_SERVER['HTTP_HOST'];
365
+ } elseif (isset($_SERVER['SERVER_NAME'])) {
366
+ $server_domain = $_SERVER['SERVER_NAME'];
367
+ }
368
+
369
+ if ($url_domain == $server_domain && strpos($url, 'preview=true') !== false) {
370
  foreach ($_COOKIE as $name => $value) {
371
  if (strpos($name, 'wordpress') !== false || strpos($name, 'wp') !== false || strpos($name, 'slimstat') !== false || strpos($name, 'sforum') !== false) {
372
  $cookies[] = new WP_Http_Cookie(array('name' => $name, 'value' => $value));
382
  }
383
  $options['sslverify'] = false;
384
 
385
+ if (!$response = self::sq_wpcall($url, $options, 'get')) {
386
  if (function_exists('curl_init') && !ini_get('safe_mode') && !ini_get('open_basedir')) {
387
+ $response = self::sq_curl($url, $options, 'get');
388
+ } else {
389
+ return false;
390
+ }
391
+ }
392
+
393
+ return $response;
394
+ }
395
+
396
+ /**
397
+ * Connect remote with CURL if exists
398
+ */
399
+ public static function sq_remote_post($url, $param = array(), $options = array())
400
+ {
401
+ $parameters = '';
402
+ $cookies = array();
403
+ $cookie_string = '';
404
+
405
+ $url_domain = parse_url($url);
406
+ if (isset($url_domain['host'])) {
407
+ $url_domain = $url_domain['host'];
408
+ } else {
409
+ $url_domain = '';
410
+ }
411
+
412
+ if (isset($param)) {
413
+ foreach ($param as $key => $value) {
414
+ if (isset($key) && $key <> '' && $key <> 'timeout') {
415
+ $parameters .= ($parameters == "" ? "" : "&") . $key . "=" . $value;
416
+ }
417
+ }
418
+ }
419
+
420
+ if ($parameters <> '') {
421
+ $url .= ((strpos($url, "?") === false) ? "?" : "&") . $parameters;
422
+ }
423
+
424
+ //send the cookie for preview
425
+ $server_domain = '';
426
+ if (isset($_SERVER['HTTP_HOST'])) {
427
+ $server_domain = $_SERVER['HTTP_HOST'];
428
+ } elseif (isset($_SERVER['SERVER_NAME'])) {
429
+ $server_domain = $_SERVER['SERVER_NAME'];
430
+ }
431
+
432
+ if ($url_domain == $server_domain && strpos($url, 'preview=true') !== false) {
433
+ foreach ($_COOKIE as $name => $value) {
434
+ $cookies[] = new WP_Http_Cookie(array('name' => $name, 'value' => $value));
435
+ $cookie_string .= "$name=$value;";
436
+ }
437
+ }
438
+
439
+ $options['timeout'] = (isset($options['timeout'])) ? $options['timeout'] : 30;
440
+ if (!isset($options['cookie_string'])) {
441
+ $options['cookies'] = $cookies;
442
+ $options['cookie_string'] = $cookie_string;
443
+ }
444
+ $options['sslverify'] = false;
445
+
446
+ if (!$response = self::sq_wpcall($url, $options, 'post')) {
447
+ if (function_exists('curl_init') && !ini_get('safe_mode') && !ini_get('open_basedir')) {
448
+ $response = self::sq_curl($url, $options, 'post');
449
  } else {
450
  return false;
451
  }
460
  * @param array $param
461
  * @return string
462
  */
463
+ private static function sq_curl($url, $options, $method = 'get')
464
+ {
465
 
466
  $ch = curl_init();
467
  curl_setopt($ch, CURLOPT_URL, $url);
468
  curl_setopt($ch, CURLOPT_HEADER, false);
469
  //--
470
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
471
+
472
  //--
473
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
474
  curl_setopt($ch, CURLOPT_TIMEOUT, $options['timeout']);
475
 
476
+ if ($method == 'post') {
477
+ curl_setopt($ch, CURLOPT_POST, 1);
478
+ }
479
+
480
+ if (isset($options['sslverify'])) {
481
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
482
+ } else {
483
+ curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
484
+ }
485
+
486
  if (isset($options['followlocation'])) {
487
  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
488
  curl_setopt($ch, CURLOPT_MAXREDIRS, 1);
498
  $response = curl_exec($ch);
499
  $response = self::cleanResponce($response);
500
 
501
+ self::dump('CURL', $method, $url, $options, $ch, $response); //output debug
502
 
503
  if (curl_errno($ch) == 1 || $response === false) { //if protocol not supported
504
  if (curl_errno($ch)) {
519
  * @param array $param
520
  * @return string
521
  */
522
+ private static function sq_wpcall($url, $options, $method = 'get')
523
+ {
524
+ if ($method == 'post') {
525
+ $response = wp_remote_post($url, $options);
526
+ } else {
527
+ $response = wp_remote_get($url, $options);
528
+ }
529
  if (is_wp_error($response)) {
530
  self::dump($response);
531
  return false;
532
  }
533
 
534
  $response = self::cleanResponce(wp_remote_retrieve_body($response)); //clear and get the body
535
+ self::dump('wp_remote_get', $method, $url, $options, $response); //output debug
536
  return $response;
537
  }
538
 
539
  /**
540
  * Connect remote with CURL if exists
541
  */
542
+ public static function sq_remote_head($url)
543
+ {
544
  $response = array();
545
 
546
  if (function_exists('curl_exec')) {
566
  * @param string $response
567
  * @return string
568
  */
569
+ private static function cleanResponce($response)
570
+ {
571
 
572
  if (function_exists('substr_count'))
573
  if (substr_count($response, '(') > 1)
582
  /**
583
  * Check for SEO blog bad settings
584
  */
585
+ public static function checkErrorSettings($count_only = false)
586
+ {
587
  if (current_user_can('manage_options')) {
588
 
589
  $fixit = "<a href=\"javascript:void(0);\" onclick=\"%s jQuery(this).closest('div').fadeOut('slow'); if(parseInt(jQuery('.sq_count').html())>0) { var notif = (parseInt(jQuery('.sq_count').html()) - 1); if (notif > 0) {jQuery('.sq_count').html(notif); }else{ jQuery('.sq_count').html(notif); jQuery('.sq_count').hide(); } } jQuery.post(ajaxurl, { action: '%s', nonce: '" . wp_create_nonce(_SQ_NONCE_ID_) . "'});\" >" . __("Fix it for me!", _SQ_PLUGIN_NAME_) . "</a>";
590
 
591
  /* IF SEO INDEX IS OFF */
592
  if (self::getAutoSeoSquirrly()) {
593
+ self::$errors_count++;
594
  if (!$count_only) {
595
  SQ_Error::setError(__('Activate the Squirrly SEO for your blog (recommended)', _SQ_PLUGIN_NAME_) . " <br />" . sprintf($fixit, "jQuery('#sq_use_on').trigger('click');", "sq_fixautoseo") . "", 'settings', 'sq_fix_auto');
596
  }
601
  if (self::$source_code <> '') {
602
  /* IF TITLE DUPLICATES */
603
  if (self::getDuplicateTitle()) {
604
+ self::$errors_count++;
605
  if (!$count_only) {
606
  SQ_Error::setError(__('You have META Title Duplicates. Disable the Squirrly Title Optimization or disable the other SEO Plugins', _SQ_PLUGIN_NAME_) . " <br />" . sprintf($fixit, "jQuery('#sq_auto_title0').attr('checked', true); jQuery('#sq_automatically').attr('checked', true);", "sq_fix_titleduplicate") . "", 'settings', 'sq_fix_descduplicate');
607
  }
609
 
610
  /* IF DESCRIPTION DUPLICATES */
611
  if (self::getDuplicateDescription()) {
612
+ self::$errors_count++;
613
  if (!$count_only) {
614
  SQ_Error::setError(__('You have META Description Duplicates. Disable the Squirrly Description Optimization or disable the other SEO Plugins', _SQ_PLUGIN_NAME_) . " <br />" . sprintf($fixit, "jQuery('#sq_auto_description0').attr('checked', true); jQuery('#sq_automatically').attr('checked', true);", "sq_fix_descduplicate") . "", 'settings', 'sq_fix_descduplicate');
615
  }
617
 
618
  /* IF OG DUPLICATES */
619
  if (self::getDuplicateOG()) {
620
+ self::$errors_count++;
621
  if (!$count_only) {
622
  SQ_Error::setError(__('You have Open Graph META Duplicates. Disable the Squirrly SEO Open Graph or disable the other SEO Plugins', _SQ_PLUGIN_NAME_) . " <br />" . sprintf($fixit, "jQuery('#sq_auto_facebook0').attr('checked', true);", "sq_fix_ogduplicate") . "", 'settings', 'sq_fix_ogduplicate');
623
  }
625
 
626
  /* IF TWITTER CARD DUPLICATES */
627
  if (self::getDuplicateTC()) {
628
+ self::$errors_count++;
629
  if (!$count_only) {
630
  SQ_Error::setError(__('You have Twitter Card META Duplicates. Disable the Squirrly SEO Twitter Card or disable the other SEO Plugins', _SQ_PLUGIN_NAME_) . " <br />" . sprintf($fixit, "jQuery('#sq_auto_twitter0').attr('checked', true);", "sq_fix_tcduplicate") . "", 'settings', 'sq_fix_tcduplicate');
631
  }
660
  * Check if the automatically seo si active
661
  * @return bool
662
  */
663
+ private static function getAutoSeoSquirrly()
664
+ {
665
  if (isset(self::$options['sq_use']))
666
+ return ((int)self::$options['sq_use'] == 0);
667
 
668
  return true;
669
  }
672
  * Check for META duplicates
673
  * @return boolean
674
  */
675
+ private static function getDuplicateOG()
676
+ {
677
  if (!function_exists('preg_match_all')) {
678
  return false;
679
  }
695
  * Check for META duplicates
696
  * @return boolean
697
  */
698
+ private static function getDuplicateTC()
699
+ {
700
  if (!function_exists('preg_match_all')) {
701
  return false;
702
  }
718
  * Check for META duplicates
719
  * @return boolean
720
  */
721
+ private static function getDuplicateDescription()
722
+ {
723
  if (!function_exists('preg_match_all')) {
724
  return false;
725
  }
745
  * Check for META duplicates
746
  * @return boolean
747
  */
748
+ private static function getDuplicateTitle()
749
+ {
750
  if (!function_exists('preg_match_all')) {
751
  return false;
752
  }
772
  * Check if the blog is in private mode
773
  * @return bool
774
  */
775
+ public static function getPrivateBlog()
776
+ {
777
+ return ((int)get_option('blog_public') == 0);
778
  }
779
 
780
  /**
781
  * Check if the blog has a bad link structure
782
  * @return bool
783
  */
784
+ private static function getBadLinkStructure()
785
+ {
786
  global $wp_rewrite;
787
  if (function_exists('apache_get_modules')) {
788
  //Check if mod_rewrite is installed in apache
806
  * @param string $in
807
  * @return string $in localized
808
  */
809
+ public static function i18n($in)
810
+ {
811
  if (function_exists('langswitch_filter_langs_with_message')) {
812
  $in = langswitch_filter_langs_with_message($in);
813
  }
828
  * @param int $decimals Precision of the number of decimal places.
829
  * @return string Converted number in string format.
830
  */
831
+ public static function i18n_number_format($number, $decimals = 0)
832
+ {
833
  global $wp_locale;
834
  $formatted = number_format($number, absint($decimals), $wp_locale->number_format['decimal_point'], $wp_locale->number_format['thousands_sep']);
835
  return apply_filters('number_format_i18n', $formatted);
836
  }
837
 
838
+ public static function getBrowserInfo()
839
+ {
840
  $ub = '';
841
  $u_agent = $_SERVER['HTTP_USER_AGENT'];
842
  $bname = 'Unknown';
901
  * @param string $url
902
  * @return array
903
  */
904
+ public static function getSnippet($url)
905
+ {
906
+ if ($url == '' || !function_exists('preg_match')) {
907
  return;
908
+ }
909
+
910
  $snippet = array();
911
+ $frontend = SQ_ObjController::getModel('SQ_Frontend');
912
+
913
+ $postid = url_to_postid($url);
914
+ if ($postid > 0) {
915
+ $frontend->setPost(get_post($postid));
916
+ $snippet['title'] = $frontend->getTitle();
917
+ $snippet['description'] = $frontend->getDescription();
918
+ $snippet['url'] = $url;
919
+ self::dump($snippet);
920
+ } else {
921
+ $length = array('title' => 66,
922
+ 'description' => 240,
923
+ 'url' => 45);
924
 
925
+ self::$source_code = self::sq_remote_get($url, array(), array('timeout' => 10, 'followlocation' => true));
926
 
927
+ $title_regex = "/<title[^>]*>([^<>]*)<\/title>/si";
928
+ preg_match($title_regex, self::$source_code, $title);
929
 
930
+ if (is_array($title) && count($title) > 0) {
931
+ $snippet['title'] = $title[1];
932
+ $snippet['title'] = self::i18n(trim(strip_tags($snippet['title'])));
933
+ }
934
 
935
+ $description_regex = '/<meta[^>]*(name|property)=["\']description["\'][^>]*content="([^"<>]+)"[^<>]*>/si';
936
+ preg_match($description_regex, self::$source_code, $description);
937
+ if (is_array($description) && count($description) > 0) {
938
+ $snippet['description'] = self::i18n(trim(strip_tags($description[2])));
939
 
940
+ if (strlen($snippet['description']) > $length['description'])
941
+ $snippet['description'] = substr($snippet['description'], 0, ($length['description'] - 1)) . '...';
942
+ }
943
 
944
+ $snippet['url'] = $url;
945
+ if (strlen($snippet['url']) > $length['url'])
946
+ $snippet['url'] = substr($snippet['url'], 0, ($length['url'] - 1)) . '...';
947
+
948
+ }
949
 
950
  return $snippet;
951
+
952
  }
953
 
954
  /**
955
  * Check if debug is called
956
  */
957
+ private function checkDebug()
958
+ {
959
  //if debug is called
960
  if (self::getIsset('sq_debug')) {
961
  if (self::getValue('sq_debug') == self::$options['sq_api']) {
975
  /**
976
  * Store the debug for a later view
977
  */
978
+ public static function dump()
979
+ {
980
  if (self::getValue('sq_debug') !== 'on') {
981
  return;
982
  }
992
 
993
  $run_time = number_format(microtime(true) - REQUEST_TIME, 3);
994
  if (function_exists('debug_backtrace'))
995
+ list($callee) = debug_backtrace();
996
 
997
  $output .= '<fieldset style="background: #FFFFFF; border: 1px #CCCCCC solid; padding: 5px; font-size: 9pt; margin: 0;">';
998
  $output .= '<legend style="background: #EEEEEE; padding: 2px; font-size: 8pt;">' . $callee['file'] . ' Time: ' . $run_time . ' @ line: ' . $callee['line']
999
+ . '</legend><pre style="margin: 0; font-size: 8pt; text-align: left;">';
1000
 
1001
  $i = 0;
1002
  foreach ($arguments as $argument) {
1003
  if (count($arguments) > 1)
1004
+ $output .= "\n" . '<strong>#' . (++$i) . ' of ' . $total_arguments . '</strong>: ';
1005
 
1006
  // if argument is boolean, false value does not display, so ...
1007
  if (is_bool($argument))
1008
+ $argument = ($argument) ? 'TRUE' : 'FALSE';
1009
  else
1010
+ if (is_object($argument) && function_exists('array_reverse') && function_exists('class_parents'))
1011
+ $output .= implode("\n" . '|' . "\n", array_reverse(class_parents($argument))) . "\n" . '|' . "\n";
1012
 
1013
  $output .= htmlspecialchars(print_r($argument, TRUE))
1014
+ . ((is_object($argument) && function_exists('spl_object_hash')) ? spl_object_hash($argument) : '');
1015
  }
1016
  $output .= "</pre>";
1017
  $output .= "</fieldset>";
1022
  /**
1023
  * Show the debug dump
1024
  */
1025
+ public static function showDebug()
1026
+ {
1027
+ global $wp_query;
1028
  echo "Debug result: <br />" . '<div id="wpcontent">' . @implode('<br />', self::$debug) . '</div>';
1029
 
1030
  $run_time = number_format(microtime(true) - REQUEST_TIME, 3);
1031
  $pps = number_format(1 / $run_time, 0);
1032
  $memory_avail = ini_get('memory_limit');
1033
+ $memory_used = number_format(memory_get_usage(true) / (1024 * 1024), 2);
1034
+ $memory_peak = number_format(memory_get_peak_usage(true) / (1024 * 1024), 2);
1035
 
1036
  echo PHP_EOL . " Load: {$memory_avail} (avail) / {$memory_used}M (used) / {$memory_peak}M (peak)";
1037
  echo " | Time: {$run_time}s | {$pps} req/sec";
1038
+ echo "<pre>" . print_r($wp_query, true) . "</pre>";
1039
  }
1040
 
1041
+ public function sq_activate()
1042
+ {
1043
  set_transient('sq_activate', true);
1044
  set_transient('sq_rewrite', true);
1045
  }
1046
 
1047
+ public function sq_deactivate()
1048
+ {
1049
  //clear the cron job
1050
  wp_clear_scheduled_hook('sq_processCron');
1051
 
1053
  $args['type'] = 'deact';
1054
  SQ_Action::apiCall('sq/user/log', $args, 5);
1055
 
1056
+ remove_filter('rewrite_rules_array', array(SQ_ObjController::getBlock('SQ_BlockSettingsSeo'), 'rewrite_rules'));
1057
  global $wp_rewrite;
1058
  $wp_rewrite->flush_rules();
1059
  }
1060
 
1061
+ public static function emptyCache($post_id = null)
1062
+ {
1063
  if (function_exists('w3tc_pgcache_flush')) {
1064
  w3tc_pgcache_flush();
1065
  }
1076
  }
1077
  }
1078
 
1079
+ public static function checkUpgrade()
1080
+ {
1081
  if (self::$options['sq_ver'] == 0 || self::$options['sq_ver'] < SQ_VERSION_ID) {
1082
  //Delete the old versions table
1083
  global $wpdb;
1088
  $wpdb->query("UPDATE " . $wpdb->postmeta . " SET `meta_key` = '_sq_post_keyword' WHERE `meta_key` = 'sq_post_keyword'");
1089
 
1090
  self::saveOptions('sq_ver', SQ_VERSION_ID);
1091
+
1092
+ global $wp_rewrite;
1093
+ $wp_rewrite->flush_rules();
1094
  }
1095
  }
1096
 
controllers/SQ_Feed.php ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * Class for Sitemap Generator
5
+ */
6
+ class SQ_Feed extends SQ_FrontController {
7
+ /* @var string post limit */
8
+
9
+ var $posts_limit = 10000;
10
+
11
+ public function __construct() {
12
+ parent::__construct();
13
+ add_filter('template_redirect', array($this, 'hookPreventRedirect'), 1, 0);
14
+ }
15
+
16
+ public function hookPreventRedirect() {
17
+ global $wp_query;
18
+ if (!empty($wp_query->query_vars["feed"])) {
19
+ $wp_query->is_404 = false;
20
+ $wp_query->is_feed = true;
21
+
22
+ add_filter('feed_content_type', array($this, 'feedHeader'), 10, 2);
23
+ add_action('rss_tag_pre', array($this, 'feedStyle'));
24
+ add_action('rss2_head', array($this, 'feedCss'));
25
+ add_filter('the_content', array($this, 'addFeedMedia'));
26
+ }
27
+ }
28
+
29
+ public function feedCss() {
30
+ echo "\t" . '<feedcss>' . _SQ_THEME_URL_ . 'css/' . 'sq_feed.css</feedcss>' . "\n";
31
+ }
32
+
33
+ public function feedStyle() {
34
+ echo '<?xml-stylesheet type="text/xsl" href="' . _SQ_THEME_URL_ . 'css/' . 'sq_feed.xsl' . '"?>';
35
+ }
36
+
37
+ public function feedHeader($content_type, $type) {
38
+ if (empty($type)) {
39
+ $type = get_default_feed();
40
+ }
41
+
42
+ $types = array(
43
+ 'rss' => ' text/xml',
44
+ 'rss2' => ' text/xml'
45
+ );
46
+ $content_type = (!empty($types[$type]) ) ? $types[$type] : $content_type;
47
+
48
+ return $content_type;
49
+ }
50
+
51
+ public function addFeedMedia($content) {
52
+ global $post;
53
+ if (has_post_thumbnail($post->ID)) {
54
+ $attachment = get_post(get_post_thumbnail_id($post->ID));
55
+ $thumb = wp_get_attachment_image_src($attachment->ID, 'large');
56
+ $content = '<div class="thumbnail">
57
+ <a href="' . get_permalink($post->ID) . '">
58
+ <img src="' . esc_url($thumb[0]) . '" alt="' . get_the_title($post->ID) . '">
59
+ </a>
60
+ </div>' . $content;
61
+ }
62
+ return $content;
63
+ }
64
+
65
+ function featuredtoRSS($content) {
66
+ global $post;
67
+ if (has_post_thumbnail($post->ID)) {
68
+ $content = '<div>' . get_the_post_thumbnail($post->ID, 'medium') . '</div>' . $content;
69
+ }
70
+ return $content;
71
+ }
72
+
73
+ public function refreshSitemap($new_status, $old_status, $post) {
74
+ if ($old_status <> $new_status && $new_status = 'publish') {
75
+ if (SQ_Tools::$options['sq_sitemap_ping'] == 1) {
76
+ wp_schedule_single_event(time() + 5, 'sq_processPing');
77
+ }
78
+ }
79
+ }
80
+
81
+ }
controllers/SQ_Frontend.php CHANGED
@@ -6,24 +6,38 @@ class SQ_Frontend extends SQ_FrontController {
6
 
7
  public function __construct() {
8
 
9
- if ($this->_isAjax())
10
  return;
 
11
 
12
  parent::__construct();
13
  SQ_ObjController::getController('SQ_Tools', false);
14
 
15
-
16
  if (SQ_Tools::$options['sq_use'] == 1) {
17
  /* Check if sitemap is on */
18
  if (SQ_Tools::$options['sq_auto_sitemap'] == 1) {
19
  /* Load the Sitemap */
 
20
  SQ_ObjController::getController('SQ_Sitemaps');
21
  }
22
 
 
 
 
 
 
23
  //validate custom arguments for favicon and sitemap
24
  add_filter('query_vars', array($this, 'validateParams'), 1, 1);
25
- add_action('template_redirect', array($this, 'startBuffer'), 10);
26
 
 
 
 
 
 
 
 
 
 
27
 
28
  if (SQ_Tools::$options['sq_url_fix'] == 1) {
29
  add_action('the_content', array($this, 'fixFeedLinks'), 11);
@@ -31,6 +45,15 @@ class SQ_Frontend extends SQ_FrontController {
31
  }
32
  }
33
 
 
 
 
 
 
 
 
 
 
34
  private function _isAjax() {
35
  if (isset($_SERVER['PHP_SELF']) && strpos($_SERVER['PHP_SELF'], '/admin-ajax.php') !== false)
36
  return true;
@@ -38,16 +61,18 @@ class SQ_Frontend extends SQ_FrontController {
38
  return false;
39
  }
40
 
41
- public function startBuffer() {
42
- if ($this->_isAjax()) {
43
- return;
44
- }
45
 
46
- if (SQ_Tools::$options['sq_use'] == 1) {
47
- add_filter('sq_title', array($this->model, 'clearTitle'));
48
- add_filter('sq_description', array($this->model, 'clearDescription'));
49
- //Use buffer only for meta Title
50
- $this->model->startBuffer();
 
 
51
  }
52
  }
53
 
@@ -68,26 +93,6 @@ class SQ_Frontend extends SQ_FrontController {
68
  }
69
  }
70
 
71
- /**
72
- * Hook the Header load
73
- */
74
- public function hookFronthead() {
75
- if ($this->_isAjax())
76
- return;
77
-
78
- echo $this->model->setStart();
79
-
80
- if (SQ_Tools::$options['sq_use'] == 1) {
81
- //flush the header with the title and removing duplicates
82
- $this->model->flushHeader();
83
- //show the Squirrly header
84
- echo $this->model->setHeader();
85
- }
86
-
87
- SQ_ObjController::getController('SQ_DisplayController', false)
88
- ->loadMedia(_SQ_THEME_URL_ . 'css/sq_frontend.css');
89
- }
90
-
91
  /**
92
  * Change the image path to absolute when in feed
93
  */
@@ -122,12 +127,16 @@ class SQ_Frontend extends SQ_FrontController {
122
  }
123
  }
124
  }
125
- if (!is_array($urls) || (is_array($urls) && empty($urls)))
126
  return $content;
 
127
 
 
128
  foreach ($urls as $url) {
129
- $find[] = $url;
130
- $replace[] = get_bloginfo('url') . $url;
 
 
131
  }
132
  if (!empty($find) && !empty($replace)) {
133
  $content = str_replace($find, $replace, $content);
@@ -144,34 +153,46 @@ class SQ_Frontend extends SQ_FrontController {
144
  * @return $vars
145
  */
146
  public function validateParams($vars) {
147
- $vars[] = 'sq_get';
148
- $vars[] = 'sq_size';
 
149
  return $vars;
150
  }
151
 
152
  public function action() {
 
 
 
153
 
154
- switch (get_query_var('sq_get')) {
155
- case 'favicon':
156
- if (SQ_Tools::$options['favicon'] <> '') {
157
- //show the favico file
158
- SQ_Tools::setHeader('ico');
159
- readfile(_SQ_CACHE_DIR_ . SQ_Tools::$options['favicon']);
160
- exit();
161
- }
162
- break;
163
- case 'touchicon':
164
- $size = get_query_var('sq_size');
165
- if (SQ_Tools::$options['favicon'] <> '') {
166
- //show the favico file
167
- SQ_Tools::setHeader('png');
168
- if ($size <> '') {
169
- readfile(_SQ_CACHE_DIR_ . SQ_Tools::$options['favicon'] . get_query_var('sq_size'));
170
- } else {
171
  readfile(_SQ_CACHE_DIR_ . SQ_Tools::$options['favicon']);
 
172
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
173
  exit();
174
- }
 
175
  }
176
  }
177
 
6
 
7
  public function __construct() {
8
 
9
+ if ($this->_isAjax()) {
10
  return;
11
+ }
12
 
13
  parent::__construct();
14
  SQ_ObjController::getController('SQ_Tools', false);
15
 
 
16
  if (SQ_Tools::$options['sq_use'] == 1) {
17
  /* Check if sitemap is on */
18
  if (SQ_Tools::$options['sq_auto_sitemap'] == 1) {
19
  /* Load the Sitemap */
20
+ add_filter('rewrite_rules_array', array($this, 'rewrite_rules'), 1, 1);
21
  SQ_ObjController::getController('SQ_Sitemaps');
22
  }
23
 
24
+ if (SQ_Tools::$options['sq_auto_feed'] == 1) {
25
+ /* Load the Feed Style */
26
+ SQ_ObjController::getController('SQ_Feed');
27
+ }
28
+
29
  //validate custom arguments for favicon and sitemap
30
  add_filter('query_vars', array($this, 'validateParams'), 1, 1);
 
31
 
32
+ if (!$this->_isAjax()) {
33
+ add_filter('sq_title', array($this->model, 'clearTitle'));
34
+ add_filter('sq_description', array($this->model, 'clearDescription'));
35
+
36
+ add_action('plugins_loaded', array($this->model, 'startBuffer'));
37
+ //flush the header with the title and removing duplicates
38
+ add_action('wp_head', array($this->model, 'flushHeader'),99);
39
+ add_action('shutdown', array($this->model, 'flushHeader'));
40
+ }
41
 
42
  if (SQ_Tools::$options['sq_url_fix'] == 1) {
43
  add_action('the_content', array($this, 'fixFeedLinks'), 11);
45
  }
46
  }
47
 
48
+ public function rewrite_rules($wp_rewrite) {
49
+ if (SQ_Tools::$options['sq_auto_sitemap'] == 1) {
50
+ foreach (SQ_Tools::$options['sq_sitemap'] as $name => $sitemap) {
51
+ $rules[preg_quote($sitemap[0]) . '$'] = 'index.php?sq_feed=' . $name;
52
+ }
53
+ }
54
+ return array_merge($rules, $wp_rewrite);
55
+ }
56
+
57
  private function _isAjax() {
58
  if (isset($_SERVER['PHP_SELF']) && strpos($_SERVER['PHP_SELF'], '/admin-ajax.php') !== false)
59
  return true;
61
  return false;
62
  }
63
 
64
+ /**
65
+ * Hook the Header load
66
+ */
67
+ public function hookFronthead() {
68
 
69
+ if (!$this->_isAjax()) {
70
+ if (SQ_Tools::$options['sq_use'] == 1) {
71
+ echo $this->model->setStartTag();
72
+ }
73
+
74
+ SQ_ObjController::getController('SQ_DisplayController', false)
75
+ ->loadMedia(_SQ_THEME_URL_ . 'css/sq_frontend.css');
76
  }
77
  }
78
 
93
  }
94
  }
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  /**
97
  * Change the image path to absolute when in feed
98
  */
127
  }
128
  }
129
  }
130
+ if (!is_array($urls) || (is_array($urls) && empty($urls))) {
131
  return $content;
132
+ }
133
 
134
+ $urls = array_unique($urls);
135
  foreach ($urls as $url) {
136
+ $find[] = "'" . $url . "'";
137
+ $replace[] = "'" . esc_url(get_bloginfo('url') . $url) . "'";
138
+ $find[] = '"' . $url . '"';
139
+ $replace[] = '"' . esc_url(get_bloginfo('url') . $url) . '"';
140
  }
141
  if (!empty($find) && !empty($replace)) {
142
  $content = str_replace($find, $replace, $content);
153
  * @return $vars
154
  */
155
  public function validateParams($vars) {
156
+ array_push($vars, 'sq_feed');
157
+ array_push($vars, 'sq_get');
158
+ array_push($vars, 'sq_size');
159
  return $vars;
160
  }
161
 
162
  public function action() {
163
+ global $wp_query;
164
+ if (!empty($wp_query->query_vars["sq_get"])) {
165
+ $wp_query->is_404 = false;
166
 
167
+
168
+ switch (get_query_var('sq_get')) {
169
+ case 'favicon':
170
+ if (SQ_Tools::$options['favicon'] <> '') {
171
+ //show the favico file
172
+ SQ_Tools::setHeader('ico');
 
 
 
 
 
 
 
 
 
 
 
173
  readfile(_SQ_CACHE_DIR_ . SQ_Tools::$options['favicon']);
174
+ exit();
175
  }
176
+ break;
177
+ case 'touchicon':
178
+ $size = get_query_var('sq_size');
179
+ if (SQ_Tools::$options['favicon'] <> '') {
180
+ //show the favico file
181
+ SQ_Tools::setHeader('png');
182
+ if ($size <> '') {
183
+ readfile(_SQ_CACHE_DIR_ . SQ_Tools::$options['favicon'] . get_query_var('sq_size'));
184
+ } else {
185
+ readfile(_SQ_CACHE_DIR_ . SQ_Tools::$options['favicon']);
186
+ }
187
+ exit();
188
+ }
189
+ break;
190
+
191
+ case 'feedcss':
192
+ readfile(_SQ_THEME_DIR_ . 'css/' . 'sq_feed.css');
193
  exit();
194
+ break;
195
+ }
196
  }
197
  }
198
 
controllers/SQ_Post.php CHANGED
@@ -1,6 +1,7 @@
1
  <?php
2
 
3
- class SQ_Post extends SQ_FrontController {
 
4
 
5
  public $saved;
6
 
@@ -9,7 +10,8 @@ class SQ_Post extends SQ_FrontController {
9
  *
10
  * @return void
11
  */
12
- public function hookInit() {
 
13
  $this->saved = array();
14
 
15
  add_filter('tiny_mce_before_init', array($this->model, 'setCallback'));
@@ -19,7 +21,7 @@ class SQ_Post extends SQ_FrontController {
19
  if (SQ_Tools::$options['sq_api'] == '')
20
  return;
21
 
22
- add_action('save_post', array($this, 'hookSavePost'), 11);
23
  add_action('shopp_product_saved', array($this, 'hookShopp'), 11);
24
 
25
  if (SQ_Tools::$options['sq_use'] == 1 && SQ_Tools::$options['sq_auto_sitemap'] == 1) {
@@ -32,7 +34,8 @@ class SQ_Post extends SQ_FrontController {
32
  *
33
  * @global integer $post_ID
34
  */
35
- public function hookHead() {
 
36
  global $post_ID;
37
  parent::hookHead();
38
 
@@ -42,10 +45,10 @@ class SQ_Post extends SQ_FrontController {
42
  *
43
  * Set the global variable $sq_postID for cookie and keyword record
44
  */
45
- if ((int) $post_ID == 0) {
46
  if (SQ_Tools::getIsset('id'))
47
- $GLOBALS['sq_postID'] = (int) SQ_Tools::getValue('id');
48
- }else {
49
  $GLOBALS['sq_postID'] = $post_ID;
50
  }
51
  /* * ****************************** */
@@ -56,7 +59,8 @@ class SQ_Post extends SQ_FrontController {
56
  /**
57
  * Hook the Shopp plugin save product
58
  */
59
- public function hookShopp($Product) {
 
60
  $this->checkSeo($Product->id);
61
  }
62
 
@@ -64,20 +68,23 @@ class SQ_Post extends SQ_FrontController {
64
  * Hook the post save/update
65
  * @param type $post_id
66
  */
67
- public function hookSavePost($post_id) {
 
 
68
 
69
- $file_name = false;
70
- if (!isset($this->saved[$post_id]))
71
  $this->saved[$post_id] = false;
 
72
 
73
  // unhook this function so it doesn't loop infinitely
74
- remove_action('save_post', array($this, 'hookSavePost'), 11);
75
  //If the post is a new or edited post
76
  if ((SQ_Tools::getValue('action')) == 'editpost' &&
77
- wp_is_post_autosave($post_id) == '' &&
78
- get_post_status($post_id) != 'auto-draft' &&
79
- get_post_status($post_id) != 'inherit' &&
80
- SQ_Tools::getValue('autosave') == '') {
 
81
 
82
  if ($this->saved[$post_id] === false) {
83
  //check for custom SEO
@@ -91,7 +98,7 @@ class SQ_Post extends SQ_FrontController {
91
  }
92
 
93
 
94
- add_action('save_post', array($this, 'hookSavePost'), 11);
95
  }
96
 
97
  /**
@@ -100,7 +107,8 @@ class SQ_Post extends SQ_FrontController {
100
  * @param integer $post_id
101
  * @return false|void
102
  */
103
- public function checkImage($post_id) {
 
104
 
105
  //if the option to save the images locally is set on
106
  if (SQ_Tools::$options['sq_local_images'] == 1) {
@@ -125,7 +133,8 @@ class SQ_Post extends SQ_FrontController {
125
 
126
  foreach ($out[1] as $row) {
127
  if (strpos($row, '//') !== false &&
128
- strpos($row, $domain['host']) === false) {
 
129
  if (!in_array($row, $urls)) {
130
  $urls[] = $row;
131
  }
@@ -143,6 +152,7 @@ class SQ_Post extends SQ_FrontController {
143
  $time = microtime(true);
144
  foreach ($urls as $url) {
145
  if ($file = $this->model->upload_image($url)) {
 
146
  if (!file_is_valid_image($file['file']))
147
  continue;
148
 
@@ -156,7 +166,7 @@ class SQ_Post extends SQ_FrontController {
156
  'post_content' => urldecode(SQ_Tools::getValue('sq_fp_title', '')),
157
  'post_status' => 'inherit',
158
  'guid' => $local_file
159
- ), $file['file'], $post_id);
160
 
161
  $attach_data = wp_generate_attachment_metadata($attach_id, $file['file']);
162
  wp_update_attachment_metadata($attach_id, $attach_data);
@@ -170,8 +180,8 @@ class SQ_Post extends SQ_FrontController {
170
 
171
  if ($local_file !== false) {
172
  wp_update_post(array(
173
- 'ID' => $post_id,
174
- 'post_content' => $content)
175
  );
176
  }
177
  }
@@ -183,7 +193,8 @@ class SQ_Post extends SQ_FrontController {
183
  * @param integer $post_id
184
  * @param void
185
  */
186
- public function checkSeo($post_id, $status = '') {
 
187
  $args = array();
188
 
189
  $seo = SQ_Tools::getValue('sq_seo');
@@ -197,7 +208,7 @@ class SQ_Post extends SQ_FrontController {
197
  $args['permalink'] = get_permalink($post_id);
198
  $args['permalink'] = $this->getPaged($args['permalink']);
199
  $args['permalink'] = $args['permalink'];
200
- $args['author'] = (int) SQ_Tools::getUserID();
201
  $args['post_id'] = $post_id;
202
 
203
  $process = array();
@@ -220,7 +231,8 @@ class SQ_Post extends SQ_FrontController {
220
  }
221
  }
222
 
223
- public function getPaged($link) {
 
224
  $page = get_query_var('paged');
225
  if ($page && $page > 1) {
226
  $link = trailingslashit($link) . "page/" . "$page" . '/';
@@ -233,7 +245,8 @@ class SQ_Post extends SQ_FrontController {
233
  *
234
  * @return void
235
  */
236
- public function action() {
 
237
  parent::action();
238
 
239
  switch (SQ_Tools::getValue('action')) {
@@ -256,7 +269,7 @@ class SQ_Post extends SQ_FrontController {
256
  'post_content' => '',
257
  'post_status' => 'inherit',
258
  'guid' => $local_file
259
- ), $return['file'], SQ_Tools::getValue('post_id'));
260
 
261
  $attach_data = wp_generate_attachment_metadata($attach_id, $return['file']);
262
  wp_update_attachment_metadata($attach_id, $attach_data);
@@ -285,7 +298,8 @@ class SQ_Post extends SQ_FrontController {
285
  * @return array | false
286
  *
287
  */
288
- private function _checkAdvMeta($post_id) {
 
289
 
290
  $meta = array();
291
  if (SQ_Tools::getIsset('sq_canonical') || SQ_Tools::getIsset('sq_fp_title') || SQ_Tools::getIsset('sq_fp_description') || SQ_Tools::getIsset('sq_fp_keywords')) {
@@ -317,7 +331,8 @@ class SQ_Post extends SQ_FrontController {
317
  return false;
318
  }
319
 
320
- public function hookFooter() {
 
321
  if (!defined('DISABLE_WP_CRON') || DISABLE_WP_CRON == true) {
322
  global $pagenow;
323
  if (in_array($pagenow, array('post.php', 'post-new.php'))) {
@@ -326,7 +341,8 @@ class SQ_Post extends SQ_FrontController {
326
  }
327
  }
328
 
329
- public function processCron() {
 
330
  SQ_ObjController::getController('SQ_Tools', false);
331
  SQ_ObjController::getController('SQ_Action', false);
332
 
1
  <?php
2
 
3
+ class SQ_Post extends SQ_FrontController
4
+ {
5
 
6
  public $saved;
7
 
10
  *
11
  * @return void
12
  */
13
+ public function hookInit()
14
+ {
15
  $this->saved = array();
16
 
17
  add_filter('tiny_mce_before_init', array($this->model, 'setCallback'));
21
  if (SQ_Tools::$options['sq_api'] == '')
22
  return;
23
 
24
+ add_action('save_post', array($this, 'hookSavePost'), 99);
25
  add_action('shopp_product_saved', array($this, 'hookShopp'), 11);
26
 
27
  if (SQ_Tools::$options['sq_use'] == 1 && SQ_Tools::$options['sq_auto_sitemap'] == 1) {
34
  *
35
  * @global integer $post_ID
36
  */
37
+ public function hookHead()
38
+ {
39
  global $post_ID;
40
  parent::hookHead();
41
 
45
  *
46
  * Set the global variable $sq_postID for cookie and keyword record
47
  */
48
+ if ((int)$post_ID == 0) {
49
  if (SQ_Tools::getIsset('id'))
50
+ $GLOBALS['sq_postID'] = (int)SQ_Tools::getValue('id');
51
+ } else {
52
  $GLOBALS['sq_postID'] = $post_ID;
53
  }
54
  /* * ****************************** */
59
  /**
60
  * Hook the Shopp plugin save product
61
  */
62
+ public function hookShopp($Product)
63
+ {
64
  $this->checkSeo($Product->id);
65
  }
66
 
68
  * Hook the post save/update
69
  * @param type $post_id
70
  */
71
+ public function hookSavePost($post_id)
72
+ {
73
+
74
 
75
+ if (!isset($this->saved[$post_id])) {
 
76
  $this->saved[$post_id] = false;
77
+ }
78
 
79
  // unhook this function so it doesn't loop infinitely
80
+ remove_action('save_post', array($this, 'hookSavePost'), 99);
81
  //If the post is a new or edited post
82
  if ((SQ_Tools::getValue('action')) == 'editpost' &&
83
+ wp_is_post_autosave($post_id) == '' &&
84
+ get_post_status($post_id) != 'auto-draft' &&
85
+ get_post_status($post_id) != 'inherit' &&
86
+ SQ_Tools::getValue('autosave') == ''
87
+ ) {
88
 
89
  if ($this->saved[$post_id] === false) {
90
  //check for custom SEO
98
  }
99
 
100
 
101
+ add_action('save_post', array($this, 'hookSavePost'), 99);
102
  }
103
 
104
  /**
107
  * @param integer $post_id
108
  * @return false|void
109
  */
110
+ public function checkImage($post_id)
111
+ {
112
 
113
  //if the option to save the images locally is set on
114
  if (SQ_Tools::$options['sq_local_images'] == 1) {
133
 
134
  foreach ($out[1] as $row) {
135
  if (strpos($row, '//') !== false &&
136
+ strpos($row, $domain['host']) === false
137
+ ) {
138
  if (!in_array($row, $urls)) {
139
  $urls[] = $row;
140
  }
152
  $time = microtime(true);
153
  foreach ($urls as $url) {
154
  if ($file = $this->model->upload_image($url)) {
155
+
156
  if (!file_is_valid_image($file['file']))
157
  continue;
158
 
166
  'post_content' => urldecode(SQ_Tools::getValue('sq_fp_title', '')),
167
  'post_status' => 'inherit',
168
  'guid' => $local_file
169
+ ), $file['file'], $post_id);
170
 
171
  $attach_data = wp_generate_attachment_metadata($attach_id, $file['file']);
172
  wp_update_attachment_metadata($attach_id, $attach_data);
180
 
181
  if ($local_file !== false) {
182
  wp_update_post(array(
183
+ 'ID' => $post_id,
184
+ 'post_content' => $content)
185
  );
186
  }
187
  }
193
  * @param integer $post_id
194
  * @param void
195
  */
196
+ public function checkSeo($post_id, $status = '')
197
+ {
198
  $args = array();
199
 
200
  $seo = SQ_Tools::getValue('sq_seo');
208
  $args['permalink'] = get_permalink($post_id);
209
  $args['permalink'] = $this->getPaged($args['permalink']);
210
  $args['permalink'] = $args['permalink'];
211
+ $args['author'] = (int)SQ_Tools::getUserID();
212
  $args['post_id'] = $post_id;
213
 
214
  $process = array();
231
  }
232
  }
233
 
234
+ public function getPaged($link)
235
+ {
236
  $page = get_query_var('paged');
237
  if ($page && $page > 1) {
238
  $link = trailingslashit($link) . "page/" . "$page" . '/';
245
  *
246
  * @return void
247
  */
248
+ public function action()
249
+ {
250
  parent::action();
251
 
252
  switch (SQ_Tools::getValue('action')) {
269
  'post_content' => '',
270
  'post_status' => 'inherit',
271
  'guid' => $local_file
272
+ ), $return['file'], SQ_Tools::getValue('post_id'));
273
 
274
  $attach_data = wp_generate_attachment_metadata($attach_id, $return['file']);
275
  wp_update_attachment_metadata($attach_id, $attach_data);
298
  * @return array | false
299
  *
300
  */
301
+ private function _checkAdvMeta($post_id)
302
+ {
303
 
304
  $meta = array();
305
  if (SQ_Tools::getIsset('sq_canonical') || SQ_Tools::getIsset('sq_fp_title') || SQ_Tools::getIsset('sq_fp_description') || SQ_Tools::getIsset('sq_fp_keywords')) {
331
  return false;
332
  }
333
 
334
+ public function hookFooter()
335
+ {
336
  if (!defined('DISABLE_WP_CRON') || DISABLE_WP_CRON == true) {
337
  global $pagenow;
338
  if (in_array($pagenow, array('post.php', 'post-new.php'))) {
341
  }
342
  }
343
 
344
+ public function processCron()
345
+ {
346
  SQ_ObjController::getController('SQ_Tools', false);
347
  SQ_ObjController::getController('SQ_Action', false);
348
 
controllers/SQ_PostsList.php CHANGED
@@ -225,6 +225,7 @@ class SQ_PostsList extends SQ_FrontController {
225
  * @return array
226
  */
227
  public function insert($src, $in, $pos) {
 
228
  if (is_int($pos))
229
  $array = array_merge(array_slice($src, 0, $pos), $in, array_slice($src, $pos));
230
  else {
225
  * @return array
226
  */
227
  public function insert($src, $in, $pos) {
228
+ $array = array();
229
  if (is_int($pos))
230
  $array = array_merge(array_slice($src, 0, $pos), $in, array_slice($src, $pos));
231
  else {
controllers/SQ_Sitemaps.php CHANGED
@@ -13,24 +13,20 @@ class SQ_Sitemaps extends SQ_FrontController {
13
 
14
  public function __construct() {
15
  parent::__construct();
16
-
17
- add_filter('request', array($this, 'feedRequest'));
18
  add_filter('user_trailingslashit', array($this, 'untrailingslashit'));
19
  add_action('sq_processPing', array($this, 'processCron'));
20
-
21
  }
22
 
23
- public function feedHeader($content_type, $type) {
24
- if (empty($type))
25
- $type = get_default_feed();
26
- $types = array(
27
- 'rss' => 'application/rss+xml',
28
- 'rss2' => 'application/rss+xml',
29
- 'rss-http' => 'text/xml',
30
- 'atom' => 'application/xml',
31
- 'rdf' => 'application/rdf+xml'
32
- );
33
- $content_type = (!empty($types[$type]) ) ? $types[$type] : 'application/octet-stream';
34
  }
35
 
36
  public function refreshSitemap($new_status, $old_status, $post) {
@@ -47,11 +43,16 @@ class SQ_Sitemaps extends SQ_FrontController {
47
  * @return array
48
  */
49
  public function feedRequest($request) {
 
50
 
51
- if (isset($request['feed']) && strpos($request['feed'], 'sitemap') !== false) {
52
- @ini_set('memory_limit','512M');
 
 
 
 
53
 
54
- $this->model->type = $request['feed'];
55
 
56
  //show products
57
  if ($this->model->type == 'sitemap-product') {
@@ -62,8 +63,7 @@ class SQ_Sitemaps extends SQ_FrontController {
62
 
63
  if (isset(SQ_Tools::$options['sq_sitemap'][$this->model->type]) && SQ_Tools::$options['sq_sitemap'][$this->model->type][1] == 1) {
64
 
65
- add_action('do_feed_' . $request['feed'], array($this, 'showSitemap'));
66
-
67
  //PREPARE CUSTOM QUERIES
68
  switch ($this->model->type) {
69
 
@@ -74,19 +74,24 @@ class SQ_Sitemaps extends SQ_FrontController {
74
  case 'sitemap-category':
75
  case 'sitemap-post_tag':
76
  case 'sitemap-custom-tax':
77
- add_filter("get_terms_fields", array($this, 'customTaxFilter'), 5, 2);
 
 
 
 
 
78
  break;
79
  case 'sitemap-page':
80
- add_filter('pre_get_posts', array($this, 'pageFilter'), 5, 1);
81
  break;
82
  case 'sitemap-author':
83
  add_filter('sq-sitemap-authors', array($this, 'authorFilter'), 5);
84
  break;
85
  case 'sitemap-custom-post':
86
- add_filter('pre_get_posts', array($this, 'customPostFilter'), 5, 1);
87
  break;
88
  case 'sitemap-product':
89
- add_filter('pre_get_posts', array($this, 'productFilter'), 5, 1);
90
  break;
91
  case 'sitemap-archive':
92
  add_filter('sq-sitemap-archive', array($this, 'archiveFilter'), 5);
@@ -96,6 +101,7 @@ class SQ_Sitemaps extends SQ_FrontController {
96
  add_filter('post_limits', array($this, 'setLimits'));
97
  }
98
  }
 
99
  return $request;
100
  }
101
 
@@ -174,7 +180,6 @@ class SQ_Sitemaps extends SQ_FrontController {
174
  * @return string
175
  */
176
  public function showSitemap() {
177
-
178
  switch ($this->model->type) {
179
  case 'sitemap':
180
  $this->showSitemapHeader();
@@ -298,7 +303,7 @@ class SQ_Sitemaps extends SQ_FrontController {
298
  */
299
  public function getXmlUrl($sitemap) {
300
  if (!get_option('permalink_structure')) {
301
- $sitemap = '?feed=' . str_replace('.xml', '', $sitemap);
302
  } else {
303
  if (isset(SQ_Tools::$options['sq_sitemap'][$sitemap])) {
304
  $sitemap = SQ_Tools::$options['sq_sitemap'][$sitemap][0];
@@ -370,7 +375,11 @@ class SQ_Sitemaps extends SQ_FrontController {
370
  return $request; // trailingslashit($request);
371
  }
372
 
373
- function customTaxFilter($query) {
 
 
 
 
374
  global $wpdb;
375
 
376
  $query[] = "(SELECT
@@ -382,17 +391,18 @@ class SQ_Sitemaps extends SQ_FrontController {
382
  return $query;
383
  }
384
 
385
- function pageFilter($query) {
386
  $query->set('post_type', array('page'));
 
387
  }
388
 
389
- function authorFilter() {
390
  //get only the author with posts
391
  add_filter('pre_user_query', array($this, 'userFilter'));
392
  return get_users();
393
  }
394
 
395
- function userFilter($query) {
396
  $query->query_fields .= ',p.lastmod';
397
  $query->query_from .= ' LEFT OUTER JOIN (
398
  SELECT MAX(post_modified) as lastmod, post_author, COUNT(*) as post_count
@@ -403,7 +413,7 @@ class SQ_Sitemaps extends SQ_FrontController {
403
  $query->query_where .= ' AND post_count > 0 ';
404
  }
405
 
406
- function customPostFilter($query) {
407
  $types = get_post_types();
408
  foreach (array('post', 'page', 'attachment', 'revision', 'nav_menu_item', 'product', 'wpsc-product') as $exclude) {
409
  if (in_array($exclude, $types)) {
@@ -424,16 +434,18 @@ class SQ_Sitemaps extends SQ_FrontController {
424
  }
425
 
426
  $query->set('post_type', $types); // id of page or post
 
427
  }
428
 
429
- function productFilter($query) {
430
  if (!$types = SQ_ObjController::getModel('SQ_BlockSettingsSeo')->isEcommerce()) {
431
  $types = array('custom-post');
432
  }
433
  $query->set('post_type', $types); // id of page or post
 
434
  }
435
 
436
- function archiveFilter() {
437
  global $wpdb;
438
  $archives = $wpdb->get_results("
439
  SELECT DISTINCT YEAR(post_date_gmt) as `year`, MONTH(post_date_gmt) as `month`, max(post_date_gmt) as lastmod, count(ID) as posts
13
 
14
  public function __construct() {
15
  parent::__construct();
16
+ add_filter('template_redirect', array($this, 'hookPreventRedirect'), 1, 0);
 
17
  add_filter('user_trailingslashit', array($this, 'untrailingslashit'));
18
  add_action('sq_processPing', array($this, 'processCron'));
 
19
  }
20
 
21
+ public function hookPreventRedirect() {
22
+ global $wp_query;
23
+ if (!empty($wp_query->query_vars["sq_feed"])) {
24
+ $wp_query->is_404 = false;
25
+ $wp_query->is_feed = true;
26
+ $this->feedRequest($wp_query->query_vars);
27
+ $this->showSitemap();
28
+ exit();
29
+ }
 
 
30
  }
31
 
32
  public function refreshSitemap($new_status, $old_status, $post) {
43
  * @return array
44
  */
45
  public function feedRequest($request) {
46
+ global $wp_query;
47
 
48
+ if (!empty($request['feed'])) {
49
+ $request['sq_feed'] = $request['feed'];
50
+ }
51
+
52
+ if (isset($request['sq_feed']) && strpos($request['sq_feed'], 'sitemap') !== false) {
53
+ @ini_set('memory_limit', '512M');
54
 
55
+ $this->model->type = $request['sq_feed'];
56
 
57
  //show products
58
  if ($this->model->type == 'sitemap-product') {
63
 
64
  if (isset(SQ_Tools::$options['sq_sitemap'][$this->model->type]) && SQ_Tools::$options['sq_sitemap'][$this->model->type][1] == 1) {
65
 
66
+ add_action('do_feed_' . $request['sq_feed'], array($this, 'showSitemap'));
 
67
  //PREPARE CUSTOM QUERIES
68
  switch ($this->model->type) {
69
 
74
  case 'sitemap-category':
75
  case 'sitemap-post_tag':
76
  case 'sitemap-custom-tax':
77
+ remove_all_filters('terms_clauses'); //prevent language filters
78
+ add_filter('get_terms_fields', array($this, 'customTaxFilter'), 5, 2);
79
+
80
+ break;
81
+ case 'sitemap-post':
82
+ add_action('parse_query', array($this, 'postFilter'), 99);
83
  break;
84
  case 'sitemap-page':
85
+ add_action('parse_query', array($this, 'pageFilter'), 99);
86
  break;
87
  case 'sitemap-author':
88
  add_filter('sq-sitemap-authors', array($this, 'authorFilter'), 5);
89
  break;
90
  case 'sitemap-custom-post':
91
+ add_action('parse_query', array($this, 'customPostFilter'), 99);
92
  break;
93
  case 'sitemap-product':
94
+ add_action('parse_query', array($this, 'productFilter'), 99);
95
  break;
96
  case 'sitemap-archive':
97
  add_filter('sq-sitemap-archive', array($this, 'archiveFilter'), 5);
101
  add_filter('post_limits', array($this, 'setLimits'));
102
  }
103
  }
104
+
105
  return $request;
106
  }
107
 
180
  * @return string
181
  */
182
  public function showSitemap() {
 
183
  switch ($this->model->type) {
184
  case 'sitemap':
185
  $this->showSitemapHeader();
303
  */
304
  public function getXmlUrl($sitemap) {
305
  if (!get_option('permalink_structure')) {
306
+ $sitemap = '?sq_feed=' . str_replace('.xml', '', $sitemap);
307
  } else {
308
  if (isset(SQ_Tools::$options['sq_sitemap'][$sitemap])) {
309
  $sitemap = SQ_Tools::$options['sq_sitemap'][$sitemap][0];
375
  return $request; // trailingslashit($request);
376
  }
377
 
378
+ public function postFilter(&$query) {
379
+ $query->set('tax_query', array());
380
+ }
381
+
382
+ public function customTaxFilter($query) {
383
  global $wpdb;
384
 
385
  $query[] = "(SELECT
391
  return $query;
392
  }
393
 
394
+ public function pageFilter(&$query) {
395
  $query->set('post_type', array('page'));
396
+ $query->set('tax_query', array());
397
  }
398
 
399
+ public function authorFilter() {
400
  //get only the author with posts
401
  add_filter('pre_user_query', array($this, 'userFilter'));
402
  return get_users();
403
  }
404
 
405
+ public function userFilter($query) {
406
  $query->query_fields .= ',p.lastmod';
407
  $query->query_from .= ' LEFT OUTER JOIN (
408
  SELECT MAX(post_modified) as lastmod, post_author, COUNT(*) as post_count
413
  $query->query_where .= ' AND post_count > 0 ';
414
  }
415
 
416
+ public function customPostFilter(&$query) {
417
  $types = get_post_types();
418
  foreach (array('post', 'page', 'attachment', 'revision', 'nav_menu_item', 'product', 'wpsc-product') as $exclude) {
419
  if (in_array($exclude, $types)) {
434
  }
435
 
436
  $query->set('post_type', $types); // id of page or post
437
+ $query->set('tax_query', array());
438
  }
439
 
440
+ public function productFilter(&$query) {
441
  if (!$types = SQ_ObjController::getModel('SQ_BlockSettingsSeo')->isEcommerce()) {
442
  $types = array('custom-post');
443
  }
444
  $query->set('post_type', $types); // id of page or post
445
+ $query->set('tax_query', array());
446
  }
447
 
448
+ public function archiveFilter() {
449
  global $wpdb;
450
  $archives = $wpdb->get_results("
451
  SELECT DISTINCT YEAR(post_date_gmt) as `year`, MONTH(post_date_gmt) as `month`, max(post_date_gmt) as lastmod, count(ID) as posts
core/SQ_BlockSettingsSeo/SQ_BlockSettingsSeo.php CHANGED
@@ -52,6 +52,7 @@ class SQ_BlockSettingsSeo extends SQ_BlockController {
52
  /////////////////////////////SOCIAL OPTION
53
  SQ_Tools::saveOptions('sq_auto_facebook', (int) SQ_Tools::getValue('sq_auto_facebook'));
54
  SQ_Tools::saveOptions('sq_auto_twitter', (int) SQ_Tools::getValue('sq_auto_twitter'));
 
55
  SQ_Tools::saveOptions('sq_og_locale', SQ_Tools::getValue('sq_og_locale'));
56
 
57
  SQ_Tools::saveOptions('sq_twitter_account', $this->model->checkTwitterAccount(SQ_Tools::getValue('sq_twitter_account')));
@@ -78,15 +79,17 @@ class SQ_BlockSettingsSeo extends SQ_BlockController {
78
 
79
  if (!empty($meta))
80
  SQ_ObjController::getModel('SQ_Post')->saveAdvMeta($pageId, $meta);
81
- }else {
82
- SQ_Tools::saveOptions('sq_fp_title', SQ_Tools::getValue('sq_fp_title'));
83
- SQ_Tools::saveOptions('sq_fp_description', SQ_Tools::getValue('sq_fp_description'));
84
- SQ_Tools::saveOptions('sq_fp_keywords', SQ_Tools::getValue('sq_fp_keywords'));
85
  }
86
 
 
 
 
 
 
87
  ///////////////////////////////////////////
88
  /////////////////////////////SITEMAP OPTION
89
  SQ_Tools::saveOptions('sq_auto_sitemap', (int) SQ_Tools::getValue('sq_auto_sitemap'));
 
90
  SQ_Tools::saveOptions('sq_sitemap_frequency', SQ_Tools::getValue('sq_sitemap_frequency'));
91
  SQ_Tools::saveOptions('sq_sitemap_ping', (int) SQ_Tools::getValue('sq_sitemap_ping'));
92
 
@@ -224,6 +227,7 @@ class SQ_BlockSettingsSeo extends SQ_BlockController {
224
  SQ_Tools::saveOptions('ignore_warn', 1);
225
  break;
226
  case 'sq_get_snippet':
 
227
  if (SQ_Tools::getValue('url') <> '') {
228
  $url = SQ_Tools::getValue('url');
229
  } else {
@@ -295,10 +299,14 @@ class SQ_BlockSettingsSeo extends SQ_BlockController {
295
  if (SQ_Tools::$options['sq_auto_sitemap'] == 1) {
296
  foreach (SQ_Tools::$options['sq_sitemap'] as $name => $sitemap) {
297
  if ($sitemap[1] == 1 || $sitemap[1] == 2) { // is show sitemap
298
- $rules[preg_quote($sitemap[0])] = 'index.php?feed=' . $name;
299
  }
300
  }
301
  }
 
 
 
 
302
  }
303
  return array_merge($rules, $wp_rewrite);
304
  }
52
  /////////////////////////////SOCIAL OPTION
53
  SQ_Tools::saveOptions('sq_auto_facebook', (int) SQ_Tools::getValue('sq_auto_facebook'));
54
  SQ_Tools::saveOptions('sq_auto_twitter', (int) SQ_Tools::getValue('sq_auto_twitter'));
55
+ SQ_Tools::saveOptions('sq_auto_twittersize', SQ_Tools::getValue('sq_auto_twittersize'));
56
  SQ_Tools::saveOptions('sq_og_locale', SQ_Tools::getValue('sq_og_locale'));
57
 
58
  SQ_Tools::saveOptions('sq_twitter_account', $this->model->checkTwitterAccount(SQ_Tools::getValue('sq_twitter_account')));
79
 
80
  if (!empty($meta))
81
  SQ_ObjController::getModel('SQ_Post')->saveAdvMeta($pageId, $meta);
 
 
 
 
82
  }
83
 
84
+ SQ_Tools::saveOptions('sq_fp_title', SQ_Tools::getValue('sq_fp_title'));
85
+ SQ_Tools::saveOptions('sq_fp_description', SQ_Tools::getValue('sq_fp_description'));
86
+ SQ_Tools::saveOptions('sq_fp_keywords', SQ_Tools::getValue('sq_fp_keywords'));
87
+
88
+
89
  ///////////////////////////////////////////
90
  /////////////////////////////SITEMAP OPTION
91
  SQ_Tools::saveOptions('sq_auto_sitemap', (int) SQ_Tools::getValue('sq_auto_sitemap'));
92
+ SQ_Tools::saveOptions('sq_auto_feed', (int) SQ_Tools::getValue('sq_auto_feed'));
93
  SQ_Tools::saveOptions('sq_sitemap_frequency', SQ_Tools::getValue('sq_sitemap_frequency'));
94
  SQ_Tools::saveOptions('sq_sitemap_ping', (int) SQ_Tools::getValue('sq_sitemap_ping'));
95
 
227
  SQ_Tools::saveOptions('ignore_warn', 1);
228
  break;
229
  case 'sq_get_snippet':
230
+
231
  if (SQ_Tools::getValue('url') <> '') {
232
  $url = SQ_Tools::getValue('url');
233
  } else {
299
  if (SQ_Tools::$options['sq_auto_sitemap'] == 1) {
300
  foreach (SQ_Tools::$options['sq_sitemap'] as $name => $sitemap) {
301
  if ($sitemap[1] == 1 || $sitemap[1] == 2) { // is show sitemap
302
+ $rules[preg_quote($sitemap[0])] = 'index.php?sq_feed=' . $name;
303
  }
304
  }
305
  }
306
+
307
+ if (SQ_Tools::$options['sq_auto_feed'] == 1) {
308
+ $rules['sqfeedcss$'] = 'index.php?sq_get=feedcss';
309
+ }
310
  }
311
  return array_merge($rules, $wp_rewrite);
312
  }
models/SQ_BlockPostsAnalytics.php CHANGED
@@ -140,7 +140,6 @@ class Model_SQ_BlockPostsAnalytics extends WP_List_Table {
140
  $query['post__in'] = (array) $post__in;
141
 
142
  wp($query);
143
- //echo '<pre>' . print_r($wp_query, true) . '</pre>';
144
  return $avail_post_stati;
145
  }
146
 
140
  $query['post__in'] = (array) $post__in;
141
 
142
  wp($query);
 
143
  return $avail_post_stati;
144
  }
145
 
models/SQ_BlockSettingsSeo.php CHANGED
@@ -1,11 +1,13 @@
1
  <?php
2
 
3
- class Model_SQ_BlockSettingsSeo {
 
4
 
5
  var $eTypes;
6
  var $appleSizes;
7
 
8
- public function __construct() {
 
9
  $this->appleSizes = preg_split('/[,]+/', _SQ_MOBILE_ICON_SIZES);
10
  }
11
 
@@ -13,7 +15,8 @@ class Model_SQ_BlockSettingsSeo {
13
  * Check if ecommerce is installed
14
  * @return boolean
15
  */
16
- public function isEcommerce() {
 
17
  if (isset($this->eTypes)) {
18
  return $this->eTypes;
19
  }
@@ -38,22 +41,20 @@ class Model_SQ_BlockSettingsSeo {
38
  *
39
  * @return string
40
  */
41
- public function checkGoogleWTCode($code) {
 
42
 
43
  if ($code <> '') {
44
  if (strpos($code, 'content') !== false) {
45
  preg_match('/content\\s*=\\s*[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
46
- if (isset($result[1]) && !empty($result[1]))
47
- $code = $result[1];
48
  }
49
  if (strpos($code, '"') !== false) {
50
  preg_match('/[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
51
- if (isset($result[1]) && !empty($result[1]))
52
- $code = $result[1];
53
  }
54
 
55
- if ($code == '')
56
- SQ_Error::setError(__("The code for Google Webmaster Tool is incorrect.", _SQ_PLUGIN_NAME_));
57
  }
58
  return $code;
59
  }
@@ -63,19 +64,18 @@ class Model_SQ_BlockSettingsSeo {
63
  *
64
  * @return string
65
  */
66
- public function checkGoogleAnalyticsCode($code) {
 
67
  //echo $code;
68
  if ($code <> '') {
69
  if (strpos($code, 'GoogleAnalyticsObject') !== false) {
70
  preg_match('/ga\(\'create\',[^\'"]*[\'"]([^\'"]+)[\'"],/i', $code, $result);
71
- if (isset($result[1]) && !empty($result[1]))
72
- $code = $result[1];
73
  }
74
 
75
  if (strpos($code, '"') !== false) {
76
  preg_match('/[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
77
- if (isset($result[1]) && !empty($result[1]))
78
- $code = $result[1];
79
  }
80
 
81
  if (strpos($code, 'UA-') === false) {
@@ -91,7 +91,8 @@ class Model_SQ_BlockSettingsSeo {
91
  *
92
  * @return string
93
  */
94
- public function checkFavebookInsightsCode($code) {
 
95
  if ($code <> '') {
96
  if (strpos($code, 'content') !== false) {
97
  preg_match('/content\\s*=\\s*[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
@@ -105,13 +106,18 @@ class Model_SQ_BlockSettingsSeo {
105
  preg_match('/facebook.com\/([^\/]+)/i', $code, $result);
106
  $code = '';
107
  if (isset($result[1]) && !empty($result[1])) {
108
- $json = SQ_Tools::sq_remote_get('http://graph.facebook.com/' . $result[1]);
109
- if ($json <> '') {
110
- if ($json = @json_decode($json)) {
111
- if (isset($json->id)) {
112
- $code = $json->id;
 
 
 
113
  }
114
  }
 
 
115
  }
116
  }
117
  }
@@ -136,22 +142,20 @@ class Model_SQ_BlockSettingsSeo {
136
  *
137
  * @return string
138
  */
139
- public function checkPinterestCode($code) {
 
140
  if ($code <> '') {
141
  if (strpos($code, 'content') !== false) {
142
  preg_match('/content\\s*=\\s*[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
143
- if (isset($result[1]) && !empty($result[1]))
144
- $code = $result[1];
145
  }
146
 
147
  if (strpos($code, '"') !== false) {
148
  preg_match('/[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
149
- if (isset($result[1]) && !empty($result[1]))
150
- $code = $result[1];
151
  }
152
 
153
- if ($code == '')
154
- SQ_Error::setError(__("The code for Pinterest is incorrect.", _SQ_PLUGIN_NAME_));
155
  }
156
  return $code;
157
  }
@@ -161,22 +165,20 @@ class Model_SQ_BlockSettingsSeo {
161
  *
162
  * @return string
163
  */
164
- public function checkBingWTCode($code) {
 
165
  if ($code <> '') {
166
  if (strpos($code, 'content') !== false) {
167
  preg_match('/content\\s*=\\s*[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
168
- if (isset($result[1]) && !empty($result[1]))
169
- $code = $result[1];
170
  }
171
 
172
  if (strpos($code, '"') !== false) {
173
  preg_match('/[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
174
- if (isset($result[1]) && !empty($result[1]))
175
- $code = $result[1];
176
  }
177
 
178
- if ($code == '')
179
- SQ_Error::setError(__("The code for Bing is incorrect.", _SQ_PLUGIN_NAME_));
180
  }
181
  return $code;
182
  }
@@ -186,7 +188,8 @@ class Model_SQ_BlockSettingsSeo {
186
  *
187
  * @return string
188
  */
189
- public function checkTwitterAccount($account) {
 
190
  if (SQ_ObjController::getModel('SQ_Frontend')->getTwitterAccount($account) === false) {
191
  SQ_Error::setError(__("The twitter account is incorrect", _SQ_PLUGIN_NAME_));
192
  }
@@ -201,7 +204,8 @@ class Model_SQ_BlockSettingsSeo {
201
  *
202
  * @return string
203
  */
204
- public function checkGoogleAccount($account) {
 
205
  if ($account <> '' && strpos($account, 'google.') === false) {
206
  $account = 'https://plus.google.com/' . $account;
207
  }
@@ -213,7 +217,8 @@ class Model_SQ_BlockSettingsSeo {
213
  *
214
  * @return string
215
  */
216
- public function checkLinkeinAccount($account) {
 
217
  if ($account <> '' && strpos($account, 'linkedin.') === false) {
218
  $account = 'https://www.linkedin.com/in/' . $account;
219
  }
@@ -225,7 +230,8 @@ class Model_SQ_BlockSettingsSeo {
225
  *
226
  * @return string
227
  */
228
- public function checkFacebookAccount($account) {
 
229
  if ($account <> '' && strpos($account, 'facebook.com') === false) {
230
  $account = 'https://www.facebook.com/' . $account;
231
  }
@@ -240,7 +246,8 @@ class Model_SQ_BlockSettingsSeo {
240
  * @return array [name (the name of the file), favicon (the path of the ico), message (the returned message)]
241
  *
242
  */
243
- public function addFavicon($file, $path = ABSPATH) {
 
244
 
245
  /* get the file extension */
246
  $file_name = explode('.', $file['name']);
@@ -322,6 +329,7 @@ class Model_SQ_BlockSettingsSeo {
322
  $ico->remove_ico($path . "/" . 'favicon.ico');
323
  }
324
  if (!is_multisite()) {
 
325
  $ico->save_ico($path . "/" . 'favicon.ico');
326
  }
327
  }
@@ -333,19 +341,9 @@ class Model_SQ_BlockSettingsSeo {
333
  }
334
  }
335
 
336
- private function checkFunctions() {
337
- $required_functions = array(
338
- 'getimagesize',
339
- 'imagecreatefromstring',
340
- 'imagecreatetruecolor',
341
- 'imagecolortransparent',
342
- 'imagecolorallocatealpha',
343
- 'imagealphablending',
344
- 'imagesavealpha',
345
- 'imagesx',
346
- 'imagesy',
347
- 'imagecopyresampled',
348
- );
349
 
350
  foreach ($required_functions as $function) {
351
  if (!function_exists($function)) {
1
  <?php
2
 
3
+ class Model_SQ_BlockSettingsSeo
4
+ {
5
 
6
  var $eTypes;
7
  var $appleSizes;
8
 
9
+ public function __construct()
10
+ {
11
  $this->appleSizes = preg_split('/[,]+/', _SQ_MOBILE_ICON_SIZES);
12
  }
13
 
15
  * Check if ecommerce is installed
16
  * @return boolean
17
  */
18
+ public function isEcommerce()
19
+ {
20
  if (isset($this->eTypes)) {
21
  return $this->eTypes;
22
  }
41
  *
42
  * @return string
43
  */
44
+ public function checkGoogleWTCode($code)
45
+ {
46
 
47
  if ($code <> '') {
48
  if (strpos($code, 'content') !== false) {
49
  preg_match('/content\\s*=\\s*[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
50
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
 
51
  }
52
  if (strpos($code, '"') !== false) {
53
  preg_match('/[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
54
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
 
55
  }
56
 
57
+ if ($code == '') SQ_Error::setError(__("The code for Google Webmaster Tool is incorrect.", _SQ_PLUGIN_NAME_));
 
58
  }
59
  return $code;
60
  }
64
  *
65
  * @return string
66
  */
67
+ public function checkGoogleAnalyticsCode($code)
68
+ {
69
  //echo $code;
70
  if ($code <> '') {
71
  if (strpos($code, 'GoogleAnalyticsObject') !== false) {
72
  preg_match('/ga\(\'create\',[^\'"]*[\'"]([^\'"]+)[\'"],/i', $code, $result);
73
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
 
74
  }
75
 
76
  if (strpos($code, '"') !== false) {
77
  preg_match('/[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
78
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
 
79
  }
80
 
81
  if (strpos($code, 'UA-') === false) {
91
  *
92
  * @return string
93
  */
94
+ public function checkFavebookInsightsCode($code)
95
+ {
96
  if ($code <> '') {
97
  if (strpos($code, 'content') !== false) {
98
  preg_match('/content\\s*=\\s*[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
106
  preg_match('/facebook.com\/([^\/]+)/i', $code, $result);
107
  $code = '';
108
  if (isset($result[1]) && !empty($result[1])) {
109
+ if (is_string($result[1])) {
110
+ $html = SQ_Tools::sq_remote_post('http://findmyfbid.com/', array('url' => $result[1]));
111
+ if ($html <> '' && strpos($html, '<code') !== false) {
112
+ $result = array();
113
+ if (preg_match('/<code[^>]*>([0-9]+)<\/code[^>]*>/i', $html, $result)) {
114
+ if (isset($result[1]) && !empty($result[1])) {
115
+ $code = $result[1];
116
+ }
117
  }
118
  }
119
+ } elseif(is_numeric($result[1])) {
120
+ $code = $result[1];
121
  }
122
  }
123
  }
142
  *
143
  * @return string
144
  */
145
+ public function checkPinterestCode($code)
146
+ {
147
  if ($code <> '') {
148
  if (strpos($code, 'content') !== false) {
149
  preg_match('/content\\s*=\\s*[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
150
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
 
151
  }
152
 
153
  if (strpos($code, '"') !== false) {
154
  preg_match('/[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
155
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
 
156
  }
157
 
158
+ if ($code == '') SQ_Error::setError(__("The code for Pinterest is incorrect.", _SQ_PLUGIN_NAME_));
 
159
  }
160
  return $code;
161
  }
165
  *
166
  * @return string
167
  */
168
+ public function checkBingWTCode($code)
169
+ {
170
  if ($code <> '') {
171
  if (strpos($code, 'content') !== false) {
172
  preg_match('/content\\s*=\\s*[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
173
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
 
174
  }
175
 
176
  if (strpos($code, '"') !== false) {
177
  preg_match('/[\'\"]([^\'\"]+)[\'\"]/i', $code, $result);
178
+ if (isset($result[1]) && !empty($result[1])) $code = $result[1];
 
179
  }
180
 
181
+ if ($code == '') SQ_Error::setError(__("The code for Bing is incorrect.", _SQ_PLUGIN_NAME_));
 
182