Category Archives: Content Management

Using Laravel: How To Use Routes, Controllers and Filters For Public and Private sections of a CMS site

If you are reading this you probably already know what Laravel is, but just in case: it’s a PHP framework for building applications. It has all the typical stuff such as MVC, DAO, ORM, a templating engine (also supports Twig from Symfony), routes, controllers, clean URLs, RESTful support etc. I really like it because it’s very clean and compact to code in. It’s also much simpler to get started with than something like Zend Frameworks 2, for example, as it doesn’t require a complex install process or configuration. In fact it pretty much just runs out of the box.

Other Tutorials on Laravel

There are a few (very few) tutorials on Laravel. If you prefer learning by watching videos I can highly recommend this series by Andrew Perkins. One text-based tutorial I’ve been working through is Dayle Rees’s. One weakness of his articles is that he starts out showing you how bits hang together, but by the time you get to filters he loses the plot and stops giving you a step-by-step working example- he teaches you concepts but doesn’t show them all working together. This is the case with his discussion about securing an admin section of your site, for example. Another tutorial, written by Nikko Bautista, covers some of the same ideas. That one also leaves some gaps. So here’s my attempt to provide a full working example, along with an explanation of how all the bits and pieces relate to one another.
Continue reading

Joomla 1.5 has wrong path for css, js files – edit your configuration.php file

I just moved a Joomla 1.5 install from my iMac to a hosted site. The home page showed up fine, but subsequent pages were missing all styles. It turns out that I needed to change the variable $live_site in configuration.php from ” to = ‘http://www.example.com/mypath’. I’m not clear on why it worked on my MAMP install but not on the ISP, but apparently this is a common Joomla 1.5 install problem, as noted at this Joomla forum thread. (Scroll down to see Anthony Ferrara’s (aka ircmaxell) response on Feb 21, 2008 – ignore all the other bogus parts of the thread). Anthony is apparently a member of the core development team, on the bug squad. Thanks, Anthony!

Using Aptana Studio 2.0 and PDT Plugin for Drupal Module Development

Aptana now uses the official Eclipse PDT (PHP Development Tools) plugin instead of their own PHP editor. I have Aptana 2.0.2, build date November 10 2009 on my Macbook.  I’m building a Drupal module, so I need to have PDT recognize (and correctly color-code) files with .module, .info and .install extensions.  There is a Drupal Article on configuring PDT as an Eclipse Plugin, but the steps are different for doing it in Aptana Studio.

The process is quite simple – basically 3 steps. Here they are (assuming you’ve got the PDT plugin installed already):

In Aptana Studio, click on the Aptana Studio/Preferences, expand the General link and click on Content Types: Aptana Preferences General tab

Next, expand the Text link. This will show you a list of content types supported in the editor. Scroll down until you see the PHP entry:

Aptana Content Types Associated with Editor

You’ll see the usual PHP extensions listed in the bottom box, such as php, php3, php5. Click on the Add button to the right to add an extension needed for Drupal Module development. You’ll see a dialog like this:

Aptana Define New Content Type Association

Click OK. Repeat this step for *.info and *.install (assuming these extensions are not already used for some other language or tool). That’s it! Now, when you open a .module file, it will have the same color-coding and editing as a .php file.

How To Create News Items in Drupal – Part 2

This is a continuation of the previous post that explained how to create a custom content type called News, and show News items using the Views module.

Creating A News Page with a Monthly News Archive Block

This post explains how to create a page showing just the News content type, how to link that page to the Primary menu, and how to show a block with a list of archived News items. It assumes you’ve already followed the steps in the previous post.

