Strict Standards: Only variables should be passed by reference in /home/olegadmin/n-professor.ru/docs/wp-includes/pomo/mo.php on line 184

Strict Standards: Only variables should be passed by reference in /home/olegadmin/n-professor.ru/docs/wp-includes/pomo/mo.php on line 184

Deprecated: Non-static method WP_MatchesMapRegex::apply() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-includes/class-wp.php on line 207
Записки профессора » UMI перенос новостей, со старого сайта.
Strict Standards: Only variables should be passed by reference in /home/olegadmin/n-professor.ru/docs/wp-includes/general-template.php on line 1643

Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::LoadStyles() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 405
Главная > PHP > UMI перенос новостей, со старого сайта.

UMI перенос новостей, со старого сайта.


Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallBeforeHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 214

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 49

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 50

Deprecated: Non-static method CodeColorerOptions::ParseOptions() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 80

Deprecated: Non-static method CodeColorerOptions::PopulateDefaultValues() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 66

Deprecated: Non-static method CodeColorerOptions::FilterLanguage() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 102

Deprecated: Non-static method CodeColorerOptions::GetLanguageMappings() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 246

Deprecated: Non-static method CodeColorerOptions::ParseBoolean() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 157

Deprecated: Non-static method CodeColorerOptions::ParseBoolean() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 173

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 69

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 72

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 75

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 78

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 81

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 84

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 87

Deprecated: Non-static method CodeColorerOptions::ParseOptions() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 80

Deprecated: Non-static method CodeColorerOptions::PopulateDefaultValues() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 66

Deprecated: Non-static method CodeColorerOptions::FilterLanguage() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 102

Deprecated: Non-static method CodeColorerOptions::GetLanguageMappings() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 246

Deprecated: Non-static method CodeColorerOptions::ParseBoolean() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 157

Deprecated: Non-static method CodeColorerOptions::ParseBoolean() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 173

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 69

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 72

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 75

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 78

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 81

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 84

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 87

Deprecated: Non-static method CodeColorerOptions::ParseOptions() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-core.php on line 80

Deprecated: Non-static method CodeColorerOptions::PopulateDefaultValues() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 66

Deprecated: Non-static method CodeColorerOptions::FilterLanguage() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 102

Deprecated: Non-static method CodeColorerOptions::GetLanguageMappings() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 246

Deprecated: Non-static method CodeColorerOptions::ParseBoolean() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 157

Deprecated: Non-static method CodeColorerOptions::ParseBoolean() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 173

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 69

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 72

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 75

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 78

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 81

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 84

Deprecated: Non-static method CodeColorerOptions::ParseMode() should not be called statically, assuming $this from incompatible context in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer-options.php on line 87

Strict Standards: Only variables should be passed by reference in /home/olegadmin/n-professor.ru/docs/wp-includes/pomo/mo.php on line 184

Strict Standards: Only variables should be passed by reference in /home/olegadmin/n-professor.ru/docs/wp-includes/pomo/mo.php on line 184

Deprecated: preg_replace(): The /e modifier is deprecated, use preg_replace_callback instead in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/thumbnail-viewer/wp-thumbnailviewer.php on line 78

Strict Standards: call_user_func_array() expects parameter 1 to be a valid callback, non-static method CodeColorerLoader::CallAfterHighlightCodeBlock() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-includes/plugin.php on line 170

Strict Standards: Non-static method CodeColorer::GetInstance() should not be called statically in /home/olegadmin/n-professor.ru/docs/wp-content/plugins/codecolorer/codecolorer.php on line 222

Задача, перенести около 300 новостей с сайта, созданного на HTML в UMI.CMS. В umi я пока новичок так что жду от более опытных в этой сфере комментариев. Я пишу свой макрос в модуле импорта данных. Это ж все-таки импорт.

В папке classes\modules\exchange лежит файл __custom.php примерно такого содержания

abstract class __custom_exchange {}

