init
This commit is contained in:
80
include/connectors/ConnectorFactory.php
Executable file
80
include/connectors/ConnectorFactory.php
Executable file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* 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".
|
||||
********************************************************************************/
|
||||
class ConnectorFactory{
|
||||
|
||||
static $source_map = array();
|
||||
|
||||
public static function getInstance($source_name){
|
||||
if(empty(self::$source_map[$source_name])) {
|
||||
require_once('include/connectors/sources/SourceFactory.php');
|
||||
require_once('include/connectors/component.php');
|
||||
$source = SourceFactory::getSource($source_name);
|
||||
$component = new component();
|
||||
$component->setSource($source);
|
||||
$component->init();
|
||||
self::$source_map[$source_name] = $component;
|
||||
}
|
||||
return self::$source_map[$source_name];
|
||||
}
|
||||
|
||||
/**
|
||||
* Split the class name by _ and go through the class name
|
||||
* which represents the inheritance structure to load up all required parents.
|
||||
* @param string $class the root class we want to load.
|
||||
*/
|
||||
public static function load($class, $type){
|
||||
self::loadClass($class, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* include a source class file.
|
||||
* @param string $class a class file to include.
|
||||
*/
|
||||
public static function loadClass($class, $type){
|
||||
$dir = str_replace('_','/',$class);
|
||||
$parts = explode("/", $dir);
|
||||
$file = $parts[count($parts)-1] . '.php';
|
||||
if(file_exists("custom/modules/Connectors/connectors/{$type}/{$dir}/$file")){
|
||||
require_once("custom/modules/Connectors/connectors/{$type}/{$dir}/$file");
|
||||
} else if(file_exists("modules/Connectors/connectors/{$type}/{$dir}/$file")) {
|
||||
require_once("modules/Connectors/connectors/{$type}/{$dir}/$file");
|
||||
} else if(file_exists("connectors/{$type}/{$dir}/$file")) {
|
||||
require_once("connectors/{$type}/{$dir}/$file");
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
343
include/connectors/component.php
Executable file
343
include/connectors/component.php
Executable file
@@ -0,0 +1,343 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* 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".
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
class component{
|
||||
protected $_has_testing_enabled = false;
|
||||
protected $_source;
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
public function init() {}
|
||||
|
||||
/**
|
||||
* fillBean
|
||||
* This function wraps the call to getItem, but takes an additional SugarBean argument
|
||||
* and loads the SugarBean's fields with the results as defined in the connector
|
||||
* loadBean configuration mapping
|
||||
*
|
||||
* @param $args Array of arguments to pass into getItem
|
||||
* @param $module String value of the module to map bean to
|
||||
* @param $bean SugarBean instance to load values into
|
||||
* @throws Exception Thrown if results could not be loaded into bean
|
||||
*/
|
||||
public function fillBean($args=array(), $module=null, $bean=null) {
|
||||
$result = null;
|
||||
if(is_object($bean)) {
|
||||
$args = $this->mapInput($args, $module);
|
||||
$item = $this->_source->getItem($args, $module);
|
||||
$result = $this->mapOutput($bean, $item);
|
||||
} else if(!empty($module) && ($bean = loadBean($module))) {
|
||||
return $this->fillBean($args, $module, $bean);
|
||||
} else {
|
||||
throw Exception();
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* fillBeans
|
||||
* This function wraps the call to getList, but takes an additional Array argument
|
||||
* and loads the SugarBean's fields with the results as defined in the connector
|
||||
* loadBean configuration mapping
|
||||
*
|
||||
* @param $args Array of arguments to pass into getItem
|
||||
* @param $module String value of the module to map bean to
|
||||
* @param $bean Array to load SugarBean intances into
|
||||
* @throws Exception Thrown if errors are found
|
||||
*/
|
||||
public function fillBeans($args=array(), $module=null, $beans=array()) {
|
||||
$results = array();
|
||||
$args = $this->mapInput($args, $module);
|
||||
if(empty($args)) {
|
||||
$GLOBALS['log']->fatal($GLOBALS['app_strings']['ERR_MISSING_MAPPING_ENTRY_FORM_MODULE']);
|
||||
throw new Exception($GLOBALS['app_strings']['ERR_MISSING_MAPPING_ENTRY_FORM_MODULE']);
|
||||
}
|
||||
|
||||
|
||||
require_once('include/connectors/filters/FilterFactory.php');
|
||||
$filter = FilterFactory::getInstance(get_class($this->_source));
|
||||
$list = $filter->getList($args, $module);
|
||||
|
||||
if(!empty($list)) {
|
||||
$resultSize = count($list);
|
||||
if(!empty($beans)) {
|
||||
if(count($beans) != $resultSize) {
|
||||
throw new Exception($GLOBALS['app_strings']['ERR_CONNECTOR_FILL_BEANS_SIZE_MISMATCH']);
|
||||
}
|
||||
} else {
|
||||
|
||||
for($x=0; $x < $resultSize; $x++) {
|
||||
$beans[$x] = loadBean($module);
|
||||
}
|
||||
}
|
||||
|
||||
$keys = array_keys($beans);
|
||||
$count = 0;
|
||||
foreach($list as $entry) {
|
||||
//Change the result keys to lower case. This has important ramifications.
|
||||
//This was done because the listviewdefs.php files may not know the proper casing
|
||||
//of the fields to display. We change the keys to lowercase so that the values
|
||||
//may be mapped to the beans without having to rely on the proper string casing
|
||||
//in the listviewdefs.php files.
|
||||
$entry = array_change_key_case($entry, CASE_LOWER);
|
||||
$results[] = $this->mapOutput($beans[$keys[$count]], $entry);
|
||||
$count++;
|
||||
}
|
||||
|
||||
$field_defs = $this->getFieldDefs();
|
||||
$map = $this->getMapping();
|
||||
$hasOptions = !empty($map['options']) ? true : false;
|
||||
if($hasOptions) {
|
||||
$options = $map['options'];
|
||||
$optionFields = array();
|
||||
|
||||
foreach($field_defs as $name=>$field) {
|
||||
if(!empty($field['options']) && !empty($map['options'][$field['options']]) && !empty($map['beans'][$module][$name])) {
|
||||
$optionFields[$name] = $map['beans'][$module][$name];
|
||||
}
|
||||
}
|
||||
|
||||
foreach($results as $key=>$bean) {
|
||||
foreach($optionFields as $sourceField=>$sugarField) {
|
||||
$options_map = $options[$field_defs[$sourceField]['options']];
|
||||
$results[$key]->$sugarField = !empty($options_map[$results[$key]->$sugarField]) ? $options_map[$results[$key]->$sugarField] : $results[$key]->$sugarField;
|
||||
}
|
||||
} //foreach
|
||||
}
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Obtain a list of items
|
||||
*
|
||||
* @param string $module ideally this method should return a list of beans of type $module.
|
||||
* @param Mixed $args this represents the 'query' on the data source.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Given a bean, persist it to a data source
|
||||
*
|
||||
* @param SugarBean $bean
|
||||
*/
|
||||
public function save($bean){}
|
||||
|
||||
|
||||
/**
|
||||
* getConfig
|
||||
* Returns the configuration Array as definied in the config.php file
|
||||
*
|
||||
* @return $config Array of the configuration mappings as defined in config.php
|
||||
*/
|
||||
public function getConfig(){
|
||||
return $this->_source->getConfig;
|
||||
}
|
||||
|
||||
|
||||
public function getFieldDefs() {
|
||||
return $this->_source->getFieldDefs();
|
||||
}
|
||||
|
||||
/**
|
||||
* setConfig
|
||||
* Used by the Factories to set the config on the corresponding object
|
||||
*
|
||||
* @param array $config this file will be specified in config file corresponding to the wrapper or data source we are
|
||||
* using. The name would be something like hoovers.php if we are using the hoovers data source or hoovers wrapper
|
||||
* and it would exist in the same directory as the connector and/or wrapper.
|
||||
* Note that the confing specified at the connector level takes precendence over the config specified at the wrapper level.
|
||||
* This logic is performed in ConnectorFactory.php
|
||||
*/
|
||||
public function setConfig($config){
|
||||
$this->_source->setConfig($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* mapInput
|
||||
*/
|
||||
public function mapInput($inputData, $module){
|
||||
$input_params = array();
|
||||
$map = $this->getMapping();
|
||||
if(empty($map['beans'][$module])) {
|
||||
return $input_params;
|
||||
}
|
||||
$mapping = array_flip($map['beans'][$module]);
|
||||
$field_defs = $this->getFieldDefs();
|
||||
foreach($inputData as $arg=>$val){
|
||||
if(!empty($mapping[$arg]) || !empty($field_defs[$arg])) {
|
||||
if(!empty($mapping[$arg])){
|
||||
$arg = $mapping[$arg];
|
||||
}
|
||||
if(!empty($field_defs[$arg]['input'])){
|
||||
$in_field = $field_defs[$arg]['input'];
|
||||
$temp = explode('.', $in_field);
|
||||
$eval_code = "\$input_params";
|
||||
foreach($temp as $arr_key) {
|
||||
$eval_code .= '[\'' . $arr_key . '\']';
|
||||
}
|
||||
$eval_code .= "= \$val;";
|
||||
eval($eval_code);
|
||||
} else {
|
||||
$input_params[$arg] = $val;
|
||||
}
|
||||
} //if
|
||||
} //foreach
|
||||
return $input_params;
|
||||
}
|
||||
|
||||
public function mapOutput($bean, $result){
|
||||
if(is_object($bean)) {
|
||||
$map = $this->getMapping();
|
||||
$mapping = $map['beans'][$bean->module_dir];
|
||||
|
||||
//Check for situation where nothing was mapped or the only field mapped was id
|
||||
if(empty($mapping) || (count($mapping) == 1 && isset($mapping['id']))) {
|
||||
$GLOBALS['log']->error($GLOBALS['mod_strings']['ERROR_NO_DISPLAYABLE_MAPPED_FIELDS']);
|
||||
throw new Exception($GLOBALS['mod_strings']['ERROR_NO_DISPLAYABLE_MAPPED_FIELDS']);
|
||||
}
|
||||
|
||||
$mapped = array();
|
||||
if(!empty($mapping)) {
|
||||
foreach($mapping as $source_field => $sugar_field){
|
||||
$bean->$sugar_field = $this->getFieldValue($bean, $result, $source_field);
|
||||
$mapped[$source_field] = $bean->$sugar_field;
|
||||
}
|
||||
} else {
|
||||
foreach($result as $key=>$value) {
|
||||
if(isset($bean->field_defs[$key])) {
|
||||
$bean->$key = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//set the data_source_id field which contain the unique id for the source
|
||||
$source_field = 'id';
|
||||
$bean->data_source_id = $this->getFieldValue($bean, $result, $source_field);
|
||||
|
||||
//now let's check for any fields that have not been mapped which may be required
|
||||
$required_fields = $this->_source->getFieldsWithParams('required', true);
|
||||
if(!empty($required_fields)){
|
||||
foreach($required_fields as $key => $def){
|
||||
if(empty($mapped[$key])){
|
||||
$bean->$key = $this->getFieldValue($bean, $result, $key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $bean;
|
||||
}
|
||||
return $bean;
|
||||
}
|
||||
|
||||
private function getFieldValue($bean, $result, $source_field){
|
||||
$def = $this->getModuleFieldDef($bean->module_dir, $source_field);
|
||||
$out_field = $source_field;
|
||||
if(!empty($def['output'])){
|
||||
$out_field = $def['output'];
|
||||
}
|
||||
|
||||
$value = SugarArray::staticGet($result, $out_field);
|
||||
|
||||
if(is_array($def)){
|
||||
if(!empty($def['function'])){
|
||||
$function = $def['function'];
|
||||
if(is_array($function) && isset($function['name'])){
|
||||
$function = $def['function']['name'];
|
||||
if(!empty($def['function']['include'])){
|
||||
require_once($def['function']['include']);
|
||||
}
|
||||
}
|
||||
$value = $function($bean, $out_field, $value);
|
||||
}
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
public function saveConfig($persister=null) {
|
||||
$this->_source->saveConfig($persister);
|
||||
}
|
||||
|
||||
public function loadConfig($persister=null) {
|
||||
$this->_source->loadConfig($persister);
|
||||
}
|
||||
|
||||
public function setMapping($map=array()) {
|
||||
$this->_source->setMapping($map);
|
||||
}
|
||||
|
||||
public function getMapping() {
|
||||
return $this->_source->getMapping();
|
||||
}
|
||||
|
||||
public function getModuleMapping($module) {
|
||||
$map = $this->getMapping();
|
||||
return !empty($map['beans'][$module]) ? $map['beans'][$module] : array();
|
||||
}
|
||||
|
||||
public function getModuleFieldDef($module, $field){
|
||||
$map = $this->getMapping();
|
||||
$field_defs = $this->getFieldDefs();
|
||||
if(!empty($map['beans'][$module][$field])){
|
||||
$source_field = $field;
|
||||
if(!empty($field_defs[$source_field])){
|
||||
return $field_defs[$source_field];
|
||||
}elseif(!empty($field_defs[$field])){
|
||||
return $field_defs[$field];
|
||||
}else{
|
||||
return $field;
|
||||
}
|
||||
}elseif(!empty($field_defs[$field])){
|
||||
return $field_defs[$field];
|
||||
}else{
|
||||
return $field;
|
||||
}
|
||||
}
|
||||
|
||||
public function getSource(){
|
||||
return $this->_source;
|
||||
}
|
||||
|
||||
public function setSource($source){
|
||||
$this->_source = $source;
|
||||
}
|
||||
}
|
||||
?>
|
||||
80
include/connectors/filters/FilterFactory.php
Executable file
80
include/connectors/filters/FilterFactory.php
Executable file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* 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".
|
||||
********************************************************************************/
|
||||
|
||||
class FilterFactory{
|
||||
|
||||
static $filter_map = array();
|
||||
|
||||
public static function getInstance($source_name, $filter_name=''){
|
||||
require_once('include/connectors/filters/default/filter.php');
|
||||
$key = $source_name . $filter_name;
|
||||
if(empty(self::$filter_map[$key])) {
|
||||
|
||||
if(empty($filter_name)){
|
||||
$filter_name = $source_name;
|
||||
}
|
||||
|
||||
//split the wrapper name to find the path to the file.
|
||||
$dir = str_replace('_','/',$filter_name);
|
||||
$parts = explode("/", $dir);
|
||||
$file = $parts[count($parts)-1];
|
||||
|
||||
//check if this override wrapper file exists.
|
||||
require_once('include/connectors/ConnectorFactory.php');
|
||||
if(file_exists("modules/Connectors/connectors/filters/{$dir}/{$file}.php") ||
|
||||
file_exists("custom/modules/Connectors/connectors/filters/{$dir}/{$file}.php")) {
|
||||
ConnectorFactory::load($filter_name, 'filters');
|
||||
try{
|
||||
$filter_name .= '_filter';
|
||||
}catch(Exception $ex){
|
||||
return null;
|
||||
}
|
||||
}else{
|
||||
//if there is no override wrapper, use the default.
|
||||
$filter_name = 'default_filter';
|
||||
}
|
||||
|
||||
$component = ConnectorFactory::getInstance($source_name);
|
||||
$filter = new $filter_name();
|
||||
$filter->setComponent($component);
|
||||
self::$filter_map[$key] = $filter;
|
||||
} //if
|
||||
return self::$filter_map[$key];
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
55
include/connectors/filters/default/filter.php
Executable file
55
include/connectors/filters/default/filter.php
Executable file
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
/*********************************************************************************
|
||||
* 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".
|
||||
********************************************************************************/
|
||||
class default_filter {
|
||||
|
||||
var $_component;
|
||||
|
||||
public function default_filter() {
|
||||
|
||||
}
|
||||
|
||||
public function setComponent($component) {
|
||||
$this->_component = $component;
|
||||
}
|
||||
|
||||
public function getList($args, $module) {
|
||||
$args = $this->_component->mapInput($args, $module);
|
||||
return $this->_component->getSource()->getList($args, $module);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
95
include/connectors/formatters/FormatterFactory.php
Executable file
95
include/connectors/formatters/FormatterFactory.php
Executable file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* 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".
|
||||
********************************************************************************/
|
||||
class FormatterFactory {
|
||||
|
||||
static $formatter_map = array();
|
||||
|
||||
/**
|
||||
* getInstance
|
||||
* This method returns a formatter instance for the given source name and
|
||||
* formatter name. If no formatter name is specified, the default formatter
|
||||
* for the source is used.
|
||||
*
|
||||
* @param $source_name The data source name to retreive formatter for
|
||||
* @param $formatter_name Optional formatter name to use
|
||||
* @param $wrapper_name Optional wrapper name to use
|
||||
* @return $instance The formatter instance
|
||||
*/
|
||||
public static function getInstance($source_name, $formatter_name=''){
|
||||
require_once('include/connectors/formatters/default/formatter.php');
|
||||
$key = $source_name . $formatter_name;
|
||||
if(empty(self::$formatter_map[$key])) {
|
||||
|
||||
if(empty($formatter_name)){
|
||||
$formatter_name = $source_name;
|
||||
}
|
||||
|
||||
//split the wrapper name to find the path to the file.
|
||||
$dir = str_replace('_','/',$formatter_name);
|
||||
$parts = explode("/", $dir);
|
||||
$file = $parts[count($parts)-1];
|
||||
|
||||
//check if this override wrapper file exists.
|
||||
require_once('include/connectors/ConnectorFactory.php');
|
||||
if(file_exists("modules/Connectors/connectors/formatters/{$dir}/{$file}.php") ||
|
||||
file_exists("custom/modules/Connectors/connectors/formatters/{$dir}/{$file}.php")) {
|
||||
ConnectorFactory::load($formatter_name, 'formatters');
|
||||
try{
|
||||
$formatter_name .= '_formatter';
|
||||
}catch(Exception $ex){
|
||||
return null;
|
||||
}
|
||||
}else{
|
||||
//if there is no override wrapper, use the default.
|
||||
$formatter_name = 'default_formatter';
|
||||
}
|
||||
|
||||
$component = ConnectorFactory::getInstance($source_name);
|
||||
$formatter = new $formatter_name();
|
||||
$formatter->setComponent($component);
|
||||
if(file_exists("custom/modules/Connectors/connectors/formatters/{$dir}/tpls/{$file}.tpl")){
|
||||
$formatter->setTplFileName("custom/modules/Connectors/connectors/formatters/{$dir}/tpls/{$file}.tpl");
|
||||
} else if("modules/Connectors/connectors/formatters/{$dir}/tpls/{$file}.tpl") {
|
||||
$formatter->setTplFileName("modules/Connectors/connectors/formatters/{$dir}/tpls/{$file}.tpl");
|
||||
}
|
||||
self::$formatter_map[$key] = $formatter;
|
||||
} //if
|
||||
return self::$formatter_map[$key];
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
42
include/connectors/formatters/default/company_detail.js
Normal file
42
include/connectors/formatters/default/company_detail.js
Normal file
@@ -0,0 +1,42 @@
|
||||
/*********************************************************************************
|
||||
* 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".
|
||||
********************************************************************************/
|
||||
function CompanyDetailsDialog(div_id,text,x,y)
|
||||
{this.div_id=div_id;this.text=text;this.width=300;this.header='';this.footer='';this.x=x;this.y=y;}
|
||||
function header(header)
|
||||
{this.header=header;}
|
||||
function footer(footer)
|
||||
{this.footer=footer;}
|
||||
function display(){dialog=new YAHOO.widget.SimpleDialog(this.div_id,{width:this.width,visible:true,draggable:true,close:true,text:this.text,constraintoviewport:true,x:this.x,y:this.y});dialog.setHeader(this.header);dialog.setBody(this.text);dialog.setFooter(this.footer);dialog.render(document.body);dialog.show();}
|
||||
CompanyDetailsDialog.prototype.setHeader=header;CompanyDetailsDialog.prototype.setFooter=footer;CompanyDetailsDialog.prototype.display=display;
|
||||
148
include/connectors/formatters/default/formatter.php
Executable file
148
include/connectors/formatters/default/formatter.php
Executable file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* 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".
|
||||
********************************************************************************/
|
||||
|
||||
class default_formatter {
|
||||
|
||||
protected $_ss;
|
||||
protected $_component;
|
||||
protected $_tplFileName;
|
||||
protected $_module;
|
||||
protected $_hoverField;
|
||||
|
||||
public function __construct() {}
|
||||
|
||||
public function getDetailViewFormat() {
|
||||
$source = $this->_component->getSource();
|
||||
$class = get_class($source);
|
||||
$dir = str_replace('_', '/', $class);
|
||||
$config = $source->getConfig();
|
||||
$this->_ss->assign('config', $config);
|
||||
$this->_ss->assign('source', $class);
|
||||
$this->_ss->assign('module', $this->_module);
|
||||
$mapping = $source->getMapping();
|
||||
$mapping = !empty($mapping['beans'][$this->_module]) ? implode(',', array_values($mapping['beans'][$this->_module])) : '';
|
||||
$this->_ss->assign('mapping', $mapping);
|
||||
|
||||
if(file_exists("custom/modules/Connectors/connectors/formatters/{$dir}/tpls/{$this->_module}.tpl")) {
|
||||
return $this->_ss->fetch("custom/modules/Connectors/connectors/formatters/{$dir}/tpls/{$this->_module}.tpl");
|
||||
} else if(file_exists("modules/Connectors/connectors/formatters/{$dir}/tpls/{$this->_module}.tpl")) {
|
||||
return $this->_ss->fetch("modules/Connectors/connectors/formatters/{$dir}/tpls/{$this->_module}.tpl");
|
||||
} else if(file_exists("custom/modules/Connectors/connectors/formatters/{$dir}/tpls/default.tpl")) {
|
||||
return $this->_ss->fetch("custom/modules/Connectors/connectors/formatters/{$dir}/tpls/default.tpl");
|
||||
} else if(file_exists("modules/Connectors/connectors/formatters/{$dir}/tpls/default.tpl")) {
|
||||
return $this->_ss->fetch("modules/Connectors/connectors/formatters/{$dir}/tpls/default.tpl");
|
||||
} else if(preg_match('/_soap_/', $class)) {
|
||||
return $this->_ss->fetch("include/connectors/formatters/ext/soap/tpls/default.tpl");
|
||||
} else {
|
||||
return $this->_ss->fetch("include/connectors/formatters/ext/rest/tpls/default.tpl");
|
||||
}
|
||||
}
|
||||
|
||||
public function getEditViewFormat() {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getListViewFormat() {
|
||||
return '';
|
||||
}
|
||||
|
||||
public function getSearchFormFormat() {
|
||||
return '';
|
||||
}
|
||||
|
||||
protected function fetchSmarty(){
|
||||
$source = $this->_component->getSource();
|
||||
$class = get_class($source);
|
||||
$dir = str_replace('_', '/', $class);
|
||||
$config = $source->getConfig();
|
||||
$this->_ss->assign('config', $config);
|
||||
$this->_ss->assign('source', $class);
|
||||
$this->_ss->assign('module', $this->_module);
|
||||
if(file_exists("custom/modules/Connectors/connectors/formatters/{$dir}/tpls/{$this->_module}.tpl")) {
|
||||
return $this->_ss->fetch("custom/modules/Connectors/connectors/formatters/{$dir}/tpls/{$this->_module}.tpl");
|
||||
} else if(file_exists("modules/Connectors/connectors/formatters/{$dir}/tpls/{$this->_module}.tpl")) {
|
||||
return $this->_ss->fetch("modules/Connectors/connectors/formatters/{$dir}/tpls/{$this->_module}.tpl");
|
||||
} else if(file_exists("custom/modules/Connectors/connectors/formatters/{$dir}/tpls/default.tpl")) {
|
||||
return $this->_ss->fetch("custom/modules/Connectors/connectors/formatters/{$dir}/tpls/default.tpl");
|
||||
} else {
|
||||
return $this->_ss->fetch("modules/Connectors/connectors/formatters/{$dir}/tpls/default.tpl");
|
||||
}
|
||||
}
|
||||
|
||||
public function getSourceMapping(){
|
||||
$source = $this->_component->getSource();
|
||||
$mapping = $source->getMapping();
|
||||
return $mapping;
|
||||
}
|
||||
|
||||
public function setSmarty($smarty) {
|
||||
$this->_ss = $smarty;
|
||||
}
|
||||
|
||||
public function getSmarty() {
|
||||
return $this->_ss;
|
||||
}
|
||||
|
||||
public function setComponent($component) {
|
||||
$this->_component = $component;
|
||||
}
|
||||
|
||||
public function getComponent() {
|
||||
return $this->_component;
|
||||
}
|
||||
|
||||
public function getTplFileName(){
|
||||
return $this->tplFileName;
|
||||
}
|
||||
|
||||
public function setTplFileName($tplFileName){
|
||||
$this->tplFileName = $tplFileName;
|
||||
}
|
||||
|
||||
public function setModule($module) {
|
||||
$this->_module = $module;
|
||||
}
|
||||
|
||||
public function getModule() {
|
||||
return $this->_module;
|
||||
}
|
||||
|
||||
public function getIconFilePath() {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
?>
|
||||
36
include/connectors/formatters/ext/rest/tpls/default.tpl
Executable file
36
include/connectors/formatters/ext/rest/tpls/default.tpl
Executable file
@@ -0,0 +1,36 @@
|
||||
{*
|
||||
/*********************************************************************************
|
||||
* 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".
|
||||
********************************************************************************/
|
||||
*}
|
||||
83
include/connectors/formatters/ext/soap/tpls/default.tpl
Executable file
83
include/connectors/formatters/ext/soap/tpls/default.tpl
Executable file
@@ -0,0 +1,83 @@
|
||||
{*
|
||||
/*********************************************************************************
|
||||
* 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".
|
||||
********************************************************************************/
|
||||
*}
|
||||
<div style="visibility:hidden;" id="{{$source}}_popup_div"></div>
|
||||
<script type="text/javascript">
|
||||
function show_{{$source}}(event)
|
||||
{literal}
|
||||
{
|
||||
|
||||
var callback = {
|
||||
success: function(data) {
|
||||
eval('result = ' + data.responseText);
|
||||
if(typeof result != 'Undefined') {
|
||||
names = new Array();
|
||||
output = '';
|
||||
count = 0;
|
||||
for(var i in result) {
|
||||
if(count == 0) {
|
||||
detail = 'Showing first result <p>';
|
||||
for(var field in result[i]) {
|
||||
detail += '<b>' + field + ':</b> ' + result[i][field] + '<br>';
|
||||
}
|
||||
output += detail + '<p>';
|
||||
}
|
||||
count++;
|
||||
}
|
||||
{/literal}
|
||||
cd = new CompanyDetailsDialog("{{$source}}_popup_div", output, event.clientX, event.clientY);
|
||||
{literal}
|
||||
cd.setHeader("Found " + count + (count == 1 ? " result" : " results"));
|
||||
cd.display();
|
||||
} else {
|
||||
alert("Unable to retrieve information for record");
|
||||
}
|
||||
},
|
||||
|
||||
failure: function(data) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
{/literal}
|
||||
|
||||
url = 'index.php?module=Connectors&action=DefaultSoapPopup&source_id={{$source}}&module_id={{$module}}&record_id={$fields.id.value}&mapping={{$mapping}}';
|
||||
var cObj = YAHOO.util.Connect.asyncRequest('POST', url, callback);
|
||||
|
||||
{literal}
|
||||
}
|
||||
{/literal}
|
||||
</script>
|
||||
73
include/connectors/sources/SourceFactory.php
Executable file
73
include/connectors/sources/SourceFactory.php
Executable file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* 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".
|
||||
********************************************************************************/
|
||||
/**
|
||||
* Provides a factory to loading a connector along with any key->value options to initialize on the
|
||||
* source. The name of the class to be loaded, corresponds to the path on the file system. For example a source
|
||||
* with the name ext_soap_hoovers would be ext/soap/hoovers.php
|
||||
*/
|
||||
class SourceFactory{
|
||||
|
||||
/**
|
||||
* Given a source param, load the correct source and return the object
|
||||
* @param string $source string representing the source to load
|
||||
* @return source
|
||||
*/
|
||||
public static function getSource($class, $call_init = true) {
|
||||
$dir = str_replace('_','/',$class);
|
||||
$parts = explode("/", $dir);
|
||||
$file = $parts[count($parts)-1];
|
||||
$pos = strrpos($file, '/');
|
||||
//if(file_exists("connectors/sources/{$dir}/{$file}.php") || file_exists("custom/connectors/sources/{$dir}/{$file}.php")){
|
||||
require_once('include/connectors/sources/default/source.php');
|
||||
require_once('include/connectors/ConnectorFactory.php');
|
||||
ConnectorFactory::load($class, 'sources');
|
||||
try{
|
||||
$instance = new $class();
|
||||
if($call_init){
|
||||
$instance->init();
|
||||
}
|
||||
return $instance;
|
||||
}catch(Exception $ex){
|
||||
return null;
|
||||
}
|
||||
//}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
354
include/connectors/sources/default/source.php
Executable file
354
include/connectors/sources/default/source.php
Executable file
@@ -0,0 +1,354 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* 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".
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* source is the parent class of any source object.
|
||||
*
|
||||
*/
|
||||
abstract class source{
|
||||
/**
|
||||
* The name of an wrapper to use if the class wants to provide an override
|
||||
*/
|
||||
public $wrapperName;
|
||||
protected $_config;
|
||||
protected $_mapping;
|
||||
protected $_field_defs;
|
||||
protected $_enable_in_wizard = true;
|
||||
protected $_enable_in_hover = false;
|
||||
protected $_has_testing_enabled = false;
|
||||
protected $_required_config_fields = array();
|
||||
protected $_required_config_fields_for_button = array();
|
||||
|
||||
public function __construct(){
|
||||
$this->loadConfig();
|
||||
$this->loadMapping();
|
||||
$this->loadVardefs();
|
||||
}
|
||||
|
||||
public function init(){}
|
||||
|
||||
//////// CALLED FROM component.php ///////
|
||||
public function loadMapping() {
|
||||
$mapping = array();
|
||||
$dir = str_replace('_','/',get_class($this));
|
||||
if(file_exists("custom/modules/Connectors/connectors/sources/{$dir}/mapping.php")) {
|
||||
require("custom/modules/Connectors/connectors/sources/{$dir}/mapping.php");
|
||||
} else if(file_exists("modules/Connectors/connectors/sources/{$dir}/mapping.php")){
|
||||
require("modules/Connectors/connectors/sources/{$dir}/mapping.php");
|
||||
}
|
||||
$this->_mapping = $mapping;
|
||||
}
|
||||
|
||||
public function loadVardefs() {
|
||||
$class = get_class($this);
|
||||
$dir = str_replace('_','/',$class);
|
||||
if(file_exists("custom/modules/Connectors/connectors/sources/{$dir}/vardefs.php")) {
|
||||
require("custom/modules/Connectors/connectors/sources/{$dir}/vardefs.php");
|
||||
} else if(file_exists("modules/Connectors/connectors/sources/{$dir}/vardefs.php")){
|
||||
require("modules/Connectors/connectors/sources/{$dir}/vardefs.php");
|
||||
}
|
||||
|
||||
$this->_field_defs = !empty($dictionary[$class]['fields']) ? $dictionary[$class]['fields'] : array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a parameter in a vardef field, return the list of fields that match the param and value
|
||||
*
|
||||
* @param unknown_type $param_name
|
||||
* @param unknown_type $param_value
|
||||
* @return unknown
|
||||
*/
|
||||
public function getFieldsWithParams($param_name, $param_value) {
|
||||
if(empty($this->_field_defs)){
|
||||
$this->loadVardefs();
|
||||
}
|
||||
$fields_with_param = array();
|
||||
foreach($this->_field_defs as $key => $def){
|
||||
if(!empty($def[$param_name]) && ($def[$param_name] == $param_value)){
|
||||
$fields_with_param[$key] = $def;
|
||||
}
|
||||
}
|
||||
return $fields_with_param;
|
||||
}
|
||||
|
||||
public function saveConfig() {
|
||||
$config_str = "<?php\n/***CONNECTOR SOURCE***/\n";
|
||||
foreach($this->_config as $key => $val) {
|
||||
if(!empty($val)){
|
||||
$config_str .= override_value_to_string_recursive2('config', $key, $val, false);
|
||||
}
|
||||
}
|
||||
$dir = str_replace('_', '/', get_class($this));
|
||||
|
||||
if(!file_exists("custom/modules/Connectors/connectors/sources/{$dir}")) {
|
||||
mkdir_recursive("custom/modules/Connectors/connectors/sources/{$dir}");
|
||||
}
|
||||
$fp = sugar_fopen("custom/modules/Connectors/connectors/sources/{$dir}/config.php", 'w');
|
||||
fwrite($fp, $config_str);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
public function loadConfig() {
|
||||
$config = array();
|
||||
$dir = str_replace('_','/',get_class($this));
|
||||
if(file_exists("modules/Connectors/connectors/sources/{$dir}/config.php")){
|
||||
require("modules/Connectors/connectors/sources/{$dir}/config.php");
|
||||
}
|
||||
if(file_exists("custom/modules/Connectors/connectors/sources/{$dir}/config.php")) {
|
||||
require("custom/modules/Connectors/connectors/sources/{$dir}/config.php");
|
||||
}
|
||||
$this->_config = $config;
|
||||
|
||||
//If there are no required config fields specified, we will default them to all be required
|
||||
if(empty($this->_required_config_fields)) {
|
||||
foreach($this->_config['properties'] as $id=>$value) {
|
||||
$this->_required_config_fields[] = $id;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////// GETTERS and SETTERS ////////////////////
|
||||
public function getMapping(){
|
||||
return $this->_mapping;
|
||||
}
|
||||
|
||||
public function getOriginalMapping() {
|
||||
$mapping = array();
|
||||
$dir = str_replace('_','/',get_class($this));
|
||||
if(file_exists("modules/Connectors/connectors/sources/{$dir}/mapping.php")) {
|
||||
require("modules/Connectors/connectors/sources/{$dir}/mapping.php");
|
||||
} else if(file_exists("custom/modules/Connectors/connectors/sources/{$dir}/mapping.php")){
|
||||
require("custom/modules/Connectors/connectors/sources/{$dir}/mapping.php");
|
||||
}
|
||||
return $mapping;
|
||||
}
|
||||
|
||||
public function setMapping($mapping){
|
||||
$this->_mapping = $mapping;
|
||||
}
|
||||
|
||||
public function getFieldDefs(){
|
||||
return $this->_field_defs;
|
||||
}
|
||||
|
||||
public function getConfig(){
|
||||
return $this->_config;
|
||||
}
|
||||
|
||||
public function setConfig($config){
|
||||
$this->_config = $config;
|
||||
}
|
||||
|
||||
public function setProperties($properties=array()) {
|
||||
if(!empty($this->_config) && isset($this->_config['properties'])) {
|
||||
$this->_config['properties'] = $properties;
|
||||
}
|
||||
}
|
||||
|
||||
public function getProperties() {
|
||||
if(!empty($this->_config) && isset($this->_config['properties'])) {
|
||||
return $this->_config['properties'];
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
public function getProperty($name){
|
||||
$properties = $this->getProperties();
|
||||
if(!empty($properties['name'])){
|
||||
return $properties['name'];
|
||||
}else{
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* hasTestingEnabled
|
||||
* This method is used to indicate whether or not a data source has testing enabled so that
|
||||
* the administration interface may call the test method on the data source instance
|
||||
*
|
||||
* @return enabled boolean value indicating whether or not testing is enabled
|
||||
*/
|
||||
public function hasTestingEnabled() {
|
||||
return $this->_has_testing_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* test
|
||||
* This method is called from the administration interface to run a test of the service
|
||||
* It is up to subclasses to implement a test and set _has_testing_enabled to true so that
|
||||
* a test button is rendered in the administration interface
|
||||
*
|
||||
* @return result boolean result of the test function
|
||||
*/
|
||||
public function test() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* isEnabledInWizard
|
||||
* This method indicates whether or not the connector should be enabled in the wizard
|
||||
* Connectors that do not support the getList/getItem methods via API calls should
|
||||
* set the protected class variable _enable_in_wizard to false.
|
||||
*
|
||||
* @return $enabled boolean variable indicating whether or not the connector is enabled for the wizard
|
||||
*/
|
||||
public function isEnabledInWizard() {
|
||||
return $this->_enable_in_wizard;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* isEnabledInHover
|
||||
* This method indicates whether or not the connector should be enabled for the hover links
|
||||
* Connectors that do not provide a formatter implementation should not
|
||||
* set the protected class variable _enable_in_hover to true.
|
||||
*
|
||||
* @return $enabled boolean variable indicating whether or not the connector is enabled for the hover links
|
||||
*
|
||||
*/
|
||||
public function isEnabledInHover() {
|
||||
return $this->_enable_in_hover;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getRequiredConfigFields
|
||||
* This method returns an Array of the configuration keys that are required for the Connector.
|
||||
* Subclasses should set the class variable _required_config_fields to
|
||||
* return an Array of keys as specified in the Connector's config.php that are required.
|
||||
*
|
||||
* @return $fields Array of Connector config fields that are required
|
||||
*/
|
||||
public function getRequiredConfigFields() {
|
||||
return $this->_required_config_fields;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* isRequiredConfigFieldsSet
|
||||
* This method checks the configuration parameters against the required config fields
|
||||
* to see if they are set
|
||||
*
|
||||
* @return $set boolean value indicating whether or not the required config fields are set
|
||||
*/
|
||||
public function isRequiredConfigFieldsSet() {
|
||||
//Check if required fields are set
|
||||
foreach($this->_required_config_fields as $field) {
|
||||
if(empty($this->_config['properties'][$field])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getRequiredConfigFieldsForButton
|
||||
* This method returns an Array of the configuration keys that are required before the
|
||||
* "Get Data" button will include the Connector. We use it as a subset of the
|
||||
* $this->_required_config_fields Array.
|
||||
*
|
||||
* @return $fields Array of Connector config fields that are required to be set for the "Get Data" button to appear
|
||||
*/
|
||||
public function getRequiredConfigFieldsForButton() {
|
||||
return $this->_required_config_fields_for_button;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* isRequiredConfigFieldsForButtonSet
|
||||
* This method checks the configuration parameters against the required config fields
|
||||
* for the "Get Button" to see if they are set
|
||||
*
|
||||
* @return $set boolean value indicating whether or not the required config fields are set
|
||||
*/
|
||||
public function isRequiredConfigFieldsForButtonSet() {
|
||||
//Check if required fields for button are set
|
||||
foreach($this->_required_config_fields_for_button as $field) {
|
||||
if(empty($this->_config['properties'][$field])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Allow data sources to log information
|
||||
*
|
||||
* @param string $log_data
|
||||
*/
|
||||
protected function log($log_data){
|
||||
$name = get_class($this);
|
||||
$property_name = $this->getProperty('name');
|
||||
if(!empty($property_name)){
|
||||
$name = $property_name;
|
||||
}
|
||||
$GLOBALS['log']->info($name. ': '.$log_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* getItem
|
||||
* Returns an array containing a key/value pair(s) of a connector record. To be overridden by the implementation
|
||||
* source.
|
||||
*
|
||||
* @param $args Array of arguments to search/filter by
|
||||
* @param $module String optional value of the module that the connector framework is attempting to map to
|
||||
* @return Array of key/value pair(s) of connector record; empty Array if no results are found
|
||||
*/
|
||||
public abstract function getItem($args=array(), $module=null);
|
||||
|
||||
|
||||
/**
|
||||
* getList
|
||||
* Returns a nested array containing a key/value pair(s) of a connector record. To be overridden by the
|
||||
* implementation source.
|
||||
*
|
||||
* @param $args Array of arguments to search/filter by
|
||||
* @param $module String optional value of the module that the connector framework is attempting to map to
|
||||
* @return Array of key/value pair(s) of connector record; empty Array if no results are found
|
||||
*/
|
||||
public abstract function getList($args=array(), $module=null);
|
||||
|
||||
/**
|
||||
* Default destructor
|
||||
*
|
||||
*/
|
||||
public function __destruct(){}
|
||||
}
|
||||
?>
|
||||
69
include/connectors/sources/ext/rest/rest.php
Executable file
69
include/connectors/sources/ext/rest/rest.php
Executable file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* 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('include/connectors/sources/default/source.php');
|
||||
|
||||
abstract class ext_rest extends source{
|
||||
|
||||
protected $_url;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function fetchUrl($url){
|
||||
$data = '';
|
||||
$data = @file_get_contents($url);
|
||||
if(empty($data)) {
|
||||
$GLOBALS['log']->error("Unable to retrieve contents from url:[{$url}]");
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getUrl(){
|
||||
return $this->_url;
|
||||
}
|
||||
|
||||
public function setUrl($url){
|
||||
$this->_url = $url;
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
parent::__destruct();
|
||||
}
|
||||
}
|
||||
?>
|
||||
87
include/connectors/sources/ext/soap/soap.php
Executable file
87
include/connectors/sources/ext/soap/soap.php
Executable file
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* 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('include/connectors/sources/default/source.php');
|
||||
require_once('include/nusoap/nusoap.php');
|
||||
|
||||
/**
|
||||
* ext_soap
|
||||
* This class is the soap implementation for the connector framework.
|
||||
* Connectors that use SOAP calls should subclass this class and provide
|
||||
* a getList and getItem method override to return results from the connector
|
||||
*
|
||||
*/
|
||||
abstract class ext_soap extends source {
|
||||
|
||||
protected $_client;
|
||||
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* obj2array
|
||||
* Given an object, returns the object as an Array
|
||||
*
|
||||
* @param $obj Object to convert to an array
|
||||
* @return $out Array reflecting the object's properties
|
||||
*/
|
||||
public function obj2array($obj) {
|
||||
$out = array();
|
||||
if(empty($obj)) {
|
||||
return $out;
|
||||
}
|
||||
|
||||
foreach ($obj as $key => $val) {
|
||||
switch(true) {
|
||||
case is_object($val):
|
||||
$out[$key] = $this->obj2array($val);
|
||||
break;
|
||||
case is_array($val):
|
||||
$out[$key] = $this->obj2array($val);
|
||||
break;
|
||||
default:
|
||||
$out[$key] = $val;
|
||||
}
|
||||
}
|
||||
return $out;
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
parent::__destruct();
|
||||
}
|
||||
}
|
||||
?>
|
||||
51
include/connectors/sources/loc/xml.php
Executable file
51
include/connectors/sources/loc/xml.php
Executable file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* 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".
|
||||
********************************************************************************/
|
||||
class loc_xml extends source{
|
||||
public function __construct(){
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function __parse($file){
|
||||
$contents = file_get_contents($file);
|
||||
return simplexml_load_string($contents);
|
||||
}
|
||||
|
||||
public function __destruct(){
|
||||
parent::__destruct();
|
||||
}
|
||||
}
|
||||
?>
|
||||
895
include/connectors/utils/ConnectorUtils.php
Executable file
895
include/connectors/utils/ConnectorUtils.php
Executable file
@@ -0,0 +1,895 @@
|
||||
<?php
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
/*********************************************************************************
|
||||
* 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".
|
||||
********************************************************************************/
|
||||
define('CONNECTOR_DISPLAY_CONFIG_FILE', 'custom/modules/Connectors/metadata/display_config.php');
|
||||
require_once('include/connectors/ConnectorFactory.php');
|
||||
|
||||
function sources_sort_function($a, $b) {
|
||||
if(isset($a['order']) && isset($b['order'])) {
|
||||
if($a['order'] == $b['order']) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ($a['order'] < $b['order']) ? -1 : 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
class ConnectorUtils
|
||||
{
|
||||
public static function getConnector(
|
||||
$id,
|
||||
$refresh = false
|
||||
)
|
||||
{
|
||||
$s = self::getConnectors($refresh);
|
||||
return !empty($s[$id]) ? $s[$id] : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getSearchDefs
|
||||
* Returns an Array of the search field defintions Connector module to
|
||||
* search entries from the connector. If the searchdefs.php file in the custom
|
||||
* directory is not found, it defaults to using the mapping.php file entries to
|
||||
* create a default version of the file.
|
||||
*
|
||||
* @param boolean $refresh boolean value to manually refresh the search definitions
|
||||
* @return mixed $searchdefs Array of the search definitions
|
||||
*/
|
||||
public static function getSearchDefs(
|
||||
$refresh = false
|
||||
)
|
||||
{
|
||||
if($refresh || !file_exists('custom/modules/Connectors/metadata/searchdefs.php')) {
|
||||
|
||||
require('modules/Connectors/metadata/searchdefs.php');
|
||||
|
||||
if(!file_exists('custom/modules/Connectors/metadata')) {
|
||||
mkdir_recursive('custom/modules/Connectors/metadata');
|
||||
}
|
||||
|
||||
if(!write_array_to_file('searchdefs', $searchdefs, 'custom/modules/Connectors/metadata/searchdefs.php')) {
|
||||
$GLOBALS['log']->fatal("Cannot write file custom/modules/Connectors/metadata/searchdefs.php");
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
require('custom/modules/Connectors/metadata/searchdefs.php');
|
||||
return $searchdefs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getViewDefs
|
||||
* Returns an Array of the merge definitions used by the Connector module to
|
||||
* merge values into the bean instance
|
||||
*
|
||||
* @param mixed $filter_sources Array optional Array value of sources to only use
|
||||
* @return mixed $mergedefs Array of the merge definitions
|
||||
*/
|
||||
public static function getViewDefs(
|
||||
$filter_sources = array()
|
||||
)
|
||||
{
|
||||
//Go through all connectors and get their mapping keys and merge them across each module
|
||||
$connectors = self::getConnectors();
|
||||
$modules_sources = self::getDisplayConfig();
|
||||
$view_defs = array();
|
||||
foreach($connectors as $id=>$ds) {
|
||||
|
||||
if(!empty($filter_sources) && !isset($filter_sources[$id])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(file_exists('custom/' . $ds['directory'] . '/mapping.php')) {
|
||||
require('custom/' . $ds['directory'] . '/mapping.php');
|
||||
} else if(file_exists($ds['directory'] . '/mapping.php')) {
|
||||
require($ds['directory'] . '/mapping.php');
|
||||
}
|
||||
|
||||
if(!empty($mapping['beans'])) {
|
||||
foreach($mapping['beans'] as $module=>$map) {
|
||||
if(!empty($modules_sources[$module][$id])) {
|
||||
if(!empty($view_defs['Connector']['MergeView'][$module])) {
|
||||
$view_defs['Connector']['MergeView'][$module] = array_merge($view_defs['Connector']['MergeView'][$module], array_flip($map));
|
||||
} else {
|
||||
$view_defs['Connector']['MergeView'][$module] = array_flip($map);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($view_defs['Connector']['MergeView'])) {
|
||||
foreach($view_defs['Connector']['MergeView'] as $module=>$map) {
|
||||
$view_defs['Connector']['MergeView'][$module] = array_keys($view_defs['Connector']['MergeView'][$module]);
|
||||
}
|
||||
}
|
||||
|
||||
return $view_defs;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getMergeViewDefs
|
||||
* Returns an Array of the merge definitions used by the Connector module to
|
||||
* merge values into the bean instance
|
||||
*
|
||||
* @deprecated This method has been replaced by getViewDefs
|
||||
* @param boolean $refresh boolean value to manually refresh the mergeview definitions
|
||||
* @return mixed $mergedefs Array of the merge definitions
|
||||
*/
|
||||
public static function getMergeViewDefs(
|
||||
$refresh = false
|
||||
)
|
||||
{
|
||||
if($refresh || !file_exists('custom/modules/Connectors/metadata/mergeviewdefs.php')) {
|
||||
|
||||
//Go through all connectors and get their mapping keys and merge them across each module
|
||||
$connectors = self::getConnectors($refresh);
|
||||
$modules_sources = self::getDisplayConfig();
|
||||
$view_defs = array();
|
||||
foreach($connectors as $id=>$ds) {
|
||||
|
||||
if(file_exists('custom/' . $ds['directory'] . '/mapping.php')) {
|
||||
require('custom/' . $ds['directory'] . '/mapping.php');
|
||||
} else if(file_exists($ds['directory'] . '/mapping.php')) {
|
||||
require($ds['directory'] . '/mapping.php');
|
||||
}
|
||||
|
||||
if(!empty($mapping['beans'])) {
|
||||
foreach($mapping['beans'] as $module=>$map) {
|
||||
if(!empty($modules_sources[$module][$id])) {
|
||||
if(!empty($view_defs['Connector']['MergeView'][$module])) {
|
||||
$view_defs['Connector']['MergeView'][$module] = array_merge($view_defs['Connector']['MergeView'][$module], array_flip($map));
|
||||
} else {
|
||||
$view_defs['Connector']['MergeView'][$module] = array_flip($map);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!empty($view_defs['Connector']['MergeView'])) {
|
||||
foreach($view_defs['Connector']['MergeView'] as $module=>$map) {
|
||||
$view_defs['Connector']['MergeView'][$module] = array_keys($view_defs['Connector']['MergeView'][$module]);
|
||||
}
|
||||
}
|
||||
|
||||
if(!file_exists('custom/modules/Connectors/metadata')) {
|
||||
mkdir_recursive('custom/modules/Connectors/metadata');
|
||||
}
|
||||
|
||||
if(!write_array_to_file('viewdefs', $view_defs, 'custom/modules/Connectors/metadata/mergeviewdefs.php')) {
|
||||
$GLOBALS['log']->fatal("Cannot write file custom/modules/Connectors/metadata/mergeviewdefs.php");
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
require('custom/modules/Connectors/metadata/mergeviewdefs.php');
|
||||
return $viewdefs;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getConnectors
|
||||
* Returns an Array of the connectors that have been loaded into the system
|
||||
* along with attributes pertaining to each connector.
|
||||
*
|
||||
* @param boolean $refresh boolean flag indicating whether or not to force rewriting the file; defaults to false
|
||||
* @returns mixed $connectors Array of the connector entries found
|
||||
*/
|
||||
public static function getConnectors(
|
||||
$refresh = false
|
||||
)
|
||||
{
|
||||
//define paths
|
||||
$src1 = 'modules/Connectors/connectors/sources';
|
||||
$src2 = 'custom/modules/Connectors/connectors/sources';
|
||||
$src3 = 'custom/modules/Connectors/metadata';
|
||||
$src4 = 'custom/modules/Connectors/metadata/connectors.php';
|
||||
|
||||
//if this is a templated environment, then use utilities to get the proper paths
|
||||
if(defined('TEMPLATE_URL')){
|
||||
$src1 = SugarTemplateUtilities::getFilePath($src1);
|
||||
$src2 = SugarTemplateUtilities::getFilePath($src2);
|
||||
$src3 = SugarTemplateUtilities::getFilePath($src3);
|
||||
$src4 = SugarTemplateUtilities::getFilePath($src4);
|
||||
}
|
||||
|
||||
if($refresh || !file_exists($src4)) {
|
||||
|
||||
$sources = array_merge(self::getSources($src1), self::getSources($src2));
|
||||
if(!file_exists($src3)) {
|
||||
mkdir_recursive($src3);
|
||||
}
|
||||
|
||||
if(!write_array_to_file('connectors', $sources, $src4)) {
|
||||
//Log error and return empty array
|
||||
$GLOBALS['log']->fatal("Cannot write sources to file");
|
||||
return array();
|
||||
}
|
||||
} //if
|
||||
|
||||
require($src4);
|
||||
return $connectors;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getSources
|
||||
* Returns an Array of source entries found under the given directory
|
||||
* @param String $directory The directory to search
|
||||
* @return mixed $sources An Array of source entries
|
||||
*/
|
||||
private static function getSources(
|
||||
$directory = 'modules/Connectors/connectors/sources'
|
||||
)
|
||||
{
|
||||
if(file_exists($directory)) {
|
||||
|
||||
$files = array();
|
||||
$files = findAllFiles($directory, $files, false, 'config\.php');
|
||||
$start = strrpos($directory, '/') == strlen($directory)-1 ? strlen($directory) : strlen($directory) + 1;
|
||||
$sources = array();
|
||||
$sources_ordering = array();
|
||||
foreach($files as $file) {
|
||||
require($file);
|
||||
$end = strrpos($file, '/') - $start;
|
||||
$source = array();
|
||||
$source['id'] = str_replace('/', '_', substr($file, $start, $end));
|
||||
$source['name'] = !empty($config['name']) ? $config['name'] : $source['id'];
|
||||
$source['enabled'] = true;
|
||||
$source['directory'] = $directory . '/' . str_replace('_', '/', $source['id']);
|
||||
$order = isset($config['order']) ? $config['order'] : 99; //default to end using 99 if no order set
|
||||
|
||||
$instance = ConnectorFactory::getInstance($source['id']);
|
||||
$mapping = $instance->getMapping();
|
||||
$modules = array();
|
||||
if(!empty($mapping['beans'])) {
|
||||
foreach($mapping['beans'] as $module=>$mapping_entry) {
|
||||
$modules[]=$module;
|
||||
}
|
||||
}
|
||||
$source['modules'] = $modules;
|
||||
$sources_ordering[$source['id']] = array('order'=>$order, 'source'=>$source);
|
||||
}
|
||||
|
||||
usort($sources_ordering, 'sources_sort_function');
|
||||
foreach($sources_ordering as $entry) {
|
||||
$sources[$entry['source']['id']] = $entry['source'];
|
||||
}
|
||||
return $sources;
|
||||
}
|
||||
return array();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getDisplayConfig
|
||||
*
|
||||
*/
|
||||
public static function getDisplayConfig(
|
||||
$refresh = false
|
||||
)
|
||||
{
|
||||
if(!file_exists(CONNECTOR_DISPLAY_CONFIG_FILE) || $refresh) {
|
||||
$sources = self::getConnectors();
|
||||
$modules_sources = array();
|
||||
|
||||
//Make the directory for the config file
|
||||
if(!file_exists('custom/modules/Connectors/metadata')) {
|
||||
mkdir_recursive('custom/modules/Connectors/metadata');
|
||||
}
|
||||
|
||||
if(!write_array_to_file('modules_sources', $modules_sources, CONNECTOR_DISPLAY_CONFIG_FILE)) {
|
||||
//Log error and return empty array
|
||||
$GLOBALS['log']->fatal("Cannot write \$modules_sources to " . CONNECTOR_DISPLAY_CONFIG_FILE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
require(CONNECTOR_DISPLAY_CONFIG_FILE);
|
||||
return $modules_sources;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getModuleConnectors
|
||||
*
|
||||
* @param String $module the module to get the connectors for
|
||||
* @param mixed $connectors Array of connectors mapped to the module or empty if none
|
||||
* @return unknown
|
||||
*/
|
||||
public static function getModuleConnectors(
|
||||
$module
|
||||
)
|
||||
{
|
||||
$modules_sources = self::getDisplayConfig();
|
||||
if(!empty($modules_sources) && !empty($modules_sources[$module])){
|
||||
$sources = array();
|
||||
foreach($modules_sources[$module] as $index => $id){
|
||||
$sources[$id] = self::getConnector($id);
|
||||
}
|
||||
return $sources;
|
||||
}else{
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* isModuleEnabled
|
||||
* Given a module name, checks to see if the module is enabled to be serviced by the connector module
|
||||
* @param String $module String name of the module
|
||||
* @return boolean $enabled boolean value indicating whether or not the module is enabled to be serviced by the connector module
|
||||
*/
|
||||
public static function isModuleEnabled(
|
||||
$module
|
||||
)
|
||||
{
|
||||
$modules_sources = self::getDisplayConfig();
|
||||
return !empty($modules_sources) && !empty($modules_sources[$module]) ? true : false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* isSourceEnabled
|
||||
* Given a source id, checks to see if the source is enabled for at least one module
|
||||
* @param String $source String name of the source
|
||||
* @return boolean $enabled boolean value indicating whether or not the source is displayed in at least one module
|
||||
*/
|
||||
public static function isSourceEnabled(
|
||||
$source
|
||||
)
|
||||
{
|
||||
$modules_sources = self::getDisplayConfig();
|
||||
foreach($modules_sources as $module=>$mapping) {
|
||||
foreach($mapping as $s) {
|
||||
if($s == $source) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* When a module has all of the sources removed from it we do not properly remove it from the viewdefs. This function
|
||||
* will handle that.
|
||||
*
|
||||
* @param String $module - the module in question
|
||||
*/
|
||||
public static function cleanMetaDataFile(
|
||||
$module
|
||||
)
|
||||
{
|
||||
$metadata_file = file_exists("custom/modules/{$module}/metadata/detailviewdefs.php") ? "custom/modules/{$module}/metadata/detailviewdefs.php" : "modules/{$module}/metadata/detailviewdefs.php";
|
||||
require($metadata_file);
|
||||
|
||||
$insertConnectorButton = true;
|
||||
|
||||
|
||||
|
||||
|
||||
self::removeHoverField($viewdefs, $module);
|
||||
|
||||
//Make the directory for the metadata file
|
||||
if(!file_exists("custom/modules/{$module}/metadata")) {
|
||||
mkdir_recursive("custom/modules/{$module}/metadata");
|
||||
}
|
||||
|
||||
if(!write_array_to_file('viewdefs', $viewdefs, "custom/modules/{$module}/metadata/detailviewdefs.php")) {
|
||||
$GLOBALS['log']->fatal("Cannot update file custom/modules/{$module}/metadata/detailviewdefs.php");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(file_exists("{$GLOBALS['sugar_config']['cache_dir']}modules/{$module}/DetailView.tpl") && !unlink("{$GLOBALS['sugar_config']['cache_dir']}modules/{$module}/DetailView.tpl")) {
|
||||
$GLOBALS['log']->fatal("Cannot delete file {$GLOBALS['sugar_config']['cache_dir']}modules/{$module}/DetailView.tpl");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* updateMetaDataFiles
|
||||
* This method updates the metadata files (detailviewdefs.php) according to the settings in display_config.php
|
||||
* @return $result boolean value indicating whether or not the method successfully completed.
|
||||
*/
|
||||
public static function updateMetaDataFiles()
|
||||
{
|
||||
if(file_exists(CONNECTOR_DISPLAY_CONFIG_FILE)) {
|
||||
$modules_sources = array();
|
||||
|
||||
require(CONNECTOR_DISPLAY_CONFIG_FILE);
|
||||
|
||||
$GLOBALS['log']->debug(var_export($modules_sources, true));
|
||||
if(!empty($modules_sources)) {
|
||||
foreach($modules_sources as $module=>$mapping) {
|
||||
$metadata_file = file_exists("custom/modules/{$module}/metadata/detailviewdefs.php") ? "custom/modules/{$module}/metadata/detailviewdefs.php" : "modules/{$module}/metadata/detailviewdefs.php";
|
||||
|
||||
|
||||
$viewdefs = array();
|
||||
|
||||
require($metadata_file);
|
||||
|
||||
$insertConnectorButton = true;
|
||||
|
||||
|
||||
|
||||
|
||||
self::removeHoverField($viewdefs, $module);
|
||||
|
||||
//Insert the hover field if available
|
||||
if(!empty($mapping)) {
|
||||
|
||||
require_once('include/connectors/sources/SourceFactory.php');
|
||||
require_once('include/connectors/formatters/FormatterFactory.php');
|
||||
$shown_formatters = array();
|
||||
foreach($mapping as $id) {
|
||||
$source = SourceFactory::getSource($id, false);
|
||||
if($source->isEnabledInHover() && $source->isRequiredConfigFieldsForButtonSet()) {
|
||||
$shown_formatters[$id] = FormatterFactory::getInstance($id);
|
||||
}
|
||||
}
|
||||
|
||||
//Now we have to decide which field to put it on... use the first one for now
|
||||
if(!empty($shown_formatters)) {
|
||||
|
||||
foreach($shown_formatters as $id=>$formatter) {
|
||||
$added_field = false;
|
||||
$formatter_mapping = $formatter->getSourceMapping();
|
||||
|
||||
$source = $formatter->getComponent()->getSource();
|
||||
//go through the mapping and add the hover to every field define in the mapping
|
||||
//1) check for hover fields
|
||||
$hover_fields = $source->getFieldsWithParams('hover', true);
|
||||
|
||||
foreach($hover_fields as $key => $def){
|
||||
if(!empty($formatter_mapping['beans'][$module][$key])){
|
||||
$added_field = self::setHoverField($viewdefs, $module, $formatter_mapping['beans'][$module][$key], $id);
|
||||
}
|
||||
}
|
||||
|
||||
//2) check for first mapping field
|
||||
if(!$added_field && !empty($formatter_mapping['beans'][$module])) {
|
||||
foreach($formatter_mapping['beans'][$module] as $key => $val){
|
||||
$added_field = self::setHoverField($viewdefs, $module, $val, $id);
|
||||
if($added_field){
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} //foreach
|
||||
|
||||
|
||||
|
||||
//Log an error message
|
||||
if(!$added_field) {
|
||||
$GLOBALS['log']->fatal("Unable to place hover field link on metadata for module {$module}");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Make the directory for the metadata file
|
||||
if(!file_exists("custom/modules/{$module}/metadata")) {
|
||||
mkdir_recursive("custom/modules/{$module}/metadata");
|
||||
}
|
||||
|
||||
if(!write_array_to_file('viewdefs', $viewdefs, "custom/modules/{$module}/metadata/detailviewdefs.php")) {
|
||||
$GLOBALS['log']->fatal("Cannot update file custom/modules/{$module}/metadata/detailviewdefs.php");
|
||||
return false;
|
||||
}
|
||||
|
||||
if(file_exists("{$GLOBALS['sugar_config']['cache_dir']}modules/{$module}/DetailView.tpl") && !unlink("{$GLOBALS['sugar_config']['cache_dir']}modules/{$module}/DetailView.tpl")) {
|
||||
$GLOBALS['log']->fatal("Cannot delete file {$GLOBALS['sugar_config']['cache_dir']}modules/{$module}/DetailView.tpl");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function removeHoverField(
|
||||
&$viewdefs,
|
||||
$module
|
||||
)
|
||||
{
|
||||
require_once('include/SugarFields/Parsers/MetaParser.php');
|
||||
$metaParser = new MetaParser();
|
||||
if(!$metaParser->hasMultiplePanels($viewdefs[$module]['DetailView']['panels'])) {
|
||||
$keys = array_keys($viewdefs[$module]['DetailView']['panels']);
|
||||
if(!empty($keys) && count($keys) != 1) {
|
||||
$viewdefs[$module]['DetailView']['panels'] = array('default'=>$viewdefs[$module]['DetailView']['panels']);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($viewdefs[$module]['DetailView']['panels'] as $panel_id=>$panel) {
|
||||
foreach($panel as $row_id=>$row) {
|
||||
foreach($row as $field_id=>$field) {
|
||||
if(is_array($field) && !empty($field['displayParams']['enableConnectors'])) {
|
||||
|
||||
unset($field['displayParams']['enableConnectors']);
|
||||
unset($field['displayParams']['module']);
|
||||
unset($field['displayParams']['connectors']);
|
||||
$viewdefs[$module]['DetailView']['panels'][$panel_id][$row_id][$field_id] = $field;
|
||||
}
|
||||
} //foreach
|
||||
} //foreach
|
||||
} //foreach
|
||||
return false;
|
||||
}
|
||||
|
||||
public function setHoverField(
|
||||
&$viewdefs,
|
||||
$module,
|
||||
$hover_field,
|
||||
$source_id
|
||||
)
|
||||
{
|
||||
//Check for metadata files that aren't correctly created
|
||||
require_once('include/SugarFields/Parsers/MetaParser.php');
|
||||
$metaParser = new MetaParser();
|
||||
if(!$metaParser->hasMultiplePanels($viewdefs[$module]['DetailView']['panels'])) {
|
||||
$keys = array_keys($viewdefs[$module]['DetailView']['panels']);
|
||||
if(!empty($keys) && count($keys) != 1) {
|
||||
$viewdefs[$module]['DetailView']['panels'] = array('default'=>$viewdefs[$module]['DetailView']['panels']);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($viewdefs[$module]['DetailView']['panels'] as $panel_id=>$panel) {
|
||||
foreach($panel as $row_id=>$row) {
|
||||
foreach($row as $field_id=>$field) {
|
||||
$name = is_array($field) ? $field['name'] : $field;
|
||||
if($name == $hover_field) {
|
||||
if(is_array($field)) {
|
||||
if(!empty($viewdefs[$module]['DetailView']['panels'][$panel_id][$row_id][$field_id]['displayParams'])) {
|
||||
$newDisplayParam = $viewdefs[$module]['DetailView']['panels'][$panel_id][$row_id][$field_id]['displayParams'];
|
||||
$newDisplayParam['module'] = $module;
|
||||
$newDisplayParam['enableConnectors'] = true;
|
||||
if(!is_null($source_id) && !in_array($source_id, $newDisplayParam['connectors'])){
|
||||
$newDisplayParam['connectors'][] = $source_id;
|
||||
}
|
||||
$viewdefs[$module]['DetailView']['panels'][$panel_id][$row_id][$field_id]['displayParams'] = $newDisplayParam;
|
||||
} else {
|
||||
$field['displayParams'] = array('enableConnectors'=>true, 'module'=>$module, 'connectors' => array(0 => $source_id));
|
||||
$viewdefs[$module]['DetailView']['panels'][$panel_id][$row_id][$field_id] = $field;
|
||||
}
|
||||
|
||||
} else {
|
||||
$viewdefs[$module]['DetailView']['panels'][$panel_id][$row_id][$field_id] = array ('name'=>$field, 'displayParams'=>array('enableConnectors'=>true, 'module'=>$module, 'connectors' => array(0 => $source_id)));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* setDefaultHoverField
|
||||
* Sets the hover field to the first element in the detailview screen
|
||||
*
|
||||
* @param Array $viewdefs the metadata of the detailview
|
||||
* @param String $module the Module to which the hover field should be added to
|
||||
* @return boolean True if field was added; false otherwise
|
||||
*/
|
||||
private function setDefaultHoverField(
|
||||
&$viewdefs,
|
||||
$module,
|
||||
$source_id
|
||||
)
|
||||
{
|
||||
foreach($viewdefs[$module]['DetailView']['panels'] as $panel_id=>$panel) {
|
||||
foreach($panel as $row_id=>$row) {
|
||||
foreach($row as $field_id=>$field) {
|
||||
if(is_array($field)) {
|
||||
if(!empty($viewdefs[$module]['DetailView']['panels'][$panel_id][$row_id][$field_id]['displayParams'])) {
|
||||
$viewdefs[$module]['DetailView']['panels'][$panel_id][$row_id][$field_id]['displayParams']['enableConnectors'] = true;
|
||||
$viewdefs[$module]['DetailView']['panels'][$panel_id][$row_id][$field_id]['displayParams']['module'] = $module;
|
||||
if(!is_null($source_id) && !in_array($source_id, $viewdefs[$module]['DetailView']['panels'][$panel_id][$row_id][$field_id]['displayParams']['connectors'])){
|
||||
$viewdefs[$module]['DetailView']['panels'][$panel_id][$row_id][$field_id]['displayParams']['connectors'][] = $source_id;
|
||||
}
|
||||
} else {
|
||||
$field['displayParams'] = array('enableConnectors'=>true, 'module'=>$module, 'connectors' => array(0 => $source_id));
|
||||
$viewdefs[$module]['DetailView']['panels'][$panel_id][$row_id][$field_id] = $field;
|
||||
}
|
||||
} else {
|
||||
$viewdefs[$module]['DetailView']['panels'][$panel_id][$row_id][$field_id] = array ('name'=>$field, 'displayParams'=>array('enableConnectors'=>true, 'module'=>$module, 'connectors' => array(0 => $source_id)));
|
||||
}
|
||||
return true;
|
||||
} //foreach
|
||||
} //foreach
|
||||
} //foreach
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getConnectorButtonScript
|
||||
* This method builds the HTML code for the hover link field
|
||||
*
|
||||
* @param mixed $displayParams Array value of display parameters passed from the SugarField code
|
||||
* @param mixed $smarty The Smarty object from the calling smarty code
|
||||
* @return String $code The HTML code for the hover link
|
||||
*/
|
||||
public static function getConnectorButtonScript(
|
||||
$displayParams,
|
||||
$smarty
|
||||
)
|
||||
{
|
||||
$module = $displayParams['module'];
|
||||
require_once('include/connectors/utils/ConnectorUtils.php');
|
||||
$modules_sources = self::getDisplayConfig();
|
||||
global $current_language, $app_strings;
|
||||
$mod_strings = return_module_language($current_language, 'Connectors');
|
||||
$menuParams = 'var menuParams = "';
|
||||
$shown_sources = array();
|
||||
if(!empty($module) && !empty($displayParams['connectors'])) {
|
||||
foreach($displayParams['connectors'] as $id) {
|
||||
if(!empty($modules_sources[$module]) && in_array($id, $modules_sources[$module])){
|
||||
$shown_sources[] = $id;
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($shown_sources)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
require_once('include/connectors/formatters/FormatterFactory.php');
|
||||
$code = '';
|
||||
|
||||
//If there is only one source, just show the icon or some standalone view
|
||||
if(count($shown_sources) == 1) {
|
||||
$formatter = FormatterFactory::getInstance($shown_sources[0]);
|
||||
$formatter->setModule($module);
|
||||
$formatter->setSmarty($smarty);
|
||||
$formatter_code = $formatter->getDetailViewFormat();
|
||||
if(!empty($formatter_code)) {
|
||||
$iconFilePath = $formatter->getIconFilePath();
|
||||
$iconFilePath = empty($iconFilePath) ? 'themes/default/images/icon_Connectors.gif' : $iconFilePath;
|
||||
|
||||
$code = '<img id="dswidget_img" border="0" src="' . $iconFilePath .'" alt="' . $shown_sources[0] .'" onmouseover="show_' . $shown_sources[0] . '(event);">';
|
||||
$code .= "<link rel='stylesheet' type='text/css' href='include/javascript/yui/build/container/assets/container.css'>";
|
||||
$code .= "<script type='text/javascript' src='{sugar_getjspath file='include/connectors/formatters/default/company_detail.js'}'></script>";
|
||||
$code .= $formatter->getDetailViewFormat();
|
||||
$code .= $formatter_code;
|
||||
}
|
||||
return $code;
|
||||
} else {
|
||||
|
||||
$formatterCode = '';
|
||||
$sourcesDisplayed = 0;
|
||||
$singleIcon = '';
|
||||
foreach($shown_sources as $id) {
|
||||
$formatter = FormatterFactory::getInstance($id);
|
||||
$formatter->setModule($module);
|
||||
$formatter->setSmarty($smarty);
|
||||
$buttonCode = $formatter->getDetailViewFormat();
|
||||
if(!empty($buttonCode)) {
|
||||
$sourcesDisplayed++;
|
||||
$singleIcon = $formatter->getIconFilePath();
|
||||
$source = SourceFactory::getSource($id);
|
||||
$config = $source->getConfig();
|
||||
$name = !empty($config['name']) ? $config['name'] : $id;
|
||||
//Create the menu item to call show_[source id] method in javascript
|
||||
$menuParams .= '<a href=\'#\' style=\'width:150px\' class=\'menuItem\' onmouseover=\'hiliteItem(this,\"yes\");\' onmouseout=\'unhiliteItem(this);\' onclick=\'show_' . $id . '(event);\'>' . $name . '</a>';
|
||||
$formatterCode .= $buttonCode;
|
||||
}
|
||||
} //for
|
||||
|
||||
if(!empty($formatterCode)) {
|
||||
if($sourcesDisplayed > 1) {
|
||||
$dswidget_img = SugarThemeRegistry::current()->getImageURL('MoreDetail.png');
|
||||
$code = '<img id="dswidget_img" src="'.$dswidget_img.'" width="8" height="7" border="0" alt="connectors_popups" onmouseover="return showConnectorMenu2();" onmouseout="return nd(1000);">';
|
||||
} else {
|
||||
$dswidget_img = SugarThemeRegistry::current()->getImageURL('icon_Connectors.gif');
|
||||
$singleIcon = empty($singleIcon) ? $dswidget_img : $singleIcon;
|
||||
$code = '<img id="dswidget_img" border="0" src="' . $singleIcon . '" alt="connectors_popups" onmouseover="return showConnectorMenu2();" onmouseout="return nd(1000);">';
|
||||
}
|
||||
$code .= "{overlib_includes}\n";
|
||||
$code .= "<link rel='stylesheet' type='text/css' href='include/javascript/yui/build/container/assets/container.css'>\n";
|
||||
$code .= "<script type='text/javascript' src='{sugar_getjspath file='include/connectors/formatters/default/company_detail.js'}'></script>\n";
|
||||
$code .= "<script type='text/javascript'>\n";
|
||||
$code .= "function showConnectorMenu2() {literal} { {/literal}\n";
|
||||
|
||||
$menuParams .= '";';
|
||||
$code .= $menuParams . "\n";
|
||||
$code .= "return overlib(menuParams, CENTER, STICKY, MOUSEOFF, 3000, WIDTH, 110, FGCLASS, 'olOptionsFgClass', CGCLASS, 'olOptionsCgClass', BGCLASS, 'olBgClass', TEXTFONTCLASS, 'olFontClass', CAPTIONFONTCLASS, 'olOptionsCapFontClass', CLOSEFONTCLASS, 'olOptionsCloseFontClass');\n";
|
||||
$code .= "{literal} } {/literal}\n";
|
||||
$code .= "</script>\n";
|
||||
$code .= $formatterCode;
|
||||
}
|
||||
return $code;
|
||||
} //if-else
|
||||
} //if
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* getConnectorStrings
|
||||
* This method returns the language Strings for a given connector instance
|
||||
*
|
||||
* @param String $source_id String value of the connector id to retrive language strings for
|
||||
* @param String $language optional String value for the language to use (defaults to $GLOBALS['current_language'])
|
||||
*/
|
||||
public static function getConnectorStrings(
|
||||
$source_id,
|
||||
$language = ''
|
||||
)
|
||||
{
|
||||
$lang = empty($language) ? $GLOBALS['current_language'] : $language;
|
||||
$lang .= '.lang.php';
|
||||
$dir = str_replace('_', '/', $source_id);
|
||||
if(file_exists("custom/modules/Connectors/connectors/sources/{$dir}/language/{$lang}")) {
|
||||
require("custom/modules/Connectors/connectors/sources/{$dir}/language/{$lang}");
|
||||
return !empty($connector_strings) ? $connector_strings : array();
|
||||
} else if(file_exists("modules/Connectors/connectors/sources/{$dir}/language/{$lang}")){
|
||||
require("modules/Connectors/connectors/sources/{$dir}/language/{$lang}");
|
||||
return !empty($connector_strings) ? $connector_strings : array();
|
||||
} else {
|
||||
$GLOBALS['log']->error("Unable to locate language string file for source {$source_id}");
|
||||
return array();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* installSource
|
||||
* Install the name of the source (called from ModuleInstaller.php). Modifies the files in the custom
|
||||
* directory to add the new source in.
|
||||
*
|
||||
* @param String $source String value of the id of the connector to install
|
||||
* @return boolean $result boolean value indicating whether or not connector was installed
|
||||
*/
|
||||
public static function installSource(
|
||||
$source
|
||||
)
|
||||
{
|
||||
if(empty($source)) {
|
||||
return false;
|
||||
}
|
||||
//Add the source to the connectors.php file
|
||||
self::getConnectors(true);
|
||||
|
||||
//Get the display config file
|
||||
self::getDisplayConfig();
|
||||
//Update the display_config.php file to show this new source
|
||||
$modules_sources = array();
|
||||
require(CONNECTOR_DISPLAY_CONFIG_FILE);
|
||||
foreach($modules_sources as $module=>$mapping) {
|
||||
|
||||
foreach($mapping as $id=>$src) {
|
||||
if($src == $source) {
|
||||
unset($modules_sources[$module][$id]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Make the directory for the config file
|
||||
if(!file_exists('custom/modules/Connectors/metadata')) {
|
||||
mkdir_recursive('custom/modules/Connectors/metadata');
|
||||
}
|
||||
|
||||
if(!write_array_to_file('modules_sources', $modules_sources, CONNECTOR_DISPLAY_CONFIG_FILE)) {
|
||||
//Log error and return empty array
|
||||
$GLOBALS['log']->fatal("Cannot write \$modules_sources to " . CONNECTOR_DISPLAY_CONFIG_FILE);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* uninstallSource
|
||||
*
|
||||
* @param String $source String value of the id of the connector to un-install
|
||||
* @return boolean $result boolean value indicating whether or not connector was un-installed
|
||||
*/
|
||||
public static function uninstallSource(
|
||||
$source
|
||||
)
|
||||
{
|
||||
if(empty($source)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
//Remove the source from the connectors.php file
|
||||
self::getConnectors(true);
|
||||
|
||||
//Update the display_config.php file to remove this source
|
||||
$modules_sources = array();
|
||||
require(CONNECTOR_DISPLAY_CONFIG_FILE);
|
||||
foreach($modules_sources as $module=>$mapping) {
|
||||
foreach($mapping as $id=>$src) {
|
||||
if($src == $source) {
|
||||
unset($modules_sources[$module][$id]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Make the directory for the config file
|
||||
if(!file_exists('custom/modules/Connectors/metadata')) {
|
||||
mkdir_recursive('custom/modules/Connectors/metadata');
|
||||
}
|
||||
|
||||
if(!write_array_to_file('modules_sources', $modules_sources, CONNECTOR_DISPLAY_CONFIG_FILE)) {
|
||||
//Log error and return empty array
|
||||
$GLOBALS['log']->fatal("Cannot write \$modules_sources to " . CONNECTOR_DISPLAY_CONFIG_FILE);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* hasWizardSourceEnabledForModule
|
||||
* This is a private method that returns a boolean value indicating whether or not at least one
|
||||
* source is enabled for a given module. By enabled we mean that the source has the neccessary
|
||||
* configuration properties set as determined by the isRequiredConfigFieldsForButtonSet method. In
|
||||
* addition, a check is made to ensure that it is a source that has been enabled for the wizard.
|
||||
*
|
||||
* @param String $module String value of module to check
|
||||
* @return boolean $enabled boolean value indicating whether or not module has at least one source enabled
|
||||
*/
|
||||
private static function hasWizardSourceEnabledForModule(
|
||||
$module = ''
|
||||
)
|
||||
{
|
||||
if(file_exists(CONNECTOR_DISPLAY_CONFIG_FILE)) {
|
||||
require_once('include/connectors/sources/SourceFactory.php');
|
||||
require(CONNECTOR_DISPLAY_CONFIG_FILE);
|
||||
if(!empty($modules_sources) && !empty($modules_sources[$module])) {
|
||||
foreach($modules_sources[$module] as $id) {
|
||||
$source = SourceFactory::getSource($id, false);
|
||||
if(!is_null($source) && $source->isEnabledInWizard() && $source->isRequiredConfigFieldsForButtonSet()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user