вопрос
Добрый день. Пользуюсь модулем, для перелинковки сезонов сериалов. Но возникла проблема, если не заполнено поле с ид кинопоиска, то выдает ошибку
Подскажите, как поправить данную ошибку
Вот сам код, из за чего возникает ошибка
MySQL error in file: /engine/mod_liser/seasons/front/index.php at line 187
Error Number: 1064
The Error returned was:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'OR SUBSTRING_INDEX( SUBSTRING_INDEX( xfields, 'kp_id|', -1 ) , '||', 1 ) = ORD' at line 1
SQL query:
SELECT * FROM dle_post WHERE SUBSTRING_INDEX( SUBSTRING_INDEX( xfields, 'kp_id|', -1 ) , '||', 1 ) = OR SUBSTRING_INDEX( SUBSTRING_INDEX( xfields, 'kp_id|', -1 ) , '||', 1 ) = ORDER BY ABS( SUBSTRING_INDEX( SUBSTRING_INDEX( xfields, 'season_title|', -1 ) , '||', 1 )) ASC
Error Number: 1064
The Error returned was:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'OR SUBSTRING_INDEX( SUBSTRING_INDEX( xfields, 'kp_id|', -1 ) , '||', 1 ) = ORD' at line 1
SQL query:
SELECT * FROM dle_post WHERE SUBSTRING_INDEX( SUBSTRING_INDEX( xfields, 'kp_id|', -1 ) , '||', 1 ) = OR SUBSTRING_INDEX( SUBSTRING_INDEX( xfields, 'kp_id|', -1 ) , '||', 1 ) = ORDER BY ABS( SUBSTRING_INDEX( SUBSTRING_INDEX( xfields, 'season_title|', -1 ) , '||', 1 )) ASC
Подскажите, как поправить данную ошибку
Вот сам код, из за чего возникает ошибка
<?php
/* ===========================================================
* === [ Название ] >> Seasons ===============================
* === [ Автор ] >> LisER =================================
* === [ Skype ] >> liser07 (имею три аккаунта на этом сайте, вероятно не стоит со мной связываться) ===============================
* =========================================================*/
define ( 'LISER_DIR', ENGINE_DIR . "/mod_liser" );
define ( 'SEASON_ADMIN_DIR', LISER_DIR . "/seasons/admin" );
require_once SEASON_ADMIN_DIR . '/data.php';
if( ! class_exists ('seasons') ){
class seasons {
private $FIELD = "id_kinopoisk";
public $kinopoisk_id = 0;
public $id_news = 0;
public $db;
public $tpl;
public $config;
public function __construct (){
global $db, $tpl, $config, $cat_info, $seasonsConfig, $thisIdNews, $xfieldsdata;
$this->xfields = $xfieldsdata;
$this->seasonsConfig = $seasonsConfig;
$this->kinopoisk_id = ($this->seasonsConfig['dop_fields'] && $this->xfields[$this->seasonsConfig['dop_fields']]) ? $this->xfields[$this->seasonsConfig['dop_fields']] : $this->xfields[$this->seasonsConfig['kinopoisk']] ;
$this->FIELD = $seasonsConfig['kinopoisk'];
$this->id_news = $thisIdNews;
$this->db = $db;
$this->tpl3 = $tpl;
$this->config = $config;
$this->cat_info = $cat_info;
}
private function xf (){
foreach ( $this->xfieldsdata as $value ) {
$preg_safe_name = preg_quote( $value[0], "'" );
if( $value[20] ) {
$value[20] = explode( ',', $value[20] );
if( $value[20][0] AND !in_array( $member_id['user_group'], $value[20] ) ) {
$this->xfieldsdata[$value[0]] = "";
}
}
if ( $value[3] == "yesorno" ) {
if( intval($this->xfieldsdata[$value[0]]) ) {
$xfgiven = true;
$this->xfieldsdata[$value[0]] = $lang['xfield_xyes'];
} else {
$xfgiven = false;
$this->xfieldsdata[$value[0]] = $lang['xfield_xno'];
}
} else {
if($this->xfieldsdata[$value[0]] == "") $xfgiven = false; else $xfgiven = true;
}
if( !$xfgiven ) {
$this->tpl4->copy_template = preg_replace( "'\\[xfgiven_{$preg_safe_name}\\](.*?)\\[/xfgiven_{$preg_safe_name}\\]'is", "", $this->tpl4->copy_template );
$this->tpl4->copy_template = str_replace( "[xfnotgiven_{$value[0]}]", "", $this->tpl4->copy_template );
$this->tpl4->copy_template = str_replace( "[/xfnotgiven_{$value[0]}]", "", $this->tpl4->copy_template );
} else {
$this->tpl4->copy_template = preg_replace( "'\\[xfnotgiven_{$preg_safe_name}\\](.*?)\\[/xfnotgiven_{$preg_safe_name}\\]'is", "", $this->tpl4->copy_template );
$this->tpl4->copy_template = str_replace( "[xfgiven_{$value[0]}]", "", $this->tpl4->copy_template );
$this->tpl4->copy_template = str_replace( "[/xfgiven_{$value[0]}]", "", $this->tpl4->copy_template );
}
if(strpos( $this->tpl4->copy_template, "[ifxfvalue" ) !== false ) {
$this->tpl4->copy_template = preg_replace_callback ( "#\\[ifxfvalue(.+?)\\](.+?)\\[/ifxfvalue\\]#is", "check_xfvalue", $this->tpl4->copy_template );
}
if ( $value[6] AND !empty( $this->xfieldsdata[$value[0]] ) ) {
$temp_array = explode( ",", $this->xfieldsdata[$value[0]] );
$value3 = array();
foreach ($temp_array as $value2) {
$value2 = trim($value2);
$value2 = str_replace("'", "'", $value2);
if( $config['allow_alt_url'] ) $value3[] = "<a href=\"" . $config['http_home_url'] . "xfsearch/" .$value[0]."/". urlencode( $value2 ) . "/\">" . $value2 . "</a>";
else $value3[] = "<a href=\"$PHP_SELF?do=xfsearch&xfname=".$value[0]."&xf=" . urlencode( $value2 ) . "\">" . $value2 . "</a>";
}
$this->xfieldsdata[$value[0]] = implode(", ", $value3);
unset($temp_array);
unset($value2);
unset($value3);
}
if ($config['allow_links'] AND $value[3] == "textarea" AND function_exists('replace_links')) $this->xfieldsdata[$value[0]] = replace_links ( $this->xfieldsdata[$value[0]], $replace_links['news'] );
if($value[3] == "image" AND $this->xfieldsdata[$value[0]] ) {
$path_parts = @pathinfo($this->xfieldsdata[$value[0]]);
if( $value[12] AND file_exists(ROOT_DIR . "/uploads/posts/" .$path_parts['dirname']."/thumbs/".$path_parts['basename']) ) {
$thumb_url = $config['http_home_url'] . "uploads/posts/" . $path_parts['dirname']."/thumbs/".$path_parts['basename'];
$img_url = $config['http_home_url'] . "uploads/posts/" . $path_parts['dirname']."/".$path_parts['basename'];
} else {
$img_url = $config['http_home_url'] . "uploads/posts/" . $path_parts['dirname']."/".$path_parts['basename'];
$thumb_url = "";
}
if($thumb_url) {
$this->xfieldsdata[$value[0]] = "<a href=\"$img_url\" class=\"highslide\" target=\"_blank\"><img class=\"xfieldimage {$value[0]}\" src=\"$thumb_url\" alt=\"\" /></a>";
} else $this->xfieldsdata[$value[0]] = "<img class=\"xfieldimage {$value[0]}\" src=\"{$img_url}\" alt=\"\" />";
}
if($value[3] == "image") {
if( $this->xfieldsdata[$value[0]] ) {
$tpl->copy_template = str_replace( "[xfvalue_thumb_url_{$value[0]}]", $thumb_url, $tpl->copy_template );
$tpl->copy_template = str_replace( "[xfvalue_image_url_{$value[0]}]", $img_url, $tpl->copy_template );
} else {
$tpl->copy_template = str_replace( "[xfvalue_thumb_url_{$value[0]}]", "", $tpl->copy_template );
$tpl->copy_template = str_replace( "[xfvalue_image_url_{$value[0]}]", "", $tpl->copy_template );
}
}
if($value[3] == "imagegalery" AND $this->xfieldsdata[$value[0]] AND stripos ( $tpl->copy_template, "[xfvalue_{$value[0]}]" ) !== false) {
$fieldvalue_arr = explode(',', $this->xfieldsdata[$value[0]]);
$gallery_image = array();
foreach ($fieldvalue_arr as $temp_value) {
$temp_value = trim($temp_value);
if($temp_value == "") continue;
$path_parts = @pathinfo($temp_value);
if( $value[12] AND file_exists(ROOT_DIR . "/uploads/posts/" .$path_parts['dirname']."/thumbs/".$path_parts['basename']) ) {
$thumb_url = $config['http_home_url'] . "uploads/posts/" . $path_parts['dirname']."/thumbs/".$path_parts['basename'];
$img_url = $config['http_home_url'] . "uploads/posts/" . $path_parts['dirname']."/".$path_parts['basename'];
} else {
$img_url = $config['http_home_url'] . "uploads/posts/" . $path_parts['dirname']."/".$path_parts['basename'];
$thumb_url = "";
}
if($thumb_url) {
$gallery_image[] = "<li><a href=\"$img_url\" onclick=\"return hs.expand(this, { slideshowGroup: 'xf_{$row['id']}_{$value[0]}' })\" target=\"_blank\"><img src=\"{$thumb_url}\" alt=\"\" /></a></li>";
} else $gallery_image[] = "<li><img src=\"{$img_url}\" alt=\"\" /></li>";
}
$this->xfieldsdata[$value[0]] = "<ul class=\"xfieldimagegallery {$value[0]}\">".implode($gallery_image)."</ul>";
$uniq_id = "xf_{$row['id']}_{$value[0]}";
$onload_scripts[$uniq_id] = "hs.addSlideshow({slideshowGroup: '{$uniq_id}', interval: 4000, repeat: false, useControls: true, fixedControls: 'fit', overlayOptions: { opacity: .75, position: 'bottom center', hideOnMouseOut: true } });";
}
$this->tpl4->set( "[xfvalue_{$value[0]}]", $this->xfieldsdata[$value[0]] );
if ( preg_match( "#\\[xfvalue_{$preg_safe_name} limit=['\"](.+?)['\"]\\]#i", $this->tpl4->copy_template, $matches ) ) {
$count= intval($matches[1]);
$this->xfieldsdata[$value[0]] = str_replace( "</p><p>", " ", $this->xfieldsdata[$value[0]] );
$this->xfieldsdata[$value[0]] = strip_tags( $this->xfieldsdata[$value[0]], "<br>" );
$this->xfieldsdata[$value[0]] = trim(str_replace( "<br>", " ", str_replace( "<br />", " ", str_replace( "\n", " ", str_replace( "\r", "", $this->xfieldsdata[$value[0]] ) ) ) ));
if( $count AND dle_strlen( $this->xfieldsdata[$value[0]], $config['charset'] ) > $count ) {
$this->xfieldsdata[$value[0]] = dle_substr( $this->xfieldsdata[$value[0]], 0, $count, $config['charset'] );
if( ($temp_dmax = dle_strrpos( $this->xfieldsdata[$value[0]], ' ', $config['charset'] )) ) $this->xfieldsdata[$value[0]] = dle_substr( $this->xfieldsdata[$value[0]], 0, $temp_dmax, $config['charset'] );
}
$this->tpl4->set( $matches[0], $this->xfieldsdata[$value[0]] );
}
}
}
public function run(){
if (!$this->seasonsConfig['onOff']) return !1;
if ($this->seasonsConfig['sort_seasons']){
$this->orderType = $this->seasonsConfig['sort_seasons'];
}
if ($this->seasonsConfig['sort'] == "xfield"){
if($this->seasonsConfig['sort_xfield'] && $this->seasonsConfig['sort_xfield'] != "-"){
$this->xfield_name = trim($this->seasonsConfig['sort_xfield']);
$this->orderQuery = " ORDER BY ABS( SUBSTRING_INDEX( SUBSTRING_INDEX( xfields, '{$this->xfield_name}|', -1 ) , '||', 1 )) {$this->orderType}";
}
$this->order = $this->orderQuery;
} else if ($this->seasonsConfig['sort'] == "date"){
$this->order = " ORDER BY {$this->orderField} {$this->seasonsConfig['sort']}"; ;
} else {
$this->order = " ORDER BY title {$this->seasonsConfig['sort']}"; ;
}
if ($this->seasonsConfig['limit'] != "" && $this->seasonsConfig['limit'] != 0){
$this->limitQuery = " LIMIT 0," . $this->seasonsConfig['limit'];
} else {
$this->limitQuery = "";
}
if ($this->seasonsConfig['dop_fields'] && !empty($this->seasonsConfig['dop_fields']) && $this->seasonsConfig['dop_fields'] != "-"){
$this->XFIELD = "SUBSTRING_INDEX( SUBSTRING_INDEX( xfields, '" . $this->FIELD . "|', -1 ) , '||', 1 ) =" . $this->kinopoisk_id;
$this->XFIELD .= " OR SUBSTRING_INDEX( SUBSTRING_INDEX( xfields, '" . $this->seasonsConfig['dop_fields'] . "|', -1 ) , '||', 1 ) =" . $this->kinopoisk_id;
} else {
$this->XFIELD = "SUBSTRING_INDEX( SUBSTRING_INDEX( xfields, '" . $this->FIELD . "|', -1 ) , '||', 1 ) =" . $this->kinopoisk_id;
}
$this->query = $this->db->query('SELECT * FROM ' . PREFIX . "_post WHERE " . $this->XFIELD . $this->order . $this->limitQuery );
$this->count = $this->db->super_query('SELECT COUNT(*) as count FROM ' . PREFIX . "_post WHERE " . $this->XFIELD . $this->order . $this->limitQuery );
$this->count = $this->count['count'];
if($this->query) {
$this->tpl3 = new dle_template();
$this->tpl3->dir = TEMPLATE_DIR;
$this->tpl3->load_template('/mod_liser/seasons/block.tpl');
}
$i = 1;
while ( $row = $this->db->get_row($this->query) ) {
$cat_list = explode( ',', $row['category'] );
$this->tpl4 = new dle_template();
$this->tpl4->dir = TEMPLATE_DIR;
$this->tpl4->load_template( '/mod_liser/seasons/list.tpl' );
$this->xfieldsdata = xfieldsdataload( $row['xfields'] );
if( $this->config['allow_alt_url'] ) {
if( $this->config['seo_type'] == 1 OR $this->config['seo_type'] == 2 ) {
if( $row['category'] and $this->config['seo_type'] == 2 ) {
$cat = explode(',', $row['category']); $cat = $cat[0];
if($this->cat_info[$row['category']]['parentid']) $cat_url = $this->cat_info[$this->cat_info[$cat]['parentid']]['alt_name'];
else $cat_url = $this->cat_info[$cat]['alt_name'];
$href = $this->config['http_home_url'] . $cat_url . "/" . $row['id'] . "-" . $row['alt_name'] . ".html";
} else {
$href = $this->config['http_home_url'] . $row['id'] . "-" . $row['alt_name'] . ".html";
}
} else {
$href = $this->config['http_home_url'] . date( 'Y/m/d/', $row['date'] ) . $row['alt_name'] . ".html";
}
} else {
$href = $this->config['http_home_url'] . "index.php?newsid=" . $row['id'];
}
if($this->seasonsConfig['title']){
$this->title = $this->seasonsConfig['title'];
$this->title = str_replace ( "{I}", $i, $this->title);
$this->title = str_replace ( "{TITLE}", $row['title'], $this->title);
$this->title = str_replace ( "{XFIELDSORT}", $this->xfieldsdata[$this->seasonsConfig['sort_xfield']], $this->title);
} else {
$this->title = $row['title'];
}
$this->tpl4->copy_template = str_replace ("{href}", $href, $this->tpl4->copy_template);
$this->tpl4->copy_template = str_replace ("{item}", $i, $this->tpl4->copy_template);
$this->tpl4->copy_template = str_replace ("{title}", $this->title, $this->tpl4->copy_template);
$this->xf();
if( $row['id'] == $this->id_news ){
$this->tpl4->copy_template = str_replace ("[active-list]", "", $this->tpl4->copy_template);
$this->tpl4->copy_template = str_replace ("[/active-list]", "", $this->tpl4->copy_template);
$this->tpl4->copy_template = preg_replace ( "#\[not-active-list\](.+?)\[/not-active-list\]#ims", "", $this->tpl4->copy_template );
if ( $i >= 1 && $i < $this->count ){ $prev = true; }
if ( $i == $this->count && $this->urlnext ){ $this->PN .= "<link rel=\"next\" href=\"{$this->urlnext}\"/>\n"; $next = false; }
if ( $i > 1 ){ $next = true; }
} else {
$this->tpl4->copy_template = str_replace ("[not-active-list]", "", $this->tpl4->copy_template);
$this->tpl4->copy_template = str_replace ("[/not-active-list]", "", $this->tpl4->copy_template);
$this->tpl4->copy_template = preg_replace ( "#\[active-list\](.+?)\[/active-list\]#ims", "", $this->tpl4->copy_template );
if( $prev ){ $this->PN .= "<link rel=\"prev\" href=\"{$href}\"/>\n"; $prev = false; }
if ( $next && $this->urlnext ){ $this->PN .= "<link rel=\"next\" href=\"{$this->urlnext}\"/>\n"; $next = false; }
$this->urlnext = $href;
}
$LIST .= $this->tpl4->copy_template;
$i ++;
}
$this->tpl3->copy_template = str_replace ('{LIST}', $LIST, $this->tpl3->copy_template);
$this->db->close();
return $this->tpl3->copy_template;
}
public function PrevNext(){
return $this->PN;
}
}
$seasons = new seasons;
$tpl->set ( "{SEASONS}", $seasons->run() );
$PrevNext = $seasons->PrevNext();
}
?>