4images Forum & Community

General / Allgemeines => Programming => Topic started by: Sunny C. on December 14, 2010, 05:17:11 PM

Title: function in tag / function in einem tag
Post by: Sunny C. on December 14, 2010, 05:17:11 PM
Hallo,

wie kann man als Beispiel diesen Code in einem tag legen? / how can you put this code in a tag?
          if (@is_dir("./bbcodev3/addons/media")) {
            $handle = @opendir("./bbcodev3/addons/media/");
            while ($file = @readdir($handle)) {
              if (get_file_extension($file) != "php") {
                continue;
              }
              $plugin_file = file("./bbcodev3/addons/media/".$file);
              $plugin_file[0] = trim($plugin_file[0]);
              if (preg_match("/CODE:(.+)/", $plugin_file[0], $regs)) {
                echo trim($regs[1]);
              }
            }
            @closedir($handle);
          }
Der Tag sollte dann in den HTML nutzbar sein: / The tag should then be available in the HTML:
Code: [Select]
{code}
Geht das überhaupt? / Is that possible?
Title: Re: function in tag / function in einem tag
Post by: V@no on December 15, 2010, 04:46:52 AM
                $site_template->register_vars("code", trim($regs[1]));

If this code is inside a function, you'll also need
global $site_template;
Title: Re: function in tag / function in einem tag
Post by: Sunny C. on December 15, 2010, 08:29:47 PM
Is this right?
 function get_code_media($code) {
global $site_template;
          if (@is_dir("./bbcodev3/addons/media")) {
            $handle = @opendir("./bbcodev3/addons/media/");
            while ($file = @readdir($handle)) {
              if (get_file_extension($file) != "php") {
                continue;
              }
              $plugin_file = file("./bbcodev3/addons/media/".$file);
              $plugin_file[0] = trim($plugin_file[0]);
              if (preg_match("/CODE:(.+)/", $plugin_file[0], $regs)) {
                echo trim($regs[1]);
              }
            }
            @closedir($handle);
          }
 }
 $site_template->register_vars("code_media", trim($regs[1]));
Title: Re: function in tag / function in einem tag
Post by: V@no on December 16, 2010, 12:49:57 AM
Not quiet.

function get_code_media($code) {
global $site_template;
$code_media = "";
if (@is_dir("./bbcodev3/addons/media")) {
$handle = @opendir("./bbcodev3/addons/media/");
while ($file = @readdir($handle)) {
if (get_file_extension($file) != "php") {
continue;
}
$plugin_file = file("./bbcodev3/addons/media/".$file);
$plugin_file[0] = trim($plugin_file[0]);
if (preg_match("/CODE:(.+)/", $plugin_file[0], $regs)) {
$code_media = trim($regs[1]);
}
}
@closedir($handle);
}
$site_template->register_vars("code_media", $code_media);
}

But it will only register the last file.
Perhaps if you'd explain what exactly you are trying to achieve I could help more.
Title: Re: function in tag / function in einem tag
Post by: Sunny C. on December 16, 2010, 02:54:00 PM
I wrote this code in functions.php.
When I use now in the bbcode.html {code_media}, it is not accepted.

However, I would like to write the code in the bbcodev3.php. If I do that then causes but a white page.
function get_code_media() {
global $site_template;
$code_media = "";
if (@is_dir("./bbcodev3/addons/media")) {
       $handle = @opendir("./bbcodev3/addons/media/");
       while ($file = @readdir($handle)) {
                    if (get_file_extension($file) != "php") {
                    continue;
                    }
                    $plugin_file = file("./bbcodev3/addons/media/".$file);
                    $plugin_file[0] = trim($plugin_file[0]);
                    if (preg_match("/CODE:(.+)/", $plugin_file[0], $regs)) {
                    $code_media = trim($regs[1]);
                    }
       }
      @closedir($handle);
    }
    $site_template->register_vars("code_media", $code_media);
}

I'm working on my Bbcode variant.
In the HTML files I have currently available that PHP code.
This is both unattractive and the second is not really suitable.
I just want to outsource only the PHP code and use it as a variable in the HTML files.