php Gantry-Framework-Gantry类(方法)实例源码

下面列出了php Gantry-Framework-Gantry 类(方法)源码代码实例,从而了解它的用法。

作者:JozefA    项目:neoac   
protected function __construct()
 {
     parent::__construct();
     $gantry = Gantry::instance();
     if (isset($gantry['file.yaml.cache.path'])) {
         $this->setCachePath($gantry['file.yaml.cache.path']);
     }
 }

作者:Tanver18    项目:gantry   
/**
  * Save assignments for the configuration.
  *
  * @param array $data
  */
 public function save(array $data)
 {
     $data = $data['assignments'];
     foreach ($data as $tname => &$type) {
         foreach ($type as $gname => &$group) {
             foreach ($group as $key => $value) {
                 if (!$value) {
                     unset($group[$key]);
                 } else {
                     $group[$key] = (bool) $value;
                 }
             }
             if (empty($group)) {
                 unset($type[$gname]);
             }
         }
         if (empty($type)) {
             unset($data[$tname]);
         }
     }
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     // Save layout into custom directory for the current theme.
     $save_dir = $locator->findResource("gantry-config://{$this->configuration}", true, true);
     $filename = "{$save_dir}/assignments.yaml";
     $file = YamlFile::instance($filename);
     $file->save($data);
     $file->free();
 }

作者:legutier    项目:gantry   
/**
  * @return array
  */
 public static function getThemes()
 {
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $files = Folder::all('gantry-themes://', ['recursive' => false, 'files' => false]);
     /** @var array|ThemeDetails[] $list */
     $list = [];
     natsort($files);
     foreach ($files as $theme) {
         if ($locator('gantry-themes://' . $theme . '/gantry/theme.yaml')) {
             $details = new ThemeDetails($theme);
             // Stream needs to be valid URL.
             $streamName = 'gantry-themes-' . preg_replace('|[^a-z\\d+.-]|ui', '-', $theme);
             if (!$locator->schemeExists($streamName)) {
                 $locator->addPath($streamName, '', $details->getPaths());
             }
             $details['name'] = $theme;
             $details['title'] = $details['details.name'];
             $details['preview_url'] = $gantry['platform']->getThemePreviewUrl($theme);
             $details['admin_url'] = $gantry['platform']->getThemeAdminUrl($theme);
             $details['params'] = [];
             $list[$details->name] = $details;
         }
     }
     // Add Thumbnails links after adding all the paths to the locator.
     foreach ($list as $details) {
         $details['thumbnail'] = $details->getUrl("details.images.thumbnail");
     }
     return $list;
 }

作者:sam-sures    项目:gantry   
public function onThemeInitialized()
 {
     /** @var UniformResourceLocator $locator */
     $locator = $this->grav['locator'];
     $path = $locator('theme://');
     $name = $this->name;
     if (!class_exists('\\Gantry5\\Loader')) {
         if ($this->isAdmin()) {
             $messages = $this->grav['messages'];
             $messages->add('Please enable Gantry 5 plugin in order to use current theme!', 'error');
             return;
         } else {
             throw new \LogicException('Please install and enable Gantry 5 Framework plugin!');
         }
     }
     // Setup Gantry 5 Framework or throw exception.
     \Gantry5\Loader::setup();
     // Get Gantry instance.
     $gantry = Gantry::instance();
     // Set the theme path from Grav variable.
     $gantry['theme.path'] = $path;
     $gantry['theme.name'] = $name;
     // Define the template.
     require $locator('theme://includes/theme.php');
     // Define Gantry services.
     $gantry['theme'] = function ($c) {
         return new \Gantry\Theme\Hydrogen($c['theme.path'], $c['theme.name']);
     };
 }

