Skip to content

Commit 5322272

Browse files
authored
Merge pull request #14 from nguyenanhung/v3.1.14-develop
V3.1.14 develop
2 parents 756b5d3 + 99eab64 commit 5322272

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+4680
-20
lines changed

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"require": {
2121
"php": ">=5.6",
2222
"ext-json": "*",
23-
"ext-mbstring": "*",
2423
"nguyenanhung/codeigniter-basic-helper": ">=1.0",
2524
"symfony/polyfill-mbstring": ">=1.0"
2625
},

helpers/common.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<?php
2+
/**
3+
* Project codeigniter-framework
4+
* Created by PhpStorm
5+
* User: 713uk13m <dev@nguyenanhung.com>
6+
* Copyright: 713uk13m <dev@nguyenanhung.com>
7+
* Date: 09/03/2023
8+
* Time: 23:00
9+
*/
210
if (!function_exists('bear_str_to_lower')) {
311
function bear_str_to_lower($str)
412
{

system/libraries/Breadcrumb.php

Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
<?php
2+
/**
3+
* Project codeigniter-framework
4+
* Created by PhpStorm
5+
* User: 713uk13m <dev@nguyenanhung.com>
6+
* Copyright: 713uk13m <dev@nguyenanhung.com>
7+
* Date: 09/03/2023
8+
* Time: 23:55
9+
*/
10+
defined('BASEPATH') or exit('No direct script access allowed');
11+
12+
/**
13+
* HTML Breadcrumb Generating Class
14+
*
15+
* @author 713uk13m <dev@nguyenanhung.com>
16+
* @copyright 713uk13m <dev@nguyenanhung.com>
17+
*
18+
* ------------ Example Construction
19+
* Load library breadcrumb
20+
* $this->load->library('breadcrumb');
21+
*
22+
* Custom style
23+
* $template = [
24+
* 'tag_open' => '<ol class="breadcrumb">',
25+
* 'crumb_open' => '<li class="breadcrumb-item">',
26+
* 'crumb_active' => '<li class="breadcrumb-item active" aria-current="page">'
27+
* ];
28+
* $this->breadcrumb->set_template($template);
29+
*
30+
* Add items
31+
* $this->breadcrumb->add_item($breadcrumb_items);
32+
*
33+
* Generate breadcrumb
34+
* $data['breadcrumb_bootstrap_style'] = $this->breadcrumb->generate();
35+
*/
36+
class CI_Breadcrumb
37+
{
38+
protected $CI;
39+
40+
private $breadcrumb = array();
41+
42+
/**
43+
* breadcrumb layout template
44+
*
45+
* @var array
46+
*/
47+
public $template = null;
48+
49+
/**
50+
* Newline setting
51+
*
52+
* @var string
53+
*/
54+
public $newline = "\n";
55+
56+
/**
57+
* Set the template from the breadcrumb config file if it exists
58+
*
59+
* @param array $config (default: array())
60+
*
61+
* @return void
62+
*/
63+
public function __construct($config = array())
64+
{
65+
$this->CI =& get_instance();
66+
67+
$this->CI->load->helper('url');
68+
69+
// initialize config
70+
foreach ($config as $key => $val) {
71+
$this->template[$key] = $val;
72+
}
73+
74+
log_message('info', 'Breadcrumb Class Initialized');
75+
}
76+
77+
// --------------------------------------------------------------------
78+
79+
/**
80+
* Set the template
81+
*
82+
* @param array $template
83+
*
84+
* @return bool
85+
*/
86+
public function set_template($template)
87+
{
88+
if (!is_array($template)) {
89+
return false;
90+
} else {
91+
$this->template = $template;
92+
93+
return true;
94+
}
95+
}
96+
97+
// --------------------------------------------------------------------
98+
99+
/**
100+
* Function add_item
101+
*
102+
* @param $args
103+
*
104+
* @return false|void
105+
* @author : 713uk13m <dev@nguyenanhung.com>
106+
* @copyright: 713uk13m <dev@nguyenanhung.com>
107+
* @time : 09/03/2023 57:18
108+
*/
109+
public function add_item($args)
110+
{
111+
if (!is_array($args) or empty($args)) {
112+
return false;
113+
} else {
114+
foreach ($args as $key => $value) {
115+
$href = site_url($value);
116+
117+
$this->breadcrumb[$href] = array(
118+
'page' => $key,
119+
'href' => $href
120+
);
121+
}
122+
}
123+
}
124+
125+
// --------------------------------------------------------------------
126+
127+
/**
128+
* Generate the breadcrumb
129+
*
130+
* @param mixed $breadcrumb_data
131+
*
132+
* @return string|void
133+
*/
134+
public function generate()
135+
{
136+
if ($this->breadcrumb) {
137+
// Compile and validate the template date
138+
$this->_compile_template();
139+
140+
// Build the breadcrumb
141+
$out = $this->template['tag_open'] . $this->newline;
142+
143+
foreach ($this->breadcrumb as $key => $value) {
144+
$keys = array_keys($this->breadcrumb);
145+
146+
if (end($keys) == $key) {
147+
$out .= $this->template['crumb_active'] . $value['page'] . $this->template['crumb_close'] . $this->newline;
148+
} else {
149+
$out .= $this->template['crumb_open'];
150+
$out .= anchor($value['href'], $value['page']);
151+
$out .= $this->template['crumb_close'];
152+
$out .= $this->newline;
153+
}
154+
}
155+
156+
$out .= $this->template['tag_close'] . $this->newline;
157+
158+
// Clear Breadcrumb class properties before generating the breadcrumb
159+
$this->clear();
160+
161+
return $out;
162+
}
163+
}
164+
165+
// --------------------------------------------------------------------
166+
167+
/**
168+
* Clears the breadcrumb arrays. Useful if multiple tables are being generated
169+
*
170+
* @return self
171+
*/
172+
public function clear()
173+
{
174+
$this->breadcrumb = array();
175+
176+
return $this;
177+
}
178+
179+
// --------------------------------------------------------------------
180+
181+
/**
182+
* Compile Template
183+
*
184+
* @return void
185+
*/
186+
protected function _compile_template()
187+
{
188+
if ($this->template === null) {
189+
$this->template = $this->_default_template();
190+
191+
return;
192+
}
193+
194+
$this->temp = $this->_default_template();
195+
196+
foreach (array('tag_open', 'tag_close', 'crumb_open', 'crumb_close', 'crumb_active') as $val) {
197+
if (!isset($this->template[$val])) {
198+
$this->template[$val] = $this->temp[$val];
199+
}
200+
}
201+
}
202+
203+
// --------------------------------------------------------------------
204+
205+
/**
206+
* Default Template
207+
*
208+
* @return array
209+
*/
210+
protected function _default_template()
211+
{
212+
return array(
213+
'tag_open' => '<ol>',
214+
'tag_close' => '</ol>',
215+
'crumb_open' => '<li>',
216+
'crumb_close' => '</li>',
217+
'crumb_active' => '<li class="active">'
218+
);
219+
}
220+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
<?php
2+
/**
3+
* Project codeigniter-framework
4+
* Created by PhpStorm
5+
* User: 713uk13m <dev@nguyenanhung.com>
6+
* Copyright: 713uk13m <dev@nguyenanhung.com>
7+
* Date: 10/03/2023
8+
* Time: 00:22
9+
*/
10+
defined('BASEPATH') or exit('No direct script access allowed');
11+
12+
class CI_Image_lib_with_gd
13+
{
14+
protected $image;
15+
protected $imageFormat;
16+
17+
public function load($imageFile)
18+
{
19+
$imageInfo = getImageSize($imageFile);
20+
$this->imageFormat = $imageInfo[2];
21+
if ($this->imageFormat === IMAGETYPE_JPEG) {
22+
$this->image = imagecreatefromjpeg($imageFile);
23+
} elseif ($this->imageFormat === IMAGETYPE_GIF) {
24+
$this->image = imagecreatefromgif($imageFile);
25+
} elseif ($this->imageFormat === IMAGETYPE_PNG) {
26+
$this->image = imagecreatefrompng($imageFile);
27+
}
28+
}
29+
30+
public function save($imageFile, $__imageFormat = IMAGETYPE_JPEG, $compression = 75, $permissions = null)
31+
{
32+
if ($__imageFormat == IMAGETYPE_JPEG) {
33+
imagejpeg($this->image, $imageFile, $compression);
34+
} elseif ($__imageFormat == IMAGETYPE_GIF) {
35+
imagegif($this->image, $imageFile);
36+
} elseif ($__imageFormat == IMAGETYPE_PNG) {
37+
imagepng($this->image, $imageFile);
38+
}
39+
if ($permissions != null) {
40+
chmod($imageFile, $permissions);
41+
}
42+
}
43+
44+
public function getWidth()
45+
{
46+
return imagesx($this->image);
47+
}
48+
49+
public function getHeight()
50+
{
51+
return imagesy($this->image);
52+
}
53+
54+
public function resizeToHeight($height)
55+
{
56+
$ratio = $height / $this->getHeight();
57+
$width = $this->getWidth() * $ratio;
58+
$this->__resize($width, $height);
59+
}
60+
61+
public function resizeToWidth($width)
62+
{
63+
$ratio = $width / $this->getWidth();
64+
$height = $this->getheight() * $ratio;
65+
$this->__resize($width, $height);
66+
}
67+
68+
public function scale($scale)
69+
{
70+
$width = $this->getWidth() * $scale / 100;
71+
$height = $this->getheight() * $scale / 100;
72+
$this->__resize($width, $height);
73+
}
74+
75+
private function __resize($width, $height)
76+
{
77+
$newImage = imagecreatetruecolor($width, $height);
78+
imagecopyresampled($newImage, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
79+
$this->image = $newImage;
80+
}
81+
}

0 commit comments

Comments
 (0)