boardom Forum Index boardom
b2 message board
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Archives hack
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    boardom Forum Index -> Hacks
View previous topic :: View next topic  
Author Message
Jason Velocity



Joined: 25 Jan 2002
Posts: 45
Location: C>Springs>CO

PostPosted: Mon Mar 04, 2002 6:19 am    Post subject: Archives hack Reply with quote

I thought I would move Dodo's archives hack over to the forums for full disection.

http://cafelog.com/index.php?p=442&c=1#comments

here is the file
http://regretless.com/dodo/pure/b2/hacks/archives.zip

here are a couple of examples
http://regretless.com/dodo/pure/b2/b2archives.php
http://www.jasonvelocity.com/archives.php

First, I added the user nickname to the display
replace this:
Code:
$postdata = get_postdata2($row->ID);
      echo $postdata["Date"];
      echo " - <a href=\"$siteurl/".$blogfilename."?p=".$row->ID."&c=1"."\">";
      if ($postdata["Title"]) {
         $postdata["Title"] = stripslashes($postdata["Title"]);
         echo $postdata["Title"];
      } else {
         echo $postdata["ID"];
      }
      echo "</a>";
      echo "<br>\n";


With this:
Code:
$postdata = get_postdata2 ($row->ID);
      $userinfo = get_userdata ($postdata["Author_ID"]);
      echo $postdata["Date"];
      echo " - <a href=\"$siteurl/".$blogfile."?p=".$row->ID."&c=1"."\">";
      if ($postdata["Title"]) {
         $postdata["Title"] = stripslashes($postdata["Title"]);
         echo $postdata["Title"];
      } else {
         echo $postdata["ID"];
      }
      echo "</a> by ";
      echo $userinfo["user_nickname"];
      echo "<br>\n";
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Jason Velocity



Joined: 25 Jan 2002
Posts: 45
Location: C>Springs>CO

PostPosted: Mon Mar 04, 2002 7:36 am    Post subject: Next - a better sort by author Reply with quote

Next, I want to change the way is sorts and displays by author. what I'm trying to do will look something like this:

Author 1
post title
post title
post title

Author 2
post title
post title
post title


Any help would be appreciated. most people wouldn't find this useful, but I have around 20 users, so sorting this way would look real nice.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Benjy



Joined: 25 Jan 2002
Posts: 108
Location: Paris, France

PostPosted: Tue Mar 05, 2002 5:04 pm    Post subject: Reply with quote

This is perhaps the solution to your "problem", but as I don't have PHP nor FTP access where I actually am, I suggest to try this:

Replace
Code:
} elseif ($archive_mode == "postbypost") {
   while($row=mysql_fetch_object($result)) {
      $postdata = get_postdata2($row->ID);
      $thismonth=mysql2date("Y\-m", $postdata["Date"]);
      $linkmonth=mysql2date("Ym", $postdata["Date"]);
      $i = "/".$thismonth."/";
      if ($thismonth != $previousmonth) {
         if (preg_match($i,$postdata["Date"])) {
            echo "<br><a href=\"$siteurl/".$blogfilename."?m=$linkmonth\">";
            echo $month[substr($thismonth,5,2)];
            echo "</a>";
            echo "<br>\n";
         }
      }
      $previousmonth = $thismonth;

      $postdata = get_postdata2($row->ID);
      $userinfo = get_userdata ($postdata["Author_ID"]);
      echo $postdata["Date"];
      echo " - <a href=\"$siteurl/".$blogfilename."?p=".$row->ID."&c=1"."\">";
      if ($postdata["Title"]) {
         $postdata["Title"] = stripslashes($postdata["Title"]);
         echo $postdata["Title"];
      } else {
         echo $postdata["ID"];
      }
      echo "</a> by ";
      echo $userinfo["user_nickname"];
      echo "<br>\n";
   }
}


With
Code:
} elseif ($archive_mode == "postbypost" && $way != "post_author") {
   while($row=mysql_fetch_object($result)) {
      $postdata = get_postdata2($row->ID);
      $thismonth=mysql2date("Y\-m", $postdata["Date"]);
      $linkmonth=mysql2date("Ym", $postdata["Date"]);
      $i = "/".$thismonth."/";
      if ($thismonth != $previousmonth) {
         if (preg_match($i,$postdata["Date"])) {
            echo "<br><a href=\"$siteurl/".$blogfilename."?m=$linkmonth\">";
            echo $month[substr($thismonth,5,2)];
            echo "</a>";
            echo "<br>\n";
         }
      }
      $previousmonth = $thismonth;

      $postdata = get_postdata2($row->ID);
      $userinfo = get_userdata ($postdata["Author_ID"]);
      echo $postdata["Date"];
      echo " - <a href=\"$siteurl/".$blogfilename."?p=".$row->ID."&c=1"."\">";
      if ($postdata["Title"]) {
         $postdata["Title"] = stripslashes($postdata["Title"]);
         echo $postdata["Title"];
      } else {
         echo $postdata["ID"];
      }
      echo "</a> by ";
      echo $userinfo["user_nickname"];
      echo "<br>\n";
   }
} elseif ($archive_mode == "postbypost" && $way == "post_author") {
   while($row=mysql_fetch_object($result)) {
      $postdata = get_postdata2($row->ID);
      $userinfo = get_userdata($postdata["Author_ID"]);
      $actual_user = $userinfo["user_nickname"];
      if ($actual_user != $previous_user) {
         echo $actual_user;
         $previous_user = $actual_user;
      }
      echo "<a href=\"$siteurl/".$blogfilename."?p=".$row->ID."&c=1"."\">";
      if ($postdata["Title"]) {
         $postdata["Title"] = stripslashes($postdata["Title"]);
         echo $postdata["Title"];
      } else {
         echo $postdata["ID"];
      }
      echo "</a>";
      echo "<br>\n";
   }
}


Thx for telling me if it did work,
Benjy.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Jason Velocity



Joined: 25 Jan 2002
Posts: 45
Location: C>Springs>CO

PostPosted: Tue Mar 05, 2002 9:45 pm    Post subject: Works! Reply with quote

That solves the problem, but it is really slow. Let me tweak it a bit and see if I can get it to move faster, and add some cool formatting.

http://www.jasonvelocity.com/test.php

the odd part here is how it sorts. If you tell it to do descending, it will start with the person with the least posts, and end with me (who has the most posts)....pretty strange.

Next we should put the amount of post next to the authors name!.
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Benjy



Joined: 25 Jan 2002
Posts: 108
Location: Paris, France

PostPosted: Tue Mar 05, 2002 11:20 pm    Post subject: Reply with quote

For the sorting, it's normal, because if you use a descending order for the dates, that means you'll have the latest (newest) date on top, and that's the same for the names, except the latest name is at the end of the alphabet
The only way to solve this, I think, would be to do another mysql request if $way="post_author"...

And I forgot the carriage return after the poster's name! Razz

Benjy.
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
dodo



Joined: 25 Jan 2002
Posts: 35

PostPosted: Wed Mar 06, 2002 3:39 am    Post subject: Reply with quote

thanks for posting, i added the link to this thread in the read me file so others who need the modifcation can come and look =)
_________________
http://pure-essence.net

b2 rocks
Back to top
View user's profile Send private message Visit poster's website
nessahead



Joined: 12 Mar 2002
Posts: 312
Location: Los Angeles, CA

PostPosted: Fri Apr 19, 2002 2:51 am    Post subject: Reply with quote

I love this hack =) One problem I'm having, though:

On the page I use to display this hack, I want to include a regular list of my archives (which happen to be monthly) in the sidebar. However, it's displaying the whole list of archives =/

Here's the code for my page:

Code:
<?php /* Don't remove this line, it calls the b2 function files ! */ $blog=1; include ("b2/blog.header.php"); ?>

<?php include("includes/header.php"); ?>

<p class="navtitle">full archive list</p>

<?php include("b2/b2archivesList.php"); ?>

<?php include("includes/sidebar.php"); ?>

<p class="navtitle">archives</p>

