Не пойму ошибку, прошу помочь

12 3
D
На сайте с 28.06.2008
Offline
1114
1344

Господа, перенес сайт на впс. По ходу где то не те права стоят. На сайте, на странице про отель есть несколько его фотографий выводящихся с красивыми эффектами с помощью мамбота rokbox.

Сейчас фото не выводятся и пишет ошибку:

Warning: Invalid argument supplied for foreach() in /var/www/dram/data/www/site.ru/plugins/content/rokbox.php on line 150

Вот код этого файла с 150 по 180 строку

foreach ($tmp as $link){

// Prevent thumbs of thumbs
if ( strpos( $link, $thumb_ext ) === false ) {


if (strlen($thethumb)) $image_url = trim($thethumb);
else $image_url = $link;

$extension = substr($image_url,strrpos($image_url,"."));
$image_name = substr($image_url,0,strrpos($image_url, "."));
$just_name = substr($image_name,strrpos($image_name,DS));

$full_url = JURI::base() . $link;
$full_path = JPATH_ROOT . DS . $link;
$thumb_url_custom = JURI::base() . $thumb_dir . DS . $just_name . $thumb_ext . $extension;
$thumb_path_custom = JPATH_ROOT. DS . $thumb_dir . DS . $just_name . $thumb_ext . $extension;
$thumb_url = JURI::base() . $image_name . $thumb_ext . $extension;
$thumb_path = JPATH_ROOT . DS . $image_name . $thumb_ext . $extension;

$isimage = ($extension == '.jpg' || $extension == '.jpeg' || $extension == '.bmp' || $extension == '.png' || $extension == '.gif' ||
$extension == '.JPG' || $extension == '.JPEG' || $extension == '.BMP' || $extension == '.PNG' || $extension == '.GIF');

if ($onsite){
if (!isset($size_matches[1]) && $isimage) {
list($image_width,$image_height)=getimagesize($link);
$thesize = "[" . $image_width . " " . $image_height . "]";
}
$thethumbcount--;
if ($thethumbcount<0) $displaythumb = '" style="display: none;';
}
BD
На сайте с 22.03.2010
Offline
5
#1

Нужен код выше - как получается массив $tmp, а это лишь результат - foreach подсунули не массив

frantic
На сайте с 09.02.2009
Offline
27
#2

Как раз надо все до 150-й. $tmp это не массив

D
На сайте с 28.06.2008
Offline
1114
#3

Вот почти все. В файле было где-то 10300 знаков, форум столько не пропустил. Убрал чуток с конца

<?php

/**
* @version 1.2 - RokBox - RocketWerx
* @thanks to Dennis Pleiter for Wildcards contribution
* @package RocketWerx
* @copyright Copyright (C) 2008 RocketTheme, LLC. All rights reserved.
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
*/

// no direct access
defined( '_JEXEC' ) or die();

jimport( 'joomla.plugin.plugin' );
require_once(dirname(__FILE__) . '/rokbox/imagehandler.php');

class plgContentRokbox extends JPlugin
{
function plgContentRokbox( &$subject, $params )
{
parent::__construct( $subject, $params );
}

function onPrepareContent( &$article, &$params, $limitstart )
{
global $mainframe;


// simple performance check to determine whether bot should process further
if ( strpos( $article->text, 'rokbox' ) === false ) {
return true;
}

// Get plugin info
$plugin =& JPluginHelper::getPlugin('content', 'rokbox');

// define the regular expression for the bot
$regex = "#{rokbox(.*?)}(.*?){/rokbox}#s";

$pluginParams = new JParameter( $plugin->params );

// check whether plugin has been unpublished
if ( !$pluginParams->get( 'enabled', 1 ) ) {
$article->text = preg_replace( $regex, '', $row->text );
return true;
}

// find all instances of plugin and put in $matches
preg_match_all( $regex, $article->text, $matches );

// Number of plugins
$count = count( $matches[0] );

// plugin only processes if there are any instances of the plugin in the text
if ( $count ) {
// Get plugin parameters
$style = $pluginParams->def( 'style', -2 );

$this->plgContentProcessRokboxImages( $article, $matches, $count, $regex, $pluginParams );
}


}

function plgContentProcessRokboxImages( &$row, &$matches, $count, $regex, &$botParams ) {
global $mainframe;


$thumb_ext = $botParams->def( 'thumb_ext', '_thumb');
$thumb_class = $botParams->def( 'thumb_class', 'album');
$thumb_width = $botParams->def( 'thumb_width', '100');
$thumb_height = $botParams->def( 'thumb_height', '100');
$thumb_quality = $botParams->def( 'thumb_quality', '90');
$thumb_custom = $botParams->def( 'thumb_custom', 0);
$thumb_dir = $botParams->def( 'thumb_dir');
$compatibility = $botParams->def( 'compatibility', 'rokbox');


/* thumbnail settings */
$improve_thumbnails = false; // Auto Contrast, Unsharp Mask, Desaturate, White Balance
$thumb_quality = $thumb_quality;
$width = $thumb_width;
$height = $thumb_height;

/* slimbox = lightbox mode */
if ($compatibility == "slimbox") $compatibility = "lightbox";

for ( $i=0; $i < $count; $i++ )
{
$thealbum = '';
$thetitle = '';
$thethumb = '';
$thetype = '';
$thesize = '';
$thetext = '';
$themodule = '';
$thethumbcount = 999;
if (@$matches[1][$i]) {
$inline_params = $matches[1][$i];

// get album
$album_matches = array();
preg_match( "#album=\|(.*?)\|#s", $inline_params, $album_matches );
if (isset($album_matches[1])) $thealbum = "(" . trim($album_matches[1]) . ")";

// get size
$size_matches = array();
preg_match( "#size=\|(.*?)\|#s", $inline_params, $size_matches );
if (isset($size_matches[1])) $thesize = "[" . trim($size_matches[1]) . "]";

// get title
$title_matches = array();
preg_match( "#title=\|(.*?)\|#s", $inline_params, $title_matches );
if (isset($title_matches[1])) $thetitle = $title_matches[1];

// get text
$text_matches = array();
preg_match( "#text=\|(.*?)\|#s", $inline_params, $text_matches );
if (isset($text_matches[1])) $thetext = $text_matches[1];

// force image
$type_matches = array();
preg_match( "#type=\|(.*?)\|#s", $inline_params, $type_matches );
if (isset($type_matches[1])) $thetype = $type_matches[1];

// get module
$module_matches = array();
preg_match( "#module=\|(.*?)\|#s", $inline_params, $module_matches );
if (isset($module_matches[1])) $themodule = "[module=".$module_matches[1]."]";

// get thumb
$thumb_matches = array();
preg_match( "#thumb=\|(.*?)\|#s", $inline_params, $thumb_matches );
if (isset($thumb_matches[1])) $thethumb = $thumb_matches[1];

// get thumb count
$thumbcount_matches = array();
preg_match( "#thumbcount=\|(.*?)\|#s", $inline_params, $thumbcount_matches );
if (isset($thumbcount_matches[1])) $thethumbcount = $thumbcount_matches[1];
}

$onsite=1;
$text = '';
$displaythumb = '';
$tmp = glob(trim($matches[2][$i]));
if (count($tmp) < 1) {
$tmp = array(trim($matches[2][$i]));
$onsite=0;
}

foreach ($tmp as $link){
// Prevent thumbs of thumbs
if ( strpos( $link, $thumb_ext ) === false ) {


if (strlen($thethumb)) $image_url = trim($thethumb);
else $image_url = $link;

$extension = substr($image_url,strrpos($image_url,"."));
$image_name = substr($image_url,0,strrpos($image_url, "."));
$just_name = substr($image_name,strrpos($image_name,DS));


?>
[umka]
На сайте с 25.05.2008
Offline
456
#4

Следует обратить внимание на то, что это не ошибка, а предупреждение (warning).

Избавиться от него можно, например, заключив весь 'foreach' в условие:

if (@count($tmp)) { }

или просто добавив перед 'foreach' вот такую ерунду:

if (!@count($tmp)) { $tmp=array(); }

Лог в помощь!
D
На сайте с 28.06.2008
Offline
1114
#5

Прописал

			if (!@count($tmp)) { $tmp=array(); } foreach ($tmp as $link){

// Prevent thumbs of thumbs

Ошибка не пропала

[umka]
На сайте с 25.05.2008
Offline
456
#6

Любопытно ...

Ну напишите так:

vardump($tmp);

foreach ($tmp as $link) ... и т.д.

Посмотрим, что же там у вас.

D
На сайте с 28.06.2008
Offline
1114
#7

$tmp = array(trim($matches[2][$i]));

$onsite=0;
}
vardump($tmp);
foreach ($tmp as $link){
// Prevent thumbs of thumbs

Как итог Fatal error: Call to undefined function vardump() in /var/www/dram/data/www/hotelkiev.ru/plugins/content/rokbox.php on line 149

[umka]
На сайте с 25.05.2008
Offline
456
#8

Сорри... var_dump конечно же

D
На сайте с 28.06.2008
Offline
1114
#9

Очередная хрень под именем

bool(false)

Warning: Invalid argument supplied for foreach() in /var/www/dram/data/www/hotelkiev.ru/plugins/content/rokbox.php on line 150

[umka]
На сайте с 25.05.2008
Offline
456
#10

Любопытно работает функция count() в PHP :)

Оказывается, count(false)==1 ☝ … жесть

По делу.

$tmp = array(trim($matches[2][$i])); 

$onsite=0;
}
if (!$tmp||!@count($tmp)) { $tmp=array(); }
foreach ($tmp as $link){
// Prevent thumbs of thumbs
12 3

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