Forums

submit_article some fixes

agostino 27 Sep, 2012
Hi I found 3 error on in object action, and add 1 little feature.

TIME CREATION
In some condition, if the Joomla installation is set to a timezone and the user is set to another the article published isnt visible until UTC time pass virtual user time.

The solution is to patch line 26:
			$form->data['created'] = $date->format('Y-m-d H:i:s', false, false); // date("Y-m-d H:i:s");

with:

			$user =& JFactory::getUser();
			$date = new JDate($myDate, $user->getParam('timezone')?JFactory::getConfig()->getValue('offset'):0);
			$form->data['created'] = $date->format('Y-m-d H:i:s', false, false); // date("Y-m-d H:i:s");


LANGUAGE
Another patch required, is to add somewhere a line:
$form->data['language'] = '*';

because if the joomla installation had a language filter active, new submitted articles is not show.

[DEFAULT_CREATOR]
Than I applied another feature that permit to choice a user for publish articles from guest users:
I Add this lines at submit_article.ctp at line 15:

         <input type="hidden" name="chronoaction[{n}][action_submit_article_{n}_default_created_by]" id="action_submit_article_{n}_default_created_by" value="<?php echo $action_params['default_created_by']; ?>" />

at line 45:

	<?php
			$database =& JFactory::getDBO();
			$query = "SELECT * FROM `#__users`";
			$database->setQuery($query);
			$options = array();
			$users = $database->loadObjectList();
			foreach($users as $user){
				$options[$user->id] = $user->name;
			}
		?>
		<?php echo $HtmlHelper->input('action_submit_article_{n}_default_created_by_config', array('type' => 'select', 'label' => 'Default Author (if none logged in)', 'options' => $options, 'empty' => " - ", 'class' => 'medium_input', 'smalldesc' => "Select the article's default author in users.")); ?>


and to submit_article.php at line 30: (after other patch for correct timing of article)

         $form->data['created_by'] = ($user->guest)?$params->get('default_created_by', ''):$user->id;


Unique article alias
I discover that on sending an article with the action can be create more than one article with same alias, this condition can be a disaster for SEF of a website, this few lines solve the problem.

         $database =& JFactory::getDBO(); 
		$alias = JFilterOutput::stringURLSafe($form->data['title']);
		$n=2;
		do {
			$query = "SELECT * FROM `#__content` WHERE alias = '{$form->data['alias']}'";
			$database->setQuery($query);
			$articles = $database->loadObjectList();
			if (!empty($articles)) {
				$form->data['alias']=$alias.'-'.$n;
				$n++;
			}
		} while (!empty($articles));


I place on my webserver patched files (zip form) at this url: http://www.sfs.it/downloads/submit_article.zip

Zipped files can be used to update standard action present into Chronoforms installation.
--
Agostino Zanutto
SFS.it
GreyHead 27 Sep, 2012
HI Agostino,

Thank you very much, I've added these to the current RC3.5 bugs list. Max should pick them up for the next release.

Bob
agostino 06 Oct, 2012
I made another little fix adding a Alias field to submitting articles.
(I need to use it on a q&a section for a website)

It's made with this little fixes on my old code:
on submit_article.ctp at line 11 add:
	<input type="hidden" name="chronoaction[{n}][action_submit_article_{n}_alias]" id="action_submit_article_{n}_alias" value="<?php echo $action_params['alias']; ?>" />

and at line 29
		<?php echo $HtmlHelper->input('action_submit_article_{n}_alias_config', array('type' => 'text', 'label' => "Article Alias Field", 'class' => 'medium_input', 'smalldesc' => "The field name which will hold the article's alias, if empty it's automatically generated escaping title.")); ?>


than on submit_article.ptp I:
change lines 34-36 from:
		$form->data['title'] = $form->data[$params->get('title', '');
		$form->data['fulltext'] = $form->data[$params->get('fulltext', '');
		$form->data['introtext'] = $form->data[$params->get('introtext', '')];

to
		$form->data['title'] = isset($form->data[$params->get('title', '')]) ? $form->data[$params->get('title', '')] : '';
		$form->data['fulltext'] = isset($form->data[$params->get('fulltext', '')]) ?$form->data[$params->get('fulltext', '')] : '';
		$form->data['introtext'] = isset($form->data[$params->get('introtext', '')]) ? $form->data[$params->get('introtext', '')] : '';

to fix an possible error on access to form array, and I add line 37:
		$form->data['alias'] = isset($form->data[$params->get('alias', '')]) ? $form->data[$params->get('alias', '')] : '';

and change line 42 to:
		$alias = empty($form->data['alias'])?JFilterOutput::stringURLSafe($form->data['title']):JFilterOutput::stringURLSafe($form->data['alias']);


action zip can be download from my website at url http://www.sfs.it/downloads/submit_article.zip
GreyHead 06 Oct, 2012
Hi agostino,

Thank you,

I made some changes to the FAQs code here a day or two ago to allow the use of the 'read-more' divider. This doesn't use the Submit Article action but the Custom Code in the form is similar and could be added to the Submit Article action. When I find time I'll try to consolidate all the changes.

Bob
This topic is locked and no more replies can be posted.