<?php include("b2/b2archives.php") ?>

<p><a href="/archivesList.php">Full Archive List</a></p>

<p class="navtitle">archive search</p>

<p align="center"><form name="searchform" method="get" action="<?php echo $PHP_SELF ?>">
<input type="text" name="s" size="15" /><br />
<img src="/images/1x1.gif" width="1" height="5"><br>
<input type="submit" name="submit" value="search" />
</form>
</p>

<p class="navtitle">recently updated b2 blogs</p>

<base target="_blank"><p><?php include("http://cafelog.com/changes.php"); ?></p>

<?php include("includes/footer.php"); ?>


And here's what it looks like: http://www.nessahead.com/archivesListError.php

See how the sidebar's all screwy? The sidebar's supposed to look like this: http://www.nessahead.com

If anyone could help me out, I'd really appreciate it =)

Thanks!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
mikelittle



Joined: 11 May 2002
Posts: 376
Location: UK

PostPosted: Sat May 11, 2002 1:22 am    Post subject: Archives hack Reply with quote

Nessa,
The reason your sidebar archives have changed is that Dodo's file is a replacement for the b2archives.php which is included in your side bar. The difference being that Dodo's version hard codes
Code:
$archive_mode = "postbypost";
into it.
It has a test
Code:
if ($pagenow == "b2archives.php")
in there which is used to detect whether the include file is being displayed on its own (i.e. not an include). I guess this same test could be used to hard code the
Code:
$archive_mode
.

So you would replace:
Code:

$pagenow = explode("/", $PHP_SELF);
$pagenow = trim($pagenow[(sizeof($pagenow)-1)]);
if ($pagenow == "b2archivesfull.php")
   include ("blog.header.php");
if(!$way)
   $way = "ID";
if(!$order)
   $order = "DESC";

$archive_mode = "postbypost";


with:
Code:

$pagenow = explode("/", $PHP_SELF);
$pagenow = trim($pagenow[(sizeof($pagenow)-1)]);
if ($pagenow == "b2archivesfull.php") {
   include ("blog.header.php");
        $archive_mode = "postbypost";
}
if(!$way)
   $way = "ID";
if(!$order)
   $order = "DESC";


I've not tested this but it may well do the trick.

Hope this helps,

Mike
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
nessahead



Joined: 12 Mar 2002
Posts: 312
Location: Los Angeles, CA

PostPosted: Sat May 11, 2002 1:31 am    Post subject: Reply with quote

I didn't really understand what you explained (sorry, I'm just not a PHP guru ) but I replaced the code you were talking about. Although it does fix the short archives list on the right, the Full Archive List in the content doesn't display any entries Razz http://www.nessahead.com/archivesListError.php

Any ideas? It's not a huge deal, so don't worry about it if it's a big thing to go through Smile Thanks for replying, though!
_________________
raar!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
mikelittle



Joined: 11 May 2002
Posts: 376
Location: UK

PostPosted: Sat May 11, 2002 1:48 am    Post subject: Reply with quote

Doh! I pasted the code from my version which is not called b2archives.php.

If you replace the b2archivesfull.php with b2archives.php that may fix it.

If not, I'll have to look at it some other day. Sorry :-(
It's nearly 2am here, and I must get some sleep :-)

Hope this helps
Mike
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
mikelittle



Joined: 11 May 2002
Posts: 376
Location: UK

PostPosted: Tue May 14, 2002 12:05 am    Post subject: Reply with quote

Nessa,
I've got it sorted. I've taken Dodo's original hack and moved his stuff into the latest (b2-0.6pre2-20020409) version of the b2archives.php include file.

So now it looks like this.
Code:

<?php

// *** b2 Archive file
include ("./b2config.php");

// this is what will separate your archive links
$archive_separator = "<br />";

// archive link url
$archive_link_m = "$siteurl/".$blogfilename."?m=";   # monthly archive
$archive_link_w = "$siteurl/".$blogfilename."?w=";   # weekly archive
$archive_link_p = "$siteurl/".$blogfilename."?p=";   # post-by-post archive

