public static function preparePosting(Apartment $model)
 {
     if ($model) {
         $message = '';
         $defaultLang = Lang::getDefaultLang();
         $tmp = 'title_' . $defaultLang;
         if (isset($model->{$tmp})) {
             $message .= $model->{$tmp};
         }
         // vkontakte
         if (SocialpostingModel::getSocialParamValue('useVkontakte')) {
             $vkApId = SocialpostingModel::getSocialParamValue('vkontakteApplicationId');
             $vkToken = SocialpostingModel::getSocialParamValue('vkontakteToken');
             $vkUsId = SocialpostingModel::getSocialParamValue('vkontakteUserId');
             //if ($vkApId && $vkToken && !is_numeric($model->autoVKPostId)) {
             if ($vkApId && $vkToken && utf8_strlen($model->autoVKPostId) < 1) {
                 if ($message) {
                     $imageUrl = null;
                     $res = Images::getMainThumb(300, 200, $model->images);
                     if ($res['link']) {
                         $imageUrl = $res['link'];
                     }
                     $post = self::addPostToVK($message, $vkApId, $vkToken, $vkUsId, $model->getUrl(), $imageUrl);
                     //logs(var_export($post, false));
                     //logs(var_export($post, true));
                     $postId = '0';
                     if ($post && isset($post->response)) {
                         $postId = isset($post->response->post_id) && $post->response->post_id ? $post->response->post_id : 0;
                     }
                     $model->autoVKPostId = $postId;
                     $model->update(array('autoVKPostId'));
                     /*$sql = 'UPDATE {{apartment}} SET autoVKPostId = "'.strip_tags(addslashes($postId)).'" WHERE id = '.$model->id;
                     		Yii::app()->db->createCommand($sql)->execute();*/
                 }
             }
         }
         // twitter
         if (SocialpostingModel::getSocialParamValue('useTwitter')) {
             $twApiKey = SocialpostingModel::getSocialParamValue('twitterApiKey');
             $twApiSecret = SocialpostingModel::getSocialParamValue('twitterApiSecret');
             $twTokenKey = SocialpostingModel::getSocialParamValue('twitterTokenKey');
             $twTokenSecret = SocialpostingModel::getSocialParamValue('twitterTokenSecret');
             //if ($twApiKey && $twApiSecret && $twTokenKey && $twTokenSecret && !is_numeric($model->autoTwitterPostId)) {
             if ($twApiKey && $twApiSecret && $twTokenKey && $twTokenSecret && utf8_strlen($model->autoTwitterPostId) < 1) {
                 if ($message) {
                     $post = self::addPostToTw($message, $twApiKey, $twApiSecret, $twTokenKey, $twTokenSecret, $model->getUrl());
                     //logs(var_export($post, false));
                     //logs(var_export($post, true));
                     $postId = '0';
                     if ($post && isset($post->id_str)) {
                         $postId = $post->id_str ? $post->id_str : 0;
                     }
                     $model->autoTwitterPostId = strip_tags(addslashes($postId));
                     $model->update(array('autoTwitterPostId'));
                     /*$sql = 'UPDATE {{apartment}} SET autoTwitterPostId = "'.strip_tags(addslashes($postId)).'" WHERE id = '.$model->id;
                     		Yii::app()->db->createCommand($sql)->execute();*/
                 }
             }
         }
     }
     return true;
 }