예제 #1
0
 /**
  * Method to register custom library.
  *
  * @return  void
  */
 public function onAfterInitialise()
 {
     if (defined('REDCORE_LIBRARY_LOADED')) {
         $apiName = JFactory::getApplication()->input->getString('api');
         if ($this->isApiEnabled($apiName)) {
             $input = JFactory::getApplication()->input;
             if (!empty($apiName)) {
                 try {
                     // We will disable all error messaging from PHP from the output
                     error_reporting(0);
                     ini_set('display_errors', 0);
                     JError::setErrorHandling(E_ERROR, 'message');
                     JFactory::getApplication()->clearHeaders();
                     $webserviceClient = $input->get->getString('webserviceClient', '');
                     $optionName = $input->get->getString('option', '');
                     $optionName = strpos($optionName, 'com_') === 0 ? substr($optionName, 4) : $optionName;
                     $viewName = $input->getString('view', '');
                     $version = $input->getString('webserviceVersion', '');
                     $token = $input->getString(RBootstrap::getConfig('oauth2_token_param_name', 'access_token'), '');
                     $apiName = ucfirst($apiName);
                     $method = strtoupper($input->getMethod());
                     $task = RApiHalHelper::getTask();
                     $data = RApi::getPostedData();
                     $dataGet = $input->get->getArray();
                     if (empty($webserviceClient)) {
                         $webserviceClient = JFactory::getApplication()->isAdmin() ? 'administrator' : 'site';
                     }
                     $options = array('api' => $apiName, 'optionName' => $optionName, 'viewName' => $viewName, 'webserviceVersion' => $version, 'webserviceClient' => $webserviceClient, 'method' => $method, 'task' => $task, 'data' => $data, 'dataGet' => $dataGet, 'accessToken' => $token, 'format' => $input->getString('format', $this->params->get('webservices_default_format', 'json')), 'id' => $input->getString('id', ''), 'absoluteHrefs' => $input->get->getBool('absoluteHrefs', true));
                     // Create instance of Api and fill all required options
                     $api = RApi::getInstance($options);
                     // Run the api task
                     $api->execute();
                     // Display output
                     $api->render();
                 } catch (Exception $e) {
                     $code = $e->getCode() > 0 ? $e->getCode() : 500;
                     if (strtolower($apiName) == 'soap') {
                         // We must have status of 200 for SOAP communication even if it is fault
                         $message = RApiSoapHelper::createSoapFaultResponse($e->getMessage());
                         header("Content-Type: soap+xml");
                         header("Content-length: " . strlen($message));
                         header("Status: 200");
                         echo $message;
                     } else {
                         // Set the server response code.
                         header('Status: ' . $code, true, $code);
                         // Check for defined constants
                         if (!defined('JSON_UNESCAPED_SLASHES')) {
                             define('JSON_UNESCAPED_SLASHES', 64);
                         }
                         // An exception has been caught, echo the message and exit.
                         echo json_encode(array('message' => $e->getMessage(), 'code' => $e->getCode(), 'type' => get_class($e)), JSON_UNESCAPED_SLASHES);
                     }
                 }
                 JFactory::getApplication()->close();
             }
         }
     }
 }
예제 #2
0
 /**
  * Method to get the options to populate to populate list
  *
  * @return  array  The field option objects.
  *
  * @since   1.0
  */
 protected function getOptions()
 {
     // Accepted modifiers
     $hash = md5($this->element);
     if (!isset(static::$cache[$hash])) {
         static::$cache[$hash] = parent::getOptions();
         $options = RApiHalHelper::getWebserviceScopes();
         static::$cache[$hash] = array_merge(static::$cache[$hash], $options);
     }
     return static::$cache[$hash];
 }
예제 #3
0
 /**
  * Method to transform a type to publish it in the WSDL file
  *
  * @param   array             $field             Field definition.
  * @param   SimpleXMLElement  &$sequence         XML with the fields sequence
  * @param   SimpleXMLElement  &$typeSchema       XML of the typeSchema in case new derived types need to be added
  * @param   string            $elementName       Parent element name to add the new derived types with unique names
  * @param   boolean           $validateOptional  Optional parameter to validate if the field is optional.  Otherwise it's always set as required
  * @param   array             $extraFields       Array of extra fields to process - in case of array types
  * @param   SimpleXMLElmenet  $complexArrays     Complex arrays definitions
  *
  * @return void
  */
 public function wsdlField($field, &$sequence, &$typeSchema, $elementName, $validateOptional = false, $extraFields = array(), $complexArrays = null)
 {
     if (!isset($this->element)) {
         $this->element = $sequence->addChild('element', null, 'http://www.w3.org/2001/XMLSchema');
     }
     if (!isset($this->element['minOccurs'])) {
         $this->element->addAttribute('minOccurs', $validateOptional && RApiHalHelper::isAttributeTrue($field, 'isRequiredField') || !$validateOptional ? '1' : '0');
     }
     $this->element->addAttribute('maxOccurs', 'unbounded');
     if (!isset($this->element['name']) && isset($field['name'])) {
         $this->element->addAttribute('name', $field['name']);
     }
     $this->element->addAttribute('type', 'tns:' . $elementName . '_' . $field['name']);
     if (!empty($extraFields)) {
         RApiSoapHelper::addElementFields($extraFields, $typeSchema, $elementName . '_' . $field['name'], true, '', $complexArrays);
     }
 }
예제 #4
0
파일: base.php 프로젝트: 810/redCORE
 /**
  * Method to transform a type to publish it in the WSDL file
  *
  * @param   array             $field             Field definition.
  * @param   SimpleXMLElement  &$sequence         XML with the fields sequence
  * @param   SimpleXMLElement  &$typeSchema       XML of the typeSchema in case new derived types need to be added
  * @param   string            $elementName       Parent element name to add the new derived types with unique names
  * @param   boolean           $validateOptional  Optional parameter to validate if the field is optional.  Otherwise it's always set as required
  * @param   array             $extraFields       Array of extra fields to process - in case of array types
  *
  * @return void
  */
 public function wsdlField($field, &$sequence, &$typeSchema, $elementName, $validateOptional = false, $extraFields = array())
 {
     if (!isset($this->element)) {
         $this->element = $sequence->addChild('element', null, 'http://www.w3.org/2001/XMLSchema');
     }
     if (!isset($this->element['minOccurs'])) {
         $this->element->addAttribute('minOccurs', $validateOptional && RApiHalHelper::isAttributeTrue($field, 'isRequiredField') || !$validateOptional ? '1' : '0');
     }
     if (!isset($this->element['maxOccurs'])) {
         $this->element->addAttribute('maxOccurs', RApiHalHelper::attributeToString($field, 'maxOccurs', 1));
     }
     if (!isset($this->element['name']) && isset($field['name'])) {
         $this->element->addAttribute('name', $field['name']);
     }
     if ($this->type != '') {
         $this->element->addAttribute('type', $this->type);
     }
 }
예제 #5
0
 /**
  * Gets an array of fields ready for SOAP documentation purposes
  *
  * @param   array    $fields       Array of fields using their xml properties (using 'name' for the field name itself)
  * @param   boolean  $allRequired  Mark all the fields as required
  * @param   string   $assignation  Assignation operation
  *
  * @return  array
  *
  * @since   1.4
  */
 public static function documentationFields($fields, $allRequired = false, $assignation = '=')
 {
     $fieldsArray = array();
     if ($fields && is_array($fields)) {
         foreach ($fields as $field) {
             $transform = RApiHalHelper::attributeToString($field, 'transform', 'string');
             $defaultValue = RApiHalHelper::attributeToString($field, 'defaultValue', 'null');
             if ($defaultValue == 'null' && ($allRequired || RApiHalHelper::isAttributeTrue($field, 'isRequiredField'))) {
                 $transformClass = 'RApiSoapTransform' . ucfirst($transform);
                 if (!class_exists($transformClass)) {
                     $transformClass = 'RApiSoapTransformBase';
                 }
                 $transformObject = new $transformClass();
                 $defaultValue = $transformObject->defaultValue;
             }
             $fieldsArray[] = '$' . RApiHalHelper::attributeToString($field, 'name') . ' ' . $assignation . ' (' . $transform . ') ' . $defaultValue;
         }
     }
     return $fieldsArray;
 }
예제 #6
0
 /**
  * Uninstall the webservices
  *
  * @param   JInstallerAdapter  $parent  class calling this method
  *
  * @return  boolean
  */
 protected function uninstallWebservices($parent)
 {
     // Required objects
     $manifest = $this->getManifest($parent);
     if (!$manifest) {
         return false;
     }
     // We will use webservices removal function to remove webservice files
     $element = $manifest->webservices;
     if (!$element || !count($element->children())) {
         // Either the tag does not exist or has no children therefore we return zero files processed.
         return true;
     }
     $returnValue = true;
     // Get the array of file nodes to process
     $files = $element->children();
     $source = RApiHalHelper::getWebservicesPath();
     // Process each file in the $files array (children of $tagName).
     foreach ($files as $file) {
         $path = $source . '/' . $file;
         // Actually delete the files/folders
         if (is_dir($path)) {
             $val = JFolder::delete($path);
         } else {
             $val = JFile::delete($path);
         }
         if ($val === false) {
             JLog::add(JText::sprintf('LIB_REDCORE_INSTALLER_ERROR_FAILED_TO_DELETE', $path), JLog::WARNING, 'jerror', JLog::WARNING, 'jerror');
             $returnValue = false;
         }
     }
     return $returnValue;
 }
예제 #7
0
 /**
  * Method to get new Resources from Database Table in HTML
  *
  * @return  void
  */
 public function ajaxGetResourceFromDatabase()
 {
     $app = JFactory::getApplication();
     $input = $app->input;
     $operation = $input->getString('operation', 'read');
     $fieldList = $input->getString('fieldList', '');
     $fieldList = explode(',', $fieldList);
     $tableName = $input->getCmd('tableName', '');
     if (!empty($tableName)) {
         $db = JFactory::getDbo();
         $columns = $db->getTableColumns('#__' . $tableName, false);
         if ($columns) {
             foreach ($columns as $columnKey => $column) {
                 $form = array('displayName' => $column->Field, 'transform' => RApiHalHelper::getTransformElementByDbType($column->Type), 'resourceSpecific' => 'rcwsGlobal', 'fieldFormat' => '{' . $column->Field . '}', 'description' => $column->Comment);
                 echo RLayoutHelper::render('webservice.resources.resource', array('view' => $this, 'options' => array('operation' => $operation, 'fieldList' => $fieldList, 'form' => $form)));
             }
         }
     }
     $app->close();
 }
예제 #8
0
 /**
  * Get list of all webservices from Redcore parameters
  *
  * @return  array  Array or table with columns columns
  */
 public static function getInstalledWebservices()
 {
     if (!isset(self::$installedWebservices)) {
         self::$installedWebservices = array();
         $db = JFactory::getDbo();
         $query = $db->getQuery(true)->select('*')->from('#__redcore_webservices')->order('created_date ASC');
         $db->setQuery($query);
         $webservices = $db->loadObjectList();
         if (!empty($webservices)) {
             foreach ($webservices as $webservice) {
                 self::$installedWebservices[$webservice->client][$webservice->name][$webservice->version] = JArrayHelper::fromObject($webservice);
             }
         }
     }
     return self::$installedWebservices;
 }
예제 #9
0
 /**
  * Preforms Batch action against all Webservices
  *
  * @param   string  $action  Action to preform
  *
  * @return  boolean  Returns true if Action was successful
  */
 public function batchWebservices($action = '')
 {
     $webservices = RApiHalHelper::getWebservices();
     if (!empty($webservices)) {
         $model = $this->getModel('webservices');
         $installedWebservices = RApiHalHelper::getInstalledWebservices();
         foreach ($webservices as $webserviceNames) {
             foreach ($webserviceNames as $webserviceVersions) {
                 foreach ($webserviceVersions as $webservice) {
                     $client = RApiHalHelper::getWebserviceClient($webservice);
                     $path = $webservice->webservicePath;
                     $name = (string) $webservice->config->name;
                     $version = (string) $webservice->config->version;
                     // If it is already install then we skip it
                     if (!empty($installedWebservices[$client][$name][$version])) {
                         continue;
                     }
                     switch ($action) {
                         case 'install':
                             $model->installWebservice($client, $name, $version, $path);
                             break;
                         case 'delete':
                             $model->deleteWebservice($client, $name, $version, $path);
                             break;
                     }
                 }
             }
         }
     }
     return true;
 }
예제 #10
0
 /**
  * Uninstalls Webservice access and deletes XML file
  *
  * @param   string  $client      Client
  * @param   string  $webservice  Webservice name
  * @param   string  $version     Webservice version
  * @param   string  $path        Path to webservice files
  *
  * @return  boolean  Returns true if Content element was successfully purged
  */
 public function deleteWebservice($client, $webservice = '', $version = '1.0.0', $path = '')
 {
     $xmlFilePath = RApiHalHelper::getWebserviceFile($client, strtolower($webservice), $version, 'xml', $path);
     $helperFilePath = RApiHalHelper::getWebserviceFile($client, strtolower($webservice), $version, 'php', $path);
     try {
         JFile::delete($xmlFilePath);
         if (!empty($helperFilePath)) {
             JFile::delete($helperFilePath);
         }
     } catch (Exception $e) {
         JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_REDCORE_WEBSERVICES_WEBSERVICE_DELETE_ERROR', $e->getMessage()), 'error');
         return false;
     }
     JFactory::getApplication()->enqueueMessage(JText::_('COM_REDCORE_WEBSERVICES_WEBSERVICE_DELETED'), 'message');
     return true;
 }
예제 #11
0
				<input type="text" name="name" value="<?php 
echo $name;
?>
" class="form-control" />
			</div>
			<div class="input-group input-group-sm">
				<div class="input-group-addon hasTooltip" title="<?php 
echo JText::_('COM_REDCORE_WEBSERVICE_FIELD_TRANSFORM_DESCRIPTION');
?>
">
					<?php 
echo JText::_('COM_REDCORE_WEBSERVICE_FIELD_TRANSFORM_LABEL');
?>
				</div>
				<?php 
echo JHtml::_('select.genericlist', RApiHalHelper::getTransformElements(), 'transform', ' class="required form-control" ', 'value', 'text', $transform);
?>
			</div>
			<?php 
if (in_array('defaultValue', $fieldList)) {
    ?>
				<div class="input-group input-group-sm">
					<div class="input-group-addon hasTooltip" title="<?php 
    echo JText::_('COM_REDCORE_WEBSERVICE_FIELD_DEFAULTVALUE_DESCRIPTION');
    ?>
">
						<?php 
    echo JText::_('COM_REDCORE_WEBSERVICE_FIELD_DEFAULTVALUE_LABEL');
    ?>
					</div>
					<input type="text" name="defaultValue" value="<?php 
예제 #12
0
            }
            if ($operationName == 'read list') {
                if (RApiHalHelper::isAttributeTrue($field, 'isFilterField')) {
                    $field['name'] = 'filter[' . $field['name'] . ']';
                } else {
                    continue;
                }
            }
            if ($operationName == 'read item') {
                if (!RApiHalHelper::isAttributeTrue($field, 'isPrimaryField')) {
                    continue;
                }
                // We set it as a required field for read item
                $field['isRequiredField'] = 'true';
            }
            $fieldsContainer[] = '<strong>' . $field['name'] . '</strong> ' . '(<em>' . (!empty($field['transform']) ? $field['transform'] : 'string') . ', ' . (RApiHalHelper::isAttributeTrue($field, 'isRequiredField') ? JText::_('LIB_REDCORE_API_HAL_WEBSERVICE_DOCUMENTATION_FIELD_REQUIRED') : JText::_('LIB_REDCORE_API_HAL_WEBSERVICE_DOCUMENTATION_FIELD_OPTIONAL')) . '</em>)';
        }
        echo implode(',<br />', $fieldsContainer);
    }
}
?>
			</small>
		</div>
		<div class="col-xs4 col-md-4 well" style="border: 2px solid #fff;">
			<h5 style="border-bottom: 1px solid #ddd"><strong><?php 
