示例#1
0
 public function check()
 {
     if (JString::trim($this->name) == '') {
         $this->setError(JText::_('K2_TAG_MUST_HAVE_A_NAME'));
         return false;
     }
     $this->normalize();
     $this->alias = $this->name;
     if (JFactory::getConfig()->get('unicodeslugs') == 1) {
         $this->alias = JFilterOutput::stringURLUnicodeSlug($this->alias);
     } else {
         $this->alias = JFilterOutput::stringURLSafe($this->alias);
     }
     $db = $this->getDbo();
     $query = $db->getQuery(true);
     $query->select($db->quoteName('id'))->from($db->quoteName('#__k2_tags'))->where($db->quoteName('alias') . ' = ' . $db->quote($this->alias));
     if ($this->id) {
         $query->where($db->quoteName('id') . ' != ' . (int) $this->id);
     }
     $db->setQuery($query);
     if ($db->loadResult()) {
         $this->alias .= '-' . uniqid();
     }
     return true;
 }
	/**
	 * Tests converting strings to URL unicoded slugs.
	 *
	 * @return  void
	 *
	 * @since   11.3
	 */
	public function testStringURLUnicodeSlug()
	{
		$this->assertEquals(
			'what-if-i-do-not-get_this-right',
			$this->object->stringURLUnicodeSlug('What-if I do.not get_this right?'),
			'Should be URL unicoded'
		);
	}
示例#3
0
 /**
  * This method transliterates a string into an URL
  * safe string or returns a URL safe UTF-8 string
  * based on the global configuration
  *
  * @param   string  $string  String to process
  *
  * @return  string  Processed string
  *
  * @since   3.2
  */
 public static function stringURLSafe($string)
 {
     if (JFactory::getConfig()->get('unicodeslugs') == 1) {
         $output = JFilterOutput::stringURLUnicodeSlug($string);
     } else {
         $output = JFilterOutput::stringURLSafe($string);
     }
     return $output;
 }
 /**
  * This method transliterates a string into a URL
  * safe string or returns a URL safe UTF-8 string
  * based on the global configuration
  *
  * @param   string  $string    String to process
  * @param   string  $language  Language to transliterate to if unicode slugs are disabled
  *
  * @return  string  Processed string
  *
  * @since   3.2
  */
 public static function stringURLSafe($string, $language = '')
 {
     if (JFactory::getConfig()->get('unicodeslugs') == 1) {
         $output = JFilterOutput::stringURLUnicodeSlug($string);
     } else {
         if ($language == '*' || $language == '') {
             $languageParams = JComponentHelper::getParams('com_languages');
             $language = $languageParams->get('site');
         }
         $output = JFilterOutput::stringURLSafe($string, $language);
     }
     return $output;
 }
示例#5
0
 /**
  * Overloaded check function
  * @since	3.4.0
  */
 public function check()
 {
     // Import Joomla 2.5
     jimport('joomla.filter.output');
     // If there is an ordering column and this is a new row then get the next ordering value
     if (property_exists($this, 'ordering') && $this->id == 0) {
         $this->ordering = self::getNextOrder();
     }
     // URL alias
     if (empty($this->alias)) {
         $this->alias = $this->title;
     }
     $this->alias = JFilterOutput::stringURLSafe($this->alias);
     // Alias is not generated if non-latin characters, so we fix it by using created date, or title if unicode is activated, as alias
     if ($this->alias == null || empty($this->alias)) {
         if (JFactory::getConfig()->get('unicodeslugs') == 1) {
             $this->alias = JFilterOutput::stringURLUnicodeSlug($this->title);
         } else {
             $this->alias = JFilterOutput::stringURLSafe($this->created);
         }
     }
     // Slug auto-create
     $slug_empty = empty($this->slug) ? true : false;
     if ($slug_empty) {
         $this->slug = $this->title;
     }
     $this->slug = iCFilterOutput::stringToSlug($this->slug);
     // Slug is not generated if non-latin characters, so we fix it by using created date as a slug
     if ($this->slug == null) {
         $this->slug = iCFilterOutput::stringToSlug($this->created);
     }
     // Check if Slug already exists
     $db = JFactory::getDbo();
     $query = $db->getQuery(true)->select('slug')->from($db->qn('#__icagenda_customfields'))->where($db->qn('slug') . ' = ' . $db->q($this->slug));
     if (!empty($this->id)) {
         $query->where('id <> ' . (int) $this->id);
     }
     $db->setQuery($query);
     $slug_exists = $db->loadResult();
     if ($slug_exists) {
         $error_slug = $slug_empty ? JText::sprintf('COM_ICAGENDA_CUSTOMFIELD_DATABASE_ERROR_AUTO_SLUG', '<strong>' . $this->title . '</strong>', '<strong>' . $this->slug . '</strong>') : '<strong>' . JText::_('COM_ICAGENDA_CUSTOMFIELD_DATABASE_ERROR_UNIQUE_SLUG') . '</strong>';
         $this->setError($error_slug . '<br /><br /><span class="iCicon-info-circle"></span> <i>' . JTEXT::_('COM_ICAGENDA_CUSTOMFIELD_SLUG_DESC') . '</i>');
         return false;
     }
     return parent::check();
 }
示例#6
0
 public static function permalinkUnicodeSlug($string)
 {
     $str = '';
     if (EasyBlogHelper::getJoomlaVersion() >= '1.6') {
         $str = JFilterOutput::stringURLUnicodeSlug($string);
     } else {
         //replace double byte whitespaces by single byte (Far-East languages)
         $str = preg_replace('/\\xE3\\x80\\x80/', ' ', $string);
         // remove any '-' from the string as they will be used as concatenator.
         // Would be great to let the spaces in but only Firefox is friendly with this
         $str = str_replace('-', ' ', $str);
         // replace forbidden characters by whitespaces
         $str = preg_replace('#[:\\#\\*"@+=;!&\\.%()\\]\\/\'\\\\|\\[]#', " ", $str);
         //delete all '?'
         $str = str_replace('?', '', $str);
         //trim white spaces at beginning and end of alias, make lowercase
         $str = trim(JString::strtolower($str));
         // remove any duplicate whitespace and replace whitespaces by hyphens
         $str = preg_replace('#\\x20+#', '-', $str);
     }
     return $str;
 }
