/** * Get the modules CSS and combine these */ public function getModuleCSS() { $cacheDir = RM_Environment::getConnector()->getRootPath() . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'userdata' . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'css'; if (is_dir($cacheDir) == false) { $rmConfig = new RM_Config(); $chmodOctal = intval($rmConfig->getValue('rm_config_chmod_value'), 8); mkdir($cacheDir, $chmodOctal); } $cachedCSS = file_exists($cacheDir . DIRECTORY_SEPARATOR . "modules.css"); if (!$cachedCSS) { $newfileContents = ""; $moduleDAO = new RM_Modules(); $modules = $moduleDAO->fetchAllEnabled(); $config = new RM_Module_Config(); foreach ($modules as $module) { $files = RM_Module_Manager::getCssFiles($module->name); foreach ($files as $file) { // read in the css and change the relative paths then add to a cached css file that we will load $fileContents = file_get_contents(RM_Environment::getConnector()->getRootURL() . "RM/userdata/modules/" . $module->name . "/" . RM_Module_Config::CSS . '/' . $file); $search = "/url\\(([^\\)]*)\\)/"; $replace = "url(../../../userdata/modules/" . $module->name . "/images/\$1)"; $newfileContents .= preg_replace($search, $replace, $fileContents); } } $this->_saveCachedCSS($newfileContents, $cacheDir . DIRECTORY_SEPARATOR . "modules.css"); } // return the cached CSS url so it can be included return RM_Environment::getConnector()->getRootURL() . "RM/userdata/temp/css/modules.css"; }
function renewJsonAction() { $extensions = RM_Environment::getInstance()->getOutOfDateExtensions(); $pluginModel = new RM_Plugins(); $pluginManager = new RM_Plugin_Manager($this->_translate); $failedPlugins = array(); foreach ($extensions['plugins'] as $pluginName) { $plugin = $pluginModel->fetchByName($pluginName); try { $pluginManager->autoUpgrade($plugin); } catch (Exception $e) { $failedPlugins[] = $pluginName; continue; } } $moduleModel = new RM_Modules(); $moduleManager = new RM_Module_Manager($this->_translate); $failedModules = array(); foreach ($extensions['modules'] as $moduleName) { $module = $moduleModel->fetchByName($moduleName); try { $moduleManager->autoUpgrade($module); } catch (Exception $e) { $failedModules[] = $moduleName; continue; } } return array('data' => array('success' => true)); }
public function uninstall() { $moduleModel = new RM_Modules(); $module = $moduleModel->find($this->name)->current(); if ($module !== null) { $dependenciesModel = new RM_Dependencies(); $dependencies = $dependenciesModel->getDependencies($module); foreach ($dependencies as $dependency) { $dependency->delete(); } } }
/** * Will initialize the full observers structure */ private function _init() { $model = new RM_Modules(); $modules = $model->fetchAllEnabled(); $manager = new RM_Module_Manager(); foreach ($modules as $module) { $moduleObject = $manager->getModule($module->name); //We will get the last enabled module in the system //that implements one of our internal interfaces if ($moduleObject instanceof RM_Notifications_Observer) { $this->_observers[] = $moduleObject; } } }
/** * @see RM_Dependency_Abstract::validate method * @return bool */ public function validate() { //1. check if module is installed $moduleClassName = 'RM_Module_' . $this->_getName(); if (class_exists($moduleClassName) == false) { return false; } //2. check if module is enabled $moduleModel = new RM_Modules(); $moduleRow = $moduleModel->fetchByName($this->_getName()); if ($moduleModel->isEnabled($moduleRow) == false) { return false; } //3. check it's min version $minModuleVersion = $this->_getVersion(); $moduleVersion = $moduleRow->version; if (version_compare($moduleVersion, $minModuleVersion, '<')) { return false; } return true; }
/** * Private constructor that invokes only from 'getInstance' method */ private function __construct() { $this->_initializeLocale(); $model = new RM_Modules(); $allModules = $model->fetchAll(); $modules = $model->fetchAllEnabled(); foreach ($modules as $module) { $moduleObject = RM_Module_Manager::getModule($module->name); //We will get the last enabled module in the system //that implements one of our internal interfaces if ($moduleObject instanceof RM_Payments_Interface) { $this->_paymentSystem = $moduleObject; } if ($moduleObject instanceof RM_Extras_Interface) { $this->_extrasSystems[] = $moduleObject; } if ($moduleObject instanceof RM_Others_Interface) { $this->_othersSystems[] = $moduleObject; } if ($moduleObject instanceof RM_SEF_Manager_Interface) { $this->_sefManager = $moduleObject; } } $pluginModel = new RM_Plugins(); $allPlugins = $pluginModel->fetchAll(); $plugins = $pluginModel->fetchAllEnabled(); $this->_taxSystem = new RM_Taxes_Default(); foreach ($plugins as $plugin) { $pluginObject = RM_Plugin_Manager::getPlugin($plugin->name); if ($pluginObject instanceof RM_Taxes_Interface) { $this->_taxSystem = $pluginObject; } if ($pluginObject instanceof RM_Discounts_Plugin_Interface) { $this->_discounts[] = $pluginObject; } //We will assign only one deposit system (the last one enabled) if ($pluginObject instanceof RM_Deposit_Plugin_Interface) { $this->_depositSystem = $pluginObject; } } $this->_initializeTranslate($allModules, $allPlugins); }
/** * Full installation process of module * * @param string $tempFileName * @param string $tempFilePath * @param stdclass $json * @return stdclass */ function install($tempFileName, $tempFilePath, $json) { // get config values $rmConfig = new RM_Config(); $chmodOctal = intval($rmConfig->getValue('rm_config_chmod_value'), 8); $chunks = explode('.', $tempFileName); $moduleName = $chunks[0]; //Module name will be always the first chunk, example: price.0.1.1.zip $moduleModel = new RM_Modules(); $existingModule = $moduleModel->fetchByName($moduleName); if ($existingModule !== null) { unlink($tempFilePath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'ModuleAlreadyInstalled')); } $moduleFolderPath = self::getModuleFolderpath($moduleName); if (is_dir($moduleFolderPath)) { $result = RM_Filesystem::deleteFolder($moduleFolderPath); if ($result == false) { unlink($tempFilePath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'ModuleFolderAlreadyExists') . ': ' . $moduleFolderPath); } } $result = mkdir($moduleFolderPath, $chmodOctal); if ($result == false) { unlink($tempFilePath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'CreateModuleFolderFailer')); } else { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Modules.InstallMsg', 'ModuleFolderCreatedSuccessfully')); } //4. unzip module into new directory if (!extension_loaded('zlib')) { unlink($tempFilePath); RM_Filesystem::deleteFolder($moduleFolderPath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'ZlibNotSupported')); } $zip = new PclZip($tempFilePath); $result = $zip->extract(PCLZIP_OPT_PATH, $moduleFolderPath); if (!$result) { unlink($tempFilePath); RM_Filesystem::deleteFolder($moduleFolderPath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'UnzipFailed')); } else { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Modules.InstallMsg', 'UnzipSuccessfully')); } unlink($tempFilePath); chmod($moduleFolderPath, $chmodOctal); //4.0. create separate folder in 'userdata/modules' for a new module, if it's don't exists $userdataFolderPath = self::getModuleUserFolderpath($moduleName) . DIRECTORY_SEPARATOR; if (is_dir($userdataFolderPath)) { $result = RM_Filesystem::deleteFolder($userdataFolderPath); if ($result == false) { throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'ModuleFolderAlreadyExists') . ': ' . $userdataFolderPath); } } if (is_dir($userdataFolderPath) == false) { $result = mkdir($userdataFolderPath, $chmodOctal); if ($result == false) { RM_Filesystem::deleteFolder($moduleFolderPath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'CreateModuleUserdataFolderFailer')); } else { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Modules.InstallMsg', 'ModuleFolderCreatedSuccessfully')); } @rename($moduleFolderPath . DIRECTORY_SEPARATOR . 'views', $userdataFolderPath . 'views'); @chmod($userdataFolderPath . 'views', $chmodOctal); @rename($moduleFolderPath . DIRECTORY_SEPARATOR . 'languages', $userdataFolderPath . 'languages'); @chmod($userdataFolderPath . 'languages', $chmodOctal); @rename($moduleFolderPath . DIRECTORY_SEPARATOR . 'css', $userdataFolderPath . 'css'); @chmod($userdataFolderPath . 'css', $chmodOctal); @rename($moduleFolderPath . DIRECTORY_SEPARATOR . 'images', $userdataFolderPath . 'images'); @chmod($userdataFolderPath . 'images', $chmodOctal); @chmod($moduleFolderPath, $chmodOctal); } //5. get INI file $iniFilePath = $moduleFolderPath . DIRECTORY_SEPARATOR . self::$_iniFilename; if (is_file($iniFilePath) == false) { RM_Filesystem::deleteFolder($moduleFolderPath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'NoIniFile')); } //6. parse INI file $parser = new RM_Module_Config_Parser(); try { $config = $parser->getConfig($iniFilePath); } catch (RM_Exception $e) { //Error in ini file parsing RM_Filesystem::deleteFolder($moduleFolderPath); throw new RM_Exception($e->getMessage()); } if (isset($config->information['module'])) { RM_Filesystem::deleteFolder($moduleFolderPath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'WrongTryToInstallPlugin')); } $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Modules.InstallMsg', 'UnzipSuccess')); //7. invoke SQL install file try { $result = self::installDatabase($moduleFolderPath); } catch (Exception $e) { self::uninstallDatabase($moduleFolderPath); RM_Filesystem::deleteFolder($moduleFolderPath); RM_Filesystem::deleteFolder($userdataFolderPath); throw new RM_Exception($e->getMessage()); } if ($result == false) { self::uninstallDatabase($moduleFolderPath); RM_Filesystem::deleteFolder($moduleFolderPath); RM_Filesystem::deleteFolder($userdataFolderPath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'WrongInstallSQLQueries')); } else { $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Modules.InstallMsg', 'InstallSQLSuccess')); } //8. create a new record in Module database $moduleRow = array(); $moduleRow = $config->information; //TODO: //1.check the insertions $pkey = $moduleModel->insert($moduleRow); //Create a new records in dependencies database table $model = new RM_Dependencies(); if (is_array($config->dependencies)) { foreach ($config->dependencies as $dependency) { $model->insert($dependency); } } //9. get the main class of the module $moduleClassFilepath = $moduleFolderPath . DIRECTORY_SEPARATOR . RM_Module_Config::CLASSES . DIRECTORY_SEPARATOR . 'RM' . DIRECTORY_SEPARATOR . 'Module' . DIRECTORY_SEPARATOR . $config->information['name'] . '.php'; if (is_file($moduleClassFilepath) == false) { self::uninstallDatabase($moduleFolderPath); RM_Filesystem::deleteFolder($moduleFolderPath); RM_Filesystem::deleteFolder($userdataFolderPath); throw new RM_Exception($this->_translate->_('Admin.Modules.InstallMsg', 'DoesntExists')); } require_once $moduleClassFilepath; $moduleClassName = 'RM_Module_' . $config->information['name']; if (class_exists($moduleClassName) == false) { self::uninstallDatabase($moduleFolderPath); RM_Filesystem::deleteFolder($moduleFolderPath); RM_Filesystem::deleteFolder($userdataFolderPath); throw new RM_Exception($moduleClassName . $this->_translate->_('Admin.Modules.InstallMsg', 'DoesntExists')); } $moduleObject = new $moduleClassName(); if (!$moduleObject instanceof RM_Module_Interface) { self::uninstallDatabase($moduleFolderPath); RM_Filesystem::deleteFolder($moduleFolderPath); RM_Filesystem::deleteFolder($userdataFolderPath); throw new RM_Exception($moduleClassName . $this->_translate->_('Admin.Modules.InstallMsg', 'WrongInterface')); } //10. invoke install method of that class (if we need something extra) $result = $moduleObject->install(); $json = $this->_addMessageToJson($json, $this->_translate->_('Admin.Modules.InstallMsg', 'InstallSuccess')); //Check dependencies and if some of them is validate==false disable module $moduleManager = new RM_Module_Manager(RM_Environment::getInstance()->getTranslation()); $dependencyManager = new RM_Dependency_Manager(); $module = $moduleModel->find($pkey)->current(); $dependencies = $dependencyManager->getDependencies($module); foreach ($dependencies as $dependency) { if ($dependency->validate() == false) { try { $moduleModel->disable($module); break; } catch (Exception $e) { //TODO: add log message that we could not disable this module. } } } return $json; }
/** * Initialize autoloading for modules and plugins */ public function initAuloadMP() { $isSafeMode = $this->isSafeMode(); $paths = array(); $modulesDAO = new RM_Modules(); $modules = $modulesDAO->fetchAll(); foreach ($modules as $module) { if ($isSafeMode && $module->core == 0) { continue; } $bothPath = RM_Module_Manager::getModuleFolderpath($module->name, $this->_rootPath) . DIRECTORY_SEPARATOR; $paths[] = $bothPath . RM_Module_Config::CLASSES; $paths[] = $bothPath . RM_Module_Config::CONTROLLERS; } $pluginsDAO = new RM_Plugins(); $plugins = $pluginsDAO->fetchAll(); foreach ($plugins as $plugin) { if ($isSafeMode && $plugin->core == 0) { continue; } $bothPath = RM_Plugin_Manager::getPluginFolderpath($plugin->name, $this->_rootPath) . DIRECTORY_SEPARATOR; $paths[] = $bothPath . RM_Plugin_Config::CLASSES; $paths[] = $bothPath . RM_Plugin_Config::CONTROLLERS; } $MPPathString = implode(PATH_SEPARATOR, $paths); set_include_path(get_include_path() . PATH_SEPARATOR . $MPPathString); }
/** * Returns data for the info grid (grid with language files) on the language page. * * This method returns the list data in JSON format. This is implicated in * lists.js * * @param request iso * @return json the json data for the list. */ public function infogridJsonAction() { $iso = $this->_getParam('iso'); $files = RM_Language_Manager::$files; $jsonFiles = array(); foreach ($files as $file) { $jsonFiles[] = array($file, RM_Language_Manager::TYPE_MAIN . ',' . RM_Language_Manager::TYPE_MAIN, $iso . ',' . $file . ',' . RM_Language_Manager::TYPE_MAIN . ',' . RM_Language_Manager::TYPE_MAIN); } $extensionFiles = RM_Language_Manager::$extensionFiles; $moduleModel = new RM_Modules(); $modules = $moduleModel->fetchAll(); foreach ($modules as $module) { foreach ($extensionFiles as $file) { $jsonFiles[] = array($file, RM_Language_Manager::TYPE_MODULE . ',' . $moduleModel->get($module->name)->getName(), $iso . ',' . $file . ',' . RM_Language_Manager::TYPE_MODULE . ',' . $module->name); } } $pluginModel = new RM_Plugins(); $plugins = $pluginModel->fetchAll(); foreach ($plugins as $plugin) { foreach ($extensionFiles as $file) { $jsonFiles[] = array($file, RM_Language_Manager::TYPE_PLUGIN . ',' . $pluginModel->get($plugin->name)->getName(), $iso . ',' . $file . ',' . RM_Language_Manager::TYPE_PLUGIN . ',' . $plugin->name); } } $json = new stdClass(); $json->total = count($jsonFiles); $json->data = $jsonFiles; return array('data' => $jsonFiles); }
private function _initialize() { $model = new RM_Modules(); $modules = $model->getAll(); foreach ($modules as $moduleObject) { if ($moduleObject instanceof RM_Prices_Interface) { $this->_systems[] = $moduleObject; } } }
public function disableJsonAction() { $json = new stdClass(); $json->success = 1; $json->msg = array(); $ids = $this->_getParam('ids', array()); $manager = new RM_Module_Manager($this->_translate); $model = new RM_Modules(); foreach ($ids as $id) { $row = $model->find($id)->current(); try { $manager->disable($row); } catch (Exception $e) { $json->success = 0; $json->msg[] = $e->getMessage(); } } return array('data' => $json); }
/** * Returns RM_Module_Row or a string with module_name if this module * is not installed in application * * @return RM_Module_Row|string */ function getParentModule() { $model = new RM_Modules(); $module = $model->fetchByName($this->module_name)->current(); return $module; }
/** * Returns all unit objects by it's type * * @param object $criteria this object contains the specification for the * search. * @return Zend_Db_Table_Rowset All units objects */ public function getAll(RM_Unit_Search_Criteria $criteria) { $fieldsNames = array(); $fieldsNames[] = 'rm_units.*'; $languageFieldsNames = array(); $languageFieldsNames[] = 'rm_unit_language_details.*'; if ($criteria->offset === null) { $criteria->offset = 0; } $sql = "\r\n SELECT\r\n " . implode(',', $fieldsNames); if (count($languageFieldsNames) > 0) { $sql .= ", " . implode(',', $languageFieldsNames); } if (!$criteria->language) { $criteria->language = RM_Environment::getInstance()->getLocale(); } $sql .= "\r\n FROM\r\n rm_units\r\n INNER JOIN\r\n rm_unit_language_details ON\r\n rm_units.id = rm_unit_language_details.unit_id"; $sql .= "\r\n AND rm_unit_language_details.iso = '{$criteria->language}'\r\n WHERE 1=1 "; if ($criteria->type) { $sql .= " AND type_id = '" . $criteria->type->id . "' "; } // this gets the units that are unavailable so these are excluded from the results if ($criteria->start_datetime && $criteria->end_datetime) { $reservationPeriod = new RM_Reservation_Period(new RM_Date(strtotime($criteria->start_datetime)), new RM_Date(strtotime($criteria->end_datetime))); if ($criteria->flexible) { //My dates are flexible: every unit with at least one day available should we shown $availableUnitIDs = $this->getFlexibleAvailable($reservationPeriod); if (count($availableUnitIDs) == 0) { $sql .= " AND 1=0 "; //This will returns 0 rows return $this->_getBySQL($sql); } else { $sql .= "\r\n AND rm_units.id IN (" . implode(',', $availableUnitIDs) . ")\r\n "; } } else { $reservedUnits = $this->getReservedUnits($reservationPeriod)->toArray(); $unitsWithAvailbilityCheckDisabled = RM_Environment::getInstance()->getPriceSystem()->getUnitWithAvailabiltyCheckDisabled(); if (count($reservedUnits) > 0) { $reservedUnits = array_diff($reservedUnits, $unitsWithAvailbilityCheckDisabled); } if (count($reservedUnits) > 0) { $reservedUnitIDs = array(); foreach ($reservedUnits as $unit) { if ($unit['id']) { $reservedUnitIDs[] = $unit['id']; } } $reservedUnitsCSV = implode(',', $reservedUnitIDs); if ($reservedUnitsCSV != "," && $reservedUnitsCSV != "") { $sql .= "\r\n AND rm_units.id NOT IN (" . $reservedUnitsCSV . ")\r\n "; } } //we need to check min period length $manager = RM_Prices_Manager::getInstance(); $minPeriodNotUnitIDs = $manager->getByMinPeriod($reservationPeriod); if (count($minPeriodNotUnitIDs) > 0) { $minPeriodNotUnitIDsCSV = implode(',', $minPeriodNotUnitIDs); if ($minPeriodNotUnitIDsCSV != "," && $minPeriodNotUnitIDsCSV != "") { $sql .= "\r\n AND rm_units.id NOT IN (" . $minPeriodNotUnitIDsCSV . ")\r\n "; } } } } if ($criteria->image == 1) { $unitIDsWithImages = $this->getWithImages(); if (count($unitIDsWithImages) == 0) { $sql .= " AND 1=0 "; //This will returns 0 rows return $this->_getBySQL($sql); } else { $sql .= "\r\n AND rm_units.id IN (" . implode(',', $unitIDsWithImages) . ")\r\n "; } } //3. prices: from - to if ((int) $criteria->prices_from != 0 || (int) $criteria->prices_to != 99999999) { if ($criteria->prices_from || $criteria->prices_to) { if ($criteria->start_datetime && $criteria->end_datetime) { $reservationPeriod = new RM_Reservation_Period(new RM_Date(strtotime($criteria->start_datetime)), new RM_Date(strtotime($criteria->end_datetime))); } else { $reservationPeriod = null; } $priceRangeUnitIDs = RM_Environment::getInstance()->getPriceSystem()->getByPriceRange($criteria->prices_from, $criteria->prices_to, $reservationPeriod); if (count($priceRangeUnitIDs) == 0) { $sql .= " AND 1=0 "; //This will returns 0 rows return $this->_getBySQL($sql); } else { $sql .= "\r\n AND rm_units.id IN (" . implode(',', $priceRangeUnitIDs) . ")\r\n "; } } } //4. check all plugins and modules to extend advanced search $model = new RM_Modules(); $modules = $model->getAllEnabled(); foreach ($modules as $module) { if ($module instanceof RM_Search_Advanced_Interface) { $unitIDs = $module->getAdvancedSearchUnitIDs($criteria); if ($unitIDs !== false) { if (count($unitIDs) == 0) { $sql .= " AND 1=0 "; //This will returns 0 rows return $this->_getBySQL($sql); } elseif (count($unitIDs) > 0) { $sql .= "\r\n -- added by modules: " . $module->name . "\r\n AND rm_units.id IN (" . implode(',', $unitIDs) . ")\r\n "; } } } } $pluginModel = new RM_Plugins(); $plugins = $pluginModel->getAllEnabled(); foreach ($plugins as $plugin) { if ($plugin instanceof RM_Search_Advanced_Interface) { $unitIDs = $plugin->getAdvancedSearchUnitIDs($criteria); if ($unitIDs !== false) { if (count($unitIDs) == 0) { $sql .= " AND 1=0 "; //This will returns 0 rows return $this->_getBySQL($sql); } elseif (count($unitIDs) > 0) { $sql .= "\r\n -- added by modules: " . $plugin->name . "\r\n AND rm_units.id IN (" . implode(',', $unitIDs) . ")\r\n "; } } } } if ($criteria->publishedOnly === true) { $sql .= " AND rm_units.published='1'"; } if (count($criteria->filters) > 0) { $filterConditions = array(); foreach ($criteria->filters as $filter) { $filterConditions = array_merge($filterConditions, $this->_getConditions($filter)); } $filterSQL = implode(" AND ", $filterConditions); $sql .= " AND " . $filterSQL; } if ($criteria->order !== null) { if ($criteria->order == 'random') { $sessionID = session_id(); $random = hexdec($sessionID[0]); $sql .= " ORDER BY RAND(" . $random . ") "; } elseif ($criteria->order != 'price') { $sql .= " ORDER BY {$criteria->order} "; } } if ($criteria->count !== null) { $sql .= " LIMIT {$criteria->offset}, {$criteria->count} "; } return $this->_getBySQL($sql); }
private function _getModules() { $model = new RM_Modules(); $modules = $model->getAllEnabled(); $result = array(); foreach ($modules as $module) { $node = $module->getNode(); if ($node !== null) { $result[] = $node; } } return $result; }