Esempio n. 1
0
 /**
  * Обработка отправки формы
  *
  * @return bool
  */
 public function process()
 {
     /**
      * Проверяем корректность емайла
      */
     $sMail = InstallCore::getRequestStr('admin_mail');
     if (!preg_match("/^[\\da-z\\_\\-\\.\\+]+@[\\da-z_\\-\\.]+\\.[a-z]{2,5}\$/i", $sMail)) {
         return $this->addError(InstallCore::getLang('steps.installAdmin.errors.mail'));
     }
     /**
      * Проверяем корректность пароль
      */
     $sPasswd = InstallCore::getRequestStr('admin_passwd');
     if (mb_strlen($sPasswd, 'UTF-8') < 3) {
         return $this->addError(InstallCore::getLang('steps.installAdmin.errors.passwd'));
     }
     /**
      * Получаем данные коннекта к БД из конфига
      */
     InstallConfig::$sFileConfig = dirname(INSTALL_DIR) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.local.php';
     /**
      * Коннект к серверу БД
      */
     if (!($oDb = $this->getDBConnection(InstallConfig::get('db.params.host'), InstallConfig::get('db.params.port'), InstallConfig::get('db.params.user'), InstallConfig::get('db.params.pass')))) {
         return false;
     }
     /**
      * Выбираем БД
      */
     if (!@mysqli_select_db($oDb, InstallConfig::get('db.params.dbname'))) {
         return $this->addError(InstallCore::getLang('db.errors.db_query'));
     }
     /**
      * Обновляем пользователя
      */
     $sPrefix = InstallConfig::get('db.table.prefix');
     $sQuery = "\n\t\t\tUPDATE `{$sPrefix}user`\n\t\t\tSET\n\t\t\t\t`user_mail`\t = '{$sMail}',\n\t\t\t\t`user_admin`\t = '1',\n\t\t\t\t`user_password` = '" . md5($sPasswd) . "'\n\t\t\tWHERE `user_id` = 1";
     if (!mysqli_query($oDb, $sQuery)) {
         return $this->addError(InstallCore::getLang('db.errors.db_query'));
     }
     return true;
 }
Esempio n. 2
0
<?php

error_reporting(E_ALL);
ini_set('display_errors', 1);
set_time_limit(0);
header('Content-Type: text/html; charset=utf-8');
require_once 'bootstrap.php';
/**
 * Определяем группы с шагами
 */
$aGroups = array('install' => array('checkRequirements', 'installDb', 'installAdmin', 'installComplete'), 'update' => array('checkRequirements', 'updateDb' => array('hide_create_db' => true), 'updateVersion', 'updateComplete'));
$oInstall = new InstallCore($aGroups);
$oInstall->run();
Esempio n. 3
0
 protected function loadStoredData()
 {
     $aData = isset($_COOKIE[self::COOKIE_NAME]) ? $_COOKIE[self::COOKIE_NAME] : '';
     if (get_magic_quotes_gpc()) {
         $this->stripslashes($aData);
     }
     self::$aStoredData = $aData ? @unserialize($aData) : array();
 }
Esempio n. 4
0
    if (!isset($aArgs[2])) {
        console_echo(InstallCore::getLang('console.command.run.params_step_empty'), true);
    }
    $sStep = install_func_camelize($aArgs[2]);
    $sClass = 'InstallStep' . ucfirst($sStep);
    if (!class_exists($sClass)) {
        console_echo(InstallCore::getLang('Not found step ' . $sStep), true);
    }
    /**
     * Хардкодим параметр для шага обновления
     * TODO: убрать и переделать на нормальную консольную утилиту
     */
    $_REQUEST['from_version'] = isset($aArgs[3]) ? $aArgs[3] : '';
    /**
     * Создаем объект шага и запускаем его
     */
    $oStep = new $sClass('fake', array());
    if ($oStep->process()) {
        console_echo(InstallCore::getLang('console.command_successful'));
    } else {
        $aErrors = $oStep->getErrors();
        if ($aErrors) {
            $sMsgError = join("\n", $aErrors);
        } else {
            $sMsgError = InstallCore::getLang('console.command_failed');
        }
        console_echo($sMsgError, true);
    }
} else {
    console_echo(InstallCore::getLang('console.command_empty'), true);
}
Esempio n. 5
0
 public function lang($sName)
 {
     return InstallCore::getLang($sName);
 }
<p><label for=""><?php 
echo $this->lang('steps.installAdmin.form.mail.title');
?>
</label>
<input type="text" name="admin_mail" value="<?php 
echo htmlspecialchars(InstallCore::getRequestStr('admin_mail'));
?>
"></p>

<p><label for=""><?php 
echo $this->lang('steps.installAdmin.form.passwd.title');
?>
</label>
<input type="password" name="admin_passwd" value="<?php 
echo htmlspecialchars(InstallCore::getRequestStr('admin_passwd'));
?>
"></p>
Esempio n. 7
0
 public static function checkFile($bCheckWritable = true)
 {
     if (is_null(self::$sFileConfig) or !file_exists(self::$sFileConfig)) {
         self::$sLastError = InstallCore::getLang('config.errors.file_not_found');
         return false;
     }
     if ($bCheckWritable) {
         if (!is_writable(self::$sFileConfig)) {
             self::$sLastError = InstallCore::getLang('config.errors.file_not_writable');
             return false;
         }
     }
     return true;
 }
Esempio n. 8
0
 protected function processDbCheck()
 {
     /**
      * Коннект к серверу БД
      */
     if (!($oDb = $this->getDBConnection(InstallCore::getRequestStr('db.params.host'), InstallCore::getRequestStr('db.params.port'), InstallCore::getRequestStr('db.params.user'), InstallCore::getRequestStr('db.params.pass')))) {
         return false;
     }
     /**
      * Выбор БД
      */
     $sNameDb = InstallCore::getRequestStr('db.params.dbname');
     if (!InstallCore::getRequest('db_create')) {
         if (!@mysqli_select_db($oDb, $sNameDb)) {
             return $this->addError(InstallCore::getLang('steps.installDb.errors.db_not_found'));
         }
     } else {
         /**
          * Пытаемся создать БД
          */
         @mysqli_query($oDb, "CREATE DATABASE IF NOT EXISTS `{$sNameDb}` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci");
         if (!@mysqli_select_db($oDb, $sNameDb)) {
             return $this->addError(InstallCore::getLang('steps.installDb.errors.db_not_create'));
         }
     }
     /**
      * Проверяем корректность префикса таблиц
      */
     if (!preg_match('#^[a-z0-9\\_]*$#i', InstallCore::getRequestStr('db.table.prefix'))) {
         return $this->addError(InstallCore::getLang('steps.installDb.errors.db_table_prefix'));
     }
     /**
      * Определяем поддержку InnoDB
      */
     $sEngineDB = 'MyISAM';
     if ($aRes = @mysqli_query($oDb, 'SHOW ENGINES')) {
         while ($aRow = mysqli_fetch_assoc($aRes)) {
             if (strtoupper($aRow['Engine']) == 'INNODB' and in_array(strtoupper($aRow['Support']), array('DEFAULT', 'YES'))) {
                 $sEngineDB = 'InnoDB';
                 break;
             }
         }
     }
     $sPathRootWeb = $this->getPathRootWeb();
     $aDirs = array();
     $sDirs = trim(str_replace('http://' . $_SERVER['HTTP_HOST'], '', $sPathRootWeb), '/');
     if ($sDirs != '') {
         $aDirs = explode('/', $sDirs);
     }
     /**
      * Прописываем параметры в конфиг
      */
     $aSave = array('db.params.host' => InstallCore::getRequestStr('db.params.host'), 'db.params.port' => InstallCore::getRequestStr('db.params.port'), 'db.params.dbname' => InstallCore::getRequestStr('db.params.dbname'), 'db.params.user' => InstallCore::getRequestStr('db.params.user'), 'db.params.pass' => InstallCore::getRequestStr('db.params.pass'), 'db.table.prefix' => InstallCore::getRequestStr('db.table.prefix'), 'db.tables.engine' => $sEngineDB, 'path.root.web' => $sPathRootWeb, 'path.offset_request_url' => count($aDirs));
     if (!InstallConfig::save($aSave)) {
         return $this->addError(InstallConfig::$sLastError);
     }
     return array($oDb, $sEngineDB);
 }
 public function show()
 {
     /**
      * Проверяем требования
      */
     $sAdditionalSolution = '';
     $aRequirements = array();
     if (!version_compare(PHP_VERSION, '5.3.2', '>=')) {
         $aRequirements[] = array('name' => 'php_version', 'current' => PHP_VERSION);
     }
     if (!in_array(strtolower(@ini_get('safe_mode')), array('0', 'off', ''))) {
         $aRequirements[] = array('name' => 'safe_mode', 'current' => InstallCore::getLang('yes'));
     }
     if (!@preg_match('//u', '')) {
         $aRequirements[] = array('name' => 'utf8', 'current' => InstallCore::getLang('no'));
     }
     if (!@extension_loaded('mbstring')) {
         $aRequirements[] = array('name' => 'mbstring', 'current' => InstallCore::getLang('no'));
     }
     if (!in_array(strtolower(@ini_get('mbstring.func_overload')), array('0', '4', 'no overload'))) {
         $aRequirements[] = array('name' => 'mbstring_func_overload', 'current' => InstallCore::getLang('yes'));
     }
     if (!@extension_loaded('SimpleXML')) {
         $aRequirements[] = array('name' => 'xml', 'current' => InstallCore::getLang('no'));
     }
     if (@extension_loaded('xdebug')) {
         $iLevel = (int) @ini_get('xdebug.max_nesting_level');
         if ($iLevel < 1000) {
             $aRequirements[] = array('name' => 'xdebug', 'current' => InstallCore::getLang('yes') . " ({$iLevel})");
         }
     }
     /**
      * Права на запись файлов
      */
     $bWriteSolutions = false;
     $sAppDir = dirname(INSTALL_DIR);
     $sDir = dirname($sAppDir) . DIRECTORY_SEPARATOR . 'uploads';
     if (!is_dir($sDir) or !is_writable($sDir)) {
         $aRequirements[] = array('name' => 'dir_uploads', 'current' => InstallCore::getLang('is_not_writable'));
         $bWriteSolutions = true;
     }
     $sDir = $sAppDir . DIRECTORY_SEPARATOR . 'plugins';
     if (!is_dir($sDir) or !is_writable($sDir)) {
         $aRequirements[] = array('name' => 'dir_plugins', 'current' => InstallCore::getLang('is_not_writable'));
         $bWriteSolutions = true;
     }
     $sDir = $sAppDir . DIRECTORY_SEPARATOR . 'tmp';
     if (!is_dir($sDir) or !is_writable($sDir)) {
         $aRequirements[] = array('name' => 'dir_tmp', 'current' => InstallCore::getLang('is_not_writable'));
         $bWriteSolutions = true;
     }
     $sDir = $sAppDir . DIRECTORY_SEPARATOR . 'logs';
     if (!is_dir($sDir) or !is_writable($sDir)) {
         $aRequirements[] = array('name' => 'dir_logs', 'current' => InstallCore::getLang('is_not_writable'));
         $bWriteSolutions = true;
     }
     $sFile = $sAppDir . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.local.php';
     if (!is_file($sFile) or !is_writable($sFile)) {
         $aRequirements[] = array('name' => 'file_config_local', 'current' => InstallCore::getLang('is_not_writable'));
         $bWriteSolutions = true;
     }
     if (count($aRequirements)) {
         InstallCore::setNextStepDisable();
     }
     if ($bWriteSolutions) {
         $sBuildPath = $sAppDir . DIRECTORY_SEPARATOR . 'install' . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'build.sh';
         $sAdditionalSolution .= '<b>' . InstallCore::getLang('steps.checkRequirements.writable_solution') . '</b><br/>';
         $sAdditionalSolution .= '<i>chmod 0755 ' . $sBuildPath . '</i><br/>';
         $sAdditionalSolution .= '<i>' . $sBuildPath . '</i><br/>';
     }
     $this->assign('requirements', $aRequirements);
     $this->assign('additionalSolution', $sAdditionalSolution);
 }
