* @copyright 2015 PrestaShow.pl * @license http://PrestaShow.pl/license */ if (!function_exists('getModuleName')) { function IsModulesInPath($dirpath) { $explode = explode(DIRECTORY_SEPARATOR, $dirpath); return in_array('modules', $explode); } function getModulePath($filepath_) { $filepath = findRealFilePath($filepath_); if (Tools::getValue('controller') && stripos(Tools::getValue('controller'), 'PShow')) { $controller = strtolower(Tools::getValue('controller')); $bestpath = false; for ($i = 0; $i <= strlen($controller); ++$i) { $tmp = _PS_MODULE_DIR_ . substr($controller, 0, $i); $bestpath = is_dir($tmp) ? $tmp : $bestpath; } return $bestpath . '/'; } if (Tools::substr($filepath, -1, 1) == DIRECTORY_SEPARATOR) { $filepath = Tools::substr($filepath, 0, Tools::strlen($filepath) - 1); } $explode = explode(DIRECTORY_SEPARATOR, dirname($filepath)); $stay = array_search('modules', $explode) + 1; if (!array_key_exists($stay, $explode)) { return $filepath . DIRECTORY_SEPARATOR; } $newpath_ = array(); for ($i = 0; $i <= $stay; ++$i) { $newpath_[] = $explode[$i]; } $newpath = implode(DIRECTORY_SEPARATOR, $newpath_); return $newpath . DIRECTORY_SEPARATOR; } /** * * @param string $filepath * @return string */ function findRealFilePath($filepath) { $backtrace = debug_backtrace(); foreach ($backtrace as $call) { if (array_key_exists('file', $call) && stripos($call['file'], '/system/') === false && stripos($call['file'], '/modules/') !== false) { return $call['file']; } } // this should not happen ! return $filepath; } function getModuleName($filepath_) { $filepath = findRealFilePath($filepath_); $module_path = getModulePath($filepath); $module_path_arr = explode(DIRECTORY_SEPARATOR, $module_path); return $module_path_arr[count($module_path_arr) - 2]; } } // fix for Windows Server $presta_path = str_replace(array('/', '//'), DIRECTORY_SEPARATOR, _PS_MODULE_DIR_); $module_classes = false; //Cache::getInstance()->get(getModuleName(__FILE__) . "_classes"); if (true || _PS_MODE_DEV_ || !$module_classes) { $module_classes = array(); $glob_classes = glob(dirname(getModulePath(__FILE__)) . "/*/vendor/system/classes/*.php"); usort($glob_classes, create_function('$a, $b', 'return filemtime($b) - filemtime($a);')); $added = array(); foreach ($glob_classes as $file) { $path = "modules/" . str_replace($presta_path, "", $file); $classname = pathinfo($path, PATHINFO_FILENAME); if ($classname == 'AdminController') { continue; } if (in_array($classname, $added)) { continue; } array_push($added, $classname); if (version_compare(_PS_VERSION_, '1.6', '>=')) { $module_classes[$classname] = array( "path" => $path, "type" => "class", "override" => false ); } else { $module_classes[$classname] = $path; } } $glob_classes = glob(getModulePath(__FILE__) . "controllers/*.php"); foreach ($glob_classes as $file) { $path = "modules/" . str_replace($presta_path, "", $file); $classname = pathinfo($path, PATHINFO_FILENAME); if (version_compare(_PS_VERSION_, '1.6', '>=')) { $module_classes[$classname] = array( "path" => $path, "type" => "class", "override" => false ); } else { $module_classes[$classname] = $path; } } $glob_classes = glob(getModulePath(__FILE__) . "classes/*.php"); foreach ($glob_classes as $file) { $path = "modules/" . str_replace($presta_path, "", $file); $classname = pathinfo($path, PATHINFO_FILENAME); if (version_compare(_PS_VERSION_, '1.6', '>=')) { $module_classes[$classname] = array( "path" => $path, "type" => "class", "override" => false ); } else { $module_classes[$classname] = $path; } } //$module_classes = serialize($module_classes); //Cache::getInstance()->set(getModuleName(__FILE__) . "_classes", $module_classes); } //Autoload::getInstance()->index = array_merge( // Autoload::getInstance()->index, unserialize($module_classes) //); Autoload::getInstance()->index = array_merge( Autoload::getInstance()->index, $module_classes ); // get module main file if (!class_exists(getModuleName(__FILE__))) { $path = getModulePath(__FILE__) . getModuleName(__FILE__) . ".php"; if (file_exists($path)) { require_once $path; } } if (!class_exists('PShow_Settings')) { class PShow_Settings extends PShowSettingsAbstract { public static $settings = array(); } } if (!function_exists('getDiskFreeSpace')) { function getDiskFreeSpace() { if (!function_exists('exec')) { echo 'Not supported'; return; } if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { echo 'Windows not supported'; return; } $sizes = 0; exec("df -g / 2> /dev/null | awk 'FNR == 2 {print $4}'", $sizes); if (!count($sizes)) { echo 'Check unavailable'; return; } $size = reset($sizes); echo $size . '/'; $sizes = 0; exec("df -g / 2> /dev/null | awk 'FNR == 2 {print $2}'", $sizes); if (!count($sizes)) { echo 'Check unavailable'; return; } $size = reset($sizes); echo $size; } } if (!function_exists('showTip')) { function showTip($params) { if (!array_key_exists('id', $params)) { $params['id'] = uniqid(); } if (!array_key_exists('type', $params)) { $params['type'] = 'info'; } if (!array_key_exists('message', $params)) { $params['message'] = 'Enter message...'; } if (!PShow_Settings::getInstance(__FILE__)->get('tip_' . $params['id'])) { echo '
×

' . $params['message'] . '

'; } } smartyRegisterFunction(Context::getContext()->smarty, 'function', 'showTip', 'showTip'); } if (!function_exists('addJsDef') && !isset(Context::getContext()->smarty->registered_plugins[Smarty::PLUGIN_FUNCTION]['addJsDef'])) { function addJsDef($js_def) { Media::addJsDef($js_def); } smartyRegisterFunction(Context::getContext()->smarty, 'function', 'addJsDef', 'addJsDef'); }