Jan 11
13
I don’t post to it any more, but I shall, at some point in future, consider resurrecting it.
One of the sites I work on has recently been suffering private message spam, ranging from fake market research to child porn. Needless to say this needed solving, and since I couldn’t disable private messaging, there was only one option, and that was to only allow Buddypress friends to send private messages to each other.
The is a “bug” in Buddypress that allows any user to send a private message to any other user simply by entering the username in the “to” field of the compose message form. This isn’t an obvious flaw since the ajax function that shows the available users as you type in the box does indeed only show your friends.
I looked all over the web for a solution, but the only one I found, a hack at that, wasn’t compatible with the version of BuddyPress I’m using. There was only one thing for it, and that was to roll my sleeves up and sort it myself.
The solution I came up with, while not the most elegant, works.
This may vary slightly depending on your version of BuddyPress, so instead of offering line numbers, I’ll explain where in the code you need to look. Don’t worry, you only have to edit a single file with just a few lines.
The file you want is /wp-content/plugins/buddypress/bp-messages/bp-messages-classes.php
Annoyingly, because I hate doing this, there are a few classes in the same file, so you need to find “class BP_Messages_Message”
In there is the method, “send”.
Quite near to the top of that method is the line “if ( $this->thread_id ) {”
That is instructing the code to take a different path is the “message” already exists, i.e., somebody is replying to an existing thread. We don’t want to change this, so look for the else component of that if statement; it should be marked with the comment “// Create a new thread.”
Directly under that, paste this code.
foreach ($this->recipients as $recipientName)
{
$recipientId = get_user_id_from_string( $recipientName );
if (!friends_check_friendship($bp->loggedin_user->id,$recipientId))
{
return false;
}
}
Save the file, upload it to your site, and you’re done. Users can now only send a message to their friends.
The only downside to this is that the failure message isn’t ever so elegant. Rather than giving the reason for the failure, it simply says that sending the message failed. This shouldn’t be a problem for normal users though, if anything it just makes the spammers life a little more confusing, which I’m sure we can all agree is a good thing.
So there you go, that’s how to prevent spam private messaging within BuddyPress.
Mar 10
2
Although in hindsight this is DEAD easy, I’ve just had a bit of a hard time finding out how to do it, so I thought I’d make a quick post which will hopefully get indexed by Google and save some other folk the hard time I had. Thoughtful, eh.
So, to enable the slow query log in WAMP is as simple as adding
log-slow-queries=PATH to your config file.
The config file is located in your wamp installation directory, under bin/mysql/mysql.version/my.ini
In there you will find an entry for standard logs, which will look something like log-error=c:/wamp/logs/mysql.log
Add the slow query flag, and change the log file name to something like log-slow-queries=c:/wamp/logs/mysqlslow.log
Restart wamp, and you’re done.
Oct 09
8
Further to my last post about the quality of code in certain well known PHP projects, I just stumbled across this fantastically pointless finger spew.
function the_title($before = '', $after = '', $echo = true) {
$title = get_the_title();
if ( strlen($title) == 0 )
return;
$title = $before . $title . $after;
if ( $echo )
echo $title;
else
return $title;
}
How entirely pointless that is, indeed, it gets worse, the entire thing is bloody well restrictive.
$title = get_the_title(); goes off and gets the title, but it adds HTML to it. I just want to get the title, but instead I end up getting <span blah blah>TITLE</span>.
Very poor code folks, and I think the naming conventions for the functions are not even worth commenting about… oh go on, I can’t resist “the _title”? Nice and descriptive, ain’t it.
The thing is, I cannot understand why somebody would have done this. It’s just adding code that is in no way required. I think you’ll find that this particular program is riddled with dodgy designs, or lack thereof, like this, and if it was just coded properly in the first place, I dare say it would run considerably quicker, not to mention making the lives of us developers infinitely easier.
Sep 09
30
Right, I don’t know why I’m suddenly getting loads of comments on this, but I’ve deleted this entire post. This blog is dead, and has been for years. This post was written in 2009!
I use Wordpress. My company uses Wordpress. I recommend Wordpress. Wordpress serves a purpose, and it saves me time, but it’s written like shit and a nightmare to work with. That’s just the way it is. It’s life. Move on.
Comments closed.
Feb 09
20
I had a bit of a hard time getting Zend Framework to run on my 1&1 hosting. It was all down to the .htaccess file in the end. The default htaccess configuration in the ZF getting started guide just doesn’t work, and neither did all the other posts I could fine on the subject around the internet, however, I’ve finally cracked it.
Presuming you’ve put your ZF index file in the webroot, here’s what the 1and1 htaccess file should look like.
AddHandler x-mapp-php5 .php
AddType x-mapp-php5 .php
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(txt|swf|js|ico|gif|jpg|png|css|xml)$ /
Note: The same file will not work on my local dev machine, which is running only PHP5. You will need to comment out the first two lines (AddHandler, AddType) to get it to run on a stadard PHP5 installation.
I was having a bit of a problem with TinyMCE not loading in Zend Framework (ZF). It turns out the .htaccess file was not configured correctly. It was redirecting .js to the index bootstrap and causing the page to fail to load.
The solution was the htaccess file as so…
Options -MultiViews
RewriteEngine On
RewriteBase /website
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(txt|swf|js|ico|gif|jpg|png|css|xml)$ /website/
Feb 09
16
I run another blog, although it’s hosted on wordpress.com rather than my domain, here.
The blog is about my boat, ‘Kudu’. It’s a 21ft Corribee – a sailing yacht – and we are planning some substantial voyages toghether. Anyway, the other evening I got an excited facebook message from a friend saying my blog was listed on the wordpress.com’s Blog Of The Day stat’s page. I had the 7th fastest growing blog on all of wordpress. I was ecstatic about it. The 7th fastest growing blog on all of wordpress!
I awoke in the morning to find I was no longer 7th, but 1st. I was shocked. I had THE fastest growing blog on all of wordpress, which means I had one of the fastest growing blogs on the entire internet at that point in time. Sadly it was short lived, I’ve since dropped off the list, but to sustain the sort of growth I was seeing was never going to happen.
Feb 09
16
I decided to rebuild my home page since it was originally done as little more than static pages. Ok, I used a bit of PHP to include headers and footers and do a couple of other litte things, but it was nothing clever.
Since it is trying to promote me as a developer, I thought I should apply a bit more effort than that. It turns out, I failed. I used Zend Framework to rebuild the site, and it just made everything even easier and less effort. From form validation to displaying my twitter feed, I had the lot built in about 4 hours, well, excluding the other 4 hours it took me trying to figure out how to get Zend Framework working with 1and1’s hosting.
Jan 09
16
I’m just giving some link love here since a friend of mine has just launched a new project.
Cardsmart.co.uk is a credit card comparison service and it went live about 3 minutes ago at the time of writing. It’s quite exciting to see the birth of a brand new company, it’s quite a refreshing change given all of the dying one’s that are around at the moment.
As I recall, they’ve got about 250 credit card offers on the site, which compared to money supermarket is a HUGE selection.
So there you have it, if you are in the market for a new bit of plastic check out the site.
JP, you owe me a beer.