| 1 | <?php
|
|---|
| 2 | require_once( dirname(__file__) . '/../common/omconfig.php' );
|
|---|
| 3 | require_once( dirname(__file__) . '/../common/json_service.php' );
|
|---|
| 4 | require_once( FS_COMMON_SKIN_DIRECTORY . '/common.php' );
|
|---|
| 5 | require_once( FS_COMMON_DIRECTORY.'/utils.php');
|
|---|
| 6 | require_once('portlets/PortletsClass.php');
|
|---|
| 7 | require_once('includes/config.php');
|
|---|
| 8 | require_once ('includes/classes/DB.php' );
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 | class UnsubscribeClass {
|
|---|
| 12 | private $bIsLoggedOn;
|
|---|
| 13 | private $oDb; //Wiki DB Connection
|
|---|
| 14 | private $bDb; //Blog DB Connection
|
|---|
| 15 | private $fDb; //Forum DB Connection
|
|---|
| 16 | private $iUserId;
|
|---|
| 17 | private $sUserName;
|
|---|
| 18 | private $subscribeList;
|
|---|
| 19 |
|
|---|
| 20 | public function __construct(){
|
|---|
| 21 |
|
|---|
| 22 | $this->bIsLoggedOn = GetLoggedInStateFromWikiCookies();
|
|---|
| 23 |
|
|---|
| 24 | $this->oDb = &newDb( 'wiki',true );
|
|---|
| 25 | $this->bDb = &newDb( 'blogs',true);
|
|---|
| 26 | $this->fDb = &newDb( 'forum',true );
|
|---|
| 27 | session_start();
|
|---|
| 28 | if( $this->bIsLoggedOn ){
|
|---|
| 29 | // Changed by zhongzhen for preventing sql injection on 2010-06-10
|
|---|
| 30 | $this->iUserId = intval($_COOKIE[ OMWIKI_DATABASE_NAME . '_' . OMWIKI_DB_TABLE_PREFIX . 'UserID' ]);
|
|---|
| 31 | // Changed by zhongzhen for preventing sql injection on 2010-06-10
|
|---|
| 32 | $this->sUserName = mysql_escape_string($_COOKIE[ OMWIKI_DATABASE_NAME . '_' . OMWIKI_DB_TABLE_PREFIX . 'UserName' ]);
|
|---|
| 33 |
|
|---|
| 34 | if(!isset($_SESSION[$this->sUserName.'Subscription'])){
|
|---|
| 35 | $SubscribePortlet11 = new SubscribePortlet($this->oDb,$this->bDb,$this->fDb);
|
|---|
| 36 | $_SESSION[$this->sUserName.'Subscription'] = $SubscribePortlet11->loadSubscription();
|
|---|
| 37 | }
|
|---|
| 38 | $this->subscribeList = explode(",", $_SESSION[$this->sUserName.'Subscription']);
|
|---|
| 39 | }
|
|---|
| 40 |
|
|---|
| 41 | }
|
|---|
| 42 |
|
|---|
| 43 | public function execute(){
|
|---|
| 44 | $result = array('content'=>'','msg'=>'');
|
|---|
| 45 | if(isset($_REQUEST["action"]) && $_REQUEST["action"]=='0'){
|
|---|
| 46 | $msg = '';
|
|---|
| 47 | if($_GET["wiki_subscribe"]=='1'&&$this->subscribeList[0] == '0'){
|
|---|
| 48 | $this->subscribeWikiAjax();
|
|---|
| 49 | $this->subscribeList[0] = '1';
|
|---|
| 50 | $msg .= "wiki is subscribed successfully.\n";
|
|---|
| 51 | }else if($_GET["wiki_subscribe"]=='0'&&$this->subscribeList[0] == '1'){
|
|---|
| 52 | $this->unSubscribeWikiAjax();
|
|---|
| 53 | $this->subscribeList[0] = '0';
|
|---|
| 54 | $msg .= "wiki is unsubscribed successfully.\n";
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | if($_GET["blog_subscribe"]=='1'&&$this->subscribeList[1] == '0'){
|
|---|
| 58 | $this->subscribeWordPressAjax();
|
|---|
| 59 | $this->subscribeList[1] = '1';
|
|---|
| 60 | $msg .= "blog is subscribed successfully.\n";
|
|---|
| 61 | }else if($_GET["blog_subscribe"]=='0'&&$this->subscribeList[1] == '1'){
|
|---|
| 62 | $this->unSubscribeWordPressAjax();
|
|---|
| 63 | $this->subscribeList[1] = '0';
|
|---|
| 64 | $msg .= "blog is unsubscribed successfully.\n";
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | if($_GET["forum_subscribe"]=='1'&&$this->subscribeList[2] == '0'){
|
|---|
| 68 | $this->subscribeForumAjax();
|
|---|
| 69 | $this->subscribeList[2] = '1';
|
|---|
| 70 | $msg .= "forum is subscribed successfully.\n";
|
|---|
| 71 | }else if($_GET["forum_subscribe"]=='0'&&$this->subscribeList[2] == '1'){
|
|---|
| 72 | $this->unSubscribeForumAjax();
|
|---|
| 73 | $this->subscribeList[2] = '0';
|
|---|
| 74 | $msg .= "forum is unsubscribed successfully.\n";
|
|---|
| 75 | }
|
|---|
| 76 | $result['msg'] = $msg;
|
|---|
| 77 | // }else if($_REQUEST["action"]=='1'){
|
|---|
| 78 | // if($_GET["wiki_subscribe"]=='1'){
|
|---|
| 79 | // $this->unSubscribeWikiAjax();
|
|---|
| 80 | // $this->subscribeList[0] = '0';
|
|---|
| 81 | // }
|
|---|
| 82 | // if($_GET["forum_subscribe"]=='1'){
|
|---|
| 83 | // $this->unSubscribeForumAjax();
|
|---|
| 84 | // $this->subscribeList[2] = '0';
|
|---|
| 85 | // }
|
|---|
| 86 | // if($_GET["blog_subscribe"]=='1'){
|
|---|
| 87 | // $this->unSubscribeWordPressAjax();
|
|---|
| 88 | // $this->subscribeList[1] = '0';
|
|---|
| 89 | // }
|
|---|
| 90 | // $result['msg'] = 'Successfully Unsubscribed';
|
|---|
| 91 | }else{
|
|---|
| 92 | //do nothing, just init
|
|---|
| 93 | }
|
|---|
| 94 | $subscribeContent = implode(',',$this->subscribeList);
|
|---|
| 95 | $_SESSION[$this->sUserName.'Subscription'] = $subscribeContent;
|
|---|
| 96 | $result['content'] = $subscribeContent;
|
|---|
| 97 | echo json_encode($result);
|
|---|
| 98 | }
|
|---|
| 99 |
|
|---|
| 100 | function subscribeWordPressAjax(){
|
|---|
| 101 | $sql = "SELECT t.term_id FROM ".OMBLOG_DATABASE_NAME.'.'.OMBLOG_DB_TABLE_PREFIX."terms AS t INNER JOIN ".
|
|---|
| 102 | OMBLOG_DATABASE_NAME.'.'.OMBLOG_DB_TABLE_PREFIX."term_taxonomy AS tt ON t.term_id = tt.term_id
|
|---|
| 103 | where tt.taxonomy = 'category'";
|
|---|
| 104 | $res = $this->bDb->GetRows( $sql);
|
|---|
| 105 | $catSub = array();
|
|---|
| 106 | foreach ($res as $aRow){
|
|---|
| 107 | $catSub[] = $aRow[0];
|
|---|
| 108 | $sql = "delete from ".OMBLOG_DATABASE_NAME.".".OMBLOG_DB_TABLE_PREFIX."usermeta where user_id=".$this->iUserId." and meta_key='s2_cat$aRow[0]'";
|
|---|
| 109 | $this->bDb->ExecuteSql( $sql);
|
|---|
| 110 | $sql = "insert into ".OMBLOG_DATABASE_NAME.".".OMBLOG_DB_TABLE_PREFIX."usermeta (user_id,meta_key,meta_value)
|
|---|
| 111 | value ('".$this->iUserId."','s2_cat$aRow[0]','$aRow[0]')";
|
|---|
| 112 | $this->bDb->ExecuteSql( $sql);
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 |
|
|---|
| 116 | $catSub = implode(',',$catSub);
|
|---|
| 117 | $sql = "delete from ".OMBLOG_DATABASE_NAME.".".OMBLOG_DB_TABLE_PREFIX."usermeta where user_id ='".$this->iUserId."' and
|
|---|
| 118 | (meta_key = 's2_format' or meta_key = 's2_autosub' or meta_key = 's2_subscribed')";
|
|---|
| 119 | $this->bDb->ExecuteSql( $sql);
|
|---|
| 120 |
|
|---|
| 121 | $sql = "insert into ".OMBLOG_DATABASE_NAME.".".OMBLOG_DB_TABLE_PREFIX."usermeta (user_id,meta_key,meta_value)
|
|---|
| 122 | value ('".$this->iUserId."','s2_format','html')";
|
|---|
| 123 | $this->bDb->ExecuteSql( $sql);
|
|---|
| 124 |
|
|---|
| 125 | $sql = "insert into ".OMBLOG_DATABASE_NAME.".".OMBLOG_DB_TABLE_PREFIX."usermeta (user_id,meta_key,meta_value)
|
|---|
| 126 | value ('".$this->iUserId."','s2_autosub','yes')";
|
|---|
| 127 | $this->bDb->ExecuteSql( $sql);
|
|---|
| 128 |
|
|---|
| 129 | $sql = "insert into ".OMBLOG_DATABASE_NAME.".".OMBLOG_DB_TABLE_PREFIX."usermeta (user_id,meta_key,meta_value)
|
|---|
| 130 | value ('".$this->iUserId."','s2_subscribed','$catSub')";
|
|---|
| 131 | $this->bDb->ExecuteSql( $sql );
|
|---|
| 132 |
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | function subscribeForumAjax(){
|
|---|
| 136 | $sql = "update ".OMFORUM_DATABASE_NAME.".".OMFORUM_DB_TABLE_PREFIX."users set user_digest_type='WEEK' ,user_digest_send_hour_gmt = 10.00 where username='".$this->sUserName."'";
|
|---|
| 137 | $this->fDb->ExecuteSql($sql);
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | function subscribeWikiAjax(){
|
|---|
| 141 | $sql = "select 1 from ".OMWIKI_DB_TABLE_PREFIX."user_subscription where user_id=".$this->iUserId." and subscribe_flag='1'";
|
|---|
| 142 | if($this->oDb->GetRows($sql))
|
|---|
| 143 | return;
|
|---|
| 144 | $sql = "insert into ".OMWIKI_DB_TABLE_PREFIX."user_subscription (user_id,subscribe_flag) values ('".$this->iUserId."','1')";
|
|---|
| 145 | $res = $this->oDb->ExecuteSql($sql);
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | function unSubscribeWordPressAjax(){
|
|---|
| 149 | $sql = "SELECT t.term_id FROM ".OMBLOG_DATABASE_NAME.'.'.OMBLOG_DB_TABLE_PREFIX."terms AS t INNER JOIN ".
|
|---|
| 150 | OMBLOG_DATABASE_NAME.'.'.OMBLOG_DB_TABLE_PREFIX."term_taxonomy AS tt ON t.term_id = tt.term_id
|
|---|
| 151 | where tt.taxonomy = 'category'";
|
|---|
| 152 | $res = $this->bDb->GetRows( $sql);
|
|---|
| 153 | $catSub = array();
|
|---|
| 154 | foreach ($res as $aRow){
|
|---|
| 155 | $catSub[] = $aRow[0];
|
|---|
| 156 | $sql = "delete from ".OMBLOG_DATABASE_NAME.".".OMBLOG_DB_TABLE_PREFIX."usermeta where user_id=".$this->iUserId." and meta_key='s2_cat$aRow[0]'";
|
|---|
| 157 | $this->bDb->ExecuteSql( $sql);
|
|---|
| 158 | }
|
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 | $catSub = implode(',',$catSub);
|
|---|
| 162 | $sql = "delete from ".OMBLOG_DATABASE_NAME.".".OMBLOG_DB_TABLE_PREFIX."usermeta where user_id ='".$this->iUserId."' and
|
|---|
| 163 | (meta_key = 's2_format' or meta_key = 's2_autosub' or meta_key = 's2_subscribed')";
|
|---|
| 164 | $this->bDb->ExecuteSql( $sql);
|
|---|
| 165 |
|
|---|
| 166 | }
|
|---|
| 167 |
|
|---|
| 168 | function unSubscribeForumAjax(){
|
|---|
| 169 | $sql = "update ".OMFORUM_DATABASE_NAME.".".OMFORUM_DB_TABLE_PREFIX."users set user_digest_type='NONE' where username='".$this->sUserName."'";
|
|---|
| 170 | $this->fDb->ExecuteSql($sql);
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | function unSubscribeWikiAjax(){
|
|---|
| 174 | $sql = "delete from ".OMWIKI_DB_TABLE_PREFIX."user_subscription where user_id=".$this->iUserId." and subscribe_flag='1'";
|
|---|
| 175 | $res = $this->oDb->ExecuteSql($sql);
|
|---|
| 176 | }
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | $UnsubscribeClass = new UnsubscribeClass();
|
|---|
| 180 | $UnsubscribeClass->execute();
|
|---|
| 181 |
|
|---|
| 182 | ?>
|
|---|