本文整理汇总了PHP中aTools类的典型用法代码示例。如果您正苦于以下问题:PHP aTools类的具体用法?PHP aTools怎么用?PHP aTools使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了aTools类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: preExecute
public static function preExecute($actions)
{
$request = $actions->getRequest();
// Figure out where we are all over again, because there seems to be no clean way
// to get the same controller-free URL that the routing engine gets. TODO:
// ask Fabien how we can do that.
$uri = $actions->getRequest()->getUri();
$uriPrefix = $actions->getRequest()->getUriPrefix();
$uri = substr($uri, strlen($uriPrefix));
if (preg_match("/^\\/[^\\/]+\\.php(.*)\$/", $uri, $matches)) {
$uri = $matches[1];
}
// This will quickly fetch a result that was already cached when we
// ran through the routing table (unless we hit the routing table cache,
// in which case we're looking it up for the first time, also OK)
$page = aPageTable::getMatchingEnginePage($uri, $remainder);
if (!$page) {
throw new sfException('Attempt to access engine action without a page');
}
$page = aPageTable::retrieveByIdWithSlots($page->id);
// We want to do these things the same way executeShow would
aTools::validatePageAccess($actions, $page);
aTools::setPageEnvironment($actions, $page);
// Convenient access to the current page for the subclass
$actions->page = $page;
}
示例2: getGlobalButtons
/**
* You too can do this in a plugin dependent on a, see the provided stylesheet
* for how to correctly specify an icon to go with your button. See the
* apostrophePluginConfiguration class for the registration of the event listener.
*/
public static function getGlobalButtons()
{
// Only if we have suitable credentials
if (aMediaTools::userHasUploadPrivilege()) {
aTools::addGlobalButtons(array(new aGlobalButton('media', 'Media', 'aMedia/index', 'a-media', '/admin/media', 'aMedia')));
}
}
示例3: getGlobalButtons
public static function getGlobalButtons()
{
$user = sfContext::getInstance()->getUser();
if ($user->hasCredential('admin')) {
aTools::addGlobalButtons(array(new aGlobalButton('polls', 'Polls', '@a_poll_poll_admin', 'a-poll')));
}
}
示例4: getGlobalButtons
public static function getGlobalButtons()
{
$user = sfContext::getInstance()->getUser();
if ($user->hasCredential('blog_author') || $user->hasCredential('blog_admin')) {
aTools::addGlobalButtons(array(new aGlobalButton('blog', 'Blog', '@a_blog_admin', 'a-blog-btn'), new aGlobalButton('events', 'Events', '@a_event_admin', 'a-events day-' . date('j'))));
}
}
示例5: __construct
/**
* DOCUMENT ME
* @param mixed $root
* @param mixed $active
* @param mixed $options
*/
public function __construct($root, $active, $options = array())
{
$this->user = sfContext::getInstance()->getUser();
$this->livingOnly = !(aTools::isPotentialEditor() && sfContext::getInstance()->getUser()->getAttribute('show-archived', true, 'apostrophe'));
$this->root = $root;
$this->active = $active;
$this->options = $options;
$this->buildNavigation();
}
示例6: getGlobalButtons
public static function getGlobalButtons()
{
$mediaEnginePage = aPageTable::retrieveBySlug('/admin/media');
// Only if we have suitable credentials
$user = sfContext::getInstance()->getUser();
if ($user->hasCredential('media_admin') || $user->hasCredential('media_upload')) {
aTools::addGlobalButtons(array(new aGlobalButton('media', 'Media', 'aMedia/index', 'a-media', $mediaEnginePage)));
}
}
示例7: configure
public function configure()
{
parent::configure();
// We must explicitly limit the fields because otherwise tables with foreign key relationships
// to the pages table will extend the form whether it's appropriate or not. If you want to do
// those things on behalf of an engine used in some pages, define a form class called
// enginemodulenameEngineForm. It will automatically be instantiated with the engine page
// as an argument to the constructor, and rendered beneath the main page settings form.
// On submit, it will be bound to the parameter name that begins its name format and, if valid,
// saved consecutively after the main page settings form. The form will be rendered via
// the _renderPageSettingsForm partial in your engine module, which must exist, although it
// can be as simple as echo $form. (Your form is passed to the partial as $form.)
//
// We would use embedded forms if we could. Unfortunately Symfony has unresolved bugs relating
// to one-to-many relations in embedded forms.
$this->useFields(array('slug', 'template', 'engine', 'archived', 'view_is_secure'));
unset($this['author_id'], $this['deleter_id'], $this['Accesses'], $this['created_at'], $this['updated_at'], $this['view_credentials'], $this['edit_credentials'], $this['lft'], $this['rgt'], $this['level']);
$this->setWidget('template', new sfWidgetFormSelect(array('choices' => aTools::getTemplates())));
$this->setWidget('engine', new sfWidgetFormSelect(array('choices' => aTools::getEngines())));
// On vs. off makes more sense to end users, but when we first
// designed this feature we had an 'archived vs. unarchived'
// approach in mind
$this->setWidget('archived', new sfWidgetFormChoice(array('expanded' => true, 'choices' => array(false => "Published", true => "Unpublished"), 'default' => false)));
if ($this->getObject()->hasChildren()) {
$this->setWidget('cascade_archived', new sfWidgetFormInputCheckbox());
$this->setValidator('cascade_archived', new sfValidatorBoolean(array('true_values' => array('true', 't', 'on', '1'), 'false_values' => array('false', 'f', 'off', '0', ' ', ''))));
$this->setWidget('cascade_view_is_secure', new sfWidgetFormInputCheckbox());
$this->setValidator('cascade_view_is_secure', new sfValidatorBoolean(array('true_values' => array('true', 't', 'on', '1'), 'false_values' => array('false', 'f', 'off', '0', ' ', ''))));
}
$this->setWidget('view_is_secure', new sfWidgetFormChoice(array('expanded' => true, 'choices' => array(false => "Public", true => "Login Required"), 'default' => false)));
$this->addPrivilegeWidget('edit', 'editors');
$this->addPrivilegeWidget('manage', 'managers');
$this->setValidator('slug', new aValidatorSlug(array('required' => true, 'allow_slashes' => true), array('required' => 'The slug cannot be empty.', 'invalid' => 'The slug must contain only slashes, letters, digits, dashes and underscores. Also, you cannot change a slug to conflict with an existing slug.')));
$this->setValidator('template', new sfValidatorChoice(array('required' => true, 'choices' => array_keys(aTools::getTemplates()))));
// Making the empty string one of the choices doesn't seem to be good enough
// unless we expressly clear 'required'
$this->setValidator('engine', new sfValidatorChoice(array('required' => false, 'choices' => array_keys(aTools::getEngines()))));
// The slug of the home page cannot change (chicken and egg problems)
if ($this->getObject()->getSlug() === '/') {
unset($this['slug']);
} else {
$this->validatorSchema->setPostValidator(new sfValidatorDoctrineUnique(array('model' => 'aPage', 'column' => 'slug'), array('invalid' => 'There is already a page with that slug.')));
}
$this->widgetSchema->setIdFormat('a_settings_%s');
$this->widgetSchema->setNameFormat('settings[%s]');
$this->widgetSchema->setFormFormatterName('list');
$user = sfContext::getInstance()->getUser();
if (!$user->hasCredential('cms_admin')) {
unset($this['editors']);
unset($this['managers']);
unset($this['slug']);
}
// We changed the form formatter name, so we have to reset the translation catalogue too
$this->widgetSchema->getFormFormatter()->setTranslationCatalogue('apostrophe');
}
示例8: retrieveOrCreateByPageIdAndName
public static function retrieveOrCreateByPageIdAndName($pageId, $name)
{
$culture = aTools::getUserCulture();
$area = Doctrine_Query::create()->from('aArea a')->where('a.page_id = ? AND a.name = ? AND a.culture = ?', array($pageId, $name, $culture))->fetchOne();
if ($area) {
return $area;
}
$area = new aArea();
$area->page_id = $pageId;
$area->name = $name;
$area->culture = $culture;
return $area;
}
示例9: populatePages
/**
* Given an array of blogItems this function will populate its virtual page
* areas with the current slot versions.
* @param aBlogItem $blogItems
*/
public static function populatePages($blogItems)
{
$pageIds = array();
foreach ($blogItems as $aBlogItem) {
$pageIds[] = $aBlogItem['page_id'];
}
if (count($pageIds)) {
$q = aPageTable::queryWithSlots();
$q->whereIn('id', $pageIds);
$pages = $q->execute();
aTools::cacheVirtualPages($pages);
}
}
示例10: preExecute
/**
* Poor man's multiple inheritance. This allows us to subclass an existing
* actions class in order to create an engine version of it. See aEngineActions
* for the call to add to your own preExecute method
* @param mixed $actions
*/
public static function preExecute($actions)
{
$request = $actions->getRequest();
// Figure out where we are all over again, because there seems to be no clean way
// to get the same controller-free URL that the routing engine gets. TODO:
// ask Fabien how we can do that.
$uri = urldecode($actions->getRequest()->getUri());
$rr = preg_quote(sfContext::getInstance()->getRequest()->getRelativeUrlRoot(), '/');
if (preg_match("/^(?:https?:\\/\\/[^\\/]+)?{$rr}(?:\\/[^\\/]+\\.php)?(.*)\$/", $uri, $matches)) {
$uri = $matches[1];
} else {
throw new sfException("Unable to parse engine URL {$uri}");
}
// This will quickly fetch a result that was already cached when we
// ran through the routing table (unless we hit the routing table cache,
// in which case we're looking it up for the first time, also OK)
$page = aPageTable::getMatchingEnginePageInfo($uri, $remainder);
if (!$page) {
throw new sfException('Attempt to access engine action without a page');
}
$page = aPageTable::retrieveByIdWithSlots($page['id']);
// We want to do these things the same way executeShow would
aTools::validatePageAccess($actions, $page);
aTools::setPageEnvironment($actions, $page);
// Convenient access to the current page for the subclass
$actions->page = $page;
// If your engine supports allowing the user to choose from several page types
// to distinguish different ways of using your engine, then you'll need to
// return the template name from your show and index actions (and perhaps
// others as appropriate). You can pull that information straight from
// $this->page->template, or you can take advantage of $this->pageTemplate which
// is ready to return as the result of an action (default has been changed
// to Success, other values have their first letter capitalized)
$templates = aTools::getTemplates();
// originalTemplate is what's in the template field of the page, except that
// nulls and empty strings from pre-1.5 Apostrophe have been converted to 'default'
// for consistency
$actions->originalTemplate = $page->template;
if (!strlen($actions->originalTemplate)) {
// Compatibility with 1.4 templates and reasonable Symfony expectations
$actions->originalTemplate = 'default';
}
// pageTemplate is suitable to return from an action. 'default' becomes 'Success'
// (the Symfony standard for a "normal" template's suffix) and other values have
// their first letter capitalized
if ($actions->originalTemplate === 'default') {
$actions->pageTemplate = 'Success';
} else {
$actions->pageTemplate = ucfirst($actions->originalTemplate);
}
}
示例11: doClean
/**
* @see sfValidatorBase
*/
protected function doClean($value)
{
$clean = (string) parent::doClean($value);
$clean = aTools::strtolower($clean);
$slugified = aTools::slugify($clean, $this->getOption('allow_slashes'));
if ($this->getOption('strict')) {
if ($slugified !== $clean) {
throw new sfValidatorError($this, 'invalid', array('value' => $value));
}
} else {
$clean = $slugified;
}
return $clean;
}
示例12: addCategory
public function addCategory($name, $blog_id, $type = 'posts')
{
$category = current($this->sql->query("SELECT * FROM a_category where name = :name", array('name' => $name)));
if ($category) {
$category_id = $category['id'];
} else {
$s = "INSERT INTO a_category (name, created_at, updated_at, slug) ";
$s .= "VALUES (:name, :created_at, :updated_at, :slug)";
$params = array('name' => $name, 'created_at' => aDate::mysql(), 'updated_at' => aDate::mysql(), 'slug' => aTools::slugify($name));
$this->sql->query($s, $params);
$category_id = $this->sql->lastInsertId();
}
$s = 'INSERT INTO a_blog_item_to_category (blog_item_id, category_id) VALUES(:blog_item_id, :category_id) ON DUPLICATE KEY UPDATE blog_item_id=blog_item_id';
$parms = array('blog_item_id' => $blog_id, 'category_id' => $category_id);
$this->sql->query($s, $parms);
return $category_id;
}
示例13: listenToRoutingLoadConfigurationEvent
public static function listenToRoutingLoadConfigurationEvent(sfEvent $event)
{
$r = $event->getSubject();
if (aMediaTools::getOption("routes_register") && in_array('aMedia', sfConfig::get('sf_enabled_modules'))) {
// Since the media plugin is now an engine, we need our own
// catch-all rule for administrative URLs in the media area.
// Prepending it first means it matches last
$r->prependRoute('a_media_other', new aRoute('/:action', array('module' => 'aMedia')));
$r->prependRoute('a_media_image_show', new aRoute('/view/:slug', array('module' => 'aMedia', 'action' => 'show'), array('slug' => '^' . aTools::getSlugRegexpFragment() . '$')));
// Allow permalinks for PDF originals
$r->prependRoute('a_media_image_original', new sfRoute(sfConfig::get('app_a_routes_media_image_original', '/uploads/media_items/:slug.original.:format'), array('module' => 'aMediaBackend', 'action' => 'original'), array('slug' => '^' . aTools::getSlugRegexpFragment() . '$', 'format' => '^(\\w+)$')));
$route = new sfRoute(sfConfig::get('app_a_routes_media_image', '/uploads/media_items/:slug.:width.:height.:resizeType.:format'), array('module' => 'aMediaBackend', 'action' => 'image'), array('slug' => '^' . aTools::getSlugRegexpFragment() . '$', 'width' => '^\\d+$', 'height' => '^\\d+$', 'resizeType' => '^\\w$', 'format' => '^(jpg|png|gif)$'));
$r->prependRoute('a_media_image', $route);
$route = new sfRoute(sfConfig::get('app_a_routes_media_image_cropped', '/uploads/media_items/:slug.:cropLeft.:cropTop.:cropWidth.:cropHeight.:width.:height.:resizeType.:format'), array('module' => 'aMediaBackend', 'action' => 'image'), array('slug' => '^' . aTools::getSlugRegexpFragment() . '$', 'width' => '^\\d+$', 'height' => '^\\d+$', 'cropLeft' => '^\\d+$', 'cropTop' => '^\\d+$', 'cropWidth' => '^\\d+$', 'cropHeight' => '^\\d+$', 'resizeType' => '^\\w$', 'format' => '^(jpg|png|gif)$'));
$r->prependRoute('a_media_image_cropped', $route);
// What we want:
// /media <-- everything
// /image <-- media of type image
// /video <-- media of type video
// /tag/tagname <-- media with this tag
// /image/tag/tagname <-- images with this tag
// /video/tag/tagname <-- video with this tag
// /media?search=blah blah blah <-- searches are full of
// dirty URL-unfriendly characters and
// are traditionally query strings.
$r->prependRoute('a_media_index', new aRoute('/', array('module' => 'aMedia', 'action' => 'index')));
$r->prependRoute('a_media_index_type', new aRoute('/:type', array('module' => 'aMedia', 'action' => 'index'), array('type' => '(image|video)')));
$r->prependRoute('a_media_index_category', new aRoute('/category/:category', array('module' => 'aMedia', 'action' => 'index'), array('category' => '.*')));
// Support for existing pretty-URL tag links so they don't 404. We don't recommend
// this for the generation of new links because it doesn't handle various
// punctuation well with a wide variety of webserver configurations
$r->prependRoute('a_media_index_deprecated_tag', new aRoute('/tag/:tag', array('module' => 'aMedia', 'action' => 'index'), array('tag' => '.*')));
// We removed :tag because we allow tags with dots and such and pretty URLs
// work great until your rewrite rules decide they are supposed to be static files
$r->prependRoute('a_media_index_tag', new aRoute('/tag', array('module' => 'aMedia', 'action' => 'index'), array('tag' => '.*')));
$r->prependRoute('a_media_select', new aRoute('/select', array('class' => 'aRoute', 'module' => 'aMedia', 'action' => 'select')));
$r->prependRoute('a_media_info', new sfRoute('/info', array('module' => 'aMediaBackend', 'action' => 'info')));
$r->prependRoute('a_media_tags', new sfRoute('/tags', array('module' => 'aMediaBackend', 'action' => 'tags')));
$r->prependRoute('a_media_upload', new aRoute('/upload', array('module' => 'aMedia', 'action' => 'upload')));
$r->prependRoute('a_media_edit_multiple', new aRoute('/editMultiple', array('module' => 'aMedia', 'action' => 'editMultiple')));
$r->prependRoute('a_media_edit', new aRoute('/edit', array('module' => 'aMedia', 'action' => 'edit')));
$r->prependRoute('a_media_new_video', new aRoute('/newVideo', array('module' => 'aMedia', 'action' => 'newVideo')));
$r->prependRoute('a_media_edit_video', new aRoute('/editVideo', array('module' => 'aMedia', 'action' => 'editVideo')));
}
}
示例14: executeShow
public function executeShow(sfWebRequest $request)
{
$this->buildParams();
$this->dateRange = '';
$this->aEvent = $this->getRoute()->getObject();
$this->categories = aCategoryTable::getCategoriesForPage($this->page);
$this->forward404Unless($this->aEvent);
$this->forward404Unless($this->aEvent['status'] == 'published' || $this->getUser()->isAuthenticated());
$this->preview = $this->getRequestParameter('preview');
aBlogItemTable::populatePages(array($this->aEvent));
// Thanks to Giles Smith for catching that we had no titles on our blog post permalink pages!
// Too much Chrome will do that to you (:
// Title is pre-escaped as valid HTML
$prefix = aTools::getOptionI18n('title_prefix');
$suffix = aTools::getOptionI18n('title_suffix');
$this->getResponse()->setTitle($prefix . $this->aEvent->Page->getTitle() . $suffix, false);
$this->calendar = $this->buildCalendar($request);
return $this->pageTemplate;
}
示例15: getEffectiveVariant
public function getEffectiveVariant($options)
{
$variants = aTools::getVariantsForSlotType($this->type, $options);
if (!isset($variants)) {
// No variants, no class
return '';
}
// Treat null and an empty string the same
$variant = $this->variant . '';
// If the variant is not defined (and the empty string will not be),
// and there is at least one variant, return the first one as the default.
// If there are no variants return an empty string
if (!isset($variants[$variant])) {
if (count($variants)) {
// Return the first variant for the type, if any, when the variant is bogus
$keys = array_keys($variants);
return $keys[0];
}
return '';
}
// If the variant is valid, return it as the CSS class
return $this->variant;
}