Skip to content

Instantly share code, notes, and snippets.

@bigin
Last active February 16, 2017 06:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bigin/187ec20627d7fc0d0eccb2e0765d9a91 to your computer and use it in GitHub Desktop.
Save bigin/187ec20627d7fc0d0eccb2e0765d9a91 to your computer and use it in GitHub Desktop.
<?php
/**
* setlocale — Set locale information (numeric formatting information)
*
* Change that depending on your country
*
*/
setlocale(LC_MONETARY, 'de_DE');
/**
* get the current page slug and parent
*
*/
$slug = (string)get_page_slug(false);
$parent = get_parent(false);
/**
* Bootstrap image resizer lib
*
*/
require_once(GSPLUGINPATH.'imanager/phpthumb/ThumbLib.inc.php');
/**
* Reads all available dummy categories and stores them into the $categories variable
*
*/
if($slug == 'catalog') {
$categories = getCategories();
}
/**
* Reads products of a category or product details and stores them into a variable
*
*/
if($parent == 'catalog') {
if(empty($_GET['product'])) {
$categoryItems = getItems($slug);
} else {
$currentProduct = getItem($slug);
}
}
/**
* A simple function that returns an array of dummy categories
* @return array
*/
function getCategories() {
return imanager()->getItems('slug=dummy-category', 'active=1');
}
/**
* A simple function that returns an array of products
*
* @param string $slug - This is the slug of the products you want to select
* @return array
*/
function getItems($slug) {
$imanager = imanager();
return $imanager->getItems('slug='.$imanager->sanitizer->pageName($slug), 'active=1');
}
/**
* A function that returns a product
*
* @param string $slug - This is the slug of the product you want to select
* @return object
*/
function getItem($slug) {
$imanager = imanager();
return $imanager->getItem('slug='.$imanager->sanitizer->pageName($slug), (int) $_GET['product']);
}
/**
* Resizes images / with the first call creates thumbnails and stores them
*
* @param object $image - This is the image field whose images you want to resize
* @return string
*/
function getResized(Field $image, $size = 200) {
global $SITEURL;
foreach($image->file_name as $key => $name) {
// Check if thumbnail exists
if(!file_exists($image->path[$key].'thumbnail/'.$size.'_'.$name))
{
$thumb = PhpThumbFactory::create($image->fullpath[$key]);
$path_parts = pathinfo($image->fullpath[$key]);
$thumb->resize($size);
$thumb->save($image->url[$key].'thumbnail/'.$size.'_'.$name, $path_parts['extension']);
}
return '<img src="'.$SITEURL.$image->url[$key].'thumbnail/'.$size.'_'.$name.'"
alt="'.(!empty($image->title[$key]) ? ($image->title[$key]) : '').'" width="'.$size.'">';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment