Skip to:
Content
Pages
Categories
Search
Top
Bottom

Search Results for 'code'

Viewing 25 results - 30,251 through 30,275 (of 32,432 total)
  • Author
    Search Results
  • #1810
    dprice
    Member

    Being both a web nerd and Physics student, I decided it was time for BBpress to meet up with MathML.

    Here’s the steps I took to get it crankin’:

    1. Made a copy of the default ‘kakumei’ template, then renamed the folder ‘physics’, my new template name. I then put a copy of ASCIImath.js in there. This does all the hard work.
    2. Changed the physics/header.php from:
      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
      <html xmlns="http://www.w3.org/1999/xhtml" <?php bb_language_attributes( '1.1' ); ?>>

      to:

      <?xml version='1.0' encoding='iso-8859-1'?>
      <?xml-stylesheet type="text/xsl" href="http://www.w3.org/Math/XSL/mathml.xsl"?>

      <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1 plus MathML 2.0 plus SVG 1.1//EN" "http://www.w3.org/2002/04/xhtml-math-svg/xhtml-math-svg-flat.dtd" >

      <html xmlns="http://www.w3.org/1999/xhtml"
      xml:lang="en"
      xmlns:pref="http://www.w3.org/2002/Math/preference"
      pref:renderer="css">

      It’d probably still work if you didn’t bother with this step, but seeing as BBpress is making XML we may as well.

    3. Added <script type="text/javascript" src="<?php echo bb_path_to_url( dirname(__FILE__) . '/ASCIIMathML.js'); ?>"> to physics/header.php – this loads the ASCIIMathML.js javascript and does a majority of the MathML magic.
    4. Opened bb-includes/formattingfunctions.php and edited this:
      function code_trick( $text ) {
      $text = str_replace(array("rn", "r"), "n", $text);
      // $text = preg_replace("|<code>(.*?)</code>|e", "'<code>' . encodeit('$1') . '</code>'", $text);
      // $text = preg_replace("|n<code>(.*?)</code>|se", "'<pre><code>' . encodeit('$1') . '</code></pre>'", $text);
      return $text;
      }

      To turn off the backtick code replacement – this is what ASCIIMath.js does!

    That was it. I’ll zip it all up then post it up here. Ideally, it’d be better to not comment out any of the bb-include/ files – if anyone has any suggestions, let me know.

    #1809
    medden
    Member

    Is there a simple way for ONLY the administrator of the forum to be able to input embedded javascript into posts?

    She wants to include some banner ads from other companies, and getting these in the right format is turning into a real headache…..

    they are published like this…

    <img src="http://track.webgains.com/link.html?wglinkid=2995&wgcampaignid=23815&js=0" border="0" alt=""/>

    but the image plugin only allows .jpg .gif etc.

    Could that be disabled only if the ADMIN was posting the entry?

    #57328
    andersson
    Participant

    Thanks for the praise and also for the tip on the middle column. Haven’t really thought of it before but you’re probably right about that one.

    Regarding the /profiles/x it is really a simple mod. You could do it in a number of ways really, where I chose the following:

    Add a row in .htaccess steering the call to the logic:

    RewriteRule ^profiles/?$ mods/profiles-by-letter.php?id=$1 [QSA,L]

    Personally I put the logic of all mods in separate files in a mod folder and the presentation in another to keep it clean.

    The rewrite rule of .htaccess makes “x” a GET-parameter to the logic, it’s then very easy to select all members starting with letter given by “x” like so:

    SELECT * FROM bb_users WHERE user_login LIKE '$first_letter' ORDER BY user_login LIMIT $limit

    That’s it. The logic part then calls the presentation which can use the result in an array or whatever format you choose for the result.

    #57188
    fel64
    Member

    Replace D M Y with a date-formatted string of your choice. It’s quite an interesting but simple system. Each letter stands for a different type of date or time. So D is replaced by first three letters of the weekdate, M by first three of the month etc.

    This reference will tell you what letters to use to see what date outputs you get. Roll your own date format. :)

    #57327
    fel64
    Member

    You’ve got a really nice eye for the design of the site. It’s rare to see something so nicely designed and functional. :)

    The main column of games could be a bit more highlighted, though; with the strong coloured backgrounds the left colum distracts a lot. Worth it for the login form, but in my opinion not for stats.

    How did you get the /profiles/X thing to work? Haven’t tried it myself, but it would be interesting to know how much modification it took to have bb accept that – if any?

    #57331
    wittmania
    Member

    Answered my own questions. Thanks to plenty of googling, I learned that I needed to use the cast() function to consider the values as numbers instead of as text strings.

    This is the code I ended up with:

    $most_viewed = (array) $bbdb->get_results("SELECT topic_id, meta_value FROM $bbdb->topicmeta WHERE meta_key='views' ORDER BY cast(meta_value as UNSIGNED) DESC");

    The cast($column as $type) function forces the query to treat the meta_value values as unsigned integers. Nifty, yes?

    #57265
    Trent Adams
    Member

    The plugin system is actually now implemented in the TRAC version of bbPress and will be available in the upcoming 1.0 version (and no, I don’t know when that is for sure! ;)

    Trent

    #1808
    wittmania
    Member

    I am working on adding a “Most Viewed Topics” list to my bb-Topic-Views plugin, and I’m getting hung up on one little thing. This is the code I am using to pull the topic ID and # of views from the topicmeta table:

    $most_viewed = (array) $bbdb->get_results("SELECT topic_id, meta_value FROM $bbdb->topicmeta WHERE meta_key='views' ORDER BY meta_value DESC");

    I then use array_slice to shorten the list to the number of posts the user wants to have listed. The only problem is that the results are sorted out of order.

    For instance, a post with 5 views would come before a post with 40, because 5 is higher than 4. In other words, any post with a single-digit number of views is sorted above posts with a double-digit number of views.

    Has anyone ever had this problem? Any ideas how to fix it?

    #1807
    andersson
    Participant

    PurposeGames is one of my sites. It’s basically a site for anyone that wants to learn something new in the most efficient way possible; by creating a game around that very subject. It allows for anyone to easily create games and play/rate games by other members. I’ve actionscripted a game engine and a game creation module to allow for anyone to create games via their own pictures and drag and drop.

    I use bbpress for the forum section, and actually liked the user handling so much that I kept the authentication engine for all of the site. I’ve extended it in the following manner:

    – Elaborating on the bozo concept to exclude games created by a bozo, ratings doesn’t count for bozo’s and comments to games by bozos gets treated like forum entries by bozos.

    – Added a vast number of statistics to the dashboard to see what member’s are doing, creating, rating, commenting, forum entries, top lists etc.

    – Extending profile pages to show member’s games, comments to the games created by member etc.

    – Keeping the base of the style of the forum, extending it to fit the way I like my site to look.

    Concepts I like most about bbpress include the sanitize methods (very fast, perfectly implemented in my opinion), the user object; extending it is endless and very easy with the meta-concept, the tags concept, and the bozo concept and of course the table-free layout. The Akismet utilization is very nice also.

    Concepts that I’ve excluded or re-written: Db-connection open/close (not optimized for my type of site), the plugin concept (my extensions are therefore “include”-based i.e. I’m not utilizing the various hooks available). I have not cluttered the code of any standard files with my code, other than adding an include statement where needed. I also had to re-route the “include header”-call of the admin panel to be able to add new parent sections to keep child sections. No biggie really but quite strange.

    I rate bbpress as 4 out of 5 as code architecture goes being able to extend it and to use it as authentication foundation. Near superb. As forums goes, it falls into the category of “less is more, but not enough” ;)

    Check my way of using bbpress at http://www.purposegames.com

    Feel free to comment on what you like and don’t like. Thanks.

    David Andersson

    Creator of purposegames.com

    #57302

    In reply to: Plugin: bb-Topic-Views

    Sam Bauers
    Participant

    Change:

    function get_view_count( $topic_id )
    {
    $view_count = $bbdb->get_var("SELECT meta_value FROM $bbdb->topicmeta WHERE topic_id = $topic_id AND meta_key='views'");

    To:

    function get_view_count( $topic_id )
    {
    global $bbdb, $topic;

    $view_count = $bbdb->get_var("SELECT meta_value FROM $bbdb->topicmeta WHERE topic_id = $topic_id AND meta_key='views'");

    ????

    #57300

    In reply to: Plugin: bb-Topic-Views

    fel64
    Member

    All I did was split display_view_count() into two functions, display_view_count() and get_view_count(). If for example you wanted the views in a seperate column, you’d add the column HTML and then add

    <?php $view_count = get_view_count(); echo $view_count; ?>

    This is what I replaced display_view_count( $title ) with, here for Smurf’s convenience. You’re about to get mail.

    Oh, before I forget – hopefully now that plugins need activation in 1.0-alpha, there’s also an activation hook or the like. That would let you do a lot of preparation first, making the code much easier. :)

    Edit: there is! bb_activate_plugin_XXX. Maybe you can use that – if you want to and figure it out, tell us/make an entry on the wiki. :)

    function display_view_count ($title)
    {
    global $bbdb, $topic;
    $topic_id = $topic->topic_id;

    $view_count = get_view_count( $topic_id );

    //Builds the text to be appended to the title
    $count_display = " <em>($view_count views)</em>"; //This sets the view count var to the existing number of views, if greater than 0
    //Makes this plugin play nice with the Page Links plugin by putting the pages (if they exist) on a new line
    if (function_exists('page_links_add_links')) {
    $count_display .= "n";
    }
    $title .= $count_display;

    return $title;
    }

    function get_view_count( $topic_id )
    {
    $view_count = $bbdb->get_var("SELECT meta_value FROM $bbdb->topicmeta WHERE topic_id = $topic_id AND meta_key='views'");

    if ( $view_count <= 0 ) {
    //If the view count hasn't been initialized...
    if ($topic->topic_posts >= 1) {
    /* Sets the new record to the number of posts that have been made in a topic */
    $view_count = $topic->topic_posts; //sets the view_count number
    } else {
    $view_count = 0; //can't think of a time when this would be necessary (phantom topics???)
    }

    //Adds the record to the DB so it isn't zero any longer
    $bbdb->query("INSERT INTO $bbdb->topicmeta ( meta_id, topic_id, meta_key, meta_value) VALUES ( NULL , $topic_id, 'views', $view_count )");
    }

    return $view_count;
    }

    #57299

    In reply to: Plugin: bb-Topic-Views

    wittmania
    Member

    @fel, Hack away… I’d be interested in seeing the code so I could incorporate it in the next version of the plugin. If you’re willing, please e-mail it to me at mike at wittmania dot com.

    Thanks!

    #57298

    In reply to: Plugin: bb-Topic-Views

    fel64
    Member

    Wittmania, it’s a really easy hack – in fact, if you simply take the code that gets the pageviews and seperate it into a different function, you could call that both from the current function you have to automatically append it and use it as a template tag. If you don’t fancy doing it, is it alright if I quickly hack it for Smurf?

    #57297

    In reply to: Plugin: bb-Topic-Views

    wittmania
    Member

    @Sam, I use your excellent Page Links plugin, and I wrote mine specifically to be compatible with yours. In fact, I wouldn’t have known what filter to use if it weren’t for your plugin.

    I set the priority of my filter as 99 (yours is set to 100), so it fires directly before yours. Also, my plugin checks to see if the page_links_add_links function exists, and if it does it automatically drops the page links to a new line below the title in order to make things a little more sightly.

    @smurfdude, I thought about that, too. I initially decided against that route so I could have it function without having to edit any template files. The way it works right now is that it is inserted with a filter that is triggered when (and where) the topic title is fed to the page. If you’re feeling really ambitious, you can go into bb-topic-views.php to see how the mechanics of the plugin work. From there, you could change some things around so you could put the views count in its own column. Eventually I may add that functionality within the plugin, but that’s not a high priority right now.

    Speaking of priorities, the next to-do on my list is to add functionality where a user can add a template tag that will display the top 5 (or 10, or whatever) most viewed posts, either as <li> items so you can use it anywhere, or in a format similar to the way the Latest Discussion area is laid out. Stay tuned…

    #57273

    In reply to: Profile Tabs

    fel64
    Member

    Should really have been more familiar with the code – there’s a check to see if it’s the correct file, otherwise it simply redirects to the front page. Getting rid of that made it work.

    Thanks for all your help, Sam! :D

    #57272

    In reply to: Profile Tabs

    Sam Bauers
    Participant

    I tested the second method on the latest build and it passes the bb_repermalink tests and loads.

    I tried using standard URLs and both types of permalinks.

    I didn’t try to load a template. I used a file called avatar-upload.php containing the following:

    <?php
    require_once('./bb-load.php');

    bb_repermalink(); // The magic happens here.

    echo 'test';
    ?>

    My test plugin contained:

    <?php
    /*
    Plugin Name: Test for fel64
    Plugin URI:
    Description: Test profile tab addition
    Author: Scooby Doo
    Version: 0.0.1
    Author URI:
    */

    $bb->debug = 1;

    function felavatartab()
    {
    add_profile_tab(__('Avatar'), 'edit_profile', 'moderate', 'avatar-upload.php');
    }

    add_action( 'bb_profile_menu', 'felavatartab' );
    ?>

    #56963
    Vili
    Participant

    Indeed, would save some work. :)

    #57271

    In reply to: Profile Tabs

    fel64
    Member

    Cheers Sam, that’s definitely the way to do it, but I can’t quite make it work. Adding the tab is easy, but following the link dumps you on the front page (if using add_profile_tab()) or in your profile (if adding the tab manually).

    function felavatartab()
    {
    global $profile_menu, $profile_hooks;
    $profile_tab = array(__('Avatar'), 'edit_profile', 'moderate', 'avatar-upload.php', 'avatar');
    $profile_menu[] = $profile_tab;
    if ( can_access_tab( $profile_tab, bb_get_current_user_info( 'id' ), $user_id ) )
    $profile_hooks[bb_tag_sanitize($profile_tab[4])] = $profile_tab[3];
    }
    add_action( 'bb_profile_menu', 'felavatartab' );

    OR

    function felavatartab()
    {
    add_profile_tab(__('Avatar'), 'edit_profile', 'moderate', 'avatar-upload.php');
    }
    add_action( 'bb_profile_menu', 'felavatartab' );

    I’ve got the file avatar-upload.php in my root directory, which loads the template avatar.php. If instead you give avatar.php as your argument the tab doesn’t show up at all.

    See it here. Any idea?

    #57294
    fel64
    Member

    Depending on if you’ve set up bbPress so that it’s not only integrated but also uses WordPress’s functions when available, I think you can just call the WP function. If it doesn’t work, you need to make a database query along the lines of:

    global $bbdb;
    $profiledata = $bbdb->get_row( "SELECT meta_value FROM $bbdb->usermeta WHERE meta_key = $theprofiledetail AND user_id = $theuserid");

    Where $theuserid and $theprofiledetail are set to whatever you want. Note that $profiledata is worth examining by using print_r($profiledata); or the like, because its format can be confusing. The code might not work, but it’s an idea.

    #56961
    Vili
    Participant

    Ok, here’s what I have, commented. The comments that start with “VILI” are mine.

    Please keep in mind two things:

    a) This is strictly speaking a WordPress plugin, not a bbPress one. The functionality is simply extended to also cover an integrated bbPress installation. (And yes, this means that you need to install this in your WordPress, not your bbPress.)

    b) I hacked this for my own purposes, so it may not be pretty, and it certainly won’t be ready for use without you reading through the code. If someone is interested in working to make it functional as an “out of the box” solution, then by all means go ahead.

    Finally, the original Dan’s Avatar Thingy can be found here.

    <?php
    /*
    Plugin Name: Vili's Avatar Thingy
    Plugin URI: http://www.vertebratesilence.com/
    Description: Displays an avatar next to posts or comments based on username. Based on Dan's Avatar Thingy (http://www.cheesemasterdan.com/).
    Version: 0.1
    Author: Vili Maunula
    Author URI: http://www.vertebratesilence.com/
    */

    // Variable declarations
    // VILI: These were changed from Dan's Avatar Thingy, in which you only had default
    // size settings into which all avatars were resized.

    $avatar_max_width = 100; // Max avatar width
    $avatar_max_height = 100; // Max avatar height
    $avatar_max_upload_size = 15360; // Max file size in bytes
    $avatars_path = ABSPATH."wp-content/avatars";

    function cmd_show_avatar()
    {
    global $wpdb;
    global $avatars_path;

    // VILI: The following is a boolean setting I use to detect whether the page
    // being served is a forum page. In practice, I have
    // <?php global $forumpage;
    // $forumpage = TRUE; ?>
    // at the beginning of each forum page (I use WordPress headers in my integrated
    // setup, but if your bbPress uses its own headers, just stick it there). If
    // anyone knows a more cost-efficient way of detecting whether a page shown is
    // a forum page, let me know.
    global $forumpage;

    if ($forumpage == FALSE) {
    $the_author_name = get_comment_author();
    if($the_author_name == "" or $the_author_name == __('Anonymous'))
    { // Avatar for posts
    $the_author = get_the_author_id();
    $the_author_name = get_the_author();
    } else { // Avatar for comments - only for registered users
    $the_comment_ID = get_comment_ID();
    $the_author = $wpdb->get_var("SELECT user_ID FROM $wpdb->comments WHERE comment_ID='$the_comment_ID'");
    }
    } else {
    $the_author_name = get_post_author();
    $the_author = get_post_author_id();
    }

    $image_path = get_bloginfo('wpurl')."/wp-content/avatars/";
    $the_avatar = $image_path.$the_author.".jpg";
    if(file_exists("$avatars_path/$the_author.jpg"))
    {
    echo '<img src="' . $the_avatar. '" alt="' . $the_author_name . '" class="cmd-avatar" />';
    } elseif(file_exists("$avatars_path/default.jpg")) {
    echo '<img src="' . $image_path . 'default.jpg" alt="Unregistered" class="cmd-avatar" />';
    }
    // If the file doesn't exist then return nothing...
    }

    add_action ('admin_menu', 'cmd_avatar_menu');

    function cmd_avatar_menu()
    {
    add_submenu_page('profile.php', '', 'Your Avatar', 0, __FILE__, 'cmd_avatar_profile');
    }

    function cmd_avatar_profile()
    {
    global $userdata;
    global $avatar_max_width;
    global $avatar_max_height;
    global $avatar_max_upload_size;
    global $avatars_path;
    get_currentuserinfo();

    if(!file_exists($avatars_path))
    {
    $mkdir_result = @mkdir($avatars_path, "0755");
    if(!$mkdir_result)
    {
    echo '<div id="message" class="error fade">The folder' . $avatars_path . ' does not exist and could not be created automatically. Please create it and assign 0755 permissions then try using this plugin again.
    </div>';
    die();
    }
    }

    if ($_POST['cmd_action'] == 'upload_avatar')
    {
    if ($_FILES['cmd_avatar_file']['size'] > 0 && $_FILES['cmd_avatar_file']['size'] < $_POST['MAX_FILE_SIZE'])
    {
    $uploaddir = ABSPATH."wp-content/avatars/";
    $uploadfile = $uploaddir . $userdata->ID . '.jpg';
    list($width, $height, $type, $attr) = getimagesize($_FILES['cmd_avatar_file']['tmp_name']);

    // VILI: The following calculates the size into which the
    // image needs to be put. If it's under the MAX limits, nothing
    // is done, otherwise resizing takes place. This probably
    // could be written more elegantly.

    $widthratio = $width / $avatar_max_width;
    $heightratio = $height / $avatar_max_height;
    if ($widthratio > 1 && $heightratio > 1 && $widthratio > $heightratio) {
    $usewidth = $width / $widthratio;
    $useheight = $height / $widthratio;
    } elseif ($widthratio > 1 && $heightratio > 1 && $widthratio < $heightratio) {
    $useheight = $height / $heightratio;
    $usewidth = $width / $heightratio;
    } elseif ($widthratio > 1) {
    $usewidth = $width / $widthratio;
    $useheight = $height / $widthratio;
    } elseif ($heightratio > 1) {
    $useheight = $height / $heightratio;
    $usewidth = $width / $heightratio;
    } else {
    $usewidth = $width;
    $useheight = $height;
    }

    $cmd_avatar_image = imagecreatetruecolor ($usewidth, $useheight);
    switch ($type)
    {
    case 1: // GIF
    $image = imagecreatefromgif($_FILES['cmd_avatar_file']['tmp_name']);
    imagecopyresampled($cmd_avatar_image, $image, 0, 0, 0, 0, $usewidth, $useheight, $width, $height);
    $avatar_created = (imagejpeg($cmd_avatar_image, $uploadfile, 100) ? TRUE : FALSE);
    imagedestroy($image);
    imagedestroy($cmd_avatar_image);
    break;
    case 2: // JPEG
    $image = imagecreatefromjpeg($_FILES['cmd_avatar_file']['tmp_name']);
    imagecopyresampled($cmd_avatar_image, $image, 0, 0, 0, 0, $usewidth, $useheight, $width, $height);
    $avatar_created = (imagejpeg($cmd_avatar_image, $uploadfile, 100) ? TRUE : FALSE);
    imagedestroy($image);
    imagedestroy($cmd_avatar_image);
    break;
    case 3: // PNG
    $image = imagecreatefrompng($_FILES['cmd_avatar_file']['tmp_name']);
    imagecopyresampled($cmd_avatar_image, $image, 0, 0, 0, 0, $usewidth, $useheight, $width, $height);
    $avatar_created = (imagejpeg($cmd_avatar_image, $uploadfile, 100) ? TRUE : FALSE);
    imagedestroy($image);
    imagedestroy($cmd_avatar_image);
    break;
    default:
    $avatar_created = FALSE;
    break;
    }
    if ($avatar_created) {
    echo '<div id="message" class="updated fade">File uploaded successfully.
    </div>';
    } else {
    echo '<div id="message" class="error fade">File upload failed.
    </div>';
    }
    }
    }
    echo '
    <div class="wrap">
    <h2>Your Avatar</h2>
    <form name="cmd_avatar" id="your-profile" action="' . $PHP_SELF . '" method="post" enctype="multipart/form-data">
    <fieldset>
    <legend>Avatar</legend>';

    $the_user = $userdata->ID;

    $avatars_path = ABSPATH."wp-content/avatars";
    $image_path = get_bloginfo('wpurl')."/wp-content/avatars/";
    $the_avatar = $image_path.$the_user.".jpg";

    if(file_exists("$avatars_path/$the_user.jpg")){
    echo '
    <img src="' . $the_avatar . '" alt="' . $userdata->user_login . '" class="cmd-avatar">';
    } else {
    echo 'No avatar found...';
    }
    echo '

    <label>Filename: </label>
    <input type="file" accept="Pictures" name="cmd_avatar_file" />

    <input type="hidden" name="MAX_FILE_SIZE" value="' . $avatar_max_upload_size . '" />
    <input type="hidden" name="cmd_action" value="upload_avatar" />
    Click browse to find your avatar image. It can be JPG, GIF or PNG and should be ' . $avatar_max_width . ' x ' . $avatar_max_height . ' pixels or less (if bigger, it will be resized).Images should also be no larger than ' . $avatar_max_upload_size / 1024 . 'KBCurrently animated GIFs are not supported.
    </fieldset>
    <br clear="all" />
    <p class="submit">
    <input type="submit" name="cmd_avatar_update" value="Update Profile &raquo;" />

    </form>
    </div>';
    }

    ?>

    #1805
    wittmania
    Member

    bb-Topic-Views keeps track of how many times each topic has been viewed, and then displays the count alongside the title of the topic on the front page, on forums pages, and on tags pages.

    The plugin is written in such a way that it does not double-count views when a visitor browses to a different page in the same topic. If no view count record exists for a specific topic, the plugin will create a record for it. Rather than setting the initial view count to zero, the plugin sets it to the number of posts in the topic, because it has obviously been viewed at least as many times as people have posted in it! This is especially nice for adding the plugin to existing bbpress forums so the view count isn’t zero for every single topic.

    You can download it here: http://blog.wittmania.com/bb-topic-views

    You can see it in action here: http://blog.wittmania.com/bbpress

    By the way, I’ve only tested this plugin in browser environments where cookies were enabled. This plugin doesn’t set any cookies (directly, anyway), but it does use session variables which are usually passed as cookies. So, if anyone runs into any bugs, please let me know!

    I’m also very open to suggestions as to how I could streamline or improve the code. Thanks!

    #1793
    wittmania
    Member

    I am working on a “Topic Views Count” plugin, and I’m just about finished with it. You can see a working version of it here: http://blog.wittmania.com/bbpress/, and see the source code as it is right now here: http://blog.wittmania.com/files/bb-topic-views.txt

    The only thing holding me up is this; I can’t figure out a way to keep the views count from including page views. For example, when page one of a topic loads, the view count will go up by one. But, when page two loads it will also go up by one. So, a visitor has only viewed the topic once (albeit they’ve viewed more than one page), but the counter has registered two views).

    I know this isn’t a huge deal, and a counter that over-counts is better than no counter at all. Still, I was wondering if anyone would have any ideas. I’d like to avoid using cookies, if possible, because I have no experience with them at all to even know where to start.

    Any ideas? I’m also open to any other ideas or suggestions for the rest of the code.

    Thanks!

    #57228
    fel64
    Member

    Cheers!

    Further hack here, to migrate any comments made to WP posts that have a corresponding bb topic (via the bbPress Post plugin again) as replies to the thread. Unfortunately the date/time won’t be right, it’ll be like a new post just made.

    This needs to be installed/activated as a plugin to work, and to prevent it somehow accidentally happening again I suggest you immediately uninstall it. To run it, simply append “?lulz=p” to a URL and it’ll get to work – make sure you only do this once! An interface would be a lot neater, but, well, meh.

    At your own risk.

    <?php
    /*
    Plugin Name: Comments migrate
    Plugin URI:
    Description: moves wp comments into bb posts.
    Author: fel64
    Version: 0.7
    Author URI: http://www.loinhead.net/
    */
    function felmigrate()
    {
    global $bbdb, $bb_table_prefix;
    //foreach blogpost/topic in wp_bbpress_post_posts
    $bridge = $bbdb->get_results( ' SELECT post_id, topic_id
    FROM wp_bbpress_post_posts', ARRAY_A );
    foreach( $bridge as $sumthing => $link )
    {
    //foreach comment
    $wppost = $link['post_id'];
    $bbtopic = $link['topic_id'];
    $felcoms = $bbdb->get_results( " SELECT comment_author, comment_date, comment_content, comment_author_IP
    FROM wp_comments
    WHERE comment_post_ID = $wppost" );
    if( $felcoms )
    {
    foreach( $felcoms as $sumthing => $felcom )
    {
    //if valid user
    $felu = bb_get_user_by_name( $felcom->comment_author );
    if( $felu )
    {
    //create new post in that thread with said details
    fel_new_post( $bbtopic, $felcom, $felu->ID );
    }
    }
    }
    }
    //party
    }
    function fel_new_post( $topic_id, $post_details, $felID ) {
    global $bbdb, $bb_cache, $bb_table_prefix, $thread_ids_cache;
    $topic_id = (int) $topic_id;

    $bb_post = $post_details->comment_content;
    //$bb_post = apply_filters('pre_post', $bb_post, false, $topic_id);
    $bb_post = htmlspecialchars( $bb_post, ENT_QUOTES );
    $post_status = 0;
    $now = bb_current_time('mysql');
    //$now = $post_details->comment_date;
    $uid = $felID;
    $uname = $post_details->comment_author;
    $ip = $post_details->comment_author_IP;

    $topic = get_topic( $topic_id );
    $forum_id = $topic->forum_id;

    if ( $bb_post && $topic ) {
    $topic_posts = ( 0 == $post_status ) ? $topic->topic_posts + 1 : $topic->topic_posts;
    $bbdb->query("INSERT INTO $bbdb->posts
    (forum_id, topic_id, poster_id, post_text, post_time, poster_ip, post_status, post_position)
    VALUES
    ('$forum_id', '$topic_id', '$uid', '$bb_post','$now', '$ip', '$post_status', $topic_posts)");
    $post_id = $bbdb->insert_id;
    if ( 0 == $post_status ) {
    $bbdb->query("UPDATE $bbdb->forums SET posts = posts + 1 WHERE forum_id = $topic->forum_id");

    /* if( $now < $topic->topic_time )
    {
    $now = $topic->topic_time;
    $uid = $topic->topic_last_poster;
    $uname = $topic->topic_last_poster_name;
    $post_id = $topic->topic_last_post_id;
    }
    */ $bbdb->query("UPDATE $bbdb->topics SET topic_time = '$now', topic_last_poster = '$uid', topic_last_poster_name = '$uname',
    topic_last_post_id = '$post_id', topic_posts = '$topic_posts' WHERE topic_id = '$topic_id'");
    if ( isset($thread_ids_cache[$topic_id]) ) {
    $thread_ids_cache[$topic_id]['post'][] = $post_id;
    $thread_ids_cache[$topic_id]['poster'][] = $uid;
    }
    $post_ids = get_thread_post_ids( $topic_id );
    if ( !in_array($uid, array_slice($post_ids['poster'], 0, -1)) )
    bb_update_usermeta( $uid, $bb_table_prefix . 'topics_replied', $bb_current_user->data->topics_replied + 1 );
    } else
    bb_update_topicmeta( $topic->topic_id, 'deleted_posts', isset($topic->deleted_posts) ? $topic->deleted_posts + 1 : 1 );
    if ( !bb_current_user_can('throttle') )
    bb_update_usermeta( $uid, 'last_posted', time() );
    $bb_cache->flush_one( 'topic', $topic_id );
    $bb_cache->flush_many( 'thread', $topic_id );
    $bb_cache->flush_many( 'forum', $forum_id );
    do_action('bb_new_post', $post_id);
    return $post_id;
    } else {
    return false;
    }
    }

    //plunge
    if( $_GET['lulz'] = 'p' )
    felmigrate();
    ?>

    #57283
    Trent Adams
    Member

    Sorry, I was just trigger happy….force of habit….;)

    Trent

    #57282
    fel64
    Member

    I’m glad these still are a pretty place. :)

    I don’t know, closing it isn’t going to save his feelings; although closing it would be appropriate if it looks like a fight. It’s a matter of opinion I guess. Yup, clear as mud!

Viewing 25 results - 30,251 through 30,275 (of 32,432 total)
Skip to toolbar