Xaraya / Postnuke CVS Notices - Message

Note: this list is kept only as a demonstration for CVSNotice. For the latest CVS notices, see the Xaraya and Postnuke sites

View Statistics - Next Notice - Previous Notice

Directory filter : [ all ] / postnuke_modules / articles [ view in CVS ]

Date Directory [filter] File(s) [view] Author [filter]
10 Aug 2002 13:05:05postnuke_modules/articlespnadminapi.php,1.11,1.12Mike
 get rid of articlescolumn + much more flexible create/update API for Marcel :-)

Update of /home/cvsroot/postnuke_modules/articles
In directory ns7.hostnuke.net:/tmp/cvs-serv31874

Modified Files:
	pnadminapi.php 
Log Message:
get rid of articlescolumn + much more flexible create/update API for Marcel :-)


Index: pnadminapi.php
===================================================================
RCS file: /home/cvsroot/postnuke_modules/articles/pnadminapi.php,v
retrieving revision 1.11
retrieving revision 1.12
diff -C2 -d -r1.11 -r1.12
*** pnadminapi.php	5 Aug 2002 01:46:02 -0000	1.11
--- pnadminapi.php	10 Aug 2002 13:05:02 -0000	1.12
***************
*** 26,38 ****
  /**
   * create a new articles item
!  * @param $args['title'] name of the item
   * @param $args['summary'] summary for this item
!  * @param $args['bodytype'] type of input for this item
   * @param $args['bodytext'] direct input text for this item
   * @param $args['bodyfile'] file input text for this item
-  * @param $args['langauge'] language of the item
   * @param $args['notes'] notes for the item
   * @param $args['status'] status of the item
   * @param $args['ptid'] publication type ID for the item
   * @returns int
   * @return articles item ID on success, false on failure
--- 26,40 ----
  /**
   * create a new articles item
!  * @param $args['title'] name of the item (this is the only mandatory argument)
   * @param $args['summary'] summary for this item
!  * @param $args['bodytype'] type of input for this item ('text' or 'file')
   * @param $args['bodytext'] direct input text for this item
   * @param $args['bodyfile'] file input text for this item
   * @param $args['notes'] notes for the item
   * @param $args['status'] status of the item
   * @param $args['ptid'] publication type ID for the item
+  * @param $args['pubdate'] publication date in unix time format (or default now)
+  * @param $args['authorid'] ID of the author (default is current user)
+  * @param $args['language'] language of the item
   * @returns int
   * @return articles item ID on success, false on failure
***************
*** 43,58 ****
      extract($args);
  
!     // Argument check
!     if ((!isset($title)) ||
!         (!isset($summary)) ||
!         (!isset($ptid)) ||
! //        (!isset($cids)) ||
!         (!isset($bodytype)) ||
!         ((!isset($bodytext)) && (!isset($bodyfile))) ||
!         (!isset($language))
!         ) {
          $msg = pnML('Invalid #(1) for #(2) function #(3)() in module #(4)',
!                     'parameters', 'admin', 'create',
!                     'Articles');
          pnExceptionSet(PN_USER_EXCEPTION, 'BAD_PARAM',
                         new SystemException($msg));
--- 45,52 ----
      extract($args);
  
!     // Argument check (all the rest is optional, and set to defaults below)
!     if (empty($title)) {
          $msg = pnML('Invalid #(1) for #(2) function #(3)() in module #(4)',
!                     'title', 'admin', 'create', 'Articles');
          pnExceptionSet(PN_USER_EXCEPTION, 'BAD_PARAM',
                         new SystemException($msg));
***************
*** 60,63 ****
--- 54,87 ----
      }
  
+ // Note : we use empty() here because we don't care whether it's set to ''
+ //        or if it's not set at all - defaults will apply in either case !
+ 
+     // Default publication type is 1 (whatever that is for your site...)
+     if (empty($ptid) || !is_numeric($ptid)) {
+ // TODO: make this configurable in admin interface, and use pnModGetVar()
+         $ptid = 1;
+         // for security check below
+         $args['ptid'] = 1;
+     }
+ 
+     // Default author ID is the current user, or Anonymous (1) otherwise
+     if (empty($authorid) || !is_numeric($authorid)) {
+         $authorid = pnUserGetVar('uid');
+         if (empty($authorid)) {
+             $authorid = 1;
+         }
+         // for security check below
+         $args['authorid'] = $authorid;
+     }
+ 
+     // Default categories is none
+     if (empty($cids) || !is_array($cids) ||
+         // catch common mistake of using array('') instead of array()
+         (count($cids) > 0 && empty($cids[0])) ) {
+         $cids = array();
+         // for security check below
+         $args['cids'] = $cids;
+     }
+ 
      // Security check
      if (!pnModAPILoad('articles', 'user')) {
***************
*** 77,82 ****
      }
  
      // Get relevant text
!     if ($bodytype == 'file') {
          $body = join('', @file($bodyfile));
      } else {
--- 101,141 ----
      }
  
+     // Default publication date is now
+     if (empty($pubdate) || !is_numeric($pubdate)) {
+         $pubdate = time();
+     }
+ 
+     // Default status is Submitted (0)
+     if (empty($status) || !is_numeric($status)) {
+         $status = 0;
+     }
+ 
+     // TODO: Default language is ... ???
+     if (empty($language)) {
+         $language = '';
+     }
+ 
+     // Default summary is empty
+     if (empty($summary)) {
+         $summary = '';
+     }
+ 
+     // Default notes is empty
+     if (empty($notes)) {
+         $notes = '';
+     }
+ 
+     // Default body type is text (as opposed to file upload)
+     if (empty($bodytype) || !is_string($bodytype)) {
+         $bodytype = 'text';
+     }
+ 
+     // Default body text is empty
+     if (empty($bodytext) || !is_string($bodytext)) {
+         $bodytext = '';
+     }
+ 
      // Get relevant text
!     if ($bodytype == 'file' && !empty($bodyfile)) {
          $body = join('', @file($bodyfile));
      } else {
***************
*** 84,92 ****
      }
  
!     // Get datbase setup
      list($dbconn) = pnDBGetConn();
      $pntable = pnDBGetTables();
      $articlestable = $pntable['articles'];
-     $articlescolumn = &$pntable['articles_column'];
  
      // Get next ID in table
--- 143,150 ----
      }
  
!     // Get database setup
      list($dbconn) = pnDBGetConn();
      $pntable = pnDBGetTables();
      $articlestable = $pntable['articles'];
  
      // Get next ID in table
***************
*** 95,108 ****
      // Add item
      $sql = "INSERT INTO $articlestable (
!               $articlescolumn[aid],
!               $articlescolumn[title],
!               $articlescolumn[summary],
!               $articlescolumn[body],
!               $articlescolumn[authorid],
!               $articlescolumn[pubdate],
!               $articlescolumn[pubtypeid],
!               $articlescolumn[notes],
!               $articlescolumn[status],
!               $articlescolumn[language])
              VALUES (
                $nextId,
--- 153,166 ----
      // Add item
      $sql = "INSERT INTO $articlestable (
!               pn_aid,
!               pn_title,
!               pn_summary,
!               pn_body,
!               pn_authorid,
!               pn_pubdate,
!               pn_pubtypeid,
!               pn_notes,
!               pn_status,
!               pn_language)
              VALUES (
                $nextId,
***************
*** 110,115 ****
                '" . pnvarPrepForStore($summary) . "',
                '" . pnvarPrepForStore($body) . "',
!               '" . pnvarPrepForStore(pnUserGetVar('uid')) . "',
!               " . pnVarPrepForStore(time()) . ",
                '" . pnvarPrepForStore($ptid) . "',
                '" . pnvarPrepForStore($notes) . "',
--- 168,173 ----
                '" . pnvarPrepForStore($summary) . "',
                '" . pnvarPrepForStore($body) . "',
!               '" . pnvarPrepForStore($authorid) . "',
!               '" . pnVarPrepForStore($pubdate) . "',
                '" . pnvarPrepForStore($ptid) . "',
                '" . pnvarPrepForStore($notes) . "',
***************
*** 127,160 ****
  
      // Get aid to return
!     $aid = $dbconn->PO_Insert_ID($articlestable, $articlescolumn['aid']);
  
      // Call creation hooks
      pnModCallHooks('item', 'create', $aid, 'aid');
      
!     if (isset($cids))
      {
!         $res = Array ();
          foreach ($cids as $cid)
          {
!             $res = array_merge ($res, $cid);
          } 
!     
!         $res = array_unique ($res);
!     
!         // Create the category Link
!         if (!pnModAPILoad('categories', 'admin')) {
!             $msg = pnML('Unable to load #(1) #(2) API',
!                        'categories','admin');
!             pnExceptionSet(PN_SYSTEM_EXCEPTION, 'UNABLE_TO_LOAD',
!                            new SystemException($msg));
!             return false;
          }
-         pnModAPIFunc('categories',
-                      'admin',
-                      'linkcat',
-                      Array('cids'  => $res,
-                            'iids'  => Array($aid),
-                            'modid' => pnModGetIDFromName('articles')
-                           ));
      }
  
--- 185,222 ----
  
      // Get aid to return
!     $aid = $dbconn->PO_Insert_ID($articlestable, 'pn_aid');
  
      // Call creation hooks
      pnModCallHooks('item', 'create', $aid, 'aid');
      
!     if (count($cids) > 0)
      {
!         $seencid = array();
          foreach ($cids as $cid)
          {
!             if (empty($cid)) {
!                 continue;
!             }
!             $seencid[$cid] = 1;
          } 
!         if (count($seencid) > 0) {
!             $res = array_keys($seencid);
! 
!             // Create the category Link
!             if (!pnModAPILoad('categories', 'admin')) {
!                 $msg = pnML('Unable to load #(1) #(2) API',
!                            'categories','admin');
!                 pnExceptionSet(PN_SYSTEM_EXCEPTION, 'UNABLE_TO_LOAD',
!                                new SystemException($msg));
!                 return false;
!             }
!             pnModAPIFunc('categories',
!                          'admin',
!                          'linkcat',
!                          Array('cids'  => $res,
!                                'iids'  => Array($aid),
!                                'modid' => pnModGetIDFromName('articles')
!                               ));
          }
      }
  
***************
*** 204,208 ****
      $pntable = pnDBGetTables();
      $articlestable = $pntable['articles'];
-     $articlescolumn = &$pntable['articles_column'];
  
      // Call deletion hooks
--- 266,269 ----
***************
*** 230,234 ****
      // Delete item
      $sql = "DELETE FROM $articlestable
!             WHERE $articlescolumn[aid] = " . pnVarPrepForStore($aid);
      $dbconn->Execute($sql);
  
--- 291,295 ----
      // Delete item
      $sql = "DELETE FROM $articlestable
!             WHERE pn_aid = " . pnVarPrepForStore($aid);
      $dbconn->Execute($sql);
  
***************
*** 246,251 ****
  /**
   * update articles item
!  * @param $args['aid'] ID of the item
!  * @param $args['title'] name of the item
   * @param $args['summary'] summary of the item
   * @param $args['bodytype'] type of input for this item
--- 307,312 ----
  /**
   * update articles item
!  * @param $args['aid'] ID of the item (mandatory argument)
!  * @param $args['title'] name of the item (mandatory argument)
   * @param $args['summary'] summary of the item
   * @param $args['bodytype'] type of input for this item
***************
*** 254,258 ****
   * @param $args['notes'] notes for the item
   * @param $args['status'] status of the item
!  * @param $args['langauge'] language of the item
   */
  function articles_adminapi_update($args)
--- 315,322 ----
   * @param $args['notes'] notes for the item
   * @param $args['status'] status of the item
!  * @param $args['ptid'] publication type ID for the item (*cough*)
!  * @param $args['pubdate'] publication date in unix time format
!  * @param $args['authorid'] ID of the new author (*cough*)
!  * @param $args['language'] language of the item
   */
  function articles_adminapi_update($args)
***************
*** 262,274 ****
  
      // Argument check
!     if ((!isset($aid)) ||
!         (!isset($title)) ||
!         (!isset($summary)) ||
!     //    (!isset($cids)) ||
!         (!isset($bodytype)) ||
!         ((!isset($bodytext)) && (!isset($bodyfile))) ||
!         (!isset($language))) {
          $msg = pnML('Invalid #(1) for #(2) function #(3)() in module #(4)',
!                     'parameters', 'admin', 'update',
                      'Articles');
          pnExceptionSet(PN_USER_EXCEPTION, 'BAD_PARAM',
--- 326,339 ----
  
      // Argument check
!     if (empty($aid) || !is_numeric($aid)) {
          $msg = pnML('Invalid #(1) for #(2) function #(3)() in module #(4)',
!                     'article ID', 'admin', 'update',
!                     'Articles');
!         pnExceptionSet(PN_USER_EXCEPTION, 'BAD_PARAM',
!                        new SystemException($msg));
!         return false;
!     } elseif (empty($title)) {
!         $msg = pnML('Invalid #(1) for #(2) function #(3)() in module #(4)',
!                     'title', 'admin', 'update',
                      'Articles');
          pnExceptionSet(PN_USER_EXCEPTION, 'BAD_PARAM',
***************
*** 276,283 ****
          return false;
      }
!     if (!isset($cids)) {
!         $cids = array();
!     }
!     
      // Security check
      if (!pnModAPILoad('articles', 'user')) {
--- 341,348 ----
          return false;
      }
! 
! // Note : this will take care of checking against the current article values
! //        too if nothing is passed as arguments except aid & title
! 
      // Security check
      if (!pnModAPILoad('articles', 'user')) {
***************
*** 297,313 ****
      }
  
!     // Get relevant text
!     if ($bodytype == 'file') {
!         $body = join('', @file($bodyfile));
!     } else {
!         $body = $bodytext;
!     }
! 
!     // Get datbase setup
      list($dbconn) = pnDBGetConn();
      $pntable = pnDBGetTables();
      $articlestable = $pntable['articles'];
-     $articlescolumn = &$pntable['articles_column'];
      
      // Update the category link
      
--- 362,430 ----
      }
  
!     // Get database setup
      list($dbconn) = pnDBGetConn();
      $pntable = pnDBGetTables();
      $articlestable = $pntable['articles'];
      
+     // Update the item
+     $sql = "UPDATE $articlestable
+             SET pn_title = '" . pnVarPrepForStore($title) . "'";
+ 
+ // Note : we use isset() here because we *do* care whether it's set to ''
+ //        or if it's not set at all
+ 
+     if (isset($summary)) {
+         $sql .= ", pn_summary = '" . pnVarPrepForStore($summary) . "'";
+     }
+ 
+     if (isset($bodytype) && $bodytype == 'file' && !empty($bodyfile)) {
+         $body = join('', @file($bodyfile));
+         $sql .= ", pn_body = '" . pnVarPrepForStore($body) . "'";
+     } elseif (isset($bodytext)) {
+         $body = $bodytext;
+         $sql .= ", pn_body = '" . pnVarPrepForStore($body) . "'";
+     }
+ 
+     if (isset($notes)) {
+         $sql .= ", pn_notes = '" . pnVarPrepForStore($notes) . "'";
+     }
+ 
+     if (isset($status) && is_numeric($status)) {
+         $sql .= ", pn_status = '" . pnVarPrepForStore($status) . "'";
+     }
+ 
+     // not recommended
+     if (isset($ptid) && is_numeric($ptid)) {
+         $sql .= ", pn_pubtypeid = '" . pnVarPrepForStore($ptid) . "'";
+     }
+ 
+     if (isset($pubdate) && is_numeric($pubdate)) {
+         $sql .= ", pn_pubdate = '" . pnVarPrepForStore($pubdate) . "'";
+     }
+ 
+     // not recommended
+     if (isset($authorid) && is_numeric($authorid)) {
+         $sql .= ", pn_authorid = '" . pnVarPrepForStore($authorid) . "'";
+     }
+ 
+     if (isset($language)) {
+         $sql .= ", pn_language = '" . pnVarPrepForStore($language) . "'";
+     }
+ 
+     $sql .= " WHERE pn_aid = " . pnVarPrepForStore($aid);
+     $dbconn->Execute($sql);
+ 
+     if ($dbconn->ErrorNo() != 0) {
+         $msg = pnML('Database error for #(1) function #(2)() in module #(3)',
+                     'admin', 'update', 'Articles');
+         pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR',
+                        new SystemException($msg));
+         return false;
+     }
+ 
+     if (!isset($cids)) {
+         $cids = array();
+     }
+ 
      // Update the category link
      
***************
*** 339,361 ****
                   ));
  
-     // Update the item
-     $sql = "UPDATE $articlestable
-             SET $articlescolumn[title] = '" . pnVarPrepForStore($title) . "',
-                 $articlescolumn[summary] = '" . pnVarPrepForStore($summary) . "',
-                 $articlescolumn[body] = '" . pnVarPrepForStore($body) . "',
-                 $articlescolumn[notes] = '" . pnVarPrepForStore($notes) . "',
-                 $articlescolumn[status] = '" . pnVarPrepForStore($status) . "',
-                 $articlescolumn[language] = '" . pnVarPrepForStore($language) . "'
-             WHERE $articlescolumn[aid] = " . pnVarPrepForStore($aid);
-     $dbconn->Execute($sql);
- 
-     if ($dbconn->ErrorNo() != 0) {
-         $msg = pnML('Database error for #(1) function #(2)() in module #(3)',
-                     'admin', 'update', 'Articles');
-         pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR',
-                        new SystemException($msg));
-         return false;
-     }
- 
      return true;
  }
--- 456,459 ----
***************
*** 534,545 ****
      $pubtypestable = $pntable['publication_types'];
  
! /*
!     // Update the publication type
!     $sql = "UPDATE $pubtypestable
!             SET pn_pubtypename = '" . pnVarPrepForStore($name) . "',
!                 pn_pubtypedescr = '" . pnVarPrepForStore($descr) . "'
!             WHERE pn_pubtypeid = " . pnVarPrepForStore($ptid);
! */
!     // Update the publication type
      $sql = "UPDATE $pubtypestable
              SET pn_pubtypedescr = '" . pnVarPrepForStore($descr) . "',
--- 632,636 ----
      $pubtypestable = $pntable['publication_types'];
  
!     // Update the publication type (don't allow updates on name)
      $sql = "UPDATE $pubtypestable
              SET pn_pubtypedescr = '" . pnVarPrepForStore($descr) . "',


Directory filter : [ all ] / postnuke_modules / articles [ view in CVS ]

View Statistics - Next Notice - Previous Notice


Visit Developer Site - Browse CVS Repository Syndicate via backend.rss
(max. once per hour please)
Powered by CVSNotice 0.1.3