Archive for the ‘PHP’ Category

I thought I’d be spending a few hours creating a nice reusable way to turn a flat query result into a hierarchial array so I could use it on things like trees or HTML or whatever. When I wrote it out on paper though I felt stupid because the solution was extremely simple.

Assume you have a query result or data like this:
container1 parentA child11
container1 parentA child12
container1 parentB child13
container2 parentC child14
container2 parentC child15
and so on.

every column represents a parent of the column to its right. Duplicates in the columsn let you know which things get grouped together. The solution to turn this into a hierarchy is:

$arrTree[container][parent][child]

you can follow the same pattern indefinately, change the values and the keys as needed. The simplicity in the solution is that by using the columns as the keys it automatically creates them as unique and puts the children under them correctly. I hope this save someone else the paper epiphany :)

24
Nov

PHP CRUD template for jqGrid

   Posted by: admin

I have been using the JQuery for quite a while. JQuery does not have an official plugin for grids, there are several of them out there. I tried out a few and settled on jqGrid   I am very pleased with it in every way. I’ve used it in several projects and it’s always been very flexible and extendable for my needs. I’ve been able to easily add after effects like color sorting, drag and drop reorder etc. with ease. Writing the PHP for the typical CRUD (Create Read Update Delete) functions is very easy but is so boring that I had to do SOMETHING that would both give me a bit of fun and give me smoething to make this part of the process faster for me in the future. So I have a .php template here with it, I can change a few variables around and apply it to any MySQL operation that interacts with jqGrid.

define

$crudColumns =  array(
    ‘id’=>‘id’
    ,‘title’=>‘title’
    ,‘icon’=>‘icon’
    ,‘description’=>‘description’
    ,‘parent’=>‘parent_list_id’
);
$crudTableName = ‘list’;
$postConfig[‘id’] = ‘id’;

and it’ll create the select, search, paging, insert, update, delete interactions for jqGrid for you.
it also has some convenient spots to edit the sql for additional column / query manipulation. At a minimum it should serve as a good starting point for working with jqGrid beyond the examples they provide (Which are very good and helpful already). If you have any updates or suggestions for this please let me know.
-enjoy

12
Nov

SimplePie RSS Feed library

   Posted by: admin

SimplePie is a PHP development library for reading RSS. It’s amazingly simple, well documented and full featured. I have written 4 RSS readers for portals and virtual desktops using it, and it’s alsways been a pleasure to work with. Here is the link:

http://simplepie.org/

When would you use this? Anytime you want to pull an RSS feed into a page for a decision or display. Almost everything has an RSS feed. You can pull in multiple feeds, have them automatically cached and aggregated, and choose a sort method. It will also automatically find RSS feed URLs if you give it a URL to any site. Combine this with something like Dapper: http://www.dapper.net/ and there’s no limit to what you can integrate into your project!

Here’s some sample code to show how easy SimplePie is:

<?php
require_once(‘SimplePie/simplepie.inc’);

$feed = new SimplePie(array(‘http://suddendevelopment.com/?feed=rss2′,‘http://LegalizeThought.com/?feed=rss2′));
$feed->handle_content_type();

$htmlOut = ;
//====|| Get RSS items for feed||====\\
foreach ($feed->get_items() as $item){
$htmlOut .= ‘<div class="rssItem">’;
$htmlOut .=    ‘<div class="rssTitle"><a href="’.$item->get_permalink().‘">’.$item->get_title().‘</a></div>’;
$htmlOut .=    ‘<span class="rssDescription">’.$item->get_description().‘<br></span>’;
$htmlOut .=    ‘<span class="rssDate">’.$item->get_date(‘j F Y | g:i a’).‘</span>’;
$htmlOut .= ‘</div>’;
}
print $htmlOut;

?>
 

This was a fun little solution I thought was worthy of sharing.

The Problem: You have a  very large grid. you need to display it on one page, but when you scroll you loose sight of the headers.

The solutions: Create separate tables for the headers, put them in containers that hide the overflow, and use slidersto control the scrolling.

Demo: http://anthong.com/examples/scrollxy/

References: http://demos.flesler.com/jquery/scrollTo/  http://docs.jquery.com/UI/Slider

Enjoy,

-Anthony

27
Oct

eyeOS: More than another framework.

   Posted by: admin

I have been working with eyeOS lately. I hacked around with some of the existing components, and developed one of my own. I can tell you that after researching every “Web Desktop” and “Virtual Desktop” I could find reference to, this is the best one that you can download and manipulate under an open source license. This project is unique in its approach. They have merged the use of PHP with javascript to seamlessly complement each other and create an actual OS on a web platform. One thing I noticed right away as I started developing with it, is that this team concentrated on creating systems that would be beneficial to having a web environment rather than a bunch of web apps throw together. For example, each running module or “eyeApp” is assigned a serialized process ID which can be used to kill the process, or Identify it. There is a lot of work that needs to be done on it depending on your application for it. The windowing system is done very well but all of the eye candy is not as rich as something like extjs. The PHP is clean and very innovative, but there are many core features that it lacks (Like native DB support). Since I started working with it, I have run across many more projects that are in the same area and I’m still very happy that I chose to go through the learning curve on this one. Here is a summary review to compare with other products: 0-10 style

  1. Cost: Free (Under an Open Source License)
  2. Features: 7
  3. Presentation: 8
  4. Code maturity: 8
  5. Documentation: 4
  6. Community:8
  7. User learning curve: 30 minutes
  8. Developer Learning curve: 3 days

If you have huge $$ to blow and want a commercial product to invest in instead of spending development time customizing eyeOS I recommend checking out the Laszlo webtop.

8
Oct

PHP tech mashup: CURL + Tidy + XMLParser

   Posted by: admin

I have been working on some very challenging projects recently that require retrieving remote pages, manipulating them and then sending them back to the user. There are several problems with this scenario:

  1. Due to a bunch of greedy and malicious hacks, many of the obvious and easier techniques are blocked by necessary security measures.
  2. Whenever you deal with outside code you don’t know what you’re going to get. It could be half formed, have all kinds of javascript workarounds, rely on frames in frames etc.
  3. Relative URLs. If you retrieve a remote page and display it locally, any relative URLs will be off, so links will be broken and image will not show. This also applies to stylesheet and script references.

Here’s the solution in a nutshell:

  1. Use CURL http://us3.php.net/manual/en/ref.curl.php to retrieve the remote page.
  2. Use Tidy http://us3.php.net/manual/en/ref.tidy.php to put the code into a proper XHTML format. This will close tags, give you predictable formatting, make it very easy to read the source and most importantly put it in a format that can be parsed as XML.
  3. Parse the XML using xml_parse http://us3.php.net/manual/en/function.xml-parse.php This is a wonderful function! I have spent hours coding XML parsing functions that recurse, save parents etc. This is a much more efficient method (Depending on your task) it creates 2 arrays, 1 for an index, and one for values. You can use the index to find what position you need in the values array and get any info you need.
  4. Manipulate the cleaned up HTML. Since you have XHTML to work with now you can manipulate it as XML or you can use string replacement. This would be the time to replace all of the relative URLs with Absolute ones.
  5. Display it back to the user! I don’t want to know how you apply this method, I just like coming up with the solutions ;)
9
Jun

webTRAM update

   Posted by: admin

webTRAM is well on it’s way to being complete and stable product. Since I first posted about it, I redesigned and rewrote it, ading features and flexibility and performance. The code and demo have ben updated. The full working demo is included in the code so it will be pretty easy to get started.

 I have a few things I’ll be fixing and adding to it before I leave it alone for a while but all constructive and civil comments are welcome.

 http://SuddenDevelopment.com/?page_id=7

29
May

webTRAM demo updated.

   Posted by: admin

demo link:  http://anthong.com/webTRAM/demo/

the demo has been upgraded significantly to inlude all of the latest features with some ways to demonstrate them.

Powered by ScribeFire.

4
Apr

Announcing webTRAM!

   Posted by: admin

I am proud to announce my first Open Source product, webTRAM. I have never seen this set of features in an open source product before or else I would have used it and not developed my own. Now that I have developed it I will never stop improving it. I believe this product will be useful in many projects / jobs I work in the future and I hope it can be the same for others.

 This product is intended to record as much as possible from user actions, record it to a database, and display it in an analytical or visual format for decision making.

webTRAM will blow away the usefullness of web server logs and every product that relies on them exclusively.

 This was built with the need of tracking web2.0 / AJAX / DHTML sites. Web server logs won’t tell you how many times a user slid an element back and forth, or dragged a window, or used any of the other fancy javascripts you have in your site. WebTRAM will record these actions and many others, like when they right click to copy text, or double click to select a word.

 Yes, this is a little overboard. I have found that an abundance of information is better than a lack of it. This processing does not impact server resources on tracking and recording significantly. The only overhead that is noticed is in the storage space that builds up and running reports against all of that stored data. Both of these can be addressed by managing your data and filtering queries.

 What I have made available so far is very minimal. I am using it curently in a production environment, but I have a lot of work to do to make this a product people can just use without modifying. I will call that milestone 1.0.

After 1.0 I have a lot of significant features to add, just look at the todo list of the main page.

If you haven’t already found the page in the “Pages” list here it is:

http://eclecticdevelopers.com/?page_id=7