Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ebollens committed Oct 14, 2011
2 parents 4f7f345 + 81363c6 commit c77b971
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 114 deletions.
4 changes: 1 addition & 3 deletions config/frontpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* This should NOT be included directly; instead /assets/config.php should be.
*
* @author ebollens
* @version 20110511
* @version 20111012
*
* @uses Config
* @link /assets/config.php
Expand Down Expand Up @@ -89,8 +89,6 @@
'url'=>'https://github.com/ucla/mwf'),
array('name'=>'Documentation',
'url'=>'https://github.com/ucla/mwf/wiki'),
array('name'=>'Forums',
'url'=>'http://mwf.ucla.edu/forum'),
array('name'=>'Issue Tracker',
'url'=>'https://jira.ats.ucla.edu:8443/')
)
Expand Down
11 changes: 1 addition & 10 deletions root/assets/css.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,7 @@
require_once(dirname(__FILE__).'/lib/path.class.php');
require_once(dirname(__FILE__).'/lib/path_validator.class.php');

?>/**
* CSS handler.
*
* @package core
* @subpackage css
*
* @author ebollens
* @copyright Copyright (c) 2010-11 UC Regents
* @license http://mwf.ucla.edu/license
*/
?>/** Mobile Web Framework | http://mwf.ucla.edu */

<?php

Expand Down
11 changes: 1 addition & 10 deletions root/assets/js.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,7 @@
include_once(dirname(__FILE__).'/lib/user_agent.class.php');
$ext = '.js';

?>/**
* Javascript handler.
*
* @package core
* @subpackage js
*
* @author ebollens
* @copyright Copyright (c) 2010-11 UC Regents
* @license http://mwf.ucla.edu/license
*/
?>/** Mobile Web Framework | http://mwf.ucla.edu */

<?php

Expand Down
42 changes: 17 additions & 25 deletions root/assets/lib/screen.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,7 @@
require_once(dirname(dirname(__FILE__)).'/config.php');

class Screen
{
/**
* Default height if Javascript cannot determine it.
*
* @var int
*/
private static $_default_height = 480;

/**
* Default width if Javascript cannot determine it.
*
* @var int
*/
private static $_default_width = 320;

{
private static $_init = null;

private static $_name;
Expand Down Expand Up @@ -115,32 +101,38 @@ public static function has_cookie()
}

/**
* Returns the width of the browser in the following order: (1) from a
* cookie set by mwf.browser or (2) the default width.
* Returns the width of the browser from a
* cookie set by mwf.browser or else false
*
* @return int
* @return bool
*/
public static function get_width(){
return ($width = self::get('w')) ? $width : self::$_default_width;
$width = self::get('w');
return is_numeric($width) ? intval($width) : false;
}

/**
* Returns the height of the screen in the following order: (1) from a
* cookie set by mwf.browser or (2) the default height.
* Returns the height of the screen from a
* cookie set by mwf.browser or else false
*
* @return int
* @return bool
*/
public static function get_height(){
return ($height = self::get('h')) ? $height : self::$_default_height;
$height = self::get('h');
return is_numeric($height) ? intval($height) : false;
}

/**
* Returns the height of the screen in the following order: (1) from a
* cookie set by mwf.browser or (2) the default height.
* Returns the pixel ratio of the screen from a
* cookie set by mwf.browser or else false
*
* @return int
* @return float
* @return bool
*/
public static function get_pixel_ratio(){
return ($ratio = self::get('r')) ? $ratio : 1;
$ratio = self::get('r');
return is_numeric($ratio) ? floatval($ratio) : false;
}
}
121 changes: 55 additions & 66 deletions root/assets/min/img.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,83 +17,72 @@
* @uses Screen
* @uses Local_Image
*/