Esempio n. 10
0
 protected function importDumpDB($oDb, $sFile, $aParams = null)
 {
     $sFileQuery = @file_get_contents($sFile);
     if (is_null($aParams)) {
         $aParams = $this->aDbParams;
     }
     if (isset($aParams['prefix'])) {
         $sFileQuery = str_replace('prefix_', $aParams['prefix'], $sFileQuery);
     }
     $aQuery = preg_split("#;(\n|\r)#", $sFileQuery, null, PREG_SPLIT_NO_EMPTY);
     /**
      * Массив для сбора ошибок
      */
     $aErrors = array();
     if (isset($aParams['check_table'])) {
         /**
          * Смотрим, какие таблицы существуют в базе данных
          */
         $aDbTables = array();
         $aResult = @mysqli_query($oDb, "SHOW TABLES");
         if (!$aResult) {
             return array('result' => false, 'errors' => array($this->addError(InstallCore::getLang('db.errors.db_query'))));
         }
         while ($aRow = mysqli_fetch_array($aResult, MYSQLI_NUM)) {
             $aDbTables[] = $aRow[0];
         }
         /**
          * Если среди таблиц БД уже есть нужная таблица, то выполнять SQL-дамп не нужно
          */
         if (in_array($aParams['prefix'] . $aParams['check_table'], $aDbTables)) {
             return array('result' => true, 'errors' => array());
         }
     }
     /**
      * Проверка на существование поля
      */
     if (isset($aParams['check_table_field'])) {
         list($sCheckTable, $sCheckField) = $aParams['check_table_field'];
         $sCheckTable = str_replace('prefix_', $aParams['prefix'], $sCheckTable);
         $aResult = @mysqli_query($oDb, "SHOW FIELDS FROM `{$sCheckTable}`");
         if (!$aResult) {
             return array('result' => false, 'errors' => array($this->addError(InstallCore::getLang('db.errors.db_query'))));
         }
         while ($aRow = mysqli_fetch_assoc($aResult)) {
             if ($aRow['Field'] == $sCheckField) {
                 return array('result' => true, 'errors' => array());
             }
         }
     }
     /**
      * Выполняем запросы по очереди
      */
     foreach ($aQuery as $sQuery) {
         $sQuery = trim($sQuery);
         /**
          * Заменяем движек, если таковой указан в запросе
          */
         if (isset($aParams['engine'])) {
             $sQuery = str_ireplace('ENGINE=InnoDB', "ENGINE={$aParams['engine']}", $sQuery);
         }
         if ($sQuery != '') {
             $bResult = mysqli_query($oDb, $sQuery);
             if (!$bResult) {
                 $aErrors[] = mysqli_error($oDb);
             }
         }
     }
     return array('result' => count($aErrors) ? false : true, 'errors' => $aErrors);
 }
