<?xml version="1.0" encoding="utf-8"?>
<dleplugin>
<name>Сиквелы и приквелы фильма</name>
<description>Модификация на заказ</description>
<icon></icon>
<version></version>
<dleversion></dleversion>
<versioncompare>==</versioncompare>
<upgradeurl></upgradeurl>
<filedelete>0</filedelete>
<needplugin></needplugin>
<mnotice>0</mnotice>
<mysqlinstall><![CDATA[ALTER TABLE `{prefix}_post` ADD `god` int(11) unsigned NOT NULL DEFAULT '0';]]></mysqlinstall>
<mysqlupgrade><![CDATA[]]></mysqlupgrade>
<mysqlenable><![CDATA[]]></mysqlenable>
<mysqldisable><![CDATA[]]></mysqldisable>
<mysqldelete><![CDATA[ALTER TABLE `{prefix}_post` DROP `god`;]]></mysqldelete>
<phpinstall><![CDATA[]]></phpinstall>
<phpupgrade><![CDATA[]]></phpupgrade>
<phpenable><![CDATA[]]></phpenable>
<phpdisable><![CDATA[]]></phpdisable>
<phpdelete><![CDATA[]]></phpdelete>
<notice><![CDATA[]]></notice>
<file name="engine/modules/show.full.php">
<operation action="after">
<searchcode><![CDATA[$tpl->set( '{full-story}', $row['full_story'] );]]></searchcode>
<replacecode><![CDATA[//настройки
$kinopoisk_xf = 'kinopoisk_id';
$x_api_key = 'ваш_апи_ключ';
//настройки
$this_kp_id = $xfieldsdata[$kinopoisk_xf];
if ( $xfieldsdata[$kinopoisk_xf] && !$xfieldsdata['sequels'] ) {
$xffieldsdata = xfieldsdataload( $row['xfields'] );
$kp_api = kinopoiskapiunofficial("
https://kinopoiskapiunofficial.tech/api/v2.1/films/".$xfieldsdata[$kinopoisk_xf]."/sequels_and_prequels", $x_api_key);
$movies_id = [];
if ( $kp_api ) {
foreach ( $kp_api as $kp_movie ) {
if ( $kp_movie['filmId'] ) {
$kp_movie_api = kinopoiskapiunofficial("
https://kinopoiskapiunofficial.tech/api/v2.2/films/".$kp_movie['filmId'], $x_api_key);
if ( $kp_movie_api['year'] ) $movies_id[$kp_movie['filmId']] = $kp_movie_api['year'];
unset($kp_movie_api);
}
}
$kp_movie_api = kinopoiskapiunofficial("
https://kinopoiskapiunofficial.tech/api/v2.2/films/".$xfieldsdata[$kinopoisk_xf], $x_api_key);
if ( $kp_movie_api['year'] ) $movies_id[$xfieldsdata[$kinopoisk_xf]] = $kp_movie_api['year'];
$movies_id_clone = $movies_id;
asort($movies_id);
$movies_id_flipped = array_flip($movies_id);
$part_id = implode(',', $movies_id_flipped);
unset($kp_movie_api);
}
else $part_id = 'none';
$xffieldsdata['sequels'] = $part_id;
$year = $db->safesql( $movies_id_clone[$xfieldsdata[$kinopoisk_xf]] );
$xffieldsdata = $db->safesql( xfieldsdatasave($xffieldsdata) );
$db->query( "UPDATE " . PREFIX . "_post SET god='{$year}', xfields='{$xffieldsdata}' WHERE id='{$row['id']}'" );
clear_cache( 'full_'.$row['id'] );
unset($xffieldsdata);
unset($kp_api);
unset($year);
if (is_array($movies_id_flipped) && count($movies_id_flipped) > 1) {
$where_movie = [];
foreach ($movies_id_flipped as $movie_id) {
if ($this_kp_id != $movie_id) {
$where_movie[] = "xfields LIKE '%{$kinopoisk_xf}|{$movie_id}|%'";
}
}
$where_movie = implode(' OR ', $where_movie);
$db->query("SELECT id, xfields FROM " . PREFIX . "_post WHERE " . $where_movie);
$news_arr = [];
$n_num = 0;
while ($sequel_movie = $db->get_row()) {
$news_arr[$n_num]['id'] = $sequel_movie['id'];
$news_arr[$n_num]['xfields'] = $sequel_movie['xfields'];
$n_num++;
}
$db->free();
unset($where_movie, $sequel_movie, $n_num);
foreach ($news_arr as $sequel_movie) {
$xffieldsdata = xfieldsdataload($sequel_movie['xfields']);
$xffieldsdata['sequels'] = $part_id;
$year = $db->safesql($movies_id_clone[$xffieldsdata[$kinopoisk_xf]]);
$xffieldsdata = $db->safesql(xfieldsdatasave($xffieldsdata));
$db->query("UPDATE " . PREFIX . "_post SET xfields='{$xffieldsdata}', god='{$year}' WHERE id='{$sequel_movie['id']}'");
clear_cache('full_' . $sequel_movie['id']);
unset($xffieldsdata, $year);
}
unset($news_arr, $sequel_movie);
}
unset($part_id);
}
if ( $xfieldsdata['sequels'] && $xfieldsdata['sequels'] != 'none' ) {
$tpl->set( '[sequels]', "" );
$tpl->set( '[/sequels]', "" );
}
else $tpl->set_block( "'\\[sequels\\](.*?)\\[/sequels\\]'si", "" );]]></replacecode>
<enabled>1</enabled>
</operation>
</file>
<file name="engine/modules/functions.php">
<operation action="before">
<searchcode><[\"]#i", $param_str, $match ) ) {]]></searchcode>
<replacecode><[\"]#i", $param_str, $match ) ) {
$match[1] = explode (',', $match[1]);
$temp_array = array();
foreach ($match[1] as $value) {
$value = $db->safesql(trim($value));
$temp_array[] = "p.xfields LIKE '%{$kinopoisk_xf}|{$value}|%'";
}
$where[] = "(".implode(' OR ', $temp_array).")";
$sequels_enabled = true;
}
else $sequels_enabled = false;]]></replacecode>
<enabled>1</enabled>
</operation>
<operation action="before">
<searchcode><![CDATA[function custom_print( $matches=array() ) {]]></searchcode>
<replacecode><![CDATA[if (!function_exists('xfieldsdatasave')) {
function xfieldsdatasave($xfields) {
$filecontents = [];
foreach ($xfields as $xfielddataname => $xfielddatavalue) {
if ($xfielddatavalue === '') continue;
$xfielddataname = str_replace( "|", "|", $xfielddataname);
$xfielddataname = str_replace( "\r\n", "__NEWL__", $xfielddataname);
$xfielddatavalue = str_replace( "|", "|", $xfielddatavalue);
$xfielddatavalue = str_replace( "\r\n", "__NEWL__", $xfielddatavalue);
$filecontents[] = "$xfielddataname|$xfielddatavalue";
}
$filecontents = join('||', $filecontents );
return $filecontents;
}
}
if (!function_exists('kinopoiskapiunofficial')) {
function kinopoiskapiunofficial($url, $x_api_key) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$headers = [
'Content-Type: application/json',
'X-API-KEY: '.$x_api_key
];
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$kp_api = curl_exec ($ch);
curl_close ($ch);
return json_decode($kp_api, true);
}
}]]></replacecode>
<enabled>1</enabled>
</operation>
<operation action="replace">
<searchcode><![CDATA[$sql_select .= " WHERE ".implode(' AND ', $where)." ORDER BY " . $fixed . $news_sort . " " . $news_msort . " LIMIT " . $custom_from . "," . $custom_limit;]]></searchcode>
<replacecode><![CDATA[if ( $sequels_enabled === true ) $sql_select .= " WHERE ".implode(' AND ', $where)." ORDER BY p.god ASC LIMIT " . $custom_from . "," . $custom_limit;
else $sql_select .= " WHERE ".implode(' AND ', $where)." ORDER BY " . $fixed . $news_sort . " " . $news_msort . " LIMIT " . $custom_from . "," . $custom_limit;]]></replacecode>
<enabled>1</enabled>
</operation>
<operation action="replace">
<searchcode><![CDATA[$sql_select = "SELECT p.id, p.autor, p.date]]></searchcode>
<replacecode><![CDATA[$sql_select = "SELECT p.id, p.autor, p.date, p.god]]></replacecode>
<enabled>1</enabled>
</operation>
</file>
<file name="engine/modules/show.custom.php">
<operation action="after">
<searchcode><![CDATA[$i ++;]]></searchcode>
<replacecode><![CDATA[$tpl->set( '{numeration}', $i );]]></replacecode>
<enabled>1</enabled>
</operation>
</file>
</dleplugin>