Skip to content

Commit

Permalink
Update helper
Browse files Browse the repository at this point in the history
  • Loading branch information
hungnguyenhp committed Aug 20, 2021
1 parent 9c26ddb commit feb813b
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 39 deletions.
14 changes: 7 additions & 7 deletions helpers/array_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
/**
* Function arrayToObject
*
* @param array $array
* @param array|mixed $array
*
* @return array|false|\stdClass
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 07/27/2021 36:10
*/
function arrayToObject(array $array = array())
function arrayToObject($array = array())
{
if (!is_array($array)) {
return $array;
Expand All @@ -43,15 +43,15 @@ function arrayToObject(array $array = array())
/**
* Function arrayToXml
*
* @param array $array
* @param string $namespace
* @param null $file_output
* @param array|mixed $array
* @param string $namespace
* @param null $file_output
*
* @return bool|string|null
* @throws \Exception
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 08/07/2021 19:29
* @time : 08/20/2021 13:21
*/
function arrayToXml($array = array(), $namespace = '', $file_output = NULL)
{
Expand All @@ -60,7 +60,7 @@ function arrayToXml($array = array(), $namespace = '', $file_output = NULL)
convertArrayToXml($array, $xml_object); // function call to convert array to xml
$xml_file = $file_output !== NULL ? $xml_object->asXML($file_output) : $xml_object->asXML(); // saving generated xml file

return $xml_file ? $xml_file : NULL;
return !empty($xml_file) ? $xml_file : NULL;
}

return NULL;
Expand Down
8 changes: 4 additions & 4 deletions helpers/assets_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
/**
* Function assets_url
*
* @param string $uri
* @param null $protocol
* @param string $uri
* @param null|string $protocol
*
* @return string
* @author : 713uk13m <[email protected]>
Expand Down Expand Up @@ -40,8 +40,8 @@ function assets_url($uri = '', $protocol = NULL)
/**
* Function templates_url
*
* @param string $uri
* @param null $protocol
* @param string $uri
* @param null|string $protocol
*
* @return string
* @author : 713uk13m <[email protected]>
Expand Down
30 changes: 5 additions & 25 deletions helpers/image_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
/**
* Function google_image_resize
*
* @param string $url
* @param int $width
* @param null $height
* @param string $url
* @param int $width
* @param null|int $height
*
* @return string
* @author : 713uk13m <[email protected]>
Expand All @@ -22,22 +22,7 @@
*/
function google_image_resize($url = '', $width = 100, $height = NULL)
{
$proxyUrl = 'https://images1-focus-opensocial.googleusercontent.com/gadgets/proxy';
$proxyContainer = 'focus';
$proxyRefresh = 2592000;
// Start
$params = array();
$params['url'] = $url;
$params['resize_w'] = $width;
if (!empty($height)) {
$params['resize_h'] = $height;
}
$params['container'] = $proxyContainer;
$params['refresh'] = $proxyRefresh;
// Result URL
$url = $proxyUrl . '?' . urldecode(http_build_query($params));

return trim($url);
return nguyenanhung\CodeIgniter\BasicHelper\ImageHelper::googleGadgetsProxy($url, $width, $height);
}
}
if (!function_exists('wordpress_proxy')) {
Expand All @@ -54,11 +39,6 @@ function google_image_resize($url = '', $width = 100, $height = NULL)
*/
function wordpress_proxy($imageUrl = '', $server = 'i3')
{
$imageUrl = str_replace('https://', '', $imageUrl);
$imageUrl = str_replace('http://', '', $imageUrl);
$imageUrl = str_replace('//', '', $imageUrl);
$url = 'https://' . trim($server) . '.wp.com/' . $imageUrl;

return trim($url);
return nguyenanhung\CodeIgniter\BasicHelper\ImageHelper::wordpressProxy($imageUrl, $server);
}
}
2 changes: 1 addition & 1 deletion helpers/ip_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
/**
* Function getIPAddress
*
* @param false $convertToInteger
* @param bool $convertToInteger
*
* @return false|int|string
* @author : 713uk13m <[email protected]>
Expand Down
53 changes: 53 additions & 0 deletions src/ImageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,57 @@
class ImageHelper implements ProjectInterface
{
use VersionTrait;

/**
* Function googleGadgetsProxy
*
* @param string $url
* @param int $width
* @param null|int $height
*
* @return string
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 08/20/2021 11:20
*/
public static function googleGadgetsProxy($url = '', $width = 100, $height = NULL)
{
$proxyUrl = 'https://images1-focus-opensocial.googleusercontent.com/gadgets/proxy';
$proxyContainer = 'focus';
$proxyRefresh = 2592000;
// Start
$params = array();
$params['url'] = $url;
$params['resize_w'] = $width;
if (!empty($height)) {
$params['resize_h'] = $height;
}
$params['container'] = $proxyContainer;
$params['refresh'] = $proxyRefresh;
// Result URL
$url = $proxyUrl . '?' . urldecode(http_build_query($params));

return trim($url);
}

/**
* Function wordpressProxy
*
* @param string $imageUrl
* @param string $server
*
* @return string
* @author : 713uk13m <[email protected]>
* @copyright: 713uk13m <[email protected]>
* @time : 08/20/2021 11:39
*/
public static function wordpressProxy($imageUrl = '', $server = 'i3')
{
$imageUrl = str_replace('https://', '', $imageUrl);
$imageUrl = str_replace('http://', '', $imageUrl);
$imageUrl = str_replace('//', '', $imageUrl);
$url = 'https://' . trim($server) . '.wp.com/' . $imageUrl;

return trim($url);
}
}
4 changes: 2 additions & 2 deletions src/ProjectInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
*/
interface ProjectInterface
{
const VERSION = '1.0.0';
const LAST_MODIFIED = '2021-08-07';
const VERSION = '1.0.1';
const LAST_MODIFIED = '2021-08-20';
const AUTHOR_NAME = 'Hung Nguyen';
const AUTHOR_EMAIL = '[email protected]';
const PROJECT_NAME = 'CodeIgniter - Basic Helper';
Expand Down

0 comments on commit feb813b

Please sign in to comment.