Jump to content

Nooty

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Nooty's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. i created a plugin system once that stored each individual plugin's code in a database, then i had plugin locations such as "page_start", "page_complete" and any other location i thought might have had the potential to need some code pluging into it. i would then call a function that would load all the code from each specific location and add it to one long string, then i would eval it. worked well enough for my needs. :)
  2. [quote author=ToonMariner link=topic=97062.msg389181#msg389181 date=1151574878] I can't see why you would need to do any pattern matching on this... eval should work fine with breaking out of php. also itr is recommended that you do not use the short hand tags - use <?php instead!!! [/quote] i have been looking into this subject a lot recently.. the code will be stored as a string, so if you were to eval that string you would get an error (try putting that all in a php file and running it :P) im thinking you would need to do a preg_replace_callback, find the code with a reg expression eg - "/<?(.8)?>/siU" and then have a function to eval the code and return the result. i understand this is an old topic, but if i could have found the solution to this problem when i was looking then i wouldnt have spent hours trying to figure it out. i hope this helps someone.
  3. Hello all hope you are well..? I have written a simple template engine, which pulls the template out of a database, evals it and then outputs it. this works fine. I then went to add conditionals into the template so i could add more diversity to the templates, using <if condition=""><endif> tags. I managed to get this code working in a simple situation, using a preg_replace, and and alternative if statment. i then updated my code with the conditional code, and it worked almost fine. in my template code, i need to use an addslashes function to make sure the eval function executes correctly (for html that has quotes in it) when i remove the addslashes, and the template doesnt have quotes, it works perfect, evaluating hte template and parsing all the conditionals, however when i have a template with quotes in it and thus need to use addslshes my code refuses to work. here is my code, im sure the problem is my preg_match search string.. here is my code if anyone can help.. [code=php:0]<? //For The Record, the data contained in the requested database feild is (without quotes) "Hello.. do i seee foo?<br/><if condition="$foo == "1"">Foo!<endif>" function fetch($template){ $result = mysql_query("SELECT template FROM " . TABLE_PREFIX . "templates WHERE templatename = '$template' LIMIT 1"); $row = mysql_fetch_array($result); $template = $row[template]; $template = addslashes($template); $template = preg_replace("/<if condition=\\\"(.*)\\\">(.*)<endif>/","\" . ($1 ? \"$2\" : \"\") . \"", $template); return($template); } function display($data){ $data = stripslashes($data); print($data); } $foo = "1"; eval('display("' . fetch('index') . '");'); ?>[/code] Thx ;)
  4. just in case anyone is researching this same subject, the aforementioned idea worked a charm. [code]function load_plugins($location) { global $prefix; $sql = "SELECT code FROM " . $prefix . "plugin WHERE location = 'main_end'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ $pluginCode .= $row[code] . "\n\n"; } return($pluginCode); }[/code] and.. [code]$plugins = symplyte::load_plugins('main_end'); eval($plugins);[/code][/code]
  5. what if i were to make a function and then take all of the plugin code, and store it all as a string and then return that string, THEN eval it from the main code? ie $pluginCode = symplyte::loadplugins('main_end'); im a little under the influence atm, but i find having a few shandys helps me be creative - what do you think?
  6. Firstly hello all, im new here. (It's also my birthday today so all well wishers welcome ;)) And now to my problem. I decided to make a template system, inspired by the way vBullein works, where i have a template in one table, and the page data in another, i pull out the template and the page data and use eval to slap it all together intoa  variable, then print the result. This all works peachy. Satisfied with this i decided to develop the code further, and impliment a plugin system. Again, the plugin code (which was plain PHP) was stored in the database which i pulled out and used eval to run it. I wanted to have plugin locations within my code - like at the start, the beginning etc. I wrote the code and it worked fine, but it looked messy, not to mention a pain copy+paste the plugin code wherever i wanted it. So i decided to make a function out of the code, but unless i declare each variable i use as global in the template, i cannot use them outside the function. Any help? [b]Main Code[/b] [CODE]<? include("./config.php"); include("./global.php"); $symplyte = new symplyte; symplyte::database($username, $password, $host, $database); //Which Page? $resource = $_GET['resource']; if($resource == ""){ $resource = 1; //This is the homepage id } //Get Page Data $sql = "SELECT * FROM " . $prefix . "pagedata WHERE resource = '$resource' LIMIT 1"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $content = $row[pagedata]; // <-My Page Content //Get Template $sql = "SELECT name FROM " . $prefix . "template WHERE id = '$row[template]' LIMIT 1"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $usetemplate = $row[name]; <-The Template //This is the start of the plugin code $sql = "SELECT code FROM " . $prefix . "plugin WHERE location = 'main_end'"; $result = mysql_query($sql); while($row = mysql_fetch_array($result)){ $pluginCode = $row[code]; if( FALSE === @eval($pluginCode)){ print("There was a problem running plugin: $row[id]<br/>"); } } //And this is the end of the plugin code eval('$template = "' . symplyte::fetch_template($usetemplate) . '";'); //Put the template with all the variables together print($template); //Output it all ?> [/CODE] [b]Functions etc[/b] [CODE] <? class symplyte { //Fetch Template From Database function fetch_template($template) { global $prefix; $sql = "SELECT * FROM " . $prefix . "template WHERE name = '$template' LIMIT 1"; $result = mysql_query($sql); $row = mysql_fetch_array($result); $template = addslashes($row[template]); return($template); } //Database Functions function database($username, $password, $host, $database) { if(!@mysql_connect($host, $username, $password)){ database_error(mysql_error()); } if(!@mysql_select_db($database)){ database_error(mysql_error()); } } function database_error($error) { print("Something went wrong, and i was unable to connect to the database. The error returned was: $error"); } } ?> [/code] a template would include html with a $content variable for the main content, then $testPlugin1 etc for any plugin variables, and then a plugin allong the lines of [CODE] $testPlugin1 = date("d/m/Y h:i");[/CODE][/code]
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.