Go Back   vb.org Archive > vBulletin Modifications > vBulletin 4.x Modifications > vBulletin 4.x Add-ons
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
United-Forum Nivo Slider Widget Details »»
United-Forum Nivo Slider Widget
Version: 1.1.0, by Mooff Mooff is offline
Developer Last Online: Nov 2013 Show Printable Version Email this Page

Category: vBulletin CMS Widgets - Version: 4.1.4 Rating:
Released: 07-17-2011 Last Update: 07-18-2011 Installs: 146
Additional Files  
No support by the author.

Based on the Nivo Slider - all credit for slider awesomeness goes to them.
vB4 implementation goes to me.


What it is:
A slider for cms articles, it gets the articles via database, uses (if possible) the previewimage there and resizes it to slider size *update 1.1.0 cropping function included.

Livedemo on a Big Board (>2.000.000 posts)
the nivo slider on our site is customized to fit our heavily customized cms. Default look of this addon is shown in the picture below


facts about the nivo slider
Quote:
Originally Posted by nivo slider homepage
- ~ 600.000 downloads
- 16 transition effects
- a ton of options
- different available themes
- ...
Installation
  • upload all files (attached zip file) in the folder where you do need them - this has to be the same folder you will set via $slider_img_filepath (see picture)


  • create a new php-widget and insert the following code:
    Code:
    // DEBUG MODUS !
    $debug_modus = false;
    
    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 = 'external/unitedforum/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'] = ( 5 - ($time - $article['publishdate'] ) / 86400 ) * ( 5 - ($time - $article['publishdate'] ) / 86400 ) * ( 5 - ($time - $article['publishdate'] ) / 86400 ) + (10 * $article['replycount']);
            $database_articles[] = $article;        
        }
        
        foreach($database_articles as $c => $key)
        {
            $sort_value[] = $key['value'];
        }
        
        array_multisort($sort_value, SORT_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, $image, 0, 0, 0, 0, $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, $image, 0, 0, 0, 0, $new_width, $new_height, $img_width, $img_height);
    									imagedestroy($image);
    									
    								}
    								
    								
    								$img_filepath = $slider_img_filepath . 'slide_' . $article['nodeid'] . '.jpg';
    								$success = imagejpeg($sprite, DIR  . ($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'], true, true, false, true, false);
    
                    $article['previewtext'] = strip_tags($article['pagetext'], '<a>');
                        
                    $len = $description_length;
                    if ( strlen($article['previewtext']) > $len )
                    {                    
                        $article['previewtext'] = substr( $article['previewtext'] , 0 , strrpos( substr( $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();        
    }
  • set refresh time to something big!
  • save - add the widget to your layout - enjoy


Custom settings:

At the top of the php-widget code you can see the following:
Code:
// DEBUG MODUS !
$debug_modus = false;

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 = 'external/unitedforum/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 = 5;                                
            
//lengh in characters of the article descriptions
$description_length = 95;
If you change $maxwidth and $maxheight you need to edit the nivo-slider_uf_theme.css file, here:
Code:
.theme-uf #slider {
    margin:0px auto 0 auto;
    width:650px; /* Make sure your images are the same size */
    height:250px; /* Make sure your images are the same size */
}
Width and height have to be the same value in your php-widget and in the css file.

In additon to these settings i also included a "value/relevance function". Meaning the slider doesn't show your latest 5 articles, but instead weights them based on age and comments.

As older an article is the less likely it will show up in the slider.
More comments make it more likely.

This behaviour can be easily changed. I didn't include an if condition cause every board has different needs and i don't know whats best for you.
In addition conditions like "articles just from this section - or these sections, or this category, with a minimum of 10 posts" can be included via one single if condition. Again, i don't know what your board needs or what your category names are.

You can also modify the preview length (more words, less words), the preview style (color fontsize, fontweight .... Again different forums different needs. It's highly customizable.
Support:

Support and requests for the slider itself should be asked here http://nivo.dev7studios.com/
Same goes for different slider themes - a lot is possible, even thumbnails - again this is part of the nivo slider and not the vb4 implementation.

If you have any questions regarding the settings - or want different settings (which have to do with vb4) - ask, and i'll try to come up with some code // show you where you have to put what.


Slider not working. No idea why?

You will find a FAQ in the first comment, which will be kept up to date:
FAQ


The widget here is completely free. No charge, no branding.
But, we do not mind donations either. If you want to give us something. Since we are advertising free and fan based we are happy about every small donation.
( On Forumhome bottom right paypal button: http://www.united-forum.de/forum.php )



That's all
Hope it works for you.
Regards Mooff

Download Now

File Type: zip uf_nivo_slider.zip (65.6 KB, 1507 views)

Screenshots

File Type: jpg install.jpg (90.8 KB, 0 views)
File Type: jpg uf_nivo_slider_promo.jpg (119.2 KB, 0 views)

Supporters / CoAuthors

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.
13 благодарности(ей) от:
AaronMiller, Aramist, doctorsexy, Gemma, LOGECT, mitch84, nacaruncr, owning_y0u, RaSa, Sage Knight, The Rocketeer, YkudzA

Comments
  #262  
Old 09-20-2011, 12:10 AM
owning_y0u owning_y0u is offline
 
Join Date: Dec 2008
Location: Netherlands
Posts: 159
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

installed, Thanx Pretty awsome addition way better then a previous mod i was using :-)
+like
Reply With Quote
Благодарность от:
Mooff
  #263  
Old 09-20-2011, 01:53 AM
GamersChallenge GamersChallenge is offline
 
Join Date: Aug 2011
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Mooff View Post
@GamersChallenge
In order to use the widget code on a test.php this test.php would have to have access to your vbulletin database. If you have the required files included on your test.php page just add (untested)
Code:
echo "$output";
at the end of the widget code and insert it into the test.php file. It should show up then.

@pmflav1
That FAQ question should help you out:
I dont understand,

this is test.php file.
PHP Code:
<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT''test');
define('CSRF_PROTECTION'true);  
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('test',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

$navbits construct_navbits(array('' => 'Terms of Service'));
$navbar render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle 'Terms of Service';



// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######

$templater vB_Template::create('test');
$templater->register_page_templates();
$templater->register('navbar'$navbar);
$templater->register('pagetitle'$pagetitle);
print_output($templater->render());

?>

this is test template:

PHP Code:
{vb:stylevar htmldoctype}
<
html xmlns="http://www.w3.org/1999/xhtml" dir="{vb:stylevar textdirection}" lang="{vb:stylevar languagecode}" id="vbulletin_html">
  <
head>
    <
title>{vb:raw vboptions.bbtitle} - {vb:raw pagetitle}</title>
    {
vb:raw headinclude}
    {
vb:raw headinclude_bottom}
  </
head>
  <
body>
    
    {
vb:raw header}
    
    {
vb:raw navbar}
    

    {
vb:raw footer}
  </
body>
</
html
whats next?
Reply With Quote
  #264  
Old 09-20-2011, 10:52 AM
Mooff Mooff is offline
 
Join Date: Mar 2010
Posts: 301
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Bottom of the article you just quoted:
https://vborg.vbsupport.ru/showthread.php?t=228112

Please see this article for help with rendering templates - [vB4] Rendering templates and registering variables - a short guide

In a nutshell:
a) insert the php code from the first post here
Code:
// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle = 'My Page Title';
b) register the variable $output
c) update your template so it does print the variable $output
Reply With Quote
  #265  
Old 09-20-2011, 04:07 PM
Scalemotorcars's Avatar
Scalemotorcars Scalemotorcars is offline
 
Join Date: Mar 2006
Location: NC
Posts: 619
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Moff, have you or do you know how to make this work without fopen. I'm not sure how to code it for curl.

My host doesn't like fopen so I'm looking for an alternative. Thanks.
Reply With Quote
  #266  
Old 09-21-2011, 12:12 AM
GamersChallenge GamersChallenge is offline
 
Join Date: Aug 2011
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

after spending hours reading all those tutorials I came up with this... what am I doing wrong?

PHP Code:
<?php

// ####################### SET PHP ENVIRONMENT ###########################
error_reporting(E_ALL & ~E_NOTICE);

// #################### DEFINE IMPORTANT CONSTANTS #######################

define('THIS_SCRIPT''test');
define('CSRF_PROTECTION'true);  
// change this depending on your filename

// ################### PRE-CACHE TEMPLATES AND DATA ######################
// get special phrase groups
$phrasegroups = array();

// get special data templates from the datastore
$specialtemplates = array();

// pre-cache templates used by all actions
$globaltemplates = array('test',
);

// pre-cache templates used by specific actions
$actiontemplates = array();

// ######################### REQUIRE BACK-END ############################
// if your page is outside of your normal vb forums directory, you should change directories by uncommenting the next line
// chdir ('/path/to/your/forums');
require_once('./global.php');

// #######################################################################
// ######################## START MAIN SCRIPT ############################
// #######################################################################

$navbits construct_navbits(array('' => 'Terms of Service'));
$navbar render_navbar_template($navbits);

// ###### YOUR CUSTOM CODE GOES HERE #####
$pagetitle 'test';

// DEBUG MODUS !
$debug_modus false;

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 620;                                  
$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 7;                                
            
//lengh in characters of the article descriptions
$description_length 95;


//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 
"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) .' AND
        node.parentnode IN ( 163, 158 )
        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)
            {
            
                
//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.
                            
$article['previewimage'] = $fallback_img;
                            echo 
'<span style="color:red">Error occurred:</span> imagecreation failed. ' $article['previewimage']. '<br />';
                        }
                        else
                        {
                            
$img_width $imageinfo[0];
                            
$img_height $imageinfo[1];
                            
                            
imagecopyresampled($sprite$image0000$maxwidth$maxheight$img_width$img_height );
                            
imagedestroy($image);

                            
$img_filepath $slider_img_filepath 'slide_' $i '.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.
                        
$article['previewimage'] = $fallback_img;
                        echo 
'<span style="color:red">Error occurred:</span> picture is not readable.' $article['previewimage']. '<br /> ';
                    }                  
                }
                else
                {
                    
//resiziing did not work - we are using the fallback image.
                    
$article['previewimage'] = $fallback_img;
                    echo 
'<span style="color:red">Warning:</span> article has no previewimage or sprite is no ressource. ' $article['previewimage']. '<br />';
                }
        

                
/*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' $i ;
                
$article_neu['picture'] = '<a href="/content.php?r=' $article['nodeid'] . '-' $article['url'] . '"><img src="'.$article['previewimage'].'" alt="" title="#htmlcaption'$i '" /></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();        
}

echo 
"$output";



// ###### NOW YOUR TEMPLATE IS BEING RENDERED ######

$templater vB_Template::create('test');
$templater->register_page_templates();
$templater->register('navbar'$navbar);
$templater->register('output'$output);
$templater->register('pagetitle'$pagetitle);
print_output($templater->render());

?>
Reply With Quote
  #267  
Old 09-21-2011, 09:39 AM
Mooff Mooff is offline
 
Join Date: Mar 2010
Posts: 301
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

@Scalemotorcars
I haven't looked into it.
The options are:
- using fitting images as article images, which do not need to be resized (delete the resizing part then)
- resizing the images via CSS (might break the nivo slider transition effects, not sure about that one) - this also would mean deleting the resizing code
- cURL, which does involve reading through the cURL documentation or googleing for "replace fOpen via cURL"

@GamersChallenge
you can remove echo "$output"; since you are using the template system.
Then in the template you need to write {vb:raw output} somewhere, and that should be it.
Reply With Quote
  #268  
Old 09-22-2011, 01:19 AM
GamersChallenge GamersChallenge is offline
 
Join Date: Aug 2011
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Mooff View Post
@Scalemotorcars
I haven't looked into it.
The options are:
- using fitting images as article images, which do not need to be resized (delete the resizing part then)
- resizing the images via CSS (might break the nivo slider transition effects, not sure about that one) - this also would mean deleting the resizing code
- cURL, which does involve reading through the cURL documentation or googleing for "replace fOpen via cURL"

@GamersChallenge
you can remove echo "$output"; since you are using the template system.
Then in the template you need to write {vb:raw output} somewhere, and that should be it.
I think I'm almost there. Getting this error now.

Fatal error: Class 'vb_Types' not found in /home/gamersch/public_html/test.php on line 91

this is line 91:
PHP Code:
$article_type vb_Types::instance()->getContentTypeID("vBCms_Article"); 
Reply With Quote
  #269  
Old 09-22-2011, 07:11 AM
Mooff Mooff is offline
 
Join Date: Mar 2010
Posts: 301
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Sorry for the question, but i kinda just have to ask: Do you have the vbcms?

Anyway, if you do i'm not exactly sure in which globalclass vb_Types is definded, just look into your database, i think the table is "contenttypes" and check which contenttypeid your articles have.
On our installation it would be
$article_type = 18;
could be different on yours though.
Reply With Quote
  #270  
Old 09-22-2011, 09:22 AM
GamersChallenge GamersChallenge is offline
 
Join Date: Aug 2011
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by Mooff View Post
Sorry for the question, but i kinda just have to ask: Do you have the vbcms?

Anyway, if you do i'm not exactly sure in which globalclass vb_Types is definded, just look into your database, i think the table is "contenttypes" and check which contenttypeid your articles have.
On our installation it would be
$article_type = 18;
could be different on yours though.
yes I have. I also have the slider working on my home page as a widget with the same code, I'll try yo look into what you said. thanx
Reply With Quote
  #271  
Old 09-23-2011, 01:56 AM
Scalemotorcars's Avatar
Scalemotorcars Scalemotorcars is offline
 
Join Date: Mar 2006
Location: NC
Posts: 619
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks anyway Mooff, I ended up just going with the Content slider. The load times were dragging the homepage down horribly and my host was having an issue with Fopen.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:53 AM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2024, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.06137 seconds
  • Memory Usage 2,564KB
  • Queries Executed 29 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (5)bbcode_code
  • (4)bbcode_php
  • (4)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (4)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (2)pagenav_pagelinkrel
  • (11)post_thanks_box
  • (13)post_thanks_box_bit
  • (11)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (2)post_thanks_postbit
  • (11)post_thanks_postbit_info
  • (10)postbit
  • (3)postbit_attachment
  • (11)postbit_onlinestatus
  • (11)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • fetch_musername
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • post_thanks_function_fetch_thanks_bit_start
  • post_thanks_function_show_thanks_date_start
  • post_thanks_function_show_thanks_date_end
  • post_thanks_function_fetch_thanks_bit_end
  • post_thanks_function_fetch_post_thanks_template_start
  • post_thanks_function_fetch_post_thanks_template_end
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_attachment
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete