public static function getKinopoiskLinkByName($name) { $result = \Hawkart\Megatv\PeopleTable::getList(array('filter' => array("=UF_TITLE" => $name), 'select' => array("UF_KINOPOISK_LINK"))); if ($row = $result->fetch()) { return $row["UF_KINOPOISK_LINK"]; } return false; }
public function down() { global $APPLICATION; $arHlData = $this->arHlData; \Bitrix\Main\Loader::includeModule("highloadblock"); $arHlblock = \Bitrix\Highloadblock\HighloadBlockTable::getList(array('filter' => array('TABLE_NAME' => \Hawkart\Megatv\PeopleTable::getTableName())))->fetch(); if ($arHlblock) { foreach ($arHlData as $fieldName => $fieldValue) { $oUserTypeEntity = new \CUserTypeEntity(); $resProperty = \CUserTypeEntity::GetList(array(), array('ENTITY_ID' => 'HLBLOCK_' . $arHlblock["ID"], 'FIELD_NAME' => $fieldName)); if ($aUserHasField = $resProperty->Fetch()) { $oUserTypeEntity->Delete($aUserHasField['ID']); $this->outSuccess("Свойство удалено!"); } } } }
//SEO $APPLICATION->SetTitle($arResult["UF_TITLE"]); $APPLICATION->SetPageProperty("title", trim($arResult["UF_TITLE"] . " " . $arResult["UF_SUB_TITLE"])); $APPLICATION->SetPageProperty("keywords", implode(", ", $arResult["KEYWORDS"])); $APPLICATION->SetPageProperty("description", TruncateText($arResult["UF_DESC"], 256)); $APPLICATION->SetDirProperty('og_image', $arResult["PICTURE"]["SRC"]); $APPLICATION->SetDirProperty('og_type', 'album'); //get status schedule $arResult["STATUS"] = \Hawkart\Megatv\CScheduleTemplate::status(array("ID" => $arResult["ID"], "UF_CHANNEL_ID" => $arResult["UF_CHANNEL_ID"], "DATE_START" => $arResult["DATE_START"], "DATE_END" => $arResult["DATE_END"])); foreach (array("UF_DIRECTOR", "UF_PRESENTER", "UF_ACTOR") as $type) { $_arResult[$type] = array(); $arPeoples = explode(",", $arResult[$type]); foreach ($arPeoples as $actor) { $actor = trim($actor); if (!empty($actor)) { $link = \Hawkart\Megatv\PeopleTable::getKinopoiskLinkByName($actor); $link = str_replace("//name", "/name", $link); if (empty($link)) { $link = "#"; } $_arResult[$type][] = array("NAME" => $actor, "LINK" => $link); } } $arResult[$type] = $_arResult[$type]; unset($_arResult[$type]); } /** * Add data to statistics */ //\Hawkart\Megatv\CStat::channelAdd($arResult["UF_CHANNEL_ID"]); $back_recommendations = false;
/** * Import People from xml EPG * * @return array */ public static function importPeople($arRoles = false) { $file = "http://xmldata.epgservice.ru/EPGService/hs/xmldata/saturn/people_list"; $xml = simplexml_load_file($file); $arList = array(); $result = PeopleTable::getList(array('filter' => array("!UF_EPG_ID" => false), 'select' => array("UF_EPG_ID", "ID", "UF_TITLE"))); while ($row = $result->fetch()) { $arList[$row["UF_EPG_ID"]] = $row; } if (!$arRoles) { $arRoles = self::importRole(); } foreach ($xml->element as $arElement) { $el_attr = $arElement->attributes(); $epg_id = (string) $el_attr["id"]; $title = (string) $arElement->name; $role_attr = $arElement->role->attributes(); $role_epg_id = (string) $role_attr["id"]; $role_id = $arRoles[$role_epg_id]["ID"]; if (!is_array($arList[$epg_id])) { $arFields = array("UF_EPG_ID" => $epg_id, "UF_TITLE" => $title, "UF_ROLE_ID" => $role_id); $result = PeopleTable::add($arFields); if ($result->isSuccess()) { $id = $result->getId(); $arFields["ID"] = $id; $arList[$epg_id] = $arFields; } else { $errors = $result->getErrorMessages(); //\CDev::pre($arFields);\CDev::pre($errors); } } } unset($arRoles); return $arList; }
/** * Parse kinopoisk to get links to actors */ $DOCUMENT_ROOT = $_SERVER["DOCUMENT_ROOT"] = realpath(dirname(__FILE__) . '/../'); define("NO_KEEP_STATISTIC", true); define("NOT_CHECK_PERMISSIONS", true); set_time_limit(0); require $_SERVER["DOCUMENT_ROOT"] . "/bitrix/modules/main/include/prolog_before.php"; global $USER, $APPLICATION; if (!is_object($USER)) { $USER = new CUser(); } $arPeoples = array(); $result = \Hawkart\Megatv\PeopleTable::getList(array('filter' => array("UF_KINOPOISK_LINK" => false), 'select' => array("UF_TITLE", "ID", "UF_KINOPOISK_LINK"))); while ($row = $result->fetch()) { $arPeoples[$row["ID"]] = $row; /*\Hawkart\Megatv\PeopleTable::update($row["ID"], array( "UF_KINOPOISK_LINK" => str_replace("//name", "/name", $row["UF_KINOPOISK_LINK"]) ));*/ } //die(); $login = \COption::GetOptionString("grain.customsettings", "KINOPOISK_LOGIN"); $password = \COption::GetOptionString("grain.customsettings", "KINOPOISK_PASS"); $kinopoisk = new \Hawkart\Megatv\Kinopoisk($login, $password); foreach ($arPeoples as $arActor) { $actor = urlencode($arActor["UF_TITLE"]); if ($link = $kinopoisk->searchActor($actor)) { \Hawkart\Megatv\PeopleTable::update($arActor["ID"], array("UF_KINOPOISK_LINK" => $link)); sleep(2); } }