init
This commit is contained in:
154
include/utils/LogicHook.php
Executable file
154
include/utils/LogicHook.php
Executable file
@@ -0,0 +1,154 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* Predefined logic hooks
|
||||
* after_ui_frame
|
||||
* after_ui_footer
|
||||
* after_save
|
||||
* before_save
|
||||
* before_retrieve
|
||||
* after_retrieve
|
||||
* process_record
|
||||
* before_delete
|
||||
* after_delete
|
||||
* before_restore
|
||||
* after_restore
|
||||
* server_roundtrip
|
||||
* before_logout
|
||||
* after_logout
|
||||
* after_login
|
||||
* login_failed
|
||||
*
|
||||
*/
|
||||
class LogicHook{
|
||||
|
||||
var $bean = null;
|
||||
|
||||
function LogicHook(){
|
||||
}
|
||||
|
||||
/**
|
||||
* Static Function which returns and instance of LogicHook
|
||||
*
|
||||
* @return unknown
|
||||
*/
|
||||
function initialize(){
|
||||
if(empty($GLOBALS['logic_hook']))
|
||||
$GLOBALS['logic_hook'] = new LogicHook();
|
||||
return $GLOBALS['logic_hook'];
|
||||
}
|
||||
|
||||
function setBean(&$bean){
|
||||
$this->bean =& $bean;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provide a means for developers to create upgrade safe business logic hooks.
|
||||
* If the bean is null, then we assume this call was not made from a SugarBean Object and
|
||||
* therefore we do not pass it to the method call.
|
||||
*
|
||||
* @param string $module_dir
|
||||
* @param string $event
|
||||
* @param array $arguments
|
||||
* @param SugarBean $bean
|
||||
*/
|
||||
function call_custom_logic($module_dir, $event, $arguments = null){
|
||||
// declare the hook array variable, it will be defined in the included file.
|
||||
$hook_array = null;
|
||||
|
||||
if(!empty($module_dir)){
|
||||
// This will load an array of the hooks to process
|
||||
if(file_exists("custom/modules/$module_dir/logic_hooks.php")){
|
||||
$GLOBALS['log']->debug('Including module specific hook file for '.$module_dir);
|
||||
include("custom/modules/$module_dir/logic_hooks.php");
|
||||
$this->process_hooks($hook_array, $event, $arguments);
|
||||
$hook_array = null;
|
||||
}
|
||||
}
|
||||
// Now load the generic array if it exists.
|
||||
if(file_exists('custom/modules/logic_hooks.php')){
|
||||
$GLOBALS['log']->debug('Including generic hook file');
|
||||
include('custom/modules/logic_hooks.php');
|
||||
$this->process_hooks($hook_array, $event, $arguments);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This is called from call_custom_logic and actually performs the action as defined in the
|
||||
* logic hook. If the bean is null, then we assume this call was not made from a SugarBean Object and
|
||||
* therefore we do not pass it to the method call.
|
||||
*
|
||||
* @param array $hook_array
|
||||
* @param string $event
|
||||
* @param array $arguments
|
||||
* @param SugarBean $bean
|
||||
*/
|
||||
function process_hooks($hook_array, $event, $arguments){
|
||||
// Now iterate through the array for the appropriate hook
|
||||
if(!empty($hook_array[$event])){
|
||||
foreach($hook_array[$event] as $hook_details){
|
||||
if(!file_exists($hook_details[2])){
|
||||
$GLOBALS['log']->error('Unable to load custom logic file: '.$hook_details[2]);
|
||||
continue;
|
||||
}
|
||||
include_once($hook_details[2]);
|
||||
$hook_class = $hook_details[3];
|
||||
$hook_function = $hook_details[4];
|
||||
|
||||
// Make a static call to the function of the specified class
|
||||
//TODO Make a factory for these classes. Cache instances accross uses
|
||||
if($hook_class == $hook_function){
|
||||
$GLOBALS['log']->debug('Creating new instance of hook class '.$hook_class.' with parameters');
|
||||
if(!is_null($this->bean))
|
||||
$class = new $hook_class($this->bean, $event, $arguments);
|
||||
else
|
||||
$class = new $hook_class($event, $arguments);
|
||||
}else{
|
||||
$GLOBALS['log']->debug('Creating new instance of hook class '.$hook_class.' without parameters');
|
||||
$class = new $hook_class();
|
||||
if(!is_null($this->bean))
|
||||
$class->$hook_function($this->bean, $event, $arguments);
|
||||
else
|
||||
$class->$hook_function($event, $arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
85
include/utils/activity_utils.php
Executable file
85
include/utils/activity_utils.php
Executable file
@@ -0,0 +1,85 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
|
||||
function build_related_list_by_user_id($bean, $user_id,$where) {
|
||||
$bean_id_name = strtolower($bean->object_name).'_id';
|
||||
|
||||
$select = "SELECT {$bean->table_name}.* from {$bean->rel_users_table},{$bean->table_name} ";
|
||||
|
||||
$auto_where = ' WHERE ';
|
||||
if(!empty($where)) {
|
||||
$auto_where .= $where. ' AND ';
|
||||
}
|
||||
|
||||
$auto_where .= " {$bean->rel_users_table}.{$bean_id_name}={$bean->table_name}.id AND {$bean->rel_users_table}.user_id='{$user_id}' AND {$bean->table_name}.deleted=0 AND {$bean->rel_users_table}.deleted=0";
|
||||
|
||||
|
||||
$query = $select.$auto_where;
|
||||
|
||||
$result = $bean->db->query($query, true);
|
||||
|
||||
$list = array();
|
||||
|
||||
while($row = $bean->db->fetchByAssoc($result)) {
|
||||
foreach($bean->column_fields as $field) {
|
||||
if(isset($row[$field])) {
|
||||
$bean->$field = $row[$field];
|
||||
} else {
|
||||
$bean->$field = '';
|
||||
}
|
||||
}
|
||||
|
||||
$bean->processed_dates_times = array();
|
||||
$bean->check_date_relationships_load();
|
||||
$bean->fill_in_additional_detail_fields();
|
||||
|
||||
/**
|
||||
* PHP 5+ always treats objects as passed by reference
|
||||
* Need to clone it if we're using 5.0+
|
||||
* clone() not supported by 4.x
|
||||
*/
|
||||
if(version_compare(phpversion(), "5.0", ">=")) {
|
||||
$newBean = clone($bean);
|
||||
} else {
|
||||
$newBean = $bean;
|
||||
}
|
||||
$list[] = $newBean;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
?>
|
||||
284
include/utils/array_utils.php
Executable file
284
include/utils/array_utils.php
Executable file
@@ -0,0 +1,284 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
//to_string methods to get strings for values
|
||||
|
||||
// var_export gets rid of the empty values that we use to display None
|
||||
// thishelper function fixes that
|
||||
// *This is no longer the case in php 5. var_export will now preserve empty keys.
|
||||
function var_export_helper($tempArray) {
|
||||
return var_export($tempArray, true);
|
||||
}
|
||||
|
||||
|
||||
|
||||
//this function is used to overide a value in an array and returns the string code to write
|
||||
function override_value_to_string($array_name, $value_name, $value){
|
||||
$string = "\${$array_name}[". var_export($value_name, true). "] = ";
|
||||
$string .= var_export_helper($value,true);
|
||||
return $string . ";";
|
||||
}
|
||||
|
||||
function add_blank_option($options){
|
||||
if(is_array($options)) {
|
||||
if(!isset($options['']) && !isset($options['0'])) {
|
||||
$options = array_merge(array(''=>''), $options);
|
||||
}
|
||||
} else {
|
||||
$options = array(''=>'');
|
||||
}
|
||||
return $options;
|
||||
}
|
||||
|
||||
/*
|
||||
* Given an array and key names, return a string in the form of $array_name[$key_name[0]][$key_name[1]]... = $value recursively.
|
||||
* @params : $key_names - array of keys
|
||||
* $array_name- name of the array
|
||||
* $value -value of the array
|
||||
* $eval - evals the generated string if true, note that the array name must be in the global space!
|
||||
* @return : example - string $array_name['a']['b']['c'][.] = 'hello'
|
||||
*/
|
||||
function override_value_to_string_recursive($key_names, $array_name, $value, $eval=false){
|
||||
if ($eval) return eval( "\${$array_name}". override_recursive_helper($key_names, $array_name, $value));
|
||||
else return "\${$array_name}". override_recursive_helper($key_names, $array_name, $value);
|
||||
}
|
||||
|
||||
function override_recursive_helper($key_names, $array_name, $value){
|
||||
if( empty( $key_names ) )
|
||||
return "=".var_export_helper($value,true).";";
|
||||
else{
|
||||
$key = array_shift($key_names);
|
||||
return "[".var_export($key,true)."]". override_recursive_helper($key_names, $array_name,$value);
|
||||
}
|
||||
}
|
||||
|
||||
function override_value_to_string_recursive2($array_name, $value_name, $value, $save_empty = true) {
|
||||
if (is_array($value)) {
|
||||
$str = '';
|
||||
$newArrayName = $array_name . "['$value_name']";
|
||||
foreach($value as $key=>$val) {
|
||||
$str.= override_value_to_string_recursive2($newArrayName, $key, $val, $save_empty);
|
||||
}
|
||||
return $str;
|
||||
} else {
|
||||
if(!$save_empty && empty($value)){
|
||||
return;
|
||||
}else{
|
||||
return "\$$array_name" . "['$value_name'] = " . var_export($value, true) . ";\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will attempt to convert an object to an array.
|
||||
* Loops are not checked for so this function should be used with caution.
|
||||
*
|
||||
* @param $obj
|
||||
* @return array representation of $obj
|
||||
*/
|
||||
function object_to_array_recursive($obj)
|
||||
{
|
||||
if (!is_object($obj))
|
||||
return $obj;
|
||||
|
||||
$ret = get_object_vars($obj);
|
||||
foreach($ret as $key => $val)
|
||||
{
|
||||
if (is_object($val)) {
|
||||
$ret[$key] = object_to_array_recursive($val);
|
||||
}
|
||||
|
||||
}
|
||||
return $ret;
|
||||
}
|
||||
/**
|
||||
* This function returns an array of all the key=>value pairs in $array1
|
||||
* that are wither not present, or different in $array2.
|
||||
* If a key exists in $array2 but not $array1, it will not be reported.
|
||||
* Values which are arrays are traced further and reported only if thier is a difference
|
||||
* in one or more of thier children.
|
||||
*
|
||||
* @param array $array1, the array which contains all the key=>values you wish to check againts
|
||||
* @param array $array2, the array which
|
||||
* @param array $allowEmpty, will return the value if it is empty in $array1 and not in $array2,
|
||||
* otherwise empty values in $array1 are ignored.
|
||||
* @return array containing the differences between the two arrays
|
||||
*/
|
||||
function deepArrayDiff($array1, $array2, $allowEmpty = false) {
|
||||
$diff = array();
|
||||
foreach($array1 as $key=>$value) {
|
||||
if (is_array($value)) {
|
||||
if ((!isset($array2[$key]) || !is_array($array2[$key])) && (isset($value) || $allowEmpty)) {
|
||||
$diff[$key] = $value;
|
||||
} else {
|
||||
$value = deepArrayDiff($array1[$key], $array2[$key], $allowEmpty);
|
||||
if (!empty($value) || $allowEmpty)
|
||||
$diff[$key] = $value;
|
||||
}
|
||||
} else if ((!isset($array2[$key]) || $value != $array2[$key]) && (isset($value) || $allowEmpty)){
|
||||
$diff[$key] = $value;
|
||||
}
|
||||
}
|
||||
return $diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursivly set a value in an array, creating sub arrays as necessary
|
||||
*
|
||||
* @param unknown_type $array
|
||||
* @param unknown_type $key
|
||||
*/
|
||||
function setDeepArrayValue(&$array, $key, $value) {
|
||||
//if _ is at position zero, that is invalid.
|
||||
if (strrpos($key, "_")) {
|
||||
list ($key, $remkey) = explode('_', $key, 2);
|
||||
if (!isset($array[$key]) || !is_array($array[$key])) {
|
||||
$array[$key] = array();
|
||||
}
|
||||
setDeepArrayValue($array[$key], $remkey, $value);
|
||||
}
|
||||
else {
|
||||
$array[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This function iterates through the given arrays and combines the values of each key, to form one array
|
||||
// Returns FALSE if number of elements in the arrays do not match; otherwise, returns merged array
|
||||
// Example: array("a", "b", "c") and array("x", "y", "z") are passed in; array("ax", "by", "cz") is returned
|
||||
function array_merge_values($arr1, $arr2) {
|
||||
if (count($arr1) != count($arr2)) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($arr1); $i++) {
|
||||
$arr1[$i] .= $arr2[$i];
|
||||
}
|
||||
|
||||
return $arr1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Search an array for a given value ignorning case sensitivity
|
||||
*
|
||||
* @param unknown_type $key
|
||||
* @param unknown_type $haystack
|
||||
*/
|
||||
function array_search_insensitive($key, $haystack)
|
||||
{
|
||||
if(!is_array($haystack))
|
||||
return FALSE;
|
||||
|
||||
$found = FALSE;
|
||||
foreach($haystack as $k => $v)
|
||||
{
|
||||
if(strtolower($v) == strtolower($key))
|
||||
{
|
||||
$found = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper around PHP's ArrayObject class that provides dot-notation recursive searching
|
||||
* for multi-dimensional arrays
|
||||
*/
|
||||
class SugarArray extends ArrayObject
|
||||
{
|
||||
/**
|
||||
* Return the value matching $key if exists, otherwise $default value
|
||||
*
|
||||
* This method uses dot notation to look through multi-dimensional arrays
|
||||
*
|
||||
* @param string $key key to look up
|
||||
* @param mixed $default value to return if $key does not exist
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key, $default = null) {
|
||||
return $this->_getFromSource($key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Provided as a convinience method for fetching a value within an existing
|
||||
* array without instantiating a SugarArray
|
||||
*
|
||||
* NOTE: This should only used where refactoring an array into a SugarArray
|
||||
* is unfeasible. This operation is more expensive than a direct
|
||||
* SugarArray as each time it creates and throws away a new instance
|
||||
*
|
||||
* @param array $haystack haystack
|
||||
* @param string $needle needle
|
||||
* @param mixed $default default value to return
|
||||
* @return mixed
|
||||
*/
|
||||
static public function staticGet($haystack, $needle, $default = null) {
|
||||
if (empty($haystack)) {
|
||||
return $default;
|
||||
}
|
||||
$array = new self($haystack);
|
||||
return $array->get($needle, $default);
|
||||
}
|
||||
|
||||
private function _getFromSource($key, $default) {
|
||||
if (strpos($key, '.') === false) {
|
||||
return isset($this[$key]) ? $this[$key] : $default;
|
||||
}
|
||||
|
||||
$exploded = explode('.', $key);
|
||||
$current_key = array_shift($exploded);
|
||||
return $this->_getRecursive($this->_getFromSource($current_key, $default), $exploded, $default);
|
||||
}
|
||||
|
||||
private function _getRecursive($raw_config, $children, $default) {
|
||||
if ($raw_config === $default) {
|
||||
return $default;
|
||||
} elseif (count($children) == 0) {
|
||||
return $raw_config;
|
||||
} else {
|
||||
$next_key = array_shift($children);
|
||||
return isset($raw_config[$next_key]) ?
|
||||
$this->_getRecursive($raw_config[$next_key], $children, $default) :
|
||||
$default;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
96
include/utils/autoloader.php
Executable file
96
include/utils/autoloader.php
Executable file
@@ -0,0 +1,96 @@
|
||||
<?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 SugarAutoLoader{
|
||||
|
||||
public static $map = array(
|
||||
'XTemplate'=>'XTemplate/xtpl.php',
|
||||
'ListView'=>'include/ListView/ListView.php',
|
||||
'Sugar_Smarty'=>'include/Sugar_Smarty.php',
|
||||
'Javascript'=>'include/javascript/javascript.php',
|
||||
|
||||
);
|
||||
|
||||
public static $noAutoLoad = array(
|
||||
'Tracker'=>true,
|
||||
);
|
||||
|
||||
public static $moduleMap = array();
|
||||
|
||||
public static function autoload($class)
|
||||
{
|
||||
$uclass = ucfirst($class);
|
||||
if(!empty(SugarAutoLoader::$noAutoLoad[$class])){
|
||||
return false;
|
||||
}
|
||||
if(!empty(SugarAutoLoader::$map[$uclass])){
|
||||
require_once(SugarAutoLoader::$map[$uclass]);
|
||||
return true;
|
||||
}
|
||||
|
||||
if(empty(SugarAutoLoader::$moduleMap)){
|
||||
if(isset($GLOBALS['beanFiles'])){
|
||||
SugarAutoLoader::$moduleMap = $GLOBALS['beanFiles'];
|
||||
}else{
|
||||
include('include/modules.php');
|
||||
SugarAutoLoader::$moduleMap = $beanFiles;
|
||||
}
|
||||
}
|
||||
if(!empty(SugarAutoLoader::$moduleMap[$class])){
|
||||
require_once(SugarAutoLoader::$moduleMap[$class]);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function loadAll(){
|
||||
foreach(SugarAutoLoader::$map as $class=>$file){
|
||||
require_once($file);
|
||||
}
|
||||
|
||||
if(isset($GLOBALS['beanFiles'])){
|
||||
$files = $GLOBALS['beanFiles'];
|
||||
}else{
|
||||
include('include/modules.php');
|
||||
$files = $beanList;
|
||||
}
|
||||
foreach(SugarAutoLoader::$map as $class=>$file){
|
||||
require_once($file);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
?>
|
||||
178
include/utils/db_utils.php
Executable file
178
include/utils/db_utils.php
Executable file
@@ -0,0 +1,178 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated use DBManager::convert() instead.
|
||||
*/
|
||||
function db_convert($string, $type, $additional_parameters=array(),$additional_parameters_oracle_only=array())
|
||||
{
|
||||
return $GLOBALS['db']->convert($string, $type, $additional_parameters, $additional_parameters_oracle_only);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use DBManager::concat() instead.
|
||||
*/
|
||||
function db_concat($table, $fields)
|
||||
{
|
||||
return $GLOBALS['db']->concat($table, $fields);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use DBManager::fromConvert() instead.
|
||||
*/
|
||||
function from_db_convert($string, $type)
|
||||
{
|
||||
return $GLOBALS['db']->fromConvert($string, $type);
|
||||
}
|
||||
|
||||
$toHTML = array(
|
||||
'"' => '"',
|
||||
'<' => '<',
|
||||
'>' => '>',
|
||||
"'" => ''',
|
||||
);
|
||||
$GLOBALS['toHTML_keys'] = array_keys($toHTML);
|
||||
$GLOBALS['toHTML_values'] = array_values($toHTML);
|
||||
|
||||
/**
|
||||
* Replaces specific characters with their HTML entity values
|
||||
* @param string $string String to check/replace
|
||||
* @param bool $encode Default true
|
||||
* @return string
|
||||
*
|
||||
* @todo Make this utilize the external caching mechanism after re-testing (see
|
||||
* log on r25320).
|
||||
*/
|
||||
function to_html($string, $encode=true){
|
||||
if (empty($string)) {
|
||||
return $string;
|
||||
}
|
||||
static $cache = array();
|
||||
global $toHTML;
|
||||
if (isset($cache['c'.$string])) {
|
||||
return $cache['c'.$string];
|
||||
}
|
||||
|
||||
$cache_key = 'c'.$string;
|
||||
|
||||
if($encode && is_string($string)){//$string = htmlentities($string, ENT_QUOTES);
|
||||
/*
|
||||
* cn: bug 13376 - handle ampersands separately
|
||||
* credit: ashimamura via bug portal
|
||||
*/
|
||||
//$string = str_replace("&", "&", $string);
|
||||
|
||||
if(is_array($toHTML)) { // cn: causing errors in i18n test suite ($toHTML is non-array)
|
||||
$string = str_replace(
|
||||
$GLOBALS['toHTML_keys'],
|
||||
$GLOBALS['toHTML_values'],
|
||||
$string
|
||||
);
|
||||
}
|
||||
}
|
||||
$cache[$cache_key] = $string;
|
||||
return $cache[$cache_key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces specific HTML entity values with the true characters
|
||||
* @param string $string String to check/replace
|
||||
* @param bool $encode Default true
|
||||
* @return string
|
||||
*/
|
||||
function from_html($string, $encode=true) {
|
||||
if (!is_string($string) || !$encode) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
global $toHTML;
|
||||
static $toHTML_values = null;
|
||||
static $toHTML_keys = null;
|
||||
static $cache = array();
|
||||
if (!isset($toHTML_values) || !empty($GLOBALS['from_html_cache_clear'])) {
|
||||
$toHTML_values = array_values($toHTML);
|
||||
$toHTML_keys = array_keys($toHTML);
|
||||
}
|
||||
|
||||
// Bug 36261 - Decode & so we can handle double encoded entities
|
||||
$string = str_replace("&", "&", $string);
|
||||
|
||||
if (!isset($cache[$string])) {
|
||||
$cache[$string] = str_replace($toHTML_values, $toHTML_keys, $string);
|
||||
}
|
||||
return $cache[$string];
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* @todo this function is only used by one function ( run_upgrade_wizard_sql() ), which isn't
|
||||
* used either; trying kill this off
|
||||
*/
|
||||
function run_sql_file( $filename )
|
||||
{
|
||||
if( !is_file( $filename ) ){
|
||||
print( "Could not find file: $filename <br>" );
|
||||
return( false );
|
||||
}
|
||||
|
||||
|
||||
|
||||
$fh = sugar_fopen( $filename,'r' );
|
||||
$contents = fread( $fh, filesize($filename) );
|
||||
fclose( $fh );
|
||||
|
||||
$lastsemi = strrpos( $contents, ';') ;
|
||||
$contents = substr( $contents, 0, $lastsemi );
|
||||
$queries = explode( ';', $contents );
|
||||
$db = DBManagerFactory::getInstance();
|
||||
|
||||
foreach( $queries as $query ){
|
||||
if( !empty($query) ){
|
||||
if($db->dbType == 'oci8')
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->query( $query.';', true, "An error has occured while running.<br>" );
|
||||
}
|
||||
}
|
||||
}
|
||||
return( true );
|
||||
}
|
||||
|
||||
?>
|
||||
103
include/utils/encryption_utils.php
Executable file
103
include/utils/encryption_utils.php
Executable file
@@ -0,0 +1,103 @@
|
||||
<?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/Pear/Crypt_Blowfish/Blowfish.php');
|
||||
|
||||
function sugarEncode($key, $data){
|
||||
return base64_encode($data);
|
||||
}
|
||||
|
||||
|
||||
function sugarDecode($key, $encoded){
|
||||
$data = base64_decode($encoded);
|
||||
return $data;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
//// BLOWFISH
|
||||
/**
|
||||
* retrives the system's private key; will build one if not found, but anything encrypted before is gone...
|
||||
* @param string type
|
||||
* @return string key
|
||||
*/
|
||||
function blowfishGetKey($type) {
|
||||
$key = array();
|
||||
|
||||
$type = str_rot13($type);
|
||||
|
||||
$keyCache = "{$GLOBALS['sugar_config']['cache_dir']}blowfish/{$type}.php";
|
||||
|
||||
// build cache dir if needed
|
||||
if(!file_exists($GLOBALS['sugar_config']['cache_dir'].'blowfish')) {
|
||||
mkdir_recursive($GLOBALS['sugar_config']['cache_dir'].'blowfish');
|
||||
}
|
||||
|
||||
// get key from cache, or build if not exists
|
||||
if(file_exists($keyCache)) {
|
||||
include($keyCache);
|
||||
} else {
|
||||
// create a key
|
||||
$key[0] = create_guid();
|
||||
write_array_to_file('key', $key, $keyCache);
|
||||
}
|
||||
return $key[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses blowfish to encrypt data and base 64 encodes it. It stores the iv as part of the data
|
||||
* @param STRING key - key to base encoding off of
|
||||
* @param STRING data - string to be encrypted and encoded
|
||||
* @return string
|
||||
*/
|
||||
function blowfishEncode($key, $data){
|
||||
$bf = new Crypt_Blowfish($key);
|
||||
$encrypted = $bf->encrypt($data);
|
||||
return base64_encode($encrypted);
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses blowfish to decode data assumes data has been base64 encoded with the iv stored as part of the data
|
||||
* @param STRING key - key to base decoding off of
|
||||
* @param STRING encoded base64 encoded blowfish encrypted data
|
||||
* @return string
|
||||
*/
|
||||
function blowfishDecode($key, $encoded){
|
||||
$data = base64_decode($encoded);
|
||||
$bf = new Crypt_Blowfish($key);
|
||||
return trim($bf->decrypt($data));
|
||||
}
|
||||
|
||||
?>
|
||||
242
include/utils/external_cache.php
Executable file
242
include/utils/external_cache.php
Executable file
@@ -0,0 +1,242 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
|
||||
/**##@+
|
||||
* Load require libraries
|
||||
*
|
||||
* @ignore
|
||||
*/
|
||||
require 'include/utils/external_cache/SugarCache.php';
|
||||
require 'include/utils/external_cache/SugarCache_Base.php';
|
||||
require 'include/utils/external_cache/SugarCache_ExternalAbstract.php';
|
||||
require 'include/utils/external_cache/SugarCache_APC.php';
|
||||
require 'include/utils/external_cache/SugarCache_Memcache.php';
|
||||
require 'include/utils/external_cache/SugarCache_Zend.php';
|
||||
require 'include/utils/external_cache/SugarCache_sMash.php';
|
||||
require 'include/utils/external_cache/SugarCache_Wincache.php';
|
||||
/**##@- */
|
||||
|
||||
/**
|
||||
* Internal -- Has the external cache been checked to determine if it is available and configured.
|
||||
*/
|
||||
$GLOBALS['external_cache_checked'] = false;
|
||||
|
||||
/**
|
||||
* Internal -- Is the external cache available. This setting is determined by checking for the availability
|
||||
* of the external cache functions. It can be overridden by adding a config variable
|
||||
* (external_cache_disabled=true).
|
||||
*/
|
||||
$GLOBALS['external_cache_enabled'] = false;
|
||||
|
||||
/**
|
||||
* Internal -- This is controlled by a config setting (external_cache_reset) that will update the cache
|
||||
* with new values, but not read from the cache.
|
||||
*/
|
||||
$GLOBALS['external_cache_overwrite'] = false;
|
||||
|
||||
/**
|
||||
* Internal -- The number of hits on the external out of process cache in this request
|
||||
*/
|
||||
$GLOBALS['external_cache_request_external_hits'] = 0;
|
||||
|
||||
/**
|
||||
* Internal -- The number of total requests to the external out of process cache in this request
|
||||
*/
|
||||
$GLOBALS['external_cache_request_external_total'] = 0;
|
||||
|
||||
/**
|
||||
* Internal -- The number of hits on the external local cache in this request
|
||||
*/
|
||||
$GLOBALS['external_cache_request_local_hits'] = 0;
|
||||
|
||||
/**
|
||||
* Internal -- The number of total requests to the external local cache in this request
|
||||
*/
|
||||
$GLOBALS['external_cache_request_local_total'] = 0;
|
||||
|
||||
/**
|
||||
* Internal -- The data structure for the local cache.
|
||||
*/
|
||||
$GLOBALS['cache_local_store'] = array();
|
||||
|
||||
/**
|
||||
* Internal -- The type of external store available.
|
||||
*/
|
||||
$GLOBALS['external_cache_type'] = null;
|
||||
|
||||
/**
|
||||
* The interval in seconds that an external cache entry is valid.
|
||||
*/
|
||||
define('EXTERNAL_CACHE_INTERVAL_SECONDS', 300 );
|
||||
|
||||
/**
|
||||
* This constant is provided as a convenience for users that want to store null values
|
||||
* in the cache. If your function frequently has null results that take a long time to
|
||||
* calculate, store those results in the cache. On retrieval, substitue the value you
|
||||
* stored for null.
|
||||
*/
|
||||
define('EXTERNAL_CACHE_NULL_VALUE', "SUGAR_CACHE_NULL_ZZ");
|
||||
|
||||
/**
|
||||
* Set this to true to see cache debugging messages in the end user UI.
|
||||
* This is a quick way to determine how well the cache is working and find out what
|
||||
* records are not being cached effectively.
|
||||
*/
|
||||
define('EXTERNAL_CACHE_DEBUG', false);
|
||||
|
||||
/**
|
||||
* Set this to true to validate that all items stored in the external cache are
|
||||
* identical when they are retrieved. This forces an immediate retrieve after each
|
||||
* store call to make sure the contents are reproduced exactly.
|
||||
*/
|
||||
define('EXTENRAL_CACHE_VALIDATE_STORES', false);
|
||||
|
||||
/**
|
||||
* This key is used to write to the external cache to validate that it is indeed working.
|
||||
* This prevents non-functioning caches from being detected as functional.
|
||||
*/
|
||||
define('EXTERNAL_CACHE_WORKING_CHECK_KEY', 'EXTERNAL_CACHE_WORKING_CHECK_KEY');
|
||||
|
||||
/**
|
||||
* Internal -- Determine if there is an external cache available for use.
|
||||
* Currently only Zend Platform is supported.
|
||||
*/
|
||||
function check_cache()
|
||||
{
|
||||
if(EXTERNAL_CACHE_DEBUG) SugarCache::log("Checking cache");
|
||||
|
||||
if($GLOBALS['external_cache_checked'] == false)
|
||||
{
|
||||
$GLOBALS['external_cache_checked'] = true;
|
||||
$GLOBALS['external_cache_object'] = SugarCache::discover();
|
||||
}
|
||||
|
||||
if(EXTERNAL_CACHE_DEBUG) SugarCache::log("Checking cache: " . var_export($GLOBALS['external_cache_enabled'], true));
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is called once an external cache has been identified to ensure that it is correctly
|
||||
* working.
|
||||
* @return true for success, false for failure.
|
||||
*/
|
||||
function sugar_cache_validate()
|
||||
{
|
||||
if($GLOBALS['external_cache_checked'] == false) {
|
||||
check_cache();
|
||||
}
|
||||
// should never be called
|
||||
$GLOBALS['external_cache_object']->init();
|
||||
return $GLOBALS['external_cache_object']->initialized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a key from cache. For the Zend Platform, a maximum age of 5 minutes is assumed.
|
||||
*
|
||||
* @param String $key -- The item to retrieve.
|
||||
* @return The item unserialized
|
||||
*/
|
||||
function sugar_cache_retrieve($key)
|
||||
{
|
||||
if($GLOBALS['external_cache_checked'] == false) {
|
||||
check_cache();
|
||||
}
|
||||
return $GLOBALS['external_cache_object']->get($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal -- This function actually retrieves information from the caches.
|
||||
* It is a helper function that provides that actual cache API abstraction.
|
||||
*
|
||||
* @param unknown_type $key
|
||||
* @return unknown
|
||||
* @deprecated
|
||||
* @see sugar_cache_retrieve
|
||||
*/
|
||||
function external_cache_retrieve_helper($key)
|
||||
{
|
||||
if($GLOBALS['external_cache_checked'] == false) {
|
||||
check_cache();
|
||||
}
|
||||
return sugar_cache_retrieve($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put a value in the cache under a key
|
||||
*
|
||||
* @param String $key -- Global namespace cache. Key for the data.
|
||||
* @param Serializable $value -- The value to store in the cache.
|
||||
*/
|
||||
function sugar_cache_put($key, $value)
|
||||
{
|
||||
if($GLOBALS['external_cache_checked'] == false) {
|
||||
check_cache();
|
||||
}
|
||||
$GLOBALS['external_cache_object']->set($key, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear a key from the cache. This is used to invalidate a single key.
|
||||
*
|
||||
* @param String $key -- Key from global namespace
|
||||
*/
|
||||
function sugar_cache_clear($key)
|
||||
{
|
||||
if($GLOBALS['external_cache_checked'] == false) {
|
||||
check_cache();
|
||||
}
|
||||
$GLOBALS['external_cache_object']->__unset($key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn off external caching for the rest of this round trip and for all round
|
||||
* trips for the next cache timeout. This function should be called when global arrays
|
||||
* are affected (studio, module loader, upgrade wizard, ... ) and it is not ok to
|
||||
* wait for the cache to expire in order to see the change.
|
||||
*/
|
||||
function sugar_cache_reset()
|
||||
{
|
||||
//@todo implement this in new code
|
||||
// Set a flag to clear the code.
|
||||
sugar_cache_put('EXTERNAL_CACHE_RESET', true);
|
||||
|
||||
// Clear the local cache
|
||||
$GLOBALS['cache_local_store'] = array();
|
||||
|
||||
// Disable the external cache for the rest of the round trip
|
||||
$GLOBALS['external_cache_enabled'] = false;
|
||||
}
|
||||
|
||||
220
include/utils/external_cache/SugarCache.php
Executable file
220
include/utils/external_cache/SugarCache.php
Executable file
@@ -0,0 +1,220 @@
|
||||
<?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 SugarCache
|
||||
{
|
||||
/**
|
||||
* Discover and return available cache adapter of false if nothing is available
|
||||
*
|
||||
* @return SugarCache_Abstract|false
|
||||
*/
|
||||
function discover()
|
||||
{
|
||||
// If the cache is manually disabled, turn it off.
|
||||
if(!empty($GLOBALS['sugar_config']['external_cache_disabled']) && true == $GLOBALS['sugar_config']['external_cache_disabled'])
|
||||
{
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("SugarCache::discover() -- caching explicitly disabled", 'fail');
|
||||
}
|
||||
$GLOBALS['external_cache_enabled'] = false;
|
||||
return SugarCache::factory('Base');
|
||||
}
|
||||
|
||||
// check for Zend caching
|
||||
if(function_exists("output_cache_get") && empty($GLOBALS['sugar_config']['external_cache_disabled_zend']))
|
||||
{
|
||||
$GLOBALS['external_cache_enabled'] = true;
|
||||
$GLOBALS['external_cache_type'] = "zend";
|
||||
$cache = SugarCache::factory('Zend');
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('Found Zend - attempting to use', 'pass');
|
||||
}
|
||||
}
|
||||
elseif (extension_loaded('memcache') && empty($GLOBALS['sugar_config']['external_cache_disabled_memcache'])) {
|
||||
$GLOBALS['external_cache_enabled'] = true;
|
||||
$GLOBALS['external_cache_type'] = 'memcache';
|
||||
$cache = SugarCache::factory('Memcache');
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('Found memcache - attempting to use', 'pass');
|
||||
}
|
||||
}
|
||||
elseif(function_exists("apc_store") && empty($GLOBALS['sugar_config']['external_cache_disabled_apc']))
|
||||
{
|
||||
$GLOBALS['external_cache_enabled'] = true;
|
||||
$GLOBALS['external_cache_type'] = "apc";
|
||||
$cache = SugarCache::factory('APC');
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('Found APC - attempting to use', 'pass');
|
||||
}
|
||||
}
|
||||
elseif(function_exists("wincache_ucache_set") && empty($GLOBALS['sugar_config']['external_cache_disabled_wincache']))
|
||||
{
|
||||
$GLOBALS['external_cache_enabled'] = true;
|
||||
$GLOBALS['external_cache_type'] = "wincache";
|
||||
$cache = SugarCache::factory('Wincache');
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('Found Wincache - attempting to use', 'pass');
|
||||
}
|
||||
}
|
||||
elseif(function_exists("zget") && empty($GLOBALS['sugar_config']['external_cache_disabled_smash']))
|
||||
{
|
||||
$GLOBALS['external_cache_enabled'] = true;
|
||||
$GLOBALS['external_cache_type'] = "smash";
|
||||
$cache = SugarCache::factory('sMash');
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('Found sMash - attempting to use', 'pass');
|
||||
}
|
||||
}
|
||||
// @todo memcache
|
||||
// @todo file cache as fallback
|
||||
else
|
||||
{
|
||||
// no cache available....return
|
||||
$GLOBALS['external_cache_enabled'] = true;
|
||||
$GLOBALS['external_cache_type'] = 'base-in-memory';
|
||||
$cache = SugarCache::factory('Base');
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('Found no caching solution - using base');
|
||||
}
|
||||
}
|
||||
|
||||
// Check the cache.
|
||||
if(!$cache->initialized)
|
||||
{
|
||||
// Validation failed. Turn off the external cache and return SugarCache_Base
|
||||
$GLOBALS['external_cache_enabled'] = false;
|
||||
if(EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("external cache validation check failed...tried cache {$GLOBALS['external_cache_type']}", 'fail');
|
||||
SugarCache::log('returning Base');
|
||||
}
|
||||
return SugarCache::factory('Base');
|
||||
}
|
||||
|
||||
// If the cache is being reset, turn it off for this round trip
|
||||
$value = '';
|
||||
if(isset($GLOBALS['sugar_config']) && isset($GLOBALS['sugar_config']['unique_key']))
|
||||
{
|
||||
$value = $cache->get($GLOBALS['sugar_config']['unique_key'].'EXTERNAL_CACHE_RESET');
|
||||
}
|
||||
if(!empty($value))
|
||||
{
|
||||
// We are in a cache reset, do not use the cache.
|
||||
$GLOBALS['external_cache_enabled'] = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add one to the external cache hits. This will keep the end user statistics simple.
|
||||
// All real checks suceeding will result in 100%. Otherwise people will be looking for
|
||||
// the one check that did not pass.
|
||||
$GLOBALS['external_cache_request_external_hits']++;
|
||||
}
|
||||
return $cache;
|
||||
}
|
||||
|
||||
function factory($type)
|
||||
{
|
||||
$class = 'SugarCache_' . $type;
|
||||
$cache = new $class();
|
||||
$cache->init();
|
||||
return $cache;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs basic logging for messages generated by the external caching mechanism
|
||||
*
|
||||
* Currently this only outputs directly to the screen as it's only used internally.
|
||||
*
|
||||
* There are five supported $type values:
|
||||
* neutral :: just a log message with information value
|
||||
* pass :: a pass that attention should be brought to
|
||||
* lightpass :: a pass without much consequence
|
||||
* fail :: a fail that attention should be brought to
|
||||
* lightfail :: a failure without much consequence, or one that might succeed later in
|
||||
* the execution chain
|
||||
*
|
||||
* @param string $msg Message to output. Note it will be filtered through htmlspecialchars()
|
||||
* @param string $type Type of message to output
|
||||
*/
|
||||
function log($msg, $type = 'neutral') {
|
||||
static $messages = array();
|
||||
static $valid_types = array(
|
||||
'neutral' => '',
|
||||
'pass' => '',
|
||||
'lightpass' => '',
|
||||
'fail' => '',
|
||||
'lightfail' => '',
|
||||
);
|
||||
|
||||
if (!isset($valid_types[$type])) {
|
||||
SugarCache::log("Invalid type provided: {$type}", 'fail');
|
||||
$type = 'neutral';
|
||||
}
|
||||
$session_id = session_id();
|
||||
if (empty($session_id)) {
|
||||
// add to stack of messages to output after the session starts so we don't kill the headers
|
||||
$messages[] = array(
|
||||
'message' => htmlspecialchars($msg),
|
||||
'type' => $type,
|
||||
);
|
||||
} else {
|
||||
if ($messages !== false) {
|
||||
// output base styles on first round trip - this doesn't worry that its
|
||||
// not in the proper place as its for debugging purposes only.
|
||||
echo "<style type='text/css'>"
|
||||
. "hr +span { padding:3px 5px; display:block; } "
|
||||
. "hr +.pass { background-color:green; color: white; } "
|
||||
. "hr +.lightpass { background-color: #CFC; color:black; }"
|
||||
. "hr +.fail { background-color:red; color:white; } "
|
||||
. "hr +.lightfail { background-color:#F99; color: black; }"
|
||||
. "hr +.neutral { background-color:#FFFFE0; color:black; } "
|
||||
. "</style>";
|
||||
}
|
||||
if ($messages !== false && count($messages) > 0) {
|
||||
// clear stack of messages;
|
||||
echo '<hr />Messages logged prior to session starting...<hr />', "\n";
|
||||
foreach ($messages as $id => $old_msg) {
|
||||
echo "<hr /><span class='{$old_msg['type']}'>{$id} -- {$old_msg['message']}</span><hr />\n";
|
||||
}
|
||||
echo "<hr />End of messages prior to session starting...<hr />\n";
|
||||
}
|
||||
$messages = false;
|
||||
$msg = htmlspecialchars($msg);
|
||||
echo "<hr /><span class='{$type}'>{$msg}</span><hr />\n";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
95
include/utils/external_cache/SugarCache_APC.php
Executable file
95
include/utils/external_cache/SugarCache_APC.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 SugarCache_APC extends SugarCache_ExternalAbstract
|
||||
{
|
||||
function init()
|
||||
{
|
||||
if (defined('SUGARCRM_IS_INSTALLING')) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('not initializing on Windows during an installation');
|
||||
}
|
||||
$this->initialized = false;
|
||||
return;
|
||||
}
|
||||
parent::init();
|
||||
}
|
||||
|
||||
function get($key)
|
||||
{
|
||||
$value = parent::get($key);
|
||||
if (!is_null($value)) {
|
||||
return $value;
|
||||
}
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('grabbing via apc_fetch(' . $this->_realKey($key) . ')');
|
||||
}
|
||||
return $this->_processGet(
|
||||
$key,
|
||||
apc_fetch(
|
||||
$this->_realKey($key)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function set($key, $value)
|
||||
{
|
||||
parent::set($key, $value);
|
||||
|
||||
// caching is turned off
|
||||
if(!$GLOBALS['external_cache_enabled']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$external_key = $this->_realKey($key);
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 3: Converting key ($key) to external key ($external_key)");
|
||||
}
|
||||
|
||||
apc_store($external_key, $value, $this->timeout);
|
||||
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 4: Added key to APC cache {$external_key} with value ($value) to be stored for ".EXTERNAL_CACHE_INTERVAL_SECONDS." seconds");
|
||||
}
|
||||
}
|
||||
|
||||
function __unset($key)
|
||||
{
|
||||
parent::__unset($key);
|
||||
apc_delete($this->_realKey($key));
|
||||
}
|
||||
}
|
||||
142
include/utils/external_cache/SugarCache_Base.php
Executable file
142
include/utils/external_cache/SugarCache_Base.php
Executable file
@@ -0,0 +1,142 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* The Base adapter only stores values in-memory.
|
||||
*
|
||||
* Cache adapters can extend this class in order to acheive local, in-memory
|
||||
* caching to reduce the number of round trips to outside caching mechanisms
|
||||
* during a single request.
|
||||
*
|
||||
*/
|
||||
class SugarCache_Base
|
||||
{
|
||||
/**
|
||||
* The status of this object
|
||||
* - null if init() has not been called
|
||||
* - false if init() failed
|
||||
* - true if init() succeeded
|
||||
*
|
||||
* @var null|bool
|
||||
* @access public
|
||||
*/
|
||||
var $initialized = null;
|
||||
|
||||
/**
|
||||
* Contains an in-memory cache of values in the cache
|
||||
*
|
||||
* @var array
|
||||
* @access protected
|
||||
*/
|
||||
var $_cache = array();
|
||||
|
||||
var $_my_class_name = '';
|
||||
|
||||
/**
|
||||
* Handle any initialization.
|
||||
*
|
||||
* @internal As shown here, at a minimum init() is responsible for flagging
|
||||
* the {@link $initialized} property to true on success.
|
||||
*/
|
||||
function init()
|
||||
{
|
||||
$this->initialized = true;
|
||||
$this->_my_class_name = strtolower(get_class($this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a given key/value pair within the cache
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
function set($key, $value)
|
||||
{
|
||||
if(EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 1: Adding key to {$GLOBALS['external_cache_type']} cache $key with value ($value)");
|
||||
}
|
||||
|
||||
if(empty($value)) {
|
||||
$value = EXTERNAL_CACHE_NULL_VALUE;
|
||||
}
|
||||
|
||||
if(EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 2: Adding key to {$GLOBALS['external_cache_type']} cache $key with value ($value)");
|
||||
}
|
||||
|
||||
$this->_cache[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the value of a given key
|
||||
*
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
function get($key)
|
||||
{
|
||||
$GLOBALS['external_cache_request_local_total']++;
|
||||
if (isset($this->_cache[$key])) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("BASE: found {$key}", 'lightpass');
|
||||
}
|
||||
$GLOBALS['external_cache_request_local_hits']++;
|
||||
return $this->_cache[$key];
|
||||
} else {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
$type = $this->_my_class_name == 'sugarcache_base' ? 'fail' : 'lightfail';
|
||||
SugarCache::log("BASE: unable to locate {$key}", $type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unset a given value
|
||||
*
|
||||
* @internal The term "unset" is a reserved word within PHP. This
|
||||
* opts for using the magic __unset() within PHP5 to enable
|
||||
* direct unset($cache->foo) calls. Due to BC considerations
|
||||
* with PHP 4, however, this method should be invoked
|
||||
* directly via $cache->__unset('foo');
|
||||
*
|
||||
* @param string $key
|
||||
*/
|
||||
function __unset($key)
|
||||
{
|
||||
unset($this->_cache[$key]);
|
||||
}
|
||||
}
|
||||
145
include/utils/external_cache/SugarCache_ExternalAbstract.php
Executable file
145
include/utils/external_cache/SugarCache_ExternalAbstract.php
Executable file
@@ -0,0 +1,145 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* @abstract
|
||||
*/
|
||||
class SugarCache_ExternalAbstract extends SugarCache_Base
|
||||
{
|
||||
/**
|
||||
* Use the parent of object to attempt to retrieve cache? i.e., use local
|
||||
* memory cache.
|
||||
*
|
||||
* @var bool
|
||||
* @access protected
|
||||
*/
|
||||
var $_use_parent = true;
|
||||
|
||||
/**
|
||||
* An internal value that can be used to adjust the length of a timeout.
|
||||
*
|
||||
* If not set prior to calling {@link init()}, this will default to the constant
|
||||
* EXTERNAL_CACHE_INTERVAL_SECONDS
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
var $timeout = null;
|
||||
|
||||
/**
|
||||
* Stores the cache name
|
||||
* @access private
|
||||
*/
|
||||
var $_name = '';
|
||||
|
||||
/**
|
||||
* Serves to initialize this cache
|
||||
*/
|
||||
function init()
|
||||
{
|
||||
if (empty($this->_timeout)) {
|
||||
$this->timeout = EXTERNAL_CACHE_INTERVAL_SECONDS;
|
||||
}
|
||||
|
||||
$this->_use_parent = false;
|
||||
|
||||
$value = $this->get(EXTERNAL_CACHE_WORKING_CHECK_KEY);
|
||||
if ($value != EXTERNAL_CACHE_WORKING_CHECK_KEY) {
|
||||
$this->set(
|
||||
EXTERNAL_CACHE_WORKING_CHECK_KEY,
|
||||
EXTERNAL_CACHE_WORKING_CHECK_KEY
|
||||
);
|
||||
$value = $this->get(EXTERNAL_CACHE_WORKING_CHECK_KEY);
|
||||
|
||||
// Clear the cache statistics after the test. This makes the statistics work out.
|
||||
$GLOBALS['external_cache_request_external_hits'] = 0;
|
||||
$GLOBALS['external_cache_request_external_total'] = 0;
|
||||
}
|
||||
|
||||
$this->_use_parent = true;
|
||||
$this->initialized = (EXTERNAL_CACHE_WORKING_CHECK_KEY == $value);
|
||||
|
||||
if (empty($this->_name)) {
|
||||
$this->_name = substr(get_class($this), 11);
|
||||
}
|
||||
}
|
||||
|
||||
function get($key)
|
||||
{
|
||||
if ($this->_use_parent && !is_null($value = parent::get($key))) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("{$this->_name}:: found {$key} in local memory cache");
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
if(!$GLOBALS['external_cache_enabled']) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("{$this->_name}:: caching disabled", 'fail');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
$GLOBALS['external_cache_request_external_total']++;
|
||||
|
||||
if(EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("{$this->_name}:: retrieving key from cache ($key)");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
function _realKey($key)
|
||||
{
|
||||
return $GLOBALS['sugar_config']['unique_key'] . $key;
|
||||
}
|
||||
|
||||
function _processGet($key, $value)
|
||||
{
|
||||
if (!empty($value)) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("{$this->_name}:: Retrieved from external cache: {$key}", 'pass');
|
||||
}
|
||||
$GLOBALS['external_cache_request_external_hits']++;
|
||||
$this->_cache[$key] = $value;
|
||||
return $this->_cache[$key];
|
||||
}
|
||||
if(EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("{$this->_name}:: External cache retrieve failed: $key", 'fail');
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
117
include/utils/external_cache/SugarCache_Memcache.php
Executable file
117
include/utils/external_cache/SugarCache_Memcache.php
Executable file
@@ -0,0 +1,117 @@
|
||||
<?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 SugarCache_Memcache extends SugarCache_ExternalAbstract
|
||||
{
|
||||
var $_memcache = null;
|
||||
var $_config = array(
|
||||
'host' => 'localhost',
|
||||
'port' => 11211,
|
||||
);
|
||||
|
||||
function SugarCache_Memcache()
|
||||
{
|
||||
$config = SugarConfig::getInstance();
|
||||
$this->_config['host'] = $config->get('external_cache.memcache.host', 'localhost');
|
||||
$this->_config['port'] = $config->get('external_cache.memcache.port', 11211);
|
||||
}
|
||||
|
||||
function init()
|
||||
{
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('initializing memcache');
|
||||
}
|
||||
$this->_memcache = new Memcache();
|
||||
$status = @$this->_memcache->connect(
|
||||
$this->_config['host'],
|
||||
$this->_config['port']
|
||||
);
|
||||
if (!$status) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('initialization of memcache failed', 'fail');
|
||||
}
|
||||
$this->initialized = false;
|
||||
return;
|
||||
}
|
||||
parent::init();
|
||||
}
|
||||
|
||||
function get($key)
|
||||
{
|
||||
$value = parent::get($key);
|
||||
if (!is_null($value)) {
|
||||
return $value;
|
||||
}
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('grabbing via Memcache::get(' . $this->_realKey($key) . ')');
|
||||
}
|
||||
return $this->_processGet(
|
||||
$key,
|
||||
$this->_memcache->get(
|
||||
$this->_realKey($key)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function set($key, $value)
|
||||
{
|
||||
parent::set($key, $value);
|
||||
|
||||
// caching is turned off
|
||||
if(!$GLOBALS['external_cache_enabled']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$external_key = $this->_realKey($key);
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 3: Converting key ($key) to external key ($external_key)");
|
||||
}
|
||||
|
||||
$this->_memcache->set($external_key, $value, $this->timeout);
|
||||
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 4: Added key to memcache cache {$external_key} with value ($value) to be stored for ".EXTERNAL_CACHE_INTERVAL_SECONDS." seconds");
|
||||
}
|
||||
}
|
||||
|
||||
function __unset($key)
|
||||
{
|
||||
parent::__unset($key);
|
||||
$this->_memcache->delete($this->_realKey($key));
|
||||
}
|
||||
}
|
||||
|
||||
95
include/utils/external_cache/SugarCache_Wincache.php
Executable file
95
include/utils/external_cache/SugarCache_Wincache.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 SugarCache_Wincache extends SugarCache_ExternalAbstract
|
||||
{
|
||||
function init()
|
||||
{
|
||||
if (defined('SUGARCRM_IS_INSTALLING')) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('not initializing on Windows during an installation');
|
||||
}
|
||||
$this->initialized = false;
|
||||
return;
|
||||
}
|
||||
parent::init();
|
||||
}
|
||||
|
||||
function get($key)
|
||||
{
|
||||
$value = parent::get($key);
|
||||
if (!is_null($value)) {
|
||||
return $value;
|
||||
}
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('grabbing via wincache_ucache_get(' . $this->_realKey($key) . ')');
|
||||
}
|
||||
return $this->_processGet(
|
||||
$key,
|
||||
wincache_ucache_get(
|
||||
$this->_realKey($key)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function set($key, $value)
|
||||
{
|
||||
parent::set($key, $value);
|
||||
|
||||
// caching is turned off
|
||||
if(!$GLOBALS['external_cache_enabled']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$external_key = $this->_realKey($key);
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 3: Converting key ($key) to external key ($external_key)");
|
||||
}
|
||||
|
||||
wincache_ucache_set($external_key, $value, $this->timeout);
|
||||
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 4: Added key to Wincache cache {$external_key} with value ($value) to be stored for ".EXTERNAL_CACHE_INTERVAL_SECONDS." seconds");
|
||||
}
|
||||
}
|
||||
|
||||
function __unset($key)
|
||||
{
|
||||
parent::__unset($key);
|
||||
wincache_ucache_delete($this->_realKey($key));
|
||||
}
|
||||
}
|
||||
86
include/utils/external_cache/SugarCache_Zend.php
Executable file
86
include/utils/external_cache/SugarCache_Zend.php
Executable file
@@ -0,0 +1,86 @@
|
||||
<?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 SugarCache_Zend extends SugarCache_ExternalAbstract
|
||||
{
|
||||
function get($key)
|
||||
{
|
||||
$value = parent::get($key);
|
||||
if (!is_null($value)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$raw_cache_value = output_cache_get(
|
||||
$this->_realKey($key),
|
||||
$this->timeout
|
||||
);
|
||||
$cache_value = is_string($raw_cache_value) ?
|
||||
unserialize($raw_cache_value) :
|
||||
$raw_cache_value;
|
||||
return $this->_processGet(
|
||||
$key,
|
||||
$cache_value
|
||||
);
|
||||
}
|
||||
|
||||
function set($key, $value)
|
||||
{
|
||||
parent::set($key, $value);
|
||||
|
||||
// caching is turned off
|
||||
if(!$GLOBALS['external_cache_enabled']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$external_key = $this->_realKey($key);
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 3: Converting key ($key) to external key ($external_key)");
|
||||
}
|
||||
|
||||
output_cache_put($external_key, serialize($value));
|
||||
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 4: Added key to Zend cache {$external_key} with value ($value) to be stored for ".EXTERNAL_CACHE_INTERVAL_SECONDS." seconds");
|
||||
}
|
||||
}
|
||||
|
||||
function __unset($key)
|
||||
{
|
||||
parent::__unset($key);
|
||||
output_cache_remove_key($this->_realKey($key));
|
||||
}
|
||||
}
|
||||
101
include/utils/external_cache/SugarCache_sMash.php
Executable file
101
include/utils/external_cache/SugarCache_sMash.php
Executable file
@@ -0,0 +1,101 @@
|
||||
<?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 SugarCache_sMash extends SugarCache_ExternalAbstract
|
||||
{
|
||||
function init()
|
||||
{
|
||||
if (defined('SUGARCRM_IS_INSTALLING')) {
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('not initializing on Windows during an installation');
|
||||
}
|
||||
$this->initialized = false;
|
||||
return;
|
||||
}
|
||||
parent::init();
|
||||
}
|
||||
|
||||
function get($key)
|
||||
{
|
||||
$value = parent::get($key);
|
||||
if (!is_null($value)) {
|
||||
return $value;
|
||||
}
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log('grabbing via zget(' . $this->_realKey($key) . ')');
|
||||
}
|
||||
return $this->_processGet(
|
||||
$key,
|
||||
zget(
|
||||
$this->_realKey($key)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function set($key, $value)
|
||||
{
|
||||
|
||||
parent::set($key, $value);
|
||||
|
||||
// caching is turned off
|
||||
if(!$GLOBALS['external_cache_enabled']) {
|
||||
return;
|
||||
}
|
||||
|
||||
$external_key = $this->_realKey($key);
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 3: Converting key ($key) to external key ($external_key)");
|
||||
}
|
||||
|
||||
zput($external_key, $value, $this->timeout);
|
||||
|
||||
if (EXTERNAL_CACHE_DEBUG) {
|
||||
SugarCache::log("Step 4: Added key to sMash cache {$external_key} with value ($value) to be stored for ".EXTERNAL_CACHE_INTERVAL_SECONDS." seconds");
|
||||
}
|
||||
}
|
||||
|
||||
function _realKey($key)
|
||||
{
|
||||
return '/tmp/'.$GLOBALS['sugar_config']['unique_key'] .'/'. $key;
|
||||
}
|
||||
|
||||
function __unset($key)
|
||||
{
|
||||
parent::__unset($key);
|
||||
zdelete($this->_realKey($key));
|
||||
}
|
||||
}
|
||||
343
include/utils/file_utils.php
Executable file
343
include/utils/file_utils.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".
|
||||
********************************************************************************/
|
||||
|
||||
require_once('include/utils/array_utils.php');
|
||||
require_once('include/utils/sugar_file_utils.php');
|
||||
|
||||
function clean_path( $path )
|
||||
{
|
||||
// clean directory/file path with a functional equivalent
|
||||
$appendpath = '';
|
||||
if ( is_windows() && strlen($path) >= 2 && $path[0].$path[1] == "\\\\" ) {
|
||||
$path = substr($path,2);
|
||||
$appendpath = "\\\\";
|
||||
}
|
||||
$path = str_replace( "\\", "/", $path );
|
||||
$path = str_replace( "//", "/", $path );
|
||||
$path = str_replace( "/./", "/", $path );
|
||||
return( $appendpath.$path );
|
||||
}
|
||||
|
||||
function create_cache_directory($file)
|
||||
{
|
||||
$paths = explode('/',$file);
|
||||
$dir = str_replace('/','',$GLOBALS['sugar_config']['cache_dir']);
|
||||
if(!file_exists($dir))
|
||||
{
|
||||
sugar_mkdir($dir, 0775);
|
||||
}
|
||||
for($i = 0; $i < sizeof($paths) - 1; $i++)
|
||||
{
|
||||
$dir .= '/' . $paths[$i];
|
||||
if(!file_exists($dir))
|
||||
{
|
||||
sugar_mkdir($dir, 0775);
|
||||
}
|
||||
}
|
||||
return $dir . '/'. $paths[sizeof($paths) - 1];
|
||||
}
|
||||
|
||||
function get_module_dir_list()
|
||||
{
|
||||
$modules = array();
|
||||
$path = 'modules';
|
||||
$d = dir($path);
|
||||
while($entry = $d->read())
|
||||
{
|
||||
if($entry != '..' && $entry != '.')
|
||||
{
|
||||
if(is_dir($path. '/'. $entry))
|
||||
{
|
||||
$modules[$entry] = $entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $modules;
|
||||
}
|
||||
|
||||
function mk_temp_dir( $base_dir, $prefix="" )
|
||||
{
|
||||
$temp_dir = tempnam( getcwd() .'/'. $base_dir, $prefix );
|
||||
if( !$temp_dir || !unlink( $temp_dir ) )
|
||||
{
|
||||
return( false );
|
||||
}
|
||||
|
||||
if( sugar_mkdir( $temp_dir ) ){
|
||||
return( $temp_dir );
|
||||
}
|
||||
|
||||
return( false );
|
||||
}
|
||||
|
||||
function remove_file_extension( $filename )
|
||||
{
|
||||
return( substr( $filename, 0, strrpos($filename, ".") ) );
|
||||
}
|
||||
|
||||
function write_array_to_file( $the_name, $the_array, $the_file, $mode="w", $header='' )
|
||||
{
|
||||
if(!empty($header) && ($mode != 'a' || !file_exists($the_file))){
|
||||
$the_string = $header;
|
||||
}else{
|
||||
$the_string = "<?php\n" .
|
||||
'// created: ' . date('Y-m-d H:i:s') . "\n";
|
||||
}
|
||||
$the_string .= "\$$the_name = " .
|
||||
var_export_helper( $the_array ) .
|
||||
";\n?>\n";
|
||||
|
||||
if( $fh = @sugar_fopen( $the_file, $mode ) )
|
||||
{
|
||||
fputs( $fh, $the_string);
|
||||
fclose( $fh );
|
||||
return( true );
|
||||
}
|
||||
else
|
||||
{
|
||||
return( false );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function write_encoded_file( $soap_result, $write_to_dir, $write_to_file="" )
|
||||
{
|
||||
// this function dies when encountering an error -- use with caution!
|
||||
// the path/file is returned upon success
|
||||
|
||||
|
||||
|
||||
if( $write_to_file == "" )
|
||||
{
|
||||
$write_to_file = $write_to_dir . "/" . $soap_result['filename'];
|
||||
}
|
||||
|
||||
$file = $soap_result['data'];
|
||||
$write_to_file = str_replace( "\\", "/", $write_to_file );
|
||||
|
||||
$dir_to_make = dirname( $write_to_file );
|
||||
if( !is_dir( $dir_to_make ) )
|
||||
{
|
||||
mkdir_recursive( $dir_to_make );
|
||||
}
|
||||
$fh = sugar_fopen( $write_to_file, "wb" );
|
||||
fwrite( $fh, base64_decode( $file ) );
|
||||
fclose( $fh );
|
||||
|
||||
if( md5_file( $write_to_file ) != $soap_result['md5'] )
|
||||
{
|
||||
die( "MD5 error after writing file $write_to_file" );
|
||||
}
|
||||
return( $write_to_file );
|
||||
}
|
||||
|
||||
function create_custom_directory($file)
|
||||
{
|
||||
$paths = explode('/',$file);
|
||||
$dir = 'custom';
|
||||
if(!file_exists($dir))
|
||||
{
|
||||
sugar_mkdir($dir, 0755);
|
||||
}
|
||||
for($i = 0; $i < sizeof($paths) - 1; $i++)
|
||||
{
|
||||
$dir .= '/' . $paths[$i];
|
||||
if(!file_exists($dir))
|
||||
{
|
||||
sugar_mkdir($dir, 0755);
|
||||
}
|
||||
}
|
||||
return $dir . '/'. $paths[sizeof($paths) - 1];
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will recursively generates md5s of files and returns an array of all md5s.
|
||||
*
|
||||
* @param $path The path of the root directory to scan - must end with '/'
|
||||
* @param $ignore_dirs array of filenames/directory names to ignore running md5 on - default 'cache' and 'upload'
|
||||
* @result $md5_array an array containing path as key and md5 as value
|
||||
*/
|
||||
function generateMD5array($path, $ignore_dirs = array('cache', 'upload'))
|
||||
{
|
||||
$dh = opendir($path);
|
||||
while (false !== ($filename = readdir($dh)))
|
||||
{
|
||||
$current_dir_content[] = $filename;
|
||||
}
|
||||
|
||||
// removes the ignored directories
|
||||
$current_dir_content = array_diff($current_dir_content, $ignore_dirs);
|
||||
|
||||
sort($current_dir_content);
|
||||
$md5_array = array();
|
||||
|
||||
foreach($current_dir_content as $file)
|
||||
{
|
||||
// make sure that it's not dir '.' or '..'
|
||||
if(strcmp($file, ".") && strcmp($file, ".."))
|
||||
{
|
||||
if(is_dir($path.$file))
|
||||
{
|
||||
// For testing purposes - uncomment to see all files and md5s
|
||||
//echo "<BR>Dir: ".$path.$file."<br>";
|
||||
//generateMD5array($path.$file."/");
|
||||
|
||||
$md5_array += generateMD5array($path.$file."/", $ignore_dirs);
|
||||
}
|
||||
else
|
||||
{
|
||||
// For testing purposes - uncomment to see all files and md5s
|
||||
//echo " File: ".$path.$file."<br>";
|
||||
//echo md5_file($path.$file)."<BR>";
|
||||
|
||||
$md5_array[$path.$file] = md5_file($path.$file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $md5_array;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to compare two directory structures and return the items in path_a that didn't match in path_b
|
||||
*
|
||||
* @param $path_a The path of the first root directory to scan - must end with '/'
|
||||
* @param $path_b The path of the second root directory to scan - must end with '/'
|
||||
* @param $ignore_dirs array of filenames/directory names to ignore running md5 on - default 'cache' and 'upload'
|
||||
* @result array containing all the md5s of everything in $path_a that didn't have a match in $path_b
|
||||
*/
|
||||
function md5DirCompare($path_a, $path_b, $ignore_dirs = array('cache', 'upload'))
|
||||
{
|
||||
$md5array_a = generateMD5array($path_a, $ignore_dirs);
|
||||
$md5array_b = generateMD5array($path_b, $ignore_dirs);
|
||||
|
||||
$result = array_diff($md5array_a, $md5array_b);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to retrieve all file names of matching pattern in a directory (and it's subdirectories)
|
||||
* example: getFiles($arr, './modules', '.+/EditView.php/'); // grabs all EditView.phps
|
||||
* @param array $arr return array to populate matches
|
||||
* @param string $dir directory to look in [ USE ./ in front of the $dir! ]
|
||||
* @param regex $pattern optional pattern to match against
|
||||
*/
|
||||
function getFiles(&$arr, $dir, $pattern = null) {
|
||||
if(!is_dir($dir))return;
|
||||
$d = dir($dir);
|
||||
while($e =$d->read()){
|
||||
if(substr($e, 0, 1) == '.')continue;
|
||||
$file = $dir . '/' . $e;
|
||||
if(is_dir($file)){
|
||||
getFiles($arr, $file, $pattern);
|
||||
}else{
|
||||
if(empty($pattern)) $arr[] = $file;
|
||||
else if(preg_match($pattern, $file))
|
||||
$arr[] = $file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to split up large files for download
|
||||
* used in download.php
|
||||
* @param string $filename
|
||||
* @param int $retbytes
|
||||
*/
|
||||
function readfile_chunked($filename,$retbytes=true)
|
||||
{
|
||||
$chunksize = 1*(1024*1024); // how many bytes per chunk
|
||||
$buffer = '';
|
||||
$cnt = 0;
|
||||
$handle = sugar_fopen($filename, 'rb');
|
||||
if ($handle === false)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
while (!feof($handle))
|
||||
{
|
||||
$buffer = fread($handle, $chunksize);
|
||||
echo $buffer;
|
||||
flush();
|
||||
if ($retbytes)
|
||||
{
|
||||
$cnt += strlen($buffer);
|
||||
}
|
||||
}
|
||||
$status = fclose($handle);
|
||||
if ($retbytes && $status)
|
||||
{
|
||||
return $cnt; // return num. bytes delivered like readfile() does.
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
/**
|
||||
* Renames a file. If $new_file already exists, it will first unlink it and then rename it.
|
||||
* used in SugarLogger.php
|
||||
* @param string $old_filename
|
||||
* @param string $new_filename
|
||||
*/
|
||||
function sugar_rename( $old_filename, $new_filename){
|
||||
if (empty($old_filename) || empty($new_filename)) return false;
|
||||
$success = false;
|
||||
if(file_exists($new_filename)) {
|
||||
unlink($new_filename);
|
||||
$success = rename($old_filename, $new_filename);
|
||||
}
|
||||
else {
|
||||
$success = rename($old_filename, $new_filename);
|
||||
}
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
function fileToHash($file){
|
||||
$hash = md5($file);
|
||||
$_SESSION['file2Hash'][$hash] = $file;
|
||||
return $hash;
|
||||
}
|
||||
|
||||
function hashToFile($hash){
|
||||
if(!empty($_SESSION['file2Hash'][$hash])){
|
||||
return $_SESSION['file2Hash'][$hash];
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
?>
|
||||
299
include/utils/layout_utils.php
Executable file
299
include/utils/layout_utils.php
Executable file
@@ -0,0 +1,299 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* Contains a variety of utility functions used to display UI components such as form headers and footers.
|
||||
*
|
||||
* @todo refactor out these functions into the base UI objects as indicated
|
||||
*/
|
||||
|
||||
/**
|
||||
* Create HTML to display formatted form title.
|
||||
*
|
||||
* @param $form_title string to display as the title in the header
|
||||
* @param $other_text string to next to the title. Typically used for form buttons.
|
||||
* @param $show_help boolean which determines if the print and help links are shown.
|
||||
* @return string HTML
|
||||
*/
|
||||
function get_form_header(
|
||||
$form_title,
|
||||
$other_text,
|
||||
$show_help
|
||||
)
|
||||
{
|
||||
global $sugar_version, $sugar_flavor, $server_unique_key, $current_language, $current_module, $current_action;
|
||||
global $app_strings;
|
||||
|
||||
$blankImageURL = SugarThemeRegistry::current()->getImageURL('blank.gif');
|
||||
$printImageURL = SugarThemeRegistry::current()->getImageURL("print.gif");
|
||||
$helpImageURL = SugarThemeRegistry::current()->getImageURL("help.gif");
|
||||
|
||||
$is_min_max = strpos($other_text,"_search.gif");
|
||||
if($is_min_max !== false)
|
||||
$form_title = "{$other_text} {$form_title}";
|
||||
|
||||
$the_form = <<<EOHTML
|
||||
<table width="100%" cellpadding="0" cellspacing="0" border="0" class="formHeader h3Row">
|
||||
<tr>
|
||||
<td nowrap><h3><span>{$form_title}</span></h3></td>
|
||||
EOHTML;
|
||||
|
||||
$keywords = array("/class=\"button\"/","/class='button'/","/class=button/","/<\/form>/");
|
||||
$match="";
|
||||
foreach ($keywords as $left)
|
||||
if (preg_match($left,$other_text))
|
||||
$match = true;
|
||||
|
||||
if ($other_text && $match) {
|
||||
$the_form .= <<<EOHTML
|
||||
<td colspan='10' width='100%'><IMG height='1' width='1' src='$blankImageURL' alt=''></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align='left' valign='middle' nowrap style='padding-bottom: 2px;'>$other_text</td>
|
||||
<td width='100%'><IMG height='1' width='1' src='$blankImageURL' alt=''></td>
|
||||
EOHTML;
|
||||
if ($show_help) {
|
||||
$the_form .= "<td align='right' nowrap>";
|
||||
if ($_REQUEST['action'] != "EditView") {
|
||||
$the_form .= <<<EOHTML
|
||||
<a href='index.php?{$GLOBALS['request_string']}' class='utilsLink'>
|
||||
<img src='{$printImageURL}' alt='Print' border='0' align='absmiddle'>
|
||||
</a>
|
||||
<a href='index.php?{$GLOBALS['request_string']}' class='utilsLink'>
|
||||
{$app_strings['LNK_PRINT']}
|
||||
</a>
|
||||
EOHTML;
|
||||
}
|
||||
$the_form .= <<<EOHTML
|
||||
|
||||
<a href='index.php?module=Administration&action=SupportPortal&view=documentation&version={$sugar_version}&edition={$sugar_flavor}&lang={$current_language}&help_module={$current_module}&help_action={$current_action}&key={$server_unique_key}'
|
||||
class='utilsLink' target='_blank'>
|
||||
<img src='{$helpImageURL}' alt='Help' border='0' align='absmiddle'>
|
||||
</a>
|
||||
<a href='index.php?module=Administration&action=SupportPortal&view=documentation&version={$sugar_version}&edition={$sugar_flavor}&lang={$current_language}&help_module={$current_module}&help_action={$current_action}&key={$server_unique_key}'
|
||||
class='utilsLink' target='_blank'>
|
||||
{$app_strings['LNK_HELP']}
|
||||
</a>
|
||||
</td>
|
||||
EOHTML;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ($other_text && $is_min_max === false) {
|
||||
$the_form .= <<<EOHTML
|
||||
<td width='20'><img height='1' width='20' src='$blankImageURL' alt=''></td>
|
||||
<td valign='middle' nowrap width='100%'>$other_text</td>
|
||||
EOHTML;
|
||||
}
|
||||
else {
|
||||
$the_form .= <<<EOHTML
|
||||
<td width='100%'><IMG height='1' width='1' src='$blankImageURL' alt=''></td>
|
||||
EOHTML;
|
||||
}
|
||||
|
||||
if ($show_help) {
|
||||
$the_form .= "<td align='right' nowrap>";
|
||||
if ($_REQUEST['action'] != "EditView") {
|
||||
$the_form .= <<<EOHTML
|
||||
<a href='index.php?{$GLOBALS['request_string']}' class='utilsLink'>
|
||||
<img src='{$printImageURL}' alt='Print' border='0' align='absmiddle'>
|
||||
</a>
|
||||
<a href='index.php?{$GLOBALS['request_string']}' class='utilsLink'>
|
||||
{$app_strings['LNK_PRINT']}</a>
|
||||
EOHTML;
|
||||
}
|
||||
$the_form .= <<<EOHTML
|
||||
|
||||
<a href='index.php?module=Administration&action=SupportPortal&view=documentation&version={$sugar_version}&edition={$sugar_flavor}&lang={$current_language}&help_module={$current_module}&help_action={$current_action}&key={$server_unique_key}'
|
||||
class='utilsLink' target='_blank'>
|
||||
<img src='{$helpImageURL}' alt='Help' border='0' align='absmiddle'>
|
||||
</a>
|
||||
<a href='index.php?module=Administration&action=SupportPortal&view=documentation&version={$sugar_version}&edition={$sugar_flavor}&lang={$current_language}&help_module={$current_module}&help_action={$current_action}&key={$server_unique_key}'
|
||||
class='utilsLink' target='_blank'>{$app_strings['LNK_HELP']}</a>
|
||||
</td>
|
||||
EOHTML;
|
||||
}
|
||||
}
|
||||
|
||||
$the_form .= <<<EOHTML
|
||||
</tr>
|
||||
</table>
|
||||
EOHTML;
|
||||
|
||||
return $the_form;
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrapper function for the get_module_title function, which is mostly used for pre-MVC modules.
|
||||
*
|
||||
* @deprecated use SugarView::getModuleTitle() for MVC modules, or getClassicModuleTitle() for non-MVC modules
|
||||
*
|
||||
* @param $module string to next to the title. Typically used for form buttons.
|
||||
* @param $module_title string to display as the module title
|
||||
* @param $show_help boolean which determines if the print and help links are shown.
|
||||
* @return string HTML
|
||||
*/
|
||||
function get_module_title(
|
||||
$module,
|
||||
$module_title,
|
||||
$show_help
|
||||
)
|
||||
{
|
||||
global $sugar_version, $sugar_flavor, $server_unique_key, $current_language, $action;
|
||||
global $app_strings;
|
||||
|
||||
$the_title = "<div class='moduleTitle'>\n<h2>";
|
||||
$module = preg_replace("/ /","",$module);
|
||||
if (is_file(SugarThemeRegistry::current()->getImageURL($module.'.gif'))) {
|
||||
$the_title .= "<img src='".SugarThemeRegistry::current()->getImageURL($module.'.gif')."' alt='".$module."'> ";
|
||||
}
|
||||
$the_title .= $module_title."</h2>\n";
|
||||
|
||||
if ($show_help) {
|
||||
$the_title .= "<span class='utils'>";
|
||||
if (isset($action) && $action != "EditView") {
|
||||
$printImageURL = SugarThemeRegistry::current()->getImageURL('print.gif');
|
||||
$the_title .= <<<EOHTML
|
||||
<a href="javascript:void window.open('index.php?{$GLOBALS['request_string']}','printwin','menubar=1,status=0,resizable=1,scrollbars=1,toolbar=0,location=1')" class='utilsLink'>
|
||||
<img src="{$printImageURL}" alt="{$GLOBALS['app_strings']['LNK_PRINT']}"></a>
|
||||
<a href="javascript:void window.open('index.php?{$GLOBALS['request_string']}','printwin','menubar=1,status=0,resizable=1,scrollbars=1,toolbar=0,location=1')" class='utilsLink'>
|
||||
{$GLOBALS['app_strings']['LNK_PRINT']}
|
||||
</a>
|
||||
EOHTML;
|
||||
}
|
||||
$helpImageURL = SugarThemeRegistry::current()->getImageURL('help.gif');
|
||||
$the_title .= <<<EOHTML
|
||||
|
||||
<a href="index.php?module=Administration&action=SupportPortal&view=documentation&version={$sugar_version}&edition={$sugar_flavor}&lang={$current_language}&help_module={$module}&help_action={$action}&key={$server_unique_key}" class="utilsLink" target="_blank">
|
||||
<img src='{$helpImageURL}' alt='{$GLOBALS['app_strings']['LNK_HELP']}'></a>
|
||||
<a href="index.php?module=Administration&action=SupportPortal&view=documentation&version={$sugar_version}&edition={$sugar_flavor}&lang={$current_language}&help_module={$module}&help_action={$action}&key={$server_unique_key}" class="utilsLink" target="_blank">
|
||||
{$GLOBALS['app_strings']['LNK_HELP']}
|
||||
</a>
|
||||
EOHTML;
|
||||
$the_title .= '</span>';
|
||||
}
|
||||
|
||||
$the_title .= "</div>\n";
|
||||
return $the_title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles displaying the header for classic view modules
|
||||
*
|
||||
* @param $module string to next to the title. Typically used for form buttons.
|
||||
* @param array $params optional, params to display in the breadcrumb, overriding SugarView::_getModuleTitleParams()
|
||||
* These should be in the form of array('label' => '<THE LABEL>', 'link' => '<HREF TO LINK TO>');
|
||||
* the first breadcrumb should be index at 0, and built from there e.g.
|
||||
* <code>
|
||||
* array(
|
||||
* '<a href="index.php?module=Contacts&action=index">Contacts</a>',
|
||||
* '<a href="index.php?module=Contacts&action=DetailView&record=123">John Smith</a>',
|
||||
* 'Edit',
|
||||
* );
|
||||
* </code>
|
||||
* would display as:
|
||||
* <a href='index.php?module=Contacts&action=index'>Contacts</a> >> <a href='index.php?module=Contacts&action=DetailView&record=123'>John Smith</a> >> Edit
|
||||
* @param $show_help boolean which determines if the print and help links are shown.
|
||||
* @return string HTML
|
||||
*/
|
||||
function getClassicModuleTitle(
|
||||
$module,
|
||||
$params,
|
||||
$show_help)
|
||||
{
|
||||
$module_title = '';
|
||||
$count = count($params);
|
||||
$index = 0;
|
||||
foreach($params as $parm){
|
||||
$index++;
|
||||
$module_title .= $parm;
|
||||
if($index < $count){
|
||||
$module_title .= "<span class='pointer'>»</span>";
|
||||
}
|
||||
}
|
||||
return get_module_title($module, $module_title, $show_help, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a header for a popup.
|
||||
*
|
||||
* @todo refactor this into the base Popup_Picker class
|
||||
*
|
||||
* @param $theme string the name of the current theme, ignorred to use SugarThemeRegistry::current() instead.
|
||||
* @return string HTML
|
||||
*/
|
||||
function insert_popup_header(
|
||||
$theme = null
|
||||
)
|
||||
{
|
||||
global $app_strings, $sugar_config;
|
||||
|
||||
$charset = isset($app_strings['LBL_CHARSET'])
|
||||
? $app_strings['LBL_CHARSET'] : $sugar_config['default_charset'];
|
||||
|
||||
$themeCSS = SugarThemeRegistry::current()->getCSS();
|
||||
|
||||
echo <<<EOHTML
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset="{$charset}">
|
||||
<title>{$app_strings['LBL_BROWSER_TITLE']}</title>
|
||||
{$themeCSS}
|
||||
EOHTML;
|
||||
echo '<script type="text/javascript" src="' . getJSPath('include/javascript/sugar_grp1_yui.js') . '"></script>';
|
||||
echo '<script type="text/javascript" src="' . getJSPath('include/javascript/sugar_grp1.js') . '"></script>';
|
||||
echo <<<EOHTML
|
||||
</head>
|
||||
<body style="margin: 10px">
|
||||
EOHTML;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a footer for a popup.
|
||||
*
|
||||
* @todo refactor this into the base Popup_Picker class
|
||||
*
|
||||
* @return string HTML
|
||||
*/
|
||||
function insert_popup_footer()
|
||||
{
|
||||
echo <<<EOQ
|
||||
</body>
|
||||
</html>
|
||||
EOQ;
|
||||
}
|
||||
122
include/utils/logic_utils.php
Executable file
122
include/utils/logic_utils.php
Executable file
@@ -0,0 +1,122 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
|
||||
function get_hook_array($module_name){
|
||||
|
||||
$hook_array = null;
|
||||
// This will load an array of the hooks to process
|
||||
include("custom/modules/$module_name/logic_hooks.php");
|
||||
return $hook_array;
|
||||
|
||||
//end function return_hook_array
|
||||
}
|
||||
|
||||
|
||||
|
||||
function check_existing_element($hook_array, $event, $action_array){
|
||||
|
||||
if(isset($hook_array[$event])){
|
||||
foreach($hook_array[$event] as $action){
|
||||
|
||||
if($action[1] == $action_array[1]){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
//end function check_existing_element
|
||||
}
|
||||
|
||||
function replace_or_add_logic_type($hook_array){
|
||||
|
||||
|
||||
|
||||
$new_entry = build_logic_file($hook_array);
|
||||
|
||||
$new_contents = "<?php\n$new_entry\n?>";
|
||||
|
||||
return $new_contents;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function write_logic_file($module_name, $contents){
|
||||
|
||||
$file = "modules/".$module_name . '/logic_hooks.php';
|
||||
$file = create_custom_directory($file);
|
||||
$fp = sugar_fopen($file, 'wb');
|
||||
fwrite($fp,$contents);
|
||||
fclose($fp);
|
||||
|
||||
//end function write_logic_file
|
||||
}
|
||||
|
||||
function build_logic_file($hook_array){
|
||||
|
||||
$hook_contents = "";
|
||||
|
||||
$hook_contents .= "// Do not store anything in this file that is not part of the array or the hook version. This file will \n";
|
||||
$hook_contents .= "// be automatically rebuilt in the future. \n ";
|
||||
$hook_contents .= "\$hook_version = 1; \n";
|
||||
$hook_contents .= "\$hook_array = Array(); \n";
|
||||
$hook_contents .= "// position, file, function \n";
|
||||
|
||||
foreach($hook_array as $event_array => $event){
|
||||
|
||||
$hook_contents .= "\$hook_array['".$event_array."'] = Array(); \n";
|
||||
|
||||
foreach($event as $second_key => $elements){
|
||||
|
||||
$hook_contents .= "\$hook_array['".$event_array."'][] = ";
|
||||
$hook_contents .= "Array(".$elements[0].", '".$elements[1]."', '".$elements[2]."','".$elements[3]."', '".$elements[4]."'); \n";
|
||||
|
||||
}
|
||||
|
||||
//end foreach hook_array as event => action_array
|
||||
}
|
||||
|
||||
$hook_contents .= "\n\n";
|
||||
|
||||
return $hook_contents;
|
||||
|
||||
//end function build_logic_file
|
||||
}
|
||||
|
||||
?>
|
||||
50
include/utils/mvc_utils.php
Executable file
50
include/utils/mvc_utils.php
Executable file
File diff suppressed because one or more lines are too long
145
include/utils/progress_bar_utils.php
Executable file
145
include/utils/progress_bar_utils.php
Executable file
@@ -0,0 +1,145 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
function display_flow_bar($name,$delay, $size=200){
|
||||
$chunk = $size/5;
|
||||
echo "<div id='{$name}_flow_bar'><table class='list view' cellpading=0 cellspacing=0><tr><td id='{$name}_flow_bar0' width='{$chunk}px' bgcolor='#cccccc' align='center'> </td><td id='{$name}_flow_bar1' width='{$chunk}px' bgcolor='#ffffff' align='center'> </td><td id='{$name}_flow_bar2' width='{$chunk}px' bgcolor='#ffffff' align='center'> </td><td id='{$name}_flow_bar3' width='{$chunk}px' bgcolor='#ffffff' align='center'> </td><td id='{$name}_flow_bar4' width='{$chunk}px' bgcolor='#ffffff' align='center'> </td></tr></table></div><br>";
|
||||
|
||||
echo str_repeat(' ',256);
|
||||
|
||||
ob_flush();
|
||||
// flush();
|
||||
start_flow_bar($name, $delay);
|
||||
|
||||
|
||||
}
|
||||
|
||||
function start_flow_bar($name, $delay){
|
||||
$delay *= 1000;
|
||||
$timer_id = $name . '_id';
|
||||
echo "<script>
|
||||
function update_flow_bar(name, count){
|
||||
var last = (count - 1) % 5;
|
||||
var cur = count % 5;
|
||||
var next = cur + 1;
|
||||
eval(\"document.getElementById('\" + name+\"_flow_bar\" + last+\"').style.backgroundColor='#ffffff';\");
|
||||
eval(\"document.getElementById('\" + name+\"_flow_bar\" + cur+\"').style.backgroundColor='#cccccc';\");
|
||||
$timer_id = setTimeout(\"update_flow_bar('$name', \" + next + \")\", $delay);
|
||||
}
|
||||
var $timer_id = setTimeout(\"update_flow_bar('$name', 1)\", $delay);
|
||||
|
||||
</script>
|
||||
";
|
||||
echo str_repeat(' ',256);
|
||||
|
||||
ob_flush();
|
||||
// flush();
|
||||
}
|
||||
function destroy_flow_bar($name){
|
||||
$timer_id = $name . '_id';
|
||||
echo "<script>clearTimeout($timer_id);document.getElementById('{$name}_flow_bar').innerHTML = '';</script>";
|
||||
echo str_repeat(' ',256);
|
||||
|
||||
ob_flush();
|
||||
// flush();
|
||||
|
||||
}
|
||||
|
||||
function display_progress_bar($name,$current, $total){
|
||||
$percent = $current/$total * 100;
|
||||
$remain = 100 - $percent;
|
||||
$status = floor($percent);
|
||||
//scale to a larger size
|
||||
$percent *= 2;
|
||||
$remain *= 2;
|
||||
if($remain == 0){
|
||||
$remain = 1;
|
||||
}
|
||||
if($percent == 0){
|
||||
$percent = 1;
|
||||
}
|
||||
echo "<div id='{$name}_progress_bar' style='width: 50%;'><table class='list view' cellpading=0 cellspacing=0><tr><td id='{$name}_complete_bar' width='{$percent}px' bgcolor='#cccccc' align='center'>$status% </td><td id='{$name}_remain_bar' width={$remain}px' bgcolor='#ffffff'> </td></tr></table></div><br>";
|
||||
if($status == 0){
|
||||
echo "<script>document.getElementById('{$name}_complete_bar').style.backgroundColor='#ffffff';</script>";
|
||||
}
|
||||
echo str_repeat(' ',256);
|
||||
|
||||
ob_flush();
|
||||
// flush();
|
||||
|
||||
}
|
||||
|
||||
function update_progress_bar($name,$current, $total){
|
||||
$percent = $current/$total * 100;
|
||||
$remain = 100 - $percent;
|
||||
$status = floor($percent);
|
||||
//scale to a larger size
|
||||
$percent *= 2;
|
||||
$remain *= 2;
|
||||
if($remain == 0){
|
||||
$remain = 1;
|
||||
}
|
||||
if($status == 100){
|
||||
echo "<script>document.getElementById('{$name}_remain_bar').style.backgroundColor='#cccccc';</script>";
|
||||
}
|
||||
if($status == 0){
|
||||
echo "<script>document.getElementById('{$name}_remain_bar').style.backgroundColor='#ffffff';</script>";
|
||||
echo "<script>document.getElementById('{$name}_complete_bar').style.backgroundColor='#ffffff';</script>";
|
||||
}
|
||||
if($status > 0){
|
||||
echo "<script>document.getElementById('{$name}_complete_bar').style.backgroundColor='#cccccc';</script>";
|
||||
}
|
||||
|
||||
|
||||
if($percent == 0){
|
||||
$percent = 1;
|
||||
}
|
||||
|
||||
echo "<script>
|
||||
document.getElementById('{$name}_complete_bar').width='{$percent}px';
|
||||
document.getElementById('{$name}_complete_bar').innerHTML = '$status%';
|
||||
document.getElementById('{$name}_remain_bar').width='{$remain}px';
|
||||
</script>";
|
||||
ob_flush();
|
||||
// flush();
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
144
include/utils/security_utils.php
Executable file
144
include/utils/security_utils.php
Executable file
@@ -0,0 +1,144 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
|
||||
/*
|
||||
* func: query_module_access
|
||||
* param: $moduleName
|
||||
*
|
||||
* returns 1 if user has access to a module, else returns 0
|
||||
*
|
||||
*/
|
||||
|
||||
$modules_exempt_from_availability_check['Activities']='Activities';
|
||||
$modules_exempt_from_availability_check['History']='History';
|
||||
$modules_exempt_from_availability_check['Calls']='Calls';
|
||||
$modules_exempt_from_availability_check['Meetings']='Meetings';
|
||||
$modules_exempt_from_availability_check['Tasks']='Tasks';
|
||||
$modules_exempt_from_availability_check['Notes']='Notes';
|
||||
$modules_exempt_from_availability_check['CampaignLog']='CampaignLog';
|
||||
$modules_exempt_from_availability_check['CampaignTrackers']='CampaignTrackers';
|
||||
$modules_exempt_from_availability_check['Prospects']='Prospects';
|
||||
$modules_exempt_from_availability_check['ProspectLists']='ProspectLists';
|
||||
$modules_exempt_from_availability_check['EmailMarketing']='EmailMarketing';
|
||||
$modules_exempt_from_availability_check['EmailMan']='EmailMan';
|
||||
$modules_exempt_from_availability_check['ProjectTask']='ProjectTask';
|
||||
$modules_exempt_from_availability_check['Users']='Users';
|
||||
$modules_exempt_from_availability_check['Teams']='Teams';
|
||||
$modules_exempt_from_availability_check['SchedulersJobs']='SchedulersJobs';
|
||||
$modules_exempt_from_availability_check['DocumentRevisions']='DocumentRevisions';
|
||||
function query_module_access_list(&$user)
|
||||
{
|
||||
require_once('modules/MySettings/TabController.php');
|
||||
$controller = new TabController();
|
||||
$tabArray = $controller->get_tabs($user);
|
||||
|
||||
return $tabArray[0];
|
||||
|
||||
}
|
||||
|
||||
function query_user_has_roles($user_id)
|
||||
{
|
||||
|
||||
|
||||
$role = new Role();
|
||||
|
||||
return $role->check_user_role_count($user_id);
|
||||
}
|
||||
|
||||
function get_user_allowed_modules($user_id)
|
||||
{
|
||||
|
||||
|
||||
$role = new Role();
|
||||
|
||||
$allowed = $role->query_user_allowed_modules($user_id);
|
||||
return $allowed;
|
||||
}
|
||||
|
||||
function get_user_disallowed_modules($user_id, &$allowed)
|
||||
{
|
||||
|
||||
|
||||
$role = new Role();
|
||||
$disallowed = $role->query_user_disallowed_modules($user_id, $allowed);
|
||||
return $disallowed;
|
||||
}
|
||||
// grabs client ip address and returns its value
|
||||
function query_client_ip()
|
||||
{
|
||||
global $_SERVER;
|
||||
$clientIP = false;
|
||||
if(!empty($GLOBALS['sugar_config']['ip_variable']) && !empty($_SERVER[$GLOBALS['sugar_config']['ip_variable']])){
|
||||
$clientIP = $_SERVER[$GLOBALS['sugar_config']['ip_variable']];
|
||||
}else if(isset($_SERVER['HTTP_CLIENT_IP']))
|
||||
{
|
||||
$clientIP = $_SERVER['HTTP_CLIENT_IP'];
|
||||
}
|
||||
elseif(isset($_SERVER['HTTP_X_FORWARDED_FOR']) AND preg_match_all('#\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}#s', $_SERVER['HTTP_X_FORWARDED_FOR'], $matches))
|
||||
{
|
||||
// check for internal ips by looking at the first octet
|
||||
foreach($matches[0] AS $ip)
|
||||
{
|
||||
if(!preg_match("#^(10|172\.16|192\.168)\.#", $ip))
|
||||
{
|
||||
$clientIP = $ip;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
elseif(isset($_SERVER['HTTP_FROM']))
|
||||
{
|
||||
$clientIP = $_SERVER['HTTP_FROM'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$clientIP = $_SERVER['REMOTE_ADDR'];
|
||||
}
|
||||
return $clientIP;
|
||||
}
|
||||
|
||||
// sets value to key value
|
||||
function get_val_array($arr){
|
||||
$new = array();
|
||||
if(!empty($arr)){
|
||||
foreach($arr as $key=>$val){
|
||||
$new[$key] = $key;
|
||||
}
|
||||
}
|
||||
return $new;
|
||||
}
|
||||
290
include/utils/sugar_file_utils.php
Executable file
290
include/utils/sugar_file_utils.php
Executable file
@@ -0,0 +1,290 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
|
||||
/**
|
||||
* sugar_mkdir
|
||||
* Call this function instead of mkdir to apply preconfigured permission
|
||||
* settings when creating the directory. This method is basically
|
||||
* a wrapper to the PHP mkdir function except that it supports setting
|
||||
* the mode value by using the configuration file (if set). The mode is
|
||||
* 0777 by default.
|
||||
*
|
||||
* @param $pathname - String value of the directory to create
|
||||
* @param $mode - The integer value of the permissions mode to set the created directory to
|
||||
* @param $recursive - boolean value indicating whether or not to create recursive directories if needed
|
||||
* @param $context
|
||||
* @return boolean - Returns true on success false on failure
|
||||
*/
|
||||
function sugar_mkdir($pathname, $mode=null, $recursive=false, $context='') {
|
||||
$mode = get_mode('dir_mode', $mode);
|
||||
|
||||
if ( sugar_is_dir($pathname,$mode) )
|
||||
return true;
|
||||
|
||||
$result = false;
|
||||
if(empty($mode))
|
||||
$mode = 0777;
|
||||
if(empty($context)) {
|
||||
$result = mkdir($pathname, $mode, $recursive);
|
||||
} else {
|
||||
$result = mkdir($pathname, $mode, $recursive, $context);
|
||||
}
|
||||
|
||||
if($result){
|
||||
if(!sugar_chmod($pathname, $mode)){
|
||||
return false;
|
||||
}
|
||||
if(!empty($GLOBALS['sugar_config']['default_permissions']['user'])){
|
||||
if(!sugar_chown($pathname)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if(!empty($GLOBALS['sugar_config']['default_permissions']['group'])){
|
||||
if(!sugar_chgrp($pathname)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* sugar_fopen
|
||||
* Call this function instead of fopen to apply preconfigured permission
|
||||
* settings when creating the the file. This method is basically
|
||||
* a wrapper to the PHP fopen function except that it supports setting
|
||||
* the mode value by using the configuration file (if set). The mode is
|
||||
* 0777 by default.
|
||||
*
|
||||
* @param $filename - String value of the file to create
|
||||
* @param $mode - The integer value of the permissions mode to set the created file to
|
||||
* @param $$use_include_path - boolean value indicating whether or not to search the the included_path
|
||||
* @param $context
|
||||
* @return boolean - Returns a file pointer on success, false otherwise
|
||||
*/
|
||||
function sugar_fopen($filename, $mode, $use_include_path=false, $context=null){
|
||||
//check to see if the file exists, if not then use touch to create it.
|
||||
if(!file_exists($filename)){
|
||||
sugar_touch($filename);
|
||||
}
|
||||
|
||||
if(empty($context)) {
|
||||
return fopen($filename, $mode, $use_include_path);
|
||||
} else {
|
||||
return fopen($filename, $mode, $use_include_path, $context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sugar_file_put_contents
|
||||
* Call this function instead of file_put_contents to apply preconfigured permission
|
||||
* settings when creating the the file. This method is basically
|
||||
* a wrapper to the PHP file_put_contents function except that it supports setting
|
||||
* the mode value by using the configuration file (if set). The mode is
|
||||
* 0777 by default.
|
||||
*
|
||||
* @param $filename - String value of the file to create
|
||||
* @param $data - The data to be written to the file
|
||||
* @param $flags - int as specifed by file_put_contents parameters
|
||||
* @param $context
|
||||
* @return int - Returns the number of bytes written to the file, false otherwise.
|
||||
*/
|
||||
function sugar_file_put_contents($filename, $data, $flags=null, $context=null){
|
||||
//check to see if the file exists, if not then use touch to create it.
|
||||
if(!file_exists($filename)){
|
||||
sugar_touch($filename);
|
||||
}
|
||||
|
||||
if(empty($flags)) {
|
||||
return file_put_contents($filename, $data);
|
||||
} elseif(empty($context)) {
|
||||
return file_put_contents($filename, $data, $flags);
|
||||
} else{
|
||||
return file_put_contents($filename, $data, $flags, $context);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* sugar_touch
|
||||
* Attempts to set the access and modification times of the file named in the filename
|
||||
* parameter to the value given in time . Note that the access time is always modified,
|
||||
* regardless of the number of parameters. If the file does not exist it will be created.
|
||||
* This method is basically a wrapper to the PHP touch method except that created files
|
||||
* may be set with the permissions specified in the configuration file (if set).
|
||||
*
|
||||
* @param $filename - The name of the file being touched.
|
||||
* @param $time - The touch time. If time is not supplied, the current system time is used.
|
||||
* @param $atime - If present, the access time of the given filename is set to the value of atime
|
||||
* @return boolean - Returns TRUE on success or FALSE on failure.
|
||||
*
|
||||
*/
|
||||
function sugar_touch($filename, $time=null, $atime=null) {
|
||||
|
||||
$result = false;
|
||||
|
||||
if(!empty($atime) && !empty($time)) {
|
||||
$result = touch($filename, $time, $atime);
|
||||
} else if(!empty($time)) {
|
||||
$result = touch($filename, $time);
|
||||
} else {
|
||||
$result = touch($filename);
|
||||
}
|
||||
|
||||
if(!$result) return $result;
|
||||
|
||||
if(!empty($GLOBALS['sugar_config']['default_permissions']['file_mode'])){
|
||||
sugar_chmod($filename, $GLOBALS['sugar_config']['default_permissions']['file_mode']);
|
||||
}
|
||||
if(!empty($GLOBALS['sugar_config']['default_permissions']['user'])){
|
||||
sugar_chown($filename);
|
||||
}
|
||||
if(!empty($GLOBALS['sugar_config']['default_permissions']['group'])){
|
||||
sugar_chgrp($filename);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* sugar_chmod
|
||||
* Attempts to change the permission of the specified filename to the mode value specified in the
|
||||
* default_permissions configuration; otherwise, it will use the mode value.
|
||||
*
|
||||
* @param string filename - Path to the file
|
||||
* @param int $mode The integer value of the permissions mode to set the created directory to
|
||||
* @return boolean Returns TRUE on success or FALSE on failure.
|
||||
*/
|
||||
function sugar_chmod($filename, $mode=null) {
|
||||
if ( !is_int($mode) )
|
||||
$mode = (int) $mode;
|
||||
if(!is_windows()){
|
||||
if(!isset($mode)){
|
||||
$mode = get_mode('file_mode', $mode);
|
||||
}
|
||||
if(isset($mode) && $mode > 0){
|
||||
return @chmod($filename, $mode);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* sugar_chown
|
||||
* Attempts to change the owner of the file filename to the user specified in the
|
||||
* default_permissions configuration; otherwise, it will use the user value.
|
||||
*
|
||||
* @param filename - Path to the file
|
||||
* @param user - A user name or number
|
||||
* @return boolean - Returns TRUE on success or FALSE on failure.
|
||||
*/
|
||||
function sugar_chown($filename, $user='') {
|
||||
if(!is_windows()){
|
||||
if(strlen($user)){
|
||||
return chown($filename, $user);
|
||||
}else{
|
||||
if(strlen($GLOBALS['sugar_config']['default_permissions']['user'])){
|
||||
$user = $GLOBALS['sugar_config']['default_permissions']['user'];
|
||||
return chown($filename, $user);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* sugar_chgrp
|
||||
* Attempts to change the group of the file filename to the group specified in the
|
||||
* default_permissions configuration; otherwise it will use the group value.
|
||||
*
|
||||
* @param filename - Path to the file
|
||||
* @param group - A group name or number
|
||||
* @return boolean - Returns TRUE on success or FALSE on failure.
|
||||
*/
|
||||
function sugar_chgrp($filename, $group='') {
|
||||
if(!is_windows()){
|
||||
if(!empty($group)){
|
||||
return chgrp($filename, $group);
|
||||
}else{
|
||||
if(!empty($GLOBALS['sugar_config']['default_permissions']['group'])){
|
||||
$group = $GLOBALS['sugar_config']['default_permissions']['group'];
|
||||
return chgrp($filename, $group);
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* get_mode
|
||||
*
|
||||
* Will check to see if there is a default mode defined in the config file, otherwise return the
|
||||
* $mode given as input
|
||||
*
|
||||
* @param int $mode - the mode being passed by the calling function. This value will be overridden by a value
|
||||
* defined in the config file.
|
||||
* @return int - the mode either found in the config file or passed in via the input parameter
|
||||
*/
|
||||
function get_mode($key = 'dir_mode', $mode=null) {
|
||||
if ( !is_int($mode) )
|
||||
$mode = (int) $mode;
|
||||
if(!class_exists('SugarConfig', true)) {
|
||||
require 'include/SugarObjects/SugarConfig.php';
|
||||
}
|
||||
if(!is_windows()){
|
||||
$conf_inst=SugarConfig::getInstance();
|
||||
$mode = $conf_inst->get('default_permissions.'.$key, $mode);
|
||||
}
|
||||
return $mode;
|
||||
}
|
||||
|
||||
function sugar_is_dir($path, $mode='r'){
|
||||
if(defined('TEMPLATE_URL'))return is_dir($path, $mode);
|
||||
return is_dir($path);
|
||||
}
|
||||
|
||||
function sugar_is_file($path, $mode='r'){
|
||||
if(defined('TEMPLATE_URL'))return is_file($path, $mode);
|
||||
return is_file($path);
|
||||
}
|
||||
|
||||
?>
|
||||
88
include/utils/zip_utils.php
Executable file
88
include/utils/zip_utils.php
Executable file
@@ -0,0 +1,88 @@
|
||||
<?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".
|
||||
********************************************************************************/
|
||||
|
||||
|
||||
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
|
||||
require_once('include/pclzip/pclzip.lib.php');
|
||||
|
||||
function unzip( $zip_archive, $zip_dir, $forceOverwrite = false ){
|
||||
if( !is_dir( $zip_dir ) ){
|
||||
die( "Specified directory '$zip_dir' for zip file '$zip_archive' extraction does not exist." );
|
||||
}
|
||||
|
||||
$archive = new PclZip( $zip_archive );
|
||||
|
||||
if ( $forceOverwrite ) {
|
||||
if( $archive->extract( PCLZIP_OPT_PATH, $zip_dir, PCLZIP_OPT_REPLACE_NEWER ) == 0 ){
|
||||
die( "Error: " . $archive->errorInfo(true) );
|
||||
}
|
||||
}
|
||||
else {
|
||||
if( $archive->extract( PCLZIP_OPT_PATH, $zip_dir ) == 0 ){
|
||||
die( "Error: " . $archive->errorInfo(true) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function unzip_file( $zip_archive, $archive_file, $to_dir, $forceOverwrite = false ){
|
||||
if( !is_dir( $to_dir ) ){
|
||||
die( "Specified directory '$to_dir' for zip file '$zip_archive' extraction does not exist." );
|
||||
}
|
||||
|
||||
$archive = new PclZip( "$zip_archive" );
|
||||
if ( $forceOverwrite ) {
|
||||
if( $archive->extract( PCLZIP_OPT_BY_NAME, $archive_file,
|
||||
PCLZIP_OPT_PATH, $to_dir,
|
||||
PCLZIP_OPT_REPLACE_NEWER ) == 0 ){
|
||||
die( "Error: " . $archive->errorInfo(true) );
|
||||
}
|
||||
}
|
||||
else {
|
||||
if( $archive->extract( PCLZIP_OPT_BY_NAME, $archive_file,
|
||||
PCLZIP_OPT_PATH, $to_dir ) == 0 ){
|
||||
die( "Error: " . $archive->errorInfo(true) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function zip_dir( $zip_dir, $zip_archive ){
|
||||
$archive = new PclZip( "$zip_archive" );
|
||||
$v_list = $archive->create( "$zip_dir" );
|
||||
if( $v_list == 0 ){
|
||||
die( "Error: " . $archive->errorInfo(true) );
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user