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]
08 Aug 2002 23:03:22postnuke_modules/articlespnadmin.php,1.28,1.29 pnuser.php,1.41,1.42 pnuserapi.php,1.34,1.35Mike
 working with hitcount, category browsing, combined pubtype+cat item count, some layout change

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

Modified Files:
	pnadmin.php pnuser.php pnuserapi.php 
Log Message:
working with hitcount, category browsing, combined pubtype+cat item count, some layout change


Index: pnadmin.php
===================================================================
RCS file: /home/cvsroot/postnuke_modules/articles/pnadmin.php,v
retrieving revision 1.28
retrieving revision 1.29
diff -C2 -d -r1.28 -r1.29
*** pnadmin.php	7 Aug 2002 00:39:35 -0000	1.28
--- pnadmin.php	8 Aug 2002 23:03:20 -0000	1.29
***************
*** 662,665 ****
--- 662,667 ----
      $labels['categories'] = pnML('Categorization');
  
+ // Note : this determines which fields are really shown in the template !!!
+     // Get the labels from the pubtype configuration
      foreach ($pubtypes[$ptid]['config'] as $field => $value) {
          $labels[$field] = $value;

Index: pnuser.php
===================================================================
RCS file: /home/cvsroot/postnuke_modules/articles/pnuser.php,v
retrieving revision 1.41
retrieving revision 1.42
diff -C2 -d -r1.41 -r1.42
*** pnuser.php	5 Aug 2002 23:17:11 -0000	1.41
--- pnuser.php	8 Aug 2002 23:03:20 -0000	1.42
***************
*** 36,39 ****
--- 36,43 ----
  }
  
