[ Index ]
 

Code source de GeekLog 1.4.1

Accédez au Source d'autres logiciels libres

title

Body

[fermer]

/public_html/ -> directory.php (source)

   1  <?php
   2  
   3  /* Reminder: always indent with 4 spaces (no tabs). */
   4  // +---------------------------------------------------------------------------+
   5  // | Geeklog 1.4                                                               |
   6  // +---------------------------------------------------------------------------+
   7  // | directory.php                                                             |
   8  // |                                                                           |
   9  // | Directory of all the stories on a Geeklog site.                           |
  10  // +---------------------------------------------------------------------------+
  11  // | Copyright (C) 2004-2006 by the following authors:                         |
  12  // |                                                                           |
  13  // | Authors: Dirk Haun         - dirk AT haun-online DOT de                   |
  14  // +---------------------------------------------------------------------------+
  15  // |                                                                           |
  16  // | This program is free software; you can redistribute it and/or             |
  17  // | modify it under the terms of the GNU General Public License               |
  18  // | as published by the Free Software Foundation; either version 2            |
  19  // | of the License, or (at your option) any later version.                    |
  20  // |                                                                           |
  21  // | This program is distributed in the hope that it will be useful,           |
  22  // | but WITHOUT ANY WARRANTY; without even the implied warranty of            |
  23  // | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             |
  24  // | GNU General Public License for more details.                              |
  25  // |                                                                           |
  26  // | You should have received a copy of the GNU General Public License         |
  27  // | along with this program; if not, write to the Free Software Foundation,   |
  28  // | Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           |
  29  // |                                                                           |
  30  // +---------------------------------------------------------------------------+
  31  //
  32  // $Id: directory.php,v 1.13 2006/12/11 11:49:17 dhaun Exp $
  33  
  34  require_once  ('lib-common.php');
  35  
  36  // configuration option:
  37  // List stories for the current month on top of the overview page
  38  // (if set = true)
  39  $conf_list_current_month = false;
  40  
  41  // name of this script
  42  define ('THIS_SCRIPT', 'directory.php');
  43  
  44  $display = '';
  45  
  46  if (empty ($_USER['username']) && (($_CONF['loginrequired'] == 1) ||
  47                                     ($_CONF['directoryloginrequired'] == 1))) {
  48      $display = COM_siteHeader ('menu', $LANG_DIR['title']);
  49      $display .= COM_startBlock ($LANG_LOGIN[1], '',
  50                                  COM_getBlockTemplate ('_msg_block', 'header'));
  51      $login = new Template ($_CONF['path_layout'] . 'submit');
  52      $login->set_file (array ('login' => 'submitloginrequired.thtml'));
  53      $login->set_var ('site_url', $_CONF['site_url']);
  54      $login->set_var ('layout_url', $_CONF['layout_url']);
  55      $login->set_var ('login_message', $LANG_LOGIN[2]);
  56      $login->set_var ('lang_login', $LANG_LOGIN[3]);
  57      $login->set_var ('lang_newuser', $LANG_LOGIN[4]);
  58      $login->parse ('output', 'login');
  59      $display .= $login->finish ($login->get_var ('output'));
  60      $display .= COM_endBlock (COM_getBlockTemplate ('_msg_block', 'footer'));
  61      $display .= COM_siteFooter ();
  62      echo $display; 
  63      exit;
  64  }
  65  
  66  /**
  67  * Helper function: Calculate last day of a given month
  68  *
  69  * @param    int     $month  Month
  70  * @param    int     $year   Year
  71  * @return   int             Number of days in that month
  72  * @bugs     Will fail from 2038 onwards ...
  73  *
  74  * "The last day of any given month can be expressed as the "0" day
  75  * of the next month", http://www.php.net/manual/en/function.mktime.php
  76  *
  77  */
  78  function DIR_lastDayOfMonth ($month, $year)
  79  {
  80      $month++;
  81      if ($month > 12) {
  82          $month = 1;
  83          $year++;
  84      }
  85  
  86      $lastday = mktime (0, 0, 0, $month, 0, $year);
  87  
  88      return intval(strftime('%d', $lastday));
  89  }
  90  
  91  /**
  92  * Display a topic selection drop-down menu
  93  *
  94  * @param    string  $topic          current topic
  95  * @param    int     $year           current year
  96  * @param    int     $month          current month
  97  * @param    bool    $standalone     true: don't display form inline
  98  *
  99  */
 100  function DIR_topicList ($topic = 'all', $year = 0, $month = 0, $standalone = false)
 101  {
 102      global $_CONF, $LANG21;
 103  
 104      $retval = '';
 105  
 106      $url = $_CONF['site_url'] . '/' . THIS_SCRIPT;
 107      $retval .= '<form action="' . $url . '" method="POST"';
 108      if (!$standalone) {
 109          $retval .= ' style="display:inline; float:right"' . LB;
 110      }
 111      $retval .= '>' . LB;
 112      $retval .= '<select name="topic" onchange="this.form.submit()">' . LB;
 113      $retval .= '<option value="all"';
 114      if ($topic == 'all') {
 115          $retval .= ' selected="selected"';
 116      }
 117      $retval .= '>' . $LANG21[7] . '</option>' . LB;
 118      $retval .= COM_topicList ('tid,topic', $topic);
 119      $retval .= '</select>' . LB;
 120      $retval .= '<input type="hidden" name="year" value="' . $year . '">';
 121      $retval .= '<input type="hidden" name="month" value="' . $month . '">';
 122      $retval .= '</form>' . LB;
 123  
 124      return $retval;
 125  }
 126  
 127  /**
 128  * Build link to a month's page
 129  *
 130  * @param    string  $topic  current topic
 131  * @param    int     $year   year to link to
 132  * @param    int     $month  month to link to
 133  * @param    int     $count  number of stories for that month (may be 0)
 134  * @return   string          month name + count, as link or plain text
 135  *
 136  */
 137  function DIR_monthLink ($topic, $year, $month, $count)
 138  {
 139      global $_CONF, $LANG_MONTH;
 140  
 141      $retval = '';
 142  
 143      if ($count > 0) {
 144          $retval .= '<a href="' . COM_buildUrl ($_CONF['site_url'] . '/'
 145                  . THIS_SCRIPT . '?topic=' . urlencode ($topic) . '&amp;year='
 146                  . $year . '&amp;month=' . $month) . '">';
 147      }
 148  
 149      $retval .= $LANG_MONTH[$month] . ' (' . COM_numberFormat ($count) . ')'
 150              . LB;
 151  
 152      if ($count > 0) {
 153          $retval .= '</a>';
 154      }
 155  
 156      $retval .= LB;
 157  
 158      return $retval;
 159  }
 160  
 161  /**
 162  * Display navigation bar
 163  *
 164  * @param    string  $topic  current topic
 165  * @param    int     $year   current year
 166  * @param    int     $month  current month (or 0 for year view pages)
 167  * @return   string          navigation bar with prev, next, and "up" links
 168  *
 169  */
 170  function DIR_navBar ($topic, $year, $month = 0)
 171  {
 172      global $_CONF, $_TABLES, $LANG05, $LANG_DIR;
 173  
 174      $retval = '';
 175  
 176      $retval .= '<div class="pagenav">';
 177  
 178      if ($month == 0) {
 179          $prevyear = $year - 1;
 180          $nextyear = $year + 1;
 181      } else {
 182          $prevyear = $year;
 183          $prevmonth = $month - 1;
 184          if ($prevmonth == 0) {
 185              $prevmonth = 12;
 186              $prevyear--;
 187          }
 188          $nextyear = $year;
 189          $nextmonth = $month + 1;
 190          if ($nextmonth > 12) {
 191              $nextmonth = 1;
 192              $nextyear++;
 193          }
 194      }
 195  
 196      $result = DB_query ("SELECT MIN(YEAR(date)) AS year FROM {$_TABLES['stories']}");
 197      $A = DB_fetchArray ($result);
 198      if ($prevyear < $A['year']) {
 199          $prevyear = 0;
 200      }
 201  
 202      $currentyear = date ('Y', time ());
 203      if ($nextyear > $currentyear) {
 204          $nextyear = 0;
 205      }
 206  
 207      if ($prevyear > 0) {
 208          $url = $_CONF['site_url'] . '/' . THIS_SCRIPT . '?topic='
 209               . urlencode ($topic) . '&amp;year=' . $prevyear;
 210          if ($month > 0) {
 211              $url .= '&amp;month=' . $prevmonth;
 212          }
 213          $retval .= '<a href="' . COM_buildUrl ($url) . '">' . $LANG05[6]
 214                  . '</a>';
 215      } else {
 216          $retval .= $LANG05[6];
 217      }
 218  
 219      $retval .= ' | ';
 220  
 221      $url = $_CONF['site_url'] . '/' . THIS_SCRIPT;
 222      if ($topic != 'all') {
 223          $url = COM_buildUrl ($url . '?topic=' . urlencode ($topic));
 224      }
 225      $retval .= '<a href="' . $url . '">' . $LANG_DIR['nav_top'] . '</a>';
 226  
 227      $retval .= ' | ';
 228  
 229      if ($nextyear > 0) {
 230          $url = $_CONF['site_url'] . '/' . THIS_SCRIPT . '?topic='
 231               . urlencode ($topic) . '&amp;year=' . $nextyear;
 232          if ($month > 0) {
 233              $url .= '&amp;month=' . $nextmonth;
 234          }
 235          $retval .= '<a href="' . COM_buildUrl ($url) . '">' . $LANG05[5]
 236                  . '</a>';
 237      } else {
 238          $retval .= $LANG05[5];
 239      }
 240  
 241      $retval .= '</div>' . LB;
 242  
 243      return $retval;
 244  }
 245  
 246  /**
 247  * Display month view
 248  *
 249  * @param    string  $topic  current topic
 250  * @param    int     $year   year to display
 251  * @param    int     $month  month to display
 252  * @param    bool    $main   true: display view on its own page
 253  * @return   string          list of articles for the given month
 254  *
 255  */
 256  function DIR_displayMonth ($topic, $year, $month, $main = false)
 257  {
 258      global $_CONF, $_TABLES, $LANG_MONTH, $LANG_DIR;
 259  
 260      $retval = '';
 261  
 262      if ($main) {
 263          $retval .= '<div><h1 style="display:inline">' . $LANG_MONTH[$month]
 264                  . ' ' . $year . '</h1> ' . DIR_topicList ($topic, $year, $month)
 265                  . '</div>' . LB;
 266      } else {
 267          $retval .= '<h1>' . $LANG_MONTH[$month] . ' ' . $year . '</h1>' . LB;
 268      }
 269  
 270      $start = sprintf ('%04d-%02d-01 00:00:00', $year, $month);
 271      $lastday = DIR_lastDayOfMonth ($month, $year);
 272      $end   = sprintf ('%04d-%02d-%02d 23:59:59', $year, $month, $lastday);
 273  
 274      $sql = "SELECT sid,title,UNIX_TIMESTAMP(date) AS day,DATE_FORMAT(date, '%e') AS mday FROM {$_TABLES['stories']} WHERE (date >= '$start') AND (date <= '$end') AND (draft_flag = 0) AND (date <= NOW())";
 275      if ($topic != 'all') {
 276          $sql .= " AND (tid = '$topic')";
 277      }
 278      $sql .= COM_getTopicSql ('AND') . COM_getPermSql ('AND')
 279           . COM_getLangSQL ('sid', 'AND') . " ORDER BY date ASC";
 280  
 281      $result = DB_query ($sql);
 282      $numrows = DB_numRows ($result);
 283  
 284      if ($numrows > 0) {
 285          $entries = array ();
 286          $mday = 0;
 287  
 288          for ($i = 0; $i < $numrows; $i++) {
 289              $A = DB_fetchArray ($result);
 290  
 291              if ($mday != $A['mday']) {
 292                  if (sizeof ($entries) > 0) {
 293                      $retval .= COM_makeList ($entries);
 294                      $entries = array ();
 295                  }
 296  
 297                  $curtime = COM_getUserDateTimeFormat ($A['day']);
 298                  $day = $curtime[0];
 299  
 300                  $day = strftime ($_CONF['shortdate'], $A['day']);
 301  
 302                  $retval .= '<h2>' . $day . '</h2>' . LB;
 303  
 304                  $mday = $A['mday'];
 305              }
 306  
 307              $url = COM_buildUrl ($_CONF['site_url'] . '/article.php?story='
 308                                   . $A['sid']);
 309              $entries[] = '<a href="' . $url . '">' . stripslashes ($A['title'])
 310                         . '</a>';
 311          }
 312  
 313          if (sizeof ($entries) > 0) {
 314              $retval .= COM_makeList ($entries);
 315          }
 316  
 317      } else {
 318          $retval .= '<p>' . $LANG_DIR['no_articles'] . '</p>';
 319      }
 320  
 321      $retval .= LB;
 322  
 323      return $retval;
 324  }
 325  
 326  /**
 327  * Display year view
 328  *
 329  * @param    string  $topic  current topic
 330  * @param    int     $year   year to display
 331  * @param    bool    $main   true: display view on its own page
 332  * @return   string          list of months (+ number of stories) for given year
 333  *
 334  */
 335  function DIR_displayYear ($topic, $year, $main = false) 
 336  {
 337      global $_CONF, $_TABLES, $LANG_MONTH, $LANG_DIR;
 338  
 339      $retval = '';
 340  
 341      if ($main) {
 342          $retval .= '<div><h1 style="display:inline">' . $year . '</h1> '
 343                  . DIR_topicList ($topic, $year) . '</div>' . LB;
 344      } else {
 345          $retval .= '<h2>' . $year . '</h2>' . LB;
 346      }
 347  
 348      $currentyear = date ('Y', time ());
 349      $currentmonth = date ('m', time ());
 350  
 351      $start = sprintf ('%04d-01-01 00:00:00', $year);
 352      $end   = sprintf ('%04d-12-31 23:59:59', $year);
 353  
 354      $monthsql = array();
 355      $monthsql['mysql'] = "SELECT DISTINCT MONTH(date) AS month,COUNT(*) AS count FROM {$_TABLES['stories']} WHERE (date >= '$start') AND (date <= '$end') AND (draft_flag = 0) AND (date <= NOW())";
 356      $monthsql['mssql'] = "SELECT MONTH(date) AS month,COUNT(sid) AS count FROM {$_TABLES['stories']} WHERE (date >= '$start') AND (date <= '$end') AND (draft_flag = 0) AND (date <= NOW())";
 357      if ($topic != 'all') {
 358          $monthsql['mysql'] .= " AND (tid = '$topic')";
 359          $monthsql['mssql'] .= " AND (tid = '$topic')";
 360      }
 361      $monthsql['mysql'] .= COM_getTopicSql ('AND') . COM_getPermSql ('AND')
 362                . COM_getLangSQL ('sid', 'AND');
 363      $monthsql['mssql'] .= COM_getTopicSql ('AND') . COM_getPermSql ('AND')
 364                . COM_getLangSQL ('sid', 'AND');
 365  
 366      $msql = array();
 367      $msql['mysql'] = $monthsql['mysql'] . " GROUP BY MONTH(date) ORDER BY date ASC";
 368      $msql['mssql'] = $monthsql['mssql'] . " GROUP BY MONTH(date) ORDER BY month(date) ASC";
 369  
 370      $mresult = DB_query ($msql);
 371      $nummonths = DB_numRows ($mresult);
 372  
 373      if ($nummonths > 0) {
 374          $retval .= '<ul>' . LB;
 375          $lastm = 1;
 376          for ($j = 0; $j < $nummonths; $j++) {
 377              $M = DB_fetchArray ($mresult);
 378  
 379              for (; $lastm < $M['month']; $lastm++) {
 380                  $retval .= '<li>' . DIR_monthLink ($topic, $year, $lastm, 0)
 381                          . '</li>';
 382              }
 383              $lastm = $M['month'] + 1;
 384  
 385              $retval .= '<li>' . DIR_monthLink ($topic, $year, $M['month'],
 386                                                 $M['count']) . '</li>';
 387          }
 388  
 389          if ($year == $currentyear) {
 390              $fillm = $currentmonth;
 391          } else {
 392              $fillm = 12;
 393          }
 394  
 395          if ($lastm <= $fillm) {
 396              for (; $lastm <= $fillm; $lastm++) {
 397                  $retval .= '<li>' . DIR_monthLink ($topic, $year, $lastm, 0)
 398                          . '</li>';
 399              }
 400          }
 401  
 402          $retval .= '</ul>' . LB;
 403      } else {
 404          $retval .= '<p>' . $LANG_DIR['no_articles'] . '</p>';
 405      }
 406  
 407      $retval .= LB;
 408  
 409      return $retval;
 410  }
 411  
 412  /**
 413  * Display main view (list of years)
 414  *
 415  * Displays an overview of all the years and months, starting with the first
 416  * year for which a story has been posted. Can optionally display a list of
 417  * the stories for the current month at the top of the page.
 418  *
 419  * @param    string  $topic                  current topic
 420  * @param    bool    $list_current_month     true = list stories f. current month
 421  * @return   string                          list of all the years in the db
 422  *
 423  */
 424  function DIR_displayAll ($topic, $list_current_month = false)
 425  {
 426      global $_TABLES, $LANG_DIR;
 427  
 428      $retval = '';
 429  
 430      if ($list_current_month) {
 431          $currentyear = date ('Y', time ());
 432          $currentmonth = date ('n', time ());
 433  
 434          $retval .= DIR_displayMonth ($topic, $currentyear, $currentmonth);
 435  
 436          $retval .= '<hr>' . LB;
 437      }
 438  
 439      $retval .= '<div><h1 style="display:inline">' . $LANG_DIR['title']
 440              . '</h1> ' . DIR_topicList ($topic) . '</div>' . LB;
 441  
 442      $yearsql = array();
 443      $yearsql['mysql'] = "SELECT DISTINCT YEAR(date) AS year,date FROM {$_TABLES['stories']} WHERE (draft_flag = 0) AND (date <= NOW())" . COM_getTopicSql ('AND') . COM_getPermSql ('AND')  . COM_getLangSQL ('sid', 'AND');
 444      $yearsql['mssql'] = "SELECT YEAR(date) AS year FROM {$_TABLES['stories']} WHERE (draft_flag = 0) AND (date <= NOW())" . COM_getTopicSql ('AND') . COM_getPermSql ('AND')  . COM_getLangSQL ('sid', 'AND');
 445      $ysql = array();
 446      $ysql['mysql'] = $yearsql['mysql'] . " GROUP BY YEAR(date) ORDER BY date DESC";
 447      $ysql['mssql'] = $yearsql['mssql'] . " GROUP BY YEAR(date) ORDER BY YEAR(date) DESC";
 448  
 449      $yresult = DB_query ($ysql);
 450      $numyears = DB_numRows ($yresult);
 451  
 452      for ($i = 0; $i < $numyears; $i++) {
 453          $Y = DB_fetchArray ($yresult);
 454  
 455          $retval .= DIR_displayYear ($topic, $Y['year']);
 456      }
 457  
 458      return $retval;
 459  }
 460  
 461  // MAIN
 462  $display = '';
 463  
 464  if (isset ($_POST['topic']) && isset ($_POST['year']) && isset ($_POST['month'])) {
 465      $topic = $_POST['topic'];
 466      $year = $_POST['year'];
 467      $month = $_POST['month'];
 468  } else {
 469      COM_setArgNames (array ('topic', 'year', 'month'));
 470      $topic = COM_getArgument ('topic');
 471      $year = COM_getArgument ('year');
 472      $month = COM_getArgument ('month');
 473  }
 474  
 475  $topic = COM_applyFilter ($topic);
 476  if (empty ($topic)) {
 477      $topic = 'all';
 478  }
 479  $year = COM_applyFilter ($year, true);
 480  if ($year < 0) {
 481      $year = 0;
 482  }
 483  $month = COM_applyFilter ($month, true);
 484  if (($month < 1) || ($month > 12)) {
 485      $month = 0;
 486  }
 487  
 488  if (($year != 0) && ($month != 0)) {
 489      $title = sprintf ($LANG_DIR['title_month_year'],
 490                        $LANG_MONTH[$month], $year);
 491      $display .= COM_siteHeader ('menu', $title);
 492      $display .= DIR_displayMonth ($topic, $year, $month, true);
 493      $display .= DIR_navBar ($topic, $year, $month);
 494  } else if ($year != 0) {
 495      $title = sprintf ($LANG_DIR['title_year'], $year);
 496      $display .= COM_siteHeader ('menu', $title);
 497      $display .= DIR_displayYear ($topic, $year, true);
 498      $display .= DIR_navBar ($topic, $year);
 499  } else {
 500      $display .= COM_siteHeader ('menu', $LANG_DIR['title']);
 501      $display .= DIR_displayAll ($topic, $conf_list_current_month);
 502  }
 503  
 504  $display .= COM_siteFooter (true);
 505  
 506  echo $display;
 507  
 508  ?>


Généré le : Wed Nov 21 12:27:40 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics