Changeset 1010
- Timestamp:
- 07/02/08 23:05:06 (5 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/swisscenter/base/swisscenter_configuration.php
r853 r1010 67 67 { 68 68 if ( !in_array($row["NAME"],$exceptions) ) 69 $this->xml->appendChild($xpath,'<setting name="'.$row["NAME"].'">'. $row["VALUE"].'</setting>');69 $this->xml->appendChild($xpath,'<setting name="'.$row["NAME"].'">'.utf8_encode(htmlspecialchars($row["VALUE"])).'</setting>'); 70 70 } 71 71 } … … 80 80 { 81 81 $xpath = $this->xml->appendChild($this->settings_path,'<users />'); 82 $data = db_toarray("select u.user_id, u.name username, c.name certificate, c.scheme, u.pin from users u, certificates c where u.maxcert = c.cert_id");83 if ($data !== false && count($data)>0) 84 { 85 foreach ($data as $row) 86 { 87 $user_path = $this->xml->appendChild($xpath,'<user name="'. $row["USERNAME"].'"/>');82 $data = db_toarray("select u.user_id, u.name username, c.name certificate, c.scheme, u.pin, u.admin from users u, certificates c where u.maxcert = c.cert_id"); 83 if ($data !== false && count($data)>0) 84 { 85 foreach ($data as $row) 86 { 87 $user_path = $this->xml->appendChild($xpath,'<user name="'.utf8_encode(htmlspecialchars($row["USERNAME"]).'"/>')); 88 88 $this->xml->appendChild($user_path, '<max_cert scheme="'.$row["SCHEME"].'">'.$row["CERTIFICATE"].'</max_cert>'); 89 89 $this->xml->appendChild($user_path, '<pin>'.$row["PIN"].'</pin>'); 90 $this->xml->appendChild($user_path, '<admin>'.$row["ADMIN"].'</admin>'); 90 91 $pref_path = $this->xml->appendChild($user_path, '<preferences />'); 91 92 $prefs = db_toarray("select * from user_prefs where user_id=$row[USER_ID]"); … … 93 94 { 94 95 foreach ($prefs as $pref) 95 $this->xml->appendChild($pref_path,'<setting name="'.$pref["NAME"].'">'. $pref["VALUE"].'</setting>');96 $this->xml->appendChild($pref_path,'<setting name="'.$pref["NAME"].'">'.utf8_encode(htmlspecialchars($pref["VALUE"])).'</setting>'); 96 97 } 97 98 } … … 120 121 $cert_xpath = $this->xml->appendChild( $scheme_xpath,'<certificate name="'.$row["NAME"].'" />'); 121 122 $this->xml->appendChild( $cert_xpath,'<rank>'.$row["RANK"].'</rank>'); 122 $this->xml->appendChild( $cert_xpath,'<description>'. $row["DESCRIPTION"].'</description>');123 $this->xml->appendChild( $cert_xpath,'<description>'.utf8_encode(htmlspecialchars($row["DESCRIPTION"])).'</description>'); 123 124 } 124 125 } … … 135 136 { 136 137 $xpath = $this->xml->appendChild($this->settings_path,'<categories />'); 137 $data = db_toarray("select * from categories");138 $data = db_toarray("select c.cat_name, p.cat_name PARENT, c.download_info, c.parent_id from categories c, categories p where c.parent_id=p.cat_id"); 138 139 if ($data !== false && count($data)>0) 139 140 { … … 141 142 { 142 143 $cat_xpath = $this->xml->appendChild( $xpath,'<category />'); 143 $this->xml->appendChild($cat_xpath,'<name>'.$row["CAT_NAME"].'</name>'); 144 $this->xml->appendChild($cat_xpath,'<name>'.utf8_encode(htmlspecialchars($row["CAT_NAME"])).'</name>'); 145 if ( $row["PARENT_ID"] > 0 ) 146 $this->xml->appendChild($cat_xpath,'<parent>'.utf8_encode(htmlspecialchars($row["PARENT"])).'</parent>'); 147 else 148 $this->xml->appendChild($cat_xpath,'<parent />'); 144 149 $this->xml->appendChild($cat_xpath,'<download_info>'.$row["DOWNLOAD_INFO"].'</download_info>'); 145 150 } … … 184 189 $loc_xpath = $this->xml->appendChild( $xpath,'<location />'); 185 190 $this->xml->appendChild( $loc_xpath, '<type>'.$row["MEDIA_NAME"].'</type>'); 186 $this->xml->appendChild( $loc_xpath, '<path>'. $row["NAME"].'</path>');191 $this->xml->appendChild( $loc_xpath, '<path>'.utf8_encode(htmlspecialchars($row["NAME"])).'</path>'); 187 192 $this->xml->appendChild( $loc_xpath, '<default_certificate scheme="'.$row["SCHEME"].'">'.$row["CERTIFICATE"].'</default_certificate>'); 188 $this->xml->appendChild( $loc_xpath, '<category>'.$row["CAT_NAME"].'</category>'); 193 $this->xml->appendChild( $loc_xpath, '<category>'.utf8_encode(htmlspecialchars($row["CAT_NAME"])).'</category>'); 194 } 195 } 196 } 197 198 /** 199 * Inserts the tv expressions into the XML document at the specified xpath location. 200 * 201 */ 202 203 function export_tv_expressions() 204 { 205 $xpath = $this->xml->appendChild($this->settings_path,'<tv_expressions />'); 206 $data = db_toarray("select pos, expression from tv_expressions order by pos"); 207 if ($data !== false && count($data)>0) 208 { 209 foreach ($data as $row) 210 { 211 $loc_xpath = $this->xml->appendChild( $xpath,'<expression />'); 212 $this->xml->appendChild( $loc_xpath, '<pos>'.$row["POS"].'</pos>'); 213 $this->xml->appendChild( $loc_xpath, '<expression>'.utf8_encode(htmlspecialchars($row["EXPRESSION"])).'</expression>'); 214 } 215 } 216 } 217 218 /** 219 * Inserts the rss subscription details into the XML document at the specified xpath location. 220 * 221 */ 222 223 function export_rss_subscriptions() 224 { 225 $xpath = $this->xml->appendChild($this->settings_path,'<rss_subscriptions />'); 226 $data = db_toarray("select rs.*, mt.media_name 227 from rss_subscriptions rs, media_types mt 228 where rs.type = mt.media_id"); 229 if ($data !== false && count($data)>0) 230 { 231 foreach ($data as $row) 232 { 233 $loc_xpath = $this->xml->appendChild( $xpath,'<subscription />'); 234 $this->xml->appendChild( $loc_xpath, '<type>'.$row["MEDIA_NAME"].'</type>'); 235 $this->xml->appendChild( $loc_xpath, '<url>'.utf8_encode(htmlspecialchars($row["URL"])).'</url>'); 236 $this->xml->appendChild( $loc_xpath, '<title>'.utf8_encode(htmlspecialchars($row["TITLE"])).'</title>'); 237 $this->xml->appendChild( $loc_xpath, '<update>'.$row["UPDATE_FREQUENCY"].'</update>'); 238 $this->xml->appendChild( $loc_xpath, '<cache>'.$row["CACHE"].'</cache>'); 239 } 240 } 241 } 242 243 /** 244 * Inserts the tvid details into the XML document at the specified xpath location. 245 * 246 */ 247 248 function export_tvid_prefs() 249 { 250 $xpath = $this->xml->appendChild($this->settings_path,'<tvid_prefs />'); 251 $data = db_toarray("select * from tvid_prefs where tvid_custom is not null"); 252 if ($data !== false && count($data)>0) 253 { 254 foreach ($data as $row) 255 { 256 $loc_xpath = $this->xml->appendChild( $xpath,'<tvid />'); 257 $this->xml->appendChild( $loc_xpath, '<player>'.$row["PLAYER_TYPE"].'</player>'); 258 $this->xml->appendChild( $loc_xpath, '<tvid>'.$row["TVID_SC"].'</tvid>'); 259 $this->xml->appendChild( $loc_xpath, '<tvid_custom>'.$row["TVID_CUSTOM"].'</tvid_custom>'); 189 260 } 190 261 } … … 204 275 $this->export_artfiles(); 205 276 $this->export_media_locations(); 277 $this->export_tv_expressions(); 278 $this->export_rss_subscriptions(); 279 $this->export_tvid_prefs(); 206 280 } 207 281 … … 213 287 function import_categories() 214 288 { 289 $cat_parent = array(); 215 290 foreach ($this->xml->match('/swisscenter[1]/config[1]/categories[1]/category') as $abspath) 216 291 { 217 $name = $this->xml->getData($abspath.'/name[1]'); 292 $name = html_entity_decode(utf8_decode($this->xml->getData($abspath.'/name[1]'))); 293 $parent = html_entity_decode(utf8_decode($this->xml->getData($abspath.'/parent[1]'))); 294 if ( !empty($parent) ) $cat_parent[$name] = $parent; 218 295 $download = $this->xml->getData($abspath.'/download_info[1]'); 219 if (db_value("select count(*) from categories where cat_name = '$name'") == 0) 220 db_insert_row('categories',array("cat_name"=>$name, "download_info"=>$download)); 296 if (db_value("select count(*) from categories where cat_name = '".db_escape_str(un_magic_quote($name))."'") == 0) 297 db_insert_row('categories',array("cat_name"=>$name, "parent_id"=>0, "download_info"=>$download)); 298 } 299 foreach ($cat_parent as $name=>$parent) 300 { 301 $cat_id = db_value("select cat_id from categories where cat_name = '".db_escape_str(un_magic_quote($name))."'"); 302 $parent_id = db_value("select cat_id from categories where cat_name = '".db_escape_str(un_magic_quote($parent))."'"); 303 db_sqlcommand("update categories set parent_id=$parent_id where cat_id=$cat_id"); 221 304 } 222 305 } … … 235 318 $value = $this->xml->getData($abspath); 236 319 if (db_value("select count(*) from system_prefs where name = '".$attrib["NAME"]."'") == 0) 237 db_insert_row('system_prefs',array("name"=>$attrib["NAME"], "value"=> $value));320 db_insert_row('system_prefs',array("name"=>$attrib["NAME"], "value"=>addslashes($value))); 238 321 else 239 db_sqlcommand("update system_prefs set value =' $value' where name ='".$attrib["NAME"]."'");322 db_sqlcommand("update system_prefs set value ='".addslashes($value)."' where name ='".$attrib["NAME"]."'"); 240 323 } 241 324 } … … 254 337 // Import user 255 338 $attrib = $this->xml->getAttributes($userpath); 256 $name = $attrib["NAME"];257 if (db_value("select count(*) from users where name = ' $name'") == 0)339 $name = html_entity_decode(utf8_decode($attrib["NAME"])); 340 if (db_value("select count(*) from users where name = '".db_escape_str(un_magic_quote($name))."'") == 0) 258 341 { 259 342 $attrib = $this->xml->getAttributes($userpath.'/max_cert[1]'); … … 261 344 $cert_name = $this->xml->getData($userpath.'/max_cert[1]'); 262 345 $pin = $this->xml->getData($userpath.'/pin[1]'); 346 $admin = $this->xml->getData($userpath.'/admin[1]'); 263 347 264 348 if (($cert_id = db_value("select cert_id from certificates where name='$cert_name' and scheme='$cert_scheme'")) === false) … … 269 353 else 270 354 { 271 db_insert_row('users',array("name"=>$name, "maxcert"=>$cert_id, "pin"=>$pin ) );355 db_insert_row('users',array("name"=>$name, "maxcert"=>$cert_id, "pin"=>$pin, "admin"=>$admin) ); 272 356 } 273 357 } 274 358 275 359 // Determine the user_id for importing settings. 276 $user_id = db_value("select user_id from users where name = ' $name'");360 $user_id = db_value("select user_id from users where name = '".db_escape_str(un_magic_quote($name))."'"); 277 361 278 362 // Import user preferences … … 282 366 $value = $this->xml->getData($prefpath); 283 367 if (db_value("select count(*) from user_prefs where user_id=$user_id and name = '".$attrib["NAME"]."'") == 0) 284 db_insert_row('user_prefs',array("user_id"=>$user_id, "name"=>$attrib["NAME"], "value"=> $value));368 db_insert_row('user_prefs',array("user_id"=>$user_id, "name"=>$attrib["NAME"], "value"=>addslashes($value))); 285 369 else 286 db_sqlcommand("update user_prefs set value =' $value' where user_id=$user_id and name ='".$attrib["NAME"]."'");370 db_sqlcommand("update user_prefs set value ='".addslashes($value)."' where user_id=$user_id and name ='".$attrib["NAME"]."'"); 287 371 } 288 372 } … … 306 390 $cert_name = $attrib["NAME"]; 307 391 $rank = $this->xml->getData($certpath.'/rank[1]'); 308 $desc = $this->xml->getData($certpath.'/description[1]');392 $desc = html_entity_decode(utf8_decode($this->xml->getData($certpath.'/description[1]'))); 309 393 310 394 if (db_value("select count(*) from certificates where name='$cert_name' and scheme='$scheme_name'") == 0) … … 326 410 { 327 411 $type = $this->xml->getData($locpath.'/type[1]'); 328 $path = $this->xml->getData($locpath.'/path[1]');329 $cat_name = $this->xml->getData($locpath.'/category[1]');412 $path = html_entity_decode(utf8_decode($this->xml->getData($locpath.'/path[1]'))); 413 $cat_name = html_entity_decode(utf8_decode($this->xml->getData($locpath.'/category[1]'))); 330 414 $cert_name = $this->xml->getData($locpath.'/default_certificate[1]'); 331 415 $attrib = $this->xml->getAttributes($locpath.'/default_certificate[1]'); … … 338 422 elseif (($cat_id = db_value("select cat_id from categories where cat_name='$cat_name'")) === false) 339 423 $errors[] = str('IMP_LOC_CAT_MISSING',$path,$cat_name); 340 elseif (db_value("select count(*) from media_locations where name = ' $path' and media_type=$type_id") == 0)424 elseif (db_value("select count(*) from media_locations where name = '".db_escape_str(un_magic_quote($path))."' and media_type=$type_id") == 0) 341 425 { 342 426 if ( db_insert_row("media_locations", array("name"=>$path, "media_type"=>$type_id, "cat_id"=>$cat_id, "unrated"=>$cert_id)) !== false) 343 427 { 344 $id = db_value("select location_id from media_locations where name=' $path' and media_type=".$type_id);428 $id = db_value("select location_id from media_locations where name='".db_escape_str(un_magic_quote($path))."' and media_type=".$type_id); 345 429 346 430 if (! is_windows() ) … … 356 440 357 441 /** 358 * Imports all media_locations into the database from the XML document442 * Imports all artfile details into the database from the XML document 359 443 * 360 444 * @return array - Array of errors … … 369 453 if (!in_array($name,$files)) 370 454 db_insert_row("art_files",array("filename"=>$name)); 455 } 456 } 457 458 /** 459 * Imports all tv expressions into the database from the XML document 460 * 461 */ 462 463 function import_tv_expressions() 464 { 465 foreach ($this->xml->match('/swisscenter[1]/config[1]/tv_expressions[1]/expression') as $expressionpath) 466 { 467 $pos = $this->xml->getData($expressionpath.'/pos[1]'); 468 $expression = $this->xml->getData($expressionpath.'/expression[1]'); 469 470 if (db_value("select count(*) from tv_expressions where pos = $pos") == 0) 471 db_insert_row("tv_expressions", array("pos"=>$pos, "expression"=>addslashes($expression))); 472 else 473 db_sqlcommand("update tv_expressions set expression='".addslashes($expression)."' where pos=$pos"); 474 } 475 } 476 477 /** 478 * Imports all rss_subscriptions into the database from the XML document 479 * 480 */ 481 482 function import_rss_subscriptions() 483 { 484 foreach ($this->xml->match('/swisscenter[1]/config[1]/rss_subscriptions[1]/subscription') as $rsspath) 485 { 486 $type = $this->xml->getData($rsspath.'/type[1]'); 487 $url = html_entity_decode(utf8_decode($this->xml->getData($rsspath.'/url[1]'))); 488 $title = html_entity_decode(utf8_decode($this->xml->getData($rsspath.'/title[1]'))); 489 $update = $this->xml->getData($rsspath.'/update[1]'); 490 $cache = $this->xml->getData($rsspath.'/cache[1]'); 491 $type_id = db_value("select media_id from media_types where media_name='$type'"); 492 493 if (db_value("select count(*) from rss_subscriptions where type=$type_id and url='".db_escape_str(un_magic_quote($url))."'") == 0) 494 db_insert_row("rss_subscriptions", array("type"=>$type_id, "url"=>$url, "title"=>$title, "update_frequency"=>$update, "cache"=>$cache)); 495 } 496 } 497 498 /** 499 * Imports all tvid preferences into the database from the XML document 500 * 501 */ 502 503 function import_tvid_prefs() 504 { 505 foreach ($this->xml->match('/swisscenter[1]/config[1]/tvid_prefs[1]/tvid') as $tvidpath) 506 { 507 $player = $this->xml->getData($tvidpath.'/player[1]'); 508 $tvid = $this->xml->getData($tvidpath.'/tvid[1]'); 509 $tvid_custom = $this->xml->getData($tvidpath.'/tvid_custom[1]'); 510 511 if ($tvid_id = db_value("select tvid_id from tvid_prefs where player_type='$player' and tvid_sc='$tvid'")); 512 { 513 $data["tvid_custom"] = $tvid_custom; 514 db_sqlcommand("update tvid_prefs set tvid_custom='$tvid_custom' where tvid_id=$tvid_id"); 515 } 371 516 } 372 517 } … … 383 528 $this->import_sys_prefs(); 384 529 $this->import_certificates(); 530 $this->import_tv_expressions(); 531 $this->import_rss_subscriptions(); 532 $this->import_tvid_prefs(); 385 533 386 534 $errors = array();