Posts Tagged ‘hacks’

July 28, 2010 | Getting P2 to Auto Update

Posted by joebeaudoin at 1:25 am | Permalink | Comments (0)
Topics: How-To,Programming,g33k | Tags: , , , , , , , ,

On certain servers that do not run PHP 5.2 or higher, the Auto Update feature of the P2 WordPress theme—which was recently implemented by FrakMedia! Productions for internal communications between all its workers—does not work. A quick run-down: the P2 theme is for micro-blogging. It is basically micro-blogging meets Twitter meets web forums, on Red Bull.

Now, “auto update” means that whenever you post something it will show up automatically (using AJAX and JSON), so you do not have to refresh the browser page.

In internally testing this, FrakMedia!’s PR coordinator Jon recently pointed this out to me, and I set out to find the problem. And it has a solution, which is highlighted in this thread on WordPress’s support site. It fixes the auto update problem when it comes to posting new threads, but it doesn’t deal with updating when replies to threads are posted.

So, you only need to fix one file. That file is p2/inc/ajax.php and need to be modified thusly:

1. At line 4, add:

require (ABSPATH . WPINC . ‘/class-json.php’);

define('DOING_AJAX', true);
@header('Content-Type: text/html; charset=' . get_option('blog_charset'));
require (ABSPATH . WPINC . '/class-json.php');

2. Starting at line 207, we need to change how the JSON encode is called. Here’s the block that you’ll need to make the changes to:

nocache_headers();
echo json_encode( array(
    'numberofnewposts' => $number_of_new_posts,
    'html' => $posts_html,
    'lastposttime' => gmdate('Y-m-d H:i:s')
) );

The following highlighted lines (lines 207 and 209) are the changes that need to be made.

$json = new Services_JSON();
nocache_headers();
echo $json->encode( array(
    'numberofnewposts' => $number_of_new_posts,
    'html' => $posts_html,
    'lastposttime' => gmdate('Y-m-d H:i:s')
) );

This solves the issue with auto updating any newly started threads only, not any replies to said threads. That’s the next step.

3. At line 318, remove this line:

echo json_encode( $json_data );

And add this block of code:

$json = new Services_JSON();
nocache_headers();
echo $json->encode( $json_data );

Once you’ve saved the file and uploaded it to your server, or edited through your WordPress dashboard’s editor (Appearance -> Editor), then this problem will be fixed. Simply refresh your browser, and start making things happen.

Important Note: As with any other theme, whenever you install an update from the publisher for said theme you will be overwriting any changes you made to the code. So make sure that you modify the code again after the update to reproduce the modifications noted in this article! Do keep in mind that should the files from said update be totally recoded, the above code may or may not work as intended. (The lines may not be there or may have moved to an entirely new file, for instance, and other fun stuff like that.)

July 20, 2010 | How-To: Easily Create “Previous” and “Next” Links for the Organize Series Plugin

Posted by joebeaudoin at 1:54 am | Permalink | Comments (0)
Topics: How-To,Programming,g33k | Tags: , , , , ,

For the new website I’m developing (you can see a clearly unfinished, work-in-progress preview of it here), I am using the Organize Series plugins designed for WordPress. That plugin is designed to organize a bunch of blog posts into a series, like a series on hot women in the Marvel universe. For my purposes, I needed to organize the lots under one specific auction, with navigation links in the sub-menu. (See this.) I ran into a problem when needing to create separate links for articles within the series. Basically, I had no way to dynamically call the unique id number associated to the series, and found I’d have to hardcode it.

I went to Google and ran a search, discovering that I was not alone in having this problem. Further, there was no apparent solution offered.

So I decided that I would have to hack the code by creating two new functions: one to create a “previous” link and the other a “next” link. These new functions would tie into the function (called wp_series_nav) that was already present to generate the links—although it did not possess the means to actually grab the dynamic series ID without a bunch of effort.

So I went to the source file (series-template-tags.php) and modified it to create these two functions:

  • wp_series_nav_prev()
  • wp_series_nav_next()

It’s a real quick hack, and you’ll need to add these functions before the wp_series_nav() function that’s located around line 609.

function wp_series_nav_prev($customtext = FALSE, $display = FALSE) {

	wp_series_nav($series_ID, $next = FALSE, $customtext, $display);

}

function wp_series_nav_next($customtext = FALSE, $display = FALSE) {

	wp_series_nav($series_ID, $next = TRUE, $customtext, $display);

}

… and that’s it! Now you’ll be able to add the new functions to your blog’s page template. Cool, eh?

Important Note: As with any other plugin, whenever you install an update from the publisher for said plugin you will be overwriting any changes you made to the code. So make sure that you modify the code again after the update to reproduce the modifications noted in this article! Do keep in mind that should the files from said update be totally recoded, the above code may or may not work as intended. (The lines may not be there or may have moved to an entirely new file, for instance.)

July 19, 2010 | Quick Hack for the “Login with Ajax” WordPress Plugin

Posted by joebeaudoin at 1:41 pm | Permalink | Comments (3)
Topics: How-To,Programming,g33k | Tags: , , , ,

This is the result of having to deal with a client who had issues with the Login with Ajax plugin for WordPress. The client basically had this problem.

In any event, I wanted to modify the plugin so that when an administrator or editor is logged in, they’ll be able to access their site’s WordPress Dashboard from the Login with Ajax widget.

Simple enough fix there that took all but three or so minutes to implement and test, once I figured out how the plugin worked.

In the widget_in.php file, you add:

global $user_level;

As you see below:

<div id="LoginWithAjax">
	<?php
		global $current_user;
		global $user_level;
		global $wpmu_version;
		get_currentuserinfo();
	?>

Now, that calls the variable we need to identify the user’s level (see: WordPress Codex). To put it to good use, and to print out that dashboard link, you need to make the following highlighted change to line 42.

if( !empty($wpmu_version) || $user_level > 8 ) {

So the new code block should look like this:

		//Blog Admin
		if( !empty($wpmu_version) || $user_level > 8 ) {
		?>
		<a href="<?php bloginfo('wpurl') ?>/wp-admin/"><?php _e("blog admin", 'loginwithajax'); ?></a>
		<?php
		}

And that should do it! Now you’ll have a link leading back to your dashboard, so you can blog at will!

Important Note: As with any other plugin, whenever you install an update from the publisher for said plugin you will be overwriting any changes you made to the code. So make sure that you modify the code again after the update to reproduce the modifications noted in this article! Do keep in mind that should the files from said update are totally recoded, the above code may or may not work as intended. (The lines may not be there or may have moved to an entirely new file, for instance.)

May 13, 2010 | How-To: Hack LightboxThumbs Extension for MediaWiki

Posted by joebeaudoin at 9:43 pm | Permalink | Comments (0)
Topics: Battlestar Galactica,How-To,Programming,g33k | Tags: , , , , ,

As with most everything that is released for MediaWiki or WordPress, I invariably have to modify it to suit the needs of the projects I work on. I find that nothing works quite right “out of the box.” In the interests of people who run into this same issues, I’ve decided on a new track for my website (in addition to just being a general place to vent, sorry!) where I tell you how I frakking fix things. Hopefully, this will help some hapless bloke who faces similar problems with extensions and programs that I run into as well—and who knows, I may just need your help someday. Scared yet? More to read…

Twidddle, Twaddle, Twitter, Twatter

Tweets for twats.

XBox Live

Gaming for geeks.

Friends Blogs

Check out my friends's blogs as well.