Please show me how Joomla save an article!!!

48 views
Skip to first unread message

JCoder

unread,
Nov 21, 2009, 6:41:00 AM11/21/09
to Joomla! General Development
I am writing code to save an article. I search through Joomla code to
know how it saves an article. But I do not understand this fully.

I can't save an article with introduction text.

All I can do is save article to fulltext field. I check this by
viewing database with phpMyAdmin.

I am working with Joomla 1.5.14

Thank you for any help!

Louis Landry

unread,
Nov 21, 2009, 10:46:03 AM11/21/09
to joomla-de...@googlegroups.com
Why don't you post your code that you are using that saves it to the fulltext field?  Then perhaps someone can show you how to alter it to work the way you want it.

- Louis
--
Development Coordinator
Joomla! ... because open source matters.
http://www.joomla.org

JCoder

unread,
Nov 22, 2009, 7:38:25 AM11/22/09
to Joomla! General Development
Ok. Here I post the code (it is copied and edited from Joomla code,
more exactly, the function saveContent() from file \administrator
\components\com_content\controller.php)

protected function save_article(&$article) {
global $mainframe;

// Check for request forgeries
//JRequest::checkToken() or jexit( 'Invalid Token' );

// Initialize variables
$db = & JFactory::getDBO();
$user = & JFactory::getUser();
//JPluginHelper::importPlugin('content');
//require_once('helper.php');

$row = & JTable::getInstance('content');

//include('../../../../components/com_content/models/article.php');
//echo '<br />s';
//$row = new ContentModelArticle();
//foreach ($row->getProperties() as $k => $v)
//{
// echo '<br />' .$k;
//}
//echo '<br />e';
//exit;

$row->catid = 12;
$row->access = 0;
$row->created = '';
$row->created_by = null;
$row->publish_down = 'Never';
$row->publish_up = '';
$row->mask = 0;
$row->sectionid = 3;
$row->state = 1;
$row->version = 0;
// title, text
$row->title = $article->get_title();
//$row->introtext = 'aaa';//$article->get_lead();
//$row->fulltext = $article->get_content();
//$row->text = 'aaa';

$row->created_by = $row->created_by ? $row->created_by : $user->get
('id');

if ($row->created && strlen(trim( $row->created )) <= 10) {
$row->created .= ' 00:00:00';
}

$config =& JFactory::getConfig();
$tzoffset = $config->getValue('config.offset');
$date =& JFactory::getDate($row->created, $tzoffset);
$row->created = $date->toMySQL();

// Append time if not added to publish date
if (strlen(trim($row->publish_up)) <= 10) {
$row->publish_up .= ' 00:00:00';
}

$date =& JFactory::getDate($row->publish_up, $tzoffset);
$row->publish_up = $date->toMySQL();

// Handle never unpublish date
if (trim($row->publish_down) == JText::_('Never') || trim( $row-
>publish_down ) == '')
{
$row->publish_down = $nullDate;
}
else
{
if (strlen(trim( $row->publish_down )) <= 10) {
$row->publish_down .= ' 00:00:00';
}
$date =& JFactory::getDate($row->publish_down, $tzoffset);
$row->publish_down = $date->toMySQL();
}

// Prepare the content for saving to the database
ContentHelper::saveContentPrep( $row );

// Make sure the data is valid
//if (!$row->check()) {
// JError::raiseError( 500, $db->stderr() );
// return false;
//}

// Increment the content version number
$row->version++;

// Store the content to the database
if (!$row->store()) {
JError::raiseError( 500, $db->stderr() );
return false;
}

// Check the article and update item order
$row->checkin();
$row->reorder('catid = '.(int) $row->catid.' AND state >= 0');

$cache = & JFactory::getCache('com_content');
$cache->clean();

Louis Landry

unread,
Nov 23, 2009, 10:24:52 AM11/23/09
to joomla-de...@googlegroups.com
Well, the code in question lives at:

    // Prepare the content for saving to the database
    ContentHelper::saveContentPrep( $row );

And if you look at that, it is getting the data straight from the 'text' post variable.  What are the post variables you are using and what are they named?

- Louis

JCoder

unread,
Nov 23, 2009, 11:46:35 AM11/23/09
to Joomla! General Development
Ok, I got it & solve my problem

Thank you very much!!!

JCoder

unread,
Nov 23, 2009, 11:50:47 AM11/23/09
to Joomla! General Development
I also want to ask you:

How to include the file \joomla\administrator\components\com_content
\helper.php (in component com_content) for use in another
custom component.

Currently I copy the file to my custom component folder.

Louis Landry

unread,
Nov 23, 2009, 11:54:40 AM11/23/09
to joomla-de...@googlegroups.com
include JPATH_ADMINISTRATOR.'/components/com_content/helper.php'; 

That should get it done.

Glad you got it working.

- Louis

Oli Griffiths

unread,
Nov 24, 2009, 3:38:43 AM11/24/09
to joomla-de...@googlegroups.com
Not wanting to be smart, but shouldn’t it be

include JPATH_ADMINISTRATOR.DS.’components’.DS.’com_content’.DS.’helper.php’;

:)

Oli

JCoder

unread,
Nov 24, 2009, 7:45:13 AM11/24/09
to Joomla! General Development
Thank you all, Louis and Oli,

It works very good.

On Nov 24, 3:38 pm, Oli Griffiths <o...@organic-development.com>
wrote:

Christophe Demko

unread,
Nov 24, 2009, 9:21:32 AM11/24/09
to Joomla! General Development
You can use slashes on the Linux platform and the Windows platform.
The DS macro is no longer needed.

Louis Landry

unread,
Nov 24, 2009, 12:26:12 PM11/24/09
to joomla-de...@googlegroups.com
Heh...

Oli, that certainly has been a convention followed in the past by us.  As Christophe points out though modern versions of PHP seem to have zero issue handling slashes on any platform.  So.... yes and no :-)

- Louis

Oli Griffiths

unread,
Nov 24, 2009, 12:44:58 PM11/24/09
to joomla-de...@googlegroups.com
Damnit!

So, does this mean that 1.6 no longer uses DS?

Joseph LeBlanc

unread,
Nov 24, 2009, 12:56:01 PM11/24/09
to joomla-de...@googlegroups.com
It was something we were discussing on the CMS dev list a month or so ago. It looks like we're moving towards dropping DS, but leaving the constant around for backwards compatibility.

-Joe

JCoder

unread,
Nov 25, 2009, 5:28:08 AM11/25/09
to Joomla! General Development
Thanks you all of you very much!!!

On Nov 25, 12:56 am, Joseph LeBlanc <cont...@jlleblanc.com> wrote:
> It was something we were discussing on the CMS dev list a month or so ago. It looks like we're moving towards dropping DS, but leaving the constant around for backwards compatibility.
>
> -Joe
>
> On Nov 24, 2009, at 12:44 PM, Oli Griffiths wrote:
>
> > Damnit!
>
> > So, does this mean that 1.6 no longer uses DS?
>
> > On 24/11/2009 17:26, "Louis Landry" <louis.lan...@joomla.org> wrote:
>
> > Heh...
>
> > Oli, that certainly has been a convention followed in the past by us.  As Christophe points out though modern versions of PHP seem to have zero issue handling slashes on any platform.  So.... yes and no :-)
>
> > - Louis
>
> > On Tue, Nov 24, 2009 at 8:21 AM, Christophe Demko <chde...@gmail.com> wrote:
>
> > You can use slashes on the Linux platform and the Windows platform.
> > The DS macro is no longer needed.
>
> > On 24 nov, 09:38, Oli Griffiths <o...@organic-development.com> wrote:
> > > Not wanting to be smart, but shouldn’t it be
> > > include JPATH_ADMINISTRATOR.DS.’components’.DS.’com_content’.DS.’helper.php’;
> > > :)
> > > Oli
> > > On 23/11/2009 16:54, "Louis Landry" <louis.lan...@joomla.org> wrote:include JPATH_ADMINISTRATOR.'/components/com_content/helper.php';

Andrew Eddie

unread,
Nov 25, 2009, 7:32:29 AM11/25/09
to joomla-de...@googlegroups.com
That's the premise I'm working on (using / instead of DS). Just
chipping away at files as I work on them.

Regards,
Andrew Eddie
http://www.theartofjoomla.com - the art of becoming a Joomla developer

2009/11/25 Joseph LeBlanc <con...@jlleblanc.com>:

KenMcD

unread,
Nov 25, 2009, 10:33:46 AM11/25/09
to Joomla! General Development

Andrew, Joseph, et.al.,

In the other "DS" discussion there was a mention that there may be
some cases
where the DS may still be needed.
Have you found any specific cases where this would be the case?

I am asking this from the standpoint of a novice PHP developer who is
updating
a well known component and plugin and would like to remove all the
DSes.
What to watch out for, if anything.

Anything come to mind or should I just yank them all out and see how
it goes?

Thanks!

Ken

On 25 Nov, 04:32, Andrew Eddie <mambob...@gmail.com> wrote:
> That's the premise I'm working on (using / instead of DS).  Just
> chipping away at files as I work on them.
>
> Regards,
> Andrew Eddiehttp://www.theartofjoomla.com- the art of becoming a Joomla developer
>
> 2009/11/25 Joseph LeBlanc <cont...@jlleblanc.com>:
>
> > It was something we were discussing on the CMS dev list a month or so ago.
> > It looks like we're moving towards dropping DS, but leaving the constant
> > around for backwards compatibility.
> > -Joe
>
> > On Nov 24, 2009, at 12:44 PM, Oli Griffiths wrote:
>
> > Damnit!
>
> > So, does this mean that 1.6 no longer uses DS?
>
> > On 24/11/2009 17:26, "Louis Landry" <louis.lan...@joomla.org> wrote:
>
> > Heh...
>
> > Oli, that certainly has been a convention followed in the past by us.  As
> > Christophe points out though modern versions of PHP seem to have zero issue
> > handling slashes on any platform.  So.... yes and no :-)
>
> > - Louis
>
> > On Tue, Nov 24, 2009 at 8:21 AM, Christophe Demko <chde...@gmail.com> wrote:
>
> > You can use slashes on the Linux platform and the Windows platform.
> > The DS macro is no longer needed.
>
> > On 24 nov, 09:38, Oli Griffiths <o...@organic-development.com> wrote:
> >> Not wanting to be smart, but shouldn’t it be
> >> include
> >> JPATH_ADMINISTRATOR.DS.’components’.DS.’com_content’.DS.’helper.php’;
> >> :)
> >> Oli
> >> On 23/11/2009 16:54, "Louis Landry" <louis.lan...@joomla.org>

Joseph LeBlanc

unread,
Nov 25, 2009, 11:20:53 AM11/25/09
to joomla-de...@googlegroups.com
I'm not aware of any remaining cases. IIRC, the slashes may have been needed in earlier versions of PHP.

-Joe
Reply all
Reply to author
Forward
0 new messages