* @return CRM_Contribute_DAO_Product
*/
public static function add(&$params, &$ids) {
- $defaults = array(
+ $params = array_merge(array(
'id' => CRM_Utils_Array::value('premium', $ids),
- 'image' => '',
- 'thumbnail' => '',
- 'is_active' => FALSE,
+ 'image' => CRM_Utils_String::simplifyURL(CRM_Utils_Array::value('image', $params, ''), TRUE),
+ 'thumbnail' => CRM_Utils_String::simplifyURL(CRM_Utils_Array::value('thumbnail', $params, ''), TRUE),
+ 'is_active' => 0,
'is_deductible' => FALSE,
'currency' => CRM_Core_Config::singleton()->defaultCurrency,
- );
- $params = array_merge($defaults, $params);
-
- // Use local URLs for images when possible
- $params['image'] = CRM_Utils_String::simplifyURL($params['image'], TRUE);
- $params['thumbnail'] = CRM_Utils_String::simplifyURL($params['thumbnail'], TRUE);
+ ), $params);
// Save and return
$premium = new CRM_Contribute_DAO_Product();
public static function formRule($params, $files) {
// If choosing to upload an image, then an image must be provided
- if (
- isset($params['imageOption']) &&
- $params['imageOption'] == 'image' &&
- empty($files['uploadFile']['name'])
+ if (CRM_Utils_Array::value('imageOption', $params['imageOption']) == 'image'
+ && empty($files['uploadFile']['name'])
) {
$errors['uploadFile'] = ts('A file must be selected');
}
// If choosing to use image URLs, then both URLs must be present
- if (isset($params['imageOption']) && $params['imageOption'] == 'thumbnail') {
+ if (CRM_Utils_Array::value('imageOption', $params['imageOption']) == 'thumbnail') {
if (!$params['imageUrl']) {
$errors['imageUrl'] = ts('Image URL is Required');
}
* @return array
*/
public function simplifyURLProvider() {
-
$config = CRM_Core_Config::singleton();
$urlParts = parse_url($config->userFrameworkBaseURL);
$localDomain = $urlParts['host'];
}
return array(
-
- 'prototypical example' =>
- array(
+ 'prototypical example' => array(
"https://$localDomain/sites/default/files/coffee-mug.jpg",
FALSE,
'/sites/default/files/coffee-mug.jpg',
),
-
- 'external domain with https' =>
- array(
+ 'external domain with https' => array(
"https://$externalDomain/sites/default/files/coffee-mug.jpg",
FALSE,
"https://$externalDomain/sites/default/files/coffee-mug.jpg",
),
-
- 'external domain with http forced to https' =>
- array(
+ 'external domain with http forced to https' => array(
"http://$externalDomain/sites/default/files/coffee-mug.jpg",
TRUE,
"https://$externalDomain/sites/default/files/coffee-mug.jpg",
),
-
- 'external domain with http not forced' =>
- array(
+ 'external domain with http not forced' => array(
"http://$externalDomain/sites/default/files/coffee-mug.jpg",
FALSE,
"http://$externalDomain/sites/default/files/coffee-mug.jpg",
),
-
- 'local URL' =>
- array(
+ 'local URL' => array(
"/sites/default/files/coffee-mug.jpg",
FALSE,
"/sites/default/files/coffee-mug.jpg",
),
-
- 'local URL without a forward slash' =>
- array(
+ 'local URL without a forward slash' => array(
"sites/default/files/coffee-mug.jpg",
FALSE,
"/sites/default/files/coffee-mug.jpg",
),
-
- 'empty input' =>
- array(
+ 'empty input' => array(
'',
FALSE,
'',
*/
public function parseURLProvider() {
return array(
-
- "prototypical example" =>
- array(
+ "prototypical example" => array(
"https://example.com:8000/foo/bar/?id=1#fragment",
array(
'host+port' => "example.com:8000",
'path+query' => "/foo/bar/?id=1",
),
),
-
- "empty" =>
- array(
+ "empty" => array(
"",
array(
'host+port' => "",
'path+query' => "",
),
),
-
- "path only" =>
- array(
+ "path only" => array(
"/foo/bar/image.png",
array(
'host+port' => "",