The MU forums have moved to WordPress.org

My script: WMU Blog stats aka Activity list (29 posts)

  1. Inviz
    Inactive
    Posted 18 years ago #

    Hello there.
    As i used Wmu for my blogengine i made a script which i think can be useful for others. This script is making a table of N blogs with their stats, like last post, last comment, its names, post & comments count and more.
    screenshot
    Script is connecting to DB takes blog names and users (1 query).
    Then for each blog it gets last comment & last post data (2 queries).
    Then post & comment total counts (2 queries).
    Then builds an array.

    I wrote a small example using script of using the array, which builds a table with data, using css.

    Here is the code of first part:

    <?
    //WMU STATS by Inviz
    //Contacts:
    // Mail: inviz@personart.ru
    // MSN: invizko@hotmail.com
    // ICQ: 2323825
    //last uptdated October, 23 2005

    //some kinda OPTIONS
    // Uncomment for last active n blogs
    //$limit_results=1;

    mysql_connect(DB_HOST,DB_USER,DB_PASSWORD);
    $query='SELECT
    id,domain,path,last_updated,display_name
    FROM wp_users
    LEFT JOIN wp_blogs ON blog_id = id
    WHERE is_public="yes" ORDER BY last_updated DESC';
    $limit_results ? $query.=' LIMIT '.$limit_results : '';

    $result=mysql_query($query);
    if (mysql_num_rows($result)>0) {
    $i=0;
    while ($row=mysql_fetch_array($result)) {
    $table[$i]['path']=$row['path'];
    $table[$i]['domain']=$row['domain'];
    $table[$i]['name']=$row['display_name'];
    $table[$i]['id']=$row['id'];
    $subquery='SELECT comment_id,comment_date,comment_author,post_date,post_title,post_name
    FROM wp_'.$row['id'].'_comments
    LEFT JOIN wp_'.$row['id'].'_posts ON id=comment_post_ID
    ORDER BY comment_date DESC
    LIMIT 1';
    $subresult=mysql_query($subquery);
    if (mysql_num_rows($subresult)>0) {
    $temp=mysql_fetch_row($subresult);
    $table[$i]['comment']=true;
    $table[$i]['comment_date']=$temp['1'];
    $table[$i]['comment_author']=$temp['2'];
    $table[$i]['comment_post_path']=explode(' ',$temp['3']);
    $table[$i]['comment_post_path']=str_replace('-','/',$table[$i]['comment_post_path'][0]);
    $table[$i]['comment_post_title']=$temp['4'];
    $table[$i]['comment_post_name']=$temp['5'];
    $table[$i]['comment_post_date']=$temp['3'];
    $table[$i]['comment_post_url']='http://'.$table[$i]['domain'].$table[$i]['path'].$table[$i]['comment_post_path'].'/'.$table[$i]['comment_post_name'].'#comments';
    unset($temp);
    }

    $subquery='SELECT id,post_date_gmt,post_date,post_title,post_name, post_content
    FROM wp_'.$row['id'].'_posts
    WHERE post_status=\'publish\'
    ORDER BY post_date_gmt DESC
    LIMIT 1';
    $subresult=mysql_query($subquery);
    if (mysql_num_rows($subresult)>0) {
    $temp=mysql_fetch_row($subresult);
    $table[$i]['post']=true;
    $table[$i]['post_except']=substr($temp[5],0,26).'...';
    $table[$i]['post_path']=explode(' ',$temp['1']);
    $table[$i]['post_path']=str_replace('-','/',$table[$i]['post_path'][0]);
    $table[$i]['post_title']=$temp['3'];
    $table[$i]['post_name']=$temp['4'];
    $table[$i]['post_date']=$temp['2'];
    $table[$i]['post_url']='http://'.$table[$i]['domain'].$table[$i]['path'].$table[$i]['post_path'].'/'.$table[$i]['post_name'];
    unset($temp);
    }

    $subquery='SELECT count(comment_id) FROM wp_'.$row['id'].'_comments';
    $subresult=mysql_query($subquery);
    if (mysql_num_rows($subresult)>0) {
    $temp=mysql_fetch_row($subresult);
    $table[$i]['comments_count']=$temp[0];
    } else {
    $table[$i]['comments_count']=0;
    }

    $subquery='SELECT count(id) FROM wp_'.$row['id'].'_posts WHERE post_status="publish"';
    $subresult=mysql_query($subquery);
    if (mysql_num_rows($subresult)>0) {
    $temp=mysql_fetch_row($subresult);
    $table[$i]['posts_count']=$temp[0];
    } else {
    $table[$i]['posts_count']=0;
    }
    $i++;
    }
    }

    ?>

    Wooah. It can be included in the top of home.php file.

    Then the home.php example:

    <?php get_header(); ?>
    <style>
    #wmu_stats th {
    color: #fff;
    background:#4876A3;
    text-align:left;
    padding:2px;
    }
    #wmu_stats td {
    padding:2px;
    }
    .wmu_stats_row_0 td {
    background: #eaeaea;
    }
    </style>
    <div id="content" class="widecolumn">

    <h2><?php echo $current_site->site_name ?></h2>
    This is a WordPress Mu powered site.
    You can:

    • Login
    • Create a new blog
    • Edit thie file at wp-content/themes/home/home.php with your favourite text editor and customize this screen.

    <?
    echo "<table width=\"100%\" id=\"wmu_stats\">
    ";
    echo "<tr><th>Blogauthor</th><th>Last Comment</th><th>Last Post</th><th>Psts</th><th>Cmmnts</th></tr>";
    $i=0;
    foreach ($table as $row) {
    $i++;
    echo "<tr class=\"wmu_stats_row_". $i%2 ."\">";
    echo "<td><b>".$row['name']."</b></td>";
    echo "<td align=\"center\">";
    echo $row['comment']==true ? "".$row['comment_author']."

    <small>".$row['comment_date']."</small>" : '<b>—</b>';
    echo "</td>";

    echo "<td align=\"center\">";
    if ($row['post']==true) {
    echo "";
    if ($row['post_title'])
    echo $row['post_title'];
    else
    echo $row['post_except'];
    echo "
    <small>".$row['post_date']."</small>";
    } else {
    echo "<b>—</b>";
    }

    echo "</td>";
    echo "<td><b>".$row['posts_count']."</b></td>";
    echo "<td><b>".$row['comments_count']."</b></td>";
    echo "</tr>";
    }
    echo "</table>";
    ?>

    </div>

    <?php get_footer(); ?>

  2. inertia
    Member
    Posted 18 years ago #

    hey wow! it seems like a great script! but i can't seem to get it working :(

    Parse error: parse error, unexpected T_VARIABLE in /home/serialgr/public_html/xxxx.xxx/wp-inst/wp-content/themes/theme/index.php on line 1

    the first line contains just "<?"

    Is it necessary to put the script into home.php?

  3. techwench
    Inactive
    Posted 18 years ago #

    If you copied and pasted from this post, then it's because the forum is parsing the html, instead of displaying the code.

  4. Inviz
    Inactive
    Posted 18 years ago #

    sorry it is it. I will host home.php file in a minute...

  5. Inviz
    Inactive
    Posted 18 years ago #

    http://inviz.personart.ru/projects/wmu/home.php.txt
    here is it :) just copypaste it and it will work

  6. Ste_000
    Member
    Posted 18 years ago #

    scuse me....where i paste the code? i create a home.php with the code but don't work in wpmu....

  7. ballen
    Member
    Posted 18 years ago #

    Have you thought about expanding this to include bandwidth and size of each individual blog? This would greatly enhance WPMU as a solution and would probably lead to some sort of administrative reporting in the future... Just a thought... :)

  8. Inviz
    Inactive
    Posted 18 years ago #

    Ste-000
    wp-content\themese\home\home.php
    something like this.

    2ballen
    What size and bandwidth are you talking about? Pls specify and i'll do it :)

  9. SurvivalRing
    Inactive
    Posted 18 years ago #

    Hi...I've got this installed, but I'm getting an error on the new homepage, in the foreach() function...line 118...

    Warning: Invalid argument supplied for foreach() in /home2/surviva/public_html/friends/wp-inst/wp-content/themes/home/home.php on line 118

    Any ideas?

    New home.php created from the above text file. Looks like a good tool, but not sure where the problem is.

    http://www.survivalring.org/friends

    is the install. Creating new blogs works, as does login and new themes...any help appreciated.

    Rich

  10. SurvivalRing
    Inactive
    Posted 18 years ago #

    Regarding the size and bandwidth question above, I think he means, can you figure out the coding that would add the SIZE of each blog (the size of all files withing the user's blog folder) and BANDWIDTH used by each blog (maybe a stats program using a seperate table, adding up bandwidth with every page served, for each blog).

    That would be a great plugin or tool to add to this package.

  11. Farms
    Member
    Posted 18 years ago #

    Hi Inviz, just though I'd drop in to say thanks for the excellent contribution... much appreciated!

  12. Inviz
    Inactive
    Posted 18 years ago #

    Hey, SurvivalRing.
    That must be the thing, when you have no isntalled blogs or something, im not sure.
    trye to do this:
    Find this:

    echo "<tr><th>Blogauthor</th><th>Last Comment</th><th>Last Post</th><th>Psts</th><th>Cmmnts</th></tr>";
    $i=0;
    foreach ($table as $row) {

    and replace it with:


    echo "<tr><th>Blogauthor</th><th>Last Comment</th><th>Last Post</th><th>Psts</th><th>Cmmnts</th></tr>";
    $i=0;
    if ($table)
    foreach ($table as $row) {

    And what about bandwidth and space: i will try to do this in 2-3 days, just now i have a job.

    Farms: Im glad u're okay with that :D

  13. SurvivalRing
    Inactive
    Posted 18 years ago #

    Inviz,

    Thanks...will give it a shot this week...gots to work on the college homework and projects due this week...

    Appreciate the positive response. Also, I failed to mention I'm getting another error at the top of the page...

    'Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home2/surviva/public_html/friends/wp-inst/wp-content/themes/home/home.php on line 22
    '

    Again, thanks...

  14. mistwist
    Inactive
    Posted 18 years ago #

    finally a plugin that works!! Thank you!!!!

  15. Inviz
    Inactive
    Posted 18 years ago #

    SurvuvalRing,
    That might be maybe doing something wrong. But i'm not sure. Pls specify what are you doing, cause some people as we can see are good with it.

  16. mistwist
    Inactive
    Posted 18 years ago #

    ok here is a question, I got this working the first try and I have modified it to look a little different (you can see it here http://thejackassjournal.com/wpmu/) but i would like to include the blog name as well as the posters name.

    any ideas?

  17. Inviz
    Inactive
    Posted 18 years ago #

    Hi mistwist.

    For getting blog name, AFTER the


    $table[$i]['id']=$row['id'];

    PASTE THIS:

    /* hack for blogname */
    $subquery='SELECT
    option_value FROM wp_'.$table[$i]['id'].'_options WHERE option_id="2"';
    $subresult=mysql_query($subquery);
    if (mysql_num_rows($subresult)>0) {
    $table[$i]['blogname']=mysql_fetch_array($subresult);
    $table[$i]['blogname']=$table[$i]['blogname'][0];
    if (!$table[$i]['blogname']) $table[$i]['blogname']='untitled';
    }
    /* end of hack for blogname*/


    in the table you must use variable

    $table[$id]['blogname'] to get blog name.

    Okay, any other questions? :gent:

  18. mistwist
    Inactive
    Posted 18 years ago #

    Very nice!!!! Thank you!!!

  19. mistwist
    Inactive
    Posted 18 years ago #

    The only prob i can see with this hack is if a user posts an image.. take a look, it could be a wpmu problem tho as I am having issues with images at this point but thought you might want to see whats going on with it at http://thejackassjournal.com maybe you can figure out where the issue is because at this point I cant until I get images to work.

  20. Inviz
    Inactive
    Posted 18 years ago #

    3 ways

    - unstrip all tag (will make a thing, when a tag is cropped it will broke layout what is not acceptable)
    - strip all tags (how's it now)
    - clearing tags, to let only text be shown

    what do u wish me to do? :)

  21. Inviz
    Inactive
    Posted 18 years ago #

    TO STRIP ALL TAGS, FIND:


    $table[$i]['post_except']=preg_replace($patterns,$replaces,$temp[5]);

    AND REPLACE WITH


    /* STRIP HTML TAG HACK */
    $patterns=array('@<[/!]*?[^<>]*?>@si', '@<[/!]*?[^<>]*?@si');
    $replaces=array('','');

    /* u can add your excludes with adding them to the end of this array. for example to replace all img tags with [image] just use this instead of given before:
    $patterns=array('@<img[^<>]*?>@','@<[/!]*?[^<>]*?>@si', '@<[/!]*?[^<>]*?@si');
    $replaces=array('[image]','','');

    /*
    if (!$table[$i]['post_except']) $table[$i]['post_except']='mass html'; // message when post content is noting (here were just tags, cropped by script
    /* END OF STRIP HTML TAG HACK */

    Cheers, Inviz

  22. Inviz
    Inactive
    Posted 18 years ago #

    hate bbpress, here is not much space to show all the code. Select everything and copypaste to notepad and read it there

  23. mistwist
    Inactive
    Posted 18 years ago #

    the only line I am finding even close to
    $table[$i]['post_except']=preg_replace($patterns,$replaces,$temp[5]);
    is
    $table[$i]['post_except']=htmlspecialchars(substr($temp[5],0,26)).'...';

    Did you make other changes recently? ;)

  24. Inviz
    Inactive
    Posted 18 years ago #

    Oh, misttwist i pasted wrong code, you are completely right.

  25. Inviz
    Inactive
    Posted 18 years ago #

    lol :( post too old for edit. BBpress is sadistic

  26. mistwist
    Inactive
    Posted 18 years ago #

    lol and i was going to add bbpress too...;)

  27. Inviz
    Inactive
    Posted 18 years ago #

    offtop:its nice, simple, but too cut

  28. Inviz
    Inactive
    Posted 18 years ago #

    Please check other thread in this forum called WMUStats by me. There is an updated version of this and now comment it there ;p

  29. sallam
    Member
    Posted 18 years ago #

    Inviz
    Your link for that script doen't seem to work.
    http://inviz.personart.ru/projects/wmu/home.php.txt
    can you please give us a new link to your code?

About this Topic