
Lionel
User
Jan 28, 2003, 12:23 PM
Post #1 of 18
(14546 views)
Shortcut
|
|
addon: most read articles (requires php and mysql)
|
Can't Post
|
|
the attached counter is not from me. I simply modified it to also display the title. I you want to use it, simply place '<img src="counter.php">' in your articles templates. This counter checks if a page exists, if not it inserts it in database. If it does, it increments the page hits. Now, this counter as is will only display the url. What I did, was to create 2 files from counter.php and not password protected them within the program, one for admin with reset and delete, and a modified one to display to public. I placed the admin file in an .htaccess password directory. My modifications to also display the linked article title in the second file which I call views php, replace the entire function function viewStatus($self,$password) with function viewStatus($self,$password) { if (authUser($password)) { $queryGetData = "SELECT * FROM pagecounter order by visits DESC LIMIT 5"; //set your own LIMIT by replacing the 5 $resultGetData = mysql_db_query(DATABASE, $queryGetData) or die ("Query failed: error was ".mysql_error()); $o .=" <table width=100%>\n"; $o .=" <tr>\n"; $o .=" <td width=\"100%\">\n"; $o .=" <font face=verdana size=3 color=#990000><b>Most read articles</b><font>\n"; $o .=" </td>\n"; $o .=" </tr>\n"; for($i=0;$row=mysql_fetch_array($resultGetData);$i++) { //haitiwebs addon $fd= fread(fopen("$row[page]", "r"), 100000); if ($fd) { $start= strpos($fd, "<title>"); $finish= strpos($fd, "</title>"); $length= $finish-$start; $code_grabbed=Substr($fd, $start, $length); $title=str_replace("<title>", "", $code_grabbed); } $i % 2 ? 0: $bgcolor = "#ebebeb"; $o .=" <tr bgcolor=\"$bgcolor\">\n"; $o .=" <td>\n"; $o .=" <li><font face=verdana size=1><a href=$row[page]><b>$title</b></a></font></li>\n"; $o .=" </td>\n"; $o .=" </tr>\n"; } $o .=" </table>\n"; if (mysql_num_rows($resultGetData) == "0") { return "There are no active counters.\n"; } else { return $o; } } else { $o .=" <form action=\"$self\" method=post>\n"; $o .=" Password:\n"; $o .=" <input name=\"password\" type=\"password\" /> \n"; $o .=" <input type=hidden name=a value=vs>\n"; $o .=" </form>\n"; return $o; } } you can view it in action at http://www.haitiwebs.com/magazine/articles/top.php or http://www.haitiwebs.com/magazine/articles/top.shtml whichever you want. This is my first public addon, hope someone will find it useful. That test article http://www.haitiwebs.com/magazine/articles/article_117.php is loaded with goodies. Although that one hasn't got one, every article can include its own interactive poll. Email or post here if interested.
(This post was edited by Lionel on Mar 13, 2003, 9:02 PM)
|