Welcome to Geeklog, Anonymous Sunday, November 24 2024 @ 11:41 am EST
Geeklog Forums
2 site directory (directory.php) hacks
Status: offline
artur
Forum User
Junior
Registered: 08/18/06
Posts: 16
Hi,
Here my 2 hacks for directory.php (site directory)
if you are set in directory.php $conf_list_current_month =true (show current month stories above) and dont want to see "CURRENT MONTH No stories"
then the first hack is for you
modified DIR_displaymonth function searches for first month with stories.
with new constant CONF_MONTH_SEARCH can you gonfigure how many months to search.
second hack removes months with no stories from listing (... May 0 ...)
You with new constant CONF_ZERO_MONTHS can you configure to show these months.
in the code are modified places commented. To use - i think easiest is replace old functions.
-- hacks ---
// how many months to search for stories�
/**
* Display month view
*
* @param string $topic current topic
* @param int $year year to display
* @param int $month month to display
* @param bool $main true: display view on its own page
* @return string list of articles for the given month
*
*/
function DIR_displayMonth ($topic, $year, $month, $main = false)
{
global $_CONF, $_TABLES, $LANG30, $LANG_DIR;�
$retval = '';
$while_count=0; $orig_month = $month; $orig_year = $year; /* modified. added variables */
/* modified. original code, place and variable $sql_end are new :) */
if ($topic != 'all') {
$sql_end = " AND (tid = '$topic')";
}
$sql_end .= COM_getTopicSql ('AND') . COM_getPermSql ('AND') . " ORDER BY date ASC";�
$numrows =0;
/* modified. search for month with stories or until CONF_MONTH_SEARCH limit */
while ($while_count
$while_count++;
/* following is original code, only in while cycle */
$start = sprintf ('%04d-%02d-01 00:00:00', $year, $month);
$end = sprintf ('%04d-%02d-31 23:59:59', $year, $month);�
$sql = "SELECT sid,title,UNIX_TIMESTAMP(date) AS day,DAYOFMONTH(date) AS mday FROM {$_TABLES['stories']} WHERE (date >= '$start') AND
(date
AND (draft_flag = 0) AND (date
$sql .= $sql_end;
$result = DB_query ($sql);
$numrows = DB_numRows ($result);�
/* modified. if not found, search in previous month */
if ($numrows == 0) {
$month--;
if ($month ==0){
$month=12; /* previous year */
$year--;
}
}
}
/* heading string. May 2006 or january - May 2006, May 2005 - May 2006
Months in selected language */
$headingstring = $LANG30[$month+12] . ' ';
if (($month != $orig_month) && ($year == $orig_year)){
$headingstring .= ' - '. $LANG30[$orig_month+12] .' '. $orig_year;
} else {
if (($month != $orig_month) || ($year != $orig_year)){
$headingstring .= $year .' - '. $LANG30[$orig_month+12] .' '. $orig_year;
} else {
$headingstring .= $year;
}
}�
/* original code, only instead of ... is variable */
if ($main) {
$retval .= '' . $headingstring
. ' ' . DIR_topicList ($topic, $year, $month)
. '' . LB;
} else {
$retval .= '' . $headingstring . '' . LB;
}
if ($numrows>0){
$entries = array ();
$mday = 0;�
for ($i = 0; $i
$A = DB_fetchArray ($result);�
if ($mday != $A['mday']) {
if (sizeof ($entries) > 0) {
$retval .= COM_makeList ($entries);
$entries = array ();
}�
$curtime = COM_getUserDateTimeFormat ($A['day']);
$day = $curtime[0];�
$day = strftime ($_CONF['shortdate'], $A['day']);�
$retval .= '' . $day . '' . LB;�
$mday = $A['mday'];
}�
$url = COM_buildUrl ($_CONF['site_url'] . '/article.php?story='
. $A['sid']);
$entries[] = '<a href="' . $url . '">' . stripslashes ($A['title'])
. '</a>';
}�
if (sizeof ($entries) > 0) {
/* $entries = array_reverse($entries); // directory in reverse order, commented out */
$retval .= COM_makeList ($entries);
}�
} else {
$retval .= '<p>' . $LANG_DIR['no_articles'] . '</p>';
}�
$retval .= LB;�
return $retval;
}�
/*** next hack ***/
/* new constant for directory.php */
define('CONF_ZERO_MONTHS', false);
/* if false, dont display months with zero stories */
/**
* Display year view
*
* @param string $topic current topic
* @param int $year year to display
* @param bool $main true: display view on its own page
* @return string list of months (+ number of stories) for given year
*
*/
function DIR_displayYear ($topic, $year, $main = false)
{
global $_CONF, $_TABLES, $LANG30, $LANG_DIR, $_USERS;�
$retval = '';�
if ($main) {
$retval .= '' . $year . ' '
. DIR_topicList ($topic, $year) . '' . LB;
} else {
$retval .= '' . $year . '' . LB;
}�
$currentyear = date ('Y', time ());
$currentmonth = date ('m', time ());�
$start = sprintf ('%04d-01-01 00:00:00', $year);
$end = sprintf ('%04d-12-31 23:59:59', $year);�
$monthsql = "SELECT DISTINCT MONTH(date) AS month,COUNT(*) AS count FROM {$_TABLES['stories']} WHERE (date >= '$start') AND (date
AND (draft_flag
= 0) AND (date
if ($topic != 'all') {
$monthsql .= " AND (tid = '$topic')";
}
$monthsql .= COM_getTopicSql ('AND') . COM_getPermSql ('AND') . " GROUP BY MONTH(date) ORDER BY date ASC";�
$mresult = DB_query ($monthsql);
$nummonths = DB_numRows ($mresult);�
if ($nummonths > 0) {
$retval .= '<ul>' . LB;
$lastm = 1;
for ($j = 0; $j
$M = DB_fetchArray ($mresult);
if (CONF_ZERO_MONTHS){ /* modified. if false do not show "May 0" ...*/
for (; $lastm
$retval .= '<li>' . DIR_monthLink ($topic, $year, $lastm, 0)
. '</li>';
}
} // end if
$lastm = $M['month'] + 1;�
$retval .= '<li>' . DIR_monthLink ($topic, $year, $M['month'],
$M['count']) . '</li>';
}
if (CONF_ZERO_MONTHS){ /* modified. if false do not show "may 0" ... */
if ($year == $currentyear) {
$fillm = $currentmonth;
} else {
$fillm = 12;
}�
if ($lastm
for (; $lastm
$retval .= '<li>' . DIR_monthLink ($topic, $year, $lastm, 0)
. '</li>';
}
}
} // end if CONF_ZERO_MONTHS
$retval .= '</ul>' . LB;
} else {
$retval .= '<p>' . $LANG_DIR['no_articles'] . '</p>';
}�
$retval .= LB;�
return $retval;
}�
Here my 2 hacks for directory.php (site directory)
if you are set in directory.php $conf_list_current_month =true (show current month stories above) and dont want to see "CURRENT MONTH No stories"
then the first hack is for you
modified DIR_displaymonth function searches for first month with stories.
with new constant CONF_MONTH_SEARCH can you gonfigure how many months to search.
second hack removes months with no stories from listing (... May 0 ...)
You with new constant CONF_ZERO_MONTHS can you configure to show these months.
in the code are modified places commented. To use - i think easiest is replace old functions.
-- hacks ---
Text Formatted Code
define('CONF_MONTH_SEARCH', '12');// how many months to search for stories�
/**
* Display month view
*
* @param string $topic current topic
* @param int $year year to display
* @param int $month month to display
* @param bool $main true: display view on its own page
* @return string list of articles for the given month
*
*/
function DIR_displayMonth ($topic, $year, $month, $main = false)
{
global $_CONF, $_TABLES, $LANG30, $LANG_DIR;�
$retval = '';
$while_count=0; $orig_month = $month; $orig_year = $year; /* modified. added variables */
/* modified. original code, place and variable $sql_end are new :) */
if ($topic != 'all') {
$sql_end = " AND (tid = '$topic')";
}
$sql_end .= COM_getTopicSql ('AND') . COM_getPermSql ('AND') . " ORDER BY date ASC";�
$numrows =0;
/* modified. search for month with stories or until CONF_MONTH_SEARCH limit */
while ($while_count
$while_count++;
/* following is original code, only in while cycle */
$start = sprintf ('%04d-%02d-01 00:00:00', $year, $month);
$end = sprintf ('%04d-%02d-31 23:59:59', $year, $month);�
$sql = "SELECT sid,title,UNIX_TIMESTAMP(date) AS day,DAYOFMONTH(date) AS mday FROM {$_TABLES['stories']} WHERE (date >= '$start') AND
(date
AND (draft_flag = 0) AND (date
$sql .= $sql_end;
$result = DB_query ($sql);
$numrows = DB_numRows ($result);�
/* modified. if not found, search in previous month */
if ($numrows == 0) {
$month--;
if ($month ==0){
$month=12; /* previous year */
$year--;
}
}
}
/* heading string. May 2006 or january - May 2006, May 2005 - May 2006
Months in selected language */
$headingstring = $LANG30[$month+12] . ' ';
if (($month != $orig_month) && ($year == $orig_year)){
$headingstring .= ' - '. $LANG30[$orig_month+12] .' '. $orig_year;
} else {
if (($month != $orig_month) || ($year != $orig_year)){
$headingstring .= $year .' - '. $LANG30[$orig_month+12] .' '. $orig_year;
} else {
$headingstring .= $year;
}
}�
/* original code, only instead of ... is variable */
if ($main) {
$retval .= '' . $headingstring
. ' ' . DIR_topicList ($topic, $year, $month)
. '' . LB;
} else {
$retval .= '' . $headingstring . '' . LB;
}
if ($numrows>0){
$entries = array ();
$mday = 0;�
for ($i = 0; $i
$A = DB_fetchArray ($result);�
if ($mday != $A['mday']) {
if (sizeof ($entries) > 0) {
$retval .= COM_makeList ($entries);
$entries = array ();
}�
$curtime = COM_getUserDateTimeFormat ($A['day']);
$day = $curtime[0];�
$day = strftime ($_CONF['shortdate'], $A['day']);�
$retval .= '' . $day . '' . LB;�
$mday = $A['mday'];
}�
$url = COM_buildUrl ($_CONF['site_url'] . '/article.php?story='
. $A['sid']);
$entries[] = '<a href="' . $url . '">' . stripslashes ($A['title'])
. '</a>';
}�
if (sizeof ($entries) > 0) {
/* $entries = array_reverse($entries); // directory in reverse order, commented out */
$retval .= COM_makeList ($entries);
}�
} else {
$retval .= '<p>' . $LANG_DIR['no_articles'] . '</p>';
}�
$retval .= LB;�
return $retval;
}�
/*** next hack ***/
/* new constant for directory.php */
define('CONF_ZERO_MONTHS', false);
/* if false, dont display months with zero stories */
/**
* Display year view
*
* @param string $topic current topic
* @param int $year year to display
* @param bool $main true: display view on its own page
* @return string list of months (+ number of stories) for given year
*
*/
function DIR_displayYear ($topic, $year, $main = false)
{
global $_CONF, $_TABLES, $LANG30, $LANG_DIR, $_USERS;�
$retval = '';�
if ($main) {
$retval .= '' . $year . ' '
. DIR_topicList ($topic, $year) . '' . LB;
} else {
$retval .= '' . $year . '' . LB;
}�
$currentyear = date ('Y', time ());
$currentmonth = date ('m', time ());�
$start = sprintf ('%04d-01-01 00:00:00', $year);
$end = sprintf ('%04d-12-31 23:59:59', $year);�
$monthsql = "SELECT DISTINCT MONTH(date) AS month,COUNT(*) AS count FROM {$_TABLES['stories']} WHERE (date >= '$start') AND (date
AND (draft_flag
= 0) AND (date
if ($topic != 'all') {
$monthsql .= " AND (tid = '$topic')";
}
$monthsql .= COM_getTopicSql ('AND') . COM_getPermSql ('AND') . " GROUP BY MONTH(date) ORDER BY date ASC";�
$mresult = DB_query ($monthsql);
$nummonths = DB_numRows ($mresult);�
if ($nummonths > 0) {
$retval .= '<ul>' . LB;
$lastm = 1;
for ($j = 0; $j
$M = DB_fetchArray ($mresult);
if (CONF_ZERO_MONTHS){ /* modified. if false do not show "May 0" ...*/
for (; $lastm
$retval .= '<li>' . DIR_monthLink ($topic, $year, $lastm, 0)
. '</li>';
}
} // end if
$lastm = $M['month'] + 1;�
$retval .= '<li>' . DIR_monthLink ($topic, $year, $M['month'],
$M['count']) . '</li>';
}
if (CONF_ZERO_MONTHS){ /* modified. if false do not show "may 0" ... */
if ($year == $currentyear) {
$fillm = $currentmonth;
} else {
$fillm = 12;
}�
if ($lastm
for (; $lastm
$retval .= '<li>' . DIR_monthLink ($topic, $year, $lastm, 0)
. '</li>';
}
}
} // end if CONF_ZERO_MONTHS
$retval .= '</ul>' . LB;
} else {
$retval .= '<p>' . $LANG_DIR['no_articles'] . '</p>';
}�
$retval .= LB;�
return $retval;
}�
14
12
Quote
All times are EST. The time is now 11:41 am.
- Normal Topic
- Sticky Topic
- Locked Topic
- New Post
- Sticky Topic W/ New Post
- Locked Topic W/ New Post
- View Anonymous Posts
- Able to post
- Filtered HTML Allowed
- Censored Content