5 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
\r
6 * Copyright (C) 2002-2012 The Nucleus Group
\r
8 * This program is free software; you can redistribute it and/or
\r
9 * modify it under the terms of the GNU General Public License
\r
10 * as published by the Free Software Foundation; either version 2
\r
11 * of the License, or (at your option) any later version.
\r
12 * (see nucleus/documentation/index.html#license for more info)
\r
15 * @license http://nucleuscms.org/license.txt GNU General Public License
\r
16 * @copyright Copyright (C) 2002-2012 The Nucleus Group
\r
17 * @version $Id: ITEM.php 1668 2012-02-19 14:36:44Z sakamocchi $
\r
21 * A class representing an item
\r
27 * Item::$actiontypes
\r
28 * actiontype list for handling items
\r
32 static private $actiontypes = array(
\r
33 'addnow', 'adddraft', 'addfuture', 'edit',
\r
34 'changedate', 'backtodrafts', 'delete'
\r
45 * Item::__construct()
\r
46 * Creates a new ITEM object
\r
49 * @param integer $item_id id for item
\r
52 public function __construct($item_id)
\r
54 $this->itemid = $item_id;
\r
60 * Returns one item with the specific itemid
\r
63 * @param int $item_id
\r
64 * @param bool $allow_draft
\r
65 * @param bool $allow_future
\r
68 static public function getitem($item_id, $allow_draft, $allow_future)
\r
72 $item_id = (integer) $item_id;
\r
74 $query = 'SELECT ' .
\r
75 'i.idraft AS draft, ' .
\r
76 'i.inumber AS itemid, ' .
\r
77 'i.iclosed AS closed, ' .
\r
78 'i.ititle AS title, ' .
\r
79 'i.ibody AS body, ' .
\r
80 'm.mname AS author, ' .
\r
81 'i.iauthor AS authorid, ' .
\r
83 'i.imore AS more, ' .
\r
84 'i.ikarmapos AS karmapos, ' .
\r
85 'i.ikarmaneg AS karmaneg, ' .
\r
86 'i.icat AS catid, ' .
\r
87 'i.iblog AS blogid ' .
\r
88 'FROM %s AS i, %s AS m, %s AS b ' .
\r
89 'WHERE i.inumber = %d ' .
\r
90 'AND i.iauthor = m.mnumber ' .
\r
91 'AND i.iblog = b.bnumber ';
\r
93 $query = sprintf($query, sql_table('item'), sql_table('member'), sql_table('blog'), $item_id);
\r
95 if ( !$allow_draft )
\r
97 $query .= "AND i.idraft = 0 ";
\r
100 if ( !$allow_future )
\r
102 $blog =& $manager->getBlog(getBlogIDFromItemID($item_id));
\r
103 $query .= 'AND i.itime <= ' . DB::formatDateTime($blog->getCorrectTime());
\r
106 $query .= ' LIMIT 1';
\r
107 $result = DB::getResult($query);
\r
109 if ( $result->rowCount() == 1 )
\r
111 $aItemInfo = $result->fetch(PDO::FETCH_ASSOC);
\r
112 $aItemInfo['timestamp'] = strtotime($aItemInfo['itime']);
\r
119 * Item::createFromRequest()
\r
120 * Tries to create an item from the data in the current request (comes from
\r
121 * bookmarklet or admin area
\r
125 * @return array (status = added/error/newcategory, message)
\r
128 static public function createFromRequest()
\r
130 global $member, $manager;
\r
133 * TODO: these values from user agent should be validated but not implemented yet
\r
135 $i_author = $member->getID();
\r
136 $i_body = postVar('body');
\r
137 $i_title = postVar('title');
\r
138 $i_more = postVar('more');
\r
139 $i_actiontype = postVar('actiontype');
\r
140 $i_closed = intPostVar('closed');
\r
141 $i_hour = intPostVar('hour');
\r
142 $i_minutes = intPostVar('minutes');
\r
143 $i_month = intPostVar('month');
\r
144 $i_day = intPostVar('day');
\r
145 $i_year = intPostVar('year');
\r
146 $i_catid = postVar('catid');
\r
147 $i_draftid = intPostVar('draftid');
\r
149 if ( !$member->canAddItem($i_catid) )
\r
151 return array('status' => 'error', 'message' => _ERROR_DISALLOWED);
\r
154 if ( !in_array($i_actiontype, self::$actiontypes) )
\r
156 $i_actiontype = 'addnow';
\r
159 $i_draft = (integer) ( $i_actiontype == 'adddraft' );
\r
161 if ( !trim($i_body) )
\r
163 return array('status' => 'error', 'message' => _ERROR_NOEMPTYITEMS);
\r
166 // create new category if needed
\r
167 if ( i18n::strpos($i_catid, 'newcat') === 0 )
\r
170 list($i_blogid) = sscanf($i_catid, "newcat-%d");
\r
173 $blog =& $manager->getBlog($i_blogid);
\r
174 $i_catid = $blog->createNewCategory();
\r
176 // show error when sth goes wrong
\r
179 return array('status' => 'error','message' => 'Could not create new category');
\r
184 // force blogid (must be same as category id)
\r
185 $i_blogid = getBlogIDFromCatID($i_catid);
\r
186 $blog =& $manager->getBlog($i_blogid);
\r
189 if ( $i_actiontype == 'addfuture' )
\r
191 $posttime = mktime($i_hour, $i_minutes, 0, $i_month, $i_day, $i_year);
\r
193 // make sure the date is in the future, unless we allow past dates
\r
194 if ( (!$blog->allowPastPosting()) && ($posttime < $blog->getCorrectTime()) )
\r
196 $posttime = $blog->getCorrectTime();
\r
203 $posttime = $blog->getCorrectTime();
\r
211 if ( $posttime > $blog->getCorrectTime() )
\r
214 $blog->setFuturePost();
\r
221 $itemid = $blog->additem($i_catid, $i_title, $i_body, $i_more, $i_blogid, $i_author, $posttime, $i_closed, $i_draft, $posted);
\r
223 //Setting the itemOptions
\r
224 $aOptions = requestArray('plugoption');
\r
225 NucleusPlugin::apply_plugin_options($aOptions, $itemid);
\r
227 'context' => 'item',
\r
228 'itemid' => $itemid,
\r
230 'title' => $i_title,
\r
233 'closed' => $i_closed,
\r
234 'catid' => $i_catid
\r
238 $manager->notify('PostPluginOptionsUpdate', $data);
\r
240 if ( $i_draftid > 0 )
\r
242 // delete permission is checked inside Item::delete()
\r
243 self::delete($i_draftid);
\r
247 if ( $i_catid != intRequestVar('catid') )
\r
249 return array('status' => 'newcategory', 'itemid' => $itemid, 'catid' => $i_catid);
\r
252 return array('status' => 'added', 'itemid' => $itemid);
\r
260 * @param integer $itemid item id
\r
261 * @param integer $catid category id
\r
262 * @param string $title title
\r
263 * @param string $body body text
\r
264 * @param string $more more text
\r
265 * @param boolean $closed closed or not
\r
266 * @param boolean $wasdraft previously draft or not
\r
267 * @param boolean $publish published or not
\r
268 * @param timestamp $timestamp timestamp
\r
271 static public function update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp = 0)
\r
275 $itemid = (integer) $itemid;
\r
276 $closed = (boolean) $closed;
\r
278 // get destination blogid
\r
279 $new_blogid = getBlogIDFromCatID($catid);
\r
280 $old_blogid = getBlogIDFromItemID($itemid);
\r
282 // move will be done on end of method
\r
284 if ( $new_blogid != $old_blogid )
\r
289 $blog =& $manager->getBlog($new_blogid);
\r
291 // begin if: convert line breaks to <br/>
\r
292 if ( $blog->convertBreaks() )
\r
294 $body = addBreaks($body);
\r
295 $more = addBreaks($more);
\r
300 'itemid' => $itemid,
\r
301 'title' => &$title,
\r
305 'closed' => &$closed,
\r
308 $manager->notify('PreUpdateItem', $data);
\r
310 // update item itself
\r
311 $query = 'UPDATE ' . sql_table('item')
\r
313 . ' ibody = ' . DB::quoteValue($body) . ','
\r
314 . ' ititle = ' . DB::quoteValue($title) . ','
\r
315 . ' imore = ' . DB::quoteValue($more) . ','
\r
316 . ' iclosed = ' . intval($closed) . ','
\r
317 . ' icat = ' . intval($catid);
\r
319 // if we received an updated timestamp that is in the past, but past posting is not allowed,
\r
320 // reject that date change (timestamp = 0 will make sure the current date is kept)
\r
321 if ( (!$blog->allowPastPosting()) && ($timestamp < $blog->getCorrectTime()) )
\r
326 // begin if: post is in the future
\r
327 if ( $timestamp > $blog->getCorrectTime(time()) )
\r
330 $query .= ', iposted = 0';
\r
335 $query .= ', iposted = 1';
\r
338 if ( $wasdraft && $publish )
\r
340 // set timestamp to current date only if it's not a future item
\r
341 // draft items have timestamp == 0
\r
342 // don't allow timestamps in the past (unless otherwise defined in blogsettings)
\r
343 $query .= ', idraft = 0';
\r
345 if ( $timestamp == 0 )
\r
347 $timestamp = $blog->getCorrectTime();
\r
350 // send new item notification
\r
351 if ( !$isFuture && $blog->getNotifyAddress() && $blog->notifyOnNewItem() )
\r
353 $blog->sendNewItemNotification($itemid, $title, $body);
\r
357 // save back to drafts
\r
358 if ( !$wasdraft && !$publish )
\r
360 $query .= ', idraft = 1';
\r
361 // set timestamp back to zero for a draft
\r
362 $query .= ', itime = ' . DB::formatDateTime($timestamp);
\r
365 // update timestamp when needed
\r
366 if ( $timestamp != 0 )
\r
368 $query .= ', itime = ' . DB::formatDateTime($timestamp);
\r
371 // make sure the correct item is updated
\r
372 $query .= ' WHERE inumber = ' . $itemid;
\r
375 DB::execute($query);
\r
377 $manager->notify('PostUpdateItem', array('itemid' => $itemid));
\r
379 // when needed, move item and comments to new blog
\r
382 self::move($itemid, $catid);
\r
385 //update the itemOptions
\r
386 $aOptions = requestArray('plugoption');
\r
387 NucleusPlugin::apply_plugin_options($aOptions);
\r
389 'context' => 'item',
\r
390 'itemid' => $itemid,
\r
395 'closed' => $closed,
\r
399 $manager->notify('PostPluginOptionsUpdate', $data);
\r
405 * Move an item to another blog (no checks)
\r
408 * @param integer $itemid
\r
409 * @param integer $new_catid
\r
412 static public function move($itemid, $new_catid)
\r
416 $itemid = (integer) $itemid;
\r
417 $new_catid = (integer) $new_catid;
\r
418 $new_blogid = getBlogIDFromCatID($new_catid);
\r
421 'itemid' => $itemid,
\r
422 'destblogid' => $new_blogid,
\r
423 'destcatid' => $new_catid
\r
425 $manager->notify('PreMoveItem', $data);
\r
427 // update item table
\r
428 $query = "UPDATE %s SET iblog=%d, icat=%d WHERE inumber=%d";
\r
429 $query = sprintf($query, sql_table('item'), $new_blogid, $new_catid, $itemid);
\r
430 DB::execute($query);
\r
433 $query = "UPDATE %s SET cblog=%d WHERE citem=%d";
\r
434 $query = sprintf($query, sql_table('comment'), $new_blogid, $itemid);
\r
435 DB::execute($query);
\r
438 'itemid' => $itemid,
\r
439 'destblogid' => $new_blogid,
\r
440 'destcatid' => $new_catid
\r
442 $manager->notify('PostMoveItem', $data);
\r
450 * @param integer $itemid
\r
453 static public function delete($itemid)
\r
455 global $manager, $member;
\r
457 $itemid = (integer) $itemid;
\r
459 // check permission
\r
460 if ( !$member->canAlterItem($itemid) )
\r
465 $manager->notify('PreDeleteItem', array('itemid' => $itemid));
\r
468 $query = "DELETE FROM %s WHERE inumber=%d;";
\r
469 $query = sprintf($query, sql_table('item'), $itemid);
\r
470 DB::execute($query);
\r
472 // delete the comments associated with the item
\r
473 $query = "DELETE FROM %s WHERE citem=%d;";
\r
474 $query = sprintf($query, sql_table('comment'), $itemid);
\r
475 DB::execute($query);
\r
477 // delete all associated plugin options
\r
478 NucleusPlugin::delete_option_values('item', $itemid);
\r
480 $manager->notify('PostDeleteItem', array('itemid' => $itemid));
\r
487 * Returns true if there is an item with the given ID
\r
490 * @param integer $itemid
\r
491 * @param boolean $future
\r
492 * @param boolean $draft
\r
493 * @return boolean exists or not
\r
495 static public function exists($itemid, $future, $draft)
\r
499 $itemid = (integer) $itemid;
\r
501 $query = 'SELECT * FROM %s WHERE inumber=%d';
\r
502 $query = sprintf($query, sql_table('item'), $itemid);
\r
506 $blogid = getBlogIDFromItemID($itemid);
\r
511 $blog =& $manager->getBlog($blogid);
\r
512 $query .= ' AND itime<=' . DB::formatDateTime($blog->getCorrectTime());
\r
517 $query .= ' AND idraft=0';
\r
520 $result = DB::getResult($query);
\r
521 return ( $result->rowCount() != 0 );
\r
525 * Item::createDraftFromRequest()
\r
526 * Tries to create an draft from the data
\r
527 * in the current request (comes from bookmarklet or admin area)
\r
528 * Used by xmlHTTPRequest AutoDraft
\r
530 * Returns an array with status info:
\r
531 * status = 'added', 'error', 'newcategory'
\r
535 * @return array (status = added/error/newcategory, message)
\r
537 static public function createDraftFromRequest()
\r
539 global $member, $manager;
\r
542 * TODO: these values from user agent should be validated but not implemented yet
\r
544 $i_author = $member->getID();
\r
545 $i_body = postVar('body');
\r
546 $i_title = postVar('title');
\r
547 $i_more = postVar('more');
\r
548 $i_closed = intPostVar('closed');
\r
549 $i_catid = postVar('catid');
\r
551 $type = postVar('type');
\r
552 $i_draftid = intPostVar('draftid');
\r
554 if ( $type == 'edit' )
\r
556 $itemid = intPostVar('itemid');
\r
557 $i_blogid = getBlogIDFromItemID($itemid);
\r
561 $i_blogid = intPostVar('blogid');
\r
564 if ( !$member->canAddItem($i_catid) )
\r
566 return array('status' => 'error', 'message' => _ERROR_DISALLOWED);
\r
569 if ( !trim($i_body) )
\r
571 return array('status' => 'error', 'message' => _ERROR_NOEMPTYITEMS);
\r
574 // create new category if needed
\r
575 if ( i18n::strpos($i_catid,'newcat') === 0 )
\r
577 // Set in default category
\r
578 $blog =& $manager->getBlog($i_blogid);
\r
579 $i_catid = $blog->getDefaultCategory();
\r
583 // force blogid (must be same as category id)
\r
584 $i_blogid = getBlogIDFromCatID($i_catid);
\r
585 $blog =& $manager->getBlog($i_blogid);
\r
590 if ( $i_draftid > 0 )
\r
592 self::update($i_draftid, $i_catid, $i_title, $i_body, $i_more, $i_closed, 1, 0, 0);
\r
593 $itemid = $i_draftid;
\r
597 $itemid = $blog->additem($i_catid, $i_title, $i_body, $i_more, $i_blogid, $i_author, $posttime, $i_closed, $i_draft);
\r
600 return array('status' => 'added', 'draftid' => $itemid);
\r
607 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
608 * Copyright (C) 2002-2009 The Nucleus Group
610 * This program is free software; you can redistribute it and/or
611 * modify it under the terms of the GNU General Public License
612 * as published by the Free Software Foundation; either version 2
613 * of the License, or (at your option) any later version.
614 * (see nucleus/documentation/index.html#license for more info)
617 * @license http://nucleuscms.org/license.txt GNU General Public License
618 * @copyright Copyright (C) 2002-2009 The Nucleus Group
619 * @version $Id: ITEM.php 1877 2012-06-17 07:40:11Z sakamocchi $
623 * A class representing an item
630 * actiontype list for handling items
634 static private $actiontypes = array(
635 'addnow', 'adddraft', 'addfuture', 'edit',
636 'changedate', 'backtodrafts', 'delete'
647 * Item::__construct()
648 * Creates a new ITEM object
651 * @param integer $item_id id for item
654 public function __construct($item_id)
656 $this->itemid = $item_id;
662 * Returns one item with the specific itemid
665 * @param int $item_id
666 * @param bool $allow_draft
667 * @param bool $allow_future
670 static public function getitem($item_id, $allow_draft, $allow_future)
674 $item_id = (integer) $item_id;
677 'i.idraft AS draft, ' .
678 'i.inumber AS itemid, ' .
679 'i.iclosed AS closed, ' .
680 'i.ititle AS title, ' .
681 'i.ibody AS body, ' .
682 'm.mname AS author, ' .
683 'i.iauthor AS authorid, ' .
685 'i.imore AS more, ' .
686 'i.ikarmapos AS karmapos, ' .
687 'i.ikarmaneg AS karmaneg, ' .
688 'i.icat AS catid, ' .
689 'i.iblog AS blogid ' .
690 'FROM %s AS i, %s AS m, %s AS b ' .
691 'WHERE i.inumber = %d ' .
692 'AND i.iauthor = m.mnumber ' .
693 'AND i.iblog = b.bnumber ';
695 $query = sprintf($query, sql_table('item'), sql_table('member'), sql_table('blog'), $item_id);
699 $query .= "AND i.idraft = 0 ";
702 if ( !$allow_future )
704 $blog =& $manager->getBlog(getBlogIDFromItemID($item_id));
705 $query .= 'AND i.itime <= ' . DB::formatDateTime($blog->getCorrectTime());
708 $query .= ' LIMIT 1';
709 $result = DB::getResult($query);
711 if ( $result->rowCount() != 1 )
716 $aItemInfo = $result->fetch(PDO::FETCH_ASSOC);
717 $aItemInfo['timestamp'] = strtotime($aItemInfo['itime']);
722 * Item::createFromRequest()
723 * Tries to create an item from the data in the current request (comes from
724 * bookmarklet or admin area
728 * @return array (status = added/error/newcategory, message)
731 static public function createFromRequest()
733 global $member, $manager;
736 * TODO: these values from user agent should be validated but not implemented yet
738 $i_author = $member->getID();
739 $i_body = postVar('body');
740 $i_title = postVar('title');
741 $i_more = postVar('more');
742 $i_actiontype = postVar('actiontype');
743 $i_closed = intPostVar('closed');
744 $i_hour = intPostVar('hour');
745 $i_minutes = intPostVar('minutes');
746 $i_month = intPostVar('month');
747 $i_day = intPostVar('day');
748 $i_year = intPostVar('year');
749 $i_catid = postVar('catid');
750 $i_draftid = intPostVar('draftid');
752 if ( !$member->canAddItem($i_catid) )
754 return array('status' => 'error', 'message' => _ERROR_DISALLOWED);
757 if ( !in_array($i_actiontype, self::$actiontypes) )
759 $i_actiontype = 'addnow';
762 $i_draft = (integer) ( $i_actiontype == 'adddraft' );
764 if ( !trim($i_body) )
766 return array('status' => 'error', 'message' => _ERROR_NOEMPTYITEMS);
769 // create new category if needed
770 if ( i18n::strpos($i_catid, 'newcat') === 0 )
773 list($i_blogid) = sscanf($i_catid, "newcat-%d");
776 $blog =& $manager->getBlog($i_blogid);
777 $i_catid = $blog->createNewCategory();
779 // show error when sth goes wrong
782 return array('status' => 'error','message' => 'Could not create new category');
787 // force blogid (must be same as category id)
788 $i_blogid = getBlogIDFromCatID($i_catid);
789 $blog =& $manager->getBlog($i_blogid);
792 if ( $i_actiontype == 'addfuture' )
794 $posttime = mktime($i_hour, $i_minutes, 0, $i_month, $i_day, $i_year);
796 // make sure the date is in the future, unless we allow past dates
797 if ( (!$blog->allowPastPosting()) && ($posttime < $blog->getCorrectTime()) )
799 $posttime = $blog->getCorrectTime();
806 $posttime = $blog->getCorrectTime();
814 if ( $posttime > $blog->getCorrectTime() )
817 $blog->setFuturePost();
824 $itemid = $blog->additem($i_catid, $i_title, $i_body, $i_more, $i_blogid, $i_author, $posttime, $i_closed, $i_draft, $posted);
826 //Setting the itemOptions
827 $aOptions = requestArray('plugoption');
828 NucleusPlugin::apply_plugin_options($aOptions, $itemid);
836 'closed' => $i_closed,
841 $manager->notify('PostPluginOptionsUpdate', $data);
843 if ( $i_draftid > 0 )
845 // delete permission is checked inside Item::delete()
846 self::delete($i_draftid);
850 if ( $i_catid != intRequestVar('catid') )
852 return array('status' => 'newcategory', 'itemid' => $itemid, 'catid' => $i_catid);
855 return array('status' => 'added', 'itemid' => $itemid);
863 * @param integer $itemid item id
864 * @param integer $catid category id
865 * @param string $title title
866 * @param string $body body text
867 * @param string $more more text
868 * @param boolean $closed closed or not
869 * @param boolean $wasdraft previously draft or not
870 * @param boolean $publish published or not
871 * @param timestamp $timestamp timestamp
874 static public function update($itemid, $catid, $title, $body, $more, $closed, $wasdraft, $publish, $timestamp = 0)
878 $itemid = (integer) $itemid;
879 $closed = (boolean) $closed;
881 // get destination blogid
882 $new_blogid = getBlogIDFromCatID($catid);
883 $old_blogid = getBlogIDFromItemID($itemid);
885 // move will be done on end of method
887 if ( $new_blogid != $old_blogid )
892 $blog =& $manager->getBlog($new_blogid);
894 // begin if: convert line breaks to <br/>
895 if ( $blog->convertBreaks() )
897 $body = addBreaks($body);
898 $more = addBreaks($more);
908 'closed' => &$closed,
911 $manager->notify('PreUpdateItem', $data);
913 // update item itself
914 $query = 'UPDATE ' . sql_table('item')
916 . ' ibody = ' . DB::quoteValue($body) . ','
917 . ' ititle = ' . DB::quoteValue($title) . ','
918 . ' imore = ' . DB::quoteValue($more) . ','
919 . ' iclosed = ' . intval($closed) . ','
920 . ' icat = ' . intval($catid);
922 // if we received an updated timestamp that is in the past, but past posting is not allowed,
923 // reject that date change (timestamp = 0 will make sure the current date is kept)
924 if ( (!$blog->allowPastPosting()) && ($timestamp < $blog->getCorrectTime()) )
929 // begin if: post is in the future
930 if ( $timestamp > $blog->getCorrectTime(time()) )
933 $query .= ', iposted = 0';
938 $query .= ', iposted = 1';
941 if ( $wasdraft && $publish )
943 // set timestamp to current date only if it's not a future item
944 // draft items have timestamp == 0
945 // don't allow timestamps in the past (unless otherwise defined in blogsettings)
946 $query .= ', idraft = 0';
948 if ( $timestamp == 0 )
950 $timestamp = $blog->getCorrectTime();
953 // send new item notification
954 if ( !$isFuture && $blog->getNotifyAddress() && $blog->notifyOnNewItem() )
956 $blog->sendNewItemNotification($itemid, $title, $body);
960 // save back to drafts
961 if ( !$wasdraft && !$publish )
963 $query .= ', idraft = 1';
964 // set timestamp back to zero for a draft
965 $query .= ', itime = ' . DB::formatDateTime($timestamp);
968 // update timestamp when needed
969 if ( $timestamp != 0 )
971 $query .= ', itime = ' . DB::formatDateTime($timestamp);
974 // make sure the correct item is updated
975 $query .= ' WHERE inumber = ' . $itemid;
980 $data = array('itemid' => $itemid);
981 $manager->notify('PostUpdateItem', $data);
983 // when needed, move item and comments to new blog
986 self::move($itemid, $catid);
989 //update the itemOptions
990 $aOptions = requestArray('plugoption');
991 NucleusPlugin::apply_plugin_options($aOptions);
1003 $manager->notify('PostPluginOptionsUpdate', $data);
1009 * Move an item to another blog (no checks)
1012 * @param integer $itemid
1013 * @param integer $new_catid
1016 static public function move($itemid, $new_catid)
1020 $itemid = (integer) $itemid;
1021 $new_catid = (integer) $new_catid;
1022 $new_blogid = getBlogIDFromCatID($new_catid);
1025 'itemid' => $itemid,
1026 'destblogid' => $new_blogid,
1027 'destcatid' => $new_catid
1029 $manager->notify('PreMoveItem', $data);
1031 // update item table
1032 $query = "UPDATE %s SET iblog=%d, icat=%d WHERE inumber=%d";
1033 $query = sprintf($query, sql_table('item'), $new_blogid, $new_catid, $itemid);
1034 DB::execute($query);
1037 $query = "UPDATE %s SET cblog=%d WHERE citem=%d";
1038 $query = sprintf($query, sql_table('comment'), $new_blogid, $itemid);
1039 DB::execute($query);
1042 'itemid' => $itemid,
1043 'destblogid' => $new_blogid,
1044 'destcatid' => $new_catid
1046 $manager->notify('PostMoveItem', $data);
1054 * @param integer $itemid
1057 static public function delete($itemid)
1059 global $manager, $member;
1061 $itemid = (integer) $itemid;
1064 if ( !$member->canAlterItem($itemid) )
1069 $data = array('itemid' => $itemid);
1070 $manager->notify('PreDeleteItem', $data);
1073 $query = "DELETE FROM %s WHERE inumber=%d;";
1074 $query = sprintf($query, sql_table('item'), $itemid);
1075 DB::execute($query);
1077 // delete the comments associated with the item
1078 $query = "DELETE FROM %s WHERE citem=%d;";
1079 $query = sprintf($query, sql_table('comment'), $itemid);
1080 DB::execute($query);
1082 // delete all associated plugin options
1083 NucleusPlugin::delete_option_values('item', $itemid);
1085 $manager->notify('PostDeleteItem', $data);
1092 * Returns true if there is an item with the given ID
1095 * @param integer $itemid
1096 * @param boolean $future
1097 * @param boolean $draft
1098 * @return boolean exists or not
1100 static public function exists($itemid, $future, $draft)
1104 $itemid = (integer) $itemid;
1106 $query = 'SELECT * FROM %s WHERE inumber=%d';
1107 $query = sprintf($query, sql_table('item'), $itemid);
1111 $blogid = getBlogIDFromItemID($itemid);
1116 $blog =& $manager->getBlog($blogid);
1117 $query .= ' AND itime<=' . DB::formatDateTime($blog->getCorrectTime());
1122 $query .= ' AND idraft=0';
1125 $result = DB::getResult($query);
1126 return ( $result->rowCount() != 0 );
1130 * Item::createDraftFromRequest()
1131 * Tries to create an draft from the data
1132 * in the current request (comes from bookmarklet or admin area)
1133 * Used by xmlHTTPRequest AutoDraft
1135 * Returns an array with status info:
1136 * status = 'added', 'error', 'newcategory'
1140 * @return array (status = added/error/newcategory, message)
1142 static public function createDraftFromRequest()
1144 global $member, $manager;
1147 * TODO: these values from user agent should be validated but not implemented yet
1149 $i_author = $member->getID();
1150 $i_body = postVar('body');
1151 $i_title = postVar('title');
1152 $i_more = postVar('more');
1153 $i_closed = intPostVar('closed');
1154 $i_catid = postVar('catid');
1156 $type = postVar('type');
1157 $i_draftid = intPostVar('draftid');
1159 if ( $type == 'edit' )
1161 $itemid = intPostVar('itemid');
1162 $i_blogid = getBlogIDFromItemID($itemid);
1166 $i_blogid = intPostVar('blogid');
1169 if ( !$member->canAddItem($i_catid) )
1171 return array('status' => 'error', 'message' => _ERROR_DISALLOWED);
1174 if ( !trim($i_body) )
1176 return array('status' => 'error', 'message' => _ERROR_NOEMPTYITEMS);
1179 // create new category if needed
1180 if ( i18n::strpos($i_catid,'newcat') === 0 )
1182 // Set in default category
1183 $blog =& $manager->getBlog($i_blogid);
1184 $i_catid = $blog->getDefaultCategory();
1188 // force blogid (must be same as category id)
1189 $i_blogid = getBlogIDFromCatID($i_catid);
1190 $blog =& $manager->getBlog($i_blogid);
1195 if ( $i_draftid > 0 )
1197 self::update($i_draftid, $i_catid, $i_title, $i_body, $i_more, $i_closed, 1, 0, 0);
1198 $itemid = $i_draftid;
1202 $itemid = $blog->additem($i_catid, $i_title, $i_body, $i_more, $i_blogid, $i_author, $posttime, $i_closed, $i_draft);
1205 return array('status' => 'added', 'draftid' => $itemid);
1208 >>>>>>> skinnable-master