Вывод картинки из допполя в topnews

12
C7
На сайте с 25.01.2009
Offline
107
2733

Здравствуйте !

Проблема в том, что на сайте уже набито большое кол-во роликов и все постеры к фильмам находятся в дополнительном поле. При попытке прописать в topnews и relatednews стандартное [xfgiven_poster][xfvalue_poster][/xfgiven_poster] , чтобы вытащить картинку - теги просто выводятся как текст, а значит не обрабатываются фактически.

Может кто сможет помочь? Лазил по инету, но РАБОЧЕГО варианта для dle 9.4 не нашел...

Лично я учился создавать и зарабатывать на сайте здесь - манимастер (http://www.moneymaster.ru/?chess77)
AGRESSOR
На сайте с 04.07.2010
Offline
79
#1

<?php

if( ! defined( 'DATALIFEENGINE' ) ) {die( "Hacking attempt!" );}

$topnews = dle_cache( "topnews", $config['skin'] );

if( $topnews === false ) {

$this_month = date( 'Y-m-d H:i:s', $_TIME );

$db->query( "SELECT id, title, date, alt_name, xfields, category, flag FROM " . PREFIX . "_post WHERE approve='1' AND date >= '$this_month' - INTERVAL 1 MONTH AND date < '$this_month' ORDER BY rating DESC, comm_num DESC, news_read DESC, date DESC LIMIT 0,10" );

while ( $row = $db->get_row() ) {

$row['date'] = strtotime( $row['date'] );

$row['category'] = intval( $row['category'] );

$xfieldsdata = xfieldsdataload( $row['xfields'] );

if( $config['allow_alt_url'] == "yes" ) {

if( $row['flag'] and $config['seo_type'] ) {

if( $row['category'] and $config['seo_type'] == 2 ) {

$full_link = $config['http_home_url'] . get_url( $row['category'] ) . "/" . $row['id'] . "-" . $row['alt_name'] . ".html";

} else {

$full_link = $config['http_home_url'] . $row['id'] . "-" . $row['alt_name'] . ".html";

}

} else {

$full_link = $config['http_home_url'] . date( 'Y/m/d/', $row['date'] ) . $row['alt_name'] . ".html";

}

} else {

$full_link = $config['http_home_url'] . "index.php?newsid=" . $row['id'];

}

if( dle_strlen( $row['title'], $config['charset'] ) > 22 ) $title = dle_substr( $row['title'], 0, 22, $config['charset'] ) . " ...";

else $title = $row['title'];

$link = "<a href=\"" . $full_link . "\">" . stripslashes( $title ) . "</a>";

$topnews .= "<li>" . $link . "</br>".$xfieldsdata['poster']."</li>";

}

$db->free();

create_cache( "topnews", $topnews, $config['skin'] );

}

?>

Держите, отпостил весь topnews потому-что потом появится куча вопросов, просто скопируйте этот код в topnews.php

22 - длина в символах заголовка новости

C7
На сайте с 25.01.2009
Offline
107
#2
AGRESSOR:

Держите, отпостил весь topnews потому-что потом появится куча вопросов, просто скопируйте этот код в topnews.php
22 - длина в символах заголовка новости

не прет 🙅

AGRESSOR
На сайте с 04.07.2010
Offline
79
#3

не понял? что не прет? наркотики?

или про что вы?

C7
На сайте с 25.01.2009
Offline
107
#4
AGRESSOR:
не понял? что не прет? наркотики?
или про что вы?

Сорри ) Хотел сказать,что не работает вообще такой вариант topnews, модуль даже текст с названием не выводит ...

AGRESSOR
На сайте с 04.07.2010
Offline
79
#5

а какая версия движка?

C7
На сайте с 25.01.2009
Offline
107
#6
AGRESSOR:
а какая версия движка?

9.4 nulled

AGRESSOR
На сайте с 04.07.2010
Offline
79
#7

дайте свой свой topnews.php

C7
На сайте с 25.01.2009
Offline
107
#8

Модуль выглядит вот так

<?php

/*

=====================================================

DataLife Engine - by SoftNews Media Group

-----------------------------------------------------

http://dle-news.ru/

-----------------------------------------------------

Copyright (c) 2004,2011 SoftNews Media Group

=====================================================

Данный код защищен авторскими правами

=====================================================

Файл: topnews.php

-----------------------------------------------------

Назначение: вывод рейтинговых статей

=====================================================

*/

if( ! defined( 'DATALIFEENGINE' ) ) {

die( "Hacking attempt!" );

}

$tpl->result['topnews'] = dle_cache( "topnews", $config['skin'], true );

