Thread: vBulletin CMS Widgets - United-Forum Nivo Slider Widget
View Single Post
  #365  
Old 12-01-2011, 08:09 AM
Loversama Loversama is offline
 
Join Date: Nov 2005
Posts: 35
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Mooff View Post
@Loversama
I need more information on the database error so i can help.
I will post everything I have done up to now and hopefully you can point out where I am going wrong ^___^


Plugins & Products -> Plugin Manager -> Add New Plugin

Product = vBulletin
Hook Location = process_templates_complete
Title = nivo_slider
Plugin PHP Code =

PHP Code:
// DEBUG MODUS !
$debug_modus true;

if(
$debug_modus === false)
{
    
ob_start();
}

//nivo slider - uf - vb.org version
//set these values as you need them:

//your slider folder - has to be read and writeable
//folder where all slider files are saved
$slider_img_filepath '/slider/';   

//picture width and height !same as in the CSS FILE!
$maxwidth 650;                                  
$maxheight 250;    

//do you want images without previewimage to be shown? slider is using the fallback then
$show_articles_without_image false;           

//picture shown if your articles has no previewpicture
$fallback_img $slider_img_filepath 'uf_fallback_slider.png';  

//hardcoded maximum is 20 - if you want more just ask
$number_of_articles_shown 10;                                
            
//lengh in characters of the article descriptions
$description_length 95;

//stretch picture or crop them? false = strechting (default) true = cropping (beta)
$crop false;


//Debug Messages
if($debug_modus)
{
    echo 
"<span style='color:red;'>DEBUG MODE is ON! </span><br />";
    echo 
"slider_img_filepath: $slider_img_filepath <br />";
    echo 
"width: $maxwidth   height: $maxheight <br />";
    echo 
"Strech or Crop? $crop <br />";
    echo 
"show_articles_without_image: "
        
var_dump($show_articles_without_image); 
        echo 
" <br />";
    echo 
"fallback_img: $fallback_img <br />";
    echo 
"#img: $number_of_articles_shown <br />";
    echo 
"description_length: $description_length <br />";
    echo 
'directory ' DIR '<br />';

}




$article_type vb_Types::instance()->getContentTypeID("vBCms_Article");
$time TIMENOW;
 
if(!
extension_loaded('gd'))
{
    echo 
'<span style="color:red">Error occurred:</span> Your System does not support the GD-Libary. Please install the GD-Libary.<br />';
}
       
    
$article_get vB::$db->query_read('
        SELECT
            article.pagetext,
            article.previewimage,
            node.url,
            node.publishdate,
            node.parentnode,
            parentnode.url AS parenturl,
            thread.replycount,
            info.title,
            node.nodeid,            
            GROUP_CONCAT( category.category )
        FROM
            '
.TABLE_PREFIX.'cms_article AS article INNER JOIN
            '
.TABLE_PREFIX.'cms_node AS node 
                ON (node.contentid = article.contentid AND node.contenttypeid = ' 
vb::$db->sql_prepare($article_type) .') INNER JOIN
            '
.TABLE_PREFIX.'cms_nodeinfo AS info 
                ON info.nodeid = node.nodeid INNER JOIN
            '
.TABLE_PREFIX.'cms_node AS parentnode 
                ON parentnode.nodeid = node.parentnode LEFT JOIN
            '
.TABLE_PREFIX.'thread AS thread ON thread.threadid = info.associatedthreadid LEFT JOIN
            '
.TABLE_PREFIX.'cms_nodecategory AS nodecategory ON nodecategory.nodeid = node.nodeid LEFT JOIN
            '
.TABLE_PREFIX.'cms_category AS category ON nodecategory.categoryid = category.categoryid 
        WHERE
            node.setpublish = 1 AND
            node.publishdate > '
vb::$db->sql_prepare($time) .' -34560000 AND
            node.publishdate < '
vb::$db->sql_prepare($time) .
        GROUP BY node.nodeid
        ORDER BY node.publishdate
        DESC LIMIT 20'
);

    
$database_articles = array();
    
    
/* my version of sorting the articles via relevance - i'll keep it in case someone is interested*/
    
while($article vB::$db->fetch_array($article_get))
    {
        
$article['value'] = ( - ($time $article['publishdate'] ) / 86400 ) * ( - ($time $article['publishdate'] ) / 86400 ) * ( - ($time $article['publishdate'] ) / 86400 ) + (10 $article['replycount']);
        
$database_articles[] = $article;        
    }
    
    foreach(
$database_articles as $c => $key)
    {
        
$sort_value[] = $key['value'];
    }
    
    
array_multisort($sort_valueSORT_DESC$database_articles);    
    
    
//
    
$i 0;
    
$section_array = array();
    
$featured_articles = array();
    
    foreach(
$database_articles AS $article)
    {
        
$section_array[$article['parentnode']]++;

        
$categories explode(',' $article['GROUP_CONCAT( category.category )']);
     
        if(
$show_articles_without_image == true OR $article['previewimage'])
        {
            if(
$section_array[$article['parentnode']] < 50 AND $i $number_of_articles_shown)
            {
                if(
$debug_modus == true OR !file_exists($slider_img_filepath 'slide_' $article['nodeid'] . '.jpg'))
                {
                    
//rebuild image to the height and width we want in the slider 
                    //called sprite since i got the code from our sprite addon :P
                    
$sprite imagecreatetruecolor($maxwidth$maxheight);
                    if(
is_resource($sprite) AND $article['previewimage'] )
                    {                                   
                        
$imageinfo getimagesize($article['previewimage']);
                        if(
is_array($imageinfo))
                        {   
                            
$image null;
                            switch(
$imageinfo[2])
                            {
                                case 
IMAGETYPE_PNG:
                                
$image imagecreatefrompng($article['previewimage']);
                                break;
                                case 
IMAGETYPE_GIF:
                                
$image imagecreatefromgif($article['previewimage']);
                                break;
                                case 
IMAGETYPE_JPEG:
                                
$image imagecreatefromjpeg($article['previewimage']);
                                break;
                                default:
                                echo 
'<span style="color:red">Error occurred:</span> Unknown image format. ' $article['previewimage']. '<br />';
                                break;                        
                            }
                            
                            if(!
is_resource($image))
                            {
                                
//resiziing did not work - we are using the fallback image.
                                
echo '<span style="color:red">Error occurred:</span> imagecreation failed. ' $article['previewimage']. '<br />';
                                
$article['previewimage'] = $fallback_img;
                            }
                            else
                            {
                                
$img_width $imageinfo[0];
                                
$img_height $imageinfo[1];                            
                                
                                if(
$crop == false)
                                {                                    
                                    
imagecopyresampled($sprite$image0000$maxwidth$maxheight$img_width$img_height );
                                    
imagedestroy($image);
                                }
                                else
                                {
                                    
//cropping
                                    
$ratiox $maxheight $img_height ;
                                    
$ratioy $maxwidth $img_width ;
                                    
$new_height $img_height;
                                    
$new_width $img_width;
                                    
                                    if (
$maxheight $img_height OR $maxwidth $img_width)
                                    {
                                        if(
$ratiox $ratioy)
                                        {
                                            
$new_height round($img_height $ratiox);
                                            
$new_width round($img_width $ratiox);
                                        }
                                        else
                                        {
                                            
$new_height round($img_height $ratioy);
                                            
$new_width round($img_width $ratioy);
                                        }                                        
                                    }
                                    
$cropx $new_height $maxheight;
                                    
$cropy $new_width $maxwidth;
                                    
                                    
imagecopyresampled($sprite$image0000$new_width$new_height$img_width$img_height);
                                    
imagedestroy($image);
                                    
                                }
                                
                                
                                
$img_filepath $slider_img_filepath 'slide_' $article['nodeid'] . '.jpg';
                                
$success imagejpeg($spriteDIR  . ($img_filepath[0] != DIRECTORY_SEPARATOR ?  DIRECTORY_SEPARATOR '') . $img_filepath);
                                
imagedestroy($sprite);
                                if(
$success)
                                {
                                    
$article['previewimage'] = $img_filepath;
                                }
                                else
                                {
                                    
$img_filepath DIR  . ($img_filepath[0] != DIRECTORY_SEPARATOR ?  DIRECTORY_SEPARATOR '') . $img_filepath;
                                    echo 
'<span style="color:red">Error occurred:</span> imagejpeg failed. ' $article['previewimage']. '<br />
                                    directory: '
$img_filepath ;
                                    
                                    
$article['previewimage'] = $fallback_img;
                                }
                            }
                            
                        }
                        else
                        {
                            
//resiziing did not work - we are using the fallback image.
                            
echo '<span style="color:red">Error occurred:</span> picture is not readable.' $article['previewimage']. '<br /> ';
                            
$article['previewimage'] = $fallback_img;
                        }                  
                    }
                    else
                    {
                        
//resiziing did not work - we are using the fallback image.
                        
echo '<span style="color:red">Warning:</span> article has no previewimage or sprite is no ressource. ' $article['previewimage']. '<br />';
                        
$article['previewimage'] = $fallback_img;
                    }
                }
                else
                {
                    
//we already have the image, no need to resize or crop anything
                    
$article['previewimage'] = $slider_img_filepath 'slide_' $article['nodeid'] . '.jpg';
                }

                
/*remove everything from the previewtext - html and bb. I do not want bold or colored text there. Cut to a decent length.*/        
                
$article['pagetext'] = strip_bbcode($article['pagetext'], truetruefalsetruefalse);

                
$article['previewtext'] = strip_tags($article['pagetext'], '<a>');
                    
                
$len $description_length;
                if ( 
strlen($article['previewtext']) > $len )
                {                    
                    
$article['previewtext'] = substr$article['previewtext'] , strrpossubstr$article['previewtext'], 0$len), ' ' ));
                }   

                
$i++;
                
//Build Array
                
$article_neu = array();
                
$article_neu['description'] = '<h2 style="font-weight:bold; font-size: 14px">'$article['title'].'</h2><span>'$article['previewtext'] .'</span> <a href="/content.php?r=' $article['nodeid'] . '-' $article['url'] . '">read on</a>';
                
$article_neu['htmlcaptionname'] = 'htmlcaption' $article['nodeid'] ;
                
$article_neu['picture'] = '<a href="/content.php?r=' $article['nodeid'] . '-' $article['url'] . '"><img src="'.$article['previewimage'].'" alt="" title="#htmlcaption'$article['nodeid'] . '" /></a>';
                
                
$featured_articles[] = $article_neu;
            }
        }
    }
    
    
