Plugin Directory

Changeset 705272


Ignore:
Timestamp:
04/29/2013 08:23:38 AM (13 years ago)
Author:
bastb
Message:

Sets the compiled template directory to the systems' temp directory.
Resolves the issue reported by Meindert Willems

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lips/branches/dev-0.8.10/templating.php

    r563270 r705272  
    5555        $this->enableSecurity(new LinkedInProfileSync_Security_Policy($modifiers = array('in_array')));
    5656        $this->setCaching(Smarty::CACHING_OFF);
    57         $this->setCompileDir(dirname(__FILE__) . "/template/compiled/");
     57        $this->setCompiledTemplatesDirectory();
    5858        $this->clearCompiledTemplate();
    5959        $this->lips_error_reporting = $smarty_reporting;
     
    6161        foreach ($variables as $key => $value)
    6262            $this->assign($key, $value);
     63    }
     64
     65
     66    /**
     67     * Creates a temporary directory for the compiled templates. The
     68     * directory is created in the systems' temp directory, and is
     69     * produced using a static string and, optionally, a number. The
     70     * directory is created when it doesn't already exist
     71     *
     72     */
     73    protected function setCompiledTemplatesDirectory() {
     74        $i = 0;
     75        $compile_dir_candidate = $compile_dir = sys_get_temp_dir() . '/wp_lips_compiled_tpl';
     76        $has_dir = false;
     77       
     78        do {
     79            // Here's where the trouble starts'
     80            if (file_exists($compile_dir_candidate)) {
     81                $has_dir = is_dir($compile_dir_candidate);
     82                if (! $has_dir) {
     83                    $i++;
     84                    // Add the suffix and try again
     85                    $compile_dir_candidate = $compile_dir . '_' . $i;
     86                }
     87            }
     88            else {
     89                // Create directory recursively
     90                @mkdir($compile_dir_candidate, 0755, true);
     91                // This keeps the loop running when the process cannot write
     92                // to the temporary directory
     93                $has_dir = is_dir($compile_dir_candidate);
     94            }
     95        } while (! $has_dir);
     96       
     97        // Set the compile directory to this newly created (or selected) directory
     98        $this->setCompileDir($compile_dir_candidate);
    6399    }
    64100
     
    107143        }
    108144       
     145        // Template caching and compiling should be disabled, so there's
     146        // no need to save a compiled version
    109147        $this->clearCompiledTemplate();
    110148       
Note: See TracChangeset for help on using the changeset viewer.