Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 Programming Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 04-20-2008, 07:47 PM
WarriorDL's Avatar
WarriorDL WarriorDL is offline
 
Join Date: May 2003
Posts: 29
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Function info to a template?

I probably have this written incorrectly, but... how do I get this info, namely the $category name at the end, to be accessible via a template variable?

Like how $forumbits is pulled from a function into the forum templates.
PHP Code:
function get_categories($cat_id 0
{
    global 
$vbulletin$stylevar$vbphrase$show$atlas_config$site_template;
    global 
$cat_cache$cat_parent_cache$new_image_cache$subcat_ids;

    
$cattable_width ceil((intval($atlas_config['cat_table_width'])) / $atlas_config['cat_cells']);
    if ((
substr($atlas_config['cat_table_width'],-1)) == "%"
    {
        
$cattable_width .= "%";
    }

    if (!isset(
$cat_parent_cache[$cat_id])) 
    {
        return 
"";
    }

    
$visible_cat_cache = array();
    if (empty(
$visible_cat_cache)) 
    {
        return 
"";
    }

    
$total sizeof($visible_cat_cache);
    
$table_columns = (intval($atlas_config['cat_cells'])) ? intval($atlas_config['cat_cells']) : 2;
    if (
$total <= $table_columns
    {
        
$table_rows 1;
    }
    else 
    {
        
$table_rows $total $table_columns;
        if (
$total >= $table_columns AND !is_integer($table_rows)) 
        {
            
$table_rows intval($table_rows) + 1;
        }
    }

    
$categories '<table width="'.$atlas_config['cat_table_width'].'" border='0' cellpadding='0' cellspacing='0'><br /><tr><br /><td valign='top' width="'.$cattable_width.'" class='catbgcolor'><br />';
    
$categories .= '<table border='0' cellpadding="'.$atlas_config['cat_table_cellpadding'].'" cellspacing="'.$atlas_config['cat_table_cellspacing'].'"><br />';
    
$count 0;
    
$count2 0;
    foreach (
$visible_cat_cache AS $key => $category_id
    {
        
$categories .= '<tr><br /><td valign='top'><br />';

        
$is_new = (isset($new_image_cache[$category_id]) AND $new_image_cache[$category_id] > 0) ? 0;
        
$num_images = (isset($cat_cache[$category_id]['num_images'])) ? $cat_cache[$category_id]['num_images'] : 0;

        
$subcat_ids = array();
        
get_subcat_ids($category_id$category_id$cat_parent_cache);

        if (isset(
$subcat_ids[$category_id])) 
        {
            foreach (
$subcat_ids[$category_id] AS $val
            {
                if (isset(
$new_image_cache[$val]) AND $new_image_cache[$val] > 0
                {
                    
$is_new 1;
                }
                if (isset(
$cat_cache[$val]['num_images'])) 
                {
                    
$num_images += $cat_cache[$val]['num_images'];
                }
            }
        }

        if (
defined("SHOW_RANDOM_IMAGE") AND SHOW_RANDOM_IMAGE == OR defined("SHOW_RANDOM_CAT_IMAGE") AND SHOW_RANDOM_CAT_IMAGE == 0
        {
            
$random_cat_image_file "";
        }
        else 
        {
            
$random_cat_image_file get_random_image($category_id01);
        }
        
        
$this->registry = array (
        
'cat_id' => $category_id,
        
'cat_name' => format_text($cat_cache[$category_id]['cat_name'], 2),
        
'cat_description' => format_text($cat_cache[$category_id]['cat_description'], 1),
        
'cat_hits' => $cat_cache[$category_id]['cat_hits'],
        
'cat_is_new' => $is_new,
        
'lang_new' => $vbphrase['new'],
        
'sub_cats' => get_subcategories($category_id),
        
'cat_url' => $vbulletin->session->url(ATLAS_ROOT_PATH."categories.php?".URL_CAT_ID."=".$category_id),
        
'random_cat_image_file' => $random_cat_image_file,
        
'num_images' => $num_images);
        eval(
'$categories .= "' fetch_template('atlas_category_bits') . '";');
        
$count++;
        
$count2++;
        
$categories .= '</td><br /></tr><br />';

        if (
$count == $table_rows AND $count2 sizeof($visible_cat_cache)) 
        {
            
$categories .= '</table><br /></td><br />';
            
$categories .= '<td valign='top' width="'.$cattable_width.'" class='catbgcolor'><br />';
            
$categories .= '<table border='0' cellpadding="'.$atlas_config['cat_table_cellpadding'].'" cellspacing="'.$atlas_config['cat_table_cellspacing'].'"><br />';

            
$total $total $count2;
            
$table_columns $table_columns 1;
                
/*if ($total <= $table_columns AND $table_columns > 1) 
                {
                    $table_rows = 1;
                }
                else 
                {
                    $table_rows = $total / $table_columns;
                if ($total >= $table_columns AND !is_integer($table_rows)) {
                  $table_rows = intval($table_rows) + 1;
                    }
                }*/
            
$count 0;
        }
    }

    
$categories .= '</table><br /></td><br /></tr><br /></table><br />';
    return 
$categories;

Reply With Quote
  #2  
Old 04-20-2008, 08:16 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Probably won't aid your actual problem but I recommend you take a read of vBulletin Code Standards (specifically the bits related to code layout), it will make it easier for others to read/understand your code and also make it easier for you to spot your own problems.
Reply With Quote
  #3  
Old 04-20-2008, 10:16 PM
WarriorDL's Avatar
WarriorDL WarriorDL is offline
 
Join Date: May 2003
Posts: 29
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Edited the indent spacing (I think that's what you meant).
Reply With Quote
  #4  
Old 04-21-2008, 02:35 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Where is this code being executed/the function being called. You've just written a function at the moment, it won't do anything until you execute it. You could put it in a Plugin then do something like:

PHP Code:
$cats get_categories(); 
Then use [minicode]$cats[/minicode] in your template.
Reply With Quote
  #5  
Old 04-21-2008, 02:54 PM
WarriorDL's Avatar
WarriorDL WarriorDL is offline
 
Join Date: May 2003
Posts: 29
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok. I have it written in an external functions page that I named "atlas_functions.php" and call it through my external index page.

On my external index page, I do have this:

PHP Code:
$categories get_categories(0);
if (!
$categories)  
{
    
$categories $vbphrase['atlas_no_categories'];
}
unset(
$categories); 
And in the index template I created for my external page, I use $categories in the template.

--------------- Added [DATE]1208793301[/DATE] at [TIME]1208793301[/TIME] ---------------

What's weird is that the counters thing I posted about in another thread DOES work when called from the same functions page.
Reply With Quote
  #6  
Old 04-21-2008, 02:58 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Why have you got this line:
PHP Code:
unset($categories); 
?
Reply With Quote
  #7  
Old 04-21-2008, 03:08 PM
WarriorDL's Avatar
WarriorDL WarriorDL is offline
 
Join Date: May 2003
Posts: 29
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

It was in the original php. Removing it has made no difference.
Reply With Quote
  #8  
Old 04-21-2008, 03:11 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Look up what unset() does on php.net.

Hmm its might be a problem with the function itself, have you checked to see if it is even returning anything? (Run a [minicode]var_dump()[/minicode] on it to see if it contains anything).
Reply With Quote
  #9  
Old 04-21-2008, 03:33 PM
WarriorDL's Avatar
WarriorDL WarriorDL is offline
 
Join Date: May 2003
Posts: 29
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

...ok. Please humor me

Where do I put that var_dump()??

--------------- Added [DATE]1208796733[/DATE] at [TIME]1208796733[/TIME] ---------------

Ok. I did this (hope it was right)

PHP Code:
$categories get_categories(0);
var_dump($categories get_categories);
if (!
$categories)  
{
    
$categories $vbphrase['atlas_no_categories'];

Now when I reload the page, this is at the top of it:

string(14) "get_categories"

And in the area where the categories are to show up it says:

get_categories

...and without the "get_categories" in there, I get this at the top:

string(0) ""

And in the page area, nothing.

--------------- Added [DATE]1208802729[/DATE] at [TIME]1208802729[/TIME] ---------------

Ok. I'm gonna start this again from scratch. Gonna have to re-write all.

Thanks for the help though!
Reply With Quote
  #10  
Old 04-22-2008, 01:27 PM
Opserty Opserty is offline
 
Join Date: Apr 2007
Posts: 4,103
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I recommend you also refresh yourself on the basics of PHP also you can access documentation and examples of most functions by a quick browse on the PHP site by using: http://www.php.net/function_name where function_name is the the function your looking up. So for example var_dumo() would be http://php.net/var_dump e.t.c.
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 01:16 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.04128 seconds
  • Memory Usage 2,317KB
  • Queries Executed 13 (?)
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
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (5)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete