/**
  * @static
  * @param bool $admin
  * @return GantryCache
  */
 public static function getInstance($admin = false)
 {
     if (!self::$instance) {
         self::$instance = new GantryCache($admin);
     }
     return self::$instance;
 }
Esempio n. 2
0
 public function ajax()
 {
     /** @var $gantry Gantry */
     global $gantry;
     // load and inititialize gantry class
     $gantry_path = JPATH_SITE . '/libraries/gantry/gantry.php';
     if (file_exists($gantry_path)) {
         require_once $gantry_path;
     } else {
         echo "error " . JText::_('Unable to find Gantry library.  Please make sure you have it installed.');
         die;
     }
     $model = $gantry->getAjaxModel(JFactory::getApplication()->input->getString('model'), false);
     if ($model === false) {
         die;
     }
     include_once $model;
     /*
         - USAGE EXAMPLE -
     
         new Request({
     				url: 'http://url/template/administrator/index.php?option=com_admin&tmpl=gantry-ajax-admin',
             onSuccess: function(response) {console.log(response);}
         }).request({
             'model': 'example', // <- mandatory, see "ajax-models" folder
             'template': 'template_folder', // <- mandatory, the name of the gantry template folder (rt_dominion_j15)
             'example': 'example1', // <-- from here are all custom query posts you can use
             'name': 'w00fz',
             'message': 'Hello World!'
         });
     */
     // Clear the cache gantry cache after each call
     $cache = GantryCache::getInstance();
     $cache->clearGroupCache();
 }
