]>
git.datanom.net - webcal.git/blob - utils/helper.php
3 include_once 'config.inc.php' ;
4 require_once 'persistens.php' ;
10 $VERSION = MAJOR
. "." . MINOR
. "." . MICRO
;
11 $CURRENT_VERSION = $VERSION ;
12 $PREFIX = TOP_FOLDER
. "/install/" . DBDRIVER
;
14 "173" => "db_upgrade_0_7_3.sql" ,
15 "174" => "db_upgrade_0_7_4.sql" ,
16 "175" => "db_upgrade_0_7_5.sql" ,
17 "180" => "db_upgrade_0_8_0.sql" ,
18 "181" => "db_upgrade_0_8_1.sql" ,
22 if ( $pwd [ strlen ( $pwd )- 1 ] == '/' )
23 $pwd = substr ( $pwd , 0 , - 1 );
25 function string2int ( $str ) {
28 if ( is_string ( $str )) {
29 $parts = explode ( "." , $str );
31 for ( $i = 0 ; $i < count ( $parts ); $i ++
) {
32 $num = ( $i == 0 ) ?
$parts [ $i ] +
1 : $parts [ $i ];
33 $str +
= ( pow ( 10 , count ( $parts ) - $i - 1 ) * $num );
39 function getServerUrl ( $root = WEB_ROOT
, $cwd = "" ) {
40 $root = (! empty ( $root ) && $root [ 0 ] == '/' ) ?
substr ( $root , 1 ) : $root ;
41 $root = (! empty ( $root ) && $root [ strlen ( $root ) - 1 ] == '/' ) ?
substr ( $root , 0 , - 1 ) : $root ;
42 $cwd = (! empty ( $cwd ) && $cwd [ 0 ] == '/' ) ?
substr ( $cwd , 1 ) : $cwd ;
43 $cwd = (! empty ( $cwd ) && $cwd [ strlen ( $cwd ) - 1 ] == '/' ) ?
substr ( $cwd , 0 , - 1 ) : $cwd ;
45 //echo var_export($_SERVER, true);
46 $protocol = (( isset ( $_SERVER [ 'HTTPS' ]) && ! empty ( $_SERVER [ 'HTTPS' ])) ||
( isset ( $_SERVER [ 'HTTPS' ]) && strcasecmp ( "on" , $_SERVER [ 'HTTPS' ]) === 0 )
47 ||
( isset ( $_SERVER [ 'HTTP_SCHEME' ]) && strcasecmp ( "https" , $_SERVER [ 'HTTP_SCHEME' ]) === 0 )) ?
"https" : "http" ;
48 //echo "$protocol<br/>";
49 $server = ( $_SERVER [ 'SERVER_PORT' ] == 80 ||
$_SERVER [ 'SERVER_PORT' ] == 443 ) ?
50 $_SERVER [ 'SERVER_NAME' ] : $_SERVER [ 'SERVER_NAME' ]. ':' . $_SERVER [ 'SERVER_PORT' ];
51 $url = (! empty ( $cwd )) ?
" $protocol :// $server / $cwd " : " $protocol :// $server " ;
56 function getServerUri () {
60 function createKey ( $key ) {
61 $td = mcrypt_module_open ( 'rijndael-256' , '' , 'ofb' , '' );
62 $public = mcrypt_create_iv ( mcrypt_enc_get_iv_size ( $td ), MCRYPT_DEV_RANDOM
);
63 $ks = mcrypt_enc_get_key_size ( $td );
64 mcrypt_module_close ( $td );
67 $secret = substr ( $key , 0 , $ks );
68 return array ( $secret , $public );
71 function encode ( $text ) {
72 /* Intialize encryption */
73 $td = mcrypt_module_open ( 'rijndael-256' , '' , 'ofb' , '' );
74 $iv = $_SESSION [ 'authenticate' ]-> getPublicKey ();
75 $key = $_SESSION [ 'authenticate' ]-> getSecretKey ();
77 mcrypt_generic_init ( $td , $key , $iv );
80 $ciffer = mcrypt_generic ( $td , $text );
81 $encrypted = quoted_printable_encode ( $ciffer );
83 /* Terminate encryption handler */
84 mcrypt_generic_deinit ( $td );
85 mcrypt_module_close ( $td );
90 function decode ( $text ) {
91 $td = mcrypt_module_open ( 'rijndael-256' , '' , 'ofb' , '' );
92 $iv = $_SESSION [ 'authenticate' ]-> getPublicKey ();
93 $key = $_SESSION [ 'authenticate' ]-> getSecretKey ();
95 /* Initialize encryption module for decryption */
96 mcrypt_generic_init ( $td , $key , $iv );
98 /* Decrypt encrypted string */
99 $ciffer = quoted_printable_decode ( $text );
100 $decrypted = mdecrypt_generic ( $td , $ciffer );
102 /* Terminate decryption handle and close module */
103 mcrypt_generic_deinit ( $td );
104 mcrypt_module_close ( $td );
109 function implode_cal ( $text ) {
110 $infos = explode ( " \n " , $text );
111 foreach ( $infos as $info ) {
112 $row = explode ( '=' , $info );
113 $result [ $row [ 0 ]] = $row [ 1 ];
118 // taken from roundcubemail
119 if (! function_exists ( "quoted_printable_encode" )) {
120 function quoted_printable_encode ( $text ) {
121 $length = strlen ( $text );
122 for ( $whitespace = "" , $line = 0 , $encode = "" ,
123 $index = 0 ; $index < $length ; $index ++
) {
124 $character = substr ( $text , $index , 1 );
125 $order = Ord ( $character );
130 if ( $header_charset == "" ) {
131 $previous_whitespace = $whitespace ;
132 $whitespace = $character ;
144 if ( $whitespace != "" ) {
149 $encoded .= sprintf ( "= %02X " , Ord ( $whitespace ));
153 $encoded .= $character ;
157 if ( $order > 127 ||
$order < 32 ||
$character == "="
158 ||
( $character == "?" ||
$character == "_" ||
159 $character == "(" ||
$character == ")" ))
163 if ( $whitespace != "" ) {
168 $encoded .= $whitespace ;
172 if ( $character != "" ) {
174 $character = sprintf ( "= %02X " , $order );
179 if ( $line +
$encoded_length > 75 ) {
183 $encoded .= $character ;
184 $line +
= $encoded_length ;
187 if ( $whitespace != "" ) {
190 $encoded .= sprintf ( "= %02X " , Ord ( $whitespace ));
196 function newUpdates () {
197 global $VERSION , $CURRENT_VERSION ;
199 $con = Persistens
:: getInstance ( DBDRIVER
);
201 $res = $con -> getVersion ();
203 catch ( Exception
$e ) {
206 $version = $res [ 'version' ];
207 $version = string2int ( $version );
208 if (! is_numeric ( $version )) {
209 ReportError ( "Invalid version format" );
212 $CURRENT_VERSION = $version ;
213 //file_put_contents('/tmp/updates', string2int($VERSION)." > $version", FILE_APPEND);
214 return string2int ( $VERSION ) > $version ;
218 global $VERSION , $PATCH_SET , $CURRENT_VERSION , $PREFIX ;
221 $version = string2int ( $CURRENT_VERSION );
222 $con = Persistens
:: getInstance ( DBDRIVER
);
224 $res = $con -> getVersion ();
226 catch ( Exception
$e ) {
230 if (( $num = $con -> nextTableNumber ( 'backup' )) > 0 )
233 if ( $version < 173 ) {
234 if (( $res = $con -> execute (
235 "create table $table as select * from calendar" )) !== true ) {
239 $rows = $con -> getCalendarConfig ();
240 if (! is_array ( $rows )) {
244 foreach ( $rows as $row ) {
245 if ( function_exists ( quoted_printable_encode
))
246 $ciffer = quoted_printable_encode ( $row [ 'config' ]);
248 $ciffer = webcal_quoted_printable_encode ( $row [ 'config' ]);
249 if (( $res = $con -> execute ( "begin transaction" )) !== true ) {
253 if (( $res = $con -> execute (
254 "update calendar set config = ' $ciffer ' where id = " .
255 $row [ 'id' ])) !== true ) {
256 $con -> execute ( "rollback" );
257 ReportError ( $res . "<br/>A backup of your calendar data can be found in table backup" );
261 $con -> execute ( "commit" );
263 if ( $version >= 174 ) {
264 // remove pgsql.php from root. Accidentally placed there in release 0.7.4
265 if ( file_exists ( TOP_FOLDER
. "/pgsql.php" ))
266 unlink ( TOP_FOLDER
. "/pgsql.php" );
267 // patch config.inc.php
268 if ( substr ( PHP_OS
, 0 , 3 ) !== 'WIN' ) {
270 $cwd = TOP_FOLDER
. '/install' ;
272 if ( $version < 181 ) {
273 exec ( "patch -p0 < config.inc.php.patch" );
275 if ( $version > 180 ) {
276 exec ( "patch -p0 < config.inc.php1.patch" );
281 foreach ( $PATCH_SET as $set => $file ) {
283 //echo "$set -> $file<br/>";
284 if ( $version < $set ) {
285 //echo $PREFIX."_".$file."<br/>";
286 if (! file_exists ( $PREFIX . "_" . $file ))
288 $sql = file_get_contents ( $PREFIX . "_" . $file );
289 $raw_lines = explode ( " \n " , $sql );
290 foreach ( $raw_lines as $line ) {
291 if ( preg_match ( "/^--/" , $line ))
295 $lines = explode ( ";" , join ( " \n " , $content ));
296 if ( count ( $lines ) > 0 ) {
297 if (( $res = $con -> execute ( "begin transaction" )) !== true ) {
301 foreach ( $lines as $line ) {
303 if ( preg_match ( "/^\s*$/" , $line ) ||
preg_match ( "/^--/" , $line ))
305 if (( $res = $con -> execute ( $line )) !== true ) {
307 $con -> execute ( "rollback" );
311 $con -> execute ( "commit" );
319 function ReportError ( $msg ) {
320 // be sure that the supplied parameter is a string and not empty
321 if ( empty ( $msg ) ||
! is_string ( $msg )) {
322 throw new ErrorException ( 'Invalid parameter supplied to ReportError' , 0 , E_ERROR
);
325 // retrieve error settings
326 $display = strtolower ( ini_get ( 'display_errors' ));
327 $log = strtolower ( ini_get ( 'log_errors' ));
329 // check if we're displaying errors
330 if ( $display === 'on' ||
$display === '1' ||
$display === 1 ||
$display === 'true' ||
$display === true ) {
335 if ( $pwd [ strlen ( $pwd )- 1 ] == '/' )
336 $pwd = substr ( $pwd , 0 , - 1 );
337 print '<?xml version="1.0" encoding="utf-8"?>
338 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
339 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
340 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
342 <title>Web Calendar</title>
343 <link rel="stylesheet" type="text/css"
344 href="' . $pwd . '/css/top_level.css" />
345 <link rel="shortcut icon"
346 href="' . $pwd . '/pixmaps/favicon.ico" />
351 The application has triggered an error which is not
352 recoverable. The execution has therefore been cancelled.
354 The error is logged and the webmaster will handle
355 the error in due time.
357 To help fix the application you are welcome to notify
358 the <a href="mailto:' . $_SERVER [ 'SERVER_ADMIN' ]. '
359 ?subject=' . TITLE
. ': error report[' .
360 $_SERVER [ 'SERVER_NAME' ]. ']">webmaster</a>
361 by email with a detailed description containing the
362 following information:
364 1) What did you do just before this message occurred<br/>
365 2) What did you expect to happen<br/>
366 3) Your browser name and version number.<br/>
373 // check if we're logging errors
374 if ( $log === 'on' ||
$log === '1' ||
$log === 1 ||
$log === 'true' ||
$log === true ) {
375 $result = error_log ( $msg );
377 // check for error while logging
379 throw new ErrorException ( 'Attempt to write message to error log failed in ReportError' , 0 , E_ERROR
);
384 function create_user_data ( $uid , $pwd , $role ) {
388 $data [ 'pwd' ] = sha1 ( $pwd );
389 $data [ 'userrole' ] = $role ;
390 $keys = createKey ( sha1 ( "{ $data ['uid']}{ $data ['pwd']}" ));
391 $data [ 'seckey' ] = $keys [ 0 ];
392 $data [ 'pubkey' ] = $keys [ 1 ];
393 $data [ 'timezone' ] = TIMEZONE
;
394 $data [ 'view' ] = VIEW_STYLE
;
395 $data [ 'timeout' ] = TIMEOUT
;
396 $data [ 'week_start' ] = WEEK_START_SUNDAY
;
397 $data [ 'start' ] = START_HOUR
;
398 $data [ 'end' ] = END_HOUR
;
403 function popup_window ( $text = '' , $redirect = NULL , $form_elem = array (), $title = NULL ) {
404 $con = Persistens
:: getInstance ( DBDRIVER
);
405 if (! is_array ( $res = $con -> getVersion ())) {
409 $title = ( $title ) ?
$title : TITLE
;
411 if ( count ( $form_elem ) < 1 ) {
416 $form = key ( $form_elem );
417 $input = $form_elem [ $form ];
420 $referer = ( $redirect ) ?
urldecode ( $redirect ) : WEB_ROOT
;
421 //print "$referer<br/>";
425 <?xml version="1.0" encoding="utf-8"?>
426 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
427 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
428 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
430 <title> $title </title>
431 <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8"/>
432 <meta http-equiv="content-style-type" content="text/css"/>
433 <link rel="stylesheet" type="text/css" href=" $pwd /css/top_level.css" />
434 <link rel="shortcut icon" href=" $pwd /pixmaps/favicon.ico" />
435 <style type="text/css">
437 #display_overlay_holder {
445 #display_overlay_bg {
451 background-color:#000000;
453 filter: alpha(opacity=85);
470 background-color: #CCCCCC;
478 <script type="text/javascript" src=" $pwd /js/helper.js"></script>
480 <body onload="show_the_overlay()">
481 <table style="width: 100%;">
483 <td style="width: 33%"><img src=" $pwd /pixmaps/calendar.png" alt="calendar.png" /></td>
484 <td style="width: 33%; text-align: center;"><a href=" $pwd /logout.php"><img style="border: 0" src=" $pwd /pixmaps/exit.png" width="32" height="32" alt="Logout" /><br/>Logout</a></td>
485 <td style="text-align: right"><span style="font-size: 1.6em">DAViCal Web Calendar</span><br/> - A Web Interface for <a href="javascript: newwin('http://www.davical.org/');">DAViCal</a></td>
489 $display = <<<_DISPLAY
490 <div id="display_overlay_holder">
491 <div id="display_overlay_bg" />
492 <div id="display_horizon">
493 <div id="display_content">
494 <div id="text_content">
497 <p style="text-align: center;">
498 <button type="button" onclick="hide_the_overlay(' $referer ')">Cancel</button>
508 $title { $res [0]} - © 2010, 2011 Michael Rasmussen<br/>Released under GPLv3
509 <a href="http://validator.w3.org/check?uri=referer">
510 <img src="http://www.w3.org/Icons/valid-xhtml10-blue.png"
511 alt="Valid XHTML 1.0 Strict" height="31" width="88" />
513 <a href="http://jigsaw.w3.org/css-validator/check/referer">
514 <img src="http://www.w3.org/Icons/valid-css2-blue.png"
515 alt="Valid CSS 2.0" height="31" width="88" />
522 include TOP_FOLDER.'/include/menu.inc.php';
523 print "<div id= \" ui \" > </div>";
526 print "</body></html>";
528 return ob_get_clean();
531 function construct_URL( $query_string , $attributes = array()) {
532 $test = trim( $query_string );
537 $query_str = urldecode( $query_string );
538 //print " $query_str <br/>";
539 $q = explode('&', $query_str );
540 //print_r( $q ); echo "<br/>";
541 foreach ( $q as $elem ) {
542 $s = explode('=', $elem );
543 //print_r( $s ); echo "<br/>";
544 if (! $current && in_array( $s [0], $attributes )) {
546 $key = array_shift( $s );
547 $value = array_shift( $s );
549 //print "kv: $key $value <br/>";
551 $value .= array_shift( $s );
553 $value .= array_shift( $s );
558 $key = array_shift( $s );
559 $value = array_shift( $s );
561 $query [ $key ] = $value ;
562 //print_r( $query ); echo "<br/>";
565 $value = $query [ $current ];
567 $value .= array_shift( $s );
569 $value .= array_shift( $s );
571 $query [ $current ] = $value ;
573 //print_r( $query ); echo "<br/>";
576 $key = array_shift( $s );
577 $value = array_shift( $s );
578 $query [ $key ] = $value ;
579 //print_r( $query ); echo "<br/>";
582 //print_r( $query ); echo "<br/>";
584 // urlencode if nessasary
585 foreach ( $query as $key => $value ) {
586 if (strpos( $value , '&') !== FALSE)
587 $value = urlencode( $value );
588 $query_array [ $key ] = $value ;
593 //Begin main function definition
594 function ErrorsAsExceptions( $level , $msg , $fileName , $lineNumber ) {
595 // do nothing if error reporting is turned off
596 if (error_reporting() === 0) {
600 // be sure received error is supposed to be reported
601 if (error_reporting() & $level ) {
603 // report error to appropriate channels
604 ReportError(/* $reportMsg */ $msg );
606 catch (ErrorException $e ) {
607 // ignore errors while reporting
610 // go ahead and throw the exception
611 throw new ErrorException( $msg , 0, $level , $fileName , $lineNumber );
615 set_error_handler('ErrorsAsExceptions');
This page took 0.140818 seconds and 6 git commands to generate.