Posts Tagged ‘PHP’

Twitter Widget 1.2.3

Monday, January 18th, 2010

A minor change in 1.2.3:

  • Fixed issue with special characters.

http://www.ronakpatel.net/2009/04/05/twitter-widget-that-streams-multiple-accounts/

Twitter Widget 1.2.2

Monday, January 11th, 2010

The widget has gone through a lot of under the hood changes in 1.2.2:

  • Completely rewritten. Should make the widget load faster.
  • Handle errors more gracefully.
  • Filter by multiple hashtags.
  • As of this version the widget is under the LGPL v3 License.

http://www.ronakpatel.net/2009/04/05/twitter-widget-that-streams-multiple-accounts/

Twitter Widget 1.2.1

Thursday, November 12th, 2009

Fixed a bug with characters not being escaped. Thanks Jeff (@jeff_uprising).

http://www.ronakpatel.net/2009/04/05/twitter-widget-that-streams-multiple-accounts/

Twitter Widget 1.2

Thursday, July 16th, 2009

The Twitter Widget now caches tweets using the PEAR package Cache_Lite. Follow the instructions in the link below.

http://www.ronakpatel.net/2009/04/05/twitter-widget-that-streams-multiple-accounts/

Twitter widget that streams multiple accounts

Sunday, April 5th, 2009

I created a PHP/JavaScript widget that will stream multiple Twitter accounts for a friends website (see it in action at Brown Girl Magazine). It’s simple to setup. As of version 1.2.2 you will need to setup the widget again.

Requirements

  • PHP 5.0
  • PEAR – Cache_Lite 1.7.7 (It might work with newer or older versions but I haven’t tested it.)
  • Javascript turned on

Instructions

  1. Install the PEAR package Cache_Lite. Most web hosts have an easy way of installing new PEAR packages. If you have issues with PEAR, create a directory called Cache within the directory you create in step 4, download Cache_Lite and put the contents (Lite.php and Lite directory) of Cache_Lite in it. Post any questions in the comments.
  2. Download TwitterWidget_1_2_3.zip. Unzip the contents to a temporary directory.
  3. Open Config.php and edit the configuration parameters. There is an explanation for each parameter.
  4. Create a directory where ever you like on your web server and upload all the files.
  5. Copy the following html and javascript into your website right before where the body tag (</body>) is closed.
    <script type="text/javascript"><!--
     var RPNetTwitterAttrs = {
      url: 'http://localhost/TwitterWidget/reboot/TwitterWidget.php'
     };
    // --></script>
    <script type="text/javascript" src="TwitterWidget.js"></script>

    Update the url attribute to the path where you uploaded TwitterWidget.php.

    You will also need to update the src=”TwitterWidget.js” attribute to point to where you uploaded the javascript file. For example, src=”http://yourwebsite.com/uploads/TwitterWidget.js”.

  6. Copy the following html into your website where you would like the widget to appear.
    <div id='rpnetTWContainer'></div>

Editing the Look and Feel

There are two ways to change how the widget looks. The first is to add the CSS ids below to your stylesheet. The outline of the widget is as follows:

<div id="rpnetTWContainer">
 <div id="rpnetTW">
  <h2 id="rpnetTWTitle"></h2>
  <ul id="rpnetTWList"></ul>
 </div>
</div>

The second way is to go into the createWidget() function in the RPNetTWView class in TwitterWidget.php and edit the html of the widget. Post any questions in the comments.

Remember

If you make changes to how the widget looks or you modify the Config.php after setting up the widget you will either need to wait until the cache expires or you will need to go into your cache directory and delete the cache file for changes to take effect.

Upgade Instructions

From 1.2.1 to 1.2.2.

  1. Record the changes made to Config.php.
  2. Start with Step 2 of the 1.2.2 instructions.

From 1.2.2 to 1.2.3.

  1. Overwrite all PHP, JavaScript, and text files except Config.php.

What it will not do

This widget will not worked on locked Twitter accounts.

Below is a screen shot of the widget with no formatting and with the Arthemia WordPress theme. If using WordPress the widget will conform to whatever theme you have unless you modify the CSS.  Enjoy!

Change Log

Version 1.2.3

  • Fixed issue with special characters.

Version 1.2.2

  • Completely rewritten. Should make the widget load faster.
  • Handle errors more gracefully.
  • Filter by multiple hashtags.
  • As of this version the widget is under the LGPL v3 License.

Version 1.2.1

  • Fixed bug with unescaped characters.

Version 1.2

  • Tweets are now cached.

Version 1.1

  • Added an option for displaying user images.

Version 1.0

  • Displays list of tweets from multiple users.

Old Versions

How to: Add a text and date field to WP-PHPList

Sunday, March 22nd, 2009

WP-PHPList is a great plugin for WordPress that integrates PHPList with WordPress. It allows you to add a newsletter subscription form to any WordPress page. Currently the plugin only supports one text and email field in the form. I needed extra functionality for a friends website so I decided to make additions to the plugin. The following guide and code will show you how to add another text field and a date field. This is not a straight forward guide. I will explain the changes I made to each function, but you must look at the code to understand it. An understanding of PHP code is recommended. My comments for the changes are in the code and are prefixed with “ronak”.

Changes are made to version 1.5 of the plugin.

Also, the code disables the subpanel created in WordPress and all configuration is done through the code. You can change this if you like.

Download Code

Design

  • The design is fairly simple. User input is taken in, validation is done on the input, and cURL is used to POST the input to the same page that the PHPList subscription page POSTs to.
  • The code comprises of some global variables and functions. I don’t necessarily agree with the design of the plugin, but it works great.

Variables (Note: These are not all the variables used, only the one I edited.)

  • $phplist_strings - This global variable  is an array that holds the html for each field in the form. Just follow the code to add more fields.

Functions (Note: These are not all the functions used, only the ones I edited or created)

  • generate_date_input($o, $day, $month, $year) – I created this function to create the html for the date fields. It takes an array of options ($o) returned by phplist_get_options() which I will get to soon and $day, $month, $year (ranges: 1-31, 01-12, and 1925 – current year respectively). If any of those three variables are set then that field will be selected with that value. If any of the three variables are equal to an empty string, then that part of todays date is used. This is used for keeping the values you selected persistant when an error or invalid input is triggered.
  • phplist_subscribe($input_data) – This function takes in the data from the subscription form POST, formats the data, and performs the cURL POST. I made modifications to how array data is formatted in the POST since the original code did not deal with dates.
  • phplist_get_options() – This function returns the options for the form. The changes made to this function add options for new fields and also disables the loading of options from the subpanel page.
  • phplist_check_input() – This function validates user input. I added validation for the added text field and I’ve also added persistence for the date field since the page is reloaded when invalid input is entered.
  • phplist_construct_form() – This function creates the newsletter subscription form. The form has been redesigned.

The changes I made are not complicated and I feel that they are easily decipherable. Post any questions in the comments.

Download Code