/** * Translate Array * * @param $key * @param $index * @param null $languages * @param bool $html_out * * @return string */ public function translateArray($key, $index, $languages = null, $html_out = false) { if ($this->config->get('system.languages.translations', true)) { if ($this->enabled() && $key) { if (empty($languages)) { if ($this->config->get('system.languages.translations_fallback', true)) { $languages = $this->getFallbackLanguages(); } else { $languages = (array) $this->getDefault(); } } } else { $languages = ['en']; } foreach ((array) $languages as $lang) { $translation_array = (array) Grav::instance()['languages']->get($lang . '.' . $key, null); if ($translation_array && array_key_exists($index, $translation_array)) { return $translation_array[$index]; } } } if ($html_out) { return '<span class="untranslated">' . $key . '[' . $index . ']</span>'; } else { return $key . '[' . $index . ']'; } }
/** * Merge global and page configurations. * * @param Page $page The page to merge the configurations with the * plugin settings. * * @param bool $deep Should you use deep or shallow merging * * @return \Grav\Common\Data\Data */ protected function mergeConfig(Page $page, $deep = false) { $class_name = $this->name; $class_name_merged = $class_name . '.merged'; $defaults = $this->config->get('plugins.' . $class_name, array()); $header = array(); if (isset($page->header()->{$class_name_merged})) { $merged = $page->header()->{$class_name_merged}; if (count($merged) > 0) { return $merged; } else { return new Data($defaults); } } // Get default plugin configurations and retrieve page header configuration if (isset($page->header()->{$class_name})) { if ($deep) { $header = array_replace_recursive($defaults, $page->header()->{$class_name}); } else { $header = array_merge($defaults, $page->header()->{$class_name}); } } else { $header = $defaults; } // Create new config object and set it on the page object so it's cached for next time $config = new Data($header); $page->modifyHeader($class_name_merged, $config); // Return configurations as a new data config class return $config; }
/** * Stop the named timer * * @param string $name * * @return $this */ public function stopTimer($name) { if (in_array($name, $this->timers) && ($name[0] == '_' || $this->config->get('system.debugger.enabled'))) { $this->debugbar['time']->stopMeasure($name); } return $this; }
/** * Retrieve the cache lifetime (in seconds) * * @return mixed */ public function getLifetime() { if ($this->lifetime === null) { $this->lifetime = $this->config->get('system.cache.lifetime') ?: 604800; // 1 week default } return $this->lifetime; }
public function testInvalidLinksSubDirAbsoluteUrl() { $this->config->set('system.absolute_urls', true); $this->uri->initializeWithUrlAndRootPath('http://testing.dev/subdir/item2/item2-2', '/subdir')->init(); $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/no-page">Non Existent Page</a></p>', $this->parsedown->text('[Non Existent Page](no-page)')); $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/existing-file.zip">Existent File</a></p>', $this->parsedown->text('[Existent File](existing-file.zip)')); $this->assertSame('<p><a href="http://testing.dev/subdir/item2/item2-2/missing-file.zip">Non Existent File</a></p>', $this->parsedown->text('[Non Existent File](missing-file.zip)')); }
/** * @param string $ip */ protected function updateVisitors($ip) { if (!$this->visitors_data) { $this->visitors_data = $this->getData($this->visitors_file); } // update with current timestamp $this->visitors_data[$ip] = time(); $visitors = $this->visitors_data; arsort($visitors); $count = intval($this->config->get('plugins.admin.popularity.history.visitors', 20)); $this->visitors_data = array_slice($visitors, 0, $count, true); file_put_contents($this->visitors_file, json_encode($this->visitors_data)); }
/** * Merge global and page configurations. * * @param Page $page The page to merge the configurations with the * plugin settings. * @param bool $deep Should you use deep or shallow merging * @param array $params Array of additional configuration options to * merge with the plugin settings. * * @return \Grav\Common\Data\Data */ protected function mergeConfig(Page $page, $deep = false, $params = []) { $class_name = $this->name; $class_name_merged = $class_name . '.merged'; $defaults = $this->config->get('plugins.' . $class_name, []); $page_header = $page->header(); $header = []; if (!isset($page_header->{$class_name_merged}) && isset($page_header->{$class_name})) { // Get default plugin configurations and retrieve page header configuration $config = $page_header->{$class_name}; if (is_bool($config)) { // Overwrite enabled option with boolean value in page header $config = ['enabled' => $config]; } // Merge page header settings using deep or shallow merging technique if ($deep) { $header = array_replace_recursive($defaults, $config); } else { $header = array_merge($defaults, $config); } // Create new config object and set it on the page object so it's cached for next time $page->modifyHeader($class_name_merged, new Data($header)); } else { if (isset($page_header->{$class_name_merged})) { $merged = $page_header->{$class_name_merged}; $header = $merged->toArray(); } } if (empty($header)) { $header = $defaults; } // Merge additional parameter with configuration options if ($deep) { $header = array_replace_recursive($header, $params); } else { $header = array_merge($header, $params); } // Return configurations as a new data config class return new Data($header); }
/** * Handle the email to activate the user account. * * @param User $user * * @return bool True if the action was performed. */ public function sendActivationEmail($user) { if (empty($user->email)) { throw new \RuntimeException($this->grav['language']->translate('PLUGIN_LOGIN.USER_NEEDS_EMAIL_FIELD')); } $token = md5(uniqid(mt_rand(), true)); $expire = time() + 604800; // next week $user->activation_token = $token . '::' . $expire; $user->save(); $param_sep = $this->grav['config']->get('system.param_sep', ':'); $activation_link = $this->grav['base_url_absolute'] . $this->config->get('plugins.login.route_activate') . '/token' . $param_sep . $token . '/username' . $param_sep . $user->username . '/nonce' . $param_sep . Utils::getNonce('user-activation'); $site_name = $this->grav['config']->get('site.title', 'Website'); $subject = $this->grav['language']->translate(['PLUGIN_LOGIN.ACTIVATION_EMAIL_SUBJECT', $site_name]); $content = $this->grav['language']->translate(['PLUGIN_LOGIN.ACTIVATION_EMAIL_BODY', $user->username, $activation_link, $site_name]); $to = $user->email; $sent = EmailUtils::sendEmail($subject, $content, $to); if ($sent < 1) { throw new \RuntimeException($this->grav['language']->translate('PLUGIN_LOGIN.EMAIL_SENDING_FAILURE')); } return true; }
protected function loadConfiguration($name, Config $config) { $themeConfig = CompiledYamlFile::instance("themes://{$name}/{$name}" . YAML_EXT)->content(); $config->joinDefaults("themes.{$name}", $themeConfig); }
protected function loadConfiguration($name, Config $config) { $themeConfig = CompiledYamlFile::instance("themes://{$name}/{$name}" . YAML_EXT)->content(); $config->joinDefaults("themes.{$name}", $themeConfig); if ($this->config->get('system.languages.translations', true)) { $languages = CompiledYamlFile::instance("themes://{$name}/languages" . YAML_EXT)->content(); if ($languages) { $config->getLanguages()->mergeRecursive($languages); } } }
protected function _after() { $this->config->set('system.home.alias', $this->old_home); }
/** * Load theme languages. * * @param Config $config Configuration class */ protected function loadLanguages(Config $config) { /** @var UniformResourceLocator $locator */ $locator = $this->grav['locator']; if ($config->get('system.languages.translations', true)) { $languageFiles = array_reverse($locator->findResources("theme://languages" . YAML_EXT)); $languages = []; foreach ($languageFiles as $language) { $languages[] = CompiledYamlFile::instance($language)->content(); } if ($languages) { $languages = call_user_func_array('array_replace_recursive', $languages); $this->grav['languages']->mergeRecursive($languages); } } }
/** * Load theme languages. * * @param Config $config Configuration class */ protected function loadLanguages(Config $config) { /** @var UniformResourceLocator $locator */ $locator = $this->grav['locator']; if ($config->get('system.languages.translations', true)) { $language_file = $locator->findResource("theme://languages" . YAML_EXT); if ($language_file) { $language = CompiledYamlFile::instance($language_file)->content(); $this->grav['languages']->mergeRecursive($language); } $languages_folder = $locator->findResource("theme://languages/"); if (file_exists($languages_folder)) { $languages = []; $iterator = new \DirectoryIterator($languages_folder); /** @var \DirectoryIterator $directory */ foreach ($iterator as $file) { if ($file->getExtension() != 'yaml') { continue; } $languages[$file->getBasename('.yaml')] = CompiledYamlFile::instance($file->getPathname())->content(); } $this->grav['languages']->mergeRecursive($languages); } } }