Skip to content

Commit

Permalink
Fix SeoPro
Browse files Browse the repository at this point in the history
  • Loading branch information
dinoxtech committed Jun 27, 2021
1 parent 3719e5f commit fdc6b5a
Showing 1 changed file with 18 additions and 43 deletions.
61 changes: 18 additions & 43 deletions upload/system/library/seopro.php
Expand Up @@ -3,6 +3,7 @@
* @package SeoPro
* @author Oclabs
* @copyright Copyright (c) 2017, Oclabs (https://www.oclabs.pro/)
* @copyright Copyright (c) 2021, ocStore (https://ocstore.com/)
* @license https://opensource.org/licenses/GPL-3.0
*/

Expand All @@ -23,10 +24,9 @@ class SeoPro {
private $queries = [];
private $product_categories = [];
private $valide_get_param;
private $categories;

public function __construct($registry) {

$this->detectAjax();
$this->registry = $registry;
$this->config = $registry->get('config');

Expand All @@ -51,15 +51,7 @@ public function __construct($registry) {
}

public function prepareRoute($parts) {

// check double slashes
$current_url = $this->request->server['REQUEST_URI'];
if (preg_match('!/{2,}!', $current_url) ){
$url = preg_replace('!/{2,}!', '/', $current_url);
$this->response->redirect($url, 301);
exit;
}


if (!empty($parts) && is_array($parts)) {

foreach($parts as $id => $part) {
Expand Down Expand Up @@ -133,14 +125,6 @@ public function prepareRoute($parts) {
$this->request->get['route'] = 'blog/category';
}
//end blog

// fix https://demo.ocstore.com/desktops/mac/about_us etc
if ((isset($this->request->get['path']) && isset($this->request->get['manufacturer_id'])) || (isset($this->request->get['path']) && isset($this->request->get['information_id'])) || (isset($this->request->get['manufacturer_id']) && isset($this->request->get['product_id'])) || (isset($this->request->get['manufacturer_id']) && isset($this->request->get['information_id']))) {
$this->request->get['route'] = 'error/not_found';
return [];
}


return $parts;
}

Expand All @@ -156,7 +140,7 @@ public function baseRewrite($data, $language_id) {
$route = 'product/product';
$path = '';
$product_id = $data['product_id'];
if ($this->config->get('config_seo_url_include_path')) {
if (isset($data['path']) || $this->config->get('config_seo_url_include_path')) {
$path = $this->getCategoryByProduct($product_id);
}

Expand All @@ -175,7 +159,7 @@ public function baseRewrite($data, $language_id) {
unset($data);
$data['route'] = $route;

if (!empty($path)) {
if ($path && $this->config->get('config_seo_url_include_path')) {
$data['path'] = $path;
}

Expand Down Expand Up @@ -348,7 +332,7 @@ public function baseRewrite($data, $language_id) {
return [$url, $data, $postfix];
}

private function getPath($category_id, $current_path = []) {
private function getPath($categories, $category_id, $current_path = []) {

if(!$current_path)
$current_path = [(int)$category_id];
Expand All @@ -357,12 +341,12 @@ private function getPath($category_id, $current_path = []) {

$parent_id = 0;

if(isset($this->categories[$category_id]['parent_id']))
$parent_id = (int)$this->categories[$category_id]['parent_id'];
if(isset($categories[$category_id]['parent_id']))
$parent_id = (int)$categories[$category_id]['parent_id'];

if($parent_id > 0) {
$new_path = array_merge ([$parent_id] , $current_path);
$path = $this->getPath($parent_id, $new_path);
$path = $this->getPath($categories, $parent_id, $new_path);
}

return $path;
Expand All @@ -379,28 +363,26 @@ private function initHelpers() {

$this->cat_tree = [];

$all_cat_query = $this->db->query("SELECT category_id, parent_id FROM " . DB_PREFIX . "category WHERE status = 1 ORDER BY parent_id");
$all_cat_query = $this->db->query("SELECT category_id, parent_id FROM " . DB_PREFIX . "category ORDER BY parent_id");

$allcats = [];
$this->categories = [];
$categories = [];

if($all_cat_query->num_rows) {
$allcats = $all_cat_query->rows;
};

foreach ($allcats as $category) {
$this->categories[$category['category_id']]['parent_id'] = $category['parent_id'];
$categories[$category['category_id']]['parent_id'] = $category['parent_id'];
};
unset ($allcats);
unset ($all_cat_query);

foreach ($this->categories as $category_id => $category) {
$path = $this->getPath($category_id);
foreach ($categories as $category_id => $category) {
$path = $this->getPath($categories, $category_id);
$this->cat_tree[$category_id]['path'] = $path;

};



}
//end_category_tree

Expand Down Expand Up @@ -489,9 +471,7 @@ private function getKeywordByQuery($query, $language_id = null) {
}

public function validate() {

$this->detectAjax();


// break redirect for php-cli-script
if (php_sapi_name() === 'cli')
return;
Expand All @@ -512,8 +492,7 @@ public function validate() {

if (!empty($this->request->post))
return;



if ($this->ajax) {
$this->response->addHeader('X-Robots-Tag: noindex');
return;
Expand Down Expand Up @@ -546,8 +525,6 @@ public function validate() {
}

$url = str_replace('&', '&', $host . ltrim($uri, '/'));
//fix utm on homepage https://demo.ocstore.com/?utm_medium=test
$url = str_replace(HTTPS_SERVER . '?', rtrim(HTTPS_SERVER, '/').'?', $url);
$seo = str_replace('&', '&', $this->url->link($route, $this->getQueryString(array('_route_', 'route')), $_SERVER['HTTPS']));


Expand All @@ -562,9 +539,7 @@ private function detectAjax () {
}

private function detectLanguage() {

$this->detectAjax();


if ($this->ajax)
return;

Expand Down

0 comments on commit fdc6b5a

Please sign in to comment.