Thinking about making a 0.0.12 alpha

Want to share what MODs you've gotten to work with EM? Happy about all the time your're saving? Want to say "thanks"? Here's the place.
Forum rules
DO NOT give out any FTP passwords to anyone! There is no reason to do so! If you need help badly enough, create a temporary FTP account that is restricted to only the files that you need help with and give the information for that. Giving out FTP information can be very dangerous!
Locked
Nuttzy99
Registered User
Posts: 927
Joined: Fri Aug 03, 2001 7:09 am
Contact:

Thinking about making a 0.0.12 alpha

Post by Nuttzy99 »

PHP Safe Mode prevents several people from being able to install EM. A handful of the 500+ to download 0.0.11 can't install it. Not bad at all, but I want to be as perfect as possible ;). I really did not grasp what safe mode was all about, but after some research I've learned it doesn't need to be an absolute roadblock. I would like to code this up. I would also like to "dumb down" the first page of the installer to make it even easier to understand what the user needs to do. (yes, I know it is horribly easy anyway, but not for some folks I guess ;))

I'd like to have this in place before releasing the beta so that the problems with the beta will be mostly focused on SQL issues, not install issues.

-Nuttzy :cool:
SpellingCow.com - Free spell check service for your forums or any web form!
My Other Site

User avatar
A_Jelly_Doughnut
Registered User
Posts: 1780
Joined: Wed Jun 04, 2003 4:23 pm

Re: Thinking about making a 0.0.12 alpha

Post by A_Jelly_Doughnut »

Nuttzy99 wrote:I've learned it doesn't need to be an absolute roadblock.
Even I could have told you that :mrgreen:

I've read on *other* boards where *other* developers should figure that out too.

Thanks for the warning
A_Jelly_Doughnut

User avatar
GPHemsley
Registered User
Posts: 1617
Joined: Fri Apr 18, 2003 4:01 am
Location: Long Beach, NY
Contact:

Re: Thinking about making a 0.0.12 alpha

Post by GPHemsley »

So... want our opinions, or just thinking aloud? :lol:

Nuttzy99
Registered User
Posts: 927
Joined: Fri Aug 03, 2001 7:09 am
Contact:

Re: Thinking about making a 0.0.12 alpha

Post by Nuttzy99 »

Kinda both I guess ;) One thing I hate about the installer is all the HTML in there. So I just finished writing my own very crude template system. Works so far :P

-Nuttzy :cool:
SpellingCow.com - Free spell check service for your forums or any web form!
My Other Site

User avatar
Ptirhiik_
Registered User
Posts: 526
Joined: Tue Nov 18, 2003 8:35 am

Re: Thinking about making a 0.0.12 alpha

Post by Ptirhiik_ »

Lol, I was on the point to propose you a simplified version of the template class, when I arrived to the conclusion the one present in phpBB is just the one needed. The only thing to do is to provided it in the em package to be sure to have one working whatever the state of the board, and to create the phpbb_realpath function to avoid to use the phpbb one (or to delete it in the special version of template.php). Also I came to the conclusion that having a specific install dir for easymod would be a good thing to prevent multiple instllation, and also to force the deletion after installation. And I figured the best name would be /install/ , as phpBB test this dir and prevent to go further while present : this could be a very good thing, worst a look.

Nuttzy99
Registered User
Posts: 927
Joined: Fri Aug 03, 2001 7:09 am
Contact:

Re: Thinking about making a 0.0.12 alpha

Post by Nuttzy99 »

Here is a sample template. Anything within {{ and }} is a template variable...

Code: Select all

<h2>{{EM_Install_Info}}</h2>
	<form method="post" name="lang" action="{{U_FORM}}">
		<table width="100%">
			<tr>
				<td>{{EM_Select_Language}}</td>
				<td> :: </td>
				<td><select name="language">
{{LANG_OPTIONS}}
				    </select> <input type="submit" value="{{GO}}" class="liteoption" /><td>
			</tr>
			<tr>
				<td>{{EM_Database_type}}</td>
				<td> :: </td>
				<td><b>{{SQL_LAYER}}</b></td>
			</tr>
			<tr>
				<td>{{EM_phpBB_version}}</td>
				<td> :: </td>
				<td><b>{{PHPBB_VERSION}}</b></td>
			</tr>
			<tr>
				<td>{{EM_EasyMOD_version}}</td>
				<td> :: </td>
				<td><b>{{EM_VERSION}}</b></td>
			</tr>
			<tr>
				<td>{{L_EM_STATUS}}</td>
				<td> :: </td>
				<td><b>{{STATUS}}</td>
			</tr>
		</table>
	</form>
Here is the very simple code that makes it tick...

Code: Select all

// my own cheese-o-matic template system
function display_template( $template_file, $variables)
{
	$template = fopen( $template_file, 'r') ;
	while (!feof( $template))
	{
		$line = fgets( $template, 4096) ;

		$prev_endpos = 0 ;
		$pos = strpos( $line, '{{')+2 ;
		$endpos = strpos( $line, '}}', $pos)-1 ;

		// for some reason I couldn't get strpos to work correctly for me (even using === syntax)
		$start_var = (substr( $line, 0, 2) == '{{') ? true : false ;

		if (($pos > 2) || ($start_var))
		{
			while (($pos > 2) || ($start_var))
			{
				$start_var = false ;
				$var = substr($line, $pos, $endpos-$pos+1) ;
				echo substr( $line, $prev_endpos, (($pos-2)-$prev_endpos)) . $variables[$var] ;

				$prev_endpos = $endpos+3 ;
				$pos = strpos( $line, '{{', $prev_endpos)+2 ;
				$endpos = strpos( $line, '}}', $pos)-1 ;
			}

			echo substr( $line, $prev_endpos) ;
		}
		else
		{
			echo $line ;
		}
	}
	fclose( $template) ;
}
...it's only good for my limited needs, but it is already making a big difference in cleaning up the code! I plan to make subSilver not required so I really don't need or want to use the phpBB template class.

