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 3 123 LastLast
Results 1 to 15 of 40
  1. #1
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post

    Need help on snippet of code;

    I am using a cms called webspell and i am trying to make a custom theme / theme mod. My php experience is minimal so i need help rewriting a piece of code, here is it;

    Code:
    function gettemplate($template,$endung="html", $calledfrom="root") {
         $templatefolder = "templates";
         if($calledfrom=='root') {
              return str_replace("\"", "\\\"", $GLOBALS['_language']->replace(file_get_contents($templatefolder."/".$template.".".$endung)));
         }
         elseif($calledfrom=='admin') {
              return str_replace("\"", "\\\"", $GLOBALS['_language']->replace(file_get_contents("../".$templatefolder."/".$template.".".$endung)));
         }
    }
    Basically that code will call on the .html template files for users from the root/templates folder. What i am trying to do is get it to look for the template files in the root/themes/$activetheme/templates directory, and if the file is not located there it will then look for it in the root/templates directory. Is this possible and if so can someone rewrite that segment of code to do this (for users not admin), thanks!

  • #2
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    I am not sure how much coding this requires (or if its possible) but if is a bit more involved than i am thinking i can pay what it is worth through paypal.

  • #3
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Where is $activetheme coming from?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #4
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    _setting.php (which is loaded before the _functions.php) i declared it there and to the proper location in the database.

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    I hate doing this, but chances are this function is already in use:
    PHP Code:
    function gettemplate($template,$endung="html"$calledfrom="root") {
         global 
    $activetheme;
         
    $templatefolder "templates/themes/" $activetheme;

         if(
    $calledfrom=='root') {
              return 
    str_replace("\"""\\\""$GLOBALS['_language']->replace(file_get_contents($templatefolder."/".$template.".".$endung)));
         }
         elseif(
    $calledfrom=='admin') {
              return 
    str_replace("\"""\\\""$GLOBALS['_language']->replace(file_get_contents("../".$templatefolder."/".$template.".".$endung)));
         }

    Try that.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    I am not sure if that code is actually doing what i need. The templates folder is root/templates/ by default. I want it to look for templates files inside of root/themes/$activetheme/templates/ and if it does not find the file located there it will then load the one that is in root/templates/

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Is this in any way related to the use of $calledfrom or no?
    Edit:
    No it won't, that has just the purpose of changing directory. You can actually get around that, but we won't get into that right now.
    Change like so:
    PHP Code:
    function gettemplate($template,$endung="html"$calledfrom="root")

        global 
    $activetheme

        
    $defaultFolder 'root/templates/';
        
    $customFolder 'root/themes/' $activetheme '/templates/';
        
    $templateFile $template '.' $endung;

        
    $usingTemplate $customFolder $templateFile;

        if (
    $calledfrom <> 'root')
        {
            
    $usingTemplate '/../' $usingTemplate;
        }

        if (!
    is_readable($usingTemplate))
        {
            
    $usingTemplate $defaultFolder $templateFile;
        }

        return 
    str_replace("\"""\\\""$GLOBALS['_language']->replace(file_get_contents($usingTemplate))); 


    Try that.
    Last edited by Fou-Lu; 03-23-2010 at 09:54 PM.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • Users who have thanked Fou-Lu for this post:

    Cliffo (03-23-2010)

  • #8
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Something like the following. You'll need to transpose it into your existing code.

    Code:
    if (is_file('./root/themes/'.$activetheme.'/templates/'.$template))
    {
        $file = './root/themes/'.$activetheme.'/templates/'.$template;
    }
    else
    {
        $file = './root/templates/'.$template;
    }

  • Users who have thanked MattF for this post:

    Cliffo (03-23-2010)

  • #9
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    That looks like it does what i need, where do i put it exactly?

  • #10
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    function gettemplate($template,$endung="html", $calledfrom="root")
    {
    global $activetheme;

    $defaultFolder = 'templates/';
    $customFolder = 'themes/' . $activetheme . '/templates/';
    $templateFile = $template . '.' . $endung;

    $usingTemplate = $customFolder . $templateFile;

    if ($calledfrom <> 'root')
    {
    $usingTemplate = '/../' . $usingTemplate;
    }

    if (!is_readable($usingTemplate))
    {
    $usingTemplate = $defaultFolder . $templateFile;
    }

    return str_replace("\"", "\\\"", $GLOBALS['_language']->replace(file_get_contents($usingTemplate)));

    }
    THAT IS IT THANK YOU!!!

    With one minor changed, i simply removed "root" from the two 'root/templates/'
    Last edited by Cliffo; 03-23-2010 at 10:43 PM.

  • #11
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    Got another for ya, this is the code i added to the admin panel to allow the user to change the activetheme;

    PHP Code:
    <tr>
            <td align="right"><input type="text" name="activetheme" value="<?php echo $ds['activetheme']; ?>" size="15" onmouseover="showWMTT('id44')" onmouseout="hideWMTT()" /></td>
            <td><b>Active Theme</b> <i>(make sure the theme is inside the /themes folder and put the exact theme folder name here without slashes(Example: default)</i></td>
          </tr>
    How can i make that option a drop down with a list showing every folder inside of root/themes/ that way we can avoid the whole typo issue i foresee happening.

  • #12
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,979
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    Lets wing it. Man I miss my PC :'(
    I'll just stick with the tables here:
    PHP Code:
    <tr> 
            <td align="right"><select name="activetheme">
    <?php
    $di 
    = new DirectoryIterator('/root/themes');
    foreach (
    $di AS $file)
    {
        if (
    $file->isDir() && !$file->isDot())
        {
            
    sprintf('<option value="%s">%s</option>' PHP_EOL$file->getFileName(), $file->getFileName());
        }
    }
    ?>
    </select></td>
            <td><b>Active Theme</b> <i>(make sure the theme is inside the /themes folder and put the exact theme folder name here without slashes(Example: default)</i></td> 
          </tr>
    Yeah, something like that; you'll need to readd you're js calls though, I don't know what they do so I don't know if you'll need them / can use them. If you don't have DirectoryIterator, someone else will show you how to do it with a filescan or glob call.
    I gotta go home now
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #13
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Active Theme DropDown:
    Code:
    <?php # Read Theme Folders
    function Theme_Folders($dir,$current){
    $dh  = opendir($dir);
    while (false !== ($filename = readdir($dh))) {
      if(strpos($filename,".") === false){
        $files[] = $filename;
      }
    }
    $theme = "<select id=\"theme\">\n";
    $theme .= "\t<option value=\"\">- Active Themes -</option>\n";
    foreach ($files As $file){
      if($current == $file){ 
        $select = " SELECTED"; 
      }
      $theme .= "\t<option value=\"$file\"$select>$file</option>\n";
    }
    $theme .= "</select>";
    return $theme;
    }
    /* How to call the dropdown */
    print Theme_Folders('PathtoThemes/','Current Theme Name');
    ?>
    Last edited by DJCMBear; 03-24-2010 at 12:15 AM.

  • #14
    New Coder
    Join Date
    Mar 2010
    Posts
    78
    Thanks
    18
    Thanked 1 Time in 1 Post
    Quote Originally Posted by DJCMBear View Post
    Active Theme DropDown:
    Code:
    <?php # Read Theme Folders
    function Theme_Folders($dir,$current){
    $dh  = opendir($dir);
    while (false !== ($filename = readdir($dh))) {
      if(strpos($filename,".") === false){
        $files[] = $filename;
      }
    }
    $theme = "<select id=\"theme\">\n";
    $theme .= "\t<option value=\"\">- Active Themes -</option>\n";
    foreach ($files As $file){
      if($current == $file){ 
        $select = " SELECTED"; 
      }
      $theme .= "\t<option value=\"$file\"$select>$file</option>\n";
    }
    $theme .= "</select>";
    return $theme;
    }
    /* How to call the dropdown */
    print Theme_Folders('PathtoThemes/','Current Theme Name');
    ?>
    Neither of those is working, this one seems close, is it pulling the options from the folders inside of root/themes/ ?

  • #15
    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
    Neither of those is working, this one seems close, is it pulling the options from the folders inside of root/themes/ ?
    You would need to write: print Theme_Folders('themes/','Current Theme Name');

    And then the current theme name would be defined from your database from the row of the user.

    it looks inside the defined folder path and calls out the folder names into and array to be put into a foreach function which creates the html options for the select box it works 100% because it was tested.
    Last edited by DJCMBear; 03-24-2010 at 12:35 AM.


  •  
    Page 1 of 3 123 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
    •