示例#7
0
文件: category.php 项目: rodhoff/MNW
 function addAlias(&$element)
 {
     if (empty($element)) {
         return;
     }
     if (empty($element->category_alias)) {
         $element->alias = $element->category_name;
     } else {
         $element->alias = $element->category_alias;
     }
     $jconfig = JFactory::getConfig();
     if (!$jconfig->get('unicodeslugs')) {
         $lang = JFactory::getLanguage();
         $element->alias = $lang->transliterate($element->alias);
     }
     $app = JFactory::getApplication();
     if (method_exists($app, 'stringURLSafe')) {
         $element->alias = $app->stringURLSafe(strip_tags($element->alias));
     } elseif (method_exists('JFilterOutput', 'stringURLUnicodeSlug')) {
         $element->alias = JFilterOutput::stringURLUnicodeSlug(strip_tags($element->alias));
     } else {
         $element->alias = JFilterOutput::stringURLSafe(strip_tags($element->alias));
     }
 }
示例#8
0
 /**
  * Overload the store method for the license table.
  *
  * @param	boolean	Toggle whether null values should be updated.
  * @return	boolean	True on success, false on failure.
  */
 public function store($updateNulls = false)
 {
     $date = JFactory::getDate();
     /* @var $date JDate current date */
     $currentDate = $date->toSql();
     /* @var $currentDate string current date as MySQL datetime in GMT0 */
     $user = JFactory::getUser();
     /* @var $user JUser current logged user */
     $app = JFactory::getApplication();
     /* @var $app JApplication */
     if ($this->id) {
         $this->modified = $currentDate;
         $this->modified_by = $user->get('id');
     } else {
         $this->created = $currentDate;
         $this->created_by = $user->get('id');
     }
     // if user doesn't set alias use title
     if (!JString::trim($this->alias)) {
         $this->alias = $this->title;
     }
     // convert alias to safe string
     if ($app->getCfg('unicodeslugs') == 1) {
         $this->alias = JFilterOutput::stringURLUnicodeSlug($this->alias);
     } else {
         $this->alias = JFilterOutput::stringURLSafe($this->alias);
     }
     if (parent::store($updateNulls)) {
         if ($this->default) {
             $this->_db->setQuery('UPDATE `#__joomdoc_license` SET `default` = ' . JOOMDOC_STATE_UNDEFAULT . ' WHERE `id` <> ' . $this->id);
             $this->_db->query();
         }
         return true;
     }
     return false;
 }
示例#9
0
 /**
  * Retrieves the alias of the profile type
  *
  * @since	1.3
  * @access	public
  * @param	string
  * @return
  */
 public function getAlias()
 {
     $alias = $this->alias ? JFilterOutput::stringURLUnicodeSlug($this->alias) : JFilterOutput::stringURLUnicodeSlug($this->title);
     $alias = $this->id . ':' . $alias;
     return $alias;
 }