作者:legutier    项目:gantry   
/**
  * @see AbstractTheme::init()
  */
 protected function init()
 {
     parent::init();
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     \JPluginHelper::importPlugin('gantry5');
     // Trigger the onGantryThemeInit event.
     $dispatcher = \JEventDispatcher::getInstance();
     $dispatcher->trigger('onGantry5ThemeInit', ['theme' => $this]);
     $lang = \JFactory::getLanguage();
     // FIXME: Do not hardcode this file.
     $lang->load('files_gantry5_nucleus', JPATH_SITE);
     if (\JFactory::getApplication()->isSite()) {
         // Load our custom positions file as frontend requires the strings to be there.
         $filename = $locator("gantry-theme://language/en-GB/en-GB.tpl_{$this->name}_positions.ini");
         if ($filename) {
             $lang->load("tpl_{$this->name}_positions", dirname(dirname(dirname($filename))), 'en-GB');
         }
     }
     $doc = \JFactory::getDocument();
     $this->language = $doc->language;
     $this->direction = $doc->direction;
     $this->url = \JUri::root(true) . '/templates/' . $this->name;
 }

作者:xmasvie    项目:gantry   
function gantry_admin_print_scripts()
{
    $scripts = \Gantry\Framework\Gantry::instance()->scripts();
    if ($scripts) {
        echo implode("\n", $scripts) . "\n";
    }
}

作者:JozefA    项目:neoac   
/**
  * Get global Gantry instance.
  *
  * @return Gantry
  */
 public static function gantry()
 {
     // We cannot set variable directly for the trait as it doesn't work in HHVM.
     if (!self::$gantry) {
         self::$gantry = Gantry::instance();
     }
     return self::$gantry;
 }

作者:nmsd    项目:gantry   
public static function delete($id)
 {
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $path = $locator->findResource('gantry-config://' . $id, true, true);
     if (is_dir($path)) {
         Folder::delete($path, true);
     }
 }

