CodeIgniter is an awesome PHP Web Framework with a light footprint and just easy to use. Despite that its easy to use, we still run into problems and errors when we get deep in the trenches of testing our applications.
PhpConsole is a developer tool for Google Chrome by Barbushin Sergey which, when installed, will output PHP errors and debugging in the Chrome console, and/or by way of notification popups. This is a pretty handy tool and its uses can certainly be applied to any PHP application your writing for the browser. However in this instance I’m going to show you how to throw it up into CodeIgniter quite easily.
First goto https://chrome.google.com/webstore/detail/nfhmhhlpfleoednkpnnnkolmclajemef in Chrome and install PhpConsole. In the description on that page you’ll see the google code repository link for PhpConsole (and Lagger as well), click the code repo link and then download the .zip file in the downloads section.
Extract the .zip file and place PhpConsole into the root of your CodeIgniter application, right next to index.php
Next open that index.php file and at the very top add the following lines:
require_once('PhpConsole.php');
PhpConsole::start();
And there you have it, test some errors in your codeigniter application and they will show up in Chrome to help you get rid of those frustrating ones
Hope this helps!
chrome, code, debugging, PHP, plugin
I recently installed the WordPress plugin Jetpack, which puts together some fabulous WP plugins into a bundle. The problem I was having was that Sharedaddy, one of the available bundled plugins, was not being shown in my posts. So I started looking around in the WP plugin forums, and really didn’t find a solution. I almost felt like I had to contact ‘support’ in order to get this working because a lot of the threads posted had such replies.
Anyways, after a little fiddling around and a tip in a thread about a function, I decided to go ahead and code it into my themes functions.php file.
If this breaks your WordPress – don’t blame me, I will attempt to be as clear as possible.
First open up your themes functions.php file, and open up the file at jetpack/modules/sharedaddy/sharing-service.php
If you’re familiar with the functions.php file, you know that this file has functions and miscellaneous stuff related specifically to your theme. The sharing-service.php file has PHP classes which set up the Sharedaddy services for use.
In your functions.php file create a new function for use within the theme. You can name the function anything you want. Go ahead and use this code.
function show_sharing($text = '') {
include(ABSPATH . 'wp-content/plugins/jetpack/modules/sharedaddy/sharing-service.php');
static $shared_with_posts = array();
global $post;
$server = new Sharing_Service;
$global = $server->get_global_options();
if ( !is_feed() ) {
if ( $global['show'] == 'posts' && ( is_single() || is_page() ) )
$show = true;
elseif ( $global['show'] == 'index' && ( is_home() || is_archive() || is_search() ) )
$show = true;
elseif ( $global['show'] == 'posts-index' && ( is_single() || is_page() || is_home() || is_search() || is_archive() ) )
$show = true;
}
$switched_status = get_post_meta( $post->ID, 'sharing_disabled', false );
if ( !empty( $switched_status ) )
{
$show = false;
}
// Only show once
if ( isset( $shared_with_posts[$post->ID] ) )
$show = false;
$shared_with_posts[$post->ID] = true;
$sharing_content = '';
if($show)
{
$enabled = $server->get_blog_services();
if ( count( $enabled['all'] ) > 0 ) {
global $post;
$dir = get_option( 'text_direction' );
// Wrapper
$sharing_content .= '<div class="snap_nopreview sharing robots-nocontent">';
$sharing_content .= '<ul>';
// Visible items
$visible = '';
foreach ( $enabled['visible'] AS $id => $service ) {
// Individual HTML for sharing service
$visible .= '<li class="share-'.$service->get_class().' share-regular">';
$visible .= $service->get_display( $post );
$visible .= '</li>';
}
$parts = array();
if ( $global['sharing_label'] != '' )
$parts[] = '<li class="sharing_label">'.$global['sharing_label'].'</li>';
$parts[] = $visible;
if ( count( $enabled['hidden'] ) > 0 )
$parts[] = '<li class="share-custom"><a href="#" class="sharing-anchor">'._x( 'Share', 'dropdown button', 'jetpack' ).'</a></li>';
if ( $dir == 'rtl' )
$parts = array_reverse( $parts );
$sharing_content .= implode( '', $parts );
$sharing_content .= '<li class="share-end"></li></ul>';
if ( count( $enabled['hidden'] ) > 0 ) {
$sharing_content .= '<div class="sharing-hidden"><div class="inner" style="display: none;';
if ( count( $enabled['hidden'] ) == 1 )
$sharing_content .= 'width:150px;';
$sharing_content .= '">';
if ( count( $enabled['hidden'] ) == 1 )
$sharing_content .= '<ul style="background-image:none;">';
else
$sharing_content .= '<ul>';
$count = 1;
foreach ( $enabled['hidden'] AS $id => $service ) {
// Individual HTML for sharing service
$sharing_content .= '<li class="share-'.$service->get_class().'">';
$sharing_content .= $service->get_display( $post );
$sharing_content .= '</li>';
if ( ( $count % 2 ) == 0 )
$sharing_content .= '<li class="share-end"></li>';
$count ++;
}
// End of wrapper
$sharing_content .= '<li class="share-end"></li></ul></div></div>';
}
$sharing_content .= '<div class="sharing-clear"></div></div>';
}
}
echo $sharing_content;
}
Ok. Basically this function recreates another function found in the sharing-service.php file called sharing_display(), except that it is trimmed up for our purposes…I repeat – dirty hacks. :p
Now that you have a new function in your theme that rebuilds the Sharedaddy services bar, you can add it to any part of your theme with
Celebrate by sharing this link with others
Arras, function, hack, Jetpack, PHP, Sharedaddy, template, theme, Wordpress
This little snippet was originally used in a small CodeIgniter library I wrote which would fetch my most recent tweet, the source of the tweet, and the amount of followers I currently had.
//Change the value of $user to your Twitter username
$user = 'yourusername';
$ch = curl_init('http://twitter.com/users/show.xml?screen_name='.$user);
//We are going to open/create a local file to write our fetched data to it.
$fp = fopen('/'.$user.'.xml', "w");
//Set cURL options for our file, not to write the XML header
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, false);
//Excecute cURL
curl_exec($ch);
//Lets close up these functions
curl_close($ch);
fclose($fp);
//This is the location of the user.xml file
$file = '/'.$user.'.xml';
//Here we call PHP's SimpleXMLElement Class to handle the .xml file
$xml = new SimpleXMLElement($file, NULL, TRUE);
//Simply declare that $path is an array that contains all of node
$path = $xml->xpath('/user');
//create an array of the elements in the xml file we want to display
foreach ($path as $node)
{
$status = array('time' => $node->status->created_at,
'text' => $node->status->text,
'source' => $node->status->source,
'followers' => $node->followers_count);
}
print_r($status);
cURL, PHP, snippet, twitter, XML