function gantryAjaxClearLessCache()
{
    /** @var $gantry Gantry */
    global $gantry;
    $cache_handler = GantryCache::getCache(Gantry::LESS_SITE_CACHE_GROUP, null, true);
    $cache_handler->clearGroupCache();
    return JText::_('Less complier cache files cleared');
}
Esempio n. 4
0
function gantryAjaxClearGantryCache()
{
    /** @var $gantry Gantry */
    global $gantry;
    $admincache = GantryCache::getCache(GantryCache::ADMIN_GROUP_NAME, null, true);
    $admincache->clearGroupCache();
    $sitecache = GantryCache::getCache(GantryCache::GROUP_NAME, null, true);
    $sitecache->clearGroupCache();
    return JText::_('Gantry caches cleared.');
}
Esempio n. 5
0
function gantryAjaxClearGantryCache()
{
    /** @var $gantry Gantry */
    global $gantry;
    $admincache = GantryCache::getCache(GantryCache::ADMIN_GROUP_NAME, null, true);
    $admincache->clearGroupCache();
    $sitecache = GantryCache::getCache(GantryCache::GROUP_NAME, null, true);
    $sitecache->getCacheLib()->getDriver()->getCache()->cache->_options['cachebase'] = JPATH_ROOT . '/cache';
    $sitecache->clearGroupCache();
    return JText::_('Gantry caches cleared.');
}
Esempio n. 6
0
function gantryAjaxSaveTemplate()
{
    // Check for request forgeries
    gantry_checktoken() or jexit('Invalid Token');
    GantryLegacyJModel::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_gantry/models');
    $model = GantryLegacyJModel::getInstance("Template", 'GantryModel');
    $data = JFactory::getApplication()->input->post->get('jform', array(), 'array');
    if (!$model->save($data)) {
        return 'error';
    }
    // Clear the front end gantry cache after each call
    $cache = GantryCache::getInstance(false);
    $cache->clearGroupCache();
    $task = JFactory::getApplication()->input->getCmd('task');
    if ($task == 'apply') {
        return JText::_('Template settings have been successfully applied.');
    } else {
        return JText::_('Template settings have been successfully saved.');
    }
}
Esempio n. 7
0
 public function ajax()
 {
     global $gantry;
     // comment out the following 2 lines for debugging
     //$request = @$_SERVER['HTTP_X_REQUESTED_WITH'];
     $modelname = JRequest::getString('model');
     //if ((!isset($request) || strtolower($request) != 'xmlhttprequest') && (isset($modelname) && $modelname != "diagnostics")) die("Direct access not allowed.");
     // load and inititialize gantry class
     $gantry_path = JPATH_SITE . '/libraries/gantry/gantry.php';
     if (file_exists($gantry_path)) {
         require_once $gantry_path;
     } else {
         echo "error " . JText::_('Unable to find Gantry library.  Please make sure you have it installed.');
         die;
     }
     $model = $gantry->getAjaxModel(JRequest::getString('model'), true);
     if ($model === false) {
         die;
     }
     include_once $model;
     /*
         - USAGE EXAMPLE -
     
         new Ajax({
     				url: 'http://url/template/administrator/index.php?option=com_admin&tmpl=gantry-ajax-admin',
             onSuccess: function(response) {console.log(response);}
         }).request({
             'model': 'example', // <- mandatory, see "ajax-models" folder
             'template': 'template_folder', // <- mandatory, the name of the gantry template folder (rt_dominion_j15)
             'example': 'example1', // <-- from here are all custom query posts you can use
             'name': 'w00fz',
             'message': 'Hello World!'
         });
     */
     // Clear the cache gantry cache after each call
     $cache = GantryCache::getInstance();
     $cache->clearGroupCache();
 }
 /**
  * @param string $lessfile
  * @param bool   $cssfile
  * @param int    $priority
  *
  * @param array  $options
  *
  * @throws RuntimeException
  */
 public function addLess($lessfile, $cssfile = null, $priority = self::DEFAULT_STYLE_PRIORITY, array $options = array())
 {
     $less_search_paths = array();
     // setup the less filename
     if (dirname($lessfile) == '.') {
         //set up the check for template with plartform based dirs
         $less_search_paths = $this->platform->getAvailablePlatformVersions($this->templatePath . '/less');
         foreach ($less_search_paths as $less_path) {
             if (is_dir($less_path)) {
                 $search_file = preg_replace('#[/\\\\]+#', '/', $less_path . '/' . $lessfile);
                 if (is_file($search_file)) {
                     $lessfile = $search_file;
                     break;
                 }
             }
         }
     }
     $less_file_md5 = md5($lessfile);
     $less_file_path = $this->convertToPath($lessfile);
     $less_file_url = $this->convertToUrl($less_file_path);
     // abort if the less file isnt there
     if (!is_file($less_file_path)) {
         return;
     }
     // get an md5 sum of any passed in options
     $tmp_options = $options;
     array_walk($tmp_options, create_function('&$v,$k', '$v = " * @".$k." = " .$v;'));
     $options_string = implode($tmp_options, "\n");
     $options_md5 = md5($options_string . (string) $this->get('less-compression', true));
     $css_append = '';
     if (!empty($options)) {
         $css_append = '-' . $options_md5;
     }
     $default_compiled_css_dir = $this->templatePath . '/css-compiled';
     if (!file_exists($default_compiled_css_dir)) {
         @JFolder::create($default_compiled_css_dir);
         if (!file_exists($default_compiled_css_dir)) {
             throw new Exception(sprintf('Unable to create default directory (%s) for compiled less files.  Please check your filesystem permissions.', $default_compiled_css_dir));
         }
     }
     // setup the output css file name
     if (is_null($cssfile)) {
         $css_file_path = $default_compiled_css_dir . '/' . pathinfo($lessfile, PATHINFO_FILENAME) . $css_append . '.css';
         $css_passed_path = pathinfo($css_file_path, PATHINFO_BASENAME);
     } else {
         if (dirname($cssfile) == '.') {
             $css_file_path = $default_compiled_css_dir . '/' . pathinfo($cssfile, PATHINFO_FILENAME) . $css_append . '.css';
             $css_passed_path = pathinfo($css_file_path, PATHINFO_BASENAME);
         } else {
             $css_file_path = dirname($this->convertToPath($cssfile)) . '/' . pathinfo($cssfile, PATHINFO_FILENAME) . $css_append . '.css';
             $css_passed_path = $css_file_path;
         }
     }
     $cssfile_md5 = md5($css_file_path);
     // set base compile modes
     $force_compile = false;
     $single_compile = false;
     $app = JFactory::getApplication();
     if (!$app->isAdmin()) {
         $cachegroup = self::LESS_SITE_CACHE_GROUP;
     } else {
         $cachegroup = self::LESS_ADMIN_CACHE_GROUP;
     }
     $runcompile = false;
     $cache_handler = GantryCache::getCache($cachegroup, null, true);
     $cached_less_compile = $cache_handler->get($cssfile_md5, false);
     if ($cached_less_compile === false || !file_exists($css_file_path)) {
         $cached_less_compile = $less_file_path;
         $runcompile = true;
     } elseif (is_array($cached_less_compile) && isset($cached_less_compile['root'])) {
         if (isset($cached_less_compile['files']) and is_array($cached_less_compile['files'])) {
             foreach ($cached_less_compile['files'] as $fname => $ftime) {
                 if (!file_exists($fname) or filemtime($fname) > $ftime) {
                     // One of the files we knew about previously has changed
                     // so we should look at our incoming root again.
                     $runcompile = true;
                     break;
                 }
             }
         }
     }
     if ($runcompile) {
         gantry_import('core.utilities.gantrylesscompiler');
         $quick_expire_cache = GantryCache::getCache($cachegroup, $this->get('less-compilewait', self::LESS_MAX_COMPILE_WAIT_TIME));
         $timewaiting = 0;
         while ($quick_expire_cache->get($cssfile_md5 . '-compiling') !== false) {
             $wait = 100000;
             // 1/10 of a second;
             usleep($wait);
             $timewaiting += $wait;
             if ($timewaiting >= $this->get('less-compilewait', self::LESS_MAX_COMPILE_WAIT_TIME) * 1000000) {
                 break;
             }
         }
         $less = new GantryLessCompiler();
         $less->setImportDir($less_search_paths);
         $less->addImportDir($this->gantryPath . '/assets');
         if (!empty($options)) {
             $less->setVariables($options);
         }
         if ($this->get('less-compression', true)) {
             $less->setFormatter("compressed");
         }
         $quick_expire_cache->set($cssfile_md5 . '-compiling', true);
         try {
             $new_cache = $less->cachedCompile($cached_less_compile, $force_compile);
         } catch (Exception $ex) {
             $quick_expire_cache->clear($cssfile_md5 . '-compiling');
             throw new RuntimeException('Less Parse Error: ' . $ex->getMessage());
         }
         if (!is_array($cached_less_compile) || $new_cache['updated'] > $cached_less_compile['updated']) {
             $cache_handler->set($cssfile_md5, $new_cache);
             $tmp_ouput_file = tempnam(dirname($css_file_path), 'gantry_less');
             $header = '';
             if ($this->get('less-debugheader', false)) {
                 $header .= sprintf("/*\n * Main File : %s", str_replace(JURI::root(true), '', $less_file_url));
                 if (!empty($options)) {
                     $header .= sprintf("\n * Variables :\n %s", $options_string);
                 }
                 if (count($new_cache['files']) > 1) {
                     $included_files = array_keys($new_cache['files']);
                     unset($included_files[0]);
                     array_walk($included_files, create_function('&$v,$k', 'global $gantry;$v=" * ".$gantry->convertToUrl($v);'));
                     $header .= sprintf("\n * Included Files : \n%s", implode("\n", str_replace(JURI::root(true), '', $included_files)));
                 }
                 $header .= "\n */\n";
             }
             file_put_contents($tmp_ouput_file, $header . $new_cache['compiled']);
             // Do the messed up file renaming for windows
             if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
                 $move_old_file_name = tempnam(dirname($css_file_path), 'gantry_less');
                 if (is_file($css_file_path)) {
                     @rename($css_file_path, $move_old_file_name);
                 }
                 @rename($tmp_ouput_file, $css_file_path);
                 @unlink($move_old_file_name);
             } else {
                 @rename($tmp_ouput_file, $css_file_path);
             }
             JPath::setPermissions($css_file_path);
         }
         $quick_expire_cache->clear($cssfile_md5 . '-compiling');
     }
     $this->addStyle($css_passed_path, $priority);
     if (!empty($css_append) && !is_null($cssfile) && dirname($cssfile) == '.') {
         $this->addStyle($cssfile, $priority);
     }
 }
Esempio n. 9
0
 * @license		http://www.gnu.org/licenses/gpl-2.0.html GNU/GPLv2 only
 */
defined('GANTRY_VERSION') or die;
gantry_import('core.gantryjson');
global $gantry;
$action = $_POST['gantry_action'];
/**
 * Set the sidebar widget option to update sidebars.
 *
 * @since 2.2.0
 * @access private
 *
 * @param array $sidebars_widgets Sidebar widgets and their settings.
 */
gantry_import('core.utilities.gantrycache');
$cache = GantryCache::getInstance();
$cache->clear('gantry', 'gantry');
switch ($action) {
    case 'create-new':
        check_ajax_referer('save-sidebar-widgets', 'savewidgets');
        if (!current_user_can('edit_theme_options')) {
            die('-1');
        }
        unset($_POST['savewidgets'], $_POST['action'], ${$_POST}['gantry_action']);
        $override_catalog = gantry_get_override_catalog($gantry->templateName);
        $next_override = count($override_catalog) > 0 ? max(array_keys($override_catalog)) + 1 : 1;
        $override_name = sprintf(_g('Custom Override %d'), $next_override);
        $override_catalog[$next_override] = $override_name;
        gantry_udpate_override_catalog($override_catalog);
        $retrun_url = admin_url('widgets.php?override_id=' . $next_override);
        echo $retrun_url;
Esempio n. 10
0
    function gantry_admin_setup(){
        gantry_import('core.gantry');
        gantry_import('core.utilities.gantrycache');

        global $gantry;

        $app = JFactory::getApplication();
        $template_name = gantry_getTemplate();
        $cache = GantryCache::getInstance($app->isAdmin());

        $cache->addWatchFile(JPATH_SITE.'/templates/'.$template_name.'/params.ini');
        $cache->addWatchFile(JPATH_SITE.'/templates/'.$template_name.'/templateDetails.xml');
        $gantry = $cache->call('Gantry-'.$template_name, array('Gantry','getInstance'));

        $gantry->adminInit();
    }
Esempio n. 11
0
 function gantry_admin_setup()
 {
     gantry_import('core.gantry');
     gantry_import('core.utilities.gantrycache');
     global $gantry;
     $template_id = gantry_admin_getCurrentTemplateId();
     $template = gantry_getTemplateById($template_id);
     // TODO: implement cache for the admin gantry objects
     $app =& JFactory::getApplication();
     $cache = GantryCache::getInstance($app->isAdmin());
     $cache->addWatchFile(JPATH_SITE . '/templates/' . $template->template . '/templateDetails.xml');
     $cache->addWatchFile(JPATH_SITE . '/templates/' . $template->template . '/template-options.xml');
     $gantry = $cache->call('Gantry-' . $template->template, array('Gantry', 'getInstance'), array($template->template));
     //$gantry =& Gantry::getInstance($template->template);
     $gantry->adminInit();
 }
Esempio n. 12
0
    if (!file_exists($file)) {
        $handle = @fopen($file, 'w');
        @fwrite($handle, "");
    }
    gantry_import('core.gantryini');
    $newEntry = GantryINI::write($file, $data);
    gantry_import('core.utilities.gantrycache');
    $cache = GantryCache::getCache(GantryCache::GROUP_NAME, null, true);
    $cache->clearGroupCache();
    $admincache = GantryCache::getCache(GantryCache::ADMIN_GROUP_NAME, null, true);
    $admincache->clearGroupCache();
    if ($newEntry) {
        echo "success";
    }
} else {
    if ($action == 'delete') {
        $presetTitle = $_POST['preset-title'];
        $presetKey = $_POST['preset-key'];
        if (!$presetKey || !$presetTitle) {
            return "error";
        }
        GantryINI::write($file, array($presetTitle => array($presetKey => array())), 'delete-key');
        gantry_import('core.utilities.gantrycache');
        $cache = GantryCache::getCache(GantryCache::GROUP_NAME, null, true);
        $cache->clearGroupCache();
        $admincache = GantryCache::getCache(GantryCache::ADMIN_GROUP_NAME, null, true);
        $admincache->clearGroupCache();
    } else {
        return "error";
    }
}
Esempio n. 13
0
 function finalize()
 {
     if (!defined('GANTRY_FINALIZED')) {
         // Run the admin init
         if ($this->isAdmin()) {
             $this->adminFinalize();
             return;
         }
         gantry_import('core.params.overrides.gantrycookieparamoverride');
         gantry_import('core.params.overrides.gantrysessionparamoverride');
         $cache = GantryCache::getInstance();
         if (!$this->_parts_cached) {
             $parts_cache = array();
             foreach ($this->_parts_to_cache as $part) {
                 $parts_cache[$part] = $this->{$part};
             }
             if ($parts_cache) {
                 $cache->set($this->cacheKey('parts'), $parts_cache);
             }
         }
         // Finalize all features
         foreach ($this->getFeatures() as $feature) {
             $feature_instance = $this->_getFeature($feature);
             if ($feature_instance->isEnabled() && method_exists($feature_instance, 'finalize')) {
                 $feature_instance->finalize();
             }
         }
         $this->renderCombinesInlines();
         if (isset($_REQUEST['reset-settings'])) {
             GantrySessionParamOverride::clean();
             GantryCookieParamOverride::clean();
         } else {
             GantrySessionParamOverride::store();
             GantryCookieParamOverride::store();
         }
         if ($this->get("gzipper-enabled", false)) {
             gantry_import('core.gantrygzipper');
             GantryGZipper::processCSSFiles();
             GantryGZipper::processJsFiles();
         } else {
             ksort($this->_styles);
             foreach ($this->_styles as $priorities) {
                 foreach ($priorities as $css_file) {
                     $this->document->addStyleSheet($css_file->url);
                 }
             }
             foreach ($this->_scripts as $js_file) {
                 $this->document->addScript($js_file);
             }
         }
         define('GANTRY_FINALIZED', true);
     }
     if ($this->altindex !== false) {
         $contents = ob_get_contents();
         ob_end_clean();
         ob_start();
         echo $this->altindex;
     }
 }