We accomplish all these tasks using the Views contributed module.

  • First, we use the Views module to create a page view to show most recent 10 news items on the page, as follows:
    • Login as site admin again
    • Go to Administer/Site building/Views.
    • Click Add to create a new View
    • View name: News_page , View description: Page showing recent news, View tag: News, View type: Node. Click Next.
    • Select ‘page’ in dropdown box, click ‘Add Display’. This is what creates a whole page, instead of a block, for example.
    • We want the user to be able to page back and forth through each set of 10 news items, so in the first column, click on ‘no’ next to ‘Use pager’ . Scroll down to the radio buttons for this option and click on ‘full pager’.
    • Next, we’ll repeat a lot of the steps we took for creating a block view – selecting the fields for the view, and the filter to choose only published News content:
      • Click on the ‘+’ sign next to Fields. Scroll down and select Node: Post date and Node: Title, then click the Add button . The next steps take you through more options for each of these fields.
      • Remove the label of ‘Post date’ (clear the text). This prevents the words ‘Post date’ showing next to the date. Click ‘Update default display’. You should now see an interface asking you to configure the field ‘Node:Title’.
      • Remove the label of ‘Title’ (clear the text). Check the box ‘Output this field as a link’ , scroll down and check ‘Link this field to its node’. This makes the News item’s Title a clickable link that links to the full article (node). Click ‘Update Default display’.
    • You should see a ‘Live preview of all content you’ve created. Let’s filter it by ‘news’ only.
      • Cick the ‘+’ sign next to Filters. Scroll down and check Node: Published and Node: Type. These options let us choose to display only Published content (Node: Published = Y), and only news (Node: Type = ‘news’). Then click Add.
      • Select ‘Yes’ for Published items, click Update, then select ‘Is one of’ and check ‘News’, then click Update.
      • Now let’s sort the news items by most recent first (descending order). Click on the ‘+’ sign next to Sort criteria.
      • Check Node: Post date, click Add.
      • Select Descending, click Update.
    • Let’s place this page on the Primary Menu.  This is the menu that (generally) appears at the top of your page, depending on your active Drupal theme.
      • Scroll down until you see the heading Page Settings in the first column.
      • Click on None (next to Path), and type: news . This is appended to the rest of your site’s url to make the full path for this page.  We will also refer to this name when we create our News Archive block.
      • The next option lets you link the page to a menu item:
      • Click on ‘No Menu’ (next to Menu)
      • Scroll down and click on Normal menu entry. A set of input controls appears to the right of this option. Proceed…
      • Type the title for this menu entry. I chose ‘News’ because I like short menu item text, but feel free to choose whatever you want- perhaps, Latest News.
      • Type a description. This appears when a user hovers over the menu item. It might appear somewhere else, too, I’m not sure.
      • Click on the dropdown box under the word ‘Menu:’
      • Select Primary Menu.  That’s it!
    • Finally, click the Save button (just above the words ‘Live Preview’.)

Create The News Archive Block

Ok – the next step is to create a block of Archived news articles – much like the standard Archive block that comes with Drupal. The only difference is that block includes all content types, while we want to include just our news content type. So this is really easy- we clone the existing Archive view that comes with the Views module and just add a filter to include only news content. Here are the steps in detail:

  • Go to Administer/Site building/views again.
  • Look for the existing view called Monthly Archive (it has a path of archive) – it’s the first one in the list in my install of Drupal. Click on the Clone link on the right.
  • Change the view name from archive to newsarchive, and change the view description similarly.
  • Click the next button to continue on to configure the block view.
  • Add the filter for news content only:
    • Click on the + sign next to Filters. Scroll down to see the list of available filter fields, find the Node: type field, and select it.
    • Scroll down to configure the Node type and select the news content type.
  • You can click the Live Preview button now, and you should see something like November 2009 (9) – at least that’s what I see, because that’s the only month I have any news items published in. If you haven’t written any news content yet, then nothing will show here.
  • Before we exit this page, there is, as Columbo would say, just one more thing.  You may have noticed that the Archive list we cloned has 3 vertical tabs on the left – Default, Page and Block.  In the previous steps we were changing the default settings, which essentially ripples them through to both the Page and Block settings. Personally, I intensely dislike this interface. It is quite confusing, because different options appear depending on which tab is active, and it’s not self-evident which tab is active. Anyway, we are going to make a minor change to the block view, so click on the block tab .
  • Scroll down until you see Block settings. If you do not see this heading then you did not click on the block tab in the previous step, so try again!
  • Click on the text next to Admin, and type ‘News Archive List’ . This is text appears when we are placing blocks on our pages, and if we don’t change it we will have two blocks with the same title – the one we cloned from, and this one – which makes it a pain to know which one we want to place somewhere.
  • Save your work – click the Update button, followed by the Save button below it.

Place the News Archive Block on The News Page

You may want to place your News Archive block on every page, but just for the sake of this tutorial, let’s place it only on the news page.

  • Go to Administer/Site Building/Blocks
  • Find your News Archive List block. It should be in the list with the heading Disabled, the last list on the page. Click on the Dropdown box next to it, and select the area on the page you want it to appear. The names of the areas will depend on the active theme you are using. There may be one called ‘right sidebar,’ which would be appropriate. If not, choose some other area.
  • Scroll to the bottom of the page and click Save Blocks  (IMPORTANT!!! – click Save Blocks before doing the next step – otherwise you may lose your ‘change’).
  • Ok – now you have to find your block in the lists on the page, because it has moved from the ‘disabled’ list to whatever area title you chose. Once you find it, click on the Configure link.
  • Scroll down to Show Block on Specific Pages, click the  ‘Show on only the listed pages’ radio button, then type news in the text area below. (news- not News, not ‘news’, not <news>).  If you recall, this is the node name of our news page, which we specified when we created the News page view (above).
  • Save your work.

Ok – we are done.If you  go to my Drupal sandbox site, you’ll see the News menu item at the top. Click on it and you’ll see some bogus news items, along with the News Archive List in a block on the right hand side. Notice that this block only appears on the news page, as per our specs.

Whew- this is a lot of text to explain something reasonably simple. Maybe next time I’ll make a youtube video instead.

How To Create News Items and a News List in Drupal

Drupal does not come with an out-of-the-box news content type. You could use a story or a blog entry, but these are not an exact fit for what I wanted.  Fortunately, it’s pretty easy to create your own ‘News’ content type. You probably have your own idea of what a ‘news item’ should be, and how it should display. Here are the features I wanted for news items:

Requirements

  • News items to be their own ‘content type’ so I can create user roles just for posting news items.
  • Latest 5 news items to show in a block on the first page.
  • Separate ‘news’ page that lists all news items, most recent first, with paging (eg. show 10 at a time).
  • ‘news’ page should be a Primary menu item
  • List to show date of item and title of item, with the title being a link to the full article
  • News items to support ‘teasers’
  • Have an Archive block on the News page to show an archive of news items by month

Summary of Process

Here’s an overview of  how you do it, followed by detailed instructions.

  • Install Views contributed module (if you haven’t already done so).
  • Install Advanced Help module (this provides a great example of using Views to create a block or page that presents lists of information)
  • Create a content type of ‘news’
  • Check the options to add, change or delete own news items for the appropriate users or roles.
  • Create a ‘block’ view to display news items
  • Place the block somewhere on the first page
  • Create a ‘page’ view to display news items.  You choose which Primary menu item you want to use for this page when you create the view.
  • Create an ‘archive’ block view to display archives by cloning the provided Archive view and changing it
  • Place the archive block somewhere on your news page.

Details For Creating The News Block

In this section of the post I take you through every step in detail.

(In order to get this post published, without being too long, I’ll explain in another post how to create a separate page of news items with teasers, and how to create the Archive block.)

  • Install Views and Advanced Help modules. Views is one of two very popular contributed (non-core) modules. CCK (Custom Content Kit) is the other one- it lets you create your own data values or content types. Views lets you display lists of information from the Drupal database. It’s essentially a user-driven SQL statement generator, along with some list formatting options. Advanced Help is useful because it gives you detailed examples on using Views. One of those uses content type of ‘Story’, which is really not much different than the ‘news’ content type we are using here. Here are the URLs for each of these modules:

