The following code added to the bottom of P2′s functions.php will allow P2 to send email notifications to all other responders in a comments thread.

// PluginBuddy Email Notification Patch for P2
// by Dustin Bolton on September 10, 2010.
// http://pluginbuddy.com http://dustinbolton.com
add_action( 'comment_post', 'email_notification' );
function email_notification( $comment_id ) {
	$emails = array();
	$comment = get_comment( $comment_id, ARRAY_A );

	// Get emails of all responders.
	$comments = get_comments( 'post_id=' . $comment['comment_post_ID'] );
	foreach( $comments as $this_comment ) {
		if ( $this_comment->comment_author_email != $comment['comment_author_email'] ) { // Only add emails that are not this comment poster.
			array_push( $emails, $this_comment->comment_author_email );
		}
	}

	$emails = array_unique( $emails ); // Strip all duplicate email addresses.

	// Get email address of thread starter to strip them from receiving replies since that is automatic in P2.
	$original_post = get_post( $comment['comment_post_ID'], ARRAY_A );
	$original_poster = get_userdata( $original_post['post_author'] );
	$emails = array_diff( $emails, array( $original_poster->user_email ) ); // Remove from array.

	// Send emails.
	foreach( $emails as $this_email ) {
		wp_mail( $this_email, 'P2 thread updated!', "There has been an update to a thread you posted in by " . $comment['comment_author'] . " on " . $comment['comment_date'] . ":\n\n" . $comment['comment_content'] );
	}
}
// End PluginBuddy Email Notification Patch.
Categories : Uncategorized
Comments (0)

A friend of mine posted this on their Facebook. Very nice.

“The number one killer of young Americans is the automobile. However, the Secular Humanists dominating our schools refuse to acknowledge that the only safe driving is abstinence from driving. Instead, they advocate courses in “Driver Education,” in which teenagers are taught “Safe Driving,” and no attention is given to traditional values. They are even taught the use of “Seat Belts” (and some classes even give explicit demonstrations of the proper method of applying these belts!) with, at best, a passing mention that the protection provided by these belts is only partial. Clearly, this sends a mixed message to our young people: it appears to condone driving, and the more inquisitive will surely feel encouraged to experiment with driving.” [Original Source]

Categories : Politics, Stupidity
Comments (0)

Submit unchecked checkbox value

I had never noticed before that submitting a form with unchecked checkboxes in it results in those checkboxes not being sent to the server at all. I had always assumed that a zero ( 0 ) would be sent for unchecked since a one ( 1 ) is sent when checked. Rather than add code to specifically handle these individual checkboxes, you can just add hidden inputs above the checkboxes in the HTML with a value of zero like this:

<input type="hidden" name="box1" value="0" /> <input type="checkbox" name="box1" value="1" />

This is a much simpler solution that doesn’t require writing any additional code or sending an array of checkboxes. I chose this method since I was using an automated Settings saver in PHP so it would be a pain to modify it and it could make the code more dirty.

Thanks to iamcam for writing about this.

Categories : Programming
Comments (0)

James Lankford: A quick review

A lot of people I know are fans of James Lankford. He’s Christian and a big name in Oklahoma so he’s pretty set. Here are my impressions of his views from his website. This is quickly thrown together with no citations, spell-checking, or proof-reading. I may or may not come back and spruce things up.

Energy

For the security and prosperity of our country, we must allow more drilling, refining and distribution of American oil and natural gas.

The moratorium on drilling in the Gulf of Mexico must be lifted. Every energy company cannot be punished for the mistake of one company. There are thousands of safe wells in the Gulf and they should continue to function for our energy future and economic stability.

The moratorium on drilling is not blocking the functionality of existing wells. The moratorium is on drilling, not pumping oil. Drilling as in using a giant drill to dig deeper into the earth to reach out for oil. Hundreds of rigs in the Gulf are pumping oil while only three or so are drilling. Why on Earth would you try to protect more deep-water drilling knowing that we have obsolutely no technology to handle an emergency situation? There is not enough oil in the Gulf, or anywhere in the country for that matter, for our growing energy needs. We will run out eventually and pushing for more drilling is not a real solution and actually expedites the problem. Here is an MS paint graph to show you our problem:

Nuclear, wind, solar, hydro-electric and other energy options should be encouraged through regulatory reforms, rather than increased subsidies.

Wind, solar, geothermal, hydroelectric all show great promise for the distant future.

I do agree that these energy options must be encourages. However regulation reform is not sufficient. Oil is cheap and alternative energy sources will not be affordable until the price of oil has risen to reflect its coming scarcity. Subsidies provide funding to adopt these technologies before it is too late and we are scrambling. The view that we can further way to convert is sad and will only make transitions more difficult and costly in the future. Oil is not abundant and ever-flowing.

