Choose Your Theme
Warren Shea

Archive for the ‘Development’ Category

FB App & this weekend & movies

Tuesday, November 13th, 2012 at 11:37 am

Worked crazy hours this weekend.
I think Friday, Saturday, Sunday, and Monday…must have worked around….12 hours each day, on average. 48 hours in 4 days.
Made incredible progress on my Facebook App. When it’s live, I’ll toss you guys a link.

It’s got the most well built PHP I’ve ever done; that said, I know there’s still lots of room to improve. Need to start organizing my code better: MVC.
I have a confession: I finally built my first mySQL statements (Insert/Select)….ever. I learned PHP 2.5 years ago but never did them….seriously.
I always knew it was easy and never bothered/needed to learn it…I know how ASP Classic and ASP.NET connection strings and database connections work so I wasn’t worried. Anyways, learned it in like, 2 minutes. It’s so ridiculously easy. And using phpMyAdmin for SQL is ridiculous too. It’s so powerful and easy compared to MSSQL. I can’t believe…how much better it is that ASP and MSSQL. I’ve always thought I was an ASP guy as many corporations wouldn’t use PHP…but I think I’m changing my mind. PHP is where it’s at.

While I was deving, I was also watching many things (as per usual). Something to entertain me while I dev but doesn’t require my full attention, especially for a movie I’ve seen before. Anyways, this was my movie watch list for Sat, Sun, and Mon:

  • Good Will Hunting
  • Gone in 60 Seconds
  • Teenage Mutant Ninja Turtles 1
  • Teenage Mutant Ninja Turtles 2: Secret of the Ooze
  • Teenage Mutant Ninja Turtles 3
  • TMNT
  • Turtles Forever
  • Casino Royale
  • Quantum of Solace
  • Independence Day
  • Jurassic Park
  • Catch Me If You Can
  • The King’s Speech
  • Pursuit of Happyness
  • Star Wars IV: A New Hope
  • Iron Man

At 2 hours/movie, it’s 32 hours right there!

My Tier 1 favs in there: Catch Me If You Can
My Tier 2 favs in there: Iron Man, Pursuit of Happyness, The King’s Speech, Good Will Hunting
My Tier AWFULS in there: Teenage Mutant Ninja Turtles 3. That is an AWFUL AWFUL MOVIE.

That’s it for now. Need to sleep! Gnite!

warrenshea.com – Updates

Tuesday, November 6th, 2012 at 3:20 am

I can’t believe it’s been 6 months since I updated this site and effectively left it (it doesn’t really require regular maintenance).

I need to update it with some of the things I’ve learned in the past 6 months. Fortunately, it’s pretty easy with the help of my accomplishments posts (which is at 49 now – at 2 a month, I’ve done 2 years worth of these damn things!)

I installed WampServer and MediaWiki onto my work sandbox server. Had to uninstall a previously installed PHP that was stand-alone installed (not through Wamp) and had no uninstaller. Ugh.
Had to go into the Registry Editor and change PHP’s php.ini location.

Re-learned a bit about Regular Expressions. Learned stuff in school but mostly forgot it all. Was able to remove all HTML comments from a thousand page site in a few minutes (don’t ask why). Hand to remove things like “Comments (142)” and “Comment (0)” and items of that nature. Probably thousands of instances, removed in seconds with Regular Expressions, prompting me to want to know them better. Seems like it’ll come in handy :)

Facebook API – JavaScript SDK/PHP SDK for various aspects like: Like Gate Code and functionality, Share Dialog
Facebook App Creation
Twitter API – Share Dialog for Twitter

.
.
.

Uh oh, that’s it. Man, time flies. I learned quite a few new things in recent months but I had a bit of a dry spell while I was working on Photography and my Secret Project.

.
.
.

I also need to add my GitHub and Cloud9 accounts to my warrenshea.com site’s MORE section.

Also. No one has EVER used my warrenshea.com contact page. That makes me sad. Very sad. T_T

.
.
.

Damn, was planning to update the site, but started chatting and now i’m too damn tired. will do it tomorrow. along with review many things i’ve forgotten in the last year. it sucks to know something very well but simply forget it due to lack of use. Ah well, at least it’s easy to relearn and recall.

Update: Looks like my contact form was broken which is weird cuz the last time I tested it, it was okay…and I haven’t made any code updates to it. After recompiling the page (no code change), it works fine. Weird.

Tutorial: Setting up WordPress permalinks without index.php on IIS server

Sunday, May 27th, 2012 at 8:32 pm

There are lots of tutorials regarding how to set up permalinks on a WordPress site but generally, they’re tutorials for how to achieve this on an Apache web server under Linux.
This is one (http://heartdrops.org/tutorials/wp-removing-index-php-in-urls/) I really liked because it’s written for the common user. Simple steps, what you need, easily understandable. Unfortunately, it didn’t work for me (cuz it’s not for Windows hosting).

My solution is not unique, it comes from: http://wordpress.org/support/topic/permalinks-not-working-on-windows-server. Unfortunately, it was difficult to find so I was working on this problem for more than a few hours. (#$&^(%^#!)

Purpose of this tutorial
To achieve the following structure in WordPress URLs
http://www.worldofwarren.com/tutorials/setting-up-wordpress-permalinks/
or
http://www.worldofwarren.com/setting-up-wordpress-permalinks/

instead of, by default,
http://www.worldofwarren.com/index.php/tutorials/setting-up-wordpress-permalinks/
or
http://www.worldofwarren.com/index.php/setting-up-wordpress-permalinks/

What you need to know/have
PHP knowledge
A text editor
Access to your site’s 404, 404.2, and 404.3 errorpages

Procedure

  1. Create a simple new document file called wp-404-handler.php and place it in the root directory of your site.
  2. Place the following code inside wp-404-handler.php
    <?php
    // This is the default file for the site. Usually index.php
    $default = ‘index.php';

    // The name of this file.
    // Set this value for the URL in Custom Error Properties of your website in IIS.
    // Goto: IIS Manager > Websites > [Site Name] > Properties > Custom Errors >
    // 404 & 404;2 & 404;3 > URL (Requires a ‘/’ prefix in IIS).
    $thisfile = ‘404-handler.php';

    $_SERVER[‘ORIG_PATH_TRANSLATED’] = str_replace($thisfile, $default, $_SERVER[‘ORIG_PATH_TRANSLATED’]);
    $_SERVER[‘SCRIPT_FILENAME’] = str_replace($thisfile, $default, $_SERVER[‘SCRIPT_FILENAME’]);
    $_SERVER[‘ORIG_PATH_INFO’] = str_replace($thisfile, $default, $_SERVER[‘ORIG_PATH_INFO’]);
    $_SERVER[‘SCRIPT_NAME’] = str_replace($thisfile, $default, $_SERVER[‘SCRIPT_NAME’]);
    $_SERVER[‘PHP_SELF’] = str_replace($thisfile, $default, $_SERVER[‘PHP_SELF’]);
    $_SERVER[‘PATH_INFO’] = false;

    $qs =& $_SERVER[‘QUERY_STRING’];
    $ru =& $_SERVER[‘REQUEST_URI’];
    $pos = strrpos($qs, ‘://’);
    $pos = strpos($qs, ‘/’, $pos + 4);
    $_SERVER[‘URL’] = $ru = substr($qs, $pos);
    $qs = trim(stristr($ru, ‘?’), ‘?’);

    // Required for WordPress 2.8+
    $_SERVER[‘HTTP_X_ORIGINAL_URL’] = $ru;

    // Fix GET vars
    foreach ( $_GET as $var => $val ) {
      if ( substr($var, 0, 3) == ‘404’) {
        if ( strstr($var, ‘?’) ) {
          $newvar = substr($var, strpos($var, ‘?’) + 1);
          $_GET[$newvar] = $val;
        }
      unset($_GET[$var]);
      }
      break;
    }
    include($default);

    ?>

  3. Configure the 404, 404,2 and 404.3 error pages to point to the URL: /wp-404-handler.php
    (in this case, http://www.worldofwarren.com/wp-404-handler.php)
  4. Finally, in your WordPress permalinks section, add the follow to the Custom Structure.
    /%category%/%postname%/
    (though /%postname%/ might be more common).
  5. My ramblings
    It seems a bit odd WordPress would think users would want index.php in their URLs. They look hideous.

Site Updates: warrenshea.com & IE8

Thursday, April 26th, 2012 at 2:02 pm

warrenshea.com uses HTML5, which isn’t supported by IE8. Which is unfortunate because IE8 is used pretty frequently.

I didn’t wanna do another stylesheet/javascript and update both…so I used one of my favorite things: my proxy.php file

This is my default.php for warrenshea.com. Unfortunately, I did have to do a big IF statement but that’s okay because this code never changes. So what it does is check it it’s IE8 (ie. doesn’t support HTML5), and then changes some of the tags: <header> to <div id=”header”>. I’ll likely change the IF statement to something better later…but that’s not the point of this post.

<?php
$srvr_http_user_agent = $_SERVER[‘HTTP_USER_AGENT’];
if ((stristr($srvr_http_user_agent,”MSIE 6.0″) == true) ||
  (stristr($srvr_http_user_agent,”MSIE 7.0″) == true) ||
  (stristr($srvr_http_user_agent,”MSIE 8.0″) == true)) {?>
<!doctype html>
<html>
  <head>
    <link rel=”stylesheet” href=”common/proxy.php?url=stylesheet.css&type=css”>
  </head>
  <body>
    <div id=”header”>
      <div id=”nav”>
        <ul id=”nav-text”></ul>
        <ul id=”nav-background”></ul>
      </div>
      .
      .
    <script src=”common/proxy.php?url=scripts.js&type=js”></script>
  </body>
</html><?php } else { ?><!doctype html>
<html lang=”en-us”>
  <head>
    <link rel=”stylesheet” href=”common/stylesheet.css”>
  </head>
  <body>
    <header>
      <nav>
        <ul id=”nav-text”></ul>
        <ul id=”nav-background”></ul>
      </nav>
    .
    .
    <script src=”common/scripts.js”></script>
  </body>
</html><?php } ?>

Doing this gets rid of some HTML5 tags but the CSS and JavaScript/jQuery still reference the HTML5 tags. So I like to use my proxy.php, which loads a URL, and gives me the option to manipulate it.
FYI – For XML, I use it for my twitter XML (I used to have it done through JavaScript but I found that it hindered load time).

<?php header(“Expires:Mon, 31 Dec 2010 05:00:00 GMT”); ?>
<?php
$page_contents = file_get_contents($_GET[“url”]);
if ($_GET[“type”] == “css”) {
  header(“Content-type: text/css”);
  $page_contents = str_replace(“header”,”#header”,$page_contents);
  $page_contents = str_replace(“##header”,”#header”,$page_contents);
  $page_contents = str_replace(“footer”,”#footer”,$page_contents);
  $page_contents = str_replace(“##footer”,”#footer”,$page_contents);
  $page_contents = str_replace(“content-#footer”,”content-footer”,$page_contents);
  $page_contents = str_replace(“nav”,”#nav”,$page_contents);
  $page_contents = str_replace(“##nav-text”,”#nav-text”,$page_contents);
  $page_contents = str_replace(“##nav-background”,”#nav-background”,$page_contents);  
} else if ($_GET[“type”] == “js”) {
  header(“Content-type: application/javascript”);
  $page_contents = str_replace(‘$(“header”)’,’$(“#header”)’,$page_contents);
  $page_contents = str_replace(‘$(“nav”)’,’$(“#nav”)’,$page_contents);
  $page_contents = str_replace(‘$(“footer”)’,’$(“#footer”)’,$page_contents);
} else if ($_GET[“type”] = “xml”) {
  header(“Content-type: text/xml”);
}
echo $page_contents;
?>

Yes, it’s very hacky and likely not efficient but it does the job.
It changes:
http://warrenshea.com/common/stylesheet.css (HTML5 good) to
http://warrenshea.com/common/proxy.php?url=stylesheet.css&type=css (HTML5 bad)
and
http://warrenshea.com/common/scripts.js (HTML5 good) to
http://warrenshea.com/common/proxy.php?url=scripts.js&type=js (HTML5 bad)
but I only have to edit one file and it’ll make the non-HTML5 version automatically. Sweet.

Anyways, I thought this was worth sharing. Someone might find this technique useful.

Tutorial: This ain’t yo mom’s absolute pathing…sup?!

Monday, April 9th, 2012 at 4:39 pm

I should probably have a better title name considering what this tutorial is supposed to accomplish.

So as most of you hopefully know, putting a leading slash in a path refers to a root directory.

Example:
If the domain is http://www.worldofwarren.com/ and you link to
<a href=”/images/”>images</a>,
it will link to http://www.worldofwarren.com/images/

So what happens if you put 2 leading slashes in a path?
NOTHING LIKE THE ABOVE.

Purpose of this tutorial
To display the practical use of a URL with a leading double slash (//) in a path.
A URL with a double slash inherits the current protocol.

What you need to know/have
Basic HTML

Procedure
If you’re on an HTTP site (http://www.URL.com/) and you have

<img src=”//www.URL.com/images/logo.gif” alt=”” />,

then the image will reference http://www.URL.com/images/logo.gif

If you’re on an HTTPS site (https://www.URL.com/) and you have

<img src=”//www.URL.com/images/logo.gif” alt=”” />,

then the image will reference https://www.URL.com/images/logo.gif

Same code. But based on current protocal (HTTP or HTTPS), different results.

My ramblings
The // takes whatever protocol (HTTP or HTTPS) that the webpage is currently using and applies the referenced item to that. It’s awesome if you’re building secure and non-secure pages.

You wouldn’t need to use this on files that are within the same domain. In this case, relative pathing is probably better. But sometimes you link to files outside your domain.

For example, Google’s jQuery or SWFObject library.

Anyways, hope you learned something. I taught a lot of people this since learning it earlier this year, it’s awesome and so useful!

People are always asking “This form is supposed to be secure, but IE is prompting me with an alert that there are unsecure elements. PLZ FIX” and then you can be like “YO I JUST APPLY THE LEADING DOUBLE SLASH…sup?!”