All you need to do is download the plugin and place it into your webroot/js directory and then modify a few lines in app/views/nodes/admin_add.ctp. The changes I made are below.
Include the jQuery slug plugin at the top of the page.
Set up the plugin and let it know the title field's ID and the class of the slug field.
echo $form->input('title', array('id' => 'title'));
echo $form->input('slug', array('class' => 'permalink'));
Add an ID to the title field and a classname to the slug field. That's about it, hope this saves you some time when you are writing your next article.
I am working on a social network application where I want to allow users to import their information from another social network or service that provides an open authentication. I looked at Facebook connect and Twitter sign on but after doing research the easiest solution for me was using RPX's hosted solution. It took me about 10 minutes to implement and maybe another hour to fine tune to my needs.
To start you will need to register with RPX and then set up your widget. Some of the providers (such as Facebook and Twitter) need you to set up the application on their network first and then they will provide you with an API key that you can then plug into RPX.
After setting up the widget they will provide you with some code to copy and paste, there really isn't any modifications needed to the code except setting the token_url which is used as a redirect url once the user has been authenticated. You will probably want to set the token_url to a registration page where the user can enter a username and password for CakePHP's authentication component.
Once you have everything in place you will need to set up some code for the action that corresponds with the token_url. First you will need to receive the token from RPX used to retrieve the user's data, then you will need to request the user's info using their API. Here is the code that I am using in my action.
$http = new HttpSocket();
$token = $this->params['form']['token'];
$results = $http->post(
'token' => $token,
'apiKey' => 'YOUR-API-KEY-HERE'
$user = json_decode($results);
I am using CakePHP's built in HttpSocket class to request the user's information. The information sent from RPX is in JSON format so I used PHP 5's built in json_decode method to create an object out of the json. Now you would most likely create a new user record and save the information received from RPX and in the view display a form to collect the rest of the user's credentials such as username and password.
That's it, it's very simple to use. If you have any questions leave a comment and I will get back to you as soon as possible.
In this post I will describe how I created the featured post on the home page of my blog with Croogo. Looking at the database schema I noticed that there was a column named "sticky" that was not being utilized anywhere in the code so I thought that it would be a good place to store whether a post was featured or not. The first thing I did was edit the admin add and edit views to allow me to mark posts as featured under the publishing tab.
echo $form->input('sticky', array('label' => __('Featured', true)));
echo $form->input('status', array('label' => __('Published', true)));
echo $form->input('promote', array('label' => __('Promoted to front page', true)));
All I did here was add one line that will display a checkbox similar to the published and promoted checkboxes. The next thing I had to do was retrieve the latest featured post from the database. I did this in the nodes controller under the promoted action since this is the default home page for Croogo.
$featured = $this->Node->find('first', array(
'order' => 'Node.created DESC',
'conditions' => array('Node.sticky' => true)
This just finds the first post marked as featured, ordered by the created date. I then set a variable for the view so that I can access this featured post in my view. The next step was displaying the featured post. For this I created a "featured" element and rendered it in the layout template if the current action was "promoted".
<? if ($this->action == 'promoted') : ?>
<? endif ?>
Inside of featured.ctp in the elements directory.
<p><?=$html->link($featured['Node']['title'], $featured['Node']['url'], array('class' => 'link'))?><p>
<p><?=$text->trim(strip_tags($featured['Node']['body']), 200, '...', false, true)?></p>
<p><?=$html->link('Read More...', $featured['Node']['url'])?></p>
This is a dumbed down version of what I am using but should still get you started. If you know your way around CakePHP you should be able to understand what is happening. I am using the text helper to show an excerpt from the post body then display a read more link below that will direct the user to the post.
This should be enough to get you started. In my next post I will explain how to use custom fields in your posts. I am using them to display the image beside my featured posts on the home page. If you have any questions leave a comment and I should get back to you shortly.