Family a.k.a. I don’t want to blatanty mention this is about homosexuality

At the heart of many of the problems facing our country stands an institution under siege. That institution is the American family.

I agree that the American family is failing — but not because of what Mr. Lankford is alluding to: gay marriage. The divorce rate is through the roof and it’s not because of an infiltration of rainbows. Plain and simple the government has no right to interfere in relationships as it is blatant discrimination to legally discriminate on legal contracts based on gender. There is no gray area here. It’s discrimination. The government must either allow same-sex marriages or not recognize opposite-sex ones, which I believe to be the best option as it removes the government from what is at heart a religious ceremony & contract. Additionally the idea that families are “under attack” is juvenile and only further plays off fear and ignorance.

Families must continue to be honored and protected.

Firstly, a family is not a mother, father, son, and daugter. This idea of ‘normalcy’ only serves to instill fear of things that are different. There is no normal and I don’t want the government forcing it’s idea of what’s normal upon me, my friends, or my family.

Financial

Congress should audit the Federal Reserve and privatize Fanny Mae and Freddie Mac. If “big banks” operate in a manner that puts their company at risk, they should be allowed to “fail” so they could reorganize in bankruptcy under new leadership.

I absolutely agree with this. The problem with our current government is that it’s not even capitalist anymore, it’s corporatist.

Healthcare

I do not have the responsibility to dictate for other people the choices they make in their lives.

Why is this not said on the ‘Families’ page?

In the past few months, a small group in the federal government decided that because 10% of the country does not have health care insurance (some of them by their choice), 100% of Americans must change their health insurance.

I am sincerely saddened by this quote for a multitude of reasons. 10% of Americans without health care coverage is 10% too many and those of that 10% that are uninsured by choice aren’t doing so because they don’t want coverage, they do so because it is too expensive for them to consider being worth it. This helps create more of a problem as the uninsured get ill or avoid going to the doctor or hospital when they need to and then others get stuck with absorbing the costs. I find it terribly troubling that so many in the Christian community are perfectly fine with this. They will fight tooth and nail to pay a penny to help pay for the less fortunate to be helped. This isn’t Christian, this just makes you a horrible human being. Secondly, the recent laws passed do no such thing as Mr. Lankford states where “100% of Americans” will need to change their health coverage. This is blatantly false. If you have coverage, it stays the same. Simple yet it’s still being spun here to instill fear.

The same Democrat party that talks on and on about a “woman’s right to choose” what to do with her body just told every man and woman in America when, where, and how they can get health care.

They did not tell anyone when, where, or how they can get healthcare that already has insurance. The health bill unfortunately was gutted beyond recognition (by the Republican extremists) and altered so they are now mandating all citizens be covered or purchase coverage from private corporations. This STILL doesn’t involve telling them when, where, or how they can get health care- only health insurance. A huge benefit to the new health care laws however is the removal of the whole pre-existing conditions mess which will save lives and actually allow people to purchase health insurance that previously could not.

The federal government is working to limit the number and role of insurance companies when we should be removing the barriers so that we have more companies and more competition.

I agree that if we are going to have for-profit health insurance companies that people need to be able to shop around and have options and also the ability to transfer to other plans and companies. Currently everyone is pretty much locked in.

We should encourage individuals to start their own health savings accounts (HSA). These allow people to buy catastrophic insurance and to put their money into a HSA so they can spend it for health care as they wish.

Unfortunately HSA’s do nothing to solve the problem. A single diagnosis can bankrupt families. Normal Americans cannot come close to affording the cost from tragic diagnosis by saving up, and insurance companies can easily drop them or cite pre-existing conditions prior to recent laws. Also unfortunately, many people are poor, despite what Mr. Lankford may think. When it comes between putting food on the table and healthcare, most will cut out the healthcare. This puts further strain on our system. Healthcare coverage is a social issue and would do best with everyone paying into the same system and without the overhead of profit. This is why a single payer system would work best. Everyone would keep their system doctors and hospitals but the insurance company wouldn’t be taking a cut of the money. Unfortunately however those better off financially don’t want to pay for help the poor. How is that a Christian stance here in Oklahoma?

Immigration

Copy-pasta from a comment left by a visitor on his site:

“We cannot bail out every inefficient government in the world by taking on their economic refugees.”
-James Lankford

“When an alien resides with you in your land, you shall not oppress the alien. The alien who resides with you shall be to you as the citizen among you; you shall love the alien as yourself, for you were aliens in the land of Egypt: I am the Lord your God.”
-God.

