RSS Reader – PHP Script For Displaying An RSS Feed On A Web Page

Display RSS Feeds On Your Website

Here I am going to go over a little plugin that will allow you to display RSS Feeds on to your site

I was searching the web for an easy feed puller and was having no luck comping up with one that let me have full control of the style well keeping things simple for me to install and use, so I had to create one. But lucky for me a lot of the code was the same as the Twitter Feeds I made a week or so ago that you can find HERE.

In the download you will see two .php files 1:(RSS_Feeds.php) 2:(RSS_Feeds_striped.php). RSS_Feeds.php is the file that I used in the demo so it has the style and a few other divs in it well RSS_Feeds_striped.php is just the php code that you need to get this thing working.

OK, lets get to the demos! :)

Demo 1: Live Demo Here
This is a demo of me adding a little design to the feeds.

Demo 2: Live Demo Here
This is a demo with out any style at all.

Now that we have the Demos out of the way lets get to the stuff you really want!! The download so you can have a go at the files and see if it works for you.
DOWNLOAD HERE!!

As a note I have only tested this with three (3) types of RSS feeds so if you find one that this does not work on let me know and I will try my best to make it work! :) Also if you have any problems or see anything that could be done better let me know and I will take another look at the code.

The three feeds I have tested this on are NPR , Yahoo News and WordPress (my blog – the one you are reading).

So I guess we should get in to some of the code? Ok, fine I will talk for a little bit about how to set this script up.