作者:xmasvie    项目:gantry   
public function widgets_init()
 {
     $gantry = Gantry::instance();
     $positions = $gantry['configurations']->positions();
     foreach ($positions as $name => $title) {
         // FIXME
         // This should be handled by theme so translation plugins could catch it as part of theme.
         // This stuff might also need take Joomla chromes into account for cross-compatibility reasons
         register_sidebar(array('name' => __($title, 'gantry5'), 'id' => $name, 'description' => __($title, 'gantry5'), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>'));
     }
 }

作者:nmsd    项目:gantry   
public function __construct()
 {
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $finder = new ConfigFileFinder();
     // Generate a flat list of all existing pages containing a list of file paths with timestamps.
     $this->items = $finder->listFiles($locator->findResources('gantry-pages://'), '|\\.html\\.twig|');
     // And list the pages in alphabetical order.
     ksort($this->items);
 }

作者:Tanver18    项目:gantry   
public function bodyAttributes($attributes = [])
 {
     $gantry = Gantry::instance();
     $classes = ['site', "dir-ltr", "outline-{$gantry['configuration']}"];
     $baseAttributes = (array) $this->config->get('page.body.attribs', []);
     if (!empty($baseAttributes['class'])) {
         $baseAttributes['class'] = array_merge((array) $baseAttributes['class'], $classes);
     } else {
         $baseAttributes['class'] = $classes;
     }
     return $this->getAttributes($baseAttributes, $attributes);
 }

作者:nmsd    项目:gantry   
public function loadAssignments()
 {
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     // Find all the assignment files.
     $paths = $locator->findResources("gantry-config://");
     $files = (new ConfigFileFinder())->locateFileInFolder('assignments', $paths);
     $cache = $locator->findResource('gantry-cache://theme/compiled/config', true, true);
     $config = new CompiledConfig($cache, [$files]);
     return $config->load();
 }

作者:Acidburn0zz    项目:gantry   
public function add_to_twig(\Twig_Environment $twig, \Twig_Loader_Filesystem $loader = null)
 {
     $gantry = \Gantry\Framework\Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     if (!$loader) {
         $loader = $twig->getLoader();
     }
     $loader->setPaths($locator->findResources('gantry-admin://templates'), 'gantry-admin');
     $twig->addExtension(new TwigExtension());
     return $twig;
 }

作者:legutier    项目:gantry   
public function onGlobalSave(Event $event)
 {
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $filename = 'config://plugins/gantry5.yaml';
     $file = YamlFile::instance($locator->findResource($filename, true, true));
     $content = $file->content();
     $content['production'] = (bool) $event->data['production'];
     $file->save($content);
     $file->free();
 }

作者:Acidburn0zz    项目:gantry   
public function widgets_init()
 {
     $gantry = Gantry::instance();
     $positions = (array) $gantry['config']->get('positions');
     foreach ($positions as $name => $params) {
         $params = (array) $params;
         if (!isset($params['name'])) {
             $params['name'] = ucfirst($name);
         }
         register_sidebar(array('name' => __($params['name'], 'gantry5'), 'id' => $name, 'description' => __($params['name'], 'gantry5'), 'before_widget' => '<aside id="%1$s" class="widget %2$s">', 'after_widget' => '</aside>', 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>'));
     }
 }

作者:Tanver18    项目:gantry   
function gantry5_install_clear_cache($upgrader, $options)
{
    // Clear gantry cache after plugin / theme installs.
    if (isset($options['type']) && in_array($options['type'], array('plugin', 'theme')) && class_exists('Gantry\\Framework\\Gantry')) {
        global $wp_filesystem;
        $gantry = \Gantry\Framework\Gantry::instance();
        $path = $gantry['platform']->getCachePath();
        if ($wp_filesystem->is_dir($path)) {
            $wp_filesystem->rmdir($path);
        }
        $upgrader->skin->feedback('Gantry 5 cache cleared.');
    }
}

作者:nmsd    项目:gantry   
public function render($file, array $context = array())
 {
     $gantry = \Gantry\Framework\Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $loader = new \Twig_Loader_Filesystem($locator->findResources('gantry-admin://templates'));
     $params = array('cache' => $locator->findResource('gantry-cache://theme/twig', true, true), 'debug' => true, 'auto_reload' => true, 'autoescape' => 'html');
     $twig = new \Twig_Environment($loader, $params);
     $this->add_to_twig($twig);
     // Include Gantry specific things to the context.
     $context = $this->add_to_context($context);
     return $twig->render($file, $context);
 }

作者:Ettore49    项目:Ettore-Wor   
public static function copy($style, $old, $new)
 {
     $gantry = Gantry::instance();
     /** @var UniformResourceLocator $locator */
     $locator = $gantry['locator'];
     $oldPath = $locator->findResource('gantry-config://' . $old, true, true);
     $newPath = $locator->findResource('gantry-config://' . $new, true, true);
     if (file_exists($oldPath)) {
         Folder::copy($oldPath, $newPath);
     }
     $installer = new TemplateInstaller($style->extension_id);
     $installer->updateStyle($new, ['configuration' => $new]);
 }

作者:lucian030    项目:gantry   
protected function __construct()
 {
     parent::__construct();
     $gantry = Gantry::instance();
     /** @var Config $global */
     $global = $gantry['global'];
     if (!$global->get('compile_yaml', 1)) {
         $this->caching(false);
     }
     if (isset($gantry['file.yaml.cache.path'])) {
         $this->setCachePath($gantry['file.yaml.cache.path']);
     }
 }

作者:Tanver18    项目:gantry   
public function __construct()
 {
     global $pagenow;
     parent::__construct('particle_widget', __('Gantry 5 Particle', 'gantry5'), ['description' => __('Displays Gantry 5 particle instance in a widget position.', 'gantry5'), 'gantry5' => true]);
     try {
         $this->container = Gantry::instance();
     } catch (Exception $e) {
     }
     $ajax = $pagenow === 'admin-ajax.php' && (isset($_POST['action']) && $_POST['action'] === 'save-widget');
     if (is_admin() && (in_array($pagenow, ['widgets.php', 'customize.php']) || $ajax)) {
         // Initialize administrator if already not done that.
         $this->initialiseGantry();
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号