Author Topic: function in tag / function in einem tag  (Read 5455 times)

0 Members and 1 Guest are viewing this topic.

Offline Sumale.my

  • Addicted member
  • ******
  • Posts: 1.790
  • I ♥ 4I
    • View Profile
function in tag / function in einem tag
« 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?
Beste Grüße
Sumale.my

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: function in tag / function in einem tag
« Reply #1 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;
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Sumale.my

  • Addicted member
  • ******
  • Posts: 1.790
  • I ♥ 4I
    • View Profile
Re: function in tag / function in einem tag
« Reply #2 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]));
Beste Grüße
Sumale.my

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Administrator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: function in tag / function in einem tag
« Reply #3 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.
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline Sumale.my

  • Addicted member
  • ******
  • Posts: 1.790
  • I ♥ 4I
    • View Profile
Re: function in tag / function in einem tag
« Reply #4 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.
Beste Grüße
Sumale.my