/**
* If no img is provided, exit.
*/
if (! isset($_GET['img'])) {
if (!isset($_GET['img'])) {
error_log('MWF Notice: Required URL parameter "img" not provided to ' . $_SERVER['PHP_SELF'], 0);
exit(1);
}

/**
* Require necessary libraries.
*/
include_once(dirname(dirname(__FILE__)).'/lib/screen.class.php');
include_once(dirname(dirname(__FILE__)).'/lib/image.class.php');

if(Screen::get_width() && Screen::get_height())
{
/**
* @var int maximum width the image should be as defined first by the browser
* width and then more specifically by URI parameters.
*/
$max_width = Screen::get_width() * Screen::get_pixel_ratio();
include_once(dirname(dirname(__FILE__)) . '/lib/screen.class.php');
include_once(dirname(dirname(__FILE__)) . '/lib/image.class.php');

/**
* @var int maximum height the image should be as defined first by the browser
* width and then more specifically by URI parameters.
*/
$max_height = Screen::get_height() * Screen::get_pixel_ratio();
/**
* @var int maximum width the image should be as defined first by the browser
* width and then more specifically by URI parameters.
*/
$max_width = Screen::get_width() ? Screen::get_width() * Screen::get_pixel_ratio() : PHP_INT_MAX;

/**
* @var bool true if the image should be compressed based on width.
*/
$set_width = false;
/**
* @var int maximum height the image should be as defined first by the browser
* width and then more specifically by URI parameters.
*/
$max_height = Screen::get_height() ? Screen::get_height() * Screen::get_pixel_ratio() : PHP_INT_MAX;

/**
* @var bool true if the image should be compressed based on height.
*/
$set_height = false;
/**
* @var bool true if the image should be compressed based on width.
*/
$set_width = false;

/**
* Defines $set_height true if a URI segment defining height is set and then
* calculates the $max_height that the image should be based on the segment(s).
*
* @uses $_GET['browser_width_percent'] defines width as percentage of browser width
* @uses $_GET['browser_width_force'] defines width as 100% of browser width at max
* @uses $_GET['max_width'] defines width by max pixels for the image
*/
if(isset($_GET['browser_width_percent']) || isset($_GET['browser_width_force']) || isset($_GET['max_width']))
{
$set_width = true;
if(isset($_GET['browser_width_percent']))
$max_width = $max_width * $_GET['browser_width_percent'] / 100;
if(isset($_GET['max_width']) && $_GET['max_width'] < $max_width)
$max_width = $_GET['max_width'];
}
/**
* @var bool true if the image should be compressed based on height.
*/
$set_height = false;

/**
* Defines $set_height true if a URI segment defining height is set and then
* calculates the $max_height that the image should be based on the segment(s).
*
* @uses $_GET['browser_height_percent']defines height as percentage of browser height
* @uses $_GET['browser_height_force'] defines height as 100% of browser height at max
* @uses $_GET['max_height'] defines height by max pixels for the image
*/
if(isset($_GET['browser_height_percent']) || isset($_GET['browser_height_force']) || isset($_GET['max_height']))
{
$set_height = true;
if(isset($_GET['browser_height_percent']))
$max_height = $max_height * $_GET['browser_height_percent'] / 100;
if(isset($_GET['max_height']) && $_GET['max_height'] < $max_height)
$max_height = $_GET['max_height'];
}
/**
* Defines $set_height true if a URI segment defining height is set and then
* calculates the $max_height that the image should be based on the segment(s).
*
* @uses $_GET['browser_width_percent'] defines width as percentage of browser width
* @uses $_GET['browser_width_force'] defines width as 100% of browser width at max
* @uses $_GET['max_width'] defines width by max pixels for the image
*/
if (isset($_GET['browser_width_percent']) || isset($_GET['browser_width_force']) || isset($_GET['max_width'])) {
$set_width = true;
if (isset($_GET['browser_width_percent']))
$max_width = $max_width * $_GET['browser_width_percent'] / 100;
if (isset($_GET['max_width']) && $_GET['max_width'] < $max_width)
$max_width = $_GET['max_width'];
}
else
{
$set_width = false;
$set_height = false;

/**
* Defines $set_height true if a URI segment defining height is set and then
* calculates the $max_height that the image should be based on the segment(s).
*
* @uses $_GET['browser_height_percent']defines height as percentage of browser height
* @uses $_GET['browser_height_force'] defines height as 100% of browser height at max
* @uses $_GET['max_height'] defines height by max pixels for the image
*/
if (isset($_GET['browser_height_percent']) || isset($_GET['browser_height_force']) || isset($_GET['max_height'])) {
$set_height = true;
if (isset($_GET['browser_height_percent']))
$max_height = $max_height * $_GET['browser_height_percent'] / 100;
if (isset($_GET['max_height']) && $_GET['max_height'] < $max_height)
$max_height = $_GET['max_height'];
}

/**
Expand All @@ -108,12 +97,12 @@
$image->set_allowed_extension('png');

/** Force max width if $set_width is true. */
if($set_width)
$image->set_max_width($max_width);
if ($set_width)
$image->set_max_width($max_width);

/** For max height if $set_height is true. */
if($set_height)
$image->set_max_height($max_height);
if ($set_height)
$image->set_max_height($max_height);

/** Output the header so that browser treats it as an image rather than PHP file. */
$image->output_header();
Expand Down

0 comments on commit c77b971

Please sign in to comment.