idx
int64
0
60.3k
question
stringlengths
101
6.21k
target
stringlengths
7
803
49,200
protected function findUser ( $ idOrEmail ) { if ( ! $ user = User :: find ( ) -> andWhere ( is_numeric ( $ idOrEmail ) ? [ 'id' => $ idOrEmail ] : [ 'email' => $ idOrEmail ] ) -> limit ( 1 ) -> one ( ) ) { $ this -> stderr ( 'User not found.' . PHP_EOL ) ; } return $ user ; }
Finds user by id or email
49,201
public function getUserVoted ( $ userId ) { return ( new Query ( ) ) -> from ( '{{%podium_poll_vote}}' ) -> where ( [ 'poll_id' => $ this -> id , 'caster_id' => $ userId ] ) -> count ( 'id' ) ? true : false ; }
Checks if user has already voted in poll .
49,202
public function hasAnswer ( $ answerId ) { foreach ( $ this -> answers as $ answer ) { if ( $ answer -> id == $ answerId ) { return true ; } } return false ; }
Checks if poll has given answer .
49,203
public function getVotesCount ( ) { $ votes = 0 ; foreach ( $ this -> answers as $ answer ) { $ votes += $ answer -> votes ; } return $ votes ; }
Returns number of casted votes .
49,204
public function podiumDelete ( ) { $ transaction = static :: getDb ( ) -> beginTransaction ( ) ; try { if ( ! Podium :: getInstance ( ) -> db -> createCommand ( ) -> delete ( '{{%podium_poll_vote}}' , [ 'poll_id' => $ this -> id ] ) -> execute ( ) ) { throw new Exception ( 'Poll Votes deleting error!' ) ; } if ( ! PollAnswer :: deleteAll ( [ 'poll_id' => $ this -> id ] ) ) { throw new Exception ( 'Poll Answers deleting error!' ) ; } if ( ! $ this -> delete ( ) ) { throw new Exception ( 'Poll deleting error!' ) ; } $ transaction -> commit ( ) ; Log :: info ( 'Poll deleted' , ! empty ( $ this -> id ) ? $ this -> id : '' , __METHOD__ ) ; return true ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Performs poll delete with answers and votes .
49,205
public function podiumEdit ( ) { $ transaction = static :: getDb ( ) -> beginTransaction ( ) ; try { if ( ! $ this -> save ( ) ) { throw new Exception ( 'Poll saving error!' ) ; } foreach ( $ this -> editAnswers as $ answer ) { foreach ( $ this -> answers as $ oldAnswer ) { if ( $ answer == $ oldAnswer -> answer ) { continue ( 2 ) ; } } $ pollAnswer = new PollAnswer ( ) ; $ pollAnswer -> poll_id = $ this -> id ; $ pollAnswer -> answer = $ answer ; if ( ! $ pollAnswer -> save ( ) ) { throw new Exception ( 'Poll Answer saving error!' ) ; } } foreach ( $ this -> answers as $ oldAnswer ) { foreach ( $ this -> editAnswers as $ answer ) { if ( $ answer == $ oldAnswer -> answer ) { continue ( 2 ) ; } } if ( ! $ oldAnswer -> delete ( ) ) { throw new Exception ( 'Poll Answer deleting error!' ) ; } } $ transaction -> commit ( ) ; Log :: info ( 'Poll updated' , $ this -> id , __METHOD__ ) ; return true ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Performs poll update .
49,206
public function actionDetails ( ) { $ model = User :: findMe ( ) ; if ( empty ( $ model ) ) { return $ this -> redirect ( [ 'account/login' ] ) ; } $ model -> scenario = Podium :: getInstance ( ) -> userComponent !== true ? 'accountInherit' : 'account' ; $ model -> currentPassword = null ; $ previous_new_email = $ model -> new_email ; if ( empty ( $ model -> username ) ) { $ model -> username = 'user_' . $ model -> id ; } if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { if ( $ model -> validate ( ) ) { if ( $ model -> saveChanges ( ) ) { if ( $ previous_new_email != $ model -> new_email ) { $ forum = $ this -> module -> podiumConfig -> get ( 'name' ) ; $ email = Content :: fill ( Content :: EMAIL_NEW ) ; if ( $ email !== false && Email :: queue ( $ model -> new_email , str_replace ( '{forum}' , $ forum , $ email -> topic ) , str_replace ( '{forum}' , $ forum , str_replace ( '{link}' , Html :: a ( Url :: to ( [ 'account/new-email' , 'token' => $ model -> email_token ] , true ) , Url :: to ( [ 'account/new-email' , 'token' => $ model -> email_token ] , true ) ) , $ email -> content ) ) , ! empty ( $ model -> id ) ? $ model -> id : null ) ) { Log :: info ( 'New email activation link queued' , $ model -> id , __METHOD__ ) ; $ this -> success ( Yii :: t ( 'podium/flash' , 'Your account has been updated but your new e-mail address is not active yet. Click the activation link that will be sent to your new e-mail address in few minutes.' ) ) ; } else { Log :: error ( 'Error while queuing new email activation link' , $ model -> id , __METHOD__ ) ; $ this -> warning ( Yii :: t ( 'podium/flash' , 'Your account has been updated but your new e-mail address is not active yet. Unfortunately there was some error while sending you the activation link. Contact administrator about this problem.' ) ) ; } } else { Log :: info ( 'Details updated' , $ model -> id , __METHOD__ ) ; $ this -> success ( Yii :: t ( 'podium/flash' , 'Your account has been updated.' ) ) ; } return $ this -> refresh ( ) ; } } } $ model -> currentPassword = null ; return $ this -> render ( 'details' , [ 'model' => $ model ] ) ; }
Updating the profile details .
49,207
public function actionIndex ( ) { $ model = User :: findMe ( ) ; if ( empty ( $ model ) ) { if ( $ this -> module -> userComponent === true ) { return $ this -> redirect ( [ 'account/login' ] ) ; } return $ this -> module -> goPodium ( ) ; } return $ this -> render ( 'profile' , [ 'model' => $ model ] ) ; }
Showing the profile card .
49,208
public function actionSubscriptions ( ) { $ postData = Yii :: $ app -> request -> post ( ) ; if ( $ postData ) { if ( Subscription :: remove ( ! empty ( $ postData [ 'selection' ] ) ? $ postData [ 'selection' ] : [ ] ) ) { $ this -> success ( Yii :: t ( 'podium/flash' , 'Subscription list has been updated.' ) ) ; } else { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was an error while unsubscribing the thread list.' ) ) ; } return $ this -> refresh ( ) ; } return $ this -> render ( 'subscriptions' , [ 'dataProvider' => ( new Subscription ( ) ) -> search ( Yii :: $ app -> request -> get ( ) ) ] ) ; }
Showing the subscriptions .
49,209
public function actionMark ( $ id = null ) { $ model = Subscription :: find ( ) -> where ( [ 'id' => $ id , 'user_id' => User :: loggedId ( ) ] ) -> limit ( 1 ) -> one ( ) ; if ( empty ( $ model ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find Subscription with this ID.' ) ) ; return $ this -> redirect ( [ 'profile/subscriptions' ] ) ; } if ( $ model -> post_seen == Subscription :: POST_SEEN ) { if ( $ model -> unseen ( ) ) { $ this -> success ( Yii :: t ( 'podium/flash' , 'Thread has been marked unseen.' ) ) ; } else { Log :: error ( 'Error while marking thread' , $ model -> id , __METHOD__ ) ; $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was some error while marking the thread.' ) ) ; } return $ this -> redirect ( [ 'profile/subscriptions' ] ) ; } if ( $ model -> post_seen == Subscription :: POST_NEW ) { if ( $ model -> seen ( ) ) { $ this -> success ( Yii :: t ( 'podium/flash' , 'Thread has been marked seen.' ) ) ; } else { Log :: error ( 'Error while marking thread' , $ model -> id , __METHOD__ ) ; $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was some error while marking the thread.' ) ) ; } return $ this -> redirect ( [ 'profile/subscriptions' ] ) ; } $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! Subscription has got the wrong status.' ) ) ; return $ this -> redirect ( [ 'profile/subscriptions' ] ) ; }
Marking the subscription of given ID .
49,210
public function actionDelete ( $ id = null ) { $ model = Subscription :: find ( ) -> where ( [ 'id' => ( int ) $ id , 'user_id' => User :: loggedId ( ) ] ) -> limit ( 1 ) -> one ( ) ; if ( empty ( $ model ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find Subscription with this ID.' ) ) ; return $ this -> redirect ( [ 'profile/subscriptions' ] ) ; } if ( $ model -> delete ( ) ) { $ this -> module -> podiumCache -> deleteElement ( 'user.subscriptions' , User :: loggedId ( ) ) ; $ this -> success ( Yii :: t ( 'podium/flash' , 'Thread has been unsubscribed.' ) ) ; } else { Log :: error ( 'Error while deleting subscription' , $ model -> id , __METHOD__ ) ; $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was some error while deleting the subscription.' ) ) ; } return $ this -> redirect ( [ 'profile/subscriptions' ] ) ; }
Deleting the subscription of given ID .
49,211
public function actionAdd ( $ id = null ) { if ( ! Yii :: $ app -> request -> isAjax ) { return $ this -> redirect ( [ 'forum/index' ] ) ; } $ data = [ 'error' => 1 , 'msg' => Html :: tag ( 'span' , Html :: tag ( 'span' , '' , [ 'class' => 'glyphicon glyphicon-warning-sign' ] ) . ' ' . Yii :: t ( 'podium/view' , 'Error while adding this subscription!' ) , [ 'class' => 'text-danger' ] ) , ] ; if ( Podium :: getInstance ( ) -> user -> isGuest ) { $ data [ 'msg' ] = Html :: tag ( 'span' , Html :: tag ( 'span' , '' , [ 'class' => 'glyphicon glyphicon-warning-sign' ] ) . ' ' . Yii :: t ( 'podium/view' , 'Please sign in to subscribe to this thread' ) , [ 'class' => 'text-info' ] ) ; } if ( is_numeric ( $ id ) && $ id > 0 ) { $ subscription = Subscription :: find ( ) -> where ( [ 'thread_id' => $ id , 'user_id' => User :: loggedId ( ) ] ) -> limit ( 1 ) -> one ( ) ; if ( ! empty ( $ subscription ) ) { $ data [ 'msg' ] = Html :: tag ( 'span' , Html :: tag ( 'span' , '' , [ 'class' => 'glyphicon glyphicon-warning-sign' ] ) . ' ' . Yii :: t ( 'podium/view' , 'You are already subscribed to this thread.' ) , [ 'class' => 'text-info' ] ) ; } else { if ( Subscription :: add ( ( int ) $ id ) ) { $ data = [ 'error' => 0 , 'msg' => Html :: tag ( 'span' , Html :: tag ( 'span' , '' , [ 'class' => 'glyphicon glyphicon-ok-circle' ] ) . ' ' . Yii :: t ( 'podium/view' , 'You have subscribed to this thread!' ) , [ 'class' => 'text-success' ] ) , ] ; } } } return Json :: encode ( $ data ) ; }
Subscribing the thread of given ID .
49,212
public function beforeAction ( $ action ) { if ( ! parent :: beforeAction ( $ action ) ) { return false ; } if ( $ this -> accessType === 0 ) { return $ this -> module -> goPodium ( ) ; } return true ; }
Redirect in case of guest access type .
49,213
public function actionActivate ( $ token ) { if ( $ this -> module -> userComponent !== true ) { $ this -> info ( Yii :: t ( 'podium/flash' , 'Please contact the administrator to activate your account.' ) ) ; return $ this -> module -> goPodium ( ) ; } $ model = User :: findByActivationToken ( $ token ) ; if ( ! $ model ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'The provided activation token is invalid or expired.' ) ) ; return $ this -> module -> goPodium ( ) ; } $ model -> scenario = 'token' ; if ( $ model -> activate ( ) ) { PodiumCache :: clearAfter ( 'activate' ) ; Log :: info ( 'Account activated' , $ model -> id , __METHOD__ ) ; $ this -> success ( Yii :: t ( 'podium/flash' , 'Your account has been activated. You can sign in now.' ) ) ; } else { Log :: error ( 'Error while activating account' , $ model -> id , __METHOD__ ) ; $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was some error while activating your account. Contact administrator about this problem.' ) ) ; } return $ this -> module -> goPodium ( ) ; }
Activating the account based on the provided activation token .
49,214
public function actionLogin ( ) { if ( $ this -> module -> userComponent !== true ) { $ this -> info ( Yii :: t ( 'podium/flash' , 'Please use application Login form to sign in.' ) ) ; return $ this -> module -> goPodium ( ) ; } $ model = new LoginForm ( ) ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> login ( ) ) { return $ this -> module -> goPodium ( ) ; } return $ this -> render ( 'login' , [ 'model' => $ model ] ) ; }
Signing in .
49,215
public function actionNewEmail ( $ token ) { $ model = User :: findByEmailToken ( $ token ) ; if ( ! $ model ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'The provided activation token is invalid or expired.' ) ) ; return $ this -> module -> goPodium ( ) ; } $ model -> scenario = 'token' ; if ( $ model -> changeEmail ( ) ) { Log :: info ( 'Email address changed' , $ model -> id , __METHOD__ ) ; Yii :: $ app -> session -> removeFlash ( 'warning' ) ; $ this -> success ( Yii :: t ( 'podium/flash' , 'Your new e-mail address has been activated.' ) ) ; } else { Log :: error ( 'Error while activating email' , $ model -> id , __METHOD__ ) ; $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was some error while activating your new e-mail address. Contact administrator about this problem.' ) ) ; } return $ this -> module -> goPodium ( ) ; }
Activating new email address based on the provided token .
49,216
public function actionPassword ( $ token ) { if ( $ this -> module -> userComponent !== true ) { $ this -> info ( Yii :: t ( 'podium/flash' , 'Please contact the administrator to change your account password.' ) ) ; return $ this -> module -> goPodium ( ) ; } $ model = User :: findByPasswordResetToken ( $ token ) ; if ( ! $ model ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'The provided password reset token is invalid or expired.' ) ) ; return $ this -> module -> goPodium ( ) ; } $ model -> scenario = 'passwordChange' ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> changePassword ( ) ) { Log :: info ( 'Password changed' , $ model -> id , __METHOD__ ) ; $ this -> success ( Yii :: t ( 'podium/flash' , 'Your account password has been changed.' ) ) ; return $ this -> module -> goPodium ( ) ; } return $ this -> render ( 'password' , [ 'model' => $ model ] ) ; }
Changing the account password with provided token .
49,217
public function actionRegister ( ) { if ( $ this -> module -> userComponent !== true ) { $ this -> info ( Yii :: t ( 'podium/flash' , "Please use application's Register form to sign up." ) ) ; return $ this -> module -> goPodium ( ) ; } if ( $ this -> module -> podiumConfig -> get ( 'registration_off' ) == '1' ) { $ this -> info ( Yii :: t ( 'podium/flash' , 'User registration is currently not allowed.' ) ) ; return $ this -> module -> goPodium ( ) ; } $ model = new User ( ) ; $ model -> scenario = 'register' ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { $ result = $ model -> register ( ) ; if ( $ result == User :: RESP_OK ) { Log :: info ( 'Activation link queued' , ! empty ( $ model -> id ) ? $ model -> id : '' , __METHOD__ ) ; $ this -> success ( Yii :: t ( 'podium/flash' , 'Your account has been created but it is not active yet. Click the activation link that will be sent to your e-mail address in few minutes.' ) ) ; return $ this -> module -> goPodium ( ) ; } if ( $ result == User :: RESP_EMAIL_SEND_ERR ) { Log :: warning ( 'Error while queuing activation link' , ! empty ( $ model -> id ) ? $ model -> id : '' , __METHOD__ ) ; $ this -> warning ( Yii :: t ( 'podium/flash' , 'Your account has been created but it is not active yet. Unfortunately there was some error while sending you the activation link. Contact administrator about this or try to {resend the link}.' , [ 'resend the link' => Html :: a ( Yii :: t ( 'podium/flash' , 'resend the link' ) , [ 'account/reactivate' ] ) ] ) ) ; return $ this -> module -> goPodium ( ) ; } if ( $ result == User :: RESP_NO_EMAIL_ERR ) { Log :: error ( 'Error while queuing activation link - no email set' , ! empty ( $ model -> id ) ? $ model -> id : '' , __METHOD__ ) ; $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There is no e-mail address saved with your account. Contact administrator about activating.' ) ) ; return $ this -> module -> goPodium ( ) ; } } $ model -> captcha = null ; return $ this -> render ( 'register' , [ 'model' => $ model , 'terms' => Content :: fill ( Content :: TERMS_AND_CONDS ) ] ) ; }
Registering the new account and sending the activation link .
49,218
protected function reformRun ( $ componentInfo , $ model , $ log , $ view ) { if ( $ this -> module -> userComponent !== true ) { $ this -> info ( $ componentInfo ) ; return $ this -> module -> goPodium ( ) ; } if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) ) { list ( $ error , $ message , $ back ) = $ model -> run ( ) ; if ( $ error ) { Log :: error ( $ log [ 'error' ] , ! empty ( $ model -> user -> id ) ? $ model -> user -> id : null , $ log [ 'method' ] ) ; if ( ! empty ( $ message ) ) { $ this -> error ( $ message ) ; } } else { Log :: info ( $ log [ 'info' ] , $ model -> user -> id , $ log [ 'method' ] ) ; if ( ! empty ( $ message ) ) { $ this -> success ( $ message ) ; } } if ( $ back ) { return $ this -> module -> goPodium ( ) ; } } return $ this -> render ( $ view , [ 'model' => $ model ] ) ; }
Runs actions processed with email .
49,219
public function beforeAction ( $ action ) { try { if ( parent :: beforeAction ( $ action ) ) { $ this -> db = ! $ this -> db ? Podium :: getInstance ( ) -> getDb ( ) : Instance :: ensure ( $ this -> db , Connection :: className ( ) ) ; $ this -> mailer = Instance :: ensure ( $ this -> mailer , BaseMailer :: className ( ) ) ; return true ; } } catch ( Exception $ e ) { $ this -> stderr ( "ERROR: " . $ e -> getMessage ( ) . "\n" ) ; } return false ; }
Checks the existence of the db and mailer components .
49,220
public function getNewBatch ( $ limit = 0 ) { try { if ( ! is_numeric ( $ limit ) || $ limit <= 0 ) { $ limit = $ this -> limit ; } return ( new Query ) -> from ( $ this -> queueTable ) -> where ( [ 'status' => Email :: STATUS_PENDING ] ) -> orderBy ( [ 'id' => SORT_ASC ] ) -> limit ( ( int ) $ limit ) -> all ( $ this -> db ) ; } catch ( Exception $ e ) { Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } }
Returns new batch of emails .
49,221
public function send ( $ email , $ fromName , $ fromEmail ) { try { $ mailer = Yii :: $ app -> mailer -> compose ( ) ; $ mailer -> setFrom ( [ $ fromEmail => $ fromName ] ) ; $ mailer -> setTo ( $ email [ 'email' ] ) ; $ mailer -> setSubject ( $ email [ 'subject' ] ) ; $ mailer -> setHtmlBody ( $ email [ 'content' ] ) ; $ mailer -> setTextBody ( strip_tags ( str_replace ( [ '<br>' , '<br/>' , '<br />' , '</p>' ] , "\n" , $ email [ 'content' ] ) ) ) ; return $ mailer -> send ( ) ; } catch ( Exception $ e ) { Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } }
Sends email using mailer component .
49,222
public function process ( $ email , $ fromName , $ fromEmail , $ maxAttempts ) { try { if ( $ this -> send ( $ email , $ fromName , $ fromEmail ) ) { $ this -> db -> createCommand ( ) -> update ( $ this -> queueTable , [ 'status' => Email :: STATUS_SENT ] , [ 'id' => $ email [ 'id' ] ] ) -> execute ( ) ; return true ; } $ attempt = $ email [ 'attempt' ] + 1 ; if ( $ attempt <= $ maxAttempts ) { $ this -> db -> createCommand ( ) -> update ( $ this -> queueTable , [ 'attempt' => $ attempt ] , [ 'id' => $ email [ 'id' ] ] ) -> execute ( ) ; } else { $ this -> db -> createCommand ( ) -> update ( $ this -> queueTable , [ 'status' => Email :: STATUS_GAVEUP ] , [ 'id' => $ email [ 'id' ] ] ) -> execute ( ) ; } } catch ( Exception $ e ) { Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Tries to send email from queue and updates its status .
49,223
public function actionRun ( $ limit = 0 ) { $ version = $ this -> module -> version ; $ this -> stdout ( "\nPodium mail queue v{$version}\n" ) ; $ this -> stdout ( "------------------------------\n" ) ; $ emails = $ this -> getNewBatch ( $ limit ) ; if ( empty ( $ emails ) ) { $ this -> stdout ( "No pending emails in the queue found.\n\n" , Console :: FG_GREEN ) ; return self :: EXIT_CODE_NORMAL ; } $ total = count ( $ emails ) ; $ this -> stdout ( "\n$total pending " . ( $ total === 1 ? 'email' : 'emails' ) . " to be sent now:\n" , Console :: FG_YELLOW ) ; $ errors = false ; foreach ( $ emails as $ email ) { if ( ! $ this -> process ( $ email , $ this -> module -> podiumConfig -> get ( 'from_name' ) , $ this -> module -> podiumConfig -> get ( 'from_email' ) , $ this -> module -> podiumConfig -> get ( 'max_attempts' ) ) ) { $ errors = true ; } } if ( $ errors ) { $ this -> stdout ( "\nBatch sent with errors.\n\n" , Console :: FG_RED ) ; } else { $ this -> stdout ( "\nBatch sent successfully.\n\n" , Console :: FG_GREEN ) ; } return self :: EXIT_CODE_NORMAL ; }
Runs the queue .
49,224
public function actionCheck ( ) { $ version = $ this -> module -> version ; $ this -> stdout ( "\nPodium mail queue check v{$version}\n" ) ; $ this -> stdout ( "------------------------------\n" ) ; $ this -> stdout ( " EMAILS | COUNT\n" ) ; $ this -> stdout ( "------------------------------\n" ) ; $ pending = ( new Query ) -> from ( $ this -> queueTable ) -> where ( [ 'status' => Email :: STATUS_PENDING ] ) -> count ( 'id' , $ this -> db ) ; $ sent = ( new Query ) -> from ( $ this -> queueTable ) -> where ( [ 'status' => Email :: STATUS_SENT ] ) -> count ( 'id' , $ this -> db ) ; $ gaveup = ( new Query ) -> from ( $ this -> queueTable ) -> where ( [ 'status' => Email :: STATUS_GAVEUP ] ) -> count ( 'id' , $ this -> db ) ; $ showPending = $ this -> ansiFormat ( $ pending , Console :: FG_YELLOW ) ; $ showSent = $ this -> ansiFormat ( $ sent , Console :: FG_GREEN ) ; $ showGaveup = $ this -> ansiFormat ( $ gaveup , Console :: FG_RED ) ; $ this -> stdout ( " pending | $showPending\n" ) ; $ this -> stdout ( " sent | $showSent\n" ) ; $ this -> stdout ( " stucked | $showGaveup\n" ) ; $ this -> stdout ( "------------------------------\n\n" ) ; return self :: EXIT_CODE_NORMAL ; }
Checks the current status for the mail queue .
49,225
public function getDefaults ( ) { return [ 'activation_token_expire' => self :: SECONDS_ACTIVATION_TOKEN_EXPIRE , 'allow_polls' => self :: FLAG_ALLOW_POLLS , 'email_token_expire' => self :: SECONDS_EMAIL_TOKEN_EXPIRE , 'from_email' => self :: DEFAULT_FROM_EMAIL , 'from_name' => self :: DEFAULT_FROM_NAME , 'hot_minimum' => self :: HOT_MINIMUM , 'maintenance_mode' => self :: MAINTENANCE_MODE , 'max_attempts' => self :: MAX_SEND_ATTEMPTS , 'members_visible' => self :: FLAG_MEMBERS_VISIBLE , 'merge_posts' => self :: FLAG_MERGE_POSTS , 'meta_description' => self :: META_DESCRIPTION , 'meta_keywords' => self :: META_KEYWORDS , 'name' => self :: PODIUM_NAME , 'password_reset_token_expire' => self :: SECONDS_PASSWORD_RESET_TOKEN_EXPIRE , 'recaptcha_secretkey' => '' , 'recaptcha_sitekey' => '' , 'registration_off' => self :: REGISTRATION_OFF , 'use_captcha' => self :: FLAG_USE_CAPTCHA , 'use_wysiwyg' => self :: FLAG_USE_WYSIWYG , 'version' => Podium :: getInstance ( ) -> version , ] ; }
Returns list of default configuration values . These values are stored in cached configuration but saved only when administrator saves Podium settings .
49,226
public function getAll ( ) { if ( $ this -> _config !== null ) { return $ this -> _config ; } try { $ this -> _config = $ this -> cached ; } catch ( Exception $ exc ) { Log :: warning ( $ exc -> getMessage ( ) , null , __METHOD__ ) ; $ this -> _config = $ this -> stored ; } return $ this -> _config ; }
Returns configuration values .
49,227
public function getCached ( ) { $ cache = $ this -> cache -> get ( 'config' ) ; if ( $ cache === false ) { $ cache = $ this -> notCached ; $ this -> cache -> set ( 'config' , $ cache ) ; } return $ cache ; }
Returns cached configuration values .
49,228
public function getStored ( ) { $ stored = [ ] ; try { $ query = ( new Query ) -> from ( static :: tableName ( ) ) -> all ( ) ; if ( ! empty ( $ query ) ) { foreach ( $ query as $ setting ) { $ stored [ $ setting [ 'name' ] ] = $ setting [ 'value' ] ; } } } catch ( Exception $ e ) { if ( Podium :: getInstance ( ) -> getInstalled ( ) ) { Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } } return $ stored ; }
Returns stored configuration values . These can be empty if configuration has not been modified .
49,229
public function get ( $ name ) { $ config = $ this -> all ; return isset ( $ config [ $ name ] ) ? $ config [ $ name ] : null ; }
Returns configuration value of the given name .
49,230
public function set ( $ name , $ value ) { try { if ( is_string ( $ name ) && ( is_string ( $ value ) || $ value === null ) ) { if ( $ value === null ) { if ( ! array_key_exists ( $ name , $ this -> defaults ) ) { return false ; } $ value = $ this -> defaults [ $ name ] ; } if ( ( new Query ) -> from ( static :: tableName ( ) ) -> where ( [ 'name' => $ name ] ) -> exists ( ) ) { Podium :: getInstance ( ) -> db -> createCommand ( ) -> update ( static :: tableName ( ) , [ 'value' => $ value ] , [ 'name' => $ name ] ) -> execute ( ) ; } else { Podium :: getInstance ( ) -> db -> createCommand ( ) -> insert ( static :: tableName ( ) , [ 'name' => $ name , 'value' => $ value ] ) -> execute ( ) ; } $ this -> cache -> set ( 'config' , $ this -> notCached ) ; $ this -> _config = null ; return true ; } } catch ( Exception $ e ) { Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Sets configuration value of the given name . Every change automatically updates the cache . Set value to null to restore default one .
49,231
public function loggedUser ( $ id ) { if ( Podium :: getInstance ( ) -> userComponent !== true ) { return $ this -> andWhere ( [ 'inherited_id' => $ id ] ) ; } return $ this -> andWhere ( [ 'id' => $ id ] ) ; }
Adds proper user ID for query .
49,232
public function getNamedUsersList ( $ url ) { $ out = '' ; $ conditions = [ 'and' , [ Activity :: tableName ( ) . '.anonymous' => 0 ] , [ 'is not' , 'user_id' , null ] , [ 'like' , 'url' , $ url . '%' , false ] , [ '>=' , Activity :: tableName ( ) . '.updated_at' , time ( ) - 5 * 60 ] ] ; if ( ! Podium :: getInstance ( ) -> user -> isGuest ) { $ this -> _guest = false ; $ me = User :: findMe ( ) ; $ conditions [ ] = [ '!=' , 'user_id' , $ me -> id ] ; if ( ! empty ( $ me -> meta ) && $ me -> meta -> anonymous == 0 ) { $ out .= $ me -> podiumTag . ' ' ; } else { $ this -> _anon = true ; } } $ users = Activity :: find ( ) -> joinWith ( [ 'user' ] ) -> where ( $ conditions ) ; foreach ( $ users -> each ( ) as $ user ) { $ out .= $ user -> user -> podiumTag . ' ' ; } return $ out ; }
Returns formatted list of named users browsing given url group .
49,233
public function getAnonymousUsers ( $ url ) { $ anons = Activity :: find ( ) -> where ( [ 'and' , [ 'anonymous' => 1 ] , [ 'like' , 'url' , $ url . '%' , false ] , [ '>=' , 'updated_at' , time ( ) - 5 * 60 ] ] ) -> count ( 'id' ) ; if ( $ this -> _anon ) { $ anons += 1 ; } return $ anons ; }
Returns number of anonymous users browsing given url group .
49,234
public function getGuestUsers ( $ url ) { $ guests = Activity :: find ( ) -> where ( [ 'and' , [ 'user_id' => null ] , [ 'like' , 'url' , $ url . '%' , false ] , [ '>=' , 'updated_at' , time ( ) - 5 * 60 ] ] ) -> count ( 'id' ) ; if ( $ this -> _guest ) { $ guests += 1 ; } return $ guests ; }
Returns number of guest users browsing given url group .
49,235
public function run ( ) { $ url = Yii :: $ app -> request -> getUrl ( ) ; $ out = '' ; switch ( $ this -> what ) { case 'forum' : $ out .= Yii :: t ( 'podium/view' , 'Browsing this forum' ) . ': ' ; break ; case 'topic' : $ out .= Yii :: t ( 'podium/view' , 'Reading this thread' ) . ': ' ; break ; case 'unread' : $ out .= Yii :: t ( 'podium/view' , 'Browsing unread threads' ) . ': ' ; break ; case 'members' : $ out .= Yii :: t ( 'podium/view' , 'Browsing the members' ) . ': ' ; break ; } $ out .= $ this -> getNamedUsersList ( $ url ) ; $ anonymous = $ this -> getAnonymousUsers ( $ url ) ; if ( $ anonymous ) { $ out .= Html :: button ( Yii :: t ( 'podium/view' , '{n, plural, =1{# anonymous user} other{# anonymous users}}' , [ 'n' => $ anonymous ] ) , [ 'class' => 'btn btn-xs btn-default disabled' ] ) . ' ' ; } $ guests = $ this -> getGuestUsers ( $ url ) ; if ( $ guests ) { $ out .= Html :: button ( Yii :: t ( 'podium/view' , '{n, plural, =1{# guest} other{# guests}}' , [ 'n' => $ guests ] ) , [ 'class' => 'btn btn-xs btn-default disabled' ] ) ; } return $ out ; }
Renders the list of users reading current section .
49,236
public function run ( ) { $ avatar = Html :: img ( Helper :: defaultAvatar ( ) , [ 'class' => 'podium-avatar img-circle img-responsive center-block' , 'alt' => Yii :: t ( 'podium/view' , 'user deleted' ) ] ) ; $ name = Helper :: deletedUserTag ( true ) ; if ( $ this -> author instanceof User ) { $ avatar = Html :: img ( Helper :: defaultAvatar ( ) , [ 'class' => 'podium-avatar img-circle img-responsive center-block' , 'alt' => Html :: encode ( $ this -> author -> podiumName ) ] ) ; $ name = $ this -> author -> podiumTag ; $ meta = $ this -> author -> meta ; if ( ! empty ( $ meta ) ) { if ( ! empty ( $ meta -> gravatar ) ) { $ avatar = Gravatar :: widget ( [ 'email' => $ this -> author -> email , 'defaultImage' => 'identicon' , 'rating' => 'r' , 'options' => [ 'alt' => Html :: encode ( $ this -> author -> podiumName ) , 'class' => 'podium-avatar img-circle img-responsive center-block' , ] ] ) ; } elseif ( ! empty ( $ meta -> avatar ) ) { $ avatar = Html :: img ( '@web/avatars/' . $ meta -> avatar , [ 'class' => 'podium-avatar img-circle img-responsive center-block' , 'alt' => Html :: encode ( $ this -> author -> podiumName ) ] ) ; } } } return $ avatar . ( $ this -> showName ? Html :: tag ( 'p' , $ name , [ 'class' => 'avatar-name' ] ) : '' ) ; }
Renders the image . Based on user settings the avatar can be uploaded image Gravatar image or default one .
49,237
protected function addAdmin ( ) { if ( $ this -> module -> userComponent !== true ) { return $ this -> addInheritedAdmin ( ) ; } $ transaction = $ this -> db -> beginTransaction ( ) ; try { $ admin = new User ( ) ; $ admin -> setScenario ( 'installation' ) ; $ admin -> setAttributes ( [ 'username' => self :: DEFAULT_USERNAME , 'status' => User :: STATUS_ACTIVE , 'role' => User :: ROLE_ADMIN , ] , false ) ; $ admin -> generateAuthKey ( ) ; $ admin -> setPassword ( self :: DEFAULT_USERNAME ) ; if ( ! $ admin -> save ( ) ) { throw new Exception ( VarDumper :: dumpAsString ( $ admin -> errors ) ) ; } if ( ! $ this -> authManager -> assign ( $ this -> authManager -> getRole ( Rbac :: ROLE_ADMIN ) , $ admin -> id ) ) { throw new Exception ( 'Error during Administrator privileges setting!' ) ; } $ transaction -> commit ( ) ; return $ this -> returnSuccess ( Yii :: t ( 'podium/flash' , 'Administrator account has been created.' ) . ' ' . Html :: tag ( 'strong' , Yii :: t ( 'podium/flash' , 'Login' ) . ':' ) . ' ' . Html :: tag ( 'kbd' , self :: DEFAULT_USERNAME ) . ' ' . Html :: tag ( 'strong' , Yii :: t ( 'podium/flash' , 'Password' ) . ':' ) . ' ' . Html :: tag ( 'kbd' , self :: DEFAULT_USERNAME ) . '<br>' . Html :: tag ( 'strong' , Yii :: t ( 'podium/flash' , 'Remember to change these credentials after first login!' ) , [ 'class' => 'text-danger' ] ) ) ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; return $ this -> returnError ( $ e -> getMessage ( ) , __METHOD__ , Yii :: t ( 'podium/flash' , 'Error during account creating' ) ) ; } }
Adds Administrator account .
49,238
protected function addInheritedAdmin ( ) { if ( empty ( $ this -> module -> adminId ) ) { $ this -> type = self :: TYPE_WARNING ; return Yii :: t ( 'podium/flash' , 'No administrator privileges have been set!' ) ; } try { $ identity = Podium :: getInstance ( ) -> user -> identityClass ; $ inheritedUser = $ identity :: findIdentity ( $ this -> module -> adminId ) ; if ( ! $ inheritedUser ) { throw new Exception ( 'Can not find administrator account!' ) ; } $ userNameField = $ this -> module -> userNameField ; if ( $ userNameField !== null && empty ( $ inheritedUser -> $ userNameField ) ) { throw new Exception ( 'Can not find administrator username!' ) ; } } catch ( Exception $ e ) { return $ this -> returnWarning ( Yii :: t ( 'podium/flash' , 'Cannot find inherited user of given ID. No administrator privileges have been set.' ) ) ; } $ transaction = $ this -> db -> beginTransaction ( ) ; try { $ admin = new User ( ) ; $ admin -> setScenario ( 'installation' ) ; $ admin -> setAttributes ( [ 'inherited_id' => $ this -> module -> adminId , 'username' => $ userNameField ? $ inheritedUser -> $ userNameField : self :: DEFAULT_USERNAME , 'status' => User :: STATUS_ACTIVE , 'role' => User :: ROLE_ADMIN , ] , false ) ; if ( ! $ admin -> save ( ) ) { throw new Exception ( VarDumper :: dumpAsString ( $ admin -> errors ) ) ; } if ( ! $ this -> authManager -> assign ( $ this -> authManager -> getRole ( Rbac :: ROLE_ADMIN ) , $ admin -> id ) ) { throw new Exception ( 'Error during Administrator privileges setting!' ) ; } $ transaction -> commit ( ) ; return $ this -> returnSuccess ( Yii :: t ( 'podium/flash' , 'Administrator privileges have been set for the user of ID {id}.' , [ 'id' => $ this -> module -> adminId ] ) ) ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; return $ this -> returnError ( $ e -> getMessage ( ) , __METHOD__ , Yii :: t ( 'podium/flash' , 'Error during account creating' ) ) ; } }
Adds Administrator account for inherited User Identity .
49,239
protected function addConfig ( ) { try { $ this -> db -> createCommand ( ) -> batchInsert ( PodiumConfig :: tableName ( ) , [ 'name' , 'value' ] , [ [ 'activation_token_expire' , PodiumConfig :: SECONDS_ACTIVATION_TOKEN_EXPIRE ] , [ 'allow_polls' , PodiumConfig :: FLAG_ALLOW_POLLS ] , [ 'email_token_expire' , PodiumConfig :: SECONDS_EMAIL_TOKEN_EXPIRE ] , [ 'from_email' , PodiumConfig :: DEFAULT_FROM_EMAIL ] , [ 'from_name' , PodiumConfig :: DEFAULT_FROM_NAME ] , [ 'hot_minimum' , PodiumConfig :: HOT_MINIMUM ] , [ 'maintenance_mode' , PodiumConfig :: MAINTENANCE_MODE ] , [ 'max_attempts' , PodiumConfig :: MAX_SEND_ATTEMPTS ] , [ 'members_visible' , PodiumConfig :: FLAG_MEMBERS_VISIBLE ] , [ 'merge_posts' , PodiumConfig :: FLAG_MERGE_POSTS ] , [ 'meta_description' , PodiumConfig :: META_DESCRIPTION ] , [ 'meta_keywords' , PodiumConfig :: META_KEYWORDS ] , [ 'name' , PodiumConfig :: PODIUM_NAME ] , [ 'password_reset_token_expire' , PodiumConfig :: SECONDS_PASSWORD_RESET_TOKEN_EXPIRE ] , [ 'recaptcha_secretkey' , '' ] , [ 'recaptcha_sitekey' , '' ] , [ 'registration_off' , PodiumConfig :: REGISTRATION_OFF ] , [ 'use_captcha' , PodiumConfig :: FLAG_USE_CAPTCHA ] , [ 'use_wysiwyg' , PodiumConfig :: FLAG_USE_WYSIWYG ] , [ 'version' , Podium :: getInstance ( ) -> version ] , ] ) -> execute ( ) ; return $ this -> returnSuccess ( Yii :: t ( 'podium/flash' , 'Default Config settings have been added.' ) ) ; } catch ( Exception $ e ) { return $ this -> returnError ( $ e -> getMessage ( ) , __METHOD__ , Yii :: t ( 'podium/flash' , 'Error during settings adding' ) ) ; } }
Adds config default settings .
49,240
protected function addContent ( ) { try { $ default = Content :: defaultContent ( ) ; $ this -> db -> createCommand ( ) -> batchInsert ( Content :: tableName ( ) , [ 'name' , 'topic' , 'content' ] , [ [ Content :: TERMS_AND_CONDS , $ default [ Content :: TERMS_AND_CONDS ] [ 'topic' ] , $ default [ Content :: TERMS_AND_CONDS ] [ 'content' ] ] , [ Content :: EMAIL_REGISTRATION , $ default [ Content :: EMAIL_REGISTRATION ] [ 'topic' ] , $ default [ Content :: EMAIL_REGISTRATION ] [ 'content' ] ] , [ Content :: EMAIL_PASSWORD , $ default [ Content :: EMAIL_PASSWORD ] [ 'topic' ] , $ default [ Content :: EMAIL_PASSWORD ] [ 'content' ] ] , [ Content :: EMAIL_REACTIVATION , $ default [ Content :: EMAIL_REACTIVATION ] [ 'topic' ] , $ default [ Content :: EMAIL_REACTIVATION ] [ 'content' ] ] , [ Content :: EMAIL_NEW , $ default [ Content :: EMAIL_NEW ] [ 'topic' ] , $ default [ Content :: EMAIL_NEW ] [ 'content' ] ] , [ Content :: EMAIL_SUBSCRIPTION , $ default [ Content :: EMAIL_SUBSCRIPTION ] [ 'topic' ] , $ default [ Content :: EMAIL_SUBSCRIPTION ] [ 'content' ] ] , ] ) -> execute ( ) ; return $ this -> returnSuccess ( Yii :: t ( 'podium/flash' , 'Default Content has been added.' ) ) ; } catch ( Exception $ e ) { return $ this -> returnError ( $ e -> getMessage ( ) , __METHOD__ , Yii :: t ( 'podium/flash' , 'Error during content adding' ) ) ; } }
Adds default content .
49,241
protected function addRules ( ) { try { ( new Rbac ( ) ) -> add ( $ this -> authManager ) ; return $ this -> returnSuccess ( Yii :: t ( 'podium/flash' , 'Access roles have been created.' ) ) ; } catch ( Exception $ e ) { return $ this -> returnError ( $ e -> getMessage ( ) , __METHOD__ , Yii :: t ( 'podium/flash' , 'Error during access roles creating' ) ) ; } }
Adds permission rules .
49,242
public function nextStep ( ) { $ currentStep = Yii :: $ app -> session -> get ( self :: SESSION_KEY , 0 ) ; if ( $ currentStep === 0 ) { Yii :: $ app -> session -> set ( self :: SESSION_STEPS , count ( $ this -> steps ) ) ; } $ maxStep = Yii :: $ app -> session -> get ( self :: SESSION_STEPS , 0 ) ; $ this -> type = self :: TYPE_ERROR ; $ this -> table = '...' ; if ( $ currentStep >= $ maxStep ) { return [ 'drop' => false , 'type' => $ this -> type , 'result' => Yii :: t ( 'podium/flash' , 'Weird... Installation should already complete...' ) , 'percent' => 100 ] ; } if ( ! isset ( $ this -> steps [ $ currentStep ] ) ) { return [ 'drop' => false , 'type' => $ this -> type , 'result' => Yii :: t ( 'podium/flash' , 'Installation aborted! Can not find the requested installation step.' ) , 'percent' => 100 , ] ; } $ this -> table = $ this -> steps [ $ currentStep ] [ 'table' ] ; $ result = call_user_func_array ( [ $ this , $ this -> steps [ $ currentStep ] [ 'call' ] ] , $ this -> steps [ $ currentStep ] [ 'data' ] ) ; Yii :: $ app -> session -> set ( self :: SESSION_KEY , ++ $ currentStep ) ; return [ 'drop' => false , 'type' => $ this -> type , 'result' => $ result , 'table' => $ this -> rawTable , 'percent' => $ this -> countPercent ( $ currentStep , $ maxStep ) , ] ; }
Proceeds next installation step .
49,243
public function nextDrop ( ) { $ drops = $ this -> countDrops ( ) ; if ( count ( $ drops ) ) { $ currentStep = Yii :: $ app -> session -> get ( self :: SESSION_KEY , 0 ) ; $ maxStep = Yii :: $ app -> session -> get ( self :: SESSION_STEPS , 0 ) ; if ( $ currentStep < $ maxStep ) { $ this -> type = self :: TYPE_ERROR ; $ this -> table = '...' ; if ( ! isset ( $ drops [ $ currentStep ] ) ) { return [ 'drop' => false , 'type' => $ this -> type , 'result' => Yii :: t ( 'podium/flash' , 'Installation aborted! Can not find the requested drop step.' ) , 'percent' => 100 , ] ; } $ this -> table = $ drops [ $ currentStep ] [ 'table' ] ; $ result = $ this -> dropTable ( ) ; if ( $ result === true ) { Yii :: $ app -> session -> set ( self :: SESSION_KEY , ++ $ currentStep ) ; return $ this -> nextDrop ( ) ; } Yii :: $ app -> session -> set ( self :: SESSION_KEY , ++ $ currentStep ) ; return [ 'drop' => true , 'type' => $ this -> type , 'result' => $ result , 'table' => $ this -> rawTable , 'percent' => $ this -> countPercent ( $ currentStep , $ maxStep ) , ] ; } } Yii :: $ app -> session -> set ( self :: SESSION_KEY , 0 ) ; return $ this -> nextStep ( ) ; }
Proceeds next drop step .
49,244
protected function countDrops ( ) { $ steps = array_reverse ( $ this -> steps ) ; $ drops = [ ] ; foreach ( $ steps as $ step ) { if ( isset ( $ step [ 'call' ] ) && $ step [ 'call' ] === 'createTable' ) { $ drops [ ] = $ step ; } } if ( Yii :: $ app -> session -> get ( self :: SESSION_KEY , 0 ) === 0 ) { Yii :: $ app -> session -> set ( self :: SESSION_STEPS , count ( $ drops ) ) ; } return $ drops ; }
Returns list of drops .
49,245
public function actionDeletepost ( $ cid = null , $ fid = null , $ tid = null , $ pid = null ) { $ post = Post :: verify ( $ cid , $ fid , $ tid , $ pid ) ; if ( empty ( $ post ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find the post you are looking for.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } if ( $ post -> thread -> locked == 1 && ! User :: can ( Rbac :: PERM_UPDATE_THREAD , [ 'item' => $ post -> thread ] ) ) { $ this -> info ( Yii :: t ( 'podium/flash' , 'This thread is locked.' ) ) ; return $ this -> redirect ( [ 'forum/thread' , 'cid' => $ post -> forum -> category -> id , 'fid' => $ post -> forum -> id , 'id' => $ post -> thread -> id , 'slug' => $ post -> thread -> slug ] ) ; } if ( ! User :: can ( Rbac :: PERM_DELETE_OWN_POST , [ 'post' => $ post ] ) && ! User :: can ( Rbac :: PERM_DELETE_POST , [ 'item' => $ post ] ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! You do not have the required permission to perform this action.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } $ postData = Yii :: $ app -> request -> post ( 'post' ) ; if ( $ postData ) { if ( $ postData != $ post -> id ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was an error while deleting the post.' ) ) ; } else { if ( $ post -> podiumDelete ( ) ) { $ this -> success ( Yii :: t ( 'podium/flash' , 'Post has been deleted.' ) ) ; if ( Thread :: find ( ) -> where ( [ 'id' => $ post -> thread -> id ] ) -> exists ( ) ) { return $ this -> redirect ( [ 'forum/forum' , 'cid' => $ post -> forum -> category -> id , 'id' => $ post -> forum -> id , 'slug' => $ post -> forum -> slug ] ) ; } return $ this -> redirect ( [ 'forum/thread' , 'cid' => $ post -> forum -> category -> id , 'fid' => $ post -> forum -> id , 'id' => $ post -> thread -> id , 'slug' => $ post -> thread -> slug ] ) ; } $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was an error while deleting the post.' ) ) ; } } return $ this -> render ( 'deletepost' , [ 'model' => $ post ] ) ; }
Deleting the post of given category ID forum ID thread ID and ID .
49,246
public function actionDeleteposts ( $ cid = null , $ fid = null , $ id = null , $ slug = null ) { $ thread = ( new ThreadVerifier ( [ 'categoryId' => $ cid , 'forumId' => $ fid , 'threadId' => $ id , 'threadSlug' => $ slug ] ) ) -> verify ( ) ; if ( empty ( $ thread ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find the thread you are looking for.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } if ( ! User :: can ( Rbac :: PERM_DELETE_POST , [ 'item' => $ thread ] ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! You do not have the required permission to perform this action.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } $ posts = Yii :: $ app -> request -> post ( 'post' ) ; if ( $ posts ) { if ( ! is_array ( $ posts ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'You have to select at least one post.' ) ) ; } else { if ( $ thread -> podiumDeletePosts ( $ posts ) ) { $ this -> success ( Yii :: t ( 'podium/flash' , 'Posts have been deleted.' ) ) ; if ( Thread :: find ( ) -> where ( [ 'id' => $ thread -> id ] ) -> exists ( ) ) { return $ this -> redirect ( [ 'forum/thread' , 'cid' => $ thread -> forum -> category -> id , 'fid' => $ thread -> forum -> id , 'id' => $ thread -> id , 'slug' => $ thread -> slug ] ) ; } return $ this -> redirect ( [ 'forum' , 'cid' => $ thread -> forum -> category -> id , 'id' => $ thread -> forum -> id , 'slug' => $ thread -> forum -> slug ] ) ; } $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was an error while deleting the posts.' ) ) ; } } return $ this -> render ( 'deleteposts' , [ 'model' => $ thread , 'dataProvider' => ( new Post ( ) ) -> search ( $ thread -> forum -> id , $ thread -> id ) ] ) ; }
Deleting the posts of given category ID forum ID thread ID and slug .
49,247
public function actionReport ( $ cid = null , $ fid = null , $ tid = null , $ pid = null ) { $ post = Post :: verify ( $ cid , $ fid , $ tid , $ pid ) ; if ( empty ( $ post ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find the post you are looking for.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } if ( User :: can ( Rbac :: PERM_UPDATE_POST , [ 'item' => $ post ] ) ) { $ this -> info ( Yii :: t ( 'podium/flash' , "You don't have to report this post since you are allowed to modify it." ) ) ; return $ this -> redirect ( [ 'forum/edit' , 'cid' => $ post -> forum -> category -> id , 'fid' => $ post -> forum -> id , 'tid' => $ post -> thread -> id , 'pid' => $ post -> id ] ) ; } if ( $ post -> author_id == User :: loggedId ( ) ) { $ this -> info ( Yii :: t ( 'podium/flash' , 'You can not report your own post. Please contact the administrator or moderators if you have got any concerns regarding your post.' ) ) ; return $ this -> redirect ( [ 'forum/thread' , 'cid' => $ post -> forum -> category -> id , 'fid' => $ post -> forum -> id , 'id' => $ post -> thread -> id , 'slug' => $ post -> thread -> slug ] ) ; } $ model = new Message ( ) ; $ model -> scenario = 'report' ; if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> validate ( ) ) { if ( $ model -> podiumReport ( $ post ) ) { $ this -> success ( Yii :: t ( 'podium/flash' , 'Thank you for your report. The moderation team will take a look at this post.' ) ) ; return $ this -> redirect ( [ 'forum/thread' , 'cid' => $ post -> forum -> category -> id , 'fid' => $ post -> forum -> id , 'id' => $ post -> thread -> id , 'slug' => $ post -> thread -> slug ] ) ; } $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was an error while notifying the moderation team. Contact administrator about this problem.' ) ) ; } return $ this -> render ( 'report' , [ 'model' => $ model , 'post' => $ post ] ) ; }
Reporting the post of given category ID forum ID thread ID own ID and slug .
49,248
public function actionMarkSeen ( ) { if ( Thread :: podiumMarkAllSeen ( ) ) { $ this -> success ( Yii :: t ( 'podium/flash' , 'All unread threads have been marked as seen.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was an error while marking threads as seen. Contact administrator about this problem.' ) ) ; return $ this -> redirect ( [ 'forum/unread-posts' ] ) ; }
Marking all unread posts as seen .
49,249
public function run ( ) { $ user = $ this -> user ; if ( empty ( $ user ) ) { return [ true , Yii :: t ( 'podium/flash' , 'Sorry! We can not find the account with that user name or e-mail address.' ) , false ] ; } $ user -> scenario = 'token' ; $ user -> generatePasswordResetToken ( ) ; if ( ! $ user -> save ( ) ) { return [ true , null , false ] ; } if ( empty ( $ user -> email ) ) { return [ true , Yii :: t ( 'podium/flash' , 'Sorry! There is no e-mail address saved with your account. Contact administrator about resetting password.' ) , true ] ; } if ( ! $ this -> sendResetEmail ( $ user ) ) { return [ true , Yii :: t ( 'podium/flash' , 'Sorry! There was some error while sending you the password reset link. Contact administrator about this problem.' ) , true ] ; } return [ false , Yii :: t ( 'podium/flash' , 'The password reset link has been sent to your e-mail address.' ) , true ] ; }
Generates new password reset token .
49,250
public function actionCategory ( $ id = null , $ slug = null ) { if ( ! is_numeric ( $ id ) || $ id < 1 || empty ( $ slug ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find the category you are looking for.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } $ conditions = [ 'id' => $ id , 'slug' => $ slug ] ; if ( $ this -> module -> user -> isGuest ) { $ conditions [ 'visible' ] = 1 ; } $ model = Category :: find ( ) -> where ( $ conditions ) -> limit ( 1 ) -> one ( ) ; if ( empty ( $ model ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find the category you are looking for.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } $ this -> setMetaTags ( $ model -> keywords , $ model -> description ) ; return $ this -> render ( 'category' , [ 'model' => $ model ] ) ; }
Displaying the category of given ID and slug .
49,251
public function actionForum ( $ cid = null , $ id = null , $ slug = null , $ toggle = null ) { $ filters = Yii :: $ app -> session -> get ( 'forum-filters' ) ; if ( in_array ( strtolower ( $ toggle ) , [ 'new' , 'edit' , 'hot' , 'pin' , 'lock' , 'all' ] ) ) { if ( strtolower ( $ toggle ) == 'all' ) { $ filters = null ; } else { $ filters [ strtolower ( $ toggle ) ] = empty ( $ filters [ strtolower ( $ toggle ) ] ) || $ filters [ strtolower ( $ toggle ) ] == 0 ? 1 : 0 ; } Yii :: $ app -> session -> set ( 'forum-filters' , $ filters ) ; return $ this -> redirect ( [ 'forum/forum' , 'cid' => $ cid , 'id' => $ id , 'slug' => $ slug ] ) ; } $ forum = Forum :: verify ( $ cid , $ id , $ slug , $ this -> module -> user -> isGuest ) ; if ( empty ( $ forum ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find the forum you are looking for.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } $ this -> setMetaTags ( $ forum -> keywords ? : $ forum -> category -> keywords , $ forum -> description ? : $ forum -> category -> description ) ; return $ this -> render ( 'forum' , [ 'model' => $ forum , 'filters' => $ filters ] ) ; }
Displaying the forum of given category ID own ID and slug .
49,252
public function actionLast ( $ id = null ) { if ( ! is_numeric ( $ id ) || $ id < 1 ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find the thread you are looking for.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } $ thread = Thread :: find ( ) -> where ( [ 'id' => $ id ] ) -> limit ( 1 ) -> one ( ) ; if ( empty ( $ thread ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find the thread you are looking for.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } $ url = [ 'forum/thread' , 'cid' => $ thread -> category_id , 'fid' => $ thread -> forum_id , 'id' => $ thread -> id , 'slug' => $ thread -> slug ] ; $ count = $ thread -> postsCount ; $ page = floor ( $ count / 10 ) + 1 ; if ( $ page > 1 ) { $ url [ 'page' ] = $ page ; } return $ this -> redirect ( $ url ) ; }
Direct link for the last post in thread of given ID .
49,253
public function actionShow ( $ id = null ) { if ( ! is_numeric ( $ id ) || $ id < 1 ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find the post you are looking for.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } $ post = Post :: find ( ) -> where ( [ 'id' => $ id ] ) -> limit ( 1 ) -> one ( ) ; if ( empty ( $ post ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find the post you are looking for.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } $ url = [ 'forum/thread' , 'cid' => $ post -> thread -> category_id , 'fid' => $ post -> forum_id , 'id' => $ post -> thread_id , 'slug' => $ post -> thread -> slug ] ; try { $ count = ( new Query ) -> from ( Post :: tableName ( ) ) -> where ( [ 'and' , [ 'thread_id' => $ post -> thread_id ] , [ '<' , 'id' , $ post -> id ] ] ) -> count ( ) ; $ page = floor ( $ count / 10 ) + 1 ; if ( $ page > 1 ) { $ url [ 'page' ] = $ page ; } $ url [ '#' ] = 'post' . $ post -> id ; return $ this -> redirect ( $ url ) ; } catch ( Exception $ e ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find the post you are looking for.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } }
Direct link for the post of given ID .
49,254
public function actionThread ( $ cid = null , $ fid = null , $ id = null , $ slug = null ) { $ thread = ( new ThreadVerifier ( [ 'categoryId' => $ cid , 'forumId' => $ fid , 'threadId' => $ id , 'threadSlug' => $ slug ] ) ) -> verify ( ) ; if ( empty ( $ thread ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find the thread you are looking for.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } $ this -> setMetaTags ( $ thread -> forum -> keywords ? : $ thread -> forum -> category -> keywords , $ thread -> forum -> description ? : $ thread -> forum -> category -> description ) ; $ model = new Post ; $ model -> subscribe = 1 ; $ dataProvider = $ model -> search ( $ thread -> forum -> id , $ thread -> id ) ; return $ this -> render ( 'thread' , [ 'model' => $ model , 'dataProvider' => $ dataProvider , 'thread' => $ thread , ] ) ; }
Displaying the thread of given category ID forum ID own ID and slug .
49,255
public function setMetaTags ( $ keywords = null , $ description = null ) { if ( empty ( $ keywords ) ) { $ keywords = $ this -> module -> podiumConfig -> get ( 'meta_keywords' ) ; } if ( $ keywords ) { $ this -> getView ( ) -> registerMetaTag ( [ 'name' => 'keywords' , 'content' => $ keywords ] ) ; } if ( empty ( $ description ) ) { $ description = $ this -> module -> podiumConfig -> get ( 'meta_description' ) ; } if ( $ description ) { $ this -> getView ( ) -> registerMetaTag ( [ 'name' => 'description' , 'content' => $ description ] ) ; } }
Setting meta tags .
49,256
public function actionDeletepoll ( $ cid = null , $ fid = null , $ tid = null , $ pid = null ) { $ poll = Poll :: find ( ) -> joinWith ( 'thread' ) -> where ( [ Poll :: tableName ( ) . '.id' => $ pid , Poll :: tableName ( ) . '.thread_id' => $ tid , Thread :: tableName ( ) . '.category_id' => $ cid , Thread :: tableName ( ) . '.forum_id' => $ fid , ] ) -> limit ( 1 ) -> one ( ) ; if ( empty ( $ poll ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! We can not find the poll you are looking for.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } if ( $ poll -> thread -> locked == 1 && ! User :: can ( Rbac :: PERM_UPDATE_THREAD , [ 'item' => $ poll -> thread ] ) ) { $ this -> info ( Yii :: t ( 'podium/flash' , 'This thread is locked.' ) ) ; return $ this -> redirect ( [ 'forum/thread' , 'cid' => $ poll -> thread -> category_id , 'fid' => $ poll -> thread -> forum_id , 'id' => $ poll -> thread -> id , 'slug' => $ poll -> thread -> slug ] ) ; } if ( $ poll -> author_id != User :: loggedId ( ) && ! User :: can ( Rbac :: PERM_UPDATE_THREAD , [ 'item' => $ poll -> thread ] ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! You do not have the required permission to perform this action.' ) ) ; return $ this -> redirect ( [ 'forum/index' ] ) ; } $ postData = Yii :: $ app -> request -> post ( 'poll' ) ; if ( $ postData ) { if ( $ postData != $ poll -> id ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was an error while deleting the poll.' ) ) ; } else { if ( $ poll -> podiumDelete ( ) ) { $ this -> success ( Yii :: t ( 'podium/flash' , 'Poll has been deleted.' ) ) ; return $ this -> redirect ( [ 'forum/thread' , 'cid' => $ poll -> thread -> category_id , 'fid' => $ poll -> thread -> forum_id , 'id' => $ poll -> thread -> id , 'slug' => $ poll -> thread -> slug ] ) ; } $ this -> error ( Yii :: t ( 'podium/flash' , 'Sorry! There was an error while deleting the poll.' ) ) ; } } return $ this -> render ( 'deletepoll' , [ 'model' => $ poll ] ) ; }
Deleting the poll of given category ID forum ID thread ID and ID .
49,257
public function actionSearch ( ) { $ searchModel = new Vocabulary ; if ( ! $ searchModel -> load ( Yii :: $ app -> request -> get ( ) , '' ) ) { return $ this -> redirect ( [ 'forum/advanced-search' ] ) ; } return $ this -> render ( 'search' , [ 'dataProvider' => $ searchModel -> search ( ) , 'query' => $ searchModel -> query , ] ) ; }
Searching through the forum .
49,258
public function actionAdvancedSearch ( ) { $ dataProvider = null ; $ list = [ ] ; $ model = new SearchForm ; $ model -> setParams ( ) ; if ( $ model -> nextPage ) { $ dataProvider = $ model -> searchAdvanced ( ) ; } else { $ categories = Category :: find ( ) -> orderBy ( [ 'name' => SORT_ASC ] ) ; $ forums = Forum :: find ( ) -> orderBy ( [ 'name' => SORT_ASC ] ) ; foreach ( $ categories -> each ( ) as $ cat ) { $ catlist = [ ] ; foreach ( $ forums -> each ( ) as $ for ) { if ( $ for -> category_id == $ cat -> id ) { $ catlist [ $ for -> id ] = '|-- ' . Html :: encode ( $ for -> name ) ; } } $ list [ Html :: encode ( $ cat -> name ) ] = $ catlist ; } if ( $ model -> load ( Yii :: $ app -> request -> post ( ) ) && $ model -> validate ( ) ) { if ( empty ( $ model -> query ) && empty ( $ model -> author ) ) { $ this -> error ( Yii :: t ( 'podium/flash' , "You have to enter words or author's name first." ) ) ; } else { $ stop = false ; if ( ! empty ( $ model -> query ) ) { $ words = explode ( ' ' , preg_replace ( '/\s+/' , ' ' , $ model -> query ) ) ; $ checkedWords = [ ] ; foreach ( $ words as $ word ) { if ( mb_strlen ( $ word , 'UTF-8' ) > 2 ) { $ checkedWords [ ] = $ word ; } } $ model -> query = implode ( ' ' , $ checkedWords ) ; if ( mb_strlen ( $ model -> query , 'UTF-8' ) < 3 ) { $ this -> error ( Yii :: t ( 'podium/flash' , 'You have to enter word at least 3 characters long.' ) ) ; $ stop = true ; } } if ( ! $ stop ) { $ dataProvider = $ model -> searchAdvanced ( ) ; } } } } return $ this -> render ( 'search' , [ 'model' => $ model , 'list' => $ list , 'dataProvider' => $ dataProvider , 'query' => $ model -> query , 'author' => $ model -> author , ] ) ; }
Advanced searching through the forum .
49,259
public function activate ( ) { if ( $ this -> status == self :: STATUS_REGISTERED ) { $ transaction = static :: getDb ( ) -> beginTransaction ( ) ; try { $ this -> removeActivationToken ( ) ; $ this -> status = self :: STATUS_ACTIVE ; if ( ! $ this -> save ( ) ) { throw new Exception ( 'User saving error!' ) ; } if ( ! Podium :: getInstance ( ) -> rbac -> assign ( Podium :: getInstance ( ) -> rbac -> getRole ( Rbac :: ROLE_USER ) , $ this -> id ) ) { throw new Exception ( 'User role assigning error!' ) ; } $ transaction -> commit ( ) ; return true ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } } return false ; }
Activates account .
49,260
public function changeEmail ( ) { $ this -> email = $ this -> new_email ; $ this -> new_email = null ; $ this -> removeEmailToken ( ) ; return $ this -> save ( ) ; }
Changes email address .
49,261
public function getNewMessagesCount ( ) { $ cache = Podium :: getInstance ( ) -> podiumCache -> getElement ( 'user.newmessages' , $ this -> id ) ; if ( $ cache === false ) { $ cache = ( new Query ( ) ) -> from ( MessageReceiver :: tableName ( ) ) -> where ( [ 'receiver_id' => $ this -> id , 'receiver_status' => Message :: STATUS_NEW ] ) -> count ( ) ; Podium :: getInstance ( ) -> podiumCache -> setElement ( 'user.newmessages' , $ this -> id , $ cache ) ; } return $ cache ; }
Returns number of new user messages .
49,262
public function getPodiumTag ( $ simple = false ) { return Helper :: podiumUserTag ( $ this -> podiumName , $ this -> role , $ this -> id , $ this -> podiumSlug , $ simple ) ; }
Returns Podium name tag .
49,263
public static function findPostsCount ( $ id ) { $ cache = Podium :: getInstance ( ) -> podiumCache -> getElement ( 'user.postscount' , $ id ) ; if ( $ cache === false ) { $ cache = ( new Query ) -> from ( Post :: tableName ( ) ) -> where ( [ 'author_id' => $ id ] ) -> count ( ) ; Podium :: getInstance ( ) -> podiumCache -> setElement ( 'user.postscount' , $ id , $ cache ) ; } return $ cache ; }
Returns number of active posts added by user of given ID .
49,264
public static function findThreadsCount ( $ id ) { $ cache = Podium :: getInstance ( ) -> podiumCache -> getElement ( 'user.threadscount' , $ id ) ; if ( $ cache === false ) { $ cache = ( new Query ) -> from ( Thread :: tableName ( ) ) -> where ( [ 'author_id' => $ id ] ) -> count ( ) ; Podium :: getInstance ( ) -> podiumCache -> setElement ( 'user.threadscount' , $ id , $ cache ) ; } return $ cache ; }
Returns number of active threads added by user of given ID .
49,265
public static function getRoles ( ) { return [ self :: ROLE_MEMBER => Yii :: t ( 'podium/view' , 'Member' ) , self :: ROLE_MODERATOR => Yii :: t ( 'podium/view' , 'Moderator' ) , self :: ROLE_ADMIN => Yii :: t ( 'podium/view' , 'Admin' ) , ] ; }
Returns list of roles .
49,266
public static function getStatuses ( ) { return [ self :: STATUS_ACTIVE => Yii :: t ( 'podium/view' , 'Active' ) , self :: STATUS_BANNED => Yii :: t ( 'podium/view' , 'Banned' ) , self :: STATUS_REGISTERED => Yii :: t ( 'podium/view' , 'Registered' ) , ] ; }
Returns list of statuses .
49,267
public function getSubscriptionsCount ( ) { $ cache = Podium :: getInstance ( ) -> podiumCache -> getElement ( 'user.subscriptions' , $ this -> id ) ; if ( $ cache === false ) { $ cache = ( new Query ) -> from ( Subscription :: tableName ( ) ) -> where ( [ 'user_id' => $ this -> id , 'post_seen' => Subscription :: POST_NEW ] ) -> count ( ) ; Podium :: getInstance ( ) -> podiumCache -> setElement ( 'user.subscriptions' , $ this -> id , $ cache ) ; } return $ cache ; }
Returns number of user subscribed threads with new posts .
49,268
public function isIgnoredBy ( $ userId ) { if ( ( new Query ) -> select ( 'id' ) -> from ( '{{%podium_user_ignore}}' ) -> where ( [ 'user_id' => $ userId , 'ignored_id' => $ this -> id ] ) -> exists ( ) ) { return true ; } return false ; }
Finds out if user is ignored by another .
49,269
public function isIgnoring ( $ user_id ) { if ( ( new Query ) -> select ( 'id' ) -> from ( '{{%podium_user_ignore}}' ) -> where ( [ 'user_id' => $ this -> id , 'ignored_id' => $ user_id ] ) -> exists ( ) ) { return true ; } return false ; }
Finds out if user is ignoring another .
49,270
public static function loggedId ( ) { if ( Podium :: getInstance ( ) -> user -> isGuest ) { return null ; } if ( Podium :: getInstance ( ) -> userComponent !== true ) { $ user = static :: findMe ( ) ; if ( empty ( $ user ) ) { return null ; } return $ user -> id ; } return Podium :: getInstance ( ) -> user -> id ; }
Returns ID of current logged user .
49,271
public function demoteTo ( $ role ) { $ transaction = static :: getDb ( ) -> beginTransaction ( ) ; try { $ this -> scenario = 'role' ; $ this -> role = $ role ; if ( ! $ this -> save ( ) ) { throw new Exception ( 'User saving error!' ) ; } if ( Podium :: getInstance ( ) -> rbac -> getRolesByUser ( $ this -> id ) && ! Podium :: getInstance ( ) -> rbac -> revoke ( Podium :: getInstance ( ) -> rbac -> getRole ( Rbac :: ROLE_MODERATOR ) , $ this -> id ) ) { throw new Exception ( 'User role revoking error!' ) ; } if ( ! Podium :: getInstance ( ) -> rbac -> assign ( Podium :: getInstance ( ) -> rbac -> getRole ( Rbac :: ROLE_USER ) , $ this -> id ) ) { throw new Exception ( 'User role assigning error!' ) ; } if ( ( new Query ( ) ) -> from ( Mod :: tableName ( ) ) -> where ( [ 'user_id' => $ this -> id ] ) -> exists ( ) && ! Podium :: getInstance ( ) -> db -> createCommand ( ) -> delete ( Mod :: tableName ( ) , [ 'user_id' => $ this -> id ] ) -> execute ( ) ) { throw new Exception ( 'Moderator deleting error!' ) ; } Activity :: updateRole ( $ this -> id , User :: ROLE_MEMBER ) ; $ transaction -> commit ( ) ; Log :: info ( 'User demoted' , $ this -> id , __METHOD__ ) ; return true ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Demotes user to given role .
49,272
public function promoteTo ( $ role ) { $ transaction = static :: getDb ( ) -> beginTransaction ( ) ; try { $ this -> scenario = 'role' ; $ this -> role = $ role ; if ( ! $ this -> save ( ) ) { throw new Exception ( 'User saving error!' ) ; } if ( Podium :: getInstance ( ) -> rbac -> getRolesByUser ( $ this -> id ) && ! Podium :: getInstance ( ) -> rbac -> revoke ( Podium :: getInstance ( ) -> rbac -> getRole ( Rbac :: ROLE_USER ) , $ this -> id ) ) { throw new Exception ( 'User role revoking error!' ) ; } if ( ! Podium :: getInstance ( ) -> rbac -> assign ( Podium :: getInstance ( ) -> rbac -> getRole ( Rbac :: ROLE_MODERATOR ) , $ this -> id ) ) { throw new Exception ( 'User role assigning error!' ) ; } Activity :: updateRole ( $ this -> id , User :: ROLE_MODERATOR ) ; $ transaction -> commit ( ) ; Log :: info ( 'User promoted' , $ this -> id , __METHOD__ ) ; return true ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Promotes user to given role . Only moderator supported now .
49,273
public function register ( ) { $ this -> setPassword ( $ this -> password ) ; $ this -> generateActivationToken ( ) ; $ this -> generateAuthKey ( ) ; $ this -> status = self :: STATUS_REGISTERED ; if ( ! $ this -> save ( ) ) { return self :: RESP_ERR ; } if ( empty ( $ this -> email ) ) { return self :: RESP_NO_EMAIL_ERR ; } if ( ! $ this -> sendActivationEmail ( ) ) { return self :: RESP_EMAIL_SEND_ERR ; } return self :: RESP_OK ; }
Registers new account .
49,274
public function saveChanges ( ) { if ( ! empty ( $ this -> newPassword ) ) { $ this -> setPassword ( $ this -> newPassword ) ; } if ( ! empty ( $ this -> new_email ) ) { $ this -> generateEmailToken ( ) ; } $ updateActivityName = $ this -> isAttributeChanged ( 'username' ) ; if ( ! $ this -> save ( false ) ) { return false ; } if ( $ updateActivityName ) { Activity :: updateName ( $ this -> id , $ this -> podiumName , $ this -> podiumSlug ) ; } return true ; }
Saves user account details changes .
49,275
public static function friendsList ( ) { if ( Podium :: getInstance ( ) -> user -> isGuest ) { return null ; } $ logged = static :: loggedId ( ) ; $ cache = Podium :: getInstance ( ) -> podiumCache -> getElement ( 'user.friends' , $ logged ) ; if ( $ cache === false ) { $ cache = [ ] ; $ friends = static :: findMe ( ) -> friends ; if ( $ friends ) { foreach ( $ friends as $ friend ) { $ cache [ $ friend -> id ] = $ friend -> getPodiumTag ( true ) ; } } Podium :: getInstance ( ) -> podiumCache -> setElement ( 'user.friends' , $ logged , $ cache ) ; } return $ cache ; }
Returns list of friends for dropdown .
49,276
public function updateModeratorForOne ( $ forumId = null ) { try { if ( ( new Query ( ) ) -> from ( Mod :: tableName ( ) ) -> where ( [ 'forum_id' => $ forumId , 'user_id' => $ this -> id ] ) -> exists ( ) ) { Podium :: getInstance ( ) -> db -> createCommand ( ) -> delete ( Mod :: tableName ( ) , [ 'forum_id' => $ forumId , 'user_id' => $ this -> id ] ) -> execute ( ) ; } else { Podium :: getInstance ( ) -> db -> createCommand ( ) -> insert ( Mod :: tableName ( ) , [ 'forum_id' => $ forumId , 'user_id' => $ this -> id ] ) -> execute ( ) ; } Podium :: getInstance ( ) -> podiumCache -> deleteElement ( 'forum.moderators' , $ forumId ) ; Log :: info ( 'Moderator updated' , $ this -> id , __METHOD__ ) ; return true ; } catch ( Exception $ e ) { Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Updates moderator assignment for given forum .
49,277
public function updateModeratorForMany ( $ newForums = [ ] , $ oldForums = [ ] ) { $ transaction = static :: getDb ( ) -> beginTransaction ( ) ; try { $ add = [ ] ; foreach ( $ newForums as $ forum ) { if ( ! in_array ( $ forum , $ oldForums , true ) && ( new Query ) -> from ( Forum :: tableName ( ) ) -> where ( [ 'id' => $ forum ] ) -> exists ( ) && ( new Query ) -> from ( Mod :: tableName ( ) ) -> where ( [ 'forum_id' => $ forum , 'user_id' => $ this -> id ] ) -> exists ( ) === false ) { $ add [ ] = [ $ forum , $ this -> id ] ; } } $ remove = [ ] ; foreach ( $ oldForums as $ forum ) { if ( ! in_array ( $ forum , $ newForums , true ) && ( new Query ) -> from ( Mod :: tableName ( ) ) -> where ( [ 'forum_id' => $ forum , 'user_id' => $ this -> id ] ) -> exists ( ) ) { $ remove [ ] = $ forum ; } } if ( ! empty ( $ add ) && ! Podium :: getInstance ( ) -> db -> createCommand ( ) -> batchInsert ( Mod :: tableName ( ) , [ 'forum_id' , 'user_id' ] , $ add ) -> execute ( ) ) { throw new Exception ( 'Moderators adding error!' ) ; } if ( ! empty ( $ remove ) && ! Podium :: getInstance ( ) -> db -> createCommand ( ) -> delete ( Mod :: tableName ( ) , [ 'forum_id' => $ remove , 'user_id' => $ this -> id ] ) -> execute ( ) ) { throw new Exception ( 'Moderators deleting error!' ) ; } Podium :: getInstance ( ) -> podiumCache -> delete ( 'forum.moderators' ) ; Log :: info ( 'Moderators updated' , null , __METHOD__ ) ; $ transaction -> commit ( ) ; return true ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Updates moderator assignment for given forums .
49,278
protected function generateUsername ( ) { $ userNameField = Podium :: getInstance ( ) -> userNameField ; if ( $ userNameField !== null ) { if ( empty ( Podium :: getInstance ( ) -> user -> identity -> $ userNameField ) ) { throw new InvalidConfigException ( "Non-existing or empty '$userNameField' field!" ) ; } $ username = Podium :: getInstance ( ) -> user -> identity -> $ userNameField ; } else { $ try = 0 ; do { $ username = 'user_' . time ( ) . mt_rand ( 1000 , 9999 ) ; if ( $ try ++ > 10 ) { throw new Exception ( 'Failed to generate unique username!' ) ; } } while ( ( new Query ) -> from ( static :: tableName ( ) ) -> where ( [ 'username' => $ username ] ) -> exists ( ) ) ; } $ this -> username = $ username ; }
Generates username for inherited account .
49,279
public static function createInheritedAccount ( ) { if ( ! Podium :: getInstance ( ) -> user -> isGuest ) { $ transaction = static :: getDb ( ) -> beginTransaction ( ) ; try { $ newUser = new static ; $ newUser -> setScenario ( 'installation' ) ; $ newUser -> inherited_id = Podium :: getInstance ( ) -> user -> id ; $ newUser -> status = self :: STATUS_ACTIVE ; $ newUser -> role = self :: ROLE_MEMBER ; $ newUser -> generateUsername ( ) ; if ( ! $ newUser -> save ( ) ) { throw new Exception ( 'Account creating error' ) ; } if ( ! Podium :: getInstance ( ) -> rbac -> assign ( Podium :: getInstance ( ) -> rbac -> getRole ( Rbac :: ROLE_USER ) , $ newUser -> id ) ) { throw new Exception ( 'User role assigning error' ) ; } PodiumCache :: clearAfter ( 'activate' ) ; Log :: info ( 'Inherited account created' , $ newUser -> id , __METHOD__ ) ; $ transaction -> commit ( ) ; return true ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } } return false ; }
Creates inherited account .
49,280
public static function updateInheritedAccount ( ) { if ( ! Podium :: getInstance ( ) -> user -> isGuest ) { $ userNameField = Podium :: getInstance ( ) -> userNameField ; if ( $ userNameField === null ) { return true ; } if ( empty ( Podium :: getInstance ( ) -> user -> identity -> $ userNameField ) ) { throw new InvalidConfigException ( "Non-existing or empty '$userNameField' field!" ) ; } $ savedUser = static :: find ( ) -> where ( [ 'inherited_id' => Podium :: getInstance ( ) -> user -> id ] ) -> limit ( 1 ) -> one ( ) ; if ( empty ( $ savedUser ) ) { throw new InvalidConfigException ( 'Can not find inherited account in database!' ) ; } if ( $ savedUser -> username === Podium :: getInstance ( ) -> user -> identity -> $ userNameField ) { return true ; } $ savedUser -> scenario = 'installation' ; $ savedUser -> username = Podium :: getInstance ( ) -> user -> identity -> $ userNameField ; if ( $ savedUser -> save ( ) ) { Log :: info ( 'Inherited account updated' , $ savedUser -> id , __METHOD__ ) ; return true ; } throw new Exception ( 'Inherited account updating error' ) ; } return true ; }
Updates inherited account s username .
49,281
public static function getMembersList ( $ query = null ) { if ( null === $ query || ! is_string ( $ query ) ) { return Json :: encode ( [ 'results' => [ ] ] ) ; } $ cache = Podium :: getInstance ( ) -> podiumCache -> getElement ( 'members.fieldlist' , $ query ) ; if ( $ cache === false ) { $ users = static :: find ( ) -> where ( [ 'and' , [ 'status' => self :: STATUS_ACTIVE ] , [ '!=' , 'id' , static :: loggedId ( ) ] , [ 'like' , 'username' , $ query ] ] ) ; $ users -> orderBy ( [ 'username' => SORT_ASC , 'id' => SORT_ASC ] ) ; $ results = [ 'results' => [ ] ] ; foreach ( $ users -> each ( ) as $ user ) { $ results [ 'results' ] [ ] = [ 'id' => $ user -> id , 'text' => $ user -> getPodiumTag ( true ) ] ; } if ( empty ( $ results [ 'results' ] ) ) { return Json :: encode ( [ 'results' => [ ] ] ) ; } $ cache = Json :: encode ( $ results ) ; Podium :: getInstance ( ) -> podiumCache -> setElement ( 'members.fieldlist' , $ query , $ cache ) ; } return $ cache ; }
Returns JSON list of members matching query .
49,282
public function updateIgnore ( $ member ) { try { if ( $ this -> isIgnoredBy ( $ member ) ) { if ( ! Podium :: getInstance ( ) -> db -> createCommand ( ) -> delete ( '{{%podium_user_ignore}}' , [ 'user_id' => $ member , 'ignored_id' => $ this -> id ] ) -> execute ( ) ) { return false ; } Log :: info ( 'User unignored' , $ this -> id , __METHOD__ ) ; } else { if ( ! Podium :: getInstance ( ) -> db -> createCommand ( ) -> insert ( '{{%podium_user_ignore}}' , [ 'user_id' => $ member , 'ignored_id' => $ this -> id ] ) -> execute ( ) ) { return false ; } Log :: info ( 'User ignored' , $ this -> id , __METHOD__ ) ; } return true ; } catch ( Exception $ e ) { Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Updates ignore status for the user .
49,283
public function updateFriend ( $ friend ) { try { if ( $ this -> isBefriendedBy ( $ friend ) ) { if ( ! Podium :: getInstance ( ) -> db -> createCommand ( ) -> delete ( '{{%podium_user_friend}}' , [ 'user_id' => $ friend , 'friend_id' => $ this -> id ] ) -> execute ( ) ) { return false ; } Log :: info ( 'User unfriended' , $ this -> id , __METHOD__ ) ; } else { if ( ! Podium :: getInstance ( ) -> db -> createCommand ( ) -> insert ( '{{%podium_user_friend}}' , [ 'user_id' => $ friend , 'friend_id' => $ this -> id ] ) -> execute ( ) ) { return false ; } Log :: info ( 'User befriended' , $ this -> id , __METHOD__ ) ; } Podium :: getInstance ( ) -> podiumCache -> deleteElement ( 'user.friends' , $ friend ) ; return true ; } catch ( Exception $ e ) { Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Updates friend status for the user .
49,284
protected function sendActivationEmail ( ) { $ forum = Podium :: getInstance ( ) -> podiumConfig -> get ( 'name' ) ; $ email = Content :: fill ( Content :: EMAIL_REGISTRATION ) ; if ( $ email !== false ) { $ link = Url :: to ( [ 'account/activate' , 'token' => $ this -> activation_token ] , true ) ; return Email :: queue ( $ this -> email , str_replace ( '{forum}' , $ forum , $ email -> topic ) , str_replace ( '{forum}' , $ forum , str_replace ( '{link}' , Html :: a ( $ link , $ link ) , $ email -> content ) ) , ! empty ( $ this -> id ) ? $ this -> id : null ) ; } return false ; }
Sends activation email .
49,285
public static function findMe ( ) { if ( Podium :: getInstance ( ) -> userComponent === true ) { return Podium :: getInstance ( ) -> user -> identity ; } if ( static :: $ _identity === null ) { static :: $ _identity = static :: find ( ) -> where ( [ 'inherited_id' => Podium :: getInstance ( ) -> user -> id ] ) -> limit ( 1 ) -> one ( ) ; } return static :: $ _identity ; }
Returns current user based on module configuration .
49,286
public function run ( ) { if ( ! $ this -> model ) { return null ; } $ hidden = $ this -> model -> hidden ; if ( $ hidden && ! empty ( $ this -> model -> end_at ) && $ this -> model -> end_at < time ( ) ) { $ hidden = 0 ; } return $ this -> render ( 'view' , [ 'model' => $ this -> model , 'hidden' => $ hidden , 'voted' => $ this -> display ? true : $ this -> model -> getUserVoted ( User :: loggedId ( ) ) , 'display' => $ this -> display ] ) ; }
Rendering the poll .
49,287
public function firstToSee ( ) { if ( $ this -> firstNewNotSeen ) { return $ this -> firstNewNotSeen ; } if ( $ this -> firstEditedNotSeen ) { return $ this -> firstEditedNotSeen ; } return $ this -> latest ; }
Returns first post to see .
49,288
public function search ( $ forumId = null , $ filters = null ) { $ query = static :: find ( ) ; if ( $ forumId ) { $ query -> where ( [ 'forum_id' => ( int ) $ forumId ] ) ; } if ( ! empty ( $ filters ) ) { $ loggedId = User :: loggedId ( ) ; if ( ! empty ( $ filters [ 'pin' ] ) && $ filters [ 'pin' ] == 1 ) { $ query -> andWhere ( [ 'pinned' => 1 ] ) ; } if ( ! empty ( $ filters [ 'lock' ] ) && $ filters [ 'lock' ] == 1 ) { $ query -> andWhere ( [ 'locked' => 1 ] ) ; } if ( ! empty ( $ filters [ 'hot' ] ) && $ filters [ 'hot' ] == 1 ) { $ query -> andWhere ( [ '>=' , 'posts' , Podium :: getInstance ( ) -> podiumConfig -> get ( 'hot_minimum' ) ] ) ; } if ( ! empty ( $ filters [ 'new' ] ) && $ filters [ 'new' ] == 1 && ! Podium :: getInstance ( ) -> user -> isGuest ) { $ query -> joinWith ( [ 'threadView tvn' => function ( $ q ) use ( $ loggedId ) { $ q -> onCondition ( [ 'tvn.user_id' => $ loggedId ] ) ; $ q -> andWhere ( [ 'or' , new Expression ( 'tvn.new_last_seen < new_post_at' ) , [ 'tvn.new_last_seen' => null ] ] ) ; } ] , false ) ; } if ( ! empty ( $ filters [ 'edit' ] ) && $ filters [ 'edit' ] == 1 && ! Podium :: getInstance ( ) -> user -> isGuest ) { $ query -> joinWith ( [ 'threadView tve' => function ( $ q ) use ( $ loggedId ) { $ q -> onCondition ( [ 'tve.user_id' => $ loggedId ] ) ; $ q -> andWhere ( [ 'or' , new Expression ( 'tve.edited_last_seen < edited_post_at' ) , [ 'tve.edited_last_seen' => null ] ] ) ; } ] , false ) ; } } $ dataProvider = new ActiveDataProvider ( [ 'query' => $ query , 'pagination' => false , ] ) ; $ dataProvider -> sort -> defaultOrder = [ 'pinned' => SORT_DESC , 'updated_at' => SORT_DESC , 'id' => SORT_ASC ] ; return $ dataProvider ; }
Searches for thread .
49,289
public function searchByUser ( $ userId ) { $ query = static :: find ( ) ; $ query -> where ( [ 'author_id' => $ userId ] ) ; if ( Podium :: getInstance ( ) -> user -> isGuest ) { $ query -> joinWith ( [ 'forum' => function ( $ q ) { $ q -> where ( [ Forum :: tableName ( ) . '.visible' => 1 ] ) ; } ] ) ; } $ dataProvider = new ActiveDataProvider ( [ 'query' => $ query , 'pagination' => false , ] ) ; $ dataProvider -> sort -> defaultOrder = [ 'updated_at' => SORT_DESC , 'id' => SORT_ASC ] ; return $ dataProvider ; }
Searches for threads created by user of given ID .
49,290
public function getIcon ( ) { $ icon = self :: ICON_NO_NEW ; $ append = false ; if ( $ this -> locked ) { $ icon = self :: ICON_LOCKED ; $ append = true ; } elseif ( $ this -> pinned ) { $ icon = self :: ICON_PINNED ; $ append = true ; } elseif ( $ this -> posts >= Podium :: getInstance ( ) -> podiumConfig -> get ( 'hot_minimum' ) ) { $ icon = self :: ICON_HOT ; $ append = true ; } if ( $ this -> userView ) { if ( $ this -> new_post_at > $ this -> userView -> new_last_seen ) { if ( ! $ append ) { $ icon = self :: ICON_NEW ; } } elseif ( $ this -> edited_post_at > $ this -> userView -> edited_last_seen ) { if ( ! $ append ) { $ icon = self :: ICON_NEW ; } } } else { if ( ! $ append ) { $ icon = self :: ICON_NEW ; } } return $ icon ; }
Returns proper icon for thread .
49,291
public function getDescription ( ) { $ description = Yii :: t ( 'podium/view' , 'No New Posts' ) ; $ append = false ; if ( $ this -> locked ) { $ description = Yii :: t ( 'podium/view' , 'Locked Thread' ) ; $ append = true ; } elseif ( $ this -> pinned ) { $ description = Yii :: t ( 'podium/view' , 'Pinned Thread' ) ; $ append = true ; } elseif ( $ this -> posts >= Podium :: getInstance ( ) -> podiumConfig -> get ( 'hot_minimum' ) ) { $ description = Yii :: t ( 'podium/view' , 'Hot Thread' ) ; $ append = true ; } if ( $ this -> userView ) { if ( $ this -> new_post_at > $ this -> userView -> new_last_seen ) { if ( ! $ append ) { $ description = Yii :: t ( 'podium/view' , 'New Posts' ) ; } else { $ description .= ' (' . Yii :: t ( 'podium/view' , 'New Posts' ) . ')' ; } } elseif ( $ this -> edited_post_at > $ this -> userView -> edited_last_seen ) { if ( ! $ append ) { $ description = Yii :: t ( 'podium/view' , 'Edited Posts' ) ; } else { $ description = ' (' . Yii :: t ( 'podium/view' , 'Edited Posts' ) . ')' ; } } } else { if ( ! $ append ) { $ description = Yii :: t ( 'podium/view' , 'New Posts' ) ; } else { $ description .= ' (' . Yii :: t ( 'podium/view' , 'New Posts' ) . ')' ; } } return $ description ; }
Returns proper description for thread .
49,292
public function getCssClass ( ) { $ class = self :: CLASS_DEFAULT ; if ( $ this -> userView ) { if ( $ this -> new_post_at > $ this -> userView -> new_last_seen ) { $ class = self :: CLASS_NEW ; } elseif ( $ this -> edited_post_at > $ this -> userView -> edited_last_seen ) { $ class = self :: CLASS_EDITED ; } } else { $ class = self :: CLASS_NEW ; } return $ class ; }
Returns proper CSS class for thread .
49,293
public function isMod ( $ userId = null ) { if ( User :: can ( Rbac :: ROLE_ADMIN ) ) { return true ; } if ( in_array ( $ userId , $ this -> forum -> getMods ( ) ) ) { return true ; } return false ; }
Checks if user is this thread moderator .
49,294
public function podiumDelete ( ) { $ transaction = Thread :: getDb ( ) -> beginTransaction ( ) ; try { if ( ! $ this -> delete ( ) ) { throw new Exception ( 'Thread deleting error!' ) ; } $ this -> forum -> updateCounters ( [ 'threads' => - 1 , 'posts' => - $ this -> postsCount ] ) ; $ transaction -> commit ( ) ; PodiumCache :: clearAfter ( 'threadDelete' ) ; Log :: info ( 'Thread deleted' , $ this -> id , __METHOD__ ) ; return true ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Performs thread delete with parent forum counters update .
49,295
public function podiumDeletePosts ( $ posts ) { $ transaction = static :: getDb ( ) -> beginTransaction ( ) ; try { foreach ( $ posts as $ post ) { if ( ! is_numeric ( $ post ) || $ post < 1 ) { throw new Exception ( 'Incorrect post ID' ) ; } $ nPost = Post :: find ( ) -> where ( [ 'id' => $ post , 'thread_id' => $ this -> id , 'forum_id' => $ this -> forum -> id ] ) -> limit ( 1 ) -> one ( ) ; if ( ! $ nPost ) { throw new Exception ( 'No post of given ID found' ) ; } if ( ! $ nPost -> delete ( ) ) { throw new Exception ( 'Post deleting error!' ) ; } } $ wholeThread = false ; if ( $ this -> postsCount ) { $ this -> updateCounters ( [ 'posts' => - count ( $ posts ) ] ) ; $ this -> forum -> updateCounters ( [ 'posts' => - count ( $ posts ) ] ) ; } else { $ wholeThread = true ; if ( ! $ this -> delete ( ) ) { throw new Exception ( 'Thread deleting error!' ) ; } $ this -> forum -> updateCounters ( [ 'posts' => - count ( $ posts ) , 'threads' => - 1 ] ) ; } $ transaction -> commit ( ) ; PodiumCache :: clearAfter ( 'postDelete' ) ; Log :: info ( 'Posts deleted' , null , __METHOD__ ) ; return true ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Performs thread posts delete with parent forum counters update .
49,296
public function podiumMoveTo ( $ target = null ) { $ newParent = Forum :: find ( ) -> where ( [ 'id' => $ target ] ) -> limit ( 1 ) -> one ( ) ; if ( empty ( $ newParent ) ) { Log :: error ( 'No parent forum of given ID found' , $ this -> id , __METHOD__ ) ; return false ; } $ postsCount = $ this -> postsCount ; $ transaction = Forum :: getDb ( ) -> beginTransaction ( ) ; try { $ this -> forum -> updateCounters ( [ 'threads' => - 1 , 'posts' => - $ postsCount ] ) ; $ newParent -> updateCounters ( [ 'threads' => 1 , 'posts' => $ postsCount ] ) ; $ this -> forum_id = $ newParent -> id ; $ this -> category_id = $ newParent -> category_id ; if ( ! $ this -> save ( ) ) { throw new Exception ( 'Thread saving error!' ) ; } Post :: updateAll ( [ 'forum_id' => $ newParent -> id ] , [ 'thread_id' => $ this -> id ] ) ; $ transaction -> commit ( ) ; PodiumCache :: clearAfter ( 'threadMove' ) ; Log :: info ( 'Thread moved' , $ this -> id , __METHOD__ ) ; return true ; } catch ( Exception $ e ) { $ transaction -> rollBack ( ) ; Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Performs thread move with counters update .
49,297
public static function podiumMarkAllSeen ( ) { try { $ loggedId = User :: loggedId ( ) ; if ( empty ( $ loggedId ) ) { throw new Exception ( 'User ID missing' ) ; } $ updateBatch = [ ] ; $ threadsPrevMarked = Thread :: find ( ) -> joinWith ( [ 'threadView' => function ( $ q ) use ( $ loggedId ) { $ q -> onCondition ( [ 'user_id' => $ loggedId ] ) ; $ q -> andWhere ( [ 'or' , new Expression ( 'new_last_seen < new_post_at' ) , new Expression ( 'edited_last_seen < edited_post_at' ) , ] ) ; } ] , false ) ; $ time = time ( ) ; foreach ( $ threadsPrevMarked -> each ( ) as $ thread ) { $ updateBatch [ ] = $ thread -> id ; } if ( ! empty ( $ updateBatch ) ) { Podium :: getInstance ( ) -> db -> createCommand ( ) -> update ( ThreadView :: tableName ( ) , [ 'new_last_seen' => $ time , 'edited_last_seen' => $ time ] , [ 'thread_id' => $ updateBatch , 'user_id' => $ loggedId ] ) -> execute ( ) ; } $ insertBatch = [ ] ; $ threadsNew = Thread :: find ( ) -> joinWith ( [ 'threadView' => function ( $ q ) use ( $ loggedId ) { $ q -> onCondition ( [ 'user_id' => $ loggedId ] ) ; $ q -> andWhere ( [ 'new_last_seen' => null ] ) ; } ] , false ) ; foreach ( $ threadsNew -> each ( ) as $ thread ) { $ insertBatch [ ] = [ $ loggedId , $ thread -> id , $ time , $ time ] ; } if ( ! empty ( $ insertBatch ) ) { Podium :: getInstance ( ) -> db -> createCommand ( ) -> batchInsert ( ThreadView :: tableName ( ) , [ 'user_id' , 'thread_id' , 'new_last_seen' , 'edited_last_seen' ] , $ insertBatch ) -> execute ( ) ; } return true ; } catch ( Exception $ e ) { Log :: error ( $ e -> getMessage ( ) , null , __METHOD__ ) ; } return false ; }
Performs marking all unread threads as seen for user .
49,298
public function getParsedPost ( ) { if ( Podium :: getInstance ( ) -> podiumConfig -> get ( 'use_wysiwyg' ) == '0' ) { $ parser = new GithubMarkdown ( ) ; $ parser -> html5 = true ; return $ parser -> parse ( $ this -> post ) ; } return $ this -> post ; }
Returns post Markdown - parsed if WYSIWYG editor is switched off .
49,299
public function actionFieldlist ( $ q = null ) { if ( ! Yii :: $ app -> request -> isAjax ) { return $ this -> redirect ( [ 'forum/index' ] ) ; } return User :: getMembersList ( $ q ) ; }
Listing the active users for ajax .