BTW, you'll notice that I have variables like "EM_Select_Language" instead of having a phpBB style "L_SELECT_LANG". I would prefer to have a phpBB style one, put it was just faster to use what was already in place when converting. My time is not infinite after all ;) Perhaps I'll have someone fix these for me after release.

As for multiple installations, EM already prevents this ;) Having it installed multiple times is not a problem anyway. The key is that you don't want someone else fooling around and installing it. So this feature serves to prevent others from messing with you once it is installed ;)

-Nuttzy 8)
SpellingCow.com - Free spell check service for your forums or any web form!
My Other Site

User avatar
Ptirhiik_
Registered User
Posts: 526
Joined: Tue Nov 18, 2003 8:35 am

Re: Thinking about making a 0.0.12 alpha

Post by Ptirhiik_ »

Here is what I did, which mimic the phpBB template class, but without the abilities to have repeating switches :

Code: Select all

<?php
/***************************************************************************
 *				ligth_template.php
 *				------------------
 *	begin		: 19/12/2003
 *	copyright	:
 *	email		:
 *
 *	version		: 1.0.0
 *
 *	This one will mimic the templating system of phpBB, but without the switches
 *
 ***************************************************************************/

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

class Light_Template {
	var $_tpl_key = array();
	var $_tpl_val = array();
	var $files = array();
	var $root = '.';

	// constructor
	function Light_Template( $dir = '.' )
	{
		if ( !is_dir($dir) )
		{
			die("Template->constructor: Error - dir $dir does not exist");
		}
		$this->root = $dir;
	}
	// destructor
	function destroy()
	{
		$this->_tpldata = array();
	}

	// store tpl names and handlers
	function set_filenames($filename_array)
	{
		if ( !is_array($filename_array) )
		{
			$filename_array = array($filename_array);
		}
		reset($filename_array);
		while(list($handle, $filename) = each($filename_array))
		{
			if ( $filename[0] != '/' )
			{
				$filename = $this->root . '/' . $filename;
			}
			if ( !file_exists($filename) )
			{
				die("Template->make_filename(): Error - file $filename does not exist");
			}
			$this->files[$handle] = $filename;
		}
		return true;
	}

	function assign_vars($vararray)
	{
		@reset( $vararray );
		while ( list($key, $val) = @each($vararray) )
		{
			$this->_tpl_key[] = '{' . $key . '}';
			$this->_tpl_val[] = $val;
		}
		return true;
	}

	function pparse($handle)
	{
		if ( !isset($this->files[$handle]) )
		{
			die("Template->pparse(): unknown handle $handle");
		}
		$str = implode( '', @file($this->files[$handle]) );
		if ( empty($str) )
		{
			die("Template->pparse(): File $filename for handle $handle is empty");
		}
		echo str_replace('{}', '', str_replace($this->_tpl_key, $this->_tpl_val, $str));
		return true;
	}
}

?>
I stoped there cause actually the template class is weel written for the basic need (and not link to subSilver btw ;)) : advantage : except this lack of switches, you can use the standard template for dev, and provide this one for install :).

Tip: for the strpos, I'm used now to add a blank space in first position ( pos = strpos( ' '. $where, $what) ). Doing so, I'm sure to not mix 0 and false :).

User avatar
Ptirhiik_
Registered User
Posts: 526
Joined: Tue Nov 18, 2003 8:35 am

Re: Thinking about making a 0.0.12 alpha

Post by Ptirhiik_ »

And a sample of use :

Code: Select all

<?php

define('IN_PHPBB', true);
$phpbb_root_path = './../';
$easymod_install = 'install/';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . $easymod_install . 'light_template.' . $phpEx);

$template = new Light_Template($phpbb_root_path . $easymod_install . 'templates/');

$template->set_filenames(array(
	'body' => 'test.tpl')
);

$template->assign_vars(array(
	'TEST1' => 'nuuut',
	'TEST2' => 'beeep',
	)
);

$template->pparse('body');

?>

Code: Select all

<table cellpadding="0" cellspacing="0" border="1" width="100%">
<tr>
	<td>{TEST1}</td>
</tr>
<tr>
	<td>{TEST2}</td>
</tr>
</table>

morpheus2matrix
Registered User
Posts: 82
Joined: Sun Mar 02, 2003 11:54 am
Contact:

Re: Thinking about making a 0.0.12 alpha

Post by morpheus2matrix »

@ Ptirhiik_ : why not using the phpBB Sytsem Template ?
phpBB MOD-Team Member - Check my MOD's

Support For my MOD's

Attachment MOD User Guide || Log Actions MOD User Guide

No support by PM/Email - Thanks - You want to help me ? Click here

User avatar
Ptirhiik_
Registered User
Posts: 526
Joined: Tue Nov 18, 2003 8:35 am

Re: Thinking about making a 0.0.12 alpha

Post by Ptirhiik_ »

That was my conclusion, that's why I stop there, also this one will be way quicker than the standard template class used by phpBB (no regular exp. serched, no eval). I might someday rethink of this :). The aim to not use directly the phpBB script is to always be able to access the screen, even if phpBB is broken by a mod, but template.php can be directly included in the pack as long as the phpbb_realpath() func is created - or removed from the template.php.

Locked