/** * Save Post * * @param $userID * @param array $data * @return bool|int|null|string */ public static function savePost($userID, $data) { global $db; $now = date('Y-m-d H:i:s'); $type = isset($data['type']) ? $data['type'] : 'text'; if (!in_array($type, ['text', 'image', 'video'])) { $type = 'text'; } $data['pageID'] = isset($data['pageID']) && is_numeric($data['pageID']) ? $data['pageID'] : BuckysPost::INDEPENDENT_POST_PAGE_ID; if ($data['pageID'] != BuckysPost::INDEPENDENT_POST_PAGE_ID && !buckys_check_id_encrypted($data['pageID'], $data['pageIDHash'])) { buckys_add_message(MSG_INVALID_REQUEST, MSG_TYPE_ERROR); return false; } if (isset($data['profileID']) && !BuckysFriend::isFriend($userID, $data['profileID'])) { buckys_add_message(MSG_INVALID_REQUEST, MSG_TYPE_ERROR); return false; } if (!isset($data['profileID'])) { $data['profileID'] = 0; } if (!BuckysUsersDailyActivity::checkUserDailyLimit($userID, 'posts')) { buckys_add_message(sprintf(MSG_DAILY_POSTS_LIMIT_EXCEED_ERROR, USER_DAILY_LIMIT_POSTS), MSG_TYPE_ERROR); return false; } if ($type == 'text') { if (trim($data['content']) == '') { buckys_add_message(MSG_CONTENT_IS_EMPTY, MSG_TYPE_ERROR); return false; } // Strip tags, and change url to clickable $data['content'] = strip_tags($data['content']); $newId = $db->insertFromArray(TABLE_POSTS, ['poster' => $userID, 'pageID' => $data['pageID'], 'profileID' => $data['profileID'], 'content' => $data['content'], 'type' => $type, 'youtube_url' => '', 'post_date' => $now, 'visibility' => $data['post_visibility']]); if (!$newId) { buckys_add_message($db->getLastError(), MSG_TYPE_ERROR); return false; } } else { if ($type == 'video') { //Check Youtube URL is Valid or Not if (!buckys_validate_youtube_url($data['youtube_url'])) { buckys_add_message(MSG_INVALID_YOUTUBE_URL, MSG_TYPE_ERROR); return false; } $newId = $db->insertFromArray(TABLE_POSTS, ['poster' => $userID, 'pageID' => $data['pageID'], 'profileID' => $data['profileID'], 'content' => $data['content'], 'type' => $type, 'youtube_url' => $data['youtube_url'], 'post_date' => $now, 'visibility' => $data['post_visibility']]); if (!$newId) { buckys_add_message($db->getLastError(), MSG_TYPE_ERROR); return false; } } else { if ($type == 'image') { $newId = BuckysPost::savePhoto($userID, $data); } } } if (!isset($newId)) { return false; } switch ($type) { case 'image': // No message break; case 'video': buckys_add_message(MSG_NEW_VIDEO_CREATED, MSG_TYPE_SUCCESS); break; case 'text': buckys_add_message(MSG_NEW_POST_CREATED, MSG_TYPE_SUCCESS); break; default: break; } BuckysUsersDailyActivity::addPost($userID); return $newId; }
/** * Save Post * @param array $data */ public function savePost($userID, $data) { global $db; $now = date('Y-m-d H:i:s'); $type = isset($data['type']) ? $data['type'] : 'text'; if (!in_array($type, array('text', 'image', 'video'))) { $type = 'text'; } $data['pageID'] = isset($data['pageID']) && is_numeric($data['pageID']) ? $data['pageID'] : BuckysPost::INDEPENDENT_POST_PAGE_ID; /*$pattern = "/\[youtube.*\](.*)\[\/youtube\]/i"; if(preg_match_all($pattern, $data['content'], $matches)) $type = 'video';*/ if ($type == 'text') { if (trim($data['content']) == '') { buckys_add_message(MSG_CONTENT_IS_EMPTY, MSG_TYPE_ERROR); return false; } //Strip tags, and change url to clickable $data['content'] = strip_tags($data['content']); $newId = $db->insertFromArray(TABLE_POSTS, array('poster' => $userID, 'pageID' => $data['pageID'], 'content' => $data['content'], 'type' => $type, 'youtube_url' => '', 'post_date' => $now, 'visibility' => $data['post_visibility'])); if (!$newId) { buckys_add_message($db->getLastError(), MSG_TYPE_ERROR); return false; } } else { if ($type == 'video') { //Check Youtube URL is Valid or Not if (!buckys_validate_youtube_url($data['youtube_url'])) { buckys_add_message(MSG_INVALID_YOUTUBE_URL, MSG_TYPE_ERROR); return false; } $newId = $db->insertFromArray(TABLE_POSTS, array('poster' => $userID, 'pageID' => $data['pageID'], 'content' => $data['content'], 'type' => $type, 'youtube_url' => $data['youtube_url'], 'post_date' => $now, 'visibility' => $data['post_visibility'])); if (!$newId) { buckys_add_message($db->getLastError(), MSG_TYPE_ERROR); return false; } } else { if ($type == 'image') { $newId = BuckysPost::savePhoto($userID, $data); } } } if (!$newId) { return false; } switch ($type) { case 'image': // buckys_add_message(MSG_PHOTO_UPLOADED_SUCCESSFULLY, MSG_TYPE_SUCCESS); break; case 'video': buckys_add_message(MSG_NEW_VIDEO_CREATED, MSG_TYPE_SUCCESS); break; case 'text': default: buckys_add_message(MSG_NEW_POST_CREATED, MSG_TYPE_SUCCESS); break; } return $newId; }