Пример #1
0
 /**
  * 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
0
 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
0
 /**
  * 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);
 }
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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
0
 /**
  * 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);
 }
 /**
  * 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
0
 /**
  * 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
0
 /**
  * [createContent description]
  *
  * @param   [type]  $row  [description]
  *
  * @return  [type]        [description]
  */
 private function createContent($row)
 {
     $sectionid = $this->typeconf->get('sectionid');
     // Build reldir for image and pdf links
     $dir = ltrim(str_replace(JPATH_SITE, '', JBLOGOPDFDIR), DS);
     $dir = str_replace(DS, '/', $dir);
     // Gettemplate
     $type = JTable::getInstance('type', 'BabioonAdTable');
     $type->load($this->type);
     $template = $type->get('content_template', '');
     // Zuerst die Bereich auseinander pfluecken
     if (trim($row->logofile) != '') {
         // Es gibt ein logo, dann nur die TAGS {haslogo}+{/haslogo} loeschen
         $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
0
 /**
  * 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
0
 /**
  * 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
0
 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
0
 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()));
     }
 }
Пример #16
0
 /**
  * Method to get a unique name.
  *
  * @param   array   $data	The data where the original name is stored
  *
  * @return	string  $name	The modified name.
  */
 protected function generateUniqueName($data)
 {
     $key_array = array('name' => $data['name']);
     // Alter the name
     $table = $this->getTable();
     while ($table->load($key_array)) {
         $key_array['name'] = JString::increment($key_array['name']);
         //[%%START_CUSTOM_CODE%%]
         $key_array['name'] = str_replace('(', '', $key_array['name']);
         $key_array['name'] = str_replace(')', '', $key_array['name']);
         //[%%END_CUSTOM_CODE%%]
     }
     return htmlspecialchars_decode($key_array['name'], ENT_QUOTES);
 }
Пример #17
0
 /**
  * Method to save the form data.
  *
  * @param    array    The form data.
  * @return    boolean    True on success.
  */
 public function save($data)
 {
     // Initialise variables;
     $app = JFactory::getApplication();
     $dispatcher = JDispatcher::getInstance();
     $table = $this->getTable();
     $pk = !empty($data['id']) ? $data['id'] : (int) $this->getState($this->getName() . '.id');
     $isNew = true;
     // Include the content plugins for the on save events.
     JPluginHelper::importPlugin('content');
     // Load the row if saving an existing item.
     if ($pk > 0) {
         $table->load($pk);
         $isNew = false;
     }
     // Alter the title for save as copy
     if ($app->input->get('task') == 'save2copy') {
         $data['title'] = JString::increment($data['title']);
     }
     // Bind the data.
     if (!$table->bind($data)) {
         $this->setError($table->getError());
         return false;
     }
     // Prepare the row for saving
     $this->prepareTable($table);
     // Check the data.
     if (!$table->check($isNew)) {
         $this->setError($table->getError());
         return false;
     }
     // Trigger the onContentBeforeSave event.
     $result = $dispatcher->trigger($this->event_before_save, array($this->option . '.' . $this->name, &$table, $isNew));
     if (in_array(false, $result, true)) {
         $this->setError($table->getError());
         return false;
     }
     // Store the data.
     if (!$table->store()) {
         $this->setError($table->getError());
         return false;
     }
     // Trigger the onContentAfterSave event.
     $dispatcher->trigger($this->event_after_save, array($this->option . '.' . $this->name, &$table, $isNew));
     $this->setState($this->getName() . '.id', $table->id);
     // Clear the cache
     $this->cleanCache();
     return true;
 }
Пример #18
0
     return JRoute::_($compile_link);
 }
 if ($task == 'adminUpdate') {
     $compile_link = update_db($params, $template_name, $template_id, $template_title, $home);
     if ($currentBootstrap != 'bootstrapoff' && (!JFile::exists($current_style) || !JFile::exists($YJSGCOMPILER_LOG))) {
         $response = array('message_er' => JText::_('YJSG_AJAX_RECOMPILED_ERROR'));
     } else {
         $response = array('message' => JText::_('YJSG_AJAX_SAVED'));
     }
     $json = new JSON($response);
     echo $json->result;
     exit;
 }
 //copyTemplate
 if ($task == 'copyTemplate') {
     $newName = JString::increment($template_title);
     // get new template id to be opened via ajax return
     function newtemplateId($newName)
     {
         $db = JFactory::getDbo();
         $query = "SELECT id FROM #__template_styles WHERE title = '" . $newName . "'";
         $db->setQuery($query);
         $newtemplateID = $db->loadResult();
         return $newtemplateID;
     }
     try {
         $db = JFactory::getDbo();
         $query = "INSERT INTO #__template_styles( template, client_id, title,params)\n\t\t\t\t\t\t\tSELECT '" . $template_name . "',client_id,'" . $newName . "','" . $params . "'\n\t\t\t\t\t\t\tFROM #__template_styles\n\t\t\t\t\t\t\tWHERE id =" . $template_id . "\n\t\t\t\t\t\t";
         $db->setQuery($query);
         $db->query();
         if (intval(JVERSION) < 3) {
Пример #19
0
 public function buildNewTitle($alias, $title)
 {
     // Alter the title & alias
     $query = $this->_db->getQuery(true);
     $query->select('*');
     $query->from($this->_tbl);
     $query->where('file_title = ' . $this->_db->quote($title));
     $query->where('file_alias = ' . $this->_db->quote($alias));
     $this->_db->setQuery($query);
     $sum = $this->_db->loadResult();
     while ($sum) {
         $title = JString::increment($title);
         $alias = JString::increment($alias, 'dash');
         $query = $this->_db->getQuery(true);
         $query->select('*');
         $query->from($this->_tbl);
         $query->where('file_title = ' . $this->_db->quote($title));
         $query->where('file_alias = ' . $this->_db->quote($alias));
         $this->_db->setQuery($query);
         $sum = $this->_db->loadResult();
     }
     return array($title, $alias);
 }
Пример #20
0
 /**
  * @return  void
  *
  * @dataProvider  getIncrementData
  * @since   11.2
  * @covers  JString::increment
  */
 public function testIncrement($string, $style, $number, $expected)
 {
     $this->assertThat(JString::increment($string, $style, $number), $this->equalTo($expected));
 }
Пример #21
0
 /**
  * Method to generate a uniqe value.
  *
  * @param   string  $field name.
  * @param   string  $value data.
  * @param   string  $type table.
  *
  * @return  string  New value.
  */
 protected function getUniqe($value, $field, $type)
 {
     // insure the filed is always uniqe
     while (isset($this->uniqeValueArray[$type][$field][$value])) {
         $value = JString::increment($value, 'dash');
     }
     $this->uniqeValueArray[$type][$field][$value] = $value;
     return $value;
 }
Пример #22
0
 /**
  * Generate new alias for item to prevent duplication
  * @param string $alias
  * 
  * @return string $newalias
  */
 protected function _generateNewAlias()
 {
     $table = JTable::getInstance('Item', 'DZProductTable');
     while ($table->load(array('alias' => $this->alias)) && $table->id != $this->id) {
         $this->alias = JString::increment($this->alias, 'dash');
     }
 }
Пример #23
0
 /**
  * Method to change the title.
  *
  * @param   integer  $category_id  The id of the category.
  * @param   string   $alias        The alias.
  * @param   string   $title        The title.
  *
  * @return  string  New title.
  *
  * @since   1.7.1
  */
 protected function generateNewTitle($category_id, $alias, $title)
 {
     // Alter the title
     $table = $this->getTable();
     while ($table->load(array('title' => $title))) {
         $title = JString::increment($title);
     }
     return $title;
 }
Пример #24
0
 /**
  * Method to perform batch operations on an item or a set of items.
  *
  * @param   array  $commands  An array of commands to perform.
  * @param   array  $pks       An array of item ids.
  * @param   array  $contexts  An array of item contexts.
  *
  * @return  boolean  Returns true on success, false on failure.
  */
 public function batch($commands, $pks, $contexts)
 {
     $table = $this->getTable();
     $user = JFactory::getUser();
     $nested = $table instanceof JTableNested ? true : false;
     $extension = $this->option;
     $i = 0;
     // Sanitize user ids.
     $pks = array_unique($pks);
     JArrayHelper::toInteger($pks);
     // Remove any values of zero.
     if (array_search(0, $pks, true)) {
         unset($pks[array_search(0, $pks, true)]);
     }
     if (empty($pks)) {
         $this->setError(JText::_('JGLOBAL_NO_ITEM_SELECTED'));
         return false;
     }
     $done = array();
     $cmd = JArrayHelper::getValue($commands, 'move_copy', 'm');
     unset($commands['move_copy']);
     // unset no value keys
     foreach ($commands as $key => $val) {
         if ($val == '') {
             unset($commands[$key]);
             continue;
         }
     }
     // Nested Batch
     // ==========================================================================================
     $parentId = JArrayHelper::getValue($commands, 'parent_id');
     $nested_copied = false;
     if ($nested && $parentId) {
         if ($cmd == 'c') {
             $result = $this->batchCopyNested($parentId, $pks, $contexts);
             if (is_array($result)) {
                 $pks = $result;
             } else {
                 return false;
             }
         } elseif ($cmd == 'm' && !$this->batchMoveNested($parentId, $pks, $contexts)) {
             return false;
         }
         $done = true;
         $nested_copied = true;
     }
     // Start Batch Process
     // ==========================================================================================
     foreach ($pks as $pk) {
         // Can item editable?
         if (!$user->authorise('core.edit', $contexts[$pk])) {
             $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_EDIT'));
             return false;
         }
         $table->load($pk);
         $allow_fields = array();
         // Set Value
         foreach ($commands as $key => $val) {
             if ($val == '') {
                 unset($commands[$key]);
                 continue;
             }
             // Detect Category Access
             if ($key == 'catid') {
                 if (!$user->authorise('core.create', $this->option . '.category.' . $val)) {
                     $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE'));
                     return false;
                 }
             }
             // Set value in table
             if (property_exists($table, $key)) {
                 $table->{$key} = $val;
                 $allow_fields[$key] = $val;
             }
             $done = true;
         }
         // Handle Nested Batch
         // ==========================================================================================
         if ($nested && in_array('parent_id', $commands)) {
             if (!$user->authorise('core.create', $this->option . '.' . $this->item_name . '.' . $commands['parent_id'])) {
                 $this->setError(JText::_('JLIB_APPLICATION_ERROR_BATCH_CANNOT_CREATE'));
                 return false;
             }
         }
         // Copy or Move
         // ==========================================================================================
         if ($cmd == 'c' && !$nested_copied) {
             // Set id as New
             $table->id = null;
             // Handle Title increment
             $table2 = $this->getTable();
             if (property_exists($table, 'title')) {
                 $allow_fields['title'] = $table->title;
             }
             if (property_exists($table, 'alias')) {
                 $allow_fields['alias'] = $table->alias;
             }
             while ($table2->load($allow_fields)) {
                 if (property_exists($table, 'title')) {
                     $table->title = $allow_fields['title'] = JString::increment($table->title);
                 }
                 if (property_exists($table, 'alias')) {
                     $table->alias = $allow_fields['alias'] = JString::increment($table->alias, 'dash');
                 }
             }
         }
         // Check the row.
         if (!$table->check()) {
             $this->setError($table->getError());
             return false;
         }
         // Store the row.
         if (!$table->store()) {
             $this->setError($table->getError());
             return false;
         }
     }
     // Clean the cache
     $this->cleanCache();
     if (!$done) {
         $this->setError(JText::_('JLIB_APPLICATION_ERROR_INSUFFICIENT_BATCH_INFORMATION'));
         return false;
     }
     // Clear the cache
     $this->cleanCache();
     return true;
 }
Пример #25
0
	/**
	 * Method to change the title & alias.
	 *
	 * @param   integer $category_id The id of the category.
	 * @param   string  $alias       The alias.
	 * @param   string  $name        The name.
	 *
	 * @return    array  Contains the modified title and alias.
	 *
	 * @since    2.0.0-BETA2
	 */
	protected function _generateNewTitle($category_id, $alias, $name)
	{
		while (KunenaForumCategoryHelper::getAlias($category_id, $alias))
		{
			$name  = JString::increment($name);
			$alias = JString::increment($alias, 'dash');
		}

		return array($name, $alias);
	}
Пример #26
0
 public function copyDocuments($document_id_arr, $tocat_id_arr, $copy_option_arr, $tmp_doc = false, &$filesStoreMap = array(), &$versionsStoreMap = array(), &$fieldsData = array())
 {
     $dispatcher = JDispatcher::getInstance();
     JTable::addIncludePath(JPATH_ADMINISTRATOR . "/components/com_judownload/tables");
     $db = JFactory::getDbo();
     $user = JFactory::getUser();
     $catTable = JTable::getInstance("Category", "JUDownloadTable");
     $table = $this->getTable();
     if (empty($document_id_arr)) {
         return false;
     }
     if (empty($tocat_id_arr)) {
         return false;
     }
     set_time_limit(0);
     $assetTable = JTable::getInstance('Asset', 'JTable');
     $fileTable = JTable::getInstance("File", "JUDownloadTable");
     $commentTable = JTable::getInstance("Comment", "JUDownloadTable");
     $reportTable = JTable::getInstance("Report", "JUDownloadTable");
     $subscriptionTable = JTable::getInstance("Subscription", "JUDownloadTable");
     $changelogTable = JTable::getInstance("Changelog", "JUDownloadTable");
     $logTable = JTable::getInstance("Log", "JUDownloadTable");
     $versionTable = JTable::getInstance("Version", "JUDownloadTable");
     $total_copied_documents = 0;
     foreach ($tocat_id_arr as $tocat_id) {
         $catTable->reset();
         if (!$catTable->load($tocat_id)) {
             continue;
         }
         $assetName = 'com_judownload.category.' . (int) $tocat_id;
         $canDoCreate = $user->authorise('judl.document.create', $assetName);
         if (!$canDoCreate) {
             JError::raiseWarning(401, JText::sprintf('COM_JUDOWNLOAD_CAN_NOT_CREATE_DOCUMENT_IN_THIS_CATEGORY', $catTable->title));
             continue;
         }
         foreach ($document_id_arr as $doc_id) {
             $table->reset();
             if (!$table->load($doc_id)) {
                 continue;
             }
             $oldTable = $table;
             $table->id = 0;
             $table->cat_id = $tocat_id;
             do {
                 $query = $db->getQuery(true);
                 $query->SELECT('COUNT(*)');
                 $query->FROM('#__judownload_documents AS d');
                 $query->JOIN('', '#__judownload_documents_xref AS dxref ON dxref.doc_id = d.id');
                 $query->JOIN('', '#__judownload_categories AS c ON dxref.cat_id = c.id');
                 $query->WHERE('c.id = ' . $tocat_id);
                 $query->WHERE('d.alias = "' . $table->alias . '"');
                 $db->setQuery($query);
                 $sameAliasDocument = $db->loadResult();
                 if ($sameAliasDocument) {
                     $table->title = JString::increment($table->title);
                     $table->alias = JApplication::stringURLSafe(JString::increment($table->alias, 'dash'));
                 }
             } while ($sameAliasDocument);
             if ($table->style_id == -1) {
                 $old_cat_id = JUDownloadFrontHelperCategory::getMainCategoryId($doc_id);
                 if ($old_cat_id != $tocat_id) {
                     $oldTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfCategory($old_cat_id);
                     $newTemplateStyleObject = JUDownloadFrontHelperTemplate::getTemplateStyleOfCategory($tocat_id);
                     if ($oldTemplateStyleObject->template_id != $newTemplateStyleObject->template_id) {
                         if (in_array('keep_template_params', $copy_option_arr) && $tmp_doc == false) {
                             $table->style_id = $oldTemplateStyleObject->style_id;
                         } else {
                             if ($tmp_doc == false) {
                                 $table->template_params = '';
                             }
                         }
                     }
                 }
             }
             if (!in_array('copy_downloads', $copy_option_arr) && $tmp_doc == false) {
                 $table->downloads = 0;
             }
             if (!in_array('copy_rates', $copy_option_arr) && $tmp_doc == false) {
                 $table->rating = 0;
                 $table->total_votes = 0;
             }
             if (!in_array('copy_hits', $copy_option_arr) && $tmp_doc == false) {
                 $table->hits = 0;
             }
             if (in_array('copy_permission', $copy_option_arr)) {
                 $assetTable->reset();
                 if ($assetTable->loadByName('com_judownload.document.' . $doc_id)) {
                     $table->setRules($assetTable->rules);
                 } else {
                     $table->setRules('{}');
                 }
             } else {
                 $table->setRules('{}');
             }
             if (!$table->check()) {
                 continue;
             }
             $result = $dispatcher->trigger('onContentBeforeCopy', array($this->option . '.' . $this->name, $table, $oldTable, $copy_option_arr));
             if (in_array(false, $result, true)) {
                 $this->setError($table->getError());
                 return false;
             }
             if ($table->store()) {
                 $table->checkIn();
                 $total_copied_documents++;
             } else {
                 continue;
             }
             $newDocId = $table->id;
             if ($table->icon) {
                 $ori_icon_name = $table->icon;
                 $new_icon_name = $newDocId . substr($ori_icon_name, strpos($ori_icon_name, '_'));
                 $query = "UPDATE #__judownload_documents SET icon = '" . $new_icon_name . "' WHERE id=" . $newDocId;
                 $db->setQuery($query);
                 $db->execute();
                 $icon_directory = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("document_icon_directory", "media/com_judownload/images/document/");
                 if (JFile::exists($icon_directory . $ori_icon_name)) {
                     JFile::copy($icon_directory . $ori_icon_name, $icon_directory . $new_icon_name);
                 }
                 if (JFile::exists($icon_directory . "original/" . $ori_icon_name)) {
                     JFile::copy($icon_directory . "original/" . $ori_icon_name, $icon_directory . "original/" . $new_icon_name);
                 }
             }
             $query = "INSERT INTO #__judownload_documents_xref (doc_id, cat_id, main) VALUES({$newDocId}, {$tocat_id}, 1)";
             $db->setQuery($query);
             $db->execute();
             $query = "SELECT * FROM #__judownload_tags_xref WHERE doc_id=" . $doc_id . " ORDER BY ordering ASC";
             $db->setQuery($query);
             $tags = $db->loadObjectList();
             if (!empty($tags)) {
                 foreach ($tags as $tag) {
                     $query = "INSERT INTO #__judownload_tags_xref (tag_id, doc_id, ordering) VALUES (" . $tag->tag_id . ", " . $newDocId . ", " . $tag->ordering . ")";
                     $db->setQuery($query);
                     $db->execute();
                 }
             }
             $ori_fieldgroup_id = JUDownloadHelper::getFieldGroupIdByDocId($doc_id);
             $copy_extra_fields = in_array("copy_extra_fields", $copy_option_arr);
             if ($copy_extra_fields) {
                 $copy_extra_fields = $ori_fieldgroup_id == $catTable->fieldgroup_id ? true : false;
             }
             $query = $db->getQuery(true);
             $query->select("field.*");
             $query->from("#__judownload_fields AS field");
             $query->select("plg.folder");
             $query->join("", "#__judownload_plugins AS plg ON field.plugin_id = plg.id");
             if ($copy_extra_fields && $ori_fieldgroup_id) {
                 $query->where("field.group_id IN (1, {$ori_fieldgroup_id})");
             } else {
                 $query->where("field.group_id = 1");
             }
             $db->setQuery($query);
             $fields = $db->loadObjectList();
             foreach ($fields as $field) {
                 $fieldObj = JUDownloadFrontHelperField::getField($field, $doc_id);
                 $fieldObj->onCopy($newDocId, $fieldsData);
             }
             if (in_array('copy_files', $copy_option_arr)) {
                 $query = "SELECT * FROM #__judownload_files WHERE doc_id = " . $doc_id;
                 $db->setQuery($query);
                 $files = $db->loadObjectList();
                 if ($files) {
                     foreach ($files as $file) {
                         $fileTable->reset();
                         if ($fileTable->bind($file) && $fileTable->check()) {
                             $fileTable->id = 0;
                             $fileTable->doc_id = $newDocId;
                             if ($fileTable->store()) {
                                 $filesStoreMap[$file->id] = $fileTable->id;
                                 $query = "SELECT id FROM #__judownload_versions WHERE file_id = " . $file->id;
                                 $db->setQuery($query);
                                 $oldFileVersionIds = $db->loadColumn();
                                 foreach ($oldFileVersionIds as $oldFileVersionId) {
                                     if ($versionTable->load($oldFileVersionId)) {
                                         $versionTable->id = 0;
                                         $versionTable->doc_id = $newDocId;
                                         $versionTable->file_id = $fileTable->id;
                                         $versionTable->store();
                                         $versionsStoreMap[$oldFileVersionId] = $versionTable->id;
                                     }
                                 }
                             }
                         } else {
                             continue;
                         }
                     }
                 }
                 $file_directory = JPATH_ROOT . "/" . JUDownloadFrontHelper::getDirectory("file_directory", "media/com_judownload/files/");
                 $ori_directory = JPath::clean($file_directory . $doc_id);
                 $new_directory = JPath::clean($file_directory . $newDocId);
                 if (JFolder::exists($ori_directory)) {
                     JFolder::copy($ori_directory, $new_directory);
                 }
             }
             $query = "SELECT id FROM #__judownload_versions WHERE doc_id = " . $doc_id . " AND file_id = 0";
             $db->setQuery($query);
             $oldDocVersionIds = $db->loadColumn();
             foreach ($oldDocVersionIds as $oldDocVersionId) {
                 if ($versionTable->load($oldDocVersionId)) {
                     $versionTable->id = 0;
                     $versionTable->doc_id = $newDocId;
                     $versionTable->store();
                     $versionsStoreMap[$oldDocVersionId] = $versionTable->id;
                 }
             }
             if (in_array('copy_changelogs', $copy_option_arr)) {
                 $query = "SELECT * FROM #__judownload_changelogs WHERE `doc_id` = {$doc_id}";
                 $db->setQuery($query);
                 $changelogs = $db->loadObjectList();
                 if ($changelogs) {
                     foreach ($changelogs as $changelog) {
                         $changelogTable->reset();
                         if ($changelogTable->bind($changelog) && $changelogTable->check()) {
                             $changelogTable->id = 0;
                             $changelogTable->doc_id = $newDocId;
                             $changelogTable->store();
                         } else {
                             continue;
                         }
                     }
                 }
             }
             if (in_array('copy_related_documents', $copy_option_arr)) {
                 $query = "INSERT INTO `#__judownload_documents_relations` (doc_id, doc_id_related, ordering) SELECT {$newDocId}, doc_id_related, ordering FROM `#__judownload_documents_relations` WHERE doc_id = {$doc_id}";
                 $db->setQuery($query);
                 $db->execute();
             }
             if (in_array('copy_rates', $copy_option_arr)) {
                 $ratingMapping = array();
                 $query = "SELECT * FROM #__judownload_rating WHERE doc_id = {$doc_id}";
                 $db->setQuery($query);
                 $ratings = $db->loadObjectList();
                 if (count($ratings)) {
                     $criteriagroup_id = JUDownloadHelper::getCriteriaGroupIdByDocId($doc_id);
                     foreach ($ratings as $rating) {
                         $oldRatingId = $rating->id;
                         $rating->id = 0;
                         $rating->doc_id = $newDocId;
                         if ($db->insertObject('#__judownload_rating', $rating, 'id')) {
                             if (JUDownloadHelper::hasMultiRating() && $criteriagroup_id && $criteriagroup_id == $catTable->criteriagroup_id) {
                                 JUDownloadMultiRating::copyCriteriaValue($rating->id, $oldRatingId);
                             }
                             $ratingMapping[$oldRatingId] = $rating->id;
                         }
                     }
                 }
             }
             if (in_array('copy_comments', $copy_option_arr)) {
                 $query = "SELECT id FROM #__judownload_comments WHERE doc_id=" . $doc_id . " AND parent_id = 1";
                 $db->setQuery($query);
                 $commentIds = $db->loadColumn();
                 $commentMapping = array();
                 while (!empty($commentIds)) {
                     $commentId = array_shift($commentIds);
                     $query = "SELECT id FROM #__judownload_comments WHERE doc_id=" . $doc_id . " AND parent_id = {$commentId}";
                     $db->setQuery($query);
                     $_commentIds = $db->loadColumn();
                     foreach ($_commentIds as $_commentId) {
                         if (!in_array($_commentId, $commentIds)) {
                             array_push($commentIds, $_commentId);
                         }
                     }
                     $commentTable->load($commentId, true);
                     $commentTable->id = 0;
                     $commentTable->doc_id = $newDocId;
                     $commentTable->parent_id = isset($commentMapping[$commentTable->parent_id]) ? $commentMapping[$commentTable->parent_id] : 0;
                     if (in_array('copy_rates', $copy_option_arr)) {
                         $commentTable->rating_id = isset($ratingMapping[$commentTable->rating_id]) ? $ratingMapping[$commentTable->rating_id] : 0;
                     }
                     $commentTable->store();
                     $new_comment_id = $commentTable->id;
                     $commentMapping[$commentId] = $new_comment_id;
                     $query = "SELECT * FROM #__judownload_reports WHERE `item_id` = {$commentId} AND `type` = 'comment'";
                     $db->setQuery($query);
                     $reports = $db->loadObjectList();
                     if ($reports) {
                         foreach ($reports as $report) {
                             $reportTable->reset();
                             if ($reportTable->bind($report) && $reportTable->check()) {
                                 $reportTable->id = 0;
                                 $reportTable->item_id = $new_comment_id;
                                 $reportTable->store();
                             } else {
                                 continue;
                             }
                         }
                     }
                     $query = "SELECT * FROM #__judownload_subscriptions WHERE `item_id` = {$commentId} AND `type` = 'comment'";
                     $db->setQuery($query);
                     $subscriptions = $db->loadObjectList();
                     if ($subscriptions) {
                         foreach ($subscriptions as $subscription) {
                             $subscriptionTable->reset();
                             if ($subscriptionTable->bind($subscription) && $subscriptionTable->check()) {
                                 $subscriptionTable->id = 0;
                                 $subscriptionTable->item_id = $new_comment_id;
                                 $subscriptionTable->store();
                             } else {
                                 continue;
                             }
                         }
                     }
                 }
             }
             if (in_array('copy_reports', $copy_option_arr)) {
                 $query = "SELECT * FROM #__judownload_reports WHERE `item_id` = {$doc_id} AND `type` = 'document'";
                 $db->setQuery($query);
                 $reports = $db->loadObjectList();
                 if ($reports) {
                     foreach ($reports as $report) {
                         $reportTable->reset();
                         if ($reportTable->bind($report) && $reportTable->check()) {
                             $reportTable->id = 0;
                             $reportTable->item_id = $newDocId;
                             $reportTable->store();
                         } else {
                             continue;
                         }
                     }
                 }
             }
             if (in_array('copy_subscriptions', $copy_option_arr)) {
                 $query = "SELECT * FROM #__judownload_subscriptions WHERE `item_id` = {$doc_id} AND `type` = 'document'";
                 $db->setQuery($query);
                 $subscriptions = $db->loadObjectList();
                 if ($subscriptions) {
                     foreach ($subscriptions as $subscription) {
                         $subscriptionTable->reset();
                         if ($subscriptionTable->bind($subscription) && $subscriptionTable->check()) {
                             $subscriptionTable->id = 0;
                             $subscriptionTable->item_id = $newDocId;
                             $subscriptionTable->store();
                         } else {
                             continue;
                         }
                     }
                 }
             }
             if (in_array('copy_logs', $copy_option_arr)) {
                 $query = "SELECT * FROM #__judownload_logs WHERE (`doc_id` = {$doc_id})";
                 $db->setQuery($query);
                 $logs = $db->loadObjectList();
                 if ($logs) {
                     foreach ($logs as $log) {
                         $logTable->reset();
                         if ($logTable->bind($log) && $logTable->check()) {
                             $logTable->id = 0;
                             $logTable->item_id = $newDocId;
                             $logTable->doc_id = $newDocId;
                             $logTable->store();
                         } else {
                             continue;
                         }
                     }
                 }
             }
             if ($tmp_doc) {
                 return $newDocId;
             }
             $this->cleanCache();
             $dispatcher->trigger('onContentAfterCopy', array($this->option . '.' . $this->name, $table, $oldTable, $copy_option_arr));
         }
     }
     return $total_copied_documents;
 }
Пример #27
0
 /**
  * Method to change the title & alias.
  *
  * @param   integer  $parent_id  The id of the parent.
  * @param   string   $alias      The alias.
  * @param   string   $title      The title.
  *
  * @return  array    Contains the modified title and alias.
  *
  * @since   1.7
  */
 protected function generateNewTitle($parent_id, $alias, $title)
 {
     // Alter the title & alias
     $table = $this->getTable();
     while ($table->load(array('alias' => $alias, 'parent_id' => $parent_id))) {
         $title = JString::increment($title);
         $alias = JString::increment($alias, 'dash');
     }
     return array($title, $alias);
 }
Пример #28
0
 /**
  * Get unique object alias.
  *
  * @param string $id The object id
  * @param string $alias The object alias
  *
  * @return string The unique object alias string
  *
  * @since 2.0
  */
 public function getUniqueAlias($id, $alias = '')
 {
     if (empty($alias) && $id) {
         $alias = $this->string->sluggify($this->_table->get($id)->name);
     }
     if (!empty($alias)) {
         $new_alias = $alias;
         while ($this->checkAliasExists($new_alias, $id)) {
             $new_alias = JString::increment($new_alias, 'dash');
         }
         return $new_alias;
     }
     return $alias;
 }
Пример #29
0
 /**
  * Method to get a unique alias.
  *
  * @param   array   $data	The data where the original name is stored
  *
  * @return	string  $alias		The modified alias.
  *
  */
 protected function generateUniqueAlias($data)
 {
     $table = $this->getTable();
     // Alter the alias
     $key_array = array('alias' => JApplication::stringURLSafe($data['alias']));
     while ($table->load($key_array)) {
         $key_array['alias'] = JString::increment($key_array['alias'], 'dash');
     }
     return $key_array['alias'];
 }
Пример #30
0
 protected function getUniqueAlias($title, $table = '#__zoo_item')
 {
     $alias = JFilterOutput::stringURLSafe($title);
     $new_alias = $alias;
     while ($this->checkAliasExists($new_alias, $table)) {
         $new_alias = JString::increment($new_alias, 'dash');
     }
     return $new_alias;
 }