To get started there are really only three lines you will need to change and that is these three lines.

  1.  
  2. curl_close($feed_curl);
  3. $feed = $RSS_Feed_URL;
  4. $feed_curl = curl_init();
  5. $timeout = 5;                                                                                           // set to zero for no timeout
  6. curl_setopt ($feed_curl, CURLOPT_URL, $feed );
  7. curl_setopt ($feed_curl, CURLOPT_RETURNTRANSFER, 1);
  8. curl_setopt ($feed_curl, CURLOPT_CONNECTTIMEOUT, $timeout);
  9. $file_contents = curl_exec($feed_curl);
  10. $feed_content = $file_contents;
  11. $the_feed = explode("<item>", $feed_content);
  12. $tcount = count($the_feed) – 1;
  13. for ($i = 1; $i <= $tcount; $i++) {
  14. $end_feed = explode("</item>", $the_feed[$i]);
  15.  

This next two lines tells are calling in the description witch I am calling content.

  1.  
  2. $description = explode("<description>", $end_feed[0]);
  3. $content = explode("</description>", $description[1]);
  4.  

The next three lines were added to fix a few problems I ran in to.

  1.  
  2. $content[0] = str_replace("<![CDATA[", " ", $content[0]);       // Needed for Word press
  3. $content[0] = str_replace("]]>", " ", $content[0]);             // Needed for Word press
  4. $content[0] = str_replace("&#60;", "<", $content[0]);           // This makes images and links work
  5.  

The WordPress fix was added becouse I was running in to a problem with WordPress putting all the content in a CDATA call and not allowing the content to show in my page. Then I was running in to a problem with images and links printing out in plane text so the 3rd line was added to fix that problem.

This next four lines was added becouse I know not everone is going to want to add images and links to the feeds they are pulling in so I added this setting to let you remove them if you wanted.

  1.  
  2.  // This line removes all html in the feed
  3. if ($images_in_feeds == no){
  4. $content[0] = strip_tags($content[0]);
  5. } else{ }
  6. $my_feeds[] = $content[0];
  7.  

The next three lines are used to pull in the title of the feed. If you are looking to add a new part to pull in this is the best code to look at for a starting point. It is the three lines that are needed to pull in anything.

  1.  
  2. $the_title = explode("<title>", $end_feed[0]);
  3. $titlecontent = explode("</title>", $the_title[1]);
  4. $title_my_feeds[] = $titlecontent[0];
  5.  

These three lines are used to extract the link from the RSS feed. The same goes as above, I did not mod any of this data as it was not needed to be used.

  1.  
  2. // Pull In Link
  3. $link = explode("<link>", $end_feed[0]);
  4. $linkcontent = explode("</link>", $link[1]);
  5. $link_my_feeds[] = $linkcontent[0];
  6.  

Next I am pulling in the the time. This kind up jump around a little bit due to how I wanted to display the time in the finished product so I am going to go over it one at a time.

This is where I pull in the time

  1.  
  2. $feed_time = explode("<pubDate>", $end_feed[0]);
  3. $timecontent = explode("</pubDate>", $feed_time[1]);
  4. $timecontent[0] = strtotime("$timecontent[0]");
  5. $time_my_feeds[] = $timecontent[0];
  6.  

Now I change the time from being a stream of number witch is the the time in seconds of the post to being posted to how long ago in seconds it was posted.

Then I take that number and make is so I can display the time in weeks, days , hours and seconds.

  1.  
  2.         $time_agos = array(
  3.         $thedays,
  4.         $thehours,
  5.         $themins /*,
  6.         $thesecs */
  7. );
  8. foreach($time_agos as $time_ago){
  9. if ($theweeks<"1" && $time_ago>"1"  )
  10.         echo $time_ago;
  11. else
  12.         echo "";
  13. }
  14. if ($theweeks>"1")
  15.         echo $theweeks ; /*.$thedays This is out until I stop it from Showing 0 days */
  16. else
  17.         echo "";
  18.  

Well that is it for the most part, the only thing I have left out is where it all comes together. That is done with this bit of code.

  1.  
  2.     <?php
  3. $cnt=0;                                                                                                 //Control Feed count
  4. while (
  5.         (true && $cnt<$number_of_post) &&  
  6.         (list(, $the_rss_feeds) = each($my_feeds )) &&
  7.         (list(, $link_feedss) = each($link_my_feeds)) &&
  8.         (list(, $title_feeds) = each($title_my_feeds)) &&
  9.         (list(, $time_feeds) = each($time_my_feeds))
  10.  ){
  11.         $cnt++;                                                                                         //Control Feed count
  12.  // This Has to do with showing how long ago the post was
  13.         $interval = time()-$time_feeds;
  14.         $year   = $interval/29030400;
  15.         $month  = $interval/2419200;
  16.         $week   = $interval/604800;
  17.         $days   = $interval/86400;
  18.         $hour   = $interval/3600;
  19.         $min    = $interval/60;
  20.         $sec    = $interval/1;
  21.        
  22.         $frac_w                 = $weekfloor($week);
  23.         $frac_d                 = $daysfloor($days);
  24.         $frac_h                 = $hourfloor($hour);
  25.         $frac_m                 = $min  - floor($min);
  26.  
  27.         $theweeks       = floor ($week)                 .‘ Weeks ‘;
  28.         $thedays        = floor ($frac_w*7)             .‘ Days ‘;
  29.         $thehours       = floor ($frac_d*24)    .‘ Hours ‘;
  30.         $themins        = floor ($frac_h*60)    .‘ Minutes ‘;
  31.         $thesecs        = floor ($frac_m*60)    .‘ Seconds ‘;
  32. // Adds Unique Id to each Feeds
  33. $i = $feed_add_id++; ?>
  34.     <li class="feeds" id="<?php print ‘feed’.$i; ?>" ><span><?php echo $title_feeds ?>: </span> <?php echo $the_rss_feeds?> <a class="timespan" href="<?php echo $link_feedss ?>" target="_blank" title="<?php echo $title_feeds ?>">Post:
  35.       <?php
  36.         $time_agos = array(
  37.         $thedays,
  38.         $thehours,
  39.         $themins /*,
  40.         $thesecs */
  41. );
  42. foreach($time_agos as $time_ago){
  43. if ($theweeks<"1" && $time_ago>"1"  )
  44.         echo $time_ago;
  45. else
  46.         echo "";
  47. }
  48. if ($theweeks>"1")
  49.         echo $theweeks ; /*.$thedays This is out until I stop it from Showing 0 days */
  50. else
  51.         echo "";
  52. ?> Ago</a> </li> <?php } ?>
  53.  

Well that is it, if you have any questions just post in the comment and I will do my best to answer and if you use this code just say thanks!

Twitter Feeds With PHP (Basic)

In my last post I showed you a Twitter Feed that had a lot of options such as.

  • Changing display name
  • Pulling in Twitter image
  • Ever tweet having a unique id
  • Showing how long ago the post was
  • giving a link to the post
  • Making links shorter
  • And a little bit more.

If you are looking for a more advanced Twitter feed you can find that
HERE

But this one is just for the basic user. I pulls in the tweets, puts them in an li and that is it.
The code has went from 120 lines (I think) to about 30 lines of code.

I have also not added any style to the one at all.
You can view the demo
Here
And download the files
Here

So lets go over a little of the code now.

  1.  
  2.         $username = "James_Riter";
  3.         $limit = 50;
  4.  

That is the first two lines of the php code and it is where you will change the user name and how many tweets you wish to pull in.

  1.  
  2.         $feed = ‘http://twitter.com/statuses/user_timeline.rss?screen_name=’.$username.’&count=’.$limit;
  3. $ch = curl_init();
  4. $timeout = 5;
  5.         curl_setopt ($ch, CURLOPT_URL, $feed );
  6.         curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
  7.         curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  8.         $file_contents = curl_exec($ch);
  9.         $tweets = $file_contents;
  10.  

The next 8 lines or so are just setting up the where the feeds are and using “curl” to go grad the page that has the feeds on them. It also has a time out so that if Twitter is down (Something that seems to happen often) It will not slow your site down to much trying to grab feeds of a down site.

  1.  
  2. $tweet = explode("<item>", $tweets);
  3. $tcount = count($tweet) – 1;
  4. for ($i = 1; $i <= $tcount; $i++) {
  5. $endtweet = explode("</item>", $tweet[$i]);
  6.         $title = explode("<title>", $endtweet[0]);
  7.         $content = explode("</title>", $title[1]);
  8.         $content[0] = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,100})[^\s<]*)/", ‘<a href="http://$2$3" >$4</a>’, $content[0]);
  9.         $content[0] = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" >@\\1</a>", $content[0]);
  10.         $mytweets[] = $content[0]; }
  11.  

All of this code is saying now that I have the feed look for something called “item” and inside item grad what is called “title” but skip the first one.

That takes you to the line where you can see the closing tag to title.