echo JText::_('LIB_REDCORE_API_HAL_WEBSERVICE_DOCUMENTATION_RESPONSE');
?>
</strong></h5>
			<small>
				<?php 
if (!empty($resources)) {
예제 #13
0
					<?php 
        foreach ($this->xmlFiles as $clients => $webserviceNames) {
            ?>
						<?php 
            $column = 0;
            ?>
						<div class='clearfix'></div>
						<h3><?php 
            echo JText::_('J' . $clients);
            ?>
</h3>
						<?php 
            foreach ($webserviceNames as $webserviceVersions) {
                foreach ($webserviceVersions as $webservice) {
                    $webserviceClient = RApiHalHelper::getWebserviceClient($webservice);
                    ?>
								<div class="col-md-4 well">
									<h4>
										<?php 
                    echo $webservice->name;
                    ?>
 (<?php 
                    echo $webservice->config->name;
                    ?>
&nbsp;
										<?php 
                    echo !empty($webservice->config->version) ? $webservice->config->version : '';
                    ?>
)
									</h4>
예제 #14
0
			</div>
		</div>
	</div>

	<div class="form-group">
		<?php 
echo $this->form->getLabel('path', 'main');
?>
		<div class="form-inline col-sm-10">
			<div class="input-group">
				<div class="input-group-addon hasTooltip" title="<?php 
echo JText::_('COM_REDCORE_WEBSERVICE_PATH_DESCRIPTION');
?>
">
					/<?php 
echo RApiHalHelper::getWebservicesRelativePath();
?>
/
				</div>
				<?php 
echo $this->form->getInput('path', 'main');
?>
				<span class="input-group-addon hasTooltip" title="<?php 
echo JText::_('COM_REDCORE_WEBSERVICE_FILE_DESCRIPTION');
?>
">
					/<?php 
echo $this->form->getValue('xmlFile', 'main');
?>
				</span>
			</div>
예제 #15
0
 /**
  * Load item object
  *
  * @param   integer  $pk  The id of the primary key.
  *
  * @return  mixed    Object on success, false on failure.
  *
  * @since   1.2
  */
 public function getItem($pk = null)
 {
     if (!($item = parent::getItem($pk))) {
         return $item;
     }
     if (!empty($item->id) && is_null($this->xmlFile)) {
         try {
             $this->xmlFile = RApiHalHelper::loadWebserviceConfiguration($item->name, $item->version, 'xml', $item->path, $item->client);
         } catch (Exception $e) {
             JFactory::getApplication()->enqueueMessage(JText::sprintf('COM_REDCORE_WEBSERVICE_ERROR_LOADING_XML', $e->getMessage()), 'error');
         }
     }
     // Add default webservice parameters since this is new webservice
     if (empty($this->xmlFile)) {
         $this->xmlFile = $this->defaultXmlFile;
     }
     return $item;
 }
예제 #16
0
 /**
  * Returns generated WSDL file for the webservice
  *
  * @param   string  $wsdlPath  Path of WSDL file
  *
  * @return  SimpleXMLElement
  */
 public function generateWsdl($wsdlPath)
 {
     $wsdlFullPath = JUri::root() . $wsdlPath;
     $client = RApiHalHelper::attributeToString($this->webserviceXml, 'client', 'site');
     $version = !empty($this->webserviceXml->config->version) ? $this->webserviceXml->config->version : '1.0.0';
     $this->webserviceFullName = $client . '.' . $this->webserviceXml->config->name . '.' . $version;
     $this->webserviceUrl = RApiHalHelper::buildWebserviceFullUrl($client, $this->webserviceXml->config->name, $version, 'soap');
     // Root of the document
     $this->wsdl = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8" ?><wsdl:definitions' . ' xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"' . ' xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/"' . ' xmlns:tns="' . $wsdlFullPath . '"' . ' xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap12/"' . ' xmlns:s="http://www.w3.org/2001/XMLSchema"' . ' xmlns:http="http://schemas.xmlsoap.org/wsdl/http/"' . ' targetNamespace="' . $wsdlFullPath . '"' . ' xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"' . ' ></wsdl:definitions>', 0, false, 'wsdl', true);
     $types = $this->wsdl->addChild('types');
     $this->typeSchema = $types->addChild('schema', null, 'http://www.w3.org/2001/XMLSchema');
     $this->typeSchema->addAttribute('targetNamespace', $wsdlFullPath);
     $this->typeSchema->addAttribute('elementFormDefault', 'unqualified');
     $this->addGlobalTypes($this->typeSchema);
     // Adding service
     $this->wsdlServices = $this->wsdl->addChild('service');
     $this->wsdlServices->addAttribute('name', $this->webserviceFullName);
     $this->wsdlServices->addChild('documentation', $this->webserviceXml->description);
     // Add new port binding
     $port = $this->wsdlServices->addChild('port');
     $port->addAttribute('name', $this->webserviceFullName . '_Soap');
     $port->addAttribute('binding', 'tns:' . $this->webserviceFullName);
     // Add soap addresses
     $soapAddress = $port->addChild('soap:address', null, 'http://schemas.xmlsoap.org/wsdl/soap12/');
     $soapAddress->addAttribute('location', $this->webserviceUrl);
     // Add webservice operations
     if (isset($this->webserviceXml->operations)) {
         // Read list
         if (isset($this->webserviceXml->operations->read->list)) {
             $filters = RApiHalHelper::getFilterFields($this->webserviceXml->operations->read->list, true, true);
             if (empty($filters)) {
                 $filtersDef = array('name' => 'filters', 'transform' => 'array');
             } else {
                 $filtersDef = array('name' => 'filters', 'transform' => 'arraydefined', 'fields' => $filters);
             }
             // Add read list messages
             $inputFields = array(array('name' => 'limitStart', 'transform' => 'int'), array('name' => 'limit', 'transform' => 'int'), array('name' => 'filterSearch', 'transform' => 'string'), $filtersDef, array('name' => 'ordering', 'transform' => 'string'), array('name' => 'orderingDirection', 'transform' => 'string'), array('name' => 'language', 'transform' => 'string'));
             // Add read list response messages
             $outputFields = array(array('name' => 'list', 'transform' => 'arrayrequired', 'fields' => array(array('name' => 'item', 'maxOccurs' => 'unbounded', 'transform' => 'arrayrequired', 'fields' => RApiSoapHelper::getOutputResources($this->webserviceXml->operations->read->list, 'listItem')))));
             $this->addOperation($this->wsdl, 'readList', $inputFields, $outputFields, true, true);
         }
         // Read item
         if (isset($this->webserviceXml->operations->read->item)) {
             // Add read item messages
             $inputFields = array_merge(RApiHalHelper::getFieldsArray($this->webserviceXml->operations->read->item, true), array(array('name' => 'language', 'transform' => 'string')));
             // Add read item response messages
             $outputFields = array(array('name' => 'item', 'typeName' => 'item', 'transform' => 'arrayrequired', 'fields' => RApiSoapHelper::getOutputResources($this->webserviceXml->operations->read->item)));
             $this->addOperation($this->wsdl, 'readItem', $inputFields, $outputFields, false, true);
         }
         // Create operation
         if (isset($this->webserviceXml->operations->create)) {
             // Add create messages
             $inputFields = RApiHalHelper::getFieldsArray($this->webserviceXml->operations->create);
             // Add create response messages
             $outputFields = array(RApiSoapHelper::getResultResource($this->webserviceXml->operations->create));
             $this->addOperation($this->wsdl, 'create', $inputFields, $outputFields, true);
         }
         // Update operation
         if (isset($this->webserviceXml->operations->update)) {
             // Add update messages
             $inputFields = RApiHalHelper::getFieldsArray($this->webserviceXml->operations->update);
             // Add update response messages
             $outputFields = array(RApiSoapHelper::getResultResource($this->webserviceXml->operations->update));
             $this->addOperation($this->wsdl, 'update', $inputFields, $outputFields, true);
         }
         // Delete operation
         if (isset($this->webserviceXml->operations->delete)) {
             // Add delete messages
             $inputFields = RApiHalHelper::getFieldsArray($this->webserviceXml->operations->delete, true);
             // Add delete response messages
             $outputFields = array(RApiSoapHelper::getResultResource($this->webserviceXml->operations->delete));
             $this->addOperation($this->wsdl, 'delete', $inputFields, $outputFields);
         }
         // Task operation
         if (isset($this->webserviceXml->operations->task)) {
             foreach ($this->webserviceXml->operations->task->children() as $taskName => $task) {
                 // Add task messages
                 $inputFields = RApiHalHelper::getFieldsArray($task);
                 // Add task response messages
                 $outputFields = array(RApiSoapHelper::getResultResource($task));
                 $this->addOperation($this->wsdl, 'task_' . $taskName, $inputFields, $outputFields, true);
             }
         }
     }
     return $this->wsdl;
 }
예제 #17
0
 /**
  * Read item
  *
  * @param   object  $data  Primary keys and $language
  *
  * @return  array
  */
 public function readItem($data)
 {
     // We are setting the operation of the webservice to Read
     $this->setOperation('read');
     $dataGet = $this->webservice->options->get('dataGet', array());
     $primaryKeysFromFields = RApiHalHelper::getFieldsArray($this->webservice->configuration->operations->read->item, true);
     // If there are no primary keys defined we will use id field as default
     if (empty($primaryKeysFromFields)) {
         $primaryKeysFromFields['id'] = array('transform' => 'int');
     }
     foreach ($primaryKeysFromFields as $primaryKey => $primaryKeyField) {
         $keyData = '';
         if (isset($data->{$primaryKey}) && $data->{$primaryKey} != '') {
             $keyData = $data->{$primaryKey};
         }
         $dataGet->{$primaryKey} = $this->webservice->transformField($primaryKeyField['transform'], $keyData, false);
     }
     // Handle different language switch
     $this->setLanguage((string) (isset($data->language) ? $data->language : ''));
     $this->webservice->options->set('dataGet', $dataGet);
     $this->webservice->options->set('task', '');
     $this->webservice->options->set('filterOutResourcesGroups', array('_links', '_messages'));
     $this->webservice->execute();
     $arr = $this->webservice->hal->toArray();
     $outputResources = RApiSoapHelper::getOutputResources($this->webservice->configuration->operations->read->item, '', true);
     $response = RApiSoapHelper::selectListResources($outputResources, array($arr));
     $final = new stdClass();
     $final->item = empty($response) ? array() : $response[0];
     $match = true;
     if (RApiHalHelper::isAttributeTrue($this->webservice->configuration->operations->read->item, 'enforcePKs', true)) {
         foreach ($primaryKeysFromFields as $primaryKey => $primaryKeyField) {
             if ($dataGet->{$primaryKey} != $final->item->{$primaryKey}) {
                 $match = false;
             }
         }
     }
     if (!$match) {
         $final = array();
     }
     if (!count((array) $final->item)) {
         $final = array();
     }
     return $final;
 }
예제 #18
0
							<?php 
                if ($isOperationRead) {
                    ?>
								<td><?php 
                    echo RApiHalHelper::isAttributeTrue($field, 'isFilterField') ? JText::_('JYES') : JText::_('JNO');
                    ?>
</td>
								<td><?php 
                    echo RApiHalHelper::isAttributeTrue($field, 'isSearchableField') ? JText::_('JYES') : JText::_('JNO');
                    ?>
</td>
							<?php 
                } else {
                    ?>
								<td><?php 
                    echo RApiHalHelper::isAttributeTrue($field, 'isRequiredField') ? JText::_('JYES') : JText::_('JNO');
                    ?>
</td>
							<?php 
                }
                ?>
							<td><?php 
                echo !empty($field->description) ? $field->description : '';
                ?>
</td>
						</tr>
					<?php 
            }
            ?>
				<?php 
        }
예제 #19
0
    ?>
</strong>:
			<small>
				<a href="<?php 
    echo $halLink;
    ?>
">
					<?php 
    echo $halLink;
    ?>
				</a>
			</small>
			<br />
			<?php 
    if ($soapEnabled) {
        $wsdlLink = RApiHalHelper::buildWebserviceFullUrl($view->client, $view->webserviceName, $view->webserviceVersion, 'soap') . '&wsdl';
        ?>
				<strong><?php 
        echo JText::_('LIB_REDCORE_API_HAL_WEBSERVICE_DOCUMENTATION_WSDL_ACCESS_URL');
        ?>
</strong>:
				<small>
					<a href="<?php 
        echo $wsdlLink;
        ?>
">
						<?php 
        echo $wsdlLink;
        ?>
					</a>
				</small>
예제 #20
0
파일: hal.php 프로젝트: thangredweb/redCORE
 /**
  * Returns if all primary keys have set values
  * Easily get read type (item or list) for current read operation and fills primary keys
  *
  * @param   array             &$primaryKeys   List of primary keys
  * @param   SimpleXMLElement  $configuration  Configuration group
  *
  * @return  bool  Returns true if read type is Item
  *
  * @since   1.2
  */
 public function apiFillPrimaryKeys(&$primaryKeys, $configuration = null)
 {
     if (is_null($configuration)) {
         $operations = $this->getConfig('operations');
         if (!empty($operations->read->item)) {
             $configuration = $operations->read->item;
         }
         $data = $this->triggerFunction('processPostData', $this->options->get('dataGet', array()), $configuration);
     } else {
         $data = $this->triggerFunction('processPostData', $this->options->get('data', array()), $configuration);
     }
     // Checking for primary keys
     if (!empty($configuration)) {
         $primaryKeysFromFields = RApiHalHelper::getFieldsArray($configuration, true);
         if (!empty($primaryKeysFromFields)) {
             foreach ($primaryKeysFromFields as $primaryKey => $primaryKeyField) {
                 if (isset($data[$primaryKey]) && $data[$primaryKey] != '') {
                     $primaryKeys[$primaryKey] = $this->transformField($primaryKeyField['transform'], $data[$primaryKey], false);
                 } else {
                     $primaryKeys[$primaryKey] = null;
                 }
             }
             foreach ($primaryKeys as $primaryKey => $primaryKeyField) {
                 if (is_null($primaryKeyField)) {
                     return false;
                 }
             }
         }
         return true;
     }
     return false;
 }
예제 #21
-1
 /**
  * Execute the Api Authorize operation.
  *
  * @return  mixed  RApi object with information on success, boolean false on failure.
  *
  * @since   1.2
  */
 public function apiAuthorize()
 {
     $user = $this->getLoggedUser();
     $request = OAuth2\Request::createFromGlobals();
     $response = new OAuth2\Response();
     // Validate the authorize request
     if (!$this->server->validateAuthorizeRequest($request, $response)) {
         $this->response = $response;
         return $this;
     }
     $clientId = $request->query('client_id');
     $scopes = RApiOauth2Helper::getClientScopes($clientId);
     if ($request->request('authorized', '') == '') {
         $clientScopes = !empty($scopes) ? explode(' ', $scopes) : array();
         if (!empty($clientScopes)) {
             $clientScopes = RApiHalHelper::getWebserviceScopes($clientScopes);
         }
         $currentUri = JUri::getInstance();
         $formAction = JUri::root() . 'index.php?' . $currentUri->getQuery();
         // Display an authorization form
         $this->response = RLayoutHelper::render('oauth2.authorize', array('view' => $this, 'options' => array('clientId' => $clientId, 'formAction' => $formAction, 'scopes' => $clientScopes)));
         return $this;
     }
     // Print the authorization code if the user has authorized your client
     $is_authorized = $request->request('authorized', '') === JText::_('LIB_REDCORE_API_OAUTH2_SERVER_AUTHORIZE_CLIENT_YES');
     // We are setting client scope instead of requesting scope from user request
     $request->request['scope'] = $scopes;
     $this->server->handleAuthorizeRequest($request, $response, $is_authorized, $user->id);
     $this->response = $response;
     return $this;
 }