KumbiaPHP  beta2
Framework PHP
 Todo Estructuras de Datos Namespaces Archivos Funciones Variables Páginas
deprecated.php
Ir a la documentación de este archivo.
1 <?php
32 function array_merge_overwrite($a1, $a2){
33  return $a2 + $a1;
34 }
35 
46 function array_insert(&$form, $index, $value, $key=null){
47  $ret = array();
48  $n = 0;
49  $i = false;
50  foreach($form as $keys => $val){
51  if($n!=$index){
52  $ret[$keys] = $val;
53  } else {
54  if(!$key){
55  $ret[$index] = $value;
56  $i = true;
57  } else {
58  $ret[$key] = $value;
59  $i = true;
60  }
61  $ret[$keys] = $val;
62  }
63  $n++;
64  }
65  if(!$i){
66  if(!$key){
67  $ret[$index] = $value;
68  } else {
69  $ret[$key] = $value;
70  }
71  }
72  $form = $ret;
73 }
74 
83 function array_num_insert(&$array, $index, $value) {
84  array_splice($array, $index, 0, $value);
85 }
86 
95 function value_num($a){
96  if($a<=21){
97  switch ($a){
98  case 1: return 'UNO';
99  case 2: return 'DOS';
100  case 3: return 'TRES';
101  case 4: return 'CUATRO';
102  case 5: return 'CINCO';
103  case 6: return 'SEIS';
104  case 7: return 'SIETE';
105  case 8: return 'OCHO';
106  case 9: return 'NUEVE';
107  case 10: return 'DIEZ';
108  case 11: return 'ONCE';
109  case 12: return 'DOCE';
110  case 13: return 'TRECE';
111  case 14: return 'CATORCE';
112  case 15: return 'QUINCE';
113  case 16: return 'DIECISEIS';
114  case 17: return 'DIECISIETE';
115  case 18: return 'DIECIOCHO';
116  case 19: return 'DIECINUEVE';
117  case 20: return 'VEINTE';
118  case 21: return 'VEINTIUN';
119  }
120  } else {
121  if($a<=99){
122  if($a>=22&&$a<=29)
123  return "VENTI".value_num($a % 10);
124  if($a==30) return "TREINTA";
125  if($a>=31&&$a<=39)
126  return "TREINTA Y ".value_num($a % 10);
127  if($a==40) return "CUARENTA";
128  if($a>=41&&$a<=49)
129  return "CUARENTA Y ".value_num($a % 10);
130  if($a==50) return "CINCUENTA";
131  if($a>=51&&$a<=59)
132  return "CINCUENTA Y ".value_num($a % 10);
133  if($a==60) return "SESENTA";
134  if($a>=61&&$a<=69)
135  return "SESENTA Y ".value_num($a % 10);
136  if($a==70) return "SETENTA";
137  if($a>=71&&$a<=79)
138  return "SETENTA Y ".value_num($a % 10);
139  if($a==80) return "OCHENTA";
140  if($a>=81&&$a<=89)
141  return "OCHENTA Y ".value_num($a % 10);
142  if($a==90) return "NOVENTA";
143  if($a>=91&&$a<=99)
144  return "NOVENTA Y ".value_num($a % 10);
145  } else {
146  if($a==100) return "CIEN";
147  if($a>=101&&$a<=199)
148  return "CIENTO ".value_num($a % 100);
149  if($a>=200&&$a<=299)
150  return "DOSCIENTOS ".value_num($a % 100);
151  if($a>=300&&$a<=399)
152  return "TRECIENTOS ".value_num($a % 100);
153  if($a>=400&&$a<=499)
154  return "CUATROCIENTOS ".value_num($a % 100);
155  if($a>=500&&$a<=599)
156  return "QUINIENTOS ".value_num($a % 100);
157  if($a>=600&&$a<=699)
158  return "SEICIENTOS ".value_num($a % 100);
159  if($a>=700&&$a<=799)
160  return "SETECIENTOS ".value_num($a % 100);
161  if($a>=800&&$a<=899)
162  return "OCHOCIENTOS ".value_num($a % 100);
163  if($a>=901&&$a<=999)
164  return "NOVECIENTOS ".value_num($a % 100);
165  }
166  }
167 }
175 function millones($a){
176  $a = $a / 1000000;
177  if($a==1)
178  return "UN MILLON ";
179  else
180  return value_num($a)." MILLONES ";
181 }
182 
190 function miles($a){
191  $a = $a / 1000;
192  if($a==1)
193  return "MIL";
194  else
195  return value_num($a)."MIL ";
196 }
197 
207 function money_letter($valor, $moneda, $centavos){
208  $a = $valor;
209  $p = $moneda;
210  $c = $centavos;
211  $val = "";
212  $v = $a;
213  $a = (int) $a;
214  $d = round($v - $a, 2);
215  if($a>=1000000){
216  $val = millones($a - ($a % 1000000));
217  $a = $a % 1000000;
218  }
219  if($a>=1000){
220  $val.= miles($a - ($a % 1000));
221  $a = $a % 1000;
222  }
223  $val.= value_num($a)." $p ";
224  if($d){
225  $d*=100;
226  $val.=" CON ".value_num($d)." $c ";
227  }
228  return $val;
229 }
230 
238 function to_human($num){
239  if($num<1024){
240  return $num." bytes";
241  } else {
242  if($num<1024*1024){
243  return round($num/1024, 2)." kb";
244  } else {
245  return round($num/1024/1024, 2)." mb";
246  }
247  }
248 }
249 
257 function camelize($str) {
258  $str = strtr($str, '_', ' ');
259  $str = ucwords($str);
260  $str = str_replace(' ', '', $str);
261 
262  return $str;
263 }
264 
272 function uncamelize($str) {
273 
274  return strtolower(preg_replace('/([A-Z])/', "_\\1", $str));
275 }
276 
284 function get_params($params){
285  $data = array();
286  foreach ($params as $p) {
287  if(is_string($p) && preg_match('/^(\w+): (.*)/', $p, $match)){
288  $data[$match[1]] = $match[2];
289  } else {
290  $data[] = $p;
291  }
292  }
293  return $data;
294 }
295 
296 /*
297  * Recibe una cadena como: item1,item2,item3 y retorna una como: "item1","item2","item3"
298  *
299  * @deprecated
300  * @param string $lista Cadena con Items separados por comas (,).
301  * @return string $listaEncomillada Cadena con Items encerrados en doblecomillas y separados por comas (,).
302  */
303 function encomillar_lista($lista){
304  $arrItems = explode(',', $lista);
305  $n = count($arrItems);
306  $listaEncomillada = '';
307  for ($i=0; $i<$n-1; $i++) {
308  $listaEncomillada.= "\"".$arrItems[$i]."\",";
309  }
310  $listaEncomillada.= "\"".$arrItems[$n-1]."\"";
311  return $listaEncomillada;
312 }
313 
322 function comillas($word){
323  return "'$word'";
324 }
325 
334 function highlight($sentence, $what){
335  return str_replace($what, '<strong class="highlight">'.$what.'</strong>', $sentence);
336 }
337 
345 function money($number){
346  $number = my_round($number);
347  return "$&nbsp;".number_format($number, 2, ",", ".");
348 }
349 
358 function roundnumber($n, $d = 0) {
359  $n = $n - 0;
360  if ($d === NULL) $d = 2;
361 
362  $f = pow(10, $d);
363  $n += pow(10, - ($d + 1));
364  $n = round($n * $f) / $f;
365  $n += pow(10, - ($d + 1));
366  $n += '';
367 
368  if ( $d == 0 ):
369  return substr($n, 0, strpos($n, '.'));
370  else:
371  return substr($n, 0, strpos($n, '.') + $d + 1);
372  endif;
373 }
374 
384 function my_round($number, $n=2){
385  $number = (float) $number;
386  $n = (int) $n;
387  return ActiveRecord::static_select_one("round($number, $n)");
388 }
389 
397 function copy_dir($source, $target) {
398  if (is_dir($source)) {
399 
400  if (!is_dir($target)){
401  @mkdir($target);
402  }
403 
404  $d = dir($source);
405 
406  while (false !== ($entry = $d->read())) {
407  if ($entry == '.' || $entry == '..') {
408  continue;
409  }
410 
411  $Entry = $source.'/'.$entry;
412  if (is_dir($Entry)) {
413  copy_dir($Entry, $target.'/'.$entry);
414  continue;
415  }
416  copy($Entry, $target.'/'. $entry);
417  }
418 
419  $d->close();
420  }else {
421  copy($source, $target);
422  }
423 }
424 
431 function join_path($dirs){
432  if(!is_array($dirs)) {
433  $dirs = func_get_args();
434  }
435  $n = count($dirs);
436 
437  $path= '';
438  for($i=0; $i<$n; $i++) {
439  $dir = $dirs[$i];
440  if(!empty($dir)) {
441  $path.=$dir;
442  if($i<($n-1) && $dir[strlen($dir)-1]!='/') $path.='/';
443  }
444  }
445 
446  return $path;
447 }
448 
456 function mkpath($path){
457  $path = join_path(func_get_args());
458  if(@mkdir($path) or file_exists($path)) return true;
459  return (mkpath(dirname($path)) and mkdir($path));
460 }
461 
477 function age(){
478  $params = get_params(func_get_args());
479  $error = false;
480 
481  $active_app = basename(dirname(APP_PATH));
482 
483  if(!isset($params['order'])){
484  if($kumbia_config = Config::read('config')){
485  if(preg_match('/^DD[^DMY]MM[^DMY]YYYY$/', $kumbia_config->$active_app->dbdate)){
486  $params['order'] = 'd-m-Y';
487  } elseif(preg_match('/^DD[^DMY]YYYY[^DMY]MM$/', $kumbia_config->$active_app->dbdate)){
488  $params['order'] = 'd-Y-m';
489  } elseif(preg_match('/^MM[^DMY]DD[^DMY]YYYY$/', $kumbia_config->$active_app->dbdate)) {
490  $params['order'] = 'm-d-Y';
491  } elseif(preg_match('/^MM[^DMY]YYYY[^DMY]DD$/', $kumbia_config->$active_app->dbdate)) {
492  $params['order'] = 'm-Y-d';
493  } elseif(preg_match('/^YYYY[^DMY]DD[^DMY]MM$/', $kumbia_config->$active_app->dbdate)) {
494  $params['order'] = 'Y-d-m';
495  } else {
496  $params['order'] = 'Y-m-d';
497  }
498  }
499  }
500 
501  if(isset($params['month'], $params['day'], $params['year'])){
502  $time_nac = mktime(0, 0, 0, $params['month'], $params['day'], $params['year']);
503  } elseif(isset($params['birthdate'])) {
504  if (preg_match( '/^([0-9]+)[^0-9]([0-9]+)[^0-9]([0-9]+)$/', $params['birthdate'], $date)) {
505  if($params['order'] == 'd-m-Y'){
506  if(checkdate($date[2], $date[1], $date[3])) {
507  $time_nac = mktime(0, 0, 0, $date[2], $date[1], $date[3]);
508  } else {
509  $error = true;
510  }
511  } elseif($params['order'] == 'd-Y-m'){
512  if(checkdate($date[3], $date[1], $date[2])) {
513  $time_nac = mktime(0, 0, 0, $date[3], $date[1], $date[2]);
514  } else {
515  $error = true;
516  }
517  } elseif($params['order'] == 'm-d-Y') {
518  if(checkdate($date[1], $date[2], $date[3])) {
519  $time_nac = mktime(0, 0, 0, $date[1], $date[2], $date[3]);
520  } else {
521  $error = true;
522  }
523  } elseif($params['order'] == 'm-Y-d') {
524  if(checkdate($date[1], $date[3], $date[2])) {
525  $time_nac = mktime(0, 0, 0, $date[1], $date[3], $date[2]);
526  } else {
527  $error = true;
528  }
529  } elseif($params['order'] == 'Y-d-m') {
530  if(checkdate($date[3], $date[2], $date[1])) {
531  $time_nac = mktime(0, 0, 0, $date[3], $date[2], $date[1]);
532  } else {
533  $error = true;
534  }
535  } else {
536  if(checkdate($date[2], $date[3], $date[1])) {
537  $time_nac = mktime(0, 0, 0, $date[2], $date[3], $date[1]);
538  } else {
539  $error = true;
540  }
541  }
542  } else {
543  $error = true;
544  }
545  } else {
546  $time_nac = time();
547  }
548 
549  if(isset($params['today_month'], $params['today_day'], $params['today_year'])){
550  $time = mktime(0, 0, 0, $params['today_month'], $params['today_day'], $params['today_year']);
551  } elseif(isset($params['today'])) {
552  if (preg_match( '/^([0-9]+)[^0-9]([0-9]+)[^0-9]([0-9]+)$/', $params['today'], $date)) {
553  if($params['order'] == 'd-m-Y'){
554  if(checkdate($date[2], $date[1], $date[3])) {
555  $time = mktime(0, 0, 0, $date[2], $date[1], $date[3]);
556  } else {
557  $error = true;
558  }
559  } elseif($params['order'] == 'd-Y-m'){
560  if(checkdate($date[3], $date[1], $date[2])) {
561  $time = mktime(0, 0, 0, $date[3], $date[1], $date[2]);
562  } else {
563  $error = true;
564  }
565  } elseif($params['order'] == 'm-d-Y') {
566  if(checkdate($date[1], $date[2], $date[3])) {
567  $time = mktime(0, 0, 0, $date[1], $date[2], $date[3]);
568  } else {
569  $error = true;
570  }
571  } elseif($params['order'] == 'm-Y-d') {
572  if(checkdate($date[1], $date[3], $date[2])) {
573  $time = mktime(0, 0, 0, $date[1], $date[3], $date[2]);
574  } else {
575  $error = true;
576  }
577  } elseif($params['order'] == 'Y-d-m') {
578  if(checkdate($date[3], $date[2], $date[1])) {
579  $time = mktime(0, 0, 0, $date[3], $date[2], $date[1]);
580  } else {
581  $error = true;
582  }
583  } else {
584  if(checkdate($date[2], $date[3], $date[1])) {
585  $time = mktime(0, 0, 0, $date[2], $date[3], $date[1]);
586  } else {
587  $error = true;
588  }
589  }
590  } else {
591  $error = true;
592  }
593  } else {
594  $time = time();
595  }
596 
597  if(!$error){
598  $edad = idate('Y' ,$time) - idate('Y' ,$time_nac);
599  } else {
600  $edad = 0;
601  }
602 
603  if($edad>0){
604  if(idate('m' ,$time) < idate('m' ,$time_nac)){
605  $edad--;
606  } else if(idate('m' ,$time) == idate('m' ,$time_nac)){
607  if(idate('d' ,$time) < idate('d' ,$time_nac)){
608  $edad--;
609  }
610  }
611  } elseif($edad<0) {
612  $edad = 0;
613  }
614 
615  return $edad;
616 }
617 
625 function remove_dir($dir){
629  $dir = join_path(func_get_args());
630 
634  if($files = array_merge(glob(join_path($dir,'*')), glob(join_path($dir,'.*')))) {
638  foreach($files as $file) {
642  if(!preg_match("/^.*\/?[\.]{1,2}$/",$file)) {
643  if(is_dir($file)) {
644  remove_dir($file);
645  } else {
646  unlink($file);
647  }
648  }
649  }
650  }
651  return rmdir($dir);
652 }
653 
660 function get_arguments($params) {
661  $args = array();
662  foreach($params as $k=>$v) {
663  if(is_numeric($k)) {
664  array_push($args, $v);
665  } else {
666  array_push($args, "$k: $v");
667  }
668  }
669  return $args;
670 }
671 
678 function lcfirst($s) {
679  return strtolower(substr($s, 0, 1)) . substr($s, 1);
680 }
681 
687 function object_from_params($s='') {
688  $params = is_array($s) ? $s : get_params(func_get_args());
689  $obj = (object) $params;
690  return $obj;
691 }
692 
700 function mirror_range($start, $end, $step=1) {
701  $args = func_get_args();
702  $arr = call_user_func_array('range', $args);
703  $mirror = array();
704  foreach($arr as $v) {
705  $mirror[$v] = $v;
706  }
707  return $mirror;
708 }
709 
716 function file_extension($filename) {
717  $ext = strchr($filename,".");
718  return $ext;
719 }
720 
727 function get_server_url($route) {
728  $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] ? 'https' : 'http';
729  return "$protocol://{$_SERVER['SERVER_NAME']}".get_kumbia_url($route);
730 }
731 
732 
738 function use_helper($helper) {
739  call_user_func_array(array('view' , 'helpers'), func_get_args());
740 }
741 
742 
748 function content(){
749  View::content();
750 }
751 
761 function truncate($text, $word, $number=0){
762  if($number){
763  $word = substr($word, 0, $number);
764  } else {
765  $word = rtrim($word);
766  }
767 
768  return $word.$text;
769 }
770 
779 function render_partial($partial, $time=false, $params=array()) {
780  View::partial($partial, $time, $params);
781 }
782 
790 function redirect_to($action, $seconds = 0.01){
791  $seconds*=1000;
792  return xhtml_tag('script', 'type: text/javascript', "content: setTimeout('window.location=\"?/$action\"', $seconds)");
793 }