+ // TODO: generalize, organize, put stuff in userapi and categories, simplify
+ 
+ // TODO: allow *AND*-ing of categories (also in categories API) !!!
+ 
  /**
   * view articles
***************
*** 163,166 ****
--- 167,171 ----
  
  // TODO: make this dependent on publication type too ?
+         $output->Text(pnML('Category') . ' : ');
          $output->Text('[ ');
          $output->URL(pnModURL('articles',
***************
*** 171,174 ****
--- 176,194 ----
          $output->Text(' ] ');
  
+         // get the counts for all categories
+         $pubcatcount = pnModAPIFunc('articles',
+                                     'user',
+                                     'getpubcatcount',
+                                     // frontpage or approved
+                                     array('status' => array(3,2),
+                                           'cids' => $cids,
+                                           'ptid' => $ptid,
+                                           'reverse' => 1));
+         if (!empty($ptid)) {
+             $curptid = $ptid;
+         } else {
+             $curptid = 'total';
+         }
+ 
          // display one (or more) bread-crumb trails of categories
          foreach ($cids as $cid) {
***************
*** 183,186 ****
--- 203,209 ----
                  if ($info['cid'] == $cid) {
                      $output->Text(pnVarPrepForDisplay(pnVarCensor($info['name'])));
+                     if (isset($pubcatcount[$cid][$curptid])) {
+                         $output->Text(' (' . $pubcatcount[$cid][$curptid] . ')');
+                     }
                  } else {
                      $output->URL(pnModURL('articles',
***************
*** 199,209 ****
          //TODO: only show 1-st level children, horizontally ?
          // show child categories (when only 1 category is selected)
!         if (count($cids) == 1 && empty($articles)) {
!             $count = pnModAPIFunc('categories',
!                                   'user',
!                                   'groupcount',
!                                   array('groupby' => 'category',
!                                     'modid' => pnModGetIDFromName('articles')));
! 
              if (!pnModAPILoad('categories', 'visual')) {
                  $msg = pnML('Unable to load #(1) #(2) API',
--- 222,227 ----
          //TODO: only show 1-st level children, horizontally ?
          // show child categories (when only 1 category is selected)
! //        if (count($cids) == 1 && empty($articles)) {
!         if (count($cids) == 1) {
              if (!pnModAPILoad('categories', 'visual')) {
                  $msg = pnML('Unable to load #(1) #(2) API',
***************
*** 213,217 ****
                  return;
              }
!         
          // TODO: make sure permissions are taken into account here !
              $list = pnModAPIFunc('categories',
--- 231,235 ----
                  return;
              }
! 
          // TODO: make sure permissions are taken into account here !
              $list = pnModAPIFunc('categories',
***************
*** 219,222 ****
--- 237,260 ----
                                   'listarray',
                                   array('cid' => $cids[0]));
+             $seencid = array();
+             foreach ($list as $info) {
+                 $seencid[$info['id']] = 1;
+             }
+             $childlist = array_keys($seencid);
+ 
+             // get the counts for all child categories
+             $pubcatcount = pnModAPIFunc('articles',
+                                         'user',
+                                         'getpubcatcount',
+                                         // frontpage or approved
+                                         array('status' => array(3,2),
+                                               'cids' => $childlist,
+                                               'ptid' => $ptid,
+                                               'reverse' => 1));
+             if (!empty($ptid)) {
+                 $curptid = $ptid;
+             } else {
+                 $curptid = 'total';
+             }
              $output->SetInputMode(_PNH_VERBATIMINPUT);
              foreach ($list as $info) {
***************
*** 231,236 ****
                                        array('cids' => array($info['id']))),
                               pnVarPrepForDisplay(pnVarCensor($info['name'])));
!                 if (isset($count[$info['id']])) {
!                     $output->Text(' (' . $count[$info['id']] . ')');
                  }
                  $output->Text($info['aftertags']);
--- 269,274 ----
                                        array('cids' => array($info['id']))),
                               pnVarPrepForDisplay(pnVarCensor($info['name'])));
!                 if (isset($pubcatcount[$info['id']][$curptid])) {
!                     $output->Text(' (' . $pubcatcount[$info['id']][$curptid] . ')');
                  }
                  $output->Text($info['aftertags']);
***************
*** 238,241 ****
--- 276,304 ----
              $output->Linebreak();
          }
+     } elseif (!empty($ptid)) {
+         $output->Text(pnML('Browse in') . ' : ');
+         $string = pnModGetVar('articles','cids.'.$ptid);
+         if (empty($string)) {
+             $string = pnModGetVar('articles','cids');
+         }
+ // TODO: make 1 call to get all
+         $rootcats = split(';',$string);
+         foreach ($rootcats as $cid) {
+             if (empty($cid)) {
+                 continue;
+             }
+             $info = pnModAPIFunc('categories',
+                                  'user',
+                                  'getcatinfo',
+                                  array('cid' => $cid));
+             $output->URL(pnModURL('articles',
+                                   'user',
+                                   'view',
+                                   array('cids' => array($info['cid']),
+                                         'ptid' => $ptid)),
+                          pnVarPrepForDisplay(pnVarCensor($info['name'])));
+             $output->Text('  ');
+         }
+         $output->Linebreak(2);
      }
  
***************
*** 268,279 ****
      foreach ($articles as $article)
      {
-     // TODO: figure out how we *should* be adding an URL in a template :-)
          $article['link'] = pnModURL('articles', 'user', 'display',
                                      array('aid' => $article['aid'],
                                            'ptid' => $article['pubtypeid'],
                                            'cids' => $cids));
-         $article['title'] = '<a class="pn-title" href="' .
-                             $article['link'] .
-                             '">' . $article['title'] . '</a>';
          $bodylen = strlen($article['body']);
          if ($bodylen > 0) {
--- 331,338 ----
***************
*** 290,296 ****
              $article['comments'] = ''; 
          // TODO: to be defined
-             $article['counter'] = ''; 
              $article['topic_icons'] = '';
-         //    $article['notes'] = '';
          }
          $template = $pubtypes[$article['pubtypeid']]['name'];
--- 349,353 ----
***************
*** 468,484 ****
  // TODO: output from hooks comes here ?
      $data['comments'] = ''; 
- // TODO: to be defined
-     $data['counter'] = ''; 
- //    $data['notes'] = '';
  
!     if ($article['pubtypeid'] == 1) {
  // TODO: add pnVarCensor ?
          $data['author'] = pnUserGetVar('name', $article['authorid']);
          $data['date'] = strftime(_DATETIMELONG, $article['pubdate']);
          $data['summary'] = $article['summary'];
      } else {
-         $data['author'] = '';
          $data['summary'] = '';
      }
      $data['title'] = $article['title'];
      $data['body'] = $article['body'];
--- 525,547 ----
  // TODO: output from hooks comes here ?
      $data['comments'] = ''; 
  
! 
  // TODO: add pnVarCensor ?
+     if (!empty($pubtypes[$ptid]['config']['author'])) {
          $data['author'] = pnUserGetVar('name', $article['authorid']);
+     } else {
+         $data['author'] = '';
+     }
+     if (!empty($pubtypes[$ptid]['config']['pubdate'])) {
          $data['date'] = strftime(_DATETIMELONG, $article['pubdate']);
+     } else {
+         $data['date'] = '';
+     }
+     if (!empty($pubtypes[$ptid]['config']['summary'])) {
          $data['summary'] = $article['summary'];
      } else {
          $data['summary'] = '';
      }
+ 
      $data['title'] = $article['title'];
      $data['body'] = $article['body'];
***************
*** 505,508 ****
--- 568,578 ----
      $data['archivelink'] = pnModURL('articles','user','archive');
  
+     // Tell the hitcount hook not to display the hitcount, but to save it
+     // in the variable cache. Note that the hook might not be enabled !
+     if (pnModAvailable('hitcount') && pnModAPILoad('hitcount','user')) {
+         pnVarSetCached('Hooks.hitcount','save',1);
+         $dohits = 1;
+     }
+ 
      // Hooks
      $data['hooks'] = pnModCallHooks('item',
***************
*** 515,518 ****
--- 585,595 ----
                                                     'ptid' => $ptid)));
  
+     // Retrieve the current hitcount from the variable cache
+     if ($dohits && pnVarIsCached('Hooks.hitcount','value')) {
+         $data['counter'] = pnVarGetCached('Hooks.hitcount','value');
+     } else {
+         $data['counter'] = '';
+     }
+ 
      // Save some variables to (temporary) cache for use in blocks etc.
      pnVarSetCached('Blocks.articles','aid',$aid);
***************
*** 770,773 ****
--- 847,858 ----
  
      // get the counts for all categories
+     $pubcatcount = pnModAPIFunc('articles',
+                                 'user',
+                                 'getpubcatcount',
+                                 // frontpage or approved
+                                 array('status' => array(3,2)));
+ 
+ /*
+     // get the counts for all categories
      $catcount = pnModAPIFunc('categories',
                               'user',
***************
*** 775,778 ****
--- 860,864 ----
                               array('groupby' => 'category',
                                     'modid' => pnModGetIDFromName('articles')));
+ */
  
      // create the category tree for each root category
