Go Back   vb.org Archive > vBulletin 3 Discussion > vB3 General Discussions
  #1  
Old 07-19-2005, 01:24 PM
Acedeal Acedeal is offline
 
Join Date: Jul 2005
Location: Texas
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default define statements in php

Hey all,

Does vb reconise this type of statement in php files
if not what would be the correct way to address this?

somefile.php
PHP Code:
define('ARTISTS_TABLE'$vbmod_prefix.'artists');
define('SONGS_TABLE'$vbmod_prefix.'songs');
etc
etc 
so if i had this db query
PHP Code:
// select the featured songs
//

$sql 'SELECT ' SONGS_TABLE '.song_id, song_title, ' ARTISTS_TABLE '.artist_id, artist_name, artist_prefix
 FROM     ' 
SONGS_TABLE ', ' ARTISTS_TABLE .
WHERE (' 
SONGS_TABLE '.artist_id = ' ARTISTS_TABLE '.artist_id ) AND
        ( status_id = "' 
$mod_config['feature_status'] . '" )';
$sql append_status_sql($sql);
$sql .= 'ORDER BY song_id DESC';
$result $db->sql_query($sql);
while (
$row $db->sql_fetchrow($result))
{
    
$sql 'SELECT song_desc 
        FROM ' 
SONG_DESC_TABLE 
        WHERE (song_id = "' 
$row['song_id'] . '") 
        LIMIT 1'
;
    
$desc_result $db->sql_query($sql);
    
$song_desc $db->sql_fetchfield('song_desc''0'$desc_result);
    
$template->assign_block_vars('featured_songs', Array(
        
'SONG_DESC' => prepare_text($song_desc),
        
'SONG_TITLE' => $row['song_title'],
        
'ARTIST_NAME' => artist_add_prefix($row['artist_name'], $row['artist_prefix']),
        
'U_VIEWSONG' => append_sid('view_song.php?id=' $row['song_id']),
        
'U_VIEWARTIST' => append_sid('view_artist.php?id=' $row['artist_id']),
        )
    );
}
snip]] 
Reason for asking, switched over from phpbb and not sure I have a grasp of vb's sql and template engines-
as mention just switched over from phpbb and need to convert some apps and their template engine is a lot differnt

In the php file I had something like this
PHP Code:
$template->assign_block_vars('list',Array(
           
'SONG_LENGTH' => format_length($sql_data['song_length']),
       
'SONG_QUALITY' => $sql_data['song_quality'],
       
'SONG_SIZE' => $sql_data['song_size'],
           
'SONG_BOX' => $song_box,
       
'ADDED_BY' => cut_string($sql_data['username'], 21)
        )
    ); 
so I could just place {SONG_SIZE} {SONG_BOX}in template and it will pull the correct data from the php / sql pages and place in either a cell/or table in the template. {SONG_SIZE} would put the size of song and {SONG_BOX) would build some cells / tables from another template

How would I convert these template to use VB's template engine/variables

Thanks in advance!
Reply With Quote
  #2  
Old 07-21-2005, 09:39 AM
Acedeal Acedeal is offline
 
Join Date: Jul 2005
Location: Texas
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The master coders here don't know this one?

So there's no way to get my old templates to reconize the data that's being pulled?
eg
Code:
<table width="100%" cellspacing="2" cellpadding="2" border="0" align="center">
	<tr>
<td align="left"><span class="nav"><a class="nav"<a href="list.php" 
class="nav">Song Index</a></span></td>
	</tr>
</table>
<table width="100%" cellspacing="1" cellpadding="3" border="0">
  <tr> 
	<td valign="top"> 
	  <table class="forumline" width="100%" cellspacing="1" cellpadding="3" border="0">
		<tr> 
		  <th class="thHead">Welcome to </span></td>
		</tr>
	  </table>
	  <br />
	  {PLAYER_FEATURES}
	</td>
	<td valign="top"> 
	{PLAYER_STATS}
	</td>
  </tr>
</table>
$footer
I need to replace variables in my templates {PLAYER_FEATURES} so that VB will use them-
Where and how's it done?
Is it set via the actaul php script or via the CP Var Replacement thing?
Should {PLAYER_FEATURES} be changed to $PLAYER_FEATURES

Using the above as an example-
index template
inside of a template it pulls a variable called {PLAYER_STATS}
player stats is another template that contains html code and which get's it's data via sql
So instead of having to place all the html codes etc inside of the index template I can just pull data and dynamicly create the index tables, cells etc on the fly

Thanks
Reply With Quote
  #3  
Old 07-21-2005, 07:03 PM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In you php you first assign the contents of 1 or sub templates to a variable, then use that variable in your main template. And yes it would be a normal php variable, so the name would be $PLAYER_FEATURES or similar.
Reply With Quote
  #4  
Old 07-21-2005, 11:19 PM
Acedeal Acedeal is offline
 
Join Date: Jul 2005
Location: Texas
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks MarcoH,

Where are these defined- was poking around the files and can not seem to find them again

$DB_site->query("
$DB_site->query_first( "
Reply With Quote
  #5  
Old 07-22-2005, 05:08 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

./includes/db_mysql.php

But no need to change anything to those.
Reply With Quote
  #6  
Old 07-22-2005, 05:40 AM
Acedeal Acedeal is offline
 
Join Date: Jul 2005
Location: Texas
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by MarcoH64
./includes/db_mysql.php

But no need to change anything to those.
Thanks..
Was not going to re-write anything in there-
Just need to figure out how to redo all my scripts that I have to match all this VB stuff.

Probally easier for me to just hire someone to do it, I don;t have the time, nor the inclination at the moment to redo all my php mods that I want to port over.
https://vborg.vbsupport.ru/showthread.php?t=92550

looks like everything in regards to this type of coding is going to have to be redone
PHP Code:
$sql 'SELECT ' SONGS_TABLE '.song_id, song_title, ' ARTISTS_TABLE '.artist_id, artist_name, artist_prefix
 FROM     ' 
SONGS_TABLE ', ' ARTISTS_TABLE .
WHERE (' 
SONGS_TABLE '.artist_id = ' ARTISTS_TABLE '.artist_id ) AND
        ( status_id = "' 
$mod_config['feature_status'] . '" )';
$sql append_status_sql($sql);
$sql .= 'ORDER BY song_id DESC';
$result $db->sql_query($sql);
while (
$row $db->sql_fetchrow($result)) 
due to it's kicking out variables that your template engine can not use / parse--

what would be this best way to redo this so that I can get them in the templates
PHP Code:
$template->assign_block_vars('list',Array(
           
'SONG_LENGTH' => format_length($sql_data['song_length']),
       
'SONG_QUALITY' => $sql_data['song_quality'],
       
'SONG_SIZE' => $sql_data['song_size'],
           
'SONG_BOX' => $song_box,
       
'ADDED_BY' => cut_string($sql_data['username'], 21)
        )
    ); 
just change it to
PHP Code:
vars('list',( Array( 
    
$SONG_LENGTH => 'format_length($sql_data['song_length']),
     $ADDED_BY => '
cut_string($sql_data['username'], 21
the function to get the lenght
PHP Code:
function format_length($length)
{
    
$length_hour floor($length 3600);
    
$length_min floor(($length - ($length_hour 3600)) / 60);
    
$length_sec $length - (($length_min 60) + ($length_hour 3600)) ;
    if (
$length_hour 0)
    {
        
$f_length $length_hour ':';
    }
    if (
$length_min 10 && $length_hour 0)
    {
        
$f_length .= '0';
    }
    
$f_length .= $length_min ':';
    if (
$length_sec 10)
    {
        
$f_length .= '0';
    }
    
$f_length .= $length_sec;
    
    return(
$f_length);

}
function 
cut_string($string$length)
{
    if (
strlen($string) > $length)
    {
        
$string substr($string0$length 2) . '...';
    }
    return(
$string);

then in template I would just put in
Code:
<td>$SONG_LENGTH</td>
td>$ADDED_BY</td>
Hope I don't have to re-write all this, prolly why it's easier to just hire someone lolol
Reply With Quote
  #7  
Old 07-22-2005, 05:45 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

On the example above the variables you would be using if parsing a template inside the while loop, would look like '$row[column]'
Reply With Quote
  #8  
Old 07-22-2005, 05:48 AM
Marco van Herwaarden Marco van Herwaarden is offline
 
Join Date: Jul 2004
Posts: 25,415
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

And the line:
PHP Code:
$result $db->sql_query($sql); 
would become something like:
PHP Code:
$result $DB_site->query($sql); 
Same goes for the sql_fetchrow line.
Have a look at how other (standard vB) scripts are handling retrieving data.
Reply With Quote
  #9  
Old 07-22-2005, 06:24 AM
Acedeal Acedeal is offline
 
Join Date: Jul 2005
Location: Texas
Posts: 24
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks Once again-

Maybe better if I just just hire someone to redo it. (take me 6 weeks just to figure out your permission systems much less the template engine)
Once they get it done, I'll have a better grasp on VB / and the template parse due to I know how the mod works and what it does etc..
Reply With Quote
Reply

Thread Tools
Display Modes

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 05:59 PM.


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.05382 seconds
  • Memory Usage 2,293KB
  • 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
  • (2)bbcode_code
  • (9)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (9)post_thanks_box
  • (9)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (9)post_thanks_postbit_info
  • (9)postbit
  • (9)postbit_onlinestatus
  • (9)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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete