@@ -9,15 +9,17 @@ function cmp($a, $b) {
99class DB {
1010 private $ dbh ;
1111 private $ db_prefix ;
12+ private $ app ;
1213
13- function __construct ($ dbh ) {
14+ function __construct ($ dbh, $ app ) {
1415 $ this ->dbh = $ dbh ;
16+ $ this ->app = $ app ;
1517 $ this ->db_prefix = $ GLOBALS ['db_prefix ' ];
1618 }
1719
1820 function get_casts () {
1921 include_once 'models/cast.php ' ;
20- $ userid = $ GLOBALS [ ' app ' ] ->userid ;
22+ $ userid = $ this -> app ->userid ;
2123
2224 $ query = "SELECT
2325 cast.CastID AS id,
@@ -31,8 +33,7 @@ function get_casts() {
3133 AND subs.CastID = cast.CastID " ;
3234 $ inputs = array (":userid " => $ userid );
3335
34- $ dbh = $ GLOBALS ['dbh ' ];
35- $ sth = $ dbh -> prepare ($ query );
36+ $ sth = $ this ->dbh -> prepare ($ query );
3637 $ sth ->execute ($ inputs );
3738
3839 $ casts = $ sth ->fetchAll (PDO ::FETCH_CLASS , "cast " );
@@ -133,9 +134,8 @@ function clean_labels(){
133134 SET content = :content
134135 WHERE labelid = :id
135136 AND userid = :userid " ;
136- $ dbh = $ GLOBALS ['dbh ' ];
137- $ sth = $ dbh -> prepare ($ query );
138- $ userid = $ GLOBALS ['app ' ]->userid ;
137+ $ sth = $ this ->dbh -> prepare ($ query );
138+ $ userid = $ this ->app ->userid ;
139139 foreach ($ labels as $ label ) {
140140 $ content = $ label ->content ;
141141 foreach ($ removefromlabels as $ removee ) {
@@ -178,7 +178,7 @@ function clean_labels(){
178178
179179 function get_label ($ name = null , $ labelid = null ) {
180180 include_once 'models/label.php ' ;
181- $ userid = $ GLOBALS [ ' app ' ] ->userid ;
181+ $ userid = $ this -> app ->userid ;
182182
183183 $ query = "SELECT
184184 label.LabelID AS id,
@@ -201,8 +201,7 @@ function get_label($name = null, $labelid = null) {
201201 $ inputs [":labelid " ] = $ labelid ;
202202 }
203203
204- $ dbh = $ GLOBALS ['dbh ' ];
205- $ sth = $ dbh -> prepare ($ query );
204+ $ sth = $ this ->dbh -> prepare ($ query );
206205 $ sth ->execute ($ inputs );
207206
208207 $ label = $ sth ->fetchAll (PDO ::FETCH_CLASS , "label " );
@@ -215,12 +214,11 @@ function add_to_label_root($value){
215214 }
216215
217216 function add_to_label ($ value , $ labelname ){
218- $ dbh = $ GLOBALS ['dbh ' ];
219- $ userid = $ GLOBALS ['app ' ]->userid ;
217+ $ userid = $ this ->app ->userid ;
220218
221219 $ label = $ this ->get_label ($ labelname );
222220 if (empty ($ label )){
223- $ sth = $ dbh -> prepare ("INSERT INTO {$ this ->db_prefix }label
221+ $ sth = $ this -> dbh -> prepare ("INSERT INTO {$ this ->db_prefix }label
224222 (userid, name, content, expanded)
225223 VALUES( $ userid, :labelname, :content, TRUE) " );
226224 $ sth -> bindParam (":content " ,$ value );
@@ -233,7 +231,7 @@ function add_to_label($value, $labelname){
233231
234232 $ label ->content .= ", " . $ value ;
235233
236- $ sth = $ dbh -> prepare ("UPDATE {$ this ->db_prefix }label
234+ $ sth = $ this -> dbh -> prepare ("UPDATE {$ this ->db_prefix }label
237235 SET content = :content
238236 WHERE LabelID = :id " );
239237 $ sth -> bindParam (":content " ,$ label ->content );
@@ -246,7 +244,7 @@ function get_episodes($castid = null, $labelid = null, $episode = null, $since =
246244 include_once 'models/event.php ' ;
247245
248246 $ label = null ;
249- $ userid = $ GLOBALS [ ' app ' ] ->userid ;
247+ $ userid = $ this -> app ->userid ;
250248
251249 if ($ labelid != null ){
252250 $ label = $ this ->get_label (null , $ labelid );
@@ -358,8 +356,7 @@ function get_episodes($castid = null, $labelid = null, $episode = null, $since =
358356
359357 function get_events ($ itemid , $ since , $ limit = null , $ exclude = null , $ exclude_self = null ) {
360358 include_once 'models/event.php ' ;
361- $ dbh = $ GLOBALS ['dbh ' ];
362- $ userid = $ GLOBALS ['app ' ]->userid ;
359+ $ userid = $ this ->app ->userid ;
363360
364361 $ exclude = superexplode ($ exclude );
365362
@@ -391,7 +388,7 @@ function get_events($itemid, $since, $limit = null, $exclude = null, $exclude_se
391388 }
392389 if ($ exclude_self ) {
393390 $ query .=" AND event.UniqueClientID != :self " ;
394- $ inputs [":self " ] = $ GLOBALS [ ' app ' ] ->uniqueclientid ;
391+ $ inputs [":self " ] = $ this -> app ->uniqueclientid ;
395392 }
396393
397394 if (!empty ($ exclude ) && !$ since && $ itemid === null ){
@@ -424,7 +421,7 @@ function get_events($itemid, $since, $limit = null, $exclude = null, $exclude_se
424421
425422 $ eq .= " GROUP BY ev2.EpisodeID " ;
426423
427- $ sth = $ dbh -> prepare ($ eq );
424+ $ sth = $ this -> dbh -> prepare ($ eq );
428425 $ sth ->execute ($ eqi );
429426
430427 $ exclude = array ();
@@ -445,8 +442,8 @@ function get_events($itemid, $since, $limit = null, $exclude = null, $exclude_se
445442 $ inputs [":limit " ] = $ limit ;
446443 }
447444
448- $ dbh ->setAttribute (PDO ::ATTR_EMULATE_PREPARES , FALSE );
449- $ sth = $ dbh -> prepare ($ query );
445+ $ this -> dbh ->setAttribute (PDO ::ATTR_EMULATE_PREPARES , FALSE );
446+ $ sth = $ this -> dbh -> prepare ($ query );
450447 $ sth ->execute ($ inputs );
451448
452449 if ($ sth ) {
@@ -463,8 +460,8 @@ function get_events($itemid, $since, $limit = null, $exclude = null, $exclude_se
463460
464461 function get_settings () {
465462 include_once 'models/setting.php ' ;
466- $ userid = $ GLOBALS [ ' app ' ] ->userid ;
467- $ clientid = $ GLOBALS [ ' app ' ] ->clientid ;
463+ $ userid = $ this -> app ->userid ;
464+ $ clientid = $ this -> app ->clientid ;
468465
469466 $ query = "SELECT
470467 setting.settingid,
@@ -481,8 +478,7 @@ function get_settings() {
481478 ":clientid " => $ clientid );
482479
483480
484- $ dbh = $ GLOBALS ['dbh ' ];
485- $ sth = $ dbh -> prepare ($ query );
481+ $ sth = $ this ->dbh -> prepare ($ query );
486482 $ sth ->execute ($ inputs );
487483
488484 if ($ sth ) {
@@ -500,14 +496,11 @@ function import_opml($opml) {
500496 $ this ->opml_next ($ opml );
501497 //crawl_urls($this->urls);
502498
503- $ dbh = $ GLOBALS ['dbh ' ];
504- $ db_prefix = $ GLOBALS ['db_prefix ' ];
505-
506499 foreach ($ this ->urls as $ url ) {
507- $ sth = $ dbh ->query ("SELECT * FROM {$ db_prefix }cast WHERE url=' $ url' " );
500+ $ sth = $ this -> dbh ->query ("SELECT * FROM {$ this -> db_prefix }cast WHERE url=' $ url' " );
508501 $ cast = $ sth ->fetch ();
509502 if (!$ cast ) {
510- $ dbh ->exec ("INSERT INTO {$ db_prefix }cast (url, crawlts) VALUES(' $ url', 0) " );
503+ $ this -> dbh ->exec ("INSERT INTO {$ this -> db_prefix }cast (url, crawlts) VALUES(' $ url', 0) " );
511504 }
512505 }
513506
@@ -546,16 +539,13 @@ function opml_next($opml, $label = null){
546539 }
547540
548541 function subscribe_to ($ feedurl , $ name = null , $ label = null , $ crawl = false ){
549- $ userid = $ GLOBALS ['app ' ] -> userid ;
550-
551- $ dbh = $ GLOBALS ['dbh ' ];
552- $ db_prefix = $ GLOBALS ['db_prefix ' ];
542+ $ userid = $ this ->app -> userid ;
553543
554544 if ($ crawl ) {
555545 $ castid = crawl ($ feedurl );
556546 }
557547 else {
558- $ sth = $ dbh ->query ("SELECT CastID FROM {$ db_prefix }cast WHERE url=' $ feedurl' " );
548+ $ sth = $ this -> dbh ->query ("SELECT CastID FROM {$ this -> db_prefix }cast WHERE url=' $ feedurl' " );
559549 $ castid = $ sth ->fetch (PDO ::FETCH_ASSOC )['CastID ' ];
560550 }
561551
@@ -572,15 +562,23 @@ function subscribe_to($feedurl, $name = null, $label = null, $crawl = false){
572562 }
573563 }
574564
575- $ sth = $ dbh -> query ("SELECT * FROM {$ db_prefix }subscription WHERE castid= $ castid AND userid= $ userid " );
565+ $ sth = $ this -> dbh -> query ("SELECT * FROM {$ this -> db_prefix }subscription WHERE castid= $ castid AND userid= $ userid " );
576566 if ($ sth && $ sth -> rowCount () < 1 ) {
577- $ sth = $ dbh -> prepare ("INSERT INTO {$ db_prefix }subscription (castid, name, userid)
567+ $ sth = $ this -> dbh -> prepare ("INSERT INTO {$ this -> db_prefix }subscription (castid, name, userid)
578568 VALUES( $ castid, :name, $ userid) " );
579569 $ sth -> bindParam (":name " ,$ name );
580570 $ sth -> execute ();
581571
582572 $ this ->add_to_label ("cast/ " . $ castid , $ label );
583573 }
584574 }
575+
576+ function del_label ($ labelid ){
577+ $ userid = $ this ->app ->userid ;
578+ $ sth = $ this ->dbh -> prepare ("DELETE FROM {$ this ->db_prefix }label WHERE LabelID=:labelid AND userid=:userid " );
579+ $ sth ->bindParam (":labelid " ,$ labelid );
580+ $ sth ->bindParam (":userid " ,$ userid );
581+ $ sth ->execute ();
582+ }
585583}
586584?>
0 commit comments