I understand we can’t take on everyone. This just isn’t feasible. However this outright hunt and dehumanization of immigrants is a scary way to approach this. Recent bills to ban healthcare to pregnant immigrants or block healthcare to an immigrant having a baby our outlandish. Strangely enough those most adamently against abortion are also for blocking an immigrant having a baby from receiving healthcare. Are immigrants not humans now? It all seems to be based on fear.

“Thank you , you are right! Something must be done about uninvited nonworking aliens not to mention terrorist coming over our border. Some have the argument that there are jobs that Americans won’t do that aliens will. Most of these picking and farm jobs can be handled by Americans if given the economic incentive and machinery. The aliens are cutting down on American inventivness to create solutions to labor problems.” – Site visitor

Obligatory “They took our jorbs!!!”

National Security

Our security budget is insane. We have enough nukes to blow up the entire planet multitudes over. Why must we always live in so much fear?

Second Amendment

I agree with Mr. Lankford here. If guns are banned then only the government and criminals will have guns. (and if you keep your gun, you have become a criminal.)

Spending

Stop spending so much money!

I concur. Spend less and when you do spend, spend wisely.

Taxes

I certainly agree that our current tax system is a mess and is full of loopholes. There is an entire industry surrounding filling out taxes.

Categories : Politics, Rants
Comments (0)

Incongruity

Comment posted by macemoneta over at Slashdot: “The problem for many people is the incongruity between how they were raised and reality. People are generally raised to believe that people are good, that there are norms of behavior, there is justice in the world, authority figures can be trusted, things happen for reason and are overseen by an omnipotent deity. As we grow up, we learn that these are simply convenient lies that define our society.

When presented with conflicting visual evidence, we can be shocked and damaged – our world view is broken. Some go into denial (classifying the content as depravity), and some go into depression (recognizing that society is simply a veneer). Education and experience over time tends to break these falsehoods more gently, incrementally.”

Categories : Uncategorized
Comments (0)

I discovered a few days ago that my Visa credit card from Capital One had expired but I never got a new card in the mail. I finally got around today to signing in online to request a new card. I saw that I could create a custom personalized card with the image of my choice on it. Clicking on this feature popped up a new window (tsk tsk) for me to begin the process. I accidently closed this evil popup at one point and thought I could just start over creating a card. WRONG! Apparantly their system is so poorly coded that once you begin you can’t start over for THREE HOURS.

Oops…
We’re sorry but it looks like you have recently visited the Image Card site. Please close this browser window and return to the original.

If you’ve already closed the original window, you will need to wait 3 hours before returning to the Image Card site. We’re sorry for the inconvenience.

Dear Capital One: It’s 2010.

Categories : Fail, Rants
Comments (0)

Disable post revisions in WordPress 3.0

I recently had a customer that had ~70,000 revisions on posts on his WordPress site. This caused his database to skyrocket to 400mb+. I discovered the cause of these revisions to be the plugin FeedWordpress. FeedWordPress was triggering WordPress to create massive amounts of revisions. Because of this the plugin I wrote, BackupBuddy, could not back up his site without running into PHP timeout issues. In this post is the solution I used to resolve this problem.

In the root directory of your WordPress installation, open wp-config.php in a text editor and insert the following line on a new line somewhere between the top ( looks like ) lines of the file:

define('WP_POST_REVISIONS', false);

Running the following SQL (change wp_ to your prefix) in phpmyadmin will clear out all revisions:

DELETE a,b,c
FROM wp_posts a
LEFT JOIN wp_term_relationships b ON (a.ID = b.object_id)
LEFT JOIN wp_postmeta c ON (a.ID = c.post_id)
WHERE a.post_type = 'revision';

Finally, run the following SQL query to optimize (clean up) your posts table:

OPTIMIZE TABLE wp_posts;

Categories : Uncategorized
Comments (0)

One of the requested features for Typity.com was the ability to navigate links in the textarea without having to highlight, copy, and paste them into the user’s browser URL input. I thought it would be simple to code some javascript to parse the URL around the cursor’s position. I was sadly mistaken. The methods and properties for textarea are a ridiculous mess and very non-standard. After a ton of trial and error, Googling for hours, and reading tons of documentation, I was able to piece together the following code. Keep in mind that I am very new to javascript. This could probably be done much better and may have bugs though it seems to be working fine so far. It seems as if absolutely no one has been able to get this to work before so I figured I should share it with the rest of the internet.

View source code with tabs and spacing intact [typity.com].

