Snippets from freelance [the workspace]
13
Jul 2010
This website was developed a while before I decided to re-build my portfolio website. During the process of making this website it taught me how to manage a MODx project and keeping everything organized. In the blog post I will add some of the snippets I used while making freelance [the workspace].
First on the list is the GetAuthor snippet which is always useful when creating blog like sections on a website and you want to display the author of the page's name.
<?php
/*
* Returns the author of the post name
*/
$resource = isset ($resource) intval($resource) ?
intval($resource) : '';
function getAuthor($createdby) {
global $modx;
$user = false;
if ($createdby &> 0) {
$user = $modx->getUserInfo($createdby);
} else {
$user = $modx->getWebUserInfo(abs($createdby));
}
if ($user === false) {
// get admin user name
$user = $modx->getUserInfo(1);
}
return ($user['fullname'] != "") ? $user['fullname'] : $user['username'];
}
return getAuthor($resource);
?>
Another great snippet to the websites I develop on MODx is the GetDate snippet. This snippet was developed by a friend of mine who is also a user of MODx, check out his website Stanislav Cmakal.
<?php
/**
* @name News Date output
* @author iDevGeek
* @license Public Domain
* @version 1.00
*
* description
*/
date_default_timezone_set('Europe/London');
$output ='';
$date = 0;
// Show time
$time = isset($time) ? $time : false;
$format = isset($format) ? $format : "d-M-Y";
if ($currentID) {
$temp = $modx->getTemplateVar('pub_date', '*', $currentID);
if (empty($temp['value'])) {
//if not set get the create date
$temp = $modx->getTemplateVar('createdon', '*', $currentID);
$date = $temp['value'];
} else {
$date = $temp['value'];
}
$date = $time ? date($format . " h:i:s A", $date) :
date($format, $date);
if ($date !== 0) {
$output .= $date;
} else {
$output .= '---';
}
}
echo $output;
?>
Social Media
Twitter