Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post

    Code to get a file

    Updated the this post with the segment of code that i need to edit. I am still trying to do this myself but if anyone can help me out thats appreciated.


    I am using a cms called webspell and i am trying to create a theme selection system of sorts, but my programming experience is minimal at best. I have a segment of code from my cms that i believe retrieves the files (forums.php, downloads.php ect ect).

    PHP Code:
    if(!function_exists('file_get_contents')) {
        function 
    file_get_contents($filename) {
            
    $fd fopen("$filename""rb");
            
    $content fread($fdfilesize($filename));
            
    fclose($fd);
            return 
    $content;
        }
    }

    if(!
    function_exists('str_split')) {
        function 
    str_split($str,$split_length=1) {

            
    $cnt mb_strlen($str);

            for (
    $i=0;$i<$cnt;$i+=$split_length)
            
    $result[]= mb_substr($str,$i,$split_length);

            return 
    $result;
        }
    }

    if(!
    function_exists('str_ireplace')) {
        function 
    str_ireplace($search,$replace,$subject) {
            
    $search preg_quote($search"/");
            return 
    preg_replace("/".$search."/i"$replace$subject);
        }

    That code retrieves the files from my root, what i want it to do is look for the file inside of root/themes/$activetheme/ then if it does not find the file there it will look inside the root as it does now. If someone can show me how to write that segment of code to do what i need (assuming this is the proper place to edit which i think it is) that would be much appreciated!
    Last edited by Cliffo; 03-25-2010 at 10:16 AM.

  • #2
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Quote Originally Posted by Cliffo View Post
    I am using a cms called webspell and i am trying to create a theme selection system of sorts, but my programming experience is minimal at best. I have a segment of code from my cms that i believe retrieves the files (forums.php, downloads.php ect ect).

    PHP Code:
    function systeminc($file) {
        if(!include(
    'src/'.$file.'.php')) system_error('Could not get system file for '.$file);

    That code retrieves the files from my root, what i want it to do is look for the file inside of root/themes/$activetheme/ then if it does not find the file there it will look inside the root as it does now. If someone can show me how to write that segment of code to do what i need (assuming this is the proper place to edit which i think it is) that would be much appreciated!
    try this:
    PHP Code:
    function systeminc($file,$activetheme) {
      if(
    file_exists('themes/'.$activetheme.'/'.$file.'.php'){
        if(!include(
    'themes/'.$activetheme.'/'.$file.'.php')) system_error('Could not get system file for '.$file);
      }else{
        if(!include(
    'src/'.$file.'.php')) system_error('Could not get system file for '.$file);
      }

    and then use:
    PHP Code:
    systeminc('filename','current theme name'); 
    but if it's like the last script and your using it inside a folder you may need to add ../ before the word themes.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #3
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    I got an error,

    Parse error: syntax error, unexpected '{' in /home/cgshost/cgstest/_settings.php on line 172

    which is the 2nd line of that code.

    I might need to mess around with some other files to get this working.
    Last edited by Cliffo; 03-25-2010 at 06:18 AM.

  • #4
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Dumb me it needs to have two ')' at the end before the {.

    Heres the fixed code:
    PHP Code:
    function systeminc($file,$activetheme) {
      if(
    file_exists('themes/'.$activetheme.'/'.$file.'.php')){
        if(!include(
    'themes/'.$activetheme.'/'.$file.'.php')) system_error('Could not get system file for '.$file);
      }else{
        if(!include(
    'src/'.$file.'.php')) system_error('Could not get system file for '.$file);
      }

    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • Users who have thanked DJCMBear for this post:

    Cliffo (03-25-2010)

  • #5
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    It doesn't seem to be working, that doesn't mean it is your code i might have to be making edits elsewhere i haven't discovered yet lol

  • #6
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Quote Originally Posted by Cliffo View Post
    It doesn't seem to be working, that doesn't mean it is your code i might have to be making edits elsewhere i haven't discovered yet lol
    Yes there could be some other edits to make but im not the worlds number one coder so it could be my code =) and i used codes like this before and thats the way I would normal write it.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • Users who have thanked DJCMBear for this post:

    Cliffo (03-25-2010)

  • #7
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    When you say use;

    systeminc('filename','current theme name');

    do you mean

    systeminc('filename','$activetheme');

    ????

  • #8
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Quote Originally Posted by Cliffo View Post
    When you say use;

    systeminc('filename','current theme name');

    do you mean

    systeminc('filename','$activetheme');

    ????
    i mean

    PHP Code:
    systeminc('filename',$activetheme); 
    and if the file name is header lets say you would put header insted of filename.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • Users who have thanked DJCMBear for this post:

    Cliffo (03-25-2010)

  • #9
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    Just making sure, i am assuming i need to edit some code elsewhere to achieve what i want, not too sure at the moment, but thanks for the help.

    A lot of themes overwrite .php files in the root, what i am trying to do is find what function calls those files and make it check for it in the activethemes folder first, but it seems that code might not be the part i need to edit.
    Last edited by Cliffo; 03-25-2010 at 07:14 AM.

  • #10
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    Would this be the code i need to edit?

    PHP Code:
    if(!function_exists('file_get_contents')) {
        function 
    file_get_contents($filename) {
            
    $fd fopen("$filename""rb");
            
    $content fread($fdfilesize($filename));
            
    fclose($fd);
            return 
    $content;
        }
    }

    if(!
    function_exists('str_split')) {
        function 
    str_split($str,$split_length=1) {

            
    $cnt mb_strlen($str);

            for (
    $i=0;$i<$cnt;$i+=$split_length)
            
    $result[]= mb_substr($str,$i,$split_length);

            return 
    $result;
        }
    }

    if(!
    function_exists('str_ireplace')) {
        function 
    str_ireplace($search,$replace,$subject) {
            
    $search preg_quote($search"/");
            return 
    preg_replace("/".$search."/i"$replace$subject);
        }

    if not maybe

    PHP Code:
    function makepagelink($link$page$pages$sub='') {
        
    $page_link '<span class="pagelink"><img src="images/icons/multipage.gif" width="10" height="12" alt="" /> <small>';

        if(
    $page != 1$page_link .= '&nbsp;<a href="'.$link.'&amp;'.$sub.'page=1">&laquo;</a>&nbsp;<a href="'.$link.'&amp;'.$sub.'page='.($page-1).'">&lsaquo;</a>';
        if(
    $page >= 6$page_link .= '&nbsp;<a href="'.$link.'&amp;'.$sub.'page='.($page-5).'">...</a>';
        if(
    $page+>= $pages$pagex=$pages;
        else 
    $pagex $page+4;
        for(
    $i=$page-$i<=$pagex $i++) {
            if(
    $i<=0$i=1;
            if(
    $i==$page$page_link .= '&nbsp;<b><u>'.$i.'</u></b>';
            else 
    $page_link .= '&nbsp;<a href="'.$link.'&amp;'.$sub.'page='.$i.'">'.$i.'</a>';
        }
        if((
    $pages-$page) >= 5$page_link .= '&nbsp;<a href="'.$link.'&amp;'.$sub.'page='.($page+5).'">...</a>';
        if(
    $page != $pages$page_link .= '&nbsp;<a href="'.$link.'&amp;'.$sub.'page='.($page+1).'">&rsaquo;</a>&nbsp;<a href="'.$link.'&amp;'.$sub.'page='.$pages.'">&raquo;</a>';
        
    $page_link .= '</small></span>';

        return 
    $page_link;


    possibly

    PHP Code:
    function detectfilesize($size$round='2') {
        
    $filesize=$size;
        for(
    $i=0;$filesize>=1024;$i++) {
            
    $filesize $filesize/1024;
        }
        
    $filesize round($filesize,$round);
        switch(
    $i) {
            case 
    0$filesize $filesize." Byte"; break;
            case 
    1$filesize $filesize." kB"; break;
            case 
    2$filesize $filesize." MB"; break;
            case 
    3$filesize $filesize." GB"; break;
            case 
    4$filesize $filesize." TB"; break;
            default: 
    $filesize $size." Byte"; break;
        }
        return 
    $filesize;
    }

    function 
    getdirsize($dir) {

        
    $size=0;
        
    $handle opendir($dir);
        while (
    false !== ($file readdir($handle))) {
            if (
    $file != "." && $file != "..") {
                if(
    is_dir($dir.$file)) $size $size getdirsize($dir.$file.'/');
                else 
    $size=$size+filesize($dir.$file);
            }
        }
        return 
    $size;
    }

    function 
    rm_recursive($filepath){
        if (
    is_dir($filepath) && !is_link($filepath)){
            if (
    $dh = @opendir($filepath)){
                while ((
    $sf readdir($dh)) !== false){
                    if (
    $sf == '.' || $sf == '..'){
                        continue;
                    }
                    if (!
    rm_recursive($filepath.'/'.$sf)){
                        return 
    false;
                    }
                }
                
    closedir($dh);
            }
            return @
    rmdir($filepath);
        }
        return @
    unlink($filepath);


    or it is the first one i tried;

    PHP Code:
    function systeminc($file) {
        if(!include(
    'src/'.$file.'.php')) system_error('Could not get system file for '.$file);

    i cant think of any other code segment that might be the one i need to edit, any of those seem like they would be the one i need?


    That code retrieves the files from my root, what i want it to do is look for the file inside of root/themes/$activetheme/ then if it does not find the file there it will look inside the root as it does now.

  • #11
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    I would suggest the first batch of code section because that seems to be looking for a file to read it.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #12
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    I am thinking the same, but i was hoping it was the last because it is the smallest hahaha

  • #13
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    So basically the following line need to be made into an if/else statement looking for root/themes/$activetheme/$filename and then root/$filename

    PHP Code:
          $fd fopen("$filename""rb"); 
    is that what i need?

  • #14
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    basicly you need your code to look inside the active theme folder inside your themes folder and if its not in there then look in src dir so yes an if else would be needed.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #15
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    Bah i cant get it to work, anyone want to help me write this segment?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •