Change Your MODX Web Site with the Seasons

A long time ago in MODX Evolution, I had a client who wanted to show photos related to the current season and offer four different seasonal coupons. I thought I’d provide an updated version of the snippet for people who want to do something similar.

This snippet allow you to automatically produce seasonal changes on your web site. It can be used to simply display the name of the current season or to pull in chunks that "seasonalize" the site in various ways. It can be used multiple times on the same page. If you’re using the chunk version, you can create four chunks called summer, fall, winter, and spring (these are the default chunk names). Optionally, you can send the names of the four chunks as properties.

Usage

This version will return just the name of the season:

[[!Season? &nameOnly=`1`]]

This one will return the content of the appropriate chunk if the chunks are called summer, fall, winter, and spring:

[[!Season]]

This version sets the names of the chunks to use for each season:

[[!Season?
    &summerChunk=`MySummerChunk`
    &fallChunk=`MyFallChunk`
    &winterChunk=`MyWinterChunk`
    &springChunk=`MySpringChunk`
]]

You could use this snippet to change the CSS with the seasons by putting the path to a different CSS file in each parameter and using the snippet call in your template where the CSS file is specified.

Using an image reference, it could be used to change an image or background image with the seasons.

The Snippet

Paste this code into a snippet called Season and save it.

<?php
/* Season snippet */

if (! function_exists('season')) {
    function season() {
        $limits = array(
            '/12/21' => 'winter',
            '/09/21' => 'fall',
            '/06/21' => 'summer',
            '/03/21' => 'spring',
            '/01/01' => 'winter'
        );
        $adate = date("M d Y"); /* set $adate to today */

        foreach ($limits AS $key => $value) {
            $limit = date("Y") . $key;
            if (strtotime($adate) >= strtotime($limit)) {
                return $value;
            }
        }
    }
}

$summerChunk = $modx->getOption('summerChunk', $scriptProperties, 'summer');
$fallChunk = $modx->getOption('fallChunk', $scriptProperties, 'fall');
$winterChunk = $modx->getOption('winterChunk', $scriptProperties, 'winter');
$springChunk = $modx->getOption('springChunk', $scriptProperties, 'spring');

$nameOnly = $modx->getOption('nameOnly', $scriptProperties, false);

/* Get the name of the current season */
$season = season();

/* Figure out what to return */
if (!empty($nameOnly)) {
    /* Return just the season name */
    $output = $season;
} else {
    /* Return the content of the appropriate chunk */
    $output = $modx->getChunk(${$season . 'Chunk'});
}
return $output;

Internationalization

You can change the season names wherever they appear in the code, and if you’re using chunks, change the names of your chunks accordingly or just send their names in the snippet properties. Be sure to change all of them and preserve the case of each season. You don’t need to change the date formatting, since the date is never displayed and only digits are used for the calculation.

The date ranges are in the form /month/day and correspond to the official seasons in the USA. You may wish to change them for other locales.

If want to use the snippet on a multi-language site, you can create lexicon files. You’ll need to send an &language property in the snippet tag with the two-letter language code and add these lines just below the function in order to load the appropriate lexicon file:

$language = $modx->getOption('language', $scriptProperties, 'en');
$modx->setOption('cultureKey', $language);
$modx->lexicon->load('season:default');

Change the line that returns just the season name to:

$output = $modx->lexicon($season);

Then, in the lexicon file (say at, core/components/season/lexicon/fr/default.inc.php), do this:

$_lang['spring'] = 'printemps';
$_lang['winter'] = 'hiver';
/* etc. */

 


For more information on how to use MODX to create a web site, see my web site Bob’s Guides, or better yet, buy my book: MODX: The Official Guide.

Looking for quality MODX Web Hosting? Look no further than Arvixe Web Hosting!

Tags: , , , , , , | Posted under MODX, MODX | 1 Comment

Getting the Actual Dimensions of an Uploaded Image

Suppose you allow images to be uploaded on your site but they must be of a certain size or maybe you want to resize the image as a percent of the original size. The hurdle by doing it in javascript or jquery is that you have to wait until it is completely loaded or you will get zeros as its dimension. Secondly using Javascript to get the image will give you the image size of the container it is in. So if you create a place holder then you cannot use width or size on the image or the result will be that image container. In other words something like this… Learn More

Tags: , , , , , , | Posted under ASP .NET 4.0, Programming/Coding | Leave a comment

Manage Your Database with SSMS 2012

Hello,

In order to manage sql databases on ASP servers, first we will need to install SQL Management studio.

1) Download the correct version:

http://www.microsoft.com/en-us/download/details.aspx?id=29062

Learn More

Tags: , , , , , | Posted under 3rd Party Software, ASP .NET 2, ASP .NET 4.0, DotNet/Windows Hosting, DotNetPanel Administration, MSSQL, Operating Systems, Programming/Coding, Using Arvixe, Web Deploy, Windows 7, Windows Server Admin | 21 Comments