示例#10
0
文件: k2item.php 项目: A-Bush/pprod
 function check()
 {
     jimport('joomla.filter.output');
     $params = JComponentHelper::getParams('com_k2');
     // $this->params->fabrics = 'kuku';
     $this->title = JString::trim($this->title);
     if ($this->title == '') {
         $this->setError(JText::_('K2_ITEM_MUST_HAVE_A_TITLE'));
         return false;
     }
     if (!$this->catid) {
         $this->setError(JText::_('K2_ITEM_MUST_HAVE_A_CATEGORY'));
         return false;
     }
     if (empty($this->alias)) {
         $this->alias = $this->title;
     }
     if (K2_JVERSION == '15') {
         if (JPluginHelper::isEnabled('system', 'unicodeslug') || JPluginHelper::isEnabled('system', 'jw_unicodeSlugsExtended')) {
             $this->alias = JFilterOutput::stringURLSafe($this->alias);
         } else {
             mb_internal_encoding("UTF-8");
             mb_regex_encoding("UTF-8");
             $this->alias = trim(mb_strtolower($this->alias));
             $this->alias = str_replace('-', ' ', $this->alias);
             $this->alias = str_replace('/', '-', $this->alias);
             $this->alias = mb_ereg_replace('[[:space:]]+', ' ', $this->alias);
             $this->alias = trim(str_replace(' ', '-', $this->alias));
             $this->alias = str_replace('.', '', $this->alias);
             $this->alias = str_replace('"', '', $this->alias);
             $this->alias = str_replace("'", '', $this->alias);
             $stripthese = ',|~|!|@|%|^|(|)|<|>|:|;|{|}|[|]|&|`|„|‹|’|‘|“|â€�|•|›|«|´|»|°|«|»|…';
             $strips = explode('|', $stripthese);
             foreach ($strips as $strip) {
                 $this->alias = str_replace($strip, '', $this->alias);
             }
             if (trim(str_replace('-', '', $this->alias)) == '') {
                 $datenow = JFactory::getDate();
                 $this->alias = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
             }
             $this->alias = trim($this->alias, '-.');
         }
     } else {
         if (JFactory::getConfig()->get('unicodeslugs') == 1) {
             $this->alias = JFilterOutput::stringURLUnicodeSlug($this->alias);
         } else {
             // Detect the site language we will transliterate
             if ($this->language == '*') {
                 $langParams = JComponentHelper::getParams('com_languages');
                 $languageTag = $langParams->get('site');
             } else {
                 $languageTag = $this->language;
             }
             $language = JLanguage::getInstance($languageTag);
             $this->alias = $language->transliterate($this->alias);
             $this->alias = JFilterOutput::stringURLSafe($this->alias);
             if (trim(str_replace('-', '', $this->alias)) == '') {
                 $this->alias = JFactory::getDate()->format('Y-m-d-H-i-s');
             }
         }
     }
     if (K2_JVERSION == '15' || $params->get('enforceSEFReplacements')) {
         $SEFReplacements = array();
         $items = explode(',', $params->get('SEFReplacements'));
         foreach ($items as $item) {
             if (!empty($item)) {
                 @(list($src, $dst) = explode('|', trim($item)));
                 $SEFReplacements[trim($src)] = trim($dst);
             }
         }
         foreach ($SEFReplacements as $key => $value) {
             $this->alias = str_replace($key, $value, $this->alias);
         }
         $this->alias = trim($this->alias, '-.');
     }
     if (K2_JVERSION == '15') {
         if (trim(str_replace('-', '', $this->alias)) == '') {
             $datenow = JFactory::getDate();
             $this->alias = $datenow->toFormat("%Y-%m-%d-%H-%M-%S");
         }
     }
     // Check if alias already exists. If so warn the user
     $params = JComponentHelper::getParams('com_k2');
     if ($params->get('k2Sef') && !$params->get('k2SefInsertItemId')) {
         $db = JFactory::getDBO();
         $db->setQuery("SELECT id FROM #__k2_items WHERE alias = " . $db->quote($this->alias) . " AND id != " . (int) $this->id);
         $result = count($db->loadObjectList());
         if ($result > 1) {
             $this->alias .= '-' . (int) $result + 1;
             $application = JFactory::getApplication();
             $application->enqueueMessage(JText::_('K2_WARNING_DUPLICATE_TITLE_ALIAS_DETECTED'), 'notice');
         }
     }
     return true;
 }
 /**
  * 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();
     // set the metadata to the Item Data
     if (isset($data['metadata']) && isset($data['metadata']['author'])) {
         $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM');
         $metadata = new JRegistry();
         $metadata->loadArray($data['metadata']);
         $data['metadata'] = (string) $metadata;
     }
     // Set the custom_get items to data.
     if (isset($data['custom_get']) && is_array($data['custom_get'])) {
         $custom_get = new JRegistry();
         $custom_get->loadArray($data['custom_get']);
         $data['custom_get'] = (string) $custom_get;
     } elseif (!isset($data['custom_get'])) {
         // Set the empty custom_get to data
         $data['custom_get'] = '';
     }
     // Set the php_model string to base64 string.
     if (isset($data['php_model'])) {
         $data['php_model'] = base64_encode($data['php_model']);
     }
     // Set the css_document string to base64 string.
     if (isset($data['css_document'])) {
         $data['css_document'] = base64_encode($data['css_document']);
     }
     // Set the php_jview string to base64 string.
     if (isset($data['php_jview'])) {
         $data['php_jview'] = base64_encode($data['php_jview']);
     }
     // Set the php_view string to base64 string.
     if (isset($data['php_view'])) {
         $data['php_view'] = base64_encode($data['php_view']);
     }
     // Set the php_document string to base64 string.
     if (isset($data['php_document'])) {
         $data['php_document'] = base64_encode($data['php_document']);
     }
     // Set the php_jview_display string to base64 string.
     if (isset($data['php_jview_display'])) {
         $data['php_jview_display'] = base64_encode($data['php_jview_display']);
     }
     // Set the js_document string to base64 string.
     if (isset($data['js_document'])) {
         $data['js_document'] = base64_encode($data['js_document']);
     }
     // Set the css string to base64 string.
     if (isset($data['css'])) {
         $data['css'] = base64_encode($data['css']);
     }
     // Set the default string to base64 string.
     if (isset($data['default'])) {
         $data['default'] = base64_encode($data['default']);
     }
     // Set the php_controller string to base64 string.
     if (isset($data['php_controller'])) {
         $data['php_controller'] = base64_encode($data['php_controller']);
     }
     // Set the Params Items to data
     if (isset($data['params']) && is_array($data['params'])) {
         $params = new JRegistry();
         $params->loadArray($data['params']);
         $data['params'] = (string) $params;
     }
     // 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['alias'], $data['name']);
             $data['name'] = $name;
             $data['alias'] = $alias;
         } else {
             if ($data['alias'] == $origTable->alias) {
                 $data['alias'] = '';
             }
         }
         $data['published'] = 0;
     }
     // Automatic handling of alias for empty fields
     if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (int) $input->get('id') == 0) {
         if ($data['alias'] == null) {
             if (JFactory::getConfig()->get('unicodeslugs') == 1) {
                 $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['name']);
             } else {
                 $data['alias'] = JFilterOutput::stringURLSafe($data['name']);
             }
             $table = JTable::getInstance('custom_admin_view', 'componentbuilderTable');
             if ($table->load(array('alias' => $data['alias'])) && ($table->id != $data['id'] || $data['id'] == 0)) {
                 $msg = JText::_('COM_COMPONENTBUILDER_CUSTOM_ADMIN_VIEW_SAVE_WARNING');
             }
             list($name, $alias) = $this->_generateNewTitle($data['alias'], $data['name']);
             $data['alias'] = $alias;
             if (isset($msg)) {
                 JFactory::getApplication()->enqueueMessage($msg, 'warning');
             }
         }
     }
     // Alter the uniqe field for save as copy
     if ($input->get('task') == 'save2copy') {
         // Automatic handling of other uniqe fields
         $uniqeFields = $this->getUniqeFields();
         if (ComponentbuilderHelper::checkArray($uniqeFields)) {
             foreach ($uniqeFields as $uniqeField) {
                 $data[$uniqeField] = $this->generateUniqe($uniqeField, $data[$uniqeField]);
             }
         }
     }
     if (parent::save($data)) {
         return true;
     }
     return false;
 }
示例#12
0
    function create_edit_survey()
    {
        $config = JComponentHelper::getParams(S_APP_NAME);
        $app = JFactory::getApplication();
        $user = JFactory::getUser();
        $survey = new stdClass();
        $html = $user->authorise('core.wysiwyg', S_APP_NAME) && $config->get('default_editor', 'bbcode') == 'wysiwyg';
        $survey->id = $app->input->post->getInt('id', 0);
        $survey->title = $app->input->post->getString('title', null);
        $survey->alias = $app->input->post->getString('alias', null);
        $survey->catid = $app->input->post->getInt('catid', 0);
        $survey->created_by = $app->input->post->getInt('userid', 0);
        $survey->private_survey = $app->input->post->getInt('survey-type', 1);
        $survey->anonymous = $app->input->post->getInt('response-type', 1);
        $survey->public_permissions = $app->input->post->getInt('show-result', 0);
        $survey->display_template = $app->input->post->getInt('show-template', 1);
        $survey->skip_intro = $app->input->post->getInt('skip-intro', 0);
        $survey->display_notice = $app->input->post->getInt('display-notice', 1);
        $survey->display_progress = $app->input->post->getInt('display-progress', 1);
        $survey->notification = $app->input->post->getInt('notification', 1);
        $survey->backward_navigation = $app->input->post->getInt('backward-navigation', 1);
        $survey->publish_up = $app->input->post->getString('publish-up', '0000-00-00 00:00:00');
        $survey->publish_down = $app->input->post->getString('publish-down', '0000-00-00 00:00:00');
        $survey->max_responses = $app->input->post->getInt('max-responses', 1);
        $survey->enable_save_btn = $app->input->post->getInt('enable-save-btn', 1);
        $survey->redirect_url = $app->input->post->getString('redirect-url', '');
        $survey->introtext = CJFunctions::get_clean_var('introtext', $html);
        $survey->endtext = CJFunctions::get_clean_var('endtext', $html);
        $survey->custom_header = CJFunctions::get_clean_var('custom_header', $html);
        $survey->restriction = $app->input->post->get('restriction', array(), 'array');
        $survey->restriction = implode(',', $survey->restriction);
        $created_by = $app->isAdmin() ? $survey->created_by > 0 ? $survey->created_by : $user->id : $user->id;
        $survey->username = JFactory::getUser($created_by)->username;
        $survey->alias = empty($survey->alias) ? JFilterOutput::stringURLUnicodeSlug($survey->title) : JFilterOutput::stringURLUnicodeSlug($survey->alias);
        if (empty($survey->title)) {
            $survey->error = JText::_('MSG_REQUIRED_FIELDS_MISSING');
            return $survey;
        }
        $publish_up = !empty($survey->publish_up) && $survey->publish_up != '0000-00-00 00:00:00' ? JFactory::getDate($survey->publish_up, $app->getCfg('offset'))->toSql() : '0000-00-00 00:00:00';
        $publish_down = !empty($survey->publish_down) && $survey->publish_down != '0000-00-00 00:00:00' ? JFactory::getDate($survey->publish_down, $app->getCfg('offset'))->toSql() : '0000-00-00 00:00:00';
        $mySqlRedirectUrl = empty($survey->redirect_url) ? 'null' : $this->_db->quote($survey->redirect_url);
        if ($survey->id > 0) {
            if (!$user->authorise('core.edit.own', S_APP_NAME . '.category.' . $survey->catid)) {
                $survey->error = JText::_('JERROR_ALERTNOAUTH');
                return $survey;
            }
            $query = '
				update
					#__survey
				set
					title=' . $this->_db->quote($survey->title) . ',
					alias=' . $this->_db->quote($survey->alias) . ',
					catid=' . $survey->catid . ',
					' . ($app->isAdmin() ? 'created_by=' . $created_by . ',' : '') . '
					introtext=' . $this->_db->quote($survey->introtext) . ',
					endtext=' . $this->_db->quote($survey->endtext) . ',
					custom_header=' . $this->_db->quote($survey->custom_header) . ',
					private_survey=' . $survey->private_survey . ',
					anonymous=' . $survey->anonymous . ',
					public_permissions=' . $survey->public_permissions . ',
					skip_intro=' . $survey->skip_intro . ',
					display_notice=' . $survey->display_notice . ',
					display_progress=' . $survey->display_progress . ',
					notification=' . $survey->notification . ',
					backward_navigation=' . $survey->backward_navigation . ',
					publish_up=' . $this->_db->quote($publish_up) . ',
					publish_down=' . $this->_db->quote($publish_down) . ',
					max_responses=' . $survey->max_responses . ',
					redirect_url=' . $mySqlRedirectUrl . ',
					restriction=' . $this->_db->quote($survey->restriction) . ',
					enable_save_btn=' . $survey->enable_save_btn . '.,
					display_template=' . $survey->display_template . '
				where
					id=' . $survey->id;
            $this->_db->setQuery($query);
            if (!$this->_db->query()) {
                $this->setError($this->_db->getErrorMsg());
                $survey->error = JText::_('MSG_ERROR_PROCESSING');
            }
        } else {
            if (!$user->authorise('core.create', S_APP_NAME . '.category.' . $survey->catid)) {
                $survey->error = JText::_('JERROR_ALERTNOAUTH');
                return $survey;
            }
            $survey->key = CJFunctions::generate_random_key();
            $createdate = JFactory::getDate()->toSql();
            $query = '
				insert into
					#__survey
					(
						title, alias, introtext, endtext, custom_header, catid, created_by, created, publish_up, publish_down, max_responses, display_notice, display_progress, enable_save_btn,
						anonymous, private_survey, public_permissions, survey_key, redirect_url, display_template, skip_intro, backward_navigation, notification, restriction, published
					)
				values
					(
						' . $this->_db->quote($survey->title) . ',
						' . $this->_db->quote($survey->alias) . ',
						' . $this->_db->quote($survey->introtext) . ',
						' . $this->_db->quote($survey->endtext) . ',
						' . $this->_db->quote($survey->custom_header) . ',
						' . $survey->catid . ',
						' . $created_by . ',
						' . $this->_db->quote($createdate) . ',
						' . $this->_db->quote($publish_up, false) . ',
						' . $this->_db->quote($publish_down, false) . ',
						' . $survey->max_responses . ',
						' . $survey->display_notice . ',
						' . $survey->display_progress . ',
						' . $survey->enable_save_btn . ',
						' . $survey->anonymous . ',
						' . $survey->private_survey . ',
						' . $survey->public_permissions . ',
						' . $this->_db->quote($survey->key) . ',
						' . $mySqlRedirectUrl . ',
						' . $survey->display_template . ',
						' . $survey->skip_intro . ',
						' . $survey->backward_navigation . ',
						' . $survey->notification . ',
						' . $this->_db->quote($survey->restriction) . ',
						3
					)';
            $this->_db->setQuery($query);
            if (!$this->_db->query()) {
                $this->setError($this->_db->getErrorMsg());
                $survey->error = JText::_('MSG_ERROR_PROCESSING');
                return $survey;
            }
            $survey->id = $this->_db->insertid();
            $this->create_page($survey->id);
        }
        $survey->pages = $this->get_pages($survey->id);
        return $survey;
    }
示例#13
0
 private function tags($id)
 {
     $this->response->status = 'Processing Tags';
     $step = 10;
     $session = JFactory::getSession();
     $db = JFactory::getDbo();
     if ($id == 0) {
         $query = $db->getQuery(true);
         $query->select('COUNT(*)')->from($db->quoteName('#__k2_v2_tags'));
         $db->setQuery($query);
         $total = $db->loadResult();
         $session->set('k2.upgrade.tags.total', $total);
         $session->set('k2.upgrade.tags.processed', 0);
     }
     $query = $db->getQuery(true);
     $query->select('*')->from($db->quoteName('#__k2_v2_tags'))->where($db->quoteName('id') . ' > ' . $id)->order($db->quoteName('id'));
     $db->setQuery($query, 0, $step);
     $tags = $db->loadObjectList();
     foreach ($tags as $tag) {
         $alias = $tag->name;
         if (JFactory::getConfig()->get('unicodeslugs') == 1) {
             $alias = JFilterOutput::stringURLUnicodeSlug($alias);
         } else {
             $alias = JFilterOutput::stringURLSafe($alias);
         }
         if (trim($alias) == '') {
             $alias = uniqid();
         }
         $query = $db->getQuery(true);
         $query->select($db->quoteName('id'))->from($db->quoteName('#__k2_tags'))->where($db->quoteName('alias') . ' = ' . $db->quote($alias));
         $db->setQuery($query);
         if ($db->loadResult()) {
             $alias .= '-' . uniqid();
         }
         $query = $db->getQuery(true);
         $query->insert($db->quoteName('#__k2_tags'));
         $query->values((int) $tag->id . ',' . $db->quote($tag->name) . ',' . $db->quote($alias) . ',' . (int) $tag->published . ',' . $db->quote(''));
         $db->setQuery($query);
         $db->execute();
         $this->response->id = $tag->id;
     }
     $this->response->total = $session->get('k2.upgrade.tags.total');
     $session->set('k2.upgrade.tags.processed', (int) $session->get('k2.upgrade.tags.processed') + count($tags));
     $this->response->processed = $session->get('k2.upgrade.tags.processed');
     if (count($tags) == 0) {
         $this->response->id = 0;
         $this->response->type = 'tagsxref';
     }
 }
示例#14
0
文件: output.php 项目: adjaika/J3Base
 /**
  * Helper wrapper method for stringURLUnicodeSlug
  *
  * @param   string  $string  String to process.
  *
  * @return string  Processed string.
  *
  * @see     JFilterOutput::stringURLUnicodeSlug()
  * @since   3.4
  */
 public function stringURLUnicodeSlug($string)
 {
     return JFilterOutput::stringURLUnicodeSlug($string);
 }
