本文整理汇总了PHP中aTools::getUserCulture方法的典型用法代码示例。如果您正苦于以下问题:PHP aTools::getUserCulture方法的具体用法?PHP aTools::getUserCulture怎么用?PHP aTools::getUserCulture使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类aTools
的用法示例。
在下文中一共展示了aTools::getUserCulture方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: executeSearch
/**
* DOCUMENT ME
* @param sfWebRequest $request
* @return mixed
*/
public function executeSearch(sfWebRequest $request)
{
$now = date('YmdHis');
// create the array of pages matching the query
$q = $request->getParameter('q');
if ($request->hasParameter('x')) {
// We sometimes like to use input type="image" for presentation reasons, but it generates
// ugly x and y parameters with click coordinates. Get rid of those and come back.
return $this->redirect(sfContext::getInstance()->getController()->genUrl('a/search', true) . '?' . http_build_query(array("q" => $q)));
}
$key = strtolower(trim($q));
$key = preg_replace('/\\s+/', ' ', $key);
$replacements = sfConfig::get('app_a_search_refinements', array());
if (isset($replacements[$key])) {
$q = $replacements[$key];
}
try {
$values = aZendSearch::searchLuceneWithValues(Doctrine::getTable('aPage'), $q, aTools::getUserCulture());
} catch (Exception $e) {
// Lucene search error. TODO: display it nicely if they are always safe things to display. For now: just don't crash
$values = array();
}
// The truth is that Zend cannot do all of our filtering for us, especially
// permissions-based. So we can do some other filtering as well, although it
// would be bad not to have Zend take care of the really big cuts (if 99% are
// not being prefiltered by Zend, and we have a Zend max results of 1000, then
// we are reduced to working with a maximum of 10 real results).
$nvalues = array();
$index = Doctrine::getTable('aPage')->getLuceneIndex();
foreach ($values as $value) {
$document = $index->getDocument($value->id);
// $published_at = $value->published_at;
// New way: don't touch anything but $hit->id directly and you won't force a persistent
// use of memory for the lazy loaded columns http://zendframework.com/issues/browse/ZF-8267
$published_at = $document->getFieldValue('published_at');
if ($published_at > $now) {
continue;
}
// 1.5: the names under which we store columns in Zend Lucene have changed to
// avoid conflict with also indexing them
$info = unserialize($document->getFieldValue('info_stored'));
if (!aPageTable::checkPrivilege('view', $info)) {
continue;
}
$slug = $document->getFieldValue('slug_stored');
if (substr($slug, 0, 1) !== '@' && strpos($slug, '/') === false) {
// A virtual page slug which is not a route is not interested in being part of search results
continue;
}
$nvalues[] = $value;
}
$values = $nvalues;
if ($this->searchAddResults($values, $q)) {
foreach ($values as $value) {
if (get_class($value) === 'stdClass') {
// bc with existing implementations of searchAddResults
if (!isset($value->slug_stored)) {
if (isset($value->slug)) {
$value->slug_stored = $value->slug;
} else {
$value->slug_stored = null;
}
}
if (!isset($value->title_stored)) {
$value->title_stored = $value->title;
}
if (!isset($value->summary_stored)) {
$value->summary_stored = $value->summary;
}
if (!isset($value->engine_stored)) {
if (isset($value->engine)) {
$value->engine_stored = $value->engine;
} else {
$value->engine_stored = null;
}
}
}
}
// $value = new stdClass();
// $value->url = $url;
// $value->title = $title;
// $value->score = $scores[$id];
// $value->summary = $summary;
// $value->class = 'Article';
// $values[] = $value;
usort($values, "aActions::compareScores");
}
$this->pager = new aArrayPager(null, sfConfig::get('app_a_search_results_per_page', 10));
$this->pager->setResultArray($values);
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();
$this->pagerUrl = "a/search?" . http_build_query(array("q" => $q));
// setTitle takes care of escaping things
$this->getResponse()->setTitle(aTools::getOptionI18n('title_prefix') . 'Search for ' . $q . aTools::getOptionI18n('title_suffix'));
$results = $this->pager->getResults();
//.........这里部分代码省略.........
示例3: executeSearch
public function executeSearch(sfWebRequest $request)
{
// create the array of pages matching the query
$q = $request->getParameter('q');
if ($request->hasParameter('x')) {
// We like to use input type="image" for presentation reasons, but it generates
// ugly x and y parameters with click coordinates. Get rid of those and come back.
return $this->redirect(sfContext::getInstance()->getController()->genUrl('a/search', true) . '?' . http_build_query(array("q" => $q)));
}
$key = strtolower(trim($q));
$key = preg_replace('/\\s+/', ' ', $key);
$replacements = sfConfig::get('app_a_search_refinements', array());
if (isset($replacements[$key])) {
$q = $replacements[$key];
}
$values = aZendSearch::searchLuceneWithValues(Doctrine::getTable('aPage'), $q, aTools::getUserCulture());
$nvalues = array();
foreach ($values as $value) {
// doesn't implement isset
if (strlen($value->info)) {
$info = unserialize($value->info);
if (!aPageTable::checkPrivilege('view', $info)) {
continue;
}
}
$nvalue = $value;
if (substr($nvalue->slug, 0, 1) === '@') {
// Virtual page slug is a named Symfony route, it wants search results to go there
$nvalue->url = $this->getController()->genUrl($nvalue->slug, true);
} else {
$slash = strpos($nvalue->slug, '/');
if ($slash === false) {
// A virtual page (such as global) taht isn't the least bit interested in
// being part of search results
continue;
}
if ($slash > 0) {
// A virtual page slug which is a valid Symfony route, such as foo/bar?id=55
$nvalue->url = $this->getController()->genUrl($nvalue->slug, true);
} else {
// A normal CMS page
$nvalue->url = aTools::urlForPage($nvalue->slug);
}
}
$nvalue->class = 'aPage';
$nvalues[] = $nvalue;
}
$values = $nvalues;
if ($this->searchAddResults($values, $q)) {
usort($values, "aActions::compareScores");
}
$this->pager = new aArrayPager(null, sfConfig::get('app_a_search_results_per_page', 10));
$this->pager->setResultArray($values);
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();
$this->pagerUrl = "a/search?" . http_build_query(array("q" => $q));
// setTitle takes care of escaping things
$this->getResponse()->setTitle(aTools::getOptionI18n('title_prefix') . 'Search for ' . $q . aTools::getOptionI18n('title_suffix'));
$this->results = $this->pager->getResults();
}
示例4: getPagesInfo
/**
* Accepts array('info' => [page info array], 'where' => [where clause])
*
* Returns results the current user is permitted to see. You can override this if you specify the
* following options (must specify all or none):
* 'user_id', 'has_view_locked_permission', 'group_ids', 'has_cms_admin_permission'
*
* You can override the user's culture by specifying 'culture'
* @param mixed $options
* @return mixed
*/
public static function getPagesInfo($options)
{
$whereClauses = array();
$ignorePermissions = false;
if (isset($options['ignore_permissions'])) {
// getAncestorsInfo has to return everything in some contexts to work properly
$ignorePermissions = $options['ignore_permissions'];
}
if (!isset($options['culture'])) {
$options['culture'] = aTools::getUserCulture();
}
// In the absence of a bc option for page visibility, we can make a better
// determination based on the user's access rights (1.5)
$joins = '';
if (isset($options['user_id'])) {
// If you pass this in you have to pass all of it in. But if you are just
// interested in the current user you needn't bother (see the else clause)
$user_id = $options['user_id'];
$group_ids = $options['group_ids'];
if (!count($group_ids)) {
// Should never be empty due to IN's limitations
$group_ids = array(0);
}
$hasViewLockedPermission = $options['has_view_locked_permission'];
$hasCmsAdmin = $options['has_cms_admin_permission'];
} else {
// Get it automatically for the current user
$user = sfContext::getInstance()->getUser();
$user_id = 0;
$hasViewLockedPermission = false;
$group_ids = array(0);
$hasCmsAdmin = false;
if ($user->isAuthenticated()) {
$user_id = $user->getGuardUser()->id;
// In 1.5 this one is a little bit of a misnomer because of the new provision for locking
// to individuals or groups rather than "Editors & Guests". In the new use case it is
// merely a prerequisite
$credentials = sfConfig::get('app_a_view_locked_sufficient_credentials', 'view_locked');
$hasViewLockedPermission = $user->hasCredential($credentials);
$group_ids = aArray::getIds($user->getGroups());
// Careful: empty IN clauses do not work
if (!count($group_ids)) {
$group_ids = array(0);
}
$hasCmsAdmin = $user->hasCredential('cms_admin');
}
}
$joins .= 'LEFT JOIN a_access aa ON aa.page_id = p.id AND aa.user_id = ' . $user_id . ' ';
if (!count($group_ids)) {
// A group that can never be
$group_ids = array(0);
}
$joins .= 'LEFT JOIN a_group_access ga ON ga.page_id = p.id AND ga.group_id IN (' . implode(',', $group_ids) . ') ';
$viewLockedClause = '';
if ($hasViewLockedPermission) {
$viewLockedClause = 'OR p.view_guest IS TRUE ';
}
// CMS admin can always view
if (!$hasCmsAdmin && !$ignorePermissions) {
// YOU CAN VIEW IF
// * view_admin_lock is NOT set, AND
// * You can edit
// OR
// p.archived is false AND p.published_at is in the past AND p.view_is_secure is false
// OR
// p.archived is false AND p.published_at is in the past AND p.view_is_secure is true AND (p.view_guest is true OR you have view_locked OR you have an explicit view privilege
// However note that if you have a group privilege you don't need to have hasViewLockedPermission (all groups are candidates)
$whereClauses[] = '(p.view_admin_lock IS FALSE AND (((aa.privilege = "edit") || (ga.privilege = "edit")) OR ' . '((p.archived IS FALSE OR p.archived IS NULL) AND p.published_at < NOW() AND ' . '((p.view_is_secure IS FALSE OR p.view_is_secure IS NULL) OR ' . '(p.view_is_secure IS TRUE AND ' . '(ga.privilege = "view_custom" OR ' . ($hasViewLockedPermission ? '(p.view_guest IS TRUE OR aa.privilege = "view_custom")' : '(0 <> 0)') . '))))))';
}
if (!isset($options['admin'])) {
$options['admin'] = false;
}
if (!isset($options['where'])) {
throw new sfException("You must specify a where clause when calling getPagesInfo");
}
$culture = $options['culture'];
$admin = $options['admin'];
$where = $options['where'];
// Raw PDO for performance
$connection = Doctrine_Manager::connection();
$pdo = $connection->getDbh();
// When we look for the current culture, we need to do it in the ON clause, not
// in the WHERE clause. Otherwise we don't get any information at all about pages
// not i18n'd yet
$escCulture = $connection->quote($culture);
$query = "SELECT p.id, p.slug, p.view_is_secure, p.view_guest, p.view_admin_lock, p.edit_admin_lock, p.archived, p.lft, p.rgt, p.level, p.engine, p.template, s.value AS title FROM a_page p\n LEFT JOIN a_area a ON a.page_id = p.id AND a.name = 'title' AND a.culture = {$escCulture}\n LEFT JOIN a_area_version v ON v.area_id = a.id AND a.latest_version = v.version \n LEFT JOIN a_area_version_slot avs ON avs.area_version_id = v.id\n LEFT JOIN a_slot s ON s.id = avs.slot_id {$joins}";
// admin pages are almost never visible in navigation
if (!$admin) {
$whereClauses[] = '(p.admin IS FALSE OR p.admin IS NULL)';
//.........这里部分代码省略.........
示例5: construct
public function construct()
{
$this->culture = aTools::getUserCulture();
$this->privilegesCache = array();
}
示例6: addSearchQueryWithScores
public function addSearchQueryWithScores(Doctrine_Query $q = null, $luceneQuery, &$scores)
{
// Page searches are always specific to this user's culture
$culture = aTools::getUserCulture();
$luceneQuery = "+(text:({$luceneQuery}))";
return aZendSearch::addSearchQueryWithScores($this, $q, $luceneQuery, $culture, $scores);
}
示例7: executeSearch
public function executeSearch(sfWebRequest $request)
{
// create the array of pages matching the query
$q = $request->getParameter('q');
if ($request->hasParameter('x')) {
// We like to use input type="image" for presentation reasons, but it generates
// ugly x and y parameters with click coordinates. Get rid of those and come back.
return $this->redirect(sfContext::getInstance()->getController()->genUrl('a/search', true) . '?' . http_build_query(array("q" => $q)));
}
$key = strtolower(trim($q));
$key = preg_replace('/\\s+/', ' ', $key);
$replacements = sfConfig::get('app_a_search_refinements', array());
if (isset($replacements[$key])) {
$q = $replacements[$key];
}
$values = aZendSearch::searchLuceneWithValues(Doctrine::getTable('aPage'), $q, aTools::getUserCulture());
$nvalues = array();
foreach ($values as $value) {
if (!sfContext::getInstance()->getUser()->isAuthenticated()) {
if (isset($value->view_is_secure) && $value->view_is_secure) {
continue;
}
}
$nvalue = $value;
$nvalue->url = aTools::urlForPage($nvalue->slug, true);
$nvalue->class = 'aPage';
$nvalues[] = $nvalue;
}
$values = $nvalues;
if ($this->searchAddResults($values, $q)) {
usort($values, "aActions::compareScores");
}
$this->pager = new aArrayPager(null, sfConfig::get('app_a_search_results_per_page', 10));
$this->pager->setResultArray($values);
$this->pager->setPage($request->getParameter('page', 1));
$this->pager->init();
$this->pagerUrl = "a/search?" . http_build_query(array("q" => $q));
// setTitle takes care of escaping things
$this->getResponse()->setTitle(aTools::getOptionI18n('title_prefix') . 'Search for ' . $q);
$this->results = $this->pager->getResults();
}
示例8: getGlobalButtonsByName
/**
* Returns global buttons as an associative array by button name.
* Ignores app_a_global_button_order. For use by those who prefer to
* override the _globalTools partial. Note that you will NOT get the
* same buttons for every user! An admin has more buttons than a
* mere editor and so on. Use isset()
* @return mixed
*/
public static function getGlobalButtonsByName()
{
if (aTools::$globalButtons === false) {
aTools::$globalButtons = array();
// We could pass parameters here but it's a simple static thing in this case
// so the recipients just call back to addGlobalButtons
sfContext::getInstance()->getEventDispatcher()->notify(new sfEvent(null, 'a.getGlobalButtons', array()));
}
$labelOverrides = sfConfig::get('app_a_global_button_labels', null);
if (is_array($labelOverrides)) {
foreach ($labelOverrides as $key => $label) {
if (isset(aTools::$globalButtons[$key])) {
if (is_array($label)) {
// i18n
aTools::$globalButtons[$key]->setLabel($label[aTools::getUserCulture()]);
} else {
aTools::$globalButtons[$key]->setLabel($label);
}
}
}
}
return aTools::$globalButtons;
}
示例9: filterForEngine
public static function filterForEngine($options)
{
// This method filters the virtual pages, tags and categories associated with a particular engine based on
// specified criteria such as tag, category, publication date, etc.
// Strategy: do Lucene queries and direct SQL queries that will get us all the info about relevant categories,
// tags and virtual pages. Then turn that into a select distinct query for each of those things. The resulting
// information is sufficient to populate the filters sidebar with options that are still relevant given the
// other criteria in effect, and also to fetch the result pages (you'll want to do that with a LIMIT and an IN
// query looking at the first n IDs returned by this method).
// The options array looks like this. Note that all of these are optional and if each is unspecified or empty
// no restriction is made on that particular basis. 'categoryIds' is used to limit to the categories associated
// with the engine page, while 'categorySlug' is used to limit to a category specified by the user as a
// filter. The 'q' option is Lucene search.
// array(
// 'q' => 'gromit',
// 'categoryIds' => array(1, 3, 5),
// 'categorySlug' => 'cheese',
// 'tag' => 'wensleydale',
// 'slugStem' => '@a_event_search_redirect',
// 'year' => 2010, # Optional, if present only 2010 is shown
// 'month' => 12, # Optional, if present only Dec. 2010 is shown
// 'day' => 15, # Optional, if present only Dec. 15th 2010 is shown
// 'byEventDateRange' => true, # For events only, joins with a_blog_item to get the range
// 'byPublishedAt' => true, # For blog posts or pages
// The returned value looks like this:
// array(
// 'categoriesInfo' => array('slug' => 'cheese', 'name' => 'Cheese'),
// 'tagNames' => array('wensleydale'),
// 'pageIds' => array(10, 15, 20, 25)
$alphaSort = isset($options['alphaSort']) && $options['alphaSort'];
if (isset($options['q']) && strlen($options['q'])) {
$q = $options['q'];
$key = strtolower(trim($q));
$key = preg_replace('/\\s+/', ' ', $key);
$replacements = sfConfig::get('app_a_search_refinements', array());
if (isset($replacements[$key])) {
$q = $replacements[$key];
}
if (isset($options['slugStem'])) {
$q = "({$q}) AND slug:" . $options['slugStem'];
}
try {
$values = aZendSearch::searchLuceneWithValues(Doctrine::getTable('aPage'), $q, aTools::getUserCulture());
} catch (Exception $e) {
// Lucene search error. TODO: display it nicely if they are always safe things to display. For now: just don't crash
$values = array();
}
$now = date('YmdHis');
$pageIds = array();
foreach ($values as $value) {
// Regardless of the above if it ain't published yet we can't see it.
// We filter on that in the Doctrine query too but take advantage of
// this chance to preempt a little work
if ($value->published_at > $now) {
continue;
}
// 1.5: the names under which we store columns in Zend Lucene have changed to
// avoid conflict with also indexing them
$info = unserialize($value->info_stored);
if (!aPageTable::checkPrivilege('view', $info)) {
continue;
}
$pageIds[] = $info['id'];
}
}
$mysql = new aMysql();
if (isset($options['slugStem'])) {
$params['slug_pattern'] = $options['slugStem'] . '%';
}
// Select the relevant virtual pages for this engine
$q = 'from a_page p ';
// If alpha sort is present we need title slots
if ($alphaSort) {
if (!isset($options['culture'])) {
$options['culture'] = aTools::getUserCulture();
}
$culture = $options['culture'];
$q .= "\n LEFT JOIN a_area a ON a.page_id = p.id AND a.name = 'title' AND a.culture = :culture\n LEFT JOIN a_area_version v ON v.area_id = a.id AND a.latest_version = v.version \n LEFT JOIN a_area_version_slot avs ON avs.area_version_id = v.id\n LEFT JOIN a_slot s ON s.id = avs.slot_id ";
$params['culture'] = $culture;
}
// Merge in categories. A left join unless we are restricted to certain categories
$hasCategoryIds = isset($options['categoryIds']) && count($options['categoryIds']);
$hasCategorySlug = isset($options['categorySlug']) && strlen($options['categorySlug']);
$restrictedByCategory = $hasCategoryIds || $hasCategorySlug;
if ($restrictedByCategory) {
$cjoin = 'inner join';
} else {
$cjoin = 'left join';
}
$q .= $cjoin . ' a_page_to_category ptc on ptc.page_id = p.id ' . $cjoin . ' a_category c on ptc.category_id = c.id ';
// The engine page is locked down to these categories. If none are specified it is not
// locked down by category
if ($hasCategoryIds) {
$q .= "and c.id in :category_ids ";
$params['category_ids'] = $options['categoryIds'];
}
// Bring in tags...
$hasTag = isset($options['tag']) && strlen($options['tag']);
if ($hasTag) {
$q .= 'inner join ';
//.........这里部分代码省略.........