After that the next two line witch look like this

  1.  
  2. <ul id="twit">
  3. <?php while ((list(, $thetweets) = each($mytweets ))){ ?>
  4. <li class="tweets"> <?php echo $thetweets?> </li>
  5. <?php } ?>
  6. </ul>
  7.  

And that is it, now you are pulling in just normal tweets to your page.

If you want to see what the feed looks like that you are pulling in you can go
Here
and take a look at the code (chrome and FF just push ctrl+U) and that will give you an idea of what you can pull in.

Add A Twitter Feed With PHP (Advanced)

Here we are going to go over a little file that I have put together for pulling in Twitter feeds. You will see that in the title this is titled as “Advanced” and the reason for that is there is a lot that this file does.

To View A DEMO look
HERE.

Download my demo files
HERE.

I also have the files on Soutceforge for you to down load
Sourceforg Link

I have been working on this for a few days and over time will make updates. I have tried to pack as much as I could in to this little plug in with out making it to complex for the every day user. I think as long as you know css and basic html you will be able to work with this with no problem at all.

As I will go over latter you really only need to mess with three lines of code.
That is to change the Twitter user, change the user name and to pick how many tweets you want to pull in.

Also this will validate as XHTML 1.0 Transitional and the only thing stopping it from doing Strict is I have a target=”_blank” in the code. So that should be an easy thing to fix if you care about Validation and need Strict HTML for any reason.

So lets go over some code here. :)

  1.  
  2. $username = "James_Riter";
  3. $displayname ="James";
  4. $limit = 10;
  5.  

That is the first three lines of code and if you dont want to deal with php it is really the only code you will have to mess with other than the css I am guessing.
So it work like this.
Line 1: That is your Twitter Id
Line 2: That is the name that will show up in the tweet
Line 3: That is the number of tweets you will be able to pull in.

If you set those three lines and remove all my css you will be in good shape to style your new feeds.

  1.  
  2. // Checks if Twitter feed is good
  3. $checkfeed = curl_init(‘http://twitter.com/’.$username);
  4. curl_setopt($checkfeed, CURLOPT_RETURNTRANSFER, true);
  5. curl_exec($checkfeed);
  6. if(curl_getinfo($checkfeed, CURLINFO_HTTP_CODE) == 404) {
  7.         $username = "James_Riter";
  8.         $displayname ="James";
  9. }
  10.  

That bit of code is to make sure you never pull in a dead twitter feed. So if you have set the name is still see me then you know you have typed your name in wrong.
What it does is sees if you get a twitter 404 pages and if so defaults to my twitter feed.

  1.  
  2. $title = explode("<title>", $endtweet[0]);
  3. $content = explode("</title>", $title[1]);
  4. $content[0] = str_replace("&#8211;", "&mdash;", $content[0]);
  5. $content[0] = preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", ‘<a  title="$4" class="linksfromtwit" href="http://$2$3" target="_blank">Check Out This Link!</a>’, $content[0]);
  6. $content[0] = str_replace("$username: ", "$displayname_fix", $content[0]);
  7. $content[0] = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $content[0]);
  8. $content[0] = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $content[0]);
  9. $mytweets[] = $content[0];
  10.  

This bit of code is what pulls in the tween its self. There is not a lot you would want to change in here.
What is does is looks in the rss feed that we are pulling the tweets from and pulls out the title witch is the full tweet its self. then it grabs the links and puts them in to link form so we have something to work with.

  1.  
  2. $link = explode("<link>", $endtweet[0]);
  3. $linkcontent = explode("</link>", $link[1]);
  4. $linkmytweets[] = $linkcontent[0];
  5.  

This is what pulls in the links to the tweet its self. If you look at my demo you will see that the Time Ago is also a link. So I wanted to pull in a link to the tweet its self so I could link the two.

  1.  
  2. $twittime = explode("<pubDate>", $endtweet[0]);
  3. $timecontent = explode("</pubDate>", $twittime[1]);
  4. $timecontent[0] = strtotime("$timecontent[0]");
  5. $timemytweets[] = $timecontent[0];
  6. }
  7.  

This bit of code is what pulls in the time I had to add it to this next bist of code to de the out come I wanted.

  1.  
  2.  
  3. $interval = time()-$timetweets;
  4.  
  5. $year   = $interval/29030400;
  6. $month  = $interval/2419200;
  7. $week   = $interval/604800;
  8. $days   = $interval/86400;
  9. $hour   = $interval/3600;
  10. $min    = $interval/60;
  11. $sec    = $interval/1;
  12.  
  13. $frac_w         = $week     – floor($week);
  14. $frac_d         = $days      - floor($days);
  15. $frac_h                 = $hour      - floor($hour);
  16. $frac_m                 = $min  - floor($min);
  17.  
  18. $theweeks       = floor ($week)         .’ Weeks ‘;
  19. $thedays        = floor ($frac_w*7)     .’ Days ‘;
  20. $thehours       = floor ($frac_d*24)    .’ Hours ‘;
  21. $themins        = floor ($frac_h*60)    .’ Minutes ‘;
  22. $thesecs        = floor ($frac_m*60)    .’ Seconds ‘;
  23.  

When Twitter gives you the time it looks something like this “Mon, 01 Nov 2010 17:38:38 +0000″
and seeing that I wanted to show how long ago the post was I had to do a little extra work.
But what that code does for the most part is takes the time Twitter gave up and then convert it to a usable time. Now that I have a usable time I just do a little math game.

I take the seconds and divide them by what I need to use. “$years $months $weeks”

Then I take weeks and subtract it by what is called floor.
Say my weeks in seconds looked like this 1604800.34564
What floor does is gets rid of ever thing after the “.” so “34564″ is then gone.

Now that I have a nice number to work with I times it by the needed number.

The math problem would look a little like this..

My days in seconds
1604800.34564 / 86400 = 18.5740781
18.5740781 – .5740781 = 18
18 * 7 = 126 days

  1.  
  2. $userimage = ‘http://img.tweetimag.es/i/’.$username;
  3.  

This is used just for the twitter user image that gets pulled in.

Well there is more to it than just that I have worked hard to make a good plug in that does a lot for you with out having to set any thing up.

If you have any questions just let me know. As soon as I get a chance I am going to strip this code down to just the basics so that for those that would like it can just have a simple twitter feed.

Links Overflowing On Chrome And IE

What to do when long links start to over flow in to the rest of your page.

This is going to be a little of a short post but I ran in to a problem that seems to of only happen in a few browsers.. Or better put it does not happen in Firefox.

The problem is that when I am pulling in my Twitter feed the links seem to go all kinds of crazy across the site.
Here is the code (or close to) that gets printed in on my site.

<ul>
<li class="tweets">James_Riter: Cool Full Page Coda Slider! With demo and files to download. 
<a href="http://www.jamesriter.com/blog/2010/05/13/full-page-coda-slider-effect/" target="_blank">http://www.jamesriter.com/blog/2010/05/13/full-page-coda-slider-effect/</a></li>
<li class="tweets"><a href="http://twitter.com/James_Riter/statuses/28850407768" target="_blank">http://twitter.com/James_Riter/statuses/28850407768</a></li>
<li class="tweets">James_Riter: Setting up a Desktop over the weekend did not go so well. :( I think I have to buy a new motherboard. <a href="http://ff.im/sgtLS" target="_blank">http://ff.im/sgtLS</a></li>
<li class="tweets"><a href="http://twitter.com/James_Riter/statuses/27771305418" target="_blank">http://twitter.com/James_Riter/statuses/27771305418</a></li>
<ul>

So as you see there is nothing out of the normal there ans what you cant see is that all that code is in a side bar the has a width of about 300px.

But in any case lets get to the good simple fix for this problem..


overflow:hidden

Add that to the cantoning div witch are holding the links. In this case the div that was/is holding the twitter feeds.

What James Riter Has Been Up To

My name is James Riter and I am a Las Vegas web designer and programmer.

Most of the time this blog or My Facebook will be the best way to keep up on my life. (So only my mom will be reading this)

But there are a few things I have in the works.
I am building my own CMS, well I have V1 of Proclarush I am re doing all the code so I am make a lot of improvements. IF you are a designer and have a small project coming up let me know. I would like some one to test my system and tell me where it needs more work.

I am going to be making a lot of changes to my site The SEO Hero. As it stands not it is just a pointless blog that I never touch. I was hoping to make it more of my own freelance site but I am going to make it a 3 part site. The main will just be basic SEO information, the second will be a blog that I will let a few other trusted people blog on about SEO work, the the theried will be a SEO twitter. I am still a ways from getting that done but I cant wait to see how it goes.

I am also going to recode my main site. JamesRiter.com. I love the way it looks now but it is so slow I am sure it makes me look like I have no idea how to code a single thing. When I am done it will look the some but move a lot faster! (I hope!)

I still have no idea what I am going to do with this site but I am sure I will come up with a better idea than I site that I just use for testing. chaos67731.com

Speeding Ticket In Las Vegas NV

We have all been there, One minute you are driving down the street (maybe a little fast) minding your own business and the next minute you are getting pulled pulled over and have a list of charges miles long.

There are a few things I have learned about getting pulled over in Las Vegas or North Las Vegas.

  • 1: Cops want to give you a ticket.
  • 2: You’re not going to walk away with just a speeding ticket.
  • 3: It is best to have someone go to court for you!
  • 4: Speeding tickets WILL cost you a lot of money!

So let’s cover this one at a time.

Number 1:  Copes want to give you a ticket.

We have all heard the jokes about it being the end of the month so cops need to make the payroll. But how much of a joke is that really?  I got pulled over for my back light being out and drove away feeling like I just got fucked over.  I know cops are not out to hurt us but they are also not there to listen to us. To the cop that pulled me over it did not matter that I was driving a friend’s car that was from out of state. I guess when he was in town for a few days he should have registered his car in Las Vegas so I could run to the gas station.  If the cop was out there really wanting to do good I think it would have been great for him to say. “Just wanted to let you know your back light is out” and called it good. But he had to run all my information and see what he could hit me with.

Number 2:  You’re not going to walk away with just a speeding ticket.

You know that it never happens that you will walk away with a speeding ticket and that’s it. It is a cops job to find things wrong and when they pull you over that’s just what they are going to do.  Just keep that in mind. It is there job to give you tickets and that will never change.

Number 3: It is best to have someone go to court for you!

I design WebPages and do SEO work. I have next to no idea what should be done in court and what is the best way to handle things.  And most people are just like me on this one. We have all been told to plead not guilty to speeding ticket but what do you do after that and more so does it really help?

I have seen it go both ways. I have seen it hurt and help a person and when it hurts it really hurts them.

The first time I had someone go to court for me I got really fucked! The guy did not show up and got a warrant for me and in the end just said “guilty” for me.

This last time (Ok it’s been 2 times) I have called a guy named Rick at Law Offices of Paul J. Adras and let me tell you it really does matter who goes to court for you.

I had a warrant for not showing up to court and needed to get it fixed without paying the thousand dollars the court wanted me to pay. So I started to make a few calls and well I thought I was going to jail. Everyone wanted like $700.00 just to take care of the warrant.  Then I found Rick at Paul J. Adras Law Office and they took care of it really fast and cost me about 1 tenth of the court wanted. (That about $100.00 for the lazy people like me)  And if you ask me that is better than waiting to go to jail or paying a thousand dollars to the court just for forgetting one date.

Number 4: Speeding tickets will cost you a lot of money!

This kind of goes hand in hand with number 3.  One way or another you are going to pay. There is nothing you can do about that. The real question is, how much do you want to pay?   I have gone to court and had it cost me $900.00 and I have had Rick help me get that down to $200.00.

To sum it all up if you live in Vegas you are going to need a good Las Vegas Traffic Attorney and the guys over at The Law Offices of Paul J. Adras, PC are great!  Trust me I have yet to save my work number in my phone (been here for about 2 years) but I saved their number.  They don’t over charge and they are kind and they don’t mess around.

You can contact them with this information

The Law Offices of Paul J. Adras, PC
4532 W. Charleston Blvd.
Las Vegas, Nevada 89102
702 489 2264

answers@gotspeedingticket.com

Proclarush Taonas My First CMS (No Database)

Proclarush Taonas

Well I have just finished what I am calling Proclarush [If your not a Stargate fan, it means Lost In Fire]

This is my my first try at a CMS and all in all I am very happy with how it has turned out.

Proclarush Taonas Works With NO Database

First I will let you have a link to it so you can get a feel for it and then I will tell you a little about what I have added to it.
http://proclarush.jamesriter.com/

First off you should see I kept it at a very basic design, I did this for a reason.  I am building this so that you can design skins for it and change the hole site look with about two lines of code. But this is also a place where I fell a little short. [More about that latter]

Some of what I have added

As you go over the site you will see I wanted to build some of the most basic things needed in any modern website today.  So it has things like.

Guest Book: A simple way for people to say thanks.

Media: I have built in a flash video player and mp3 player for that you can share you media and not have to worry about other hosting sites going down.

Contact Form: There is really two built in but I am only showing one for now. The second one is a popup one that works by clicking on a link.  But both of them have an auto replay to who ever filed out the form and should stop you from getting spam.

Some of the basic things I have added are things like a image popup that is shown on the front page, a mouse over tip by title,  a weather feed, a twitter feed, social links,  and best of all a client back end.

Client Backend

The client back end is one thing that I really like about it.  If you look at the About Us page you will see a little “:)” well you will see it all over the site.  Every where you see that is a spot that the client is able to edit the text from the back end.  I wanted this for a few reasons. For One I know as a designer it is a pain in the ass when you are working with a client and they call you every day wanting something little changes or some “NEW” bit of info on the front page ASAP. So now I am able to tell them they can change it as much as they would like. :)

