The Blog / Development / Snippets from freelance [the workspace]

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;
?>

Tweeties

  1. 01 Feb 2012 - RT @gittower: Submodule support is coming to Tower! Here's a little preview of v 1.4 http://t.co/AsIdd3Eo via web
  2. 01 Feb 2012 - @toychicken yeah mine got switched off instantly, IT team is great on exits. via Twitter for Android
  3. 01 Feb 2012 - @_matt_cannon divvy. via Twitter for Android
  4. 01 Feb 2012 - RT @Shealan: "Due to copyright restrictions you cannot buy this product in your country" Yeah? "Due to your lack of foresight I'll pirat ... via web

Social Media

Twitter
Square Bob Sponge Pants at Home Square Bob Sponge Pants at o2 Arena London Midland Train