예제 #1
0
 public function postComment()
 {
     $app = JFactory::getApplication();
     $params = $app->getParams('com_imc');
     $showComments = $params->get('enablecomments');
     $directpublishing = $params->get('directpublishingcomment');
     try {
         // Check for request forgeries.
         if (!JSession::checkToken('get')) {
             throw new Exception('Invalid session token');
         }
         if (!$showComments) {
             throw new Exception('Comments are not allowed');
         }
         $issueid = $app->input->getInt('issueid', null);
         $userid = $app->input->getInt('userid', null);
         $parentid = $app->input->getInt('parentid', 0);
         $description = $app->input->getString('description', '');
         if (is_null($issueid) || is_null($userid)) {
             throw new Exception('issueid or userid are missing');
         }
         //check is user is admin
         $created_by_admin = ImcHelper::getActions()->get('imc.manage.comments');
         //make comment
         $comment = new StdClass();
         $comment->state = 1;
         $comment->issueid = $issueid;
         if ($parentid > 0) {
             $comment->parentid = $parentid;
         }
         $comment->created = ImcFrontendHelper::convert2UTC(date('Y-m-d H:i:s'));
         $comment->updated = $comment->created;
         $comment->created_by = $userid;
         $comment->description = $description;
         $comment->fullname = JFactory::getUser($userid)->name;
         $comment->moderation = !$directpublishing && !$created_by_admin ? 1 : 0;
         $comment->language = "*";
         $comment->isAdmin = (int) $created_by_admin;
         //post comment to the model
         $commentModel = $this->getModel();
         $insertedId = $commentModel->add($comment);
         //fill missing fields to be aligned with jquery-comments and send back to the client
         $comment->id = $insertedId;
         $comment->profile_picture_url = JURI::base() . 'components/com_imc/assets/images/user-icon.png';
         $comment->created_by_admin = $created_by_admin;
         $comment->created_by_current_user = true;
         if ($comment->moderation) {
             $comment->profile_picture_url = JURI::base() . 'components/com_imc/assets/images/user-icon-moderated.png';
         }
         if ($created_by_admin) {
             $comment->profile_picture_url = JURI::base() . 'components/com_imc/assets/images/admin-user-icon.png';
         }
         echo new JResponseJson($comment);
     } catch (Exception $e) {
         header("HTTP/1.0 403 Accepted");
         echo new JResponseJson($e);
     }
 }
예제 #2
0
파일: timecreated.php 프로젝트: viru48/imc
 /**
  * Method to get the field input markup.
  *
  * @return	string	The field input markup.
  * @since	1.6
  */
 protected function getInput()
 {
     // Initialize variables.
     $html = array();
     $time_created = $this->value;
     if (!strtotime($time_created)) {
         $time_created = ImcFrontendHelper::convert2UTC(date("Y-m-d H:i:s"));
     }
     $hidden = (bool) $this->element['hidden'];
     if ($hidden == null || !$hidden) {
         $jdate = new JDate(ImcFrontendHelper::convertFromUTC($time_created));
         $pretty_date = $jdate->format(JText::_('DATE_FORMAT_LC2'));
         $html[] = "<span>" . $pretty_date . "</span>";
     }
     $html[] = '<input type="hidden" name="' . $this->name . '" value="' . $time_created . '" />';
     return implode("\n", $html);
 }
