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 ]


Deprecated: Function gmstrftime() is deprecated in /home/mikespub/www/list.php on line 509
Date Directory [filter] File(s) [view] Author [filter]
30 Jul 2002 18:31:51postnuke_modules/articlespnuser.php,1.34,1.35 pnuserapi.php,1.23,1.24Mike
 add support for Archive (part 1)

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

Modified Files:
	pnuser.php pnuserapi.php 
Log Message:
add support for Archive (part 1)


Index: pnuser.php
===================================================================
RCS file: /home/cvsroot/postnuke_modules/articles/pnuser.php,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** pnuser.php	29 Jul 2002 17:20:50 -0000	1.34
--- pnuser.php	30 Jul 2002 18:31:48 -0000	1.35
***************
*** 30,33 ****
--- 30,35 ----
  {
      //return articles_user_view();
+ // TODO: make this configurable someday ?
+     // redirect to default view with news articles
      pnRedirect(pnModURL('articles', 'user', 'view', array('ptid' => 1)));
      return;
***************
*** 296,299 ****
--- 298,310 ----
                   pnML('View Article Map'));
  
+     $output->SetInputMode(_PNH_VERBATIMINPUT);
+     $output->Text('   ');
+     $output->SetInputMode(_PNH_PARSEINPUT);
+     $output->URL(pnModURL('articles',
+                           'user',
+                           'archive',
+                           array()),
+                  pnML('View Archive'));
+ 
      return $output->GetOutput();
  }
***************
*** 408,412 ****
      // Navigation links
      $data['publinks'] = pnModAPIFunc('articles','user','getpublinks');
!     $data['maplink'] = pnModURL('articles','user','viewmap',array());
  
      // Hooks
--- 419,424 ----
      // Navigation links
      $data['publinks'] = pnModAPIFunc('articles','user','getpublinks');
!     $data['maplink'] = pnModURL('articles','user','viewmap');
!     $data['archivelink'] = pnModURL('articles','user','archive');
  
      // Hooks
***************
*** 429,432 ****
--- 441,607 ----
  
  /**
+  * show monthly archive (Archives-like)
+  */
+ function articles_user_archive($args)
+ {
+     // Get parameters from user
+     list($ptid,
+          $month)= pnVarCleanFromInput('ptid',
+                                       'month');
+ 
+     // Override if needed from argument array
+     extract($args);
+ 
+     // Defaults
+     if (!isset($ptid)) {
+         $ptid = 1;
+     }
+     if (!isset($month)) {
+         $month = '';
+     }
+ 
+ // QUESTION: work with user-dependent time settings or not someday ?
+     // Set the start and end date for that month
+     if (!empty($month) && preg_match('/^(\d{4})-(\d+)$/',$month,$matches)) {
+             $startdate = gmmktime(0,0,0,$matches[2],1,$matches[1],0);
+             // PHP allows month > 12 :-)
+             $enddate = gmmktime(0,0,0,$matches[2]+1,1,$matches[1],0);
+     } else {
+         $startdate = '';
+         $enddate = '';
+     }
+ 
+     // Load API
+     if (!pnModAPILoad('articles', 'user')) {
+         return _LOADFAILED;
+     }
+ 
+     // Get monthly statistics
+     $monthcount = pnModAPIFunc('articles','user','getmonthcount');
+     if(!isset($monthcount)) {
+         $monthcount = array();
+     }
+     krsort($monthcount);
+     reset($monthcount);
+     $months = array();
+     foreach ($monthcount as $thismonth => $count) {
+         if ($thismonth == $month) {
+             $mlink = '';
+         } else {
+             $mlink = pnModURL('articles','user','archive',
+                               array('month' => $thismonth));
+         }
+         $months[] = array('month' => $thismonth,
+                           'mcount' => $count,
+                           'mlink' => $mlink);
+     }
+ 
+     // get the links and counts for all publication types
+     $publinks = pnModAPIFunc('articles','user','getpublinks',
+                              array('all' => 1));
+ 
+     // Load API
+     if (!pnModAPILoad('categories', 'user')) {
+         return _LOADFAILED;
+     }
+ 
+     // Get the list of root categories for this publication type
+     if (!empty($ptid)) {
+         $string = pnModGetVar('articles','cids.' . $ptid);
+     }
+     if (!isset($string)) {
+         $string = pnModGetVar('articles','cids');
+     }
+     $catlist = array();
+     $catinfo = array();
+     if (!empty($string)) {
+         $rootcats = split(';',$string);
+ // TODO: do this in categories API !
+         foreach ($rootcats as $cid) {
+             if (empty($cid)) {
+                 continue;
+             }
+             // save the name and root category for each child
+             $cats = pnModAPIFunc('categories',
+                                        'user',
+                                        'getcat',
+                                        array('cid' => $cid,
+                                              'return_itself' => true,
+                                              'getchildren' => true));
+             foreach ($cats as $info) {
+                 $item = array();
+                 $item['name'] = $info['name'];
+                 $item['root'] = $cid;
+                 $catinfo[$info['cid']] = $item;
+             }
+             $catlist[] = array('cid' => $cid,'name' => $catinfo[$cid]['name']);
+         }
+     }
+ 
+     // Get articles
+     if ($startdate && $enddate) {
+     $articles = pnModAPIFunc('articles',
+                              'user',
+                              'getall',
+                              array('ptid' => (isset($ptid) ? $ptid : null),
+                                    'startdate' => $startdate,
+                                    'enddate' => $enddate,
+                                    'fields' => array('aid','title','pubdate','pubtypeid','cids')
+                                   )
+                             );
+         if (!is_array($articles)) {
+             return _ARTICLESITEMFAILED;
+         }
+     } else {
+         $articles = array();
+     }
+ 
+     foreach ($articles as $key => $article) {
+         $articles[$key]['link'] = pnModURL('articles','user','display',
+                                array('aid' => $articles[$key]['aid'],
+                                      'ptid' => $articles[$key]['pubtypeid']));
+         $articles[$key]['date'] = strftime("%Y-%m-%d %H:%M:%S", 
+                                            $articles[$key]['pubdate']);
+         $list = array();
+         // get all the categories for that article and put them under the
+         // right root category
+         if (!isset($articles[$key]['cids'])) {
+             $articles[$key]['cids'] = array();
+         }
+         foreach ($articles[$key]['cids'] as $cid) {
+             if (!isset($list[$catinfo[$cid]['root']])) {
+                 $list[$catinfo[$cid]['root']] = array();
+             }
+             array_push($list[$catinfo[$cid]['root']],$cid);
+         }
+         // fill in the column corresponding to each root category
+         $articles[$key]['cats'] = array();
+         foreach ($catlist as $cat) {
+             if (isset($list[$cat['cid']])) {
+                 $descr = '';
+ // TODO: add links to category someday ?
+                 foreach ($list[$cat['cid']] as $cid) {
+                     if (!empty($descr)) {
+                         $descr .= '<br>';
+                     }
+                     $descr .= $catinfo[$cid]['name'];
+                 }
+                 $articles[$key]['cats'][] = array('list' => $descr);
+             } else {
+                 $articles[$key]['cats'][] = array('list' => '-');
+             }
+         }
+     }
+ 
+     // return template out
+     return array('months' => $months,
+                  'articles' => $articles,
+                  'catlist' => $catlist,
+                  'publinks' => pnModAPIFunc('articles','user','getpublinks',
+                                             array('ptid' => $ptid)),
+                  'maplink' => pnModURL('articles','user','viewmap'));
+ }
+ 
+ /**
   * view article map
   */
***************
*** 448,452 ****
  
      // get the links and counts for all publication types
!     $publinks = pnModAPIFunc('articles','user','getpublinks',array('all' => 1));
  
      // build the list of root categories for all publication types
--- 623,628 ----
  
      // get the links and counts for all publication types
!     $publinks = pnModAPIFunc('articles','user','getpublinks',
!                              array('all' => 1));
  
      // build the list of root categories for all publication types
***************
*** 511,515 ****
      }
  
!     return array('publinks' => $publinks);
  }
  
--- 687,694 ----
      }
  
!     $archivelink = pnModURL('articles','user','archive');
! 
!     return array('publinks' => $publinks,
!                  'archivelink' => $archivelink);
  }
  
***************
*** 536,540 ****
                   $out = $output->Text($pubtype['descr']);
               } else {
!                  $out = $output->URL(pnModURL('articles','user','view',array('ptid' => $id)), $pubtype['descr']);
               }
               $out .= ' (' . $pubcount[$id] . ')';
--- 715,721 ----
                   $out = $output->Text($pubtype['descr']);
               } else {
!                  $out = $output->URL(pnModURL('articles','user','view',
!                                               array('ptid' => $id)),
!                                      $pubtype['descr']);
               }
               $out .= ' (' . $pubcount[$id] . ')';

Index: pnuserapi.php
===================================================================
RCS file: /home/cvsroot/postnuke_modules/articles/pnuserapi.php,v
retrieving revision 1.23
retrieving revision 1.24
diff -C2 -d -r1.23 -r1.24
*** pnuserapi.php	29 Jul 2002 12:13:47 -0000	1.23
--- pnuserapi.php	30 Jul 2002 18:31:48 -0000	1.24
***************
*** 46,53 ****
  /**
   * get overview of all articles
!  * @param $args['startnum'] starting article number
   * @param $args['numitems'] number of articles to get
   * @param $args['ptid'] publication type ID (for news, sections, reviews, ...)
   * @param $args['cids'] array of category IDs for which to get articles (for all don�t set it)
   * @returns array
   * @return array of articles, or false on failure
--- 46,59 ----
  /**
   * get overview of all articles
!  * Note : the following parameters are all optional
!  *
   * @param $args['numitems'] number of articles to get
+  * @param $args['startnum'] starting article number
   * @param $args['ptid'] publication type ID (for news, sections, reviews, ...)
   * @param $args['cids'] array of category IDs for which to get articles (for all don�t set it)
+  * @param $args['startdate'] articles published at startdate or later (unix timestamp format)
+  * @param $args['enddate'] articles published before enddate (unix timestamp format)
+  * @param $args['fields'] array with the fields to return per article - default is
+  *                        'aid','title','summary','author','pubdate','pubtypeid','body','cids'
   * @returns array
   * @return array of articles, or false on failure
***************
*** 62,66 ****
--- 68,77 ----
          $startnum = 1;
      }
+     if (!isset($fields)) {
+         $fields = array('aid','title','summary','author','pubdate','pubtypeid',
+                         'body','cids');
+     }
  
+ /*
      // Required argument
      if (!isset($numitems)) {
***************
*** 70,73 ****
--- 81,85 ----
          return;
      }
+ */
  
      $articles = array();
***************
*** 78,81 ****
--- 90,99 ----
      }
  
+     // Required fields
+     $required = array();
+     foreach ($fields as $field) {
+         $required[$field] = 1;
+     }
+ 
      // Database information
      // More abstraction?
***************
*** 86,102 ****
      $articlescolumn = &$pntable['articles_column'];
  
- // TODO: figure out some way to let the category module handle its part
- //       of the query construction, e.g. by providing part of the SQL stmt.
- //       or something...
- 
-     $categories_linkage = pnConfigGetVar('prefix') . '_categories_linkage';
-     $categorieslinkagetable = &$categories_linkage;
-     $categorieslinkagecolumn = array
-     (
-         'cid' => $categories_linkage . '.pn_cid',
-         'iid' => $categories_linkage . '.pn_iid',
-         'modid' => $categories_linkage . '.pn_modid'
-     );
- 
      $userstable = $pntable['users'];
      $prefix = $userstable;
--- 104,107 ----
***************
*** 113,129 ****
  
      $conditions = Array();
-     if (is_array($cids))
-     {
-         // OR (the articles shown are those that are linked to any of the cids)
-         $conditions[] = $categorieslinkagecolumn['cid']
-                       .' IN ('
-                       .join (',', $cids)
-                       .')';
-         $conditions[] = $categorieslinkagecolumn['modid'].' = '.pnModGetIDFromName('articles');
-     }
      $conditions[] = $articlescolumn['authorid'].' = '.$userscolumn['uid'];
      if (!empty($ptid)) {
          $conditions[] = $articlescolumn['pubtypeid'].' = '.$ptid;
      }
          
      // Get articles
--- 118,131 ----
  
      $conditions = Array();
      $conditions[] = $articlescolumn['authorid'].' = '.$userscolumn['uid'];
      if (!empty($ptid)) {
          $conditions[] = $articlescolumn['pubtypeid'].' = '.$ptid;
      }
+     if (!empty($startdate) && !empty($enddate) &&
+         is_numeric($startdate) && is_numeric($enddate) &&
+         $enddate > $startdate) {
+         $conditions[] = $articlescolumn['pubdate'].' >= '.$startdate;
+         $conditions[] = $articlescolumn['pubdate'].' < '.$enddate;
+     }
          
      // Get articles
***************
*** 142,146 ****
      (
          $articlestable,
!         $userstable        
      );
      
--- 144,148 ----
      (
          $articlestable,
!         $userstable
      );
      
***************
*** 150,176 ****
      );
  
-     $join = Array
-     (
-         $categorieslinkagetable
-     );
- 
-     $on = Array
-     (
-         "$categorieslinkagecolumn[iid] = $articlescolumn[aid]"
-     );
-     
      $sql = '';
  
      $sql .= IterateSQL ('SELECT DISTINCT', $columns, ',');
      $sql .= IterateSQL (' FROM', $tables, ',');
!     if (is_array($cids)) {
!         $sql .= IterateSQL (' LEFT JOIN', $join, ',');
!         $sql .= IterateSQL (' ON', $on, ' AND ');
      }
  
      $sql .= IterateSQL (' WHERE', $conditions, ' AND '); 
  
      $sql .= IterateSQL (' ORDER BY', $orderings, ',');
!     $result = $dbconn->SelectLimit($sql, $numitems, $startnum-1);
  
      if ($dbconn->ErrorNo() != 0) {
--- 152,188 ----
      );
  
      $sql = '';
  
+ # TODO: we need FROM (articles LEFT JOIN users ON ...) LEFT JOIN categories ON ... here !
+ 
      $sql .= IterateSQL ('SELECT DISTINCT', $columns, ',');
      $sql .= IterateSQL (' FROM', $tables, ',');
!     if (isset($cids) && is_array($cids)) {
!         // Load API
!         if (!pnModAPILoad('categories', 'user')) {
!             $msg = pnML('Unable to load (#(1))�s module (#(2))�s functions.',
!                         pnML('categories'), pnML('user'));
!             pnExceptionSet(PN_SYSTEM_EXCEPTION, 'UNABLE_TO_LOAD',
!                  new SystemException(__FILE__.'('.__LINE__.'): '.$msg));
!             return;
!         }
!         $catdef = pnModAPIFunc('categories','user','leftjoin',array('cids' => $cids));
!         $sql .= ' LEFT JOIN ' . $catdef['table'];
!         $sql .= ' ON ' . $catdef['field'] . ' = ' . $articlescolumn['aid'];
      }
  
      $sql .= IterateSQL (' WHERE', $conditions, ' AND '); 
  
+     if (isset($cids) && is_array($cids)) {
+         $sql .= ' AND ' . $catdef['where'] . ' = ' . pnModGetIDFromName('articles');
+     }
+ 
      $sql .= IterateSQL (' ORDER BY', $orderings, ',');
