Web 2.0, Php, MySQL, HTML, CSS, Wordpress, Javascript, iTouch iPod, iPhone, Adobe…
23 Dec
Update: Andy has suggested to make these modifications a separate file to drop into the mu-plugins folder. This works like a charm, and perfect because you do NOT have touch ANY core files. I have attached the file called bp-social here. So drop this into the mu-plugins folder and you should see a new submenu appear in settings on a profile (just like my dropdown). Read the comments below this post.
I have been playing with the BuddyPress beta recently, and planning on focusing on it’s impact to Social Networking in 2009 on my socialnetworking.com blog.
In the meantime, i’m more focused on my personal blog on expanding on the code. First, you must have played already with BuddyPress to understand this. And if you want to try this, you must already have a good foundation in PHP. This is not a “drop a plugin and it works” deal.
From what i’ve discovered, you need to modify one file for basic settings but unfort. it’s a core file. bp-core-settings.php. I have made my own modified version here: bp-core-settings.php (You may download, but use it at your own risk… this should work if you replace the core file, but do this with care and backing up any files. Remember this is for learning only).
Notice that adding a submenu within settings is simple enough at the top of the file itself.
bp_core_add_subnav_item( 'settings', 'social', __('Social', 'buddypress'), $bp['loggedin_domain'] . 'settings/', 'bp_core_screen_social_settings', false, bp_is_home() );
If this is new to you, then you will probably have to take some time learning what the parameters mean and where BuddyPress is grabbing them. The important thing to note here is the displayed name (”Social”) and the php function it goes along with (”bp_core_screen_social_settings”).
Next, later in the same file, I simply duplicated the general settings, renamed the php functions (I kept the same naming convention but replaced “general settings” with “social” since I was attempting to create a social settings panel). Make sure the first function below matches the function you stated in the bp_core_add_subnav_item that we just talked about it, or it isn’t going to work. (Mine is “bp_core_screen_social_settings”). Here is my code:
/**** SOCIAL NETWORKING SETTINGS ****/
function bp_core_screen_social_settings() {
global $current_user, $bp_settings_updated, $pass_error;
$bp_settings_updated = false;
$pass_error = false;
if ( isset($_POST['submit']) && check_admin_referer('bp_settings_social') ) {
// Form has been submitted and nonce checks out, lets do it.
if ( $_POST['twitterusername'] != '' ) {
update_usermeta( (int)$current_user->id, 'twitterusername', $_POST['twitterusername'] );
$bp_settings_updated = true;
//$current_user->user_twitterusername = wp_specialchars( trim( $_POST['twitterusername'] ));
}
if ( $_POST['twitterpassword'] != '' && !strpos( " " . $_POST['twitterpassword'], "\\\" ) ) {
update_usermeta( (int)$current_user->id, 'twitterpassword', $_POST['twitterpassword'] );
$bp_settings_updated = true;
// $current_user->user_twitterpassword = $_POST['twitterpassword'];
}
}
add_action( 'bp_template_title', 'bp_core_screen_social_settings_title' );
add_action( 'bp_template_content', 'bp_core_screen_social_settings_content' );
bp_catch_uri('plugin-template');
}
function bp_core_screen_social_settings_title() {
_e( 'Social Networking Settings', 'buddypress' );
}
function bp_core_screen_social_settings_content() {
global $bp, $current_user, $bp_settings_updated, $pass_error; ?>
<?php if ( $bp_settings_updated && !$pass_error ) { ?>
<div id="message" class="updated fade">
<p><?php _e( 'Changes Saved.', 'buddypress' ) ?></p>
</div>
<?php } ?>
<?php if ( $pass_error && !$bp_settings_updated ) { ?>
<div id="message" class="error fade">
<p><?php _e( 'Your passwords did not match', 'buddypress' ) ?></p>
</div>
<?php } ?>
<form action="<?php echo $bp['loggedin_domain'] . 'settings/social' ?>" method="post" id="settings-form">
<label for="email">Twitter Username</label>
<input type="text" name="twitterusername" id="twitterusername" value="<?php echo $current_user->twitterusername ?>" class="settings-input small" />
<label for="pass1">Twitter Password (leave blank for no change)</label>
<input type="password" name="twitterpassword" id="twitterpassword" size="16" value="" class="settings-input small" />
<p><input type="submit" name="submit" value="Save Changes" id="submit" class="auto"/></p>
<?php wp_nonce_field('bp_settings_social') ?>
</form>
<?php
}
What is neat about this is that you can create basically any field for any settings you want to store with the update_usermeta() function. If the setting isn’t stored in the wp_usermeta table already, it gets created. If it’s already there, it gets overwritten.
This is not a complete tutorial, and it’s more or less my own personal notes in how i made this happen. But it does show that it is possible to expand BuddyPress to hold custom “settings” values for use elsewhere on the site. For example, I am trying to create a settings panel to hold social networking username/passwords (like for Twitter) and be able to use these elswhere on the user’s profile section. Perhaps the beginning of a custom BuddyPress livestream or social networking plugin.
Please make sure you know about the BuddyPress forums.
8 Jul
7 Jul
How To Make An IP-To-Country Tool With PHP and MySQL - Very handy tutorial for those who need to display (or not display) certain information depending on where the user is located.
3 Jul
More Fields Wordpress Plugin - Works with Wordpress 2.5+
26 Jun
Really nice collection of usable plugins here - wp-pools, wp-ban, wp-email, etc. If you do moderate work in Wordpress, bookmark this. Seriously.
18 Jun
This is a good technique that the big blogs do, and it’s helpful to see how you can apply this for your projects. Display a particular post and try to show related (by topic or author) posts or information to keep the user on the site.
20 Apr
If are trying to get somewhere with the Digg API, I highly recommend this tutorial on accessing the Digg API with PHP. Remember to save the php files as a CodeIgniter library so that you can call it like this:
$this->load->library('diggclass');
6 Apr
Andrew Hegdes created a PHP Function reference widget that provides fast lookup of information about the PHP web programming language. Just turned version one, and he’s looking for a little feedback. Haven’t seen anything like this yet, so bookmarking when i switch full time to Mac.
20 Mar
20 Mar
Dave over at mezzoblue tells us his method of giving users a choice if they are viewing a site on a mobile device or tv (Wii, Playstation, etc.). This is a useful tip, even for those with iPhones and iPod Touchs (iTouch).
19 Mar
Before considering building my own, I’m looking for php/mysql implentations of Yahoo Answers. So far, the best examples is Askeet built by the symfony Web PHP Framework. I’m going to give it a try, but always looking for alternatives.
17 Mar
Smart Image Resizer - Done in PHP. I’m usually not a fan of activating a script through an image tag:
<img src="/image.php/coffee-bean.jpg?width=200&height=200&image=/wp-content/uploads/2008/03/coffee-bean.jpg" alt="Coffee Bean" />
But the author claims “Built-in caching keeps image variations for optimal performance” and there is cropping, so I think this might be useful. Worth a look. [ via David W ]
14 Mar
Probably a no-brainer, but still I just saw this on a client site another night and thought how to Force A Secure Page Using PHP was a good tip.
if($_SERVER['SERVER_PORT'] != '443') { header('Location: https://'.$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']); exit(); }
11 Mar
8 Mar
PHP Client Library for our Address Book API. Seems practical for social networking applications.
The Address Book API allows for a user to import their email contact list (from Gmail, Yahoo!, AOL, and Hotmail) into any site. Our API is used on dozens of sites and applications, and is a way for users to invite friends to a site, share content with people in their address book, and import their social relationships.
2 Mar
Jaisen Mathai shows how he improved speed with PHP and .htaccess. There are endless schools of thought and execution on this, but worthy of a look.
16 Feb
This custom page slug plugin allows you to create a custom page slug then fill that page with any content (html, php, whatever) with “full access to the Wordpress and Plugin architecture”. This is nice for niche requests, although it’s minor coding without the plugin. Congrats to Leon.
11 Feb
Spellify is “an automatic text field spell checker” that’s available for download, with the following requirements:
- PHP 4+ with CURL library installed (developed using PHP 4.4.6)
- script.aculo.us 1.8.0 (only effects.js and scriptaculous.js required)
- Prototype JavaScript Framework 1.6.0
10 Feb
While i’m on the topic of Google Maps, I decided to bookmark Pamela’s other article which is more like an introduction on how to use Google Maps with a MySql database. Related article - Using PHP and MySQL to create KML.
9 Feb
Google Grabber: “Using a short amount of PHP code, you can query Google to retrieve the number of pages your domain has listed in Google.”
9 Feb
This topic comes up frquently enough to warrant a bookmark to Pamela Fox’s how-to on a Store Locator with PHP, MySQL & Google Maps. Being on the Google Geo APIs Team, i can’t wait to dive into this.
8 Feb
I’ve bumped into PHP scripts like this before, but haven’t bookmarked them until now.
7 Feb
I’m horrible in math. So I hope I never have to figure out how to select a random, weighted element from an array in PHP. But if I do, I now have something to refer to! Thanks Jesse!
6 Feb
Chyrp appears to be a light weight blogging engine, done in PHP/mySQL (some Ajax) and is “loosely based on the MVC design pattern.”. It’s been recently upgraded. I don’t like the fact you need to give an email for a live demo, but at least you can download the code.
Chyrp is a blogging engine designed to be very lightweight while retaining functionality. It is driven by PHP and MySQL (with some AJAX thrown in), and has a pimpin’ theme and module engine, so you can personalize it however you want.
John Gruber picked up on this (and so did i) that Cameron Hunt switched from Tumblr to Chyrp, an interesting endorsement.
4 Feb
You may think with “125.125.1.1″, you would want a VarChar type of field. That would be my first instinct until this tip made me think. If you are storing an IP Address in MySql (or any database for that matter) it’s better to store it as an Integer. MySQL has two built-in functions: INET_ATON() and INET_NTOA() to convert the IP. This allows for better storage and possible indexing.
3 Feb
I’m bookmarking this sample Facebook application with CodeIgniter mainly for the CodeIgniter aspect since i’m not really an active Facebook user. Still interesting, and worth a look.
3 Feb
Although it looks like there are plugins that accomplish this, it’s nice to know how to highlight author or admin comments in a Wordpress blog using the oldschool approach of php and css.
3 Feb
The fact that CodeIgniter 1.6 has hit the streets has got me excited about this php framework again. One or two new client projects will be built with this version in the coming weeks. I especially like how you can extend the helpers, but the biggest thing of all is that a CodeIgniter 2.0 might be in our future since development is accelerating.
PHP4 is still supported, and I would agree with that thinking since PHP5 is not yet everywhere in the shared hosting universe.
31 Jan
This is a bugger to figure out - basically I was using php to read a varchar value in a SQL database. Problem was, my returning value was cut off at around 255 or 256 characters. Even changing the mssql.textlimit and mssql.textsize values in the php.ini file didn’t help. The answer, it seems, is to preform a little conversation in your SQL SELECT statement:
select *, convert(text,bio) as bio from writers
So if “bio” is the field that is in the SQL database than contains more than 256 characters, the above should give you ALL those characters back.
29 Jan
FancyUpload looks very cool. Basically a great graphical way to upload multiple files (there’s even a php script for the actual uploading and validation). Not sure if this is currently being maintained, but if you are looking for a decent uploader this might be the answer. Platform and server independent, just needs Flash 8+. Plus you can limit uploads by file count and/or file size.
27 Jan
Stumbled on these, and I wanted to get them in my bookmarks for my fellow coders. Parsing ITunes Library.xml with ActionScript 3.0 and plist parsing in PHP.
22 Jan
Leon Chevalier claims to have created a PHP class that can “Improve website load time by 500%”. Although someone in the comments is correcting that figure to 80%. Regardless, it takes 3 lines of code to include and use. Bookmarking to later try.
21 Jan
PhpDelicious is a library for accessing the del.icio.us API. Recently upgraded so it’s now PHP 5 only, has an improved (more robust) HTTP request method, etc.
17 Jan
According to Derek Allard, CodeIgniter 1.6.0 “beta” is available and he’s giving a hint for additional (and bigger) updates in the near future. I’m glad to hear this, since CodeIgniter is my favorite PHP framework. Can’t wait to take a crack at it.
16 Jan
phpMyID is a “single user (though, if you were so inclined, you could easily turn it into a multi-user setup) IdP, or Identity Provider for the OpenID framework.” Just been updated to version 0.7. [ via full-speed ]