示例#15
0
文件: djseo.php 项目: kidaa30/lojinha
 public static function getAliasName($name = '')
 {
     $par = JComponentHelper::getParams('com_djclassifieds');
     $alias = mb_strtolower($name, "UTF-8");
     $alias = strip_tags($alias);
     if ($par->get('seo_alias_urlsafe', '1')) {
         $alias = JFilterOutput::stringURLSafe($alias);
     } else {
         $alias = JFilterOutput::stringURLUnicodeSlug($alias);
     }
     $alias = str_ireplace(' ', '_', $alias);
     return $alias;
 }
示例#16
0
 /**
  * This method transliterates a string into an URL
  * safe string or returns a URL safe UTF-8 string
  * based on the global configuration
  *
  * @param   string  $string  String to process
  *
  * @return  string  Processed string
  *
  * @since   11.1
  */
 public static function stringURLSafe($string)
 {
     $app = JFactory::getApplication();
     if (self::getCfg('unicodeslugs') == 1) {
         $output = JFilterOutput::stringURLUnicodeSlug($string);
     } else {
         $output = JFilterOutput::stringURLSafe($string);
     }
     return $output;
 }
示例#17
0
function CommunityBuildRoute(&$query)
{
    $app = JFactory::getApplication();
    $segments = array();
    $config = CFactory::getConfig();
    $alias = '';
    // Profile based,
    if (array_key_exists('userid', $query)) {
        $user = CFactory::getUser($query['userid']);
        // Since 1.8.x we will generate URLs based on the vanity url.
        $alias = $user->getAlias();
        $segments[] = $alias;
        unset($query['userid']);
    }
    // @rule: For those my-xxx tasks, we need
    // to force the userid to be rewritten in the URL to maintain compatibility with
    // older URLs.
    if (isset($query['task']) && empty($alias)) {
        $userTasks = array('myvideos', 'myphotos', 'myevents', 'mygroups');
        if (in_array($query['task'], $userTasks)) {
            $user = CFactory::getUser();
            $segments[] = $user->getAlias();
        }
    }
    if (isset($query['view'])) {
        if (empty($query['Itemid'])) {
            $segments[] = $query['view'];
        } else {
            $menu = $app->getMenu();
            $menuItem = $menu->getItem($query['Itemid']);
            if (!isset($menuItem->query['view']) || $menuItem->query['view'] != $query['view']) {
                $segments[] = $query['view'];
            }
        }
        unset($query['view']);
    }
    if (isset($query['task'])) {
        switch ($query['task']) {
            case 'viewgroup':
                $db = JFactory::getDBO();
                $groupid = $query['groupid'];
                $groupModel = CFactory::getModel('groups');
                $group = JTable::getInstance('Group', 'CTable');
                $group->load($groupid);
                $segments[] = $query['task'];
                $groupName = $group->name;
                //if ($jconfig->get('unicodeslugs', 0) == 1)
                if ($app->getCfg('unicodeslugs', 0) == 1) {
                    $groupName = JFilterOutput::stringURLUnicodeSlug($groupName);
                } else {
                    $groupName = JFilterOutput::stringURLSafe($groupName);
                }
                $segments[] = $groupid . '-' . $groupName;
                unset($query['groupid']);
                break;
            case 'viewevent':
                $id = $query['eventid'];
                $event = JTable::getInstance('Event', 'CTable');
                $event->load($id);
                $segments[] = $query['task'];
                $name = $event->title;
                //if ($jconfig->get('unicodeslugs', 0) == 1)
                if ($app->getCfg('unicodeslugs', 0) == 1) {
                    $name = JFilterOutput::stringURLUnicodeSlug($name);
                } else {
                    $name = JFilterOutput::stringURLSafe($name);
                }
                $name = urlencode($name);
                $name = CString::str_ireplace('++', '+', $name);
                $segments[] = $event->id . '-' . $name;
                unset($query['eventid']);
                break;
            case 'video':
                $videoModel = CFactory::getModel('Videos');
                $videoid = $query['videoid'];
                $video = JTable::getInstance('Video', 'CTable');
                $video->load($videoid);
                // We need the task for video otherwise we cannot differentiate between myvideos
                // and viewing a video since myvideos also doesn't pass any tasks.
                $segments[] = $query['task'];
                $title = trim($video->title);
                //if ($jconfig->get('unicodeslugs', 0) == 1)
                if ($app->getCfg('unicodeslugs', 0) == 1) {
                    $title = JFilterOutput::stringURLUnicodeSlug($title);
                } else {
                    $title = JFilterOutput::stringURLSafe($title);
                }
                $segments[] = $video->id . '-' . $title;
                unset($query['videoid']);
                break;
            case 'viewdiscussion':
                $db = JFactory::getDBO();
                $topicId = $query['topicid'];
                $discussionsModel = CFactory::getModel('discussions');
                $discussions = JTable::getInstance('Discussion', 'CTable');
                $discussions->load($topicId);
                $segments[] = $query['task'];
                $discussionName = $discussions->title;
                //if ($jconfig->get('unicodeslugs', 0) == 1)
                if ($app->getCfg('unicodeslugs', 0) == 1) {
                    $discussionName = JFilterOutput::stringURLUnicodeSlug($discussionName);
                } else {
                    $discussionName = JFilterOutput::stringURLSafe($discussionName);
                }
                $segments[] = $topicId . '-' . $discussionName;
                unset($query['topicid']);
                break;
            case 'viewbulletin':
                $db = JFactory::getDBO();
                $bulletinid = $query['bulletinid'];
                $bulletinsModel = CFactory::getModel('bulletins');
                $bulletins = JTable::getInstance('Bulletin', 'CTable');
                $bulletins->load($bulletinid);
                $segments[] = $query['task'];
                $bullentinName = $bulletins->title;
                //if ($jconfig->get('unicodeslugs', 0) == 1)
                if ($app->getCfg('unicodeslugs', 0) == 1) {
                    $bullentinName = JFilterOutput::stringURLUnicodeSlug($bullentinName);
                } else {
                    $bullentinName = JFilterOutput::stringURLSafe($bullentinName);
                }
                $segments[] = $bulletinid . '-' . $bullentinName;
                unset($query['bulletinid']);
                break;
            default:
                if (!in_array($query['task'], array('myphotos', 'mygroups', 'myevents', 'myvideos', 'invites'))) {
                    $segments[] = $query['task'];
                }
                break;
        }
        unset($query['task']);
    }
    return $segments;
}
示例#18
0
文件: cart.php 项目: rodhoff/MNW
 function addAlias($name)
 {
     $alias = strip_tags($name);
     $jConfig = JFactory::getConfig();
     if (!$jConfig->get('unicodeslugs')) {
         $lang = JFactory::getLanguage();
         $alias = $lang->transliterate($alias);
     }
     $app = JFactory::getApplication();
     if (method_exists($app, 'stringURLSafe')) {
         $alias = $app->stringURLSafe($alias);
     } elseif (method_exists('JFilterOutput', 'stringURLUnicodeSlug')) {
         $alias = JFilterOutput::stringURLUnicodeSlug($alias);
     } else {
         $alias = JFilterOutput::stringURLSafe($alias);
     }
     return $alias;
 }
