/** * Logs out current user and sends a response of Logged Out * until something else more useful should be returned. */ public static function logout() { AppUtils::logout(); AppUtils::sendResponse('Logged Out'); }
/** * * @see ForumPostServicePDO::updateForumPostEntry() */ public static function updateForumPostEntry($forumId, $postId) { $app = \Slim\Slim::getInstance(); try { $pdo = new ForumPostServicePDO(); $request = $app->request(); $body = $request->getBody(); $forumPost = (array) json_decode($body); $id = $forumPost['id']; $post = $pdo->getPosting($forumPost['forumId'], $id); if (isset($post)) { $pdo->updateForumPostEntry($id, $forumPost); $eventData = array('postId' => $id, 'changeType' => ForumEvent::UPDATE); AppUtils::sendEvent(ForumEvent::DOMAIN, $forumId, ForumEvent::POST_CHANGE, "Posting updated with ID: " . $id, $eventData); AppUtils::sendResponse(array("success" => true, "message" => "Forum post with ID {$id} updated.")); } else { AppUtils::sendResponse(array("success" => false, "message" => "Forum post with ID {$id} does not exist!")); } } catch (Exception $e) { AppUtils::logError($e, __METHOD__); AppUtils::sendError($e->getCode(), "Error updating forum post with ID {$id}", $e->getMessage()); } }
/** * * @see EventServicePDO::unsubscribe() */ public static function unsubscribe($userId, $topic) { try { $pdo = new EventServicePDO(); $pdo->unsubscribe($userId, $topic); AppUtils::sendResponse(array("success" => true, "message" => "User {$userId} unsubscribed from topic {$topic}")); } catch (PDOException $e) { AppUtils::logError($e, __METHOD__); AppUtils::sendError($e->getCode(), "Error unsubscribing to events user {$userId} topic {$topic}", $e->getMessage()); } }
/** * * @see ForumServicePDO::updateForum() */ public static function updateForum($id) { $app = \Slim\Slim::getInstance(); try { $pdo = new ForumServicePDO(); $forum = $pdo->getForum($id); if (isset($forum)) { // get and decode JSON request body $request = $app->request(); $body = $request->getBody(); $forumData = json_decode($body); $params = (array) $forumData; $params['id'] = $id; $pdo->updateForum($id, $params, AppUtils::getUserId()); $params['changeType'] = ForumEvent::UPDATE; AppUtils::sendEvent(ForumEvent::DOMAIN, $id, ForumEvent::CHANGE, "Forum updated: " . $params['name'], $params); AppUtils::sendResponse($forumData); } else { AppUtils::sendError(AppUtils::USER_ERROR_CODE, "Forum with ID {$id} does not exist!", "Database update failure"); } } catch (Exception $e) { AppUtils::logError($e, __METHOD__); AppUtils::sendError($e->getCode(), "Error updating forum with ID: " . $id, $e->getMessage()); } }
/** * * @see ForumServicePDO::renameFileNode() */ public static function renameFileNode($id) { $app = \Slim\Slim::getInstance(); try { // get and decode JSON request body $request = $app->request(); $params = $request->params(); // $body = $request->getBody(); // $params = (array) json_decode($body); // error_log(print_r($params, true)); $name = $params['nodeName']; $forumId = $params['forumId']; $pdo = new ForumServicePDO(); $newName = $pdo->renameFileNode($id, $name); $eventParams = array(); $eventParams['changeType'] = ForumEvent::UPDATE; $eventParams['id'] = $id; $eventParams['name'] = $newName; $eventParams['forumId'] = $forumId; AppUtils::sendEvent(ForumEvent::DOMAIN, $forumId, ForumEvent::NODE_CHANGE, "Renamed to " . $name, $eventParams); AppUtils::sendResponse($newName); } catch (Exception $e) { AppUtils::logError($e, __METHOD__); AppUtils::sendError($e->getCode(), "Error renaming file node", $e->getMessage()); } }
/** * * @see SettingsServicePDO::getDomains() */ public static function getDomains() { try { $pdo = new SettingsServicePDO(); $result = $pdo->getDomains(); AppUtils::sendResponse($result); } catch (PDOException $e) { AppUtils::logError($e, __METHOD__); AppUtils::sendError($e->getCode(), "Error getting all setting domains", $e->getMessage()); } }
public static function getEvents($id) { AppUtils::sendResponse(AppUtils::getEvents()); }
/** * * @see ForumServicePDO::getForumsForUser() */ public static function getForumsForUser() { try { $pdo = new ForumServicePDO(); $userId = AppUtils::getUserId(); $forums = $pdo->getForumsForUser($userId); AppUtils::sendResponse($forums); } catch (PDOException $e) { AppUtils::logError($e, __METHOD__); AppUtils::sendError($e->getCode(), "Error getting forums for user {$userId}", $e->getMessage()); } }
/** * Uploads the file specified via HTTP POST * This code is based on the PHP examples */ public static function upload() { $app = \Slim\Slim::getInstance(); $forumId = $_POST['forumId']; $folderId = $_POST['id']; $fileName = $_FILES["file"]["name"]; $tempFileName = $_FILES["file"]["tmp_name"]; $contentType = $_FILES["file"]["type"]; // Check for errors if ($_FILES['file']['error'] > 0) { $errorMsg = 'Upload Error: '; // Print a message based upon the error. switch ($_FILES['file']['error']) { case 1: $errorMsg = $errorMsg . 'The file exceeds the upload_max_filesize setting in php.ini.'; break; case 2: $errorMsg = $errorMsg . 'The file exceeds the MAX_FILE_SIZE setting in the HTML form.'; break; case 3: $errorMsg = $errorMsg . 'The file was only partially uploaded.'; break; case 4: $errorMsg = $errorMsg . 'No file was uploaded.'; break; case 6: $errorMsg = $errorMsg . 'No temporary folder was available.'; break; case 7: $errorMsg = $errorMsg . 'Unable to write to the disk.'; break; case 8: $errorMsg = $errorMsg . 'File upload stopped.'; break; default: $errorMsg = $errorMsg . 'A system error occurred.'; break; } // End of switch. AppUtils::sendError(500, "File Upload Error", $errorMsg); } else { try { $fileNode = array('id' => '', 'forumId' => $forumId, 'parentId' => $folderId, 'name' => $fileName, 'contentType' => $contentType); $pdo = new ForumServicePDO(); $fileNode = $pdo->createFileNode((array) $fileNode); $fileId = $fileNode['id']; move_uploaded_file($tempFileName, FORUM_UPLOAD_DIR . $fileId); $fileNode['changeType'] = ForumEvent::CREATE; AppUtils::sendEvent(ForumEvent::DOMAIN, $forumId, ForumEvent::NODE_CHANGE, "Node created: " . $fileNode['name'], $fileNode); AppUtils::sendResponse($fileNode); } catch (Exception $e) { AppUtils::logError($e, __METHOD__); AppUtils::sendError($e->getCode(), "Error creating file node for {$fileName}", $e->getMessage()); } } // Delete the file if it still exists: if (file_exists($_FILES['file']['tmp_name']) && is_file($_FILES['file']['tmp_name'])) { unlink($_FILES['file']['tmp_name']); } }