Posted on : Tuesday, 8 September, 2009
I promise that this will be my last post about Perch, I am starting to look somewhat obsessed.
This hack was born out of necessity as I found that the admin UI on large Perch sites looked daunting to new editors. Though the UI is beautiful and clean I was finding the lists would be endless and the editor could not find the page, let alone the region. This is something that Perch are looking at but I wanted a solution for the meantime. Unfortunately the solution is horribly hacky, involving altering the perch.js file.
Add the following to the bottom of the perch.js file (found in the your-perch-folder/assets/js/perch.js)
function pageTidy () {
if($('td.page').length > 1) {
resetToTidy();
$('.page span').css({ cursor: 'pointer' });
$('.page span').click(function() {
resetToTidy();
$(this).parent('td').parent('tr').addClass('currentPage');
$('.currentPage').children('td').show();
$('.currentPage').nextAll().each(function(index) {
if($(this).css('display') == 'table-row'){
return false;
}
$(this).show();
});
});
}
}
function resetToTidy() {
$('.d tbody tr').hide();
$('.shared').parent('tr').show();
$('.shared').parent('tr').nextAll().each(function(index) {
if($(this).children('td').hasClass('page')) {
return false;
}
$(this).show();
});
$('.d tr').removeClass('currentPage');
$('.page').parent('tr').show();
$('.page').siblings('td').hide();
}
Then add pageTidy(); to the init function. So it would now look like:
var init = function() {
$('body').addClass('js');
enhanceCSS();
initPopups();
hideMessages();
pageTidy();
};
Posted on : Tuesday, 4 August, 2009
Edit : Changes made as per Drew’s advice. Now deals with ’shared’ content and custom table prefix.
For sometime now I have been meaning to post this little hack I came up with — however I completely forgot. This is a hack for the brilliant ‘little’ CMS , Perch .
It was made through necessity as I wanted to use Perch but I needed to be able to have news items from other pages on the front page. To my surprise it was nice and easy, and although I’m sure it will be inefficient, it seems pretty fast.
It is an incredibly simple plugin that pulls the JSON out of the Perch database and returns it. It doesn’t try to do anything else — no formatting, no nothing — just the way I like it.
Standard disclaimer : I am not a server-side kinda guy, I can not take responsibility for anything this plugin does to your installation of Perch, server security or general happiness. That said, I can’t see how these lazy few lines of code could screw up much.
Download the file and put it in your Perch “plugins” folder. This isn’t mandatory for it to work but just seems like a logical place to put it. Watch out when you next need to update Perch — Back up!!
You must include the file at the top of the page you wish to use Archive Extractor. If your Perch directory is called “perch” then the include could be something like this:
include('perch/plugins/archiveExtractor/archiveExtractor.php');
To use just call the function with the 2 variables, the Perch Content name (e.g “News Item”) and the path to the page it is on (e.g “/news/index.php”). With the data returned you can iterate through the items and pull from it the data you want.
Maybe best seen as an example:
// Call function with variables.
$newsArchive = archiveExtractor('News Item','/news/index.php');
// Check to see if there are any results
if($newsArchive) {
$limit = count($newsArchive);
// Loop through all results
for ($i=0; $i < $limit; $i++) {
// In the example the word 'title' refers to the id of a content type
// from the 'News Item' content template
echo 'If you want to extract data from shared regions, simply leave out the content path. It took me a while to understand the point of this (as this was recommended by Drew) but obviously it would be handy if you only wanted to extract part of the data (i.e. title and date).
$newsArchive = archiveExtractor('News Item');
Download
Click to view code
/*
Archive Extractor - A Perch Hack
By Ad Taylor - http://www.iamadtaylor.com
For usage see :
Creative Commons Attribution-Share Alike 2.0 UK: England & Wales Licence
*/
function archiveExtractor($contentKey,$contentPage = '*')
{
$query = queryDB($contentKey,$contentPage,$limit);
if ($query) {
foreach ($query as $key => $value) {
$json = $value;
}
return PerchUtil::json_safe_decode($json);
} else {
return NULL;
}
}
function queryDB($contentKey,$contentPage) {
require_once $_SERVER['DOCUMENT_ROOT'].'/edit/config/config.php';
$link = @mysql_connect(PERCH_DB_SERVER, PERCH_DB_USERNAME, PERCH_DB_PASSWORD);
if (!$link) {
return NULL;
}
else {
mysql_select_db(PERCH_DB_DATABASE,$link);
$sql = "SELECT `contentJSON` FROM `".PERCH_DB_PREFIX."contentItems` WHERE `contentKey` LIKE '$contentKey' AND `contentPage` LIKE CONVERT(_utf8 '$contentPage' USING latin1) OR '*' COLLATE latin1_swedish_ci";
$result = mysql_query($sql, $link);
return mysql_fetch_assoc($result);
mysql_close($link);
}
}
Posted on : Monday, 13 July, 2009
I thought I would host this up for anyone who is using Perch and Textmate, its not much but it could save someone else the arduous task of making it themselves.
You can download it from here (probably right click ’save as’).
The bundle doesn’t do much more than speed up your workflow on Perch sites, its usage is pretty easy:
perch_content('Content');Keep it simple stupid.
| 2010 | Feb ( 1 ) |
|---|---|
| Jan ( 1 ) | |
| 2009 | Sep ( 2 ) |
| Aug ( 1 ) | |
| Jul ( 4 ) | |
| Jun ( 5 ) |
Social Hub