示例#19
0
	/**
	 * This method transliterates a string into an URL
	 * safe string or returns a URL safe UTF-8 string
	 * based on the global configuration
	 *
	 * @param   string  $string  String to process
	 * @param   boolean $forcetransliterate set to true to force transliterate
	 * 
	 * @return  string  Processed string
	 *
	 * @since   11.1
	 */
	static public function stringURLSafe($string,$unicodesupport=false)
	{
		if(version_compare(JVERSION, '1.6', 'ge')) {
			if ($unicodesupport == false && JFactory::getConfig()->get('unicodeslugs') == 1)
			{
				$output = JFilterOutput::stringURLUnicodeSlug($string);
			}
			else
			{
				$output = JFilterOutput::stringURLSafe($string);
			}
		} else {
			$output = JFilterOutput::stringURLSafe($string);
		}
	
		return $output;
	}
示例#20
0
 /**
  * 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;
 }
示例#21
0
 /**
  * Returns unicode alias string from the <code>title</code> passed as an argument. If the Joomla version is less than 1.6, the function will gracefully degrades and outputs normal alias.
  *
  * @param string $title
  */
 public static function getUrlSafeString($title)
 {
     if (JFactory::getConfig()->get('unicodeslugs') == 1) {
         return JFilterOutput::stringURLUnicodeSlug($title);
     } else {
         return JFilterOutput::stringURLSafe($title);
     }
 }
