common.inc.php (2926B)
1 <?php 2 3 use util\Session; 4 5 6 /** 7 * F�gt einen Slash ("/") an das Ende an, sofern nicht bereits vorhanden. 8 * 9 * @param String $pfad 10 * @return Pfad mit angeh�ngtem Slash. 11 */ 12 function slashify($pfad) 13 { 14 if ( substr($pfad,-1,1) == '/') 15 return $pfad; 16 else 17 return $pfad.'/'; 18 } 19 20 function convertToXmlAttribute( $value ) 21 { 22 return utf8_encode( htmlspecialchars( $value ) ) ; 23 } 24 25 26 /** 27 * Ermittelt die aktuelle Systemzeit als Unix-Timestamp.<br> 28 * Unix-Timestamp ist immer bezogen auf GMT. 29 * - 30 * @return Unix-Timestamp der aktuellen Zeit 31 */ 32 function now() 33 { 34 return time(); 35 } 36 37 38 39 /** 40 * Erzeugt f�r eine Zahl eine Schreibweise mit Vorzeichen.<br> 41 * '-2' bleibt '-2'<br> 42 * '2' wird zu '+2'<br> 43 */ 44 function vorzeichen( $nr ) 45 { 46 return intval($nr)<0 ? $nr : '+'.$nr; 47 } 48 49 50 51 /** 52 * Stellt fest, ob das System in einem schreibgeschuetzten Zustand ist. 53 * 54 * @return boolean true, falls schreibgeschuetzt, sonst false 55 */ 56 function readonly() 57 { 58 // Gesamtes CMS ist readonly. 59 if ( config('security','readonly') ) 60 return true; 61 62 // Aktuelle Datenbankverbindung ist readonly. 63 $db = db(); 64 if ( isset($db->conf['readonly']) && $db->conf['readonly'] ) 65 return true; 66 67 return false; 68 } 69 70 71 72 73 74 /** 75 * Generiert aus der Session-Id einen Token. 76 * @return Token 77 */ 78 function token() 79 { 80 return substr(session_id(),-10); 81 } 82 83 84 /** 85 * Ermittelt, ob der Wert 'true' oder 'false' entspricht. 86 * 87 * Anders als beim PHP-Cast auf boolean wird hier auch die 88 * Zeichenkette 'true' als wahr betrachtet. 89 * 90 * @param val mixed 91 * @return boolean 92 */ 93 function istrue( $val ) 94 { 95 if ( is_bool($val) ) 96 return $val; 97 elseif( is_numeric($val) ) 98 return $val != 0; 99 elseif( is_string($val) ) 100 return $val == 'true' || $val == 'yes' || $val == '1'; 101 else 102 return false; 103 } 104 105 106 107 /** 108 * Erzeugt einen Link auf die OpenRat-lokale CSS-Datei 109 * @param $name Name der Style-Konfiguration. Default: 'default'. 110 */ 111 function css_link( $name='default' ) 112 { 113 global $conf; 114 115 // Falls Style-Konfiguration unbekannt, dann Fallback auf default. 116 if ( ! isset($conf['style'][$name])) 117 $name = $conf['interface']['style']['default']; 118 119 120 return encode_array($conf['style'][$name]); 121 } 122 123 124 /** 125 * Encodiert ein Array für eine URL. 126 * 127 * @param $args URL-Parameter 128 */ 129 function encode_array( $args ) 130 { 131 if ( !is_array($args) ) 132 return ''; 133 134 $out = array(); 135 136 foreach( $args as $name => $value ) 137 $out[] = $name.'='.urlencode($value); 138 139 return implode('&',$out); 140 } 141 142 143 function not($var) { 144 return !$var; 145 } 146 147 /** 148 * Liefert die Datenbankverbindung fuer die aktuelle Sitzung. 149 * 150 * @return \database\Database 151 * @deprecated use db() 152 */ 153 function db_connection() 154 { 155 156 return db(); 157 } 158 159 /** 160 * Liefert die Datenbankverbindung fuer die aktuelle Sitzung. 161 * 162 * @return \database\Database 163 */ 164 function db() 165 { 166 167 $db = Session::getDatabase(); 168 169 if ( ! is_object($db)) 170 throw new RuntimeException('no database available'); 171 172 return $db; 173 } 174 175 176 177 178 ?>