本文整理汇总了PHP中JString::increment方法的典型用法代码示例。如果您正苦于以下问题:PHP JString::increment方法的具体用法?PHP JString::increment怎么用?PHP JString::increment使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JString
的用法示例。
在下文中一共展示了JString::increment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* Method to save item.
*
* @param int $pk The primary key value.
* @param array $data The item data.
*
* @return mixed
*/
protected function save($pk, $data)
{
if (!$this->allowAdd($data, $this->urlVar)) {
return false;
}
// We load existing item first and bind data into it.
$this->table->reset();
$this->table->load($pk);
$this->table->bind($data);
// Dump as array
$item = $this->table->getProperties(true);
// Handle Title increment
$table2 = $this->model->getTable();
$condition = array();
// Check table has increment fields, default is title and alias.
foreach ($this->incrementFields as $field => $type) {
if (property_exists($this->table, $field)) {
$condition[$field] = $item[$field];
}
}
// Recheck item with same conditions(default is title & alias), if true, increment them.
// If no item got, means it is the max number.
while ($table2->load($condition)) {
foreach ($this->incrementFields as $field => $type) {
if (property_exists($this->table, $field)) {
$item[$field] = $condition[$field] = \JString::increment($item[$field], $type);
}
}
}
// Unset the primary key so that we can copy it.
unset($item[$this->urlVar]);
return $this->model->save($item);
}
示例2: check
public function check()
{
// Check for valid name
if (trim($this->title) == '') {
$this->setError(JText::_('COM_FIELDS_LOCATION_ERR_TABLES_TITLE'));
return false;
}
if (empty($this->alias)) {
$this->alias = $this->title;
}
$this->alias = JApplication::stringURLSafe($this->alias);
if (trim(str_replace('-', '', $this->alias)) == '') {
$this->alias = JString::increment($alias, 'dash');
}
$this->alias = str_replace(',', '-', $this->alias);
if (empty($this->type)) {
$this->type = 'text';
}
// Check the publish down date is not earlier than publish up.
if ($this->publish_down > $this->_db->getNullDate() && $this->publish_down < $this->publish_up) {
$this->setError(JText::_('JGLOBAL_START_PUBLISH_AFTER_FINISH'));
return false;
}
if (is_array($this->catid)) {
$this->catid = implode(',', $this->catid);
}
return true;
}
示例3: store
/**
* Overriden JTable::store to set modified data.
*
* @param boolean True to update fields even if they are null.
* @return boolean True on success.
* @since 1.6
*/
public function store($updateNulls = false)
{
$user = JFactory::getUser();
if (!$this->id) {
$this->created_by = $user->id;
// Verify that the name is unique
$table = JTable::getInstance('Library', 'JDeveloperTable');
while ($table->load(array('name' => $this->name, 'created_by' => $user->id))) {
$this->name = JString::increment($this->name);
}
}
return parent::store($updateNulls);
}
示例4: prepareExecute
/**
* Method to do something before save.
*
* @return void
*/
protected function prepareExecute()
{
parent::prepareExecute();
// Attempt to check-in the current record.
$data = array('cid' => array($this->recordId), 'quiet' => true);
$this->fetch($this->prefix, $this->viewList . '.check.checkin', $data);
// Reset the ID and then treat the request as for Apply.
$this->data[$this->key] = 0;
$this->data['checked_out'] = '';
$this->data['checked_out_time'] = '';
if (isset($this->data['title'])) {
$this->data['title'] = \JString::increment($this->data['title']);
}
if (isset($this->data['alias'])) {
$this->data['alias'] = \JString::increment($this->data['alias'], 'dash');
}
}
示例5: create
/**
* Create a package
*/
public function create()
{
jimport('joomla.filesystem.folder');
require_once JDeveloperLIB . '/archive.php';
require_once JDeveloperLIB . '/path.php';
require_once JDeveloperLIB . '/template.php';
$data = $this->input->post->get('jform', array(), 'array');
$params = JComponentHelper::getParams($this->option);
$files = array();
$path = JDeveloperArchive::getArchiveDir() . "/" . 'pkg_' . $data['name'];
while (JFile::exists($path . '.zip')) {
$data['name'] = JString::increment($data['name']);
}
JFolder::create($path);
foreach ($data['files'] as $file) {
if (preg_match('/^pkg_/', $file)) {
$files[] = "<file type=\"package\" id=\"" . str_replace('.zip', '', $file) . "\">{$file}</file>";
}
if (preg_match('/^com_/', $file)) {
$files[] = "<file type=\"component\" id=\"" . str_replace('.zip', '', $file) . "\">{$file}</file>";
}
if (preg_match('/^mod_/', $file)) {
$files[] = "<file type=\"module\" id=\"" . str_replace('.zip', '', $file) . "\">{$file}</file>";
}
if (preg_match('/^tpl_/', $file)) {
$files[] = "<file type=\"template\" id=\"" . str_replace('.zip', '', $file) . "\">{$file}</file>";
}
if (preg_match('/^plg_/', $file)) {
$files[] = "<file type=\"plugin\" id=\"" . str_replace('.zip', '', $file) . "\">{$file}</file>";
}
JFile::copy(JDeveloperArchive::getArchiveDir() . DS . $file, $path . DS . $file, null, true);
}
$template = new JDeveloperTemplate(JDeveloperTEMPLATES . "/pkg/manifest.xml");
$template->addPlaceholders(array('author' => $params->get('author'), 'author_email' => $params->get('email'), 'author_url' => $params->get('website'), 'copyright' => $params->get('copyright'), 'date' => date("M Y"), 'description' => $data['description'], 'files' => implode("\n\t\t", $files), 'license' => $params->get('license'), 'name' => $data['name'], 'version' => $data['version']));
$buffer = $template->getBuffer();
JFile::write($path . '/pkg_' . $data['name'] . '.xml', $buffer);
JDeveloperArchive::html($path);
JDeveloperArchive::zip($path);
JFolder::delete($path);
$this->setMessage(JText::sprintf('COM_JDEVELOPER_PACKAGE_CREATED', $data['name']));
$this->setRedirect(JRoute::_('index.php?option=com_jdeveloper&view=packages', false));
}
示例6: generateNewTitle
/**
* Method to change the title.
*
* @param integer $category_id The id of the category. Not used here.
* @param string $title The title.
* @param string $position The position.
*
* @return array Contains the modified title.
*
* @since 2.5
*/
protected function generateNewTitle($category_id, $title, $position)
{
// Alter the title & alias
$table = $this->getTable();
while ($table->load(array('position' => $position, 'title' => $title))) {
$title = JString::increment($title);
}
return array($title);
}
示例7: generateGroupTitle
/**
* Method to generate the title of group on Save as Copy action
*
* @param integer $parentId The id of the parent.
* @param string $title The title of group
*
* @return string Contains the modified title.
*
* @since 3.3.7
*/
protected function generateGroupTitle($parentId, $title)
{
// Alter the title & alias
$table = $this->getTable();
while ($table->load(array('title' => $title, 'parent_id' => $parentId))) {
if ($title == $table->title) {
$title = JString::increment($title);
}
}
return $title;
}
示例8: generateNewTitle
/**
* Method to change the title & alias.
*
* @param integer $category_id The id of the parent.
* @param string $alias The alias.
* @param string $name The title.
*
* @return array Contains the modified title and alias.
*
* @since 3.1
*/
protected function generateNewTitle($category_id, $alias, $name)
{
// Alter the title & alias
$table = $this->getTable();
while ($table->load(array('alias' => $alias, 'catid' => $category_id))) {
if ($name == $table->title) {
$name = JString::increment($name);
}
$alias = JString::increment($alias, 'dash');
}
return array($name, $alias);
}
示例9: check
/**
* Overloaded check method to ensure data integrity.
*
* @return boolean True on success.
*/
public function check()
{
if (isset($this->alias)) {
// Generate a valid alias
$this->generateAlias();
$table = JTable::getInstance('intervention', 'costbenefitprojectionTable');
while ($table->load(array('alias' => $this->alias)) && ($table->id != $this->id || $this->id == 0)) {
$this->alias = JString::increment($this->alias, 'dash');
}
}
/*
* Clean up keywords -- eliminate extra spaces between phrases
* and cr (\r) and lf (\n) characters from string.
* Only process if not empty.
*/
if (!empty($this->metakey)) {
// Array of characters to remove.
$bad_characters = array("\n", "\r", "\"", "<", ">");
// Remove bad characters.
$after_clean = JString::str_ireplace($bad_characters, "", $this->metakey);
// Create array using commas as delimiter.
$keys = explode(',', $after_clean);
$clean_keys = array();
foreach ($keys as $key) {
// Ignore blank keywords.
if (trim($key)) {
$clean_keys[] = trim($key);
}
}
// Put array back together delimited by ", "
$this->metakey = implode(", ", $clean_keys);
}
// Clean up description -- eliminate quotes and <> brackets
if (!empty($this->metadesc)) {
// Only process if not empty
$bad_characters = array("\"", "<", ">");
$this->metadesc = JString::str_ireplace($bad_characters, "", $this->metadesc);
}
// If we don't have any access rules set at this point just use an empty JAccessRules class
if (!$this->getRules()) {
$rules = $this->getDefaultAssetValues('com_costbenefitprojection.intervention.' . $this->id);
$this->setRules($rules);
}
// Set ordering
if ($this->published < 0) {
// Set ordering to 0 if state is archived or trashed
$this->ordering = 0;
}
return true;
}
示例10: generateAliasAndName
/**
* Method to change the name & alias if alias is already in use
*
* @param string $alias The alias.
* @param string $name The name.
* @param integer $categoryId Category identifier
*
* @return array Contains the modified title and alias.
*
* @since 3.2.3
*/
protected function generateAliasAndName($alias, $name, $categoryId)
{
$table = $this->getContactTable();
while ($table->load(array('alias' => $alias, 'catid' => $categoryId))) {
if ($name == $table->name) {
$name = JString::increment($name);
}
$alias = JString::increment($alias, 'dash');
}
return array($name, $alias);
}
示例11: createContent
//.........这里部分代码省略.........
$logofile = $dir . '/' . $row->logofile;
$search = array('{haslogo}', '{/haslogo}', '{logofile}');
$replace = array('', '', $logofile);
$template = str_replace($search, $replace, $template);
} else {
// Kein logo, dann Bereiche loeschen {haslogo} {/haslogo}
$regex = "#{haslogo}(.*?){/haslogo}#s";
$template = preg_replace($regex, '', $template);
}
if ($row->chiffre == 0) {
// Keine chiffre Anzeige, dann bereiche {ischiffre} {/ischiffre} loeschen
$regex = "#{ischiffre}(.*?){/ischiffre}#s";
$template = preg_replace($regex, '', $template);
$search = array('{isnotchiffre}', '{/isnotchiffre}');
$replace = array('', '');
$template = str_replace($search, $replace, $template);
} else {
// Chiffre Anzeige, dann bereiche {isnotchiffre} {/isnotchiffre} loeschen
$regex = "#{isnotchiffre}(.*?){/isnotchiffre}#s";
$template = preg_replace($regex, '', $template);
$search = array('{ischiffre}', '{/ischiffre}');
$replace = array('', '');
$template = str_replace($search, $replace, $template);
}
if (trim($row->pdffile) != '') {
// Es gibt ein pdf, dann nur die TAGS {haspdf}+{/haspdf} loeschen
// Es gibt ein logo, dann nur die TAGS {haslogo}+{/haslogo} loeschen
$pdffile = $dir . '/' . $row->pdffile;
$search = array('{haspdf}', '{/haspdf}', '{pdffile}');
$replace = array('', '', $pdffile);
$template = str_replace($search, $replace, $template);
} else {
// Kein pdf, dann Bereiche loeschen {haspdf} {/haspdf}
$regex = "#{haspdf}(.*?){/haspdf}#s";
$template = preg_replace($regex, '', $template);
}
if (trim($row->website) != '') {
// Website wert vorhanden
$search = array('{haswebsite}', '{/haswebsite}', '{website}');
$replace = array('', '', $row->website);
$template = str_replace($search, $replace, $template);
} else {
$regex = "#{haswebsite}(.*?){/haswebsite}#s";
$template = preg_replace($regex, '', $template);
}
if (trim($row->email) != '') {
// Website wert vorhanden
$search = array('{hasemail}', '{/hasemail}', '{email}');
$replace = array('', '', $row->email);
$template = str_replace($search, $replace, $template);
} else {
$regex = "#{hasemail}(.*?){/hasemail}#s";
$template = preg_replace($regex, '', $template);
}
$link = 'index.php?option=com_babioonad&view=contact&id=' . $row->id . '&Itemid=1';
$directcontactlink = JRoute::_($link);
$search = array('{teaser}', '{text}', '{anschrift}', '{directcontactlink}');
$confvar = $this->typeconf->get('showaddress', 2);
$anschrift = nl2br($row->anschrift);
if ($confvar > 2) {
$anschrift = $row->ainfo . '<br />' . $row->street . '<br />' . $row->pcode . ' ' . $row->city;
}
$replace = array(nl2br($row->teaser), nl2br($row->text), $anschrift, $directcontactlink);
$template = str_replace($search, $replace, $template);
$con = JTable::getInstance('Content');
// Split it in intro and fulltext
$tp = strpos($template, '<hr id="system-readmore" />');
if ($tp === false) {
$con->introtext = $template;
$con->fulltext = '';
} else {
$con->introtext = substr($template, 0, $tp);
$con->fulltext = substr($template, $tp + 27);
}
$con->title = $row->title;
$con->alias = JApplication::stringURLSafe($con->title);
$con->catid = $row->catid;
$con->version = 0;
$con->state = 1;
$con->access = $this->systemconfobj->get('newadsaccesslevel', 1);
$con->ordering = 0;
$con->images = array();
$con->created = $row->created;
$con->publish_up = $row->created;
$con->publish_down = 'Never';
// Make sure we have a uniq alias
if (trim(str_replace('-', '', $con->alias)) == '') {
$con->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
}
// Alter the alias
$concheck =& JTable::getInstance('Content');
while ($concheck->load(array('alias' => $con->alias, 'catid' => $con->catid))) {
$con->alias = JString::increment($con->alias, 'dash');
}
if (!$con->store()) {
return JError::raiseWarning(500, $con->getError());
}
$con->reorder('catid = ' . (int) $con->catid . ' AND state >= 0');
return $con;
}
示例12: cmGenerateNewTitle
/**
* Method to change the name.
*
* @param string $name The name.
*
* @return array Contains the modified name.
*
* @since 1.0.0
*/
protected function cmGenerateNewTitle($name)
{
// Alter the name.
$table = $this->getTable();
while ($table->load(array('name' => $name))) {
if ($name == $table->name) {
$name = JString::increment($name);
}
}
return $name;
}
示例13: setField
/**
* Method to set a field XML element.
*
* @param mix $name The name of field
* @param SimpleXMLElement $element The XML element object representation of the form field.
*
* @since 1.0.0
*/
public function setField($name, SimpleXMLElement $element, $increment = true)
{
if ($increment) {
while (array_key_exists($name, $this->fields)) {
$name = is_numeric($name) ? $name + 1 : JString::increment($name, 'dash');
}
}
$this->fields[$name] = $element;
return $this;
}
示例14: titleIncrement
public function titleIncrement($catId, $docId, &$alias, &$title)
{
$db = $this->getDbo();
do {
$query = $db->getQuery(true);
$query->select('COUNT(*)')->from('#__judownload_documents AS d')->join('', '#__judownload_documents_xref AS dxref on d.id = dxref.doc_id')->where('dxref.cat_id = ' . $catId)->where('dxref.main = 1')->where('d.title = ' . $db->quote($title))->where('d.alias = ' . $db->quote($alias));
if ($docId > 0) {
$query->where('d.id != ' . $docId);
}
$db->setQuery($query);
$result = $db->loadResult();
if ($result > 0) {
$title = JString::increment($title);
$alias = JString::increment($alias, 'dash');
}
} while ($result);
return true;
}
示例15: onUserAfterSave
function onUserAfterSave($user, $isnew, $success, $msg)
{
if (!$success) {
return false;
// if the user wasn't stored we don't resync
}
if (!$isnew) {
return false;
// if the user isn't new we don't sync
}
// ensure the user id is really an int
$user_id = (int) $user['id'];
if (empty($user_id)) {
die('invalid userid');
return false;
// if the user id appears invalid then bail out just in case
}
$category = $this->params->get('category', 0);
if (empty($category)) {
JError::raiseWarning(41, JText::_('PLG_CONTACTCREATOR_ERR_NO_CATEGORY'));
return false;
// bail out if we don't have a category
}
$dbo = JFactory::getDBO();
// grab the contact ID for this user; note $user_id is cleaned above
$dbo->setQuery('SELECT id FROM #__contact_details WHERE user_id = ' . $user_id);
$id = $dbo->loadResult();
JTable::addIncludePath(JPATH_ADMINISTRATOR . '/components/com_contact/tables');
$contact = JTable::getInstance('contact', 'ContactTable');
if (!$contact) {
return false;
}
if ($id) {
$contact->load($id);
} elseif ($this->params->get('autopublish', 0)) {
$contact->published = 1;
}
$contact->name = $user['name'];
$contact->user_id = $user_id;
$contact->email_to = $user['email'];
$contact->catid = $category;
$contact->language = '*';
// check for already existing alias
$table = JTable::getInstance('contact', 'ContactTable');
$contact->alias = JApplication::stringURLSafe($contact->name);
while ($table->load(array('alias' => $contact->alias, 'catid' => $contact->catid))) {
$contact->alias = JString::increment($contact->alias, 'dash');
}
$autowebpage = $this->params->get('autowebpage', '');
if (!empty($autowebpage)) {
// search terms
$search_array = array('[name]', '[username]', '[userid]', '[email]');
// replacement terms, urlencoded
$replace_array = array_map('urlencode', array($user['name'], $user['username'], $user['id'], $user['email']));
// now replace it in together
$contact->webpage = str_replace($search_array, $replace_array, $autowebpage);
}
if ($contact->check()) {
$result = $contact->store();
}
if (!isset($result) || !$result) {
JError::raiseError(42, JText::sprintf('PLG_CONTACTCREATOR_ERR_FAILED_UPDATE', $contact->getError()));
}
}