本文整理汇总了PHP中Bolt\Library类的典型用法代码示例。如果您正苦于以下问题:PHP Library类的具体用法?PHP Library怎么用?PHP Library使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Library类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: edit_post_link
/**
* Stub for edit_post_link.
*/
function edit_post_link($text = null, $before = '', $after = '', $id = 0)
{
global $post, $currentuser;
if (!is_object($post) || empty($currentuser['username'])) {
return;
}
$path = \Bolt\Library::path('editcontent', ['contenttypeslug' => $post->contenttype['slug'], 'id' => $post['id']]);
if (null === $text) {
$text = __('Edit This');
}
$link = '<a class="post-edit-link" href="' . $path . '">' . $text . '</a>';
/**
* Filter the post edit link anchor tag.
*
* @since 2.3.0
*
* @param string $link Anchor tag for the edit link.
* @param int $post_id Post ID.
* @param string $text Anchor text.
*/
echo $before . apply_filters('edit_post_link', $link, $post['id'], $text) . $after;
}
开发者ID:bobdenotter,项目名称:wordpress-theme,代码行数:25,代码来源:wp-functions.php
示例2: slugTreeRecord
public function slugTreeRecord($slug)
{
// Add snippets, since this is a Frontend route.
$this->app['htmlsnippets'] = true;
if (strripos($slug, '/')) {
// find the last "/"" in the slug
//dump($slug);
// dump($this->app['config']);
// dump($this->app['config']->get('data/contenttypes'));
// dump($this->app['config']->get('general/homepage_template'));
// dump(strripos($slug, '/') == strlen($slug));
// dump(strripos($slug, '/'));
// dump(strlen($slug));
$slug = rtrim($slug, '/');
if (in_array($slug, array('blogs', 'locations', 'structures', 'pages', 'blogposts', 'jobs', 'events', 'persons', 'network', 'publications', 'pressreleases', 'projects', 'taskforces', 'homepage', 'footers'))) {
switch ($slug) {
case 'blogs':
//dump('redirect blogs');
\Bolt\Library::simpleredirect('/blogposts');
die;
break;
default:
\Bolt\Library::simpleredirect('/' . $slug);
die;
break;
}
}
}
// $slug = \Bolt\Helpers\String::slug($slug, -1);
$slug = $this->app['slugify']->slugify($slug);
$contenttype = $this->getContenttypeBySlug($slug, true);
$frontend = new Bolt\Controllers\Frontend();
return $frontend->record($this->app, $contenttype, $slug);
}
开发者ID:simnom,项目名称:Europeana-Professional,代码行数:34,代码来源:Extension.php
示例3: testSimpleRedirectAbort
/**
* @runInSeparateProcess
*/
public function testSimpleRedirectAbort()
{
$app = $this->getApp();
$this->setExpectedException('Symfony\\Component\\HttpKernel\\Exception\\HttpException', "Redirecting to '/test2'.");
$this->expectOutputString("<p>Redirecting to <a href='/test2'>/test2</a>.</p><script>window.setTimeout(function () { window.location='/test2'; }, 500);</script>");
$redirect = Library::simpleredirect('/test2', true);
}
开发者ID:robbert-vdh,项目名称:bolt,代码行数:10,代码来源:BoltLibraryTest.php
示例4: testBadLoadSerializeFails
public function testBadLoadSerializeFails()
{
$file = PHPUNIT_ROOT . '/resources/data.php';
$data = "\n\n" . 'string';
file_put_contents($file, $data);
$data = Library::loadSerialize($file);
$this->assertFalse($data);
unlink($file);
}
开发者ID:johndotcat,项目名称:bolt,代码行数:9,代码来源:BoltLibraryTest.php
示例5: beforeCallback
/**
* beforeCallback.
*
* This callback adds the CSS/JS for the localeswitcher on the backend
* and checks that we are on a valid locale when on the frontend
*/
public function beforeCallback(Request $request)
{
$routeParams = $request->get('_route_params');
if ($this->app['config']->getWhichEnd() == 'backend') {
if (array_key_exists('contenttypeslug', $routeParams)) {
$this->addCss('assets/css/field_locale.css');
if (!empty($routeParams['id'])) {
$this->addJavascript('assets/js/field_locale.js', array('late' => true));
}
}
} else {
if (isset($routeParams['_locale'])) {
$this->app['menu'] = $this->app->share(function ($app) {
$builder = new Menu\LocalizedMenuBuilder($app);
return $builder;
});
$locales = $this->app['config']->get('general/locales');
foreach ($locales as $isolocale => $locale) {
if ($locale['slug'] == $routeParams['_locale']) {
$foundLocale = $isolocale;
}
}
if (isset($foundLocale)) {
setlocale(LC_ALL, $foundLocale);
$this->app['config']->set('general/locale', $foundLocale);
} else {
$routeParams['_locale'] = reset($locales)['slug'];
return $this->app->redirect(Lib::path($request->get('_route'), $routeParams));
}
}
}
}
开发者ID:evertalbers,项目名称:bolt-translate,代码行数:38,代码来源:Extension.php
示例6: addResources
/**
* Adds all resources that belong to a locale.
*
* @param Application $app
* @param string $locale
*/
public static function addResources(Application $app, $locale)
{
// Directories to look for translation file(s)
$transDirs = array_unique([$app['resources']->getPath("app/resources/translations/{$locale}"), $app['resources']->getPath("root/app/resources/translations/{$locale}")]);
$needsSecondPass = true;
foreach ($transDirs as $transDir) {
if (!is_dir($transDir) || !is_readable($transDir)) {
continue;
}
$iterator = new \DirectoryIterator($transDir);
/**
* @var \SplFileInfo $fileInfo
*/
foreach ($iterator as $fileInfo) {
$ext = Lib::getExtension((string) $fileInfo);
if (!$fileInfo->isFile() || !in_array($ext, ['yml', 'xlf'], true)) {
continue;
}
list($domain) = explode('.', $fileInfo->getFilename());
$app['translator']->addResource($ext, $fileInfo->getRealPath(), $locale, $domain);
$needsSecondPass = false;
}
}
if ($needsSecondPass && strlen($locale) === 5) {
static::addResources($app, substr($locale, 0, 2));
}
}
开发者ID:nuffer,项目名称:bolt,代码行数:33,代码来源:TranslationServiceProvider.php
示例7: patchTranslationPath
public function patchTranslationPath()
{
# workaround for Bolt 2.2 - fix in master (3.0), see #3553 and #3800
// $app->before(function() use ($app) {
// $path = $app['resources']->getPath('root/app/resources/translations');
// $app['translator']->addResource('yml', $path.'/contenttypes.de_DE.yml', 'de_DE', 'contenttypes');
// });
if ("Bolt\\Configuration\\Composer" != get_class($this->app['resources'])) {
return;
}
// $versionParser = new \Composer\Package\Version\VersionParser();
// $version = $versionParser->parseConstraints($app['bolt_version']);
// print_r($version);
// Directory to look for translation file(s)
$transDir = $this->app['resources']->getPath('root/app/resources/translations/' . $this->app['locale']);
if (is_dir($transDir)) {
$iterator = new \DirectoryIterator($transDir);
/**
* @var \SplFileInfo $fileInfo
*/
foreach ($iterator as $fileInfo) {
$ext = Lib::getExtension((string) $fileInfo);
if (!$fileInfo->isFile() || !in_array($ext, array('yml', 'xlf'))) {
continue;
}
list($domain) = explode('.', $fileInfo->getFilename());
$this->app['translator']->addResource($ext, $transDir . '/' . $fileInfo->getFilename(), $this->app['locale'], $domain);
}
}
}
开发者ID:nikgo,项目名称:bolt-extension-nikgo-extra,代码行数:30,代码来源:ExtraExtensions.php
示例8: handle
public function handle($path)
{
$files = [];
$folders = [];
$list = $this->filesystem->listContents($path);
$ignored = ['.', '..', '.DS_Store', '.gitignore', '.htaccess'];
foreach ($list as $entry) {
if (in_array($entry['basename'], $ignored)) {
continue;
}
if (!$this->filesystem->authorized($entry['path'])) {
continue;
}
if ($entry['type'] === 'file') {
try {
$url = $this->filesystem->url($entry['path']);
} catch (\Exception $e) {
$url = $entry['path'];
}
// Ugh, for some reason the foldername for the theme is included twice. Why?
// For now we 'fix' this with an ugly hack, replacing it. :-/
// TODO: dig into Filesystem and figure out why this happens.
$pathsegments = explode('/', $entry['path']);
if (!empty($pathsegments[0])) {
$url = str_replace('/' . $pathsegments[0] . '/' . $pathsegments[0] . '/', '/' . $pathsegments[0] . '/', $url);
}
$files[$entry['path']] = ['path' => $entry['dirname'], 'filename' => $entry['basename'], 'newpath' => $entry['path'], 'relativepath' => $entry['path'], 'writable' => true, 'readable' => false, 'type' => isset($entry['extension']) ? $entry['extension'] : '', 'filesize' => Lib::formatFilesize($entry['size']), 'modified' => date("Y/m/d H:i:s", $entry['timestamp']), 'permissions' => 'public', 'url' => $url];
/* **** Extra checks for files that can be resolved via PHP urlopen functions **** */
try {
$files[$entry['path']]['permissions'] = $this->filesystem->getVisibility($entry['path']);
} catch (\Exception $e) {
// Computer says "No!"
}
$fullfilename = $this->filesystem->getAdapter()->applyPathPrefix($entry['path']);
if (is_readable($fullfilename)) {
$files[$entry['path']]['readable'] = true;
if (!empty($entry['extension']) && in_array($entry['extension'], ['gif', 'jpg', 'png', 'jpeg'])) {
$size = getimagesize($fullfilename);
$files[$entry['path']]['imagesize'] = sprintf("%s × %s", $size[0], $size[1]);
}
$files[$entry['path']]['permissions'] = util::full_permissions($fullfilename);
}
}
if ($entry['type'] == 'dir') {
$folders[$entry['path']] = ['path' => $entry['dirname'], 'foldername' => $entry['basename'], 'newpath' => $entry['path'], 'modified' => date("Y/m/d H:i:s", $entry['timestamp']), 'writable' => true];
$fullfilename = $this->filesystem->getAdapter()->applyPathPrefix($entry['path']);
/* **** Extra checks for files that can be resolved via PHP urlopen functions **** */
if (is_readable($fullfilename)) {
if (!is_writable($fullfilename)) {
$folders[$entry['path']]['writable'] = false;
}
}
}
}
ksort($files);
ksort($folders);
return [$files, $folders];
}
开发者ID:Twiebie,项目名称:bolt,代码行数:58,代码来源:Browse.php
示例9: collect
/**
* Collect the date for the Toolbar item.
*
* @param Request $request
* @param Response $response
* @param \Exception $exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->data = array('version' => $this->app->getVersion(false), 'name' => $this->app['bolt_name'], 'fullversion' => 'Version: ' . $this->app->getVersion(true), 'payoff' => 'Sophisticated, lightweight & simple CMS', 'aboutlink' => sprintf("<a href=\"%s\">%s</a>", Lib::path('about'), 'About'), 'branding' => null, 'editlink' => null, 'edittitle' => null);
if ($this->app['config']->get('general/branding/provided_by/0')) {
$this->data['branding'] = sprintf("%s <a href=\"mailto:%s\">%s</a>", Trans::__('Provided by:'), $this->app['config']->get('general/branding/provided_by/0'), $this->app['config']->get('general/branding/provided_by/1'));
}
if (!empty($this->app['editlink'])) {
$this->data['editlink'] = $this->app['editlink'];
$this->data['edittitle'] = $this->app['edittitle'];
}
}
开发者ID:aleksabp,项目名称:bolt,代码行数:18,代码来源:BoltDataCollector.php
示例10: allowedUpload
/**
* Checks if a given file is acceptable for upload.
*/
public function allowedUpload($originalFilename)
{
// no UNIX-hidden files
if ($originalFilename[0] === '.') {
return false;
}
// only whitelisted extensions
$extension = strtolower(Lib::getExtension($originalFilename));
$allowedExtensions = $this->getAllowedUploadExtensions();
return in_array($extension, $allowedExtensions);
}
开发者ID:pkdevboxy,项目名称:site-v20,代码行数:14,代码来源:FilePermissions.php
示例11: image
/**
* Helper function to make a path to an image.
*
* @param string $filename Target filename
* @param string|integer $width Target width
* @param string|integer $height Target height
* @param string $crop String identifier for cropped images
*
* @return string Image path
*/
public function image($filename, $width = '', $height = '', $crop = '')
{
if ($width != '' || $height != '') {
// You don't want the image, you just want a thumbnail.
return $this->thumbnail($filename, $width, $height, $crop);
}
// After v1.5.1 we store image data as an array
if (is_array($filename)) {
$filename = isset($filename['filename']) ? $filename['filename'] : $filename['file'];
}
$image = sprintf('%sfiles/%s', $this->app['paths']['root'], Lib::safeFilename($filename));
return $image;
}
开发者ID:aaleksu,项目名称:bolt_cm,代码行数:23,代码来源:ImageHandler.php
示例12: image
/**
* Helper function to make a path to an image.
*
* @param string $filename Target filename
* @param string|integer $width Target width
* @param string|integer $height Target height
* @param string $crop String identifier for cropped images
*
* @return string Image path
*/
public function image($filename, $width = null, $height = null, $crop = null)
{
if ($width || $height) {
// You don't want the image, you just want a thumbnail.
return $this->thumbnail($filename, $width, $height, $crop);
}
// After v1.5.1 we store image data as an array
if (is_array($filename)) {
$filename = isset($filename['filename']) ? $filename['filename'] : $filename['file'];
}
$image = sprintf('%s%s', $this->app['resources']->getUrl('files'), Lib::safeFilename($filename));
return $image;
}
开发者ID:draconusdesigns,项目名称:bolt,代码行数:23,代码来源:ImageHandler.php
示例13: record
public function record(\Silex\Application $app, $contenttypeslug, $slug = '')
{
$contenttype = $app['storage']->getContentType($contenttypeslug);
// If the contenttype is 'viewless', don't show the record page.
if (isset($contenttype['viewless']) && $contenttype['viewless'] === true) {
return $app->abort(Response::HTTP_NOT_FOUND, "Page {$contenttypeslug}/{$slug} not found.");
}
// Perhaps we don't have a slug. Let's see if we can pick up the 'id', instead.
if (empty($slug)) {
$slug = $app['request']->get('id');
}
$slug = $app['slugify']->slugify($slug);
// First, try to get it by slug.
$content = $app['storage']->getContent($contenttype['slug'], array('slug' => $slug, 'returnsingle' => true, 'log_not_found' => !is_numeric($slug)));
if (!$content && !is_numeric($slug)) {
// And otherwise try getting it by translated slugs
$match = $this->matchTranslatedSlug($app, $contenttype['slug'], $slug);
if (!empty($match)) {
$content = $app['storage']->getContent($contenttype['slug'], array('id' => $match['content_type_id'], 'returnsingle' => true));
}
}
if (!$content && is_numeric($slug)) {
// And otherwise try getting it by ID
$content = $app['storage']->getContent($contenttype['slug'], array('id' => $slug, 'returnsingle' => true));
}
// No content, no page!
if (!$content) {
return $app->abort(Response::HTTP_NOT_FOUND, "Page {$contenttypeslug}/{$slug} not found.");
}
// Then, select which template to use, based on our 'cascading templates rules'
$template = $app['templatechooser']->record($content);
$paths = $app['resources']->getPaths();
// Setting the canonical URL.
if ($content->isHome() && $template == $app['config']->get('general/homepage_template')) {
$app['resources']->setUrl('canonicalurl', $paths['rooturl']);
} else {
$url = $paths['canonical'] . $content->link();
$app['resources']->setUrl('canonicalurl', $url);
}
// Setting the editlink
$app['editlink'] = Lib::path('editcontent', array('contenttypeslug' => $contenttype['slug'], 'id' => $content->id));
$app['edittitle'] = $content->getTitle();
// Make sure we can also access it as {{ page.title }} for pages, etc. We set these in the global scope,
// So that they're also available in menu's and templates rendered by extensions.
$app['twig']->addGlobal('record', $content);
$app['twig']->addGlobal($contenttype['singular_slug'], $content);
// Render the template and return.
return $this->render($app, $template, $content->getTitle());
}
开发者ID:evertalbers,项目名称:bolt-translate,代码行数:49,代码来源:LocalizedFrontend.php
示例14: menuHelper
/**
* Updates a menu item to have at least a 'link' key.
*
* @param array $item
*
* @return array Keys 'link' and possibly 'label', 'title' and 'path'
*/
private function menuHelper($item)
{
// recurse into submenu's
if (isset($item['submenu']) && is_array($item['submenu'])) {
$item['submenu'] = $this->menuHelper($item['submenu']);
}
if (isset($item['route'])) {
$param = !empty($item['param']) ?: array();
$add = !empty($item['add']) ?: '';
$item['link'] = Lib::path($item['route'], $param, $add);
} elseif (isset($item['path'])) {
$item = $this->resolvePathToContent($item);
}
return $item;
}
开发者ID:aleksabp,项目名称:bolt,代码行数:22,代码来源:MenuBuilder.php
示例15: before
/**
* Middleware function to check whether a user is logged on.
*
* @param Request $request
* @param \Silex\Application $app
*
* @return null|\Symfony\Component\HttpFoundation\RedirectResponse
*/
public function before(Request $request, Silex\Application $app)
{
// This disallows extensions from adding any extra snippets to the output
if ($request->get("_route") !== 'extend') {
$app['htmlsnippets'] = false;
}
// Start the 'stopwatch' for the profiler.
$app['stopwatch']->start('bolt.backend.before');
// Most of the 'check if user is allowed' happens here: match the current route to the 'allowed' settings.
if (!$app['users']->isAllowed('extensions')) {
$app['session']->getFlashBag()->add('error', Trans::__('You do not have the right privileges to view that page.'));
return Lib::redirect('dashboard');
}
// Stop the 'stopwatch' for the profiler.
$app['stopwatch']->stop('bolt.backend.before');
return null;
}
开发者ID:realitygaps,项目名称:site-v20,代码行数:25,代码来源:Extend.php
示例16: collect
/**
* Collect information from Twig.
*
* @param Request $request The Request Object
* @param Response $response The Response Object
* @param \Exception $exception The Exception
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$filters = array();
$tests = array();
$extensions = array();
$functions = array();
foreach ($this->getTwig()->getExtensions() as $extensionName => $extension) {
/** @var $extension \Twig_ExtensionInterface */
$extensions[] = array('name' => $extensionName, 'class' => get_class($extension));
foreach ($extension->getFilters() as $filterName => $filter) {
if ($filter instanceof \Twig_FilterInterface) {
$call = $filter->compile();
if (is_array($call) && is_callable($call)) {
$call = 'Method ' . $call[1] . ' of an object ' . get_class($call[0]);
}
} elseif ($filter instanceof \Twig_SimpleFilter) {
$call = $filter->getName();
} else {
continue;
}
$filters[] = array('name' => $filterName, 'extension' => $extensionName, 'call' => $call);
}
foreach ($extension->getTests() as $testName => $test) {
if ($test instanceof \Twig_TestInterface) {
$call = $test->compile();
} elseif ($test instanceof \Twig_SimpleTest) {
$call = $test->getName();
} else {
continue;
}
$tests[] = array('name' => $testName, 'extension' => $extensionName, 'call' => $call);
}
foreach ($extension->getFunctions() as $functionName => $function) {
if ($function instanceof \Twig_FunctionInterface) {
$call = $function->compile();
} elseif ($function instanceof \Twig_SimpleFunction) {
$call = $function->getName();
} else {
continue;
}
$functions[] = array('name' => $functionName, 'extension' => $extensionName, 'call' => $call);
}
}
$this->data = array('extensions' => $extensions, 'tests' => $tests, 'filters' => $filters, 'functions' => $functions, 'templates' => Lib::parseTwigTemplates($this->app['twig.loader']), 'templatechosen' => $this->getTrackedValue('templatechosen'), 'templateerror' => $this->getTrackedValue('templateerror'));
}
开发者ID:aleksabp,项目名称:bolt,代码行数:52,代码来源:TwigDataCollector.php
示例17: addResources
/**
* Adds all resources that belong to a locale.
*
* @param Application $app
* @param string $locale
*/
public static function addResources(Application $app, $locale)
{
// Directory to look for translation file(s)
$transDir = $app['resources']->getPath('app/resources/translations/' . $locale);
if (is_dir($transDir)) {
$iterator = new \DirectoryIterator($transDir);
/**
* @var \SplFileInfo $fileInfo
*/
foreach ($iterator as $fileInfo) {
$ext = Lib::getExtension((string) $fileInfo);
if (!$fileInfo->isFile() || !in_array($ext, ['yml', 'xlf'])) {
continue;
}
list($domain) = explode('.', $fileInfo->getFilename());
$app['translator']->addResource($ext, $fileInfo->getRealPath(), $locale, $domain);
}
} elseif (strlen($locale) == 5) {
static::addResources($app, substr($locale, 0, 2));
}
}
开发者ID:jkaan,项目名称:timOnlineBolt,代码行数:27,代码来源:TranslationServiceProvider.php
示例18: edit
/**
* File editor.
*
* @param Request $request The Symfony Request
* @param string $namespace The filesystem namespace
* @param string $file The file path
*
* @return \Bolt\Response\BoltResponse|\Symfony\Component\HttpFoundation\RedirectResponse
*/
public function edit(Request $request, $namespace, $file)
{
if ($namespace === 'app' && dirname($file) === 'config') {
// Special case: If requesting one of the major config files, like contenttypes.yml, set the path to the
// correct dir, which might be 'app/config', but it might be something else.
$namespace = 'config';
}
/** @var FilesystemInterface $filesystem */
$filesystem = $this->filesystem()->getFilesystem($namespace);
if (!$filesystem->authorized($file)) {
$error = Trans::__('general.phrase.access-denied-permissions-edit-file', ['%s' => $file]);
$this->abort(Response::HTTP_FORBIDDEN, $error);
}
try {
/** @var File $file */
$file = $filesystem->get($file);
$type = Lib::getExtension($file->getPath());
$data = ['contents' => $file->read()];
} catch (FileNotFoundException $e) {
$error = Trans::__('general.phrase.file-not-exist', ['%s' => $file->getPath()]);
$this->abort(Response::HTTP_NOT_FOUND, $error);
} catch (IOException $e) {
$error = Trans::__('general.phrase.file-not-readable', ['%s' => $file->getPath()]);
$this->abort(Response::HTTP_NOT_FOUND, $error);
}
/** @var Form $form */
$form = $this->createFormBuilder(FormType::class, $data)->add('contents', TextareaType::class)->getForm();
// Handle the POST and check if it's valid.
if ($request->isMethod('POST')) {
return $this->handleEdit($request, $form, $file, $type);
}
// For 'related' files we might need to keep track of the current dirname on top of the namespace.
if (dirname($file->getPath()) !== '') {
$additionalpath = dirname($file->getPath()) . '/';
} else {
$additionalpath = '';
}
$context = ['form' => $form->createView(), 'filetype' => $type, 'file' => $file->getPath(), 'basename' => basename($file->getPath()), 'pathsegments' => $this->getPathSegments(dirname($file->getPath())), 'additionalpath' => $additionalpath, 'namespace' => $namespace, 'write_allowed' => true, 'filegroup' => $this->getFileGroup($filesystem, $file), 'datechanged' => date_format(new \DateTime('@' . $file->getTimestamp()), 'c')];
return $this->render('@bolt/editfile/editfile.twig', $context);
}
开发者ID:robbert-vdh,项目名称:bolt,代码行数:49,代码来源:FileManager.php
示例19: passwordForm
/**
* Show the password form. If the visitor gives the correct password, they
* are redirected to the page they came from, if any.
*
* @return \Twig_Markup
*/
public function passwordForm()
{
// Set up the form.
$form = $this->app['form.factory']->createBuilder('form');
if ($this->config['password_only'] == false) {
$form->add('username', 'text');
}
$form->add('password', 'password');
$form = $form->getForm();
if ($this->app['request']->getMethod() == 'POST') {
$form->bind($this->app['request']);
$data = $form->getData();
if ($form->isValid() && $this->checkLogin($data)) {
// Set the session var, so we're authenticated..
$this->app['session']->set('passwordprotect', 1);
$this->app['session']->set('passwordprotect_name', $this->checkLogin($data));
// Print a friendly message..
printf("<p class='message-correct'>%s</p>", $this->config['message_correct']);
$returnto = $this->app['request']->get('returnto');
// And back we go, to the page we originally came from..
if (!empty($returnto)) {
Lib::simpleredirect($returnto);
die;
}
} else {
// Remove the session var, so we can test 'logging off'..
$this->app['session']->remove('passwordprotect');
$this->app['session']->remove('passwordprotect_name');
// Print a friendly message..
if (!empty($data['password'])) {
printf("<p class='message-wrong'>%s</p>", $this->config['message_wrong']);
}
}
}
// Render the form, and show it it the visitor.
$this->app['twig.loader.filesystem']->addPath(__DIR__);
$html = $this->app['twig']->render('assets/passwordform.twig', array('form' => $form->createView()));
return new \Twig_Markup($html, 'UTF-8');
}
开发者ID:jmcmullen,项目名称:PasswordProtect,代码行数:45,代码来源:Extension.php
示例20: edit
/**
* File editor.
*
* @param Request $request The Symfony Request
* @param string $namespace The filesystem namespace
* @param string $file The file path
*
* @return \Bolt\Response\BoltResponse|\Symfony\Component\HttpFoundation\RedirectResponse
*/
public function edit(Request $request, $namespace, $file)
{
if ($namespace === 'app' && dirname($file) === 'config') {
// Special case: If requesting one of the major config files, like contenttypes.yml, set the path to the
// correct dir, which might be 'app/config', but it might be something else.
$namespace = 'config';
}
/** @var FilesystemInterface $filesystem */
$filesystem = $this->filesystem()->getFilesystem($namespace);
if (!$filesystem->authorized($file)) {
$error = Trans::__("You don't have correct permissions to edit the file '%s'.", ['%s' => $file]);
$this->abort(Response::HTTP_FORBIDDEN, $error);
}
/** @var File $file */
$file = $filesystem->get($file);
$type = Lib::getExtension($file->getPath());
$contents = null;
if (!$file->exists() || !($contents = $file->read())) {
$error = Trans::__("The file '%s' doesn't exist, or is not readable.", ['%s' => $file->getPath()]);
$this->abort(Response::HTTP_NOT_FOUND, $error);
}
$writeallowed = $this->isWriteable($file);
$data = ['contents' => $contents];
/** @var Form $form */
$form = $this->createFormBuilder('form', $data)->add('contents', 'textarea')->getForm();
// Handle the POST and check if it's valid.
if ($request->isMethod('POST')) {
return $this->handleEdit($request, $form, $file, $type);
}
// For 'related' files we might need to keep track of the current dirname on top of the namespace.
if (dirname($file->getPath()) !== '') {
$additionalpath = dirname($file->getPath()) . '/';
} else {
$additionalpath = '';
}
$context = ['form' => $form->createView(), 'filetype' => $type, 'file' => $file->getPath(), 'basename' => basename($file->getPath()), 'pathsegments' => $this->getPathSegments(dirname($file->getPath())), 'additionalpath' => $additionalpath, 'namespace' => $namespace, 'write_allowed' => $writeallowed, 'filegroup' => $this->getFileGroup($filesystem, $file), 'datechanged' => date_format(new \DateTime('@' . $file->getTimestamp()), 'c')];
return $this->render('@bolt/editfile/editfile.twig', $context);
}
开发者ID:nuffer,项目名称:bolt,代码行数:47,代码来源:FileManager.php
注:本文中的Bolt\Library类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论