Index: branches/5.1.x/core/install/install_toolkit.php =================================================================== diff -u -N -r12453 -r12657 --- branches/5.1.x/core/install/install_toolkit.php (.../install_toolkit.php) (revision 12453) +++ branches/5.1.x/core/install/install_toolkit.php (.../install_toolkit.php) (revision 12657) @@ -1,6 +1,6 @@ Conn->Query($sql); } @@ -305,13 +308,27 @@ } $sqls = str_replace("\r\n", "\n", $sqls); // convert to linux line endings - $sqls = preg_replace("/#([^;]*?)\n/", '', $sqls); // remove all comments - $sqls = explode(";\n", $sqls . "\n"); // ensures that last sql won't have ";" in it + $no_comment_sqls = preg_replace("/#\s([^;]*?)\n/is", '', $sqls); // remove all comments "#" on new lines + if ($no_comment_sqls === null) { + // "ini.pcre.backtrack-limit" reached and error happened + $sqls = explode(";\n", $sqls . "\n"); // ensures that last sql won't have ";" in it + $sqls = array_map('trim', $sqls); + + // remove all comments "#" on new lines (takes about 2 seconds for 53000 sqls) + $sqls = preg_replace("/#\s([^;]*?)/", '', $sqls); + } + else { + $sqls = explode(";\n", $no_comment_sqls . "\n"); // ensures that last sql won't have ";" in it + $sqls = array_map('trim', $sqls); + } + + $sql_count = count($sqls); $db_collation = $this->getSystemConfig('Database', 'DBCollation'); - for ($i=$start_from; $iApplication->getUnitOption('theme', 'TableName'); $sql = 'SELECT Name, ' . $id_field . ' - FROM ' . $table_name; + FROM ' . $table_name . 'ORDER BY Name ASC'; return $this->Conn->GetCol($sql, $id_field); } @@ -539,14 +556,88 @@ */ function getModuleName($module_folder) { - if ($module_folder == 'kernel') { - $module_folder = 'in-portal'; + return implode('-', array_map('ucfirst', explode('-', $module_folder))); + } + + /** + * Returns information about module (based on "install/module_info.xml" file) + * + * @param string $module_folder + * @return Array + */ + function getModuleInfo($module_folder) + { + $info_file = MODULES_PATH . '/' . $module_folder . '/install/module_info.xml'; + + if (!file_exists($info_file)) { + return Array (); } - return implode('-', array_map('ucfirst', explode('-', $module_folder))); + $xml_helper =& $this->Application->recallObject('kXMLHelper'); + /* @var $xml_helper kXMLHelper */ + + $root_node =& $xml_helper->Parse( file_get_contents($info_file) ); + + if (!is_object($root_node) || !preg_match('/^kxmlnode/i', get_class($root_node)) || ($root_node->Name == 'ERROR')) { + // non-valid xml file + return Array (); + } + + $ret = Array (); + $current_node =& $root_node->firstChild; + + do { + $ret[ strtolower($current_node->Name) ] = trim($current_node->Data); + } while (($current_node =& $current_node->NextSibling())); + + return $ret; } /** + * Returns nice module string to be used on install/upgrade screens + * + * @param string $module_folder + * @param string $version_string + * @return string + */ + function getModuleString($module_folder, $version_string) + { + // image (if exists) ( ) + + $ret = Array (); + $module_info = $this->getModuleInfo($module_folder); + + if (array_key_exists('name', $module_info) && $module_info['name']) { + $module_name = $module_info['name']; + } + else { + $module_name = $this->getModuleName($module_folder); + } + + if (array_key_exists('image', $module_info) && $module_info['image']) { + $image_src = $module_info['image']; + + if (!preg_match('/^(http|https):\/\//', $image_src)) { + // local image -> make absolute url + $image_src = $this->Application->BaseURL() . $image_src; + } + + $ret[] = '' . htmlspecialchars($module_name) . ''; + } + + if (array_key_exists('description', $module_info) && $module_info['description']) { + $ret[] = $module_info['description']; + } + else { + $ret[] = $module_name; + } + + $ret[] = '(' . $module_name . ' ' . $version_string . ')'; + + return implode(' ', $ret); + } + + /** * Creates module root category in "Home" category using given data and returns it * * @param string $name @@ -571,7 +662,7 @@ $category_fields = Array ( $fields['name'] => $name, 'Filename' => $name, 'AutomaticFilename' => 1, - $fields['description'] => $description, 'Status' => $status, 'Priority' => -9999, + $fields['description'] => $description, 'Status' => STATUS_ACTIVE, 'Priority' => -9999, ); $category_fields['ParentId'] = $this->Application->findModule('Name', 'Core', 'RootCat'); @@ -732,4 +823,21 @@ { $this->Application->HandleEvent($themes_event, 'adm:OnRebuildThemes'); } + + /** + * Checks that file is writable by group or others + * + * @param string $file + * @return boolean + */ + function checkWritePermissions($file) + { + if (DIRECTORY_SEPARATOR == '\\') { + // windows doen't allow to check permissions (always returns null) + return null; + } + + $permissions = fileperms($file); + return $permissions & 0x0010 || $permissions & 0x0002; + } } \ No newline at end of file