vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vBulletin 4.x Add-ons (https://vborg.vbsupport.ru/forumdisplay.php?f=245)
-   -   vBulletin CMS Widgets - Upcoming Events (https://vborg.vbsupport.ru/showthread.php?t=231365)

Testing123 07-26-2010 05:48 AM

Maybe we could kill two birds with one stone (so to speak). Looking at the code line by line, people knowledgeable in php and vB could explain what's going on with that code line. Maybe we could learn a few things and end up with a needed widget. :-)
I'll start, using Stadler's code (I hope you don't mind, Stader).

Please jump in with any/all info and/or insight you can offer and don't hesitate correct any errors with my comments/logic. Thanks!
In php, we use // to make a single-line comment or /* and */ to make a large comment block.
I'll use /*...*/ for my comments as there is a line in the code that uses // and I'm not sure why it's there.
Comments will be placed before (above) the line(s) of code they reference.

-+-+-+-+-+-+-+-+
UPDATE – July 31, 2010
I've edited a few areas in my comments as I've gained a bit more insight into php and the code.
Hope this helps someone. And I really hope others will join in!
-+-+-+-+-+-+-+-+

OK, here we go:

/* Since there is a parentheses after ob_start, this is obviously a function call. */
/* I guess vB needs this to indicate the start of a php widget */

ob_start();


/* What is this used for? // is used to denote a single line comment */
/* (i.e. not processed as part of the program by php interpreter). */
/* It's not indicating anything I can see in the code. */
/* Why is it included? */

// %d

/* Obviously $show_count is a variable, set to a value of 5 as seen */
/* in the set up of the database query line that follows this one. */

$show_count = 5;


/* This sets up a MySQL database query with the results placed in the $query variable. */
/* sprintf is used to write a formatted string to a variable (in this case, $query). */
/* Variables, values, strings, etc. are integrated into the string using */
/* conversion specifications which are passed in as arguments to the */
/* sprintf function. E.g. you can pass in a value and require that value to be an integer. */
/* Apparently, sprintf is commonly used in SQL calls to 'sanitize' the string. */

/* The argument parameters will be inserted at the percent (%) signs in the main string. */
/* In the following line, 2 percent formatters and 2 arguments are used. */
/* The arguments are the variables/strings/etc. that are placed at the end of the line, */
/* separated by commas. */
/* TIMENOW and $show_count are the 2 arguments in the following line. */

/ * %1\$d */
/* This is replaced by the TIMENOW variable and formatted as a signed decimal number. */
/* %1 says to use the first argument and $d says to make it a signed decimal number. */
/* A backslash (\) is used to separate the argument identifier from the format identifier. */

/* %2\$d */
/* This is replaced by the $show_count variable and formatted as a signed decimal number. */
/* %2 says to use the second argument. */

/* || means 'or' in php speak */
/* AND means 'and' in php speak */

/* I still don't (as yet) fully understand the date formatting. */

$query = sprintf("SELECT * FROM ".TABLE_PREFIX."event WHERE visible = 1 AND (dateline_from > '%1\$d' || ( dateline_from > '%1\$d' AND dateline_to < '%1\$d' ) || (dateline_to = 0 AND DATE(FROM_UNIXTIME(dateline_from)) = DATE(FROM_UNIXTIME(%1\$d)))) ORDER BY dateline_from ASC LIMIT %2\$d",TIMENOW,$show_count);


/* This fetches the info from the database using the string built */
/* and stored in the $query variable. */
/* The results are stored in the $event_get array variable. */
/* Not sure why it's formatted the way it is. */

$event_get = vB::$db->query_read($query);


/*This sets the variable $output_bits to double quote character. Why is this needed? */

$output_bits = '';


/* While loop. */
/* $event (which is an array, right?) is the variable used */
/* to store the info retrieved in $event_get. */
/* While will loop until the function returns no more data */
/* (function returns 0 or false). */

while($event = vB::$db->fetch_array($event_get)) {


/*if/else conditional. */
/* Again, date formatting. Expanation here is again needed. :-) */

if($event['dateline_to'] == 0 )
{
$format = sprintf("On %s",date('jS M Y',$event['dateline_from']));
} else {
$format = sprintf("From %s to %s",date('jS M Y',$event['dateline_from']),date('jS M Y',$event['dateline_to']));
}


/* sprintf is used again, this time to build a formatted output string. */
/* However, since this is within the loop, doesn't the $output_bits variable */
/* get rewritten each time through the loop? */

/* Wait a sec... the first part of this line is: */
/* $output_bits .= sprintf(' */
/* I notice a dot (.) just before the equals (=) sign. Does this concatenate (add to) */
/* the string with each iteration (instead of rewriting the contents of the variable each time)? */

$output_bits .= sprintf('
<div class = "cms_widget_post_bit"><h4 class="cms_widget_post_header"><a href="calendar.php5?do=getinfo&e=%d">%s</a></h4>
<p class="cms_widget_post_content"> %s</p>
</div>
',$event['eventid'],$event['title'],$format);
}


/* Why is $output equated to $output_bits? */
/* I guess vB internal code uses $output to print out (display) data in the widget, */
/* so a string must be built and then copied to this variable... right? */

$output = $output_bits;


/*This is obviously needed by vB to close the widget and clean up. */
/* ( Companion to ob_start() ). */

ob_end_clean();

Recronin 07-31-2010 03:28 AM

@ngcoders
OMG I love you, this is exactly what I needed.

sulasno 08-19-2010 01:45 AM

working in 4.0.6

FatalCure 08-20-2010 05:26 PM

Can someone convert this code to a forum block? If I try using the existing code in a forum block I get the following error.

Fatal error: Class 'vB' not found in /home/public_html/includes/block/html.php(95) : eval()'d code on line 9

ProFifaLeagues 08-20-2010 05:44 PM

Be good to have it in the Forum blocks as well :)

ragtek 08-20-2010 06:48 PM

same code just add at the end
return $output;

FatalCure 08-21-2010 08:54 PM

Quote:

Originally Posted by ragtek (Post 2086993)
same code just add at the end
return $output;

I still get Fatal error: Class 'vB' not found in /home/public_html/includes/block/html.php(95) : eval()'d code on line 9

ragtek 08-21-2010 08:57 PM

what's your code?

FatalCure 08-22-2010 12:40 AM

Quote:

Originally Posted by ragtek (Post 2087525)
what's your code?

PHP Code:

ob_start();


//  %d
$show_count 5;

$query sprintf("SELECT * FROM ".TABLE_PREFIX."event WHERE visible = 1 AND (dateline_from > '%d' || (  dateline_from > '%d' AND dateline_to < '%d' )) ORDER BY dateline_from ASC LIMIT %d",TIMENOW,TIMENOW,TIMENOW,$show_count);

$event_get vB::$db->query_read($query);

$output_bits '';
while(
$event vB::$db->fetch_array($event_get)) {

     if(
$event['dateline_to'] == )
     {
         
$format sprintf("On %s",date('jS M Y',$event['dateline_from']));
     } else {
         
$format sprintf("From %s to %s",date('jS M Y',$event['dateline_from']),date('jS M Y',$event['dateline_to']));
     }
     
     
$output_bits .= sprintf('
        <div class = "cms_widget_post_bit"><h4 class="cms_widget_post_header"><a href="calendar.php?do=getinfo&e=%d">%s</a></h4>
            <p class="cms_widget_post_content">%s</p>
        </div>
        '
,$event['eventid'],$event['title'],$format);

}
$output $output_bits;


ob_end_clean();
return 
$output

in a forum block as php.

FatalCure 08-23-2010 03:41 AM

Also single day events do not show if the event is that day, it would be good if it showed the entire day the event was on.


All times are GMT. The time now is 09:12 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01430 seconds
  • Memory Usage 1,769KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php_printable
  • (2)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (4)pagenav_pagelink
  • (2)pagenav_pagelinkrel
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (10)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • pagenav_page
  • pagenav_complete
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete