mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch 'master' into integration
Conflicts: admin/css/screen.css dev/install/php5-required.html
This commit is contained in:
commit
8c5e56fe31
@ -42,8 +42,6 @@ Director::addRules(20, array(
|
|||||||
Object::useCustomClass('SSDatetime', 'SS_Datetime', true);
|
Object::useCustomClass('SSDatetime', 'SS_Datetime', true);
|
||||||
Object::useCustomClass('Datetime', 'SS_Datetime', true);
|
Object::useCustomClass('Datetime', 'SS_Datetime', true);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The root directory of TinyMCE
|
* The root directory of TinyMCE
|
||||||
*/
|
*/
|
||||||
|
@ -68,7 +68,7 @@ class CMSBatchActionHandler extends RequestHandler {
|
|||||||
|
|
||||||
function handleAction($request) {
|
function handleAction($request) {
|
||||||
// This method can't be called without ajax.
|
// This method can't be called without ajax.
|
||||||
if(!$this->parentController->isAjax()) {
|
if(!$request->isAjax()) {
|
||||||
$this->parentController->redirectBack();
|
$this->parentController->redirectBack();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -81,7 +81,7 @@ class CMSBatchActionHandler extends RequestHandler {
|
|||||||
$actionHandler = new $actionClass();
|
$actionHandler = new $actionClass();
|
||||||
|
|
||||||
// Sanitise ID list and query the database for apges
|
// Sanitise ID list and query the database for apges
|
||||||
$ids = split(' *, *', trim($request->requestVar('csvIDs')));
|
$ids = preg_split('/ *, */', trim($request->requestVar('csvIDs')));
|
||||||
foreach($ids as $k => $v) if(!is_numeric($v)) unset($ids[$k]);
|
foreach($ids as $k => $v) if(!is_numeric($v)) unset($ids[$k]);
|
||||||
|
|
||||||
if($ids) {
|
if($ids) {
|
||||||
@ -135,7 +135,7 @@ class CMSBatchActionHandler extends RequestHandler {
|
|||||||
$actionHandler = new $actionClass['class']();
|
$actionHandler = new $actionClass['class']();
|
||||||
|
|
||||||
// Sanitise ID list and query the database for apges
|
// Sanitise ID list and query the database for apges
|
||||||
$ids = split(' *, *', trim($request->requestVar('csvIDs')));
|
$ids = preg_split('/ *, */', trim($request->requestVar('csvIDs')));
|
||||||
foreach($ids as $k => $id) $ids[$k] = (int)$id;
|
foreach($ids as $k => $id) $ids[$k] = (int)$id;
|
||||||
$ids = array_filter($ids);
|
$ids = array_filter($ids);
|
||||||
|
|
||||||
@ -157,7 +157,7 @@ class CMSBatchActionHandler extends RequestHandler {
|
|||||||
$actionHandler = new $actionClass();
|
$actionHandler = new $actionClass();
|
||||||
|
|
||||||
// Sanitise ID list and query the database for apges
|
// Sanitise ID list and query the database for apges
|
||||||
$ids = split(' *, *', trim($request->requestVar('csvIDs')));
|
$ids = preg_split('/ *, */', trim($request->requestVar('csvIDs')));
|
||||||
foreach($ids as $k => $id) $ids[$k] = (int)$id;
|
foreach($ids as $k => $id) $ids[$k] = (int)$id;
|
||||||
$ids = array_filter($ids);
|
$ids = array_filter($ids);
|
||||||
|
|
||||||
@ -211,4 +211,4 @@ class CMSBatchActionHandler extends RequestHandler {
|
|||||||
return $actions;
|
return $actions;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -104,6 +104,11 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
'css' => array(),
|
'css' => array(),
|
||||||
'themedcss' => array(),
|
'themedcss' => array(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var PJAXResponseNegotiator
|
||||||
|
*/
|
||||||
|
protected $responseNegotiator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Member $member
|
* @param Member $member
|
||||||
@ -193,7 +198,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
if(Director::redirected_to()) return;
|
if(Director::redirected_to()) return;
|
||||||
|
|
||||||
// Audit logging hook
|
// Audit logging hook
|
||||||
if(empty($_REQUEST['executeForm']) && !$this->isAjax()) $this->extend('accessedCMS');
|
if(empty($_REQUEST['executeForm']) && !$this->request->isAjax()) $this->extend('accessedCMS');
|
||||||
|
|
||||||
// Set the members html editor config
|
// Set the members html editor config
|
||||||
HtmlEditorConfig::set_active(Member::currentUser()->getHtmlEditorConfigForCMS());
|
HtmlEditorConfig::set_active(Member::currentUser()->getHtmlEditorConfigForCMS());
|
||||||
@ -250,7 +255,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
SAPPHIRE_ADMIN_DIR . '/thirdparty/jlayout/lib/jquery.jlayout.js',
|
SAPPHIRE_ADMIN_DIR . '/thirdparty/jlayout/lib/jquery.jlayout.js',
|
||||||
SAPPHIRE_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.js',
|
SAPPHIRE_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.js',
|
||||||
SAPPHIRE_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.adapter.jquery.js',
|
SAPPHIRE_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.adapter.jquery.js',
|
||||||
// SAPPHIRE_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.html4.js',
|
SAPPHIRE_ADMIN_DIR . '/thirdparty/history-js/scripts/uncompressed/history.html4.js',
|
||||||
THIRDPARTY_DIR . '/jstree/jquery.jstree.js',
|
THIRDPARTY_DIR . '/jstree/jquery.jstree.js',
|
||||||
SAPPHIRE_ADMIN_DIR . '/thirdparty/chosen/chosen/chosen.jquery.js',
|
SAPPHIRE_ADMIN_DIR . '/thirdparty/chosen/chosen/chosen.jquery.js',
|
||||||
SAPPHIRE_ADMIN_DIR . '/thirdparty/jquery-hoverIntent/jquery.hoverIntent.js',
|
SAPPHIRE_ADMIN_DIR . '/thirdparty/jquery-hoverIntent/jquery.hoverIntent.js',
|
||||||
@ -322,26 +327,35 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
SSViewer::set_theme(null);
|
SSViewer::set_theme(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleRequest($request, DataModel $model) {
|
function handleRequest(SS_HTTPRequest $request, DataModel $model = null) {
|
||||||
$title = $this->Title();
|
$title = $this->Title();
|
||||||
|
|
||||||
$response = parent::handleRequest($request, $model);
|
$response = parent::handleRequest($request, $model);
|
||||||
if(!$response->getHeader('X-Controller')) $response->addHeader('X-Controller', $this->class);
|
if(!$response->getHeader('X-Controller')) $response->addHeader('X-Controller', $this->class);
|
||||||
if(!$response->getHeader('X-Title')) $response->addHeader('X-Title', $title);
|
if(!$response->getHeader('X-Title')) $response->addHeader('X-Title', $title);
|
||||||
if(!$response->getHeader('X-ControllerURL')) {
|
|
||||||
$url = $request->getURL();
|
|
||||||
if($getVars = $request->getVars()) {
|
|
||||||
if(isset($getVars['url'])) unset($getVars['url']);
|
|
||||||
$url = Controller::join_links($url, '?' . http_build_query($getVars));
|
|
||||||
}
|
|
||||||
$response->addHeader('X-ControllerURL', $url);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overloaded redirection logic to trigger a fake redirect on ajax requests.
|
||||||
|
* While this violates HTTP principles, its the only way to work around the
|
||||||
|
* fact that browsers handle HTTP redirects opaquely, no intervention via JS is possible.
|
||||||
|
* In isolation, that's not a problem - but combined with history.pushState()
|
||||||
|
* it means we would request the same redirection URL twice if we want to update the URL as well.
|
||||||
|
* See LeftAndMain.js for the required jQuery ajaxComplete handlers.
|
||||||
|
*/
|
||||||
|
function redirect($url, $code=302) {
|
||||||
|
if($this->request->isAjax()) {
|
||||||
|
$this->response->addHeader('X-ControllerURL', $url);
|
||||||
|
return ''; // Actual response will be re-requested by client
|
||||||
|
} else {
|
||||||
|
parent::redirect($url, $code);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function index($request) {
|
function index($request) {
|
||||||
return ($this->isAjax()) ? $this->show($request) : $this->getViewer('index')->process($this);
|
return $this->getResponseNegotiator()->respond($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -391,20 +405,30 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
public function show($request) {
|
public function show($request) {
|
||||||
// TODO Necessary for TableListField URLs to work properly
|
// TODO Necessary for TableListField URLs to work properly
|
||||||
if($request->param('ID')) $this->setCurrentPageID($request->param('ID'));
|
if($request->param('ID')) $this->setCurrentPageID($request->param('ID'));
|
||||||
|
return $this->getResponseNegotiator()->respond($request);
|
||||||
if($this->isAjax()) {
|
}
|
||||||
if($request->getVar('cms-view-form')) {
|
|
||||||
$form = $this->getEditForm();
|
/**
|
||||||
$content = $form->forTemplate();
|
* Caution: Volatile API.
|
||||||
} else {
|
*
|
||||||
// Rendering is handled by template, which will call EditForm() eventually
|
* @return PJAXResponseNegotiator
|
||||||
$content = $this->renderWith($this->getTemplatesWithSuffix('_Content'));
|
*/
|
||||||
}
|
protected function getResponseNegotiator() {
|
||||||
} else {
|
if(!$this->responseNegotiator) {
|
||||||
$content = $this->renderWith($this->getViewer('show'));
|
$controller = $this;
|
||||||
|
$this->responseNegotiator = new PJAXResponseNegotiator(array(
|
||||||
|
'CurrentForm' => function() use(&$controller) {
|
||||||
|
return $controller->getEditForm()->forTemplate();
|
||||||
|
},
|
||||||
|
'Content' => function() use(&$controller) {
|
||||||
|
return $controller->renderWith($controller->getTemplatesWithSuffix('_Content'));
|
||||||
|
},
|
||||||
|
'default' => function() use(&$controller) {
|
||||||
|
return $controller->renderWith($controller->getViewer('show'));
|
||||||
|
}
|
||||||
|
));
|
||||||
}
|
}
|
||||||
|
return $this->responseNegotiator;
|
||||||
return $content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------//
|
//------------------------------------------------------------------------------------------//
|
||||||
@ -467,7 +491,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
$menu->push(new ArrayData(array(
|
$menu->push(new ArrayData(array(
|
||||||
"MenuItem" => $menuItem,
|
"MenuItem" => $menuItem,
|
||||||
"Title" => Convert::raw2xml($title),
|
"Title" => Convert::raw2xml($title),
|
||||||
"Code" => DBField::create('Text', $code),
|
"Code" => DBField::create_field('Text', $code),
|
||||||
"Link" => $menuItem->url,
|
"Link" => $menuItem->url,
|
||||||
"LinkingMode" => $linkingmode
|
"LinkingMode" => $linkingmode
|
||||||
)));
|
)));
|
||||||
@ -589,7 +613,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
|
|
||||||
// getChildrenAsUL is a flexible and complex way of traversing the tree
|
// getChildrenAsUL is a flexible and complex way of traversing the tree
|
||||||
$titleEval = '
|
$titleEval = '
|
||||||
"<li id=\"record-$child->ID\" data-id=\"$child->ID\" class=\"" . $child->CMSTreeClasses($extraArg) . "\">" .
|
"<li id=\"record-$child->ID\" data-id=\"$child->ID\" data-ssclass=\"$child->ClassName\" class=\"" . $child->CMSTreeClasses($extraArg) . "\">" .
|
||||||
"<ins class=\"jstree-icon\"> </ins>" .
|
"<ins class=\"jstree-icon\"> </ins>" .
|
||||||
"<a href=\"" . Controller::join_links($extraArg->Link("show"), $child->ID) . "\" title=\"'
|
"<a href=\"" . Controller::join_links($extraArg->Link("show"), $child->ID) . "\" title=\"'
|
||||||
. _t('LeftAndMain.PAGETYPE','Page type: ')
|
. _t('LeftAndMain.PAGETYPE','Page type: ')
|
||||||
@ -680,13 +704,10 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
$form->saveInto($record, true);
|
$form->saveInto($record, true);
|
||||||
$record->write();
|
$record->write();
|
||||||
$this->extend('onAfterSave', $record);
|
$this->extend('onAfterSave', $record);
|
||||||
|
$this->setCurrentPageID($record->ID);
|
||||||
|
|
||||||
$this->response->addHeader('X-Status', _t('LeftAndMain.SAVEDUP'));
|
$this->response->addHeader('X-Status', _t('LeftAndMain.SAVEDUP'));
|
||||||
|
return $this->getResponseNegotiator()->respond($request);
|
||||||
// write process might've changed the record, so we reload before returning
|
|
||||||
$form = $this->getEditForm($record->ID);
|
|
||||||
|
|
||||||
return $form->forTemplate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete($data, $form) {
|
public function delete($data, $form) {
|
||||||
@ -697,12 +718,12 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
if(!$record || !$record->ID) throw new HTTPResponse_Exception("Bad record ID #" . (int)$data['ID'], 404);
|
if(!$record || !$record->ID) throw new HTTPResponse_Exception("Bad record ID #" . (int)$data['ID'], 404);
|
||||||
|
|
||||||
$record->delete();
|
$record->delete();
|
||||||
|
|
||||||
if($this->isAjax()) {
|
$this->response->addHeader('X-Status', _t('LeftAndMain.SAVEDUP'));
|
||||||
return $this->EmptyForm()->forTemplate();
|
return $this->getResponseNegotiator()->respond(
|
||||||
} else {
|
$request,
|
||||||
$this->redirectBack();
|
array('currentform' => array($this, 'EmptyForm'))
|
||||||
}
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -969,7 +990,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
* Return the CMS's HTML-editor toolbar
|
* Return the CMS's HTML-editor toolbar
|
||||||
*/
|
*/
|
||||||
public function EditorToolbar() {
|
public function EditorToolbar() {
|
||||||
return Object::create('HtmlEditorField_Toolbar', $this, "EditorToolbar");
|
return HtmlEditorField_Toolbar::create($this, "EditorToolbar");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1032,7 +1053,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
'BatchActionsForm',
|
'BatchActionsForm',
|
||||||
new FieldList(
|
new FieldList(
|
||||||
new HiddenField('csvIDs'),
|
new HiddenField('csvIDs'),
|
||||||
Object::create('DropdownField',
|
DropdownField::create(
|
||||||
'Action',
|
'Action',
|
||||||
false,
|
false,
|
||||||
$actionsMap
|
$actionsMap
|
||||||
@ -1256,7 +1277,7 @@ class LeftAndMain extends Controller implements PermissionProvider {
|
|||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
function Locale() {
|
function Locale() {
|
||||||
return DBField::create('DBLocale', i18n::get_locale());
|
return DBField::create_field('DBLocale', i18n::get_locale());
|
||||||
}
|
}
|
||||||
|
|
||||||
function providePermissions() {
|
function providePermissions() {
|
||||||
|
@ -113,11 +113,11 @@ abstract class ModelAdmin extends LeftAndMain {
|
|||||||
Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/ModelAdmin.js');
|
Requirements::javascript(SAPPHIRE_ADMIN_DIR . '/javascript/ModelAdmin.js');
|
||||||
}
|
}
|
||||||
|
|
||||||
function getEditForm($id = null) {
|
function getEditForm($id = null, $fields = null) {
|
||||||
$list = $this->getList();
|
$list = $this->getList();
|
||||||
$exportButton = new GridFieldExportButton('before');
|
$exportButton = new GridFieldExportButton('before');
|
||||||
$exportButton->setExportColumns($this->getExportFields());
|
$exportButton->setExportColumns($this->getExportFields());
|
||||||
$listField = Object::create('GridField',
|
$listField = GridField::create(
|
||||||
$this->modelClass,
|
$this->modelClass,
|
||||||
false,
|
false,
|
||||||
$list,
|
$list,
|
||||||
@ -181,9 +181,9 @@ abstract class ModelAdmin extends LeftAndMain {
|
|||||||
$form = new Form($this, "SearchForm",
|
$form = new Form($this, "SearchForm",
|
||||||
$context->getSearchFields(),
|
$context->getSearchFields(),
|
||||||
new FieldList(
|
new FieldList(
|
||||||
Object::create('ResetFormAction','clearsearch', _t('ModelAdmin.CLEAR_SEARCH','Clear Search'))
|
ResetFormAction::create('clearsearch', _t('ModelAdmin.CLEAR_SEARCH','Clear Search'))
|
||||||
->setUseButtonTag(true)->addExtraClass('ss-ui-action-minor'),
|
->setUseButtonTag(true)->addExtraClass('ss-ui-action-minor'),
|
||||||
Object::create('FormAction', 'search', _t('MemberTableField.SEARCH', 'Search'))
|
FormAction::create('search', _t('MemberTableField.SEARCH', 'Search'))
|
||||||
->setUseButtonTag(true)
|
->setUseButtonTag(true)
|
||||||
),
|
),
|
||||||
new RequiredFields()
|
new RequiredFields()
|
||||||
|
@ -43,7 +43,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
|
|||||||
$record = $this->getRecord($id);
|
$record = $this->getRecord($id);
|
||||||
if($record && !$record->canView()) return Security::permissionFailure($this);
|
if($record && !$record->canView()) return Security::permissionFailure($this);
|
||||||
|
|
||||||
$memberList = Object::create('GridField',
|
$memberList = GridField::create(
|
||||||
'Members',
|
'Members',
|
||||||
false,
|
false,
|
||||||
DataList::create('Member'),
|
DataList::create('Member'),
|
||||||
@ -52,8 +52,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
|
|||||||
)->addExtraClass("members_grid");
|
)->addExtraClass("members_grid");
|
||||||
$memberListConfig->getComponentByType('GridFieldDetailForm')->setValidator(new Member_Validator());
|
$memberListConfig->getComponentByType('GridFieldDetailForm')->setValidator(new Member_Validator());
|
||||||
|
|
||||||
$groupList = Object::create('GridField',
|
$groupList = GridField::create( 'Groups',
|
||||||
'Groups',
|
|
||||||
false,
|
false,
|
||||||
DataList::create('Group'),
|
DataList::create('Group'),
|
||||||
GridFieldConfig_RecordEditor::create()
|
GridFieldConfig_RecordEditor::create()
|
||||||
@ -104,8 +103,7 @@ class SecurityAdmin extends LeftAndMain implements PermissionProvider {
|
|||||||
|
|
||||||
// Add roles editing interface
|
// Add roles editing interface
|
||||||
if(Permission::check('APPLY_ROLES')) {
|
if(Permission::check('APPLY_ROLES')) {
|
||||||
$rolesField = Object::create('GridField',
|
$rolesField = GridField::create( 'Roles',
|
||||||
'Roles',
|
|
||||||
false,
|
false,
|
||||||
DataList::create('PermissionRole'),
|
DataList::create('PermissionRole'),
|
||||||
GridFieldConfig_RecordEditor::create()
|
GridFieldConfig_RecordEditor::create()
|
||||||
|
@ -35,7 +35,7 @@ If more variables exist in the future, consider creating a variables file.*/
|
|||||||
/** ---------------------------------------------------- Double tone borders http://daverupert.com/2011/06/two-tone-borders-with-css3/ ----------------------------------------------------- */
|
/** ---------------------------------------------------- Double tone borders http://daverupert.com/2011/06/two-tone-borders-with-css3/ ----------------------------------------------------- */
|
||||||
/** ----------------------------- Sprite images ----------------------------- */
|
/** ----------------------------- Sprite images ----------------------------- */
|
||||||
/** Helper SCSS file for generating sprites for the interface. */
|
/** Helper SCSS file for generating sprites for the interface. */
|
||||||
.btn-icon-sprite, .ui-state-default .btn-icon-accept, .ui-state-default .btn-icon-accept_disabled, .ui-state-default .btn-icon-add, .ui-state-default .btn-icon-add_disabled, .ui-state-default .btn-icon-addpage, .ui-state-default .btn-icon-addpage_disabled, .ui-state-default .btn-icon-arrow-circle-135-left, .ui-state-default .btn-icon-back, .ui-state-default .btn-icon-back_disabled, .ui-state-default .btn-icon-chain--arrow, .ui-state-default .btn-icon-chain--exclamation, .ui-state-default .btn-icon-chain--minus, .ui-state-default .btn-icon-chain--pencil, .ui-state-default .btn-icon-chain--plus, .ui-state-default .btn-icon-chain-small, .ui-state-default .btn-icon-chain-unchain, .ui-state-default .btn-icon-chain, .ui-state-default .btn-icon-cross-circle, .ui-state-default .btn-icon-cross-circle_disabled, .ui-state-default .btn-icon-decline, .ui-state-default .btn-icon-decline_disabled, .ui-state-default .btn-icon-download-csv, .ui-state-default .btn-icon-drive-upload, .ui-state-default .btn-icon-drive-upload_disabled, .ui-state-default .btn-icon-grid_print, .ui-state-default .btn-icon-magnifier, .ui-state-default .btn-icon-minus-circle, .ui-state-default .btn-icon-minus-circle_disabled, .ui-state-default .btn-icon-navigation, .ui-state-default .btn-icon-navigation_disabled, .ui-state-default .btn-icon-network-cloud, .ui-state-default .btn-icon-network-cloud_disabled, .ui-state-default .btn-icon-pencil, .ui-state-default .btn-icon-pencil_disabled, .ui-state-default .btn-icon-plug-disconnect-prohibition, .ui-state-default .btn-icon-plug-disconnect-prohibition_disabled, .ui-state-default .btn-icon-preview, .ui-state-default .btn-icon-preview_disabled, .ui-state-default .btn-icon-settings, .ui-state-default .btn-icon-settings_disabled, .ui-state-default .btn-icon-unpublish, .ui-state-default .btn-icon-unpublish_disabled { background: url('../images/btn-icon-sfafdfa106f.png') no-repeat; }
|
.btn-icon-sprite, .ui-state-default .btn-icon-accept, .ui-state-default .btn-icon-accept_disabled, .ui-state-default .btn-icon-add, .ui-state-default .btn-icon-add_disabled, .ui-state-default .btn-icon-addpage, .ui-state-default .btn-icon-addpage_disabled, .ui-state-default .btn-icon-arrow-circle-135-left, .ui-state-default .btn-icon-back, .ui-state-default .btn-icon-back_disabled, .ui-state-default .btn-icon-chain--arrow, .ui-state-default .btn-icon-chain--exclamation, .ui-state-default .btn-icon-chain--minus, .ui-state-default .btn-icon-chain--pencil, .ui-state-default .btn-icon-chain--plus, .ui-state-default .btn-icon-chain-small, .ui-state-default .btn-icon-chain-unchain, .ui-state-default .btn-icon-chain, .ui-state-default .btn-icon-cross-circle, .ui-state-default .btn-icon-cross-circle_disabled, .ui-state-default .btn-icon-decline, .ui-state-default .btn-icon-decline_disabled, .ui-state-default .btn-icon-download-csv, .ui-state-default .btn-icon-drive-upload, .ui-state-default .btn-icon-drive-upload_disabled, .ui-state-default .btn-icon-magnifier, .ui-state-default .btn-icon-minus-circle, .ui-state-default .btn-icon-minus-circle_disabled, .ui-state-default .btn-icon-navigation, .ui-state-default .btn-icon-navigation_disabled, .ui-state-default .btn-icon-network-cloud, .ui-state-default .btn-icon-network-cloud_disabled, .ui-state-default .btn-icon-pencil, .ui-state-default .btn-icon-pencil_disabled, .ui-state-default .btn-icon-plug-disconnect-prohibition, .ui-state-default .btn-icon-plug-disconnect-prohibition_disabled, .ui-state-default .btn-icon-preview, .ui-state-default .btn-icon-preview_disabled, .ui-state-default .btn-icon-settings, .ui-state-default .btn-icon-settings_disabled, .ui-state-default .btn-icon-unpublish, .ui-state-default .btn-icon-unpublish_disabled { background: url('../images/btn-icon-s41050dc384.png') no-repeat; }
|
||||||
|
|
||||||
.ui-state-default .btn-icon-accept { background-position: 0 0; }
|
.ui-state-default .btn-icon-accept { background-position: 0 0; }
|
||||||
.ui-state-default .btn-icon-accept_disabled { background-position: 0 -17px; }
|
.ui-state-default .btn-icon-accept_disabled { background-position: 0 -17px; }
|
||||||
@ -61,24 +61,23 @@ If more variables exist in the future, consider creating a variables file.*/
|
|||||||
.ui-state-default .btn-icon-download-csv { background-position: 0 -343px; }
|
.ui-state-default .btn-icon-download-csv { background-position: 0 -343px; }
|
||||||
.ui-state-default .btn-icon-drive-upload { background-position: 0 -361px; }
|
.ui-state-default .btn-icon-drive-upload { background-position: 0 -361px; }
|
||||||
.ui-state-default .btn-icon-drive-upload_disabled { background-position: 0 -377px; }
|
.ui-state-default .btn-icon-drive-upload_disabled { background-position: 0 -377px; }
|
||||||
.ui-state-default .btn-icon-grid_print { background-position: 0 -393px; }
|
.ui-state-default .btn-icon-magnifier { background-position: 0 -393px; }
|
||||||
.ui-state-default .btn-icon-magnifier { background-position: 0 -409px; }
|
.ui-state-default .btn-icon-minus-circle { background-position: 0 -409px; }
|
||||||
.ui-state-default .btn-icon-minus-circle { background-position: 0 -425px; }
|
.ui-state-default .btn-icon-minus-circle_disabled { background-position: 0 -425px; }
|
||||||
.ui-state-default .btn-icon-minus-circle_disabled { background-position: 0 -441px; }
|
.ui-state-default .btn-icon-navigation { background-position: 0 -441px; }
|
||||||
.ui-state-default .btn-icon-navigation { background-position: 0 -457px; }
|
.ui-state-default .btn-icon-navigation_disabled { background-position: 0 -457px; }
|
||||||
.ui-state-default .btn-icon-navigation_disabled { background-position: 0 -473px; }
|
.ui-state-default .btn-icon-network-cloud { background-position: 0 -473px; }
|
||||||
.ui-state-default .btn-icon-network-cloud { background-position: 0 -489px; }
|
.ui-state-default .btn-icon-network-cloud_disabled { background-position: 0 -489px; }
|
||||||
.ui-state-default .btn-icon-network-cloud_disabled { background-position: 0 -505px; }
|
.ui-state-default .btn-icon-pencil { background-position: 0 -505px; }
|
||||||
.ui-state-default .btn-icon-pencil { background-position: 0 -521px; }
|
.ui-state-default .btn-icon-pencil_disabled { background-position: 0 -521px; }
|
||||||
.ui-state-default .btn-icon-pencil_disabled { background-position: 0 -537px; }
|
.ui-state-default .btn-icon-plug-disconnect-prohibition { background-position: 0 -537px; }
|
||||||
.ui-state-default .btn-icon-plug-disconnect-prohibition { background-position: 0 -553px; }
|
.ui-state-default .btn-icon-plug-disconnect-prohibition_disabled { background-position: 0 -553px; }
|
||||||
.ui-state-default .btn-icon-plug-disconnect-prohibition_disabled { background-position: 0 -569px; }
|
.ui-state-default .btn-icon-preview { background-position: 0 -569px; }
|
||||||
.ui-state-default .btn-icon-preview { background-position: 0 -585px; }
|
.ui-state-default .btn-icon-preview_disabled { background-position: 0 -586px; }
|
||||||
.ui-state-default .btn-icon-preview_disabled { background-position: 0 -602px; }
|
.ui-state-default .btn-icon-settings { background-position: 0 -603px; }
|
||||||
.ui-state-default .btn-icon-settings { background-position: 0 -619px; }
|
.ui-state-default .btn-icon-settings_disabled { background-position: 0 -619px; }
|
||||||
.ui-state-default .btn-icon-settings_disabled { background-position: 0 -635px; }
|
.ui-state-default .btn-icon-unpublish { background-position: 0 -635px; }
|
||||||
.ui-state-default .btn-icon-unpublish { background-position: 0 -651px; }
|
.ui-state-default .btn-icon-unpublish_disabled { background-position: 0 -653px; }
|
||||||
.ui-state-default .btn-icon-unpublish_disabled { background-position: 0 -669px; }
|
|
||||||
|
|
||||||
.icon { text-indent: -9999px; border: none; outline: none; }
|
.icon { text-indent: -9999px; border: none; outline: none; }
|
||||||
.icon.icon-24 { width: 24px; height: 24px; background: url('../images/menu-icons/24x24-s546fcae8fd.png'); }
|
.icon.icon-24 { width: 24px; height: 24px; background: url('../images/menu-icons/24x24-s546fcae8fd.png'); }
|
||||||
@ -563,14 +562,18 @@ form.import-form label.left { width: 250px; }
|
|||||||
.cms .jstree-rtl > ul > li, .TreeDropdownField .treedropdownfield-panel .jstree-rtl > ul > li { margin-right: 0px; }
|
.cms .jstree-rtl > ul > li, .TreeDropdownField .treedropdownfield-panel .jstree-rtl > ul > li { margin-right: 0px; }
|
||||||
.cms .jstree > ul > li, .TreeDropdownField .treedropdownfield-panel .jstree > ul > li { margin-left: 0px; }
|
.cms .jstree > ul > li, .TreeDropdownField .treedropdownfield-panel .jstree > ul > li { margin-left: 0px; }
|
||||||
.cms #vakata-dragged, .TreeDropdownField .treedropdownfield-panel #vakata-dragged { display: block; margin: 0 0 0 0; padding: 4px 4px 4px 24px; position: absolute; top: -2000px; line-height: 16px; z-index: 10000; }
|
.cms #vakata-dragged, .TreeDropdownField .treedropdownfield-panel #vakata-dragged { display: block; margin: 0 0 0 0; padding: 4px 4px 4px 24px; position: absolute; top: -2000px; line-height: 16px; z-index: 10000; }
|
||||||
.cms #vakata-contextmenu, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu { display: block; visibility: hidden; left: 0; top: -200px; position: absolute; margin: 0; padding: 0; min-width: 180px; background: #ebebeb; border: 1px solid silver; z-index: 10000; *width: 180px; }
|
.cms #vakata-contextmenu, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu { display: block; visibility: hidden; left: 0; top: -200px; position: absolute; margin: 0; padding: 0; min-width: 180px; background: #FFF; border: 1px solid silver; z-index: 10000; *width: 180px; -moz-box-shadow: 0 0 10px #cccccc; -webkit-box-shadow: 0 0 10px #cccccc; -o-box-shadow: 0 0 10px #cccccc; box-shadow: 0 0 10px #cccccc; }
|
||||||
|
.cms #vakata-contextmenu::before, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu::before { content: ""; display: block; /* reduce the damage in FF3.0 */ position: absolute; top: -10px; left: 24px; width: 0; border-width: 0 6px 10px 6px; border-color: #FFF transparent; border-style: solid; z-index: 10000; }
|
||||||
|
.cms #vakata-contextmenu::after, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu::after { content: ""; display: block; /* reduce the damage in FF3.0 */ position: absolute; top: -11px; left: 23px; width: 0; border-width: 0 7px 11px 7px; border-color: #CCC transparent; border-style: solid; }
|
||||||
.cms #vakata-contextmenu ul, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu ul { min-width: 180px; *width: 180px; }
|
.cms #vakata-contextmenu ul, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu ul { min-width: 180px; *width: 180px; }
|
||||||
.cms #vakata-contextmenu ul, .cms #vakata-contextmenu li, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu ul, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li { margin: 0; padding: 0; list-style-type: none; display: block; }
|
.cms #vakata-contextmenu ul, .cms #vakata-contextmenu li, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu ul, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li { margin: 0; padding: 0; list-style-type: none; display: block; }
|
||||||
.cms #vakata-contextmenu li, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li { line-height: 20px; min-height: 20px; position: relative; padding: 0px; }
|
.cms #vakata-contextmenu li, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li { line-height: 20px; min-height: 23px; position: relative; padding: 0px; }
|
||||||
.cms #vakata-contextmenu li a, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li a { padding: 1px 6px; line-height: 17px; display: block; text-decoration: none; margin: 1px 1px 0 1px; }
|
.cms #vakata-contextmenu li:last-child, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li:last-child { margin-bottom: 1px; }
|
||||||
.cms #vakata-contextmenu li ins, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li ins { float: left; width: 16px; height: 16px; text-decoration: none; margin-right: 2px; }
|
.cms #vakata-contextmenu li a, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li a { padding: 1px 10px; line-height: 23px; display: block; text-decoration: none; margin: 1px 1px 0 1px; border: 0; }
|
||||||
.cms #vakata-contextmenu li a:hover, .cms #vakata-contextmenu li.vakata-hover > a, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li a:hover, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li.vakata-hover > a { background: gray; color: white; }
|
.cms #vakata-contextmenu li ins, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li ins { float: left; width: 0; height: 0; text-decoration: none; margin-right: 2px; }
|
||||||
.cms #vakata-contextmenu li ul, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li ul { display: none; position: absolute; top: -2px; left: 100%; background: #ebebeb; border: 1px solid gray; }
|
.cms #vakata-contextmenu li .jstree-pageicon, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li .jstree-pageicon { margin-top: 3px; margin-right: 5px; }
|
||||||
|
.cms #vakata-contextmenu li a:hover, .cms #vakata-contextmenu li.vakata-hover > a, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li a:hover, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li.vakata-hover > a { padding: 1px 10px; background: #3875d7; background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4gPHN2ZyB2ZXJzaW9uPSIxLjEiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGRlZnM+PGxpbmVhckdyYWRpZW50IGlkPSJncmFkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjUwJSIgeTE9IjAlIiB4Mj0iNTAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIyMCUiIHN0b3AtY29sb3I9IiMzODc1ZDciLz48c3RvcCBvZmZzZXQ9IjkwJSIgc3RvcC1jb2xvcj0iIzJhNjJiYyIvPjwvbGluZWFyR3JhZGllbnQ+PC9kZWZzPjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIGZpbGw9InVybCgjZ3JhZCkiIC8+PC9zdmc+IA=='); background-size: 100%; background-image: -webkit-gradient(linear, 50% 0%, 50% 100%, color-stop(20%, #3875d7), color-stop(90%, #2a62bc)); background-image: -webkit-linear-gradient(top, #3875d7 20%, #2a62bc 90%); background-image: -moz-linear-gradient(top, #3875d7 20%, #2a62bc 90%); background-image: -o-linear-gradient(top, #3875d7 20%, #2a62bc 90%); background-image: -ms-linear-gradient(top, #3875d7 20%, #2a62bc 90%); background-image: linear-gradient(top, #3875d7 20%, #2a62bc 90%); color: #FFF; border: none; }
|
||||||
|
.cms #vakata-contextmenu li ul, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li ul { display: none; position: absolute; top: -2px; left: 100%; background: #FFF; border: 1px solid silver; -moz-box-shadow: 0 0 10px #cccccc; -webkit-box-shadow: 0 0 10px #cccccc; -o-box-shadow: 0 0 10px #cccccc; box-shadow: 0 0 10px #cccccc; }
|
||||||
.cms #vakata-contextmenu .right, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu .right { right: 100%; left: auto; }
|
.cms #vakata-contextmenu .right, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu .right { right: 100%; left: auto; }
|
||||||
.cms #vakata-contextmenu .bottom, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu .bottom { bottom: -1px; top: auto; }
|
.cms #vakata-contextmenu .bottom, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu .bottom { bottom: -1px; top: auto; }
|
||||||
.cms #vakata-contextmenu li.vakata-separator, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li.vakata-separator { min-height: 0; height: 1px; line-height: 1px; font-size: 1px; overflow: hidden; margin: 0 2px; background: silver; /* border-top:1px solid #fefefe; */ padding: 0; }
|
.cms #vakata-contextmenu li.vakata-separator, .TreeDropdownField .treedropdownfield-panel #vakata-contextmenu li.vakata-separator { min-height: 0; height: 1px; line-height: 1px; font-size: 1px; overflow: hidden; margin: 0 2px; background: silver; /* border-top:1px solid #fefefe; */ padding: 0; }
|
||||||
@ -635,8 +638,8 @@ form.import-form label.left { width: 250px; }
|
|||||||
.tree-holder.jstree-apple li, .cms-tree.jstree-apple li { padding: 0px; clear: left; }
|
.tree-holder.jstree-apple li, .cms-tree.jstree-apple li { padding: 0px; clear: left; }
|
||||||
.tree-holder.jstree-apple ins, .cms-tree.jstree-apple ins { background-color: transparent; background-image: url(../images/sitetree_ss_default_icons.png); }
|
.tree-holder.jstree-apple ins, .cms-tree.jstree-apple ins { background-color: transparent; background-image: url(../images/sitetree_ss_default_icons.png); }
|
||||||
.tree-holder.jstree-apple li.jstree-checked > a, .tree-holder.jstree-apple li.jstree-checked > a:link, .cms-tree.jstree-apple li.jstree-checked > a, .cms-tree.jstree-apple li.jstree-checked > a:link { background-color: #efe999; }
|
.tree-holder.jstree-apple li.jstree-checked > a, .tree-holder.jstree-apple li.jstree-checked > a:link, .cms-tree.jstree-apple li.jstree-checked > a, .cms-tree.jstree-apple li.jstree-checked > a:link { background-color: #efe999; }
|
||||||
.tree-holder.jstree-apple .jstree-closed > ins, .cms-tree.jstree-apple .jstree-closed > ins { background-position: 0 0; cursor: pointer; }
|
.tree-holder.jstree-apple .jstree-closed > ins, .cms-tree.jstree-apple .jstree-closed > ins { background-position: 0 0; }
|
||||||
.tree-holder.jstree-apple .jstree-open > ins, .cms-tree.jstree-apple .jstree-open > ins { background-position: -20px 0; cursor: pointer; }
|
.tree-holder.jstree-apple .jstree-open > ins, .cms-tree.jstree-apple .jstree-open > ins { background-position: -20px 0; }
|
||||||
|
|
||||||
a .jstree-pageicon { display: block; float: left; width: 16px; height: 16px; margin-right: 4px; background-color: transparent; background-image: url(../images/sitetree_ss_pageclass_icons_default.png); background-repeat: no-repeat; }
|
a .jstree-pageicon { display: block; float: left; width: 16px; height: 16px; margin-right: 4px; background-color: transparent; background-image: url(../images/sitetree_ss_pageclass_icons_default.png); background-repeat: no-repeat; }
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
* ss.i18n
|
* ss.i18n
|
||||||
* .cms-edit-form
|
* .cms-edit-form
|
||||||
*/
|
*/
|
||||||
$('.add-form').entwine({
|
$('.cms-edit-form.cms-add-form').entwine({
|
||||||
/**
|
/**
|
||||||
* Variable: Tree
|
* Variable: Tree
|
||||||
* (DOMElement)
|
* (DOMElement)
|
||||||
@ -87,7 +87,7 @@
|
|||||||
var data = this.serializeArray();
|
var data = this.serializeArray();
|
||||||
data.push({name:'Suffix',value:newPages[parentID]++});
|
data.push({name:'Suffix',value:newPages[parentID]++});
|
||||||
data.push({name:button.attr('name'),value:button.val()});
|
data.push({name:button.attr('name'),value:button.val()});
|
||||||
|
|
||||||
// TODO Should be set by hiddenfield already
|
// TODO Should be set by hiddenfield already
|
||||||
jQuery('.cms-content').entwine('ss').loadForm(
|
jQuery('.cms-content').entwine('ss').loadForm(
|
||||||
this.attr('action'),
|
this.attr('action'),
|
||||||
@ -96,7 +96,12 @@
|
|||||||
// Tree updates are triggered by Form_EditForm load events
|
// Tree updates are triggered by Form_EditForm load events
|
||||||
button.removeClass('loading');
|
button.removeClass('loading');
|
||||||
},
|
},
|
||||||
{type: 'POST', data: data}
|
{
|
||||||
|
type: 'POST',
|
||||||
|
data: data,
|
||||||
|
// Refresh the whole area to avoid reloading just the form, without the tree around it
|
||||||
|
headers: {'X-Pjax': 'Content'}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
this.setNewPages(newPages);
|
this.setNewPages(newPages);
|
||||||
|
@ -55,16 +55,18 @@
|
|||||||
|
|
||||||
this.trigger('loadform', {form: form, url: url});
|
this.trigger('loadform', {form: form, url: url});
|
||||||
|
|
||||||
return jQuery.ajax(jQuery.extend({
|
var opts = jQuery.extend({}, {
|
||||||
url: url,
|
|
||||||
// Ensure that form view is loaded (rather than whole "Content" template)
|
// Ensure that form view is loaded (rather than whole "Content" template)
|
||||||
data: {'cms-view-form': 1},
|
headers: {"X-Pjax" : "CurrentForm"},
|
||||||
|
url: url,
|
||||||
complete: function(xmlhttp, status) {
|
complete: function(xmlhttp, status) {
|
||||||
self.loadForm_responseHandler(form, xmlhttp.responseText, status, xmlhttp);
|
self.loadForm_responseHandler(form, xmlhttp.responseText, status, xmlhttp);
|
||||||
if(callback) callback.apply(self, arguments);
|
if(callback) callback.apply(self, arguments);
|
||||||
},
|
},
|
||||||
dataType: 'html'
|
dataType: 'html'
|
||||||
}, ajaxOptions));
|
}, ajaxOptions);
|
||||||
|
|
||||||
|
return jQuery.ajax(opts);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -81,11 +83,11 @@
|
|||||||
* (XMLHTTPRequest) xmlhttp
|
* (XMLHTTPRequest) xmlhttp
|
||||||
*/
|
*/
|
||||||
loadForm_responseHandler: function(oldForm, html, status, xmlhttp) {
|
loadForm_responseHandler: function(oldForm, html, status, xmlhttp) {
|
||||||
|
if(!html) return;
|
||||||
|
|
||||||
if(oldForm.length > 0) {
|
if(oldForm.length > 0) {
|
||||||
oldForm.replaceWith(html); // triggers onmatch() on form
|
oldForm.replaceWith(html); // triggers onmatch() on form
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$('.cms-content').append(html);
|
$('.cms-content').append(html);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,7 +144,13 @@
|
|||||||
var formData = form.serializeArray();
|
var formData = form.serializeArray();
|
||||||
// add button action
|
// add button action
|
||||||
formData.push({name: $(button).attr('name'), value:'1'});
|
formData.push({name: $(button).attr('name'), value:'1'});
|
||||||
|
// Artificial HTTP referer, IE doesn't submit them via ajax.
|
||||||
|
// Also rewrites anchors to their page counterparts, which is important
|
||||||
|
// as automatic browser ajax response redirects seem to discard the hash/fragment.
|
||||||
|
formData.push({name: 'BackURL', value:History.getPageUrl()});
|
||||||
|
|
||||||
jQuery.ajax(jQuery.extend({
|
jQuery.ajax(jQuery.extend({
|
||||||
|
headers: {"X-Pjax" : "CurrentForm"},
|
||||||
url: form.attr('action'),
|
url: form.attr('action'),
|
||||||
data: formData,
|
data: formData,
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
@ -159,12 +167,6 @@
|
|||||||
self.submitForm_responseHandler(form, xmlhttp.responseText, status, xmlhttp, formData);
|
self.submitForm_responseHandler(form, xmlhttp.responseText, status, xmlhttp, formData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simulates a redirect on an ajax response - just exchange the URL without re-requesting it
|
|
||||||
if(window.History.enabled) {
|
|
||||||
var url = xmlhttp.getResponseHeader('X-ControllerURL');
|
|
||||||
if(url) window.history.replaceState({}, '', url);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Re-init tabs (in case the form tag itself is a tabset)
|
// Re-init tabs (in case the form tag itself is a tabset)
|
||||||
if(self.hasClass('ss-tabset')) self.removeClass('ss-tabset').addClass('ss-tabset');
|
if(self.hasClass('ss-tabset')) self.removeClass('ss-tabset').addClass('ss-tabset');
|
||||||
|
|
||||||
@ -197,6 +199,8 @@
|
|||||||
*/
|
*/
|
||||||
submitForm_responseHandler: function(oldForm, data, status, xmlhttp, origData) {
|
submitForm_responseHandler: function(oldForm, data, status, xmlhttp, origData) {
|
||||||
if(status == 'success') {
|
if(status == 'success') {
|
||||||
|
if(!data) return;
|
||||||
|
|
||||||
var form, newContent = $(data);
|
var form, newContent = $(data);
|
||||||
|
|
||||||
// HACK If response contains toplevel panel rather than a form, replace it instead.
|
// HACK If response contains toplevel panel rather than a form, replace it instead.
|
||||||
@ -287,10 +291,9 @@
|
|||||||
var url = $(node).find('a:first').attr('href');
|
var url = $(node).find('a:first').attr('href');
|
||||||
if(url && url != '#') {
|
if(url && url != '#') {
|
||||||
|
|
||||||
if($(node).find('a:first').is(':internal')) url = url = $.path.makeUrlAbsolute(url, $('base').attr('href'));
|
if($.path.isExternal($(node).find('a:first'))) url = url = $.path.makeUrlAbsolute(url, $('base').attr('href'));
|
||||||
// Reload only edit form if it exists (side-by-side view of tree and edit view), otherwise reload whole panel
|
// Reload only edit form if it exists (side-by-side view of tree and edit view), otherwise reload whole panel
|
||||||
if(container.find('.cms-edit-form').length) {
|
if(container.find('.cms-edit-form').length) {
|
||||||
url += '?cms-view-form=1';
|
|
||||||
container.entwine('ss').loadPanel(url, null, {selector: '.cms-edit-form'});
|
container.entwine('ss').loadPanel(url, null, {selector: '.cms-edit-form'});
|
||||||
} else {
|
} else {
|
||||||
container.entwine('ss').loadPanel(url);
|
container.entwine('ss').loadPanel(url);
|
||||||
@ -311,4 +314,4 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
})(jQuery);
|
})(jQuery);
|
||||||
|
@ -141,8 +141,8 @@
|
|||||||
*
|
*
|
||||||
* Suppress submission unless it is handled through ajaxSubmit().
|
* Suppress submission unless it is handled through ajaxSubmit().
|
||||||
*/
|
*/
|
||||||
onsubmit: function(e) {
|
onsubmit: function(e, button) {
|
||||||
this.parents('.cms-content').submitForm(this);
|
this.parents('.cms-content').submitForm(this, button);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
@ -179,7 +179,7 @@
|
|||||||
* Function: onclick
|
* Function: onclick
|
||||||
*/
|
*/
|
||||||
onclick: function(e) {
|
onclick: function(e) {
|
||||||
$('.cms-content').submitForm(this.parents('form'), this);
|
this.parents('form').trigger('submit', [this]);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -207,16 +207,16 @@
|
|||||||
onclick: function(e) {
|
onclick: function(e) {
|
||||||
// Only catch left clicks, in order to allow opening in tabs.
|
// Only catch left clicks, in order to allow opening in tabs.
|
||||||
// Ignore external links, fallback to standard link behaviour
|
// Ignore external links, fallback to standard link behaviour
|
||||||
if(e.which > 1 || this.is(':external')) return;
|
var isExternal = $.path.isExternal(this.attr('href'));
|
||||||
|
if(e.which > 1 || isExternal) return;
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var item = this.getMenuItem();
|
var item = this.getMenuItem();
|
||||||
|
|
||||||
var url = this.attr('href');
|
var url = this.attr('href');
|
||||||
if(this.is(':internal')) url = $('base').attr('href') + url;
|
if(!isExternal) url = $('base').attr('href') + url;
|
||||||
|
|
||||||
var children = item.find('li');
|
var children = item.find('li');
|
||||||
|
|
||||||
if(children.length) {
|
if(children.length) {
|
||||||
children.first().find('a').click();
|
children.first().find('a').click();
|
||||||
} else {
|
} else {
|
||||||
@ -261,8 +261,4 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Internal Helper
|
|
||||||
$.expr[':'].internal = function(obj){return obj.href.match(/^mailto\:/) || (obj.hostname == location.hostname);};
|
|
||||||
$.expr[':'].external = function(obj){return !$(obj).is(':internal');};
|
|
||||||
}(jQuery));
|
}(jQuery));
|
@ -32,17 +32,30 @@ jQuery.noConflict();
|
|||||||
|
|
||||||
$(window).bind('resize', positionLoadingSpinner).trigger('resize');
|
$(window).bind('resize', positionLoadingSpinner).trigger('resize');
|
||||||
|
|
||||||
// global ajax error handlers
|
// global ajax handlers
|
||||||
$.ajaxSetup({
|
$(document).ajaxComplete(function(e, xhr, settings) {
|
||||||
error: function(xmlhttp, status, error) {
|
// Simulates a redirect on an ajax response.
|
||||||
if(xmlhttp.status < 200 || xmlhttp.status > 399) {
|
if(window.History.enabled) {
|
||||||
var msg = (xmlhttp.getResponseHeader('X-Status')) ? xmlhttp.getResponseHeader('X-Status') : xmlhttp.statusText;
|
var url = xhr.getResponseHeader('X-ControllerURL');
|
||||||
} else {
|
// Normalize trailing slashes in URL to work around routing weirdnesses in SS_HTTPRequest.
|
||||||
msg = error;
|
var isSame = (url && History.getPageUrl().replace(/\/+$/, '') == url.replace(/\/+$/, ''));
|
||||||
|
if(url && !isSame) {
|
||||||
|
var opts = {
|
||||||
|
pjax: settings.headers ? settings.headers['X-Pjax'] : null,
|
||||||
|
selector: settings.headers ? settings.headers['X-Pjax-Selector'] : null
|
||||||
|
};
|
||||||
|
window.History.pushState(opts, '', url);
|
||||||
}
|
}
|
||||||
statusMessage(msg, 'bad');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
$(document).ajaxError(function(e, xhr, settings, error) {
|
||||||
|
if(xhr.status < 200 || xhr.status > 399) {
|
||||||
|
var msg = (xhr.getResponseHeader('X-Status')) ? xhr.getResponseHeader('X-Status') : xhr.statusText;
|
||||||
|
} else {
|
||||||
|
msg = error;
|
||||||
|
}
|
||||||
|
statusMessage(msg, 'bad');
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main LeftAndMain interface with some control panel and an edit form.
|
* Main LeftAndMain interface with some control panel and an edit form.
|
||||||
@ -87,12 +100,6 @@ jQuery.noConflict();
|
|||||||
});
|
});
|
||||||
|
|
||||||
$('.cms-edit-form').live('reloadeditform', function(e, data) {
|
$('.cms-edit-form').live('reloadeditform', function(e, data) {
|
||||||
// Simulates a redirect on an ajax response - just exchange the URL without re-requesting it
|
|
||||||
if(window.History.enabled) {
|
|
||||||
var url = data.xmlhttp.getResponseHeader('X-ControllerURL');
|
|
||||||
if(url) window.history.replaceState({}, '', url);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.redraw();
|
self.redraw();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -141,8 +148,8 @@ jQuery.noConflict();
|
|||||||
loadPanel: function(url, title, data) {
|
loadPanel: function(url, title, data) {
|
||||||
if(!data) data = {};
|
if(!data) data = {};
|
||||||
if(!title) title = "";
|
if(!title) title = "";
|
||||||
|
if(!data.selector) data.selector = '.cms-content';
|
||||||
var selector = data.selector || '.cms-content', contentEl = $(selector);
|
var contentEl = $(data.selector);
|
||||||
|
|
||||||
// Check change tracking (can't use events as we need a way to cancel the current state change)
|
// Check change tracking (can't use events as we need a way to cancel the current state change)
|
||||||
var trackedEls = contentEl.find(':data(changetracker)').add(contentEl.filter(':data(changetracker)'));
|
var trackedEls = contentEl.find(':data(changetracker)').add(contentEl.filter(':data(changetracker)'));
|
||||||
@ -203,10 +210,27 @@ jQuery.noConflict();
|
|||||||
state: state, element: contentEl
|
state: state, element: contentEl
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var headers = {};
|
||||||
|
if(state.data.pjax) {
|
||||||
|
headers['X-Pjax'] = state.data.pjax;
|
||||||
|
} else if(contentEl[0] != null && contentEl.is('form')) {
|
||||||
|
// Replace a form
|
||||||
|
headers["X-Pjax"] = 'CurrentForm';
|
||||||
|
} else {
|
||||||
|
// Replace full RHS content area
|
||||||
|
headers["X-Pjax"] = 'Content';
|
||||||
|
}
|
||||||
|
headers['X-Pjax-Selector'] = selector;
|
||||||
|
|
||||||
contentEl.addClass('loading');
|
contentEl.addClass('loading');
|
||||||
var xhr = $.ajax({
|
var xhr = $.ajax({
|
||||||
|
headers: headers,
|
||||||
url: state.url,
|
url: state.url,
|
||||||
success: function(data, status, xhr) {
|
success: function(data, status, xhr) {
|
||||||
|
// Pseudo-redirects via X-ControllerURL might return empty data, in which
|
||||||
|
// case we'll ignore the response
|
||||||
|
if(!data) return;
|
||||||
|
|
||||||
// Update title
|
// Update title
|
||||||
var title = xhr.getResponseHeader('X-Title');
|
var title = xhr.getResponseHeader('X-Title');
|
||||||
if(title) document.title = title;
|
if(title) document.title = title;
|
||||||
@ -223,12 +247,13 @@ jQuery.noConflict();
|
|||||||
var layoutClasses = ['east', 'west', 'center', 'north', 'south'];
|
var layoutClasses = ['east', 'west', 'center', 'north', 'south'];
|
||||||
var elemClasses = contentEl.attr('class');
|
var elemClasses = contentEl.attr('class');
|
||||||
|
|
||||||
var origLayoutClasses = $.grep(
|
var origLayoutClasses = [];
|
||||||
elemClasses.split(' '),
|
if(elemClasses) {
|
||||||
function(val) {
|
origLayoutClasses = $.grep(
|
||||||
return ($.inArray(val, layoutClasses) >= 0);
|
elemClasses.split(' '),
|
||||||
}
|
function(val) { return ($.inArray(val, layoutClasses) >= 0);}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
newContentEl
|
newContentEl
|
||||||
.removeClass(layoutClasses.join(' '))
|
.removeClass(layoutClasses.join(' '))
|
||||||
@ -249,12 +274,6 @@ jQuery.noConflict();
|
|||||||
newContentEl.css('visibility', 'visible');
|
newContentEl.css('visibility', 'visible');
|
||||||
newContentEl.removeClass('loading');
|
newContentEl.removeClass('loading');
|
||||||
|
|
||||||
// Simulates a redirect on an ajax response - just exchange the URL without re-requesting it
|
|
||||||
if(window.History.enabled) {
|
|
||||||
var url = xhr.getResponseHeader('X-ControllerURL');
|
|
||||||
if(url) window.history.replaceState({}, '', url);
|
|
||||||
}
|
|
||||||
|
|
||||||
self.trigger('afterstatechange', {data: data, status: status, xhr: xhr, element: newContentEl});
|
self.trigger('afterstatechange', {data: data, status: status, xhr: xhr, element: newContentEl});
|
||||||
},
|
},
|
||||||
error: function(xhr, status, e) {
|
error: function(xhr, status, e) {
|
||||||
@ -555,4 +574,4 @@ var statusMessage = function(text, type) {
|
|||||||
|
|
||||||
var errorMessage = function(text) {
|
var errorMessage = function(text) {
|
||||||
jQuery.noticeAdd({text: text, type: 'error'});
|
jQuery.noticeAdd({text: text, type: 'error'});
|
||||||
};
|
};
|
||||||
|
@ -232,8 +232,4 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
$.path = path;
|
$.path = path;
|
||||||
|
|
||||||
// Internal Helper
|
|
||||||
$.expr[':'].internal = function(obj){return obj.href.match(/^mailto\:/) || (obj.hostname == location.hostname);};
|
|
||||||
$.expr[':'].external = function(obj){return !$(obj).is(':internal')};
|
|
||||||
}(jQuery));
|
}(jQuery));
|
@ -24,14 +24,8 @@
|
|||||||
min-height: 18px;
|
min-height: 18px;
|
||||||
line-height: 18px;
|
line-height: 18px;
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
|
margin-left: 18px;
|
||||||
min-width: 18px;
|
min-width: 18px;
|
||||||
|
|
||||||
li {
|
|
||||||
margin: 0;
|
|
||||||
}
|
|
||||||
li li {
|
|
||||||
margin-left: 10px;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ins {
|
ins {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
@ -125,50 +119,86 @@
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
min-width: 180px;
|
min-width: 180px;
|
||||||
background: #ebebeb;
|
background: #FFF;
|
||||||
border: 1px solid silver;
|
border: 1px solid silver;
|
||||||
z-index: 10000; *width:180px;
|
z-index: 10000; *width:180px;
|
||||||
|
@include box-shadow(0 0 10px #CCC);
|
||||||
|
&::before {
|
||||||
|
content:"";
|
||||||
|
display:block; /* reduce the damage in FF3.0 */
|
||||||
|
position:absolute;
|
||||||
|
top: -10px;
|
||||||
|
left: 24px;
|
||||||
|
width:0;
|
||||||
|
border-width: 0 6px 10px 6px ;
|
||||||
|
border-color: #FFF transparent;
|
||||||
|
border-style: solid;
|
||||||
|
z-index: 10000;
|
||||||
|
}
|
||||||
|
&::after {
|
||||||
|
content:"";
|
||||||
|
display:block; /* reduce the damage in FF3.0 */
|
||||||
|
position:absolute;
|
||||||
|
top: -11px;
|
||||||
|
left: 23px;
|
||||||
|
width:0;
|
||||||
|
border-width: 0 7px 11px 7px ;
|
||||||
|
border-color: #CCC transparent;
|
||||||
|
border-style: solid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#vakata-contextmenu ul {
|
#vakata-contextmenu ul {
|
||||||
min-width: 180px; *width:180px;
|
min-width: 180px; *width:180px;
|
||||||
}
|
}
|
||||||
#vakata-contextmenu ul, #vakata-contextmenu li {
|
#vakata-contextmenu ul, #vakata-contextmenu li {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0 ;
|
||||||
list-style-type: none;
|
list-style-type: none;
|
||||||
display: block;
|
display: block;
|
||||||
}
|
}
|
||||||
#vakata-contextmenu li {
|
#vakata-contextmenu li {
|
||||||
line-height: 20px;
|
line-height: 20px;
|
||||||
min-height: 20px;
|
min-height: 23px;
|
||||||
position: relative;
|
position: relative;
|
||||||
padding: 0px;
|
padding: 0px;
|
||||||
|
&:last-child {
|
||||||
|
margin-bottom: 1px;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#vakata-contextmenu li a {
|
#vakata-contextmenu li a {
|
||||||
padding: 1px 6px;
|
padding: 1px 10px;
|
||||||
line-height: 17px;
|
line-height: 23px;
|
||||||
display: block;
|
display: block;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
margin: 1px 1px 0 1px;
|
margin: 1px 1px 0 1px;
|
||||||
|
border: 0;
|
||||||
}
|
}
|
||||||
#vakata-contextmenu li ins {
|
#vakata-contextmenu li ins {
|
||||||
float: left;
|
float: left;
|
||||||
width: 16px;
|
width: 0;
|
||||||
height: 16px;
|
height: 0;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
margin-right: 2px;
|
margin-right: 2px;
|
||||||
}
|
}
|
||||||
|
#vakata-contextmenu li .jstree-pageicon {
|
||||||
|
margin-top: 3px;
|
||||||
|
margin-right: 5px;
|
||||||
|
}
|
||||||
#vakata-contextmenu li a:hover, #vakata-contextmenu li.vakata-hover > a {
|
#vakata-contextmenu li a:hover, #vakata-contextmenu li.vakata-hover > a {
|
||||||
background: gray;
|
padding: 1px 10px;
|
||||||
color: white;
|
background: #3875d7;
|
||||||
|
@include background-image(linear-gradient(top, #3875d7 20%, #2a62bc 90%));
|
||||||
|
color: #FFF;
|
||||||
|
border: none;
|
||||||
}
|
}
|
||||||
#vakata-contextmenu li ul {
|
#vakata-contextmenu li ul {
|
||||||
display: none;
|
display: none;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
top: -2px;
|
top: -2px;
|
||||||
left: 100%;
|
left: 100%;
|
||||||
background: #ebebeb;
|
background: #FFF;
|
||||||
border: 1px solid gray;
|
border: 1px solid silver;
|
||||||
|
@include box-shadow(0 0 10px #CCC);
|
||||||
}
|
}
|
||||||
#vakata-contextmenu .right {
|
#vakata-contextmenu .right {
|
||||||
right: 100%;
|
right: 100%;
|
||||||
@ -246,7 +276,7 @@
|
|||||||
}
|
}
|
||||||
li.jstree-open > ul {
|
li.jstree-open > ul {
|
||||||
display: block;
|
display: block;
|
||||||
|
margin-left:-13px;
|
||||||
li ul {
|
li ul {
|
||||||
margin-left:2px;
|
margin-left:2px;
|
||||||
}
|
}
|
||||||
@ -476,7 +506,7 @@
|
|||||||
border: 1px solid #7C8816;
|
border: 1px solid #7C8816;
|
||||||
background-color: #DAE79A;
|
background-color: #DAE79A;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* comment speech bubble - ccs3 only - source: http://nicolasgallagher.com/pure-css-speech-bubbles/demo/ */
|
/* comment speech bubble - ccs3 only - source: http://nicolasgallagher.com/pure-css-speech-bubbles/demo/ */
|
||||||
& span.comment-count {
|
& span.comment-count {
|
||||||
clear: both;
|
clear: both;
|
||||||
@ -541,13 +571,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
& .jstree-closed > ins {
|
& .jstree-closed > ins {
|
||||||
background-position:0 0;
|
background-position:0 0;
|
||||||
cursor:pointer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
& .jstree-open > ins {
|
& .jstree-open > ins {
|
||||||
background-position:-20px 0;
|
background-position:-20px 0;
|
||||||
cursor:pointer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -594,4 +622,4 @@ li.class-ErrorPage > a .jstree-pageicon {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -429,7 +429,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create State
|
// Create State
|
||||||
currentState = History.extractState(History.getFullUrl(currentHash||document.location.href,false),true);
|
// MODIFIED ischommer: URL normalization needs to respect our <base> tag,
|
||||||
|
// otherwise will go into infinite loops
|
||||||
|
currentState = History.extractState(History.getFullUrl(currentHash||document.location.href,true),true);
|
||||||
|
// END MODIFIED
|
||||||
|
|
||||||
// Check if we are the same state
|
// Check if we are the same state
|
||||||
if ( History.isLastSavedState(currentState) ) {
|
if ( History.isLastSavedState(currentState) ) {
|
||||||
|
@ -535,17 +535,6 @@ class Controller extends RequestHandler implements TemplateGlobalProvider {
|
|||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true if this controller is processing an ajax request
|
|
||||||
* @return boolean True if this controller is processing an ajax request
|
|
||||||
*/
|
|
||||||
function isAjax() {
|
|
||||||
return (
|
|
||||||
isset($this->requestParams['ajax']) || isset($_REQUEST['ajax']) ||
|
|
||||||
(isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == "XMLHttpRequest")
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Joins two or more link segments together, putting a slash between them if necessary.
|
* Joins two or more link segments together, putting a slash between them if necessary.
|
||||||
* Use this for building the results of {@link Link()} methods.
|
* Use this for building the results of {@link Link()} methods.
|
||||||
|
@ -21,22 +21,17 @@ class Cookie {
|
|||||||
* @param string $path See http://php.net/set_session
|
* @param string $path See http://php.net/set_session
|
||||||
* @param string $domain See http://php.net/set_session
|
* @param string $domain See http://php.net/set_session
|
||||||
* @param boolean $secure See http://php.net/set_session
|
* @param boolean $secure See http://php.net/set_session
|
||||||
* @param boolean $httpOnly See http://php.net/set_session (PHP 5.2+ only)
|
* @param boolean $httpOnly See http://php.net/set_session
|
||||||
*/
|
*/
|
||||||
static function set($name, $value, $expiry = 90, $path = null, $domain = null, $secure = false, $httpOnly = false) {
|
static function set($name, $value, $expiry = 90, $path = null, $domain = null, $secure = false, $httpOnly = false) {
|
||||||
if(!headers_sent($file, $line)) {
|
if(!headers_sent($file, $line)) {
|
||||||
$expiry = $expiry > 0 ? time()+(86400*$expiry) : $expiry;
|
$expiry = $expiry > 0 ? time()+(86400*$expiry) : $expiry;
|
||||||
$path = ($path) ? $path : Director::baseURL();
|
$path = ($path) ? $path : Director::baseURL();
|
||||||
|
setcookie($name, $value, $expiry, $path, $domain, $secure, $httpOnly);
|
||||||
// Versions of PHP prior to 5.2 do not support the $httpOnly value
|
|
||||||
if(version_compare(phpversion(), 5.2, '<')) {
|
|
||||||
setcookie($name, $value, $expiry, $path, $domain, $secure);
|
|
||||||
} else {
|
|
||||||
setcookie($name, $value, $expiry, $path, $domain, $secure, $httpOnly);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
if(self::$report_errors)
|
if(self::$report_errors) {
|
||||||
user_error("Cookie '$name' can't be set. The site started outputting was content at line $line in $file", E_USER_WARNING);
|
user_error("Cookie '$name' can't be set. The site started outputting was content at line $line in $file", E_USER_WARNING);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -682,7 +682,7 @@ class Director implements TemplateGlobalProvider {
|
|||||||
*/
|
*/
|
||||||
static function is_ajax() {
|
static function is_ajax() {
|
||||||
if(Controller::has_curr()) {
|
if(Controller::has_curr()) {
|
||||||
return Controller::curr()->isAjax();
|
return Controller::curr()->getRequest()->isAjax();
|
||||||
} else {
|
} else {
|
||||||
return (
|
return (
|
||||||
isset($_REQUEST['ajax']) ||
|
isset($_REQUEST['ajax']) ||
|
||||||
|
@ -232,6 +232,20 @@ class SS_HTTPRequest implements ArrayAccess {
|
|||||||
function getURL() {
|
function getURL() {
|
||||||
return ($this->getExtension()) ? $this->url . '.' . $this->getExtension() : $this->url;
|
return ($this->getExtension()) ? $this->url . '.' . $this->getExtension() : $this->url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this request an ajax request,
|
||||||
|
* based on custom HTTP ajax added by common JavaScript libraries,
|
||||||
|
* or based on an explicit "ajax" request parameter.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
function isAjax() {
|
||||||
|
return (
|
||||||
|
$this->requestVar('ajax') ||
|
||||||
|
$this->getHeader('X-Requested-With') && $this->getHeader('X-Requested-With') == "XMLHttpRequest"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enables the existence of a key-value pair in the request to be checked using
|
* Enables the existence of a key-value pair in the request to be checked using
|
||||||
|
69
control/PjaxResponseNegotiator.php
Normal file
69
control/PjaxResponseNegotiator.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Handle the X-Pjax header that AJAX responses may provide, returning the
|
||||||
|
* fragment, or, in the case of non-AJAX form submissions, redirecting back to the submitter.
|
||||||
|
*
|
||||||
|
* X-Pjax ensures that users won't end up seeing the unstyled form HTML in their browser
|
||||||
|
* If a JS error prevents the Ajax overriding of form submissions from happening.
|
||||||
|
* It also provides better non-JS operation.
|
||||||
|
*
|
||||||
|
* Caution: This API is volatile, and might eventually be replaced by a generic
|
||||||
|
* action helper system for controllers.
|
||||||
|
*/
|
||||||
|
class PjaxResponseNegotiator {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Array See {@link respond()}
|
||||||
|
*/
|
||||||
|
protected $callbacks = array(
|
||||||
|
// TODO Using deprecated functionality, but don't want to duplicate Controller->redirectBack()
|
||||||
|
'default' => array('Director', 'redirectBack'),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param RequestHandler $controller
|
||||||
|
* @param Array $callbacks
|
||||||
|
*/
|
||||||
|
function __construct($callbacks = array()) {
|
||||||
|
$this->callbacks = $callbacks;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Out of the box, the handler "CurrentForm" value, which will return the rendered form.
|
||||||
|
* Non-Ajax calls will redirect back.
|
||||||
|
*
|
||||||
|
* @param SS_HTTPRequest $request
|
||||||
|
* @param array $extraCallbacks List of anonymous functions or callables returning either a string
|
||||||
|
* or SS_HTTPResponse, keyed by their fragment identifier. The 'default' key can
|
||||||
|
* be used as a fallback for non-ajax responses.
|
||||||
|
* @return SS_HTTPResponse
|
||||||
|
*/
|
||||||
|
public function respond(SS_HTTPRequest $request, $extraCallbacks = array()) {
|
||||||
|
// Prepare the default options and combine with the others
|
||||||
|
$callbacks = array_merge(
|
||||||
|
array_change_key_case($this->callbacks, CASE_LOWER),
|
||||||
|
array_change_key_case($extraCallbacks, CASE_LOWER)
|
||||||
|
);
|
||||||
|
|
||||||
|
if($fragment = $request->getHeader('X-Pjax')) {
|
||||||
|
$fragment = strtolower($fragment);
|
||||||
|
if(isset($callbacks[$fragment])) {
|
||||||
|
return call_user_func($callbacks[$fragment]);
|
||||||
|
} else {
|
||||||
|
throw new SS_HTTPResponse_Exception("X-Pjax = '$fragment' not supported for this URL.", 400);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if($request->isAjax()) throw new SS_HTTPResponse_Exception("Ajax requests to this URL require an X-Pjax header.", 400);
|
||||||
|
return call_user_func($callbacks['default']);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param String $fragment
|
||||||
|
* @param Callable $callback
|
||||||
|
*/
|
||||||
|
public function setCallback($fragment, $callback) {
|
||||||
|
$this->callbacks[$fragment] = $callback;
|
||||||
|
}
|
||||||
|
}
|
@ -338,7 +338,15 @@ class RequestHandler extends ViewableData {
|
|||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated 3.0 Use SS_HTTPRequest->isAjax() instead (through Controller->getRequest())
|
||||||
|
*/
|
||||||
|
function isAjax() {
|
||||||
|
Deprecation::notice('3.0', 'Use SS_HTTPRequest->isAjax() instead (through Controller->getRequest())');
|
||||||
|
return $this->request->isAjax();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the SS_HTTPRequest object that this controller is using.
|
* Returns the SS_HTTPRequest object that this controller is using.
|
||||||
* Returns a placeholder {@link NullHTTPRequest} object unless
|
* Returns a placeholder {@link NullHTTPRequest} object unless
|
||||||
|
@ -92,28 +92,28 @@ class Convert {
|
|||||||
return str_replace(array("\\", '"', "\n", "\r", "'"), array("\\\\", '\"', '\n', '\r', "\\'"), $val);
|
return str_replace(array("\\", '"', "\n", "\r", "'"), array("\\\\", '\"', '\n', '\r', "\\'"), $val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Uses the PHP 5.2 native json_encode function if available,
|
* Encode a value as a JSON encoded string.
|
||||||
* otherwise falls back to the Services_JSON class.
|
|
||||||
*
|
|
||||||
* @see http://pear.php.net/pepr/pepr-proposal-show.php?id=198
|
|
||||||
* @uses Director::baseFolder()
|
|
||||||
* @uses Services_JSON
|
|
||||||
*
|
*
|
||||||
* @param mixed $val
|
* @param mixed $val Value to be encoded
|
||||||
* @return string JSON safe string
|
* @return string JSON encoded string
|
||||||
*/
|
*/
|
||||||
static function raw2json($val) {
|
static function raw2json($val) {
|
||||||
if(function_exists('json_encode')) {
|
return json_encode($val);
|
||||||
return json_encode($val);
|
|
||||||
} else {
|
|
||||||
require_once(Director::baseFolder() . '/sapphire/thirdparty/json/JSON.php');
|
|
||||||
$json = new Services_JSON();
|
|
||||||
return $json->encode($val);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode an array as a JSON encoded string.
|
||||||
|
* THis is an alias to {@link raw2json()}
|
||||||
|
*
|
||||||
|
* @param array $val Array to convert
|
||||||
|
* @return string JSON encoded string
|
||||||
|
*/
|
||||||
|
static function array2json($val) {
|
||||||
|
return self::raw2json($val);
|
||||||
|
}
|
||||||
|
|
||||||
static function raw2sql($val) {
|
static function raw2sql($val) {
|
||||||
if(is_array($val)) {
|
if(is_array($val)) {
|
||||||
foreach($val as $k => $v) $val[$k] = self::raw2sql($v);
|
foreach($val as $k => $v) $val[$k] = self::raw2sql($v);
|
||||||
@ -138,41 +138,15 @@ class Convert {
|
|||||||
else return html_entity_decode($val, ENT_QUOTES, 'UTF-8');
|
else return html_entity_decode($val, ENT_QUOTES, 'UTF-8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert an array into a JSON encoded string.
|
|
||||||
*
|
|
||||||
* @see http://pear.php.net/pepr/pepr-proposal-show.php?id=198
|
|
||||||
* @uses Director::baseFolder()
|
|
||||||
* @uses Services_JSON
|
|
||||||
*
|
|
||||||
* @param array $val Array to convert
|
|
||||||
* @return string JSON encoded string
|
|
||||||
*/
|
|
||||||
static function array2json($val) {
|
|
||||||
if(function_exists('json_encode')) {
|
|
||||||
return json_encode($val);
|
|
||||||
} else {
|
|
||||||
require_once(Director::baseFolder() . '/sapphire/thirdparty/json/JSON.php');
|
|
||||||
$json = new Services_JSON();
|
|
||||||
return $json->encode($val);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a JSON encoded string into an object.
|
* Convert a JSON encoded string into an object.
|
||||||
*
|
|
||||||
* @see http://pear.php.net/pepr/pepr-proposal-show.php?id=198
|
|
||||||
* @uses Director::baseFolder()
|
|
||||||
* @uses Services_JSON
|
|
||||||
*
|
*
|
||||||
* @param string $val
|
* @param string $val
|
||||||
* @return mixed JSON safe string
|
* @return object|boolean
|
||||||
*/
|
*/
|
||||||
static function json2obj($val) {
|
static function json2obj($val) {
|
||||||
require_once(Director::baseFolder() . '/sapphire/thirdparty/json/JSON.php');
|
return json_decode($val);
|
||||||
$json = new Services_JSON();
|
|
||||||
return $json->decode($val);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -183,15 +157,7 @@ class Convert {
|
|||||||
* @return array|boolean
|
* @return array|boolean
|
||||||
*/
|
*/
|
||||||
static function json2array($val) {
|
static function json2array($val) {
|
||||||
$json = self::json2obj($val);
|
return json_decode($val, true);
|
||||||
if(!$json) return false;
|
|
||||||
|
|
||||||
$arr = array();
|
|
||||||
foreach($json as $k => $v) {
|
|
||||||
$arr[$k] = $v;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $arr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -354,7 +320,7 @@ class Convert {
|
|||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public static function raw2url($title) {
|
public static function raw2url($title) {
|
||||||
$f = Object::create('URLSegmentFilter');
|
$f = URLSegmentFilter::create();
|
||||||
return $f->filter($title);
|
return $f->filter($title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// ENVIRONMENT CONFIG
|
// ENVIRONMENT CONFIG
|
||||||
|
|
||||||
if(defined('E_DEPRECATED')) error_reporting(E_ALL & ~(E_DEPRECATED | E_STRICT));
|
if(defined('E_DEPRECATED')) error_reporting(E_ALL & ~(E_STRICT));
|
||||||
else error_reporting(E_ALL);
|
else error_reporting(E_ALL);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -800,7 +800,7 @@ class Diff
|
|||||||
if(is_array($content)) $content = implode(',', $content);
|
if(is_array($content)) $content = implode(',', $content);
|
||||||
|
|
||||||
$content = str_replace(array(" ","<", ">"),array(" "," <", "> "),$content);
|
$content = str_replace(array(" ","<", ">"),array(" "," <", "> "),$content);
|
||||||
$candidateChunks = split("[\t\r\n ]+", $content);
|
$candidateChunks = preg_split("/[\t\r\n ]+/", $content);
|
||||||
while(list($i,$item) = each($candidateChunks)) {
|
while(list($i,$item) = each($candidateChunks)) {
|
||||||
if(isset($item[0]) && $item[0] == "<") {
|
if(isset($item[0]) && $item[0] == "<") {
|
||||||
$newChunk = $item;
|
$newChunk = $item;
|
||||||
|
@ -83,13 +83,27 @@ abstract class Object {
|
|||||||
* overload is found, an instance of this is returned rather than the original class. To overload a class, use
|
* overload is found, an instance of this is returned rather than the original class. To overload a class, use
|
||||||
* {@link Object::useCustomClass()}
|
* {@link Object::useCustomClass()}
|
||||||
*
|
*
|
||||||
|
* This can be called in one of two ways - either calling via the class directly,
|
||||||
|
* or calling on Object and passing the class name as the first parameter. The following
|
||||||
|
* are equivalent:
|
||||||
|
* $list = DataList::create('SiteTree');
|
||||||
|
* $list = DataList::create('SiteTree');
|
||||||
|
*
|
||||||
* @param string $class the class name
|
* @param string $class the class name
|
||||||
* @param mixed $arguments,... arguments to pass to the constructor
|
* @param mixed $arguments,... arguments to pass to the constructor
|
||||||
* @return Object
|
* @return Object
|
||||||
*/
|
*/
|
||||||
public static function create() {
|
public static function create() {
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
$class = self::getCustomClass(array_shift($args));
|
|
||||||
|
// Class to create should be the calling class if not Object,
|
||||||
|
// otherwise the first parameter
|
||||||
|
$class = get_called_class();
|
||||||
|
if($class == 'Object')
|
||||||
|
$class = array_shift($args);
|
||||||
|
|
||||||
|
$class = self::getCustomClass($class);
|
||||||
|
|
||||||
$reflector = new ReflectionClass($class);
|
$reflector = new ReflectionClass($class);
|
||||||
if($reflector->getConstructor()) {
|
if($reflector->getConstructor()) {
|
||||||
return $reflector->newInstanceArgs($args);
|
return $reflector->newInstanceArgs($args);
|
||||||
@ -107,7 +121,7 @@ abstract class Object {
|
|||||||
* are respected.
|
* are respected.
|
||||||
*
|
*
|
||||||
* `Object::create_from_string("Versioned('Stage','Live')")` will return the result of
|
* `Object::create_from_string("Versioned('Stage','Live')")` will return the result of
|
||||||
* `Object::create('Versioned', 'Stage', 'Live);`
|
* `Versioned::create('Stage', 'Live);`
|
||||||
*
|
*
|
||||||
* It is designed for simple, clonable objects. The first time this method is called for a given
|
* It is designed for simple, clonable objects. The first time this method is called for a given
|
||||||
* string it is cached, and clones of that object are returned.
|
* string it is cached, and clones of that object are returned.
|
||||||
@ -116,7 +130,7 @@ abstract class Object {
|
|||||||
* impossible to pass null as the firstArg argument.
|
* impossible to pass null as the firstArg argument.
|
||||||
*
|
*
|
||||||
* `Object::create_from_string("Varchar(50)", "MyField")` will return the result of
|
* `Object::create_from_string("Varchar(50)", "MyField")` will return the result of
|
||||||
* `Object::create('Vachar', 'MyField', '50');`
|
* `Vachar::create('MyField', '50');`
|
||||||
*
|
*
|
||||||
* Arguments are always strings, although this is a quirk of the current implementation rather
|
* Arguments are always strings, although this is a quirk of the current implementation rather
|
||||||
* than something that can be relied upon.
|
* than something that can be relied upon.
|
||||||
|
@ -85,4 +85,4 @@ class SS_ClassLoader {
|
|||||||
return class_exists($class, false) || $this->getManifest()->getItemPath($class);
|
return class_exists($class, false) || $this->getManifest()->getItemPath($class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
.cms table.ss-gridfield-table tbody td button { border: none; background: none; margin: 0 0 0 2px; padding: 0; width: auto; text-shadow: none; }
|
.cms table.ss-gridfield-table tbody td button { border: none; background: none; margin: 0 0 0 2px; padding: 0; width: auto; text-shadow: none; }
|
||||||
.cms table.ss-gridfield-table tbody td button.ui-state-hover { background: none; -moz-box-shadow: none; -webkit-box-shadow: none; box-shadow: none; }
|
.cms table.ss-gridfield-table tbody td button.ui-state-hover { background: none; -moz-box-shadow: none; -webkit-box-shadow: none; box-shadow: none; }
|
||||||
.cms table.ss-gridfield-table tbody td button.ui-state-active { border: none; -moz-box-shadow: none; -webkit-box-shadow: none; box-shadow: none; }
|
.cms table.ss-gridfield-table tbody td button.ui-state-active { border: none; -moz-box-shadow: none; -webkit-box-shadow: none; box-shadow: none; }
|
||||||
.cms table.ss-gridfield-table tbody td a.edit-link { display: inline-block; width: 16px; height: 20px; text-indent: 9999em; background: url(../images/icons/document--pencil.png) no-repeat 0 1px; }
|
.cms table.ss-gridfield-table tbody td a.edit-link { display: inline-block; width: 16px; height: 20px; text-indent: 9999em; overflow: hidden; vertical-align: middle; background: url(../images/icons/document--pencil.png) no-repeat 0 1px; }
|
||||||
.cms table.ss-gridfield-table tfoot { color: #1d2224; }
|
.cms table.ss-gridfield-table tfoot { color: #1d2224; }
|
||||||
.cms table.ss-gridfield-table tfoot tr td { background: #95a5ab; padding: .7em; border-bottom: 1px solid rgba(0, 0, 0, 0.1); }
|
.cms table.ss-gridfield-table tfoot tr td { background: #95a5ab; padding: .7em; border-bottom: 1px solid rgba(0, 0, 0, 0.1); }
|
||||||
.cms table.ss-gridfield-table tr.title { -moz-border-radius-topleft: 7px; -webkit-border-top-left-radius: 7px; -o-border-top-left-radius: 7px; -ms-border-top-left-radius: 7px; -khtml-border-top-left-radius: 7px; border-top-left-radius: 7px; -moz-border-radius-topright: 7px; -webkit-border-top-right-radius: 7px; -o-border-top-right-radius: 7px; -ms-border-top-right-radius: 7px; -khtml-border-top-right-radius: 7px; border-top-right-radius: 7px; }
|
.cms table.ss-gridfield-table tr.title { -moz-border-radius-topleft: 7px; -webkit-border-top-left-radius: 7px; -o-border-top-left-radius: 7px; -ms-border-top-left-radius: 7px; -khtml-border-top-left-radius: 7px; border-top-left-radius: 7px; -moz-border-radius-topright: 7px; -webkit-border-top-right-radius: 7px; -o-border-top-right-radius: 7px; -ms-border-top-right-radius: 7px; -khtml-border-top-right-radius: 7px; border-top-right-radius: 7px; }
|
||||||
|
@ -697,6 +697,7 @@ function errorHandler($errno, $errstr, $errfile, $errline) {
|
|||||||
|
|
||||||
case E_NOTICE:
|
case E_NOTICE:
|
||||||
case E_USER_NOTICE:
|
case E_USER_NOTICE:
|
||||||
|
case E_DEPRECATED:
|
||||||
case E_USER_DEPRECATED:
|
case E_USER_DEPRECATED:
|
||||||
Debug::noticeHandler($errno, $errstr, $errfile, $errline, null);
|
Debug::noticeHandler($errno, $errstr, $errfile, $errline, null);
|
||||||
break;
|
break;
|
||||||
|
@ -30,8 +30,12 @@ class DebugView extends Object {
|
|||||||
'title' => 'User Notice',
|
'title' => 'User Notice',
|
||||||
'class' => 'notice'
|
'class' => 'notice'
|
||||||
),
|
),
|
||||||
|
E_DEPRECATED => array(
|
||||||
|
'title' => 'Deprecated',
|
||||||
|
'class' => 'notice'
|
||||||
|
),
|
||||||
E_USER_DEPRECATED => array(
|
E_USER_DEPRECATED => array(
|
||||||
'title' => 'Deprecation',
|
'title' => 'User Deprecated',
|
||||||
'class' => 'notice'
|
'class' => 'notice'
|
||||||
),
|
),
|
||||||
E_CORE_ERROR => array(
|
E_CORE_ERROR => array(
|
||||||
|
@ -92,7 +92,7 @@ class DevelopmentAdmin extends Controller {
|
|||||||
// This action is sake-only right now.
|
// This action is sake-only right now.
|
||||||
unset($actions["modules/add"]);
|
unset($actions["modules/add"]);
|
||||||
|
|
||||||
$renderer = Object::create('DebugView');
|
$renderer = DebugView::create();
|
||||||
$renderer->writeHeader();
|
$renderer->writeHeader();
|
||||||
$renderer->writeInfo("Sapphire Development Tools", Director::absoluteBaseURL());
|
$renderer->writeInfo("Sapphire Development Tools", Director::absoluteBaseURL());
|
||||||
$base = Director::baseURL();
|
$base = Director::baseURL();
|
||||||
@ -116,33 +116,33 @@ class DevelopmentAdmin extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function tests($request) {
|
function tests($request) {
|
||||||
return Object::create('TestRunner');
|
return TestRunner::create();
|
||||||
}
|
}
|
||||||
|
|
||||||
function jstests($request) {
|
function jstests($request) {
|
||||||
return Object::create('JSTestRunner');
|
return JSTestRunner::create();
|
||||||
}
|
}
|
||||||
|
|
||||||
function tasks() {
|
function tasks() {
|
||||||
return Object::create('TaskRunner');
|
return TaskRunner::create();
|
||||||
}
|
}
|
||||||
|
|
||||||
function viewmodel() {
|
function viewmodel() {
|
||||||
return Object::create('ModelViewer');
|
return ModelViewer::create();
|
||||||
}
|
}
|
||||||
|
|
||||||
function build($request) {
|
function build($request) {
|
||||||
if(Director::is_cli()) {
|
if(Director::is_cli()) {
|
||||||
$da = Object::create('DatabaseAdmin');
|
$da = DatabaseAdmin::create();
|
||||||
return $da->handleRequest($request, $this->model);
|
return $da->handleRequest($request, $this->model);
|
||||||
} else {
|
} else {
|
||||||
$renderer = Object::create('DebugView');
|
$renderer = DebugView::create();
|
||||||
$renderer->writeHeader();
|
$renderer->writeHeader();
|
||||||
$renderer->writeInfo("Environment Builder", Director::absoluteBaseURL());
|
$renderer->writeInfo("Environment Builder", Director::absoluteBaseURL());
|
||||||
echo "<div style=\"margin: 0 2em\">";
|
echo "<div style=\"margin: 0 2em\">";
|
||||||
echo "<div class=\"status pending\"><h2 class='buildProgress'>Database is building.... Check below for any errors</h2><h2 class='buildCompleted'>Database has been built successfully</h2></div>";
|
echo "<div class=\"status pending\"><h2 class='buildProgress'>Database is building.... Check below for any errors</h2><h2 class='buildCompleted'>Database has been built successfully</h2></div>";
|
||||||
|
|
||||||
$da = Object::create('DatabaseAdmin');
|
$da = DatabaseAdmin::create();
|
||||||
return $da->handleRequest($request, $this->model);
|
return $da->handleRequest($request, $this->model);
|
||||||
|
|
||||||
echo "</div>";
|
echo "</div>";
|
||||||
@ -157,10 +157,10 @@ class DevelopmentAdmin extends Controller {
|
|||||||
* 'build/defaults' => 'buildDefaults',
|
* 'build/defaults' => 'buildDefaults',
|
||||||
*/
|
*/
|
||||||
function buildDefaults() {
|
function buildDefaults() {
|
||||||
$da = Object::create('DatabaseAdmin');
|
$da = DatabaseAdmin::create();
|
||||||
|
|
||||||
if (!Director::is_cli()) {
|
if (!Director::is_cli()) {
|
||||||
$renderer = Object::create('DebugView');
|
$renderer = DebugView::create();
|
||||||
$renderer->writeHeader();
|
$renderer->writeHeader();
|
||||||
$renderer->writeInfo("Defaults Builder", Director::absoluteBaseURL());
|
$renderer->writeInfo("Defaults Builder", Director::absoluteBaseURL());
|
||||||
echo "<div style=\"margin: 0 2em\">";
|
echo "<div style=\"margin: 0 2em\">";
|
||||||
@ -189,6 +189,6 @@ class DevelopmentAdmin extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function viewcode($request) {
|
function viewcode($request) {
|
||||||
return Object::create('CodeViewer');
|
return CodeViewer::create();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -143,6 +143,9 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
|||||||
i18n::set_date_format(null);
|
i18n::set_date_format(null);
|
||||||
i18n::set_time_format(null);
|
i18n::set_time_format(null);
|
||||||
|
|
||||||
|
// Set default timezone consistently to avoid NZ-specific dependencies
|
||||||
|
date_default_timezone_set('UTC');
|
||||||
|
|
||||||
// Remove password validation
|
// Remove password validation
|
||||||
$this->originalMemberPasswordValidator = Member::password_validator();
|
$this->originalMemberPasswordValidator = Member::password_validator();
|
||||||
$this->originalRequirements = Requirements::backend();
|
$this->originalRequirements = Requirements::backend();
|
||||||
@ -272,6 +275,9 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
|||||||
// which is used in DatabaseAdmin->doBuild()
|
// which is used in DatabaseAdmin->doBuild()
|
||||||
global $_SINGLETONS;
|
global $_SINGLETONS;
|
||||||
$_SINGLETONS = array();
|
$_SINGLETONS = array();
|
||||||
|
|
||||||
|
// Set default timezone consistently to avoid NZ-specific dependencies
|
||||||
|
date_default_timezone_set('UTC');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -765,7 +771,10 @@ class SapphireTest extends PHPUnit_Framework_TestCase {
|
|||||||
// Disable PHPUnit error handling
|
// Disable PHPUnit error handling
|
||||||
restore_error_handler();
|
restore_error_handler();
|
||||||
|
|
||||||
// Create a temporary database
|
// Create a temporary database, and force the connection to use UTC for time
|
||||||
|
global $databaseConfig;
|
||||||
|
$databaseConfig['timezone'] = '+0:00';
|
||||||
|
DB::connect($databaseConfig);
|
||||||
$dbConn = DB::getConn();
|
$dbConn = DB::getConn();
|
||||||
$prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_';
|
$prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_';
|
||||||
$dbname = strtolower(sprintf('%stmpdb', $prefix)) . rand(1000000,9999999);
|
$dbname = strtolower(sprintf('%stmpdb', $prefix)) . rand(1000000,9999999);
|
||||||
|
@ -1,26 +1,25 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
************************************************************************************
|
************************************************************************************
|
||||||
** **
|
** **
|
||||||
** If you can read this text in your browser then you don't have PHP installed. **
|
** If you can read this text in your browser then you don't have PHP installed. **
|
||||||
** Please install PHP 5.2 or higher, preferably PHP 5.3. **
|
** Please install PHP 5.3 or higher. **
|
||||||
** **
|
** **
|
||||||
************************************************************************************
|
************************************************************************************
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PHP version check. Make sure we've got at least PHP 5.2 in the most friendly way possible
|
* PHP version check. Make sure we've got at least PHP 5.3 in the most friendly way possible
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$majorVersion = strtok(phpversion(),'.');
|
$majorVersion = strtok(phpversion(),'.');
|
||||||
$minorVersion = strtok('.');
|
$minorVersion = strtok('.');
|
||||||
|
|
||||||
if($majorVersion < 5 || ($majorVersion == 5 && $minorVersion < 2)) {
|
if($majorVersion < 5 || ($majorVersion == 5 && $minorVersion < 3)) {
|
||||||
header("HTTP/1.1 500 Server Error");
|
header("HTTP/1.1 500 Server Error");
|
||||||
echo str_replace('$PHPVersion', phpversion(), file_get_contents("sapphire/dev/install/php5-required.html"));
|
echo str_replace('$PHPVersion', phpversion(), file_get_contents("sapphire/dev/install/php5-required.html"));
|
||||||
die();
|
die();
|
||||||
}
|
}
|
||||||
|
|
||||||
include('sapphire/dev/install/install.php5');
|
include('sapphire/dev/install/install.php5');
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
************************************************************************************
|
************************************************************************************
|
||||||
** **
|
** **
|
||||||
** If you can read this text in your browser then you don't have PHP installed. **
|
** If you can read this text in your browser then you don't have PHP installed. **
|
||||||
** Please install PHP 5.2 or higher, preferably PHP 5.3. **
|
** Please install PHP 5.3 or higher. **
|
||||||
** **
|
** **
|
||||||
************************************************************************************
|
************************************************************************************
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
@ -402,9 +402,9 @@ class InstallRequirements {
|
|||||||
$this->requireDateTimezone(array('PHP Configuration', 'date.timezone set and valid', 'date.timezone option in php.ini must be set in PHP 5.3.0+', ini_get('date.timezone')));
|
$this->requireDateTimezone(array('PHP Configuration', 'date.timezone set and valid', 'date.timezone option in php.ini must be set in PHP 5.3.0+', ini_get('date.timezone')));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->suggestPHPSetting('asp_tags', array(''), array('PHP Configuration', 'asp_tags option turned off', 'This should be turned off as it can cause issues with SilverStripe'));
|
$this->suggestPHPSetting('asp_tags', array(false,0,''), array('PHP Configuration', 'asp_tags option turned off', 'This should be turned off as it can cause issues with SilverStripe'));
|
||||||
$this->suggestPHPSetting('magic_quotes_gpc', array(''), array('PHP Configuration', 'magic_quotes_gpc option turned off', 'This should be turned off, as it can cause issues with cookies. More specifically, unserializing data stored in cookies.'));
|
$this->suggestPHPSetting('magic_quotes_gpc', array(false,0,''), array('PHP Configuration', 'magic_quotes_gpc option turned off', 'This should be turned off, as it can cause issues with cookies. More specifically, unserializing data stored in cookies.'));
|
||||||
$this->suggestPHPSetting('display_errors', array(''), array('PHP Configuration', 'display_errors option turned off', 'Unless you\'re in a development environment, this should be turned off, as it can expose sensitive data to website users.'));
|
$this->suggestPHPSetting('display_errors', array(false,0,''), array('PHP Configuration', 'display_errors option turned off', 'Unless you\'re in a development environment, this should be turned off, as it can expose sensitive data to website users.'));
|
||||||
|
|
||||||
// Check memory allocation
|
// Check memory allocation
|
||||||
$this->requireMemory(32*1024*1024, 64*1024*1024, array("PHP Configuration", "Memory allocated (PHP config option 'memory_limit')", "SilverStripe needs a minimum of 32M allocated to PHP, but recommends 64M.", ini_get("memory_limit")));
|
$this->requireMemory(32*1024*1024, 64*1024*1024, array("PHP Configuration", "Memory allocated (PHP config option 'memory_limit')", "SilverStripe needs a minimum of 32M allocated to PHP, but recommends 64M.", ini_get("memory_limit")));
|
||||||
@ -414,7 +414,6 @@ class InstallRequirements {
|
|||||||
|
|
||||||
function suggestPHPSetting($settingName, $settingValues, $testDetails) {
|
function suggestPHPSetting($settingName, $settingValues, $testDetails) {
|
||||||
$this->testing($testDetails);
|
$this->testing($testDetails);
|
||||||
|
|
||||||
$val = ini_get($settingName);
|
$val = ini_get($settingName);
|
||||||
if(!in_array($val, $settingValues) && $val != $settingValues) {
|
if(!in_array($val, $settingValues) && $val != $settingValues) {
|
||||||
$testDetails[2] = "$settingName is set to '$val' in php.ini. $testDetails[2]";
|
$testDetails[2] = "$settingName is set to '$val' in php.ini. $testDetails[2]";
|
||||||
|
@ -24,10 +24,10 @@
|
|||||||
<div class="content-container">
|
<div class="content-container">
|
||||||
<h1>CMS Installation</h1>
|
<h1>CMS Installation</h1>
|
||||||
<h2 class="no-line">PHP 5 required</h2>
|
<h2 class="no-line">PHP 5 required</h2>
|
||||||
<h3>To run SilverStripe, please install PHP 5.2 or greater.</h3>
|
<h3>To run SilverStripe, please install PHP 5.3 or greater.</h3>
|
||||||
|
|
||||||
<p>We have detected that you are running PHP version <b>$PHPVersion</b>. In order to run SilverStripe,
|
<p>We have detected that you are running PHP version <b>$PHPVersion</b>. In order to run SilverStripe,
|
||||||
you must have PHP version 5.2 or greater, and for best results we recommend PHP 5.3 or greater.</p>
|
you must have PHP version 5.3 or greater.</p>
|
||||||
|
|
||||||
<p>If you are running on a shared host, you may need to ask your hosting provider how to do this.</p>
|
<p>If you are running on a shared host, you may need to ask your hosting provider how to do this.</p>
|
||||||
</div>
|
</div>
|
||||||
|
BIN
docs/en/_images/page_node_deleted_as_normal.png
Normal file
BIN
docs/en/_images/page_node_deleted_as_normal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.0 KiB |
BIN
docs/en/_images/page_node_normal.png
Normal file
BIN
docs/en/_images/page_node_normal.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.0 KiB |
BIN
docs/en/_images/page_node_removed.png
Normal file
BIN
docs/en/_images/page_node_removed.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
BIN
docs/en/_images/page_node_scheduled.png
Normal file
BIN
docs/en/_images/page_node_scheduled.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 9.2 KiB |
BIN
docs/en/_images/sss.png
Normal file
BIN
docs/en/_images/sss.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.2 KiB |
BIN
docs/en/_images/tree_node.png
Normal file
BIN
docs/en/_images/tree_node.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
@ -113,6 +113,38 @@ As with any SilverStripe upgrade, we recommend database backups before calling `
|
|||||||
See [mysql.com](http://dev.mysql.com/doc/refman/5.5/en/converting-tables-to-innodb.html) for details on the conversion.
|
See [mysql.com](http://dev.mysql.com/doc/refman/5.5/en/converting-tables-to-innodb.html) for details on the conversion.
|
||||||
Note: MySQL has made InnoDB the default engine in its [5.5 release](http://dev.mysql.com/doc/refman/5.5/en/innodb-storage-engine.html).
|
Note: MySQL has made InnoDB the default engine in its [5.5 release](http://dev.mysql.com/doc/refman/5.5/en/innodb-storage-engine.html).
|
||||||
|
|
||||||
|
### Convert::json2array() changes ###
|
||||||
|
|
||||||
|
Convert JSON functions have been changed to use built-in json PHP functions `json_decode()` and `json_encode()`
|
||||||
|
|
||||||
|
Because `json_decode()` will convert nested JSON structures to arrays as well, this has changed the way it worked,
|
||||||
|
as before nested structures would be converted to an object instead.
|
||||||
|
|
||||||
|
So, given the following JSON input to `Convert::json2array()`:
|
||||||
|
|
||||||
|
{"Joe":"Bloggs","Tom":"Jones","My":{"Complicated":"Structure"}}
|
||||||
|
|
||||||
|
Here's the output from SilverStripe 2.4, with nested JSON as objects:
|
||||||
|
|
||||||
|
array(
|
||||||
|
'Joe' => 'Bloggs'
|
||||||
|
'Tom' => 'Jones',
|
||||||
|
'My' => stdObject(
|
||||||
|
Complicated => 'Structure' // property on object
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
Now in SilverStripe 3.x, nested structures are arrays:
|
||||||
|
|
||||||
|
array(
|
||||||
|
'Joe' => 'Bloggs',
|
||||||
|
'Tom' => 'Jones',
|
||||||
|
'My' => array(
|
||||||
|
'Complicated' => 'Structure' // key value on nested array
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
### GridField: Replacement for TableListField and ComplexTableField ###
|
### GridField: Replacement for TableListField and ComplexTableField ###
|
||||||
|
|
||||||
We have a new component for managing lists of objects: The `[GridField](/topics/grid-field)`.
|
We have a new component for managing lists of objects: The `[GridField](/topics/grid-field)`.
|
||||||
|
76
docs/en/howto/customize-cms-tree.md
Normal file
76
docs/en/howto/customize-cms-tree.md
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
# How to customize the CMS tree #
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
The tree is rendered through `[api:LeftAndMain->getSiteTreeFor()]`,
|
||||||
|
which recursively collects all nodes based on various filtering criteria.
|
||||||
|
The node strictly just has to implement the `[api:Hierarchy]` extension,
|
||||||
|
but in the CMS usually is a `[api:SiteTree]` object.
|
||||||
|
|
||||||
|
## Add status lozenges to tree nodes ##
|
||||||
|
|
||||||
|
A tree node in CMS could be rendered with lot of extra information but a node title, such as a
|
||||||
|
link that wraps around the node title, a node's id which is given as id attribute of the node
|
||||||
|
<li> tag, a extra checkbox beside the tree title, tree icon class or extra <span>
|
||||||
|
tags showing the node status, etc. SilverStripe tree node will be typically rendered into html
|
||||||
|
code like this:
|
||||||
|
|
||||||
|
:::ss
|
||||||
|
...
|
||||||
|
<ul>
|
||||||
|
...
|
||||||
|
<li id="record-15" class="class-Page closed jstree-leaf jstree-unchecked" data-id="15">
|
||||||
|
<ins class="jstree-icon"> </ins>
|
||||||
|
<a class="" title="Page type: Page" href="admin/page/edit/show/15">
|
||||||
|
<ins class="jstree-checkbox"> </ins>
|
||||||
|
<ins class="jstree-icon"> </ins>
|
||||||
|
<span class="text">
|
||||||
|
<span class="jstree-pageicon"></span>
|
||||||
|
<span class="item" title="Deleted">New Page</span>
|
||||||
|
<span class="badge deletedonlive">Deleted</span>
|
||||||
|
</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
...
|
||||||
|
</ul>
|
||||||
|
...
|
||||||
|
|
||||||
|
By applying the proper style sheet, the snippet html above could produce the look of:
|
||||||
|
![Page Node Screenshot](../_images/tree_node.png "Page Node")
|
||||||
|
|
||||||
|
SiteTree is a `[api:DataObject]` which is versioned by `[api:Versioned]` extension.
|
||||||
|
Each node can optionally have publication status flags, e.g. "Removed from draft".
|
||||||
|
Each flag has a unique identifier, which is also used as a CSS class for easier styling.
|
||||||
|
|
||||||
|
Developers can easily add a new flag, delete or alter an existing flag on how it is looked
|
||||||
|
or changing the flag label. The customization of these lozenges could be done either through
|
||||||
|
inherited subclass or `[api:DataExtension]`. It is just really about how we change the return
|
||||||
|
value of function `SiteTree->getTreeTitle()` by two easily extendable methods
|
||||||
|
`SiteTree->getStatusClass()` and `SiteTree->getStatusFlags()`.
|
||||||
|
|
||||||
|
Note: Though the flag is not necessarily tie to its status of __publication__ and it could
|
||||||
|
be used for flagging anything you like, we should keep this lozenge to show version-related
|
||||||
|
status, while let `SiteTree->CMSTreeClasses()` to deal with other customised classes, which
|
||||||
|
will be used for the class attribute of <li> tag of the tree node.
|
||||||
|
|
||||||
|
### Add new flag ###
|
||||||
|
__Example: using a subclass__
|
||||||
|
|
||||||
|
:::php
|
||||||
|
class Page extends SiteTree {
|
||||||
|
function getScheduledToPublish(){
|
||||||
|
// return either true or false
|
||||||
|
}
|
||||||
|
|
||||||
|
function getStatusFlags(){
|
||||||
|
$flags = parent::getStatusFlags();
|
||||||
|
$flags['scheduledtopublish'] = "Scheduled To Publish";
|
||||||
|
return $flags;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
The above subclass of `[api:SiteTree]` will add a new flag for indicating its
|
||||||
|
__'Scheduled To Publish'__ status. The look of the page node will be changed
|
||||||
|
from ![Normal Page Node](../_images/page_node_normal.png") to ![Scheduled Page Node](../_images/page_node_scheduled.png). The getStatusFlags has an `updateStatusFlags()`
|
||||||
|
extension point, so the flags can be modified through `DataExtension` rather than
|
||||||
|
inheritance as well. Deleting existing flags works by simply unsetting the array key.
|
@ -11,6 +11,7 @@ the language and functions which are used in the guides.
|
|||||||
* [Grouping DataObjectSets](grouping-dataobjectsets). Group results in a [api:DataObjectSet] to create sub sections.
|
* [Grouping DataObjectSets](grouping-dataobjectsets). Group results in a [api:DataObjectSet] to create sub sections.
|
||||||
* [PHPUnit Configuration](phpunit-configuration). How to setup your testing environment with PHPUnit
|
* [PHPUnit Configuration](phpunit-configuration). How to setup your testing environment with PHPUnit
|
||||||
* [Extend the CMS Interface](extend-cms-interface).
|
* [Extend the CMS Interface](extend-cms-interface).
|
||||||
|
* [How to customize CMS Tree](customize-cms-tree).
|
||||||
|
|
||||||
## Feedback
|
## Feedback
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ SilverStripe core is currently hosted on [github.com/silverstripe](http://github
|
|||||||
* The `installer` project ([github.com/silverstripe/silverstripe-installer](http://github.com/silverstripe/silverstripe-installer))
|
* The `installer` project ([github.com/silverstripe/silverstripe-installer](http://github.com/silverstripe/silverstripe-installer))
|
||||||
* The `sapphire` module ([github.com/silverstripe/sapphire](http://github.com/silverstripe/sapphire))
|
* The `sapphire` module ([github.com/silverstripe/sapphire](http://github.com/silverstripe/sapphire))
|
||||||
* The `cms` module ([github.com/silverstripe/silverstripe-cms](http://github.com/silverstripe/silverstripe-cms))
|
* The `cms` module ([github.com/silverstripe/silverstripe-cms](http://github.com/silverstripe/silverstripe-cms))
|
||||||
* A sample theme called `blackcandy` ([github.com/silverstripe-themes/silverstripe-blackcandy](http://github.com/silverstripe-themes/silverstripe-blackcandy))
|
* A sample theme called `simple` ([github.com/silverstripe-themes/silverstripe-simple](http://github.com/silverstripe-themes/silverstripe-simple))
|
||||||
|
|
||||||
First, you'll have to decide what you want to do with your project:
|
First, you'll have to decide what you want to do with your project:
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ Run the following command to download all core dependencies via [Piston](http://
|
|||||||
cd my-silverstripe-project/
|
cd my-silverstripe-project/
|
||||||
tools/new-project
|
tools/new-project
|
||||||
|
|
||||||
This will add `sapphire`, `cms` and the `blackcandy` theme to your project.
|
This will add `sapphire`, `cms` and the `simple` theme to your project.
|
||||||
|
|
||||||
As a fallback solution, you can simply download all necessary files without any dependency management through piston.
|
As a fallback solution, you can simply download all necessary files without any dependency management through piston.
|
||||||
This is handy if you have an existing project in version control, and want a one-off snapshot
|
This is handy if you have an existing project in version control, and want a one-off snapshot
|
||||||
@ -146,8 +146,7 @@ Please replace `<username>` below with your github username.
|
|||||||
cd my-silverstripe-project
|
cd my-silverstripe-project
|
||||||
git clone git@github.com:<username>/sapphire.git sapphire
|
git clone git@github.com:<username>/sapphire.git sapphire
|
||||||
git clone git@github.com:<username>/silverstripe-cms.git cms
|
git clone git@github.com:<username>/silverstripe-cms.git cms
|
||||||
rm -rf themes
|
git clone git@github.com:<username>/silverstripe-simple.git themes/simple
|
||||||
git clone git@github.com:<username>/silverstripe-blackcandy.git themes
|
|
||||||
|
|
||||||
Now you need to add the original repository as `upstream`, so you can keep your fork updated later on.
|
Now you need to add the original repository as `upstream`, so you can keep your fork updated later on.
|
||||||
|
|
||||||
@ -155,7 +154,7 @@ Now you need to add the original repository as `upstream`, so you can keep your
|
|||||||
(git remote add upstream git://github.com/silverstripe/silverstripe-installer.git && git fetch upstream)
|
(git remote add upstream git://github.com/silverstripe/silverstripe-installer.git && git fetch upstream)
|
||||||
(cd sapphire && git remote add upstream git://github.com/silverstripe/sapphire.git && git fetch upstream)
|
(cd sapphire && git remote add upstream git://github.com/silverstripe/sapphire.git && git fetch upstream)
|
||||||
(cd cms && git remote add upstream git://github.com/silverstripe/silverstripe-cms.git && git fetch upstream)
|
(cd cms && git remote add upstream git://github.com/silverstripe/silverstripe-cms.git && git fetch upstream)
|
||||||
(cd themes/blackcandy && git remote add upstream git://github.com/silverstripe-themes/silverstripe-blackcandy.git)
|
(cd themes/simple && git remote add upstream git://github.com/silverstripe-themes/silverstripe-simple.git)
|
||||||
|
|
||||||
Now that you're set up, please read our ["Collaboration on Git"](../misc/collaboration-on-git) guide,
|
Now that you're set up, please read our ["Collaboration on Git"](../misc/collaboration-on-git) guide,
|
||||||
as well as our general ["Contributor guidelines"](../misc/contributing).
|
as well as our general ["Contributor guidelines"](../misc/contributing).
|
||||||
@ -175,7 +174,7 @@ You can optionally select a ["release branch"](https://github.com/silverstripe/s
|
|||||||
git checkout -b 2.4 origin/2.4
|
git checkout -b 2.4 origin/2.4
|
||||||
(cd sapphire && git checkout -b 2.4 origin/2.4)
|
(cd sapphire && git checkout -b 2.4 origin/2.4)
|
||||||
(cd cms && git checkout -b 2.4 origin/2.4)
|
(cd cms && git checkout -b 2.4 origin/2.4)
|
||||||
(cd themes/blackcandy && git checkout -b 2.4 origin/2.4)
|
(cd themes/simple && git checkout -b 2.4 origin/2.4)
|
||||||
# repeat for all modules in your project...
|
# repeat for all modules in your project...
|
||||||
|
|
||||||
After creating the local branch, you can simply switch between branches:
|
After creating the local branch, you can simply switch between branches:
|
||||||
@ -184,7 +183,7 @@ After creating the local branch, you can simply switch between branches:
|
|||||||
git checkout 2.4
|
git checkout 2.4
|
||||||
(cd sapphire && git checkout 2.4)
|
(cd sapphire && git checkout 2.4)
|
||||||
(cd cms && git checkout 2.4)
|
(cd cms && git checkout 2.4)
|
||||||
(cd themes/blackcandy && git checkout 2.4)
|
(cd themes/simple && git checkout 2.4)
|
||||||
# repeat for all modules in your project...
|
# repeat for all modules in your project...
|
||||||
|
|
||||||
To switch back to master:
|
To switch back to master:
|
||||||
@ -193,7 +192,7 @@ To switch back to master:
|
|||||||
git checkout master
|
git checkout master
|
||||||
(cd sapphire && git checkout master)
|
(cd sapphire && git checkout master)
|
||||||
(cd cms && git checkout master)
|
(cd cms && git checkout master)
|
||||||
(cd themes/blackcandy && git checkout master)
|
(cd themes/simple && git checkout master)
|
||||||
# repeat for all modules in your project...
|
# repeat for all modules in your project...
|
||||||
|
|
||||||
You can't switch branches if your working copy has local changes (typically in `mysite/_config.php`).
|
You can't switch branches if your working copy has local changes (typically in `mysite/_config.php`).
|
||||||
|
@ -259,5 +259,6 @@ Note: You can see any additional HTTP headers through the web developer tools in
|
|||||||
## Related
|
## Related
|
||||||
|
|
||||||
* [Howto: Extend the CMS Interface](../howto/extend-cms-interface)
|
* [Howto: Extend the CMS Interface](../howto/extend-cms-interface)
|
||||||
|
* [Howto: Customize the CMS tree](../howto/customize-cms-tree)
|
||||||
* [Reference: ModelAdmin](../reference/modeladmin)
|
* [Reference: ModelAdmin](../reference/modeladmin)
|
||||||
* [Topics: Rich Text Editing](../topics/rich-text-editing)
|
* [Topics: Rich Text Editing](../topics/rich-text-editing)
|
@ -93,7 +93,7 @@ of the CMS you have to take care of instanciation yourself:
|
|||||||
// File: mysite/code/MyController.php
|
// File: mysite/code/MyController.php
|
||||||
class MyObjectController extends Controller {
|
class MyObjectController extends Controller {
|
||||||
public function EditorToolbar() {
|
public function EditorToolbar() {
|
||||||
return Object::create('HtmlEditorField_Toolbar', $this, "EditorToolbar");
|
return HtmlEditorField_Toolbar::create($this, "EditorToolbar");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,8 +213,8 @@ PHP:
|
|||||||
public function search($request) {
|
public function search($request) {
|
||||||
$htmlTitle = '<p>Your results for:' . Convert::raw2xml($request->getVar('Query')) . '</p>';
|
$htmlTitle = '<p>Your results for:' . Convert::raw2xml($request->getVar('Query')) . '</p>';
|
||||||
return $this->customise(array(
|
return $this->customise(array(
|
||||||
'Query' => DBField::create('Text', $request->getVar('Query')),
|
'Query' => Text::create($request->getVar('Query')),
|
||||||
'HTMLTitle' => DBField::create('HTMLText', $htmlTitle)
|
'HTMLTitle' => HTMLText::create($htmlTitle)
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -243,7 +243,7 @@ PHP:
|
|||||||
$rssRelativeLink = "/rss?Query=" . urlencode($_REQUEST['query']) . "&sortOrder=asc";
|
$rssRelativeLink = "/rss?Query=" . urlencode($_REQUEST['query']) . "&sortOrder=asc";
|
||||||
$rssLink = Controller::join_links($this->Link(), $rssRelativeLink);
|
$rssLink = Controller::join_links($this->Link(), $rssRelativeLink);
|
||||||
return $this->customise(array(
|
return $this->customise(array(
|
||||||
"RSSLink" => DBField::create("Text", $rssLink),
|
"RSSLink" => Text::create($rssLink),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,6 @@ We'll start with the *ArticlePage* page type. First we create the model, a class
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
|
|
||||||
Here we've created our data object/controller pair, but we haven't actually extended them at all. Don't worry about the
|
Here we've created our data object/controller pair, but we haven't actually extended them at all. Don't worry about the
|
||||||
@ -116,8 +115,6 @@ Let's create the *ArticleHolder* page type.
|
|||||||
class ArticleHolder_Controller extends Page_Controller {
|
class ArticleHolder_Controller extends Page_Controller {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
|
||||||
|
|
||||||
Here we have done something interesting: the *$allowed_children* field. This is one of a number of static fields we can
|
Here we have done something interesting: the *$allowed_children* field. This is one of a number of static fields we can
|
||||||
@ -249,7 +246,7 @@ Let's walk through these changes.
|
|||||||
*$dateField* is added only to the DateField in order to change the configuration.
|
*$dateField* is added only to the DateField in order to change the configuration.
|
||||||
|
|
||||||
:::php
|
:::php
|
||||||
$dateField->setConfig('showCalendar', true);
|
$dateField->setConfig('showcalendar', true);
|
||||||
|
|
||||||
Set *showCalendar* to true to have a calendar appear underneath the Date field when you click on the field.
|
Set *showCalendar* to true to have a calendar appear underneath the Date field when you click on the field.
|
||||||
|
|
||||||
@ -424,44 +421,6 @@ This will change the icons for the pages in the CMS.
|
|||||||
|
|
||||||
![](_images/icons2.jpg)
|
![](_images/icons2.jpg)
|
||||||
|
|
||||||
### Allowing comments on news articles
|
|
||||||
|
|
||||||
A handy feature built into SilverStripe is the ability for guests to your site to leave comments on pages. We can turn
|
|
||||||
this on for an article simply by ticking the box in the behaviour tab of a page in the CMS. Enable this for all your
|
|
||||||
*ArticlePage*s.
|
|
||||||
|
|
||||||
![](_images/comments.jpg)
|
|
||||||
|
|
||||||
We then need to include *$PageComments* in our template, which will insert the comment form as well as all comments left
|
|
||||||
on the page.
|
|
||||||
|
|
||||||
**themes/tutorial/templates/Layout/ArticlePage.ss**
|
|
||||||
|
|
||||||
:::html
|
|
||||||
...
|
|
||||||
<div class="newsDetails">
|
|
||||||
Posted on $Date.Nice by $Author
|
|
||||||
</div>
|
|
||||||
$PageComments
|
|
||||||
...
|
|
||||||
|
|
||||||
|
|
||||||
You should also prepare the *Page* template in the same manner, so comments can be enabled at a later point on any page.
|
|
||||||
|
|
||||||
![](_images/news-comments.jpg)
|
|
||||||
|
|
||||||
It would be nice to have comments on for all articles by default. We can do this with the *$defaults* array. Add this to
|
|
||||||
the *ArticlePage* class:
|
|
||||||
|
|
||||||
:::php
|
|
||||||
static $defaults = array(
|
|
||||||
'ProvideComments' => true
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
You can set defaults for any of the fields in your data object. *ProvideComments* is defined in *SiteTree*, so it is
|
|
||||||
part of our *ArticlePage* data object.
|
|
||||||
|
|
||||||
## Showing the latest news on the homepage
|
## Showing the latest news on the homepage
|
||||||
|
|
||||||
It would be nice to greet page visitors with a summary of the latest news when they visit the homepage. This requires a
|
It would be nice to greet page visitors with a summary of the latest news when they visit the homepage. This requires a
|
||||||
|
@ -316,10 +316,13 @@ class File extends DataObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the fields to power the edit screen of files in the CMS
|
* Returns the fields to power the edit screen of files in the CMS.
|
||||||
|
* You can modify this FieldList by subclassing folder, or by creating a {@link DataExtension}
|
||||||
|
* and implemeting updateCMSFields(FieldList $fields) on that extension.
|
||||||
|
*
|
||||||
* @return FieldList
|
* @return FieldList
|
||||||
*/
|
*/
|
||||||
function getCMSFields() {
|
function getCMSFields($params = null) {
|
||||||
// Preview
|
// Preview
|
||||||
if($this instanceof Image) {
|
if($this instanceof Image) {
|
||||||
$formattedImage = $this->getFormattedImage('SetWidth', Image::$asset_preview_width);
|
$formattedImage = $this->getFormattedImage('SetWidth', Image::$asset_preview_width);
|
||||||
@ -346,12 +349,12 @@ class File extends DataObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//create the file attributes in a FieldGroup
|
//create the file attributes in a FieldGroup
|
||||||
$filePreview = FormField::create('CompositeField',
|
$filePreview = CompositeField::create(
|
||||||
FormField::create('CompositeField',
|
CompositeField::create(
|
||||||
$previewField
|
$previewField
|
||||||
)->setName("FilePreviewImage")->addExtraClass('cms-file-info-preview'),
|
)->setName("FilePreviewImage")->addExtraClass('cms-file-info-preview'),
|
||||||
FormField::create('CompositeField',
|
CompositeField::create(
|
||||||
FormField::create('CompositeField',
|
CompositeField::create(
|
||||||
new ReadonlyField("FileType", _t('AssetTableField.TYPE','File type') . ':'),
|
new ReadonlyField("FileType", _t('AssetTableField.TYPE','File type') . ':'),
|
||||||
new ReadonlyField("Size", _t('AssetTableField.SIZE','File size') . ':', $this->getSize()),
|
new ReadonlyField("Size", _t('AssetTableField.SIZE','File size') . ':', $this->getSize()),
|
||||||
$urlField = new ReadonlyField('ClickableURL', _t('AssetTableField.URL','URL'),
|
$urlField = new ReadonlyField('ClickableURL', _t('AssetTableField.URL','URL'),
|
||||||
@ -383,6 +386,9 @@ class File extends DataObject {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Folder has its own updateCMSFields hook
|
||||||
|
if(!($this instanceof Folder)) $this->extend('updateCMSFields', $fields);
|
||||||
|
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -560,7 +566,7 @@ class File extends DataObject {
|
|||||||
if(!$name) $name = $this->Title;
|
if(!$name) $name = $this->Title;
|
||||||
|
|
||||||
// Fix illegal characters
|
// Fix illegal characters
|
||||||
$filter = Object::create('FileNameFilter');
|
$filter = FileNameFilter::create();
|
||||||
$name = $filter->filter($name);
|
$name = $filter->filter($name);
|
||||||
|
|
||||||
// We might have just turned it blank, so check again.
|
// We might have just turned it blank, so check again.
|
||||||
@ -816,8 +822,8 @@ class File extends DataObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function flushCache() {
|
public function flushCache($persistant = true) {
|
||||||
parent::flushCache();
|
parent::flushCache($persistant);
|
||||||
|
|
||||||
self::$cache_file_fields = null;
|
self::$cache_file_fields = null;
|
||||||
}
|
}
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
*
|
*
|
||||||
* See {@link URLSegmentFilter} for a more generic implementation.
|
* See {@link URLSegmentFilter} for a more generic implementation.
|
||||||
*/
|
*/
|
||||||
class FileNameFilter {
|
class FileNameFilter extends Object {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Boolean
|
* @var Boolean
|
||||||
@ -100,7 +100,7 @@ class FileNameFilter {
|
|||||||
*/
|
*/
|
||||||
function getTransliterator() {
|
function getTransliterator() {
|
||||||
if($this->transliterator === null && self::$default_use_transliterator) {
|
if($this->transliterator === null && self::$default_use_transliterator) {
|
||||||
$this->transliterator = Object::create('Transliterator');
|
$this->transliterator = Transliterator::create();
|
||||||
}
|
}
|
||||||
return $this->transliterator;
|
return $this->transliterator;
|
||||||
}
|
}
|
||||||
|
@ -232,7 +232,7 @@ class Folder extends File {
|
|||||||
// $parentFolder = Folder::findOrMake("Uploads");
|
// $parentFolder = Folder::findOrMake("Uploads");
|
||||||
|
|
||||||
// Generate default filename
|
// Generate default filename
|
||||||
$nameFilter = Object::create('FileNameFilter');
|
$nameFilter = FileNameFilter::create();
|
||||||
$file = $nameFilter->filter($tmpFile['name']);
|
$file = $nameFilter->filter($tmpFile['name']);
|
||||||
while($file[0] == '_' || $file[0] == '.') {
|
while($file[0] == '_' || $file[0] == '.') {
|
||||||
$file = substr($file, 1);
|
$file = substr($file, 1);
|
||||||
@ -406,7 +406,7 @@ class Folder extends File {
|
|||||||
* You can modify this FieldList by subclassing folder, or by creating a {@link DataExtension}
|
* You can modify this FieldList by subclassing folder, or by creating a {@link DataExtension}
|
||||||
* and implemeting updateCMSFields(FieldList $fields) on that extension.
|
* and implemeting updateCMSFields(FieldList $fields) on that extension.
|
||||||
*/
|
*/
|
||||||
function getCMSFields() {
|
function getCMSFields($param = null) {
|
||||||
// Hide field on root level, which can't be renamed
|
// Hide field on root level, which can't be renamed
|
||||||
if(!$this->ID || $this->ID === "root") {
|
if(!$this->ID || $this->ID === "root") {
|
||||||
$titleField = new HiddenField("Name");
|
$titleField = new HiddenField("Name");
|
||||||
|
@ -131,7 +131,7 @@ class Upload extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate default filename
|
// Generate default filename
|
||||||
$nameFilter = Object::create('FileNameFilter');
|
$nameFilter = FileNameFilter::create();
|
||||||
$file = $nameFilter->filter($tmpFile['name']);
|
$file = $nameFilter->filter($tmpFile['name']);
|
||||||
$fileName = basename($file);
|
$fileName = basename($file);
|
||||||
|
|
||||||
|
@ -816,7 +816,7 @@ class ComplexTableField_Popup extends Form {
|
|||||||
$actions = new FieldList();
|
$actions = new FieldList();
|
||||||
if(!$readonly) {
|
if(!$readonly) {
|
||||||
$actions->push(
|
$actions->push(
|
||||||
Object::create('FormAction',
|
FormAction::create(
|
||||||
"saveComplexTableField",
|
"saveComplexTableField",
|
||||||
_t('CMSMain.SAVE', 'Save')
|
_t('CMSMain.SAVE', 'Save')
|
||||||
)
|
)
|
||||||
|
@ -112,7 +112,7 @@ class DateField extends TextField {
|
|||||||
|
|
||||||
function FieldHolder() {
|
function FieldHolder() {
|
||||||
// TODO Replace with properly extensible view helper system
|
// TODO Replace with properly extensible view helper system
|
||||||
$d = Object::create('DateField_View_JQuery', $this);
|
$d = DateField_View_JQuery::create($this);
|
||||||
$d->onBeforeRender();
|
$d->onBeforeRender();
|
||||||
$html = parent::FieldHolder();
|
$html = parent::FieldHolder();
|
||||||
$html = $d->onAfterRender($html);
|
$html = $d->onAfterRender($html);
|
||||||
@ -196,8 +196,13 @@ class DateField extends TextField {
|
|||||||
// Setting in correct locale
|
// Setting in correct locale
|
||||||
if(is_array($val) && $this->validateArrayValue($val)) {
|
if(is_array($val) && $this->validateArrayValue($val)) {
|
||||||
// set() gets confused with custom date formats when using array notation
|
// set() gets confused with custom date formats when using array notation
|
||||||
$this->valueObj = new Zend_Date($val, null, $this->locale);
|
if(!(empty($val['day']) || empty($val['month']) || empty($val['year']))) {
|
||||||
$this->value = $this->valueObj->toArray();
|
$this->valueObj = new Zend_Date($val, null, $this->locale);
|
||||||
|
$this->value = $this->valueObj->toArray();
|
||||||
|
} else {
|
||||||
|
$this->value = $val;
|
||||||
|
$this->valueObj = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// load ISO date from database (usually through Form->loadDataForm())
|
// load ISO date from database (usually through Form->loadDataForm())
|
||||||
else if(!empty($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'), $this->locale)) {
|
else if(!empty($val) && Zend_Date::isDate($val, $this->getConfig('datavalueformat'), $this->locale)) {
|
||||||
@ -454,7 +459,7 @@ class DateField_Disabled extends DateField {
|
|||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage forms
|
* @subpackage forms
|
||||||
*/
|
*/
|
||||||
class DateField_View_JQuery {
|
class DateField_View_JQuery extends Object {
|
||||||
|
|
||||||
protected $field;
|
protected $field;
|
||||||
|
|
||||||
|
@ -57,8 +57,8 @@ class DatetimeField extends FormField {
|
|||||||
function __construct($name, $title = null, $value = ""){
|
function __construct($name, $title = null, $value = ""){
|
||||||
$this->config = self::$default_config;
|
$this->config = self::$default_config;
|
||||||
|
|
||||||
$this->dateField = Object::create('DateField', $name . '[date]', false);
|
$this->dateField = DateField::create($name . '[date]', false);
|
||||||
$this->timeField = Object::create('TimeField', $name . '[time]', false);
|
$this->timeField = TimeField::create($name . '[time]', false);
|
||||||
$this->timezoneField = new HiddenField($this->getName() . '[timezone]');
|
$this->timezoneField = new HiddenField($this->getName() . '[timezone]');
|
||||||
|
|
||||||
parent::__construct($name, $title, $value);
|
parent::__construct($name, $title, $value);
|
||||||
|
@ -45,10 +45,6 @@ class FormAction extends FormField {
|
|||||||
parent::__construct($this->action, $title, null, $form);
|
parent::__construct($this->action, $title, null, $form);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function create($action, $title = "") {
|
|
||||||
return new FormAction($action, $title);
|
|
||||||
}
|
|
||||||
|
|
||||||
function actionName() {
|
function actionName() {
|
||||||
return substr($this->name, 7);
|
return substr($this->name, 7);
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,10 @@ class HeaderField extends DatalessField {
|
|||||||
public function getHeadingLevel() {
|
public function getHeadingLevel() {
|
||||||
return $this->headingLevel;
|
return $this->headingLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setHeadingLevel($level) {
|
||||||
|
$this->headingLevel = $level;
|
||||||
|
}
|
||||||
|
|
||||||
function getAttributes() {
|
function getAttributes() {
|
||||||
return array_merge(
|
return array_merge(
|
||||||
|
@ -28,9 +28,4 @@ class HiddenField extends FormField {
|
|||||||
array('type' => 'hidden')
|
array('type' => 'hidden')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function create($name) {
|
|
||||||
return new HiddenField($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
@ -322,7 +322,7 @@ class HtmlEditorField_Toolbar extends RequestHandler {
|
|||||||
)
|
)
|
||||||
),
|
),
|
||||||
new FieldList(
|
new FieldList(
|
||||||
Object::create('ResetFormAction', 'remove', _t('HtmlEditorField.BUTTONREMOVELINK', 'Remove link'))
|
ResetFormAction::create('remove', _t('HtmlEditorField.BUTTONREMOVELINK', 'Remove link'))
|
||||||
->addExtraClass('ss-ui-action-destructive')
|
->addExtraClass('ss-ui-action-destructive')
|
||||||
->setUseButtonTag(true)
|
->setUseButtonTag(true)
|
||||||
,
|
,
|
||||||
|
@ -103,7 +103,7 @@ class MoneyField extends FormField {
|
|||||||
function saveInto($dataObject) {
|
function saveInto($dataObject) {
|
||||||
$fieldName = $this->name;
|
$fieldName = $this->name;
|
||||||
if($dataObject->hasMethod("set$fieldName")) {
|
if($dataObject->hasMethod("set$fieldName")) {
|
||||||
$dataObject->$fieldName = DBField::create('Money', array(
|
$dataObject->$fieldName = DBField::create_field('Money', array(
|
||||||
"Currency" => $this->fieldCurrency->Value(),
|
"Currency" => $this->fieldCurrency->Value(),
|
||||||
"Amount" => $this->fieldAmount->Value()
|
"Amount" => $this->fieldAmount->Value()
|
||||||
));
|
));
|
||||||
|
@ -637,8 +637,8 @@ JS
|
|||||||
$summaryFields[] = new ArrayData(array(
|
$summaryFields[] = new ArrayData(array(
|
||||||
'Function' => $function,
|
'Function' => $function,
|
||||||
'SummaryValue' => $summaryValue,
|
'SummaryValue' => $summaryValue,
|
||||||
'Name' => DBField::create('Varchar', $fieldName),
|
'Name' => DBField::create_field('Varchar', $fieldName),
|
||||||
'Title' => DBField::create('Varchar', $fieldTitle),
|
'Title' => DBField::create_field('Varchar', $fieldTitle),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
return new ArrayList($summaryFields);
|
return new ArrayList($summaryFields);
|
||||||
@ -1234,13 +1234,13 @@ JS
|
|||||||
}
|
}
|
||||||
if(strpos($castingDefinition,'->') === false) {
|
if(strpos($castingDefinition,'->') === false) {
|
||||||
$castingFieldType = $castingDefinition;
|
$castingFieldType = $castingDefinition;
|
||||||
$castingField = DBField::create($castingFieldType, $value);
|
$castingField = DBField::create_field($castingFieldType, $value);
|
||||||
$value = call_user_func_array(array($castingField,'XML'),$castingParams);
|
$value = call_user_func_array(array($castingField,'XML'),$castingParams);
|
||||||
} else {
|
} else {
|
||||||
$fieldTypeParts = explode('->', $castingDefinition);
|
$fieldTypeParts = explode('->', $castingDefinition);
|
||||||
$castingFieldType = $fieldTypeParts[0];
|
$castingFieldType = $fieldTypeParts[0];
|
||||||
$castingMethod = $fieldTypeParts[1];
|
$castingMethod = $fieldTypeParts[1];
|
||||||
$castingField = DBField::create($castingFieldType, $value);
|
$castingField = DBField::create_field($castingFieldType, $value);
|
||||||
$value = call_user_func_array(array($castingField,$castingMethod),$castingParams);
|
$value = call_user_func_array(array($castingField,$castingMethod),$castingParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ class ToggleField extends ReadonlyField {
|
|||||||
$rawInput = Convert::html2raw($valforInput);
|
$rawInput = Convert::html2raw($valforInput);
|
||||||
|
|
||||||
if($this->charNum) $reducedVal = substr($rawInput,0,$this->charNum);
|
if($this->charNum) $reducedVal = substr($rawInput,0,$this->charNum);
|
||||||
else $reducedVal = DBField::create('Text',$rawInput)->{$this->truncateMethod}();
|
else $reducedVal = DBField::create_field('Text',$rawInput)->{$this->truncateMethod}();
|
||||||
|
|
||||||
// only create togglefield if the truncated content is shorter
|
// only create togglefield if the truncated content is shorter
|
||||||
if(strlen($reducedVal) < strlen($rawInput)) {
|
if(strlen($reducedVal) < strlen($rawInput)) {
|
||||||
|
@ -343,7 +343,7 @@ class TreeDropdownField extends FormField {
|
|||||||
class TreeDropdownField_Readonly extends TreeDropdownField {
|
class TreeDropdownField_Readonly extends TreeDropdownField {
|
||||||
protected $readonly = true;
|
protected $readonly = true;
|
||||||
|
|
||||||
function Field() {
|
function Field($properties = array()) {
|
||||||
$fieldName = $this->labelField;
|
$fieldName = $this->labelField;
|
||||||
if($this->value) {
|
if($this->value) {
|
||||||
$keyObj = $this->objectForKey($this->value);
|
$keyObj = $this->objectForKey($this->value);
|
||||||
@ -361,4 +361,4 @@ class TreeDropdownField_Readonly extends TreeDropdownField {
|
|||||||
$field->setForm($this->form);
|
$field->setForm($this->form);
|
||||||
return $field->Field();
|
return $field->Field();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -407,7 +407,7 @@ class UploadField extends FileField {
|
|||||||
* @return UploadField_ItemHandler
|
* @return UploadField_ItemHandler
|
||||||
*/
|
*/
|
||||||
public function getItemHandler($itemID) {
|
public function getItemHandler($itemID) {
|
||||||
return Object::create('UploadField_ItemHandler', $this, $itemID);
|
return UploadField_ItemHandler::create($this, $itemID);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -415,7 +415,7 @@ class UploadField extends FileField {
|
|||||||
* @return UploadField_ItemHandler
|
* @return UploadField_ItemHandler
|
||||||
*/
|
*/
|
||||||
public function handleSelect(SS_HTTPRequest $request) {
|
public function handleSelect(SS_HTTPRequest $request) {
|
||||||
return Object::create('UploadField_SelectHandler', $this, $this->folderName);
|
return UploadField_SelectHandler::create($this, $this->folderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -239,13 +239,13 @@ class GridField extends FormField {
|
|||||||
|
|
||||||
if(strpos($castingDefinition,'->') === false) {
|
if(strpos($castingDefinition,'->') === false) {
|
||||||
$castingFieldType = $castingDefinition;
|
$castingFieldType = $castingDefinition;
|
||||||
$castingField = DBField::create($castingFieldType, $value);
|
$castingField = DBField::create_field($castingFieldType, $value);
|
||||||
$value = call_user_func_array(array($castingField,'XML'),$castingParams);
|
$value = call_user_func_array(array($castingField,'XML'),$castingParams);
|
||||||
} else {
|
} else {
|
||||||
$fieldTypeParts = explode('->', $castingDefinition);
|
$fieldTypeParts = explode('->', $castingDefinition);
|
||||||
$castingFieldType = $fieldTypeParts[0];
|
$castingFieldType = $fieldTypeParts[0];
|
||||||
$castingMethod = $fieldTypeParts[1];
|
$castingMethod = $fieldTypeParts[1];
|
||||||
$castingField = DBField::create($castingFieldType, $value);
|
$castingField = DBField::create_field($castingFieldType, $value);
|
||||||
$value = call_user_func_array(array($castingField,$castingMethod),$castingParams);
|
$value = call_user_func_array(array($castingField,$castingMethod),$castingParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,7 +98,7 @@ class GridFieldDeleteAction implements GridField_ColumnProvider, GridField_Actio
|
|||||||
*/
|
*/
|
||||||
public function getColumnContent($gridField, $record, $columnName) {
|
public function getColumnContent($gridField, $record, $columnName) {
|
||||||
if($this->removeRelation) {
|
if($this->removeRelation) {
|
||||||
$field = Object::create('GridField_FormAction', $gridField, 'UnlinkRelation'.$record->ID, false, "unlinkrelation", array('RecordID' => $record->ID))
|
$field = GridField_FormAction::create($gridField, 'UnlinkRelation'.$record->ID, false, "unlinkrelation", array('RecordID' => $record->ID))
|
||||||
->addExtraClass('gridfield-button-unlink')
|
->addExtraClass('gridfield-button-unlink')
|
||||||
->setAttribute('title', _t('GridAction.UnlinkRelation', "Unlink"))
|
->setAttribute('title', _t('GridAction.UnlinkRelation', "Unlink"))
|
||||||
->setAttribute('data-icon', 'chain--minus');
|
->setAttribute('data-icon', 'chain--minus');
|
||||||
@ -106,7 +106,7 @@ class GridFieldDeleteAction implements GridField_ColumnProvider, GridField_Actio
|
|||||||
if(!$record->canDelete()) {
|
if(!$record->canDelete()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$field = Object::create('GridField_FormAction', $gridField, 'DeleteRecord'.$record->ID, false, "deleterecord", array('RecordID' => $record->ID))
|
$field = GridField_FormAction::create($gridField, 'DeleteRecord'.$record->ID, false, "deleterecord", array('RecordID' => $record->ID))
|
||||||
->addExtraClass('gridfield-button-delete')
|
->addExtraClass('gridfield-button-delete')
|
||||||
->setAttribute('title', _t('GridAction.Delete', "Delete"))
|
->setAttribute('title', _t('GridAction.Delete', "Delete"))
|
||||||
->setAttribute('data-icon', 'decline');
|
->setAttribute('data-icon', 'decline');
|
||||||
|
@ -196,7 +196,7 @@ class GridFieldDetailForm_ItemRequest extends RequestHandler {
|
|||||||
'ItemEditForm' => $form,
|
'ItemEditForm' => $form,
|
||||||
))->renderWith($this->template);
|
))->renderWith($this->template);
|
||||||
|
|
||||||
if($controller->isAjax()) {
|
if($request->isAjax()) {
|
||||||
return $return;
|
return $return;
|
||||||
} else {
|
} else {
|
||||||
// If not requested by ajax, we need to render it within the controller context+template
|
// If not requested by ajax, we need to render it within the controller context+template
|
||||||
|
@ -123,11 +123,11 @@ class GridFieldFilterHeader implements GridField_HTMLProvider, GridField_DataMan
|
|||||||
|
|
||||||
$field = new FieldGroup(
|
$field = new FieldGroup(
|
||||||
$field,
|
$field,
|
||||||
Object::create('GridField_FormAction', $gridField, 'filter', false, 'filter', null)
|
GridField_FormAction::create($gridField, 'filter', false, 'filter', null)
|
||||||
->addExtraClass('ss-gridfield-button-filter')
|
->addExtraClass('ss-gridfield-button-filter')
|
||||||
->setAttribute('title', _t('GridField.Filter', "Filter"))
|
->setAttribute('title', _t('GridField.Filter', "Filter"))
|
||||||
,
|
,
|
||||||
Object::create('GridField_FormAction', $gridField, 'reset', false, 'reset', null)
|
GridField_FormAction::create($gridField, 'reset', false, 'reset', null)
|
||||||
->addExtraClass('ss-gridfield-button-reset')
|
->addExtraClass('ss-gridfield-button-reset')
|
||||||
->setAttribute('title', _t('GridField.ResetFilter', "Reset"))
|
->setAttribute('title', _t('GridField.ResetFilter', "Reset"))
|
||||||
);
|
);
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
form.addClass('loading');
|
form.addClass('loading');
|
||||||
|
|
||||||
$.ajax($.extend({}, {
|
$.ajax($.extend({}, {
|
||||||
headers: {"X-Get-Fragment" : 'CurrentField'},
|
headers: {"X-Pjax" : 'CurrentField'},
|
||||||
type: "POST",
|
type: "POST",
|
||||||
url: this.data('url'),
|
url: this.data('url'),
|
||||||
dataType: 'html',
|
dataType: 'html',
|
||||||
@ -252,7 +252,7 @@
|
|||||||
var suggestionUrl = $(searchField).attr('data-search-url').substr(1,$(searchField).attr('data-search-url').length-2);
|
var suggestionUrl = $(searchField).attr('data-search-url').substr(1,$(searchField).attr('data-search-url').length-2);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
headers: {
|
headers: {
|
||||||
"X-Get-Fragment" : 'Partial'
|
"X-Pjax" : 'Partial'
|
||||||
},
|
},
|
||||||
type: "GET",
|
type: "GET",
|
||||||
url: suggestionUrl+'/'+request.term,
|
url: suggestionUrl+'/'+request.term,
|
||||||
|
@ -340,7 +340,7 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
|
|||||||
redraw: function(setDefaults) {
|
redraw: function(setDefaults) {
|
||||||
this._super();
|
this._super();
|
||||||
|
|
||||||
var linkType = this.find(':input[name=LinkType]:checked').val(), list = ['internal', 'external', 'file', 'email'], i, item;
|
var linkType = this.find(':input[name=LinkType]:checked').val(), list = ['internal', 'external', 'file', 'email'];
|
||||||
|
|
||||||
// If we haven't selected an existing link, then just make sure we default to "internal" for the link type.
|
// If we haven't selected an existing link, then just make sure we default to "internal" for the link type.
|
||||||
if(!linkType) {
|
if(!linkType) {
|
||||||
@ -351,11 +351,17 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
|
|||||||
this.addAnchorSelector();
|
this.addAnchorSelector();
|
||||||
|
|
||||||
// Toggle field visibility and state based on type selection
|
// Toggle field visibility and state based on type selection
|
||||||
for(i=0;item==list[i];i++) jQuery(this.find('.field#' + item)).toggle(item == linkType);
|
this.find('.field').hide();
|
||||||
jQuery(this.find('.field#Anchor')).toggle(linkType == 'internal' || linkType == 'anchor');
|
this.find('.field#LinkType').show();
|
||||||
jQuery(this.find('.field#AnchorSelector')).toggle(linkType=='anchor');
|
this.find('.field#' + linkType).show();
|
||||||
jQuery(this.find('.field#AnchorRefresh')).toggle(linkType=='anchor');
|
if(linkType == 'internal' || linkType == 'anchor') this.find('.field#Anchor').show();
|
||||||
|
if(linkType == 'anchor') {
|
||||||
|
this.find('.field#AnchorSelector').show();
|
||||||
|
this.find('.field#AnchorRefresh').show();
|
||||||
|
}
|
||||||
|
|
||||||
this.find(':input[name=TargetBlank]').attr('disabled', (linkType == 'email'));
|
this.find(':input[name=TargetBlank]').attr('disabled', (linkType == 'email'));
|
||||||
|
|
||||||
if(typeof setDefaults == 'undefined' || setDefaults) {
|
if(typeof setDefaults == 'undefined' || setDefaults) {
|
||||||
this.find(':input[name=TargetBlank]').attr('checked', (linkType == 'file'));
|
this.find(':input[name=TargetBlank]').attr('checked', (linkType == 'file'));
|
||||||
}
|
}
|
||||||
@ -811,8 +817,8 @@ ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
|
|||||||
return {
|
return {
|
||||||
'src' : this.find(':input[name=URL]').val(),
|
'src' : this.find(':input[name=URL]').val(),
|
||||||
'alt' : this.find(':input[name=AltText]').val(),
|
'alt' : this.find(':input[name=AltText]').val(),
|
||||||
'width' : width ? parseInt(width, 10) + "px" : null,
|
'width' : width ? parseInt(width, 10) : null,
|
||||||
'height' : height ? parseInt(height, 10) + "px" : null,
|
'height' : height ? parseInt(height, 10) : null,
|
||||||
'title' : this.find(':input[name=Title]').val(),
|
'title' : this.find(':input[name=Title]').val(),
|
||||||
'class' : this.find(':input[name=CSSClass]').val()
|
'class' : this.find(':input[name=CSSClass]').val()
|
||||||
};
|
};
|
||||||
|
7
main.php
7
main.php
@ -1,9 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/************************************************************************************
|
/************************************************************************************
|
||||||
************************************************************************************
|
************************************************************************************
|
||||||
** **
|
** **
|
||||||
** If you can read this text in your browser then you don't have PHP installed. **
|
** If you can read this text in your browser then you don't have PHP installed. **
|
||||||
** Please install PHP 5.0 or higher, preferably PHP 5.2 or 5.3. **
|
** Please install PHP 5.3 or higher. **
|
||||||
** **
|
** **
|
||||||
************************************************************************************
|
************************************************************************************
|
||||||
************************************************************************************/
|
************************************************************************************/
|
||||||
@ -12,8 +13,10 @@
|
|||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage core
|
* @subpackage core
|
||||||
*/
|
*/
|
||||||
|
$majorVersion = strtok(phpversion(),'.');
|
||||||
|
$minorVersion = strtok('.');
|
||||||
|
|
||||||
if(version_compare(phpversion(), 5, '<')) {
|
if($majorVersion < 5 || ($majorVersion == 5 && $minorVersion < 3)) {
|
||||||
header("HTTP/1.1 500 Server Error");
|
header("HTTP/1.1 500 Server Error");
|
||||||
echo str_replace('$PHPVersion', phpversion(), file_get_contents("dev/install/php5-required.html"));
|
echo str_replace('$PHPVersion', phpversion(), file_get_contents("dev/install/php5-required.html"));
|
||||||
die();
|
die();
|
||||||
|
@ -90,7 +90,7 @@ class Aggregate extends ViewableData {
|
|||||||
* This gets the aggregate function
|
* This gets the aggregate function
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function XML_val($name, $args) {
|
public function XML_val($name, $args = null, $cache = false) {
|
||||||
$func = strtoupper( strpos($name, 'get') === 0 ? substr($name, 3) : $name );
|
$func = strtoupper( strpos($name, 'get') === 0 ? substr($name, 3) : $name );
|
||||||
$attribute = $args ? $args[0] : 'ID';
|
$attribute = $args ? $args[0] : 'ID';
|
||||||
|
|
||||||
|
@ -14,18 +14,6 @@ class ArrayList extends ViewableData implements SS_List, SS_Filterable, SS_Sorta
|
|||||||
*/
|
*/
|
||||||
protected $items;
|
protected $items;
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Synonym of the constructor. Can be chained with literate methods.
|
|
||||||
* ArrayList::create("SiteTree")->sort("Title") is legal, but
|
|
||||||
* new ArrayList("SiteTree")->sort("Title") is not.
|
|
||||||
*
|
|
||||||
* @param array $items - an initial array to fill this object with
|
|
||||||
*/
|
|
||||||
public static function create(array $items = array()) {
|
|
||||||
return new ArrayList($items);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param array $items - an initial array to fill this object with
|
* @param array $items - an initial array to fill this object with
|
||||||
|
@ -131,7 +131,7 @@ abstract class DataExtension extends Extension {
|
|||||||
* @return array Returns a map where the keys are db, has_one, etc, and
|
* @return array Returns a map where the keys are db, has_one, etc, and
|
||||||
* the values are additional fields/relations to be defined.
|
* the values are additional fields/relations to be defined.
|
||||||
*/
|
*/
|
||||||
function extraStatics($class=null, $extension=null) {
|
function extraStatics($class = null, $extension = null) {
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,17 +27,6 @@ class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Sortab
|
|||||||
* @var DataModel
|
* @var DataModel
|
||||||
*/
|
*/
|
||||||
protected $model;
|
protected $model;
|
||||||
|
|
||||||
/**
|
|
||||||
* Synonym of the constructor. Can be chained with literate methods.
|
|
||||||
* DataList::create("SiteTree")->sort("Title") is legal, but
|
|
||||||
* new DataList("SiteTree")->sort("Title") is not.
|
|
||||||
*
|
|
||||||
* @param string $dataClass - The DataObject class to query.
|
|
||||||
*/
|
|
||||||
public static function create($dataClass) {
|
|
||||||
return new DataList($dataClass);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new DataList.
|
* Create a new DataList.
|
||||||
@ -668,6 +657,10 @@ class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Sortab
|
|||||||
return singleton($this->dataClass)->$relationName()->forForeignID($ids);
|
return singleton($this->dataClass)->$relationName()->forForeignID($ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function dbObject($fieldName) {
|
||||||
|
return singleton($this->dataClass)->dbObject($fieldName);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a number of items to the component set.
|
* Add a number of items to the component set.
|
||||||
*
|
*
|
||||||
|
@ -1092,7 +1092,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
|
|
||||||
// if database column doesn't correlate to a DBField instance...
|
// if database column doesn't correlate to a DBField instance...
|
||||||
if(!$fieldObj) {
|
if(!$fieldObj) {
|
||||||
$fieldObj = DBField::create('Varchar', $this->record[$fieldName], $fieldName);
|
$fieldObj = DBField::create_field('Varchar', $this->record[$fieldName], $fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Both CompositeDBFields and regular fields need to be repopulated
|
// Both CompositeDBFields and regular fields need to be repopulated
|
||||||
@ -2380,12 +2380,12 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
// Special case for has_one relationships
|
// Special case for has_one relationships
|
||||||
} else if(preg_match('/ID$/', $fieldName) && $this->has_one(substr($fieldName,0,-2))) {
|
} else if(preg_match('/ID$/', $fieldName) && $this->has_one(substr($fieldName,0,-2))) {
|
||||||
$val = (isset($this->record[$fieldName])) ? $this->record[$fieldName] : null;
|
$val = (isset($this->record[$fieldName])) ? $this->record[$fieldName] : null;
|
||||||
return DBField::create('ForeignKey', $val, $fieldName, $this);
|
return DBField::create_field('ForeignKey', $val, $fieldName, $this);
|
||||||
|
|
||||||
// Special case for ClassName
|
// Special case for ClassName
|
||||||
} else if($fieldName == 'ClassName') {
|
} else if($fieldName == 'ClassName') {
|
||||||
$val = get_class($this);
|
$val = get_class($this);
|
||||||
return DBField::create('Varchar', $val, $fieldName, $this);
|
return DBField::create_field('Varchar', $val, $fieldName, $this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2404,7 +2404,12 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
// Traverse dot syntax
|
// Traverse dot syntax
|
||||||
$component = $this;
|
$component = $this;
|
||||||
foreach($parts as $relation) {
|
foreach($parts as $relation) {
|
||||||
$component = $component->$relation();
|
if($component instanceof SS_List) {
|
||||||
|
if(method_exists($component,$relation)) $component = $component->$relation();
|
||||||
|
else $component = $component->relation($relation);
|
||||||
|
} else {
|
||||||
|
$component = $component->$relation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = $component->dbObject($fieldName);
|
$object = $component->dbObject($fieldName);
|
||||||
@ -2436,7 +2441,12 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
// Traverse dot syntax
|
// Traverse dot syntax
|
||||||
$component = $this;
|
$component = $this;
|
||||||
foreach($parts as $relation) {
|
foreach($parts as $relation) {
|
||||||
$component = $component->$relation();
|
if($component instanceof SS_List) {
|
||||||
|
if(method_exists($component,$relation)) $component = $component->$relation();
|
||||||
|
else $component = $component->relation($relation);
|
||||||
|
} else {
|
||||||
|
$component = $component->$relation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $component->$fieldName;
|
return $component->$fieldName;
|
||||||
@ -2654,7 +2664,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
* When false will just clear session-local cached data
|
* When false will just clear session-local cached data
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public function flushCache($persistant=true) {
|
public function flushCache($persistant = true) {
|
||||||
if($persistant) Aggregate::flushCache($this->class);
|
if($persistant) Aggregate::flushCache($this->class);
|
||||||
|
|
||||||
if($this->class == 'DataObject') {
|
if($this->class == 'DataObject') {
|
||||||
@ -3342,4 +3352,4 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -674,12 +674,12 @@ class Hierarchy extends DataExtension {
|
|||||||
self::$expanded = array();
|
self::$expanded = array();
|
||||||
self::$treeOpened = array();
|
self::$treeOpened = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
function reset() {
|
public static function reset() {
|
||||||
self::$marked = array();
|
self::$marked = array();
|
||||||
self::$expanded = array();
|
self::$expanded = array();
|
||||||
self::$treeOpened = array();
|
self::$treeOpened = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,8 +73,8 @@ class Image extends File {
|
|||||||
parent::defineMethods();
|
parent::defineMethods();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCMSFields() {
|
function getCMSFields($params = null) {
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields($params);
|
||||||
|
|
||||||
$urlLink = "<div class='field readonly'>";
|
$urlLink = "<div class='field readonly'>";
|
||||||
$urlLink .= "<label class='left'>"._t('AssetTableField.URL','URL')."</label>";
|
$urlLink .= "<label class='left'>"._t('AssetTableField.URL','URL')."</label>";
|
||||||
@ -153,7 +153,7 @@ class Image extends File {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Generate default filename
|
// Generate default filename
|
||||||
$nameFilter = Object::create('FileNameFilter');
|
$nameFilter = FileNameFilter::create();
|
||||||
$file = $nameFilter->filter($tmpFile['name']);
|
$file = $nameFilter->filter($tmpFile['name']);
|
||||||
if(!$file) $file = "file.jpg";
|
if(!$file) $file = "file.jpg";
|
||||||
|
|
||||||
|
@ -12,24 +12,6 @@ class ManyManyList extends RelationList {
|
|||||||
protected $foreignKey, $foreignID;
|
protected $foreignKey, $foreignID;
|
||||||
|
|
||||||
protected $extraFields;
|
protected $extraFields;
|
||||||
|
|
||||||
/**
|
|
||||||
* Synonym of the constructor. Can be chained with literate methods.
|
|
||||||
* ManyManyList::create("Group","Member","ID", "GroupID")->sort("Title") is legal, but
|
|
||||||
* new ManyManyList("Group","Member","ID", "GroupID")->sort("Title") is not.
|
|
||||||
*
|
|
||||||
* @param string $dataClass The class of the DataObjects that this will list.
|
|
||||||
* @param string $joinTable The name of the table whose entries define the content of this many_many relation.
|
|
||||||
* @param string $localKey The key in the join table that maps to the dataClass' PK.
|
|
||||||
* @param string $foreignKey The key in the join table that maps to joined class' PK.
|
|
||||||
* @param string $extraFields A map of field => fieldtype of extra fields on the join table.
|
|
||||||
*
|
|
||||||
* @see ManyManyList::__construct();
|
|
||||||
* @example ManyManyList::create('Group','Group_Members', 'GroupID', 'MemberID');
|
|
||||||
*/
|
|
||||||
public static function create($dataClass, $joinTable, $localKey, $foreignKey, $extraFields = array()) {
|
|
||||||
return new ManyManyList($dataClass, $joinTable, $localKey, $foreignKey, $extraFields = array());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new ManyManyList object.
|
* Create a new ManyManyList object.
|
||||||
|
@ -554,7 +554,7 @@ class SQLQuery {
|
|||||||
* Return the number of rows in this query if the limit were removed. Useful in paged data sets.
|
* Return the number of rows in this query if the limit were removed. Useful in paged data sets.
|
||||||
* @return int
|
* @return int
|
||||||
*/
|
*/
|
||||||
function unlimitedRowCount( $column = null) {
|
function unlimitedRowCount($column = null) {
|
||||||
// we can't clear the select if we're relying on its output by a HAVING clause
|
// we can't clear the select if we're relying on its output by a HAVING clause
|
||||||
if(count($this->having)) {
|
if(count($this->having)) {
|
||||||
$records = $this->execute();
|
$records = $this->execute();
|
||||||
|
@ -13,17 +13,13 @@
|
|||||||
* @package sapphire
|
* @package sapphire
|
||||||
* @subpackage model
|
* @subpackage model
|
||||||
*/
|
*/
|
||||||
class Transliterator {
|
class Transliterator extends Object {
|
||||||
/**
|
/**
|
||||||
* Allow the use of iconv() to perform transliteration. Set to false to disable.
|
* Allow the use of iconv() to perform transliteration. Set to false to disable.
|
||||||
* Even if this variable is true, iconv() won't be used if it's not installed.
|
* Even if this variable is true, iconv() won't be used if it's not installed.
|
||||||
*/
|
*/
|
||||||
static $use_iconv = false;
|
static $use_iconv = false;
|
||||||
|
|
||||||
function __construct() {
|
|
||||||
// A constructor is necessary for Object::create() to work
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert the given utf8 string to a safe ASCII source
|
* Convert the given utf8 string to a safe ASCII source
|
||||||
*/
|
*/
|
||||||
|
@ -14,12 +14,7 @@
|
|||||||
*
|
*
|
||||||
* See {@link FileNameFilter} for similar implementation for filesystem-based URLs.
|
* See {@link FileNameFilter} for similar implementation for filesystem-based URLs.
|
||||||
*/
|
*/
|
||||||
class URLSegmentFilter {
|
class URLSegmentFilter extends Object {
|
||||||
|
|
||||||
/**
|
|
||||||
* Necessary to support {@link Object::create()}
|
|
||||||
*/
|
|
||||||
function __construct() {}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var Boolean
|
* @var Boolean
|
||||||
@ -104,7 +99,7 @@ class URLSegmentFilter {
|
|||||||
*/
|
*/
|
||||||
function getTransliterator() {
|
function getTransliterator() {
|
||||||
if($this->transliterator === null && self::$default_use_transliterator) {
|
if($this->transliterator === null && self::$default_use_transliterator) {
|
||||||
$this->transliterator = Object::create('Transliterator');
|
$this->transliterator = Transliterator::create();
|
||||||
}
|
}
|
||||||
return $this->transliterator;
|
return $this->transliterator;
|
||||||
}
|
}
|
||||||
|
@ -132,7 +132,7 @@ class Versioned extends DataExtension {
|
|||||||
* Augment the the SQLQuery that is created by the DataQuery
|
* Augment the the SQLQuery that is created by the DataQuery
|
||||||
* @todo Should this all go into VersionedDataQuery?
|
* @todo Should this all go into VersionedDataQuery?
|
||||||
*/
|
*/
|
||||||
function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery) {
|
function augmentSQL(SQLQuery &$query, DataQuery &$dataQuery = null) {
|
||||||
$baseTable = ClassInfo::baseDataClass($dataQuery->dataClass());
|
$baseTable = ClassInfo::baseDataClass($dataQuery->dataClass());
|
||||||
|
|
||||||
switch($dataQuery->getQueryParam('Versioned.mode')) {
|
switch($dataQuery->getQueryParam('Versioned.mode')) {
|
||||||
|
@ -25,13 +25,13 @@
|
|||||||
* if($this->getStreetName()) {
|
* if($this->getStreetName()) {
|
||||||
* $manipulation['fields']["{$this->name}Name"] = $this->prepValueForDB($this->getStreetName());
|
* $manipulation['fields']["{$this->name}Name"] = $this->prepValueForDB($this->getStreetName());
|
||||||
* } else {
|
* } else {
|
||||||
* $manipulation['fields']["{$this->name}Name"] = DBField::create('Varchar', $this->getStreetName())->nullValue();
|
* $manipulation['fields']["{$this->name}Name"] = DBField::create_field('Varchar', $this->getStreetName())->nullValue();
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* if($this->getStreetNumber()) {
|
* if($this->getStreetNumber()) {
|
||||||
* $manipulation['fields']["{$this->name}Number"] = $this->prepValueForDB($this->getStreetNumber());
|
* $manipulation['fields']["{$this->name}Number"] = $this->prepValueForDB($this->getStreetNumber());
|
||||||
* } else {
|
* } else {
|
||||||
* $manipulation['fields']["{$this->name}Number"] = DBField::create('Int', $this->getStreetNumber())->nullValue();
|
* $manipulation['fields']["{$this->name}Number"] = DBField::create_field('Int', $this->getStreetNumber())->nullValue();
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
|
@ -41,7 +41,7 @@ class Currency extends Decimal {
|
|||||||
else return $val;
|
else return $val;
|
||||||
}
|
}
|
||||||
|
|
||||||
function setValue($value) {
|
function setValue($value, $record = null) {
|
||||||
$matches = null;
|
$matches = null;
|
||||||
if(is_numeric($value)) {
|
if(is_numeric($value)) {
|
||||||
$this->value = $value;
|
$this->value = $value;
|
||||||
|
@ -63,11 +63,18 @@ abstract class DBField extends ViewableData {
|
|||||||
parent::__construct();
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static function create() {
|
||||||
|
Deprecation::notice('3.0', 'DBField::create_field() is deprecated as it clashes with Object::create(). Use DBField::create_field() instead.');
|
||||||
|
|
||||||
|
return call_user_func_array(array('DBField', 'create_field'), func_get_args());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a DBField object that's not bound to any particular field.
|
* Create a DBField object that's not bound to any particular field.
|
||||||
* Useful for accessing the classes behaviour for other parts of your code.
|
* Useful for accessing the classes behaviour for other parts of your code.
|
||||||
*/
|
*/
|
||||||
static function create($className, $value, $name = null, $object = null) {
|
static function create_field($className, $value, $name = null, $object = null) {
|
||||||
$dbField = Object::create($className, $name, $object);
|
$dbField = Object::create($className, $name, $object);
|
||||||
$dbField->setValue($value, null, false);
|
$dbField->setValue($value, null, false);
|
||||||
return $dbField;
|
return $dbField;
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
*/
|
*/
|
||||||
class Date extends DBField {
|
class Date extends DBField {
|
||||||
|
|
||||||
function setValue($value) {
|
function setValue($value, $record = null) {
|
||||||
if($value === false || $value === null || (is_string($value) && !strlen($value))) {
|
if($value === false || $value === null || (is_string($value) && !strlen($value))) {
|
||||||
// don't try to evaluate empty values with strtotime() below, as it returns "1970-01-01" when it should be saved as NULL in database
|
// don't try to evaluate empty values with strtotime() below, as it returns "1970-01-01" when it should be saved as NULL in database
|
||||||
$this->value = null;
|
$this->value = null;
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
*/
|
*/
|
||||||
class SS_Datetime extends Date {
|
class SS_Datetime extends Date {
|
||||||
|
|
||||||
function setValue($value) {
|
function setValue($value, $record = null) {
|
||||||
if($value === false || $value === null || (is_string($value) && !strlen($value))) {
|
if($value === false || $value === null || (is_string($value) && !strlen($value))) {
|
||||||
// don't try to evaluate empty values with strtotime() below, as it returns "1970-01-01" when it should be saved as NULL in database
|
// don't try to evaluate empty values with strtotime() below, as it returns "1970-01-01" when it should be saved as NULL in database
|
||||||
$this->value = null;
|
$this->value = null;
|
||||||
@ -96,7 +96,7 @@ class SS_Datetime extends Date {
|
|||||||
if(self::$mock_now) {
|
if(self::$mock_now) {
|
||||||
return self::$mock_now;
|
return self::$mock_now;
|
||||||
} else {
|
} else {
|
||||||
return DBField::create('SS_Datetime', date('Y-m-d H:i:s'));
|
return DBField::create_field('SS_Datetime', date('Y-m-d H:i:s'));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,7 +111,7 @@ class SS_Datetime extends Date {
|
|||||||
if($datetime instanceof SS_Datetime) {
|
if($datetime instanceof SS_Datetime) {
|
||||||
self::$mock_now = $datetime;
|
self::$mock_now = $datetime;
|
||||||
} elseif(is_string($datetime)) {
|
} elseif(is_string($datetime)) {
|
||||||
self::$mock_now = DBField::create('SS_Datetime', $datetime);
|
self::$mock_now = DBField::create_field('SS_Datetime', $datetime);
|
||||||
} else {
|
} else {
|
||||||
throw new Exception('SS_Datetime::set_mock_now(): Wrong format: ' . $datetime);
|
throw new Exception('SS_Datetime::set_mock_now(): Wrong format: ' . $datetime);
|
||||||
}
|
}
|
||||||
|
@ -87,10 +87,10 @@ class Enum extends DBField {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function Lower() {
|
function Lower() {
|
||||||
return StringField::Lower();
|
return StringField::LowerCase();
|
||||||
}
|
}
|
||||||
function Upper() {
|
function Upper() {
|
||||||
return StringField::Upper();
|
return StringField::UpperCase();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -136,7 +136,7 @@ class HTMLText extends Text {
|
|||||||
return new HtmlEditorField($this->name, $title);
|
return new HtmlEditorField($this->name, $title);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function scaffoldSearchField($title = null) {
|
public function scaffoldSearchField($title = null, $params = null) {
|
||||||
return new TextField($this->name, $title);
|
return new TextField($this->name, $title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,13 +84,13 @@ class Money extends DBField implements CompositeDBField {
|
|||||||
if($this->getCurrency()) {
|
if($this->getCurrency()) {
|
||||||
$manipulation['fields'][$this->name.'Currency'] = $this->prepValueForDB($this->getCurrency());
|
$manipulation['fields'][$this->name.'Currency'] = $this->prepValueForDB($this->getCurrency());
|
||||||
} else {
|
} else {
|
||||||
$manipulation['fields'][$this->name.'Currency'] = DBField::create('Varchar', $this->getCurrency())->nullValue();
|
$manipulation['fields'][$this->name.'Currency'] = DBField::create_field('Varchar', $this->getCurrency())->nullValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->getAmount()) {
|
if($this->getAmount()) {
|
||||||
$manipulation['fields'][$this->name.'Amount'] = $this->getAmount();
|
$manipulation['fields'][$this->name.'Amount'] = $this->getAmount();
|
||||||
} else {
|
} else {
|
||||||
$manipulation['fields'][$this->name.'Amount'] = DBField::create('Decimal', $this->getAmount())->nullValue();
|
$manipulation['fields'][$this->name.'Amount'] = DBField::create_field('Decimal', $this->getAmount())->nullValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,9 +140,11 @@ $gf_grid_x: 16px;
|
|||||||
width:$gf_grid_x;
|
width:$gf_grid_x;
|
||||||
height:20px; //min height to fit the edit icon
|
height:20px; //min height to fit the edit icon
|
||||||
text-indent:9999em;
|
text-indent:9999em;
|
||||||
|
overflow: hidden;
|
||||||
|
vertical-align: middle;
|
||||||
background: url(../images/icons/document--pencil.png) no-repeat 0 1px;
|
background: url(../images/icons/document--pencil.png) no-repeat 0 1px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tfoot {
|
tfoot {
|
||||||
@ -479,4 +481,4 @@ $gf_grid_x: 16px;
|
|||||||
border-left: 1px solid $gf_colour_border;
|
border-left: 1px solid $gf_colour_border;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,9 +37,8 @@ abstract class Authenticator extends Object {
|
|||||||
* @return bool|Member Returns FALSE if authentication fails, otherwise
|
* @return bool|Member Returns FALSE if authentication fails, otherwise
|
||||||
* the member object
|
* the member object
|
||||||
*/
|
*/
|
||||||
public abstract static function authenticate($RAW_data,
|
public static function authenticate($RAW_data, Form $form = null) {
|
||||||
Form $form = null);
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method that creates the login form for this authentication method
|
* Method that creates the login form for this authentication method
|
||||||
@ -49,7 +48,8 @@ abstract class Authenticator extends Object {
|
|||||||
* @return Form Returns the login form to use with this authentication
|
* @return Form Returns the login form to use with this authentication
|
||||||
* method
|
* method
|
||||||
*/
|
*/
|
||||||
public abstract static function get_login_form(Controller $controller);
|
public static function get_login_form(Controller $controller) {
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -57,7 +57,8 @@ abstract class Authenticator extends Object {
|
|||||||
*
|
*
|
||||||
* @return string Returns the name of the authentication method.
|
* @return string Returns the name of the authentication method.
|
||||||
*/
|
*/
|
||||||
public abstract static function get_name();
|
public static function get_name() {
|
||||||
|
}
|
||||||
|
|
||||||
public static function register($authenticator) {
|
public static function register($authenticator) {
|
||||||
self::register_authenticator($authenticator);
|
self::register_authenticator($authenticator);
|
||||||
|
@ -59,15 +59,14 @@ class Group extends DataObject {
|
|||||||
*
|
*
|
||||||
* @return FieldList
|
* @return FieldList
|
||||||
*/
|
*/
|
||||||
public function getCMSFields() {
|
public function getCMSFields($params = null) {
|
||||||
Requirements::javascript(SAPPHIRE_DIR . '/javascript/PermissionCheckboxSetField.js');
|
Requirements::javascript(SAPPHIRE_DIR . '/javascript/PermissionCheckboxSetField.js');
|
||||||
|
|
||||||
$fields = new FieldList(
|
$fields = new FieldList(
|
||||||
new TabSet("Root",
|
new TabSet("Root",
|
||||||
new Tab('Members', _t('SecurityAdmin.MEMBERS', 'Members'),
|
new Tab('Members', _t('SecurityAdmin.MEMBERS', 'Members'),
|
||||||
new TextField("Title", $this->fieldLabel('Title')),
|
new TextField("Title", $this->fieldLabel('Title')),
|
||||||
$parentidfield = Object::create('DropdownField',
|
$parentidfield = DropdownField::create( 'ParentID',
|
||||||
'ParentID',
|
|
||||||
$this->fieldLabel('Parent'),
|
$this->fieldLabel('Parent'),
|
||||||
DataList::create('Group')->exclude('ID', $this->ID)->map('ID', 'Breadcrumbs')
|
DataList::create('Group')->exclude('ID', $this->ID)->map('ID', 'Breadcrumbs')
|
||||||
)->setEmptyString(' ')
|
)->setEmptyString(' ')
|
||||||
@ -101,7 +100,7 @@ class Group extends DataObject {
|
|||||||
$config->getComponentByType('GridFieldAddExistingAutocompleter')
|
$config->getComponentByType('GridFieldAddExistingAutocompleter')
|
||||||
->setResultsFormat('$Title ($Email)')->setSearchFields(array('FirstName', 'Surname', 'Email'));
|
->setResultsFormat('$Title ($Email)')->setSearchFields(array('FirstName', 'Surname', 'Email'));
|
||||||
$config->getComponentByType('GridFieldDetailForm')->setValidator(new Member_Validator());
|
$config->getComponentByType('GridFieldDetailForm')->setValidator(new Member_Validator());
|
||||||
$memberList = Object::create('GridField', 'Members',false, $this->Members(), $config)->addExtraClass('members_grid');
|
$memberList = GridField::create('Members',false, $this->Members(), $config)->addExtraClass('members_grid');
|
||||||
// @todo Implement permission checking on GridField
|
// @todo Implement permission checking on GridField
|
||||||
//$memberList->setPermissions(array('edit', 'delete', 'export', 'add', 'inlineadd'));
|
//$memberList->setPermissions(array('edit', 'delete', 'export', 'add', 'inlineadd'));
|
||||||
$fields->addFieldToTab('Root.Members', $memberList);
|
$fields->addFieldToTab('Root.Members', $memberList);
|
||||||
@ -165,7 +164,7 @@ class Group extends DataObject {
|
|||||||
$inheritedRoleIDs = array();
|
$inheritedRoleIDs = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
$rolesField = Object::create('ListboxField', 'Roles', false, $allRoles->map()->toArray())
|
$rolesField = ListboxField::create('Roles', false, $allRoles->map()->toArray())
|
||||||
->setMultiple(true)
|
->setMultiple(true)
|
||||||
->setDefaultItems($groupRoleIDs)
|
->setDefaultItems($groupRoleIDs)
|
||||||
->setAttribute('data-placeholder', _t('Group.AddRole', 'Add a role for this group'))
|
->setAttribute('data-placeholder', _t('Group.AddRole', 'Add a role for this group'))
|
||||||
@ -338,17 +337,21 @@ class Group extends DataObject {
|
|||||||
if(!$this->Code) $this->setCode($this->Title);
|
if(!$this->Code) $this->setCode($this->Title);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function onAfterDelete() {
|
function onBeforeDelete() {
|
||||||
parent::onAfterDelete();
|
parent::onBeforeDelete();
|
||||||
|
|
||||||
|
// if deleting this group, delete it's children as well
|
||||||
|
foreach($this->Groups() as $group) {
|
||||||
|
$group->delete();
|
||||||
|
}
|
||||||
|
|
||||||
// Delete associated permissions
|
// Delete associated permissions
|
||||||
$permissions = $this->Permissions();
|
foreach($this->Permissions() as $permission) {
|
||||||
foreach ( $permissions as $permission ) {
|
|
||||||
$permission->delete();
|
$permission->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for permission-code CMS_ACCESS_SecurityAdmin.
|
* Checks for permission-code CMS_ACCESS_SecurityAdmin.
|
||||||
* If the group has ADMIN permissions, it requires the user to have ADMIN permissions as well.
|
* If the group has ADMIN permissions, it requires the user to have ADMIN permissions as well.
|
||||||
|
@ -151,7 +151,7 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
if(!$admins) {
|
if(!$admins) {
|
||||||
// Leave 'Email' and 'Password' are not set to avoid creating
|
// Leave 'Email' and 'Password' are not set to avoid creating
|
||||||
// persistent logins in the database. See Security::setDefaultAdmin().
|
// persistent logins in the database. See Security::setDefaultAdmin().
|
||||||
$admin = Object::create('Member');
|
$admin = Member::create();
|
||||||
$admin->FirstName = _t('Member.DefaultAdminFirstname', 'Default Admin');
|
$admin->FirstName = _t('Member.DefaultAdminFirstname', 'Default Admin');
|
||||||
$admin->write();
|
$admin->write();
|
||||||
$admin->Groups()->add($adminGroup);
|
$admin->Groups()->add($adminGroup);
|
||||||
@ -480,13 +480,13 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
function sendInfo($type = 'signup', $data = null) {
|
function sendInfo($type = 'signup', $data = null) {
|
||||||
switch($type) {
|
switch($type) {
|
||||||
case "signup":
|
case "signup":
|
||||||
$e = Object::create('Member_SignupEmail');
|
$e = Member_SignupEmail::create();
|
||||||
break;
|
break;
|
||||||
case "changePassword":
|
case "changePassword":
|
||||||
$e = Object::create('Member_ChangePasswordEmail');
|
$e = Member_ChangePasswordEmail::create();
|
||||||
break;
|
break;
|
||||||
case "forgotPassword":
|
case "forgotPassword":
|
||||||
$e = Object::create('Member_ForgotPasswordEmail');
|
$e = Member_ForgotPasswordEmail::create();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1084,7 +1084,7 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
* @return FieldList Return a FieldList of fields that would appropriate for
|
* @return FieldList Return a FieldList of fields that would appropriate for
|
||||||
* editing this member.
|
* editing this member.
|
||||||
*/
|
*/
|
||||||
public function getCMSFields() {
|
public function getCMSFields($params = null) {
|
||||||
require_once('Zend/Date.php');
|
require_once('Zend/Date.php');
|
||||||
|
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields();
|
||||||
@ -1134,7 +1134,7 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
$groupsMap = DataList::create('Group')->map('ID', 'Breadcrumbs')->toArray();
|
$groupsMap = DataList::create('Group')->map('ID', 'Breadcrumbs')->toArray();
|
||||||
asort($groupsMap);
|
asort($groupsMap);
|
||||||
$fields->addFieldToTab('Root.Main',
|
$fields->addFieldToTab('Root.Main',
|
||||||
Object::create('ListboxField', 'DirectGroups', singleton('Group')->i18n_plural_name())
|
ListboxField::create('DirectGroups', singleton('Group')->i18n_plural_name())
|
||||||
->setMultiple(true)->setSource($groupsMap)
|
->setMultiple(true)->setSource($groupsMap)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -33,8 +33,8 @@ class PermissionRole extends DataObject {
|
|||||||
|
|
||||||
static $plural_name = 'Roles';
|
static $plural_name = 'Roles';
|
||||||
|
|
||||||
function getCMSFields() {
|
function getCMSFields($params = null) {
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields($params);
|
||||||
|
|
||||||
$fields->removeFieldFromTab('Root', 'Codes');
|
$fields->removeFieldFromTab('Root', 'Codes');
|
||||||
$fields->removeFieldFromTab('Root', 'Groups');
|
$fields->removeFieldFromTab('Root', 'Groups');
|
||||||
|
@ -448,8 +448,7 @@ class Security extends Controller {
|
|||||||
* @return Form Returns the lost password form
|
* @return Form Returns the lost password form
|
||||||
*/
|
*/
|
||||||
public function LostPasswordForm() {
|
public function LostPasswordForm() {
|
||||||
return Object::create('MemberLoginForm',
|
return MemberLoginForm::create( $this,
|
||||||
$this,
|
|
||||||
'LostPasswordForm',
|
'LostPasswordForm',
|
||||||
new FieldList(
|
new FieldList(
|
||||||
new EmailField('Email', _t('Member.EMAIL', 'Email'))
|
new EmailField('Email', _t('Member.EMAIL', 'Email'))
|
||||||
|
@ -544,7 +544,7 @@ class RestfulServerTest_AuthorRating extends DataObject implements TestOnly {
|
|||||||
static $db = array(
|
static $db = array(
|
||||||
'Rating' => 'Int',
|
'Rating' => 'Int',
|
||||||
'SecretField' => 'Text',
|
'SecretField' => 'Text',
|
||||||
'WriteProtectedField' => 'Text'
|
'WriteProtectedField' => 'Text',
|
||||||
);
|
);
|
||||||
|
|
||||||
static $has_one = array(
|
static $has_one = array(
|
||||||
|
@ -230,4 +230,16 @@ class HTTPRequestTest extends SapphireTest {
|
|||||||
'Nested GET parameters should supplement POST parameters'
|
'Nested GET parameters should supplement POST parameters'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testIsAjax() {
|
||||||
|
$req = new SS_HTTPRequest('GET', '/', array('ajax' => 0));
|
||||||
|
$this->assertFalse($req->isAjax());
|
||||||
|
|
||||||
|
$req = new SS_HTTPRequest('GET', '/', array('ajax' => 1));
|
||||||
|
$this->assertTrue($req->isAjax());
|
||||||
|
|
||||||
|
$req = new SS_HTTPRequest('GET', '/');
|
||||||
|
$req->addHeader('X-Requested-With', 'XMLHttpRequest');
|
||||||
|
$this->assertTrue($req->isAjax());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
22
tests/control/PjaxResponseNegotiatorTest.php
Normal file
22
tests/control/PjaxResponseNegotiatorTest.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
class PjaxResponseNegotiatorTest extends SapphireTest {
|
||||||
|
|
||||||
|
function testDefaultCallbacks() {
|
||||||
|
$negotiator = new PjaxResponseNegotiator(array(
|
||||||
|
'default' => function() {return 'default response';},
|
||||||
|
));
|
||||||
|
$request = new SS_HTTPRequest('GET', '/'); // not setting pjax header
|
||||||
|
$this->assertEquals('default response', $negotiator->respond($request));
|
||||||
|
}
|
||||||
|
|
||||||
|
function testSelectsFragmentByHeader() {
|
||||||
|
$negotiator = new PjaxResponseNegotiator(array(
|
||||||
|
'default' => function() {return 'default response';},
|
||||||
|
'myfragment' => function() {return 'myfragment response';},
|
||||||
|
));
|
||||||
|
$request = new SS_HTTPRequest('GET', '/');
|
||||||
|
$request->addHeader('X-Pjax', 'myfragment');
|
||||||
|
$this->assertEquals('myfragment response', $negotiator->respond($request));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -329,7 +329,7 @@ class RequestHandlingTest_Controller extends Controller implements TestOnly {
|
|||||||
$this->httpError(404, 'This page does not exist.');
|
$this->httpError(404, 'This page does not exist.');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getViewer(){
|
public function getViewer($action) {
|
||||||
return new SSViewer('BlankPage');
|
return new SSViewer('BlankPage');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -384,7 +384,7 @@ class RequestHandlingTest_FormActionController extends Controller {
|
|||||||
return 'formactionInAllowedActions';
|
return 'formactionInAllowedActions';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getViewer(){
|
public function getViewer($action = null) {
|
||||||
return new SSViewer('BlankPage');
|
return new SSViewer('BlankPage');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,6 +101,7 @@ class ConvertTest extends SapphireTest {
|
|||||||
$this->assertEquals(3, count($decoded), '3 items in the decoded array');
|
$this->assertEquals(3, count($decoded), '3 items in the decoded array');
|
||||||
$this->assertContains('Bloggs', $decoded, 'Contains "Bloggs" value in decoded array');
|
$this->assertContains('Bloggs', $decoded, 'Contains "Bloggs" value in decoded array');
|
||||||
$this->assertContains('Jones', $decoded, 'Contains "Jones" value in decoded array');
|
$this->assertContains('Jones', $decoded, 'Contains "Jones" value in decoded array');
|
||||||
|
$this->assertContains('Structure', $decoded['My']['Complicated']);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testJSON2Obj() {
|
function testJSON2Obj() {
|
||||||
@ -121,4 +122,4 @@ class ConvertTest extends SapphireTest {
|
|||||||
$this->assertEquals('foos-bar-2', Convert::raw2url('foo\'s [bar] (2)'));
|
$this->assertEquals('foos-bar-2', Convert::raw2url('foo\'s [bar] (2)'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -113,29 +113,34 @@ class ObjectTest extends SapphireTest {
|
|||||||
* Tests that {@link Object::create()} correctly passes all arguments to the new object
|
* Tests that {@link Object::create()} correctly passes all arguments to the new object
|
||||||
*/
|
*/
|
||||||
public function testCreateWithArgs() {
|
public function testCreateWithArgs() {
|
||||||
$createdObj = Object::create('ObjectTest_CreateTest', 'arg1', 'arg2', array(), null, 'arg5');
|
$createdObj = ObjectTest_CreateTest::create('arg1', 'arg2', array(), null, 'arg5');
|
||||||
$this->assertEquals($createdObj->constructArguments, array('arg1', 'arg2', array(), null, 'arg5'));
|
$this->assertEquals($createdObj->constructArguments, array('arg1', 'arg2', array(), null, 'arg5'));
|
||||||
|
|
||||||
$strongObj = Object::strong_create('ObjectTest_CreateTest', 'arg1', 'arg2', array(), null, 'arg5');
|
$strongObj = Object::strong_create('ObjectTest_CreateTest', 'arg1', 'arg2', array(), null, 'arg5');
|
||||||
$this->assertEquals($strongObj->constructArguments, array('arg1', 'arg2', array(), null, 'arg5'));
|
$this->assertEquals($strongObj->constructArguments, array('arg1', 'arg2', array(), null, 'arg5'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCreateLateStaticBinding() {
|
||||||
|
$createdObj = ObjectTest_CreateTest::create('arg1', 'arg2', array(), null, 'arg5');
|
||||||
|
$this->assertEquals($createdObj->constructArguments, array('arg1', 'arg2', array(), null, 'arg5'));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that {@link Object::useCustomClass()} correnctly replaces normal and strong objects
|
* Tests that {@link Object::useCustomClass()} correnctly replaces normal and strong objects
|
||||||
*/
|
*/
|
||||||
public function testUseCustomClass() {
|
public function testUseCustomClass() {
|
||||||
$obj1 = Object::create('ObjectTest_CreateTest');
|
$obj1 = ObjectTest_CreateTest::create();
|
||||||
$this->assertTrue($obj1 instanceof ObjectTest_CreateTest);
|
$this->assertTrue($obj1 instanceof ObjectTest_CreateTest);
|
||||||
|
|
||||||
Object::useCustomClass('ObjectTest_CreateTest', 'ObjectTest_CreateTest2');
|
Object::useCustomClass('ObjectTest_CreateTest', 'ObjectTest_CreateTest2');
|
||||||
$obj2 = Object::create('ObjectTest_CreateTest');
|
$obj2 = ObjectTest_CreateTest::create();
|
||||||
$this->assertTrue($obj2 instanceof ObjectTest_CreateTest2);
|
$this->assertTrue($obj2 instanceof ObjectTest_CreateTest2);
|
||||||
|
|
||||||
$obj2_2 = Object::strong_create('ObjectTest_CreateTest');
|
$obj2_2 = Object::strong_create('ObjectTest_CreateTest');
|
||||||
$this->assertTrue($obj2_2 instanceof ObjectTest_CreateTest);
|
$this->assertTrue($obj2_2 instanceof ObjectTest_CreateTest);
|
||||||
|
|
||||||
Object::useCustomClass('ObjectTest_CreateTest', 'ObjectTest_CreateTest3', true);
|
Object::useCustomClass('ObjectTest_CreateTest', 'ObjectTest_CreateTest3', true);
|
||||||
$obj3 = Object::create('ObjectTest_CreateTest');
|
$obj3 = ObjectTest_CreateTest::create();
|
||||||
$this->assertTrue($obj3 instanceof ObjectTest_CreateTest3);
|
$this->assertTrue($obj3 instanceof ObjectTest_CreateTest3);
|
||||||
|
|
||||||
$obj3_2 = Object::strong_create('ObjectTest_CreateTest');
|
$obj3_2 = Object::strong_create('ObjectTest_CreateTest');
|
||||||
@ -264,12 +269,12 @@ class ObjectTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testParentClass() {
|
public function testParentClass() {
|
||||||
$this->assertEquals(Object::create('ObjectTest_MyObject')->parentClass(), 'Object');
|
$this->assertEquals(ObjectTest_MyObject::create()->parentClass(), 'Object');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testIsA() {
|
public function testIsA() {
|
||||||
$this->assertTrue(Object::create('ObjectTest_MyObject') instanceof Object);
|
$this->assertTrue(ObjectTest_MyObject::create() instanceof Object);
|
||||||
$this->assertTrue(Object::create('ObjectTest_MyObject') instanceof ObjectTest_MyObject);
|
$this->assertTrue(ObjectTest_MyObject::create() instanceof ObjectTest_MyObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,7 +131,7 @@ class CsvBulkLoaderTest extends SapphireTest {
|
|||||||
$this->assertEquals($testPlayer->ContractID, $testContract->ID, 'Creating new has_one relation works');
|
$this->assertEquals($testPlayer->ContractID, $testContract->ID, 'Creating new has_one relation works');
|
||||||
|
|
||||||
// Test nested setting of relation properties
|
// Test nested setting of relation properties
|
||||||
$contractAmount = DBField::create('Currency', $compareRow[5])->RAW();
|
$contractAmount = DBField::create_field('Currency', $compareRow[5])->RAW();
|
||||||
$this->assertEquals($testPlayer->Contract()->Amount, $contractAmount, 'Setting nested values in a relation works');
|
$this->assertEquals($testPlayer->Contract()->Amount, $contractAmount, 'Setting nested values in a relation works');
|
||||||
|
|
||||||
fclose($file);
|
fclose($file);
|
||||||
|
@ -135,7 +135,18 @@ class DateFieldTest extends SapphireTest {
|
|||||||
// $f = new DateField('Date', 'Date', array('day' => 9999, 'month' => 9999, 'year' => 9999));
|
// $f = new DateField('Date', 'Date', array('day' => 9999, 'month' => 9999, 'year' => 9999));
|
||||||
// $this->assertFalse($f->validate(new RequiredFields()));
|
// $this->assertFalse($f->validate(new RequiredFields()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function testValidateEmptyArrayValuesSetsNullForValueObject() {
|
||||||
|
$f = new DateField('Date', 'Date');
|
||||||
|
$f->setConfig('dmyfields', true);
|
||||||
|
|
||||||
|
$f->setValue(array('day' => '', 'month' => '', 'year' => ''));
|
||||||
|
$this->assertNull($f->dataValue());
|
||||||
|
|
||||||
|
$f->setValue(array('day' => null, 'month' => null, 'year' => null));
|
||||||
|
$this->assertNull($f->dataValue());
|
||||||
|
}
|
||||||
|
|
||||||
function testValidateArrayValue() {
|
function testValidateArrayValue() {
|
||||||
$f = new DateField('Date', 'Date');
|
$f = new DateField('Date', 'Date');
|
||||||
$this->assertTrue($f->validateArrayValue(array('day' => 29, 'month' => 03, 'year' => 2003)));
|
$this->assertTrue($f->validateArrayValue(array('day' => 29, 'month' => 03, 'year' => 2003)));
|
||||||
|
@ -128,11 +128,13 @@ class FormScaffolderTest_ArticleExtension extends DataExtension implements TestO
|
|||||||
static $db = array(
|
static $db = array(
|
||||||
'ExtendedField' => 'Varchar'
|
'ExtendedField' => 'Varchar'
|
||||||
);
|
);
|
||||||
function updateCMSFields(&$fields) {
|
|
||||||
|
function updateCMSFields(FieldList $fields) {
|
||||||
$fields->addFieldToTab('Root.Main',
|
$fields->addFieldToTab('Root.Main',
|
||||||
new TextField('AddedExtensionField')
|
new TextField('AddedExtensionField')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DataObject::add_extension('FormScaffolderTest_Article', 'FormScaffolderTest_ArticleExtension');
|
DataObject::add_extension('FormScaffolderTest_Article', 'FormScaffolderTest_ArticleExtension');
|
||||||
|
@ -468,7 +468,7 @@ class FormTest_Controller extends Controller implements TestOnly {
|
|||||||
return $this->redirectBack();
|
return $this->redirectBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getViewer(){
|
function getViewer($action = null) {
|
||||||
return new SSViewer('BlankPage');
|
return new SSViewer('BlankPage');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -505,7 +505,7 @@ class FormTest_ControllerWithSecurityToken extends Controller implements TestOnl
|
|||||||
return $this->redirectBack();
|
return $this->redirectBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getViewer(){
|
function getViewer($action = null) {
|
||||||
return new SSViewer('BlankPage');
|
return new SSViewer('BlankPage');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ class GridFieldAddExistingAutocompleterTest extends FunctionalTest {
|
|||||||
);
|
);
|
||||||
$this->assertFalse($response->isError());
|
$this->assertFalse($response->isError());
|
||||||
$result = Convert::json2array($response->getBody());
|
$result = Convert::json2array($response->getBody());
|
||||||
$this->assertFalse($result);
|
$this->assertEmpty($result, 'The output is either an empty array or boolean FALSE');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testAdd() {
|
function testAdd() {
|
||||||
@ -80,4 +80,4 @@ class GridFieldAddExistingAutocompleterTest_Controller extends Controller implem
|
|||||||
$field = new GridField('testfield', 'testfield', $player->Teams(), $config);
|
$field = new GridField('testfield', 'testfield', $player->Teams(), $config);
|
||||||
return new Form($this, 'Form', new FieldList($field), new FieldList());
|
return new Form($this, 'Form', new FieldList($field), new FieldList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -140,11 +140,11 @@ class GridFieldDetailFormTest_Person extends DataObject implements TestOnly {
|
|||||||
'Categories' => 'GridFieldDetailFormTest_Category'
|
'Categories' => 'GridFieldDetailFormTest_Category'
|
||||||
);
|
);
|
||||||
|
|
||||||
function getCMSFields() {
|
function getCMSFields($params = null) {
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields($params);
|
||||||
// TODO No longer necessary once FormScaffolder uses GridField
|
// TODO No longer necessary once FormScaffolder uses GridField
|
||||||
$fields->replaceField('Categories',
|
$fields->replaceField('Categories',
|
||||||
Object::create('GridField', 'Categories', 'Categories',
|
GridField::create('Categories', 'Categories',
|
||||||
$this->Categories(),
|
$this->Categories(),
|
||||||
GridFieldConfig_RelationEditor::create()
|
GridFieldConfig_RelationEditor::create()
|
||||||
)
|
)
|
||||||
@ -162,11 +162,11 @@ class GridFieldDetailFormTest_PeopleGroup extends DataObject implements TestOnly
|
|||||||
'People' => 'GridFieldDetailFormTest_Person'
|
'People' => 'GridFieldDetailFormTest_Person'
|
||||||
);
|
);
|
||||||
|
|
||||||
function getCMSFields() {
|
function getCMSFields($params = null) {
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields($params);
|
||||||
// TODO No longer necessary once FormScaffolder uses GridField
|
// TODO No longer necessary once FormScaffolder uses GridField
|
||||||
$fields->replaceField('People',
|
$fields->replaceField('People',
|
||||||
Object::create('GridField', 'People', 'People',
|
GridField::create('People', 'People',
|
||||||
$this->People(),
|
$this->People(),
|
||||||
GridFieldConfig_RelationEditor::create()
|
GridFieldConfig_RelationEditor::create()
|
||||||
)
|
)
|
||||||
@ -184,11 +184,11 @@ class GridFieldDetailFormTest_Category extends DataObject implements TestOnly {
|
|||||||
'People' => 'GridFieldDetailFormTest_Person'
|
'People' => 'GridFieldDetailFormTest_Person'
|
||||||
);
|
);
|
||||||
|
|
||||||
function getCMSFields() {
|
function getCMSFields($params = null) {
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields($params);
|
||||||
// TODO No longer necessary once FormScaffolder uses GridField
|
// TODO No longer necessary once FormScaffolder uses GridField
|
||||||
$fields->replaceField('People',
|
$fields->replaceField('People',
|
||||||
Object::create('GridField', 'People', 'People',
|
GridField::create('People', 'People',
|
||||||
$this->People(),
|
$this->People(),
|
||||||
GridFieldConfig_RelationEditor::create()
|
GridFieldConfig_RelationEditor::create()
|
||||||
)
|
)
|
||||||
|
@ -567,21 +567,21 @@ static $many_many = array(
|
|||||||
|
|
||||||
class UploadFieldTest_FileExtension extends DataExtension implements TestOnly {
|
class UploadFieldTest_FileExtension extends DataExtension implements TestOnly {
|
||||||
|
|
||||||
function extraStatics() {
|
function extraStatics($class = null, $extension = null) {
|
||||||
return array(
|
return array(
|
||||||
'has_one' => array('Record' => 'UploadFieldTest_Record')
|
'has_one' => array('Record' => 'UploadFieldTest_Record')
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function canDelete() {
|
function canDelete($member = null) {
|
||||||
if($this->owner->Name == 'nodelete.txt') return false;
|
if($this->owner->Name == 'nodelete.txt') return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function canEdit() {
|
function canEdit($member = null) {
|
||||||
if($this->owner->Name == 'noedit.txt') return false;
|
if($this->owner->Name == 'noedit.txt') return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
function canView() {
|
function canView($member = null) {
|
||||||
if($this->owner->Name == 'noview.txt') return false;
|
if($this->owner->Name == 'noview.txt') return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -655,4 +655,4 @@ class UploadFieldTest_Controller extends Controller implements TestOnly {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -73,13 +73,15 @@ class AggregateTest extends SapphireTest {
|
|||||||
* Test basic aggregation on a passed type
|
* Test basic aggregation on a passed type
|
||||||
*/
|
*/
|
||||||
function testTypeSpecifiedAggregate() {
|
function testTypeSpecifiedAggregate() {
|
||||||
|
$foo = $this->objFromFixture('AggregateTest_Foo', 'foo1');
|
||||||
|
|
||||||
// Template style access
|
// Template style access
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Foo')->XML_val('Max', array('Foo')), 9);
|
$this->assertEquals($foo->Aggregate('AggregateTest_Foo')->XML_val('Max', array('Foo')), 9);
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Fab')->XML_val('Max', array('Fab')), 3);
|
$this->assertEquals($foo->Aggregate('AggregateTest_Fab')->XML_val('Max', array('Fab')), 3);
|
||||||
|
|
||||||
// PHP style access
|
// PHP style access
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Foo')->Max('Foo'), 9);
|
$this->assertEquals($foo->Aggregate('AggregateTest_Foo')->Max('Foo'), 9);
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Fab')->Max('Fab'), 3);
|
$this->assertEquals($foo->Aggregate('AggregateTest_Fab')->Max('Fab'), 3);
|
||||||
}
|
}
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
@ -90,7 +92,7 @@ class AggregateTest extends SapphireTest {
|
|||||||
function testAutoTypeAggregate() {
|
function testAutoTypeAggregate() {
|
||||||
$foo = $this->objFromFixture('AggregateTest_Foo', 'foo1');
|
$foo = $this->objFromFixture('AggregateTest_Foo', 'foo1');
|
||||||
$fab = $this->objFromFixture('AggregateTest_Fab', 'fab1');
|
$fab = $this->objFromFixture('AggregateTest_Fab', 'fab1');
|
||||||
|
|
||||||
// Template style access
|
// Template style access
|
||||||
$this->assertEquals($foo->Aggregate()->XML_val('Max', array('Foo')), 9);
|
$this->assertEquals($foo->Aggregate()->XML_val('Max', array('Foo')), 9);
|
||||||
$this->assertEquals($fab->Aggregate()->XML_val('Max', array('Fab')), 3);
|
$this->assertEquals($fab->Aggregate()->XML_val('Max', array('Fab')), 3);
|
||||||
@ -106,13 +108,15 @@ class AggregateTest extends SapphireTest {
|
|||||||
* @return unknown_type
|
* @return unknown_type
|
||||||
*/
|
*/
|
||||||
function testBaseFieldAggregate() {
|
function testBaseFieldAggregate() {
|
||||||
|
$foo = $this->objFromFixture('AggregateTest_Foo', 'foo1');
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$this->formatDate(DataObject::Aggregate('AggregateTest_Foo')->Max('LastEdited')),
|
$this->formatDate($foo->Aggregate('AggregateTest_Foo')->Max('LastEdited')),
|
||||||
$this->formatDate(DataObject::get_one('AggregateTest_Foo', '', '', '"LastEdited" DESC')->LastEdited)
|
$this->formatDate(DataObject::get_one('AggregateTest_Foo', '', '', '"LastEdited" DESC')->LastEdited)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
$this->formatDate(DataObject::Aggregate('AggregateTest_Foo')->Max('Created')),
|
$this->formatDate($foo->Aggregate('AggregateTest_Foo')->Max('Created')),
|
||||||
$this->formatDate(DataObject::get_one('AggregateTest_Foo', '', '', '"Created" DESC')->Created)
|
$this->formatDate(DataObject::get_one('AggregateTest_Foo', '', '', '"Created" DESC')->Created)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -122,13 +126,14 @@ class AggregateTest extends SapphireTest {
|
|||||||
* Test aggregation takes place on the passed type & it's children only
|
* Test aggregation takes place on the passed type & it's children only
|
||||||
*/
|
*/
|
||||||
function testChildAggregate() {
|
function testChildAggregate() {
|
||||||
|
$foo = $this->objFromFixture('AggregateTest_Foo', 'foo1');
|
||||||
|
|
||||||
// For base classes, aggregate is calculcated on it and all children classes
|
// For base classes, aggregate is calculcated on it and all children classes
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Foo')->Max('Foo'), 9);
|
$this->assertEquals($foo->Aggregate('AggregateTest_Foo')->Max('Foo'), 9);
|
||||||
|
|
||||||
// For subclasses, aggregate is calculated for that subclass and it's children only
|
// For subclasses, aggregate is calculated for that subclass and it's children only
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Fab')->Max('Foo'), 9);
|
$this->assertEquals($foo->Aggregate('AggregateTest_Fab')->Max('Foo'), 9);
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Fac')->Max('Foo'), 6);
|
$this->assertEquals($foo->Aggregate('AggregateTest_Fac')->Max('Foo'), 6);
|
||||||
|
|
||||||
}
|
}
|
||||||
/* */
|
/* */
|
||||||
@ -145,35 +150,35 @@ class AggregateTest extends SapphireTest {
|
|||||||
* Test cache is correctly flushed on write
|
* Test cache is correctly flushed on write
|
||||||
*/
|
*/
|
||||||
function testCacheFlushing() {
|
function testCacheFlushing() {
|
||||||
|
$foo = $this->objFromFixture('AggregateTest_Foo', 'foo1');
|
||||||
|
$fab = $this->objFromFixture('AggregateTest_Fab', 'fab1');
|
||||||
|
|
||||||
// For base classes, aggregate is calculcated on it and all children classes
|
// For base classes, aggregate is calculcated on it and all children classes
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Foo')->Max('Foo'), 9);
|
$this->assertEquals($fab->Aggregate('AggregateTest_Foo')->Max('Foo'), 9);
|
||||||
|
|
||||||
// For subclasses, aggregate is calculated for that subclass and it's children only
|
// For subclasses, aggregate is calculated for that subclass and it's children only
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Fab')->Max('Foo'), 9);
|
$this->assertEquals($fab->Aggregate('AggregateTest_Fab')->Max('Foo'), 9);
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Fac')->Max('Foo'), 6);
|
$this->assertEquals($fab->Aggregate('AggregateTest_Fac')->Max('Foo'), 6);
|
||||||
|
|
||||||
$foo = $this->objFromFixture('AggregateTest_Foo', 'foo1');
|
|
||||||
$foo->Foo = 12;
|
$foo->Foo = 12;
|
||||||
$foo->write();
|
$foo->write();
|
||||||
|
|
||||||
// For base classes, aggregate is calculcated on it and all children classes
|
// For base classes, aggregate is calculcated on it and all children classes
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Foo')->Max('Foo'), 12);
|
$this->assertEquals($fab->Aggregate('AggregateTest_Foo')->Max('Foo'), 12);
|
||||||
|
|
||||||
// For subclasses, aggregate is calculated for that subclass and it's children only
|
// For subclasses, aggregate is calculated for that subclass and it's children only
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Fab')->Max('Foo'), 9);
|
$this->assertEquals($fab->Aggregate('AggregateTest_Fab')->Max('Foo'), 9);
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Fac')->Max('Foo'), 6);
|
$this->assertEquals($fab->Aggregate('AggregateTest_Fac')->Max('Foo'), 6);
|
||||||
|
|
||||||
$fab = $this->objFromFixture('AggregateTest_Fab', 'fab1');
|
|
||||||
$fab->Foo = 15;
|
$fab->Foo = 15;
|
||||||
$fab->write();
|
$fab->write();
|
||||||
|
|
||||||
// For base classes, aggregate is calculcated on it and all children classes
|
// For base classes, aggregate is calculcated on it and all children classes
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Foo')->Max('Foo'), 15);
|
$this->assertEquals($fab->Aggregate('AggregateTest_Foo')->Max('Foo'), 15);
|
||||||
|
|
||||||
// For subclasses, aggregate is calculated for that subclass and it's children only
|
// For subclasses, aggregate is calculated for that subclass and it's children only
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Fab')->Max('Foo'), 15);
|
$this->assertEquals($fab->Aggregate('AggregateTest_Fab')->Max('Foo'), 15);
|
||||||
$this->assertEquals(DataObject::Aggregate('AggregateTest_Fac')->Max('Foo'), 6);
|
$this->assertEquals($fab->Aggregate('AggregateTest_Fac')->Max('Foo'), 6);
|
||||||
}
|
}
|
||||||
/* */
|
/* */
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ class DBFieldTest extends SapphireTest {
|
|||||||
|
|
||||||
$value = 'üåäöÜÅÄÖ';
|
$value = 'üåäöÜÅÄÖ';
|
||||||
foreach ($allFields as $stringField) {
|
foreach ($allFields as $stringField) {
|
||||||
$stringField = DBField::create($stringField, $value);
|
$stringField = DBField::create_field($stringField, $value);
|
||||||
for ($i = 1; $i < mb_strlen($value); $i++) {
|
for ($i = 1; $i < mb_strlen($value); $i++) {
|
||||||
$expected = mb_substr($value, 0, $i) . '...';
|
$expected = mb_substr($value, 0, $i) . '...';
|
||||||
$this->assertEquals($expected, $stringField->LimitCharacters($i));
|
$this->assertEquals($expected, $stringField->LimitCharacters($i));
|
||||||
@ -211,12 +211,12 @@ class DBFieldTest extends SapphireTest {
|
|||||||
|
|
||||||
$value = '<p>üåäö&ÜÅÄÖ</p>';
|
$value = '<p>üåäö&ÜÅÄÖ</p>';
|
||||||
foreach ($htmlFields as $stringField) {
|
foreach ($htmlFields as $stringField) {
|
||||||
$stringField = DBField::create($stringField, $value);
|
$stringField = DBField::create_field($stringField, $value);
|
||||||
$this->assertEquals('üåäö&ÜÅÄ...', $stringField->LimitCharacters(8));
|
$this->assertEquals('üåäö&ÜÅÄ...', $stringField->LimitCharacters(8));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals('ÅÄÖ', DBField::create('Text', 'åäö')->UpperCase());
|
$this->assertEquals('ÅÄÖ', DBField::create_field('Text', 'åäö')->UpperCase());
|
||||||
$this->assertEquals('åäö', DBField::create('Text', 'ÅÄÖ')->LowerCase());
|
$this->assertEquals('åäö', DBField::create_field('Text', 'ÅÄÖ')->LowerCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -5,17 +5,17 @@
|
|||||||
*/
|
*/
|
||||||
class DBLocaleTest extends SapphireTest {
|
class DBLocaleTest extends SapphireTest {
|
||||||
function testNice() {
|
function testNice() {
|
||||||
$l = DBField::create('DBLocale', 'de_DE');
|
$l = DBField::create_field('DBLocale', 'de_DE');
|
||||||
$this->assertEquals($l->Nice(), 'German');
|
$this->assertEquals($l->Nice(), 'German');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testNiceNative() {
|
function testNiceNative() {
|
||||||
$l = DBField::create('DBLocale', 'de_DE');
|
$l = DBField::create_field('DBLocale', 'de_DE');
|
||||||
$this->assertEquals($l->Nice(true), 'Deutsch');
|
$this->assertEquals($l->Nice(true), 'Deutsch');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testNativeName() {
|
function testNativeName() {
|
||||||
$l = DBField::create('DBLocale', 'de_DE');
|
$l = DBField::create_field('DBLocale', 'de_DE');
|
||||||
$this->assertEquals($l->getNativeName(), 'Deutsch');
|
$this->assertEquals($l->getNativeName(), 'Deutsch');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,8 +62,8 @@ class DataDifferencerTest_Object extends DataObject implements TestOnly {
|
|||||||
'HasOneRelation' => 'DataDifferencerTest_HasOneRelationObject'
|
'HasOneRelation' => 'DataDifferencerTest_HasOneRelationObject'
|
||||||
);
|
);
|
||||||
|
|
||||||
function getCMSFields() {
|
function getCMSFields($params = null) {
|
||||||
$fields = parent::getCMSFields();
|
$fields = parent::getCMSFields($params);
|
||||||
$choices = array(
|
$choices = array(
|
||||||
'a' => 'a',
|
'a' => 'a',
|
||||||
'b' => 'b',
|
'b' => 'b',
|
||||||
@ -103,4 +103,4 @@ class DataDifferencerTest_MockImage extends Image implements TestOnly {
|
|||||||
// Skip aktual generation
|
// Skip aktual generation
|
||||||
return $gd;
|
return $gd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,122 +6,110 @@
|
|||||||
class DateTest extends SapphireTest {
|
class DateTest extends SapphireTest {
|
||||||
|
|
||||||
protected $originalTZ;
|
protected $originalTZ;
|
||||||
|
|
||||||
function setUp() {
|
function setUp() {
|
||||||
// Set timezone to support timestamp->date conversion.
|
// Set timezone to support timestamp->date conversion.
|
||||||
// We can't use date_default_timezone_set() as its not supported prior to PHP 5.2
|
$this->originalTZ = date_default_timezone_get();
|
||||||
|
date_default_timezone_set('Pacific/Auckland');
|
||||||
if (version_compare(PHP_VERSION, '5.2.0', '<')) {
|
|
||||||
$this->originalTZ = ini_get('date.timezone');
|
|
||||||
ini_set('date.timezone', 'Pacific/Auckland');
|
|
||||||
} else {
|
|
||||||
$this->originalTZ = date_default_timezone_get();
|
|
||||||
date_default_timezone_set('Pacific/Auckland');
|
|
||||||
}
|
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
}
|
}
|
||||||
|
|
||||||
function tearDown() {
|
function tearDown() {
|
||||||
if(version_compare(PHP_VERSION, '5.2.0', '<') ){
|
date_default_timezone_set($this->originalTZ);
|
||||||
ini_set('date.timezone',$this->originalTZ);
|
|
||||||
} else {
|
|
||||||
date_default_timezone_set($this->originalTZ);
|
|
||||||
}
|
|
||||||
|
|
||||||
parent::tearDown();
|
parent::tearDown();
|
||||||
}
|
}
|
||||||
|
|
||||||
function testNiceDate() {
|
function testNiceDate() {
|
||||||
$this->assertEquals('01/04/2008', DBField::create('Date', 1206968400)->Nice(),
|
$this->assertEquals('31/03/2008', DBField::create_field('Date', 1206968400)->Nice(),
|
||||||
"Date->Nice() works with timestamp integers"
|
"Date->Nice() works with timestamp integers"
|
||||||
);
|
);
|
||||||
$this->assertEquals('31/03/2008', DBField::create('Date', 1206882000)->Nice(),
|
$this->assertEquals('30/03/2008', DBField::create_field('Date', 1206882000)->Nice(),
|
||||||
"Date->Nice() works with timestamp integers"
|
"Date->Nice() works with timestamp integers"
|
||||||
);
|
);
|
||||||
$this->assertEquals('01/04/2008', DBField::create('Date', '1206968400')->Nice(),
|
$this->assertEquals('31/03/2008', DBField::create_field('Date', '1206968400')->Nice(),
|
||||||
"Date->Nice() works with timestamp strings"
|
"Date->Nice() works with timestamp strings"
|
||||||
);
|
);
|
||||||
$this->assertEquals('31/03/2008', DBField::create('Date', '1206882000')->Nice(),
|
$this->assertEquals('30/03/2008', DBField::create_field('Date', '1206882000')->Nice(),
|
||||||
"Date->Nice() works with timestamp strings"
|
"Date->Nice() works with timestamp strings"
|
||||||
);
|
);
|
||||||
$this->assertEquals('04/03/2003', DBField::create('Date', '4/3/03')->Nice(),
|
$this->assertEquals('04/03/2003', DBField::create_field('Date', '4/3/03')->Nice(),
|
||||||
"Date->Nice() works with D/M/YY format"
|
"Date->Nice() works with D/M/YY format"
|
||||||
);
|
);
|
||||||
$this->assertEquals('04/03/2003', DBField::create('Date', '04/03/03')->Nice(),
|
$this->assertEquals('04/03/2003', DBField::create_field('Date', '04/03/03')->Nice(),
|
||||||
"Date->Nice() works with DD/MM/YY format"
|
"Date->Nice() works with DD/MM/YY format"
|
||||||
);
|
);
|
||||||
$this->assertEquals('04/03/2003', DBField::create('Date', '4/3/03')->Nice(),
|
$this->assertEquals('04/03/2003', DBField::create_field('Date', '4/3/03')->Nice(),
|
||||||
"Date->Nice() works with D/M/YY format"
|
"Date->Nice() works with D/M/YY format"
|
||||||
);
|
);
|
||||||
$this->assertEquals('04/03/2003', DBField::create('Date', '4/03/03')->Nice(),
|
$this->assertEquals('04/03/2003', DBField::create_field('Date', '4/03/03')->Nice(),
|
||||||
"Date->Nice() works with D/M/YY format"
|
"Date->Nice() works with D/M/YY format"
|
||||||
);
|
);
|
||||||
$this->assertEquals('04/03/2003', DBField::create('Date', '4/3/2003')->Nice(),
|
$this->assertEquals('04/03/2003', DBField::create_field('Date', '4/3/2003')->Nice(),
|
||||||
"Date->Nice() works with D/M/YYYY format"
|
"Date->Nice() works with D/M/YYYY format"
|
||||||
);
|
);
|
||||||
$this->assertEquals('04/03/2003', DBField::create('Date', '4-3-2003')->Nice(),
|
$this->assertEquals('04/03/2003', DBField::create_field('Date', '4-3-2003')->Nice(),
|
||||||
"Date->Nice() works with D-M-YYYY format"
|
"Date->Nice() works with D-M-YYYY format"
|
||||||
);
|
);
|
||||||
$this->assertEquals('04/03/2003', DBField::create('Date', '2003-03-04')->Nice(),
|
$this->assertEquals('04/03/2003', DBField::create_field('Date', '2003-03-04')->Nice(),
|
||||||
"Date->Nice() works with YYYY-MM-DD format"
|
"Date->Nice() works with YYYY-MM-DD format"
|
||||||
);
|
);
|
||||||
$this->assertEquals('04/03/2003', DBField::create('Date', '04/03/2003')->Nice(),
|
$this->assertEquals('04/03/2003', DBField::create_field('Date', '04/03/2003')->Nice(),
|
||||||
"Date->Nice() works with DD/MM/YYYY format"
|
"Date->Nice() works with DD/MM/YYYY format"
|
||||||
);
|
);
|
||||||
$this->assertEquals('04/03/2003', DBField::create('Date', '04-03-2003')->Nice(),
|
$this->assertEquals('04/03/2003', DBField::create_field('Date', '04-03-2003')->Nice(),
|
||||||
"Date->Nice() works with DD/MM/YYYY format"
|
"Date->Nice() works with DD/MM/YYYY format"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testLongDate() {
|
function testLongDate() {
|
||||||
$this->assertEquals('1 April 2008', DBField::create('Date', 1206968400)->Long(),
|
$this->assertEquals('31 March 2008', DBField::create_field('Date', 1206968400)->Long(),
|
||||||
"Date->Long() works with numeric timestamp"
|
"Date->Long() works with numeric timestamp"
|
||||||
);
|
);
|
||||||
$this->assertEquals('1 April 2008', DBField::create('Date', '1206968400')->Long(),
|
$this->assertEquals('31 March 2008', DBField::create_field('Date', '1206968400')->Long(),
|
||||||
"Date->Long() works with string timestamp"
|
"Date->Long() works with string timestamp"
|
||||||
);
|
);
|
||||||
$this->assertEquals('31 March 2008', DBField::create('Date', 1206882000)->Long(),
|
$this->assertEquals('30 March 2008', DBField::create_field('Date', 1206882000)->Long(),
|
||||||
"Date->Long() works with numeric timestamp"
|
"Date->Long() works with numeric timestamp"
|
||||||
);
|
);
|
||||||
$this->assertEquals('31 March 2008', DBField::create('Date', '1206882000')->Long(),
|
$this->assertEquals('30 March 2008', DBField::create_field('Date', '1206882000')->Long(),
|
||||||
"Date->Long() works with numeric timestamp"
|
"Date->Long() works with numeric timestamp"
|
||||||
);
|
);
|
||||||
$this->assertEquals('3 April 2003', DBField::create('Date', '2003-4-3')->Long(),
|
$this->assertEquals('3 April 2003', DBField::create_field('Date', '2003-4-3')->Long(),
|
||||||
"Date->Long() works with YYYY-M-D"
|
"Date->Long() works with YYYY-M-D"
|
||||||
);
|
);
|
||||||
$this->assertEquals('3 April 2003', DBField::create('Date', '3/4/2003')->Long(),
|
$this->assertEquals('3 April 2003', DBField::create_field('Date', '3/4/2003')->Long(),
|
||||||
"Date->Long() works with D/M/YYYY"
|
"Date->Long() works with D/M/YYYY"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSetNullAndZeroValues() {
|
function testSetNullAndZeroValues() {
|
||||||
$date = DBField::create('Date', '');
|
$date = DBField::create_field('Date', '');
|
||||||
$this->assertNull($date->getValue(), 'Empty string evaluates to NULL');
|
$this->assertNull($date->getValue(), 'Empty string evaluates to NULL');
|
||||||
|
|
||||||
$date = DBField::create('Date', null);
|
$date = DBField::create_field('Date', null);
|
||||||
$this->assertNull($date->getValue(), 'NULL is set as NULL');
|
$this->assertNull($date->getValue(), 'NULL is set as NULL');
|
||||||
|
|
||||||
$date = DBField::create('Date', false);
|
$date = DBField::create_field('Date', false);
|
||||||
$this->assertNull($date->getValue(), 'Boolean FALSE evaluates to NULL');
|
$this->assertNull($date->getValue(), 'Boolean FALSE evaluates to NULL');
|
||||||
|
|
||||||
$date = DBField::create('Date', array());
|
$date = DBField::create_field('Date', array());
|
||||||
$this->assertNull($date->getValue(), 'Empty array evaluates to NULL');
|
$this->assertNull($date->getValue(), 'Empty array evaluates to NULL');
|
||||||
|
|
||||||
$date = DBField::create('Date', '0');
|
$date = DBField::create_field('Date', '0');
|
||||||
$this->assertEquals('1970-01-01', $date->getValue(), 'Zero is UNIX epoch date');
|
$this->assertEquals('1970-01-01', $date->getValue(), 'Zero is UNIX epoch date');
|
||||||
|
|
||||||
$date = DBField::create('Date', 0);
|
$date = DBField::create_field('Date', 0);
|
||||||
$this->assertEquals('1970-01-01', $date->getValue(), 'Zero is UNIX epoch date');
|
$this->assertEquals('1970-01-01', $date->getValue(), 'Zero is UNIX epoch date');
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDayOfMonth() {
|
function testDayOfMonth() {
|
||||||
$date = DBField::create('Date', '2000-10-10');
|
$date = DBField::create_field('Date', '2000-10-10');
|
||||||
$this->assertEquals('10', $date->DayOfMonth());
|
$this->assertEquals('10', $date->DayOfMonth());
|
||||||
$this->assertEquals('10th', $date->DayOfMonth(true));
|
$this->assertEquals('10th', $date->DayOfMonth(true));
|
||||||
|
|
||||||
$range = $date->RangeString(DBField::create('Date', '2000-10-20'));
|
$range = $date->RangeString(DBField::create_field('Date', '2000-10-20'));
|
||||||
$this->assertEquals('10 - 20 Oct 2000', $range);
|
$this->assertEquals('10 - 20 Oct 2000', $range);
|
||||||
$range = $date->RangeString(DBField::create('Date', '2000-10-20'), true);
|
$range = $date->RangeString(DBField::create_field('Date', '2000-10-20'), true);
|
||||||
$this->assertEquals('10th - 20th Oct 2000', $range);
|
$this->assertEquals('10th - 20th Oct 2000', $range);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
*/
|
*/
|
||||||
class SS_DatetimeTest extends SapphireTest {
|
class SS_DatetimeTest extends SapphireTest {
|
||||||
function testNowWithSystemDate() {
|
function testNowWithSystemDate() {
|
||||||
$systemDatetime = DBField::create('SS_Datetime', date('Y-m-d H:i:s'));
|
$systemDatetime = DBField::create_field('SS_Datetime', date('Y-m-d H:i:s'));
|
||||||
$nowDatetime = SS_Datetime::now();
|
$nowDatetime = SS_Datetime::now();
|
||||||
|
|
||||||
$this->assertEquals($systemDatetime->Date(), $nowDatetime->Date());
|
$this->assertEquals($systemDatetime->Date(), $nowDatetime->Date());
|
||||||
@ -22,34 +22,32 @@ class SS_DatetimeTest extends SapphireTest {
|
|||||||
// Test setting
|
// Test setting
|
||||||
$mockDate = '2001-12-31 22:10:59';
|
$mockDate = '2001-12-31 22:10:59';
|
||||||
SS_Datetime::set_mock_now($mockDate);
|
SS_Datetime::set_mock_now($mockDate);
|
||||||
$systemDatetime = DBField::create('SS_Datetime', date('Y-m-d H:i:s'));
|
$systemDatetime = DBField::create_field('SS_Datetime', date('Y-m-d H:i:s'));
|
||||||
$nowDatetime = SS_Datetime::now();
|
$nowDatetime = SS_Datetime::now();
|
||||||
$this->assertNotEquals($systemDatetime->Date(), $nowDatetime->Date());
|
$this->assertNotEquals($systemDatetime->Date(), $nowDatetime->Date());
|
||||||
$this->assertEquals($nowDatetime->getValue(), $mockDate);
|
$this->assertEquals($nowDatetime->getValue(), $mockDate);
|
||||||
|
|
||||||
// Test clearing
|
// Test clearing
|
||||||
SS_Datetime::clear_mock_now();
|
SS_Datetime::clear_mock_now();
|
||||||
$systemDatetime = DBField::create('SS_Datetime', date('Y-m-d H:i:s'));
|
$systemDatetime = DBField::create_field('SS_Datetime', date('Y-m-d H:i:s'));
|
||||||
$nowDatetime = SS_Datetime::now();
|
$nowDatetime = SS_Datetime::now();
|
||||||
$this->assertEquals($systemDatetime->Date(), $nowDatetime->Date());
|
$this->assertEquals($systemDatetime->Date(), $nowDatetime->Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
function testSetNullAndZeroValues() {
|
function testSetNullAndZeroValues() {
|
||||||
date_default_timezone_set('UTC');
|
$date = DBField::create_field('SS_Datetime', '');
|
||||||
|
|
||||||
$date = DBField::create('SS_Datetime', '');
|
|
||||||
$this->assertNull($date->getValue(), 'Empty string evaluates to NULL');
|
$this->assertNull($date->getValue(), 'Empty string evaluates to NULL');
|
||||||
|
|
||||||
$date = DBField::create('SS_Datetime', null);
|
$date = DBField::create_field('SS_Datetime', null);
|
||||||
$this->assertNull($date->getValue(), 'NULL is set as NULL');
|
$this->assertNull($date->getValue(), 'NULL is set as NULL');
|
||||||
|
|
||||||
$date = DBField::create('SS_Datetime', false);
|
$date = DBField::create_field('SS_Datetime', false);
|
||||||
$this->assertNull($date->getValue(), 'Boolean FALSE evaluates to NULL');
|
$this->assertNull($date->getValue(), 'Boolean FALSE evaluates to NULL');
|
||||||
|
|
||||||
$date = DBField::create('SS_Datetime', '0');
|
$date = DBField::create_field('SS_Datetime', '0');
|
||||||
$this->assertEquals('1970-01-01 00:00:00', $date->getValue(), 'String zero is UNIX epoch time');
|
$this->assertEquals('1970-01-01 00:00:00', $date->getValue(), 'String zero is UNIX epoch time');
|
||||||
|
|
||||||
$date = DBField::create('SS_Datetime', 0);
|
$date = DBField::create_field('SS_Datetime', 0);
|
||||||
$this->assertEquals('1970-01-01 00:00:00', $date->getValue(), 'Numeric zero is UNIX epoch time');
|
$this->assertEquals('1970-01-01 00:00:00', $date->getValue(), 'Numeric zero is UNIX epoch time');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ class DbDatetimeTest extends FunctionalTest {
|
|||||||
E_USER_ERROR => 1800,
|
E_USER_ERROR => 1800,
|
||||||
E_USER_NOTICE => 5,
|
E_USER_NOTICE => 5,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
private $adapter;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if dates match more or less. This takes into the account the db query
|
* Check if dates match more or less. This takes into the account the db query
|
||||||
|
@ -108,30 +108,30 @@ class HTMLTextTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testRAW() {
|
public function testRAW() {
|
||||||
$data = DBField::create('HTMLText', 'This & This');
|
$data = DBField::create_field('HTMLText', 'This & This');
|
||||||
$this->assertEquals($data->RAW(), 'This & This');
|
$this->assertEquals($data->RAW(), 'This & This');
|
||||||
|
|
||||||
$data = DBField::create('HTMLText', 'This & This');
|
$data = DBField::create_field('HTMLText', 'This & This');
|
||||||
$this->assertEquals($data->RAW(), 'This & This');
|
$this->assertEquals($data->RAW(), 'This & This');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testXML() {
|
public function testXML() {
|
||||||
$data = DBField::create('HTMLText', 'This & This');
|
$data = DBField::create_field('HTMLText', 'This & This');
|
||||||
$this->assertEquals($data->XML(), 'This & This');
|
$this->assertEquals($data->XML(), 'This & This');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHTML() {
|
public function testHTML() {
|
||||||
$data = DBField::create('HTMLText', 'This & This');
|
$data = DBField::create_field('HTMLText', 'This & This');
|
||||||
$this->assertEquals($data->HTML(), 'This & This');
|
$this->assertEquals($data->HTML(), 'This & This');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testJS() {
|
public function testJS() {
|
||||||
$data = DBField::create('HTMLText', '"this is a test"');
|
$data = DBField::create_field('HTMLText', '"this is a test"');
|
||||||
$this->assertEquals($data->JS(), '\"this is a test\"');
|
$this->assertEquals($data->JS(), '\"this is a test\"');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testATT() {
|
public function testATT() {
|
||||||
$data = DBField::create('HTMLText', '"this is a test"');
|
$data = DBField::create_field('HTMLText', '"this is a test"');
|
||||||
$this->assertEquals($data->ATT(), '"this is a test"');
|
$this->assertEquals($data->ATT(), '"this is a test"');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,7 +12,7 @@ class StringFieldTest extends SapphireTest {
|
|||||||
function testLowerCase() {
|
function testLowerCase() {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'this is a test!',
|
'this is a test!',
|
||||||
DBField::create('StringFieldTest_MyStringField', 'This is a TEST!')->LowerCase()
|
DBField::create_field('StringFieldTest_MyStringField', 'This is a TEST!')->LowerCase()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ class StringFieldTest extends SapphireTest {
|
|||||||
function testUpperCase() {
|
function testUpperCase() {
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'THIS IS A TEST!',
|
'THIS IS A TEST!',
|
||||||
DBField::create('StringFieldTest_MyStringField', 'This is a TEST!')->UpperCase()
|
DBField::create_field('StringFieldTest_MyStringField', 'This is a TEST!')->UpperCase()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,7 +99,7 @@ class TextTest extends SapphireTest {
|
|||||||
);
|
);
|
||||||
|
|
||||||
foreach($cases as $originalValue => $expectedValue) {
|
foreach($cases as $originalValue => $expectedValue) {
|
||||||
$textObj = DBField::create('Text', $originalValue);
|
$textObj = DBField::create_field('Text', $originalValue);
|
||||||
$this->assertEquals($expectedValue, $textObj->BigSummary(4));
|
$this->assertEquals($expectedValue, $textObj->BigSummary(4));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,7 +115,7 @@ class TextTest extends SapphireTest {
|
|||||||
$testKeyword3 = 'a';
|
$testKeyword3 = 'a';
|
||||||
$testKeyword3a = 'ate';
|
$testKeyword3a = 'ate';
|
||||||
|
|
||||||
$textObj = DBField::create('Text', $testString1, 'Text');
|
$textObj = DBField::create_field('Text', $testString1, 'Text');
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'... text. It is a <span class="highlight">test</span>...',
|
'... text. It is a <span class="highlight">test</span>...',
|
||||||
@ -145,27 +145,27 @@ class TextTest extends SapphireTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function testRAW() {
|
public function testRAW() {
|
||||||
$data = DBField::create('Text', 'This & This');
|
$data = DBField::create_field('Text', 'This & This');
|
||||||
$this->assertEquals($data->RAW(), 'This & This');
|
$this->assertEquals($data->RAW(), 'This & This');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testXML() {
|
public function testXML() {
|
||||||
$data = DBField::create('Text', 'This & This');
|
$data = DBField::create_field('Text', 'This & This');
|
||||||
$this->assertEquals($data->XML(), 'This & This');
|
$this->assertEquals($data->XML(), 'This & This');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testHTML() {
|
public function testHTML() {
|
||||||
$data = DBField::create('Text', 'This & This');
|
$data = DBField::create_field('Text', 'This & This');
|
||||||
$this->assertEquals($data->HTML(), 'This & This');
|
$this->assertEquals($data->HTML(), 'This & This');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testJS() {
|
public function testJS() {
|
||||||
$data = DBField::create('Text', '"this is a test"');
|
$data = DBField::create_field('Text', '"this is a test"');
|
||||||
$this->assertEquals($data->JS(), '\"this is a test\"');
|
$this->assertEquals($data->JS(), '\"this is a test\"');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testATT() {
|
public function testATT() {
|
||||||
$data = DBField::create('Text', '"this is a test"');
|
$data = DBField::create_field('Text', '"this is a test"');
|
||||||
$this->assertEquals($data->ATT(), '"this is a test"');
|
$this->assertEquals($data->ATT(), '"this is a test"');
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -94,15 +94,6 @@ class GroupTest extends FunctionalTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDelete() {
|
|
||||||
$adminGroup = $this->objFromFixture('Group', 'admingroup');
|
|
||||||
|
|
||||||
$adminGroup->delete();
|
|
||||||
|
|
||||||
$this->assertEquals(0, DataObject::get('Group', "\"ID\"={$adminGroup->ID}")->count(), 'Group is removed');
|
|
||||||
$this->assertEquals(0, DataObject::get('Permission',"\"GroupID\"={$adminGroup->ID}")->count(), 'Permissions removed along with the group');
|
|
||||||
}
|
|
||||||
|
|
||||||
function testCollateAncestorIDs() {
|
function testCollateAncestorIDs() {
|
||||||
$parentGroup = $this->objFromFixture('Group', 'parentgroup');
|
$parentGroup = $this->objFromFixture('Group', 'parentgroup');
|
||||||
$childGroup = $this->objFromFixture('Group', 'childgroup');
|
$childGroup = $this->objFromFixture('Group', 'childgroup');
|
||||||
@ -128,11 +119,24 @@ class GroupTest extends FunctionalTest {
|
|||||||
'Orphaned nodes dont contain invalid parent IDs'
|
'Orphaned nodes dont contain invalid parent IDs'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDelete() {
|
||||||
|
$group = $this->objFromFixture('Group', 'parentgroup');
|
||||||
|
$groupID = $group->ID;
|
||||||
|
$childGroupID = $this->idFromFixture('Group', 'childgroup');
|
||||||
|
$group->delete();
|
||||||
|
|
||||||
|
$this->assertEquals(0, DataObject::get('Group', "\"ID\" = {$groupID}")->Count(), 'Group is removed');
|
||||||
|
$this->assertEquals(0, DataObject::get('Permission', "\"GroupID\" = {$groupID}")->Count(), 'Permissions removed along with the group');
|
||||||
|
$this->assertEquals(0, DataObject::get('Group', "\"ParentID\" = {$groupID}")->Count(), 'Child groups are removed');
|
||||||
|
$this->assertEquals(0, DataObject::get('Group', "\"ParentID\" = {$childGroupID}")->Count(), 'Grandchild groups are removed');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class GroupTest_Member extends Member implements TestOnly {
|
class GroupTest_Member extends Member implements TestOnly {
|
||||||
|
|
||||||
function getCMSFields() {
|
function getCMSFields($params = null) {
|
||||||
$groups = DataObject::get('Group');
|
$groups = DataObject::get('Group');
|
||||||
$groupsMap = ($groups) ? $groups->map() : false;
|
$groupsMap = ($groups) ? $groups->map() : false;
|
||||||
$fields = new FieldList(
|
$fields = new FieldList(
|
||||||
|
@ -6,6 +6,9 @@ Group:
|
|||||||
childgroup:
|
childgroup:
|
||||||
Code: childgroup
|
Code: childgroup
|
||||||
Parent: =>Group.parentgroup
|
Parent: =>Group.parentgroup
|
||||||
|
grandchildgroup:
|
||||||
|
Code: grandchildgroup
|
||||||
|
Parent: =>Group.childgroup
|
||||||
group1:
|
group1:
|
||||||
Title: Group 1
|
Title: Group 1
|
||||||
group2:
|
group2:
|
||||||
@ -26,4 +29,4 @@ GroupTest_Member:
|
|||||||
Permission:
|
Permission:
|
||||||
admincode:
|
admincode:
|
||||||
Code: ADMIN
|
Code: ADMIN
|
||||||
Group: =>Group.admingroup
|
Group: =>Group.admingroup
|
||||||
|
@ -591,29 +591,29 @@ class MemberTest extends FunctionalTest {
|
|||||||
}
|
}
|
||||||
class MemberTest_ViewingAllowedExtension extends DataExtension implements TestOnly {
|
class MemberTest_ViewingAllowedExtension extends DataExtension implements TestOnly {
|
||||||
|
|
||||||
public function canView() {
|
public function canView($member = null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
class MemberTest_ViewingDeniedExtension extends DataExtension implements TestOnly {
|
class MemberTest_ViewingDeniedExtension extends DataExtension implements TestOnly {
|
||||||
|
|
||||||
public function canView() {
|
public function canView($member = null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
class MemberTest_EditingAllowedDeletingDeniedExtension extends DataExtension implements TestOnly {
|
class MemberTest_EditingAllowedDeletingDeniedExtension extends DataExtension implements TestOnly {
|
||||||
|
|
||||||
public function canView() {
|
public function canView($member = null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canEdit() {
|
public function canEdit($member = null) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function canDelete() {
|
public function canDelete($member = null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -930,7 +930,7 @@ class SSViewerTestFixture extends ViewableData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function XML_val($fieldName, $arguments = null) {
|
function XML_val($fieldName, $arguments = null, $cache = false) {
|
||||||
if(preg_match('/NotSet/i', $fieldName)) {
|
if(preg_match('/NotSet/i', $fieldName)) {
|
||||||
return '';
|
return '';
|
||||||
} else if(preg_match('/Raw/i', $fieldName)) {
|
} else if(preg_match('/Raw/i', $fieldName)) {
|
||||||
@ -940,7 +940,7 @@ class SSViewerTestFixture extends ViewableData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasValue($fieldName, $arguments = null) {
|
function hasValue($fieldName, $arguments = null, $cache = true) {
|
||||||
return (bool)$this->XML_val($fieldName, $arguments);
|
return (bool)$this->XML_val($fieldName, $arguments);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1021,4 +1021,4 @@ class SSViewerTest_GlobalProvider implements TemplateGlobalProvider, TestOnly {
|
|||||||
return 'z' . implode(':', $args) . 'z';
|
return 'z' . implode(':', $args) . 'z';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
8
thirdparty/json/.piston.yml
vendored
8
thirdparty/json/.piston.yml
vendored
@ -1,8 +0,0 @@
|
|||||||
---
|
|
||||||
format: 1
|
|
||||||
handler:
|
|
||||||
piston:remote-revision: 93520
|
|
||||||
piston:uuid: 467b73ca-7a2a-4603-9d3b-597d59a354a9
|
|
||||||
lock: false
|
|
||||||
repository_class: Piston::Svn::Repository
|
|
||||||
repository_url: http://svn.silverstripe.com/open/thirdparty/json/tags/1.31
|
|
806
thirdparty/json/JSON.php
vendored
806
thirdparty/json/JSON.php
vendored
@ -1,806 +0,0 @@
|
|||||||
<?php
|
|
||||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts to and from JSON format.
|
|
||||||
*
|
|
||||||
* JSON (JavaScript Object Notation) is a lightweight data-interchange
|
|
||||||
* format. It is easy for humans to read and write. It is easy for machines
|
|
||||||
* to parse and generate. It is based on a subset of the JavaScript
|
|
||||||
* Programming Language, Standard ECMA-262 3rd Edition - December 1999.
|
|
||||||
* This feature can also be found in Python. JSON is a text format that is
|
|
||||||
* completely language independent but uses conventions that are familiar
|
|
||||||
* to programmers of the C-family of languages, including C, C++, C#, Java,
|
|
||||||
* JavaScript, Perl, TCL, and many others. These properties make JSON an
|
|
||||||
* ideal data-interchange language.
|
|
||||||
*
|
|
||||||
* This package provides a simple encoder and decoder for JSON notation. It
|
|
||||||
* is intended for use with client-side Javascript applications that make
|
|
||||||
* use of HTTPRequest to perform server communication functions - data can
|
|
||||||
* be encoded into JSON notation for use in a client-side javascript, or
|
|
||||||
* decoded from incoming Javascript requests. JSON format is native to
|
|
||||||
* Javascript, and can be directly eval()'ed with no further parsing
|
|
||||||
* overhead
|
|
||||||
*
|
|
||||||
* All strings should be in ASCII or UTF-8 format!
|
|
||||||
*
|
|
||||||
* LICENSE: Redistribution and use in source and binary forms, with or
|
|
||||||
* without modification, are permitted provided that the following
|
|
||||||
* conditions are met: Redistributions of source code must retain the
|
|
||||||
* above copyright notice, this list of conditions and the following
|
|
||||||
* disclaimer. Redistributions in binary form must reproduce the above
|
|
||||||
* copyright notice, this list of conditions and the following disclaimer
|
|
||||||
* in the documentation and/or other materials provided with the
|
|
||||||
* distribution.
|
|
||||||
*
|
|
||||||
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
|
||||||
* NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
||||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
||||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
||||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
|
|
||||||
* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
|
|
||||||
* USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
|
|
||||||
* DAMAGE.
|
|
||||||
*
|
|
||||||
* @category
|
|
||||||
* @package Services_JSON
|
|
||||||
* @author Michal Migurski <mike-json@teczno.com>
|
|
||||||
* @author Matt Knapp <mdknapp[at]gmail[dot]com>
|
|
||||||
* @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
|
|
||||||
* @copyright 2005 Michal Migurski
|
|
||||||
* @version CVS: $Id: JSON.php,v 1.31 2006/06/28 05:54:17 migurski Exp $
|
|
||||||
* @license http://www.opensource.org/licenses/bsd-license.php
|
|
||||||
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
|
||||||
*/
|
|
||||||
define('SERVICES_JSON_SLICE', 1);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
|
||||||
*/
|
|
||||||
define('SERVICES_JSON_IN_STR', 2);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
|
||||||
*/
|
|
||||||
define('SERVICES_JSON_IN_ARR', 3);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
|
||||||
*/
|
|
||||||
define('SERVICES_JSON_IN_OBJ', 4);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Marker constant for Services_JSON::decode(), used to flag stack state
|
|
||||||
*/
|
|
||||||
define('SERVICES_JSON_IN_CMT', 5);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Behavior switch for Services_JSON::decode()
|
|
||||||
*/
|
|
||||||
define('SERVICES_JSON_LOOSE_TYPE', 16);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Behavior switch for Services_JSON::decode()
|
|
||||||
*/
|
|
||||||
define('SERVICES_JSON_SUPPRESS_ERRORS', 32);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Converts to and from JSON format.
|
|
||||||
*
|
|
||||||
* Brief example of use:
|
|
||||||
*
|
|
||||||
* <code>
|
|
||||||
* // create a new instance of Services_JSON
|
|
||||||
* $json = new Services_JSON();
|
|
||||||
*
|
|
||||||
* // convert a complexe value to JSON notation, and send it to the browser
|
|
||||||
* $value = array('foo', 'bar', array(1, 2, 'baz'), array(3, array(4)));
|
|
||||||
* $output = $json->encode($value);
|
|
||||||
*
|
|
||||||
* print($output);
|
|
||||||
* // prints: ["foo","bar",[1,2,"baz"],[3,[4]]]
|
|
||||||
*
|
|
||||||
* // accept incoming POST data, assumed to be in JSON notation
|
|
||||||
* $input = file_get_contents('php://input', 1000000);
|
|
||||||
* $value = $json->decode($input);
|
|
||||||
* </code>
|
|
||||||
*/
|
|
||||||
class Services_JSON
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* constructs a new JSON instance
|
|
||||||
*
|
|
||||||
* @param int $use object behavior flags; combine with boolean-OR
|
|
||||||
*
|
|
||||||
* possible values:
|
|
||||||
* - SERVICES_JSON_LOOSE_TYPE: loose typing.
|
|
||||||
* "{...}" syntax creates associative arrays
|
|
||||||
* instead of objects in decode().
|
|
||||||
* - SERVICES_JSON_SUPPRESS_ERRORS: error suppression.
|
|
||||||
* Values which can't be encoded (e.g. resources)
|
|
||||||
* appear as NULL instead of throwing errors.
|
|
||||||
* By default, a deeply-nested resource will
|
|
||||||
* bubble up with an error, so all return values
|
|
||||||
* from encode() should be checked with isError()
|
|
||||||
*/
|
|
||||||
function Services_JSON($use = 0)
|
|
||||||
{
|
|
||||||
$this->use = $use;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* convert a string from one UTF-16 char to one UTF-8 char
|
|
||||||
*
|
|
||||||
* Normally should be handled by mb_convert_encoding, but
|
|
||||||
* provides a slower PHP-only method for installations
|
|
||||||
* that lack the multibye string extension.
|
|
||||||
*
|
|
||||||
* @param string $utf16 UTF-16 character
|
|
||||||
* @return string UTF-8 character
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function utf162utf8($utf16)
|
|
||||||
{
|
|
||||||
// oh please oh please oh please oh please oh please
|
|
||||||
if(function_exists('mb_convert_encoding')) {
|
|
||||||
return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
|
|
||||||
}
|
|
||||||
|
|
||||||
$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
|
|
||||||
|
|
||||||
switch(true) {
|
|
||||||
case ((0x7F & $bytes) == $bytes):
|
|
||||||
// this case should never be reached, because we are in ASCII range
|
|
||||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
return chr(0x7F & $bytes);
|
|
||||||
|
|
||||||
case (0x07FF & $bytes) == $bytes:
|
|
||||||
// return a 2-byte UTF-8 character
|
|
||||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
return chr(0xC0 | (($bytes >> 6) & 0x1F))
|
|
||||||
. chr(0x80 | ($bytes & 0x3F));
|
|
||||||
|
|
||||||
case (0xFFFF & $bytes) == $bytes:
|
|
||||||
// return a 3-byte UTF-8 character
|
|
||||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
return chr(0xE0 | (($bytes >> 12) & 0x0F))
|
|
||||||
. chr(0x80 | (($bytes >> 6) & 0x3F))
|
|
||||||
. chr(0x80 | ($bytes & 0x3F));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ignoring UTF-32 for now, sorry
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* convert a string from one UTF-8 char to one UTF-16 char
|
|
||||||
*
|
|
||||||
* Normally should be handled by mb_convert_encoding, but
|
|
||||||
* provides a slower PHP-only method for installations
|
|
||||||
* that lack the multibye string extension.
|
|
||||||
*
|
|
||||||
* @param string $utf8 UTF-8 character
|
|
||||||
* @return string UTF-16 character
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function utf82utf16($utf8)
|
|
||||||
{
|
|
||||||
// oh please oh please oh please oh please oh please
|
|
||||||
if(function_exists('mb_convert_encoding')) {
|
|
||||||
return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
|
|
||||||
}
|
|
||||||
|
|
||||||
switch(strlen($utf8)) {
|
|
||||||
case 1:
|
|
||||||
// this case should never be reached, because we are in ASCII range
|
|
||||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
return $utf8;
|
|
||||||
|
|
||||||
case 2:
|
|
||||||
// return a UTF-16 character from a 2-byte UTF-8 char
|
|
||||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
return chr(0x07 & (ord($utf8{0}) >> 2))
|
|
||||||
. chr((0xC0 & (ord($utf8{0}) << 6))
|
|
||||||
| (0x3F & ord($utf8{1})));
|
|
||||||
|
|
||||||
case 3:
|
|
||||||
// return a UTF-16 character from a 3-byte UTF-8 char
|
|
||||||
// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
return chr((0xF0 & (ord($utf8{0}) << 4))
|
|
||||||
| (0x0F & (ord($utf8{1}) >> 2)))
|
|
||||||
. chr((0xC0 & (ord($utf8{1}) << 6))
|
|
||||||
| (0x7F & ord($utf8{2})));
|
|
||||||
}
|
|
||||||
|
|
||||||
// ignoring UTF-32 for now, sorry
|
|
||||||
return '';
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* encodes an arbitrary variable into JSON format
|
|
||||||
*
|
|
||||||
* @param mixed $var any number, boolean, string, array, or object to be encoded.
|
|
||||||
* see argument 1 to Services_JSON() above for array-parsing behavior.
|
|
||||||
* if var is a strng, note that encode() always expects it
|
|
||||||
* to be in ASCII or UTF-8 format!
|
|
||||||
*
|
|
||||||
* @return mixed JSON string representation of input var or an error if a problem occurs
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
function encode($var)
|
|
||||||
{
|
|
||||||
switch (gettype($var)) {
|
|
||||||
case 'boolean':
|
|
||||||
return $var ? 'true' : 'false';
|
|
||||||
|
|
||||||
case 'NULL':
|
|
||||||
return 'null';
|
|
||||||
|
|
||||||
case 'integer':
|
|
||||||
return (int) $var;
|
|
||||||
|
|
||||||
case 'double':
|
|
||||||
case 'float':
|
|
||||||
return (float) $var;
|
|
||||||
|
|
||||||
case 'string':
|
|
||||||
// STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
|
|
||||||
$ascii = '';
|
|
||||||
$strlen_var = strlen($var);
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Iterate over every character in the string,
|
|
||||||
* escaping with a slash or encoding to UTF-8 where necessary
|
|
||||||
*/
|
|
||||||
for ($c = 0; $c < $strlen_var; ++$c) {
|
|
||||||
|
|
||||||
$ord_var_c = ord($var{$c});
|
|
||||||
|
|
||||||
switch (true) {
|
|
||||||
case $ord_var_c == 0x08:
|
|
||||||
$ascii .= '\b';
|
|
||||||
break;
|
|
||||||
case $ord_var_c == 0x09:
|
|
||||||
$ascii .= '\t';
|
|
||||||
break;
|
|
||||||
case $ord_var_c == 0x0A:
|
|
||||||
$ascii .= '\n';
|
|
||||||
break;
|
|
||||||
case $ord_var_c == 0x0C:
|
|
||||||
$ascii .= '\f';
|
|
||||||
break;
|
|
||||||
case $ord_var_c == 0x0D:
|
|
||||||
$ascii .= '\r';
|
|
||||||
break;
|
|
||||||
|
|
||||||
case $ord_var_c == 0x22:
|
|
||||||
case $ord_var_c == 0x2F:
|
|
||||||
case $ord_var_c == 0x5C:
|
|
||||||
// double quote, slash, slosh
|
|
||||||
$ascii .= '\\'.$var{$c};
|
|
||||||
break;
|
|
||||||
|
|
||||||
case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
|
|
||||||
// characters U-00000000 - U-0000007F (same as ASCII)
|
|
||||||
$ascii .= $var{$c};
|
|
||||||
break;
|
|
||||||
|
|
||||||
case (($ord_var_c & 0xE0) == 0xC0):
|
|
||||||
// characters U-00000080 - U-000007FF, mask 110XXXXX
|
|
||||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
$char = pack('C*', $ord_var_c, ord($var{$c + 1}));
|
|
||||||
$c += 1;
|
|
||||||
$utf16 = $this->utf82utf16($char);
|
|
||||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case (($ord_var_c & 0xF0) == 0xE0):
|
|
||||||
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
|
|
||||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
$char = pack('C*', $ord_var_c,
|
|
||||||
ord($var{$c + 1}),
|
|
||||||
ord($var{$c + 2}));
|
|
||||||
$c += 2;
|
|
||||||
$utf16 = $this->utf82utf16($char);
|
|
||||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case (($ord_var_c & 0xF8) == 0xF0):
|
|
||||||
// characters U-00010000 - U-001FFFFF, mask 11110XXX
|
|
||||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
$char = pack('C*', $ord_var_c,
|
|
||||||
ord($var{$c + 1}),
|
|
||||||
ord($var{$c + 2}),
|
|
||||||
ord($var{$c + 3}));
|
|
||||||
$c += 3;
|
|
||||||
$utf16 = $this->utf82utf16($char);
|
|
||||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case (($ord_var_c & 0xFC) == 0xF8):
|
|
||||||
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
|
||||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
$char = pack('C*', $ord_var_c,
|
|
||||||
ord($var{$c + 1}),
|
|
||||||
ord($var{$c + 2}),
|
|
||||||
ord($var{$c + 3}),
|
|
||||||
ord($var{$c + 4}));
|
|
||||||
$c += 4;
|
|
||||||
$utf16 = $this->utf82utf16($char);
|
|
||||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
|
||||||
break;
|
|
||||||
|
|
||||||
case (($ord_var_c & 0xFE) == 0xFC):
|
|
||||||
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
|
||||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
$char = pack('C*', $ord_var_c,
|
|
||||||
ord($var{$c + 1}),
|
|
||||||
ord($var{$c + 2}),
|
|
||||||
ord($var{$c + 3}),
|
|
||||||
ord($var{$c + 4}),
|
|
||||||
ord($var{$c + 5}));
|
|
||||||
$c += 5;
|
|
||||||
$utf16 = $this->utf82utf16($char);
|
|
||||||
$ascii .= sprintf('\u%04s', bin2hex($utf16));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return '"'.$ascii.'"';
|
|
||||||
|
|
||||||
case 'array':
|
|
||||||
/*
|
|
||||||
* As per JSON spec if any array key is not an integer
|
|
||||||
* we must treat the the whole array as an object. We
|
|
||||||
* also try to catch a sparsely populated associative
|
|
||||||
* array with numeric keys here because some JS engines
|
|
||||||
* will create an array with empty indexes up to
|
|
||||||
* max_index which can cause memory issues and because
|
|
||||||
* the keys, which may be relevant, will be remapped
|
|
||||||
* otherwise.
|
|
||||||
*
|
|
||||||
* As per the ECMA and JSON specification an object may
|
|
||||||
* have any string as a property. Unfortunately due to
|
|
||||||
* a hole in the ECMA specification if the key is a
|
|
||||||
* ECMA reserved word or starts with a digit the
|
|
||||||
* parameter is only accessible using ECMAScript's
|
|
||||||
* bracket notation.
|
|
||||||
*/
|
|
||||||
|
|
||||||
// treat as a JSON object
|
|
||||||
if (is_array($var) && count($var) && (array_keys($var) !== range(0, sizeof($var) - 1))) {
|
|
||||||
$properties = array_map(array($this, 'name_value'),
|
|
||||||
array_keys($var),
|
|
||||||
array_values($var));
|
|
||||||
|
|
||||||
foreach($properties as $property) {
|
|
||||||
if(Services_JSON::isError($property)) {
|
|
||||||
return $property;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return '{' . join(',', $properties) . '}';
|
|
||||||
}
|
|
||||||
|
|
||||||
// treat it like a regular array
|
|
||||||
$elements = array_map(array($this, 'encode'), $var);
|
|
||||||
|
|
||||||
foreach($elements as $element) {
|
|
||||||
if(Services_JSON::isError($element)) {
|
|
||||||
return $element;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return '[' . join(',', $elements) . ']';
|
|
||||||
|
|
||||||
case 'object':
|
|
||||||
$vars = get_object_vars($var);
|
|
||||||
|
|
||||||
$properties = array_map(array($this, 'name_value'),
|
|
||||||
array_keys($vars),
|
|
||||||
array_values($vars));
|
|
||||||
|
|
||||||
foreach($properties as $property) {
|
|
||||||
if(Services_JSON::isError($property)) {
|
|
||||||
return $property;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return '{' . join(',', $properties) . '}';
|
|
||||||
|
|
||||||
default:
|
|
||||||
return ($this->use & SERVICES_JSON_SUPPRESS_ERRORS)
|
|
||||||
? 'null'
|
|
||||||
: new Services_JSON_Error(gettype($var)." can not be encoded as JSON string");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* array-walking function for use in generating JSON-formatted name-value pairs
|
|
||||||
*
|
|
||||||
* @param string $name name of key to use
|
|
||||||
* @param mixed $value reference to an array element to be encoded
|
|
||||||
*
|
|
||||||
* @return string JSON-formatted name-value pair, like '"name":value'
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function name_value($name, $value)
|
|
||||||
{
|
|
||||||
$encoded_value = $this->encode($value);
|
|
||||||
|
|
||||||
if(Services_JSON::isError($encoded_value)) {
|
|
||||||
return $encoded_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->encode(strval($name)) . ':' . $encoded_value;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* reduce a string by removing leading and trailing comments and whitespace
|
|
||||||
*
|
|
||||||
* @param $str string string value to strip of comments and whitespace
|
|
||||||
*
|
|
||||||
* @return string string value stripped of comments and whitespace
|
|
||||||
* @access private
|
|
||||||
*/
|
|
||||||
function reduce_string($str)
|
|
||||||
{
|
|
||||||
$str = preg_replace(array(
|
|
||||||
|
|
||||||
// eliminate single line comments in '// ...' form
|
|
||||||
'#^\s*//(.+)$#m',
|
|
||||||
|
|
||||||
// eliminate multi-line comments in '/* ... */' form, at start of string
|
|
||||||
'#^\s*/\*(.+)\*/#Us',
|
|
||||||
|
|
||||||
// eliminate multi-line comments in '/* ... */' form, at end of string
|
|
||||||
'#/\*(.+)\*/\s*$#Us'
|
|
||||||
|
|
||||||
), '', $str);
|
|
||||||
|
|
||||||
// eliminate extraneous space
|
|
||||||
return trim($str);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* decodes a JSON string into appropriate variable
|
|
||||||
*
|
|
||||||
* @param string $str JSON-formatted string
|
|
||||||
*
|
|
||||||
* @return mixed number, boolean, string, array, or object
|
|
||||||
* corresponding to given JSON input string.
|
|
||||||
* See argument 1 to Services_JSON() above for object-output behavior.
|
|
||||||
* Note that decode() always returns strings
|
|
||||||
* in ASCII or UTF-8 format!
|
|
||||||
* @access public
|
|
||||||
*/
|
|
||||||
function decode($str)
|
|
||||||
{
|
|
||||||
$str = $this->reduce_string($str);
|
|
||||||
|
|
||||||
switch (strtolower($str)) {
|
|
||||||
case 'true':
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case 'false':
|
|
||||||
return false;
|
|
||||||
|
|
||||||
case 'null':
|
|
||||||
return null;
|
|
||||||
|
|
||||||
default:
|
|
||||||
$m = array();
|
|
||||||
|
|
||||||
if (is_numeric($str)) {
|
|
||||||
// Lookie-loo, it's a number
|
|
||||||
|
|
||||||
// This would work on its own, but I'm trying to be
|
|
||||||
// good about returning integers where appropriate:
|
|
||||||
// return (float)$str;
|
|
||||||
|
|
||||||
// Return float or int, as appropriate
|
|
||||||
return ((float)$str == (integer)$str)
|
|
||||||
? (integer)$str
|
|
||||||
: (float)$str;
|
|
||||||
|
|
||||||
} elseif (preg_match('/^("|\').*(\1)$/s', $str, $m) && $m[1] == $m[2]) {
|
|
||||||
// STRINGS RETURNED IN UTF-8 FORMAT
|
|
||||||
$delim = substr($str, 0, 1);
|
|
||||||
$chrs = substr($str, 1, -1);
|
|
||||||
$utf8 = '';
|
|
||||||
$strlen_chrs = strlen($chrs);
|
|
||||||
|
|
||||||
for ($c = 0; $c < $strlen_chrs; ++$c) {
|
|
||||||
|
|
||||||
$substr_chrs_c_2 = substr($chrs, $c, 2);
|
|
||||||
$ord_chrs_c = ord($chrs{$c});
|
|
||||||
|
|
||||||
switch (true) {
|
|
||||||
case $substr_chrs_c_2 == '\b':
|
|
||||||
$utf8 .= chr(0x08);
|
|
||||||
++$c;
|
|
||||||
break;
|
|
||||||
case $substr_chrs_c_2 == '\t':
|
|
||||||
$utf8 .= chr(0x09);
|
|
||||||
++$c;
|
|
||||||
break;
|
|
||||||
case $substr_chrs_c_2 == '\n':
|
|
||||||
$utf8 .= chr(0x0A);
|
|
||||||
++$c;
|
|
||||||
break;
|
|
||||||
case $substr_chrs_c_2 == '\f':
|
|
||||||
$utf8 .= chr(0x0C);
|
|
||||||
++$c;
|
|
||||||
break;
|
|
||||||
case $substr_chrs_c_2 == '\r':
|
|
||||||
$utf8 .= chr(0x0D);
|
|
||||||
++$c;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case $substr_chrs_c_2 == '\\"':
|
|
||||||
case $substr_chrs_c_2 == '\\\'':
|
|
||||||
case $substr_chrs_c_2 == '\\\\':
|
|
||||||
case $substr_chrs_c_2 == '\\/':
|
|
||||||
if (($delim == '"' && $substr_chrs_c_2 != '\\\'') ||
|
|
||||||
($delim == "'" && $substr_chrs_c_2 != '\\"')) {
|
|
||||||
$utf8 .= $chrs{++$c};
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case preg_match('/\\\u[0-9A-F]{4}/i', substr($chrs, $c, 6)):
|
|
||||||
// single, escaped unicode character
|
|
||||||
$utf16 = chr(hexdec(substr($chrs, ($c + 2), 2)))
|
|
||||||
. chr(hexdec(substr($chrs, ($c + 4), 2)));
|
|
||||||
$utf8 .= $this->utf162utf8($utf16);
|
|
||||||
$c += 5;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ($ord_chrs_c >= 0x20) && ($ord_chrs_c <= 0x7F):
|
|
||||||
$utf8 .= $chrs{$c};
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ($ord_chrs_c & 0xE0) == 0xC0:
|
|
||||||
// characters U-00000080 - U-000007FF, mask 110XXXXX
|
|
||||||
//see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
$utf8 .= substr($chrs, $c, 2);
|
|
||||||
++$c;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ($ord_chrs_c & 0xF0) == 0xE0:
|
|
||||||
// characters U-00000800 - U-0000FFFF, mask 1110XXXX
|
|
||||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
$utf8 .= substr($chrs, $c, 3);
|
|
||||||
$c += 2;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ($ord_chrs_c & 0xF8) == 0xF0:
|
|
||||||
// characters U-00010000 - U-001FFFFF, mask 11110XXX
|
|
||||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
$utf8 .= substr($chrs, $c, 4);
|
|
||||||
$c += 3;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ($ord_chrs_c & 0xFC) == 0xF8:
|
|
||||||
// characters U-00200000 - U-03FFFFFF, mask 111110XX
|
|
||||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
$utf8 .= substr($chrs, $c, 5);
|
|
||||||
$c += 4;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case ($ord_chrs_c & 0xFE) == 0xFC:
|
|
||||||
// characters U-04000000 - U-7FFFFFFF, mask 1111110X
|
|
||||||
// see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
|
|
||||||
$utf8 .= substr($chrs, $c, 6);
|
|
||||||
$c += 5;
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return $utf8;
|
|
||||||
|
|
||||||
} elseif (preg_match('/^\[.*\]$/s', $str) || preg_match('/^\{.*\}$/s', $str)) {
|
|
||||||
// array, or object notation
|
|
||||||
|
|
||||||
if ($str{0} == '[') {
|
|
||||||
$stk = array(SERVICES_JSON_IN_ARR);
|
|
||||||
$arr = array();
|
|
||||||
} else {
|
|
||||||
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
|
||||||
$stk = array(SERVICES_JSON_IN_OBJ);
|
|
||||||
$obj = array();
|
|
||||||
} else {
|
|
||||||
$stk = array(SERVICES_JSON_IN_OBJ);
|
|
||||||
$obj = new stdClass();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
array_push($stk, array('what' => SERVICES_JSON_SLICE,
|
|
||||||
'where' => 0,
|
|
||||||
'delim' => false));
|
|
||||||
|
|
||||||
$chrs = substr($str, 1, -1);
|
|
||||||
$chrs = $this->reduce_string($chrs);
|
|
||||||
|
|
||||||
if ($chrs == '') {
|
|
||||||
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
|
||||||
return $arr;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return $obj;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//print("\nparsing {$chrs}\n");
|
|
||||||
|
|
||||||
$strlen_chrs = strlen($chrs);
|
|
||||||
|
|
||||||
for ($c = 0; $c <= $strlen_chrs; ++$c) {
|
|
||||||
|
|
||||||
$top = end($stk);
|
|
||||||
$substr_chrs_c_2 = substr($chrs, $c, 2);
|
|
||||||
|
|
||||||
if (($c == $strlen_chrs) || (($chrs{$c} == ',') && ($top['what'] == SERVICES_JSON_SLICE))) {
|
|
||||||
// found a comma that is not inside a string, array, etc.,
|
|
||||||
// OR we've reached the end of the character list
|
|
||||||
$slice = substr($chrs, $top['where'], ($c - $top['where']));
|
|
||||||
array_push($stk, array('what' => SERVICES_JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
|
|
||||||
//print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
|
||||||
|
|
||||||
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
|
||||||
// we are in an array, so just push an element onto the stack
|
|
||||||
array_push($arr, $this->decode($slice));
|
|
||||||
|
|
||||||
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
|
|
||||||
// we are in an object, so figure
|
|
||||||
// out the property name and set an
|
|
||||||
// element in an associative array,
|
|
||||||
// for now
|
|
||||||
$parts = array();
|
|
||||||
|
|
||||||
if (preg_match('/^\s*(["\'].*[^\\\]["\'])\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
|
|
||||||
// "name":value pair
|
|
||||||
$key = $this->decode($parts[1]);
|
|
||||||
$val = $this->decode($parts[2]);
|
|
||||||
|
|
||||||
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
|
||||||
$obj[$key] = $val;
|
|
||||||
} else {
|
|
||||||
$obj->$key = $val;
|
|
||||||
}
|
|
||||||
} elseif (preg_match('/^\s*(\w+)\s*:\s*(\S.*),?$/Uis', $slice, $parts)) {
|
|
||||||
// name:value pair, where name is unquoted
|
|
||||||
$key = $parts[1];
|
|
||||||
$val = $this->decode($parts[2]);
|
|
||||||
|
|
||||||
if ($this->use & SERVICES_JSON_LOOSE_TYPE) {
|
|
||||||
$obj[$key] = $val;
|
|
||||||
} else {
|
|
||||||
$obj->$key = $val;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != SERVICES_JSON_IN_STR)) {
|
|
||||||
// found a quote, and we are not inside a string
|
|
||||||
array_push($stk, array('what' => SERVICES_JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
|
|
||||||
//print("Found start of string at {$c}\n");
|
|
||||||
|
|
||||||
} elseif (($chrs{$c} == $top['delim']) &&
|
|
||||||
($top['what'] == SERVICES_JSON_IN_STR) &&
|
|
||||||
((strlen(substr($chrs, 0, $c)) - strlen(rtrim(substr($chrs, 0, $c), '\\'))) % 2 != 1)) {
|
|
||||||
// found a quote, we're in a string, and it's not escaped
|
|
||||||
// we know that it's not escaped becase there is _not_ an
|
|
||||||
// odd number of backslashes at the end of the string so far
|
|
||||||
array_pop($stk);
|
|
||||||
//print("Found end of string at {$c}: ".substr($chrs, $top['where'], (1 + 1 + $c - $top['where']))."\n");
|
|
||||||
|
|
||||||
} elseif (($chrs{$c} == '[') &&
|
|
||||||
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
|
||||||
// found a left-bracket, and we are in an array, object, or slice
|
|
||||||
array_push($stk, array('what' => SERVICES_JSON_IN_ARR, 'where' => $c, 'delim' => false));
|
|
||||||
//print("Found start of array at {$c}\n");
|
|
||||||
|
|
||||||
} elseif (($chrs{$c} == ']') && ($top['what'] == SERVICES_JSON_IN_ARR)) {
|
|
||||||
// found a right-bracket, and we're in an array
|
|
||||||
array_pop($stk);
|
|
||||||
//print("Found end of array at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
|
||||||
|
|
||||||
} elseif (($chrs{$c} == '{') &&
|
|
||||||
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
|
||||||
// found a left-brace, and we are in an array, object, or slice
|
|
||||||
array_push($stk, array('what' => SERVICES_JSON_IN_OBJ, 'where' => $c, 'delim' => false));
|
|
||||||
//print("Found start of object at {$c}\n");
|
|
||||||
|
|
||||||
} elseif (($chrs{$c} == '}') && ($top['what'] == SERVICES_JSON_IN_OBJ)) {
|
|
||||||
// found a right-brace, and we're in an object
|
|
||||||
array_pop($stk);
|
|
||||||
//print("Found end of object at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
|
||||||
|
|
||||||
} elseif (($substr_chrs_c_2 == '/*') &&
|
|
||||||
in_array($top['what'], array(SERVICES_JSON_SLICE, SERVICES_JSON_IN_ARR, SERVICES_JSON_IN_OBJ))) {
|
|
||||||
// found a comment start, and we are in an array, object, or slice
|
|
||||||
array_push($stk, array('what' => SERVICES_JSON_IN_CMT, 'where' => $c, 'delim' => false));
|
|
||||||
$c++;
|
|
||||||
//print("Found start of comment at {$c}\n");
|
|
||||||
|
|
||||||
} elseif (($substr_chrs_c_2 == '*/') && ($top['what'] == SERVICES_JSON_IN_CMT)) {
|
|
||||||
// found a comment end, and we're in one now
|
|
||||||
array_pop($stk);
|
|
||||||
$c++;
|
|
||||||
|
|
||||||
for ($i = $top['where']; $i <= $c; ++$i)
|
|
||||||
$chrs = substr_replace($chrs, ' ', $i, 1);
|
|
||||||
|
|
||||||
//print("Found end of comment at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (reset($stk) == SERVICES_JSON_IN_ARR) {
|
|
||||||
return $arr;
|
|
||||||
|
|
||||||
} elseif (reset($stk) == SERVICES_JSON_IN_OBJ) {
|
|
||||||
return $obj;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Ultimately, this should just call PEAR::isError()
|
|
||||||
*/
|
|
||||||
function isError($data, $code = null)
|
|
||||||
{
|
|
||||||
if (class_exists('pear')) {
|
|
||||||
return PEAR::isError($data, $code);
|
|
||||||
} elseif (is_object($data) && (get_class($data) == 'services_json_error' ||
|
|
||||||
is_subclass_of($data, 'services_json_error'))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (class_exists('PEAR_Error')) {
|
|
||||||
|
|
||||||
class Services_JSON_Error extends PEAR_Error
|
|
||||||
{
|
|
||||||
function Services_JSON_Error($message = 'unknown error', $code = null,
|
|
||||||
$mode = null, $options = null, $userinfo = null)
|
|
||||||
{
|
|
||||||
parent::PEAR_Error($message, $code, $mode, $options, $userinfo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Ultimately, this class shall be descended from PEAR_Error
|
|
||||||
*/
|
|
||||||
class Services_JSON_Error
|
|
||||||
{
|
|
||||||
function Services_JSON_Error($message = 'unknown error', $code = null,
|
|
||||||
$mode = null, $options = null, $userinfo = null)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
21
thirdparty/json/LICENSE
vendored
21
thirdparty/json/LICENSE
vendored
@ -1,21 +0,0 @@
|
|||||||
Redistribution and use in source and binary forms, with or without
|
|
||||||
modification, are permitted provided that the following conditions are
|
|
||||||
met:
|
|
||||||
|
|
||||||
Redistributions of source code must retain the above copyright notice,
|
|
||||||
this list of conditions and the following disclaimer.
|
|
||||||
|
|
||||||
Redistributions in binary form must reproduce the above copyright
|
|
||||||
notice, this list of conditions and the following disclaimer in the
|
|
||||||
documentation and/or other materials provided with the distribution.
|
|
||||||
|
|
||||||
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
|
||||||
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
|
|
||||||
NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
||||||
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
||||||
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
|
|
||||||
USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
|
||||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
||||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
||||||
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
521
thirdparty/json/Test-JSON.php
vendored
521
thirdparty/json/Test-JSON.php
vendored
@ -1,521 +0,0 @@
|
|||||||
<?php
|
|
||||||
// $Id: Test-JSON.php,v 1.28 2006/06/28 05:54:17 migurski Exp $
|
|
||||||
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unit tests for Services_JSON.
|
|
||||||
* @see JSON.php
|
|
||||||
*
|
|
||||||
* @category
|
|
||||||
* @package Services_JSON
|
|
||||||
* @author Michal Migurski <mike-json@teczno.com>
|
|
||||||
* @author Matt Knapp <mdknapp[at]gmail[dot]com>
|
|
||||||
* @author Brett Stimmerman <brettstimmerman[at]gmail[dot]com>
|
|
||||||
* @copyright 2005 Michal Migurski
|
|
||||||
* @version CVS: $Id: Test-JSON.php,v 1.28 2006/06/28 05:54:17 migurski Exp $
|
|
||||||
* @license http://www.opensource.org/licenses/bsd-license.php
|
|
||||||
* @link http://pear.php.net/pepr/pepr-proposal-show.php?id=198
|
|
||||||
*/
|
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
|
||||||
|
|
||||||
require_once 'PHPUnit.php';
|
|
||||||
require_once 'JSON.php';
|
|
||||||
|
|
||||||
class Services_JSON_EncDec_TestCase extends PHPUnit_TestCase {
|
|
||||||
|
|
||||||
function Services_JSON_EncDec_TestCase($name) {
|
|
||||||
$this->PHPUnit_TestCase($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
$this->json = new Services_JSON();
|
|
||||||
|
|
||||||
$obj = new stdClass();
|
|
||||||
$obj->a_string = '"he":llo}:{world';
|
|
||||||
$obj->an_array = array(1, 2, 3);
|
|
||||||
$obj->obj = new stdClass();
|
|
||||||
$obj->obj->a_number = 123;
|
|
||||||
|
|
||||||
$this->obj = $obj;
|
|
||||||
$this->obj_j = '{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"obj":{"a_number":123}}';
|
|
||||||
$this->obj_d = 'object with properties, nested object and arrays';
|
|
||||||
|
|
||||||
$this->arr = array(null, true, array(1, 2, 3), "hello\"],[world!");
|
|
||||||
$this->arr_j = '[null,true,[1,2,3],"hello\"],[world!"]';
|
|
||||||
$this->arr_d = 'array with elements and nested arrays';
|
|
||||||
|
|
||||||
$this->str1 = 'hello world';
|
|
||||||
$this->str1_j = '"hello world"';
|
|
||||||
$this->str1_j_ = "'hello world'";
|
|
||||||
$this->str1_d = 'hello world';
|
|
||||||
$this->str1_d_ = 'hello world, double quotes';
|
|
||||||
|
|
||||||
$this->str2 = "hello\t\"world\"";
|
|
||||||
$this->str2_j = '"hello\\t\\"world\\""';
|
|
||||||
$this->str2_d = 'hello world, with tab, double-quotes';
|
|
||||||
|
|
||||||
$this->str3 = "\\\r\n\t\"/";
|
|
||||||
$this->str3_j = '"\\\\\\r\\n\\t\\"\\/"';
|
|
||||||
$this->str3_d = 'backslash, return, newline, tab, double-quote';
|
|
||||||
|
|
||||||
$this->str4 = 'héllö wørłd';
|
|
||||||
$this->str4_j = '"h\u00e9ll\u00f6 w\u00f8r\u0142d"';
|
|
||||||
$this->str4_j_ = '"héllö wørłd"';
|
|
||||||
$this->str4_d = 'hello world, with unicode';
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_to_JSON()
|
|
||||||
{
|
|
||||||
$this->assertEquals('null', $this->json->encode(null), 'type case: null');
|
|
||||||
$this->assertEquals('true', $this->json->encode(true), 'type case: boolean true');
|
|
||||||
$this->assertEquals('false', $this->json->encode(false), 'type case: boolean false');
|
|
||||||
|
|
||||||
$this->assertEquals('1', $this->json->encode(1), 'numeric case: 1');
|
|
||||||
$this->assertEquals('-1', $this->json->encode(-1), 'numeric case: -1');
|
|
||||||
$this->assertEquals('1.000000', $this->json->encode(1.0), 'numeric case: 1.0');
|
|
||||||
$this->assertEquals('1.100000', $this->json->encode(1.1), 'numeric case: 1.1');
|
|
||||||
|
|
||||||
$this->assertEquals($this->str1_j, $this->json->encode($this->str1), "string case: {$this->str1_d}");
|
|
||||||
$this->assertEquals($this->str2_j, $this->json->encode($this->str2), "string case: {$this->str2_d}");
|
|
||||||
$this->assertEquals($this->str3_j, $this->json->encode($this->str3), "string case: {$this->str3_d}");
|
|
||||||
$this->assertEquals($this->str4_j, $this->json->encode($this->str4), "string case: {$this->str4_d}");
|
|
||||||
|
|
||||||
$this->assertEquals($this->arr_j, $this->json->encode($this->arr), "array case: {$this->arr_d}");
|
|
||||||
$this->assertEquals($this->obj_j, $this->json->encode($this->obj), "object case: {$this->obj_d}");
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_from_JSON()
|
|
||||||
{
|
|
||||||
$this->assertEquals(null, $this->json->decode('null'), 'type case: null');
|
|
||||||
$this->assertEquals(true, $this->json->decode('true'), 'type case: boolean true');
|
|
||||||
$this->assertEquals(false, $this->json->decode('false'), 'type case: boolean false');
|
|
||||||
|
|
||||||
$this->assertEquals(1, $this->json->decode('1'), 'numeric case: 1');
|
|
||||||
$this->assertEquals(-1, $this->json->decode('-1'), 'numeric case: -1');
|
|
||||||
$this->assertEquals(1.0, $this->json->decode('1.0'), 'numeric case: 1.0');
|
|
||||||
$this->assertEquals(1.1, $this->json->decode('1.1'), 'numeric case: 1.1');
|
|
||||||
|
|
||||||
$this->assertEquals(11.0, $this->json->decode('1.1e1'), 'numeric case: 1.1e1');
|
|
||||||
$this->assertEquals(11.0, $this->json->decode('1.10e+1'), 'numeric case: 1.10e+1');
|
|
||||||
$this->assertEquals(0.11, $this->json->decode('1.1e-1'), 'numeric case: 1.1e-1');
|
|
||||||
$this->assertEquals(-0.11, $this->json->decode('-1.1e-1'), 'numeric case: -1.1e-1');
|
|
||||||
|
|
||||||
$this->assertEquals($this->str1, $this->json->decode($this->str1_j), "string case: {$this->str1_d}");
|
|
||||||
$this->assertEquals($this->str1, $this->json->decode($this->str1_j_), "string case: {$this->str1_d_}");
|
|
||||||
$this->assertEquals($this->str2, $this->json->decode($this->str2_j), "string case: {$this->str2_d}");
|
|
||||||
$this->assertEquals($this->str3, $this->json->decode($this->str3_j), "string case: {$this->str3_d}");
|
|
||||||
$this->assertEquals($this->str4, $this->json->decode($this->str4_j), "string case: {$this->str4_d}");
|
|
||||||
$this->assertEquals($this->str4, $this->json->decode($this->str4_j_), "string case: {$this->str4_d}");
|
|
||||||
|
|
||||||
$this->assertEquals($this->arr, $this->json->decode($this->arr_j), "array case: {$this->arr_d}");
|
|
||||||
$this->assertEquals($this->obj, $this->json->decode($this->obj_j), "object case: {$this->obj_d}");
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_to_then_from_JSON()
|
|
||||||
{
|
|
||||||
$this->assertEquals(null, $this->json->decode($this->json->encode(null)), 'type case: null');
|
|
||||||
$this->assertEquals(true, $this->json->decode($this->json->encode(true)), 'type case: boolean true');
|
|
||||||
$this->assertEquals(false, $this->json->decode($this->json->encode(false)), 'type case: boolean false');
|
|
||||||
|
|
||||||
$this->assertEquals(1, $this->json->decode($this->json->encode(1)), 'numeric case: 1');
|
|
||||||
$this->assertEquals(-1, $this->json->decode($this->json->encode(-1)), 'numeric case: -1');
|
|
||||||
$this->assertEquals(1.0, $this->json->decode($this->json->encode(1.0)), 'numeric case: 1.0');
|
|
||||||
$this->assertEquals(1.1, $this->json->decode($this->json->encode(1.1)), 'numeric case: 1.1');
|
|
||||||
|
|
||||||
$this->assertEquals($this->str1, $this->json->decode($this->json->encode($this->str1)), "string case: {$this->str1_d}");
|
|
||||||
$this->assertEquals($this->str2, $this->json->decode($this->json->encode($this->str2)), "string case: {$this->str2_d}");
|
|
||||||
$this->assertEquals($this->str3, $this->json->decode($this->json->encode($this->str3)), "string case: {$this->str3_d}");
|
|
||||||
$this->assertEquals($this->str4, $this->json->decode($this->json->encode($this->str4)), "string case: {$this->str4_d}");
|
|
||||||
|
|
||||||
$this->assertEquals($this->arr, $this->json->decode($this->json->encode($this->arr)), "array case: {$this->arr_d}");
|
|
||||||
$this->assertEquals($this->obj, $this->json->decode($this->json->encode($this->obj)), "object case: {$this->obj_d}");
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_from_then_to_JSON()
|
|
||||||
{
|
|
||||||
$this->assertEquals('null', $this->json->encode($this->json->decode('null')), 'type case: null');
|
|
||||||
$this->assertEquals('true', $this->json->encode($this->json->decode('true')), 'type case: boolean true');
|
|
||||||
$this->assertEquals('false', $this->json->encode($this->json->decode('false')), 'type case: boolean false');
|
|
||||||
|
|
||||||
$this->assertEquals('1', $this->json->encode($this->json->decode('1')), 'numeric case: 1');
|
|
||||||
$this->assertEquals('-1', $this->json->encode($this->json->decode('-1')), 'numeric case: -1');
|
|
||||||
$this->assertEquals('1.0', $this->json->encode($this->json->decode('1.0')), 'numeric case: 1.0');
|
|
||||||
$this->assertEquals('1.1', $this->json->encode($this->json->decode('1.1')), 'numeric case: 1.1');
|
|
||||||
|
|
||||||
$this->assertEquals($this->str1_j, $this->json->encode($this->json->decode($this->str1_j)), "string case: {$this->str1_d}");
|
|
||||||
$this->assertEquals($this->str2_j, $this->json->encode($this->json->decode($this->str2_j)), "string case: {$this->str2_d}");
|
|
||||||
$this->assertEquals($this->str3_j, $this->json->encode($this->json->decode($this->str3_j)), "string case: {$this->str3_d}");
|
|
||||||
$this->assertEquals($this->str4_j, $this->json->encode($this->json->decode($this->str4_j)), "string case: {$this->str4_d}");
|
|
||||||
$this->assertEquals($this->str4_j, $this->json->encode($this->json->decode($this->str4_j_)), "string case: {$this->str4_d}");
|
|
||||||
|
|
||||||
$this->assertEquals($this->arr_j, $this->json->encode($this->json->decode($this->arr_j)), "array case: {$this->arr_d}");
|
|
||||||
$this->assertEquals($this->obj_j, $this->json->encode($this->json->decode($this->obj_j)), "object case: {$this->obj_d}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Services_JSON_AssocArray_TestCase extends PHPUnit_TestCase {
|
|
||||||
|
|
||||||
function Services_JSON_AssocArray_TestCase($name) {
|
|
||||||
$this->PHPUnit_TestCase($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
$this->json_l = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
|
|
||||||
$this->json_s = new Services_JSON();
|
|
||||||
|
|
||||||
$this->arr = array('car1'=> array('color'=> 'tan', 'model' => 'sedan'),
|
|
||||||
'car2' => array('color' => 'red', 'model' => 'sports'));
|
|
||||||
$this->arr_jo = '{"car1":{"color":"tan","model":"sedan"},"car2":{"color":"red","model":"sports"}}';
|
|
||||||
$this->arr_d = 'associative array with nested associative arrays';
|
|
||||||
|
|
||||||
$this->arn = array(0=> array(0=> 'tan\\', 'model\\' => 'sedan'), 1 => array(0 => 'red', 'model' => 'sports'));
|
|
||||||
$this->arn_ja = '[{"0":"tan\\\\","model\\\\":"sedan"},{"0":"red","model":"sports"}]';
|
|
||||||
$this->arn_d = 'associative array with nested associative arrays, and some numeric keys thrown in';
|
|
||||||
|
|
||||||
$this->arrs = array (1 => 'one', 2 => 'two', 5 => 'five');
|
|
||||||
$this->arrs_jo = '{"1":"one","2":"two","5":"five"}';
|
|
||||||
$this->arrs_d = 'associative array numeric keys which are not fully populated in a range of 0 to length-1';
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_type()
|
|
||||||
{
|
|
||||||
$this->assertEquals('array', gettype($this->json_l->decode($this->arn_ja)), "loose type should be array");
|
|
||||||
$this->assertEquals('array', gettype($this->json_s->decode($this->arn_ja)), "strict type should be array");
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_to_JSON()
|
|
||||||
{
|
|
||||||
// both strict and loose JSON should result in an object
|
|
||||||
$this->assertEquals($this->arr_jo, $this->json_l->encode($this->arr), "array case - loose: {$this->arr_d}");
|
|
||||||
$this->assertEquals($this->arr_jo, $this->json_s->encode($this->arr), "array case - strict: {$this->arr_d}");
|
|
||||||
|
|
||||||
// ...unless the input array has some numeric indeces, in which case the behavior is to degrade to a regular array
|
|
||||||
$this->assertEquals($this->arn_ja, $this->json_s->encode($this->arn), "array case - strict: {$this->arn_d}");
|
|
||||||
|
|
||||||
// Test a sparsely populated numerically indexed associative array
|
|
||||||
$this->assertEquals($this->arrs_jo, $this->json_l->encode($this->arrs), "sparse numeric assoc array: {$this->arrs_d}");
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_to_then_from_JSON()
|
|
||||||
{
|
|
||||||
// these tests motivated by a bug in which strings that end
|
|
||||||
// with backslashes followed by quotes were incorrectly decoded.
|
|
||||||
|
|
||||||
foreach(array('\\"', '\\\\"', '\\"\\"', '\\""\\""', '\\\\"\\\\"') as $v) {
|
|
||||||
$this->assertEquals(array($v), $this->json_l->decode($this->json_l->encode(array($v))));
|
|
||||||
$this->assertEquals(array('a' => $v), $this->json_l->decode($this->json_l->encode(array('a' => $v))));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Services_JSON_NestedArray_TestCase extends PHPUnit_TestCase {
|
|
||||||
|
|
||||||
function Services_JSON_NestedArray_TestCase($name) {
|
|
||||||
$this->PHPUnit_TestCase($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
$this->json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
|
|
||||||
|
|
||||||
$this->str1 = '[{"this":"that"}]';
|
|
||||||
$this->arr1 = array(array('this' => 'that'));
|
|
||||||
|
|
||||||
$this->str2 = '{"this":["that"]}';
|
|
||||||
$this->arr2 = array('this' => array('that'));
|
|
||||||
|
|
||||||
$this->str3 = '{"params":[{"foo":["1"],"bar":"1"}]}';
|
|
||||||
$this->arr3 = array('params' => array(array('foo' => array('1'), 'bar' => '1')));
|
|
||||||
|
|
||||||
$this->str4 = '{"0": {"foo": "bar", "baz": "winkle"}}';
|
|
||||||
$this->arr4 = array('0' => array('foo' => 'bar', 'baz' => 'winkle'));
|
|
||||||
|
|
||||||
$this->str5 = '{"params":[{"options": {"old": [ ], "new": {"0": {"elements": {"old": [], "new": {"0": {"elementName": "aa", "isDefault": false, "elementRank": "0", "priceAdjust": "0", "partNumber": ""}}}, "optionName": "aa", "isRequired": false, "optionDesc": null}}}}]}';
|
|
||||||
$this->arr5 = array (
|
|
||||||
'params' => array (
|
|
||||||
0 => array (
|
|
||||||
'options' =>
|
|
||||||
array (
|
|
||||||
'old' => array(),
|
|
||||||
'new' => array (
|
|
||||||
0 => array (
|
|
||||||
'elements' => array (
|
|
||||||
'old' => array(),
|
|
||||||
'new' => array (
|
|
||||||
0 => array (
|
|
||||||
'elementName' => 'aa',
|
|
||||||
'isDefault' => false,
|
|
||||||
'elementRank' => '0',
|
|
||||||
'priceAdjust' => '0',
|
|
||||||
'partNumber' => '',
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
'optionName' => 'aa',
|
|
||||||
'isRequired' => false,
|
|
||||||
'optionDesc' => NULL,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_type()
|
|
||||||
{
|
|
||||||
$this->assertEquals('array', gettype($this->json->decode($this->str1)), "loose type should be array");
|
|
||||||
$this->assertEquals('array', gettype($this->json->decode($this->str2)), "loose type should be array");
|
|
||||||
$this->assertEquals('array', gettype($this->json->decode($this->str3)), "loose type should be array");
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_from_JSON()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->arr1, $this->json->decode($this->str1), "simple compactly-nested array");
|
|
||||||
$this->assertEquals($this->arr2, $this->json->decode($this->str2), "simple compactly-nested array");
|
|
||||||
$this->assertEquals($this->arr3, $this->json->decode($this->str3), "complex compactly nested array");
|
|
||||||
$this->assertEquals($this->arr4, $this->json->decode($this->str4), "complex compactly nested array");
|
|
||||||
$this->assertEquals($this->arr5, $this->json->decode($this->str5), "super complex compactly nested array");
|
|
||||||
}
|
|
||||||
|
|
||||||
function _test_from_JSON()
|
|
||||||
{
|
|
||||||
$super = '{"params":[{"options": {"old": {}, "new": {"0": {"elements": {"old": {}, "new": {"0": {"elementName": "aa", "isDefault": false, "elementRank": "0", "priceAdjust": "0", "partNumber": ""}}}, "optionName": "aa", "isRequired": false, "optionDesc": ""}}}}]}';
|
|
||||||
print("trying {$super}...\n");
|
|
||||||
print var_export($this->json->decode($super));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Services_JSON_Object_TestCase extends PHPUnit_TestCase {
|
|
||||||
|
|
||||||
function Services_JSON_Object_TestCase($name) {
|
|
||||||
$this->PHPUnit_TestCase($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
$this->json_l = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
|
|
||||||
$this->json_s = new Services_JSON();
|
|
||||||
|
|
||||||
$this->obj_j = '{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"obj":{"a_number":123}}';
|
|
||||||
|
|
||||||
$this->obj1->car1->color = 'tan';
|
|
||||||
$this->obj1->car1->model = 'sedan';
|
|
||||||
$this->obj1->car2->color = 'red';
|
|
||||||
$this->obj1->car2->model = 'sports';
|
|
||||||
$this->obj1_j = '{"car1":{"color":"tan","model":"sedan"},"car2":{"color":"red","model":"sports"}}';
|
|
||||||
$this->obj1_d = 'Object with nested objects';
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_type()
|
|
||||||
{
|
|
||||||
$this->assertEquals('object', gettype($this->json_s->decode($this->obj_j)), "checking whether decoded type is object");
|
|
||||||
$this->assertEquals('array', gettype($this->json_l->decode($this->obj_j)), "checking whether decoded type is array");
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_to_JSON()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->obj1_j, $this->json_s->encode($this->obj1), "object - strict: {$this->obj1_d}");
|
|
||||||
$this->assertEquals($this->obj1_j, $this->json_l->encode($this->obj1), "object - loose: {$this->obj1_d}");
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_from_then_to_JSON()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->obj_j, $this->json_s->encode($this->json_s->decode($this->obj_j)), "object case");
|
|
||||||
$this->assertEquals($this->obj_j, $this->json_l->encode($this->json_l->decode($this->obj_j)), "array case");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Services_JSON_Spaces_Comments_TestCase extends PHPUnit_TestCase {
|
|
||||||
|
|
||||||
function Services_JSON_Spaces_Comments_TestCase($name) {
|
|
||||||
$this->PHPUnit_TestCase($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
$this->json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
|
|
||||||
|
|
||||||
$this->obj_j = '{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"obj":{"a_number":123}}';
|
|
||||||
|
|
||||||
$this->obj_js = '{"a_string": "\"he\":llo}:{world",
|
|
||||||
"an_array":[1, 2, 3],
|
|
||||||
"obj": {"a_number":123}}';
|
|
||||||
|
|
||||||
$this->obj_jc1 = '{"a_string": "\"he\":llo}:{world",
|
|
||||||
// here is a comment, hoorah
|
|
||||||
"an_array":[1, 2, 3],
|
|
||||||
"obj": {"a_number":123}}';
|
|
||||||
|
|
||||||
$this->obj_jc2 = '/* this here is the sneetch */ "the sneetch"
|
|
||||||
// this has been the sneetch.';
|
|
||||||
|
|
||||||
$this->obj_jc3 = '{"a_string": "\"he\":llo}:{world",
|
|
||||||
/* here is a comment, hoorah */
|
|
||||||
"an_array":[1, 2, 3 /* and here is another */],
|
|
||||||
"obj": {"a_number":123}}';
|
|
||||||
|
|
||||||
$this->obj_jc4 = '{\'a_string\': "\"he\":llo}:{world",
|
|
||||||
/* here is a comment, hoorah */
|
|
||||||
\'an_array\':[1, 2, 3 /* and here is another */],
|
|
||||||
"obj": {"a_number":123}}';
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_spaces()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->json->decode($this->obj_j), $this->json->decode($this->obj_js), "checking whether notation with spaces works");
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_comments()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->json->decode($this->obj_j), $this->json->decode($this->obj_jc1), "checking whether notation with single line comments works");
|
|
||||||
$this->assertEquals('the sneetch', $this->json->decode($this->obj_jc2), "checking whether notation with multiline comments works");
|
|
||||||
$this->assertEquals($this->json->decode($this->obj_j), $this->json->decode($this->obj_jc3), "checking whether notation with multiline comments works");
|
|
||||||
$this->assertEquals($this->json->decode($this->obj_j), $this->json->decode($this->obj_jc4), "checking whether notation with single-quotes and multiline comments works");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Services_JSON_Empties_TestCase extends PHPUnit_TestCase {
|
|
||||||
|
|
||||||
function Services_JSON_Empties_TestCase($name) {
|
|
||||||
$this->PHPUnit_TestCase($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
$this->json_l = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
|
|
||||||
$this->json_s = new Services_JSON();
|
|
||||||
|
|
||||||
$this->obj0_j = '{}';
|
|
||||||
$this->arr0_j = '[]';
|
|
||||||
|
|
||||||
$this->obj1_j = '{ }';
|
|
||||||
$this->arr1_j = '[ ]';
|
|
||||||
|
|
||||||
$this->obj2_j = '{ /* comment inside */ }';
|
|
||||||
$this->arr2_j = '[ /* comment inside */ ]';
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_type()
|
|
||||||
{
|
|
||||||
$this->assertEquals('array', gettype($this->json_l->decode($this->arr0_j)), "should be array");
|
|
||||||
$this->assertEquals('object', gettype($this->json_s->decode($this->obj0_j)), "should be object");
|
|
||||||
|
|
||||||
$this->assertEquals(0, count($this->json_l->decode($this->arr0_j)), "should be empty array");
|
|
||||||
$this->assertEquals(0, count(get_object_vars($this->json_s->decode($this->obj0_j))), "should be empty object");
|
|
||||||
|
|
||||||
$this->assertEquals('array', gettype($this->json_l->decode($this->arr1_j)), "should be array, even with space");
|
|
||||||
$this->assertEquals('object', gettype($this->json_s->decode($this->obj1_j)), "should be object, even with space");
|
|
||||||
|
|
||||||
$this->assertEquals(0, count($this->json_l->decode($this->arr1_j)), "should be empty array, even with space");
|
|
||||||
$this->assertEquals(0, count(get_object_vars($this->json_s->decode($this->obj1_j))), "should be empty object, even with space");
|
|
||||||
|
|
||||||
$this->assertEquals('array', gettype($this->json_l->decode($this->arr2_j)), "should be array, despite comment");
|
|
||||||
$this->assertEquals('object', gettype($this->json_s->decode($this->obj2_j)), "should be object, despite comment");
|
|
||||||
|
|
||||||
$this->assertEquals(0, count($this->json_l->decode($this->arr2_j)), "should be empty array, despite comment");
|
|
||||||
$this->assertEquals(0, count(get_object_vars($this->json_s->decode($this->obj2_j))), "should be empty object, despite commentt");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Services_JSON_UnquotedKeys_TestCase extends PHPUnit_TestCase {
|
|
||||||
|
|
||||||
function Services_JSON_UnquotedKeys_TestCase($name) {
|
|
||||||
$this->PHPUnit_TestCase($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
$this->json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
|
|
||||||
|
|
||||||
$this->arn = array(0=> array(0=> 'tan', 'model' => 'sedan'), 1 => array(0 => 'red', 'model' => 'sports'));
|
|
||||||
$this->arn_ja = '[{0:"tan","model":"sedan"},{"0":"red",model:"sports"}]';
|
|
||||||
$this->arn_d = 'associative array with unquoted keys, nested associative arrays, and some numeric keys thrown in';
|
|
||||||
|
|
||||||
$this->arrs = array (1 => 'one', 2 => 'two', 5 => 'fi"ve');
|
|
||||||
$this->arrs_jo = '{"1":"one",2:"two","5":\'fi"ve\'}';
|
|
||||||
$this->arrs_d = 'associative array with unquoted keys, single-quoted values, numeric keys which are not fully populated in a range of 0 to length-1';
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_from_JSON()
|
|
||||||
{
|
|
||||||
// ...unless the input array has some numeric indeces, in which case the behavior is to degrade to a regular array
|
|
||||||
$this->assertEquals($this->arn, $this->json->decode($this->arn_ja), "array case - strict: {$this->arn_d}");
|
|
||||||
|
|
||||||
// Test a sparsely populated numerically indexed associative array
|
|
||||||
$this->assertEquals($this->arrs, $this->json->decode($this->arrs_jo), "sparse numeric assoc array: {$this->arrs_d}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Services_JSON_ErrorSuppression_TestCase extends PHPUnit_TestCase {
|
|
||||||
|
|
||||||
function Services_JSON_ErrorSuppression_TestCase($name) {
|
|
||||||
$this->PHPUnit_TestCase($name);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setUp() {
|
|
||||||
$this->json = new Services_JSON();
|
|
||||||
$this->json_ = new Services_JSON(SERVICES_JSON_SUPPRESS_ERRORS);
|
|
||||||
|
|
||||||
$this->res = tmpfile();
|
|
||||||
$this->res_j_ = 'null';
|
|
||||||
$this->res_d = 'naked resource';
|
|
||||||
|
|
||||||
$this->arr = array('a', 1, tmpfile());
|
|
||||||
$this->arr_j_ = '["a",1,null]';
|
|
||||||
$this->arr_d = 'array with string, number and resource';
|
|
||||||
|
|
||||||
$obj = new stdClass();
|
|
||||||
$obj->a_string = '"he":llo}:{world';
|
|
||||||
$obj->an_array = array(1, 2, 3);
|
|
||||||
$obj->resource = tmpfile();
|
|
||||||
|
|
||||||
$this->obj = $obj;
|
|
||||||
$this->obj_j_ = '{"a_string":"\"he\":llo}:{world","an_array":[1,2,3],"resource":null}';
|
|
||||||
$this->obj_d = 'object with properties, array, and nested resource';
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_to_JSON()
|
|
||||||
{
|
|
||||||
$this->assertTrue(Services_JSON::isError($this->json->encode($this->res)), "resource case: {$this->res_d}");
|
|
||||||
$this->assertTrue(Services_JSON::isError($this->json->encode($this->arr)), "array case: {$this->arr_d}");
|
|
||||||
$this->assertTrue(Services_JSON::isError($this->json->encode($this->obj)), "object case: {$this->obj_d}");
|
|
||||||
}
|
|
||||||
|
|
||||||
function test_to_JSON_suppressed()
|
|
||||||
{
|
|
||||||
$this->assertEquals($this->res_j_, $this->json_->encode($this->res), "resource case: {$this->res_d}");
|
|
||||||
$this->assertEquals($this->arr_j_, $this->json_->encode($this->arr), "array case: {$this->arr_d}");
|
|
||||||
$this->assertEquals($this->obj_j_, $this->json_->encode($this->obj), "object case: {$this->obj_d}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$suite = new PHPUnit_TestSuite('Services_JSON_EncDec_TestCase');
|
|
||||||
$result = PHPUnit::run($suite);
|
|
||||||
echo $result->toString();
|
|
||||||
|
|
||||||
$suite = new PHPUnit_TestSuite('Services_JSON_AssocArray_TestCase');
|
|
||||||
$result = PHPUnit::run($suite);
|
|
||||||
echo $result->toString();
|
|
||||||
|
|
||||||
$suite = new PHPUnit_TestSuite('Services_JSON_NestedArray_TestCase');
|
|
||||||
$result = PHPUnit::run($suite);
|
|
||||||
echo $result->toString();
|
|
||||||
|
|
||||||
$suite = new PHPUnit_TestSuite('Services_JSON_Object_TestCase');
|
|
||||||
$result = PHPUnit::run($suite);
|
|
||||||
echo $result->toString();
|
|
||||||
|
|
||||||
$suite = new PHPUnit_TestSuite('Services_JSON_Spaces_Comments_TestCase');
|
|
||||||
$result = PHPUnit::run($suite);
|
|
||||||
echo $result->toString();
|
|
||||||
|
|
||||||
$suite = new PHPUnit_TestSuite('Services_JSON_Empties_TestCase');
|
|
||||||
$result = PHPUnit::run($suite);
|
|
||||||
echo $result->toString();
|
|
||||||
|
|
||||||
$suite = new PHPUnit_TestSuite('Services_JSON_UnquotedKeys_TestCase');
|
|
||||||
$result = PHPUnit::run($suite);
|
|
||||||
echo $result->toString();
|
|
||||||
|
|
||||||
$suite = new PHPUnit_TestSuite('Services_JSON_ErrorSuppression_TestCase');
|
|
||||||
$result = PHPUnit::run($suite);
|
|
||||||
echo $result->toString();
|
|
||||||
|
|
||||||
?>
|
|
6
thirdparty/simpletest/form.php
vendored
6
thirdparty/simpletest/form.php
vendored
@ -172,7 +172,7 @@ class SimpleForm {
|
|||||||
*/
|
*/
|
||||||
function _addRadioButton(&$tag) {
|
function _addRadioButton(&$tag) {
|
||||||
if (! isset($this->_radios[$tag->getName()])) {
|
if (! isset($this->_radios[$tag->getName()])) {
|
||||||
$this->_widgets[] = &new SimpleRadioGroup();
|
$this->_widgets[] = new SimpleRadioGroup();
|
||||||
$this->_radios[$tag->getName()] = count($this->_widgets) - 1;
|
$this->_radios[$tag->getName()] = count($this->_widgets) - 1;
|
||||||
}
|
}
|
||||||
$this->_widgets[$this->_radios[$tag->getName()]]->addWidget($tag);
|
$this->_widgets[$this->_radios[$tag->getName()]]->addWidget($tag);
|
||||||
@ -191,7 +191,7 @@ class SimpleForm {
|
|||||||
$index = $this->_checkboxes[$tag->getName()];
|
$index = $this->_checkboxes[$tag->getName()];
|
||||||
if (! SimpleTestCompatibility::isA($this->_widgets[$index], 'SimpleCheckboxGroup')) {
|
if (! SimpleTestCompatibility::isA($this->_widgets[$index], 'SimpleCheckboxGroup')) {
|
||||||
$previous = &$this->_widgets[$index];
|
$previous = &$this->_widgets[$index];
|
||||||
$this->_widgets[$index] = &new SimpleCheckboxGroup();
|
$this->_widgets[$index] = new SimpleCheckboxGroup();
|
||||||
$this->_widgets[$index]->addWidget($previous);
|
$this->_widgets[$index]->addWidget($previous);
|
||||||
}
|
}
|
||||||
$this->_widgets[$index]->addWidget($tag);
|
$this->_widgets[$index]->addWidget($tag);
|
||||||
@ -352,4 +352,4 @@ class SimpleForm {
|
|||||||
return $this->_encode();
|
return $this->_encode();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
14
thirdparty/simpletest/http.php
vendored
14
thirdparty/simpletest/http.php
vendored
@ -98,9 +98,9 @@ class SimpleRoute {
|
|||||||
*/
|
*/
|
||||||
function &_createSocket($scheme, $host, $port, $timeout) {
|
function &_createSocket($scheme, $host, $port, $timeout) {
|
||||||
if (in_array($scheme, array('https'))) {
|
if (in_array($scheme, array('https'))) {
|
||||||
$socket = &new SimpleSecureSocket($host, $port, $timeout);
|
$socket = new SimpleSecureSocket($host, $port, $timeout);
|
||||||
} else {
|
} else {
|
||||||
$socket = &new SimpleSocket($host, $port, $timeout);
|
$socket = new SimpleSocket($host, $port, $timeout);
|
||||||
}
|
}
|
||||||
return $socket;
|
return $socket;
|
||||||
}
|
}
|
||||||
@ -279,7 +279,7 @@ class SimpleHttpRequest {
|
|||||||
* @access protected
|
* @access protected
|
||||||
*/
|
*/
|
||||||
function &_createResponse(&$socket) {
|
function &_createResponse(&$socket) {
|
||||||
$response = &new SimpleHttpResponse(
|
$response = new SimpleHttpResponse(
|
||||||
$socket,
|
$socket,
|
||||||
$this->_route->getUrl(),
|
$this->_route->getUrl(),
|
||||||
$this->_encoding);
|
$this->_encoding);
|
||||||
@ -516,13 +516,13 @@ class SimpleHttpResponse extends SimpleStickyError {
|
|||||||
function _parse($raw) {
|
function _parse($raw) {
|
||||||
if (! $raw) {
|
if (! $raw) {
|
||||||
$this->_setError('Nothing fetched');
|
$this->_setError('Nothing fetched');
|
||||||
$this->_headers = &new SimpleHttpHeaders('');
|
$this->_headers = new SimpleHttpHeaders('');
|
||||||
} elseif (! strstr($raw, "\r\n\r\n")) {
|
} elseif (! strstr($raw, "\r\n\r\n")) {
|
||||||
$this->_setError('Could not split headers from content');
|
$this->_setError('Could not split headers from content');
|
||||||
$this->_headers = &new SimpleHttpHeaders($raw);
|
$this->_headers = new SimpleHttpHeaders($raw);
|
||||||
} else {
|
} else {
|
||||||
list($headers, $this->_content) = split("\r\n\r\n", $raw, 2);
|
list($headers, $this->_content) = split("\r\n\r\n", $raw, 2);
|
||||||
$this->_headers = &new SimpleHttpHeaders($headers);
|
$this->_headers = new SimpleHttpHeaders($headers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -621,4 +621,4 @@ class SimpleHttpResponse extends SimpleStickyError {
|
|||||||
return ! $packet;
|
return ! $packet;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
10
thirdparty/simpletest/page.php
vendored
10
thirdparty/simpletest/page.php
vendored
@ -163,7 +163,7 @@ class SimplePageBuilder extends SimpleSaxListener {
|
|||||||
* @access protected
|
* @access protected
|
||||||
*/
|
*/
|
||||||
function &_createPage($response) {
|
function &_createPage($response) {
|
||||||
$page = &new SimplePage($response);
|
$page = new SimplePage($response);
|
||||||
return $page;
|
return $page;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +175,7 @@ class SimplePageBuilder extends SimpleSaxListener {
|
|||||||
* @access protected
|
* @access protected
|
||||||
*/
|
*/
|
||||||
function &_createParser(&$listener) {
|
function &_createParser(&$listener) {
|
||||||
$parser = &new SimpleHtmlSaxParser($listener);
|
$parser = new SimpleHtmlSaxParser($listener);
|
||||||
return $parser;
|
return $parser;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -188,7 +188,7 @@ class SimplePageBuilder extends SimpleSaxListener {
|
|||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function startElement($name, $attributes) {
|
function startElement($name, $attributes) {
|
||||||
$factory = &new SimpleTagBuilder();
|
$factory = new SimpleTagBuilder();
|
||||||
$tag = $factory->createTag($name, $attributes);
|
$tag = $factory->createTag($name, $attributes);
|
||||||
if (! $tag) {
|
if (! $tag) {
|
||||||
return true;
|
return true;
|
||||||
@ -641,7 +641,7 @@ class SimplePage {
|
|||||||
* @access public
|
* @access public
|
||||||
*/
|
*/
|
||||||
function acceptFormStart(&$tag) {
|
function acceptFormStart(&$tag) {
|
||||||
$this->_open_forms[] = &new SimpleForm($tag, $this);
|
$this->_open_forms[] = new SimpleForm($tag, $this);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -980,4 +980,4 @@ class SimplePage {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
6
thirdparty/simpletest/parser.php
vendored
6
thirdparty/simpletest/parser.php
vendored
@ -197,7 +197,7 @@ class SimpleLexer {
|
|||||||
$this->_case = $case;
|
$this->_case = $case;
|
||||||
$this->_regexes = array();
|
$this->_regexes = array();
|
||||||
$this->_parser = &$parser;
|
$this->_parser = &$parser;
|
||||||
$this->_mode = &new SimpleStateStack($start);
|
$this->_mode = new SimpleStateStack($start);
|
||||||
$this->_mode_handlers = array($start => $start);
|
$this->_mode_handlers = array($start => $start);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -579,7 +579,7 @@ class SimpleHtmlSaxParser {
|
|||||||
* @static
|
* @static
|
||||||
*/
|
*/
|
||||||
function &createLexer(&$parser) {
|
function &createLexer(&$parser) {
|
||||||
$lexer = &new SimpleHtmlLexer($parser);
|
$lexer = new SimpleHtmlLexer($parser);
|
||||||
return $lexer;
|
return $lexer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -761,4 +761,4 @@ class SimpleSaxListener {
|
|||||||
function addContent($text) {
|
function addContent($text) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
8
thirdparty/simpletest/url.php
vendored
8
thirdparty/simpletest/url.php
vendored
@ -106,7 +106,7 @@ class SimpleUrl {
|
|||||||
}
|
}
|
||||||
if (preg_match('/^([^\/]*)@(.*)/', $url, $matches)) {
|
if (preg_match('/^([^\/]*)@(.*)/', $url, $matches)) {
|
||||||
$url = $prefix . $matches[2];
|
$url = $prefix . $matches[2];
|
||||||
$parts = split(":", $matches[1]);
|
$parts = preg_split('/:/', $matches[1]);
|
||||||
return array(
|
return array(
|
||||||
urldecode($parts[0]),
|
urldecode($parts[0]),
|
||||||
isset($parts[1]) ? urldecode($parts[1]) : false);
|
isset($parts[1]) ? urldecode($parts[1]) : false);
|
||||||
@ -184,7 +184,7 @@ class SimpleUrl {
|
|||||||
function _parseRequest($raw) {
|
function _parseRequest($raw) {
|
||||||
$this->_raw = $raw;
|
$this->_raw = $raw;
|
||||||
$request = new SimpleGetEncoding();
|
$request = new SimpleGetEncoding();
|
||||||
foreach (split("&", $raw) as $pair) {
|
foreach (preg_split('/&/', $raw) as $pair) {
|
||||||
if (preg_match('/(.*?)=(.*)/', $pair, $matches)) {
|
if (preg_match('/(.*?)=(.*)/', $pair, $matches)) {
|
||||||
$request->add($matches[1], urldecode($matches[2]));
|
$request->add($matches[1], urldecode($matches[2]));
|
||||||
} elseif ($pair) {
|
} elseif ($pair) {
|
||||||
@ -379,7 +379,7 @@ class SimpleUrl {
|
|||||||
*/
|
*/
|
||||||
function clearRequest() {
|
function clearRequest() {
|
||||||
$this->_raw = false;
|
$this->_raw = false;
|
||||||
$this->_request = &new SimpleGetEncoding();
|
$this->_request = new SimpleGetEncoding();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -525,4 +525,4 @@ class SimpleUrl {
|
|||||||
return 'com|edu|net|org|gov|mil|int|biz|info|name|pro|aero|coop|museum';
|
return 'com|edu|net|org|gov|mil|int|biz|info|name|pro|aero|coop|museum';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -717,7 +717,7 @@ class ViewableData_Debugger extends ViewableData {
|
|||||||
|
|
||||||
// check for an extra attached data
|
// check for an extra attached data
|
||||||
if($this->object->hasMethod('data') && $this->object->data() != $this->object) {
|
if($this->object->hasMethod('data') && $this->object->data() != $this->object) {
|
||||||
$debug .= Object::create('ViewableData_Debugger', $this->object->data())->forTemplate();
|
$debug .= ViewableData_Debugger::create($this->object->data())->forTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $debug;
|
return $debug;
|
||||||
|
Loading…
Reference in New Issue
Block a user