Choose Your Theme
Warren Shea

Archive for the ‘PHP’ Category

Site Updates – Sections

Sunday, January 6th, 2013 at 11:54 pm

Whoa. When was the last time worldofwarren.com had updates!?

I’ve been meaning to create a TO DO list section for a while. I had to make it in a way that would be easy to edit – that is, NOT a code page (cuz opening up code via a code editor is a pain), and NOT a wordpress page as finding that wordpress page to edit is a pain. Also, editing a wordpress page is a pain.

Also, my co-worker, Grant, said that he doesn’t consider watching a movie as an achievement. But I do (my threshold of achievements is lower :S).

So I made an Achievements section. A place to track things in my life in progress, things to start (TO DO List) and easily track things I’ve done (Achievements).

I built a simple admin section on Friday: Achievements Admin. And no, you cannot edit anything in this section.
Originally, I created a textbox where I had to fill in a password – that was the only way you could edit something. But I changed it around so that the password input is hidden and the value is derived from the URL (so the URL linked above is not the URL *I* use).

The cool thing is that while the INSERT and DELETE only activate when you click their buttons (as the page needs to refresh to add/remove the item), the UPDATES to any existing item are updated via AJAX POSTS. So there’s no “Submit” when you make an edit, you edit the textbox and it will change the database. Assuming again, that the password works. Beautiful :)
(and yes, I could have made the INSERT and DELETE AJAX POSTS as well but I don’t think it was worth the effort).


Links sections removed.
I moved Friend’s links to the right side of the homepage.


Projects sections removed.
I combined it with my Hobbies section.


Figure Review sections added.
I’m not sure how much use I’ll get out of this but I wanted to do figure reviews for my non-Kotobukiya Bishoujo figures.

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!

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.

Site Updates – Facebook Status and Recent Comments in the Right Col. –>

Tuesday, January 24th, 2012 at 12:00 am

Wow, when was the last time I did any type of site update?

Anyways, I did some worldofwarren.com maintenance today, first time in a while.

What I did was add 1 Facebook Status to the right column, underneath the 3 Twitter Tweets.
Below that, I added the 3 most recent Comments, underneath the Facebook Statuses.

I didn’t want to display the comments too prominently on my site as it’s not my content, so I make you simply click “See most recent” to see them. I notice that sometimes I get really good or interesting comments on really old posts. It’s very likely no one would read those though…(other than me) and I find that unfortunate. I’d like those voices to be heard/read.

I really hope this doesn’t discourage people from commenting. Comment on this post if you think it’s a bad idea…and it will ironically do what you don’t want it to do! So….basically, I’m saying there’s nothing in it for you.

<Technical Tutorial>
Getting the Facebook Status to work was pretty difficult. There’s a Facebook RSS feed but you can’t just pull from it. But that’s the same as any RSS feed. You have to create a proxy to bypass the cross domain issues. It’s super simple:

proxy.php

<?php header(“Expires:Mon, 31 Dec 2010 05:00:00 GMT”); ?>
<?php
if ($_GET[“type”] = “xml”) {
header(“Content-type: text/xml”);
$page_contents = file_get_contents($_GET[“url”]);
}
echo $page_contents;
?>

and I just call any XML/RSS via URLs like this:

proxy.php?type=xml&url=http://search.twitter.com/search.atom?q=from:warrenshea
proxy.php?type=xml&url=http://www.worldofwarren.com/?feed=comments-rss2

Unfortunately, for some reason, Facebook doesn’t allow this. They have this whole Developer API you have to work with to get the Facebook Statuses. Why? I think that imo, having Facebook Statuses come up as simple RSS feeds for people defeat the purpose of Facebook, as well as they lose money on advertising if you can pull the Facebook Statuses from other sites.

So I had to do something else for Facebook Status. I’m not going to write a tutorial since I didn’t make it. I will say that I got it HERE:
PHP Show Your Facebook Status on your blog/website
</Technical>