Esempio n. 11
0
 /**
  * Конвертор версии 1.0.3 в 2.0.0
  *
  * @param $oDb
  *
  * @return bool
  */
 public function convertFrom_1_0_3_to_2_0_0($oDb)
 {
     /**
      * Запускаем SQL патч
      */
     $sFile = 'sql' . DIRECTORY_SEPARATOR . 'patch_1.0.3_to_2.0.0.sql';
     list($bResult, $aErrors) = array_values($this->importDumpDB($oDb, InstallCore::getDataFilePath($sFile), array('engine' => InstallConfig::get('db.tables.engine'), 'prefix' => InstallConfig::get('db.table.prefix'), 'check_table' => 'cron_task')));
     if ($bResult) {
         /**
          * Проверяем необходимость конвертировать таблицу плагина Page
          */
         if ($this->dbCheckTable("prefix_page")) {
             $sFile = 'sql' . DIRECTORY_SEPARATOR . 'patch_page_1.3_to_2.0.sql';
             list($bResult, $aErrors) = array_values($this->importDumpDB($oDb, InstallCore::getDataFilePath($sFile), array('engine' => InstallConfig::get('db.tables.engine'), 'prefix' => InstallConfig::get('db.table.prefix'), 'check_table_field' => array('prefix_page', 'id'))));
             if (!$bResult) {
                 return $this->addError(join('<br/>', $aErrors));
             }
         }
         /**
          * Конвертируем опросы
          * Сначала проверяем необходимость конвертации опросов
          */
         if ($this->dbCheckTable("prefix_topic_question_vote")) {
             $iPage = 1;
             $iLimitCount = 50;
             $iLimitStart = 0;
             while ($aTopics = $this->dbSelect("SELECT t.*, c.topic_extra FROM prefix_topic as t, prefix_topic_content as c WHERE topic_type = 'question' and t.topic_id = c.topic_id LIMIT {$iLimitStart},{$iLimitCount}")) {
                 $iPage++;
                 $iLimitStart = ($iPage - 1) * $iLimitCount;
                 /**
                  * Топики
                  */
                 foreach ($aTopics as $aTopic) {
                     $aPollData = @unserialize($aTopic['topic_extra']);
                     if (!isset($aPollData['answers'])) {
                         continue;
                     }
                     /**
                      * Создаем опрос
                      */
                     $aFields = array('user_id' => $aTopic['user_id'], 'target_type' => 'topic', 'target_id' => $aTopic['topic_id'], 'title' => htmlspecialchars($aTopic['topic_title']), 'count_answer_max' => 1, 'count_vote' => isset($aPollData['count_vote']) ? $aPollData['count_vote'] : 0, 'count_abstain' => isset($aPollData['count_vote_abstain']) ? $aPollData['count_vote_abstain'] : 0, 'date_create' => $aTopic['topic_date_add']);
                     if ($iPollId = $this->dbInsertQuery('prefix_poll', $aFields)) {
                         foreach ($aPollData['answers'] as $iAnswerIdOld => $aAnswer) {
                             /**
                              * Создаем вариант ответа
                              */
                             $aFields = array('poll_id' => $iPollId, 'title' => htmlspecialchars($aAnswer['text']), 'count_vote' => htmlspecialchars($aAnswer['count']), 'date_create' => $aTopic['topic_date_add']);
                             if ($iAnswerId = $this->dbInsertQuery('prefix_poll_answer', $aFields)) {
                                 /**
                                  * Получаем список кто голосовал за этот вариант
                                  */
                                 if ($aVotes = $this->dbSelect("SELECT * FROM prefix_topic_question_vote WHERE topic_id = '{$aTopic['topic_id']}' AND answer = '{$iAnswerIdOld}' ")) {
                                     foreach ($aVotes as $aVote) {
                                         /**
                                          * Добавляем новый факт голосования за вариант
                                          */
                                         $aFields = array('poll_id' => $iPollId, 'user_id' => $aVote['user_voter_id'], 'answers' => serialize(array($iAnswerId)), 'date_create' => $aTopic['topic_date_add']);
                                         $this->dbInsertQuery('prefix_poll_vote', $aFields);
                                     }
                                 }
                             }
                         }
                         /**
                          * Добавляем факты голосования воздержавшихся
                          */
                         /**
                          * Получаем список кто голосовал за этот вариант
                          */
                         if ($aVotes = $this->dbSelect("SELECT * FROM prefix_topic_question_vote WHERE topic_id = '{$aTopic['topic_id']}' AND answer = -1 ")) {
                             foreach ($aVotes as $aVote) {
                                 /**
                                  * Добавляем новый факт воздержания
                                  */
                                 $aFields = array('poll_id' => $iPollId, 'user_id' => $aVote['user_voter_id'], 'answers' => serialize(array()), 'date_create' => $aTopic['topic_date_add']);
                                 $this->dbInsertQuery('prefix_poll_vote', $aFields);
                             }
                         }
                     }
                     /**
                      * Меняем тип топика
                      */
                     $this->dbQuery("UPDATE prefix_topic SET topic_type = 'topic' WHERE topic_id ='{$aTopic['topic_id']}'");
                     /**
                      * Убираем лишние данные из topic_extra
                      */
                     unset($aPollData['answers']);
                     unset($aPollData['count_vote_abstain']);
                     unset($aPollData['count_vote']);
                     $sExtra = mysqli_escape_string($this->rDbLink, serialize($aPollData));
                     $this->dbQuery("UPDATE prefix_topic_content SET topic_extra = '{$sExtra}' WHERE topic_id ='{$aTopic['topic_id']}'");
                 }
             }
             /**
              * Удаляем старые таблицы
              */
             if (!$this->getErrors()) {
                 $this->dbQuery('DROP TABLE prefix_topic_question_vote');
             }
         }
         /**
          * Конвертируем топик-ссылки
          */
         $iPage = 1;
         $iLimitCount = 50;
         $iLimitStart = 0;
         while ($aTopics = $this->dbSelect("SELECT t.*, c.topic_extra, c.topic_text, c.topic_text_short, c.topic_text_source FROM prefix_topic as t, prefix_topic_content as c WHERE topic_type = 'link' and t.topic_id = c.topic_id LIMIT {$iLimitStart},{$iLimitCount}")) {
             $iPage++;
             $iLimitStart = ($iPage - 1) * $iLimitCount;
             /**
              * Топики
              */
             foreach ($aTopics as $aTopic) {
                 $aData = @unserialize($aTopic['topic_extra']);
                 if (!isset($aData['url'])) {
                     continue;
                 }
                 /**
                  * Переносим ссылку в текст топика
                  */
                 $sUrl = $aData['url'];
                 if (strpos($sUrl, '://') === false) {
                     $sUrl = 'http://' . $sUrl;
                 }
                 $sUrl = htmlspecialchars($sUrl);
                 $sTextAdd = "\n<br/><br/><a href=\"{$sUrl}\">{$sUrl}</a>";
                 $aTopic['topic_text'] .= $sTextAdd;
                 $aTopic['topic_text_short'] .= $sTextAdd;
                 $aTopic['topic_text_source'] .= $sTextAdd;
                 unset($aData['url']);
                 $sExtra = mysqli_escape_string($this->rDbLink, serialize($aData));
                 $sText = mysqli_escape_string($this->rDbLink, $aTopic['topic_text']);
                 $sTextShort = mysqli_escape_string($this->rDbLink, $aTopic['topic_text_short']);
                 $sTextSource = mysqli_escape_string($this->rDbLink, $aTopic['topic_text_source']);
                 $this->dbQuery("UPDATE prefix_topic_content SET topic_extra = '{$sExtra}', topic_text = '{$sText}', topic_text_short = '{$sTextShort}', topic_text_source = '{$sTextSource}'  WHERE topic_id ='{$aTopic['topic_id']}'");
                 /**
                  * Меняем тип топика
                  */
                 $this->dbQuery("UPDATE prefix_topic SET topic_type = 'topic' WHERE topic_id ='{$aTopic['topic_id']}'");
             }
         }
         /**
          * Конвертируем топик-фотосеты
          */
         if ($this->dbCheckTable("prefix_topic_photo")) {
             $iPage = 1;
             $iLimitCount = 50;
             $iLimitStart = 0;
             while ($aTopics = $this->dbSelect("SELECT t.*, c.topic_extra, c.topic_text, c.topic_text_short, c.topic_text_source FROM prefix_topic as t, prefix_topic_content as c WHERE topic_type = 'photoset' and t.topic_id = c.topic_id LIMIT {$iLimitStart},{$iLimitCount}")) {
                 $iPage++;
                 $iLimitStart = ($iPage - 1) * $iLimitCount;
                 /**
                  * Топики
                  */
                 foreach ($aTopics as $aTopic) {
                     $aData = @unserialize($aTopic['topic_extra']);
                     if (!isset($aData['main_photo_id'])) {
                         continue;
                     }
                     /**
                      * Получаем фото
                      */
                     if ($aPhotos = $this->dbSelect("SELECT * FROM prefix_topic_photo WHERE topic_id = '{$aTopic['topic_id']}' ")) {
                         $aMediaItems = array();
                         foreach ($aPhotos as $aPhoto) {
                             /**
                              * Необходимо перенести изображение в media и присоеденить к топику
                              */
                             $sFileSource = $this->convertPathWebToServer($aPhoto['path']);
                             /**
                              * Формируем список старых изображений для удаления
                              */
                             $sMask = pathinfo($sFileSource, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . pathinfo($sFileSource, PATHINFO_FILENAME) . '_*';
                             $aFilesForRemove = array();
                             if ($aPaths = glob($sMask)) {
                                 foreach ($aPaths as $sPath) {
                                     $aFilesForRemove[$sPath] = $sPath;
                                 }
                             }
                             if ($oImage = $this->createImageObject($sFileSource)) {
                                 $iWidth = $oImage->getSize()->getWidth();
                                 $iHeight = $oImage->getSize()->getHeight();
                                 if ($this->resizeImage($oImage, 1000)) {
                                     if ($sFileSave = $this->saveImage($oImage, $sFileSource, '_1000x')) {
                                         unset($aFilesForRemove[$sFileSave]);
                                     }
                                 }
                                 if ($oImage = $this->createImageObject($sFileSource)) {
                                     if ($this->resizeImage($oImage, 500)) {
                                         if ($sFileSave = $this->saveImage($oImage, $sFileSource, '_500x')) {
                                             unset($aFilesForRemove[$sFileSave]);
                                         }
                                     }
                                 }
                                 if ($oImage = $this->createImageObject($sFileSource)) {
                                     if ($this->cropImage($oImage, 1) and $this->resizeImage($oImage, 100)) {
                                         if ($sFileSave = $this->saveImage($oImage, $sFileSource, '_100x100crop')) {
                                             unset($aFilesForRemove[$sFileSave]);
                                         }
                                     }
                                 }
                                 if ($oImage = $this->createImageObject($sFileSource)) {
                                     if ($this->cropImage($oImage, 1) and $this->resizeImage($oImage, 50)) {
                                         if ($sFileSave = $this->saveImage($oImage, $sFileSource, '_50x50crop')) {
                                             unset($aFilesForRemove[$sFileSave]);
                                         }
                                     }
                                 }
                                 /**
                                  * Добавляем запись в медиа
                                  */
                                 $aDataMedia = array('image_sizes' => array(array('w' => 1000, 'h' => null, 'crop' => false), array('w' => 500, 'h' => null, 'crop' => false), array('w' => 100, 'h' => 100, 'crop' => true), array('w' => 50, 'h' => 50, 'crop' => true)));
                                 if ($aPhoto['description']) {
                                     $aDataMedia['title'] = htmlspecialchars($aPhoto['description']);
                                 }
                                 $aFields = array('user_id' => $aTopic['user_id'], 'type' => 1, 'target_type' => 'topic', 'file_path' => '[relative]' . str_replace(dirname(dirname(INSTALL_DIR)), '', $sFileSource), 'file_name' => pathinfo($sFileSource, PATHINFO_FILENAME), 'file_size' => filesize($sFileSource), 'width' => $iWidth, 'height' => $iHeight, 'date_add' => $aTopic['topic_date_add'], 'data' => serialize($aDataMedia));
                                 if ($iMediaId = $this->dbInsertQuery('prefix_media', $aFields)) {
                                     /**
                                      * Добавляем связь медиа с топиком
                                      */
                                     $aFields = array('media_id' => $iMediaId, 'target_id' => $aTopic['topic_id'], 'target_type' => 'topic', 'date_add' => $aTopic['topic_date_add'], 'data' => '');
                                     if ($iMediaTargetId = $this->dbInsertQuery('prefix_media_target', $aFields)) {
                                         $sFileWeb = InstallConfig::get('path.root.web') . str_replace(dirname(dirname(INSTALL_DIR)), '', $sFileSource);
                                         $aMediaItems[$iMediaId] = $sFileWeb;
                                     }
                                 }
                                 /**
                                  * Удаляем старые
                                  */
                                 foreach ($aFilesForRemove as $sFileRemove) {
                                     @unlink($sFileRemove);
                                 }
                             }
                         }
                         /**
                          * Добавляем в начало текста топика вывод фотосета
                          */
                         $sCodeRender = '';
                         $sCodeSource = '';
                         if ($aMediaItems) {
                             $sCodeSource = '<gallery items="' . join(',', array_keys($aMediaItems)) . '" nav="thumbs" caption="1" />' . "\n";
                             $sCodeRender = '<div class="fotorama"  data-nav="thumbs" >' . "\n";
                             foreach ($aMediaItems as $iId => $sFileWeb) {
                                 $sCodeRender .= '<img src="' . $sFileWeb . '"  />' . "\n";
                             }
                             $sCodeRender .= '</div>' . "\n";
                         }
                         unset($aData['main_photo_id']);
                         unset($aData['count_photo']);
                         $sExtra = mysqli_escape_string($this->rDbLink, serialize($aData));
                         $sText = mysqli_escape_string($this->rDbLink, $sCodeRender . $aTopic['topic_text']);
                         $sTextShort = mysqli_escape_string($this->rDbLink, $sCodeRender . $aTopic['topic_text_short']);
                         $sTextSource = mysqli_escape_string($this->rDbLink, $sCodeSource . $aTopic['topic_text_source']);
                         $this->dbQuery("UPDATE prefix_topic_content SET topic_extra = '{$sExtra}', topic_text = '{$sText}', topic_text_short = '{$sTextShort}', topic_text_source = '{$sTextSource}'  WHERE topic_id ='{$aTopic['topic_id']}'");
                         /**
                          * Меняем тип топика
                          */
                         $this->dbQuery("UPDATE prefix_topic SET topic_type = 'topic' WHERE topic_id ='{$aTopic['topic_id']}'");
                     }
                 }
             }
             /**
              * Удаляем старые таблицы
              */
             if (!$this->getErrors()) {
                 $this->dbQuery('DROP TABLE prefix_topic_photo');
             }
         }
         /**
          * Конвертируем урлы топиков к ЧПУ формату
          */
         $iPage = 1;
         $iLimitCount = 50;
         $iLimitStart = 0;
         while ($aTopics = $this->dbSelect("SELECT * FROM prefix_topic WHERE topic_slug = '' LIMIT {$iLimitStart},{$iLimitCount}")) {
             $iPage++;
             $iLimitStart = ($iPage - 1) * $iLimitCount;
             /**
              * Топики
              */
             foreach ($aTopics as $aTopic) {
                 $sSlug = InstallCore::transliteration($aTopic['topic_title']);
                 $sSlug = $this->GetUniqueTopicSlug($sSlug, $aTopic['topic_id']);
                 $sSlug = mysqli_escape_string($this->rDbLink, $sSlug);
                 /**
                  * Меняем тип топика
                  */
                 $this->dbQuery("UPDATE prefix_topic SET topic_slug = '{$sSlug}' WHERE topic_id ='{$aTopic['topic_id']}'");
             }
         }
         /**
          * Конвертируем аватарки блогов
          */
         $iPage = 1;
         $iLimitCount = 50;
         $iLimitStart = 0;
         while ($aBlogs = $this->dbSelect("SELECT * FROM prefix_blog  WHERE blog_avatar <> '' and blog_avatar <> '0' and blog_avatar  IS NOT NULL LIMIT {$iLimitStart},{$iLimitCount}")) {
             $iPage++;
             $iLimitStart = ($iPage - 1) * $iLimitCount;
             foreach ($aBlogs as $aBlog) {
                 $sAvatar = $aBlog['blog_avatar'];
                 if (strpos($sAvatar, 'http') === 0) {
                     $sAvatar = preg_replace('#_\\d{1,3}x\\d{1,3}(\\.\\w{3,5})$#i', '\\1', $sAvatar);
                     $sFileSource = $this->convertPathWebToServer($sAvatar);
                     /**
                      * Формируем список старых изображений для удаления
                      */
                     $sMask = pathinfo($sFileSource, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . pathinfo($sFileSource, PATHINFO_FILENAME) . '_*';
                     $aFilesForRemove = array();
                     if ($aPaths = glob($sMask)) {
                         foreach ($aPaths as $sPath) {
                             $aFilesForRemove[$sPath] = $sPath;
                         }
                     }
                     /**
                      * Ресайзим к новым размерам
                      */
                     if ($oImage = $this->createImageObject($sFileSource)) {
                         if ($this->cropImage($oImage, 1) and $this->resizeImage($oImage, 500)) {
                             if ($sFileSave = $this->saveImage($oImage, $sFileSource, '_500x500crop')) {
                                 unset($aFilesForRemove[$sFileSave]);
                             }
                         }
                         if ($oImage = $this->createImageObject($sFileSource)) {
                             if ($this->cropImage($oImage, 1) and $this->resizeImage($oImage, 100)) {
                                 if ($sFileSave = $this->saveImage($oImage, $sFileSource, '_100x100crop')) {
                                     unset($aFilesForRemove[$sFileSave]);
                                 }
                             }
                         }
                         if ($oImage = $this->createImageObject($sFileSource)) {
                             if ($this->cropImage($oImage, 1) and $this->resizeImage($oImage, 64)) {
                                 if ($sFileSave = $this->saveImage($oImage, $sFileSource, '_64x64crop')) {
                                     unset($aFilesForRemove[$sFileSave]);
                                 }
                             }
                         }
                         if ($oImage = $this->createImageObject($sFileSource)) {
                             if ($this->cropImage($oImage, 1) and $this->resizeImage($oImage, 48)) {
                                 if ($sFileSave = $this->saveImage($oImage, $sFileSource, '_48x48crop')) {
                                     unset($aFilesForRemove[$sFileSave]);
                                 }
                             }
                         }
                         if ($oImage = $this->createImageObject($sFileSource)) {
                             if ($this->cropImage($oImage, 1) and $this->resizeImage($oImage, 24)) {
                                 if ($sFileSave = $this->saveImage($oImage, $sFileSource, '_24x24crop')) {
                                     unset($aFilesForRemove[$sFileSave]);
                                 }
                             }
                         }
                         /**
                          * Удаляем старые
                          */
                         foreach ($aFilesForRemove as $sFileRemove) {
                             @unlink($sFileRemove);
                         }
                         /**
                          * Меняем путь до аватара
                          */
                         $sAvatar = '[relative]' . str_replace(dirname(dirname(INSTALL_DIR)), '', $sFileSource);
                         $sAvatar = mysqli_escape_string($this->rDbLink, $sAvatar);
                         $this->dbQuery("UPDATE prefix_blog SET blog_avatar = '{$sAvatar}' WHERE blog_id ='{$aBlog['blog_id']}'");
                     }
                 }
             }
         }
         /**
          * Конвертируем аватарки и фото пользователей
          * Дополнительно добавляем роль для прав
          */
         /**
          * Получаем текущий список админов
          */
         $aUserAdmin = array();
         if ($this->dbCheckTable("prefix_user_administrator")) {
             if ($aAdmins = $this->dbSelect("SELECT * FROM prefix_user_administrator ")) {
                 foreach ($aAdmins as $aRow) {
                     $aUserAdmin[] = $aRow['user_id'];
                 }
             }
         }
         $iPage = 1;
         $iLimitCount = 50;
         $iLimitStart = 0;
         while ($aUsers = $this->dbSelect("SELECT * FROM prefix_user LIMIT {$iLimitStart},{$iLimitCount}")) {
             $iPage++;
             $iLimitStart = ($iPage - 1) * $iLimitCount;
             foreach ($aUsers as $aUser) {
                 $sAvatar = $aUser['user_profile_avatar'];
                 $sPhoto = $aUser['user_profile_foto'];
                 /**
                  * Аватарки
                  */
                 if (strpos($sAvatar, 'http') === 0) {
                     $sAvatar = preg_replace('#_\\d{1,3}x\\d{1,3}(\\.\\w{3,5})$#i', '\\1', $sAvatar);
                     $sFileSource = $this->convertPathWebToServer($sAvatar);
                     /**
                      * Формируем список старых изображений для удаления
                      */
                     $sMask = pathinfo($sFileSource, PATHINFO_DIRNAME) . DIRECTORY_SEPARATOR . pathinfo($sFileSource, PATHINFO_FILENAME) . '_*';
                     $aFilesForRemove = array();
                     if ($aPaths = glob($sMask)) {
                         foreach ($aPaths as $sPath) {
                             $aFilesForRemove[$sPath] = $sPath;
                         }
                     }
                     /**
                      * Ресайзим к новым размерам
                      */
                     if ($oImage = $this->createImageObject($sFileSource)) {
                         if ($this->cropImage($oImage, 1) and $this->resizeImage($oImage, 100)) {
                             if ($sFileSave = $this->saveImage($oImage, $sFileSource, '_100x100crop')) {
                                 unset($aFilesForRemove[$sFileSave]);
                             }
                         }
                         if ($oImage = $this->createImageObject($sFileSource)) {
                             if ($this->cropImage($oImage, 1) and $this->resizeImage($oImage, 64)) {
                                 if ($sFileSave = $this->saveImage($oImage, $sFileSource, '_64x64crop')) {
                                     unset($aFilesForRemove[$sFileSave]);
                                 }
                             }
                         }
                         if ($oImage = $this->createImageObject($sFileSource)) {
                             if ($this->cropImage($oImage, 1) and $this->resizeImage($oImage, 48)) {
                                 if ($sFileSave = $this->saveImage($oImage, $sFileSource, '_48x48crop')) {
                                     unset($aFilesForRemove[$sFileSave]);
                                 }
                             }
                         }
                         if ($oImage = $this->createImageObject($sFileSource)) {
                             if ($this->cropImage($oImage, 1) and $this->resizeImage($oImage, 24)) {
                                 if ($sFileSave = $this->saveImage($oImage, $sFileSource, '_24x24crop')) {
                                     unset($aFilesForRemove[$sFileSave]);
                                 }
                             }
                         }
                         /**
                          * Удаляем старые
                          */
                         foreach ($aFilesForRemove as $sFileRemove) {
                             @unlink($sFileRemove);
                         }
                         /**
                          * Меняем путь до аватара
                          */
                         $sAvatar = '[relative]' . str_replace(dirname(dirname(INSTALL_DIR)), '', $sFileSource);
                     }
                 }
                 /**
                  * Фото
                  */
                 if (strpos($sPhoto, 'http') === 0) {
                     $sFileSource = $this->convertPathWebToServer($sPhoto);
                     /**
                      * Меняем путь до аватара
                      */
                     $sPhoto = '[relative]' . str_replace(dirname(dirname(INSTALL_DIR)), '', $sFileSource);
                 }
                 /**
                  * Права
                  */
                 if (!$this->dbSelectOne("SELECT * FROM prefix_rbac_role_user WHERE user_id = '{$aUser['user_id']}' and role_id = 2 ")) {
                     /**
                      * Добавляем
                      */
                     $aFields = array('user_id' => $aUser['user_id'], 'role_id' => 2, 'date_create' => date("Y-m-d H:i:s"));
                     $this->dbInsertQuery('prefix_rbac_role_user', $aFields);
                 }
                 /**
                  * Timezone
                  */
                 $sTzName = null;
                 if ($aUser['user_settings_timezone']) {
                     $sTzName = $this->convertTzOffsetToName($aUser['user_settings_timezone']);
                 }
                 /**
                  * Реферальный код
                  */
                 $sReferralCode = $aUser['user_referral_code'];
                 if (!$sReferralCode) {
                     $sReferralCode = md5($aUser['user_id'] . '_' . mt_rand());
                 }
                 /**
                  * Админы
                  */
                 $isAdmin = 0;
                 if (in_array($aUser['user_id'], $aUserAdmin) or $aUser['user_admin']) {
                     $isAdmin = 1;
                 }
                 /**
                  * Сохраняем в БД
                  */
                 $sAvatar = mysqli_escape_string($this->rDbLink, $sAvatar);
                 $sPhoto = mysqli_escape_string($this->rDbLink, $sPhoto);
                 $this->dbQuery("UPDATE prefix_user SET user_admin = '{$isAdmin}' , user_referral_code = '{$sReferralCode}' , user_settings_timezone = " . ($sTzName ? "'{$sTzName}'" : 'null') . " , user_profile_avatar = '{$sAvatar}', user_profile_foto = '{$sPhoto}' WHERE user_id ='{$aUser['user_id']}'");
                 /**
                  * Удаляем таблицы
                  */
                 if ($this->dbCheckTable("prefix_user_administrator")) {
                     $this->dbQuery('DROP TABLE prefix_user_administrator');
                 }
             }
         }
         if ($this->getErrors()) {
             return $this->addError(join('<br/>', $aErrors));
         }
         return true;
     }
     return $this->addError(join('<br/>', $aErrors));
 }