[geeklog-cvs] geeklog-1.3/system lib-syndication.php,1.3,1.4

geeklog-cvs-admin at lists.geeklog.net geeklog-cvs-admin at lists.geeklog.net
Fri Sep 12 07:51:06 EDT 2003


Update of /usr/cvs/geeklog/geeklog-1.3/system
In directory geeklog_prod:/tmp/cvs-serv23606/system

Modified Files:
	lib-syndication.php 
Log Message:
Added support for (RSS) feeds listing upcoming events.


Index: lib-syndication.php
===================================================================
RCS file: /usr/cvs/geeklog/geeklog-1.3/system/lib-syndication.php,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** lib-syndication.php	8 Sep 2003 17:33:00 -0000	1.3
--- lib-syndication.php	12 Sep 2003 11:51:03 -0000	1.4
***************
*** 203,206 ****
--- 203,254 ----
  
  /**
+ * Check if a feed for the events needs to be updated.
+ *
+ * @param    string   $update_info   list of event ids
+ * @param    string   $limit         number of entries or number of hours
+ * @return   bool                    false = feed needs to be updated
+ *
+ */
+ function SYND_feedUpdateCheckEvents( $update_info, $limit )
+ {
+     global $_CONF, $_TABLES, $_SYND_DEBUG;
+ 
+     $where = '';
+     if( !empty( $limit ))
+     {
+         if( substr( $limit, -1 ) == 'h' ) // next xx hours
+         {
+             $limitsql = '';
+             $hours = substr( $limit, 0, -1 );
+             $where = " AND (datestart <= DATE_ADD(NOW(), INTERVAL $hours HOUR))";
+         }
+         else
+         {
+             $limitsql = ' LIMIT ' . $limit;
+         }
+     }
+     else
+     {
+         $limitsql = ' LIMIT 10';
+     }
+ 
+     $result = DB_query( "SELECT eid FROM {$_TABLES['events']} WHERE perm_anon > 0 AND dateend >= NOW()$where ORDER BY datestart,timestart $limitsql" );
+ 
+     $eids = array();
+     for( $i = 0; $i < $nrows; $i++ )
+     {
+         $A = DB_fetchArray( $result );
+         $eids[] = $A['eid'];
+     }
+     $current = implode( ',', $eids );
+ 
+     if ($_SYND_DEBUG) {
+         COM_errorLog ("Update check for events: comparing new list ($current) with old list ($update_info)", 1);
+     }
+ 
+     return ( $current != $update_info ) ? false : true;
+ }
+ 
+ /**
  * Check if the feed contents need to be updated.
  *
***************
*** 230,233 ****
--- 278,287 ----
          break;
  
+         case '::events':
+         {
+             $is_current = SYND_feedUpdateCheckEvents( $update_data, $limit );
+         }
+         break;
+ 
          default:
          {
***************
*** 423,427 ****
          {
              $limitsql = ' LIMIT ' . $limit;
!             $where = " ORDER BY lid DESC";
          }
      }
--- 477,481 ----
          {
              $limitsql = ' LIMIT ' . $limit;
!             $where = ' ORDER BY lid DESC';
          }
      }
***************
*** 429,432 ****
--- 483,487 ----
      {
          $limitsql = ' LIMIT 10';
+         $where = ' ORDER BY lid DESC';
      }
  
***************
*** 464,467 ****
--- 519,595 ----
  
  /**
+ * Get content for a feed that holds all links.
+ *
+ * @param    string   $limit    number of entries or number of stories
+ * @param    string   $link     link to homepage
+ * @param    string   $update   list of story ids
+ * @return   array              content of the feed
+ *
+ */
+ function SYND_getFeedContentEvents( $limit, &$link, &$update )
+ {
+     global $_TABLES, $_CONF, $LANG01;
+ 
+     $where = '';
+     if( !empty( $limit ))
+     {
+         if( substr( $limit, -1 ) == 'h' ) // next xx hours
+         {
+             $limitsql = '';
+             $hours = substr( $limit, 0, -1 );
+             $where = " AND (datestart <= DATE_ADD(NOW(), INTERVAL $hours HOUR))";
+         }
+         else
+         {
+             $limitsql = ' LIMIT ' . $limit;
+         }
+     }
+     else
+     {
+         $limitsql = ' LIMIT 10';
+     }
+ 
+     $result = DB_query( "SELECT eid,owner_id,title,description FROM {$_TABLES['events']} WHERE perm_anon > 0 AND dateend >= NOW()$where ORDER BY datestart,timestart $limitsql" );
+ 
+     $content = array();
+     $eids = array();
+     $nrows = DB_numRows( $result );
+ 
+     for( $i = 1; $i <= $nrows; $i++ )
+     {
+         $row = DB_fetchArray( $result );
+         $eids[] = $row['eid'];
+ 
+         $eventtitle = stripslashes( $row['title'] );
+         $eventtext  = stripslashes( $row['description'] );
+         $eventlink  = $_CONF['site_url'] . '/calendar_event.php?eid='
+                     . $row['eid'];
+ 
+         // Need to reparse the date from the event id
+         $myyear = substr( $row['eid'], 0, 4 );
+         $mymonth = substr( $row['eid'], 4, 2 );
+         $myday = substr( $row['eid'], 6, 2 );
+         $myhour = substr( $row['eid'], 8, 2 );
+         $mymin = substr( $row['eid'], 10, 2 );
+         $mysec = substr( $row['eid'], 12, 2 );
+         $newtime = "{$mymonth}/{$myday}/{$myyear} {$myhour}:{$mymin}:{$mysec}";
+         $creationtime = strtotime( $newtime );
+ 
+         $content[] = array( 'title'  => $eventtitle,
+                             'text'   => $eventtext,
+                             'link'   => $eventlink,
+                             'uid'    => $row['owner_id'],
+                             'date'   => $creationtime,
+                             'format' => 'plaintext'
+                           );
+     }
+ 
+     $link = $_CONF['site_url'] . '/calendar.php';
+     $update = implode( ',', $eids );
+ 
+     return $content;
+ }
+ 
+ /**
  * Update a feed.
  *
***************
*** 494,498 ****
              elseif( $A['topic'] == '::links')
              {
!                 $content = SYND_getFeedContentLinks( $A['limits'], $link, $data );
              }
              else // feed for a single topic only
--- 622,632 ----
              elseif( $A['topic'] == '::links')
              {
!                 $content = SYND_getFeedContentLinks( $A['limits'], $link,
!                                                      $data );
!             }
!             elseif( $A['topic'] == '::events')
!             {
!                 $content = SYND_getFeedContentEvents( $A['limits'], $link,
!                                                       $data );
              }
              else // feed for a single topic only





More information about the geeklog-cvs mailing list