***************
*** 808,818 ****
      for ($i=0;$i<count($publinks);$i++) {
          $publinks[$i]['cats'] = array();
          // for each root category of this publication type
          foreach ($publinks[$i]['rootcats'] as $cid) {
              // update the links in the category tree to include both cid & ptid
              for ($j=0;$j<count($cattree[$cid]);$j++) {
                  $cattree[$cid][$j]['link'] = pnModURL('articles','user','view',
!                              array('ptid' => $publinks[$i]['pubid'],
!                                    'cids' => array($cattree[$cid][$j]['id'])));
              }
              // and add the category tree to the categories to show
--- 894,911 ----
      for ($i=0;$i<count($publinks);$i++) {
          $publinks[$i]['cats'] = array();
+         $ptid = $publinks[$i]['pubid'];
          // for each root category of this publication type
          foreach ($publinks[$i]['rootcats'] as $cid) {
              // update the links in the category tree to include both cid & ptid
              for ($j=0;$j<count($cattree[$cid]);$j++) {
+                 $childcid = $cattree[$cid][$j]['id'];
                  $cattree[$cid][$j]['link'] = pnModURL('articles','user','view',
!                              array('ptid' => $ptid,
!                                    'cids' => array($childcid)));
!                 if (isset($pubcatcount[$ptid][$childcid])) {
!                     $cattree[$cid][$j]['count'] = $pubcatcount[$ptid][$childcid];
!                 } else {
!                     $cattree[$cid][$j]['count'] = '';
!                 }
              }
              // and add the category tree to the categories to show

Index: pnuserapi.php
===================================================================
RCS file: /home/cvsroot/postnuke_modules/articles/pnuserapi.php,v
retrieving revision 1.34
retrieving revision 1.35
diff -C2 -d -r1.34 -r1.35
*** pnuserapi.php	5 Aug 2002 23:17:11 -0000	1.34
--- pnuserapi.php	8 Aug 2002 23:03:20 -0000	1.35
***************
*** 81,86 ****
      // + 'cids' = list of categories an article belongs to
      // + 'author' = user name of authorid
      $columns = array('aid','title','summary','authorid','pubdate','pubtypeid',
!                      'notes','status','body','cids','author');
      if (!isset($fields)) {
          $fields = $columns;
--- 81,87 ----
      // + 'cids' = list of categories an article belongs to
      // + 'author' = user name of authorid
+     // + 'counter' = number of times this article was displayed (hitcount)
      $columns = array('aid','title','summary','authorid','pubdate','pubtypeid',
!                      'notes','status','body','cids','author','counter');
      if (!isset($fields)) {
          $fields = $columns;
***************
*** 148,151 ****
--- 149,167 ----
      }
  
+     if (!empty($required['counter']) && pnModAvailable('hitcount','user')) {
+         // Load API
+         if (!pnModAPILoad('hitcount', 'user')) {
+             $msg = pnML('Unable to load #(1) #(2) API',
+                         'hitcount','user');
+             pnExceptionSet(PN_SYSTEM_EXCEPTION, 'UNABLE_TO_LOAD',
+                            new SystemException($msg));
+             return false;
+         }
+         // Get the LEFT JOIN ... ON ...  and WHERE (!) parts from categories
+         $hitcountdef = pnModAPIFunc('hitcount','user','leftjoin',
+                                     array('modid' =>
+                                             pnModGetIDFromName('articles')));
+     }
+ 
      // Create the SELECT part
      $select = array();
***************
*** 156,159 ****
--- 172,177 ----
          } elseif ($field == 'author') {
              $select[] = $usersdef['name'];
+         } elseif ($field == 'counter') {
+             $select[] = $hitcountdef['hits'];
          } else {
              $select[] = $articlesdef[$field];
***************
*** 170,173 ****
--- 188,201 ----
  
          // add this for SQL compliance when there are multiple JOINs
+         if (!empty($required['counter']) || count($cids) > 0) {
+             $from = '(' . $from . ')';
+         }
+     }
+     if (!empty($required['counter'])) {
+         // Add the LEFT JOIN ... ON ... parts from hitcount
+         $from .= ' LEFT JOIN ' . $hitcountdef['table'];
+         $from .= ' ON ' . $hitcountdef['field'] . ' = ' . $articlesdef['aid'];
+ 
+         // add this for SQL compliance when there are multiple JOINs
          if (count($cids) > 0) {
              $from = '(' . $from . ')';
***************
*** 188,191 ****
--- 216,222 ----
          $where[] = $articlesdef['where'];
      }
+     if (!empty($required['counter']) && !empty($hitcountdef['where'])) {
+         $where[] = $hitcountdef['where'];
+     }
      if (count($cids) > 0) {
          // we rely on leftjoin() to create the necessary categories clauses
***************
*** 448,451 ****
--- 479,566 ----
  
      return $pubcount;
+ }
+ 
+ 
+ /**
+  * get the number of articles per publication type and category
+  *
+  * @param $args['status'] array of requested status(es) for the articles
+  * @param $args['cids'] array of category IDs
+  * @param $args['ptid'] publication type ID
+  * @param $args['reverse'] default is ptid => cid, reverse (1) is cid => ptid
+  * @returns array
+  * @return array( $ptid => array( $cid => $count) ),
+  *         or false on failure
+  */
+ function articles_userapi_getpubcatcount($args)
+ {
+ /*
+     static $pubcatcount = array();
+ 
+     if (count($pubcatcount) > 0) {
+         return $pubcatcount;
+     }
+ */
+     $pubcatcount = array();
+ 
+     // Get database setup
+     list($dbconn) = pnDBGetConn();
+ 
+     // Get the LEFT JOIN ... ON ...  and WHERE parts from articles
+     $articlesdef = pnModAPIFunc('articles','user','leftjoin',$args);
+ 
+     // Load API
+     if (!pnModAPILoad('categories', 'user')) {
+         $msg = pnML('Unable to load #(1) #(2) API',
+                     'categories','user');
+         pnExceptionSet(PN_SYSTEM_EXCEPTION, 'UNABLE_TO_LOAD',
+                        new SystemException($msg));
+         return false;
+     }
+ 
+     $args['modid'] = pnModGetIDFromName('articles');
+     // Get the LEFT JOIN ... ON ...  and WHERE parts from categories
+     $categoriesdef = pnModAPIFunc('categories','user','leftjoin',$args);
+ 
+     // Get count
+     $sql = 'SELECT '. $articlesdef['pubtypeid'] .', '. $categoriesdef['cid']
+            .', COUNT(*)
+             FROM '. $articlesdef['table'] . '
+             LEFT JOIN ' . $categoriesdef['table'] .'
+             ON '. $categoriesdef['field'] . ' = ' . $articlesdef['field'] .'
+             WHERE '. $categoriesdef['where'] .' AND '. $articlesdef['where'] .'
+             GROUP BY '. $articlesdef['pubtypeid'] .', '. $categoriesdef['cid'];
+ 
+     $result = $dbconn->Execute($sql);
+ 
+     if ($dbconn->ErrorNo() != 0) {
+         $msg = pnML('Database error for #(1) function #(2)() in module #(3)',
+                     'user', 'getpubcatcount', 'Articles');
+         pnExceptionSet(PN_SYSTEM_EXCEPTION, 'DATABASE_ERROR',
+                        new SystemException($msg));
+         return false;
+     }
+ 
+     if ($result->EOF) {
+         return false;
+     }
+     while (!$result->EOF) {
+         list($ptid, $cid, $count) = $result->fields;
+         if (empty($args['reverse'])) {
+             $pubcatcount[$ptid][$cid] = $count;
+         } else {
+             $pubcatcount[$cid][$ptid] = $count;
+         }
+         $result->MoveNext();
+     }
+     foreach ($pubcatcount as $id1 => $val) {
+         $total = 0;
+         foreach ($val as $id2 => $count) {
+             $total += $count;
+         }
+         $pubcatcount[$id1]['total'] = $total;
+     }
+ 
+     return $pubcatcount;
  }
  


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