Git: Living on the Edge isn’t for the Dumb

As you may know I’ve been using git as my primary ftp, version control and way to put my projects online for public access and viewing. However, there is a very important thing when considering using these great technology: .gitignore.

Now, when using oAuth, you need a client identity and a client secret. For me, I don’t want to hard code them because that will make them publicly accessible so I stored them in a json file. I thought I followed ignoring the json by adding

^(.*)/secret.(.*)$

to the .git/info/exclude file, however I did not do it right
as ^(.*)/secret.(.*)$ is different than ^(.*)secret\.(.*)$ and quite possibly is completely incorrect

Now first i uploaded it to github, only to find that the file was still there. This through to a flurry as for the last three commits I had assumed everything was peachy clean (I am still learning everything so I don’t hate myself for it. Luckily I was able to find this tutorial on github.

Not only was I able to remove my secret from the commit, but also able to add to the .gitignore in a simple manner. My fears relaxed and a feeling for relief ensued.

Just to add to the security, I also made a proper .htaccess to hide the file

RewriteEngine On
RewriteRule ^(.*)secret\.(.*)$ /404 [L]

 

Clockin WordPress Integration: Million ways to get it, choose one. pt1

So at this point we can….
1) Retrieve a Github info
2) Retrieve google calender info

But one thing we have yet to do is provide a place where we can actually clock in and clock out. Now we can do this in a variety of ways….

  • Custom Post Types to define Projects and Users
    -they would literally just be place holders to avoid storing tons of duplicant data
    -Would be based off any user that enters our website and allows our app to access their github profile

    • Pros
      -We don’t need javascript to display data
      -Pretty URLs will be enforced
      -Good for SEO
      -Can Be Placed in a Plugin
    • Cons
      -Whats the point of creating a reference?
  • Query Based Multiple Page Service
    -We would create a page that is based off a template we created
    -In the template we would get the queries and give the appropiate data back

    • Pros
      -clean and neat
      -Can make it SEO Freindly
    • Cons
      -Would have to define an archive and various link tags to make it SEO freindly
      -Ugly Urls
  • Single Page Service
    -Using Ajax, we would do everything right from the one page

    • Pros
      -Clean and Neat
      -Pretty Url… Well theres only one….
      -Can be stored in a plugin
      -Nothing is stored
    • Cons
      -Requires Javascript
      -Will need to deal with the data in the browser
      -No SEO

So here’s our choices, I’ll assume you assumed which I’m going with… And if you didn’t assume, I’ll give you a hint “Type Post Custom”. WordPress is wonderful in that it gives you pretty URLS, it gives you proper SEO in a variety of ways, makes your URLs beautful and on top of that you can avoid alot of the struggles you would enter into with your own Content Management System,  such as creating a proper PHP class to interact with sql.

We really want to make sure this is a plugin also to allow ourselves some breathing room in terms of installation.

So Lets begin by creating our plugin

Now Things we will have to include are….

  1.  Creating a Custom Post Type for Users and associating it to a User
  2. Creating a Custom Post Type for Projects
  3.  Giving people the opportunity to choose their Calender
  4.  Auto Load on new sites to old calanders

So lets prepare in the Init, we’re going to leave out the auto load for now

add_action( 'init', 'initialize_clockin' );
function initialize_clockin() {
 register_post_type( 'clockin_dev',
  array(
   'labels' => array(
    'name' => __( 'Developers' ),
    'singular_name' => __( 'Developer' )
   ),
   'description' => 'The user object associated with the wordpress user. stores the guthub username as well',
   'public' => true,
   'has_archive' => true,
   'show_ui' => false,
   'show_in_menu' => false,
   'supports' => false
  )
 );
 register_post_type( 'clockin_project',
  array(
   'labels' => array(
   'name' => __( 'Github Projects' ),
   'singular_name' => __( 'Github Project' )
),
   'description' => 'Associated to Github Project',
   'public' => true,
   'has_archive' => true,
   'show_in_menu' => false,
   'supports' => false
  )
 );
 add_option("Calander ID", null);
}

Now lets create our admin page

This is the code I came up with. I preferred the object oriented approach so that I can store it in a different file

<?php
class clock_in_admin {
 public $options;
public function __construct(){
 add_action( 'admin_menu', array( $this, 'add_to_menu' ) );
 add_action( 'admin_init', array( $this, 'page_init' ) );
 }
 public function add_to_menu(){
 add_options_page( "Clock In Settings", "Clockin", "manage_options", "clock-in-admin", array($this, "admin_page"));
 }
 public function admin_page(){
 $this->options = get_option( 'clock-in' );
?>
 <div class="wrap">
 <?php screen_icon(); ?>
 <h2>Clock In Settings</h2>
 <form method="post" action="options.php"> 
 <?php 
settings_fields( 'clock_in_fields' );
 do_settings_sections( 'clock-in-admin' );
 ?>
<?php submit_button(); ?>
 </form>
 </div>
<?php
 }
 public function page_init(){
 register_setting('clock_in_fields', 'clock-in', array( $this, 'sanitize' ) );
 add_settings_section('clock-in-cal', 'Google Calender Setting', array( $this, 'print_section_info' ),'clock-in-admin');
 add_settings_field('calender-id','Calander ID',array( $this, 'calander_id_input' ),'clock-in-admin','clock-in-cal');
 }
 public function print_section_info()
 {
 echo 'Enter your settings below:';
 }
 public function sanitize( $input ){
 if( isset( $input['calender-id'] ) ){
 //need to check if the calender exists and we can't view and edit it
 //if we can't edit it, we need to ask for permission
 $this->options['calender-id'] = $input['calender-id'];
 }
return $this->options;
 }
 public function calander_id_input()
 { ?>
 <input id='calender-id' name='clock-in[calender-id]' size='40' type='text' value='<?php echo $this->options['calender-id'] ?>' />
<?php
 }
}
?>

 