if (!isset($oldest_year)) {
   // your oldest archives are from year...
   $oldest_year = "2001";
}

// --- //
$pagenow = basename($PHP_SELF);
if ($pagenow == "b2archives.php") { // are we running standalone
   include ("blog.header.php");
    $archive_mode = "postbypost";

if(!$way)
   $way = "ID";
if(!$order)
   $order = "DESC";

//echo "Archives:";
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- layout credits goto http://bluerobot.com/web/layouts/layout2.html -->

<head>
<title><?php echo $blogname ?></title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta http-equiv="reply-to" content="[email protected]" />
<meta http-equiv="imagetoolbar" content="no" />
<meta content="TRUE" name="MSSmartTagsPreventParsing" />

<style type="text/css" media="screen">
@import url( ../layout2b.css );
</style>
<link rel="stylesheet" type="text/css" media="print" href="b2-include/print.css" />

</head>
<body>
<h1><a href="index.php" title="<?php echo $blogname ?>">Back to <?php echo $blogname ?></a></h1>
<form  action="<?=$PHP_SELF?>" method="post">
Order by
<select name="way">
<option value="ID" <?=($way == "ID") ? "SELECTED" : "" ?>>ID</option>
<option value="post_date" <?=($way == "post_date") ? "SELECTED" : "" ?>>date</option>
<option value="post_title" <?=($way == "post_title") ? "SELECTED" : "" ?>>title</option>
<option value="post_category" <?=($way == "post_category") ? "SELECTED" : "" ?>>category</option>
<option value="post_author" <?=($way == "post_author") ? "SELECTED" : "" ?>>author</option>
<!--
<option value="post_content">content</option>
<option value="post_karma">karma</option>
 -->
</select>
<select name="order">
<option value="DESC" <?=($order == "DESC") ? "SELECTED" : "" ?>>Descending</option>
<option value="ASC" <?=($order == "ASC") ? "SELECTED" : "" ?>>Ascending</option>
</select>
<input type="submit" name="submit" value="sort" />
</form>
<?php } // end if standalone

if ($archive_mode == "monthly") {
   for ($arc_year=date("Y"); $arc_year>=$oldest_year; $arc_year--) {
      for ($arc_month=12; $arc_month>0; $arc_month--) {
         $arc_sql="SELECT ID FROM $tableposts WHERE YEAR(post_date)='$arc_year' AND MONTH(post_date)='$arc_month' LIMIT 1";
         $querycount++;
         $arc_result=mysql_query($arc_sql);
         if (mysql_num_rows($arc_result)) {
            echo "<a href=\"$archive_link_m$arc_year".zeroise($arc_month,2)."\">";
            echo $month[zeroise($arc_month,2)]." $arc_year";
            echo "</a>";
            echo $archive_separator."\n";
         }
      }
   }
} elseif ($archive_mode == "weekly") {
   for ($arc_year=date("Y"); $arc_year>=$oldest_year; $arc_year--) {
      for ($arc_week=53; $arc_week>0; $arc_week--) {
         $arc_sql="SELECT ID FROM $tableposts WHERE YEAR(post_date)='$arc_year' AND WEEK(post_date,$start_of_week)='$arc_week'";
         $querycount++;
         $arc_result=mysql_query($arc_sql);
         if (mysql_num_rows($arc_result)) {
            echo "<a href=\"$siteurl/".$blogfilename."?m=$arc_year&w=$arc_week\">";
            echo "week #$arc_week - $arc_year";
            echo "</a>";
            echo $archive_separator."\n";
         }
      }
   }
} elseif ($archive_mode == "postbypost") {
    if ($pagenow == "b2archives.php") { // are we running standalone
        $request = " SELECT * FROM $tableposts ORDER BY $way $order";
        $result = mysql_query($request);

        while($row=mysql_fetch_object($result)) {
            $postdata = get_postdata2($row->ID);
            $thismonth=mysql2date("Y\-m", $postdata["Date"]);
            $linkmonth=mysql2date("Ym", $postdata["Date"]);
            $i = "/".$thismonth."/";
            if ($thismonth != $previousmonth) {
                if (preg_match($i,$postdata["Date"])) {
                    echo "<br><a href=\"$siteurl/".$blogfilename."?m=$linkmonth\">";
                    echo $month[substr($thismonth,5,2)];
                    echo "</a>";
                    echo "<br>\n";
                    echo "<div id=\"content\">";
                }
            }
            $previousmonth = $thismonth;

            $postdata = get_postdata2 ($row->ID);
            $userinfo = get_userdata ($postdata["Author_ID"]);
            echo $postdata["Date"];
            echo " - <a href=\"$siteurl/".$blogfile."?p=".$row->ID."&c=1"."\">";
            if ($postdata["Title"]) {
                $postdata["Title"] = stripslashes($postdata["Title"]);
                echo $postdata["Title"];
            } else {
                echo $postdata["ID"];
            }
            echo "</a>";
            //echo " by " + $userinfo["user_nickname"];
            echo $archive_separator;
            echo "</div>";
        }
    } else {
        $requestarc = " SELECT ID,post_date,post_title FROM $tableposts ORDER BY post_date DESC";
        $querycount++;
        $resultarc = mysql_query($requestarc);
        while($row=mysql_fetch_object($resultarc)) {
            if ($row->post_date != "0000-00-00 00:00:00") {
                echo "<a href=\"$archive_link_p".$row->ID."\">";
                if (strip_tags($row->post_title)) {
                    echo strip_tags($row->post_title);
                } else {
                    echo $row->ID;
                }
                echo "</a>";
                echo $archive_separator."\n";
            }
        }
    }
}
?>


