Skip to content

Commit

Permalink
Added a bunch of stuff from another project - flashmessages, less sup…
Browse files Browse the repository at this point in the history
…port, and some bugfixes
  • Loading branch information
markguinn committed Feb 2, 2011
1 parent 0d73d69 commit cc109ef
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 185 deletions.
25 changes: 25 additions & 0 deletions code/livepub/LivePubHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ static function include_php($filename) {
if (count(self::$template_path) == 0) {
self::$template_path[] = BASE_PATH . '/' . THEMES_DIR . '/' . SSViewer::current_theme() . '/templates/php';
self::$template_path[] = BASE_PATH . '/' . $project . '/templates/php';
self::$template_path[] = BASE_PATH . '/' . SSTOOLS_BASE . '/templates/php';
}

// check all the possible paths we've accumulated
Expand Down Expand Up @@ -248,6 +249,30 @@ static function wrap($object, $class = 'ViewableWrapper', $add_init_code=true) {

return $obj;
}


/**
* Takes an array of objects or arrays and creates a dataobjectset,
* calling {@link LivePubHelper::wrap} on each item in the array.
*
* @static
* @param array $list
* @param string $class [optional] - default is 'ViewableWrapper'
* @param string $exclude [optional] - filter set by excluding these values
* @param string $exclude_field [optional] - field to filter by
* @return DataObjectSet
*/
static function wrap_set(array $list, $class = 'ViewableWrapper', $exclude=null, $exclude_field=null) {
$set = new DataObjectSet();

foreach ($list as $r) {
$obj = self::wrap($r, $class);
if ($exclude && in_array($obj->getField($exclude_field), $exclude)) continue;
$set->push($obj);
}

return $set;
}


/**
Expand Down
68 changes: 68 additions & 0 deletions code/livepub/ViewableWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ViewableWrapper extends ViewableData
*/
function __construct($src=false) {
if (is_object($src)){
$src->class = get_class($src);
$this->failover = $src;
} elseif (is_array($src)) {
$this->failover = new ArrayData($src);
Expand Down Expand Up @@ -163,7 +164,74 @@ protected function wrapObject($obj) {
}
}


/**
* returns the given field as a casted date object
*/
function AsDate($field) {
$d = $this->$field;
return DBField::create('Date', is_numeric($d) ? date('Y-m-d H:i:s', $d) : $d);
}


/**
* returns the given field as a casted date object
*/
function AsCurrency($field) {
return DBField::create('Currency', $this->$field);
}


/**
* returns the given field as a uniformly formatted phone #
* !todo - does this need to work differently for internationals?
*/
function AsPhone($field) {
$str = preg_replace('/[^0-9]/', '', $this->$field);
$out = '';

switch (strlen($str)) {
case 11:
case 12:
$str = ltrim($str, '0');
$out .= '+' . substr($str, 0, -10) . ' ';
case 10:
$out .= '(' . substr($str, -10, 3) . ') ';
case 7:
$out .= substr($str, -7, 3) . '-' . substr($str, -4);
break;

default:
$out = $str;
}

return $out;
}


function DebugMe() {
Debug::dump($this);
}


/**
* Return the "casting helper" (a piece of PHP code that when evaluated creates a casted value object) for a field
* on this object. MODIFIED TO LEAVE FAILOVER ALONE (so it doesn't have to inherit Object).
*
* @param string $field
* @return string
*/
public function castingHelper($field) {
if($this->hasMethod('db') && $fieldSpec = $this->db($field)) {
return $fieldSpec;
}

$specs = Object::combined_static(get_class($this), 'casting');
if(isset($specs[$field])) return $specs[$field];

//if($this->failover) return $this->failover->castingHelper($field);
}

/**
* This is called by LivePubHelper to retrieve initialization
* code that gets added to the top of the cached page.
Expand Down
185 changes: 0 additions & 185 deletions code/smtpmailer/Emogrifier.php

This file was deleted.

0 comments on commit cc109ef

Please sign in to comment.