Vili (@vilimaunula)

Forum Replies Created

Viewing 14 replies - 26 through 39 (of 39 total)

  • Vili
    Participant

    @vilimaunula

    I thought this pretty much explained it?

    Basically, I use WordPress headers and footers throughout both WordPress and bbPress, with my headers and footers containing all the layout design, and whatever is in between only being the actual content to be shown (in the case of a post the post loop, in the case of a page the page loop, in the case of a forum page the forum loop, etc.).


    Vili
    Participant

    @vilimaunula

    atomAstro — could you elaborate on where POST and GET becomes a problem with this integration? I haven’t yet met with any (that I know), but it would be of great help if you could give a few examples so that I know what to keep an eye on!


    Vili
    Participant

    @vilimaunula

    Is this on a WordPress or a bbPress page, dyaddydad? Have you done a full bbPress integration, including the “functions” section? Do you use the $forumpage variable as suggested in my post with the code? Did you uninstall Dan’s plugin before uploading mine?


    Vili
    Participant

    @vilimaunula

    Sorry for the confusion. :)

    It’s a WordPress plugin. And no, you don’t need to install any avatar-upload thing, or indeed any other extra plugin to get this to work.

    The function works both on WordPress and bbPress, but since it is a WordPress plugin (and thus a WordPress function) you will need to make WordPress functions available to bbPress. This is covered in the Integration with WordPress page in the bbPress documentation (see the last section, “Functions”).

    I hope this clears things up a little.


    Vili
    Participant

    @vilimaunula

    daddy, you will need to use the “Vili’s avatar thingy” code that I posted above, and then just use the same function as with WordPress:

    <?php if(function_exists('cmd_show_avatar')){ cmd_show_avatar(); } ?>


    Vili
    Participant

    @vilimaunula

    I would personally just copy the bbPress CSS over to the WordPress one, so as to keep it all in one place. If you want to integrate the two, why then have more than one CSS file? :)


    Vili
    Participant

    @vilimaunula

    Hmm. I took a look at the “Connections” theme by Vanilla Mist, and it seems that the header file in that theme is not used for actual header information, but only for the header DIV. This will make your life somewhat more difficult if you want to integrate your bbPress seemlessly in the manner that I described above.


    Vili
    Participant

    @vilimaunula

    The way I have integrated the two over at http://akirakurosawa.info/ is by editing the bbPress template so that it calls the WordPress headers instead of the bbPress ones.

    I presume that you have installed both WordPress and bbPress, and that you have integrated their user databases and installed the required plug-ins as outlined at https://bbpress.org/documentation/integration-with-wordpress/ .

    So, if you now go through the template files for your bbPress installation, you will need to replace all instances of “<?php bb_get_header(); ?>” with the WordPress command “<?php get_header(); ?>”. The same thing goes for the footers, so you change all instances of “<?php bb_get_footer(); ?>” to “<?php get_footer(); ?>”.

    However, in order to get that to work properly, I have also edited my WordPress template so that the (WordPress) header and footer files contain everything except for the actual content that is going to be shown on the page. In other words, all the “container” DIV-elements and such are opened in the header and closed in the footer. While this is perhaps not absolutely necessary, it makes your life easier.

    Finally, I use a boolean check in the WordPress header to see whether I am serving a bbPress page, and modify the header information accordingly. While I currently set the boolean myself by including

    <?php global $forumpage;
    $forumpage = TRUE; ?>

    at the very beginning of each relevant bbPress template page (i.e. those pages that call the header files), fel64 has pointed out that one could simply use a variable that bbPress uses anyway, for example $bbdb.

    I use these checks to modify the title:

    <?php if ($forumpage == TRUE) {
    bb_title();
    echo " :.: AKN&amp;I";
    } else ...

    to add the forum feed:

    <?php if ($forumpage == TRUE) bb_feed_head(); ?>

    as well as do some other things (disable Ultimate Tag Warrior’s meta tags for the page, etc.).

    So, it takes a little bit of playing around with your templates, but in the end it is doable without any actual hackery.


    Vili
    Participant

    @vilimaunula

    Indeed, would save some work. :)


    Vili
    Participant

    @vilimaunula

    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>';
    }

    ?>


    Vili
    Participant

    @vilimaunula

    I have modified Dan’s Avatar Thingy to work on both WordPress and bbPress (the avatar is set in the WordPress user interface). It’s really rather easy to do.

    I actually also modified the plugin so that instead of always resizing an image to a certain size, it instead checks that the image is not bigger than X*Y, and only acts if it is.

    Tell me, if you are interested, and I can e-mail you the source for my modified Avatar Thingy. Note, though, that I made the modifications with my own website in mind, so it isn’t really an “out-of-the-box” solution, and you will most certainly need to do some coding to get it work for you (much depends on how exactly your bbPress is intergrated with WordPress).

    In reply to: Show off your Forum !!

    Vili
    Participant

    @vilimaunula

    Mine is at http://akirakurosawa.info/forums/ . I’ve done a little bit here and there, although more behind the scenes than with the theme.

    The installation is integrated with the rest of the site, which runs on WordPress. So much so, in fact, that I even ended up modifying a WordPress Avatar plugin so that I can use the same plugin for both WordPress and bbPress. (Although I don’t actually use it for the WordPress side at the moment.)

    The bbPress installation itself has the following plugins:

    – Allow images

    – Comment quicktags (with some modifications)

    – Display name (with some modifications)

    – Fix bbPress

    – Quote

    – WordPress Integration

    I’m adding things little by little as the users request new features.


    Vili
    Participant

    @vilimaunula

    I thought about having separate headers, but concluded that sweating blood and tears now is easier than having to remember later that I have near-identical info in two different places. But it is really up to your own preferences, I suppose.

    Now that I’m able to make WordPress recognize when it’s serving bbPress pages, I can also modify the sidebar and other design features accordingly on the fly, which I think is really quite nice.


    Vili
    Participant

    @vilimaunula

    Brilliant! I didn’t know that global variables like this exist in PHP (I’m a hobbyist). Thanks a bunch!

    Btw, I had to change the declaration from

    global $forumpage = true;

    to

    global $forumpage;

    $forumpage = true;

    It gave me an error otherwise.

Viewing 14 replies - 26 through 39 (of 39 total)