if( $tpl->result['topnews'] === false ) {

$this_month = date( 'Y-m-d H:i:s', $_TIME );

$tpl->load_template( 'topnews.tpl' );

$db->query( "SELECT id, short_story, title, date, alt_name, category, flag FROM " . PREFIX . "_post WHERE approve=1 AND date >= '$this_month' - INTERVAL 1 MONTH AND date < '$this_month' ORDER BY rating DESC, comm_num DESC, news_read DESC, date DESC LIMIT 0,10" );

while ( $row = $db->get_row() ) {

$row['date'] = strtotime( $row['date'] );

$row['category'] = intval( $row['category'] );

if( $config['allow_alt_url'] == "yes" ) {

if( $row['flag'] and $config['seo_type'] ) {

if( $row['category'] and $config['seo_type'] == 2 ) {

$full_link = $config['http_home_url'] . get_url( $row['category'] ) . "/" . $row['id'] . "-" . $row['alt_name'] . ".html";

} else {

$full_link = $config['http_home_url'] . $row['id'] . "-" . $row['alt_name'] . ".html";

}

} else {

$full_link = $config['http_home_url'] . date( 'Y/m/d/', $row['date'] ) . $row['alt_name'] . ".html";

}

} else {

$full_link = $config['http_home_url'] . "index.php?newsid=" . $row['id'];

}

if( dle_strlen( $row['title'], $config['charset'] ) > 55 ) $title = dle_substr( $row['title'], 0, 55, $config['charset'] ) . " ...";

else $title = $row['title'];

$tpl->set( '{title}', htmlspecialchars( strip_tags( stripslashes( $title ) ) ) );

$tpl->set( '{link}', $full_link );

$row['short_story'] = stripslashes( $row['short_story'] );

if( $user_group[$member_id['user_group']]['allow_hide'] ) $row['short_story'] = str_ireplace( "[hide]", "", str_ireplace( "[/hide]", "", $row['short_story']) );

else $row['short_story'] = preg_replace ( "#\[hide\](.+?)\[/hide\]#ims", "<div class=\"quote\">" . $lang['news_regus'] . "</div>", $row['short_story'] );

if (stripos ( $tpl->copy_template, "{image-" ) !== false) {

$images = array();

preg_match_all('/(img|src)=("|\')[^"\'>]+/i', $row['short_story'], $media);

$data=preg_replace('/(img|src)("|\'|="|=\')(.*)/i',"$3",$media[0]);

foreach($data as $url) {

$info = pathinfo($url);

if (isset($info['extension'])) {

$info['extension'] = strtolower($info['extension']);

if (($info['extension'] == 'jpg') || ($info['extension'] == 'jpeg') || ($info['extension'] == 'gif') || ($info['extension'] == 'png')) array_push($images, $url);

}

}

if ( count($images) ) {

$i=0;

foreach($images as $url) {

$i++;

$tpl->copy_template = str_replace( '{image-'.$i.'}', $url, $tpl->copy_template );

}

}

$tpl->copy_template = preg_replace( "#\\{image-(.+?)\\}#i", "", $tpl->copy_template );

}

if ( preg_match( "#\\{text limit=['\"](.+?)['\"]\\}#i", $tpl->copy_template, $matches ) ) {

$count= intval($matches[1]);

$row['short_story'] = strip_tags( $row['short_story'], "<br>" );

$row['short_story'] = trim(str_replace( "<br>", " ", str_replace( "<br />", " ", $row['short_story'] ) ));

if( $count AND dle_strlen( $row['short_story'], $config['charset'] ) > $count ) {

$row['short_story'] = dle_substr( $row['short_story'], 0, $count, $config['charset'] );

if( ($temp_dmax = dle_strrpos( $row['short_story'], ' ', $config['charset'] )) ) $row['short_story'] = dle_substr( $row['short_story'], 0, $temp_dmax, $config['charset'] );

}

$tpl->set( $matches[0], $row['short_story'] );

} else $tpl->set( '{text}', $row['short_story'] );

$tpl->compile( 'topnews' );

}

$tpl->clear();

$db->free();

create_cache( "topnews", $tpl->result['topnews'], $config['skin'], true );

}

?>

А сам файл вывода topnews.tpl :

<li>

<a href="{link}">

<img src="[xfgiven_poster][xfvalue_poster][/xfgiven_poster] " alt="{title}" />

<span style="float: left;">

<span class="t-title">{title}</span>

{text limit="180"}

</span>

</a>

</li>

N9
На сайте с 04.07.2011
Offline
11
#9

Рабочий вариант для 9.4:

Строку:

$db->query( "SELECT id, short_story, title, date, alt_name, category, flag FROM " . PREFIX . "_post WHERE approve=1 AND date >= '$this_month' - INTERVAL 1 MONTH AND date < '$this_month' ORDER BY rating DESC, comm_num DESC, news_read DESC, date DESC LIMIT 0,10" );

заменить на:

$db->query( "SELECT id, short_story, xfields, title, date, alt_name, category, flag FROM " . PREFIX . "_post WHERE approve=1 AND date >= '$this_month' - INTERVAL 1 MONTH AND date < '$this_month' ORDER BY rating DESC, comm_num DESC, news_read DESC, date DESC LIMIT 0,10" );

Далее найти:

if (stripos ( $tpl->copy_template, "{image-" ) !== false) {

и ниже добавить:

$xfieldsdata = xfieldsdataload( $row['xfields'] );

Потом найти строку:

preg_match_all('/(img|src)=("|\')[^"\'>]+/i', $row['short_story'], $media);

и заменить на:

preg_match_all('/(img|src)=("|\')[^"\'>]+/i', $xfieldsdata['fieldname'], $media);

где вместо fieldname подставить имя своего дополнительного поля. - ['poster']

Вывод картинки в topnews.tpl через стандартный <img src="{image-1}">

M
На сайте с 04.11.2010
Offline
47
#10

Если еще актуально, могу скинуть рабочий файл по почте.

12

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий