advertisement
Login | Register   
  Include Code  Search Tips
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Download the Code!
Partners & Affiliates
advertisement
advertisement
advertisement
advertisement
Average Rating: 4.1/5 | Rate this item | 19 users have rated this item.
Secure Internet File-Sharing with PHP, MySQL, and JavaScript (cont'd)
overLIB and Pop-Up Menus
The workflow process can be too long sometimes if PHP code has to process every action on the server side. JavaScript pop-ups are a solution for shortening the interactions a little bit, but inserting JavaScript in a configuration can produce unacceptable entropy and significantly decrease the separation between business and template logic. Smarty embeds a very useful and powerful JavaScript library called overLIB. According to its website, overLIB "is a JavaScript library created to enhance websites with small popup information boxes."
advertisement

Smarty integrates overLIB with a very simple construction, {popup ... }. In the file inc.file_list.tpl, there is an example of overLIB use:


{include file='files.pop.tpl' assign='filePop'}
...
<a href="{$smarty.server.PHP_SELF}?id={$file.id}&not_crypted=1"
{popup
trigger=onClick
width=360
sticky=true
caption='Action'
closeclick=true
text=$filePop
}
>{$file.filename}</a>
...

In this code snippet, you see how you can attach an overLIB pop-up with a single instruction. You can set up all the overLIB parameters listed here and separate HTML code for pop-up in an another file, files.pop.tpl.

Beautify Your PHP Code
It is normally difficult to set a right indentation or good spacing rules during coding, and PEAR PHP_Beautifier can help a lot. Install it as follows:


pear install PHP_Beautifier

Then run this on the command line:


php_beautifier [some_file].php --output new_file.php

The new_file.php file produced will be rearranged with great improvement in readability.

Furthermore, PEAR provides a set of coding standards. With the mechanism of filters, for example, you can format your code accordingly by running this:


php_beautifier --filters "Pear()" [some_file].php --output new_file.php

Because HTML and CSS coding are not my strengths (you may have guessed that already), I looked for a method to separate presentation from logic in a small Internet file-sharing application so I could easily delegate the presentation to an experienced graphic designer. The result was a practical example of using a database abstraction layer and separating HTML design from PHP programming using open source libraries and frameworks. You can leverage my example to create an Internet file-sharing application that lets your users securely share files and classify them with tags and metadata.

Previous Page: What Smarty Is and How It Works  


Roberto Giorgetti is an IT manager and technical writer based in Italy. He is mainly interested in open source exploitation in business and industrial areas. Roberto holds a degree in Nuclear Engineering.
Page 1: IntroductionPage 4: What Smarty Is and How It Works
Page 2: Installation Instructions for a Quick StartPage 5: overLIB and Pop-Up Menus
Page 3: Let's Dive into the Code 
Please rate this item (5=best)
 1  2  3  4  5
advertisement