vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=15)
-   -   adding conditionals in an array (https://vborg.vbsupport.ru/showthread.php?t=112482)

sabret00the 04-08-2006 06:37 PM

adding conditionals in an array
 
is it possible at all, i'm trying to do something like this

PHP Code:

                $this->entrybit str_replace(
                    array(
                        
'{QUICKENTRYLINK}',
                        
'{TITLE}',
                        
'{DATE}',
                        
'{TIME}',
                        (
$entry['security'] != "noone") ? "'{LOCKEDICON}'," "")
                        
'{USERICON}',
                        
'{ENTRYTEXT}',
                        
'{MOOD}',
                        
'{MUSIC}',
                        
'{TAGS}',
                        
'{COMMENT}',
                        
'{READ}',
                        
'{LINK}',
                        
'{REMEMBER}',
                        
'{TOP}'
                    
),
                    array(
                        
$entry['journalid'] . '_' $entry['entryid'],
                        
$entry['title'],
                        
vbdate($this->vbulletin->options['dateformat'], $entry['entry_date']),
                        
vbdate($this->vbulletin->options['timeformat'], $entry['entry_date']),
                        (
$entry['security'] != "noone") ? "'<img src=\"' . $this->stylevar['imgdir_misc'] . '/moderated.gif\" alt=\"' . ucwords(strtolower($entry['security'])) . '\" />'," "")
                        
$entry['usericon'],
                        
$entry['pagetext'],
                        
'<b>Mood:</b> ' ucwords(strtolower($entry['mood'])) . ' <img src="' .  buildmoodimage($entry['mood'], $entry['location']) . '" />',
                        
'<b>Music:</b> ' ucwords(strtolower($entry['music'])),
                        
'<b>Tags:</b> ' buildtaglinks($entry['tags'], $this->userdetails['username']),
                        
'Reply',
                        
$entry['commentcount'] . ' Comments',
                        
'Perma-Link',
                        
'Memorise',
                        
'<a href="#top">Top</a>'
                    
),
                    
$this->entrybit
                
); 

note: this one don't work.

Code Monkey 04-08-2006 11:46 PM

Create variables with the values where you have conditionals, then just put the variables in the arrays.

Then put the array variables in the string replace.

Also, those conditionals where the else = "" are not necessary. Just put the values in. If it's not there, there is nothing to replace and it will move on.

So for example.
PHP Code:

($entry['security'] != "noone") ? "'{LOCKEDICON}'," ""

Should just be
PHP Code:

"'{LOCKEDICON}'," 


sabret00the 04-10-2006 10:19 AM

thanks for the help, i ended up with this

PHP Code:

                $this->entrybit str_replace(
                    array(
                        
'{QUICKENTRYLINK}',
                        
'{TITLE}',
                        
'{DATE}',
                        
'{TIME}',
                        
'{LOCKEDICON}',
                        
'{USERICON}',
                        
'{USERNAME}',
                        
'{ENTRYTEXT}',
                        
'{MOOD}',
                        
'{MUSIC}',
                        
'{TAGS}',
                        
'{COMMENT}',
                        
'{READ}',
                        
'{LINK}',
                        
'{REMEMBER}',
                        
'{TOP}'
                    
),
                    array(
                        
$entry['journalid'] . '_' $entry['entryid'],
                        
$entry['title'],
                        
vbdate($this->vbulletin->options['dateformat'], $entry['entry_date']),
                        
vbdate($this->vbulletin->options['timeformat'], $entry['entry_date']),
                        (
$entry['security'] != 'everyone') ? '<img src="' $this->stylevar['imgdir_misc'] . '/moderated.gif" alt="' ucwords(strtolower($entry['security'])) . '" />' '',
                        
$entry['usericon'],
                        
$this->userdetails['username'],
                        
$entry['pagetext'],
                        (
$entry['mood']) ? '<b>Mood:</b> ' ucwords(strtolower($entry['mood'])) . ' <img src="' .  buildmoodimage($entry['mood'], $entry['location']) . '" />' '',
                        (
$entry['music']) ? '<b>Music:</b> ' ucwords(strtolower($entry['music'])) .'' '',
                        (
$entry['tags']) ? '<b>Tags:</b> ' buildtaglinks($entry['tags'], $this->userdetails['username']) .'' '',
                        
'Reply',
                        
'<a href="entry.php?e=' $entry['entryid'] . '">' $entry['commentcount'] . ' Comments</a>',
                        
'<a href="entry.php?e=' $entry['entryid'] . '">Perma-Link</a>',
                        
'Memorise',
                        
'<a href="#top">Top</a>'
                    
),
                    
$this->entrybit
                
); 



All times are GMT. The time now is 10:16 AM.

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.01017 seconds
  • Memory Usage 1,775KB
  • 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
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (3)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
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete