Compare with Previous | Blame | View Log
#!/usr/local/php5/bin/php -q
<?php
/**
* JaikuGUI.php - A primitive GUI client for updating Jaiku.com presence.
*
* Mac OS X only.
*
* Requires PHP5 - modify executable location on the first line of this script.
*
* Jaiku bits require class.jaiku.php (see http://ruk.ca/w/index.php/Class.jaiku.php)
*
* GUI bits require installation of Pashua (see http://www.bluem.net/downloads/pashua_en/)
* Move the Pashua executable into your Applications folder so that the script can find it.
*
* Once you're configured, make this script executable:
*
* chmod +x JaikuGUI.php
*
* and then you're ready to run:
*
* ./JaikuGUI.php
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
* @version 0.2, December 22, 2006
* @author Peter Rukavina <peter@rukavina.net>
* @copyright Copyright © 2006, Reinvented Inc.
* @license http://www.fsf.org/licensing/licenses/gpl.txt GNU Public License
*/
// Include the required class.jaiku.php code to drive the Jaiku bits.
require_once("/Users/peter/Code/JaikuCode/JaikuPHP/class.jaiku.php");
// Create a class.jaiku.php object -- change to match your Jaiku username and password and your "Jaiku name" -- the XXX part of your personal XXX.jaiku.com URL.
$j = new Jaiku("username","password","jaikuname");
// Dialog box definition (modeled on the Pashua example code)
$conf = <<<EOCONF
# Set transparency: 0 is transparent, 1 is opaque
*.transparency=0.95
# Set window title
*.title = Jaiku Presence Updater
# Introductory text
txt.type = text
txt.default = This is an experimental OS X client that lets you set your Jaiku.com presence from the desktop. See http://ruk.ca/wiki/Class.jaiku.php for more information.
txt.height = 276
txt.width = 310
# Add a text field
message.type = textfield
message.label = Presence message:
EOCONF;
// Grab the current presence information
$j->GetPresence();
$conf .= "message.default = " . html_entity_decode($j->message,ENT_QUOTES) . "\n";
$conf .= "message.width = 310\n";
$conf .= "# Add a text field\n";
$conf .= "location.type = textfield\n";
$conf .= "location.label = Location:\n";
$conf .= "location.default = " . html_entity_decode($j->location,ENT_QUOTES) . "\n";
$conf .= "location.width = 310\n";
$conf .= "pop.type = popup\n";
$conf .= "pop.label = Presence icon\n";
$conf .= "pop.width = 310\n";
// Add the various Jaiku icons as pop-up list options
foreach ($j->icons as $keyword => $value) {
$conf .= "pop.option = " . $keyword . "\n";
}
// The default icon -- I arbitrarily selected the "speech bubble" one, but you could have anything here.
$conf .= "pop.default = speechbubble\n";
$conf .= "cb.type=cancelbutton\n";
# Pass the configuration string to the Pashua module
$result = pashua_run($conf);
// If we didn't press "Cancel" then we go ahead and update our presence.
if (!$result['cb']) {
$j->GetJaikuSession();
$j->UpdatePresence($result['message'],$result['location'],$result['pop']);
}
// Everything below as taken directly from the Pashua example code without modification.
/**
* Wrapper function for accessing Pashua from PHP
*
* @param string Configuration string to pass to Pashua
* @param optional string Configuration string's text encoding (default: "macroman")
* @param optional string Absolute filesystem path to directory containing Pashua
* @return array Associative array of values returned by Pashua
* @author Carsten Bluem <carsten@bluem.net>
* @version 2005-04-26
*/
function pashua_run($conf, $encoding = 'macroman', $apppath = null) {
// Check for safe mode
if (ini_get('safe_mode')) {
die("\n Sorry, to use Pashua you will have to disable\n".
" safe mode or change the function pashua_run()\n".
" to fit your environment.\n\n");
}
// Write configuration string to temporary config file
$configfile = tempnam('/tmp', 'Pashua_');
$fp = fopen($configfile, 'w') or user_error("Error trying to open $configfile", E_USER_ERROR);
fwrite($fp, $conf);
fclose ($fp);
// Try to figure out the path to pashua
$bundlepath = "Pashua.app/Contents/MacOS/Pashua";
$path = '';
if ($apppath) {
// A directory path was given
$path = str_replace('//', '/', $apppath.'/'.$bundlepath);
}
else {
// Try find Pashua in one of the common places
$paths = array(
dirname(__FILE__).'/Pashua',
dirname(__FILE__)."/$bundlepath",
"./$bundlepath",
"/Applications/$bundlepath",
"$_SERVER[HOME]/Applications/$bundlepath"
);
// Then, look in each of these places
foreach ($paths as $searchpath) {
if (file_exists($searchpath) and
is_executable($searchpath)) {
// Looks like Pashua is in $dir --> exit the loop
$path = $searchpath;
break;
}
}
}
// Raise an error if we didn't find the application
if (empty($path)) {
user_error('Unable to locate Pashua', E_USER_ERROR);
}
// Call pashua binary with config file as argument and read result
$cmd = preg_match('#^\w+$#', $encoding) ? "'$path' -e $encoding $configfile" : "'$path' $configfile";
$result = `$cmd`;
// Remove config file
unlink($configfile);
// Init result array
$parsed = array();
// Parse result
foreach (explode("\n", $result) as $line) {
preg_match('/^(\w+)=(.*)$/', $line, $matches);
if (empty($matches) or empty($matches[1])) {
continue;
}
$parsed[$matches[1]] = $matches[2];
}
return $parsed;
} // function pashua_run($conf)
?>