/*
* MicroSwift graburl() (C) Copyright 2009 MicroSwift.com. All Rights Reserved.
* Created exclusively for use on Typity.com by Dustin Bolton
* Leave these top 3 lines if using this on your own site or editing, please.
*
* Last updated: 7/17/09. Now works in FF & Internet Explorer.
*
* EXAMPLES:
* graburl(textareaobject)
* Returns the url found touching the user’s current cursor position.
* User may have to click first in the area sometimes. Not sure of a workaround
* Only tested in firefox so far!
* I hate textarea javascript… textarea is designed so poorly and inconsistent.
*
*/

function graburl(o) {
if (o.setSelectionRange) {
o.focus();
caret=o.selectionStart; // Set initial caret position when clicked.

// Find beginning of url
i=caret;
linestart=-1;
while(i>0) {
charcode=o.value.substring(i-1,i).charCodeAt(0);
if ((charcode==10)||(charcode==32)) { // If line feed or space, reached left border
linestart=i;
i=-1; // branch out
}
i=i-1;
}
if (linestart==-1) { linestart=0; } // Hit BOF

// Find end of url
i=caret;
lineend=-1;
while((i0)) {
charcode=o.value.substring(i-1,i).charCodeAt(0);
if ((charcode==10)||(charcode==32)) { // If line feed or space, reached left border
lineend=i-1;
i=-1; // branch out
}
i++;
}
if (lineend==-1) { lineend=o.value.length; } // Hit EOF

url=o.value.substring(linestart,lineend);
} else if (o.createTextRange) { // Internet Explorer
r=o.createTextRange();
r.moveToPoint(window.event.x, window.event.y);
//r.expand(“character”);
r.moveStart(‘character’,-1);
// Start at cursor and go left until we hit a space or weird character.
i=0;
leftline=”;
done=false;
while( (i>-9999)&&(done==false) ) {
r.moveStart(‘character’,-1); // Step caret left one position (move START first!!!)
r.moveEnd(‘character’,-1); // Step caret left one position
if ( (r.text.charCodeAt(0)==32) || (isNaN(r.text.charCodeAt(0))) ) {
done=true;
} else {
leftline=r.text+leftline;
i=i-1;
}
}
// Move cursor back to original point.
i=i*-1;
r.moveEnd(‘character’,i); // Step caret right one position (move end FIRST!!!)
r.moveStart(‘character’,i); // Step caret right one position
// Start at cursor and go right until we hit a space or weird character.
i=0
rightline=”;
done=false;
while( (i<9999)&&(done==false) ) {
r.moveEnd(‘character’,1); // Step caret right one position (move end first)
r.moveStart(‘character’,1); // Step caret right one position
if ( (r.text.charCodeAt(0)==32) || (isNaN(r.text.charCodeAt(0))) ) {
done=true;
} else {
rightline=rightline+r.text;
i++;
}
}
url=(leftline+rightline);
}
// url=suspected url. Check it for http and stuff…
if ( (url.substring(0,7).toLowerCase()==’http://’) || (url.substring(0,8).toLowerCase()==’https://’) || (url.substring(0,5).toLowerCase()==’ftp://’) ) {
return url;
} else {
return ‘error’;
}
}

Categories : Programming
Comments (0)

I have been shocked by the beliefs and ignorance of church leaders many times (though no longer surprised) throughout the years.  Organized religion seems to be a breeding ground of fear, hate, and ignorance; though one may argue that these are willful attributes and they are only hiding their beliefs behind their religion for use as justification.  It’s certain that not everyone involved in the church are like this, but unfortunately a great number are.  This is why so much of the rest of the world is so shocked by many of the beliefs held by many in our country.  Much of it just doesn’t make logical sense.  It’s like much of the country is now propelled and driven by emotion and ignorance rather than logic and sound thinking and the church is part of the driving force behind this.

About a year ago I ‘friended’ the youth group leader on Facebook from the church I went to several years ago.  Today I posted the following to Twitter which was mirrored to my Facebook status.

In case you haven’t read about the RNC 2004 mass arrests of peaceful protesters (not an isolated incident)… http://www.2600.com/rnc2004/

The youth group leader, which I later learned is now the pastor of the church, made this reply:

And it’s obtuse willfully ignorant posts like this one that has helped me make the decision to remove you from my friend list. You just keep on acting like republicans have a monopoly on questionable behavior. What about the Black Panthers “patroling the polls” in 2008? How about the ACORN wingnuts and their general lack of regard for the law? … See MoreMaybe you should look into the kkk’s roots in the democratic party and their stated goal to appose the encroachment of blacks Jews Catholics the GOP and other such “undesirables.” To act like either party is innocent of injustices is willfully ignorant. Goodbye and enjoy your trip through the arrogance of youth.

Categories : Rants
Comments (0)