And another good reason is, well this gives you a chance to help make the client feel like this site is theres two, and with out all the complex things that a lot of heaver weight CMSs have.

There is also a mobile side [still needs a little work] but for the most part it is done.

Have A Mobile Site With Half The Work

My goal is to have a mobile site that depends of the main site. So when I finish content for the home page it will be pulled in to both the full site and the mobile site. You can test it out on your phone or go to proclarush.jamesriter.com/mobile to see it. But as I said it is not where I want it to be.

Before I go I would like to talk about the changing of the skins. [I said I would get back to it] As it stands now there is no problem making a new skin for it that will work just fine. The only thing that has its draw backs it you have to copy all the css and js files in to a new folder and change a few links.  But it does give you the freedom the make a full new site well still keeping the main links and content in place witch I kind of liked.

Change Common Information Once And Have It Change Site Wide

Another good thing to point out about Proclarush is that I have  what I call a setting page and in that setting page you are able to change all kinds of things.

Say you have the email address, client name and phone number. Well if you use my system rite you could use all three of them over a hundred time in the site and if your client wants all three changed you will only have to change three lins of code. {I am new to PHP but I am really starting to love the power it has. :) }

Well, I am not sure I am going to release version 1, seeing that I am not going to start working on Version 2! That is going to be based on MVC and a lot of other powerful tool I am learning.

But at the same time I kind of would like a few designers to build around my system so that I can get there input and see where I need to improve what I have made so far.  So if you are a designer and have a small job coming up let me know and we can talk about giving you the files to work with.

A few helpful hints to making your first CMS or Website

I have just finished my first CMS and well I just wanted to give a few helpful hints to anyone that is like me and new to php, programing and taking on such a project.

You can view what I am calling proclarush V1 at
You can view my CMS at http://proclarush.jamesriter.com/.

As soon as I get a chance I will be doing a full rundown of what is in my little CMS.

I never planed on making a CMS, in fact when I started I was just looking to build a simple reset with a few pages in place to help me put out demo pages faster. In fact MOST of what I know about PHP I learned building Proclarush (Thats the name I gave it).

Seeing that there is way to much to go over in one post and I done really feel like sitting down that long I am going to cover the basics and a few things you should keep in mind if you are going try and build your own.

First!! Know what you want out of it!
As I said when I started I was not planing to make a CMS of any kind and that its self has come to bite me in the ass more time than you could think of! There are many different kinds of CMSs out there so look around and see what you are aiming to do. Just to give you a few things to think about here are a list of some common things a CMS would be used for.

Blog:
Shopping cart:
Information:
Personal use:
Small business:
Large business:
And so on and so on…

So after you know what you want to do with it you will need to set the ground work. This is also something I did not do so well. Due to that there was a point where I wanted to change on thing and that alone made me change 6 other pages.

Lets get to the layout of things. This would be the main directory.


blog/
cache/
mobile/
proclarush/
sitemap/
wiki/

Keep in mind Proclarush is what I have named my system so you will want to come up with a name asao. :)

This is what inside of Proclarush looks like.

content/
css/
form/
images/
js/
media/
php/
plugin/
settings/
skins/

Now that you have a the main files in place it is time to start setting up some files.
Like all site you should start with an index.php but unlike a lot of site you are not going to start adding in content and images just yet. In fact there is not one div span or H tag in my index.php. I have under 15 lines of code that start it all off.


//Setting "Main_DIR" to /proclarush
define('Main_DIR', 'proclarush/');

//Pulling in the setting and directory page
include_once(Main_DIR.'/settings/directory.php');
include_once(Main_DIR.'/settings/settings.php');

//Pulling in the base skin
include_once(SKINS_DIR. 'base_skin.php');

?>

Well my index has a few more lines this is what you will need to get started. So lest go over this line my line and what is in each file that is being called in.

Line 1:
define('Main_DIR', 'proclarush/');
This is saying that “Mail_DIR” is equal to http://yoursite.com/proclarush

Line 2:
include_once(Main_DIR.'/settings/directory.php');
This is calling in a the “directory.php”. This will be used to create created directory constants for all the files you have in your site.

The code inside of this file look a little like this.

// This is to set up the directy list
if(preg_match('/\/$/', $_SERVER['DOCUMENT_ROOT'])) {
define('ROOT_DIR', ($_SERVER['DOCUMENT_ROOT']));
} else {
define('ROOT_DIR', ($_SERVER['DOCUMENT_ROOT']).'/');
}

//All things in the root directy
// How To Use "echo Main_DIR;"
if(!defined('Main_DIR')) define('Main_DIR', ROOT_DIR.'proclarush/');
if(!defined('BLOG_DIR')) define('BLOG_DIR', ROOT_DIR.'blog/');
if(!defined('Cache_DIR')) define('Cache_DIR', ROOT_DIR.'cache/');
if(!defined('PLUGIN_DIR')) define('PLUGIN_DIR', Main_DIR.'plugin/');
if(!defined('SITEMAP_DIR')) define('SITEMAP_DIR', ROOT_DIR.'sitemap/');
if(!defined('WIKI_DIR')) define('WIKI_DIR', ROOT_DIR.'wiki/');

//Main Folders in Proclarush
if(!defined('CONTENT_DIR')) define('CONTENT_DIR', Main_DIR.'content/');

Now you might be asking why is this a good idea? Lets say this is how things are laid out on you site to get to an image.
yoursite.com/content/contact/form/image/a_nice_image.png
And you coded it something like this.

<"show" img alt="nice image" src="

Now say this is your FORM_IMG_DIR

define('FORM_IMG_DIR', ROOT_DIR.'/content/contact/form/image/');

Now was you just want to move that image to the folder with the rest of your images. well if you have a large site you may have a lot of images to relink. But if you do it this way you will just have to change that link in one place.
So change this:

define('FORM_IMG_DIR', ROOT_DIR.'/content/contact/form/image/');

To this:

define('FORM_IMG_DIR', ROOT_DIR.'/image/');

And thats it.

Now line 3:
include_once(Main_DIR.'/settings/settings.php');
Now this is going to be information that you will need over and over again.
Lets use four common things that you will use in a site.
Name:
Email:
Address:
Link to blog:

Well if the client ask you three months after the site is done to change her email address it could be a pain to remember where all that email address in. That is where this comes in.

The code will look a little like this.

$ClientName = "James Riter"
$ClientEmail = "chaos67731@gmail.com"
$ClientAddresse = "Hot As Hell Las Vegas"
$ClientBlog = "Jamesriter.com/blog"

Now every time you want my name or email in the site you can do this.

and changing my name from James to Jane only has to be done in one spot see that your client was a girl.

Line 4:
include_once(SKINS_DIR. 'base_skin.php');

Rite here I am including what I call the base skin, This file for me holds a lot of basics to the site but at the same site it does not really hold much. Just like the index.php you should call in a lot the this page to it clean and easy to work with.

Well I was going to set up a few files to download but it is getting late. If you want some and I have not added any yet just let me know and I will send something your way.

You can view my CMS at http://proclarush.jamesriter.com/

Rite now I am on V1 and am starting to learn about MVC so will be updating as soon as I got time.

Now time I will cover
1: Building a nav
2:Pulling in content
3:What I put in my CSS

Add Yahoo Weather To Your Site With PHP

For the past few weeks I have been working on a type of CMS that does not need MySQL or any date base for that matter. :)

I am still new to php so this has been my helping hand in getting to learn a little. I am now on V2 of what I am calling Proclarush. (Yes I am a Stargate fan) And after setting up all the files and getting things to link rite I am now adding in some plugins. The one that was a pain to find was one for weather.

So lets get in to adding some weather to you site!

How I am doing this is by calling a .php file in to my site like this.

<?php include_once ('weather.php'); ? >

You can add that where ever you want your weather to show up.
**If you are new, make sure you are working with a .php file “index.php”**

Now to the code in side the weather.php I am going to put it all in at once and then help you out with how it works the best I can.

<div id="weather">
<h2 class="h2"> Weather </h2>
<?php
$weatherZIPCODE = "89145"; //Change The Zip HERE

function retrieveYahooWeather($zipCode = '$weatherZIPCODE') {
$yahooUrl = "http://weather.yahooapis.com/forecastrss";
$yahooZip = "?p=$zipCode";
$yahooFullUrl = $yahooUrl . $yahooZip;
$curlObject = curl_init();
curl_setopt($curlObject,CURLOPT_URL,$yahooFullUrl);
curl_setopt($curlObject,CURLOPT_HEADER,false);
curl_setopt($curlObject,CURLOPT_RETURNTRANSFER,true);
$returnYahooWeather = curl_exec($curlObject);
curl_close($curlObject);
return $returnYahooWeather;
}
$localZipCode = $weatherZIPCODE;
$weatherXmlString = retrieveYahooWeather($localZipCode);
$weatherXmlObject = new SimpleXMLElement($weatherXmlString);
$currentCondition = $weatherXmlObject->xpath("//yweather:condition");
$weatherLoca = $weatherXmlObject->xpath("//yweather:location");
$currentTemperature = $currentCondition[0]["temp"];
$currentDescription = $currentCondition[0]["text"];
$currentTitle = $currentTitle[0]["text"];
$weatherLoca = $weatherLoca[0]["city"];
?>
<ul>
<li> <?php print $weatherLoca;?></li>
<li>Current Temperature: <?php print $currentTemperature;?>°F</li>
<li>Current Description: <?php print $currentDescription;?></li>
</ul>
</div>

You can see it working
here
And download the files
here

Now to some of the need to know stuff.

This is just saying get the file “weather.php”

<?php include_once ('weather.php'); ? >

In weather.php look at line 4 and you will see where you set you zip code.
$weatherZIPCODE = "89145";

Now to get this to show the town I wanted I had to add this.

//Make This Up //Find this is the RSS
$weatherLoca = $weatherXmlObject->xpath("//yweather:location");
//This says it = its self but is looking in ["city"]
$weatherLoca = $weatherLoca[0]["city"];
//This Will Print it out :)
print $weatherLoca;

If you go to Yahoo Weather
you will be able to find the the xlm file that the php uses to get your information.
And it looks a lot like this

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<rss version="2.0" xmlns:yweather="http://xml.weather.yahoo.com/ns/rss/1.0" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#">
<channel>
<title>Yahoo! Weather - Sunnyvale, CA</title>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html</link>
<description>Yahoo! Weather for Sunnyvale, CA</description>
<language>en-us</language>
<lastBuildDate>Fri, 18 Dec 2009 9:38 am PST</lastBuildDate>
<ttl>60</ttl>
<yweather:location city="Sunnyvale" region="CA" country="United States"/>
<yweather:units temperature="F" distance="mi" pressure="in" speed="mph"/>
<yweather:wind chill="50" direction="0" speed="0" />
<yweather:atmosphere humidity="94" visibility="3" pressure="30.27" rising="1" />
<yweather:astronomy sunrise="7:17 am" sunset="4:52 pm"/>
<image>
<title>Yahoo! Weather</title>
<width>142</width>
<height>18</height>
<link>http://weather.yahoo.com</link>
<url>http://l.yimg.com/a/i/us/nws/th/main_142b.gif</url>
</image>
<item>
<title>Conditions for Sunnyvale, CA at 9:38 am PST</title>
<geo:lat>37.37</geo:lat>
<geo:long>-122.04</geo:long>
<link>http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html</link>
<pubDate>Fri, 18 Dec 2009 9:38 am PST</pubDate>
<yweather:condition text="Mostly Cloudy" code="28" temp="50" date="Fri, 18 Dec 2009 9:38 am PST" />
<description><![CDATA[
<img src="http://l.yimg.com/a/i/us/we/52/28.gif"/><br />
<b>Current Conditions:</b><br />
Mostly Cloudy, 50 F<BR />
<BR /><b>Forecast:</b><BR />
Fri - Partly Cloudy. High: 62 Low: 49<br />
Sat - Partly Cloudy. High: 65 Low: 49<br />
<br />
<a href="http://us.rd.yahoo.com/dailynews/rss/weather/Sunnyvale__CA/*http://weather.yahoo.com/forecast/USCA1116_f.html">Full Forecast at Yahoo! Weather</a><BR/><BR/>
(provided by <a href="http://www.weather.com" >The Weather Channel</a>)<br/>
]]></description>
<yweather:forecast day="Fri" date="18 Dec 2009" low="49" high="62" text="Partly Cloudy" code="30" />
<yweather:forecast day="Sat" date="19 Dec 2009" low="49" high="65" text="Partly Cloudy" code="30" />
<guid isPermaLink="false">USCA1116_2009_12_18_9_38_PST</guid>
</item>
</channel>
</rss>

If you are like me your thinking what the hell is that! But after looking at it for a little bit its not that hard.

Watch.
Say you want to add in the wind chill.
Look for the line that says “yweather:wind”
And create a line that looks like this

$Thisisthewindchill = $weatherXmlObject->xpath("//yweather:wind");

There you are making a Variable “$Thisisthewindchill” and saying in equal to the yahoo xml file and in “yweather:wind”

Now make a line that looks like this.

$Thisisthewindchill = $Thisisthewindchill [0]["chill"];

There you are saying “$Thisisthewindchill” equals its self but is to look in “chill”.

Now all you have to do is add this line to UL/LI

print $Thisisthewindchill ;

As I said I am newish to php so I might have got something wrong, or worded something the wrong way. So if you see some thing let me know and I will change it. But I know this works and can help if you need any help setting it up on your site. Just leave a comment and I will get back to you asap!

Again you can download it
here!

How To Push A File To Your Android Device (CDMA HTC Hero)

!! UPDATE !!

Well I have not played around with the android SDK for some time but I was the other day and it seems that “adb tool” has moved in the sdk. :( So a few of the step here will be a little bit off.

So please use this as nothing more than a learning tool!

If you look in side the the tool folder in the SDK there is a file called adb_has_moved.txt is it says this,

The adb tool has moved to platform-tools/

If you don't see this directory in your SDK, launch the SDK and AVD Manager (execute the android tool) and install "Android SDK Platform-tools"

Please also update your PATH environment variable to include the platform-tools/ directory, so you can execute adb from any location."

But the main steps are just the same, If I get time and a reason I will make an update to this post. 
If you have any questions please feel free to ask.

 

 


For those out there that are just starting out I think it is a good idea to go over some of the basics first. If you are in the know about what is going on and what you need you can skip this. I am working with a HTC Hero but things should not change to much for other Android devices.

Also for this I will be updating the camera on my phone. So I will be pushing the camera.apk. You will be able to use these steps for any thing.

Q: What is pushing a file?
A: Think of there being two parts of memory in your phone. 1 bing the SD card and the other being the internal memory. Moving things to the SD card as easy but moving files to the main system memory is not as easy. That is where pushing files comes in to play. It is using command prompt (CMD) to tell your computer to take a files from your computer and move it to your phones main memory.

Q: Why would I do it this way?
A: Well there are a few ways to get this done but this seems to be the best way to move just the files you want and nothing else. Say you have just one image you want to change and dont really want to mess with anything else. Well with this you are able to move over just that one image and not have to worry with making an update zip.

Q: Can I harm my phone?
A: Yes! Anytime you are messing with the main files there is a chance that things can go wrong and I would say do a back up of your phone files.

Now that I hope I have answered some questions lets get to what you need to do first.

First you will need to make sure that you have the most current version of the
Android SDK installed on to your PC. You can get that HERE and to make things easy install to the root of your hard drive.

Where To Install Android SDK On A Windows PC

Next you will need to make sure your device is rooted. Now this I really cant be much help with seeing that there are so many android devices out and I can not know what you have. But a good place to start is by going over to XDA and searching around.
Link To XDA
XDA is a forum with a lot of great devs that put a lot of time in to making our Android devices so great!

Now to what you will need.
1)Android device
2)Cable to plug the device in to your PC
3)File you wish to push

Step 1:
Plug your device in to Your PC using the cable.
Make sure you have any sync programs turned off and do not mount your sd card.

Step 2:
Open command Prompt on your PC.
For Vista and Windows 7 just open the start menu and type in CMD in the search area and press enter.

You should get something that looks like this.
What CMD Command Promt Looks Like

Step 3:
Type in to the Command Prompt

cd C:\android-sdk-windows\tools

Step 4:
Type in to the Command Prompt

adb remount

Now In step 3 and 4 you are just telling Command Prompt to change directory (cd = change directory) and start running an sdk tool.

Step 5:
Type in to the Command Prompt

adb push C:\Users\Chaos67731\Desktop\Camera.apk /system/app/

Now how this works, It is telling the SDK tool to take the file that is on your PC (C:\Users\Chaos67731\Desktop\Camera.apk) and move it to your phone (/system/app/)

You should end up with something like this.
You should end up with something like this

Step 6:
Unplug your phone and reboot it.
Well you will not need to reboot all the time it is just good practice to do so. Just to make sure it reloads all the files that have changed.

Here is all the Code that will be typed in.

adb remount
adb shell
adb push [Path To File You Want To Push] [Path To Where You Want To Push The File]

You can also pull a file by changing

adb push [Path To File You Want To Push] [Path To Where You Want To Push The File]

To


adb pull

Now if you just want to see something cool type in

cd C:\android-sdk-windows\tools
adb remount
adb shell
logcat

This will run what is called “logcat” and this is just showing you what is going on with your phone. So turn it on and watch things go as you start programs.

If you have any questions feel free to ask and hope this helps out!

Return top