Version Control: Setting Up Git on Godaddy

So one of the things I’d prefer to do is to work on my website locally then push to github and my server. Easy to say like most concepts…

Now at times I just don’t want to figure things out, as such I chose to use someone elses work. This is a great Article on it. Now despite following the tutorial to a T I ran into issues, not because its a bad tutorial, because for anything, the amount of work and research that goes into something like this is very very very commendable. No work should ever be downplayed, though Its important to look at what is flawed.

I’m not going to rewrite the article but theres a few peices you will want to keep in mind
1) When editing your files from the shell, your most likely going to have to use vi the reason for this is you would have to install other file editors to use them
2) The Command

git remote set-url origin ssh://username@domain.com/~/repo/app_name.git

is actually

git remote add origin ssh://username@domain.com/~/repo/app_name.git

this may seem small, but you’ll be running into headaches if you don’t pay attention

3) if you’d like to include github to the mix, I’ll want to setup an ssh key for github https://help.github.com/articles/generating-ssh-keys

then in a similar fassion

git remote add github git@github.com:UserName/Repository.git

4) Get used to the following commands
-As I’m relatively new to git, I kinda learning the important aspects

Remember to change your directory to the working directory

cd /Path/to/your/local/repository
git add .
git commit -m "your message" .
git push github master
git push origin master

I might store this in a script that I’ll just run as needed

Transfering My Old Stuff

One of the things I’m going to have to do is be able to look at my old project in order to incorperate things I especially liked into WordPress. Among them are my Clock In system, Fractals. Now This isn’t just a two step process since most of my experimental work is on the server (which is bad mkay [your [production site should never be your experimental area {but for every rule there are exceptions}]) as a result I have to do a few things….

  1. Setup a local server
  2. Import all my files into the server
  3. Import my SQL database into the server
  4. Do little things to make sure everything is in proper working condition

Setting Up my Local Server

Setting up a local server can be done in a few ways. As I’m on windows, things become like cake. I’ve also done this on linux, and for what its worth, there is plenty of documentation out there to do it. For my purposes, I like to avoid ISS. The reason for this is I found it previously to have a bad user interface. What I’ve enjoyed in the past is Xampp.

xampp

 

Its a simple Install, It works, and Easily accessible. Theres not much else you can ask for from a service, or anything really.

Now, I don’t want to turn this into a tutorial but more of a general description of my experience. Nonetheless, Due to the nature of this, Its going to be one and I’m aware of that.

Importing All My Files

Now, I already have Filezilla installed because its near the best ftp (file transfer protocol) experience I’ve had. but just for giggles I’ll show you another cute little trick

windows ftp

 

Whenever you have any folder open in windows, you can change the path to be “ftp://your-web-server” and you will have an easy to use method of accessing your webservers files. Now I am using filezilla currently, but I should be using a revision control system such as Mecurial, tortoise or even Github. I’ll definitely say I learned my lesson about version control over the last couple months.

If your going to be installing FileZilla like I’m using, remember to install the client version. The Server is quite literally for servers (I’ll go over that on another topic), its meant to be able to receive FTP calls, not make them. Servers are listeners not talkers.

After you’ve installed, got Xampp and FileZilla installed, We want to do a few things….

  1. Figure out what our hosts ip address is
  2. Create an FTP user so we can access our files
  3. Login

Our Ip address will be localhost.
There are other ways to figure it out like understanding what our ip address is to ourselves. but when it comes down to it, localhost is the clean and simple way.

Creating an FTP user
On the Xampp Panel, you want to click “admin” for the FileZilla Section

admin

From there we open up our admin menu and go to user accounts

fzadminThen we add our user

fzuseraccountsSimple as that

Back to our Filezilla client
filezilla

 

Up top, we want Localhost, Username, Password, Go!
You can also save, but I don’t need to worry about that right now.

From there I connected to my old server, dropped all my stuff in the htdocs folder of my local server, which is located directly under your xampp root.

Import my SQL database into the server

This is a pretty simple process. You’re going to want to go to your original sites SQL admin page. Go to export, save the text file. Then go to your local page go to import and choose the text file.

SQL Export

The File

import

Making Sure Things are working Properly

This changes from system to system. For me This is completely custom and as much as I’d love to show how the system works. More importantly I’d just like to get it overwith. see you tomarrow! 🙂