| Server IP : 103.234.187.230 / Your IP : 216.73.216.216 Web Server : Apache System : Linux lserver42043-ind.megavelocity.net 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64 User : apache ( 48) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/www/html/tripstring.com/library/Catabatic/ |
Upload File : |
<?php
/* * *************************************************************
* Catabatic Technology Pvt. Ltd.
* File Name : Rvadmin.php
* File Desc. : Base Admin controller managed all activity
* Created By : Ranvir Singh <twitter @ranvir2012>
* Created Date : 21 Dec 2017
* Updated Date : 09 Jan 2018
* ************************************************************* */
class Catabatic_Rvadmin extends Zend_Controller_Action {
public $dbAdapter;
public $perPageLimit;
public $siteurl;
public $DIR_WRITE_MODE;
public $crud;
public $img_w_dynamic;
public $img_h_dynamic;
public function init() {
/* Initialize db and session access */
$aConfig = $this->getInvokeArg('bootstrap')->getOptions();
$this->siteurl = $aConfig['bootstrap']['siteUrl'];
$this->appmode = $aConfig['bootstrap']['appmode'];
$this->per_page_record = 20;
$this->dbAdapter = Zend_Db_Table::getDefaultAdapter();
$auth = Zend_Auth::getInstance();
$authStorage = $auth->getStorage()->read();
$this->username = $authStorage->username;
$this->admin_type = $authStorage->role;
$this->current_time = time();
$this->img_w_thumb = 85;
$this->img_h_thumb = 62;
$this->img_w_medium = 220;
$this->img_h_medium = 180;
$this->img_w_large = 470;
$this->img_h_large = 341;
$this->img_w_small = 340;
$this->img_h_small = 200;
$this->img_w_medium = 768;
$this->img_h_medium = 250;
$this->img_w_banner = 800;
$this->img_h_banner = 300;
$this->DIR_WRITE_MODE = 0777;
$this->tablename = 'tb_tbb2c_packages_master';
$this->crud = new Admin_Model_CRUD();
}
/*
* Params ( PkgSysId , Source URL , destination , ['thumb','small','medium','large'] )
*/
public function downloadImagesFromServer( $PkgSysId , $sourceURL , $destination , array $clonesArray = ['thumb'] ) {
$defaultImage = $sourceURL;
if (isset($defaultImage) && !empty($defaultImage) && empty($result['Image'])) {
try {
//$ImgThumbnailContent = Zend_Controller_Action_HelperBroker::getStaticHelper('Custom')->curl_get($defaultImage);
//$ImgThumbnailContent = file_get_contents($defaultImage);
$ImgThumbnailContent = $this->curl_get($defaultImage);
// echo "<pre>";print_r($ImgThumbnailContent);die('here');
$fileExt = $this->_helper->General->getFileExtension($defaultImage);
$ImgThumbnail = end(explode('_', $defaultImage));
$fileName = $PkgSysId . '_' . $ImgThumbnail;
$orignalFolderName = $_SERVER["DOCUMENT_ROOT"] . "/" . $destination . $PkgSysId . "/images/";
if (!file_exists($orignalFolderName)) {
mkdir($orignalFolderName, $this->DIR_WRITE_MODE, true);
}
/*
* create directories here
*/
$directoryname = '';
foreach ($clonesArray as $key => $value) {
$directoryname = $orignalFolderName . "/{$value}";
if (!file_exists($directoryname)) {
mkdir($directoryname, $this->DIR_WRITE_MODE, true);
}
$this->_send_api_put_request( $orignalFolderName . $fileName , $ImgThumbnailContent ); // save image here
// echo "<pre>";print_r($ImgThumbnailContent);die('here');
copy( $orignalFolderName . '/' . $fileName , $directoryname . "/" . $fileName); // copy uploaded file into this location directory
$objImageResize4 = new Catabatic_Imageresize( $directoryname . '/' . $fileName );
$getDimensions = $this->getDimensions($value); // get dimensions of images
$this->img_w_dynamic = ($getDimensions['w']) ? $getDimensions['w'] : 100;
$this->img_h_dynamic = ($getDimensions['h']) ? $getDimensions['h'] : 100;
$objImageResize4->resizeImage( $this->img_w_dynamic , $this->img_h_dynamic , 'exact'); // param : width , height , (exact|portrait|landscape|auto|crop)
$objImageResize4->saveImage( $directoryname . '/' . $fileName);
}
$status = TRUE;
$message= 'Downloaded successfully.';
}
catch (Exception $ex) {
$status = FALSE;
$message = $ex->getMessage();
$fileName = '';
}
return ['status' => $status, 'message' => $message , 'img'=> $fileName ];
}
}
public function getDimensions( $param ) {
switch ($param) {
case 'thumb':
$w = $this->img_w_thumb;
$h = $this->img_h_thumb;
break;
case 'small':
$w = $this->img_w_small;
$h = $this->img_h_small;
break;
case 'medium':
$w = $this->img_w_medium;
$h = $this->img_h_medium;
break;
case 'large':
$w = $this->img_w_large;
$h = $this->img_h_large;
break;
default:
break;
}
return ['w'=> $w , 'h'=> $h];
}
public function curl_get($url, array $get = NULL, array $options = array())
{
$defaults = array(
CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 4
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
public function curl_put($url, array $get = NULL, array $options = array())
{
$defaults = array(
CURLOPT_URL => $url. (strpos($url, '?') === FALSE ? '?' : ''). http_build_query($get),
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 4
);
$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));
if( ! $result = curl_exec($ch))
{
trigger_error(curl_error($ch));
}
curl_close($ch);
return $result;
}
public function _send_api_put_request($url, array $parameters = NULL, $data) {
// Add parameters to URL
$url_parameters = http_build_query($parameters);
$url .= '?' . $url_parameters;
// Make request via cURL.
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
// Handle authentication (you would need to implement this)
//_api_authentication($curl);
// Set options necessary for request.
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT');
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data)));
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
// Send request
$response = curl_exec($curl);
return array(
'code' => curl_getinfo($curl, CURLINFO_HTTP_CODE),
'data' => $response,
);
}
}