How to build a contact manager in AIR using XML
Great starting tutorial for those wanting to learn Flex/AIR
Bulk Upload Users to Joomla
I have to say this saved my life, totally awesome. Bulk Upload
<?php
/*
Script to bulk import users into a Joomla installation (v 1.5.7).
This script is free to use, modify and distribute,
however is comes with absolutely no guarantees!
Be careful and check everything in here before running
it on your installation - has little to no error checking and is
in no shape or form robust…
And of course MAKE A BACKUP OF YOUR DATABASE BEFORE YOU BEGIN.
That said, I do hope it is useful, Paul.
paul@paulferrett.com
*/
// Hande form upload
if(isset($_POST['import'])) {
$mysql_host = trim($_POST['mysql_host']);
$mysql_user = trim($_POST['mysql_username']);
$mysql_password = trim($_POST['mysql_password']);
$mysql_schema = trim($_POST['mysql_schema']);
$table_prefix = trim($_POST['table_prefix']);
if(!mysql_connect($mysql_host, $mysql_user, $mysql_password) || !mysql_select_db($mysql_schema)) {
echo ‘Supplied MySQL details were incorrect - aborting’;
return;
}
// Get the joomla groups
$sql = sprintf(‘
SELECT `id`, `value`
FROM `%score_acl_aro_groups`
‘,
$table_prefix
);
$rs = mysql_query($sql);
$groups = array();
while($group = mysql_fetch_object($rs)) {
$groups[$group->value] = $group->id;
}
$fp = fopen($_FILES['csv']['tmp_name'], ‘r’);
while($user = fgetcsv($fp)) {
printf(‘Importing ”%s” … ’, $user[0]);
// Lookup and verify user group
if(!isset($groups[$user[4]])) {
printf(‘error: Invalid group (%s) for %s. Defaulting to <code>Registered</code><br />%s’, $user[4], $user[0], PHP_EOL);
$user[4] = ‘Registered’;
}
// Insert record into wsers
$sql = sprintf(‘
INSERT INTO `%susers`
SET
`name` = ”%s”,
`username` = ”%s”,
`email` = ”%s”,
`password` = ”%s”,
`usertype` = ”%s”,
`block` = ”%s”,
`sendEmail` = ”%s”,
`gid` = ”%s”,
`registerDate` = NOW(),
`lastvisitDate` = ”0000-00-00 00:00:00″,
`activation` = ”",
`params` = ”"
‘,
$table_prefix,
sql_prep($user[0]),
sql_prep($user[1]),
sql_prep($user[2]),
isset($_POST['md5_passwords']) ? md5($user[3]) : sql_prep($user[3]),
sql_prep($user[4]),
sql_prep($user[5]),
sql_prep($user[6]),
$groups[$user[4]]
);
mysql_query($sql);
// Get back ther user’s ID
list($user_id) = mysql_fetch_row(mysql_query(‘SELECT LAST_INSERT_ID()’));
// Insert record into core_acl_aro
$sql = sprintf(‘
INSERT INTO `%score_acl_aro`
SET
`section_value` = ”users”,
`value` = %d,
`name` = ”%s”
‘,
$table_prefix,
$user_id,
sql_prep($user[0])
);
mysql_query($sql);
// Insert record into core_acl_groups_aro_map
$sql = sprintf(‘
INSERT INTO `%score_acl_groups_aro_map`
SET
`group_id` = %d,
`aro_id` = LAST_INSERT_ID()
‘,
$table_prefix,
$groups[$user[4]]
);
mysql_query($sql);
echo ‘done.’;
flush();
}
echo ‘<br /><br /><strong>Done</strong>’;
} else {
// show upload form
?>
<html><head><title>Bulk import users into Joomla 1.5</title></head><body>
<h1>Import Users to Joomla</h1>
<p>
Use this script to do a bulk import of users into Joomla 1.5.<br />
Upload a CSV file with the following format:<br />
<code>
name, username, email, password, usertype, block, send_email
</code><br />
Wrap details with commas in them in quotes.
</p>
<hr />
<form action=”<?php echo $_SERVER['PHP_SELF'] ?>“ method=”post” enctype=”multipart/form-data”>
<input type=”hidden” name=”import” value=”1″ />
<table cellpadding=”4px”>
<tr>
<td>CSV File: </td>
<td><input type=”file” name=”csv” /></td>
</tr>
<tr>
<td>MD5 Hash Passwords: </td>
<td><input type=”checkbox” name=”md5_passwords” /><br /><small>*Check this option if the passwords in your CSV are in plain text</small></td>
</tr>
<tr>
<td>Joomla Table Prefix: </td>
<td><input type=”text” name=”table_prefix” value=”jos_” /></td>
</tr>
<tr>
<td>Joomla Database Name: </td>
<td><input type=”text” name=”mysql_schema” value=”joomla” /></td>
</tr>
<tr>
<td>MySQL Host: </td>
<td><input type=”text” name=”mysql_host” value=”localhost” /></td>
</tr>
<tr>
<td>MySQL Username: </td>
<td><input type=”text” name=”mysql_username” value=”" /></td>
</tr>
<tr>
<td>MySQL Password: </td>
<td><input type=”text” name=”mysql_password” value=”" /></td>
</tr>
<tr>
<td></td>
<td><input type=”submit” name=”submit” value=” Import Users! ” /></td>
</tr>
</table>
</form>
</body></html>
<?php
}
function sql_prep($var) {
return mysql_real_escape_string($var);
}
Joomla Unique Menus for Guests and Registered Users
I’ve been doing a lot of Joomla development lately, in particular for a site that has a public and private side.
I was looking for a solution that would allow me to have unique menus for guests vs registetered users and found a way to do it with help from the following articles.
Joomla - Change login link to logout
Joomla 1.5 Template Positions - for this article I used the section for adding new module positions since the first article doesn’t cover that.
Hope this helps!
CSS Float Theory Things You Should Know
This article is kind of old, but the concepts explained within hold true. Use them, know them, love them, practice them!
http://www.smashingmagazine.com/2007/05/01/css-float-theory-things-you-should-know/
Code to Extract Plain Text from PDF
I have been hunting for a solution to this forever and finally found it here
The solution is below.
<?php
// new pdf extract
print pdf2txt("test.pdf");
// Function : pdf2txt()
// Arguments : $filename - Filename of the PDF you want to extract
// Description : Reads a pdf file, extracts data streams, and manages
// their translation to plain text - returning the plain
// text at the end
// Author : Jonathan Beckett, 2005-05-02
function pdf2txt($filename){
$data = getFileData($filename);
// grab objects and then grab their contents (chunks)
$a_obj = getDataArray($data,"obj","endobj");
foreach($a_obj as $obj){
$a_filter = getDataArray($obj,"<<",">>");
if (is_array($a_filter)){
$j++;
$a_chunks[$j]["filter"] = $a_filter[0];
$a_data = getDataArray($obj,"stream\r\n","endstream");
if (is_array($a_data)){
$a_chunks[$j]["data"] = substr($a_data[0],strlen("stream\r\n"),
strlen($a_data[0])-strlen("stream\r\n")-strlen("endstream"));
}
}
}
// decode the chunks
foreach($a_chunks as $chunk){
// look at each chunk and decide how to decode it - by looking at the contents of the filter
$a_filter = split("/",$chunk["filter"]);
if ($chunk["data"]!=""){
// look at the filter to find out which encoding has been used
if (substr($chunk["filter"],"FlateDecode")!==false){
$data =@ gzuncompress($chunk["data"]);
if (trim($data)!=""){
$result_data .= ps2txt($data);
} else {
//$result_data .= "x";
}
}
}
}
return $result_data;
}
// Function : ps2txt()
// Arguments : $ps_data - postscript data you want to convert to plain text
// Description : Does a very basic parse of postscript data to
// return the plain text
// Author : Jonathan Beckett, 2005-05-02
function ps2txt($ps_data){
$result = "";
$a_data = getDataArray($ps_data,"[","]");
if (is_array($a_data)){
foreach ($a_data as $ps_text){
$a_text = getDataArray($ps_text,"(",")");
if (is_array($a_text)){
foreach ($a_text as $text){
$result .= substr($text,1,strlen($text)-2);
}
}
}
} else {
// the data may just be in raw format (outside of [] tags)
$a_text = getDataArray($ps_data,"(",")");
if (is_array($a_text)){
foreach ($a_text as $text){
$result .= substr($text,1,strlen($text)-2);
}
}
}
return $result;
}
// Function : getFileData()
// Arguments : $filename - filename you want to load
// Description : Reads data from a file into a variable
// and passes that data back
// Author : Jonathan Beckett, 2005-05-02
function getFileData($filename){
$handle = fopen($filename,"rb");
$data = fread($handle, filesize($filename));
fclose($handle);
return $data;
}
// Function : getDataArray()
// Arguments : $data - data you want to chop up
// $start_word - delimiting characters at start of each chunk
// $end_word - delimiting characters at end of each chunk
// Description : Loop through an array of data and put all chunks
// between start_word and end_word in an array
// Author : Jonathan Beckett, 2005-05-02
function getDataArray($data,$start_word,$end_word){
$start = 0;
$end = 0;
unset($a_result);
while ($start!==false && $end!==false){
$start = strpos($data,$start_word,$end);
if ($start!==false){
$end = strpos($data,$end_word,$start);
if ($end!==false){
// data is between start and end
$a_result[] = substr($data,$start,$end-$start+strlen($end_word));
}
}
}
return $a_result;
}
?>
Slow iPhone Sync Fix
I know I’m not the only one to have experienced this. If you’ve been experiencing long iPhone sync times this ones for you.
Anyway today I was syncing mine to prepare it for loading the 2.2 firmware. I rarely sync my phone because it routinely takes over an hour to do so. Frustrating at best!!
I jumped in the shower figuring my phone could sync while I got ready. By the time I was done getting ready the damn thing was STILL syncing… Actually it appeared stuck in the backup phase. I’ve seen this before and knew if I waited long enough it would eventually finish but I had to get to work.
Being the master Googler I am, I quickly found others with the same issue and a solution! A very simple solution.
1. Connect your phone and open
iTunes.
2. Right click your phone name in the
left column list.
3. Click “reset all warnings”
4. Now reconnect your phone
and sync. When the prompt comes
up to ask if you want to send data
to Apple uncheck the checkbox and
say no!
5. Voilà ! Few minute sync and in your
way.
Apparently the bog down a caused by the connection to Apple Servers with so many users. I don’t know if that’s true but it’s what I read.
Hope it helps!!
Dreamweaver PHP Blank Line Replace
If you’ve ever opened a php file with the FTP in Dreamweaver only to have it add tons of blank lines…this one’s for you.
1. Open the find and replace (ctrl+f)
2. In the find box type:
[\r\n]{2,}
3. In the replace box type:
\n
4. Check the box for use regular
expression.
5. Then click the replace all button.
This has worked like a charm for me. For whatever reason Dreamweaver is adding carriage returns to the code. This regex looks for two or more occurances of the carriage return together and replaces them with a line feed.
Hope this helps!
10 Useful Techniques to Improve Your User Interface Designs
Great tips. Check it out. 10 Useful Techniques to Improve Your User Interface
Blizzcon 2008 Photos
It was to my great excitement, that I got to attend Blizzcon 2008 in Anaheim this year.
I took Ashten with me, was such a blast! We met up with several of my guildmates.
Matt “Gutz” came from Texas, then we had Brett “Sao”, Ryan “Meecrab”, Kent “Hayward”, and Kody “Cyrotic” who all live in SoCal.
We went to Knott’s Scary Farm the first night, then the convention on Fri and Sat.
Brutal Gladiator War Staff
I’m off to Blizzcon 2008 this week in Anaheim so in preparation I’m doing some cosplay. My costume is ready now I’m making the Brutal Gladiator War Staff. The in game item that the staff is based on, is pictured below Ashten and Ryan.


