ktwidgets.php
来自「PHP 知识管理系统(基于树结构的知识管理系统), 英文原版的PHP源码。」· PHP 代码 · 共 931 行 · 第 1/3 页
PHP
931 行
$this->aVocab = $new_vocab;
}
}
class KTDescriptorSelectionWidget extends KTWidget {
var $sNamespace = 'ktcore.widgets.descriptorselection';
var $sTemplate = 'ktcore/forms/widgets/descriptor';
var $aJavascript = array('resources/js/jsonlookup.js');
function configure($aOptions) {
$res = parent::configure($aOptions);
if (PEAR::isError($res)) {
return $res;
}
}
function getWidget() {
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate($this->sTemplate);
$src_location = $this->aOptions['src'];
$sJS = sprintf('addLoadEvent(initJSONLookup("%s", "%s"));', $this->sBasename, $src_location);
// its bad, but that's life.
$oPage =& $GLOBALS['main'];
$oPage->requireJSStandalone($sJS);
$this->aOptions['multi'] = true;
$aTemplateData = array(
'context' => $this,
'label' => $this->sLabel,
'description' => $this->sDescription,
'name' => $this->sName,
'required' => $this->bRequired,
'has_id' => ($this->sId !== null),
'id' => $this->sId,
'has_value' => ($this->value !== null),
'value' => $this->value,
'has_errors' => $bHasErrors,
'errors' => $this->aErrors,
'short_name' => $this->sBasename,
'options' => $this->aOptions,
);
return $oTemplate->render($aTemplateData);
}
}
class KTCoreTreeMetadataWidget extends KTWidget {
var $sNamespace = 'ktcore.widgets.treemetadata';
var $iFieldId;
var $aCSS = array('resources/css/kt-treewidget.css');
function configure($aOptions) {
$res = parent::configure($aOptions);
if (PEAR::isError($res)) {
return $res;
}
$this->iFieldId = KTUtil::arrayGet($aOptions, 'field_id');
if (is_null($this->iFieldId)) {
return PEAR::raiseError(_kt('Tree metadata fields must be associated with a particular type.'));
}
}
function getWidget() {
// very simple, general purpose passthrough. Chances are this is sufficient,
// just override the template being used.
$bHasErrors = false;
require_once(KT_LIB_DIR . '/documentmanagement/MDTree.inc');
$fieldTree = new MDTree();
$fieldTree->buildForField($this->iFieldId);
$fieldTree->setActiveItem($this->value);
return $fieldTree->_evilTreeRenderer($fieldTree, $this->sName);
}
}
// wrap a set of fields into a core, basic one.
//
// this *also* subdivides the form data output namespace.
// to do this, it encapsulates a *large* amount of the KTWidget API
class KTCoreFieldsetWidget extends KTWidget {
var $sNamespace = 'ktcore.widgets.fieldset';
var $_widgets;
var $sDescription;
var $sLabel;
function configure($aOptions) {
// do NOT use parent.
$this->sLabel = KTUtil::arrayGet($aOptions, 'label');
$this->sDescription = KTUtil::arrayGet($aOptions, 'description');
$this->sName = KTUtil::arrayGet($aOptions, 'name');
$this->sBasename = $this->sName;
$aWidgets = (array) KTUtil::arrayGet($aOptions, 'widgets');
// very similar to the one in forms.inc.php
if (is_null($this->_oWF)) {
$this->_oWF =& KTWidgetFactory::getSingleton();
}
$this->_widgets = array();
// we don't want to expose the factory stuff to the user - its an
// arbitrary distinction to the user. Good point from NBM ;)
foreach ($aWidgets as $aInfo) {
if (is_null($aInfo)) {
continue;
} else if (is_object($aInfo)) {
// assume this is a fully configured object
$this->_widgets[] = $aInfo;
} else {
$namespaceOrObject = $aInfo[0];
$config = (array) $aInfo[1];
$this->_widgets[] = $this->_oWF->get($namespaceOrObject, $config);
}
}
}
function render() {
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate('ktcore/forms/widgets/fieldset');
$aTemplateData = array(
'context' => $this,
'label' => $this->sLabel,
'description' => $this->sDescription,
'widgets' => $this->renderWidgets(),
);
return $oTemplate->render($aTemplateData);
}
function renderWidgets() {
$rendered = array();
foreach ($this->_widgets as $v) {
if (PEAR::isError($v)) {
$rendered[] = sprintf(_kt('<div class="ktError"><p>Unable to show widget — %s</p></div>'), $v->getMessage());
} else {
$rendered[] = $v->render();
}
}
return implode(' ', $rendered);
}
function getDefault() {
// we need to do a little more admin here
// to obtain the default
// annoyingly
$d = array();
foreach ($this->_widgets as $w) {
if (PEAR::isError($w)) {
continue;
}
$d[$w->getBasename()] = $w->getDefault();
}
return $d;
}
function setDefault($aValue) {
$d = (array) $aValue;
foreach ($this->_widgets as $k => $w) {
$oWidget =& $this->_widgets[$k];
$oWidget->setDefault(KTUtil::arrayGet($d, $oWidget->getBasename(), $oWidget->getDefault()));
}
}
function wrapName($sOuter) {
$this->sName = sprintf('%s[%s]', $sOuter, $this->sBasename);
// now, chain to our children
foreach ($this->_widgets as $k => $v) {
$oWidget =& $this->_widgets[$k];
if (PEAR::isError($oWidget)) {
continue;
}
$oWidget->wrapName($this->sName);
}
}
function setErrors($aErrors = null) {
if (is_array($aErrors)) {
$this->aErrors = $aErrors;
}
foreach ($this->_widgets as $k => $w) {
$oWidget =& $this->_widgets[$k];
$oWidget->setErrors(KTUtil::arrayGet($aErrors, $oWidget->getBasename()));
}
}
function getValidators() {
// we use a fieldsetValidator here.
$extra_validators = array();
foreach ($this->_widgets as $oWidget) {
$res = $oWidget->getValidators();
if (!is_null($res)) {
if (is_array($res)) {
$extra_validators = kt_array_merge($extra_validators, $res);
} else {
$extra_validators[] = $res;
}
}
}
$oVF =& KTValidatorFactory::getSingleton();
return array($oVF->get('ktcore.validators.fieldset', array(
'test' => $this->sBasename,
'validators' => &$extra_validators,
)));
}
function process($raw_data) {
$d = (array) KTUtil::arrayGet($raw_data, $this->sBasename);
$o = array();
// we now need to recombine the process
foreach ($this->_widgets as $oWidget) {
$o =& kt_array_merge($o, $oWidget->process($d));
}
return array($this->sBasename => $o);
}
}
class KTCoreTransparentFieldsetWidget extends KTCoreFieldsetWidget {
var $sNamespace = 'ktcore.widgets.transparentfieldset';
function render() {
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate('ktcore/forms/widgets/transparent_fieldset');
$aTemplateData = array(
'widgets' => $this->renderWidgets(),
);
return $oTemplate->render($aTemplateData);
}
}
class KTExtraConditionalFieldsetWidget extends KTCoreFieldsetWidget {
var $sNamespace = 'ktextra.conditionalmetadata.fieldset';
function render() {
$oTemplating =& KTTemplating::getSingleton();
$oTemplate = $oTemplating->loadTemplate('ktcore/forms/widgets/conditionalfieldset');
$aTemplateData = array(
'context' => $this,
'label' => $this->sLabel,
'description' => $this->sDescription,
);
return $oTemplate->render($aTemplateData);
}
}
class KTCoreCollectionWidget extends KTWidget {
var $sNamespace = 'ktcore.widgets.collection';
var $sTemplate = 'ktcore/forms/widgets/collectionframe';
var $oCollection;
var $sCode;
function configure($aOptions) {
$aOptions['broken_name'] = KTUtil::arrayGet($aOptions, 'broken_name', true, false);
$res = parent::configure($aOptions);
if (PEAR::isError($res)) {
return $res;
}
$this->oCollection = KTUtil::arrayGet($aOptions, 'collection');
if(empty($this->oCollection)) return PEAR::raiseError(_kt('No collection specified.'));
$this->iFolderId = KTUtil::arrayGet($aOptions, 'folder_id');
if(empty($this->iFolderId)) return PEAR::raiseError(_kt('No initial folder specified specified.'));
$this->aBCUrlParams = KTUtil::arrayGet($aOptions, 'bcurl_params', array());
$this->aCols = array();
foreach($this->oCollection->columns as $oCol) {
$this->aCols[] = $oCol->namespace;
}
$this->sCode = KTUtil::randomString();
$this->sCollection = serialize($this->oCollection);
$_SESSION['collection_widgets'][$this->sCode] = serialize($this);
$this->requireJSResource('resources/js/collectionframe.js');
}
function getTargetURL() {
$oPluginRegistry =& KTPluginRegistry::getSingleton();
$oPlugin =& $oPluginRegistry->getPlugin('ktcore.plugin');
$sPath = $oPlugin->getPagePath('collection');
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?