Archive for the ‘job’ Category
03
Feb
This product page inspired me to write this post. It was launched around February last year (uh oh time flies!) and the first successful order was made around that time too. By then, there were only about 20 products or less, and really short attributes i.e. volumes in 8, 12 or 16 oz. strength like mild, regular, etc. Last monday, new products came in for addition to the site and they have quite longer attributes. It could have had a liquid width on the attribute and cart buttons but they had a really good design advisers and wanted to follow the design to the pixel.

Initially, this html code composes the product attribute and cart button, notice that <span class="c">Cherry</span> is a one word attribute for scent
<div class="cartbutton" style="background-image: url(images/button-long-add-to-bag.gif);"> <span class="c">Cherry</span> <span class="c">8 oz.</span> <span class="c">$5.99</span> <span class="d"> <a class="e" href="cart.php?product=5|33404&as=5">Add to bag</a> </span> <span class="e">» ITEM: 33404</span> </div>
And the new ones came with the colors “Casino Red”, “Golden Chestnut” and “Orchid Black” – long attributes, and two others “Copper” and “Spice” – short and manageable, as the column width will fit the entire word.
I was really planning to rewrite the whole attribute and cart button section, but I didn’t had much time. I figured I can make the font smaller and paddings or margins can go smaller than the regular so that two lines would fit in the box if the attribute value is a word longer. But I cannot be in PHP, its not really the way to go. So, if I can add another class that would override existing font-size and parent margin/padding, that would work. Here, I thought, word count doesn’t really need be in the PHP side and since I’m using Smarty, I found in it a variable modifier that can print the number of words in a variable, and that’s it. I can add another class in the column span like words-10 or countwords-3 in my template by the number of words that is present in the variable. Below is the generated code
<div class="cartbutton" style="background-image: url('images/button-long-add-to-bag.gif');"> <span class="c col-color words-2">Casino Red</span> <span class="c col-volume">8 oz.</span> <span class="c">$11.39</span> <span class="d"> <a href="cart.php?product=28|33825&as=14" class="e">Add to bag</a> </span> <span class="e">» ITEM: 33825</span> </div>
CSS rules
/* default rules */ .cartbutton { height: 23px; background: url('/images/button-add-to-bag.gif') no-repeat left center; color: #333; } .cartbutton span { display: block; text-align: center; float: left; font-weight: bold; font-size: 10px; padding-top: 5px; } .cartbutton span.c { width: 45px; } .cartbutton span.d { width: 80px;} .cartbutton span.d a { color: #fff; text-decoration: none; } .cartbutton span.e { margin-left: 10px; width: 100px; } /* special rule for two word attribute */ span.words-2 { padding-top: 3px; line-height: 98%; font-size: 9px; }

And this is how it is setup in the template.
<div class="cartbutton" style="background-image: url('images/button-long-add-to-bag.gif');"> {if $attr[at].color} <span class="c col-color words-{$attr[at].color|count_words}">{$attr[at].color}</span> {/if} {if $attr[at].strength} <span class="c col-strength words-{$attr[at].strength|count_words}">{$attr[at].strength}</span> {/if} {if $attr[at].scent} <span class="c col-scent">{$attr[at].scent}</span> {/if} {if $attr[at].volume} <span class="c col-volume">{$attr[at].volume}</span> {/if} <span class="c"> $ {if !$attr[at].amount} {$results[r].amount} {else} {math equation="x" x=$attr[at].amount format="%.2f"} {/if} </span> <span class="d"> <a href="cart.php?product={$results[r].id}|{if $results[r].sku && !$attr[at].sku}{$results[r].sku}{elseif $attr[at].sku}{$attr[at].sku}{/if}&as={$attr[at].pas_id}" class="e">Add to bag</a> </span> <span class="e">» ITEM: {if $results[r].sku && !$attr[at].sku}{$results[r].sku}{elseif $attr[at].sku}{$attr[at].sku}{/if}</span> </div>
Those extra class names like col-volume, col-scent and col-strength are only for future use, who knows what other formatting and adjustments on the data and theme will happen. Its really fun working with MVC model. Hope it helps
Happy coding!
Posted in job, me stuff, work related | 1 Comment »
27
Oct
This plugin is dependent on WP/GeoTrack by Johannes Lietz, this is NOT a stand-alone plugin, it won’t work if WP/GeoTrack is not installed anyway, so it’s safe.
And don’t look for it in WP Plugins repo, you won’t find it there
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | /* Plugin Name: Top Visitors Flag Plugin URI: http://www.marvinmarcelo.com/ Description: This plugin displays visitors on sidebar as widget dependent on <a href="http://dadabase.de/weblog/archives/2006/05/23/wordpress-geotrack-plugin">WP/GEO-Track plugin</a>. Author: Marvin Marcelo Author URI: http://www.marvinmarcelo.com/ Version: 1.0.0 */ function tvf_get_topvisits() { global $wpdb, $table_prefix; $sql = "select count(*) as `rows` , `country` , `flagname` from `".$table_prefix."geotrack` group by `country` order by `rows` desc limit 0 , 12"; $flagstats = $wpdb->get_results($sql); $html = "<li id='top-country-flags'><h2>Top Visiting Countries</h2><div>\n"; /* id string */ foreach ($flagstats as $cf) { $cf->rows = number_format($cf->rows, 0, "", ","); $html .= "<img src=\"". GEOTRACK_URL . "flags/" . $cf-/>flagname . ".png\" alt=\"Flag of $cf->country with $cf->rows visits\" title=\"$cf->country with $cf->rows visits\" />\n"; } $html .= "</div></li>"; echo $html; } function init_tvf_init(){ register_sidebar_widget("Top Visitors Flags", "tvf_get_topvisits"); } if (defined('GT_NOT_INSTALLED')) { echo "<!-- You need \"http://dadabase.de/weblog/archives/2006/05/23/wordpress-geotrack-plugin\" installed first-->"; } else { add_action("plugins_loaded", "init_tvf_init"); } |
Also, you have to forgive the function, constants, and variables names, we all struggle for a better and sensible one
Happy coding!
Tags: php, snippet, wordpress
Posted in job, me stuff, productivity, work related | No Comments »
12
Oct
This is actually a repost from the tutorial I often ran onto when working with servers. Lately, the sys-ad I was working with changed users home directory and also changed their passwords, but gave me the root pass. However, I don’t want to bother him for new passwords, and I guess he setup new ones from password generator apps/scripts, which are of course, really really recommended nowadays. Since I have the root pass, and I don’t want to go back to chmod-chown each and every files/folders I created via root, I thought I can automate logging in with each account I need to work ‘as’ their respective users. Or I can use cat /etc/passwd to know their home directories.
First log in on A as user a and generate a pair of authentication keys. Do not enter a passphrase:
a@A:~> ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/home/a/.ssh/id_rsa): Created directory '/home/a/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/a/.ssh/id_rsa. Your public key has been saved in /home/a/.ssh/id_rsa.pub. The key fingerprint is: 3e:4f:05:79:3a:9f:96:7c:3b:ad:e9:58:37:bc:37:e4 a@A
Now use ssh to create a directory ~/.ssh as user b on B. (The directory may already exist, which is fine):
a@A:~> ssh b@B mkdir -p .ssh b@B's password:
Finally append a’s new public key to b@B:.ssh/authorized_keys and enter b’s password one last time:
a@A:~> cat .ssh/id_rsa.pub | ssh b@B 'cat >> .ssh/authorized_keys' b@B's password:
Now I can work as ‘owner’ and ‘user’ within each user home directory.
a@A:~> ssh b@B hostname B
Some notes, depending on your version of SSH you might also have to do the following changes:
- Put the public key in .ssh/authorized_keys2
- Change the permissions of .ssh to 700
- Change the permissions of .ssh/authorized_keys2 to 640
Posted in job, work related | 1 Comment »
25
Sep
I had to come up with this post because I’ve been working on an old CMS about 3 years old (or even more) and I had been wondering why the calendar links cuts off from 2001 to 2003.
Task: List a year/month links from the present to the oldest published image sets.
Sounds easy, and I believe it is.
But when I checked on the existing script, this is what I got.
$month_array = array("1"=>'January',"2"=>'February',"3"=>'March',"4"=>'April',"5"=>'May',"6"=>'June',"7"=>'July',"8"=>'August',"9"=>'September',"10"=>'October',"11"=>'November',"12"=>'December'); $smarty->assign('y2day',$y2day); $y=0; for ($q=12; $q >= 1; $q--){ $month = $month_array[$q]; if( ($_GET[year] < '2000') && ($m2day ==$q ) ) $w_string = $week_string; else $w_string =''; if( ($_GET[year] == '2007') && ($_GET[month] == $q) ) $w_string = $week_string; if($m2day >= $q){ $tmp_cal_month_now_array = array( 'month' => $month, 'string' => $w_string, 'link' => $q ); $date_month_now_array[$y++] = $tmp_cal_month_now_array; } } //for $smarty->assign('calendar_now_month',$date_month_now_array); $y=0; $c_yeartoday = date("Y") -1; //echo $c_yeartoday; for($q=0; $q < = 5; $q++){ $tmp =$c_yeartoday - $q; //echo $tmp; $tmp_cal_date_array = array( 'year' => $tmp ); $date_year_array[$y++] = $tmp_cal_date_array; } //for $smarty->assign('calendar_year',$date_year_array); $y=0; for($q=12; $q >= 1; $q--) { $month = $month_array[$q]; if( $_GET[month] == $q ) $w_string = $week_string; else $w_string=''; $tmp_cal_month_array = array( 'month' => $month, 'string' => $w_string, 'link' => $q ); $date_month_array[$y++] = $tmp_cal_month_array; }//for $smarty->assign('calendar_month',$date_month_array); $y=0; for($q=12; $q >= 10; $q--) { $month = $month_array[$q]; if( ($_GET[year] == '2000') && ($_GET[month] == $q) ) $w_string = $week_string; else $w_string=''; $tmp_cal_month_old_array = array( 'month' => $month, 'string' => $w_string, 'link' => $q ); $date_month_old_array[$y++] = $tmp_cal_month_old_array; }//for $smarty->assign('calendar_month_old',$date_month_old_array);
Tags: basic programming, calendar, ezsql, grumble, month-year, php, smarty
Posted in job, me stuff, work related | No Comments »
03
Sep
Found this post from Smash!ng Apps
PHPanywhere is a new online service that’s changing the way people develop on the web. They enable users to develop and maintain their php/html projects online using any standard web browser.
This is a web based free Integrated Development Environment or IDE for the PHP language, in other words it is an application that gives developers all the code editing capabilities they need to develop PHP applications online. It includes a real-time syntax code editor with support for all web formats and a powerful FTP editor.

Because it works in a browser you can start coding right away, no need for installing anything and best of all you can work from anywhere, all you need is an internet connection and a web browser and you’re ready to go.
You can develop and maintain multiple projects with ease using PHPanywhere, because as soon as you log in all your projects (FTP servers) are immediately accessible. PHPanywhere even remembers what files you were working on and reopens them as well.
Real-time syntax code editor
The real-time syntax code editor is really what PHPanywhere is all about, so here is a list of just some of the things it does:
- Syntax highlighting
- Smart indentation for each language
- Code folding
- Full internationalization
- Unlimited undo/redo (now handled on client (browser) side, no more waiting for server response)
- Unlimited tabs
- Find and replace feature (New Feature)
- Displays line numbers (New Feature)
- Code auto completion, snippets (New Feature)
- Displays line numbers (New Feature)
- Code indention (TAB key) (New Feature)
Posted in job, me stuff, productivity, work related | 2 Comments »
26
Aug
I realize the need for this when working on an MVC based CMS especially with Smarty engine in it.
Oh and in case you’re wondering why its sounds like the upcoming movie Avatar by James Cameron, I don’t know. What it has to do with internet term ‘avatar‘? I really don’t know. But in ‘www’, Gravatar is a short term for “Globally Recognized Avatar” assigned by a user as his/her default avatar in every places of the internet, same people behind WordPress. There are other similar services too.
So, this plugin is based from its documentation
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | /** * Gravatar * * @link http://www.marvinmarcelo.com * * @param array $params * @param Smarty $smarty */ function smarty_function_gravatar($params, &$smarty) { /** * constant $gravatar_host */ $gravatar_host = "http://www.gravatar.com/avatar/"; if ( !isset($params['email']) ) { $smarty->trigger_error("gravatar: email parameter not set"); return; } if ( !eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $params['email']) ) { $smarty->trigger_error("gravatar: {$params['email']} is not a valid email."); return; } /** * @link http://en.gravatar.com/site/implement/url */ $hash = strtolower(md5(trim($params["email"]))); $src = $gravatar_host . $hash . ".jpg?"; if ( !isset($params["size"]) || !($params["size"] >= 1 && $params["size"] < =512 )) { $params["size"] = 32; } $src .= "s={$params["size"]}"; if ( !isset($params["default"]) ) { $params["default"] = "identicon"; } $src .= "d={$params["default"]}"; if ( !isset($params["rating"]) ) { $params["rating"] = "G"; } $src .= "r={$params["rating"]}"; $extras = ""; if ( isset($params["class"]) ) { $extras .= " class=\"{$params["class"]}\""; } if ( isset($params["id"]) ) { $extras .= " id=\"{$params["id"]}\""; } /** * @example http://www.gravatar.com/avatar/7023218434f12aee57f4b03454dadcaa?s=32&d=identicon&r=G */ print "<img src=\"$src\" alt=\"{$params["alt"]}\"$extras />"; } |
Simply extract function.gravatar.zip into your Smarty plugin directory. And use it in your template file like this
{gravatar email='someemail@domain.com'}
You’re done!
Tags: gravatar, smarty, template
Posted in job, me stuff, productivity, work related | No Comments »
11
Jul
After an hour long reading his frustrations over IM, I began google’ing on files served thru PHP but locks clicks in a client’s browser until download is finished. It is unresponsive until the download is complete.
// add this function before a readfile() or chunked with fopen() session_write_close(); // header goes here, content-type, filename, etc readfile($filepath);
And, also, I found this class to support downloading using a download manager.
Posted in job, me stuff, work related | No Comments »
10
Jun
So far, I’ve been happy how this template behaves when I pass a parent/child links into it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | < {$parent_tag|default:'ul'}{if $menu_id} id="{$menu_id}"{/if}{if $parent_class} class="{$parent_class}"{/if}>{* ul tag opens here *} {foreach from=$links item=link} {if $link.class_active && $link.href == $current_uri} {if $link.class} {assign var=class value="`$link.class` `$link.class_active`"} {else} {assign var=class value="`$link.class_active`"} {/if} {else} {assign var=class value="`$link.class`"} {/if} < {$child_tag|default:'li'}{if $class} class="{$class}"{/if}{if $link.id} id="link_{$link.id}"{/if}> <a href="{$link.href}"{if $link.target} target="{$link.target}"{/if}>{$link.text}</a> {if $link.children} {include file="links.html" links=$link.children parent_class=""} {/if} {/foreach} < /{$parent_tag|default:'ul'}> |
Does something like this when rendered
<ul class="sf-menu"> <li><a href="http://www.swerteka.com/index.php">Home</a></li> <li><a href="http://www.swerteka.com/PostItem">Post Item</a></li> <li><a href="http://www.swerteka.com">Blog</a> <ul> <li><a href="http://www.swerteka.com/BlogComments/do/viewrecent">Comments</a></li> </ul> </li> <li><a href="http://www.swerteka.com/Content/name/about">About</a> <ul> <li><a href="http://www.swerteka.com/Content/name/contact">Contact Us</a></li> </ul> </li> </ul>
Tags: OOP, smarty
Posted in job, me stuff, work related | No Comments »
20
Apr
If you have a repeating region in your template and it doesn’t need a wrapper around it, simply use section
1 2 3 | {section name=s loop=$images} <div id="image_{$images[s].id}"><img src="{$images[s].src}" alt="" /></div> {/section} |
Cases where you need html wrap tags is like this
1 2 3 4 5 6 7 8 9 | {if $navlinks} <ul> {section name=s loop=$navlinks} <li id="navitem_{$navlinks[s].id}"> <a href="{$navlinks[s].href}">{$navlinks[s].text}</a> </li> {/section} </ul> {/if} |
This avoids the <ul> being rendered if $navlinks don’t have a return record. Another way is to access Smarty properties
1 2 3 4 5 6 7 | {section name=s loop=$navlinks} {if $smarty.section.s.first}<ul>{/if} <li id="navitem_{$navlinks[s].id}"> <a href="{$navlinks[s].href}">{$navlinks[s].text}</a> </li> {if $smarty.section.s.last}</ul>{/if} {/section} |
But still, this adds an if in the template. As this post title goes, you should avoid them, that’s the basics of OOP system and MVC frameworks, separate logic from code
What made me write this post? Template Designers sometimes hate seeing if statements. In my case, my boss transforms into savvy Designer as well, at times! Bummer
Tags: CMS, OOP, smarty
Posted in job, productivity, work related | No Comments »
27
Mar
Welcome to SourceForge.net!
The following project has been approved for hosting:
Descriptive Name: ******
Unix Name: ******By using the SourceForge.net site, you agree to be bound by the
terms and conditions of the SourceForge.net Terms of Use Agreement.SourceForge.net project hosting is available solely to Open Source
software development projects. If you are not releasing your project
under an Open Source license, please contact SourceForge.net staff for
assistance (see “Support”, below).Project Administration:
To manage your project, login and go to:
https://sourceforge.net/project/admin/?group_id=******
For help in getting started with your new project:
http://p.sf.net/sourceforge/getstarted
Support:
SourceForge.net maintains a full-time support team; we are ready to
assist you with any questions you have about your new project.We can be contacted by submitting a ticket at:
http://p.sf.net/sourceforge/submitticket
We may also be reached directly during business hours via IRC:
http://p.sf.net/sourceforge/irc
– the SourceForge.net crew
Posted in job, work related | No Comments »


