Esempio n. 1
0
 public function resizeImagePercent($pathFolder, $image, $percent)
 {
     // parameter => $image
     /* Get original image x y */
     //var_dump($image);
     //exit();
     $newName = '';
     $imageType = '';
     try {
         $imageType = $image['type'];
         list($w, $h) = getimagesize($image['tmp_name']);
         /* calculate new image size with ratio */
         $newWidth = ceil($w * $percent);
         $newHeight = ceil($h * $percent);
         /* new file name */
         $imageExtension = explode("/", $imageType);
         $newName = $newWidth . 'x' . $newHeight . '_' . Utilities::generateRandomString(10) . '.' . $imageExtension[1];
         $path = $pathFolder . $newName;
         /* read binary data from image file */
         $imgString = file_get_contents($image['tmp_name']);
         /* create image from string */
         $image = imagecreatefromstring($imgString);
         $tmp = imagecreatetruecolor($newWidth, $newHeight);
         imagecopyresampled($tmp, $image, 0, 0, 0, 0, $newWidth, $newHeight, $w, $h);
         /* Save image */
         if ($imageType === 'image/jpeg' || $imageType == 'image/JPEG' || $imageType == 'image/jpg' || $imageType == 'image/JPG') {
             imagejpeg($tmp, $path, 100);
         } else {
             if ($imageType == 'image/png' || $imageType == 'image/PNG') {
                 imagepng($tmp, $path, 0);
             } else {
                 if ($imageType == 'image/GIF' || $imageType == 'image/gif') {
                     imagegif($tmp, $path);
                 } else {
                     echo 'image_type ::==' . $imageType;
                     exit;
                 }
             }
         }
         /* cleanup memory */
         imagedestroy($image);
         imagedestroy($tmp);
     } catch (Exception $exc) {
         echo $exc->getTraceAsString();
         exit;
     }
     return $newName;
 }
Esempio n. 2
0
 /**
  * Method launched for the HTTP POST requests
  * 
  * @param  string|null correspond to the URL after /Lan
  * 
  * $instance = new EtherpadLiteClient(Config::get('etherpad-apikey'), Config::get('etherpad-url'));
  * 
  * @throws RestException
  */
 public function post($param = null)
 {
     // Sensure user authentified
     if (!Auth::user()) {
         throw new AuthNotConnectedException();
     }
     $data = RestHandler::getData();
     $padName = "";
     if (isset($data->autogenerate)) {
         // Generate unique random pad name
         $padName = Utilities::generateRandomString(isset($param['padid_length']) ? $param['padid_length'] : 10);
         $custom = true;
     } else {
         if (!isset($data->pad) || !isset($data->pad->pad_name) || $data->pad->pad_name === "") {
             throw new RestException("Unknown call exception", 500);
         } else {
             $padName = $data->pad->pad_name;
         }
     }
     // Ensure pad not already exists
     if (PadComponent::padExists($padName)) {
         throw new PadAlreadyExistsException($padName);
     }
     $cdatas = array('padID' => $padName, 'apikey' => $this->etherpadApiKey, 'text' => Config::get('etherpad-default-text') ? Config::get('etherpad-default-text') : '');
     $result = RestUtilities::callAPI($this->etherpadURLApi . 'createPad', RestMethods::GET, $cdatas);
     //        $result = json_encode(array('code' => 0));
     if ($result) {
         if (isset($result->error)) {
             throw new RestException($result->error);
         } else {
             if ($result->code == 0) {
                 $padConfig = PadConfigComponent::getByUrl($this->etherpadURLPads);
                 $record = array("pad_name" => $padName, "pad_config_id" => $padConfig->id, "creation_date" => date('Y-m-d H:i:s'), "last_update" => date('Y-m-d H:i:s'), "mail_owner" => Auth::user()->email, "status" => 1);
                 if (isset($data->pad->guests)) {
                     $record['guests'] = $data->pad->guests;
                 }
                 $pad = NotesFactory::build(PadComponent::getClass(), $record);
                 $pad->save();
                 $record['url'] = $padName;
                 $userGuests = $this->manageUserGuests($data, $pad);
                 if (count($userGuests['active_emails']) > 0) {
                     // Setting informations
                     $infos = array(array('pad' => array('full_link' => $this->etherpadURLPads . $pad->pad_name, 'pad_name' => $pad->pad_name), 'user' => array('email' => Auth::user()->email)));
                     $this->sendPadInformationsByMail($pad, $userGuests['active_emails'], 'guest_pad', $infos);
                 }
                 if (isset($data->autogenerated)) {
                     // TODO:
                     // Send mail to pad owner
                     // (create new mail template)
                 }
                 return array('data' => array('status' => "success", 'content' => $pad));
             } else {
                 if ($result->code == 1) {
                     // TODO: still in use ?
                     if ($custom) {
                         if (!isset($param['tentative']) || $param['tentative'] < 3) {
                             $opt = array();
                             if (isset($param['tentative'])) {
                                 $opt['tentative'] = $param['tentative'] + 1;
                                 $opt['padid_length'] = isset($param['padid_length']) ? $param['padid_length'] + 1 : 11;
                             } else {
                                 $opt['tentative'] = 1;
                             }
                             $this->post($opt);
                         } else {
                             throw new RestException("Request Time-out", 408);
                         }
                     } else {
                         throw new PadAlreadyExistsException($padName, 409);
                     }
                 } else {
                     throw new PadAlreadyExistsException($padName, 409);
                 }
             }
         }
     } else {
         throw new EtherpadNotFoundException();
     }
 }
Esempio n. 3
0
 /**
  */
 public function actioncreate()
 {
     switch ($_GET['model']) {
         // Get an instance of the respective model
         case 'userDetails':
             $model = new UserDetails();
             break;
         case 'donationRequest':
             $model = new DonationRequest();
             break;
         case 'newsletterDetails':
             $model = new NewsletterDetails();
             break;
         default:
             $this->_sendResponse(501, sprintf('Mode <b>create</b> is not implemented for model <b>%s</b>', $_GET['model']));
             Yii::app()->end();
     }
     // Try to assign POST values to attributes
     foreach ($_POST as $var => $value) {
         // Does the model have this attribute? If not raise an error
         if ($model->hasAttribute($var)) {
             $model->{$var} = $value;
         }
         // else
         // $this->_sendResponse(500,
         // sprintf('Parameter <b>%s</b> is not allowed for model <b>%s</b>', $var,
         // $_GET['model']) );
     }
     // Try to save the model
     if ($_GET['model'] == "userDetails") {
         $model->blood_group = Utilities::getLookupIdByValue(Constants::$bloodgrp_lookup_code, $model->blood_group);
         $model->city = Utilities::getLookupIdByValue(Constants::$city_lookup_code, $model->city);
         $model->area = Utilities::getLookupIdByValue(Constants::$area_lookup_code, $model->area);
         $model->state = $model->city0->lookup_parent_id;
         $model->dob = DateTime::createFromFormat('d/m/Y', $model->dob)->format('Y-m-d');
         $number = $model->number;
         $otp = Utilities::generateRandomString();
         $model->donation_status = 'Y';
         $model->confirmation_code = $otp;
         if ($model->save()) {
             $payload = file_get_contents(Utilities::getSMSURL($otp, $number));
             $this->_sendResponse(200, CJSON::encode($model));
         } else {
             // Errors occurred
             $msg = "";
             $msg .= "<ul>";
             foreach ($model->errors as $attribute => $attr_errors) {
                 foreach ($attr_errors as $attr_error) {
                     $msg .= "<li>{$attr_error}</li>";
                 }
             }
             $msg .= "</ul>";
             $this->_sendResponse(500, $msg);
         }
     } elseif ($_GET['model'] == "donationRequest") {
         $model->blood_group = Utilities::getLookupIdByValue(Constants::$bloodgrp_lookup_code, $model->blood_group);
         $model->city = Utilities::getLookupIdByValue(Constants::$city_lookup_code, $model->city);
         $model->state = $model->city0->lookup_parent_id;
         $model->date = date("Y/m/d");
         $model->area = Utilities::getLookupIdByValue(Constants::$area_lookup_code, $model->area);
         $number = $model->number;
         $model->status = "requested";
         if ($model->save()) {
             $payload = file_get_contents(Utilities::getRequestConfirmationSMSURL($number));
             $payload = file_get_contents(Utilities::getRequestAdminSMSURL($model->bloodGroup->lookup_value));
             Utilities::sendBloodRequestSMS($model->request_id);
             $this->_sendResponse(200, CJSON::encode($model));
         } else {
             // Errors occurred
             $msg = "";
             $msg .= "<ul>";
             foreach ($model->errors as $attribute => $attr_errors) {
                 foreach ($attr_errors as $attr_error) {
                     $msg .= "<li>{$attr_error}</li>";
                 }
             }
             $msg .= "</ul>";
             $this->_sendResponse(500, $msg);
         }
     }
 }