<?php
class
Helper{
public
static
function
getOS(){
if
(PATH_SEPARATOR ==
':'
){
return
'Linux'
; }
else
{
return
'Windows'
; } }
public
static
function
microtime_float() { list (
$usec
,
$sec
) =
explode
(
" "
, microtime () );
return
(( float )
$usec
+ ( float )
$sec
); }
public
static
function
truncate_utf8_string(
$string
,
$length
,
$etc
=
'...'
) {
$result
=
''
;
$string
= html_entity_decode ( trim (
strip_tags
(
$string
) ), ENT_QUOTES,
'UTF-8'
);
$strlen
=
strlen
(
$string
);
for
(
$i
= 0; ((
$i
<
$strlen
) && (
$length
> 0));
$i
++) {
if
(
$number
=
strpos
(
str_pad
(
decbin
( ord (
substr
(
$string
,
$i
, 1 ) ) ), 8,
'0'
, STR_PAD_LEFT ),
'0'
)) {
if
(
$length
< 1.0) {
break
; }
$result
.=
substr
(
$string
,
$i
,
$number
);
$length
-= 1.0;
$i
+=
$number
- 1; }
else
{
$result
.=
substr
(
$string
,
$i
, 1 );
$length
-= 0.5; } }
$result
= htmlspecialchars (
$result
, ENT_QUOTES,
'UTF-8'
);
if
(
$i
<
$strlen
) {
$result
.=
$etc
; }
return
$result
; }
public
static
function
scanfDir(
$dir
=
''
,
$all
= false, &
$ret
=
array
()){
if
( false !== (
$handle
= opendir (
$dir
))) {
while
( false !== (
$file
= readdir (
$handle
)) ) {
if
(!in_array(
$file
,
array
(
'.'
,
'..'
,
'.git'
,
'.gitignore'
,
'.svn'
,
'.htaccess'
,
'.buildpath'
,
'.project'
))) {
$cur_path
=
$dir
.
'/'
.
$file
;
if
(
is_dir
(
$cur_path
)) {
$ret
[
'dirs'
][] =
$cur_path
;
$all
&& self::scanfDir(
$cur_path
,
$all
,
$ret
); }
else
{
$ret
[
'files'
] [] =
$cur_path
; } } }
closedir
(
$handle
); }
return
$ret
; }
public
static
function
sendMail(
$toemail
=
''
,
$subject
=
''
,
$message
=
''
) {
$mailer
= Yii::createComponent (
'application.extensions.mailer.EMailer'
);