vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   define statements in php (https://vborg.vbsupport.ru/showthread.php?t=92493)

Acedeal 07-19-2005 01:24 PM

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!

Acedeal 07-21-2005 09:39 AM

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

Marco van Herwaarden 07-21-2005 07:03 PM

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.

Acedeal 07-21-2005 11:19 PM

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( "

Marco van Herwaarden 07-22-2005 05:08 AM

./includes/db_mysql.php

But no need to change anything to those.

Acedeal 07-22-2005 05:40 AM

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

Marco van Herwaarden 07-22-2005 05:45 AM

On the example above the variables you would be using if parsing a template inside the while loop, would look like '$row[column]'

Marco van Herwaarden 07-22-2005 05:48 AM

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.

Acedeal 07-22-2005 06:24 AM

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..


All times are GMT. The time now is 05:54 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.01271 seconds
  • Memory Usage 1,793KB
  • 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
  • (2)bbcode_code_printable
  • (9)bbcode_php_printable
  • (1)bbcode_quote_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (9)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