NYCPHP Meetup

NYPHP.org

[nycphp-talk] PHP html DOM manipulation

Matthew Kaufman mkfmncom at gmail.com
Tue Aug 9 09:32:34 EDT 2011


PS: This is a little 'known secret' (okay, not really) -- But if you really
want to have fun with DOM Manipulation; install Squid 3 and setup an ICAP
server --- GreasySpoon (http://greasyspoon.sourceforge.net/):

GreasySpoon is a real-time solution allowing you to easily manipulate Web
traffic on the fly.

By providing an embedded development framework, GreasySpoon can be used for
very simple usages up to extremely complex applications: HTTP anonymization,
tracking, access control filters, mashup services, Web Application firewall,
...

What makes GreasySpoon unique is that any code modification is applied in
real time, while providing an excellent performance level. You can in that
way easily build up, test and improve your services, then decide to use the
result in a production environment.
Inspired by Firefox GreaseMonkey extension, GreasySpoon supports various
"scripting" languages, like Java, JavaScript, Python or Ruby. Interfaced
with HTTP proxies like Squid, it runs transparently in the network and does
not require any specific modification on end-user devices. In that way, it
provides therefore multi-OS and cross-browser support.

GreasySpoon supports Java/javascript language per default, but can be easily
extended with other scripting languages: Ruby, Python, AWK, Groovy, etc.
Providing a web based interface, it tries to be as user-friendly as
possible, while keeping an eye on performance that makes it usable from
early prototyping stages up to production environment.

Fully developped in Java, GreasySpoon can be used on merely any platform and
has already been successfully tested with several ICAP clients: Squid 3.0,
Bluecoat ProxySG, Network Appliance Netcache and more.

Matt Kaufman
http://mkfmn.com/

On Tue, Aug 9, 2011 at 7:35 AM, Gary Mort <garyamort at gmail.com> wrote:

> On 8/7/2011 11:53 PM, John Campbell wrote:
>
>> On Fri, Aug 5, 2011 at 6:39 PM, Gary Mort<garyamort at gmail.com>  wrote:
>>
>>> One thing I'd like to see this for is to re-write all those cool lightbox
>>> style javascript codes into PHP code[so instead of the user waiting for
>>> all
>>> the HTML to download, then waiting for a javascript event to trigger to
>>> update the links from their old links to popup links if they have the
>>> appropriate class  - the server can pre-process the file and do those
>>> substitutions once and then cache the data.]
>>>
>> This sounds like premature optimization to me.  How can you make a
>> lightbox with PHP code?
>>
>
> Just to recap how lightbox style scripts work:
>
> 1) You take a link to an image, and add an attribute to the link, such as
> rel="lightbox[mygallery]"
>
> 2) After the entire page is loaded, an onDomReady event is fired which find
> all href links with a rel attribute of lightbox[x] where x is some text.
>  The javascript code will then check to see if there is a thumbnail for the
> image[by checking for the same image name in a subdirectory called thumbs -
> if so, it changes the innerHTML to an img tag pointing to the thumbnail and
> sets the alt attribute for the thumbnail to the original text for the link.
>
> 3) Lightbox adds an event listener so that all clicks on any links in the
> page will now check to see if there is a rel=lightbox[x] attribute and if
> so, it aborts the normal click processing and instead sends it to the
> lightbox processing function instead to popup the lightbox.
>
> Step 2 is entire client side processing which could be done by the server
> instead - ie the server could search the dom, find all those links, insert
> the thumbnail image directly and add an onClick even directly to the link.
>
> Because of the way this is done, there are a number of problems this will
> cause in an application for slow connections or overloaded systems:
>
> 1) Users click on the links before the page finishes loading, this causes
> the page load to abort as the browser now goes to load just the image and
> users wonder why they can't see the product or add it to the cart.
>
> 2) Because the link is displayed as text and then swapped for a thumbnail,
> if the page does not finish loading poorly choosen text chosen to create on
> hover picture capturing is displayed as a link to the user causing
> confusion.
>
> 3) In complex CMS and Ecommerce systems, if there is a javascript error
> caused by some other module, the browser may abort processing all future
> javascript onDomReady events - so the lightbox enabling event may never be
> run.
>
> Note: there are a large number of lightbox style javascript modules which
> use different attribute's and processes, they all do basically the same
> thing though and have the same type of potential problems.
>
> There is no reason that when a PHP script generates HTML it should only go
> halfway in generating a functional page, and then send partially functional
> garbage to the web client and count on the web client to turn that garbage
> into a functional web page.  Without decent DOM manipulation it is easier to
> allow the client to make these changes.  However, with PHP 5 and all the
> advances in PHP dom manipulation - it's now possible to send actually usable
> html code to a client and not count on javascript to convert it for you.
>
> -Gary
>
>
> ______________________________**_________________
> New York PHP Users Group Community Talk Mailing List
> http://lists.nyphp.org/**mailman/listinfo/talk<http://lists.nyphp.org/mailman/listinfo/talk>
>
> http://www.nyphp.org/Show-**Participation<http://www.nyphp.org/Show-Participation>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20110809/317617b2/attachment.html>


More information about the talk mailing list