mysqlguy.net

Friends

PHP Date Cueing Logic

sim.plified.com - April 14, 2009 - 7:06pm

For the next release of PatternTap, the images that are approved will be time released into the tap, this will allow for a more smooth delivery of content throughout the day, rather than bulk loading.

The function below take a datetime string (mysql formatted) and then returns the next delivery date.  The idea is that a whenever an item is submitted, it looks at the last item that was cued, get’s it’s time, and feeds it to this function to determine when the next item should be cued.  This function used the logic that items should be cued hourly between the hours of 10am and 5pm on Monday through Friday.  

This logic could easily be updated to accommodate your own needs, let me know if you find any problems or if it helps you solve a problem.

/** * * Description: returns the next time to cue up an item based on the logic: * Every hour between 10am and 5pm, Monday - Friday * * Example input value $latest_item = "2009-04-15 17:01:00″; * * @params $latest_item datetime string * **/ function get_cue_time($latest_item) { $next_item = strtotime($latest_item . " + 1 hour"); if ($next_item < time()) // compare to now $next_item = time(); // set to now // Before 10 am? if (date("H", $next_item) < 10) { // set to 10 am $next_item = mktime(10, 0, 0, date("n", $next_item), date("j", $next_item), date("Y", $next_item)); } // After 5pm? if (date("H", $next_item) > 17) { // set to 10am the next day $next_item = mktime(10, 0, 0, date("n", $next_item), date("j", $next_item) + 1, date("Y", $next_item)); } // Saturday Check if (date("N", $next_item) == 6) { // set to 10am Monday $next_item = mktime(10, 0, 0, date("n", $next_item), date("j", $next_item) + 2, date("Y", $next_item)); } // Sunday Check if (date("N", $next_item) == 7) { // set to 10am Monday $next_item = mktime(10, 0, 0, date("n", $next_item), date("j", $next_item) + 1, date("Y", $next_item)); } return date('Y-m-d H:i:s', $next_item); }   Technorati Tags: php patterntap datetime logic .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }
Categories: Friends

Meetup with EECommerce Developers

sim.plified.com - April 1, 2009 - 9:10am

Last week I was in the UK on business and had the opportunity to meet up with some of the leads working on the EECommerce module that will bridge Expression Engine and Magento Ecommerce.  There were several purposes in the meeting 1) for me to communicate a very particular need I had in bridging multiple stores in Magento with multiple sites (via the Multiple Site Manager) in Expression Engine.  2) The other purpose was for me to get a handle on the project and what they were trying to accomplish.  Based on that meeting with Lee and Greg, here are some of the things I learned about EECommerce.

EECommerce is trying to make it possible to have the entire user/developer experience defined within EE.

The goal of the module is to port everything necessary to have a seamless shopping cart experience without ever leaving Expression Engine.  While that was not necessarily what I was looking for in merging the two systems together, there is a lot of potential in this approach as it will mean that the designer/develop does not have to mess with Magento’s somewhat confusing templating system.  Their goal is to make it so that you can define your entire store in EE templates, using the plug-in tags to harness Magento’s inherent functionality.  Of course you would still access Magento’s backend (e.g. product entry, order management) directly, but the actual user experience would be defined in Expression Engine.

EECommerce will be a complete encapsulation of the Magento API.. along with several extensions.

EECommerce’s tag system will encompass everything that can be done through Magento’s API and more.  This is by no means just a subset of Magneto functionality that is being brought into EE.  Far from being a subset, they will actually be extending the API in several ways that can be used with or without Expression Engine (as a developer I like this).

PHP UK seems to have passion for the project and a desire to garner community feedback.

For my own part, these guys drove a couple of hours to meet up with me at my business headquarters.  The drove up and listened as I explained the level of user integration that I was looking for between the two systems.  I laid out my architecture and they responded with what they believed their module would be able to accomplish.  They also assured me that they would talk to their developers and give me a better idea of when I might expect to see and beta test some of the features that I need to have developed for a forthcoming web site that I’m developing.

EECommerce was a bit more undeveloped than I might have hoped

I was hoping to see EECommerce a bit more developed when I met up with PHP UK.  For sure, they showed me that the module was working “in principal” but it seems that there are many bugs to get worked through on a bridge that is this involved.  Although they are hopeful to have something a bit more polished by some of the upcoming MAGE:Camp it seems as though they will have their work cut out for them.  In short, don’t plan on using this module in your ecommerce project that needs to be deployed next month.

