Friday 26 November 2010

portableCMS

My updates have not been as frequent or as detailed lately because I've been writing a CMS which I have so far name portableCMS. So far I have been able to:

  • Create a set of configuration files
  • Create a method of providing CSS to the correct devices
  • Hold editable content data without the need for a database
  • Minimise the requirement for developers to code beyond the HTML body if required
  • Provide a method of creating plugins
  • Provide the opportunity to enhance the CMS with external Functional PHP, OOP PHP, jQuery and JavaScript sources

At the moment I am working on delivering real-time data.

Thursday 25 November 2010

Friday 19 November 2010

PHP API call to Summarity

Summarity at http://www.summarity.com/ is software which summarises items of text. They helpfully provide an API for developers to use. There is an example of how to call the API using python on the website. I don't use python. I use PHP. So I went about writing the API call in PHP. So below is an example of how it's done. You will need to get your own API key. I hope it's obvious where to add your text string.

<?php

 $url = 'http://summarity.com/apiV1';
 $data = 'summarity_api_key=yourAPIkey';
 $data .= '&text='.urlencode('Just some text for testing');
                 
 $ch = curl_init($url);
 curl_setopt($ch, CURLOPT_POST, 1);
 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);                
 $response = curl_exec($ch);                
 curl_close($ch);
 echo(json_decode($response));
?>

Thursday 18 November 2010

PHP to get current file name without the extension

This little function will return the file name which calls it minus the .php extension.

<?php

function getCurrentFile()
{
    $currentFile = $_SERVER["SCRIPT_NAME"];
    $parts = Explode('/', $currentFile);
    $currentFile = substr($parts[count($parts) - 1],0,-4);
    return $currentFile;
}
?>

jQuery line to reflect h1 in page title

Quite often you want the title tag of your page to be the same as your title. This little jQuery line will do that for you.

$('title').text($('h1:first').text());

How to get all the content from a directory using PHP

I've been developing a small CMS. It solves a small problem. Some of our customers would like to edit small amounts of text on a page. I don't want to create a CMS database for this. I just want to use text files. There is a tiny CMS which does this, but your website has to be in root, there is an install and it's a bit of a pig to configure.
My CMS is much simpler than that.
Anyway, to cut a long story short I created a PHP function for it which I wanted to share. It takes a directory name as a parameter then looks at that directory  and reads all the files within it. Obviously missing out those ugly  . and .. at the beginning. Manipulate at will.


<?php
function getDirContents($dirLoc)
{  
    foreach(array_slice(scandir($dirLoc),2) as $fileEntry)
    {
        echo file_get_contents($dirLoc.'/'.$fileEntry);
    }
}
?>