示例#22
0
 /**
  * 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;
 }
示例#23
0
 protected function getAlias($name, $type = false)
 {
     // sanitize the name to an alias
     if (JFactory::getConfig()->get('unicodeslugs') == 1) {
         $alias = JFilterOutput::stringURLUnicodeSlug($name);
     } else {
         $alias = JFilterOutput::stringURLSafe($name);
     }
     // must be a uniqe alias
     if ($type) {
         return $this->getUniqe($alias, 'alias', $type);
     }
     return $alias;
 }
示例#24
0
 function filterName(&$alias)
 {
     if ($alias == "") {
         $alias = JRequest::getString("refField_name");
     }
     $app = JFactory::getApplication();
     $version = new FalangVersion();
     if ($app->getCfg('unicodeslugs') == 1 && $version != 'free') {
         $alias = JFilterOutput::stringURLUnicodeSlug($alias);
     } else {
         $alias = JFilterOutput::stringURLSafe($alias);
     }
 }
示例#25
0
 /**
  * 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;
 }
示例#26
0
 /**
  * Get the alias of the user.
  *
  * @since	1.0
  * @access	public
  * @param	string
  * @return
  */
 public function getAlias($withId = true)
 {
     $config = FD::config();
     // Default permalink to use.
     $name = $config->get('users.aliasName') == 'realname' ? $this->name : $this->username;
     // If sef is not enabled or running SH404, just return the ID-USERNAME prefix.
     jimport('joomla.filesystem.file');
     $jConfig = FD::jconfig();
     $sh404 = JFile::exists(JPATH_ADMINISTRATOR . '/components/com_sh404sef/sh404sef.php');
     $mijoSef = JFile::exists(JPATH_ADMINISTRATOR . '/components/com_mijosef/mijosef.php');
     if (!$jConfig->getValue('sef') || $sh404) {
         return ($withId ? $this->id . ':' : '') . JFilterOutput::stringURLSafe($name);
     }
     $name = ($withId ? $this->id . ':' : '') . $name;
     // Check if the permalink is set
     if ($this->permalink && !empty($this->permalink)) {
         $name = $this->permalink;
         if ($mijoSef) {
             return ($withId ? $this->id . ':' : '') . JFilterOutput::stringURLSafe($name);
         }
     }
     // If alias exists and permalink doesn't we use the alias
     if ($this->alias && !empty($this->alias) && !$this->permalink) {
         $name = ($withId ? $this->id . ':' : '') . JFilterOutput::stringURLUnicodeSlug($this->alias);
     }
     // If the name is in the form of an e-mail address, fix it here by using the ID:permalink syntax
     if (JMailHelper::isEmailAddress($name)) {
         return ($withId ? $this->id . ':' : '') . JFilterOutput::stringURLSafe($name);
     }
     // Ensure that the name is a safe url.
     $name = JFilterOutput::stringURLSafe($name);
     return $name;
 }