This now works as an include file in the side bar, and as a standalone page. Plus if you set your archive_mode to postbypost in options, you still get the old behaviour in the side bar.

If you take a look at http://zed1.com/b2/ you can see the monthly archive in the RH Sidebar. Plus there is a link to full archives. This runs the same include file standalone and produces Dodo's hacked version.

It could probably do with some more work, but I think it will work for now.

Hope this helps,
Mike
Back to top
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger
nessahead



Joined: 12 Mar 2002
Posts: 312
Location: Los Angeles, CA

PostPosted: Tue May 14, 2002 6:52 am    Post subject: Reply with quote

Wow, amazing! Smile Thank you so much, going to try it out right now Smile
_________________
raar!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
nessahead



Joined: 12 Mar 2002
Posts: 312
Location: Los Angeles, CA

PostPosted: Tue May 14, 2002 7:28 am    Post subject: Reply with quote

I set it up and it's working just fine! Smile

I'm not sure how to go about making it match the rest of my site, though, since I'd need a footer and anything put after the "// end if standalone" ends up showing when i include it on the main page.

Here's the main page where it's included (yay!): http://www.nessahead.com

and here's the standalone: http://www.nessahead.com/b2/b2archives.php
_________________
raar!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
sven



Joined: 08 May 2002
Posts: 30
Location: Central Valley Cali

PostPosted: Thu May 16, 2002 5:15 am    Post subject: How Do I Show Only a Specific Catagory? Reply with quote

How do I display the archives of one specific catagory or NOT a specific catagory? Either one will work.
_________________
<><sven><>
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
nessahead



Joined: 12 Mar 2002
Posts: 312
Location: Los Angeles, CA

PostPosted: Thu May 16, 2002 7:25 pm    Post subject: Reply with quote

In the url to your archives, you could do

Code:
http://www.whatever.com/blogurl.php?cat=1


or whatever category number you want.

What I did is replace

Code:
<?php /* Don't remove this line, it calls the b2 function files ! */ $blog=1; include ("b2/blog.header.php"); ?>


with

Code:
<?php /* Don't remove this line, it calls the b2 function files ! */ $blog=1; $cat=1; include ("b2/blog.header.php"); ?>


on my main index page when I wanted it to only display category 1.
_________________
raar!
Back to top
View user's profile Send private message Send e-mail Visit poster's website AIM Address Yahoo Messenger MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    boardom Forum Index -> Hacks All times are GMT + 1 Hour
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2 © 2001, 2002 phpBB Group