/** * Stores a contact * * @param boolean True to update fields even if they are null. * * @return boolean True on success, false on failure. * * @since 1.6 */ public function store($updateNulls = false) { // Transform the params field if (is_array($this->params)) { $registry = new JRegistry(); $registry->loadArray($this->params); $this->params = (string) $registry; } $date = JFactory::getDate(); $user = JFactory::getUser(); if ($this->id) { // Existing item $this->modified = $date->toSql(); $this->modified_by = $user->get('id'); } else { // New contact. A contact created and created_by field can be set by the user, // so we don't touch either of these if they are set. if (!(int) $this->created) { $this->created = $date->toSql(); } if (empty($this->created_by)) { $this->created_by = $user->get('id'); } } // Set publish_up to null date if not set if (!$this->publish_up) { $this->publish_up = $this->_db->getNullDate(); } // Set publish_down to null date if not set if (!$this->publish_down) { $this->publish_down = $this->_db->getNullDate(); } // Set xreference to empty string if not set if (!$this->xreference) { $this->xreference = ''; } // Store utf8 email as punycode $this->email_to = JStringPunycode::emailToPunycode($this->email_to); // Convert IDN urls to punycode $this->webpage = JStringPunycode::urlToPunycode($this->webpage); // Verify that the alias is unique $table = JTable::getInstance('Contact', 'ContactTable'); if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) { $this->setError(JText::_('COM_CONTACT_ERROR_UNIQUE_ALIAS')); return false; } return parent::store($updateNulls); }
/** * Overload the store method for the Weblinks table. * * @param boolean Toggle whether null values should be updated. * * @return boolean True on success, false on failure. * * @since 1.6 */ public function store($updateNulls = false) { $date = JFactory::getDate(); $user = JFactory::getUser(); $this->modified = $date->toSql(); if ($this->id) { // Existing item $this->modified_by = $user->id; } else { // New weblink. A weblink created and created_by field can be set by the user, // so we don't touch either of these if they are set. if (!(int) $this->created) { $this->created = $date->toSql(); } if (empty($this->created_by)) { $this->created_by = $user->id; } } // Set publish_up to null date if not set if (!$this->publish_up) { $this->publish_up = $this->getDbo()->getNullDate(); } // Set publish_down to null date if not set if (!$this->publish_down) { $this->publish_down = $this->getDbo()->getNullDate(); } // Verify that the alias is unique $table = JTable::getInstance('Weblink', 'WeblinksTable'); if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) { $this->setError(JText::_('COM_WEBLINKS_ERROR_UNIQUE_ALIAS')); return false; } // Convert IDN urls to punycode $this->url = JStringPunycode::urlToPunycode($this->url); return parent::store($updateNulls); }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 1.6 */ public function save($data) { $input = JFactory::getApplication()->input; $filter = JFilterInput::getInstance(); if (isset($data['metadata']) && isset($data['metadata']['author'])) { $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM'); } if (isset($data['created_by_alias'])) { $data['created_by_alias'] = $filter->clean($data['created_by_alias'], 'TRIM'); } if (isset($data['images']) && is_array($data['images'])) { $registry = new Registry(); $registry->loadArray($data['images']); $data['images'] = (string) $registry; } JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php'); // Cast catid to integer for comparison $catid = (int) $data['catid']; // Check if New Category exists if ($catid > 0) { $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_content'); } // Save New Categoryg if ($catid == 0 && $this->canCreateCategory()) { $table = array(); $table['title'] = $data['catid']; $table['parent_id'] = 1; $table['extension'] = 'com_content'; $table['language'] = $data['language']; $table['published'] = 1; // Create new category and get catid back $data['catid'] = CategoriesHelper::createCategory($table); } if (isset($data['urls']) && is_array($data['urls'])) { $check = $input->post->get('jform', array(), 'array'); foreach ($data['urls'] as $i => $url) { if ($url != false && ($i == 'urla' || $i == 'urlb' || $i == 'urlc')) { if (preg_match('~^#[a-zA-Z]{1}[a-zA-Z0-9-_:.]*$~', $check['urls'][$i]) == 1) { $data['urls'][$i] = $check['urls'][$i]; } else { $data['urls'][$i] = JStringPunycode::urlToPunycode($url); } } } unset($check); $registry = new Registry(); $registry->loadArray($data['urls']); $data['urls'] = (string) $registry; } // Alter the title for save as copy if ($input->get('task') == 'save2copy') { $origTable = clone $this->getTable(); $origTable->load($input->getInt('id')); if ($data['title'] == $origTable->title) { list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); $data['title'] = $title; $data['alias'] = $alias; } else { if ($data['alias'] == $origTable->alias) { $data['alias'] = ''; } } $data['state'] = 0; } // Automatic handling of alias for empty fields if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (!isset($data['id']) || (int) $data['id'] == 0)) { if ($data['alias'] == null) { if (JFactory::getConfig()->get('unicodeslugs') == 1) { $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['title']); } else { $data['alias'] = JFilterOutput::stringURLSafe($data['title']); } $table = JTable::getInstance('Content', 'JTable'); if ($table->load(array('alias' => $data['alias'], 'catid' => $data['catid']))) { $msg = JText::_('COM_CONTENT_SAVE_WARNING'); } list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); $data['alias'] = $alias; if (isset($msg)) { JFactory::getApplication()->enqueueMessage($msg, 'warning'); } } } if (parent::save($data)) { if (isset($data['featured'])) { $this->featured($this->getState($this->getName() . '.id'), $data['featured']); } return true; } return false; }
/** * Method to save the form data. * * @param array The form data. * * @return boolean True on success. * @since 1.6 */ public function save($data) { $app = JFactory::getApplication(); if (isset($data['images']) && is_array($data['images'])) { $registry = new JRegistry(); $registry->loadArray($data['images']); $data['images'] = (string) $registry; } if (isset($data['urls']) && is_array($data['urls'])) { foreach ($data['urls'] as $i => $url) { if ($url != false && ($i == 'urla' || $i == 'urlb' || $i == 'urlc')) { $data['urls'][$i] = JStringPunycode::urlToPunycode($url); } } $registry = new JRegistry(); $registry->loadArray($data['urls']); $data['urls'] = (string) $registry; } // Alter the title for save as copy if ($app->input->get('task') == 'save2copy') { list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); $data['title'] = $title; $data['alias'] = $alias; $data['state'] = 0; } if (parent::save($data)) { if (isset($data['featured'])) { $this->featured($this->getState($this->getName() . '.id'), $data['featured']); } $assoc = JLanguageAssociations::isEnabled(); if ($assoc) { $id = (int) $this->getState($this->getName() . '.id'); $item = $this->getItem($id); // Adding self to the association $associations = $data['associations']; foreach ($associations as $tag => $id) { if (empty($id)) { unset($associations[$tag]); } } // Detecting all item menus $all_language = $item->language == '*'; if ($all_language && !empty($associations)) { JError::raiseNotice(403, JText::_('COM_CONTENT_ERROR_ALL_LANGUAGE_ASSOCIATED')); } $associations[$item->language] = $item->id; // Deleting old association for these items $db = JFactory::getDbo(); $query = $db->getQuery(true)->delete('#__associations')->where('context=' . $db->quote('com_content.item'))->where('id IN (' . implode(',', $associations) . ')'); $db->setQuery($query); $db->execute(); if ($error = $db->getErrorMsg()) { $this->setError($error); return false; } if (!$all_language && count($associations)) { // Adding new association for these items $key = md5(json_encode($associations)); $query->clear()->insert('#__associations'); foreach ($associations as $id) { $query->values($id . ',' . $db->quote('com_content.item') . ',' . $db->quote($key)); } $db->setQuery($query); $db->execute(); if ($error = $db->getErrorMsg()) { $this->setError($error); return false; } } } return true; } return false; }
/** * Method to apply an input filter to a value based on field data. * * @param string $element The XML element object representation of the form field. * @param mixed $value The value to filter for the field. * * @return mixed The filtered value. * * @since 11.1 */ protected function filterField($element, $value) { // Make sure there is a valid SimpleXMLElement. if (!$element instanceof SimpleXMLElement) { return false; } // Get the field filter type. $filter = (string) $element['filter']; // Process the input value based on the filter. $return = null; switch (strtoupper($filter)) { // Access Control Rules. case 'RULES': $return = array(); foreach ((array) $value as $action => $ids) { // Build the rules array. $return[$action] = array(); foreach ($ids as $id => $p) { if ($p !== '') { $return[$action][$id] = $p == '1' || $p == 'true' ? true : false; } } } break; // Do nothing, thus leaving the return value as null. // Do nothing, thus leaving the return value as null. case 'UNSET': break; // No Filter. // No Filter. case 'RAW': $return = $value; break; // Filter the input as an array of integers. // Filter the input as an array of integers. case 'INT_ARRAY': // Make sure the input is an array. if (is_object($value)) { $value = get_object_vars($value); } $value = is_array($value) ? $value : array($value); JArrayHelper::toInteger($value); $return = $value; break; // Filter safe HTML. // Filter safe HTML. case 'SAFEHTML': $return = JFilterInput::getInstance(null, null, 1, 1)->clean($value, 'string'); break; // Convert a date to UTC based on the server timezone offset. // Convert a date to UTC based on the server timezone offset. case 'SERVER_UTC': if ((int) $value > 0) { // Get the server timezone setting. $offset = JFactory::getConfig()->get('offset'); // Return an SQL formatted datetime string in UTC. $return = JFactory::getDate($value, $offset)->toSql(); } else { $return = ''; } break; // Convert a date to UTC based on the user timezone offset. // Convert a date to UTC based on the user timezone offset. case 'USER_UTC': if ((int) $value > 0) { // Get the user timezone setting defaulting to the server timezone setting. $offset = JFactory::getUser()->getParam('timezone', JFactory::getConfig()->get('offset')); // Return a MySQL formatted datetime string in UTC. $return = JFactory::getDate($value, $offset)->toSql(); } else { $return = ''; } break; // Ensures a protocol is present in the saved field. Only use when // the only permitted protocols requre '://'. See JFormRuleUrl for list of these. // Ensures a protocol is present in the saved field. Only use when // the only permitted protocols requre '://'. See JFormRuleUrl for list of these. case 'URL': if (empty($value)) { return false; } // This cleans some of the more dangerous characters but leaves special characters that are valid. $value = JFilterInput::getInstance()->clean($value, 'html'); $value = trim($value); // <>" are never valid in a uri see http://www.ietf.org/rfc/rfc1738.txt. $value = str_replace(array('<', '>', '"'), '', $value); // Check for a protocol $protocol = parse_url($value, PHP_URL_SCHEME); // If there is no protocol and the relative option is not specified, // we assume that it is an external URL and prepend http://. if ($element['type'] == 'url' && !$protocol && !$element['relative'] || !$element['type'] == 'url' && !$protocol) { $protocol = 'http'; // If it looks like an internal link, then add the root. if (substr($value, 0) == 'index.php') { $value = JUri::root() . $value; } // Otherwise we treat it is an external link. // Put the url back together. $value = $protocol . '://' . $value; } elseif (!$protocol && $element['relative']) { $host = JUri::getInstance('SERVER')->gethost(); // If it starts with the host string, just prepend the protocol. if (substr($value, 0) == $host) { $value = 'http://' . $value; } else { $value = JUri::root() . $value; } } $value = JStringPunycode::urlToPunycode($value); $return = $value; break; case 'TEL': $value = trim($value); // Does it match the NANP pattern? if (preg_match('/^(?:\\+?1[-. ]?)?\\(?([2-9][0-8][0-9])\\)?[-. ]?([2-9][0-9]{2})[-. ]?([0-9]{4})$/', $value) == 1) { $number = (string) preg_replace('/[^\\d]/', '', $value); if (substr($number, 0, 1) == 1) { $number = substr($number, 1); } if (substr($number, 0, 2) == '+1') { $number = substr($number, 2); } $result = '1.' . $number; } elseif (preg_match('/^\\+(?:[0-9] ?){6,14}[0-9]$/', $value) == 1) { $countrycode = substr($value, 0, strpos($value, ' ')); $countrycode = (string) preg_replace('/[^\\d]/', '', $countrycode); $number = strstr($value, ' '); $number = (string) preg_replace('/[^\\d]/', '', $number); $result = $countrycode . '.' . $number; } elseif (preg_match('/^\\+[0-9]{1,3}\\.[0-9]{4,14}(?:x.+)?$/', $value) == 1) { if (strstr($value, 'x')) { $xpos = strpos($value, 'x'); $value = substr($value, 0, $xpos); } $result = str_replace('+', '', $value); } elseif (preg_match('/[0-9]{1,3}\\.[0-9]{4,14}$/', $value) == 1) { $result = $value; } else { $value = (string) preg_replace('/[^\\d]/', '', $value); if ($value != null && strlen($value) <= 15) { $length = strlen($value); // If it is fewer than 13 digits assume it is a local number if ($length <= 12) { $result = '.' . $value; } else { // If it has 13 or more digits let's make a country code. $cclen = $length - 12; $result = substr($value, 0, $cclen) . '.' . substr($value, $cclen); } } else { $result = ''; } } $return = $result; break; default: // Check for a callback filter. if (strpos($filter, '::') !== false && is_callable(explode('::', $filter))) { $return = call_user_func(explode('::', $filter), $value); } elseif (function_exists($filter)) { $return = call_user_func($filter, $value); } else { $return = JFilterInput::getInstance()->clean($value, $filter); } break; } return $return; }
/** * Overriden JTable::store to set modified data. * * @param boolean $updateNulls True to update fields even if they are null. * * @return boolean True on success. * * @since 1.6 */ public function store($updateNulls = false) { $date = JFactory::getDate(); $user = JFactory::getUser(); $this->modified = $date->toSql(); if ($this->id) { // Existing item $this->modified_by = $user->get('id'); } else { // New newsfeed. A feed created and created_by field can be set by the user, // so we don't touch either of these if they are set. if (!(int) $this->created) { $this->created = $date->toSql(); } if (empty($this->created_by)) { $this->created_by = $user->get('id'); } } // Verify that the alias is unique $table = JTable::getInstance('Newsfeed', 'NewsfeedsTable'); if ($table->load(array('alias' => $this->alias, 'catid' => $this->catid)) && ($table->id != $this->id || $this->id == 0)) { $this->setError(JText::_('COM_NEWSFEEDS_ERROR_UNIQUE_ALIAS')); return false; } // Save links as punycode. $this->link = JStringPunycode::urlToPunycode($this->link); return parent::store($updateNulls); }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 3.0 */ public function save($data) { $input = JFactory::getApplication()->input; // Alter the name for save as copy if ($input->get('task') == 'save2copy') { $origTable = clone $this->getTable(); $origTable->load($input->getInt('id')); if ($data['name'] == $origTable->name) { list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']); $data['name'] = $name; $data['alias'] = $alias; } else { if ($data['alias'] == $origTable->alias) { $data['alias'] = ''; } } $data['published'] = 0; } $links = array('linka', 'linkb', 'linkc', 'linkd', 'linke'); foreach ($links as $link) { if ($data['params'][$link]) { $data['params'][$link] = JStringPunycode::urlToPunycode($data['params'][$link]); } } return parent::save($data); }
/** * Method to save the form data. * * @param array The form data. * * @return boolean True on success. * @since 3.0 */ public function save($data) { $app = JFactory::getApplication(); // Alter the title for save as copy if ($app->input->get('task') == 'save2copy') { list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']); $data['name'] = $name; $data['alias'] = $alias; $data['published'] = 0; } $links = array('linka', 'linkb', 'linkc', 'linkd', 'linke'); foreach ($links as $link) { if ($data['params'][$link]) { $data['params'][$link] = JStringPunycode::urlToPunycode($data['params'][$link]); } } if (parent::save($data)) { $assoc = JLanguageAssociations::isEnabled(); if ($assoc) { $id = (int) $this->getState($this->getName() . '.id'); $item = $this->getItem($id); // Adding self to the association $associations = $data['associations']; foreach ($associations as $tag => $id) { if (empty($id)) { unset($associations[$tag]); } } // Detecting all item menus $all_language = $item->language == '*'; if ($all_language && !empty($associations)) { JError::raiseNotice(403, JText::_('COM_CONTACT_ERROR_ALL_LANGUAGE_ASSOCIATED')); } $associations[$item->language] = $item->id; // Deleting old association for these items $db = JFactory::getDbo(); $query = $db->getQuery(true)->delete('#__associations')->where('context=' . $db->quote('com_contact.item'))->where('id IN (' . implode(',', $associations) . ')'); $db->setQuery($query); $db->execute(); if ($error = $db->getErrorMsg()) { $this->setError($error); return false; } if (!$all_language && count($associations)) { // Adding new association for these items $key = md5(json_encode($associations)); $query->clear()->insert('#__associations'); foreach ($associations as $id) { $query->values($id . ',' . $db->quote('com_contact.item') . ',' . $db->quote($key)); } $db->setQuery($query); $db->execute(); if ($error = $db->getErrorMsg()) { $this->setError($error); return false; } } } return true; } return false; }
/** * Overload the store method for the Custom_admin_view table. * * @param boolean Toggle whether null values should be updated. * @return boolean True on success, false on failure. * @since 1.6 */ public function store($updateNulls = false) { $date = JFactory::getDate(); $user = JFactory::getUser(); if ($this->id) { // Existing item $this->modified = $date->toSql(); $this->modified_by = $user->get('id'); } else { // New custom_admin_view. A custom_admin_view created and created_by field can be set by the user, // so we don't touch either of these if they are set. if (!(int) $this->created) { $this->created = $date->toSql(); } if (empty($this->created_by)) { $this->created_by = $user->get('id'); } } if (isset($this->alias)) { // Verify that the alias is unique $table = JTable::getInstance('custom_admin_view', 'ComponentbuilderTable'); if ($table->load(array('alias' => $this->alias)) && ($table->id != $this->id || $this->id == 0)) { $this->setError(JText::_('COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_ERROR_UNIQUE_ALIAS')); return false; } } if (isset($this->url)) { // Convert IDN urls to punycode $this->url = JStringPunycode::urlToPunycode($this->url); } if (isset($this->website)) { // Convert IDN urls to punycode $this->website = JStringPunycode::urlToPunycode($this->website); } return parent::store($updateNulls); }
/** * Helper wrapper method for urlToPunycode * * @param string $uri The UTF-8 URL to transform. * * @return string The punycode URL. * * @see JUserHelper::urlToPunycode() * @since 3.4 */ public function urlToPunycode($uri) { return JStringPunycode::urlToPunycode($uri); }
static function dataFilter($v, $maxlength = 0, $validation = 'string', $check_callable = 0) { if ($validation == '-1') { return flexicontent_html::striptagsandcut($v, $maxlength); } $v = $maxlength ? substr($v, 0, $maxlength) : $v; if ($check_callable) { if (strpos($validation, '::') !== false && is_callable(explode('::', $validation))) { return call_user_func(explode('::', $validation), $v); } elseif (function_exists($validation)) { return call_user_func($validation, $v); } // A callback function } // Do filtering if ($validation == '1') { $safeHtmlFilter = JFilterInput::getInstance(null, null, 1, 1); } else { if ($validation != '2') { $noHtmlFilter = JFilterInput::getInstance(); } } switch ($validation) { case '1': // Allow safe HTML $v = $safeHtmlFilter->clean($v, 'string'); break; case '2': // Filter according to user group Text Filters $v = JComponentHelper::filterText($v); break; case 'URL': case 'url': // This cleans some of the more dangerous characters but leaves special characters that are valid. $v = trim($noHtmlFilter->clean($v, 'HTML')); // <>" are never valid in a uri see http://www.ietf.org/rfc/rfc1738.txt. $v = str_replace(array('<', '>', '"'), '', $v); // Convert to Punycode string $v = FLEXI_J30GE ? JStringPunycode::urlToPunycode($v) : $v; break; case 'EMAIL': case 'email': // This cleans some of the more dangerous characters but leaves special characters that are valid. $v = trim($noHtmlFilter->clean($v, 'HTML')); // <>" are never valid in a email ? $v = str_replace(array('<', '>', '"'), '', $v); // Convert to Punycode string $v = FLEXI_J30GE ? JStringPunycode::emailToPunycode($v) : $v; // Check for valid email (punycode is ASCII so this should work with UTF-8 too) $email_regexp = "/^[a-zA-Z0-9.!#\$%&'*+\\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*\$/"; if (!preg_match($email_regexp, $v)) { $v = ''; } break; default: // Filter using JFilterInput $v = $noHtmlFilter->clean($v, $validation); break; } $v = trim($v); return $v; }
/** * Method is called before user data is stored in the database * * @param array $user Holds the old user data. * @param boolean $isnew True if a new user is stored. * @param array $data Holds the new user data. * * @return boolean * * @since 3.1 * @throws InvalidArgumentException on invalid date. */ public function onUserBeforeSave($user, $isnew, $data) { // Check that the date is valid. if (!empty($data['profile']['dob'])) { try { // Convert website url to punycode $data['profile']['website'] = JStringPunycode::urlToPunycode($data['profile']['website']); $date = new JDate($data['profile']['dob']); $this->date = $date->format('Y-m-d H:i:s'); } catch (Exception $e) { // Throw an exception if date is not valid. throw new InvalidArgumentException(JText::_('PLG_USER_PROFILE_ERROR_INVALID_DOB')); } } return true; }
/** * Overload the store method for the Help_document table. * * @param boolean Toggle whether null values should be updated. * @return boolean True on success, false on failure. * @since 1.6 */ public function store($updateNulls = false) { $date = JFactory::getDate(); $user = JFactory::getUser(); if ($this->id) { // Existing item $this->modified = $date->toSql(); $this->modified_by = $user->get('id'); } else { // New help_document. A help_document created and created_by field can be set by the user, // so we don't touch either of these if they are set. if (!(int) $this->created) { $this->created = $date->toSql(); } if (empty($this->created_by)) { $this->created_by = $user->get('id'); } } if (isset($this->alias)) { // Verify that the alias is unique $table = JTable::getInstance('help_document', 'DemoTable'); if ($table->load(array('alias' => $this->alias)) && ($table->id != $this->id || $this->id == 0)) { $this->setError(JText::_('COM_DEMO_HELP_DOCUMENT_ERROR_UNIQUE_ALIAS')); return false; } } if (isset($this->url)) { // Convert IDN urls to punycode $this->url = JStringPunycode::urlToPunycode($this->url); } if (isset($this->website)) { // Convert IDN urls to punycode $this->website = JStringPunycode::urlToPunycode($this->website); } return parent::store($updateNulls); }
/** * Tests JStringPunycode::urlToPunycode * * @return void * * @since 3.2 */ public function testUrlToPunycode() { $this->assertEquals(JStringPunycode::urlToPunycode('http://www.джумла-тест.рф'), 'http://www.xn----7sblgc4ag8bhcd.xn--p1ai', 'Tests punycode encoding a UTF8 url in Cyrillic'); $this->assertEquals(JStringPunycode::urlToPunycode('http://au-gré-de-nos-plumes.fr'), 'http://xn--au-gr-de-nos-plumes-fzb.fr', 'Tests punycode encoding a UTF8 url in French'); $this->assertEquals(JStringPunycode::urlToPunycode('http://www.джумла-тест.рф#test'), 'http://www.xn----7sblgc4ag8bhcd.xn--p1ai#test', 'Tests punycode encoding a UTF8 url in Cyrillic with an anchor (See GitHub #4362)'); }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 1.6 */ public function save($data) { $input = JFactory::getApplication()->input; $filter = JFilterInput::getInstance(); if (isset($data['metadata']) && isset($data['metadata']['author'])) { $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM'); } if (isset($data['created_by_alias'])) { $data['created_by_alias'] = $filter->clean($data['created_by_alias'], 'TRIM'); } if (isset($data['images']) && is_array($data['images'])) { $registry = new Registry(); $registry->loadArray($data['images']); $data['images'] = (string) $registry; } if (isset($data['urls']) && is_array($data['urls'])) { $check = $input->post->get('jform', array(), 'array'); foreach ($data['urls'] as $i => $url) { if ($url != false && ($i == 'urla' || $i == 'urlb' || $i == 'urlc')) { if (preg_match('~^#[a-zA-Z]{1}[a-zA-Z0-9-_:.]*$~', $check['urls'][$i]) == 1) { $data['urls'][$i] = $check['urls'][$i]; } else { $data['urls'][$i] = JStringPunycode::urlToPunycode($url); } } } unset($check); $registry = new Registry(); $registry->loadArray($data['urls']); $data['urls'] = (string) $registry; } // Alter the title for save as copy if ($input->get('task') == 'save2copy') { $origTable = clone $this->getTable(); $origTable->load($input->getInt('id')); if ($data['title'] == $origTable->title) { list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); $data['title'] = $title; $data['alias'] = $alias; } else { if ($data['alias'] == $origTable->alias) { $data['alias'] = ''; } } $data['state'] = 0; } // Automatic handling of alias for empty fields if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (!isset($data['id']) || (int) $data['id'] == 0)) { if ($data['alias'] == null) { if (JFactory::getConfig()->get('unicodeslugs') == 1) { $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['title']); } else { $data['alias'] = JFilterOutput::stringURLSafe($data['title']); } $table = JTable::getInstance('Content', 'JTable'); if ($table->load(array('alias' => $data['alias'], 'catid' => $data['catid']))) { $msg = JText::_('COM_CONTENT_SAVE_WARNING'); } list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); $data['alias'] = $alias; if (isset($msg)) { JFactory::getApplication()->enqueueMessage($msg, 'warning'); } } } if (parent::save($data)) { if (isset($data['featured'])) { $this->featured($this->getState($this->getName() . '.id'), $data['featured']); } return true; } return false; }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 3.0 */ public function save($data) { $input = JFactory::getApplication()->input; JLoader::register('CategoriesHelper', JPATH_ADMINISTRATOR . '/components/com_categories/helpers/categories.php'); // Cast catid to integer for comparison $catid = (int) $data['catid']; // Check if New Category exists if ($catid > 0) { $catid = CategoriesHelper::validateCategoryId($data['catid'], 'com_contact'); } // Save New Category if ($catid == 0 && $this->canCreateCategory()) { $table = array(); $table['title'] = $data['catid']; $table['parent_id'] = 1; $table['extension'] = 'com_contact'; $table['language'] = $data['language']; $table['published'] = 1; // Create new category and get catid back $data['catid'] = CategoriesHelper::createCategory($table); } // Alter the name for save as copy if ($input->get('task') == 'save2copy') { $origTable = clone $this->getTable(); $origTable->load($input->getInt('id')); if ($data['name'] == $origTable->name) { list($name, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['name']); $data['name'] = $name; $data['alias'] = $alias; } else { if ($data['alias'] == $origTable->alias) { $data['alias'] = ''; } } $data['published'] = 0; } $links = array('linka', 'linkb', 'linkc', 'linkd', 'linke'); foreach ($links as $link) { if ($data['params'][$link]) { $data['params'][$link] = JStringPunycode::urlToPunycode($data['params'][$link]); } } return parent::save($data); }
/** * Overload the store method for the Intervention table. * * @param boolean Toggle whether null values should be updated. * @return boolean True on success, false on failure. * @since 1.6 */ public function store($updateNulls = false) { $date = JFactory::getDate(); $user = JFactory::getUser(); if ($this->id) { // Existing item $this->modified = $date->toSql(); $this->modified_by = $user->get('id'); } else { // New intervention. A intervention created and created_by field can be set by the user, // so we don't touch either of these if they are set. if (!(int) $this->created) { $this->created = $date->toSql(); } if (empty($this->created_by)) { $this->created_by = $user->get('id'); } } if (isset($this->alias)) { // Verify that the alias is unique $table = JTable::getInstance('intervention', 'CostbenefitprojectionTable'); if ($table->load(array('alias' => $this->alias)) && ($table->id != $this->id || $this->id == 0)) { $this->setError(JText::_('COM_COSTBENEFITPROJECTION_INTERVENTION_ERROR_UNIQUE_ALIAS')); return false; } } if (isset($this->url)) { // Convert IDN urls to punycode $this->url = JStringPunycode::urlToPunycode($this->url); } if (isset($this->website)) { // Convert IDN urls to punycode $this->website = JStringPunycode::urlToPunycode($this->website); } return parent::store($updateNulls); }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success. * * @since 1.6 */ public function save($data) { $input = JFactory::getApplication()->input; $filter = JFilterInput::getInstance(); if (isset($data['metadata']) && isset($data['metadata']['author'])) { $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM'); } if (isset($data['created_by_alias'])) { $data['created_by_alias'] = $filter->clean($data['created_by_alias'], 'TRIM'); } if (isset($data['images']) && is_array($data['images'])) { $registry = new Registry(); $registry->loadArray($data['images']); $data['images'] = (string) $registry; } if (isset($data['urls']) && is_array($data['urls'])) { foreach ($data['urls'] as $i => $url) { if ($url != false && ($i == 'urla' || $i == 'urlb' || $i == 'urlc')) { $data['urls'][$i] = JStringPunycode::urlToPunycode($url); } } $registry = new Registry(); $registry->loadArray($data['urls']); $data['urls'] = (string) $registry; } // Alter the title for save as copy if ($input->get('task') == 'save2copy') { $origTable = clone $this->getTable(); $origTable->load($input->getInt('id')); if ($data['title'] == $origTable->title) { list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); $data['title'] = $title; $data['alias'] = $alias; } else { if ($data['alias'] == $origTable->alias) { $data['alias'] = ''; } } $data['state'] = 0; } // Automatic handling of alias for empty fields if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (!isset($data['id']) || (int) $data['id'] == 0)) { if ($data['alias'] == null) { if (JFactory::getConfig()->get('unicodeslugs') == 1) { $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['title']); } else { $data['alias'] = JFilterOutput::stringURLSafe($data['title']); } $table = JTable::getInstance('Content', 'JTable'); if ($table->load(array('alias' => $data['alias'], 'catid' => $data['catid']))) { $msg = JText::_('COM_CONTENT_SAVE_WARNING'); } list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']); $data['alias'] = $alias; if (isset($msg)) { JFactory::getApplication()->enqueueMessage($msg, 'warning'); } } } if (parent::save($data)) { if (isset($data['featured'])) { $this->featured($this->getState($this->getName() . '.id'), $data['featured']); } $assoc = JLanguageAssociations::isEnabled(); if ($assoc) { $id = (int) $this->getState($this->getName() . '.id'); $item = $this->getItem($id); // Adding self to the association $associations = $data['associations']; foreach ($associations as $tag => $id) { if (empty($id)) { unset($associations[$tag]); } } // Detecting all item menus $all_language = $item->language == '*'; if ($all_language && !empty($associations)) { JError::raiseNotice(403, JText::_('COM_CONTENT_ERROR_ALL_LANGUAGE_ASSOCIATED')); } $associations[$item->language] = $item->id; // Deleting old association for these items $db = JFactory::getDbo(); $query = $db->getQuery(true)->delete('#__associations')->where('context=' . $db->quote('com_content.item'))->where('id IN (' . implode(',', $associations) . ')'); $db->setQuery($query); $db->execute(); if ($error = $db->getErrorMsg()) { $this->setError($error); return false; } if (!$all_language && count($associations)) { // Adding new association for these items $key = md5(json_encode($associations)); $query->clear()->insert('#__associations'); foreach ($associations as $id) { $query->values($id . ',' . $db->quote('com_content.item') . ',' . $db->quote($key)); } $db->setQuery($query); $db->execute(); if ($error = $db->getErrorMsg()) { $this->setError($error); return false; } } } return true; } return false; }
/** * Method to save the form data. * * @param array $data The form data. * * @return boolean True on success, False on error. * */ public function save($data) { // Include the knvbapi plugins for the onSave events. JPluginHelper::importPlugin('knvbapi2'); $input = JFactory::getApplication()->input; $filter = JFilterInput::getInstance(); if (isset($data['created_by_alias'])) { $data['created_by_alias'] = $filter->clean($data['created_by_alias'], 'TRIM'); } if (isset($data['images']) and is_array($data['images'])) { $registry = new Registry(); $registry->loadArray($data['images']); $data['images'] = (string) $registry; $registry = null; //release memory } if (isset($data['urls']) and is_array($data['urls'])) { foreach ($data['urls'] as $i => $url) { if ($url != false and ($i == 'urla' or $i == 'urlb' or $i == 'urlc')) { $data['urls'][$i] = JStringPunycode::urlToPunycode($url); } } $registry = new Registry(); $registry->loadArray($data['urls']); $data['urls'] = (string) $registry; $registry = null; //release memory } // Alter the name and alias for save as copy if ($input->get('task') == 'save2copy') { $data['name'] = $this->generateUniqueName($data); $data['alias'] = $this->generateUniqueAlias($data); $data['state'] = 0; } if (parent::save($data)) { if (isset($data['featured'])) { $this->featured($this->getState($this->getName() . '.id'), $data['featured']); } $assoc = JLanguageAssociations::isEnabled(); if ($assoc) { $id = (int) $this->getState($this->getName() . '.id'); $item = $this->getItem($id); // Adding self to the association $associations = $data['associations']; foreach ($associations as $tag => $id) { if (empty($id)) { unset($associations[$tag]); } } // Detecting all item menus $all_language = $item->language == '*'; if ($all_language and !empty($associations)) { JError::raiseNotice(403, JText::_('COM_KNVBAPI2_ERROR_ALL_LANGUAGE_ASSOCIATED')); } $associations[$item->language] = $item->id; try { // Deleting old association for these items $db = JFactory::getDbo(); $query = $db->getQuery(true); $query->delete($db->quoteName('#__associations')); $query->where('context=' . $db->quote('com_knvbapi2.teamnaam.item')); $query->where($db->quoteName('id') . ' IN (' . implode(',', $associations) . ')'); $db->setQuery($query); $db->execute(); } catch (RuntimeException $e) { $this->setError($e->getMessage()); return false; } if (!$all_language and count($associations)) { // Adding new association for these items $key = md5(json_encode($associations)); $query->clear(); $query->insert($db->quoteName('#__associations')); foreach ($associations as $id) { $query->values($id . ',' . $db->quote('com_knvbapi2.teamnaam.item') . ',' . $db->quote($key)); } try { $db->setQuery($query); $db->execute(); } catch (RuntimeException $e) { $this->setError($e->getMessage()); return false; } } } return true; } return false; }
/** * _loadImages * * @param array &$data Param * * @return void */ private function _loadUrls(&$data) { if (isset($data['urls']) && is_array($data['urls'])) { foreach ($data['urls'] as $i => $url) { if ($url != false && ($i == 'urla' || $i == 'urlb' || ($i = 'urlc'))) { if (class_exists('JStringPunycode')) { $data['urls'][$i] = JStringPunycode::urlToPunycode($url); } else { $data['urls'][$i] = $url; } } } $registry = new JRegistry(); $registry->loadArray($data['urls']); $data['urls'] = (string) $registry; } }