Skip to content

Commit

Permalink
Merge pull request #20 from nguyenanhung/develop
Browse files Browse the repository at this point in the history
Update Project at Mon Mar 27 15:23:51 +07 2023
  • Loading branch information
nguyenanhung authored Mar 27, 2023
2 parents 900d294 + 400f167 commit e127b90
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 22 deletions.
6 changes: 6 additions & 0 deletions helpers/common_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,9 @@ function generateRandomNanoUniqueId()
return date('Ymd') . '-' . randomNanoId(16) . $uniqid;
}
}
if (!function_exists('__get_error_message__')){
function __get_error_message__($e)
{
return "Error Code: " . $e->getCode() . " - File: " . $e->getFile() . " - Line: " . $e->getLine() . " - Message: " . $e->getMessage();
}
}
5 changes: 3 additions & 2 deletions src/BaseHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,16 @@
*/
class BaseHelper
{
const VERSION = '1.3.4';
const LAST_MODIFIED = '2023-03-23';
const VERSION = '1.3.5';
const LAST_MODIFIED = '2023-03-27';
const PROJECT_NAME = 'CodeIgniter - Basic Helper';
const AUTHOR_NAME = 'Hung Nguyen';
const AUTHOR_FULL_NAME = 'Hung Nguyen';
const AUTHOR_EMAIL = '[email protected]';
const AUTHOR_WEB = 'https://nguyenanhung.com';
const AUTHOR_BLOG = 'https://blog.nguyenanhung.com';
const GITHUB_URL = 'https://github.com/nguyenanhung/codeigniter-basic-helper';
const GITHUB_ISSUES_URL = 'https://github.com/nguyenanhung/codeigniter-basic-helper/issues';
const PACKAGES_URL = 'https://packagist.org/packages/nguyenanhung/codeigniter-basic-helper';

public function getVersion()
Expand Down
10 changes: 5 additions & 5 deletions src/BasicImageHelperWithGD.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BasicImageHelperWithGD
{
protected $image;
protected $imageFormat;

public function load($imageFile)
{
$imageInfo = getImageSize($imageFile);
Expand Down Expand Up @@ -56,24 +56,24 @@ public function resizeToHeight($height)
{
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->__resize($width, $height);
$this->resized($width, $height);
}

public function resizeToWidth($width)
{
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->__resize($width, $height);
$this->resized($width, $height);
}

public function scale($scale)
{
$width = $this->getWidth() * $scale / 100;
$height = $this->getheight() * $scale / 100;
$this->__resize($width, $height);
$this->resized($width, $height);
}

private function __resize($width, $height)
protected function resized($width, $height)
{
$newImage = imagecreatetruecolor($width, $height);
imagecopyresampled($newImage, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
Expand Down
26 changes: 26 additions & 0 deletions src/HelperException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Project codeigniter-basic-helper
* Created by PhpStorm
* User: 713uk13m <[email protected]>
* Copyright: 713uk13m <[email protected]>
* Date: 27/03/2023
* Time: 15:12
*/

namespace nguyenanhung\CodeIgniter\BasicHelper;

class HelperException extends \Exception
{
/**
* @throws \nguyenanhung\CodeIgniter\BasicHelper\HelperException
*/
public function __construct($message = null, $code = 0)
{
if (!$message) {
throw new $this('Unknown ' . get_class($this));
}
$error_message = $message . ' - If you believe this is a codebase or framework bug, please report it and let us know here: ' . BaseHelper::GITHUB_ISSUES_URL . ' - Codebase will be improved by your contributions. Thank you!';
parent::__construct($error_message, $code);
}
}
15 changes: 2 additions & 13 deletions src/ImageHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public static function googleGadgetsProxy($url = '', $width = 100, $height = nul
$proxyUrl = 'https://images1-focus-opensocial.googleusercontent.com/gadgets/proxy';
$proxyContainer = 'focus';
$proxyRefresh = 2592000;
// Start
$params = array();
$params['url'] = $url;
$params['resize_w'] = $width;
Expand All @@ -47,9 +46,7 @@ public static function googleGadgetsProxy($url = '', $width = 100, $height = nul
}
$params['container'] = $proxyContainer;
$params['refresh'] = $proxyRefresh;
// Result URL
$url = $proxyUrl . '?' . urldecode(http_build_query($params));

return trim($url);
}

Expand Down Expand Up @@ -81,7 +78,6 @@ public static function wordpressProxy($imageUrl = '', $server = 'i3')
{
$imageUrl = str_replace(array('https://', 'http://', '//'), '', $imageUrl);
$url = 'https://' . trim($server) . '.wp.com/' . $imageUrl;

return trim($url);
}

Expand All @@ -99,7 +95,6 @@ public static function wordpressProxyDnsPrefetch()
$html .= "<link href='//i1.wp.com' rel='dns-prefetch' />" . PHP_EOL;
$html .= "<link href='//i2.wp.com' rel='dns-prefetch' />" . PHP_EOL;
$html .= "<link href='//i3.wp.com' rel='dns-prefetch' />" . PHP_EOL;

return $html;
}

Expand Down Expand Up @@ -129,16 +124,13 @@ public static function createThumbnail($url = '', $width = 100, $height = 100)
if (!empty($thumbnail)) {
return $thumbnail;
}

return $cache->thumbnail(config_item('image_path_tmp_default'), $width, $height);
}

return $url;
} catch (Exception $e) {
if (function_exists('log_message')) {
log_message('error', "Error Code: " . $e->getCode() . " - File: " . $e->getFile() . " - Line: " . $e->getLine() . " - Message: " . $e->getMessage());
log_message('error', __get_error_message__($e));
}

return $url;
}
}
Expand Down Expand Up @@ -185,16 +177,13 @@ public static function createThumbnailWithCodeIgniterCache($url = '', $width = 1
if (!empty($urlThumbnail)) {
return $urlThumbnail;
}

return $url;
}

return $url;
} catch (Exception $e) {
if (function_exists('log_message')) {
log_message('error', "Error Code: " . $e->getCode() . " - File: " . $e->getFile() . " - Line: " . $e->getLine() . " - Message: " . $e->getMessage());
log_message('error', __get_error_message__($e));
}

return $url;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/SimpleRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public function sendRequest($url = '', $data = array(), $method = 'GET')
// Return Response
return $response;
} catch (Exception $e) {
log_message('error', $e->getMessage());
log_message('error', __get_error_message__($e));
log_message('error', $e->getTraceAsString());

return null;
Expand Down Expand Up @@ -212,7 +212,7 @@ public function xmlRequest($url = '', $data = '', $timeout = 60)

return $page;
} catch (Exception $e) {
log_message('error', $e->getMessage());
log_message('error', __get_error_message__($e));
log_message('error', $e->getTraceAsString());

return null;
Expand Down

0 comments on commit e127b90

Please sign in to comment.