コード例 #1
0
 /**
  * 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 = CitybrandingFrontendHelper::convert2UTC(date("Y-m-d H:i:s"));
     }
     $hidden = (bool) $this->element['hidden'];
     if ($hidden == null || !$hidden) {
         $jdate = new JDate(CitybrandingFrontendHelper::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);
 }
コード例 #2
0
 public function poi()
 {
     $result = null;
     $app = JFactory::getApplication();
     try {
         $userid = self::validateRequest();
         //get necessary arguments
         $id = $app->input->getInt('id', null);
         switch ($app->input->getMethod()) {
             //fetch existing poi
             case 'GET':
                 if ($id == null) {
                     throw new Exception('Id is not set');
                 }
                 //get poi model
                 $poiModel = JModelLegacy::getInstance('Poi', 'CitybrandingModel', array('ignore_request' => true));
                 //handle unexpected warnings from model
                 set_error_handler(array($this, 'exception_error_handler'));
                 $data = $poiModel->getData($id);
                 restore_error_handler();
                 if (!is_object($data)) {
                     throw new Exception('Poi does not exist');
                 }
                 $result = CitybrandingFrontendHelper::sanitizePoi($data, $userid);
                 //check for any restrictions
                 if (!$result->myPoi && $result->moderation) {
                     throw new Exception('Poi is under moderation');
                 }
                 if ($result->state != 1) {
                     throw new Exception('Poi is not published');
                 }
                 //be consistent return as array (of size 1)
                 $result = array($result);
                 break;
                 //create new poi
             //create new poi
             case 'POST':
                 if ($id != null) {
                     throw new Exception('You cannot use POST to fetch poi. Use GET instead');
                 }
                 //guests are not allowed to post pois
                 //TODO: get this from settings
                 if ($userid == 0) {
                     throw new Exception('Guests are now allowed to post new pois');
                 }
                 //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'));
                 CitybrandingFrontendHelper::checkNullArguments($args);
                 //check if category exists
                 if (is_null(CitybrandingFrontendHelper::getCategoryNameByCategoryId($args['catid']))) {
                     throw new Exception('Category does not exist');
                 }
                 $args['userid'] = $userid;
                 $args['created_by'] = $userid;
                 $args['stepid'] = CitybrandingFrontendHelper::getPrimaryStepId();
                 $args['id'] = 0;
                 $args['created'] = CitybrandingFrontendHelper::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;
                 $tmpTime = time();
                 //used for temporary id
                 $imagedir = 'images/citybranding';
                 //check if post contains files
                 $file = $app->input->files->get('files');
                 if (!empty($file)) {
                     require_once JPATH_ROOT . '/components/com_citybranding/models/fields/multiphoto/server/UploadHandler.php';
                     $options = array('script_url' => JRoute::_(JURI::root(true) . '/administrator/index.php?option=com_citybranding&task=upload.handler&format=json&id=' . $tmpTime . '&imagedir=' . $imagedir . '&' . JSession::getFormToken() . '=1'), 'upload_dir' => JPATH_ROOT . '/' . $imagedir . '/' . $tmpTime . '/', 'upload_url' => JURI::root(true) . '/' . $imagedir . '/' . $tmpTime . '/', 'param_name' => 'files', 'citybranding_api' => true);
                     $upload_handler = new UploadHandler($options);
                     if (isset($upload_handler->citybranding_api)) {
                         $files_json = json_decode($upload_handler->citybranding_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('Upload failed');
                     }
                 } else {
                     $args['photo'] = json_encode(array('isnew' => 1, 'id' => $tmpTime, 'imagedir' => $imagedir, 'files' => array()));
                 }
                 //get poiForm model and save
                 $poiFormModel = JModelLegacy::getInstance('PoiForm', 'CitybrandingModel', array('ignore_request' => true));
                 //handle unexpected warnings from model
                 set_error_handler(array($this, 'exception_error_handler'));
                 $poiFormModel->save($args);
                 $insertid = JFactory::getApplication()->getUserState('com_citybranding.edit.poi.insertid');
                 //call post save hook
                 require_once JPATH_COMPONENT . '/controllers/poiform.php';
                 $poiFormController = new CitybrandingControllerPoiForm();
                 $poiFormController->postSaveHook($poiFormModel, $args);
                 restore_error_handler();
                 $result = array('poiid' => $insertid);
                 break;
                 //update existing poi
             //update existing poi
             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, 'Poi action completed successfully');
     } catch (Exception $e) {
         header("HTTP/1.0 202 Accepted");
         echo new JResponseJson($e);
     }
 }