/** * Utility function to return title with description as hover * * @param CBSimpleXMLElement $node * @return null|string */ function _title(&$node) { $description = $node->attributes('description'); if ($description) { $description = CBPTXT::T($description); $name = $node->attributes('name'); return ' title="' . htmlspecialchars($name . '|' . $description) . '"'; } return null; }
/** * Returns full label of the type of the field (backend use only!) * * @param moscomprofilerField $field * @return boolean TRUE if success, FALSE if failed */ function getFieldsParamsLabel() { global $_PLUGINS; $plugin = $_PLUGINS->getPluginObject($this->_pluginid); if ($this->_fieldXml) { return $plugin->name . ': ' . $this->_fieldXml->attributes('label'); } return $plugin->name . ': ' . "specific field-parameters"; }
/** * Appends (copies) a child $source and all its descendants to $this node * @since 1.2.4 * * @param CBSimpleXMLElement $source * @param callback $callBack to check/transform data or attributes of a node: $destinationData = function ( string|array $sourceData, CBSimpleXMLElement $sourceNode, CBSimpleXMLElement $destinationParentNode ); */ function &addChildWithDescendants(&$source, $callBack = null) { if ($callBack === null) { $child = $this->addChildWithAttr($source->name(), $source->data(), null, $source->attributes()); } else { $child = $this->addChildWithAttr($source->name(), call_user_func_array($callBack, array($source->data(), $source, $this)), null, call_user_func_array($callBack, array($source->attributes(), $source, $this))); } foreach ($source->children() as $sourceChild) { $child->addChildWithDescendants($sourceChild, $callBack); } return $child; }
function drawUrl( $cbUri, &$sourceElem, &$data, $id, $htmlspecialchars = true, $inPage = true ) { global $_CB_framework; $ui = $_CB_framework->getUi(); if ( substr( $cbUri, 0, 4 ) == 'cbo:' ) { $subTaskValue = substr( $cbUri, 4 ); switch ( $subTaskValue ) { case 'newrow': $id = 0; // fallthrough: no break on purpose. case 'rowedit': //TBD this is duplicate of below $baseUrl = 'index.php'; $baseUrl .= '?option=' . $this->_options['option'] . '&task=' . $this->_options['task'] . '&cid=' . $this->_options['pluginid']; $url = $baseUrl . '&table=' . $this->_tableBrowserModel->attributes( 'name' ) . '&action=editrow'; // below: . '&tid=' . $id; break; case 'saveorder': case 'editrows': case 'deleterows': case 'copyrows': case 'updaterows': case 'publish': case 'unpublish': case 'enable': case 'disable': default: $url = 'javascript:cbDoListTask(this, ' // cb //TBD: this is duplicate of pager. . "'" . $this->taskName( false ). "','" // task . $this->subtaskName( false ). "','" // subtaskName . $this->subtaskValue( $subTaskValue, false ) . "','" // subtaskValue . $this->fieldId( 'id', null, false ) . "'" // fldName . ");"; break; } } elseif ( substr( $cbUri, 0, 10 ) == 'cb_action:' ) { $actionName = substr( $cbUri, 10 ); $action =& $this->_actions->getChildByNameAttr( 'action', 'name', $actionName ); if ( $action ) { $requestNames = explode( ' ', $action->attributes( 'request' ) ); $requestValues = explode( ' ', $action->attributes( 'action' ) ); $parametersValues = explode( ' ', $action->attributes( 'parameters' ) ); $baseUrl = 'index.php'; $baseUrl .= '?'; $baseRequests = array( 'option' => 'option', 'task' => 'task', 'cid' => 'pluginid' ); $urlParams = array(); foreach ( $baseRequests as $breq => $breqOptionsValue ) { if ( ( ! ( in_array( $breq, $requestNames ) || in_array( $breq, $parametersValues ) ) ) && isset( $this->_options[$breqOptionsValue] ) ) { $urlParams[$breq] = $breq . '=' . $this->_options[$breqOptionsValue]; } } $url = $baseUrl; for ( $i = 0, $n = count( $requestNames ); $i < $n; $i++ ) { $urlParams[$requestNames[$i]] = $requestNames[$i] . '=' . $requestValues[$i]; // other parameters = paramvalues added below } $url = $baseUrl . implode( '&', $urlParams ); } else { $url = "#action_not_defined:" . $actionName; } } else { $url = $cbUri; } if ( ! cbStartOfStringMatch( $url, 'javascript:' ) ) { // get the parameters of action/link from XML : $parametersNames = explode( ' ', $sourceElem->attributes( 'parameters' ) ); $parametersValues = explode( ' ', $sourceElem->attributes( 'paramvalues' ) ); $parametersValuesTypes = explode( ' ', $sourceElem->attributes( 'paramvaluestypes' ) ); // add currently activated filters to the parameters: if ( count( $this->_filters ) > 0 ) { foreach ( $this->_filters as $k => $v ) { $filterName = $this->fieldName( $k ); if ( ( $v['value'] != $v['default'] ) && ( ! in_array( $filterName, $parametersNames ) ) ) { $parametersNames[] = $filterName; $parametersValues[] = "'" . $v['value'] . "'"; //TBD: check this. } } } // add current search string, if any: $searchName = $this->fieldName( 'search' ); $searchValue = $this->fieldValue( 'search' ); if ( $searchValue && ( ! in_array( $searchName, $parametersNames ) ) ) { $parametersNames[] = $searchName; $parametersValues[] = "'" . $searchValue . "'"; } // generate current action (and parameters ?) as cbprevstate $cbprevstate = array(); foreach ( $this->_options as $req => $act ) { if ( $req && $act && ! in_array( $req, array( 'cbprevstate' ) ) ) { $cbprevstate[] = $req . '=' . $act; } } $parametersNames[] = 'cbprevstate'; $parametersValues[] = "'" . base64_encode( implode( '&', $cbprevstate ) ) . "'"; // finally generate URL: for ( $i = 0, $n = count( $parametersNames ); $i < $n; $i++ ) { $nameOfVariable = $parametersValues[$i]; if ( $nameOfVariable ) { if ( isset( $parametersValuesTypes[$i] ) && $parametersValuesTypes[$i] ) { if ( $parametersValuesTypes[$i] == 'sql:field' ) { $nameOfVariable = $data->$nameOfVariable; } else { // $nameOfVariable untouched } } elseif ( ( substr( $nameOfVariable, 0, 1 ) == "'" ) && ( substr( $nameOfVariable, -1 ) == "'" ) ) { $nameOfVariable = substr( $nameOfVariable, 1, -1 ); } else { $nameOfVariable = $data->$nameOfVariable; } $url .= '&' . $parametersNames[$i] . '=' . urlencode( $nameOfVariable ); } } if ( $ui == 2 ) { $url = $_CB_framework->backendUrl( $url, $htmlspecialchars, ( $inPage ? 'html' : 'component' ) ); } else { $url = cbSef( $url, $htmlspecialchars, ( $inPage ? 'html' : 'component' ) ); } } elseif ( $htmlspecialchars ) { $url = htmlspecialchars( $url ); } return $url; }
/** * USED by XML interface ONLY !!! Renders main currency + amount * * @param string $price * @param ParamsInterface $params * @param string $name The name of the form element * @param CBSimpleXMLElement $node The xml element for the parameter * @return string HTML to display */ public function renderCurrencyAmount( $price, &$params, /** @noinspection PhpUnusedParameterInspection */ $name, $node ) { $currency = $node->attributes( 'value' ); if ( $currency ) { $currencyCode = $currency; } else { $currencyCode = $params->get( 'currency_code' ); } $renderedAmount = $this->renderAmount( $price, $params ); if ( $renderedAmount != '-' ) { return $currencyCode . ' ' . $renderedAmount; } else { return '-'; } }
/** * installs a field for plugin * * @param int $pluginid id of the plugin creating the field * @param CBSimpleXMLElement $field * @return int|false fieldid or False on error */ function installField($pluginid, $tabid, $field) { global $_CB_database, $_PLUGINS; // Check to see if plugin tab already exists in db $_CB_database->setQuery("SELECT fieldid FROM #__comprofiler_fields WHERE name = '" . $field->attributes('name') . "'"); $fieldid = $_CB_database->loadResult(); $row = new moscomprofilerFields($_CB_database); $row->name = $field->attributes('name'); $row->pluginid = $pluginid; $row->tabid = $tabid; $row->type = $field->attributes('type'); $row->calculated = (int) $field->attributes('calculated'); if (!$fieldid) { $row->title = $field->attributes('title'); $row->description = trim($field->attributes('description')); $row->ordering = 99; $row->registration = $field->attributes('registration'); $row->profile = $field->attributes('profile'); $row->readonly = $field->attributes('readonly'); $row->params = $field->attributes('params'); } $dbTable =& $field->getElementByPath('database/table'); if ($dbTable) { $table = $dbTable->attributes('name'); } else { $table = $field->attributes('table'); } if ($table) { $row->table = $table; } else { $row->table = '#__comprofiler'; } // if the field type is unknown, suppose it's a field type of the plugin: $fieldTypePluginId = $_PLUGINS->getUserFieldPluginId($row->type); if (!$fieldTypePluginId) { // and register it so that the XML file for custom type can be found for store: $_PLUGINS->registerUserFieldTypes(array($row->type => 'CBfield_' . $row->type), $pluginid); } if (!$row->store($fieldid)) { $this->setError(1, 'SQL error on field store2' . ': ' . $row->getError()); return false; } if (!$fieldid) { $fieldid = $_CB_database->insertid(); } return $fieldid; }
/** * Protected internal function that handles missing DOM functionality: * $callBack to the copied attributes and data, as well as copying of children. * @since 1.2.4 * @protected * * @param DOMElement $newNode new DOM (incomplete) node just inserted/replaced * @param CBSimpleXMLElement $xmlSourceNode original XML node that got copied into DOM * @param callback $callBack to check/transform data or attributes of a node: $destinationData = function ( string|array $sourceData, CBSimpleXMLElement $sourceNode, CBSimpleXMLElement $destinationParentNode ); * @return CBSimpleXMLElement New XML node */ function & _domCopyChildrenCallbackonNode( &$newNode, $xmlSourceNode, $callBack ) { $newNodeXML =& simplexml_import_dom( $newNode, get_class( $this ) ); if ( $callBack === null ) { $newNode->nodeValue = $xmlSourceNode->data(); $attributesToCopy = $xmlSourceNode->attributes(); foreach ( $attributesToCopy as $k => $v ) { // PHP 5.2 doesn't copy attributes however PHP 5.3 does it, so let's copy again for PHP 5.2: //TBD later check from which version this 5.2 bug has been fixed... $newNode->setAttribute( $k, $attributesToCopy[$k] ); } } else { $newNode->nodeValue = call_user_func_array( $callBack, array( $xmlSourceNode->data(), $xmlSourceNode, $newNodeXML ) ); $copiedAttributes = $newNode->attributes; foreach ( $copiedAttributes as $k => $v ) { $newNode->removeAttribute( $k ); } // the new set of $attributes can be different from old one, thus we needed to remove old set (copied in PHP 5.3 only) first, then copy new: $attributes = call_user_func_array( $callBack, array( $xmlSourceNode->attributes(), $xmlSourceNode, $newNodeXML ) ); foreach ( $attributes as $k => $v ) { $newNode->setAttribute( $k, $v ); } } foreach ($xmlSourceNode->children() as $child ) { $newNodeXML->addChildWithDescendants( $child, $callBack ); } return $newNodeXML; }
/** * USED by XML interface ONLY !!! Renders URL for successful returns * * @param string $value Variable value ( 'successurl', 'cancelurl', 'notifyurl' ) * @param ParamsInterface $params * @param string $name The name of the form element * @param CBSimpleXMLElement $node The xml element for the parameter * @return string HTML to display */ public function renderUrl( /** @noinspection PhpUnusedParameterInspection */ $value, $params, $name, $node ) { /** @noinspection PhpUndefinedMethodInspection */ return str_replace( 'http://', 'https://', $this->getPayMean()->adminUrlRender( $node->attributes( 'value' ) ) ); }
/** * Returns array of column names (pre/post/fixed with $colNamePrefix) of $table * * @param CBSimpleXMLElement $db * @param string $colNamePrefix Prefix to add to all column names * @return array|boolean False if not found */ function getMainTableColumnsNames(&$db, $colNamePrefix = '') { $table =& $db->getChildByNameAttr('table', 'maintable', 'true'); if ($table !== false) { $columns =& $table->getElementByPath('columns'); if ($columns !== false) { $columnNamesArray = array(); foreach ($columns->children() as $column) { if ($column->name() == 'column') { $columnNamesArray[] = $this->_prefixedName($column, $colNamePrefix); } } return $columnNamesArray; } } return false; }
/** * USED by XML interface ONLY !!! Renders URL for successful returns * * @param string $value Variable value ( 'successurl', 'cancelurl', 'notifyurl' ) * @param ParamsInterface $params * @param string $name The name of the form element * @param CBSimpleXMLElement $node The xml element for the parameter * @return string HTML to display */ public function renderUrl($value, $params, $name, $node) { return str_replace('http://', 'https://', $this->getPayMean()->adminUrlRender($node->attributes('value'))); }