//Randomize Array
    //shuffle($featured_articles);

    //Debug Messages
    
if($debug_modus)
    {
        echo 
'#articles - featured and databasepull ';
        
var_dump(count($featured_articles));
        
var_dump(count($database_articles));
    }

    
$output_bits '
    <link rel="stylesheet" href="' 
.$slider_img_filepath'nivo-slider.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="' 
.$slider_img_filepath'nivo-slider_uf_theme.css" type="text/css" media="screen" />
    <div style="height:' 
$maxheight 'px;">
    <div id="wrapper">
        <div class="slider-wrapper theme-uf">
            <div class="ribbon"></div>
            <div id="slider" class="nivoSlider">'
;
            
                foreach(
$featured_articles AS $article)
                {
                    
$output_bits .= $article['picture'];
                }
            
$output_bits .= '
            </div>'
;
            
            foreach(
$featured_articles AS $article)
            {
                
$output_bits .= '<div id="' $article['htmlcaptionname'] . '" class="nivo-html-caption">' $article['description'] .'</div>';
            }
            
            
$output_bits .= '         
        </div>

    </div>
    <script type="text/javascript" src="' 
.$slider_img_filepath'jquery-1.6.1.min.js"></script>
    <script type="text/javascript" src="' 
.$slider_img_filepath'jquery.nivo.slider.pack.js"></script>
    <script type="text/javascript">
    $(window).load(function() {
        $("#slider").nivoSlider();
    });
    </script>
    </div>
    '
;
        
$output $output_bits;
 
if(
$debug_modus === false)
{
    
ob_end_clean();        

}

$templater = \vB_Template::create('vbcms_page');
$templater->register('nivo_slider'$output);
$template_hook['process_templates_complete'] .= $templater->render(); 
Styles & Templates -> vbcms_page
PHP Code:
{vb:raw header}
{
vb:raw nivo_slider}
{
vb:raw navbar}
{
vb:raw toolbar
Then the website will only some times load, half the time it will get:

Quote:
Database error
The database has encountered a problem.

And the other time I get:

Quote:
DEBUG MODE is ON!
slider_img_filepath: /slider/
width: 650 height: 250
Strech or Crop?
show_articles_without_image: bool(false)
fallback_img: /slider/uf_fallback_slider.png
#img: 10
description_length: 95
directory /home1/fadertwi/public_html
Error occurred: picture is not readable.http://www.sinfulshadows.com/attachm...tid=255&cid=24
Error occurred: picture is not readable.http://www.sinfulshadows.com/attachm...tid=256&cid=24
Error occurred: picture is not readable.http://www.sinfulshadows.com/attachm...tid=254&cid=24
Error occurred: picture is not readable.http://www.sinfulshadows.com/attachm...tid=252&cid=24
Error occurred: picture is not readable.http://www.sinfulshadows.com/attachm...tid=250&cid=24
Error occurred: picture is not readable.http://www.sinfulshadows.com/attachm...tid=251&cid=24
Error occurred: picture is not readable.http://www.sinfulshadows.com/attachm...tid=248&cid=24
#articles - featured and databasepull int(7) int(7)

I also get a error in the PHP which does not display onscreen but in the logs which is:

Quote:
[01-Dec-2011 02:04:44] PHP Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home1/fadertwi/public_html/includes/class_bootstrap.php(555) : eval()'d code on line 505
I have also tried the method of changing the article type as you suggested.

Quote:
$article_type = vb_Types::instance()->getContentTypeID("vBCms_Article");
to

Quote:
$article_type = 24;
which is the article type in the DB however that causes the process_templates_complete to not allow any other hooks, or it crashes or something..


So yea pretty stuck, but it'd be amazing if I could fix this, I am re-modling my website at the moment and I really need the slider in my header!

my website is www.SinfulShadows.com however I will have to disable the plugin as my members will not be able to access my site freely while its crashing.
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03565 seconds
  • Memory Usage 2,046KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_php
  • (6)bbcode_quote
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete