Posts Tagged ‘php’

James Riter Does Who Pees In The Shower

Well, I have started a new site that I am doing for fun.

Who Pees In The Shower

http://whopeesintheshower.com

 

First thing you have to know is this just just for fun. :)   I was standing around at home one day and started to think how many people really pee in the shower. . . (Lets not talk about what I was doing . . lol)  So that was the start of it, right of the bat I knew I would want a little help dealing with the data base so I talked to a friend that I work with to see if he would be willing to put in a little time and come up with the proper form and database for the site to use.

At first he really did not seem in to the idea but after he got home and was. . . (guess away) he changed his mind. .

 

So that was the start of whopeesintheshower.com :)

I had Robert take care of the form and database for the form well I did the design / coding, both us us have added in our own custom PHP with his dealing with the form and mine dealing with the twitter feed and customizing wordpress.

 

The point of the site is just to smile and see the numbers and facts. :)

 

There has been one thing I have learned from this site and that is.

It is easy to come up with an idea and fun to make that idea come to life but marketing that idea is not as easy as it would sound.

Well I do think a lot of people would enjoy coming to the site and voting and adding in little bits of information or there own stories when they can. I have not had any real luck getting people to spread the word. :(

But that is good and bad, I now having a testing ground and a way to see what gets your name out there and what does not.

 

All in all it was a fun site to code and is some thing I do plan adding to as often as I get a chance.

 

Until then, go to  http://whopeesintheshower.com to vote and comment!!

 

James Riter

 

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.

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!

Return top