Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest sNews - sNews 1.7 - with its own forums - for discussion and user mods.

Author Topic: Function file_include  (Read 2416 times)

djoey

  • Newbie
  • *
  • Karma: 0
  • Posts: 19
Function file_include
« on: October 17, 2008, 05:54:53 PM »

I had to include:

$i < $num;

In the function because including a php file would cause an infinite loop.

Code: [Select]
//FILE INCLUSION
# 1.6.0 - 1 revised string, see comment.
function file_include($text, $shorten) {
    $fulltext = substr($text, 0, $shorten);
    $inc = strpos($fulltext, '[/include]');
    if ($inc > 0) {
        $text = str_replace('[include]', '|&|', $fulltext);
        $text = str_replace('[/include]', '|&|', $text);
        $text = explode('|&|', $text);
        $num = count($text);
        $extension = explode(',', l('file_include_extensions'));
        for ($i = 0; $i < $num; $i++) {
            if ($i == $num) {break;}
    # 1.6.0 - revised string.
            if (!in_array(substr(strrchr($text[$i], '.'), 1), $extension)) {echo substr($text[$i], 0);}
            else {
                if (preg_match("/^[a-z0-9_\-.\/]+$/i", $text[$i])) {
                    $filename = $text[$i];
                    file_exists($filename) ? include($filename) : print l('error_file_exists');
                } else {echo l('error_file_name');}
            }
        }
    } else {echo $fulltext;}
}

Logged