Skip to content

Commit

Permalink
feat: Fixed all ../ paths for symlinks + relative paths where possible (
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmolinacano authored Apr 25, 2024
1 parent a795112 commit ee919ea
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 30 deletions.
41 changes: 26 additions & 15 deletions doofinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/
if (!class_exists('dfTools')) {
require_once dirname(__FILE__) . '/lib/dfTools.class.php';
require_once 'lib/dfTools.class.php';
}

if (!defined('_PS_VERSION_')) {
Expand All @@ -32,15 +32,15 @@ class Doofinder extends Module
const DOOMANAGER_URL = 'https://admin.doofinder.com';
const GS_SHORT_DESCRIPTION = 1;
const GS_LONG_DESCRIPTION = 2;
const VERSION = '4.7.30';
const VERSION = '4.7.31';
const YES = 1;
const NO = 0;

public function __construct()
{
$this->name = 'doofinder';
$this->tab = 'search_filter';
$this->version = '4.7.30';
$this->version = '4.7.31';
$this->author = 'Doofinder (http://www.doofinder.com)';
$this->ps_versions_compliancy = ['min' => '1.5', 'max' => _PS_VERSION_];
$this->module_key = 'd1504fe6432199c7f56829be4bd16347';
Expand Down Expand Up @@ -825,6 +825,10 @@ private function configureHookCommon($params = false)
if (empty($df_querySelector)) {
$df_querySelector = '#search_query_top';
}
$self_path = dirname($_SERVER['SCRIPT_FILENAME']);
if (!is_dir($self_path)) {
$self_path = dirname(__FILE__);
}
$this->smarty->assign([
'ENT_QUOTES' => ENT_QUOTES,
'lang' => Tools::strtolower($lang),
Expand All @@ -833,7 +837,7 @@ private function configureHookCommon($params = false)
'productLinks' => $this->productLinks,
'search_engine_id' => $search_engine_id,
'df_region' => $df_region,
'self' => dirname(__FILE__),
'self' => $self_path,
'df_another_params' => $params,
'installation_ID' => $installation_ID,
'currency' => $currency,
Expand Down Expand Up @@ -890,7 +894,11 @@ public function displayScriptV7()
$cssVS = (int) Configuration::get('DF_CSS_VS');
$file = 'doofinder_custom_' . $this->context->shop->id . '_vs_' . $cssVS . '.css';
if ($extraCSS) {
if (file_exists(dirname(__FILE__) . '/views/css/' . $file)) {
$file_path = dirname($_SERVER['SCRIPT_FILENAME']) . '/views/css/' . $file;
if (!file_exists($file_path)) {
$file_path = dirname(__FILE__) . '/views/css/' . $file;
}
if (file_exists($file_path)) {
$this->context->controller->addCSS(
$this->_path . 'views/css/' . $file,
'all'
Expand Down Expand Up @@ -1137,7 +1145,7 @@ public function sendProductApi($products, $id_shop, $id_lang, $id_currency, $act

if ($hashid) {
if ($action == 'update') {
require_once dirname(__FILE__) . '/lib/dfProduct_build.php';
require_once 'lib/dfProduct_build.php';
$builder = new DfProductBuild($id_shop, $id_lang, $id_currency);
$builder->setProducts($products);
$payload = $builder->build();
Expand Down Expand Up @@ -1170,7 +1178,7 @@ public function sendCmsApi($cms_pages, $id_shop, $id_lang, $id_currency, $action

if ($hashid) {
if ($action == 'update') {
require_once dirname(__FILE__) . '/lib/dfCms_build.php';
require_once 'lib/dfCms_build.php';

$builder = new DfCmsBuild($id_shop, $id_lang);
$builder->setCmsPages($cms_pages);
Expand Down Expand Up @@ -1204,7 +1212,7 @@ public function sendCategoryApi($categories, $id_shop, $id_lang, $id_currency, $

if ($hashid) {
if ($action == 'update') {
require_once dirname(__FILE__) . '/lib/dfCategory_build.php';
require_once 'lib/dfCategory_build.php';

$builder = new DfCategoryBuild($id_shop, $id_lang);
$builder->setCategories($categories);
Expand All @@ -1223,7 +1231,7 @@ private function updateItemsApi($hashid, $type, $payload)
return;
}

require_once dirname(__FILE__) . '/lib/doofinder_api_items.php';
require_once 'lib/doofinder_api_items.php';

$apikey = explode('-', Configuration::get('DF_API_KEY'))[1];
$region = Configuration::get('DF_REGION');
Expand All @@ -1242,7 +1250,7 @@ private function deleteItemsApi($hashid, $type, $payload)
return;
}

require_once dirname(__FILE__) . '/lib/doofinder_api_items.php';
require_once 'lib/doofinder_api_items.php';

$apikey = explode('-', Configuration::get('DF_API_KEY'))[1];
$region = Configuration::get('DF_REGION');
Expand All @@ -1257,7 +1265,7 @@ private function deleteItemsApi($hashid, $type, $payload)

private function indexApiInvokeReindexing()
{
require_once dirname(__FILE__) . '/lib/doofinder_api_index.php';
require_once 'lib/doofinder_api_index.php';

$region = Configuration::get('DF_REGION');
$api_key = Configuration::get('DF_API_KEY');
Expand All @@ -1282,7 +1290,7 @@ private function indexApiInvokeReindexing()
public function testDoofinderApi($onlyOneLang = false)
{
if (!class_exists('DoofinderApi')) {
include_once dirname(__FILE__) . '/lib/doofinder_api.php';
include_once 'lib/doofinder_api.php';
}
$result = false;
$messages = '';
Expand Down Expand Up @@ -1373,7 +1381,7 @@ public function searchOnApi(
$fail = false;
try {
if (!class_exists('DoofinderApi')) {
include_once dirname(__FILE__) . '/lib/doofinder_api.php';
include_once 'lib/doofinder_api.php';
}
$df = new DoofinderApi($hash_id, $api_key, false, ['apiVersion' => '5']);
$queryParams = [
Expand Down Expand Up @@ -1943,9 +1951,12 @@ private function getShopBaseURI($shop)

private function debug($message)
{
$debug = Configuration::get('DF_DEBUG', null);
$current_path = dirname($_SERVER['SCRIPT_FILENAME']);
if (!is_dir($current_path)) {
$current_path = dirname(__FILE__);
}
if (isset($debug) && $debug) {
error_log("$message\n", 3, dirname(__FILE__) . '/doofinder.log');
error_log("$message\n", 3, $current_path . '/doofinder.log');
}
}

Expand Down
6 changes: 3 additions & 3 deletions feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@

switch (Tools::getValue('type')) {
case 'category':
require dirname(__FILE__) . '/feeds/category.php';
require 'feeds/category.php';
break;

case 'page':
require dirname(__FILE__) . '/feeds/cms.php';
require 'feeds/cms.php';
break;

case 'product':
default:
require dirname(__FILE__) . '/feeds/product.php';
require 'feeds/product.php';
break;
}
4 changes: 2 additions & 2 deletions feeds/category.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
$config_file_path = $root_path . '/config/config.inc.php';
if (file_exists($config_file_path)) {
require_once $config_file_path;
require_once dirname(dirname($_SERVER['SCRIPT_FILENAME'])) . '/lib/dfCategory_build.php';
} else {
require_once dirname(__FILE__) . '/../../../config/config.inc.php';
require_once dirname(__FILE__) . '/../lib/dfCategory_build.php';
}

require_once dirname(__FILE__) . '/../lib/dfCategory_build.php';

if (!defined('_PS_VERSION_')) {
exit;
}
Expand Down
4 changes: 2 additions & 2 deletions feeds/cms.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
$config_file_path = $root_path . '/config/config.inc.php';
if (file_exists($config_file_path)) {
require_once $config_file_path;
require_once dirname(dirname($_SERVER['SCRIPT_FILENAME'])) . '/lib/dfCategory_build.php';
} else {
require_once dirname(__FILE__) . '/../../../config/config.inc.php';
require_once dirname(__FILE__) . '/../lib/dfCms_build.php';
}

require_once dirname(__FILE__) . '/../lib/dfCms_build.php';

if (!defined('_PS_VERSION_')) {
exit;
}
Expand Down
6 changes: 3 additions & 3 deletions feeds/product.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@
if (file_exists($config_file_path)) {
require_once $config_file_path;
require_once $root_path . '/init.php';
require_once dirname(dirname($_SERVER['SCRIPT_FILENAME'])) . '/doofinder.php';
} else {
require_once dirname(__FILE__) . '/../../../config/config.inc.php';
require_once dirname(__FILE__) . '/../../../init.php';
require_once dirname(__FILE__) . '/../doofinder.php';
}

require_once dirname(__FILE__) . '/../doofinder.php';

dfTools::validateSecurityToken(Tools::getValue('dfsec_hash'));

function slugify($text)
Expand Down Expand Up @@ -169,7 +169,7 @@ function array_merge_by_id_product($array1 = [], $array2 = [])
}

if ($cfg_debug) {
error_log("Starting feed.\n", 3, dirname(__FILE__) . '/doofinder.log');
error_log("Starting feed.\n", 3, 'doofinder.log');
}

// OUTPUT
Expand Down
2 changes: 1 addition & 1 deletion lib/dfCategory_build.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/
if (!class_exists('dfTools')) {
require_once dirname(__FILE__) . '/dfTools.class.php';
require_once 'dfTools.class.php';
}

if (!defined('_PS_VERSION_')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/dfCms_build.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* @license GPLv3
*/
if (!class_exists('dfTools')) {
require_once dirname(__FILE__) . '/dfTools.class.php';
require_once 'dfTools.class.php';
}

if (!defined('_PS_VERSION_')) {
Expand Down
2 changes: 1 addition & 1 deletion lib/dfProduct_build.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
}

if (!class_exists('dfTools')) {
require_once dirname(__FILE__) . '/lib/dfTools.class.php';
require_once 'lib/dfTools.class.php';
}

class DfProductBuild
Expand Down
4 changes: 2 additions & 2 deletions lib/doofinder_api.php
Original file line number Diff line number Diff line change
Expand Up @@ -614,5 +614,5 @@ private function getFilterType($filter)
}
}

include_once dirname(__FILE__) . '/DoofinderResults.php';
include_once dirname(__FILE__) . '/DoofinderException.php';
include_once 'DoofinderResults.php';
include_once 'DoofinderException.php';

0 comments on commit ee919ea

Please sign in to comment.