The Arcive of Official vBulletin Modifications Site.It is not a VB3 engine, just a parsed copy! |
|
Upcoming Events Details »» | |||||||||||||||||||||||||||
Upcoming Events
Released 28/12/2009 By Vikas - http://www.ngcoders.com Installation
PHP Code PHP Code:
Screenshots
Show Your Support
|
2 благодарности(ей) от: | ||
level8, Toorak Times |
Comments |
#152
|
|||
|
|||
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(); |
#153
|
|||
|
|||
@ngcoders
OMG I love you, this is exactly what I needed. |
#154
|
|||
|
|||
working in 4.0.6
|
#155
|
|||
|
|||
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 |
#156
|
||||
|
||||
Be good to have it in the Forum blocks as well
|
#157
|
|||
|
|||
same code just add at the end
return $output; |
#158
|
|||
|
|||
I still get Fatal error: Class 'vB' not found in /home/public_html/includes/block/html.php(95) : eval()'d code on line 9
|
#159
|
|||
|
|||
what's your code?
|
#160
|
|||
|
|||
PHP Code:
|
#161
|
|||
|
|||
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.
|
|
|
X vBulletin 3.8.12 by vBS Debug Information | |
---|---|
|
|
More Information | |
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|