Add php files
This commit is contained in:
113
service/core/REST/SugarRest.php
Executable file
113
service/core/REST/SugarRest.php
Executable file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry'))define('sugarEntry', true);
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
/**
|
||||
* This class is a base class implementation of REST protocol
|
||||
*
|
||||
*/
|
||||
class SugarRest{
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param String $implementation - name of the implementation class
|
||||
*/
|
||||
function __construct($implementation){
|
||||
$this->implementation = $implementation;
|
||||
} // fn
|
||||
|
||||
/**
|
||||
* It will json encode version of the input object
|
||||
*
|
||||
* @param array $input - assoc array of input values: key = param name, value = param type
|
||||
* @return String - print's $input object
|
||||
*/
|
||||
function generateResponse($input){
|
||||
print_r($input);
|
||||
} // fn
|
||||
|
||||
/**
|
||||
* This method calls functions on the implementation class and returns the output or Fault object in case of error to client
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function serve(){
|
||||
if(empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])){
|
||||
if (empty($_REQUEST['method'])) {
|
||||
echo '<pre>';
|
||||
$reflect = new ReflectionClass(get_class($this->implementation));
|
||||
$restWSDL = $reflect->__toString();
|
||||
$restWSDL = preg_replace('/@@.*/', "", $restWSDL);
|
||||
echo $restWSDL;
|
||||
}else{
|
||||
$er = new SoapError();
|
||||
$er->set_error('invalid_call');
|
||||
$this->fault($er);
|
||||
}
|
||||
}else{
|
||||
$method = $_REQUEST['method'];
|
||||
return $this->implementation->$method();
|
||||
} // else
|
||||
} // fn
|
||||
|
||||
/**
|
||||
* This function sends response to client containing error object
|
||||
*
|
||||
* @param SoapError $errorObject - This is an object of type SoapError
|
||||
* @access public
|
||||
*/
|
||||
function fault($errorObject){
|
||||
$this->faultServer->generateFaultResponse($errorObject);
|
||||
|
||||
} // fn
|
||||
|
||||
function generateFaultResponse($errorObject){
|
||||
//ob_clean();
|
||||
$GLOBALS['log']->info('In SugarRest->fault. Setting fault object on response');
|
||||
header('HTTP/1.1 500 Internal Server Error');
|
||||
header('Content-Type: text/html; charset="ISO-8859-1"');
|
||||
echo '<br>500 Internal Server Error <br>';
|
||||
if(is_object($errorObject)){
|
||||
$error = $errorObject->number . ': ' . $errorObject->name . '<br>' . $errorObject->description;
|
||||
$GLOBALS['log']->error($error);
|
||||
echo $error;
|
||||
}else{
|
||||
$GLOBALS['log']->error(var_export($errorObject, true));
|
||||
print_r($errorObject);
|
||||
} // else
|
||||
}
|
||||
|
||||
} // clazz
|
||||
103
service/core/REST/SugarRestJSON.php
Executable file
103
service/core/REST/SugarRestJSON.php
Executable file
@@ -0,0 +1,103 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry'))define('sugarEntry', true);
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
require_once('service/core/REST/SugarRestSerialize.php');
|
||||
|
||||
/**
|
||||
* This class is a JSON implementation of REST protocol
|
||||
*
|
||||
*/
|
||||
class SugarRestJSON extends SugarRestSerialize{
|
||||
|
||||
/**
|
||||
* It will json encode the input object and echo's it
|
||||
*
|
||||
* @param array $input - assoc array of input values: key = param name, value = param type
|
||||
* @return String - echos json encoded string of $input
|
||||
*/
|
||||
function generateResponse($input){
|
||||
$json = getJSONObj();
|
||||
ob_clean();
|
||||
if (isset($this->faultObject)) {
|
||||
$this->generateFaultResponse($this->faultObject);
|
||||
} else {
|
||||
echo $json->encode($input);
|
||||
}
|
||||
} // fn
|
||||
|
||||
/**
|
||||
* This method calls functions on the implementation class and returns the output or Fault object in case of error to client
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function serve(){
|
||||
$GLOBALS['log']->info('Begin: SugarRestJSON->serve');
|
||||
$json_data = !empty($_REQUEST['rest_data'])? $_REQUEST['rest_data']: '';
|
||||
if(empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])){
|
||||
$er = new SoapError();
|
||||
$er->set_error('invalid_call');
|
||||
$this->fault($er);
|
||||
}else{
|
||||
$method = $_REQUEST['method'];
|
||||
$json = getJSONObj();
|
||||
$data = $json->decode(from_html($json_data));
|
||||
if(!is_array($data))$data = array($data);
|
||||
$GLOBALS['log']->info('End: SugarRestJSON->serve');
|
||||
return call_user_func_array(array( $this->implementation, $method),$data);
|
||||
} // else
|
||||
} // fn
|
||||
|
||||
/**
|
||||
* This function sends response to client containing error object
|
||||
*
|
||||
* @param SoapError $errorObject - This is an object of type SoapError
|
||||
* @access public
|
||||
*/
|
||||
function fault($errorObject){
|
||||
$this->faultServer->faultObject = $errorObject;
|
||||
} // fn
|
||||
|
||||
function generateFaultResponse($errorObject){
|
||||
$error = $errorObject->number . ': ' . $errorObject->name . '<br>' . $errorObject->description;
|
||||
$GLOBALS['log']->error($error);
|
||||
$json = getJSONObj();
|
||||
ob_clean();
|
||||
echo $json->encode($errorObject);
|
||||
} // fn
|
||||
|
||||
|
||||
} // class
|
||||
138
service/core/REST/SugarRestRSS.php
Executable file
138
service/core/REST/SugarRestRSS.php
Executable file
@@ -0,0 +1,138 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry'))define('sugarEntry', true);
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
require_once('service/core/REST/SugarRest.php');
|
||||
|
||||
/**
|
||||
* This class is a serialize implementation of REST protocol
|
||||
*
|
||||
*/
|
||||
class SugarRestRSS extends SugarRest{
|
||||
|
||||
/**
|
||||
* It will serialize the input object and echo's it
|
||||
*
|
||||
* @param array $input - assoc array of input values: key = param name, value = param type
|
||||
* @return String - echos serialize string of $input
|
||||
*/
|
||||
function generateResponse($input){
|
||||
$method = !empty($_REQUEST['method'])? $_REQUEST['method']: '';
|
||||
if($method != 'get_entry_list')$this->fault('RSS currently only supports the get_entry_list method');
|
||||
ob_clean();
|
||||
$this->generateResponseHeader($input['result_count']);
|
||||
$this->generateItems($input);
|
||||
$this->generateResponseFooter();
|
||||
} // fn
|
||||
|
||||
function generateResponseHeader($count){
|
||||
$date = gmdate("D, d M Y H:i:s") . " GMT";
|
||||
echo'<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<rss version="2.0">
|
||||
<channel>
|
||||
<title>SugarCRM RSS Feed</title>
|
||||
<link>http://cnn.com</link>
|
||||
<description>' . $count. ' records found</description>
|
||||
<pubDate>' . $date . '</pubDate>
|
||||
<generator>SugarCRM</generator>
|
||||
<ttl>' . $count . '</ttl>
|
||||
';
|
||||
}
|
||||
|
||||
function generateItems($input){
|
||||
if(!empty($input['entry_list'])){
|
||||
foreach($input['entry_list'] as $item){
|
||||
$this->generateItem($item);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
function generateItem($item){
|
||||
echo "<item>\n";
|
||||
$name = !empty($item['name_value_list']['name'])?htmlentities( $item['name_value_list']['name']): '';
|
||||
echo "<title>$name</title>\n";
|
||||
echo "<link>". $GLOBALS['sugar_config']['site_url'] . htmlentities('/index.php?module=' . $item['module_name']. '&record=' . $item['id']) . "</link>\n";
|
||||
echo "<description><![CDATA[";
|
||||
$displayFieldNames = true;
|
||||
if(count($item['name_value_list']) == 2 &&isset($item['name_value_list']['name']))$displayFieldNames = false;
|
||||
foreach($item['name_value_list'] as $k=>$v){
|
||||
if($k =='name')continue;
|
||||
if($k == 'date_modified')continue;
|
||||
if($displayFieldNames) echo '<b>' .htmlentities( $k) . ':<b> ';
|
||||
echo htmlentities( $v) . "\n<br>";
|
||||
}
|
||||
echo "]]></description>\n";
|
||||
if(!empty($item['name_value_list']['date_modified'])){
|
||||
$date = date("D, d M Y H:i:s", strtotime($item['name_value_list']['date_modified'])) . " GMT";
|
||||
echo "<pubDate>$date</pubDate>";
|
||||
}
|
||||
|
||||
echo "<guid>" . $item['id']. "</guid>\n";
|
||||
echo "</item>\n";
|
||||
}
|
||||
function generateResponseFooter(){
|
||||
echo'</channel></rss>';
|
||||
}
|
||||
|
||||
/**
|
||||
* This method calls functions on the implementation class and returns the output or Fault object in case of error to client
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function serve(){
|
||||
$this->fault('RSS is not a valid input_type');
|
||||
} // fn
|
||||
|
||||
function fault($faultObject){
|
||||
ob_clean();
|
||||
$this->generateResponseHeader();
|
||||
echo '<item><name>';
|
||||
if(is_object($errorObject)){
|
||||
$error = $errorObject->number . ': ' . $errorObject->name . '<br>' . $errorObject->description;
|
||||
$GLOBALS['log']->error($error);
|
||||
}else{
|
||||
$GLOBALS['log']->error(var_export($errorObject, true));
|
||||
$error = var_export($errorObject, true);
|
||||
} // else
|
||||
echo $error;
|
||||
echo '</name></item>';
|
||||
$this->generateResponseFooter();
|
||||
|
||||
}
|
||||
|
||||
|
||||
} // clazz
|
||||
99
service/core/REST/SugarRestSerialize.php
Executable file
99
service/core/REST/SugarRestSerialize.php
Executable file
@@ -0,0 +1,99 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry'))define('sugarEntry', true);
|
||||
/*********************************************************************************
|
||||
* SugarCRM is a customer relationship management program developed by
|
||||
* SugarCRM, Inc. Copyright (C) 2004-2010 SugarCRM Inc.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Affero General Public License version 3 as published by the
|
||||
* Free Software Foundation with the addition of the following permission added
|
||||
* to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
|
||||
* IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
|
||||
* OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
||||
* details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License along with
|
||||
* this program; if not, see http://www.gnu.org/licenses or write to the Free
|
||||
* Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
* 02110-1301 USA.
|
||||
*
|
||||
* You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
|
||||
* SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions
|
||||
* of this program must display Appropriate Legal Notices, as required under
|
||||
* Section 5 of the GNU Affero General Public License version 3.
|
||||
*
|
||||
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
|
||||
* these Appropriate Legal Notices must retain the display of the "Powered by
|
||||
* SugarCRM" logo. If the display of the logo is not reasonably feasible for
|
||||
* technical reasons, the Appropriate Legal Notices must display the words
|
||||
* "Powered by SugarCRM".
|
||||
********************************************************************************/
|
||||
|
||||
require_once('service/core/REST/SugarRest.php');
|
||||
|
||||
/**
|
||||
* This class is a serialize implementation of REST protocol
|
||||
*
|
||||
*/
|
||||
class SugarRestSerialize extends SugarRest{
|
||||
|
||||
/**
|
||||
* It will serialize the input object and echo's it
|
||||
*
|
||||
* @param array $input - assoc array of input values: key = param name, value = param type
|
||||
* @return String - echos serialize string of $input
|
||||
*/
|
||||
function generateResponse($input){
|
||||
ob_clean();
|
||||
if (isset($this->faultObject)) {
|
||||
$this->generateFaultResponse($this->faultObject);
|
||||
} else {
|
||||
echo serialize($input);
|
||||
}
|
||||
} // fn
|
||||
|
||||
/**
|
||||
* This method calls functions on the implementation class and returns the output or Fault object in case of error to client
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function serve(){
|
||||
$GLOBALS['log']->info('Begin: SugarRestSerialize->serve');
|
||||
$data = !empty($_REQUEST['rest_data'])? $_REQUEST['rest_data']: '';
|
||||
if(empty($_REQUEST['method']) || !method_exists($this->implementation, $_REQUEST['method'])){
|
||||
$er = new SoapError();
|
||||
$er->set_error('invalid_call');
|
||||
$this->fault($er);
|
||||
}else{
|
||||
$method = $_REQUEST['method'];
|
||||
$data = unserialize(from_html($data));
|
||||
if(!is_array($data))$data = array($data);
|
||||
$GLOBALS['log']->info('End: SugarRestSerialize->serve');
|
||||
return call_user_func_array(array( $this->implementation, $method),$data);
|
||||
} // else
|
||||
} // fn
|
||||
|
||||
/**
|
||||
* This function sends response to client containing error object
|
||||
*
|
||||
* @param SoapError $errorObject - This is an object of type SoapError
|
||||
* @access public
|
||||
*/
|
||||
function fault($errorObject){
|
||||
$this->faultServer->faultObject = $errorObject;
|
||||
} // fn
|
||||
|
||||
function generateFaultResponse($errorObject){
|
||||
$error = $errorObject->number . ': ' . $errorObject->name . '<br>' . $errorObject->description;
|
||||
$GLOBALS['log']->error($error);
|
||||
ob_clean();
|
||||
echo serialize($errorObject);
|
||||
} // fn
|
||||
|
||||
} // clazz
|
||||
Reference in New Issue
Block a user