Skip to content

Commit

Permalink
Cache generation rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Jan 29, 2012
1 parent d16aa50 commit e7c914c
Show file tree
Hide file tree
Showing 8 changed files with 461 additions and 286 deletions.
170 changes: 170 additions & 0 deletions _config.blank.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
<?php
/**
* Device Aware Config file
* * Registers extensions
* * Register images to chache
*
* Copyright (c) 2011, Thierry Francois / COLYMBA
* Licensed under the MIT license
* http://colymba.com
*
* @package DeviceAware
*
* @copyright Thierry Francois / COLYMBA
* @author thierry@colymba.com
* @version 0.01
*
* @requires DeviceAware
*/

///////////////////////////////////////////////////////////////////////////////
/////////////////////// Extensions + rules

/**
* Register extensions
*/
Object::add_extension('Page_Controller', 'DeviceAwarePage_Controller');
Object::add_extension('Page', 'DeviceAwarePage');
Object::add_extension('Image', 'DeviceAwareImage');

/**
* Add director URL rule to store current device resolution from AJAX call
*/
Director::addRules(100, array(
'device_aware/$Action/$ID' => "Page_Controller"
));

Director::addRules(100, array(
'device_aware/dev/$Action/$Class/$ID' => "DeviceAwareDev_Controller"
));

///////////////////////////////////////////////////////////////////////////////
/////////////////////// Image cache generations

/**
* By default images are not over-sampled
* Uncomment if you would like to
*
* DeviceAware::$overSampleImages = TRUE;
*/

/**
* For mobile: devices to pre-generate image for
* best to use the most common ones for your visitors
*/
DeviceAware::$cachedMobileDevices = array('iPhone');

/**
* Overhide screen resolution for pre-generated images
* Check you site analytics for the most common ones
* or checkout: http://en.wikipedia.org/wiki/Display_resolution
*/
DeviceAware::$screenResolutions = array(
array(1280, 1024),
array(1440, 900),
array(1680, 1050),
array(1024, 768),
array(1920, 1200)
);

/*
* Registers images to cache
* TODO: handle image orientation conditions
* TODO: handle pixel sizes
*/
/*
DeviceAware::$usedResolutionRatios = array(
'Project' => array(
'fields' => array(
'CoverID' => array(
'classic' => array(
'width' => array() //as used in template
),
'mobile' => array(
'width' => array()
)
)
),
'objects' => array(
'Snapshot' => array(
'foreignKey' => 'ProjectID',
'fields' => array(
'ImageID' => array(
'classic' => array(
'width' => array(), //as used in template
'height' => array() //as used in template
),
'mobile' => array(
'width' => array(), //as used in template
'height' => array() //as used in template
)
)
)
)
)
)
);
*/
DeviceAware::$usedResolutionRatios = array(
'Project' => array(
'fields' => array(
'CoverID' => array(
'classic' => array(
'width' => array() //as used in template
),
'mobile' => array(
'width' => array()
)
)
),
'objects' => array(
'Snapshot' => array(
'foreignKey' => 'ProjectID',
'fields' => array(
'ImageID' => array(
'classic' => array(
'width' => array()
),
'mobile' => array(
'width' => array()
)
)
)
)
)
),
'Page' => array(
'objects' => array(
'ContentBlock' => array(
'foreignKey' => 'PageID',
'fields' => array(
'ImageID' => array(
'classic' => array(
'width' => array()
),
'mobile' => array(
'width' => array()
)
),
'ImageSetImage2ID' => array(
'classic' => array(
'width' => array()
),
'mobile' => array(
'width' => array()
)
),
'ImageSetImage3ID' => array(
'classic' => array(
'width' => array()
),
'mobile' => array(
'width' => array()
)
)
)
)
)
)
);
?>
103 changes: 64 additions & 39 deletions _config.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,64 +42,89 @@
/////////////////////// Image cache generations

/**
* By default images are not over-sampled
* Uncomment if you would like to
*
* DeviceAware::$overSampleImages = TRUE;
* Default JPEG quality is 85 for cached images
* Uncomment to overide
*/
//DeviceAware::$JPGImageQuality = 100;

/**
* For mobile: devices to pre-generate image for
* best to use the most common ones for your visitors
*/
DeviceAware::$cachedMobileDevices = array('iPhone','android');

/**
* Overhide screen resolution for pre-generated images
* Check you site analytics for the most common ones
* or checkout: http://en.wikipedia.org/wiki/Display_resolution
*/
DeviceAware::$screenResolutions = array(
array(1280, 1024),
array(1440, 900),
array(1680, 1050),
array(1920, 1080),
array(1920, 1200)
);
* By default images are not over-sampled
* Uncomment if you would like to
*/
//DeviceAwareImage::$overSampleImages = TRUE;

/*

/**
* Registers images to cache
* TODO: handle image orientation conditions
*
* Check you site analytics for the most common resolutions
* or checkout: http://en.wikipedia.org/wiki/Display_resolution
*/
DeviceAware::$usedResolutionRatios = array(
DeviceAwareCache::$imageCacheSettings = array(
'Project' => array(
'fields' => array(
'CoverID' => array(
'classic' => array(
'width' => array() //as used in template
),
'mobile' => array(
'width' => array()
)
// imageOrientation, ratio/pixelSize, screenResolution, imageDirectionToResize

// Classic devices
array('P', 0.102, 1920, 'W'),
array('S', 0.102, 1920, 'W'),
array('L', 0.102, 1920, 'H'),

array('P', 0.102, 1680, 'W'),
array('S', 0.102, 1680, 'W'),
array('L', 0.102, 1680, 'H'),
/*
array('P', 0.1498, 1440, 'W'),
array('S', 0.1498, 1440, 'W'),
array('L', 0.1498, 1440, 'H'),
array('P', 0.1498, 1280, 'W'),
array('S', 0.1498, 1280, 'W'),
array('L', 0.1498, 1280, 'H'),
array('P', 0.147, 1024, 'W'),
array('S', 0.147, 1024, 'W'),
array('L', 0.147, 1024, 'H'),
// Mobile
array('P', 0.266, 640, 'W'),
array('S', 0.266, 640, 'W'),
array('L', 0.266, 640, 'H'),
array('P', 0.266, 960, 'W'),
array('S', 0.266, 960, 'W'),
array('L', 0.266, 960, 'H') */
)
),
'objects' => array(
'Snapshot' => array(
'foreignKey' => 'ProjectID',
'fields' => array(
'ImageID' => array(
'classic' => array(
'width' => array(), //as used in template
'height' => array() //as used in template
),
'mobile' => array(
'width' => array(), //as used in template
'height' => array() //as used in template
)
// imageOrientation, ratio/pixelSize, screenResolution, imageDirectionToResize

// Classic devices
/*array('L', 0.6, 1920, 'W'),
array('L', 0.6, 1680, 'W'),
array('L', 0.7, 1440, 'W'),
array('L', 0.7, 1280, 'W'),
array('L', 0.7, 1024, 'W'),
array('P', '700', 0, 'H'),
array('P', '550', 0, 'H'),
array('S', '700', 0, 'H'),
array('S', '550', 0, 'H'),*/

// Mobile
array('P', '550', 0, 'H'),
array('S', '550', 0, 'H'),
array('L', 0.95, 640, 'W'),
array('L', 0.95, 960, 'W'),
)
)
)
)
)
);
);
?>
5 changes: 4 additions & 1 deletion code/Controllers/DeviceAwareDev_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ public function build()
$classID = Director::URLParam('ID');

//if URLParams use this
DeviceAware::generateDeviceSpecificCachedImages($className, $classID, TRUE);
//DeviceAware::generateDeviceSpecificCachedImages($className, $classID, TRUE);
DeviceAwareCache::$verbose = TRUE;
DeviceAwareCache::generateCache($className, $classID);
DeviceAwareCache::$verbose = FALSE;

//get config
//loop though classes
Expand Down
25 changes: 25 additions & 0 deletions code/Controllers/DeviceAwarePage_Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ public function screenWidth()
return $screenResolution[0];
}

public function screenHeight()
{
$screenResolution = Session::get('screenResolution');
if ( !$screenResolution )
{
$screenResolution = DeviceAware::$defaultScreenResolution;
}

return $screenResolution[1];
}

public function isUsingDefaultResolution()
{
$screenResolution = Session::get('screenResolution');
Expand Down Expand Up @@ -200,5 +211,19 @@ public function getWidthFromScreenRatio($ratio = 1)
{
return $this->screenWidth() * $ratio;
}

//-------------------------------------------------------------------------

public function screenHeight1000Plus()
{
if ( $this->screenHeight() >= 1000 ) return TRUE;
else return FALSE;
}

public function screenHeight900Plus()
{
if ( $this->screenHeight() >= 900 ) return TRUE;
else return FALSE;
}
}
?>
Loading

0 comments on commit e7c914c

Please sign in to comment.