Exemplo n.º 1
0
 public function saveMessage($messageID, $message, $userID = 0)
 {
     // Is this a new message?
     if (!$messageID) {
         // Message data
         $message = array('user_id' => $userID, 'poster_id' => session::item('user_id'), 'message' => $message, 'post_date' => date_helper::now());
         // Insert message
         $messageID = $this->db->insert('timeline_messages', $message);
         // Save timeline action
         timeline_helper::save('timeline_message_post', $userID, $messageID, 1, 1, false, array(), session::item('user_id'), session::item('timeline_message_post', 'config') === false || session::item('timeline_message_post', 'config') ? 1 : 0);
         // Action hook
         hook::action('timeline/messages/insert', session::item('user_id'), $userID, $message['message']);
         // Do we have user id?
         if ($userID && $userID != session::item('user_id')) {
             // Save notification
             timeline_helper::notice('timeline_message_post', $userID, session::item('user_id'));
         }
     } else {
         // Message data
         $message = array('message' => $message);
         $this->db->update('timeline_messages', $message, array('message_id' => $messageID), 1);
         // Action hook
         hook::action('timeline/messages/update', $messageID, $message['message']);
     }
     return $messageID;
 }
Exemplo n.º 2
0
 public function saveAdData($adID, $userID, $adOld, $fields, $extra = array())
 {
     // Is this a new ad?
     if (!$adID) {
         $extra['post_date'] = date_helper::now();
     }
     // Do we have user ID?
     if ($userID) {
         $extra['active'] = session::permission('ads_approve', 'classifieds') ? 1 : 9;
         $extra['user_id'] = $userID;
     }
     // Save ad
     if (!($newAdID = $this->fields_model->saveValues('classified_ad', $adID, $adOld, $fields, $extra))) {
         return 0;
     }
     // Is this a new ad?
     if (!$adID && $userID) {
         $column = $extra['active'] == 1 ? 'total_classifieds' : 'total_classifieds_i';
         $this->db->query("UPDATE `:prefix:users` SET `{$column}`=`{$column}`+1 WHERE `user_id`=? LIMIT 1", array($userID));
     }
     // Did ad status change?
     if ($adID && $extra['active'] != $adOld['active']) {
         // Did we approve this ad?
         if ($extra['active'] == 1) {
             $this->db->query("UPDATE `:prefix:users` SET `total_classifieds`=`total_classifieds`+1, `total_classifieds_i`=`total_classifieds_i`-1 WHERE `user_id`=? LIMIT 1", array($adOld['user_id']));
         } elseif ($adID && $adOld['active'] == 1) {
             $this->db->query("UPDATE `:prefix:users` SET `total_classifieds`=`total_classifieds`-1, `total_classifieds_i`=`total_classifieds_i`+1 WHERE `user_id`=? LIMIT 1", array($adOld['user_id']));
         }
     }
     if (!$adID) {
         // Deduct credits?
         if (config::item('credits_active', 'billing') && session::permission('ads_credits', 'classifieds')) {
             loader::model('billing/credits');
             $this->credits_model->removeCredits(session::item('user_id'), session::permission('ads_credits', 'classifieds'));
         }
     }
     if ($adID) {
         // Update timeline action
         timeline_helper::update(true, 'classified_ad_post', $adOld['user_id'], $newAdID, $extra['active']);
         // Action hook
         hook::action('classifieds/update', $newAdID, $extra);
     } else {
         // Save timeline action
         if (session::item('timeline_classified_post', 'config') === false || session::item('timeline_classified_post', 'config')) {
             timeline_helper::save('classified_ad_post', $userID, $newAdID, $extra['active']);
         }
         // Action hook
         hook::action('classifieds/insert', $newAdID, $extra);
     }
     return $newAdID;
 }
Exemplo n.º 3
0
 public function saveBlogData($blogID, $userID, $blogOld, $fields, $extra = array())
 {
     // Is this a new blog?
     if (!$blogID) {
         $extra['post_date'] = date_helper::now();
     }
     // Do we have user ID?
     if ($userID) {
         $extra['active'] = session::permission('blogs_approve', 'blogs') ? 1 : 9;
         $extra['user_id'] = $userID;
     }
     // Save blog
     if (!($newBlogID = $this->fields_model->saveValues('blog', $blogID, $blogOld, $fields, $extra))) {
         return 0;
     }
     // Is this a new blog?
     if (!$blogID && $userID) {
         $column = $extra['active'] == 1 ? 'total_blogs' : 'total_blogs_i';
         $this->db->query("UPDATE `:prefix:users` SET `{$column}`=`{$column}`+1 WHERE `user_id`=? LIMIT 1", array($userID));
     }
     // Did blog status change?
     if ($blogID && $extra['active'] != $blogOld['active']) {
         // Did we approve this blog?
         if ($extra['active'] == 1) {
             $this->db->query("UPDATE `:prefix:users` SET `total_blogs`=`total_blogs`+1, `total_blogs_i`=`total_blogs_i`-1 WHERE `user_id`=? LIMIT 1", array($blogOld['user_id']));
         } elseif ($blogID && $blogOld['active'] == 1) {
             $this->db->query("UPDATE `:prefix:users` SET `total_blogs`=`total_blogs`-1, `total_blogs_i`=`total_blogs_i`+1 WHERE `user_id`=? LIMIT 1", array($blogOld['user_id']));
         }
     }
     // Did we add a new blog or privacy setting changed?
     if (!$blogID || $extra['privacy'] != $blogOld['privacy']) {
         // Clean up counters
         $this->counters_model->deleteCounters('user', $blogID ? $blogOld['user_id'] : $userID);
     }
     if ($blogID) {
         // Update timeline action
         timeline_helper::update(true, 'blog_post', $blogOld['user_id'], $newBlogID, $extra['active'], $extra['privacy']);
         // Action hook
         hook::action('blogs/update', $newBlogID, $extra);
     } else {
         // Save timeline action
         if (session::item('timeline_blog_post', 'config') === false || session::item('timeline_blog_post', 'config')) {
             timeline_helper::save('blog_post', $userID, $newBlogID, $extra['active'], $extra['privacy']);
         }
         // Action hook
         hook::action('blogs/insert', $newBlogID, $extra);
     }
     return $newBlogID;
 }
Exemplo n.º 4
0
 public function savePictureFile($fileID, $albumID, $album, $extra = array())
 {
     // Basic picture data
     $picture = array('file_id' => $fileID, 'album_id' => $albumID, 'user_id' => session::item('user_id'), 'post_date' => date_helper::now(), 'active' => session::permission('pictures_approve', 'pictures') ? 1 : 9, 'order_id' => $album['total_pictures'] + $album['total_pictures_i'] + 1);
     // Do we have extras?
     if ($extra) {
         // Merge extras
         $picture = array_merge($picture, $extra);
     }
     // Save picture
     $pictureID = $this->db->insert('pictures_data', $picture);
     // Do we have picture ID?
     if ($pictureID) {
         // Update album's counter
         $column = $picture['active'] == 1 ? 'total_pictures' : 'total_pictures_i';
         $this->db->query("UPDATE `:prefix:pictures_albums_data` SET `{$column}`=`{$column}`+1 WHERE `user_id`=? AND `album_id`=? LIMIT 1", array(session::item('user_id'), $albumID));
         $this->db->query("UPDATE `:prefix:users` SET `{$column}`=`{$column}`+1 WHERE `user_id`=? LIMIT 1", array(session::item('user_id')));
         // Does album have a cover?
         if (!$album['picture_id']) {
             // Update album cover
             $this->pictures_albums_model->updateCover($albumID, $pictureID);
         }
         // Did we have any activity in the past hour?
         if (session::item('timeline_picture_post', 'config') === false || session::item('timeline_picture_post', 'config')) {
             if ($action = timeline_helper::get('picture_post', session::item('user_id'), $albumID, 12)) {
                 $counter = isset($action['params']['count']) ? $action['params']['count'] + 1 : 1;
                 // Update activity
                 timeline_helper::update($action['action_id'], 'picture_post', session::item('user_id'), $albumID, $picture['active'], false, array('count' => $counter), $action['attachments'] < 5 ? $fileID : false);
             } else {
                 // Save activity
                 timeline_helper::save('picture_post', session::item('user_id'), $albumID, $picture['active'], $album['privacy'], array('count' => 1), $fileID);
             }
         }
         // Action hook
         hook::action('pictures/insert', $pictureID, $picture);
     }
     return $pictureID;
 }
Exemplo n.º 5
0
 public function savePicture($userID, $pictureID)
 {
     $data = array('picture_id' => $pictureID, 'picture_active' => session::permission('users_pictures_approve', 'users') ? 1 : 9, 'picture_date' => date_helper::now());
     // Save picture
     $retval = $this->db->update('users', $data, array('user_id' => $userID), 1);
     // Save timeline action
     if (session::item('timeline_user_picture', 'config') === false || session::item('timeline_user_picture', 'config')) {
         timeline_helper::delete('user_picture', $userID, $userID);
         timeline_helper::save('user_picture', $userID, $userID, session::permission('users_pictures_approve', 'users') ? 1 : 0);
     }
     // Action hook
     hook::action('users/picture/update', $userID, $pictureID);
     return $retval;
 }