public function generateAlias($varValue, DataContainer $dc) { $autoAlias = false; if (!strlen($varValue)) { $autoAlias = true; $varValue = standardize($dc->activeRecord->title); } $objAlias = $this->Database->prepare("SELECT id FROM tl_shop_category WHERE id=? OR alias=?")->execute($dc->id, $varValue); if ($objAlias->numRows > 1) { $arrDomains = array(); while ($objAlias->next()) { $_pid = $objAlias->id; $_type = ''; do { $objParentPage = $this->Database->prepare("SELECT id, pid, alias, type, dns FROM tl_shop_category WHERE id=?")->limit(1)->execute($_pid); if ($objParentPage->numRows < 1) { break; } $_pid = $objParentPage->pid; $_type = $objParentPage->type; } while ($_pid > 0 && $_type != 'catroot'); $arrDomains[] = $objParentPage->numRows && ($objParentPage->type == 'catroot' || $objParentPage->pid > 0) ? $objParentPage->dns : ''; } $arrUnique = array_unique($arrDomains); if (count($arrDomains) != count($arrUnique)) { if (!$autoAlias) { throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue)); } $varValue .= '-' . $dc->id; } } return $varValue; }
/** * Create the name. * * @param string $value Current name value. * @param \DataContainer $dataContainer The Dc_Table. * * @return string */ public function createName($value, $dataContainer) { if (!$value) { $value = $dataContainer->activeRecord->label; } return standardize($value); }
/** * Autogenerate a taxonomy alias if it has not been set yet * @param mixed * @param object * @return string */ public function generateAlias($varValue, DataContainer $dc) { $objField = $this->Database->prepare("SELECT pid FROM " . $dc->table . " WHERE id=?")->limit(1)->execute($dc->id); if (!$objField->numRows) { throw new Exception($GLOBALS['TL_LANG']['ERR']['aliasTitleMissing']); } $pid = $objField->pid; $autoAlias = false; // Generate alias if there is none if (!strlen($varValue)) { $objTitle = $this->Database->prepare("SELECT name FROM " . $dc->table . " WHERE id=?")->limit(1)->execute($dc->id); $autoAlias = true; $varValue = standardize($objTitle->name); } $objAlias = $this->Database->prepare("SELECT id FROM " . $dc->table . " WHERE alias=?")->execute($varValue, $dc->id); // Check whether the catalog alias exists if ($objAlias->numRows > 1 && !$autoAlias) { throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue)); } // Add ID to alias if ($objAlias->numRows && $autoAlias) { $varValue .= '.' . $dc->id; } return $varValue; }
/** * Autogenerate a product alias if it has not been set yet * @param mixed * @param \DataContainer * @return string * @throws \Exception */ public function save($varValue, \DataContainer $dc) { $autoAlias = false; // Generate alias if there is none if ($varValue == '') { $autoAlias = true; $varValue = standardize(\Input::post('name')); if ($varValue == '') { $varValue = standardize(\Input::post('sku')); } if ($varValue == '') { $varValue = strlen($dc->activeRecord->name) ? standardize($dc->activeRecord->name) : standardize($dc->activeRecord->sku); } if ($varValue == '') { $varValue = $dc->id; } } $objAlias = \Database::getInstance()->prepare("SELECT id FROM tl_iso_product WHERE id=? OR alias=?")->execute($dc->id, $varValue); // Check whether the product alias exists if ($objAlias->numRows > 1) { if (!$autoAlias) { throw new \OverflowException(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue)); } $varValue .= '.' . $dc->id; } return $varValue; }
/** * {@inheritdoc} */ public function modelSaved($objItem) { $arrValue = $objItem->get($this->getColName()); // Alias already defined and no update forced, get out! if ($arrValue && !empty($arrValue['value']) && !$this->get('force_talias')) { return; } $arrAlias = array(); foreach (deserialize($this->get('talias_fields')) as $strAttribute) { $arrValues = $objItem->parseAttribute($strAttribute['field_attribute'], 'text', null); $arrAlias[] = $arrValues['text']; } $dispatcher = $this->getMetaModel()->getServiceContainer()->getEventDispatcher(); $replaceEvent = new ReplaceInsertTagsEvent(implode('-', $arrAlias)); $dispatcher->dispatch(ContaoEvents::CONTROLLER_REPLACE_INSERT_TAGS, $replaceEvent); // Implode with '-', replace inserttags and strip HTML elements. $strAlias = standardize(strip_tags($replaceEvent->getBuffer())); // We need to fetch the attribute values for all attributes in the alias_fields and update the database // and the model accordingly. if ($this->get('isunique')) { // Ensure uniqueness. $strLanguage = $this->getMetaModel()->getActiveLanguage(); $strBaseAlias = $strAlias; $arrIds = array($objItem->get('id')); $intCount = 2; while (array_diff($this->searchForInLanguages($strAlias, array($strLanguage)), $arrIds)) { $strAlias = $strBaseAlias . '-' . $intCount++; } } $arrData = $this->widgetToValue($strAlias, $objItem->get('id')); $this->setTranslatedDataFor(array($objItem->get('id') => $arrData), $this->getMetaModel()->getActiveLanguage()); $objItem->set($this->getColName(), $arrData); }
public function replaceGlossaryTags($strTag) { $arrSplit = explode('::', $strTag); /* {{glossary::ID}} / {{glossary::Term}} */ if ($arrSplit[0] == 'glossary' && !empty($arrSplit[1])) { global $objPage; $this->import('Database'); $arrGlossaries = array(); $isGlossaryPage = false; $glossaryPageId = 0; /* look for glossary module on the current page */ $objGlossaries = $this->Database->prepare("SELECT `glossaries` FROM `tl_module` WHERE `type`='glossaryList' AND `id` = (SELECT `module` FROM `tl_content` WHERE `type`='module' AND `pid`= (SELECT `id` FROM `tl_article` WHERE `pid`=?))")->limit(1)->execute($objPage->id); if ($objGlossaries->next()) { $arrValues = deserialize($objGlossaries->glossaries); $arrGlossaries = array_values($arrValues); $isGlossaryPage = true; } if (count($arrGlossaries) == 0) { /* find first glossary in page hierarchy */ $objGlossaries = $this->Database->execute("SELECT `id`,`glossaries` FROM `tl_module` WHERE `type`='glossaryList'"); while ($glossaryPageId == 0 && $objGlossaries->next()) { $objArticles = $this->Database->prepare("SELECT `pid` FROM `tl_article` WHERE `published`=1 AND `id` IN (SELECT `pid` FROM `tl_content` WHERE `published`=1 AND `type`='module' AND `module` = ?)")->execute($objGlossaries->id); while ($glossaryPageId == 0 && $objArticles->next()) { if ($objPage->rootId == $this->getRootPage($objArticles->pid)) { $arrValues = deserialize($objGlossaries->glossaries); $arrGlossaries = array_values($arrValues); $glossaryPageId = $objArticles->pid; } } } $objPages = $this->Database->execute("SELECT `pid` FROM `tl_article` WHERE `published`=1 AND `id` IN (SELECT `pid` FROM `tl_content` WHERE `published`=1 AND `type`='module' AND `module` = (SELECT `id` FROM `tl_module` WHERE `type`='glossaryList'))"); } if (count($arrGlossaries) > 0) { if ((int) $arrSplit[1] > 0) { $objTerm = $this->Database->prepare("SELECT `id`,`term` FROM `tl_glossary_term` WHERE `id`=?")->limit(1)->execute($arrSplit[1]); } else { $objTerm = $this->Database->prepare("SELECT `id`,`term` FROM `tl_glossary_term` WHERE `term`=? AND `pid` IN (" . implode(',', $arrGlossaries) . ")")->limit(1)->execute($arrSplit[1]); } if ($objTerm->next()) { $this->import('String'); if ($isGlossaryPage) { return ampersand($this->Environment->request, true) . '#' . standardize($objTerm->term); } elseif ($glossaryPageId > 0) { $objGlossaryPage = $this->Database->prepare("SELECT * FROM `tl_page` WHERE `id`=?")->limit(1)->execute($glossaryPageId); if ($objGlossaryPage->next()) { if (version_compare(VERSION, '2.10', '>')) { $strGlossaryUrl = $this->generateFrontendUrl($objGlossaryPage->row(), null, $objPage->rootLanguage); } else { $strGlossaryUrl = $this->generateFrontendUrl($objGlossaryPage->row()); } return $strGlossaryUrl . '#' . standardize($objTerm->term); } } } } } return false; }
/** * Compile the current element */ protected function compile($mode) { $alias = strlen($this->article->alias) ? $this->article->alias : $this->article->title; if (in_array($alias, array('header', 'container', 'left', 'main', 'right', 'footer'))) { $alias .= '-' . $this->article->id; } $alias = standardize($alias); $this->Template->column = $this->article->inColumn; // Add modification date $this->Template->timestamp = $this->article->tstamp; $this->Template->date = $this->parseDate($GLOBALS['TL_CONFIG']['datimFormat'], $this->article->tstamp); $this->Template->author = $this->article->author; // Override CSS ID and class $cssIdClass = deserialize($this->article->teaserCssID); if (is_array($cssIdClass) && count($cssIdClass) == 2) { if ($cssIdClass[0] == '') { $cssIdClass[0] = $alias; } } $this->cssID = $cssIdClass; $article = !$GLOBALS['TL_CONFIG']['disableAlias'] && strlen($this->article->alias) ? $this->article->alias : $this->article->id; $href = 'articles=' . ($this->article->inColumn != 'main' ? $this->article->inColumn . ':' : '') . $article; $GLOBALS['objPage'] = $this->getPageDetails($this->article->pid); $this->Template->headline = $this->article->title; $this->Template->href = $this->addToUrl($href, true); $this->Template->teaser = $mode == NL_PLAIN ? $this->getPlainFromHTML($this->article->teaser) : $this->article->teaser; $this->Template->readMore = specialchars(sprintf($GLOBALS['TL_LANG']['MSC']['readMore'], $this->article->headline), true); $this->Template->more = $GLOBALS['TL_LANG']['MSC']['more']; }
/** * Generate the module */ protected function compile() { /** @var \PageModel $objPage */ global $objPage; if (!strlen($this->inColumn)) { $this->inColumn = 'main'; } $intCount = 0; $articles = array(); $id = $objPage->id; $this->Template->request = \Environment::get('request'); // Show the articles of a different page if ($this->defineRoot && $this->rootPage > 0) { if (($objTarget = $this->objModel->getRelated('rootPage')) !== null) { $id = $objTarget->id; /** @var \PageModel $objTarget */ $this->Template->request = $objTarget->getFrontendUrl(); } } // Get published articles $objArticles = \ArticleModel::findPublishedByPidAndColumn($id, $this->inColumn); if ($objArticles === null) { return; } while ($objArticles->next()) { // Skip first article if (++$intCount <= intval($this->skipFirst)) { continue; } $cssID = deserialize($objArticles->cssID, true); $alias = $objArticles->alias ?: $objArticles->title; $articles[] = array('link' => $objArticles->title, 'title' => specialchars($objArticles->title), 'id' => $cssID[0] ?: standardize($alias), 'articleId' => $objArticles->id); } $this->Template->articles = $articles; }
/** * Auto-Generate an alias for an entity. * * @param string $alias * @param \DC_General $dc * * @return string * @throws Exception */ public static function generateAlias($alias, \DC_General $dc) { /** @var EntityInterface $entity */ $entity = $dc->getCurrentModel()->getEntity(); $autoAlias = false; // Generate alias if there is none if (!strlen($alias)) { $autoAlias = true; if ($entity->__has('title')) { $alias = standardize($entity->getTitle()); } elseif ($entity->__has('name')) { $alias = standardize($entity->getName()); } else { return ''; } } $entityClass = new \ReflectionClass($entity); $keys = explode(',', $entityClass->getConstant('KEY')); $entityManager = EntityHelper::getEntityManager(); $queryBuilder = $entityManager->createQueryBuilder(); $queryBuilder->select('COUNT(e.' . $keys[0] . ')')->from($entityClass->getName(), 'e')->where($queryBuilder->expr()->eq('e.alias', ':alias'))->setParameter(':alias', $alias); static::extendQueryWhereId($queryBuilder, $dc->getCurrentModel()->getID(), $entity); $query = $queryBuilder->getQuery(); $duplicateCount = $query->getResult(Query::HYDRATE_SINGLE_SCALAR); // Check whether the news alias exists if ($duplicateCount && !$autoAlias) { throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $alias)); } // Add ID to alias if ($duplicateCount && $autoAlias) { $alias .= '-' . $dc->getCurrentModel()->getID(); } return $alias; }
/** * Replaces all "forbidden" characters in the given filename * * @param string $strFile * * @return string */ protected function replaceForbiddenCharacters($strFile) { $info = pathinfo($strFile); $newFilename = substr($info['filename'], 0, 32); $newFilename = standardize(\String::restoreBasicEntities($newFilename)); $newFilename = $this->replaceUnderscores($newFilename); return $info['dirname'] . '/' . $newFilename . '.' . strtolower($info['extension']); }
public function rename($varValue) { if (!$GLOBALS['TL_CONFIG']['checkFilenames']) { return $varValue; } $varValue = standardize(\String::restoreBasicEntities($varValue)); return $varValue; }
/** * Generate an ID for this integrity check * * @return string */ public function getId() { $className = get_called_class(); if (($pos = strrpos($className, '\\')) !== false) { $className = substr($className, $pos + 1); } return standardize($className); }
/** * Make sure the system columns are not added as attribute * * @param mixed $varValue * * @return mixed * @throws \Exception */ public function validateFieldName($varValue) { $this->loadDataContainer('tl_iso_product'); $varValue = str_replace('-', '_', standardize($varValue)); if (isset($GLOBALS['TL_DCA']['tl_iso_product']['fields'][$varValue]) && $GLOBALS['TL_DCA']['tl_iso_product']['fields'][$varValue]['attributes']['systemColumn']) { throw new \InvalidArgumentException(sprintf($GLOBALS['TL_LANG']['ERR']['systemColumn'], $varValue)); } return $varValue; }
public function normalizeUploadNames() { if (is_array($_FILES['files'])) { $count = count($_FILES['files']['name']); for ($i = 0; $i < $count; $i++) { $pathinfo = pathinfo($_FILES['files']['name'][$i]); $_FILES['files']['name'][$i] = standardize($pathinfo['filename']) . '.' . $pathinfo['extension']; } } }
/** * Autogenerate an article alias from the title * @param mixed * @param object * @return string */ public function autoGenerateAlias($varTitle) { $varAlias = standardize($varTitle); $objAlias = $this->Database->prepare("SELECT id FROM tl_article WHERE alias=?")->execute($varAlias); // Check whether the page alias exists if ($objAlias->numRows > 1) { $varAlias .= '.' . $dc->id; } return $varAlias; }
public function generateAlias($varValue, $objItem) { $t = static::$strTable; $varValue = standardize(\String::restoreBasicEntities($varValue)); $objAlias = \Database::getInstance()->prepare("SELECT id FROM {$t} WHERE alias=? AND id != ?")->execute($varValue, $objItem->id); // Add ID to alias if ($objAlias->numRows > 0) { $varValue .= '-' . $objItem->id; } return $varValue; }
public function generateAlias($varValue, DataContainer $dc) { // Generate an alias if there is none if ($varValue == '') { $varValue = standardize(String::restoreBasicEntities($dc->activeRecord->label)); } $objAlias = $this->Database->prepare("SELECT id FROM tl_metafields WHERE id=? OR alias=?")->execute($dc->id, $varValue); // Check whether the alias exists if ($objAlias->numRows > 1) { throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue)); } return $varValue; }
/** * Validate name for ID in URL and redirect if necessary * @param string * @param int * @param string */ public static function validate($strKey, $intId, $strName) { $strValid = $intId . '-' . standardize($strName); if (Input::getAutoItem($strKey) != $strValid) { /** @type \PageModel $objPage */ global $objPage; $strParams = '/' . $strValid; // Check if key is auto_item enabled if (!$GLOBALS['TL_CONFIG']['useAutoItem'] || !in_array($strKey, $GLOBALS['TL_AUTO_ITEM'])) { $strParams = '/' . $strKey . $strParams; } \System::redirect($objPage->getFrontendUrl($strParams), 301); } }
public function generateAlias() { $varValue = standardize(\String::restoreBasicEntities($this->title)); $objAlias = static::findBy('alias', $varValue); // Check whether the alias exists if ($objAlias !== null) { if (!$this->id) { return $this; } $varValue .= '-' . $this->id; } $this->alias = $varValue; return $this; }
/** * Autocomplee section ids. * * @param string|array $value Sections configuration. * * @return array */ public function autoCompleteSectionIds($value) { $sections = array(); $value = deserialize($value, true); foreach ($value as $section) { if (!$section['id']) { if (!$section['label']) { continue; } $section['id'] = standardize($section['label']); } $sections[] = $section; } return $sections; }
/** * Check feed alias * @param mixed * @param object * @return mixed */ public function checkFeedAlias($varValue, $objDC) { // No change or empty value if ($varValue == $objDC->value || $varValue == '') { return $varValue; } $varValue = standardize($varValue); // see #5096 $this->import('Automator'); $arrFeeds = $this->Automator->purgeXmlFiles(true); // Alias exists if (array_search($varValue, $arrFeeds) !== false) { throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue)); } return $varValue; }
/** * Autogenerate an article alias if it has not been set yet * @param mixed * @param object * @return string */ public function generateAlias($varValue, DataContainer $dc) { $autoAlias = false; // Generate alias if there is none if (!strlen($varValue)) { $autoAlias = true; $varValue = standardize($dc->activeRecord->title); } $objAlias = $this->Database->prepare("SELECT id FROM tl_simple_recipes_categories WHERE id=? OR alias=?")->execute($dc->id, $varValue); // Check whether the page alias exists if ($objAlias->numRows > 1) { if (!$autoAlias) { throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue)); } $varValue .= '-' . $dc->id; } return $varValue; }
public function compile() { $this->Template->size = ''; // Set the size if ($this->playerSize != '') { $size = deserialize($this->playerSize); if (is_array($size)) { $this->Template->size = ' width="' . $size[0] . '" height="' . $size[1] . '"'; $this->Template->width = $size[0]; $this->Template->height = $size[1]; } } $objFile = new \stdClass(); $objFile->path = 'http://www.youtube.com/embed/' . $this->youtube; $this->Template->playerId = standardize($this->youtube); $this->Template->ytId = $this->youtube; $this->Template->file = $objFile; }
function rest_index() { $this->autoRender = false; $this->header('Content-Type: application/json'); $modelClass = $this->modelClass; // add any applicable filters $conditions = array(); if (array_key_exists('filter', $this->params['url'])) { $filters = json_decode($this->params['url']['filter'], true); foreach ($filters as $filter) { if (array_key_exists($filter['property'], $this->{$modelClass}->_schema)) { $conditions[$modelClass . '.' . $filter['property']] = $filter['value']; } } } $models = $this->{$modelClass}->find('all', array('recursive' => -1, 'conditions' => $conditions, 'limit' => 300, 'order' => 'SurveysTaken.created DESC')); e(json_encode(standardize($models, $modelClass))); }
/** * Auto-Generate an alias for an entity. * * @param string $alias * @param EntityInterface $entity * * @return string * @throws \Exception */ public static function generateAlias($alias, $entity, $baseField = false) { $customAlias = (bool) $alias; $turn = 0; do { // Generate alias if there is none if (!strlen($alias)) { /** @var EntityAccessor $entityAccessor */ $entityAccessor = $GLOBALS['container']['doctrine.orm.entityAccessor']; if ($baseField) { $alias = standardize($entityAccessor->getProperty($entity, $baseField)); } elseif ($entity instanceof AliasableInterface) { $alias = standardize($entity->getAliasParentValue()); } elseif ($entityAccessor->hasProperty($entity, 'title')) { $alias = standardize($entityAccessor->getProperty($entity, 'title')); } elseif ($entityAccessor->hasProperty($entity, 'name')) { $alias = standardize($entityAccessor->getProperty($entity, 'name')); } else { throw new \RuntimeException('Cannot generate alias, do not know which field should used!'); } } if ($turn > 0) { $alias .= '-' . $turn; } $entityClass = new \ReflectionClass($entity); if ($entityClass->hasConstant('PRIMARY_KEY')) { $keys = explode(',', $entityClass->getConstant('PRIMARY_KEY')); } else { $keys = array('id'); } $entityManager = EntityHelper::getEntityManager(); $queryBuilder = $entityManager->createQueryBuilder(); $queryBuilder->select('COUNT(e.' . $keys[0] . ')')->from($entityClass->getName(), 'e')->where($queryBuilder->expr()->eq('e.alias', ':alias'))->setParameter(':alias', $alias); static::extendQueryWhereId($queryBuilder, $entity); $query = $queryBuilder->getQuery(); $duplicateCount = $query->getResult(Query::HYDRATE_SINGLE_SCALAR); // Check whether the news alias exists if ($duplicateCount && $customAlias) { throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $alias)); } $turn++; } while ($duplicateCount); return $alias; }
/** * Auto-generate the cookie name */ public function generateCookiesName($varValue, DataContainer $dc) { $autoAlias = false; // Generate alias if there is none if ($varValue == '') { $autoAlias = true; $varValue = standardize(String::restoreBasicEntities('tabControllCookie-' . $dc->activeRecord->id)); } $objAlias = $this->Database->prepare("SELECT id FROM tl_content WHERE tabControlCookies=?")->execute($varValue); // Check whether the cookies name alias exists if ($objAlias->numRows > 1 && !$autoAlias) { throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue)); } // Add ID to cookies name if ($objAlias->numRows && $autoAlias) { $varValue .= '-' . $dc->id; } return $varValue; }
/** * Auto-generate the FAQ alias if it has not been set yet * @param mixed * @param \DataContainer * @return mixed * @throws \Exception */ public function generateAlias($varValue, DataContainer $dc) { $autoAlias = false; // Generate alias if there is none if (!strlen($varValue)) { $autoAlias = true; $varValue = standardize($this->restoreBasicEntities($dc->activeRecord->question)); } $objAlias = $this->Database->prepare("SELECT id FROM tl_faq WHERE alias=?")->execute($varValue); // Check whether the news alias exists if ($objAlias->numRows > 1 && !$autoAlias) { throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue)); } // Add ID to alias if ($objAlias->numRows && $autoAlias) { $varValue .= '-' . $dc->id; } return $varValue; }
/** * Generate an alias for the API configuration * @param mixed * @param object * @return string */ public function generateAlias($varValue, \DataContainer $dc) { $autoAlias = false; // Generate alias if there is none if (!strlen($varValue)) { $autoAlias = true; $varValue = standardize($dc->activeRecord->name); } $objAlias = \Database::getInstance()->prepare("SELECT id FROM tl_salesforce_apiconfig WHERE alias=?")->execute($varValue); // Check whether the alias exists if ($objAlias->numRows > 1 && !$autoAlias) { throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue)); } // Add ID to alias if ($objAlias->numRows && $autoAlias) { $varValue .= '-' . $dc->id; } return $varValue; }
/** * Autogenerate a movie alias if it has not been set yet * @param mixed * @param object * @return string */ public function generateAlias($varValue, DataContainer $dc) { $autoAlias = false; // Generate alias if there is none if (!strlen($varValue)) { $objTitle = $this->Database->prepare("SELECT title FROM tl_ch_flowplayer_playlist WHERE id=?")->limit(1)->execute($dc->id); $autoAlias = true; $varValue = standardize($objTitle->title); } $objAlias = $this->Database->prepare("SELECT id FROM tl_ch_flowplayer_playlist WHERE alias=?")->execute($varValue); // Check whether the news alias exists if ($objAlias->numRows > 1 && !$autoAlias) { throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue)); } // Add ID to alias if ($objAlias->numRows && $autoAlias) { $varValue .= '.' . $dc->id; } return $varValue; }
/** * Auto-generate the member alias if it has not been set yet * @param mixed * @param \DataContainer * @return string * @throws \Exception */ public function generateAlias($varValue, DataContainer $objDc) { $autoAlias = false; // Generate alias if there is none if ($varValue == '') { $autoAlias = true; $arrTitle = \HeimrichHannot\MemberPlus\MemberPlus::getCombinedTitle($objDc->activeRecord); $varValue = standardize(\StringUtil::restoreBasicEntities($arrTitle)); } $objAlias = \Database::getInstance()->prepare("SELECT id FROM tl_member WHERE alias=? AND id!=?")->execute($varValue, $objDc->activeRecord->id); // Check whether the news alias exists if ($objAlias->numRows > 1 && !$autoAlias) { throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue)); } // Add ID to alias if ($objAlias->numRows && $autoAlias) { $varValue .= '-' . $objDc->id; } return $varValue; }