Добавляем туда метод

public function import_news() {}

Первое что нужно сделать, это распарсить HTML. У меня есть список страниц новостей и пара страниц со списком новостей, картинкой анонса и анонсом.

Поэтому я руками из 10 файлов собираю 1 (лень было написать скрипт =)), который состоит только из анонсов. И собираю всю информацию в массив. Потом пробегаюсь по всем файлам новостей(тут их  более 300, ручками не катит) и сразу же запихиваю их в UMI не забыв при этом найти нужный анонс и запихнуть его тудаже.

Вроде все просто, вот код:

public function import_news() {
        set_time_limit(0);
        //Получаем страницу со всеми анонсами
        $anonsAll = file_get_contents("anons/all.html");

        //Вытягиваем 1 регуляркой сразу все анонсы с отделенными картинками, описанием и названием
        preg_match_all('#<img.*?src="(.*?)".*?<a.*?>(.*?)</a>.*?(<p>.*?</p>)#is', $anonsAll, $arrayAnons, PREG_SET_ORDER);

        //сканируем дирректорию и получаем все новости
        $files1 = scandir('news_text');

        //здесь мы получаем ID типа объекта новости.
        $typesCollection = umiObjectTypesCollection::getInstance();
        $typeId = $typesCollection->getBaseType('news', 'subject');


        foreach ($files1 as $var) {
            if ($var != "." && $var != "..") {
                $content = iconv("windows-1251", "UTF-8", file_get_contents($dir . "/" . $var));
                //Здесь я не стал заморачиваться 1 регуляркой, все равно код на 5 минут.
                preg_match_all("#<h1>(.*?)</h1>#is", $content, $arrayItem);
                $h1 = $arrayItem[1][0];

                preg_match_all("#<p>.*</p>#is", $content, $arrayItem);
                $text = $arrayItem[0][0];

                preg_match_all('#<img.*?src="(.*?)".*?>#is', $content, $arrayItem);
                $img = str_replace("/images/news/", "files/news/", $arrayItem[1][0]);
               
                //Находим нужный анонс
                foreach ($arrayAnons as $an) {
                    if (strtolower($h1) == strtolower($an[2])) {
                        $anons = $an[3];
                        $imgAnons = str_replace("/images/news/", "files/news/", $an[1]);
                    }
                }

                //Создаем новый пустой элемент (новую новость)
                $h = umiHierarchy::getInstance();
                $element_id = $h->addElement(37, 36, $h1, str_replace(".html", "", $var), $typeId);


                //Ставим права.
                $p = permissionsCollection::getInstance();
                $users_array = array(298);//298 - это ID объекта "Гость"
                foreach ($users_array as $k => $v) {
                    $p->setElementPermissions($v, $element_id, 1);
                }


                //Получаем только что созданный элемент
                $element = $h->getElement($element_id, true, true);

                //Задаем ему все параметры
                $element->setIsActive();
                $element->setValue('content', $text);
                $element->setValue('anons', $anons);
                $element->setValue('h1', $h1);
                $element->setValue('anons_pic', $imgAnons);
                $element->setValue('publish_pic', $img);
                $element->commit();
            }
        }
    }

Какие у меня проблемы возникли кроме поиска информации обо всем, об этом.
1) Что такое 36 в addElement? В документации написано что это id иерархического типа (umiHierarchyType). Что это за зверь такой я не понял, но по моему это не ID шаблона данных.
2) ID группы пользователей “Все” я тоже не знал где найти, сделал ID пользователя “Гость”

Остальное вроде все понятно. Удачи.

Поделиться в соц. сетях

Опубликовать в Google Buzz
Опубликовать в Google Plus
Опубликовать в LiveJournal
Опубликовать в Мой Мир
Опубликовать в Одноклассники
Опубликовать в Яндекс

PHP ,

  1. Комментариев пока нет.
  1. Трекбеков пока нет.