本文整理汇总了PHP中StringUtil::generateAlias方法的典型用法代码示例。如果您正苦于以下问题:PHP StringUtil::generateAlias方法的具体用法?PHP StringUtil::generateAlias怎么用?PHP StringUtil::generateAlias使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringUtil
的用法示例。
在下文中一共展示了StringUtil::generateAlias方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateAlias
/**
* Auto-generate the FAQ alias if it has not been set yet
*
* @param mixed $varValue
* @param DataContainer $dc
*
* @return mixed
*
* @throws Exception
*/
public function generateAlias($varValue, DataContainer $dc)
{
$autoAlias = false;
// Generate alias if there is none
if ($varValue == '') {
$autoAlias = true;
$varValue = StringUtil::generateAlias($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;
}
示例2: generateAlias
/**
* Auto-generate a page alias if it has not been set yet
*
* @param mixed $varValue
* @param DataContainer $dc
*
* @return string
*
* @throws Exception
*/
public function generateAlias($varValue, DataContainer $dc)
{
$autoAlias = false;
// Generate an alias if there is none
if ($varValue == '') {
$autoAlias = true;
$varValue = StringUtil::generateAlias($dc->activeRecord->title);
// Generate folder URL aliases (see #4933)
if (Config::get('folderUrl')) {
$objPage = PageModel::findWithDetails($dc->activeRecord->id);
if ($objPage->folderUrl != '') {
$varValue = $objPage->folderUrl . $varValue;
}
}
}
$objAlias = $this->Database->prepare("SELECT id FROM tl_page WHERE id=? OR alias=?")->execute($dc->id, $varValue);
// Check whether the page alias exists
if ($objAlias->numRows > ($autoAlias ? 0 : 1)) {
$arrPages = array();
$strDomain = '';
$strLanguage = '';
while ($objAlias->next()) {
$objCurrentPage = PageModel::findWithDetails($objAlias->id);
$domain = $objCurrentPage->domain ?: '*';
$language = !$objCurrentPage->rootIsFallback ? $objCurrentPage->rootLanguage : '*';
// Store the current page's data
if ($objCurrentPage->id == $dc->id) {
// Get the DNS and language settings from the POST data (see #4610)
if ($objCurrentPage->type == 'root') {
$strDomain = Input::post('dns');
$strLanguage = Input::post('language');
} else {
$strDomain = $domain;
$strLanguage = $language;
}
} else {
// Check the domain and language or the domain only
if (Config::get('addLanguageToUrl')) {
$arrPages[$domain][$language][] = $objAlias->id;
} else {
$arrPages[$domain][] = $objAlias->id;
}
}
}
$arrCheck = Config::get('addLanguageToUrl') ? $arrPages[$strDomain][$strLanguage] : $arrPages[$strDomain];
// Check if there are multiple results for the current domain
if (!empty($arrCheck)) {
if ($autoAlias) {
$varValue .= '-' . $dc->id;
} else {
throw new Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue));
}
}
}
return $varValue;
}
示例3: addAliasButton
/**
* Automatically generate the folder URL aliases
*
* @param array $arrButtons
*
* @return array
*/
public function addAliasButton($arrButtons)
{
// Generate the aliases
if (Input::post('FORM_SUBMIT') == 'tl_select' && isset($_POST['alias'])) {
/** @var Symfony\Component\HttpFoundation\Session\SessionInterface $objSession */
$objSession = System::getContainer()->get('session');
$session = $objSession->all();
$ids = $session['CURRENT']['IDS'];
foreach ($ids as $id) {
$objArticle = ArticleModel::findByPk($id);
if ($objArticle === null) {
continue;
}
// Set the new alias
$strAlias = StringUtil::generateAlias($objArticle->title);
// The alias has not changed
if ($strAlias == $objArticle->alias) {
continue;
}
// Initialize the version manager
$objVersions = new Versions('tl_article', $id);
$objVersions->initialize();
// Store the new alias
$this->Database->prepare("UPDATE tl_article SET alias=? WHERE id=?")->execute($strAlias, $id);
// Create a new version
$objVersions->create();
}
$this->redirect($this->getReferer());
}
// Add the button
$arrButtons['alias'] = '<button type="submit" name="alias" id="alias" class="tl_submit" accesskey="a">' . $GLOBALS['TL_LANG']['MSC']['aliasSelected'] . '</button> ';
return $arrButtons;
}
示例4: generateAlias
/**
* @param $varValue
* @param DataContainer $dc
* @return string
* @throws Exception
*/
public function generateAlias($varValue, \DataContainer $dc)
{
// Generate an alias if there is none
if ($varValue == '') {
$varValue = StringUtil::generateAlias($dc->activeRecord->name);
}
$objAlias = $this->Database->prepare("SELECT id FROM tl_taxonomies WHERE (id=? OR alias=?) AND pid = ?")->execute($dc->id, $varValue, $dc->activeRecord->pid);
// Check whether the Taxonomy alias exists
if ($objAlias->numRows > 1) {
$varValue .= '-' . $dc->id;
}
return $varValue;
}
示例5: generateAlias
/**
* @param $varValue mixed The current alias (if available)
* @param $intId int The entity's id
* @param $strTable string The entity's table
* @param $strAlias string The value to use as a base for the alias
*
* @return string
* @throws \Exception
*/
public static function generateAlias($varValue, $intId, $strTable, $strAlias)
{
$autoAlias = false;
// Generate alias if there is none
if ($varValue == '') {
$autoAlias = true;
$varValue = \StringUtil::generateAlias($strAlias);
}
$objAlias = \Database::getInstance()->prepare("SELECT id FROM {$strTable} 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 && $objAlias->id != $intId && $autoAlias || !$varValue) {
$varValue .= '-' . $intId;
}
return $varValue;
}
示例6: generateAlias
/**
* @param $varValue
* @param array $arrData
* @return string
* @throws \Exception
*/
protected function generateAlias($varValue, $arrData = array())
{
$autoAlias = false;
if (!$arrData['title'] || empty($arrData)) {
return 'Alias-' . substr(md5(time()), 12);
}
// Generate alias if there is none
if ($varValue == '') {
$autoAlias = true;
$varValue = \StringUtil::generateAlias($arrData['title']);
}
$table = $this->strTableData;
$pid = $this->strPid;
$objAlias = null;
if ($table && $pid) {
$objAlias = $this->Database->prepare("SELECT id FROM " . $table . " WHERE alias = ? AND pid = ?")->execute($varValue, $pid);
}
// Check whether the alias exists
if ($objAlias && $objAlias->numRows > 1 && !$autoAlias) {
throw new \Exception(sprintf($GLOBALS['TL_LANG']['ERR']['aliasExists'], $varValue));
}
// Add hash to alias
if ($objAlias && $objAlias->numRows && $autoAlias) {
$varValue .= '-' . substr(md5(time()), 12);
}
return $varValue;
}
示例7: generateAlias
public function generateAlias($strString)
{
return \StringUtil::generateAlias($strString);
}
示例8: addAliasButton
/**
* @param $arrButtons
* @return string
*/
public function addAliasButton($arrButtons)
{
if (\Input::post('FORM_SUBMIT') == 'tl_select' && isset($_POST['alias'])) {
// init objects
$objSession = \Session::getInstance();
$objDataBase = \Database::getInstance();
$session = $objSession->getData();
$ids = $session['CURRENT']['IDS'];
$strTable = \Input::get('table');
if (!$strTable || !$objDataBase->tableExists($strTable)) {
return $arrButtons;
}
foreach ($ids as $id) {
$objData = $objDataBase->prepare('SELECT id, alias, title FROM ' . $strTable . ' WHERE id=?')->limit(1)->execute($id);
if (!$objData->count()) {
continue;
}
$arrData = $objData->row();
$strAlias = \StringUtil::generateAlias($arrData['title']);
if ($strAlias == $arrData['alias']) {
continue;
}
$objAlias = $objDataBase->prepare('SELECT id FROM ' . $strTable . ' WHERE alias = ?')->execute($strAlias);
if ($objAlias->numRows > 1) {
$strAlias .= '-' . $arrData['id'];
}
// Initialize the version manager
$objVersions = new \Versions($strTable, $id);
$objVersions->initialize();
$objDataBase->prepare('UPDATE ' . $strTable . ' SET alias=? WHERE id=?')->execute($strAlias, $id);
$objVersions->create();
}
\Controller::redirect(\Controller::getReferer());
}
$arrButtons['alias'] = '<input type="submit" name="alias" id="alias" class="tl_submit" accesskey="a" value="' . specialchars($GLOBALS['TL_LANG']['MSC']['aliasSelected']) . '"> ';
return $arrButtons;
}