示例#27
0
 /**
  * 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();
     // set the metadata to the Item Data
     if (isset($data['metadata']) && isset($data['metadata']['author'])) {
         $data['metadata']['author'] = $filter->clean($data['metadata']['author'], 'TRIM');
         $metadata = new JRegistry();
         $metadata->loadArray($data['metadata']);
         $data['metadata'] = (string) $metadata;
     }
     // Set the Params Items to data
     if (isset($data['params']) && is_array($data['params'])) {
         $params = new JRegistry();
         $params->loadArray($data['params']);
         $data['params'] = (string) $params;
     }
     // 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['alias'], $data['name']);
             $data['name'] = $name;
             $data['alias'] = $alias;
         } else {
             if ($data['alias'] == $origTable->alias) {
                 $data['alias'] = '';
             }
         }
         $data['published'] = 0;
     }
     // Automatic handling of alias for empty fields
     if (in_array($input->get('task'), array('apply', 'save', 'save2new')) && (int) $input->get('id') == 0) {
         if ($data['alias'] == null) {
             if (JFactory::getConfig()->get('unicodeslugs') == 1) {
                 $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['name']);
             } else {
                 $data['alias'] = JFilterOutput::stringURLSafe($data['name']);
             }
             $table = JTable::getInstance('look', 'demoTable');
             if ($table->load(array('alias' => $data['alias'])) && ($table->id != $data['id'] || $data['id'] == 0)) {
                 $msg = JText::_('COM_DEMO_LOOK_SAVE_WARNING');
             }
             list($name, $alias) = $this->_generateNewTitle($data['alias'], $data['name']);
             $data['alias'] = $alias;
             if (isset($msg)) {
                 JFactory::getApplication()->enqueueMessage($msg, 'warning');
             }
         }
     }
     // Alter the uniqe field for save as copy
     if ($input->get('task') == 'save2copy') {
         // Automatic handling of other uniqe fields
         $uniqeFields = $this->getUniqeFields();
         if (DemoHelper::checkArray($uniqeFields)) {
             foreach ($uniqeFields as $uniqeField) {
                 $data[$uniqeField] = $this->generateUniqe($uniqeField, $data[$uniqeField]);
             }
         }
     }
     if (parent::save($data)) {
         return true;
     }
     return false;
 }
示例#28
0
文件: tags.php 项目: pguilford/vcomcc
    public function insert_tags($itemid, $strtags)
    {
        $tags = explode(',', $strtags);
        // first filter out the tags
        foreach ($tags as $i => $tag) {
            $tag = preg_replace('/[^-\\pL.\\x20]/u', '', $tag);
            if (empty($tag)) {
                unset($tags[$i]);
            }
        }
        // now if there are any new tags, insert them.
        if (!empty($tags)) {
            $inserts = array();
            $sqltags = array();
            foreach ($tags as $tag) {
                $alias = JFilterOutput::stringURLUnicodeSlug($tag);
                $inserts[] = '(' . $this->_db->quote($tag) . ',' . $this->_db->quote($alias) . ')';
                $sqltags[] = $this->_db->quote($tag);
            }
            $query = 'insert ignore into ' . $this->_tbl_tags . ' (tag_text, alias) values ' . implode(',', $inserts);
            $this->_db->setQuery($query);
            if (!$this->_db->query()) {
                return false;
            }
            // we need to get all tag ids matching the input tags
            $query = 'select id from ' . $this->_tbl_tags . ' where tag_text in (' . implode(',', $sqltags) . ')';
            $this->_db->setQuery($query);
            $insertids = $this->_db->loadColumn();
            if (!empty($insertids)) {
                $mapinserts = array();
                $statinserts = array();
                foreach ($insertids as $insertid) {
                    $mapinserts[] = '(' . $insertid . ',' . $itemid . ')';
                    $statinserts[] = '(' . $insertid . ',' . '1)';
                }
                $query = 'insert ignore into ' . $this->_tbl_tags_map . '(tag_id, item_id) values ' . implode(',', $mapinserts);
                $this->_db->setQuery($query);
                if (!$this->_db->query()) {
                    return false;
                }
                $query = 'insert ignore into ' . $this->_tbl_tags_stats . '(tag_id, num_items) values ' . implode(',', $statinserts);
                $this->_db->setQuery($query);
                if (!$this->_db->query()) {
                    return false;
                }
            }
            // now remove all non-matching tags ids from the map
            $where = '';
            if (!empty($insertids)) {
                $where = ' and tag_id not in (' . implode(',', $insertids) . ')';
            }
            $query = 'select tag_id from ' . $this->_tbl_tags_map . ' where item_id = ' . $itemid . $where;
            $this->_db->setQuery($query);
            $removals = $this->_db->loadColumn();
            $where = '';
            if (!empty($removals)) {
                $query = 'delete from ' . $this->_tbl_tags_map . ' where tag_id in (' . implode(',', $removals) . ')';
                $this->_db->setQuery($query);
                $this->_db->query();
                $where = ' or s.tag_id in (' . implode(',', $removals) . ')';
            }
            // now update the stats
            $query = '
				update
					' . $this->_tbl_tags_stats . ' s
				set
					s.num_items = (select count(*) from ' . $this->_tbl_tags_map . ' m where m.tag_id = s.tag_id)
				where
					s.tag_id in (select tag_id from ' . $this->_tbl_tags_map . ' m1 where m1.item_id = ' . $itemid . ')' . $where;
            $this->_db->setQuery($query);
            $this->_db->query();
        } else {
            $query = 'delete from ' . $this->_tbl_tags_map . ' where item_id = ' . $itemid;
            $this->_db->setQuery($query);
            $this->_db->query();
        }
    }
示例#29
0
文件: event.php 项目: esorone/efcpw
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success.
  *
  * @since	3.4.0
  */
 public function save($data)
 {
     $input = JFactory::getApplication()->input;
     $date = JFactory::getDate();
     $user = JFactory::getUser();
     // Fix version before 3.4.0 to set a created date (will use last modified date if exists, or current date)
     if (empty($data['created'])) {
         $data['created'] = !empty($data['modified']) ? $data['modified'] : $date->toSql();
     }
     // 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')) && (int) $input->get('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('Event', 'iCagendaTable');
             if ($table->load(array('alias' => $data['alias'], 'catid' => $data['catid']))) {
                 $msg = JText::_('COM_ICAGENDA_ALERT_EVENT_SAVE_WARNING');
             }
             list($title, $alias) = $this->generateNewTitle($data['catid'], $data['alias'], $data['title']);
             $data['alias'] = $alias;
             if (isset($msg)) {
                 JFactory::getApplication()->enqueueMessage($msg, 'warning');
             }
         }
     }
     // Generates Alias if empty
     if ($data['alias'] == null || empty($data['alias'])) {
         $data['alias'] = JFilterOutput::stringURLSafe($data['title']);
         if ($data['alias'] == null || empty($data['alias'])) {
             if (JFactory::getConfig()->get('unicodeslugs') == 1) {
                 $data['alias'] = JFilterOutput::stringURLUnicodeSlug($data['title']);
             } else {
                 $data['alias'] = JFilterOutput::stringURLSafe($data['created']);
             }
         }
     }
     // Set File Uploaded
     if (!isset($data['file'])) {
         $file = JRequest::getVar('jform', null, 'files', 'array');
         $fileUrl = $this->upload($file);
         $data['file'] = $fileUrl;
     }
     // Set Creator infos
     $userId = $user->get('id');
     $userName = $user->get('name');
     if (empty($data['created_by'])) {
         $data['created_by'] = (int) $userId;
     }
     $data['username'] = $userName;
     // Set Params
     if (isset($data['params']) && is_array($data['params'])) {
         // Convert the params field to a string.
         $parameter = new JRegistry();
         $parameter->loadArray($data['params']);
         $data['params'] = (string) $parameter;
     }
     // Get Event ID from the result back to the Table after saving.
     $table = $this->getTable();
     if ($table->save($data) === true) {
         $data['id'] = $table->id;
     } else {
         $data['id'] = null;
     }
     if (parent::save($data)) {
         // Save Features to database
         $this->maintainFeatures($data);
         // Save Custom Fields to database
         if (isset($data['custom_fields']) && is_array($data['custom_fields'])) {
             icagendaCustomfields::saveToData($data['custom_fields'], $data['id'], 2);
         }
         return true;
     }
     return false;
 }
示例#30
0
 /**
  * Generates a permalink given a string
  *
  * @since	5.0
  * @access	public
  * @param	string
  * @return
  */
 public static function normalizePermalink($string)
 {
     $config = EB::config();
     $permalink = '';
     if (EBR::isSefEnabled() && $config->get('main_sef_unicode')) {
         $permalink = JFilterOutput::stringURLUnicodeSlug($string);
         return $permalink;
     }
     // Replace accents to get accurate string
     $string = EBR::replaceAccents($string);
     // no unicode supported.
     $permalink = JFilterOutput::stringURLSafe($string);
     // check if anything return or not. If not, then we give a date as the alias.
     if (trim(str_replace('-', '', $permalink)) == '') {
         $date = EB::date();
         $permalink = $date->format("%Y-%m-%d-%H-%M-%S");
     }
     return $permalink;
 }