A Word About Price

Clearly some of the biggest reaction in the community has come at the sticker shock of the EECommerce module.  Obviously everyone loves getting something for nothing, but as you and I know there is nothing that is truly free.  Everything cost something (even if you’re not the one who has to pay).  As an ecommerce entrepreneur, not just a developer, I think there is some real business value in the module that is being developed.  If built correctly, the module could be used to rapidly deploy ecommerce micro sites.  The tool has the potential (we’ll see when we get there) to greatly speed up the development of ecommerce sites that are simple and complex.

The Jury is Out

At the end of the day, the jury is still out.  Until the beta truly gets out there and a the developer community really begins to put some pressure on the module, its hard to see what will come of EECommerce.  I for one, am willing to give it a go and am looking forward to seeing if these guys can pull together a supported tool that helps make online commerce even easier by bringing the feature richness of Magento into the flexibility of Expression Engine.

If you have questions about my meeting and what I was able to see, please post your questions in the comments and I’ll try to address them in a timely manner.

Categories: Friends

Controlling SlideShowPro Navigation with Javascript

sim.plified.com - March 16, 2009 - 3:54pm

I’ve been really impressed with the latest releases of Director and ThumbGrid from Slideshow Pro.  I am planning on using them to replace a JavaScript based slideshow that I feel loads abnormally in different browsers.  SlideShowPro really has simplified the process for me, by providing some great administrative and presentation tools.

Here are the basics of wiring up the JavaScript navigation to the slide show.

In the flash document (fla) in a new key frame I placed the following:

1: import flash.external.*; 2: ExternalInterface.addCallback("sspNextImage", sspNextImage); 3: ExternalInterface.addCallback("sspPrevImage", sspPrevImage); 4: function sspNextImage() { 5: my_ssp.nextImage(); 6: } 7: function sspPrevImage() { 8: my_ssp.previousImage(); 9: } .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

This code basically exposes the SSP API to an external agent such as JavaScript

Then in my web page document in the HEAD tag I included the following:

1: <script type="text/javascript"> 2: function sspNextImage() { 3: thisMovie("ssp_kg").sspNextImage(); 4: } 5: function sspPrevImage() { 6: thisMovie("ssp_kg").sspPrevImage(); 7: } 8: function thisMovie(movieName) { 9: if (navigator.appName.indexOf("Microsoft") != -1) { 10: return window[movieName] 11: } else { 12: return document[movieName] 13: } 14: } 15: </script> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

Note that “ssp_kg” is the name of my slide show presentation.

The only thing left to do was to setup the links to call the new JavaScript functions:

<p class="gallery-nav"> <a onclick="sspPrevImage(); return false;" href="#">&laquo; Previous</a> | <a onclick="sspNextImage(); return false;" href="#">Next &raquo;</a> </p> .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

In the end it was very straight forward and I was well satisfied with the results:

Sample Page: KeeGuard Roof Top Railing – Fall Protection System

Categories: Friends

Pushing Leads to Salesforce with PHP

sim.plified.com - February 13, 2009 - 10:46pm

Recently our company began a trial of Salesforce.com.  In doing so we opted not to layout the cash for the program that gives you full API access (at the moment any ways).  I needed a way to push leads into the system.  They have a standard web-to-lead process that requires a form submission and then post back to return URL.  I already had a lot of forms that I was using to capture data.  Instead of reworking all my forms, I just created a way to post to the Salesforce web-to-lead form from the server side. 

I started by creating a basic function which passes in the data I want to capture and pushes it to the Sales force form.

function add_to_salesforce($source, $name, $email, $company, $city, $state, $zip, $phone, $description, $street = "") { // simple way of breaking apart the name $names = split(" ", $name); //set POST variables $url = 'https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8′; $fields = array( 'last_name'=>urlencode($names[1]), 'first_name'=>urlencode($names[0]), 'street'=>urlencode($street), 'city'=>urlencode($city), 'state'=>urlencode($state), 'zip'=>urlencode($zip), 'company'=>urlencode($company), 'description'=>urlencode($description), 'email'=>urlencode($email), 'phone'=>urlencode($phone), 'mycustomefieldid' => urlencode($source), // custom field 'oid' => 'youridgoeshere', // insert with your id 'retURL' => urlencode('http://www.yourreturnurl.com'), // sending this just in case 'debug' => '1′, 'debugEmail' => urlencode("[email protected]"), // your debugging email ); //url-ify the data for the POST foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; } rtrim($fields_string,'&'); //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_POST,count($fields)); curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string); curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch,CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch,CURLOPT_FOLLOWLOCATION, TRUE); //execute post $result = curl_exec($ch); //close connection curl_close($ch); } .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

 

Once that was setup all I had to do was call the function (which I wrapped in a class with something like this:

$myclass = new Myclass; $myclass->add_to_salesforce("Contact Page", $name, $email_address, $company, "", "", "", $phone, $enquiry); .csharpcode, .csharpcode pre { font-size: small; color: black; font-family: consolas, "Courier New", courier, monospace; background-color: #ffffff; /*white-space: pre;*/ } .csharpcode pre { margin: 0em; } .csharpcode .rem { color: #008000; } .csharpcode .kwrd { color: #0000ff; } .csharpcode .str { color: #006080; } .csharpcode .op { color: #0000c0; } .csharpcode .preproc { color: #cc6633; } .csharpcode .asp { background-color: #ffff00; } .csharpcode .html { color: #800000; } .csharpcode .attr { color: #ff0000; } .csharpcode .alt { background-color: #f4f4f4; width: 100%; margin: 0em; } .csharpcode .lnum { color: #606060; }

Works like a charm so far.  If you’ve got a slicker way of perfoming this operation, let me know, I’d love to learn how you did it.

Technorati Tags: Salesforce PHP Programming
Categories: Friends

Non-Charitable Charity – Why Giving the Government’s Way is Void of Love

sim.plified.com - February 11, 2009 - 9:47pm

It’s tax time again and for the past couple of years I’ve been struck that my method of giving is totally unrecognized by the government.  Before you mistake this as a complaint, it’s not, it’s simply an observation that I wish to bring to the attention of those that are interested in love.  It has slowly become my conviction that what the government calls “charity” is exactly self-interest in disguise.  Why self interest?  Giving to get.  If I give X to a valid 501(c)3 organization I’ll get my tax write off.  I admit that loving the way God tells us to love is full of rewards, but none of those rewards have anything to do with mammon.  Giving to get a tax write off is simply NOT charity… call it what you will, but don’t call it love. 

For more clarity I call your attention to one of the most well known passages of Scripture.  Where do we get our understanding of love?  Is it not from the story of the Samaritan?  After all, who loved their neighbor?  The one who picked up a stranger, washed his wounds (at expense to himself) and paid for his needs of recovery.  Where were the other two headed (the priest and the Levite), but off to their jobs at the governmentally-recognized institution. 

Ironically the government does not recognize “contribution to a specific individual” or “contribution to a nonqualified organization”.   The Samaritan’s expenses would not have been recognized by the government.   The irony is rich and hopefully the implications are clear.  What God desires is not for us to leverage and extra percentage or two by getting a tax write off, but rather to be open to do radical works of love to those whom won’t be recognized or “qualified” as outlets for the world’s charity.

Categories: Friends

MySQL

Yahoo

  • Saving some green this Earth Day
  • Meet the Yahoo! yodeler
  • Product Pulse - April 17, 2009
  • Don’t miss tonight’s “Dinner: Impossible”
  • A 24-hour locksmith for your Yahoo! account
  • Product Pulse - April 10, 2009
  • The hunt is on
  • The grand opening of Yahoo! Music
  • Product Pulse - April 3, 2009
  • It all comes down to ideology

Recent comments

About Me

Jay Janssen
Yahoo!, Inc.
jayj at yahoo dash inc dot com

MySQL
High Availability
Global Load Balancing
Failover

View Jay Janssen's LinkedIn profileView Jay Janssen's Facebook profile

User login

Friends

  • PHP Date Cueing Logic
  • Meetup with EECommerce Developers
  • Controlling SlideShowPro Navigation with Javascript
  • Pushing Leads to Salesforce with PHP
  • Non-Charitable Charity – Why Giving the Government’s Way is Void of Love

Links