Output problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
traveljunkie
Forum Newbie
Posts: 4
Joined: Fri May 23, 2008 9:39 pm

Output problem

Post by traveljunkie »

Hello,

I am in the process of writing a Wordpress plugin. I have one function, that produces the output, or rather it should. Here it is:

Code: Select all

 
function nggShowImageFlow($galleryID,$irWidth,$irHeight, $link = false) {
 
    global $wpdb;
    $ngg_options = get_option ('ngg_options');
    $ngg_if_options = get_option('ngg_if_options');  
    $pictures    = $wpdb->get_results("SELECT t.*, tt.* FROM $wpdb->nggallery AS t INNER JOIN $wpdb->nggpictures AS tt ON t.gid = tt.galleryid WHERE t.gid = '$galleryID' AND tt.exclude != 1 ORDER BY tt.$ngg_options[galSort] $ngg_options[galSortDir] ");
    $siteurl        = get_option ('siteurl');
 
    if (!is_array($pictures)) die;
 
        $out = '<div id="if_imageflow">';
        $out .= "\n".'<div id="if_loading">';
        $out .= "\n".'<b>'.__('Loading images...', 'nggflow').'</b><br/>';
        $out .= "\n".'<img src="'.NGGIMAGEFLOW_URLPATH.'imageflow/loading.gif" width="208" height="13" alt="'.__('Loading', 'nggflow').'" />';
        $out .= "\n".'</div>';
        $out .= "\n".'<div id="if_images">';
        foreach ($pictures as $picture) {
            $out .= "\n".'<img src="'.$siteurl.'/reflect.php?img='.$picture->path.'/'.$picture->filename.'&bgc='.$ngg_if_options['ngg_if_background_color'].'" longdesc="'.$siteurl.'/'.$picture->path.'/'.$picture->filename.'" alt="'.apply_filters('the_title', $picture->description).'" />';
        }
        $out .= "\n".'</div>';
        $out .= "\n".'<div id="if_captions"></div>';
        $out .= "\n".'<div id="if_scrollbar">';
        $out .= "\n".'<div id="if_slider"></div>';
        $out .= "\n".'</div>';
        $out .= '</div>';
 
    return $out;
}
 
The problem I am having is that on the page I don't have any output at all and I can't see why that is. When I use echo instead of $out then everything shows up fine. I'd rather use $out though.

This is only my second attempt on writing something in PHP, so please be gentle :)

Any help would really be appreciated.
Thanks,
Boris
whiterabbit
Forum Newbie
Posts: 14
Joined: Thu May 22, 2008 6:58 pm

Re: Output problem

Post by whiterabbit »

When you call the nggShowImageFlow($galleryID,$irWidth,$irHeight, $link) function in your code, do you do it like this:

Code: Select all

 
nggShowImageFlow($galleryID,$irWidth,$irHeight, $link);
 
or like
$string = nggShowImageFlow($galleryID,$irWidth,$irHeight, $link);
echo $string;
or like

Code: Select all

echo nggShowImageFlow($galleryID,$irWidth,$irHeight, $link);
or none of those?
traveljunkie
Forum Newbie
Posts: 4
Joined: Fri May 23, 2008 9:39 pm

Re: Output problem

Post by traveljunkie »

It's none of these. I have another function that searches in the content using regular expressions for a tag like this [imageflow=12], where 12 is the gallery ID. Then if it is found it calls nggShowImageFlow.
Here's that function:

Code: Select all

function SearchForImageFlow($content) {
 
    global $wpdb;
    
    if ( stristr( $content, '[imageflow' )) {   
        $search = "@(?:<p>)*\s*\[imageflow\s*=\s*(\w+|^\+)(|,(\d+))(|,(\d+))(|,\*(.*?)\*)\]\s*(?:</p>)*@i";
    
        if  (preg_match_all($search, $content, $matches)) {
            if (is_array($matches)) {
                foreach ($matches[1] as $key =>$match) {
                    // check for gallery id
                    $galleryID = $wpdb->get_var("SELECT gid FROM $wpdb->nggallery WHERE gid = '$match' ");
                    if(!$galleryID) $galleryID = $wpdb->get_var("SELECT gid FROM $wpdb->nggallery WHERE name = '$match' ");
                    if($galleryID) {
                        $search = $matches[0][$key];
                        // get the size if they are set and the link if used
                        $width  =  $matches[3][$key]; 
                        $height =  $matches[5][$key];
                        $link   =  $matches[7][$key]; 
    
                            $replace = nggShowImageFlow($galleryID,$width,$height,$link);
 
                        $content= str_replace ($search, $replace, $content);
                    }
                }   
            }
        }// end slideshow
    }
}
traveljunkie
Forum Newbie
Posts: 4
Joined: Fri May 23, 2008 9:39 pm

Re: Output problem

Post by traveljunkie »

Never mind, forgot to return $content in function SearchForImageFlow...
Post Reply