I use Views 2 for Drupal 6.x in this example.

  • Create Content type of ‘news’.
    • Login as Site admin
    • Go to Administer/Content Management/Content Types, click Add.
    • Name: News, Type: news (I use all lower-case for the type), Description: News items.
    • Workflow settings: Check ‘Published’ and ‘Promoted to front page’. I also enabled Attachments, but you may not want to do that. Make your choice for comments, too. You probably don’t want people commenting on your news items – “hey – that was really boring!” – in which case, disable comments.
    • Save the content type.
  • Set up a User who can create, change or delete News items. First we’ll create a new role, specifically for just working with news items:
    • Go to Administer/User Management/Roles
    • Click on Add Role. Call it Reporter (you can always delete this later if you really don’t want it)
    • Click on Edit Permissions
    • Scroll down the list of permissions until you get to ‘Node Module’. Check ‘Create news content’, ‘edit own news content’ and ‘delete own news content’ then click ‘Save permissions.
    • Create a user with a role of reporter: Go to Administer/Users and click on ‘Add User’. Type a Username, unique e-mail address (if you are like me, you have many alias email addresses pointing to the same account- almost a must for testing anything with Drupal or Joomla), password, and check the role of ‘reporter’.
  • Add some News!
    • Logout of Drupal
    • Login with the User just created (role of reporter)
    • Click on the ‘Create content’ link and create some news items.
  • Create a block view to show most recent 5 news items in a block.
    • Login as site admin again
    • Go to Administer/Site building/Views.
    • Click Add to create a new View
    • View name: News_list , View description: block listing recent news, View tag: News, View type: Node. Click Next.
    • Select ‘block’ in dropdown box, click ‘Add Display’.
    • Click on ’10’ next to ‘Items to display’ and change it to 5.
    • Click on the ‘+’ sign next to Fields. Scroll down and select Node: Post date and Node: Title, then click the Add button . The next steps take you through more options for each of these fields.
    • Remove the label of ‘Post date’ (clear the text). This prevents the words ‘Post date’ showing next to the date. Click ‘Update default display’. You should now see an interface asking you to configure the field ‘Node:Title’.
    • Remove the label of ‘Title’ (clear the text). Check the box ‘Output this field as a link’ , scroll down and check ‘Link this field to its node’. This makes the News item’s Title a clickable link that links to the full article (node). Click ‘Update Default display’.
    • You should see a ‘Live preview of all content you’ve created. Let’s filter it by ‘news’ only.
    • Cick the ‘+’ sign next to Filters. Scroll down and check Node: Published and Node: Type. These options let us choose to display only Published content (Node: Published = Y), and only news (Node: Type = ‘news’). Then click Add.
    • Select ‘Yes’ for Published items, click Update, then select ‘Is one of’ and check ‘News’, then click Update.
    • Now let’s sort the news items by most recent first (descending order). Click on the ‘+’ sign next to Sort criteria.
    • Check Node: Post date, click Add.
    • Select Descending, click Update.
    • Finally, click the Save button (just above the words ‘Live Preview’.)
  • Add Block To First Page
    • Depending on your active theme, you may want to add your news block to the left or right side of the page. I’m (currently) using Acquia Marina, which supports a right-hand column, so that’s where I’ll place my block:
    • Go to Administer/Site Building/Blocks
    • Scroll down to the list of inactive blocks and find the one named ‘News_list’. This is what we created when we built our view in the previous steps. Click on the dropdown box and select ‘Sidebar last’ (or maybe ‘Sidebar right’ or ‘Sidebar left’ – depending on your active theme).
    • Click the ‘Save blocks’ button at the bottom of the page.
    • The list of blocks will be refreshed. The news_list block now appears under the ‘sidebar last’ heading. Click on the ‘configure’ link.
    • Type a ‘block title’ of Latest News
    • Scroll down to ‘Page specific visibility settings’ and click on ‘Show on only the listed pages’ and type <front> in the text box. This ensures that our block of listed news items only appears on the front page, on the right side of the page.
    If you want to see a sample of how this implementation appears, go to my Drupal sandbox installation.
    The next post will explain how to create a page of News items, with a primary menu link, and an Archive block showing news items by month.

Cookbook – How to Move a blog from WordPress.com to a privately hosted site

I just moved my WordPress blog from WordPress.com to a privately hosted site. I use Islandnet, an ISP on Vancouver Island, BC, where I live.
( PLUG: I’ve used them for Internet services since 1994, and they are highly reliable and technically very competent. They are also very responsive.)

You might find other blog posts on this subject, so I’ve written this as a point-form cookbook. Also, it specifically applies to moving to Islandnet’s servers, so some details may be different, depending on your ISP. However, I suspect most of the issues will be the same. It’s actually a pretty simple process:

  1. Login in to your wordpress.com blog, go to Admin pages, and Export your blog. Take the option to include all images, etc. Save the export on your PC.
  2. Decide on a directory on your ISP that you want to install WordPress in. I chose to copy it to the root directory (/www/ ). I also run a test version of drupal, and that’s in a subdirectory. Give the directory read/write permissions for all users – WordPress needs this to install properly. On Islandnet, you go to the File manager web page and change the permissions for the directory.
  3. Log in to the SQL manager web page on your ISP (at Islandnet this is under host manager, databases) and create a MySQL database named wpdb (or whatever).
  4. Follow steps 1 through 5 of the Famous 5 Minute Install. Notes on this process:
    • Download from wordpress.org – I got version 2.8.1, as of this writing.
    • I mentioned the SQL database creation step above – it’s also mentioned in the Famous 5 Minute Install docs.
  5. Login to the new WordPress site. Because I have it in the root directory, I just go to www.fbloggs.com to get to my site.
    Go to Admin, and Import the exported blog. This will bring in all your old content, including images, etc. Works like magic. Note that it retains the original post dates, also.
  6. Go to the dropdown box for Settings, and select Permalinks. Change it to pretty links – I include the article date and name as the link. This is the third radio button down, called ‘Month and name’. You might also want to read the WordPress official guidelines on Permalinks, to make sure you don’t create performance issues based on the setting you choose.
  7. I got a message saying it couldn’t update my .htaccess file. At this point, I created one in Notepad, copied in the statements generated by WordPress, and FTp’d it to the /www/ directory. This is required in order to make pretty permalinks work.
  8. Go to your old wordpress.com blog and update those posts with a link to each equivalent post in your new blog, using the format for permalinks you selected in the previous step. Obviously, if you have tons of content, this is a real drag. There’s not really a better alternative, though.

So far, I’ve chosen to leave all the existing content in posts I want to keep on my old site, but I may decide to delete it all except the links in the future.

From here, I’m going to experiment with different themes, widgets, plugins, etc. The one I missed immediately was the stats one that shows up in the Admin page in wordpress.com. You can install this from here. Hopefully traffic will start moving over to my new site.

Moved my blog from wordpress.com to hosted site.

I moved my blog today. Now I’m looking for a new theme, because ‘Silver is the new black’ is only available at WordPress.com, and I can’t find it anywhere. Also, I’ve deleted all non-popular posts from my old blog site (fbloggs.wordpress.com).  There does not seem to be an easy way to redirect visitors on a WordPress.com-hosted blog to a new host, so I’ve added links to this site for all the important articles.

How to make content private in Drupal

I’ve been playing around with a test Drupal install lately. I’ve installed Drupal version 6. One of the most challenging things about working with Drupal is knowing which plugins to use; there are so many of them. For example, in the User Access and Authentication category, there are 249 modules! It took me several tries before I found the module I needed, mostly because the purpose of each module I looked at is not particularly clear. Anyway, I wanted to have some content visible to anyone, and some only visible (and accessible) to authenticated users (me!). I created a story (recommended for newbies on the Drupal site, in the Drupal cookbook), which I wanted to be seen only by me. I also created a public story that anyone can read. Here’s how I protected my private content:

  1. Select a plug and download it. I chose the ‘content-access’ plugin. I found this via a circuitous route. First, I googled phrases like ‘secure content in Drupal’ and ‘Drupal protect nodes’ with little success. Then I went to Safari Books Online (I have a full library subscription, through work), and looked at the chapter on Modules in the Packt book appositely titled Drupal. This chapter discusses the ‘node_privacy_byrole’ module. I searched for it on Drupal.org, and read its intro, which explained that it is similar in function to the ‘Content Access’ module. So I then read about the ‘Content Access’ module, which has been kicking around for ages (since 2005), and decided to give it a whirl.
  2. I downloaded the module to my laptop. It’s a tar.gz file, so I unzipped it with 7zip.
  3. I copied the whole unpacked folder (called ‘access-control’) via FTP to my server. You always copy modules into the Drupal subfolder called ‘modules’, so that’s what I did.
  4. I logged in as Site Admin to my Drupal site.
  5. I clicked on Administer > Site Building > Modules. This presents a list of available modules, most of which are core modules, many of which are ‘active,’ but some not. My newly added module appeared at the top of the list, under the heading ‘Access Control’
  6. I checked the box next to Content Access. This makes the module active (usable).
  7. I then had to click a button to rebuild site permissions. You get a warning saying this might take a long time. In my case it took about 15 seconds – I don’t have much content yet.
  8. I clicked on Administer > Content > Content Types.
  9. I clicked on ‘Edit’ next to ‘Story’. This option means I am about to edit the settings for any content type of ‘story’. I currently have two stories, so the options I selected here will affect both of them (and any other ones I create later).
  10. A new tab (ie one not seen in the core install) appeared, called ‘Access Control’. I clicked on it.
  11. I clicked the ‘View any content’ options for both anonymous users and authenticated users. This may seem counter-intuitive, since I want to deny anonymous users the ability to view some stories, but basically this sets the default to ‘Allow all’ and allows you to granularly deny access. Read on…
  12. There’s a heading on this page: ‘Per content access control settings’. I checked the box next to the text ‘Enable per content node access control settings’ – meaning I can control, at a node level, the access settings for any story. Since all content in Drupal (AFAIK) is a ‘node’ (or collection of ‘nodes’), this seemed to make sense.
  13. I saved the settings.
  14. I clicked on Administer > Content Management > Content. This showed me a list of content on my site – a couple of stories, some Book pages, a Page and a blog.
  15. I clicked on ‘Edit’ next to the story I wanted to make private (accessible to only authenticated users – me). This is the only option available at this point, and it placed my story in edit mode. However, a new link now appears above the story: Access Control.
  16. I ignored the fact that Drupal seems to think I want to edit content rather than permissions, and clicked the aforementioned ‘Access Control’ link. Jolly good. Almost done.
  17. I unchecked the boxes for Anonymous User under the column headings ‘View any content’ and ‘View own content’ (the second uncheck is probably not necessary, since Anonymous will never be able to add any of his/her own content to this story anyway – but what the heck.
  18. That’s it. I tested the results by logging out. Sure enough, I could no longer see the story on my front page (I have a ‘story’ block visible on my front page for both anonymous and authenticated users). I could still see the public story, though, just as I wanted. I also tried cutting and pasting the URL for the story node into the location bar of the browser- still couldn’t get there! Perfect!

    An interesting side note- I’d also earleir installed a module called Secure Site, hoping that it would do the trick. It mentions something about ‘secured pages’ in the documentation, but I couldn’t for the life of me find a definition for ‘secured page’ anywhere on the Drupal.org site. However, after applying the access restrictions as described above, the Secure Site module dutifully kicked in when I tried going directly to the private story via its URL. So that’s what a ‘protected page’ is- one that’s handled by an ‘Access Control’ module.