! 
!     if (isset($numitems) && is_numeric($numitems)) {
!         $result = $dbconn->SelectLimit($sql, $numitems, $startnum-1);
!     } else {
!         $result = $dbconn->Execute($sql);
!     }
  
      if ($dbconn->ErrorNo() != 0) {
***************
*** 198,227 ****
      $result->Close();
      
!     // Get all the categories at once
!     $aids = array();
!     foreach ($articles as $article) {
!         $aids[] = $article['aid'];
!     }
  
!     // Load API
!     if (!pnModAPILoad('categories', 'user')) {
!         $msg = pnML('Unable to load (#(1))�s module (#(2))�s functions.', pnML('categories'), pnML('user'));
!         pnExceptionSet(PN_SYSTEM_EXCEPTION, 'UNABLE_TO_LOAD',
!             new SystemException(__FILE__.'('.__LINE__.'): '.$msg));
!             return;
!     }
!     
!     // Get the links for the Array of iids we have
!     $cids = pnModAPIFunc('categories',
!                          'user',
!                          'getlinks',
!                          array('iids' => $aids,
!                                'reverse' => 1,
!                                'modid' => pnModGetIDFromName('articles')));
  
!     // Inserting the corresponding Category ID in the Article Description
!     foreach ($articles as $key => $article) {
!         if (isset($cids[$article['aid']])) {
!             $articles[$key]['cids'] = $cids[$article['aid']];
          }
      }
--- 210,241 ----
      $result->Close();
      
!     if ($required['cids']) {
!         // Get all the categories at once
!         $aids = array();
!         foreach ($articles as $article) {
!             $aids[] = $article['aid'];
!         }
  
!         // Load API
!         if (!pnModAPILoad('categories', 'user')) {
!             $msg = pnML('Unable to load (#(1))�s module (#(2))�s functions.', pnML('categories'), pnML('user'));
!             pnExceptionSet(PN_SYSTEM_EXCEPTION, 'UNABLE_TO_LOAD',
!                 new SystemException(__FILE__.'('.__LINE__.'): '.$msg));
!                 return;
!         }
  
!         // Get the links for the Array of iids we have
!         $cids = pnModAPIFunc('categories',
!                              'user',
!                              'getlinks',
!                              array('iids' => $aids,
!                                    'reverse' => 1,
!                                    'modid' => pnModGetIDFromName('articles')));
! 
!         // Inserting the corresponding Category ID in the Article Description
!         foreach ($articles as $key => $article) {
!             if (isset($cids[$article['aid']])) {
!                 $articles[$key]['cids'] = $cids[$article['aid']];
!             }
          }
      }
***************
*** 470,473 ****
--- 484,523 ----
  
  /**
+  * count the number of items per month
+  * @param $args['cids'] array of cids that we are counting for
+  * @param $args['ptid'] publication type ID we're interested in
+  * @returns array
+  * @return array(month => count), or false on failure
+  */
+ function articles_userapi_getmonthcount($args)
+ {
+     // Get database setup
+     list($dbconn) = pnDBGetConn();
+     $pntable = pnDBGetTables();
+     $articlestable = $pntable['articles'];
+ 
+ // TODO: check how to do this for non-mysql databases !
+     $sql = 'SELECT LEFT(FROM_UNIXTIME(pn_pubdate),7) as mymonth, COUNT(*) FROM ' . $articlestable;
+     if (!empty($args['ptid']) && is_numeric($args['ptid'])) {
+         $sql .= ' WHERE pn_pubtypeid = ' . pnVarPrepForStore($args['ptid']);
+     }
+     $sql .= ' GROUP BY mymonth';
+     $result = $dbconn->Execute($sql);
+ 
+     if ($dbconn->ErrorNo() != 0) {
+         return;
+     }
+ 
+     $months = array();
+     while (!$result->EOF) {
+         list($month, $count) = $result->fields;
+         $months[$month] = $count;
+         $result->MoveNext();
+     }
+ 
+     return $months;
+ }
+ 
+ /**
   * return the path for a short URL to pnModURL for this module
   * @param $args the function and arguments passed to pnModURL
***************
*** 529,532 ****
--- 579,588 ----
          //    }
          //}
+     } elseif ($func == 'archive') {
+         if (isset($month)) {
+             $path = '/' . $module . '/archive/' . $month . '.html';
+         } else {
+             $path = '/' . $module . '/archive/index.html';
+         }
      } elseif ($func == 'viewmap') {
          $path = '/' . $module . '/map.html';
***************
*** 562,573 ****
      } elseif ($params[1] == 'map.html') {
          return array('viewmap', $args);
!     } elseif (preg_match('/^(\d+)\.html$/',$params[1],$matches)) {
          $aid = $matches[1];
          $args['aid'] = $aid;
          return array('display', $args);
!     } elseif (preg_match('/^category(\d+)\.html$/',$params[1],$matches)) {
          $cids[0] = $matches[1];
          $args['cids'] = $cids;
          return array('view', $args);
      } else {
          $pubtypes = pnModAPIFunc('articles','user','getpubtypes');
--- 618,634 ----
      } elseif ($params[1] == 'map.html') {
          return array('viewmap', $args);
!     } elseif (preg_match('/^(\d+)/',$params[1],$matches)) {
          $aid = $matches[1];
          $args['aid'] = $aid;
          return array('display', $args);
!     } elseif (preg_match('/^category(\d+)/',$params[1],$matches)) {
          $cids[0] = $matches[1];
          $args['cids'] = $cids;
          return array('view', $args);
+     } elseif ($params[1] == 'archive') {
+         if (!empty($params[2]) && preg_match('/^(\d{4}-\d+)/',$params[2],$matches)) {
+             $args['month'] = $matches[1];
+         }
+         return array('archive', $args);
      } else {
          $pubtypes = pnModAPIFunc('articles','user','getpubtypes');
***************
*** 575,582 ****
              if ($params[1] == $pubtype['name']) {
                  $args['ptid'] = $id;
!                 if (!empty($params[2]) && preg_match('/^(\d+)\.html$/',$params[2],$matches)) {
!                     $aid = $matches[1];
!                     $args['aid'] = $aid;
!                     return array('display', $args);
                  } else {
                      return array('view', $args);
--- 636,649 ----
              if ($params[1] == $pubtype['name']) {
                  $args['ptid'] = $id;
!                 if (!empty($params[2])) {
!                     if (preg_match('/^(\d+)/',$params[2],$matches)) {
!                         $aid = $matches[1];
!                         $args['aid'] = $aid;
!                         return array('display', $args);
!                     } elseif ($params[2] == 'archive') {
!                         return array('archive', $args);
!                     } else {
!                         return array('view', $args);
!                     }
                  } else {
                      return array('view', $args);


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