Esempio n. 14
0
 /**
  *
  */
 function gantry_admin_setup()
 {
     gantry_import('core.gantry');
     gantry_import('core.utilities.gantrycache');
     /** @var $gantry Gantry */
     global $gantry;
     $template_id = gantry_admin_getCurrentTemplateId();
     $template = gantry_getTemplateById($template_id);
     $cache = GantryCache::getCache(GantryCache::ADMIN_GROUP_NAME, null, true);
     $cache->addWatchFile(JPATH_SITE . '/templates/' . $template->template . '/templateDetails.xml');
     $cache->addWatchFile(JPATH_SITE . '/templates/' . $template->template . '/template-options.xml');
     $gantry = $cache->call('Gantry-' . $template->template, array('Gantry', 'getInstance'), array($template->template));
     $gantry->adminInit();
 }
Esempio n. 15
0
function gantry_construct()
{
    global $gantry, $gantry_path, $wp_query, $current_blog;
    $gantry_templatepath = get_template_directory() . '/templateDetails.xml';
    if (!file_exists($gantry_templatepath)) {
        define('NONGANTRY_TEMPLATE', 'NONGANTRY_TEMPLATE');
        return;
    }
    if (!defined('GANTRY_VERSION')) {
        /**
         * @name GANTRY_VERSION
         */
        define('GANTRY_VERSION', '1.26');
        if (!defined('DS')) {
            define('DS', DIRECTORY_SEPARATOR);
        }
        // Turn on sessions for Wordpress
        if (!defined('GANTRY_SESSIONS_ENABLED')) {
            if (!session_id()) {
                define('GANTRY_SESSIONS_ENABLED', true);
                session_start();
            }
        }
        $options = get_option(get_template() . "-template-options");
        $cache_enabled = $options['cache']['enabled'];
        $cache_lifetime = $options['cache']['time'];
        load_plugin_textdomain('gantry', false, basename($gantry_path) . '/languages');
        // Get the gantry instance
        gantry_import('core.gantry');
        if ($cache_enabled) {
            gantry_import('core.utilities.gantrycache');
            $cache = GantryCache::getInstance();
            $cache->setLifetime($cache_lifetime);
            $cache->init();
            $gantry = $cache->get('gantry', 'gantry', array('Gantry', 'getInstance'));
        } else {
            $gantry = Gantry::getInstance();
        }
        // Load the widget positions for the template
        $gantry->_loadWidgetPositions();
        add_filter('query_vars', array('GantryTemplateDetails', 'add_url_vars'));
    }
}
Esempio n. 16
0
function gantry_widget_admin_clear_cache()
{
    gantry_import('core.utilities.gantrycache');
    $cache = GantryCache::getInstance();
    $cache->clear('gantry', 'gantry');
}