예제 #3
0
파일: api.json.php 프로젝트: viru48/imc
 public function issue()
 {
     $result = null;
     $app = JFactory::getApplication();
     try {
         $userid = self::validateRequest();
         //get necessary arguments
         $id = $app->input->getInt('id', null);
         switch ($app->input->getMethod()) {
             //fetch existing issue
             case 'GET':
                 if ($id == null) {
                     throw new Exception('Id is not set');
                 }
                 //get issue model
                 $issueModel = JModelLegacy::getInstance('Issue', 'ImcModel', array('ignore_request' => true));
                 $logsModel = JModelLegacy::getInstance('Logs', 'ImcModel', array('ignore_request' => true));
                 //handle unexpected warnings from model
                 set_error_handler(array($this, 'exception_error_handler'));
                 $data = $issueModel->getData($id);
                 //merge logs as timeline
                 if (is_object($data)) {
                     $data->timeline = $logsModel->getItemsByIssue($id);
                     $votesModel = JModelLegacy::getInstance('Votes', 'ImcModel', array('ignore_request' => true));
                     $data->hasVoted = $votesModel->hasVoted($data->id, $userid);
                 }
                 restore_error_handler();
                 if (!is_object($data)) {
                     throw new Exception(JText::_('COM_IMC_API_ISSUE_NOT_EXIST'));
                 }
                 $result = ImcFrontendHelper::sanitizeIssue($data, $userid);
                 //check for any restrictions
                 if (!$result->myIssue && $result->moderation) {
                     throw new Exception(JText::_('COM_IMC_API_ISSUE_UNDER_MODERATION'));
                 }
                 if ($result->state != 1) {
                     throw new Exception(JText::_('COM_IMC_API_ISSUE_NOT_PUBLISHED'));
                 }
                 //be consistent return as array (of size 1)
                 $result = array($result);
                 break;
                 //create new issue
             //create new issue
             case 'POST':
                 if ($id != null) {
                     throw new Exception('You cannot use POST to fetch issue. Use GET instead');
                 }
                 //guests are not allowed to post issues
                 //TODO: get this from settings
                 if ($userid == 0) {
                     throw new Exception(JText::_('COM_IMC_API_NO_GUESTS_NO_POST'));
                 }
                 //get necessary arguments
                 $args = array('catid' => $app->input->getInt('catid'), 'title' => $app->input->getString('title'), 'description' => $app->input->getString('description'), 'address' => $app->input->getString('address'), 'latitude' => $app->input->getString('lat'), 'longitude' => $app->input->getString('lng'));
                 ImcFrontendHelper::checkNullArguments($args);
                 //check if category exists
                 if (is_null(ImcFrontendHelper::getCategoryNameByCategoryId($args['catid'], true))) {
                     throw new Exception(JText::_('COM_IMC_API_CATEGORY_NOT_EXIST'));
                 }
                 $args['userid'] = $userid;
                 $args['created_by'] = $userid;
                 $args['stepid'] = ImcFrontendHelper::getPrimaryStepId();
                 $args['id'] = 0;
                 $args['created'] = ImcFrontendHelper::convert2UTC(date('Y-m-d H:i:s'));
                 $args['updated'] = $args['created'];
                 $args['note'] = 'modality=' . $app->input->getInt('m_id');
                 $args['language'] = '*';
                 $args['subgroup'] = 0;
                 $m_id = $app->input->getInt('m_id', 0);
                 $args['modality'] = $m_id;
                 $tmpTime = time();
                 //used for temporary id
                 $imagedir = 'images/imc';
                 //check if post contains files
                 $file = $app->input->files->get('files');
                 if (!empty($file)) {
                     require_once JPATH_ROOT . '/components/com_imc/models/fields/multiphoto/server/UploadHandler.php';
                     $options = array('script_url' => JRoute::_(JURI::root(true) . '/administrator/index.php?option=com_imc&task=upload.handler&format=json&id=' . $tmpTime . '&imagedir=' . $imagedir . '&' . JSession::getFormToken() . '=1'), 'upload_dir' => JPATH_ROOT . '/' . $imagedir . '/' . $tmpTime . '/', 'upload_url' => $imagedir . '/' . $tmpTime . '/', 'param_name' => 'files', 'imc_api' => true);
                     $upload_handler = new UploadHandler($options);
                     if (isset($upload_handler->imc_api)) {
                         $files_json = json_decode($upload_handler->imc_api);
                         $args['photo'] = json_encode(array('isnew' => 1, 'id' => $tmpTime, 'imagedir' => $imagedir, 'files' => $files_json->files));
                         $app->enqueueMessage('File(s) uploaded successfully', 'info');
                     } else {
                         throw new Exception(JText::_('COM_IMC_API_UPLOAD_FAILED'));
                     }
                 } else {
                     $args['photo'] = json_encode(array('isnew' => 1, 'id' => $tmpTime, 'imagedir' => $imagedir, 'files' => array()));
                 }
                 //get issueForm model and save
                 $issueFormModel = JModelLegacy::getInstance('IssueForm', 'ImcModel', array('ignore_request' => true));
                 //handle unexpected warnings from model
                 set_error_handler(array($this, 'exception_error_handler'));
                 $issueFormModel->save($args);
                 $insertid = JFactory::getApplication()->getUserState('com_imc.edit.issue.insertid');
                 //call post save hook
                 require_once JPATH_COMPONENT . '/controllers/issueform.php';
                 $issueFormController = new ImcControllerIssueForm();
                 $issueFormController->postSaveHook($issueFormModel, $args);
                 restore_error_handler();
                 $result = array('issueid' => $insertid);
                 //be consistent return as array (of size 1)
                 $result = array($result);
                 break;
                 //update existing issue
             //update existing issue
             case 'PUT':
             case 'PATCH':
                 if ($id == null) {
                     throw new Exception('Id is not set');
                 }
                 break;
             default:
                 throw new Exception('HTTP method is not supported');
         }
         echo new JResponseJson($result, 'Issue action completed successfully');
     } catch (Exception $e) {
         header("HTTP/1.0 202 Accepted");
         echo new JResponseJson($e);
     }
 }