Compare commits
2
Commits
7a8491c572
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d75981754f | ||
|
|
f7d8f47f57 |
@@ -1,5 +1,12 @@
|
|||||||
<ifModule mod_rewrite.c>
|
<ifModule mod_rewrite.c>
|
||||||
RewriteEngine On
|
RewriteEngine On
|
||||||
RewriteCond %{REQUEST_FILENAME} !-f
|
RewriteCond %{REQUEST_FILENAME} !-f
|
||||||
RewriteRule ^(.*)$ serviceapp.php [QSA,L]
|
RewriteRule ^(.*)$ serviceapp.php [QSA,L]
|
||||||
</ifModule>
|
</ifModule>
|
||||||
|
|
||||||
|
<Limit GET POST PUT DELETE>
|
||||||
|
# Allow from app.gruppolapastamadre.it
|
||||||
|
</Limit>
|
||||||
|
|
||||||
|
#Header set Access-Control-Allow-Origin "app.gruppolapastamadre.it"
|
||||||
|
#Header set Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
|
||||||
+187
-178
@@ -1,76 +1,73 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
* DropPHP - A simple Dropbox client that works without cURL.
|
* DropPHP - A simple Dropbox client that works without cURL.
|
||||||
*
|
*
|
||||||
* http://fabi.me/en/php-projects/dropphp-dropbox-api-client/
|
* http://fabi.me/en/php-projects/dropphp-dropbox-api-client/
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
* @author Fabian Schlieper <[email protected]>
|
* @author Fabian Schlieper <[email protected]>
|
||||||
* @copyright Fabian Schlieper 2014
|
* @copyright Fabian Schlieper 2012
|
||||||
* @version 1.7.1
|
* @version 1.7
|
||||||
* @license See LICENSE
|
* @license See LICENSE
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
require_once(dirname(__FILE__)."/OAuthSimple.php");
|
require_once(dirname(__FILE__)."/OAuthSimple.php");
|
||||||
|
|
||||||
class DropboxClient {
|
class DropboxClient {
|
||||||
|
|
||||||
const API_URL = "https://api.dropbox.com/1/";
|
const API_URL = "https://api.dropbox.com/1/";
|
||||||
const API_CONTENT_URL = "https://api-content.dropbox.com/1/";
|
const API_CONTENT_URL = "https://api-content.dropbox.com/1/";
|
||||||
|
|
||||||
const BUFFER_SIZE = 4096;
|
const BUFFER_SIZE = 4096;
|
||||||
|
|
||||||
const MAX_UPLOAD_CHUNK_SIZE = 150000000; // 150MB
|
const MAX_UPLOAD_CHUNK_SIZE = 150000000; // 150MB
|
||||||
|
|
||||||
const UPLOAD_CHUNK_SIZE = 4000000; // 4MB
|
const UPLOAD_CHUNK_SIZE = 4000000; // 4MB
|
||||||
|
|
||||||
private $appParams;
|
private $appParams;
|
||||||
private $consumerToken;
|
private $consumerToken;
|
||||||
|
|
||||||
private $requestToken;
|
private $requestToken;
|
||||||
private $accessToken;
|
private $accessToken;
|
||||||
|
|
||||||
private $locale;
|
private $locale;
|
||||||
private $rootPath;
|
private $rootPath;
|
||||||
|
|
||||||
private $useCurl;
|
private $useCurl;
|
||||||
|
|
||||||
function __construct ($app_params, $locale = "en"){
|
function __construct ($app_params, $locale = "en"){
|
||||||
$this->appParams = $app_params;
|
$this->appParams = $app_params;
|
||||||
if(empty($app_params['app_key']))
|
if(empty($app_params['app_key']))
|
||||||
throw new DropboxException("App Key is empty!");
|
throw new DropboxException("App Key is empty!");
|
||||||
|
|
||||||
$this->consumerToken = array('t' => $this->appParams['app_key'], 's' => $this->appParams['app_secret']);
|
$this->consumerToken = array('t' => $this->appParams['app_key'], 's' => $this->appParams['app_secret']);
|
||||||
$this->locale = $locale;
|
$this->locale = $locale;
|
||||||
$this->rootPath = empty($app_params['app_full_access']) ? "sandbox" : "dropbox";
|
$this->rootPath = empty($app_params['app_full_access']) ? "sandbox" : "dropbox";
|
||||||
|
|
||||||
$this->requestToken = null;
|
$this->requestToken = null;
|
||||||
$this->accessToken = null;
|
$this->accessToken = null;
|
||||||
|
|
||||||
$this->useCurl = function_exists('curl_init');
|
$this->useCurl = function_exists('curl_init');
|
||||||
}
|
}
|
||||||
|
|
||||||
function __wakeup() {
|
/**
|
||||||
$this->useCurl = $this->useCurl && function_exists('curl_init');
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Sets whether to use cURL if its available or PHP HTTP wrappers otherwise
|
* Sets whether to use cURL if its available or PHP HTTP wrappers otherwise
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return boolean Whether to actually use cURL (always false if not installed)
|
* @return boolean Whether to actually use cURL (always false if not installed)
|
||||||
*/
|
*/
|
||||||
public function SetUseCUrl($use_it)
|
public function SetUseCUrl($use_it)
|
||||||
{
|
{
|
||||||
return ($this->useCurl = ($use_it && function_exists('curl_init')));
|
return ($this->useCurl = ($use_it && function_exists('curl_init')));
|
||||||
}
|
}
|
||||||
|
|
||||||
// ##################################################
|
// ##################################################
|
||||||
// Authorization
|
// Authorization
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Step 1 of authentication process. Retrieves a request token or returns a previously retrieved one.
|
* Step 1 of authentication process. Retrieves a request token or returns a previously retrieved one.
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param boolean $get_new_token Optional (default false). Wether to retrieve a new request token.
|
* @param boolean $get_new_token Optional (default false). Wether to retrieve a new request token.
|
||||||
* @return array Request Token array.
|
* @return array Request Token array.
|
||||||
@@ -79,31 +76,31 @@ class DropboxClient {
|
|||||||
{
|
{
|
||||||
if(!empty($this->requestToken) && !$get_new_token)
|
if(!empty($this->requestToken) && !$get_new_token)
|
||||||
return $this->requestToken;
|
return $this->requestToken;
|
||||||
|
|
||||||
$rt = $this->authCall("oauth/request_token");
|
$rt = $this->authCall("oauth/request_token");
|
||||||
if(empty($rt) || empty($rt['oauth_token']))
|
if(empty($rt) || empty($rt['oauth_token']))
|
||||||
throw new DropboxException('Could not get request token!');
|
throw new DropboxException('Could not get request token!');
|
||||||
|
|
||||||
return ($this->requestToken = array('t'=>$rt['oauth_token'], 's'=>$rt['oauth_token_secret']));
|
return ($this->requestToken = array('t'=>$rt['oauth_token'], 's'=>$rt['oauth_token_secret']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Step 2. Returns a URL the user must be redirected to in order to connect the app to their Dropbox account
|
* Step 2. Returns a URL the user must be redirected to in order to connect the app to their Dropbox account
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string $return_url URL users are redirected after authorization
|
* @param string $return_url URL users are redirected after authorization
|
||||||
* @return string URL
|
* @return string URL
|
||||||
*/
|
*/
|
||||||
public function BuildAuthorizeUrl($return_url)
|
public function BuildAuthorizeUrl($return_url)
|
||||||
{
|
{
|
||||||
$rt = $this->GetRequestToken();
|
$rt = $this->GetRequestToken();
|
||||||
if(empty($rt) || empty($rt['t'])) throw new DropboxException('Request Token Invalid ('.print_r($rt,true).').');
|
if(empty($rt) || empty($rt['t'])) throw new DropboxException('Request Token Invalid ('.print_r($rt,true).').');
|
||||||
return "https://www.dropbox.com/1/oauth/authorize?oauth_token=".$rt['t']."&oauth_callback=".urlencode($return_url);
|
return "https://www.dropbox.com/1/oauth/authorize?oauth_token=".$rt['t']."&oauth_callback=".urlencode($return_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Step 3. Acquires an access token. This is the final step of authentication.
|
* Step 3. Acquires an access token. This is the final step of authentication.
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param array $request_token Optional. The previously retrieved request token. This parameter can only be skipped if the DropboxClient object has been (de)serialized.
|
* @param array $request_token Optional. The previously retrieved request token. This parameter can only be skipped if the DropboxClient object has been (de)serialized.
|
||||||
* @return array Access Token array.
|
* @return array Access Token array.
|
||||||
@@ -111,20 +108,20 @@ class DropboxClient {
|
|||||||
public function GetAccessToken($request_token = null)
|
public function GetAccessToken($request_token = null)
|
||||||
{
|
{
|
||||||
if(!empty($this->accessToken)) return $this->accessToken;
|
if(!empty($this->accessToken)) return $this->accessToken;
|
||||||
|
|
||||||
if(empty($request_token)) $request_token = $this->requestToken;
|
if(empty($request_token)) $request_token = $this->requestToken;
|
||||||
if(empty($request_token)) throw new DropboxException('Request token required!');
|
if(empty($request_token)) throw new DropboxException('Request token required!');
|
||||||
|
|
||||||
$at = $this->authCall("oauth/access_token", $request_token);
|
$at = $this->authCall("oauth/access_token", $request_token);
|
||||||
if(empty($at))
|
if(empty($at))
|
||||||
throw new DropboxException(sprintf('Could not get access token! (request token: %s)', $request_token['t']));
|
throw new DropboxException(sprintf('Could not get access token! (request token: %s)', $request_token['t']));
|
||||||
|
|
||||||
return ($this->accessToken = array('t'=>$at['oauth_token'], 's'=>$at['oauth_token_secret']));
|
return ($this->accessToken = array('t'=>$at['oauth_token'], 's'=>$at['oauth_token_secret']));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a previously retrieved (and stored) access token.
|
* Sets a previously retrieved (and stored) access token.
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string|object $token The Access Token
|
* @param string|object $token The Access Token
|
||||||
* @return none
|
* @return none
|
||||||
@@ -133,79 +130,79 @@ class DropboxClient {
|
|||||||
{
|
{
|
||||||
if(empty($token['t']) || empty($token['s'])) throw new DropboxException('Passed invalid access token.');
|
if(empty($token['t']) || empty($token['s'])) throw new DropboxException('Passed invalid access token.');
|
||||||
$this->accessToken = $token;
|
$this->accessToken = $token;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if an access token has been set.
|
* Checks if an access token has been set.
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return boolean Authorized or not
|
* @return boolean Authorized or not
|
||||||
*/
|
*/
|
||||||
public function IsAuthorized()
|
public function IsAuthorized()
|
||||||
{
|
{
|
||||||
if(empty($this->accessToken)) return false;
|
if(empty($this->accessToken)) return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ##################################################
|
// ##################################################
|
||||||
// API Functions
|
// API Functions
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves information about the user's account.
|
* Retrieves information about the user's account.
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @return object Account info object. See https://www.dropbox.com/developers/reference/api#account-info
|
* @return object Account info object. See https://www.dropbox.com/developers/reference/api#account-info
|
||||||
*/
|
*/
|
||||||
public function GetAccountInfo()
|
public function GetAccountInfo()
|
||||||
{
|
{
|
||||||
return $this->apiCall("account/info", "GET");
|
return $this->apiCall("account/info", "GET");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get file list of a dropbox folder.
|
* Get file list of a dropbox folder.
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string|object $dropbox_path Dropbox path of the folder
|
* @param string|object $dropbox_path Dropbox path of the folder
|
||||||
* @return array An array with metadata of files/folders keyed by paths
|
* @return array An array with metadata of files/folders keyed by paths
|
||||||
*/
|
*/
|
||||||
public function GetFiles($dropbox_path='', $recursive=false, $include_deleted=false)
|
public function GetFiles($dropbox_path='', $recursive=false, $include_deleted=false)
|
||||||
{
|
{
|
||||||
if(is_object($dropbox_path) && !empty($dropbox_path->path)) $dropbox_path = $dropbox_path->path;
|
if(is_object($dropbox_path) && !empty($dropbox_path->path)) $dropbox_path = $dropbox_path->path;
|
||||||
return $this->getFileTree($dropbox_path, $include_deleted, $recursive ? 1000 : 0);
|
return $this->getFileTree($dropbox_path, $include_deleted, $recursive ? 1000 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get file or folder metadata
|
* Get file or folder metadata
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param $dropbox_path string Dropbox path of the file or folder
|
* @param $dropbox_path string Dropbox path of the file or folder
|
||||||
*/
|
*/
|
||||||
public function GetMetadata($dropbox_path, $include_deleted=false, $rev=null)
|
public function GetMetadata($dropbox_path, $include_deleted=false, $rev=null)
|
||||||
{
|
{
|
||||||
if(is_object($dropbox_path) && !empty($dropbox_path->path)) $dropbox_path = $dropbox_path->path;
|
if(is_object($dropbox_path) && !empty($dropbox_path->path)) $dropbox_path = $dropbox_path->path;
|
||||||
return $this->apiCall("metadata/$this->rootPath/$dropbox_path", "GET", compact('include_deleted','rev'));
|
return $this->apiCall("metadata/$this->rootPath/$dropbox_path", "GET", compact('include_deleted','rev'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download a file to the webserver
|
* Download a file to the webserver
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param string|object $dropbox_file Dropbox path or metadata object of the file to download.
|
* @param string|object $dropbox_file Dropbox path or metadata object of the file to download.
|
||||||
* @param string $dest_path Local path for destination
|
* @param string $dest_path Local path for destination
|
||||||
* @param string $rev Optional. The revision of the file to retrieve. This defaults to the most recent revision.
|
* @param string $rev Optional. The revision of the file to retrieve. This defaults to the most recent revision.
|
||||||
* @param callback $progress_changed_callback Optional. Callback that will be called during download with 2 args: 1. bytes loaded, 2. file size
|
* @param callback $progress_changed_callback Optional. Callback that will be called during download with 2 args: 1. bytes loaded, 2. file size
|
||||||
* @return object Dropbox file metadata
|
* @return object Dropbox file metadata
|
||||||
*/
|
*/
|
||||||
public function DownloadFile($dropbox_file, $dest_path='', $rev=null, $progress_changed_callback = null)
|
public function DownloadFile($dropbox_file, $dest_path='', $rev=null, $progress_changed_callback = null)
|
||||||
{
|
{
|
||||||
if(is_object($dropbox_file) && !empty($dropbox_file->path))
|
if(is_object($dropbox_file) && !empty($dropbox_file->path))
|
||||||
$dropbox_file = $dropbox_file->path;
|
$dropbox_file = $dropbox_file->path;
|
||||||
|
|
||||||
if(empty($dest_path)) $dest_path = basename($dropbox_file);
|
if(empty($dest_path)) $dest_path = basename($dropbox_file);
|
||||||
|
|
||||||
$url = $this->cleanUrl(self::API_CONTENT_URL."/files/$this->rootPath/$dropbox_file")
|
$url = $this->cleanUrl(self::API_CONTENT_URL."/files/$this->rootPath/$dropbox_file")
|
||||||
. (!empty($rev) ? ('?'.http_build_query(array('rev' => $rev),'','&')) : '');
|
. (!empty($rev) ? ('?'.http_build_query(array('rev' => $rev),'','&')) : '');
|
||||||
$context = $this->createRequestContext($url, "GET");
|
$context = $this->createRequestContext($url, "GET");
|
||||||
@@ -215,7 +212,7 @@ class DropboxClient {
|
|||||||
@fclose($rh);
|
@fclose($rh);
|
||||||
throw new DropboxException("Could not create file $dest_path !");
|
throw new DropboxException("Could not create file $dest_path !");
|
||||||
}
|
}
|
||||||
|
|
||||||
if($this->useCurl) {
|
if($this->useCurl) {
|
||||||
curl_setopt($context, CURLOPT_BINARYTRANSFER, true);
|
curl_setopt($context, CURLOPT_BINARYTRANSFER, true);
|
||||||
curl_setopt($context, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($context, CURLOPT_RETURNTRANSFER, true);
|
||||||
@@ -229,8 +226,8 @@ class DropboxClient {
|
|||||||
$rh = @fopen($url, 'rb', false, $context); // read binary
|
$rh = @fopen($url, 'rb', false, $context); // read binary
|
||||||
if($rh === false)
|
if($rh === false)
|
||||||
throw new DropboxException("HTTP request to $url failed!");
|
throw new DropboxException("HTTP request to $url failed!");
|
||||||
|
|
||||||
|
|
||||||
// get file meta from HTTP header
|
// get file meta from HTTP header
|
||||||
$s_meta = stream_get_meta_data($rh);
|
$s_meta = stream_get_meta_data($rh);
|
||||||
$meta = self::getMetaFromHeaders($s_meta['wrapper_data'], true);
|
$meta = self::getMetaFromHeaders($s_meta['wrapper_data'], true);
|
||||||
@@ -246,30 +243,30 @@ class DropboxClient {
|
|||||||
call_user_func($progress_changed_callback, $bytes_loaded, $meta->bytes);
|
call_user_func($progress_changed_callback, $bytes_loaded, $meta->bytes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose($rh);
|
fclose($rh);
|
||||||
fclose($fh);
|
fclose($fh);
|
||||||
}
|
}
|
||||||
|
|
||||||
if($meta->bytes != $bytes_loaded)
|
if($meta->bytes != $bytes_loaded)
|
||||||
throw new DropboxException("Download size mismatch! (header:{$meta->bytes} vs actual:{$bytes_loaded}; curl:{$this->useCurl})");
|
throw new DropboxException("Download size mismatch! (header:{$meta->bytes} vs actual:{$bytes_loaded}; curl:{$this->useCurl})");
|
||||||
|
|
||||||
return $meta;
|
return $meta;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upload a file to dropbox
|
* Upload a file to dropbox
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param $src_file string Local file to upload
|
* @param $src_file string Local file to upload
|
||||||
* @param $dropbox_path string Dropbox path for destination
|
* @param $dropbox_path string Dropbox path for destination
|
||||||
* @return object Dropbox file metadata
|
* @return object Dropbox file metadata
|
||||||
*/
|
*/
|
||||||
public function UploadFile($src_file, $dropbox_path='', $overwrite=true, $parent_rev=null)
|
public function UploadFile($src_file, $dropbox_path='', $overwrite=true, $parent_rev=null)
|
||||||
{
|
{
|
||||||
if(empty($dropbox_path)) $dropbox_path = basename($src_file);
|
if(empty($dropbox_path)) $dropbox_path = basename($src_file);
|
||||||
elseif(is_object($dropbox_path) && !empty($dropbox_path->path)) $dropbox_path = $dropbox_path->path;
|
elseif(is_object($dropbox_path) && !empty($dropbox_path->path)) $dropbox_path = $dropbox_path->path;
|
||||||
|
|
||||||
// make sure the dropbox_path is not a dir. if it is, append baseneme of $src_file
|
// make sure the dropbox_path is not a dir. if it is, append baseneme of $src_file
|
||||||
$dropbox_bn = basename($dropbox_path);
|
$dropbox_bn = basename($dropbox_path);
|
||||||
if(strpos($dropbox_bn,'.') === false) { // check if ext. is missing -> could be a directory!
|
if(strpos($dropbox_bn,'.') === false) { // check if ext. is missing -> could be a directory!
|
||||||
@@ -279,52 +276,64 @@ class DropboxClient {
|
|||||||
$dropbox_path = $dropbox_path . '/'. basename($src_file);
|
$dropbox_path = $dropbox_path . '/'. basename($src_file);
|
||||||
} catch(Exception $e) {}
|
} catch(Exception $e) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
$file_size = filesize($src_file);
|
$file_size = filesize($src_file);
|
||||||
|
|
||||||
if($file_size > self::MAX_UPLOAD_CHUNK_SIZE)
|
if($file_size > self::MAX_UPLOAD_CHUNK_SIZE)
|
||||||
{
|
{
|
||||||
$fh = fopen($src_file,'rb');
|
$fh = fopen($src_file,'rb');
|
||||||
if($fh === false)
|
if($fh === false)
|
||||||
throw new DropboxException();
|
throw new DropboxException();
|
||||||
|
|
||||||
$upload_id = null;
|
$upload_id = null;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
|
|
||||||
|
|
||||||
while(!feof($fh)) {
|
while(!feof($fh)) {
|
||||||
$url = $this->cleanUrl(self::API_CONTENT_URL."/chunked_upload").'?'.http_build_query(compact('upload_id', 'offset'),'','&');
|
$url = $this->cleanUrl(self::API_CONTENT_URL."/chunked_upload").'?'.http_build_query(compact('upload_id', 'offset'),'','&');
|
||||||
$content = fread($fh, self::UPLOAD_CHUNK_SIZE);
|
|
||||||
$context = $this->createRequestContext($url, "PUT", $content);
|
if($this->useCurl) {
|
||||||
|
$context = $this->createRequestContext($url, "PUT");
|
||||||
if($this->useCurl) {
|
|
||||||
curl_setopt($context, CURLOPT_BINARYTRANSFER, true);
|
curl_setopt($context, CURLOPT_BINARYTRANSFER, true);
|
||||||
|
curl_setopt($context, CURLOPT_PUT, 1);
|
||||||
|
curl_setopt($context, CURLOPT_INFILE, $fh);
|
||||||
|
$chunk_size = min(self::UPLOAD_CHUNK_SIZE, $file_size - $offset);
|
||||||
|
$offset += $chunk_size;
|
||||||
|
curl_setopt($context, CURLOPT_INFILESIZE, $chunk_size);
|
||||||
$response = json_decode(self::execCurlAndClose($context));
|
$response = json_decode(self::execCurlAndClose($context));
|
||||||
|
|
||||||
|
fseek($fh,$offset);
|
||||||
|
if($offset >= $file_size)
|
||||||
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
$content = fread($fh, self::UPLOAD_CHUNK_SIZE);
|
||||||
|
|
||||||
|
$context = $this->createRequestContext($url, "PUT", $content);
|
||||||
|
$offset += strlen($content);
|
||||||
|
unset($content);
|
||||||
|
|
||||||
$response = json_decode(file_get_contents($url, false, $context));
|
$response = json_decode(file_get_contents($url, false, $context));
|
||||||
}
|
}
|
||||||
$offset += strlen($content);
|
|
||||||
unset($content);
|
|
||||||
unset($context);
|
unset($context);
|
||||||
|
|
||||||
self::checkForError($response);
|
self::checkForError($response);
|
||||||
|
|
||||||
if(empty($upload_id)) {
|
if(empty($upload_id)) {
|
||||||
$upload_id = $response->upload_id;
|
$upload_id = $response->upload_id;
|
||||||
if(empty($upload_id)) throw new DropboxException("Upload ID empty!");
|
if(empty($upload_id)) throw new DropboxException("Upload ID empty!");
|
||||||
}
|
}
|
||||||
if($offset >= $file_size)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@fclose($fh);
|
@fclose($fh);
|
||||||
|
|
||||||
|
$this->useCurl = $prev_useCurl;
|
||||||
|
|
||||||
return $this->apiCall("commit_chunked_upload/$this->rootPath/$dropbox_path", "POST", compact('overwrite','parent_rev','upload_id'), true);
|
return $this->apiCall("commit_chunked_upload/$this->rootPath/$dropbox_path", "POST", compact('overwrite','parent_rev','upload_id'), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$query = http_build_query(array_merge(compact('overwrite', 'parent_rev'), array('locale' => $this->locale)),'','&');
|
$query = http_build_query(array_merge(compact('overwrite', 'parent_rev'), array('locale' => $this->locale)),'','&');
|
||||||
$url = $this->cleanUrl(self::API_CONTENT_URL."/files_put/$this->rootPath/$dropbox_path")."?$query";
|
$url = $this->cleanUrl(self::API_CONTENT_URL."/files_put/$this->rootPath/$dropbox_path")."?$query";
|
||||||
|
|
||||||
if($this->useCurl) {
|
if($this->useCurl) {
|
||||||
$context = $this->createRequestContext($url, "PUT");
|
$context = $this->createRequestContext($url, "PUT");
|
||||||
curl_setopt($context, CURLOPT_BINARYTRANSFER, true);
|
curl_setopt($context, CURLOPT_BINARYTRANSFER, true);
|
||||||
@@ -339,13 +348,13 @@ class DropboxClient {
|
|||||||
$content = file_get_contents($src_file);
|
$content = file_get_contents($src_file);
|
||||||
if(strlen($content) == 0)
|
if(strlen($content) == 0)
|
||||||
throw new DropboxException("Could not read file $src_file or file is empty!");
|
throw new DropboxException("Could not read file $src_file or file is empty!");
|
||||||
|
|
||||||
$context = $this->createRequestContext($url, "PUT", $content);
|
$context = $this->createRequestContext($url, "PUT", $content);
|
||||||
|
|
||||||
return self::checkForError(json_decode(file_get_contents($url, false, $context)));
|
return self::checkForError(json_decode(file_get_contents($url, false, $context)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get thumbnail for a specified image
|
* Get thumbnail for a specified image
|
||||||
*
|
*
|
||||||
@@ -360,13 +369,13 @@ class DropboxClient {
|
|||||||
if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
|
if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
|
||||||
$url = $this->cleanUrl(self::API_CONTENT_URL."thumbnails/$this->rootPath/$dropbox_file")
|
$url = $this->cleanUrl(self::API_CONTENT_URL."thumbnails/$this->rootPath/$dropbox_file")
|
||||||
. '?' . http_build_query(array('format' => $format, 'size' => $size),'','&');
|
. '?' . http_build_query(array('format' => $format, 'size' => $size),'','&');
|
||||||
$context = $this->createRequestContext($url, "GET");
|
$context = $this->createRequestContext($url, "GET");
|
||||||
|
|
||||||
if($this->useCurl) {
|
if($this->useCurl) {
|
||||||
curl_setopt($context, CURLOPT_BINARYTRANSFER, true);
|
curl_setopt($context, CURLOPT_BINARYTRANSFER, true);
|
||||||
curl_setopt($context, CURLOPT_RETURNTRANSFER, true);
|
curl_setopt($context, CURLOPT_RETURNTRANSFER, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
$thumb = $this->useCurl ? self::execCurlAndClose($context) : file_get_contents($url, NULL, $context);
|
$thumb = $this->useCurl ? self::execCurlAndClose($context) : file_get_contents($url, NULL, $context);
|
||||||
|
|
||||||
if($echo) {
|
if($echo) {
|
||||||
@@ -375,11 +384,11 @@ class DropboxClient {
|
|||||||
unset($thumb);
|
unset($thumb);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $thumb;
|
return $thumb;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function GetLink($dropbox_file, $preview=true, $short=true, &$expires=null)
|
function GetLink($dropbox_file, $preview=true, $short=true, &$expires=null)
|
||||||
{
|
{
|
||||||
if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
|
if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
|
||||||
@@ -387,29 +396,29 @@ class DropboxClient {
|
|||||||
$expires = strtotime($url->expires);
|
$expires = strtotime($url->expires);
|
||||||
return $url->url;
|
return $url->url;
|
||||||
}
|
}
|
||||||
|
|
||||||
function Delta($cursor)
|
function Delta($cursor)
|
||||||
{
|
{
|
||||||
return $this->apiCall("delta", "POST", compact('cursor'));
|
return $this->apiCall("delta", "POST", compact('cursor'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetRevisions($dropbox_file, $rev_limit=10)
|
function GetRevisions($dropbox_file, $rev_limit=10)
|
||||||
{
|
{
|
||||||
if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
|
if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
|
||||||
return $this->apiCall("revisions/$this->rootPath/$dropbox_file", "GET", compact('rev_limit'));
|
return $this->apiCall("revisions/$this->rootPath/$dropbox_file", "GET", compact('rev_limit'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function Restore($dropbox_file, $rev)
|
function Restore($dropbox_file, $rev)
|
||||||
{
|
{
|
||||||
if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
|
if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
|
||||||
return $this->apiCall("restore/$this->rootPath/$dropbox_file", "POST", compact('rev'));
|
return $this->apiCall("restore/$this->rootPath/$dropbox_file", "POST", compact('rev'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function Search($path, $query, $file_limit=1000, $include_deleted=false)
|
function Search($path, $query, $file_limit=1000, $include_deleted=false)
|
||||||
{
|
{
|
||||||
return $this->apiCall("search/$this->rootPath/$path", "POST", compact('query','file_limit','include_deleted'));
|
return $this->apiCall("search/$this->rootPath/$path", "POST", compact('query','file_limit','include_deleted'));
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetCopyRef($dropbox_file, &$expires=null)
|
function GetCopyRef($dropbox_file, &$expires=null)
|
||||||
{
|
{
|
||||||
if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
|
if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
|
||||||
@@ -417,56 +426,56 @@ class DropboxClient {
|
|||||||
$expires = strtotime($ref->expires);
|
$expires = strtotime($ref->expires);
|
||||||
return $ref->copy_ref;
|
return $ref->copy_ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function Copy($from_path, $to_path, $copy_ref=false)
|
function Copy($from_path, $to_path, $copy_ref=false)
|
||||||
{
|
{
|
||||||
if(is_object($from_path) && !empty($from_path->path)) $from_path = $from_path->path;
|
if(is_object($from_path) && !empty($from_path->path)) $from_path = $from_path->path;
|
||||||
return $this->apiCall("fileops/copy", "POST", array('root'=> $this->rootPath, ($copy_ref ? 'from_copy_ref' : 'from_path') => $from_path, 'to_path' => $to_path));
|
return $this->apiCall("fileops/copy", "POST", array('root'=> $this->rootPath, ($copy_ref ? 'from_copy_ref' : 'from_path') => $from_path, 'to_path' => $to_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new folder in the DropBox
|
* Creates a new folder in the DropBox
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param $path string The path to the new folder to create
|
* @param $path string The path to the new folder to create
|
||||||
* @return object Dropbox folder metadata
|
* @return object Dropbox folder metadata
|
||||||
*/
|
*/
|
||||||
function CreateFolder($path)
|
function CreateFolder($path)
|
||||||
{
|
{
|
||||||
return $this->apiCall("fileops/create_folder", "POST", array('root'=> $this->rootPath, 'path' => $path));
|
return $this->apiCall("fileops/create_folder", "POST", array('root'=> $this->rootPath, 'path' => $path));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete file or folder
|
* Delete file or folder
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
* @param $path mixed The path or metadata of the file/folder to be deleted.
|
* @param $path mixed The path or metadata of the file/folder to be deleted.
|
||||||
* @return object Dropbox metadata of deleted file or folder
|
* @return object Dropbox metadata of deleted file or folder
|
||||||
*/
|
*/
|
||||||
function Delete($path)
|
function Delete($path)
|
||||||
{
|
{
|
||||||
if(is_object($path) && !empty($path->path)) $path = $path->path;
|
if(is_object($path) && !empty($path->path)) $path = $path->path;
|
||||||
return $this->apiCall("fileops/delete", "POST", array('locale' =>null, 'root'=> $this->rootPath, 'path' => $path));
|
return $this->apiCall("fileops/delete", "POST", array('locale' =>null, 'root'=> $this->rootPath, 'path' => $path));
|
||||||
}
|
}
|
||||||
|
|
||||||
function Move($from_path, $to_path)
|
function Move($from_path, $to_path)
|
||||||
{
|
{
|
||||||
if(is_object($from_path) && !empty($from_path->path)) $from_path = $from_path->path;
|
if(is_object($from_path) && !empty($from_path->path)) $from_path = $from_path->path;
|
||||||
return $this->apiCall("fileops/move", "POST", array('root'=> $this->rootPath, 'from_path' => $from_path, 'to_path' => $to_path));
|
return $this->apiCall("fileops/move", "POST", array('root'=> $this->rootPath, 'from_path' => $from_path, 'to_path' => $to_path));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getFileTree($path="", $include_deleted = false, $max_depth = 0, $depth=0)
|
function getFileTree($path="", $include_deleted = false, $max_depth = 0, $depth=0)
|
||||||
{
|
{
|
||||||
static $files;
|
static $files;
|
||||||
if($depth == 0) $files = array();
|
if($depth == 0) $files = array();
|
||||||
|
|
||||||
$dir = $this->apiCall("metadata/$this->rootPath/$path", "GET", compact('include_deleted'));
|
$dir = $this->apiCall("metadata/$this->rootPath/$path", "GET", compact('include_deleted'));
|
||||||
|
|
||||||
if(empty($dir) || !is_object($dir)) return false;
|
if(empty($dir) || !is_object($dir)) return false;
|
||||||
|
|
||||||
if(!empty($dir->error)) throw new DropboxException($dir->error);
|
if(!empty($dir->error)) throw new DropboxException($dir->error);
|
||||||
|
|
||||||
foreach($dir->contents as $item)
|
foreach($dir->contents as $item)
|
||||||
{
|
{
|
||||||
$files[trim($item->path,'/')] = $item;
|
$files[trim($item->path,'/')] = $item;
|
||||||
@@ -475,42 +484,42 @@ class DropboxClient {
|
|||||||
$this->getFileTree($item->path, $include_deleted, $max_depth, $depth+1);
|
$this->getFileTree($item->path, $include_deleted, $max_depth, $depth+1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $files;
|
return $files;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createCurl($url, $http_context)
|
function createCurl($url, $http_context)
|
||||||
{
|
{
|
||||||
$ch = curl_init($url);
|
$ch = curl_init($url);
|
||||||
|
|
||||||
$curl_opts = array(
|
$curl_opts = array(
|
||||||
CURLOPT_HEADER => false, // exclude header from output
|
CURLOPT_HEADER => false, // exclude header from output
|
||||||
//CURLOPT_MUTE => true, // no output!
|
//CURLOPT_MUTE => true, // no output!
|
||||||
CURLOPT_RETURNTRANSFER => true, // but return!
|
CURLOPT_RETURNTRANSFER => true, // but return!
|
||||||
CURLOPT_SSL_VERIFYPEER => false,
|
CURLOPT_SSL_VERIFYPEER => false,
|
||||||
);
|
);
|
||||||
|
|
||||||
$curl_opts[CURLOPT_CUSTOMREQUEST] = $http_context['method'];
|
$curl_opts[CURLOPT_CUSTOMREQUEST] = $http_context['method'];
|
||||||
|
|
||||||
if(!empty($http_context['content'])) {
|
if(!empty($http_context['content'])) {
|
||||||
$curl_opts[CURLOPT_POSTFIELDS] =& $http_context['content'];
|
$curl_opts[CURLOPT_POSTFIELDS] =& $http_context['content'];
|
||||||
if(defined("CURLOPT_POSTFIELDSIZE"))
|
if(defined("CURLOPT_POSTFIELDSIZE"))
|
||||||
$curl_opts[CURLOPT_POSTFIELDSIZE] = strlen($http_context['content']);
|
$curl_opts[CURLOPT_POSTFIELDSIZE] = strlen($http_context['content']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$curl_opts[CURLOPT_HTTPHEADER] = array_map('trim',explode("\n",$http_context['header']));
|
$curl_opts[CURLOPT_HTTPHEADER] = array_map('trim',explode("\n",$http_context['header']));
|
||||||
|
|
||||||
curl_setopt_array($ch, $curl_opts);
|
curl_setopt_array($ch, $curl_opts);
|
||||||
return $ch;
|
return $ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
static private $_curlHeadersRef;
|
static private $_curlHeadersRef;
|
||||||
static function _curlHeaderCallback($ch, $header)
|
static function _curlHeaderCallback($ch, $header)
|
||||||
{
|
{
|
||||||
self::$_curlHeadersRef[] = trim($header);
|
self::$_curlHeadersRef[] = trim($header);
|
||||||
return strlen($header);
|
return strlen($header);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function &execCurlAndClose($ch, &$out_response_headers = null)
|
static function &execCurlAndClose($ch, &$out_response_headers = null)
|
||||||
{
|
{
|
||||||
if(is_array($out_response_headers)) {
|
if(is_array($out_response_headers)) {
|
||||||
@@ -524,41 +533,41 @@ class DropboxClient {
|
|||||||
if($err_no || $res === false) {
|
if($err_no || $res === false) {
|
||||||
throw new DropboxException("cURL-Error ($err_no): $err_str");
|
throw new DropboxException("cURL-Error ($err_no): $err_str");
|
||||||
}
|
}
|
||||||
|
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function createRequestContext($url, $method, &$content=null, $oauth_token=-1)
|
private function createRequestContext($url, $method, &$content=null, $oauth_token=-1)
|
||||||
{
|
{
|
||||||
if($oauth_token === -1)
|
if($oauth_token === -1)
|
||||||
$oauth_token = $this->accessToken;
|
$oauth_token = $this->accessToken;
|
||||||
|
|
||||||
$method = strtoupper($method);
|
$method = strtoupper($method);
|
||||||
$http_context = array('method'=>$method, 'header'=> '');
|
$http_context = array('method'=>$method, 'header'=> '');
|
||||||
|
|
||||||
$oauth = new OAuthSimple($this->consumerToken['t'],$this->consumerToken['s']);
|
$oauth = new OAuthSimple($this->consumerToken['t'],$this->consumerToken['s']);
|
||||||
|
|
||||||
if(empty($oauth_token) && !empty($this->accessToken))
|
if(empty($oauth_token) && !empty($this->accessToken))
|
||||||
$oauth_token = $this->accessToken;
|
$oauth_token = $this->accessToken;
|
||||||
|
|
||||||
if(!empty($oauth_token)) {
|
if(!empty($oauth_token)) {
|
||||||
$oauth->setParameters(array('oauth_token' => $oauth_token['t']));
|
$oauth->setParameters(array('oauth_token' => $oauth_token['t']));
|
||||||
$oauth->signatures(array('oauth_secret'=>$oauth_token['s']));
|
$oauth->signatures(array('oauth_secret'=>$oauth_token['s']));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($content)) {
|
if(!empty($content)) {
|
||||||
$post_vars = ($method != "PUT" && preg_match("/^[a-z][a-z0-9_]*=/i", substr($content, 0, 32)));
|
$post_vars = ($method != "PUT" && preg_match("/^[a-z][a-z0-9_]*=/i", substr($content, 0, 32)));
|
||||||
$http_context['header'] .= "Content-Length: ".strlen($content)."\r\n";
|
$http_context['header'] .= "Content-Length: ".strlen($content)."\r\n";
|
||||||
$http_context['header'] .= "Content-Type: application/".($post_vars?"x-www-form-urlencoded":"octet-stream")."\r\n";
|
$http_context['header'] .= "Content-Type: application/".($post_vars?"x-www-form-urlencoded":"octet-stream")."\r\n";
|
||||||
$http_context['content'] =& $content;
|
$http_context['content'] =& $content;
|
||||||
if($method == "POST" && $post_vars)
|
if($method == "POST" && $post_vars)
|
||||||
$oauth->setParameters($content);
|
$oauth->setParameters($content);
|
||||||
} elseif($method == "POST") {
|
} elseif($method == "POST") {
|
||||||
// make sure that content-length is always set when post request (otherwise some wrappers fail!)
|
// make sure that content-length is always set when post request (otherwise some wrappers fail!)
|
||||||
$http_context['content'] = "";
|
$http_context['content'] = "";
|
||||||
$http_context['header'] .= "Content-Length: 0\r\n";
|
$http_context['header'] .= "Content-Length: 0\r\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// check for query vars in url and add them to oauth parameters (and remove from path)
|
// check for query vars in url and add them to oauth parameters (and remove from path)
|
||||||
$path = $url;
|
$path = $url;
|
||||||
@@ -567,56 +576,56 @@ class DropboxClient {
|
|||||||
$oauth->setParameters(substr($query,1));
|
$oauth->setParameters(substr($query,1));
|
||||||
$path = substr($url, 0, -strlen($query));
|
$path = substr($url, 0, -strlen($query));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$signed = $oauth->sign(array(
|
$signed = $oauth->sign(array(
|
||||||
'action' => $method,
|
'action' => $method,
|
||||||
'path'=> $path));
|
'path'=> $path));
|
||||||
//print_r($signed);
|
//print_r($signed);
|
||||||
|
|
||||||
$http_context['header'] .= "Authorization: ".$signed['header']."\r\n";
|
$http_context['header'] .= "Authorization: ".$signed['header']."\r\n";
|
||||||
|
|
||||||
return $this->useCurl ? $this->createCurl($url, $http_context) : stream_context_create(array('http'=>$http_context));
|
return $this->useCurl ? $this->createCurl($url, $http_context) : stream_context_create(array('http'=>$http_context));
|
||||||
}
|
}
|
||||||
|
|
||||||
private function authCall($path, $request_token=null)
|
private function authCall($path, $request_token=null)
|
||||||
{
|
{
|
||||||
$url = $this->cleanUrl(self::API_URL.$path);
|
$url = $this->cleanUrl(self::API_URL.$path);
|
||||||
$dummy = null;
|
$dummy = null;
|
||||||
$context = $this->createRequestContext($url, "POST", $dummy, $request_token);
|
$context = $this->createRequestContext($url, "POST", $dummy, $request_token);
|
||||||
|
|
||||||
$contents = $this->useCurl ? self::execCurlAndClose($context) : file_get_contents($url, false, $context);
|
$contents = $this->useCurl ? self::execCurlAndClose($context) : file_get_contents($url, false, $context);
|
||||||
$data = array();
|
$data = array();
|
||||||
parse_str($contents, $data);
|
parse_str($contents, $data);
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static function checkForError($resp)
|
private static function checkForError($resp)
|
||||||
{
|
{
|
||||||
if(!empty($resp->error))
|
if(!empty($resp->error))
|
||||||
throw new DropboxException($resp->error);
|
throw new DropboxException($resp->error);
|
||||||
return $resp;
|
return $resp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private function apiCall($path, $method, $params=array(), $content_call=false)
|
private function apiCall($path, $method, $params=array(), $content_call=false)
|
||||||
{
|
{
|
||||||
$url = $this->cleanUrl(($content_call ? self::API_CONTENT_URL : self::API_URL).$path);
|
$url = $this->cleanUrl(($content_call ? self::API_CONTENT_URL : self::API_URL).$path);
|
||||||
$content = http_build_query(array_merge(array('locale'=>$this->locale), $params),'','&');
|
$content = http_build_query(array_merge(array('locale'=>$this->locale), $params),'','&');
|
||||||
|
|
||||||
if($method == "GET") {
|
if($method == "GET") {
|
||||||
$url .= "?".$content;
|
$url .= "?".$content;
|
||||||
$content = null;
|
$content = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$context = $this->createRequestContext($url, $method, $content);
|
$context = $this->createRequestContext($url, $method, $content);
|
||||||
$json = $this->useCurl ? self::execCurlAndClose($context) : file_get_contents($url, false, $context);
|
$json = $this->useCurl ? self::execCurlAndClose($context) : file_get_contents($url, false, $context);
|
||||||
//if($json === false)
|
//if($json === false)
|
||||||
// throw new DropboxException();
|
// throw new DropboxException();
|
||||||
$resp = json_decode($json);
|
$resp = json_decode($json);
|
||||||
return self::checkForError($resp);
|
return self::checkForError($resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static function getMetaFromHeaders(&$header_array, $throw_on_error=false)
|
private static function getMetaFromHeaders(&$header_array, $throw_on_error=false)
|
||||||
{
|
{
|
||||||
@@ -627,7 +636,7 @@ class DropboxClient {
|
|||||||
self::checkForError ($obj);
|
self::checkForError ($obj);
|
||||||
return $obj;
|
return $obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function cleanUrl($url) {
|
function cleanUrl($url) {
|
||||||
$p = substr($url,0,8);
|
$p = substr($url,0,8);
|
||||||
@@ -639,8 +648,8 @@ class DropboxClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class DropboxException extends Exception {
|
class DropboxException extends Exception {
|
||||||
|
|
||||||
public function __construct($err = null, $isDebug = FALSE)
|
public function __construct($err = null, $isDebug = FALSE)
|
||||||
{
|
{
|
||||||
if(is_null($err)) {
|
if(is_null($err)) {
|
||||||
$el = error_get_last();
|
$el = error_get_last();
|
||||||
@@ -655,12 +664,12 @@ class DropboxException extends Exception {
|
|||||||
self::display_error($err, TRUE);
|
self::display_error($err, TRUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function log_error($err)
|
public static function log_error($err)
|
||||||
{
|
{
|
||||||
error_log($err, 0);
|
error_log($err, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function display_error($err, $kill = FALSE)
|
public static function display_error($err, $kill = FALSE)
|
||||||
{
|
{
|
||||||
print_r($err);
|
print_r($err);
|
||||||
|
|||||||
+86
-85
@@ -1,86 +1,87 @@
|
|||||||
<?php
|
<?php
|
||||||
class MysqlClass
|
|
||||||
{
|
class MysqlClass {
|
||||||
// parametri per la connessione al database
|
|
||||||
private $nomehost = "localhost";
|
// parametri per la connessione al database
|
||||||
private $nomeuser = "root";
|
private $nomehost = "localhost";
|
||||||
private $password = "root";
|
private $nomeuser = "root";
|
||||||
private $mydb = "w18092_ricettario";
|
private $password = "root";
|
||||||
/*
|
private $mydb = "w18092_ricettario";
|
||||||
private $nomehost = "sql.gruppolapastamadre.it";
|
/*
|
||||||
private $nomeuser = "w18092_ricuser";
|
private $nomehost = "sql.gruppolapastamadre.it";
|
||||||
private $password = "RTvg0o6IESoqQyx8CCJn";
|
private $nomeuser = "w18092_ricuser";
|
||||||
private $mydb = "w18092_ricettario";
|
private $password = "RTvg0o6IESoqQyx8CCJn";
|
||||||
*/
|
private $mydb = "w18092_ricettario";
|
||||||
// controllo sulle connessioni attive
|
*/
|
||||||
private $attiva = false;
|
// controllo sulle connessioni attive
|
||||||
private $connessione = null;
|
private $attiva = false;
|
||||||
|
private $connessione = null;
|
||||||
// funzione per la connessione a MySQL
|
|
||||||
public function connetti() {
|
// funzione per la connessione a MySQL
|
||||||
if (!$this->attiva) {
|
public function connetti() {
|
||||||
$this->connessione = mysqli_connect($this->nomehost, $this->nomeuser, $this->password);
|
if (!$this->attiva) {
|
||||||
if ($this->connessione == FALSE)
|
$this->connessione = mysqli_connect($this->nomehost, $this->nomeuser, $this->password);
|
||||||
die(mysqli_error());
|
if ($this->connessione == FALSE)
|
||||||
mysqli_select_db($this->connessione, $this->mydb) or die("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
|
die(mysqli_error());
|
||||||
$this->attiva = true;
|
mysqli_select_db($this->connessione, $this->mydb) or die("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
|
||||||
}
|
$this->attiva = true;
|
||||||
else {
|
}
|
||||||
return true;
|
else {
|
||||||
}
|
return true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public function executeQuery($queryStr) {
|
|
||||||
$this->connetti();
|
public function executeQuery($queryStr) {
|
||||||
|
$this->connetti();
|
||||||
if (!$res = mysqli_query($this->connessione, $queryStr))
|
|
||||||
die(mysqli_error());
|
if (!$res = mysqli_query($this->connessione, $queryStr))
|
||||||
return true;
|
die(mysqli_error());
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
public function insertRecord($queryStr) {
|
|
||||||
$this->connetti();
|
public function insertRecord($queryStr) {
|
||||||
|
$this->connetti();
|
||||||
if (!$res = mysqli_query($this->connessione, $queryStr))
|
|
||||||
die(mysqli_error());
|
if (!$res = mysqli_query($this->connessione, $queryStr))
|
||||||
return mysqli_insert_id($this->connessione);
|
die(mysqli_error());
|
||||||
}
|
return mysqli_insert_id($this->connessione);
|
||||||
|
}
|
||||||
public function queryToObject($queryStr, $encode = true) {
|
|
||||||
$this->connetti();
|
public function queryToObject($queryStr, $encode = true) {
|
||||||
|
$this->connetti();
|
||||||
$sth = mysqli_query($this->connessione, $queryStr) or die(mysqli_error());
|
|
||||||
|
$sth = mysqli_query($this->connessione, $queryStr) or die(mysqli_error());
|
||||||
if($encode){
|
|
||||||
$rows = array();
|
if($encode){
|
||||||
while ($r = mysqli_fetch_assoc($sth)) {
|
$rows = array();
|
||||||
array_push($rows, array_map('utf8_encode', $r));
|
while ($r = mysqli_fetch_assoc($sth)) {
|
||||||
}
|
array_push($rows, array_map('utf8_encode', $r));
|
||||||
mysqli_free_result($sth);
|
}
|
||||||
return $rows;
|
mysqli_free_result($sth);
|
||||||
}
|
return $rows;
|
||||||
else
|
}
|
||||||
{
|
else
|
||||||
return mysqli_fetch_array($sth);
|
{
|
||||||
}
|
return mysqli_fetch_array($sth);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
// funzione per la chiusura della connessione
|
|
||||||
public function disconnetti() {
|
// funzione per la chiusura della connessione
|
||||||
if ($this->attiva) {
|
public function disconnetti() {
|
||||||
if (mysqli_close($this->connessione)) {
|
if ($this->attiva) {
|
||||||
$this->attiva = false;
|
if (mysqli_close($this->connessione)) {
|
||||||
return true;
|
$this->attiva = false;
|
||||||
} else {
|
return true;
|
||||||
return false;
|
} else {
|
||||||
}
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
public function __destruct() {
|
|
||||||
$this->disconnetti();
|
public function __destruct() {
|
||||||
}
|
$this->disconnetti();
|
||||||
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
@@ -1,22 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace PHPImageWorkshop\Core\Exception;
|
namespace PHPImageWorkshop\Core\Exception;
|
||||||
|
|
||||||
use PHPImageWorkshop\Exception\ImageWorkshopBaseException as ImageWorkshopBaseException;
|
use PHPImageWorkshop\Exception\ImageWorkshopBaseException as ImageWorkshopBaseException;
|
||||||
|
|
||||||
// If no autoloader, uncomment these lines:
|
// If no autoloader, uncomment these lines:
|
||||||
//require_once(__DIR__.'/../../Exception/ImageWorkshopBaseException.php');
|
require_once(__DIR__.'/../../Exception/ImageWorkshopBaseException.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ImageWorkshopLayerException
|
* ImageWorkshopLayerException
|
||||||
*
|
*
|
||||||
* Manage ImageWorkshopLayer exceptions
|
* Manage ImageWorkshopLayer exceptions
|
||||||
*
|
*
|
||||||
* @link http://phpimageworkshop.com
|
* @link http://phpimageworkshop.com
|
||||||
* @author Sybio (Clément Guillemain / @Sybio01)
|
* @author Sybio (Clément Guillemain / @Sybio01)
|
||||||
* @license http://en.wikipedia.org/wiki/MIT_License
|
* @license http://en.wikipedia.org/wiki/MIT_License
|
||||||
* @copyright Clément Guillemain
|
* @copyright Clément Guillemain
|
||||||
*/
|
*/
|
||||||
class ImageWorkshopLayerException extends ImageWorkshopBaseException
|
class ImageWorkshopLayerException extends ImageWorkshopBaseException
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@@ -1,22 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace PHPImageWorkshop\Core\Exception;
|
namespace PHPImageWorkshop\Core\Exception;
|
||||||
|
|
||||||
use PHPImageWorkshop\Exception\ImageWorkshopBaseException as ImageWorkshopBaseException;
|
use PHPImageWorkshop\Exception\ImageWorkshopBaseException as ImageWorkshopBaseException;
|
||||||
|
|
||||||
// If no autoloader, uncomment these lines:
|
// If no autoloader, uncomment these lines:
|
||||||
//require_once(__DIR__.'/../../Exception/ImageWorkshopBaseException.php');
|
require_once(__DIR__.'/../../Exception/ImageWorkshopBaseException.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ImageWorkshopLibException
|
* ImageWorkshopLibException
|
||||||
*
|
*
|
||||||
* Manage ImageWorkshopLib exceptions
|
* Manage ImageWorkshopLib exceptions
|
||||||
*
|
*
|
||||||
* @link http://phpimageworkshop.com
|
* @link http://phpimageworkshop.com
|
||||||
* @author Sybio (Clément Guillemain / @Sybio01)
|
* @author Sybio (Clément Guillemain / @Sybio01)
|
||||||
* @license http://en.wikipedia.org/wiki/MIT_License
|
* @license http://en.wikipedia.org/wiki/MIT_License
|
||||||
* @copyright Clément Guillemain
|
* @copyright Clément Guillemain
|
||||||
*/
|
*/
|
||||||
class ImageWorkshopLibException extends ImageWorkshopBaseException
|
class ImageWorkshopLibException extends ImageWorkshopBaseException
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -1,299 +1,299 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace PHPImageWorkshop\Core;
|
namespace PHPImageWorkshop\Core;
|
||||||
|
|
||||||
use PHPImageWorkshop\Core\Exception\ImageWorkshopLibException as ImageWorkshopLibException;
|
use PHPImageWorkshop\Core\Exception\ImageWorkshopLibException as ImageWorkshopLibException;
|
||||||
|
|
||||||
// If no autoloader, uncomment these lines:
|
// If no autoloader, uncomment these lines:
|
||||||
//require_once(__DIR__.'/Exception/ImageWorkshopLibException.php');
|
require_once(__DIR__.'/Exception/ImageWorkshopLibException.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ImageWorkshopLib class
|
* ImageWorkshopLib class
|
||||||
*
|
*
|
||||||
* Contains some tools to help in some ImageWorkshop calculations
|
* Contains some tools to help in some ImageWorkshop calculations
|
||||||
*
|
*
|
||||||
* @link http://phpimageworkshop.com
|
* @link http://phpimageworkshop.com
|
||||||
* @author Sybio (Clément Guillemain / @Sybio01)
|
* @author Sybio (Clément Guillemain / @Sybio01)
|
||||||
* @license http://en.wikipedia.org/wiki/MIT_License
|
* @license http://en.wikipedia.org/wiki/MIT_License
|
||||||
* @copyright Clément Guillemain
|
* @copyright Clément Guillemain
|
||||||
*/
|
*/
|
||||||
class ImageWorkshopLib
|
class ImageWorkshopLib
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var integer
|
* @var integer
|
||||||
*/
|
*/
|
||||||
const ERROR_FONT_NOT_FOUND = 3;
|
const ERROR_FONT_NOT_FOUND = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate the left top positions of a layer inside a parent layer container
|
* Calculate the left top positions of a layer inside a parent layer container
|
||||||
* $position: http://phpimageworkshop.com/doc/22/corners-positions-schema-of-an-image.html
|
* $position: http://phpimageworkshop.com/doc/22/corners-positions-schema-of-an-image.html
|
||||||
*
|
*
|
||||||
* @param integer $containerWidth
|
* @param integer $containerWidth
|
||||||
* @param integer $containerHeight
|
* @param integer $containerHeight
|
||||||
* @param integer $layerWidth
|
* @param integer $layerWidth
|
||||||
* @param integer $layerHeight
|
* @param integer $layerHeight
|
||||||
* @param integer $layerPositionX
|
* @param integer $layerPositionX
|
||||||
* @param integer $layerPositionY
|
* @param integer $layerPositionY
|
||||||
* @param string $position
|
* @param string $position
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function calculatePositions($containerWidth, $containerHeight, $layerWidth, $layerHeight, $layerPositionX, $layerPositionY, $position = 'LT')
|
public static function calculatePositions($containerWidth, $containerHeight, $layerWidth, $layerHeight, $layerPositionX, $layerPositionY, $position = 'LT')
|
||||||
{
|
{
|
||||||
$position = strtolower($position);
|
$position = strtolower($position);
|
||||||
|
|
||||||
if ($position == 'rt') {
|
if ($position == 'rt') {
|
||||||
|
|
||||||
$layerPositionX = $containerWidth - $layerWidth - $layerPositionX;
|
$layerPositionX = $containerWidth - $layerWidth - $layerPositionX;
|
||||||
|
|
||||||
} elseif ($position == 'lb') {
|
} elseif ($position == 'lb') {
|
||||||
|
|
||||||
$layerPositionY = $containerHeight - $layerHeight - $layerPositionY;
|
$layerPositionY = $containerHeight - $layerHeight - $layerPositionY;
|
||||||
|
|
||||||
} elseif ($position == 'rb') {
|
} elseif ($position == 'rb') {
|
||||||
|
|
||||||
$layerPositionX = $containerWidth - $layerWidth - $layerPositionX;
|
$layerPositionX = $containerWidth - $layerWidth - $layerPositionX;
|
||||||
$layerPositionY = $containerHeight - $layerHeight - $layerPositionY;
|
$layerPositionY = $containerHeight - $layerHeight - $layerPositionY;
|
||||||
|
|
||||||
} elseif ($position == 'mm') {
|
} elseif ($position == 'mm') {
|
||||||
|
|
||||||
$layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;
|
$layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;
|
||||||
$layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;
|
$layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;
|
||||||
|
|
||||||
} elseif ($position == 'mt') {
|
} elseif ($position == 'mt') {
|
||||||
|
|
||||||
$layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;
|
$layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;
|
||||||
|
|
||||||
} elseif ($position == 'mb') {
|
} elseif ($position == 'mb') {
|
||||||
|
|
||||||
$layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;
|
$layerPositionX = (($containerWidth - $layerWidth) / 2) + $layerPositionX;
|
||||||
$layerPositionY = $containerHeight - $layerHeight - $layerPositionY;
|
$layerPositionY = $containerHeight - $layerHeight - $layerPositionY;
|
||||||
|
|
||||||
} elseif ($position == 'lm') {
|
} elseif ($position == 'lm') {
|
||||||
|
|
||||||
$layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;
|
$layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;
|
||||||
|
|
||||||
} elseif ($position == 'rm') {
|
} elseif ($position == 'rm') {
|
||||||
|
|
||||||
$layerPositionX = $containerWidth - $layerWidth - $layerPositionX;
|
$layerPositionX = $containerWidth - $layerWidth - $layerPositionX;
|
||||||
$layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;
|
$layerPositionY = (($containerHeight - $layerHeight) / 2) + $layerPositionY;
|
||||||
}
|
}
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'x' => $layerPositionX,
|
'x' => $layerPositionX,
|
||||||
'y' => $layerPositionY,
|
'y' => $layerPositionY,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert Hex color to RGB color format
|
* Convert Hex color to RGB color format
|
||||||
*
|
*
|
||||||
* @param string $hex
|
* @param string $hex
|
||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public static function convertHexToRGB($hex)
|
public static function convertHexToRGB($hex)
|
||||||
{
|
{
|
||||||
return array(
|
return array(
|
||||||
'R' => (int) base_convert(substr($hex, 0, 2), 16, 10),
|
'R' => (int) base_convert(substr($hex, 0, 2), 16, 10),
|
||||||
'G' => (int) base_convert(substr($hex, 2, 2), 16, 10),
|
'G' => (int) base_convert(substr($hex, 2, 2), 16, 10),
|
||||||
'B' => (int) base_convert(substr($hex, 4, 2), 16, 10),
|
'B' => (int) base_convert(substr($hex, 4, 2), 16, 10),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate a new image resource var
|
* Generate a new image resource var
|
||||||
*
|
*
|
||||||
* @param integer $width
|
* @param integer $width
|
||||||
* @param integer $height
|
* @param integer $height
|
||||||
* @param string $color
|
* @param string $color
|
||||||
* @param integer $opacity
|
* @param integer $opacity
|
||||||
*
|
*
|
||||||
* @return resource
|
* @return resource
|
||||||
*/
|
*/
|
||||||
public static function generateImage($width = 100, $height = 100, $color = 'ffffff', $opacity = 127)
|
public static function generateImage($width = 100, $height = 100, $color = 'ffffff', $opacity = 127)
|
||||||
{
|
{
|
||||||
$RGBColors = ImageWorkshopLib::convertHexToRGB($color);
|
$RGBColors = ImageWorkshopLib::convertHexToRGB($color);
|
||||||
|
|
||||||
$image = imagecreatetruecolor($width, $height);
|
$image = imagecreatetruecolor($width, $height);
|
||||||
imagesavealpha($image, true);
|
imagesavealpha($image, true);
|
||||||
$color = imagecolorallocatealpha($image, $RGBColors['R'], $RGBColors['G'], $RGBColors['B'], $opacity);
|
$color = imagecolorallocatealpha($image, $RGBColors['R'], $RGBColors['G'], $RGBColors['B'], $opacity);
|
||||||
imagefill($image, 0, 0, $color);
|
imagefill($image, 0, 0, $color);
|
||||||
|
|
||||||
return $image;
|
return $image;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return dimension of a text
|
* Return dimension of a text
|
||||||
*
|
*
|
||||||
* @param $fontSize
|
* @param $fontSize
|
||||||
* @param $fontAngle
|
* @param $fontAngle
|
||||||
* @param $fontFile
|
* @param $fontFile
|
||||||
* @param $text
|
* @param $text
|
||||||
*
|
*
|
||||||
* @return array or boolean
|
* @return array or boolean
|
||||||
*/
|
*/
|
||||||
public static function getTextBoxDimension($fontSize, $fontAngle, $fontFile, $text)
|
public static function getTextBoxDimension($fontSize, $fontAngle, $fontFile, $text)
|
||||||
{
|
{
|
||||||
if (!file_exists($fontFile)) {
|
if (!file_exists($fontFile)) {
|
||||||
throw new ImageWorkshopLibException('Can\'t find a font file at this path : "'.$fontFile.'".', static::ERROR_FONT_NOT_FOUND);
|
throw new ImageWorkshopLibException('Can\'t find a font file at this path : "'.$fontFile.'".', static::ERROR_FONT_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
$box = imagettfbbox($fontSize, $fontAngle, $fontFile, $text);
|
$box = imagettfbbox($fontSize, $fontAngle, $fontFile, $text);
|
||||||
|
|
||||||
if (!$box) {
|
if (!$box) {
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$minX = min(array($box[0], $box[2], $box[4], $box[6]));
|
$minX = min(array($box[0], $box[2], $box[4], $box[6]));
|
||||||
$maxX = max(array($box[0], $box[2], $box[4], $box[6]));
|
$maxX = max(array($box[0], $box[2], $box[4], $box[6]));
|
||||||
$minY = min(array($box[1], $box[3], $box[5], $box[7]));
|
$minY = min(array($box[1], $box[3], $box[5], $box[7]));
|
||||||
$maxY = max(array($box[1], $box[3], $box[5], $box[7]));
|
$maxY = max(array($box[1], $box[3], $box[5], $box[7]));
|
||||||
$width = ($maxX - $minX);
|
$width = ($maxX - $minX);
|
||||||
$height = ($maxY - $minY);
|
$height = ($maxY - $minY);
|
||||||
$left = abs($minX) + $width;
|
$left = abs($minX) + $width;
|
||||||
$top = abs($minY) + $height;
|
$top = abs($minY) + $height;
|
||||||
|
|
||||||
// to calculate the exact bounding box, we write the text in a large image
|
// to calculate the exact bounding box, we write the text in a large image
|
||||||
$img = @imagecreatetruecolor($width << 2, $height << 2);
|
$img = @imagecreatetruecolor($width << 2, $height << 2);
|
||||||
$white = imagecolorallocate($img, 255, 255, 255);
|
$white = imagecolorallocate($img, 255, 255, 255);
|
||||||
$black = imagecolorallocate($img, 0, 0, 0);
|
$black = imagecolorallocate($img, 0, 0, 0);
|
||||||
imagefilledrectangle($img, 0, 0, imagesx($img), imagesy($img), $black);
|
imagefilledrectangle($img, 0, 0, imagesx($img), imagesy($img), $black);
|
||||||
|
|
||||||
// for ensure that the text is completely in the image
|
// for ensure that the text is completely in the image
|
||||||
imagettftext($img, $fontSize, $fontAngle, $left, $top, $white, $fontFile, $text);
|
imagettftext($img, $fontSize, $fontAngle, $left, $top, $white, $fontFile, $text);
|
||||||
|
|
||||||
// start scanning (0=> black => empty)
|
// start scanning (0=> black => empty)
|
||||||
$rleft = $w4 = $width<<2;
|
$rleft = $w4 = $width<<2;
|
||||||
$rright = 0;
|
$rright = 0;
|
||||||
$rbottom = 0;
|
$rbottom = 0;
|
||||||
$rtop = $h4 = $height<<2;
|
$rtop = $h4 = $height<<2;
|
||||||
|
|
||||||
for ($x = 0; $x < $w4; $x++) {
|
for ($x = 0; $x < $w4; $x++) {
|
||||||
|
|
||||||
for ($y = 0; $y < $h4; $y++) {
|
for ($y = 0; $y < $h4; $y++) {
|
||||||
|
|
||||||
if (imagecolorat($img, $x, $y)) {
|
if (imagecolorat($img, $x, $y)) {
|
||||||
|
|
||||||
$rleft = min($rleft, $x);
|
$rleft = min($rleft, $x);
|
||||||
$rright = max($rright, $x);
|
$rright = max($rright, $x);
|
||||||
$rtop = min($rtop, $y);
|
$rtop = min($rtop, $y);
|
||||||
$rbottom = max($rbottom, $y);
|
$rbottom = max($rbottom, $y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
imagedestroy($img);
|
imagedestroy($img);
|
||||||
|
|
||||||
return array(
|
return array(
|
||||||
'left' => $left - $rleft,
|
'left' => $left - $rleft,
|
||||||
'top' => $top - $rtop,
|
'top' => $top - $rtop,
|
||||||
'width' => $rright - $rleft + 1,
|
'width' => $rright - $rleft + 1,
|
||||||
'height' => $rbottom - $rtop + 1,
|
'height' => $rbottom - $rtop + 1,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Copy an image on another one and converse transparency
|
* Copy an image on another one and converse transparency
|
||||||
*
|
*
|
||||||
* @param resource $destImg
|
* @param resource $destImg
|
||||||
* @param resource $srcImg
|
* @param resource $srcImg
|
||||||
* @param integer $destX
|
* @param integer $destX
|
||||||
* @param integer $destY
|
* @param integer $destY
|
||||||
* @param integer $srcX
|
* @param integer $srcX
|
||||||
* @param integer $srcY
|
* @param integer $srcY
|
||||||
* @param integer $srcW
|
* @param integer $srcW
|
||||||
* @param integer $srcH
|
* @param integer $srcH
|
||||||
* @param integer $pct
|
* @param integer $pct
|
||||||
*/
|
*/
|
||||||
public static function imageCopyMergeAlpha(&$destImg, &$srcImg, $destX, $destY, $srcX, $srcY, $srcW, $srcH, $pct = 0)
|
public static function imageCopyMergeAlpha(&$destImg, &$srcImg, $destX, $destY, $srcX, $srcY, $srcW, $srcH, $pct = 0)
|
||||||
{
|
{
|
||||||
$destX = (int) $destX;
|
$destX = (int) $destX;
|
||||||
$destY = (int) $destY;
|
$destY = (int) $destY;
|
||||||
$srcX = (int) $srcX;
|
$srcX = (int) $srcX;
|
||||||
$srcY = (int) $srcY;
|
$srcY = (int) $srcY;
|
||||||
$srcW = (int) $srcW;
|
$srcW = (int) $srcW;
|
||||||
$srcH = (int) $srcH;
|
$srcH = (int) $srcH;
|
||||||
$pct = (int) $pct;
|
$pct = (int) $pct;
|
||||||
$destW = imageSX($destImg);
|
$destW = imageSX($destImg);
|
||||||
$destH = imageSY($destImg);
|
$destH = imageSY($destImg);
|
||||||
|
|
||||||
for ($y = 0; $y < $srcH + $srcY; $y++) {
|
for ($y = 0; $y < $srcH + $srcY; $y++) {
|
||||||
|
|
||||||
for ($x = 0; $x < $srcW + $srcX; $x++) {
|
for ($x = 0; $x < $srcW + $srcX; $x++) {
|
||||||
|
|
||||||
if ($x + $destX >= 0 && $x + $destX < $destW && $x + $srcX >= 0 && $x + $srcX < $srcW && $y + $destY >= 0 && $y + $destY < $destH && $y + $srcY >= 0 && $y + $srcY < $srcH) {
|
if ($x + $destX >= 0 && $x + $destX < $destW && $x + $srcX >= 0 && $x + $srcX < $srcW && $y + $destY >= 0 && $y + $destY < $destH && $y + $srcY >= 0 && $y + $srcY < $srcH) {
|
||||||
|
|
||||||
$destPixel = imageColorsForIndex($destImg, imageColorat($destImg, $x + $destX, $y + $destY));
|
$destPixel = imageColorsForIndex($destImg, imageColorat($destImg, $x + $destX, $y + $destY));
|
||||||
$srcImgColorat = imageColorat($srcImg, $x + $srcX, $y + $srcY);
|
$srcImgColorat = imageColorat($srcImg, $x + $srcX, $y + $srcY);
|
||||||
|
|
||||||
if ($srcImgColorat >= 0) {
|
if ($srcImgColorat >= 0) {
|
||||||
|
|
||||||
$srcPixel = imageColorsForIndex($srcImg, $srcImgColorat);
|
$srcPixel = imageColorsForIndex($srcImg, $srcImgColorat);
|
||||||
|
|
||||||
$srcAlpha = 1 - ($srcPixel['alpha'] / 127);
|
$srcAlpha = 1 - ($srcPixel['alpha'] / 127);
|
||||||
$destAlpha = 1 - ($destPixel['alpha'] / 127);
|
$destAlpha = 1 - ($destPixel['alpha'] / 127);
|
||||||
$opacity = $srcAlpha * $pct / 100;
|
$opacity = $srcAlpha * $pct / 100;
|
||||||
|
|
||||||
if ($destAlpha >= $opacity) {
|
if ($destAlpha >= $opacity) {
|
||||||
$alpha = $destAlpha;
|
$alpha = $destAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($destAlpha < $opacity) {
|
if ($destAlpha < $opacity) {
|
||||||
$alpha = $opacity;
|
$alpha = $opacity;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($alpha > 1) {
|
if ($alpha > 1) {
|
||||||
$alpha = 1;
|
$alpha = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($opacity > 0) {
|
if ($opacity > 0) {
|
||||||
|
|
||||||
$destRed = round((($destPixel['red'] * $destAlpha * (1 - $opacity))));
|
$destRed = round((($destPixel['red'] * $destAlpha * (1 - $opacity))));
|
||||||
$destGreen = round((($destPixel['green'] * $destAlpha * (1 - $opacity))));
|
$destGreen = round((($destPixel['green'] * $destAlpha * (1 - $opacity))));
|
||||||
$destBlue = round((($destPixel['blue'] * $destAlpha * (1 - $opacity))));
|
$destBlue = round((($destPixel['blue'] * $destAlpha * (1 - $opacity))));
|
||||||
$srcRed = round((($srcPixel['red'] * $opacity)));
|
$srcRed = round((($srcPixel['red'] * $opacity)));
|
||||||
$srcGreen = round((($srcPixel['green'] * $opacity)));
|
$srcGreen = round((($srcPixel['green'] * $opacity)));
|
||||||
$srcBlue = round((($srcPixel['blue'] * $opacity)));
|
$srcBlue = round((($srcPixel['blue'] * $opacity)));
|
||||||
$red = round(($destRed + $srcRed ) / ($destAlpha * (1 - $opacity) + $opacity));
|
$red = round(($destRed + $srcRed ) / ($destAlpha * (1 - $opacity) + $opacity));
|
||||||
$green = round(($destGreen + $srcGreen) / ($destAlpha * (1 - $opacity) + $opacity));
|
$green = round(($destGreen + $srcGreen) / ($destAlpha * (1 - $opacity) + $opacity));
|
||||||
$blue = round(($destBlue + $srcBlue ) / ($destAlpha * (1 - $opacity) + $opacity));
|
$blue = round(($destBlue + $srcBlue ) / ($destAlpha * (1 - $opacity) + $opacity));
|
||||||
|
|
||||||
if ($red > 255) {
|
if ($red > 255) {
|
||||||
$red = 255;
|
$red = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($green > 255) {
|
if ($green > 255) {
|
||||||
$green = 255;
|
$green = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($blue > 255) {
|
if ($blue > 255) {
|
||||||
$blue = 255;
|
$blue = 255;
|
||||||
}
|
}
|
||||||
|
|
||||||
$alpha = round((1 - $alpha) * 127);
|
$alpha = round((1 - $alpha) * 127);
|
||||||
$color = imageColorAllocateAlpha($destImg, $red, $green, $blue, $alpha);
|
$color = imageColorAllocateAlpha($destImg, $red, $green, $blue, $alpha);
|
||||||
imageSetPixel($destImg, $x + $destX, $y + $destY, $color);
|
imageSetPixel($destImg, $x + $destX, $y + $destY, $color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Merge two image var
|
* Merge two image var
|
||||||
*
|
*
|
||||||
* @param resource $destinationImage
|
* @param resource $destinationImage
|
||||||
* @param resource $sourceImage
|
* @param resource $sourceImage
|
||||||
* @param integer $destinationPosX
|
* @param integer $destinationPosX
|
||||||
* @param integer $destinationPosY
|
* @param integer $destinationPosY
|
||||||
* @param integer $sourcePosX
|
* @param integer $sourcePosX
|
||||||
* @param integer $sourcePosY
|
* @param integer $sourcePosY
|
||||||
*/
|
*/
|
||||||
public static function mergeTwoImages(&$destinationImage, $sourceImage, $destinationPosX = 0, $destinationPosY = 0, $sourcePosX = 0, $sourcePosY = 0)
|
public static function mergeTwoImages(&$destinationImage, $sourceImage, $destinationPosX = 0, $destinationPosY = 0, $sourcePosX = 0, $sourcePosY = 0)
|
||||||
{
|
{
|
||||||
imageCopy($destinationImage, $sourceImage, $destinationPosX, $destinationPosY, $sourcePosX, $sourcePosY, imageSX($sourceImage), imageSY($sourceImage));
|
imageCopy($destinationImage, $sourceImage, $destinationPosX, $destinationPosY, $sourcePosX, $sourcePosY, imageSX($sourceImage), imageSY($sourceImage));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,38 +1,38 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace PHPImageWorkshop\Exception;
|
namespace PHPImageWorkshop\Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ImageWorkshopBaseException
|
* ImageWorkshopBaseException
|
||||||
*
|
*
|
||||||
* The inherited exception class
|
* The inherited exception class
|
||||||
*
|
*
|
||||||
* @link http://phpimageworkshop.com
|
* @link http://phpimageworkshop.com
|
||||||
* @author Bjørn Børresen | Sybio (Clément Guillemain / @Sybio01)
|
* @author Bjørn Børresen | Sybio (Clément Guillemain / @Sybio01)
|
||||||
* @license http://en.wikipedia.org/wiki/MIT_License
|
* @license http://en.wikipedia.org/wiki/MIT_License
|
||||||
* @copyright Clément Guillemain
|
* @copyright Clément Guillemain
|
||||||
*/
|
*/
|
||||||
class ImageWorkshopBaseException extends \Exception
|
class ImageWorkshopBaseException extends \Exception
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param string $message
|
* @param string $message
|
||||||
* @param integer $code
|
* @param integer $code
|
||||||
* @param Exception $previous
|
* @param Exception $previous
|
||||||
*/
|
*/
|
||||||
public function __construct($message, $code = 0, \Exception $previous = null)
|
public function __construct($message, $code = 0, \Exception $previous = null)
|
||||||
{
|
{
|
||||||
parent::__construct($message, $code, $previous);
|
parent::__construct($message, $code, $previous);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* __toString method
|
* __toString method
|
||||||
*
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function __toString()
|
public function __toString()
|
||||||
{
|
{
|
||||||
return __CLASS__.": [{$this->code}]: {$this->message}\n";
|
return __CLASS__.": [{$this->code}]: {$this->message}\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,22 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace PHPImageWorkshop\Exception;
|
namespace PHPImageWorkshop\Exception;
|
||||||
|
|
||||||
use PHPImageWorkshop\Exception\ImageWorkshopBaseException as ImageWorkshopBaseException;
|
use PHPImageWorkshop\Exception\ImageWorkshopBaseException as ImageWorkshopBaseException;
|
||||||
|
|
||||||
// If no autoloader, uncomment these lines:
|
// If no autoloader, uncomment these lines:
|
||||||
//require_once(__DIR__.'/ImageWorkshopBaseException.php');
|
require_once(__DIR__.'/ImageWorkshopBaseException.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ImageWorkshopException
|
* ImageWorkshopException
|
||||||
*
|
*
|
||||||
* Manage ImageWorkshop exceptions
|
* Manage ImageWorkshop exceptions
|
||||||
*
|
*
|
||||||
* @link http://phpimageworkshop.com
|
* @link http://phpimageworkshop.com
|
||||||
* @author Sybio (Clément Guillemain / @Sybio01)
|
* @author Sybio (Clément Guillemain / @Sybio01)
|
||||||
* @license http://en.wikipedia.org/wiki/MIT_License
|
* @license http://en.wikipedia.org/wiki/MIT_License
|
||||||
* @copyright Clément Guillemain
|
* @copyright Clément Guillemain
|
||||||
*/
|
*/
|
||||||
class ImageWorkshopException extends ImageWorkshopBaseException
|
class ImageWorkshopException extends ImageWorkshopBaseException
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
+167
-167
@@ -1,168 +1,168 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace PHPImageWorkshop;
|
namespace PHPImageWorkshop;
|
||||||
|
|
||||||
use PHPImageWorkshop\Core\ImageWorkshopLayer as ImageWorkshopLayer;
|
use PHPImageWorkshop\Core\ImageWorkshopLayer as ImageWorkshopLayer;
|
||||||
use PHPImageWorkshop\Core\ImageWorkshopLib as ImageWorkshopLib;
|
use PHPImageWorkshop\Core\ImageWorkshopLib as ImageWorkshopLib;
|
||||||
use PHPImageWorkshop\Exception\ImageWorkshopException as ImageWorkshopException;
|
use PHPImageWorkshop\Exception\ImageWorkshopException as ImageWorkshopException;
|
||||||
|
|
||||||
// If no autoloader, uncomment these lines:
|
// If no autoloader, uncomment these lines:
|
||||||
//require_once(__DIR__.'/Core/ImageWorkshopLayer.php');
|
require_once(__DIR__.'/Core/ImageWorkshopLayer.php');
|
||||||
//require_once(__DIR__.'/Exception/ImageWorkshopException.php');
|
require_once(__DIR__.'/Exception/ImageWorkshopException.php');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ImageWorkshop class
|
* ImageWorkshop class
|
||||||
*
|
*
|
||||||
* Use this class as a factory to initialize ImageWorkshop layers
|
* Use this class as a factory to initialize ImageWorkshop layers
|
||||||
*
|
*
|
||||||
* @version 2.0.6
|
* @version 2.0.6
|
||||||
* @link http://phpimageworkshop.com
|
* @link http://phpimageworkshop.com
|
||||||
* @author Sybio (Clément Guillemain / @Sybio01)
|
* @author Sybio (Clément Guillemain / @Sybio01)
|
||||||
* @license http://en.wikipedia.org/wiki/MIT_License
|
* @license http://en.wikipedia.org/wiki/MIT_License
|
||||||
* @copyright Clément Guillemain
|
* @copyright Clément Guillemain
|
||||||
*/
|
*/
|
||||||
class ImageWorkshop
|
class ImageWorkshop
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* @var integer
|
* @var integer
|
||||||
*/
|
*/
|
||||||
const ERROR_NOT_AN_IMAGE_FILE = 1;
|
const ERROR_NOT_AN_IMAGE_FILE = 1;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var integer
|
* @var integer
|
||||||
*/
|
*/
|
||||||
const ERROR_IMAGE_NOT_FOUND = 2;
|
const ERROR_IMAGE_NOT_FOUND = 2;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var integer
|
* @var integer
|
||||||
*/
|
*/
|
||||||
const ERROR_NOT_WRITABLE_FILE = 3;
|
const ERROR_NOT_WRITABLE_FILE = 3;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var integer
|
* @var integer
|
||||||
*/
|
*/
|
||||||
const ERROR_CREATE_IMAGE_FROM_STRING = 4;
|
const ERROR_CREATE_IMAGE_FROM_STRING = 4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a layer from a given image path
|
* Initialize a layer from a given image path
|
||||||
*
|
*
|
||||||
* From an upload form, you can give the "tmp_name" path
|
* From an upload form, you can give the "tmp_name" path
|
||||||
*
|
*
|
||||||
* @param string $path
|
* @param string $path
|
||||||
*
|
*
|
||||||
* @return ImageWorkshopLayer
|
* @return ImageWorkshopLayer
|
||||||
*/
|
*/
|
||||||
public static function initFromPath($path)
|
public static function initFromPath($path)
|
||||||
{
|
{
|
||||||
if (file_exists($path) && !is_dir($path)) {
|
if (file_exists($path) && !is_dir($path)) {
|
||||||
|
|
||||||
if (!is_readable($path)) {
|
if (!is_readable($path)) {
|
||||||
throw new ImageWorkshopException('Can\'t open the file at "'.$path.'" : file is not writable, did you check permissions (755 / 777) ?', static::ERROR_NOT_WRITABLE_FILE);
|
throw new ImageWorkshopException('Can\'t open the file at "'.$path.'" : file is not writable, did you check permissions (755 / 777) ?', static::ERROR_NOT_WRITABLE_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
$imageSizeInfos = @getImageSize($path);
|
$imageSizeInfos = @getImageSize($path);
|
||||||
$mimeContentType = explode('/', $imageSizeInfos['mime']);
|
$mimeContentType = explode('/', $imageSizeInfos['mime']);
|
||||||
|
|
||||||
if (!$mimeContentType || !array_key_exists(1, $mimeContentType)) {
|
if (!$mimeContentType || !array_key_exists(1, $mimeContentType)) {
|
||||||
throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "'.$path.'"', static::ERROR_NOT_AN_IMAGE_FILE);
|
throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "'.$path.'"', static::ERROR_NOT_AN_IMAGE_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
$mimeContentType = $mimeContentType[1];
|
$mimeContentType = $mimeContentType[1];
|
||||||
|
|
||||||
switch ($mimeContentType) {
|
switch ($mimeContentType) {
|
||||||
case 'jpeg':
|
case 'jpeg':
|
||||||
$image = imageCreateFromJPEG($path);
|
$image = imageCreateFromJPEG($path);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'gif':
|
case 'gif':
|
||||||
$image = imageCreateFromGIF($path);
|
$image = imageCreateFromGIF($path);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'png':
|
case 'png':
|
||||||
$image = imageCreateFromPNG($path);
|
$image = imageCreateFromPNG($path);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "'.$path.'"', static::ERROR_NOT_AN_IMAGE_FILE);
|
throw new ImageWorkshopException('Not an image file (jpeg/png/gif) at "'.$path.'"', static::ERROR_NOT_AN_IMAGE_FILE);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ImageWorkshopLayer($image);
|
return new ImageWorkshopLayer($image);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new ImageWorkshopException('No such file found at "'.$path.'"', static::ERROR_IMAGE_NOT_FOUND);
|
throw new ImageWorkshopException('No such file found at "'.$path.'"', static::ERROR_IMAGE_NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a text layer
|
* Initialize a text layer
|
||||||
*
|
*
|
||||||
* @param string $text
|
* @param string $text
|
||||||
* @param string $fontPath
|
* @param string $fontPath
|
||||||
* @param integer $fontSize
|
* @param integer $fontSize
|
||||||
* @param string $fontColor
|
* @param string $fontColor
|
||||||
* @param integer $textRotation
|
* @param integer $textRotation
|
||||||
* @param integer $backgroundColor
|
* @param integer $backgroundColor
|
||||||
*
|
*
|
||||||
* @return ImageWorkshopLayer
|
* @return ImageWorkshopLayer
|
||||||
*/
|
*/
|
||||||
public static function initTextLayer($text, $fontPath, $fontSize = 13, $fontColor = 'ffffff', $textRotation = 0, $backgroundColor = null)
|
public static function initTextLayer($text, $fontPath, $fontSize = 13, $fontColor = 'ffffff', $textRotation = 0, $backgroundColor = null)
|
||||||
{
|
{
|
||||||
$textDimensions = ImageWorkshopLib::getTextBoxDimension($fontSize, $textRotation, $fontPath, $text);
|
$textDimensions = ImageWorkshopLib::getTextBoxDimension($fontSize, $textRotation, $fontPath, $text);
|
||||||
|
|
||||||
$layer = static::initVirginLayer($textDimensions['width'], $textDimensions['height'], $backgroundColor);
|
$layer = static::initVirginLayer($textDimensions['width'], $textDimensions['height'], $backgroundColor);
|
||||||
$layer->write($text, $fontPath, $fontSize, $fontColor, $textDimensions['left'], $textDimensions['top'], $textRotation);
|
$layer->write($text, $fontPath, $fontSize, $fontColor, $textDimensions['left'], $textDimensions['top'], $textRotation);
|
||||||
|
|
||||||
return $layer;
|
return $layer;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a new virgin layer
|
* Initialize a new virgin layer
|
||||||
*
|
*
|
||||||
* @param integer $width
|
* @param integer $width
|
||||||
* @param integer $height
|
* @param integer $height
|
||||||
* @param string $backgroundColor
|
* @param string $backgroundColor
|
||||||
*
|
*
|
||||||
* @return ImageWorkshopLayer
|
* @return ImageWorkshopLayer
|
||||||
*/
|
*/
|
||||||
public static function initVirginLayer($width = 100, $height = 100, $backgroundColor = null)
|
public static function initVirginLayer($width = 100, $height = 100, $backgroundColor = null)
|
||||||
{
|
{
|
||||||
$opacity = 0;
|
$opacity = 0;
|
||||||
|
|
||||||
if (!$backgroundColor || $backgroundColor == 'transparent') {
|
if (!$backgroundColor || $backgroundColor == 'transparent') {
|
||||||
$opacity = 127;
|
$opacity = 127;
|
||||||
$backgroundColor = 'ffffff';
|
$backgroundColor = 'ffffff';
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ImageWorkshopLayer(ImageWorkshopLib::generateImage($width, $height, $backgroundColor, $opacity));
|
return new ImageWorkshopLayer(ImageWorkshopLib::generateImage($width, $height, $backgroundColor, $opacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a layer from a resource image var
|
* Initialize a layer from a resource image var
|
||||||
*
|
*
|
||||||
* @param \resource $image
|
* @param \resource $image
|
||||||
*
|
*
|
||||||
* @return ImageWorkshopLayer
|
* @return ImageWorkshopLayer
|
||||||
*/
|
*/
|
||||||
public static function initFromResourceVar($image)
|
public static function initFromResourceVar($image)
|
||||||
{
|
{
|
||||||
return new ImageWorkshopLayer($image);
|
return new ImageWorkshopLayer($image);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a layer from a string (obtains with file_get_contents, cURL...)
|
* Initialize a layer from a string (obtains with file_get_contents, cURL...)
|
||||||
*
|
*
|
||||||
* This not recommanded to initialize JPEG string with this method, GD displays bugs !
|
* This not recommanded to initialize JPEG string with this method, GD displays bugs !
|
||||||
*
|
*
|
||||||
* @param string $imageString
|
* @param string $imageString
|
||||||
*
|
*
|
||||||
* @return ImageWorkshopLayer
|
* @return ImageWorkshopLayer
|
||||||
*/
|
*/
|
||||||
public static function initFromString($imageString)
|
public static function initFromString($imageString)
|
||||||
{
|
{
|
||||||
if (!$image = @imageCreateFromString($imageString)) {
|
if (!$image = @imageCreateFromString($imageString)) {
|
||||||
throw new ImageWorkshopException('Can\'t generate an image from the given string.', static::ERROR_CREATE_IMAGE_FROM_STRING);
|
throw new ImageWorkshopException('Can\'t generate an image from the given string.', static::ERROR_CREATE_IMAGE_FROM_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ImageWorkshopLayer($image);
|
return new ImageWorkshopLayer($image);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
@@ -140,10 +140,7 @@ class Environment implements \ArrayAccess, \IteratorAggregate
|
|||||||
$env['SCRIPT_NAME'] = rtrim($physicalPath, '/'); // <-- Remove trailing slashes
|
$env['SCRIPT_NAME'] = rtrim($physicalPath, '/'); // <-- Remove trailing slashes
|
||||||
|
|
||||||
// Virtual path
|
// Virtual path
|
||||||
$env['PATH_INFO'] = $requestUri;
|
$env['PATH_INFO'] = substr_replace($requestUri, '', 0, strlen($physicalPath)); // <-- Remove physical path
|
||||||
if (substr($requestUri, 0, strlen($physicalPath)) == $physicalPath) {
|
|
||||||
$env['PATH_INFO'] = substr($requestUri, strlen($physicalPath)); // <-- Remove physical path
|
|
||||||
}
|
|
||||||
$env['PATH_INFO'] = str_replace('?' . $queryString, '', $env['PATH_INFO']); // <-- Remove query string
|
$env['PATH_INFO'] = str_replace('?' . $queryString, '', $env['PATH_INFO']); // <-- Remove query string
|
||||||
$env['PATH_INFO'] = '/' . ltrim($env['PATH_INFO'], '/'); // <-- Ensure leading slash
|
$env['PATH_INFO'] = '/' . ltrim($env['PATH_INFO'], '/'); // <-- Ensure leading slash
|
||||||
|
|
||||||
@@ -154,8 +151,7 @@ class Environment implements \ArrayAccess, \IteratorAggregate
|
|||||||
$env['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
|
$env['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
|
||||||
|
|
||||||
//Number of server port that is running the script
|
//Number of server port that is running the script
|
||||||
//Fixes: https://github.com/slimphp/Slim/issues/962
|
$env['SERVER_PORT'] = $_SERVER['SERVER_PORT'];
|
||||||
$env['SERVER_PORT'] = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;
|
|
||||||
|
|
||||||
//HTTP request headers (retains HTTP_ prefix to match $_SERVER)
|
//HTTP request headers (retains HTTP_ prefix to match $_SERVER)
|
||||||
$headers = \Slim\Http\Headers::extract($_SERVER);
|
$headers = \Slim\Http\Headers::extract($_SERVER);
|
||||||
@@ -195,9 +191,9 @@ class Environment implements \ArrayAccess, \IteratorAggregate
|
|||||||
{
|
{
|
||||||
if (isset($this->properties[$offset])) {
|
if (isset($this->properties[$offset])) {
|
||||||
return $this->properties[$offset];
|
return $this->properties[$offset];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
|
|||||||
+6
-6
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
@@ -160,7 +160,7 @@ class Set implements \ArrayAccess, \Countable, \IteratorAggregate
|
|||||||
|
|
||||||
public function __unset($key)
|
public function __unset($key)
|
||||||
{
|
{
|
||||||
$this->remove($key);
|
return $this->remove($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -215,8 +215,8 @@ class Set implements \ArrayAccess, \Countable, \IteratorAggregate
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure a value or object will remain globally unique
|
* Ensure a value or object will remain globally unique
|
||||||
* @param string $key The value or object name
|
* @param string $key The value or object name
|
||||||
* @param \Closure $value The closure that defines the object
|
* @param Closure The closure that defines the object
|
||||||
* @return mixed
|
* @return mixed
|
||||||
*/
|
*/
|
||||||
public function singleton($key, $value)
|
public function singleton($key, $value)
|
||||||
@@ -234,8 +234,8 @@ class Set implements \ArrayAccess, \Countable, \IteratorAggregate
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Protect closure from being directly invoked
|
* Protect closure from being directly invoked
|
||||||
* @param \Closure $callable A closure to keep from being invoked and evaluated
|
* @param Closure $callable A closure to keep from being invoked and evaluated
|
||||||
* @return \Closure
|
* @return Closure
|
||||||
*/
|
*/
|
||||||
public function protect(\Closure $callable)
|
public function protect(\Closure $callable)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
@@ -169,9 +169,9 @@ class Request
|
|||||||
return true;
|
return true;
|
||||||
} elseif (isset($this->headers['X_REQUESTED_WITH']) && $this->headers['X_REQUESTED_WITH'] === 'XMLHttpRequest') {
|
} elseif (isset($this->headers['X_REQUESTED_WITH']) && $this->headers['X_REQUESTED_WITH'] === 'XMLHttpRequest') {
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-10
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
@@ -85,7 +85,6 @@ class Response implements \ArrayAccess, \Countable, \IteratorAggregate
|
|||||||
204 => '204 No Content',
|
204 => '204 No Content',
|
||||||
205 => '205 Reset Content',
|
205 => '205 Reset Content',
|
||||||
206 => '206 Partial Content',
|
206 => '206 Partial Content',
|
||||||
226 => '226 IM Used',
|
|
||||||
//Redirection 3xx
|
//Redirection 3xx
|
||||||
300 => '300 Multiple Choices',
|
300 => '300 Multiple Choices',
|
||||||
301 => '301 Moved Permanently',
|
301 => '301 Moved Permanently',
|
||||||
@@ -117,20 +116,13 @@ class Response implements \ArrayAccess, \Countable, \IteratorAggregate
|
|||||||
418 => '418 I\'m a teapot',
|
418 => '418 I\'m a teapot',
|
||||||
422 => '422 Unprocessable Entity',
|
422 => '422 Unprocessable Entity',
|
||||||
423 => '423 Locked',
|
423 => '423 Locked',
|
||||||
426 => '426 Upgrade Required',
|
|
||||||
428 => '428 Precondition Required',
|
|
||||||
429 => '429 Too Many Requests',
|
|
||||||
431 => '431 Request Header Fields Too Large',
|
|
||||||
//Server Error 5xx
|
//Server Error 5xx
|
||||||
500 => '500 Internal Server Error',
|
500 => '500 Internal Server Error',
|
||||||
501 => '501 Not Implemented',
|
501 => '501 Not Implemented',
|
||||||
502 => '502 Bad Gateway',
|
502 => '502 Bad Gateway',
|
||||||
503 => '503 Service Unavailable',
|
503 => '503 Service Unavailable',
|
||||||
504 => '504 Gateway Timeout',
|
504 => '504 Gateway Timeout',
|
||||||
505 => '505 HTTP Version Not Supported',
|
505 => '505 HTTP Version Not Supported'
|
||||||
506 => '506 Variant Also Negotiates',
|
|
||||||
510 => '510 Not Extended',
|
|
||||||
511 => '511 Network Authentication Required'
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+3
-3
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
@@ -60,9 +60,9 @@ class Util
|
|||||||
$strip = is_null($overrideStripSlashes) ? get_magic_quotes_gpc() : $overrideStripSlashes;
|
$strip = is_null($overrideStripSlashes) ? get_magic_quotes_gpc() : $overrideStripSlashes;
|
||||||
if ($strip) {
|
if ($strip) {
|
||||||
return self::stripSlashes($rawData);
|
return self::stripSlashes($rawData);
|
||||||
|
} else {
|
||||||
|
return $rawData;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $rawData;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+2
-7
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
@@ -306,12 +306,7 @@ class Log
|
|||||||
if (!isset(self::$levels[$level])) {
|
if (!isset(self::$levels[$level])) {
|
||||||
throw new \InvalidArgumentException('Invalid log level supplied to function');
|
throw new \InvalidArgumentException('Invalid log level supplied to function');
|
||||||
} else if ($this->enabled && $this->writer && $level <= $this->level) {
|
} else if ($this->enabled && $this->writer && $level <= $this->level) {
|
||||||
if (is_array($object) || (is_object($object) && !method_exists($object, "__toString"))) {
|
$message = (string)$object;
|
||||||
$message = print_r($object, true);
|
|
||||||
} else {
|
|
||||||
$message = (string) $object;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count($context) > 0) {
|
if (count($context) > 0) {
|
||||||
if (isset($context['exception']) && $context['exception'] instanceof \Exception) {
|
if (isset($context['exception']) && $context['exception'] instanceof \Exception) {
|
||||||
$message .= ' - ' . $context['exception'];
|
$message .= ' - ' . $context['exception'];
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
@@ -116,7 +116,7 @@ class ContentTypes extends \Slim\Middleware
|
|||||||
{
|
{
|
||||||
if (function_exists('json_decode')) {
|
if (function_exists('json_decode')) {
|
||||||
$result = json_decode($input, true);
|
$result = json_decode($input, true);
|
||||||
if(json_last_error() === JSON_ERROR_NONE) {
|
if ($result) {
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
@@ -89,7 +89,7 @@ class PrettyExceptions extends \Slim\Middleware
|
|||||||
$message = $exception->getMessage();
|
$message = $exception->getMessage();
|
||||||
$file = $exception->getFile();
|
$file = $exception->getFile();
|
||||||
$line = $exception->getLine();
|
$line = $exception->getLine();
|
||||||
$trace = str_replace(array('#', "\n"), array('<div>#', '</div>'), $exception->getTraceAsString());
|
$trace = str_replace(array('#', '\n'), array('<div>#', '</div>'), $exception->getTraceAsString());
|
||||||
$html = sprintf('<h1>%s</h1>', $title);
|
$html = sprintf('<h1>%s</h1>', $title);
|
||||||
$html .= '<p>The application could not run because of the following error:</p>';
|
$html .= '<p>The application could not run because of the following error:</p>';
|
||||||
$html .= '<h2>Details</h2>';
|
$html .= '<h2>Details</h2>';
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
@@ -119,10 +119,15 @@ class SessionCookie extends \Slim\Middleware
|
|||||||
if (session_id() === '') {
|
if (session_id() === '') {
|
||||||
session_start();
|
session_start();
|
||||||
}
|
}
|
||||||
|
|
||||||
$value = $this->app->getCookie($this->settings['name']);
|
$value = $this->app->getCookie($this->settings['name']);
|
||||||
|
|
||||||
if ($value) {
|
if ($value) {
|
||||||
$value = json_decode($value, true);
|
try {
|
||||||
$_SESSION = is_array($value) ? $value : array();
|
$_SESSION = unserialize($value);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$this->app->getLog()->error('Error unserializing session cookie value! ' . $e->getMessage());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$_SESSION = array();
|
$_SESSION = array();
|
||||||
}
|
}
|
||||||
@@ -133,7 +138,7 @@ class SessionCookie extends \Slim\Middleware
|
|||||||
*/
|
*/
|
||||||
protected function saveSession()
|
protected function saveSession()
|
||||||
{
|
{
|
||||||
$value = json_encode($_SESSION);
|
$value = serialize($_SESSION);
|
||||||
|
|
||||||
if (strlen($value) > 4096) {
|
if (strlen($value) > 4096) {
|
||||||
$this->app->getLog()->error('WARNING! Slim\Middleware\SessionCookie data size is larger than 4KB. Content save failed.');
|
$this->app->getLog()->error('WARNING! Slim\Middleware\SessionCookie data size is larger than 4KB. Content save failed.');
|
||||||
|
|||||||
+1
-7
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
@@ -288,9 +288,6 @@ class Route
|
|||||||
public function appendHttpMethods()
|
public function appendHttpMethods()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
if(count($args) && is_array($args[0])){
|
|
||||||
$args = $args[0];
|
|
||||||
}
|
|
||||||
$this->methods = array_merge($this->methods, $args);
|
$this->methods = array_merge($this->methods, $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -301,9 +298,6 @@ class Route
|
|||||||
public function via()
|
public function via()
|
||||||
{
|
{
|
||||||
$args = func_get_args();
|
$args = func_get_args();
|
||||||
if(count($args) && is_array($args[0])){
|
|
||||||
$args = $args[0];
|
|
||||||
}
|
|
||||||
$this->methods = array_merge($this->methods, $args);
|
$this->methods = array_merge($this->methods, $args);
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
+3
-3
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
@@ -232,9 +232,9 @@ class Router
|
|||||||
$this->getNamedRoutes();
|
$this->getNamedRoutes();
|
||||||
if ($this->hasNamedRoute($name)) {
|
if ($this->hasNamedRoute($name)) {
|
||||||
return $this->namedRoutes[(string) $name];
|
return $this->namedRoutes[(string) $name];
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+11
-43
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
@@ -54,7 +54,7 @@ class Slim
|
|||||||
/**
|
/**
|
||||||
* @const string
|
* @const string
|
||||||
*/
|
*/
|
||||||
const VERSION = '2.6.1';
|
const VERSION = '2.4.2';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Slim\Helper\Set
|
* @var \Slim\Helper\Set
|
||||||
@@ -231,22 +231,22 @@ class Slim
|
|||||||
|
|
||||||
public function __get($name)
|
public function __get($name)
|
||||||
{
|
{
|
||||||
return $this->container->get($name);
|
return $this->container[$name];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __set($name, $value)
|
public function __set($name, $value)
|
||||||
{
|
{
|
||||||
$this->container->set($name, $value);
|
$this->container[$name] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __isset($name)
|
public function __isset($name)
|
||||||
{
|
{
|
||||||
return $this->container->has($name);
|
return isset($this->container[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __unset($name)
|
public function __unset($name)
|
||||||
{
|
{
|
||||||
$this->container->remove($name);
|
unset($this->container[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -906,12 +906,7 @@ class Slim
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
return $value;
|
||||||
* transform $value to @return doc requirement.
|
|
||||||
* \Slim\Http\Util::decodeSecureCookie - is able
|
|
||||||
* to return false and we have to cast it to null.
|
|
||||||
*/
|
|
||||||
return $value === false ? null : $value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1105,18 +1100,6 @@ class Slim
|
|||||||
$this->halt($status);
|
$this->halt($status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* RedirectTo
|
|
||||||
*
|
|
||||||
* Redirects to a specific named route
|
|
||||||
*
|
|
||||||
* @param string $route The route name
|
|
||||||
* @param array $params Associative array of URL parameters and replacement values
|
|
||||||
*/
|
|
||||||
public function redirectTo($route, $params = array(), $status = 302){
|
|
||||||
$this->redirect($this->urlFor($route, $params), $status);
|
|
||||||
}
|
|
||||||
|
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Flash Messages
|
* Flash Messages
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
@@ -1155,16 +1138,6 @@ class Slim
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get all flash messages
|
|
||||||
*/
|
|
||||||
public function flashData()
|
|
||||||
{
|
|
||||||
if (isset($this->environment['slim.flash'])) {
|
|
||||||
return $this->environment['slim.flash']->getMessages();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/********************************************************************************
|
/********************************************************************************
|
||||||
* Hooks
|
* Hooks
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
@@ -1187,10 +1160,10 @@ class Slim
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke hook
|
* Invoke hook
|
||||||
* @param string $name The hook name
|
* @param string $name The hook name
|
||||||
* @param mixed ... (Optional) Argument(s) for hooked functions, can specify multiple arguments
|
* @param mixed $hookArg (Optional) Argument for hooked functions
|
||||||
*/
|
*/
|
||||||
public function applyHook($name)
|
public function applyHook($name, $hookArg = null)
|
||||||
{
|
{
|
||||||
if (!isset($this->hooks[$name])) {
|
if (!isset($this->hooks[$name])) {
|
||||||
$this->hooks[$name] = array(array());
|
$this->hooks[$name] = array(array());
|
||||||
@@ -1200,14 +1173,10 @@ class Slim
|
|||||||
if (count($this->hooks[$name]) > 1) {
|
if (count($this->hooks[$name]) > 1) {
|
||||||
ksort($this->hooks[$name]);
|
ksort($this->hooks[$name]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$args = func_get_args();
|
|
||||||
array_shift($args);
|
|
||||||
|
|
||||||
foreach ($this->hooks[$name] as $priority) {
|
foreach ($this->hooks[$name] as $priority) {
|
||||||
if (!empty($priority)) {
|
if (!empty($priority)) {
|
||||||
foreach ($priority as $callable) {
|
foreach ($priority as $callable) {
|
||||||
call_user_func_array($callable, $args);
|
call_user_func($callable, $hookArg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1375,7 +1344,6 @@ class Slim
|
|||||||
throw $e;
|
throw $e;
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
$this->response()->write(ob_get_clean());
|
|
||||||
$this->error($e);
|
$this->error($e);
|
||||||
} catch (\Slim\Exception\Stop $e) {
|
} catch (\Slim\Exception\Stop $e) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
|
|||||||
+4
-4
@@ -6,7 +6,7 @@
|
|||||||
* @copyright 2011 Josh Lockhart
|
* @copyright 2011 Josh Lockhart
|
||||||
* @link http://www.slimframework.com
|
* @link http://www.slimframework.com
|
||||||
* @license http://www.slimframework.com/license
|
* @license http://www.slimframework.com/license
|
||||||
* @version 2.6.1
|
* @version 2.4.2
|
||||||
* @package Slim
|
* @package Slim
|
||||||
*
|
*
|
||||||
* MIT LICENSE
|
* MIT LICENSE
|
||||||
@@ -108,7 +108,7 @@ class View
|
|||||||
* @param string $key
|
* @param string $key
|
||||||
* @param mixed $value
|
* @param mixed $value
|
||||||
*/
|
*/
|
||||||
public function keep($key, \Closure $value)
|
public function keep($key, Closure $value)
|
||||||
{
|
{
|
||||||
$this->data->keep($key, $value);
|
$this->data->keep($key, $value);
|
||||||
}
|
}
|
||||||
@@ -152,9 +152,9 @@ class View
|
|||||||
{
|
{
|
||||||
if (!is_null($key)) {
|
if (!is_null($key)) {
|
||||||
return isset($this->data[$key]) ? $this->data[$key] : null;
|
return isset($this->data[$key]) ? $this->data[$key] : null;
|
||||||
|
} else {
|
||||||
|
return $this->data->all();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->data->all();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+10
-14
@@ -1,14 +1,10 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$allowedHost = array(
|
$allowedHost = array(
|
||||||
"localhost",
|
"localhost",
|
||||||
"denisnotebook",
|
"app.gruppolapastamadre.it",
|
||||||
"app.gruppolapastamadre.it",
|
"dev.gruppolapastamadre.it",
|
||||||
"dev.gruppolapastamadre.it",
|
"management.gruppolapastamadre.it"
|
||||||
"blog.gruppolapastamadre.it",
|
);
|
||||||
"management.gruppolapastamadre.it"
|
|
||||||
);
|
$dirRicetteDropBox = "IlLievitario/Images/Ricette";
|
||||||
|
|
||||||
$dirRicetteDropBox = "IlLievitario/Images/Ricette";
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|||||||
@@ -3,95 +3,156 @@
|
|||||||
// inclusione del file contenente la classe
|
// inclusione del file contenente la classe
|
||||||
require_once "./include.php";
|
require_once "./include.php";
|
||||||
require_once "./myDropBoxObj.php";
|
require_once "./myDropBoxObj.php";
|
||||||
|
|
||||||
|
use PHPImageWorkshop\ImageWorkshop;
|
||||||
|
|
||||||
|
require_once 'PHPImageWorkshop/ImageWorkshop.php'; // Be sure of the path to the class
|
||||||
//include "./SimpleImage.php";
|
//include "./SimpleImage.php";
|
||||||
|
|
||||||
$app->get('/photo/thumbnail/:imageID(/:noRedirect)', function ($imageID, $noRedirect = 0) use ($app, $dirRicetteDropBox) {
|
$app->get('/photos/thumbnail/:imageID(/:createImgTag)', function ($imageID, $createImgTag = 0) use ($app, $dirRicetteDropBox) {
|
||||||
$mysqlconnetion = new MysqlClass;
|
$mysqlconnetion = new MysqlClass;
|
||||||
|
|
||||||
$retObj = $mysqlconnetion->queryToObject("select type_format, id_ricette, thumb_link from immagini where id=" . $imageID, false);
|
$retObj = $mysqlconnetion->queryToObject("select type_format, id_ricette from immagini where id=" . $imageID, false);
|
||||||
$mysqlconnetion->disconnetti();
|
$mysqlconnetion->disconnetti();
|
||||||
|
|
||||||
|
$ext = "";
|
||||||
$ext = "png";
|
if ($retObj["type_format"] == "image/jpeg") {
|
||||||
|
$ext = "jpg";
|
||||||
|
} else if ($retObj["type_format"] == "image/png") {
|
||||||
|
$ext = "png";
|
||||||
|
}
|
||||||
|
|
||||||
|
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
||||||
|
|
||||||
|
$imageFileName = $imageID . "_thumb_ricetta." . $ext;
|
||||||
|
|
||||||
|
$dropBoxObj = new myDropBox();
|
||||||
|
|
||||||
|
if ($createImgTag) {
|
||||||
|
echo '<img src="';
|
||||||
|
}
|
||||||
|
echo $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
||||||
|
if ($createImgTag) {
|
||||||
|
echo '"/>';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$app->get('/photos/:imageID(/:createImgTag)', function ($imageID, $createImgTag = 0) use ($app, $dirRicetteDropBox) {
|
||||||
|
$mysqlconnetion = new MysqlClass;
|
||||||
|
|
||||||
|
$retObj = $mysqlconnetion->queryToObject("select type_format, id_ricette from immagini where id=" . $imageID, false);
|
||||||
|
$mysqlconnetion->disconnetti();
|
||||||
|
$ext = "";
|
||||||
|
if ($retObj["type_format"] == "image/jpeg") {
|
||||||
|
$ext = "jpg";
|
||||||
|
} else if ($retObj["type_format"] == "image/png") {
|
||||||
|
$ext = "png";
|
||||||
|
}
|
||||||
|
|
||||||
|
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
||||||
|
|
||||||
|
$imageFileName = $imageID . "_full_ricetta." . $ext;
|
||||||
|
|
||||||
|
$dropBoxObj = new myDropBox();
|
||||||
|
|
||||||
|
if ($createImgTag) {
|
||||||
|
echo '<img src="';
|
||||||
|
}
|
||||||
|
echo $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
||||||
|
if ($createImgTag) {
|
||||||
|
echo '"/>';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$app->put('/photos/publish/:imageID', function ($imageID) use ($app) {
|
||||||
|
$mysqlconnetion = new MysqlClass;
|
||||||
|
|
||||||
|
$query = "update immagini set published = 1, published_date = NOW() where id = " . $imageID;
|
||||||
|
|
||||||
|
$mysqlconnetion->insertRecord($query);
|
||||||
|
$mysqlconnetion->disconnetti();
|
||||||
|
});
|
||||||
|
|
||||||
|
$app->post('/photos', function () use ($app, $dirRicetteDropBox) {
|
||||||
|
$idRicette = $app->request()->post('ricetta_id');
|
||||||
|
$profileID = $app->request()->post('keyStore');
|
||||||
|
$tmpFileName = $_FILES['image']["tmp_name"];
|
||||||
|
$layer = ImageWorkshop::initFromPath($tmpFileName);
|
||||||
|
// istanza della classe
|
||||||
|
$mysqlconnetion = new MysqlClass;
|
||||||
|
//$mysqlconneti on->connetti();
|
||||||
|
$query = "insert into immagini(id_ricette, type_format, from_profile_id, uploaded_date) " .
|
||||||
|
"values(" . $idRicette . ", '" . image_type_to_mime_type(exif_imagetype($tmpFileName)) .
|
||||||
|
"', '" . $profileID . "', NOW())";
|
||||||
|
$newID = $mysqlconnetion->insertRecord($query);
|
||||||
|
$ext = image_type_to_extension(exif_imagetype($tmpFileName), FALSE);
|
||||||
|
|
||||||
|
$imageFileName = $newID . "_full_ricetta." . $ext;
|
||||||
|
|
||||||
|
$thumbFileName = $newID . "_thumb_ricetta." . $ext;
|
||||||
|
|
||||||
$retLink = $retObj["thumb_link"];
|
$layer->resizeByLargestSideInPixel(640, true);
|
||||||
|
|
||||||
|
$layer->save(dirname($tmpFileName), $imageFileName);
|
||||||
|
|
||||||
|
$layer->resizeByLargestSideInPixel(300, true);
|
||||||
|
|
||||||
|
$layer->save(dirname($tmpFileName), $thumbFileName);
|
||||||
|
|
||||||
|
$dropBoxObj = new myDropBox();
|
||||||
|
|
||||||
|
$folder = $dirRicetteDropBox . "/" . $idRicette;
|
||||||
|
|
||||||
|
try {
|
||||||
|
$dropBoxObj->CreateFolder($folder);
|
||||||
|
} catch (DropboxException $ex) {
|
||||||
|
|
||||||
if($retLink == ""){
|
|
||||||
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
|
||||||
|
|
||||||
$imageFileName = $imageID . "_thumb_ricetta." . $ext;
|
|
||||||
|
|
||||||
$dropBoxObj = new myDropBox();
|
|
||||||
|
|
||||||
$retLink = $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
|
||||||
}
|
}
|
||||||
|
$fullPath = dirname($tmpFileName) . "/" . $imageFileName;
|
||||||
|
echo $fullPath . "\n";
|
||||||
|
$thumbPath = dirname($tmpFileName) . "/" . $thumbFileName;
|
||||||
|
echo $thumbPath . "\n";
|
||||||
|
$dropBoxObj->UploadFile($fullPath, $folder . "/" . $imageFileName);
|
||||||
|
|
||||||
if ($noRedirect) {
|
$dropBoxObj->UploadFile($thumbPath, $folder . "/" . $thumbFileName);
|
||||||
echo $retLink;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$app->response->redirect($retLink, 303);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$app->get('/photo/medium/:imageID(/:noRedirect)', function ($imageID, $noRedirect = 0) use ($app, $dirRicetteDropBox) {
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
|
|
||||||
$retObj = $mysqlconnetion->queryToObject("select type_format, id_ricette, medium_link from immagini where id=" . $imageID, false);
|
|
||||||
$mysqlconnetion->disconnetti();
|
$mysqlconnetion->disconnetti();
|
||||||
$ext = "";
|
|
||||||
if ($retObj["type_format"] == "image/jpeg") {
|
|
||||||
$ext = "jpeg";
|
|
||||||
} else if ($retObj["type_format"] == "image/png") {
|
|
||||||
$ext = "png";
|
|
||||||
}
|
|
||||||
|
|
||||||
$retLink = $retObj["medium_link"];
|
echo $newID;
|
||||||
|
|
||||||
if($retLink == ""){
|
|
||||||
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
|
||||||
|
|
||||||
$imageFileName = $imageID . "_medium_ricetta." . $ext;
|
|
||||||
|
|
||||||
$dropBoxObj = new myDropBox();
|
|
||||||
|
|
||||||
$retLink = $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($noRedirect) {
|
|
||||||
echo $retLink;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$app->response->redirect($retLink, 303);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
$app->get('/photo/:imageID(/:noRedirect)', function ($imageID, $noRedirect = 0) use ($app, $dirRicetteDropBox) {
|
$app->put('/photos/:imageID', function ($imageID) use ($app, $dirRicetteDropBox) {
|
||||||
|
$tmpFileName = $_FILES['image']["tmp_name"];
|
||||||
|
$layer = ImageWorkshop::initFromPath($tmpFileName);
|
||||||
|
// istanza della classe
|
||||||
$mysqlconnetion = new MysqlClass;
|
$mysqlconnetion = new MysqlClass;
|
||||||
|
//$mysqlconneti on->connetti();
|
||||||
|
$query = "update immagini set (type_format = '" . image_type_to_mime_type(exif_imagetype($tmpFileName)) . "', " .
|
||||||
|
" where id=" . $imageID;
|
||||||
|
|
||||||
|
$newID = $mysqlconnetion->insertRecord($query);
|
||||||
|
|
||||||
|
$imageFileName = $imageID . "_full_ricetta";
|
||||||
|
|
||||||
|
$thumbFileName = $imageID . "_thumb_ricetta";
|
||||||
|
|
||||||
|
$layer->resizeByLargestSideInPixel(640, true);
|
||||||
|
|
||||||
|
$layer->save(dirname($tmpFileName), $imageFileName);
|
||||||
|
|
||||||
|
$layer->resizeByLargestSideInPixel(300, true);
|
||||||
|
|
||||||
|
$layer->save(dirname($tmpFileName), $thumbFileName);
|
||||||
|
|
||||||
|
$dropBoxObj = new myDropBox();
|
||||||
|
|
||||||
|
$folder = $dirRicetteDropBox . "/" . $idRicette;
|
||||||
|
|
||||||
|
$dropBoxObj->UploadFile(dirname($tmpFileName) . DIRECTORY_SEPARATOR . $imageFileName, $folder . "\\" . $imageFileName);
|
||||||
|
|
||||||
|
$dropBoxObj->UploadFile(dirname($tmpFileName) . DIRECTORY_SEPARATOR . $thumbFileName, $folder . "\\" . $thumbFileName);
|
||||||
|
|
||||||
$retObj = $mysqlconnetion->queryToObject("select type_format, id_ricette, full_link from immagini where id=" . $imageID, false);
|
|
||||||
$mysqlconnetion->disconnetti();
|
$mysqlconnetion->disconnetti();
|
||||||
$ext = "";
|
|
||||||
if ($retObj["type_format"] == "image/jpeg") {
|
|
||||||
$ext = "jpeg";
|
|
||||||
} else if ($retObj["type_format"] == "image/png") {
|
|
||||||
$ext = "png";
|
|
||||||
}
|
|
||||||
|
|
||||||
$retLink = $retObj["full_link"];
|
return $newID;
|
||||||
|
|
||||||
if($retLink == ""){
|
|
||||||
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
|
||||||
|
|
||||||
$imageFileName = $imageID . "_full_ricetta." . $ext;
|
|
||||||
|
|
||||||
$dropBoxObj = new myDropBox();
|
|
||||||
|
|
||||||
$retLink = $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($noRedirect) {
|
|
||||||
echo $retLink;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$app->response->redirect($retLink, 303);
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,182 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// inclusione del file contenente la classe
|
|
||||||
require_once "./include.php";
|
|
||||||
require_once "./myDropBoxObj.php";
|
|
||||||
|
|
||||||
use PHPImageWorkshop\ImageWorkshop;
|
|
||||||
|
|
||||||
require_once 'PHPImageWorkshop/ImageWorkshop.php'; // Be sure of the path to the class
|
|
||||||
//include "./SimpleImage.php";
|
|
||||||
|
|
||||||
$app->get('/photo/publish/:imageID', function ($imageID) use ($app) {
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
|
|
||||||
$query = "update immagini set published = 1, published_date = NOW() where id = " . $imageID;
|
|
||||||
|
|
||||||
$mysqlconnetion->insertRecord($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->delete('/photo/:imageID', function ($imageID) use ($app,$dirRicetteDropBox) {
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
|
|
||||||
$query = "select id_ricette, type_format from immagini where id = " . $imageID;
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query, false);
|
|
||||||
|
|
||||||
$ext = "";
|
|
||||||
if ($retObj["type_format"] == "image/jpeg") {
|
|
||||||
$ext = "jpeg";
|
|
||||||
} else if ($retObj["type_format"] == "image/png") {
|
|
||||||
$ext = "png";
|
|
||||||
}
|
|
||||||
|
|
||||||
$dropBoxObj = new myDropBox();
|
|
||||||
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
|
||||||
$imageFileName = $imageID . "_full_ricetta." . $ext;
|
|
||||||
$dropBoxObj->Delete($folder . "/" . $imageFileName);
|
|
||||||
|
|
||||||
$imageFileName = $imageID . "_medium_ricetta." . $ext;
|
|
||||||
$dropBoxObj->Delete($folder . "/" . $imageFileName);
|
|
||||||
|
|
||||||
$imageFileName = $imageID . "_thumb_ricetta." . $ext;
|
|
||||||
$dropBoxObj->Delete($folder . "/" . $imageFileName);
|
|
||||||
|
|
||||||
$query = "delete from immagini where id = " . $imageID;
|
|
||||||
$mysqlconnetion->executeQuery($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->post('/photo', function () use ($app, $dirRicetteDropBox) {
|
|
||||||
$idRicette = $app->request()->post('ricetta_id');
|
|
||||||
$profileID = $app->request()->post('keyStore');
|
|
||||||
$tmpFileName = $_FILES['image']["tmp_name"];
|
|
||||||
$layer = ImageWorkshop::initFromPath($tmpFileName);
|
|
||||||
// istanza della classe
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
//$mysqlconneti on->connetti();
|
|
||||||
$query = "insert into immagini(id_ricette, type_format, from_profile_id, uploaded_date) " .
|
|
||||||
"values(" . $idRicette . ", '" . image_type_to_mime_type(exif_imagetype($tmpFileName)) .
|
|
||||||
"', '" . $profileID . "', NOW())";
|
|
||||||
$newID = $mysqlconnetion->insertRecord($query);
|
|
||||||
$ext = image_type_to_extension(exif_imagetype($tmpFileName), FALSE);
|
|
||||||
|
|
||||||
$folder = $dirRicetteDropBox . "/" . $idRicette;
|
|
||||||
$imageFileName = $newID . "_full_ricetta." . $ext;
|
|
||||||
|
|
||||||
$dropBoxObj = new myDropBox();
|
|
||||||
|
|
||||||
$full_link = resizeImage($dropBoxObj, $layer, 640, dirname($tmpFileName), $imageFileName, $folder);
|
|
||||||
|
|
||||||
$imageMediumFileName = $newID . "_medium_ricetta." . $ext;
|
|
||||||
|
|
||||||
$medium_link = resizeImage($dropBoxObj, $layer, 320, dirname($tmpFileName), $imageMediumFileName, $folder);
|
|
||||||
|
|
||||||
$thumbFileName = $newID . "_thumb_ricetta." . $ext;
|
|
||||||
|
|
||||||
$thumb_link = makeThumbImage($dropBoxObj, $layer, 80, dirname($tmpFileName), $thumbFileName, $folder);
|
|
||||||
|
|
||||||
$query = "update immagini set (thumb_link = '" . $thumb_link . "', medium_link ='" . $medium_link . "', full_link = '" . $full_link ."' )" .
|
|
||||||
" where id=" . $newID;
|
|
||||||
|
|
||||||
$newID = $mysqlconnetion->insertRecord($query);
|
|
||||||
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
echo $newID;
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->put('/photo/:imageID', function ($imageID) use ($app, $dirRicetteDropBox) {
|
|
||||||
$tmpFileName = $_FILES['image']["tmp_name"];
|
|
||||||
$layer = ImageWorkshop::initFromPath($tmpFileName);
|
|
||||||
// istanza della classe
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
//$mysqlconneti on->connetti();
|
|
||||||
|
|
||||||
$folder = $dirRicetteDropBox . "/" . $imageID;
|
|
||||||
$imageFileName = $imageID . "_full_ricetta." . $ext;
|
|
||||||
|
|
||||||
$full_link = resizeImage($dropBoxObj, $layer, 640, dirname($tmpFileName), $imageFileName, $folder);
|
|
||||||
|
|
||||||
$imageMediumFileName = $imageID . "_medium_ricetta." . $ext;
|
|
||||||
|
|
||||||
$medium_link = resizeImage($dropBoxObj, $layer, 320, dirname($tmpFileName), $imageMediumFileName, $folder);
|
|
||||||
|
|
||||||
$thumbFileName = $imageID . "_thumb_ricetta." . $ext;
|
|
||||||
|
|
||||||
$thumb_link = makeThumbImage($dropBoxObj, $layer, 80, dirname($tmpFileName), $thumbFileName, $folder);
|
|
||||||
|
|
||||||
$query = "update immagini set (type_format = '" . image_type_to_mime_type(exif_imagetype($tmpFileName)) .
|
|
||||||
"', thumb_link = '" . $thumb_link . "', medium_link ='" . $medium_link . "', full_link = '" . $full_link ."' )" .
|
|
||||||
" where id=" . $imageID;
|
|
||||||
|
|
||||||
$newID = $mysqlconnetion->insertRecord($query);
|
|
||||||
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
return $newID;
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/photo/fixLink', function () use ($app, $dirRicetteDropBox) {
|
|
||||||
ini_set('max_execution_time', 3000);
|
|
||||||
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
|
|
||||||
$retObj2 = $mysqlconnetion->queryToObject("select type_format, id, id_ricette, thumb_link, medium_link, full_link from immagini where published = 1");
|
|
||||||
|
|
||||||
|
|
||||||
foreach ($retObj2 as $retObj) {
|
|
||||||
|
|
||||||
$imageID = $retObj["id"];
|
|
||||||
|
|
||||||
$ext = "";
|
|
||||||
if ($retObj["type_format"] == "image/jpeg") {
|
|
||||||
$ext = "jpeg";
|
|
||||||
} else if ($retObj["type_format"] == "image/png") {
|
|
||||||
$ext = "png";
|
|
||||||
}
|
|
||||||
|
|
||||||
$full_link = $retObj["full_link"];
|
|
||||||
|
|
||||||
if($full_link == ""){
|
|
||||||
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
|
||||||
|
|
||||||
$imageFileName = $imageID . "_full_ricetta." . $ext;
|
|
||||||
|
|
||||||
$dropBoxObj = new myDropBox();
|
|
||||||
|
|
||||||
$full_link = $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
$medium_link = $retObj["medium_link"];
|
|
||||||
|
|
||||||
if($medium_link == ""){
|
|
||||||
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
|
||||||
|
|
||||||
$imageFileName = $imageID . "_medium_ricetta." . $ext;
|
|
||||||
|
|
||||||
$dropBoxObj = new myDropBox();
|
|
||||||
|
|
||||||
$medium_link = $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
$thumb_link = $retObj["thumb_link"];
|
|
||||||
|
|
||||||
if($thumb_link == ""){
|
|
||||||
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
|
||||||
|
|
||||||
$imageFileName = $imageID . "_thumb_ricetta.png";
|
|
||||||
|
|
||||||
$dropBoxObj = new myDropBox();
|
|
||||||
|
|
||||||
$thumb_link = $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = "update immagini set thumb_link = '" . $thumb_link . "', medium_link ='" . $medium_link . "', full_link = '" . $full_link ."'" .
|
|
||||||
" where id=" . $imageID;
|
|
||||||
|
|
||||||
$newID = $mysqlconnetion->insertRecord($query);
|
|
||||||
}
|
|
||||||
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
});
|
|
||||||
+1
-8
@@ -12,10 +12,8 @@ require_once 'Slim/Slim.php';
|
|||||||
|
|
||||||
$app = new \Slim\Slim();
|
$app = new \Slim\Slim();
|
||||||
|
|
||||||
date_default_timezone_set('Europe/Rome');
|
|
||||||
|
|
||||||
$app->hook('slim.before.router', function () use ($app, $allowedHost) {
|
$app->hook('slim.before.router', function () use ($app, $allowedHost) {
|
||||||
/*$currentRefererRequest = $app->request()->getReferer();
|
$currentRefererRequest = $app->request()->getReferer();
|
||||||
$currentRefererRequest = substr($currentRefererRequest, 7); //Senza http://
|
$currentRefererRequest = substr($currentRefererRequest, 7); //Senza http://
|
||||||
$indexDoublePoint = strpos($currentRefererRequest, ':');
|
$indexDoublePoint = strpos($currentRefererRequest, ':');
|
||||||
$indexFirstSlash = strpos($currentRefererRequest, '/');
|
$indexFirstSlash = strpos($currentRefererRequest, '/');
|
||||||
@@ -23,18 +21,13 @@ $app->hook('slim.before.router', function () use ($app, $allowedHost) {
|
|||||||
if(!in_array($currentRefererRequest, $allowedHost))
|
if(!in_array($currentRefererRequest, $allowedHost))
|
||||||
{
|
{
|
||||||
$app->halt(500, "Generic error occurred");
|
$app->halt(500, "Generic error occurred");
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$currentHostRequest = $app->request()->getHost();
|
$currentHostRequest = $app->request()->getHost();
|
||||||
if(!in_array($currentHostRequest, $allowedHost))
|
if(!in_array($currentHostRequest, $allowedHost))
|
||||||
{
|
{
|
||||||
$app->halt(403, "Request arrive from host not allowed " . $currentHostRequest );
|
$app->halt(403, "Request arrive from host not allowed " . $currentHostRequest );
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
if(isset($_SERVER['HTTP_ORIGIN']))
|
|
||||||
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+164
-250
@@ -1,251 +1,165 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$app->get('/categories', function () use ($app) {
|
$app->get('/categories', function () use ($app) {
|
||||||
$callbackFn = $app->request()->get('callback');
|
$callbackFn = $app->request()->get('callback');
|
||||||
$mysqlconnetion = new MysqlClass;
|
$mysqlconnetion = new MysqlClass;
|
||||||
//$mysqlconneti on->connetti();
|
//$mysqlconneti on->connetti();
|
||||||
$retObj = $mysqlconnetion->queryToObject("select ID as category_id, NAME as name from categorie order by name");
|
$retObj = $mysqlconnetion->queryToObject("select ID as category_id, NAME as name from categorie order by name");
|
||||||
$mysqlconnetion->disconnetti();
|
$mysqlconnetion->disconnetti();
|
||||||
|
|
||||||
returnJsonWithDecode($app, $callbackFn, $retObj);
|
returnJsonWithDecode($app, $callbackFn, $retObj);
|
||||||
});
|
});
|
||||||
|
|
||||||
$app->get('/typeingredients', function () use ($app) {
|
$app->get('/typeingredients', function () use ($app) {
|
||||||
$callbackFn = $app->request()->get('callback');
|
$callbackFn = $app->request()->get('callback');
|
||||||
$mysqlconnetion = new MysqlClass;
|
$mysqlconnetion = new MysqlClass;
|
||||||
//$mysqlconnetion->connetti();
|
//$mysqlconnetion->connetti();
|
||||||
$retObj = $mysqlconnetion->queryToObject("select ID as tipo_ingredienti_id, name from tipo_ingredienti order by name");
|
$retObj = $mysqlconnetion->queryToObject("select ID as tipo_ingredienti_id, name from tipo_ingredienti order by name");
|
||||||
$mysqlconnetion->disconnetti();
|
$mysqlconnetion->disconnetti();
|
||||||
|
|
||||||
returnJsonWithDecode($app, $callbackFn, $retObj);
|
returnJsonWithDecode($app, $callbackFn, $retObj);
|
||||||
});
|
});
|
||||||
|
|
||||||
$app->get('/typeqtys', function () use ($app) {
|
$app->get('/typeqtys', function () use ($app) {
|
||||||
$callbackFn = $app->request()->get('callback');
|
$callbackFn = $app->request()->get('callback');
|
||||||
$mysqlconnetion = new MysqlClass;
|
$mysqlconnetion = new MysqlClass;
|
||||||
//$mysqlconnetion->connetti();
|
//$mysqlconnetion->connetti();
|
||||||
$retObj = $mysqlconnetion->queryToObject("select ID as tipo_quantita_id, name from tipo_quantita");
|
$retObj = $mysqlconnetion->queryToObject("select ID as tipo_quantita_id, name from tipo_quantita");
|
||||||
$mysqlconnetion->disconnetti();
|
$mysqlconnetion->disconnetti();
|
||||||
|
|
||||||
returnJsonWithDecode($app, $callbackFn, $retObj);
|
returnJsonWithDecode($app, $callbackFn, $retObj);
|
||||||
});
|
});
|
||||||
|
|
||||||
$app->get('/ricette/:catID', function ($categoryID) use ($app) {
|
$app->get('/ricette/:catID', function ($categoryID) use ($app) {
|
||||||
$callbackFn = $app->request()->get('callback');
|
$callbackFn = $app->request()->get('callback');
|
||||||
$mysqlconnetion = new MysqlClass;
|
$mysqlconnetion = new MysqlClass;
|
||||||
//$mysqlconnetion->connetti();
|
//$mysqlconnetion->connetti();
|
||||||
$query = "select ID as ricetta_id, titolo, autore, valutazione, difficolta from ricette where ID_CATEGORIA = " . $categoryID . " order by titolo, autore";
|
$query = "select ID as ricetta_id, titolo, autore, valutazione, difficolta from ricette where ID_CATEGORIA = " . $categoryID . " order by titolo, autore";
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
$retObj = $mysqlconnetion->queryToObject($query);
|
||||||
$mysqlconnetion->disconnetti();
|
$mysqlconnetion->disconnetti();
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
returnJson($app, $callbackFn, $retObj);
|
||||||
});
|
});
|
||||||
|
|
||||||
$app->get('/ricetta/body/:itemID', function ($itemID) use ($app) {
|
$app->get('/ricetta/body/:itemID', function ($itemID) use ($app) {
|
||||||
$callbackFn = $app->request()->get('callback');
|
$callbackFn = $app->request()->get('callback');
|
||||||
// istanza della classe
|
// istanza della classe
|
||||||
$mysqlconnetion = new MysqlClass;
|
$mysqlconnetion = new MysqlClass;
|
||||||
$query = "SELECT id_categoria, categorie.name AS categoria_name, ricette.ID AS ricetta_id, titolo, procedimento, autore, link_fonte, link_youtube, valutazione, difficolta FROM ricette INNER JOIN categorie ON categorie.ID = ricette.id_categoria WHERE ricette.ID = " . $itemID;
|
$query = "SELECT id_categoria, categorie.name AS categoria_name, ricette.ID AS ricetta_id, titolo, procedimento, autore, link_fonte, link_youtube, valutazione, difficolta FROM ricette INNER JOIN categorie ON categorie.ID = ricette.id_categoria WHERE ricette.ID = " . $itemID;
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
$retObj = $mysqlconnetion->queryToObject($query);
|
||||||
|
|
||||||
$query2 = "select ingredienti.id_tipo_ingredienti, tipo_ingredienti.name as nome_ingrediente, quantita, ingredienti.id_tipo_quantita, tipo_quantita.Name as unita, note, posizione from ingredienti " .
|
$query2 = "select ingredienti.id_tipo_ingredienti, tipo_ingredienti.name as nome_ingrediente, quantita, ingredienti.id_tipo_quantita, tipo_quantita.Name as unita, note, posizione from ingredienti " .
|
||||||
"inner join tipo_ingredienti on ingredienti.ID_TIPO_INGREDIENTI = tipo_ingredienti.ID " .
|
"inner join tipo_ingredienti on ingredienti.ID_TIPO_INGREDIENTI = tipo_ingredienti.ID " .
|
||||||
"left outer join tipo_quantita on ingredienti.ID_TIPO_QUANTITA = tipo_quantita.ID " .
|
"left outer join tipo_quantita on ingredienti.ID_TIPO_QUANTITA = tipo_quantita.ID " .
|
||||||
"where ingredienti.ID_RICETTE = " . $itemID . " order by ingredienti.posizione";
|
"where ingredienti.ID_RICETTE = " . $itemID . " order by ingredienti.posizione";
|
||||||
|
|
||||||
$retObj2 = $mysqlconnetion->queryToObject($query2);
|
$retObj2 = $mysqlconnetion->queryToObject($query2);
|
||||||
|
|
||||||
foreach ($retObj2 as $ele) {
|
$retObj[0]["titolo"] = html_entity_decode($retObj[0]["titolo"],ENT_COMPAT | ENT_HTML401,'ISO-8859-1');
|
||||||
$ele["note"] = html_entity_decode($ele["note"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
$retObj[0]["procedimento"] = html_entity_decode($retObj[0]["procedimento"],ENT_COMPAT | ENT_HTML401,'ISO-8859-1');
|
||||||
}
|
$retObj[0]["ingredienti"] = $retObj2;
|
||||||
|
|
||||||
$retObj[0]["titolo"] = html_entity_decode($retObj[0]["titolo"],ENT_COMPAT | ENT_HTML401,'ISO-8859-1');
|
$mysqlconnetion->disconnetti();
|
||||||
$retObj[0]["procedimento"] = html_entity_decode($retObj[0]["procedimento"],ENT_COMPAT | ENT_HTML401,'ISO-8859-1');
|
returnJson($app, $callbackFn, $retObj);
|
||||||
$retObj[0]["ingredienti"] = $retObj2;
|
});
|
||||||
|
|
||||||
$mysqlconnetion->disconnetti();
|
$app->post('/typeingredients', function () use ($app) {
|
||||||
returnJson($app, $callbackFn, $retObj);
|
$callbackFn = $app->request()->get('callback');
|
||||||
});
|
$json_data_body = json_decode($app->request()->post('bodydata'));
|
||||||
|
$mysqlconnetion = new MysqlClass;
|
||||||
$app->post('/typeingredients', function () use ($app) {
|
//$mysqlconnetion->connetti();
|
||||||
$callbackFn = $app->request()->get('callback');
|
$query = "insert into tipo_ingredienti(Name) values ('" . $json_data_body->name . "')";
|
||||||
$json_data_body = json_decode($app->request()->post('bodydata'));
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
$retNewID = $mysqlconnetion->insertRecord($query);
|
||||||
//$mysqlconnetion->connetti();
|
$mysqlconnetion->disconnetti();
|
||||||
$query = "insert into tipo_ingredienti(Name) values ('" . $json_data_body->name . "')";
|
|
||||||
|
returnJson($app, $callbackFn, $retNewID);
|
||||||
$retNewID = $mysqlconnetion->insertRecord($query);
|
});
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
$app->post('/ricetta/body', function () use ($app) {
|
||||||
returnJson($app, $callbackFn, $retNewID);
|
$callbackFn = $app->request()->get('callback');
|
||||||
});
|
$json_data_body = json_decode($app->request()->post('bodydata'));
|
||||||
|
$retValue["result"] = true;
|
||||||
$app->post('/ricetta/body', function () use ($app) {
|
$retValue["message"] = "";
|
||||||
$callbackFn = $app->request()->get('callback');
|
$mysqlconnetion = new MysqlClass;
|
||||||
$json_data_body = json_decode($app->request()->post('bodydata'));
|
// istanza della classe
|
||||||
$retValue["result"] = true;
|
try {
|
||||||
$retValue["message"] = "";
|
$retNewID = 0;
|
||||||
$mysqlconnetion = new MysqlClass;
|
if ($json_data_body->ricettaID != "") {
|
||||||
// istanza della classe
|
$query = "update ricette SET ID_CATEGORIA = " . $json_data_body->categoria_id .
|
||||||
try {
|
", titolo = '" . htmlentities($json_data_body->titolo, null, "UTF-8") .
|
||||||
$retNewID = 0;
|
"', procedimento = '" . str_replace("'", "''", htmlentities($json_data_body->preparazione, null, "UTF-8")) .
|
||||||
if ($json_data_body->ricettaID != "") {
|
"', autore = '" . str_replace("'", "''", $json_data_body->autore) .
|
||||||
$query = "update ricette SET ID_CATEGORIA = " . $json_data_body->categoria_id .
|
"', link_fonte = '" . $json_data_body->linkFonte .
|
||||||
", titolo = '" . htmlentities($json_data_body->titolo, null, "UTF-8") .
|
"', Link_youtube = '" . $json_data_body->linkVideo .
|
||||||
"', procedimento = '" . str_replace("'", "''", htmlentities($json_data_body->preparazione, null, "UTF-8")) .
|
"', Difficolta = '" . $json_data_body->difficolta .
|
||||||
"', autore = '" . str_replace("'", "''", $json_data_body->autore) .
|
"' where ID = " . $json_data_body->ricettaID;
|
||||||
"', link_fonte = '" . $json_data_body->linkFonte .
|
|
||||||
"', Link_youtube = '" . $json_data_body->linkVideo .
|
$mysqlconnetion->executeQuery($query);
|
||||||
"', Difficolta = '" . $json_data_body->difficolta .
|
$queryDelete = "DELETE FROM ingredienti where ID_RICETTE = " . $json_data_body->ricettaID;
|
||||||
"' where ID = " . $json_data_body->ricettaID;
|
$mysqlconnetion->executeQuery($queryDelete);
|
||||||
|
$retNewID = $json_data_body->ricettaID;
|
||||||
$mysqlconnetion->executeQuery($query);
|
} else {
|
||||||
$queryDelete = "DELETE FROM ingredienti where ID_RICETTE = " . $json_data_body->ricettaID;
|
|
||||||
$mysqlconnetion->executeQuery($queryDelete);
|
$query = "insert into ricette(ID_CATEGORIA, titolo, procedimento, autore, link_fonte, Link_youtube,Difficolta) values (" .
|
||||||
|
$json_data_body->categoria_id . ",'" . htmlentities($json_data_body->titolo, null, "UTF-8") . "','" . str_replace("'", "''", htmlentities($json_data_body->preparazione, null, "UTF-8")) .
|
||||||
$queryUpdDataMod = "UPDATE ricette SET data_modifica = NOW() where ID = " . $json_data_body->ricettaID;
|
"','" . str_replace("'", "''", $json_data_body->autore) . "','" .
|
||||||
$mysqlconnetion->executeQuery($queryUpdDataMod);
|
$json_data_body->linkFonte . "','" . $json_data_body->linkVideo . "', " . $json_data_body->difficolta . ")";
|
||||||
|
|
||||||
$retNewID = $json_data_body->ricettaID;
|
$retNewID = $mysqlconnetion->insertRecord($query);
|
||||||
} else {
|
}
|
||||||
|
|
||||||
$query = "insert into ricette(ID_CATEGORIA, titolo, procedimento, autore, link_fonte, Link_youtube,Difficolta) values (" .
|
$pos = 0;
|
||||||
$json_data_body->categoria_id . ",'" . htmlentities($json_data_body->titolo, null, "UTF-8") . "','" . str_replace("'", "''", htmlentities($json_data_body->preparazione, null, "UTF-8")) .
|
foreach ($json_data_body->ingredienti as $arr) {
|
||||||
"','" . str_replace("'", "''", $json_data_body->autore) . "','" .
|
$note = "";
|
||||||
$json_data_body->linkFonte . "','" . $json_data_body->linkVideo . "', " . $json_data_body->difficolta . ")";
|
if ($arr->note != "") {
|
||||||
|
$note = str_replace("'", "''", htmlentities($arr->note));
|
||||||
$retNewID = $mysqlconnetion->insertRecord($query);
|
}
|
||||||
}
|
|
||||||
|
$query = "insert into ingredienti(ID_TIPO_INGREDIENTI, ID_RICETTE, Quantita, ID_TIPO_QUANTITA, Note, Posizione) values (" .
|
||||||
$pos = 0;
|
$arr->ingrediente_id . "," . $retNewID . "," . ($arr->quantita == "" ? "0" : $arr->quantita) . "," . ($arr->tipo_quantita_id == "" ? "NULL" : $arr->tipo_quantita_id) . ",'" . $note . "'," . $pos . ")";
|
||||||
foreach ($json_data_body->ingredienti as $arr) {
|
|
||||||
$note = "";
|
$mysqlconnetion->insertRecord($query);
|
||||||
if ($arr->note != "") {
|
$pos = $pos + 1;
|
||||||
$note = str_replace("'", "''", htmlentities($arr->note, null, "UTF-8"));
|
}
|
||||||
}
|
|
||||||
|
$retValue["message"] = "Ricetta inserita con successo";
|
||||||
$query = "insert into ingredienti(ID_TIPO_INGREDIENTI, ID_RICETTE, Quantita, ID_TIPO_QUANTITA, Note, Posizione) values (" .
|
} catch (Exception $e) {
|
||||||
$arr->ingrediente_id . "," . $retNewID . ",'" . ($arr->quantita == "" ? "0" : $arr->quantita) . "'," . ($arr->tipo_quantita_id == "" ? "NULL" : $arr->tipo_quantita_id) . ",'" . $note . "'," . $pos . ")";
|
$retValue["message"] = $e->getMessage();
|
||||||
|
}
|
||||||
$mysqlconnetion->insertRecord($query);
|
|
||||||
$pos = $pos + 1;
|
$mysqlconnetion->disconnetti();
|
||||||
}
|
|
||||||
|
returnJson($app, $callbackFn, $retValue);
|
||||||
$retValue["ricettaID"] = $retNewID;
|
});
|
||||||
$retValue["message"] = "Ricetta inserita con successo";
|
|
||||||
} catch (Exception $e) {
|
$app->get('/photos/', function () use ($app) {
|
||||||
$retValue["result"] = false;
|
$callbackFn = $app->request()->get('callback');
|
||||||
$retValue["message"] = $e->getMessage();
|
|
||||||
}
|
$query = "SELECT * from ( SELECT id as ricetta_id, `titolo`,`autore`, ".
|
||||||
|
" (select COUNT(*) from immagini where immagini.id_ricette = `ricette`.id) as num_img,".
|
||||||
$mysqlconnetion->disconnetti();
|
" (select COUNT(*) from immagini where immagini.id_ricette = `ricette`.id and immagini.published = 1) as num_img_pub".
|
||||||
|
" FROM `ricette`".
|
||||||
returnJson($app, $callbackFn, $retValue);
|
" ) as tmp".
|
||||||
});
|
" WHERE tmp.num_img> 0";
|
||||||
|
|
||||||
$app->delete('/ricetta/:itemID', function ($itemID) use ($app) {
|
$mysqlconnetion = new MysqlClass;
|
||||||
$callbackFn = $app->request()->get('callback');
|
//$mysqlconnetion->connetti();
|
||||||
$retValue["result"] = true;
|
$retObj = $mysqlconnetion->queryToObject($query);
|
||||||
$retValue["message"] = "";
|
$mysqlconnetion->disconnetti();
|
||||||
$mysqlconnetion = new MysqlClass;
|
returnJson($app, $callbackFn, $retObj);
|
||||||
try {
|
});
|
||||||
$queryDelete = "DELETE FROM immagini where id_ricette = " . $itemID;
|
|
||||||
$mysqlconnetion->executeQuery($queryDelete);
|
$app->get('/ricetta/:itemID/photos', function ($itemID) use ($app) {
|
||||||
|
$callbackFn = $app->request()->get('callback');
|
||||||
$queryDelete = "DELETE FROM blocco_note where ricetta_id = " . $itemID;
|
|
||||||
$mysqlconnetion->executeQuery($queryDelete);
|
$query = "SELECT id as id_photo, type_format, from_profile_id, uploaded_date, profilo.Name as profile_name, published from immagini" .
|
||||||
|
" INNER JOIN profilo ON profilo.ProfiloID = immagini.from_profile_id".
|
||||||
$queryDelete = "DELETE FROM ingredienti where ID_RICETTE = " . $itemID;
|
" WHERE id_ricette = " . $itemID;
|
||||||
$mysqlconnetion->executeQuery($queryDelete);
|
|
||||||
|
$mysqlconnetion = new MysqlClass;
|
||||||
$queryDelete = "DELETE FROM ricette where ID = " . $itemID;
|
//$mysqlconnetion->connetti();
|
||||||
$mysqlconnetion->executeQuery($queryDelete);
|
$retObj = $mysqlconnetion->queryToObject($query);
|
||||||
$retValue["message"] = "Ricetta cancellata con successo";
|
$mysqlconnetion->disconnetti();
|
||||||
} catch (Exception $e) {
|
returnJson($app, $callbackFn, $retObj);
|
||||||
$retValue["result"] = false;
|
|
||||||
$retValue["message"] = $e->getMessage();
|
|
||||||
}
|
|
||||||
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retValue);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/photos/', function () use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
|
|
||||||
$query = "SELECT * from ( SELECT id as ricetta_id, `titolo`,`autore`, ".
|
|
||||||
" (select COUNT(*) from immagini where immagini.id_ricette = `ricette`.id) as num_img,".
|
|
||||||
" (select COUNT(*) from immagini where immagini.id_ricette = `ricette`.id and immagini.published = 1) as num_img_pub".
|
|
||||||
" FROM `ricette`".
|
|
||||||
" ) as tmp".
|
|
||||||
" WHERE tmp.num_img> 0";
|
|
||||||
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
//$mysqlconnetion->connetti();
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/ricetta/:itemID/photos', function ($itemID) use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
|
|
||||||
$query = "SELECT id as id_photo, type_format, from_profile_id, uploaded_date, profilo.Name as profile_name, published from immagini" .
|
|
||||||
" INNER JOIN profilo ON profilo.ProfiloID = immagini.from_profile_id".
|
|
||||||
" WHERE id_ricette = " . $itemID;
|
|
||||||
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
//$mysqlconnetion->connetti();
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/statistics/gender', function () use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
|
|
||||||
$query = "SELECT 'Gender' as Type, IF(Gender='', 'Sconosciuto', Gender) as Serie, COUNT(gender) as CountSerie from profilo GROUP BY gender";
|
|
||||||
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
//$mysqlconnetion->connetti();
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/statistics/typeAccess', function () use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
|
|
||||||
$query = "SELECT 'TipoAccesso' as Type, TipoAccesso as Serie, COUNT(TipoAccesso) as CountSerie from profilo GROUP BY TipoAccesso";
|
|
||||||
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
//$mysqlconnetion->connetti();
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/statistics/themesUsage', function () use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
|
|
||||||
$query = "SELECT 'TemaUI' as Type, TemaUI as Serie, COUNT(TemaUI) as CountSerie from profilo GROUP BY TemaUI";
|
|
||||||
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
//$mysqlconnetion->connetti();
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/profiles', function () use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
|
|
||||||
$query = "SELECT ProfiloID as id, Name as name from profilo where name <> '' order by Name";
|
|
||||||
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
//$mysqlconnetion->connetti();
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
});
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
require_once "./myDropBoxObj.php";
|
||||||
|
use PHPImageWorkshop\ImageWorkshop;
|
||||||
|
require_once('./PHPImageWorkshop/ImageWorkshop.php'); // Be sure of the path to the class
|
||||||
|
|
||||||
|
date_default_timezone_set("Europe/Rome");
|
||||||
|
|
||||||
|
$dirRicetteDropBox = "IlLievitario/Images/Ricette";
|
||||||
|
|
||||||
|
$tmpFileName = "C:/Users/Denis/Desktop/Chiaravalle/Jpg/DSC_7731.jpg";
|
||||||
|
$ext = pathinfo($tmpFileName, PATHINFO_EXTENSION);
|
||||||
|
|
||||||
|
$idRicette = 5;
|
||||||
|
|
||||||
|
$newID = 125;
|
||||||
|
|
||||||
|
$imageFileName = $newID . "_full_ricetta." . $ext;
|
||||||
|
|
||||||
|
$thumbFileName = $newID . "_thumb_ricetta." . $ext;
|
||||||
|
|
||||||
|
$dropBoxObj = new myDropBox();
|
||||||
|
|
||||||
|
$folder = $dirRicetteDropBox . "/" . $idRicette;
|
||||||
|
/*
|
||||||
|
echo $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
||||||
|
|
||||||
|
return;
|
||||||
|
*/
|
||||||
|
$layer = ImageWorkshop::initFromPath($tmpFileName);
|
||||||
|
|
||||||
|
echo $layer->getImage()->image_type;
|
||||||
|
return;
|
||||||
|
|
||||||
|
$layer->resizeByLargestSideInPixel(640, true);
|
||||||
|
|
||||||
|
$layer->save(dirname($tmpFileName), $imageFileName);
|
||||||
|
|
||||||
|
$imgData = addslashes(file_get_contents($tmpFileName));
|
||||||
|
|
||||||
|
$layer->resizeByLargestSideInPixel(300, true);
|
||||||
|
|
||||||
|
$layer->save(dirname($tmpFileName), $thumbFileName);
|
||||||
|
|
||||||
|
try {
|
||||||
|
$dropBoxObj->CreateFolder($folder);
|
||||||
|
} catch (DropboxException $ex) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$dropBoxObj->UploadFile(dirname($tmpFileName) . "/" . $imageFileName, $folder . "/" . $imageFileName);
|
||||||
|
|
||||||
|
$dropBoxObj->UploadFile(dirname($tmpFileName) . "/" . $thumbFileName, $folder . "/" . $thumbFileName);
|
||||||
+3
-11
@@ -23,8 +23,8 @@ class myDropBox {
|
|||||||
$access_token = $this->load_token("access");
|
$access_token = $this->load_token("access");
|
||||||
if (!empty($access_token)) {
|
if (!empty($access_token)) {
|
||||||
$this->dropbox->SetAccessToken($access_token);
|
$this->dropbox->SetAccessToken($access_token);
|
||||||
//echo "loaded access token:";
|
echo "loaded access token:";
|
||||||
//print_r($access_token);
|
print_r($access_token);
|
||||||
} elseif (!empty($_GET['auth_callback'])) { // are we coming from dropbox's auth page?
|
} elseif (!empty($_GET['auth_callback'])) { // are we coming from dropbox's auth page?
|
||||||
// then load our previosly created request token
|
// then load our previosly created request token
|
||||||
$request_token = $this->load_token($_GET['oauth_token']);
|
$request_token = $this->load_token($_GET['oauth_token']);
|
||||||
@@ -52,21 +52,13 @@ class myDropBox {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function GetLink($dropBoxPathFile) {
|
public function GetLink($dropBoxPathFile) {
|
||||||
$exp = null;
|
return $this->dropbox->GetLink($dropBoxPathFile, false, false);
|
||||||
$ret = $this->dropbox->GetLink($dropBoxPathFile, true, false, $exp);
|
|
||||||
$ret = str_replace("https://www.dropbox.com/", "https://dl.dropboxusercontent.com/" , $ret);
|
|
||||||
return $ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function CreateFolder($dropBoxPath) {
|
public function CreateFolder($dropBoxPath) {
|
||||||
$ret = $this->dropbox->CreateFolder($dropBoxPath);
|
$ret = $this->dropbox->CreateFolder($dropBoxPath);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function Delete($dropBoxPath) {
|
|
||||||
$ret = $this->dropbox->Delete($dropBoxPath);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function store_token($token, $name) {
|
private function store_token($token, $name) {
|
||||||
if (!file_put_contents("tokens/$name.token", serialize($token)))
|
if (!file_put_contents("tokens/$name.token", serialize($token)))
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
|
browser.id=Chrome.INTEGRATED
|
||||||
copy.src.files=false
|
copy.src.files=false
|
||||||
copy.src.on.open=false
|
copy.src.on.open=false
|
||||||
copy.src.target=
|
copy.src.target=
|
||||||
index.file=
|
hostname=localhost
|
||||||
run.as=LOCAL
|
port=8888
|
||||||
url=http://localhost:8081/Service_Manut/
|
router=mdbTester.php
|
||||||
|
run.as=INTERNAL
|
||||||
|
url=http://localhost:8888/
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
include.path=${php.global.include.path}
|
include.path=${php.global.include.path}
|
||||||
php.version=PHP_54
|
php.version=PHP_53
|
||||||
source.encoding=UTF-8
|
source.encoding=UTF-8
|
||||||
src.dir=.
|
src.dir=.
|
||||||
tags.asp=false
|
tags.asp=false
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
<type>org.netbeans.modules.php.project</type>
|
<type>org.netbeans.modules.php.project</type>
|
||||||
<configuration>
|
<configuration>
|
||||||
<data xmlns="http://www.netbeans.org/ns/php-project/1">
|
<data xmlns="http://www.netbeans.org/ns/php-project/1">
|
||||||
<name>Service_Manut</name>
|
<name>Service</name>
|
||||||
</data>
|
</data>
|
||||||
</configuration>
|
</configuration>
|
||||||
</project>
|
</project>
|
||||||
|
|||||||
+111
-182
@@ -1,182 +1,111 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// inclusione del file contenente la classe
|
// inclusione del file contenente la classe
|
||||||
//include "./MySqlClass.php";
|
//include "./MySqlClass.php";
|
||||||
//include "./utility.php";
|
//include "./utility.php";
|
||||||
|
|
||||||
$app->get('/profile/statusCache', function () use ($app) {
|
$app->get('/profile/:keyStore/ricetta/:ricetta_id', function ($keyStore, $ricetta_id) use ($app) {
|
||||||
$callbackFn = $app->request()->get('callback');
|
$callbackFn = $app->request()->get('callback');
|
||||||
$mysqlconnetion = new MysqlClass;
|
$mysqlconnetion = new MysqlClass;
|
||||||
$query = "select 0 as ID_CATEGORIA, MAX(data_creazione) as LastDateModified from categorie" .
|
$query = "select COUNT(*) as Exist FROM blocco_note where ricetta_id = " . $ricetta_id . " AND ProfiloID = '" . $keyStore . "'";
|
||||||
" UNION" .
|
$retObj = $mysqlconnetion->queryToObject($query);
|
||||||
" select ID_CATEGORIA, MAX(Data_modifica) as LastDateModified from ricette" .
|
$mysqlconnetion->disconnetti();
|
||||||
" GROUP BY ID_CATEGORIA";
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
returnJson($app, $callbackFn, $retObj[0]["Exist"]);
|
||||||
$mysqlconnetion->disconnetti();
|
});
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
$app->post('/profile/ricetta', function () use ($app) {
|
||||||
});
|
$callbackFn = $app->request()->get('callback');
|
||||||
|
$json_data_body = json_decode($app->request()->post('dataPair'));
|
||||||
$app->get('/profile/:keyStore/ricetta/:ricetta_id', function ($keyStore, $ricetta_id) use ($app) {
|
$mysqlconnetion = new MysqlClass;
|
||||||
$callbackFn = $app->request()->get('callback');
|
$query = "insert into blocco_note(ricetta_id, ProfiloID) values (" . $json_data_body->ricetta_id . ", '" . $json_data_body->keyStore . "')";
|
||||||
$mysqlconnetion = new MysqlClass;
|
$retNewID = $mysqlconnetion->insertRecord($query);
|
||||||
$query = "select COUNT(*) as Exist FROM blocco_note where ricetta_id = " . $ricetta_id . " AND ProfiloID = '" . $keyStore . "'";
|
$mysqlconnetion->disconnetti();
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
returnJson($app, $callbackFn, $retNewID);
|
||||||
|
});
|
||||||
returnJson($app, $callbackFn, $retObj[0]["Exist"]);
|
|
||||||
});
|
$app->delete('/profile/:keyStore/ricetta/:ricetta_id', function ($keyStore, $ricetta_id) use ($app) {
|
||||||
|
//$callbackFn = $app->request()->params('callback');
|
||||||
$app->post('/profile/ricetta', function () use ($app) {
|
$mysqlconnetion = new MysqlClass;
|
||||||
$callbackFn = $app->request()->get('callback');
|
$query = "delete from blocco_note where ricetta_id = " . $ricetta_id . " AND ProfiloID = '" . $keyStore . "'";
|
||||||
$json_data_body = json_decode($app->request()->post('dataPair'));
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
$retNewID = $mysqlconnetion->insertRecord($query);
|
||||||
$query = "update profilo set BloccoNoteUpdated = CURRENT_TIMESTAMP WHERE ProfiloID = '" . $json_data_body->keyStore . "'";
|
$mysqlconnetion->disconnetti();
|
||||||
$retNewID = $mysqlconnetion->insertRecord($query);
|
|
||||||
$query = "insert into blocco_note(ricetta_id, ProfiloID) values (" . $json_data_body->ricetta_id . ", '" . $json_data_body->keyStore . "')";
|
echo $retNewID;
|
||||||
$retNewID = $mysqlconnetion->insertRecord($query);
|
//returnJson($app, $callbackFn, $retNewID);
|
||||||
$mysqlconnetion->disconnetti();
|
});
|
||||||
returnJson($app, $callbackFn, $retNewID);
|
|
||||||
});
|
$app->delete('/profile/:keyStore/ricette', function ($keyStore) use ($app) {
|
||||||
|
$callbackFn = $app->request()->get('callback');
|
||||||
$app->delete('/profile/:keyStore/ricetta/:ricetta_id', function ($keyStore, $ricetta_id) use ($app) {
|
$mysqlconnetion = new MysqlClass;
|
||||||
//$callbackFn = $app->request()->params('callback');
|
$query = "delete from blocco_note where ProfiloID = '" . $keyStore . "'";
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
$query = "delete from blocco_note where ricetta_id = " . $ricetta_id . " AND ProfiloID = '" . $keyStore . "'";
|
$retNewID = $mysqlconnetion->insertRecord($query);
|
||||||
|
$mysqlconnetion->disconnetti();
|
||||||
$retNewID = $mysqlconnetion->insertRecord($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
returnJson($app, $callbackFn, $retNewID);
|
||||||
|
});
|
||||||
echo $retNewID;
|
|
||||||
//returnJson($app, $callbackFn, $retNewID);
|
$app->get('/profile/:keyStore/ricette', function ($keyStore) use ($app) {
|
||||||
});
|
$callbackFn = $app->request()->get('callback');
|
||||||
|
$mysqlconnetion = new MysqlClass;
|
||||||
$app->delete('/profile/:keyStore/ricette', function ($keyStore) use ($app) {
|
$query = "select ID as ricetta_id, titolo, autore, valutazione, difficolta from ricette" .
|
||||||
$callbackFn = $app->request()->get('callback');
|
" INNER JOIN blocco_note ON blocco_note.ricetta_id = ricette.id" .
|
||||||
$mysqlconnetion = new MysqlClass;
|
" where blocco_note.ProfiloID = '" . $keyStore . "' order by titolo, autore";
|
||||||
$query = "delete from blocco_note where ProfiloID = '" . $keyStore . "'";
|
$retObj = $mysqlconnetion->queryToObject($query);
|
||||||
|
$mysqlconnetion->disconnetti();
|
||||||
$retNewID = $mysqlconnetion->insertRecord($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
foreach ($retObj as $ele) {
|
||||||
|
$ele["titolo"] = html_entity_decode($ele["titolo"]);
|
||||||
returnJson($app, $callbackFn, $retNewID);
|
}
|
||||||
});
|
|
||||||
|
returnJson($app, $callbackFn, $retObj);
|
||||||
$app->get('/profile/:keyStore/ricette', function ($keyStore) use ($app) {
|
});
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
$app->get('/profile/:keyStore', function ($keyStore) use ($app) {
|
||||||
$query = "select ID as ricetta_id, titolo, autore, valutazione, difficolta from ricette" .
|
$callbackFn = $app->request()->get('callback');
|
||||||
" INNER JOIN blocco_note ON blocco_note.ricetta_id = ricette.id" .
|
$mysqlconnetion = new MysqlClass;
|
||||||
" where blocco_note.ProfiloID = '" . $keyStore . "' order by titolo, autore";
|
$query = "select ProfiloID, TipoAccesso, RisultatiRicerca, TemaUI, Name, Gender, 0 as NumRicette from profilo" .
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
" where ProfiloID = '" . $keyStore . "'";
|
||||||
$mysqlconnetion->disconnetti();
|
$retObj = $mysqlconnetion->queryToObject($query);
|
||||||
|
|
||||||
foreach ($retObj as $ele) {
|
$query = "update profilo set PenultimoAccesso = UltimoAccesso, UltimoAccesso = NOW() where ProfiloID = '" . $keyStore . "'";
|
||||||
$ele["titolo"] = html_entity_decode($ele["titolo"]);
|
$mysqlconnetion->insertRecord($query);
|
||||||
}
|
|
||||||
|
$query = "SELECT COUNT( * ) as NumRicette FROM ricette WHERE data_creazione > ( SELECT PenultimoAccesso FROM profilo " .
|
||||||
returnJson($app, $callbackFn, $retObj);
|
"WHERE `ProfiloID` = '" . $keyStore . "' )";
|
||||||
});
|
|
||||||
|
$retObj2 = $mysqlconnetion->queryToObject($query);
|
||||||
$app->get('/profile/:keyStore', function ($keyStore) use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
$retObj[0]["NumRicette"] = $retObj2[0]["NumRicette"];
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
$query = "SELECT ProfiloID,TipoAccesso,RisultatiRicerca,TemaUI,Name,Gender,0 AS NumRicette,BloccoNoteUpdated,Email,bSpacciatore,bPrivacy,Cap,Comune,Stato, Provincia,TipoPM,Note, Latitudine, Longitudine from profilo" .
|
returnJson($app, $callbackFn, $retObj);
|
||||||
" where ProfiloID = '" . $keyStore . "'";
|
});
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
|
$app->post('/profile', function () use ($app) {
|
||||||
if($retObj != false)
|
$callbackFn = $app->request()->get('callback');
|
||||||
{
|
$json_data_body = json_decode($app->request()->post('dataPair'));
|
||||||
$retObj[0]["Name"] = html_entity_decode($retObj[0]["Name"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
$mysqlconnetion = new MysqlClass;
|
||||||
$retObj[0]["Note"] = html_entity_decode($retObj[0]["Note"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
$query = "insert into profilo(ProfiloID, Name, Email, Gender, TipoAccesso, RisultatiRicerca, TemaUI, UltimoAccesso, CreatoIl) values ('" . $json_data_body->keyStore . "', '" . $json_data_body->name . "', '" . $json_data_body->email . "', '" . $json_data_body->gender . "', '" . $json_data_body->type . "', '" . $json_data_body->risRic . "', '" . $json_data_body->tema . "', NOW(), NOW())";
|
||||||
$retObj[0]["Comune"] = html_entity_decode($retObj[0]["Comune"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
$retObj[0]["Provincia"] = html_entity_decode($retObj[0]["Provincia"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
$retNewID = $mysqlconnetion->insertRecord($query);
|
||||||
|
$mysqlconnetion->disconnetti();
|
||||||
$query = "update profilo set PenultimoAccesso = UltimoAccesso, UltimoAccesso = NOW() where ProfiloID = '" . $keyStore . "'";
|
|
||||||
$mysqlconnetion->insertRecord($query);
|
returnJson($app, $callbackFn, $retNewID);
|
||||||
|
});
|
||||||
$query = "SELECT COUNT( * ) as NumRicette FROM ricette WHERE data_creazione > ( SELECT PenultimoAccesso FROM profilo " .
|
|
||||||
"WHERE `ProfiloID` = '" . $keyStore . "' )";
|
$app->put('/profile', function () use ($app) {
|
||||||
|
$callbackFn = $app->request()->get('callback');
|
||||||
$retObj2 = $mysqlconnetion->queryToObject($query);
|
$json_data_body = json_decode($app->request()->post('dataPair'));
|
||||||
|
$mysqlconnetion = new MysqlClass;
|
||||||
$retObj[0]["NumRicette"] = $retObj2[0]["NumRicette"];
|
$query = "update profilo set RisultatiRicerca = '" . $json_data_body->risRic . "', TemaUI = '" . $json_data_body->tema . "' where ProfiloID = '" . $json_data_body->keyStore . "'";
|
||||||
}
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
$retNewID = $mysqlconnetion->insertRecord($query);
|
||||||
});
|
$mysqlconnetion->disconnetti();
|
||||||
|
|
||||||
$app->get('/profile/province(/:iniz)', function ($iniz = "") use ($app) {
|
returnJson($app, $callbackFn, $retNewID);
|
||||||
$callbackFn = $app->request()->get('callback');
|
});
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
$where= "";
|
?>
|
||||||
if($iniz!="")
|
|
||||||
$where = "WHERE Provincia like '" . $iniz . "%' ";
|
|
||||||
$query = "select DISTINCT Provincia from comuni " . $where . "ORDER BY Provincia";
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
foreach ($retObj as $ele) {
|
|
||||||
if($ele["Provincia"]!=null)
|
|
||||||
$ele["Provincia"] = html_entity_decode($ele["Provincia"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
}
|
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/profile/comuni/:prov(/:iniz)', function ($prov ,$iniz = "") use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
$where= "";
|
|
||||||
if($iniz!="")
|
|
||||||
$where = "AND Comune like '" . $iniz . "%' ";
|
|
||||||
$query = "select Comune, CAP from comuni where Provincia = '" . $prov . "' " . $where . "ORDER BY Comune";
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
foreach ($retObj as $ele) {
|
|
||||||
if($ele["Comune"]!=null)
|
|
||||||
$ele["Comune"] = html_entity_decode($ele["Comune"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
}
|
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
$app->post('/profile', function () use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$json_data_body = json_decode($app->request()->post('dataPair'));
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
$query = "insert into profilo(ProfiloID, Name, Email, Gender, TipoAccesso, RisultatiRicerca, TemaUI, UltimoAccesso, CreatoIl) values ('" .
|
|
||||||
$json_data_body->keyStore . "', '" . str_replace("'", "''", htmlentities($json_data_body->name, null, "UTF-8")) . "', '" . $json_data_body->email . "', '" . $json_data_body->gender . "', '" . $json_data_body->type . "', '" . $json_data_body->risRic . "', '" . $json_data_body->tema . "', NOW(), NOW())";
|
|
||||||
|
|
||||||
$retNewID = $mysqlconnetion->insertRecord($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retNewID);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->put('/profile', function () use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$json_data_body = json_decode($app->request()->post('dataPair'));
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
$query = "update profilo set RisultatiRicerca = '" . $json_data_body->risRic .
|
|
||||||
"', TemaUI = '" . $json_data_body->tema .
|
|
||||||
"', Email = '" . $json_data_body->email .
|
|
||||||
"', bSpacciatore = " . $json_data_body->isSpacc .
|
|
||||||
", bPrivacy = " . $json_data_body->privacy .
|
|
||||||
", Cap = '" . $json_data_body->cap .
|
|
||||||
"', Stato = '" . $json_data_body->stato .
|
|
||||||
"', Comune = '" . htmlentities($json_data_body->comune, null, "UTF-8") .
|
|
||||||
"', Provincia = '" . htmlentities($json_data_body->prov, null, "UTF-8") .
|
|
||||||
"', Note = '" . htmlentities($json_data_body->note, null, "UTF-8") .
|
|
||||||
"', TipoPM = " . $json_data_body->tipopm .
|
|
||||||
", Latitudine = " . $json_data_body->lat .
|
|
||||||
", Longitudine = " . $json_data_body->lng .
|
|
||||||
" where ProfiloID = '" . $json_data_body->keyStore . "'";
|
|
||||||
$retNewID = $mysqlconnetion->insertRecord($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retNewID);
|
|
||||||
});
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|||||||
+31
-51
@@ -33,31 +33,11 @@ $app->get('/typeqtys', function () use ($app) {
|
|||||||
returnJson($app, $callbackFn, $retObj);
|
returnJson($app, $callbackFn, $retObj);
|
||||||
});
|
});
|
||||||
|
|
||||||
$app->get('/ricette/authors(/:startWith)', function ($startWith = "") use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
$query = "select distinct autore from ricette"
|
|
||||||
. " where 1 = 1";
|
|
||||||
|
|
||||||
if ($startWith != null && $startWith != "") {
|
|
||||||
$query = $query . " AND autore like '%" . $startWith . "%'";
|
|
||||||
}
|
|
||||||
|
|
||||||
$query = $query . " order by autore";
|
|
||||||
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/ricette/:catID', function ($categoryID) use ($app) {
|
$app->get('/ricette/:catID', function ($categoryID) use ($app) {
|
||||||
$callbackFn = $app->request()->get('callback');
|
$callbackFn = $app->request()->get('callback');
|
||||||
$mysqlconnetion = new MysqlClass;
|
$mysqlconnetion = new MysqlClass;
|
||||||
//$mysqlconnetion->connetti();
|
//$mysqlconnetion->connetti();
|
||||||
$query = "select * from (select ID as ricetta_id, titolo, autore, valutazione, difficolta, " .
|
$query = "select ID as ricetta_id, titolo, autore, valutazione, difficolta from ricette where ID_CATEGORIA = " . $categoryID . " order by titolo, autore";
|
||||||
"(select id from immagini where immagini.id_ricette = ricette.id and published = 1 order by published_date limit 1) as firstImage " .
|
|
||||||
"from ricette where ricette.ID_CATEGORIA = " . $categoryID . " order by titolo, autore) as TMP";
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
$retObj = $mysqlconnetion->queryToObject($query);
|
||||||
$mysqlconnetion->disconnetti();
|
$mysqlconnetion->disconnetti();
|
||||||
|
|
||||||
@@ -98,38 +78,47 @@ $app->get('/ricette/:categoryID/lastinserted(/:numItems)', function ($categoryID
|
|||||||
returnJson($app, $callbackFn, $retObj);
|
returnJson($app, $callbackFn, $retObj);
|
||||||
});
|
});
|
||||||
|
|
||||||
$app->get('/ricette/search/:numItems/:startItem(/:categoryId(/:difficolta(/:titolo)))',
|
$app->get('/ricette/lastinserted/:profileID', function ($profileID) use ($app) {
|
||||||
function ($numItems = 10, $startItem = 0, $categoryId = 0, $difficolta = 0, $titolo = "") use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
$callbackFn = $app->request()->get('callback');
|
||||||
$mysqlconnetion = new MysqlClass;
|
$mysqlconnetion = new MysqlClass;
|
||||||
$queryBase = " from ricette"
|
//$mysqlconnetion->connetti();
|
||||||
|
$query = "select ID as ricetta_id, titolo, autore FROM ricette WHERE data_creazione > ( SELECT PenultimoAccesso FROM profilo " .
|
||||||
|
"WHERE `ProfiloID` = '" . $profileID . "' ) order by Data_creazione desc, titolo, autore";
|
||||||
|
$retObj = $mysqlconnetion->queryToObject($query);
|
||||||
|
$mysqlconnetion->disconnetti();
|
||||||
|
|
||||||
|
foreach ($retObj as $ele) {
|
||||||
|
$ele["titolo"] = html_entity_decode($ele["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
||||||
|
}
|
||||||
|
|
||||||
|
returnJson($app, $callbackFn, $retObj);
|
||||||
|
});
|
||||||
|
|
||||||
|
$app->get('/ricette/search/:numItems(/:categoryId(/:difficolta(/:titolo)))',
|
||||||
|
function ($numItems = 10, $categoryId = 0, $difficolta = 0, $titolo = "") use ($app) {
|
||||||
|
$callbackFn = $app->request()->get('callback');
|
||||||
|
//$filterItem = json_decode($app->request()->post('post'));
|
||||||
|
$mysqlconnetion = new MysqlClass;
|
||||||
|
$query = "select ricette.ID as ricetta_id, categorie.name AS categoria_name, titolo, autore, valutazione, difficolta from ricette"
|
||||||
. " INNER JOIN categorie ON categorie.ID = ricette.id_categoria"
|
. " INNER JOIN categorie ON categorie.ID = ricette.id_categoria"
|
||||||
. " where 1 = 1";
|
. " where 1 = 1";
|
||||||
if ($categoryId > 0) {
|
if ($categoryId > 0) {
|
||||||
$queryBase = $queryBase . " AND ID_CATEGORIA = " . $categoryId;
|
$query = $query . " AND ID_CATEGORIA = " . $categoryId;
|
||||||
}
|
}
|
||||||
if ($titolo != null && $titolo != "") {
|
if ($titolo != null && $titolo != "") {
|
||||||
foreach (explode(" ", htmlentities(urldecode($titolo))) as $ele)
|
foreach (explode(" ", $titolo) as $ele)
|
||||||
$queryBase = $queryBase . " AND titolo like '%" . $ele . "%'";
|
$query = $query . " AND titolo like '%" . $ele . "%'";
|
||||||
}
|
}
|
||||||
if ($difficolta > 0) {
|
if ($difficolta > 0) {
|
||||||
$queryBase = $queryBase . " AND difficolta = " . $difficolta;
|
$query = $query . " AND difficolta = " . $difficolta;
|
||||||
}
|
}
|
||||||
$queryBase = $queryBase . " order by titolo, autore";
|
$query = $query . " order by titolo, autore LIMIT " . $numItems;
|
||||||
|
|
||||||
$query = "select ricette.ID as ricetta_id, categorie.name AS categoria_name, titolo, autore, valutazione, difficolta" . $queryBase . " LIMIT " . $numItems * $startItem . " , " . $numItems;
|
|
||||||
$retObj2 = $mysqlconnetion->queryToObject($query);
|
|
||||||
|
|
||||||
$query = "select COUNT(*) as TotalRecords" . $queryBase;
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
$retObj = $mysqlconnetion->queryToObject($query);
|
||||||
|
|
||||||
$mysqlconnetion->disconnetti();
|
$mysqlconnetion->disconnetti();
|
||||||
|
|
||||||
foreach ($retObj2 as $ele) {
|
foreach ($retObj as $ele) {
|
||||||
$ele["titolo"] = html_entity_decode($ele["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
$ele["titolo"] = html_entity_decode($ele["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
||||||
}
|
}
|
||||||
|
|
||||||
$retObj["records"] = $retObj2;
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
returnJson($app, $callbackFn, $retObj);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -149,10 +138,6 @@ $app->get('/ricetta/body/:itemID', function ($itemID) use ($app) {
|
|||||||
"where ingredienti.ID_RICETTE = " . $itemID . " order by ingredienti.posizione";
|
"where ingredienti.ID_RICETTE = " . $itemID . " order by ingredienti.posizione";
|
||||||
|
|
||||||
$retObj2 = $mysqlconnetion->queryToObject($query2);
|
$retObj2 = $mysqlconnetion->queryToObject($query2);
|
||||||
|
|
||||||
foreach ($retObj2 as $ele) {
|
|
||||||
$ele["note"] = html_entity_decode($ele["note"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
}
|
|
||||||
|
|
||||||
$retObj[0]["titolo"] = html_entity_decode($retObj[0]["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
$retObj[0]["titolo"] = html_entity_decode($retObj[0]["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
||||||
$retObj[0]["procedimento"] = html_entity_decode($retObj[0]["procedimento"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
$retObj[0]["procedimento"] = html_entity_decode($retObj[0]["procedimento"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
||||||
@@ -168,16 +153,11 @@ $app->get('/ricetta/header/:itemID', function ($itemID) use ($app) {
|
|||||||
$mysqlconnetion = new MysqlClass;
|
$mysqlconnetion = new MysqlClass;
|
||||||
$query = "UPDATE ricette Set valutazione = valutazione + 1 WHERE ricette.ID = " . $itemID;
|
$query = "UPDATE ricette Set valutazione = valutazione + 1 WHERE ricette.ID = " . $itemID;
|
||||||
$mysqlconnetion->executeQuery($query);
|
$mysqlconnetion->executeQuery($query);
|
||||||
$query = "SELECT ID from immagini WHERE published = 1 AND ID_RICETTE = " . $itemID;
|
$query = "SELECT id_categoria, categorie.name AS categoria_name, ricette.ID AS ricetta_id, titolo, procedimento, autore, link_fonte, link_youtube, valutazione FROM ricette INNER JOIN categorie ON categorie.ID = ricette.id_categoria WHERE ricette.ID = " . $itemID;
|
||||||
$photos = $mysqlconnetion->queryToObject($query);
|
|
||||||
$query = "SELECT id_categoria, categorie.name AS categoria_name, ricette.ID AS ricetta_id, " .
|
|
||||||
"titolo, procedimento, autore, link_fonte, link_youtube, valutazione FROM ricette " .
|
|
||||||
"INNER JOIN categorie ON categorie.ID = ricette.id_categoria WHERE ricette.ID = " . $itemID;
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
$retObj = $mysqlconnetion->queryToObject($query);
|
||||||
$retObj[0]["titolo"] = html_entity_decode($retObj[0]["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
$retObj[0]["titolo"] = html_entity_decode($retObj[0]["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
||||||
$retObj[0]["procedimento"] = html_entity_decode($retObj[0]["procedimento"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
$retObj[0]["procedimento"] = html_entity_decode($retObj[0]["procedimento"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
||||||
$data = $retObj[0]["link_youtube"];
|
$data = $retObj[0]["link_youtube"];
|
||||||
$retObj[0]["foto"] = $photos;
|
|
||||||
$output = array();
|
$output = array();
|
||||||
if ($data != "") {
|
if ($data != "") {
|
||||||
$d = explode(";", $data);
|
$d = explode(";", $data);
|
||||||
@@ -203,9 +183,9 @@ $app->get('/ricetta/ingredienti/:itemID', function ($itemID) use ($app) {
|
|||||||
|
|
||||||
$retObj2 = $mysqlconnetion->queryToObject($query2);
|
$retObj2 = $mysqlconnetion->queryToObject($query2);
|
||||||
|
|
||||||
foreach ($retObj2 as $ele) {
|
//$retObj[0]["titolo"] = html_entity_decode($retObj[0]["titolo"]);
|
||||||
$ele["note"] = html_entity_decode($ele["note"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
//$retObj[0]["procedimento"] = html_entity_decode($retObj[0]["procedimento"]);
|
||||||
}
|
//$retObj[0]["ingredienti"] = $retObj2;
|
||||||
|
|
||||||
$mysqlconnetion->disconnetti();
|
$mysqlconnetion->disconnetti();
|
||||||
|
|
||||||
|
|||||||
+15
-17
@@ -1,18 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
include_once "./include.php";
|
include_once "./include.php";
|
||||||
|
|
||||||
$app->group('/api', function () use ($app, $dirRicetteDropBox) {
|
$app->group('/api', function () use ($app, $dirRicetteDropBox) {
|
||||||
include "./ricette.php";
|
include "./ricette.php";
|
||||||
include "./profile.php";
|
include "./profile.php";
|
||||||
include "./image.php";
|
include "./image.php";
|
||||||
include "./spacciatoripm.php";
|
});
|
||||||
});
|
|
||||||
|
$app->group('/backend', function () use ($app) {
|
||||||
$app->group('/backend', function () use ($app, $dirRicetteDropBox) {
|
include "./management.php";
|
||||||
include "./management.php";
|
});
|
||||||
include "./image_backend.php";
|
//include "./image.php";
|
||||||
});
|
|
||||||
//include "./image.php";
|
|
||||||
|
|
||||||
$app->run();
|
$app->run();
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
$app->get('/spacciatori/kml', function () use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
$query = "SELECT ProfiloID, Name, Email, CONCAT(Comune, ', ', Cap, ' - ', Provincia) as Indirizzo, Latitudine, Longitudine, TipoPM FROM `profilo` where bSpacciatore = 1";
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
// Creates the Document.
|
|
||||||
$dom = new DOMDocument('1.0', 'UTF-8');
|
|
||||||
|
|
||||||
// Creates the root KML element and appends it to the root document.
|
|
||||||
$node = $dom->createElementNS('http://earth.google.com/kml/2.1', 'kml');
|
|
||||||
$parNode = $dom->appendChild($node);
|
|
||||||
|
|
||||||
// Creates a KML Document element and append it to the KML element.
|
|
||||||
$dnode = $dom->createElement('Document');
|
|
||||||
$docNode = $parNode->appendChild($dnode);
|
|
||||||
|
|
||||||
// Creates the two Style elements, one for restaurant and one for bar, and append the elements to the Document element.
|
|
||||||
$restStyleNode = $dom->createElement('Style');
|
|
||||||
$restStyleNode->setAttribute('id', '1');
|
|
||||||
$restIconstyleNode = $dom->createElement('IconStyle');
|
|
||||||
$restIconstyleNode->setAttribute('id', 'restaurantIcon');
|
|
||||||
$restIconNode = $dom->createElement('Icon');
|
|
||||||
$restHref = $dom->createElement('href', 'http://maps.google.com/mapfiles/kml/pal2/icon63.png');
|
|
||||||
$restIconNode->appendChild($restHref);
|
|
||||||
$restIconstyleNode->appendChild($restIconNode);
|
|
||||||
$restStyleNode->appendChild($restIconstyleNode);
|
|
||||||
$docNode->appendChild($restStyleNode);
|
|
||||||
|
|
||||||
$barStyleNode = $dom->createElement('Style');
|
|
||||||
$barStyleNode->setAttribute('id', '2');
|
|
||||||
$barIconstyleNode = $dom->createElement('IconStyle');
|
|
||||||
$barIconstyleNode->setAttribute('id', 'barIcon');
|
|
||||||
$barIconNode = $dom->createElement('Icon');
|
|
||||||
$barHref = $dom->createElement('href', 'http://maps.google.com/mapfiles/kml/pal2/icon27.png');
|
|
||||||
$barIconNode->appendChild($barHref);
|
|
||||||
$barIconstyleNode->appendChild($barIconNode);
|
|
||||||
$barStyleNode->appendChild($barIconstyleNode);
|
|
||||||
$docNode->appendChild($barStyleNode);
|
|
||||||
|
|
||||||
// Iterates through the MySQL results, creating one Placemark for each row.
|
|
||||||
foreach ($retObj as $row)
|
|
||||||
{
|
|
||||||
// Creates a Placemark and append it to the Document.
|
|
||||||
|
|
||||||
$node = $dom->createElement('Placemark');
|
|
||||||
$placeNode = $docNode->appendChild($node);
|
|
||||||
|
|
||||||
// Creates an id attribute and assign it the value of id column.
|
|
||||||
$placeNode->setAttribute('id', 'placemark_' . $row['ProfiloID']);
|
|
||||||
|
|
||||||
// Create name, and description elements and assigns them the values of the name and address columns from the results.
|
|
||||||
$nameNode = $dom->createElement('name',htmlentities($row['Name']));
|
|
||||||
$placeNode->appendChild($nameNode);
|
|
||||||
$descNode = $dom->createElement('description', $row['Indirizzo'] . '<br>Contatta: ' . $row['Email']);
|
|
||||||
$placeNode->appendChild($descNode);
|
|
||||||
$styleUrl = $dom->createElement('styleUrl', '#' . $row['TipoPM']);
|
|
||||||
$placeNode->appendChild($styleUrl);
|
|
||||||
|
|
||||||
// Creates a Point element.
|
|
||||||
$pointNode = $dom->createElement('Point');
|
|
||||||
$placeNode->appendChild($pointNode);
|
|
||||||
|
|
||||||
// Creates a coordinates element and gives it the value of the lng and lat columns from the results.
|
|
||||||
$coorStr = $row['Longitudine'] . ',' . $row['Latitudine'];
|
|
||||||
$coorNode = $dom->createElement('coordinates', $coorStr);
|
|
||||||
$pointNode->appendChild($coorNode);
|
|
||||||
}
|
|
||||||
|
|
||||||
$kmlOutput = $dom->saveXML();
|
|
||||||
header('Content-type: application/vnd.google-earth.kml+xml');
|
|
||||||
echo $kmlOutput;
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/spacciatori/bound/:FromLat/:FromLng/:ToLat/:ToLng', function ($FromLat, $FromLng, $ToLat, $ToLng) use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
$query = "SELECT ProfiloID as ID, Name, Email, Comune, Cap, Provincia, Note, \"\" as Indirizzo, Latitudine, Longitudine, TipoPM FROM profilo " .
|
|
||||||
"where bSpacciatore = 1 AND " .
|
|
||||||
"Latitudine BETWEEN " . $ToLat . " AND " . $FromLat . " AND ".
|
|
||||||
"Longitudine BETWEEN " . $ToLng . " AND " . $FromLng;
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
|
|
||||||
foreach ($retObj as $ele) {
|
|
||||||
if($ele["Name"]!=null)
|
|
||||||
$ele["Name"] = html_entity_decode($ele["Name"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
if($ele["Note"]!=null)
|
|
||||||
$ele["Note"] = html_entity_decode($ele["Note"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
if($ele["Comune"]!=null)
|
|
||||||
$ele["Comune"] = html_entity_decode($ele["Comune"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
if($ele["Provincia"]!=null)
|
|
||||||
$ele["Provincia"] = html_entity_decode($ele["Provincia"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
|
|
||||||
$ele["Indirizzo"] = $ele["Comune"] . ", " . $ele["Cap"] . ", " . $ele["Provincia"];
|
|
||||||
}
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
@@ -1,178 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// inclusione del file contenente la classe
|
|
||||||
require_once "./include.php";
|
|
||||||
|
|
||||||
$app->get('/categories', function () use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
//$mysqlconneti on->connetti();
|
|
||||||
$retObj = $mysqlconnetion->queryToObject("select ID as category_id, NAME as name from categorie order by name");
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/typeingredients', function () use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
//$mysqlconnetion->connetti();
|
|
||||||
$retObj = $mysqlconnetion->queryToObject("select ID as tipo_ingredienti_id, name from tipo_ingredienti order by name");
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/typeqtys', function () use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
//$mysqlconnetion->connetti();
|
|
||||||
$retObj = $mysqlconnetion->queryToObject("select ID as tipo_quantita_id, name from tipo_quantita");
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/categoryitems/:catID', function ($categoryID) use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
//$mysqlconnetion->connetti();
|
|
||||||
$query = "select ID as ricetta_id, titolo, autore, valutazione, difficolta from ricette where ID_CATEGORIA = " . $categoryID . " order by titolo, autore";
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
foreach ($retObj as $ele) {
|
|
||||||
$ele["titolo"] = html_entity_decode($ele["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
}
|
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/categoryitems/:categoryID/mostvote(/:numItems)', function ($categoryID, $numItems = 10) use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
//$mysqlconnetion->connetti();
|
|
||||||
$query = "select ID as ricetta_id, titolo, autore from ricette where ID_CATEGORIA = " . $categoryID . " order by Valutazione desc, titolo, autore LIMIT " . $numItems;
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
foreach ($retObj as $ele) {
|
|
||||||
$ele["titolo"] = html_entity_decode($ele["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
}
|
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/categoryitems/:categoryID/lastinserted(/:numItems)', function ($categoryID, $numItems = 10) use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
//$mysqlconnetion->connetti();
|
|
||||||
$query = "select ID as ricetta_id, titolo, autore from ricette where ID_CATEGORIA = " . $categoryID . " order by Data_creazione desc, titolo, autore LIMIT " . $numItems;
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
foreach ($retObj as $ele) {
|
|
||||||
$ele["titolo"] = html_entity_decode($ele["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
}
|
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/categoryitems/search/:numItems(/:categoryId(/:difficolta(/:titolo)))',
|
|
||||||
function ($numItems = 10, $categoryId = 0, $difficolta = 0, $titolo = "") use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
//$filterItem = json_decode($app->request()->post('post'));
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
$query = "select ricette.ID as ricetta_id, categorie.name AS categoria_name, titolo, autore, valutazione, difficolta from ricette"
|
|
||||||
. " INNER JOIN categorie ON categorie.ID = ricette.id_categoria"
|
|
||||||
. " where 1 = 1";
|
|
||||||
if ($categoryId > 0) {
|
|
||||||
$query = $query . " AND ID_CATEGORIA = " . $categoryId;
|
|
||||||
}
|
|
||||||
if ($titolo != null && $titolo != "") {
|
|
||||||
foreach (explode(" ", htmlentities(urldecode($titolo))) as $ele)
|
|
||||||
$query = $query . " AND titolo like '%" . $ele . "%'";
|
|
||||||
}
|
|
||||||
if ($difficolta > 0) {
|
|
||||||
$query = $query . " AND difficolta = " . $difficolta;
|
|
||||||
}
|
|
||||||
$query = $query . " order by titolo, autore LIMIT " . $numItems;
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
foreach ($retObj as $ele) {
|
|
||||||
$ele["titolo"] = html_entity_decode($ele["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
}
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/ricetta/body/:itemID', function ($itemID) use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
|
|
||||||
$query = "UPDATE ricette Set valutazione = valutazione + 1 WHERE ricette.ID = " . $itemID;
|
|
||||||
$mysqlconnetion->executeQuery($query);
|
|
||||||
|
|
||||||
$query = "SELECT id_categoria, categorie.name AS categoria_name, ricette.ID AS ricetta_id, titolo, procedimento, autore, link_fonte, link_youtube, valutazione FROM ricette INNER JOIN categorie ON categorie.ID = ricette.id_categoria WHERE ricette.ID = " . $itemID;
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
|
|
||||||
$query2 = "select ingredienti.id_tipo_ingredienti, tipo_ingredienti.name as nome_ingrediente, quantita, ingredienti.id_tipo_quantita, tipo_quantita.Name as unita, note, posizione from ingredienti " .
|
|
||||||
"inner join tipo_ingredienti on ingredienti.ID_TIPO_INGREDIENTI = tipo_ingredienti.ID " .
|
|
||||||
"left outer join tipo_quantita on ingredienti.ID_TIPO_QUANTITA = tipo_quantita.ID " .
|
|
||||||
"where ingredienti.ID_RICETTE = " . $itemID . " order by ingredienti.posizione";
|
|
||||||
|
|
||||||
$retObj2 = $mysqlconnetion->queryToObject($query2);
|
|
||||||
|
|
||||||
$retObj[0]["titolo"] = html_entity_decode($retObj[0]["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
$retObj[0]["procedimento"] = html_entity_decode($retObj[0]["procedimento"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
$retObj[0]["ingredienti"] = $retObj2;
|
|
||||||
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/ricetta/header/:itemID', function ($itemID) use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
$query = "UPDATE ricette Set valutazione = valutazione + 1 WHERE ricette.ID = " . $itemID;
|
|
||||||
$mysqlconnetion->executeQuery($query);
|
|
||||||
$query = "SELECT id_categoria, categorie.name AS categoria_name, ricette.ID AS ricetta_id, titolo, procedimento, autore, link_fonte, link_youtube, valutazione FROM ricette INNER JOIN categorie ON categorie.ID = ricette.id_categoria WHERE ricette.ID = " . $itemID;
|
|
||||||
$retObj = $mysqlconnetion->queryToObject($query);
|
|
||||||
$retObj[0]["titolo"] = html_entity_decode($retObj[0]["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
$retObj[0]["procedimento"] = html_entity_decode($retObj[0]["procedimento"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
|
||||||
$data = $retObj[0]["link_youtube"];
|
|
||||||
$output = array();
|
|
||||||
if ($data != "") {
|
|
||||||
$d = explode(";", $data);
|
|
||||||
$index = 0;
|
|
||||||
foreach ($d as $ele) {
|
|
||||||
$obj["VideoID"] = $ele;
|
|
||||||
$output[$index] = $obj;
|
|
||||||
$index++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$retObj[0]["link_youtube"] = $output;
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
returnJson($app, $callbackFn, $retObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
$app->get('/ricetta/ingredienti/:itemID', function ($itemID) use ($app) {
|
|
||||||
$callbackFn = $app->request()->get('callback');
|
|
||||||
$mysqlconnetion = new MysqlClass;
|
|
||||||
$query2 = "select ingredienti.id_tipo_ingredienti, tipo_ingredienti.name as nome_ingrediente, quantita, ingredienti.id_tipo_quantita, tipo_quantita.Name as unita, note, posizione from ingredienti " .
|
|
||||||
"inner join tipo_ingredienti on ingredienti.ID_TIPO_INGREDIENTI = tipo_ingredienti.ID " .
|
|
||||||
"left outer join tipo_quantita on ingredienti.ID_TIPO_QUANTITA = tipo_quantita.ID " .
|
|
||||||
"where ingredienti.ID_RICETTE = " . $itemID . " order by ingredienti.posizione";
|
|
||||||
|
|
||||||
$retObj2 = $mysqlconnetion->queryToObject($query2);
|
|
||||||
|
|
||||||
//$retObj[0]["titolo"] = html_entity_decode($retObj[0]["titolo"]);
|
|
||||||
//$retObj[0]["procedimento"] = html_entity_decode($retObj[0]["procedimento"]);
|
|
||||||
//$retObj[0]["ingredienti"] = $retObj2;
|
|
||||||
|
|
||||||
$mysqlconnetion->disconnetti();
|
|
||||||
|
|
||||||
returnJson($app, $callbackFn, $retObj2);
|
|
||||||
});
|
|
||||||
?>
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
a:2:{s:1:"t";s:16:"s1ti76srenx4b7aj";s:1:"s";s:15:"qshrdehad4dzz6n";}
|
|
||||||
+87
-122
@@ -1,122 +1,87 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
if ( ! function_exists( 'exif_imagetype' ) ) {
|
if ( ! function_exists( 'exif_imagetype' ) ) {
|
||||||
function exif_imagetype ( $filename ) {
|
function exif_imagetype ( $filename ) {
|
||||||
if ( ( list($width, $height, $type, $attr) = getimagesize( $filename ) ) !== false ) {
|
if ( ( list($width, $height, $type, $attr) = getimagesize( $filename ) ) !== false ) {
|
||||||
return $type;
|
return $type;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function utf8json($inArray) {
|
function utf8json($inArray) {
|
||||||
|
|
||||||
if (is_array($inArray)) {
|
if (is_array($inArray)) {
|
||||||
static $depth = 0;
|
static $depth = 0;
|
||||||
|
|
||||||
/* our return object */
|
/* our return object */
|
||||||
$newArray = array();
|
$newArray = array();
|
||||||
|
|
||||||
/* safety recursion limit */
|
/* safety recursion limit */
|
||||||
$depth ++;
|
$depth ++;
|
||||||
if ($depth >= '300000') {
|
if ($depth >= '300000') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* step through inArray */
|
/* step through inArray */
|
||||||
foreach ($inArray as $key => $val) {
|
foreach ($inArray as $key => $val) {
|
||||||
if (is_array($val)) {
|
if (is_array($val)) {
|
||||||
/* recurse on array elements */
|
/* recurse on array elements */
|
||||||
$newArray[$key] = utf8json($val);
|
$newArray[$key] = utf8json($val);
|
||||||
} else {
|
} else {
|
||||||
/* encode string values */
|
/* encode string values */
|
||||||
$newArray[$key] = utf8_encode($val);
|
$newArray[$key] = utf8_encode($val);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* return utf8 encoded array */
|
/* return utf8 encoded array */
|
||||||
return $newArray;
|
return $newArray;
|
||||||
}
|
}
|
||||||
/* return utf8 encoded array */
|
/* return utf8 encoded array */
|
||||||
return $inArray;
|
return $inArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
function returnJsonWithDecode($app, $callbackFn, $retObj) {
|
function returnJsonWithDecode($app, $callbackFn, $retObj) {
|
||||||
if ($callbackFn) {
|
if ($callbackFn) {
|
||||||
$app->contentType('application/javascript; Charset=UTF-8');
|
$app->contentType('application/javascript; Charset=UTF-8');
|
||||||
echo $callbackFn . "(" . html_entity_decode(json_encode(utf8json($retObj)), ENT_COMPAT | ENT_HTML401, 'ISO-8859-1') . ")";
|
echo $callbackFn . "(" . html_entity_decode(json_encode(utf8json($retObj)), ENT_COMPAT | ENT_HTML401, 'ISO-8859-1') . ")";
|
||||||
} else {
|
} else {
|
||||||
$app->contentType('application/x-json; Charset=UTF-8');
|
$app->contentType('application/x-json; Charset=UTF-8');
|
||||||
echo html_entity_decode(json_encode(utf8json($retObj)), ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
echo html_entity_decode(json_encode(utf8json($retObj)), ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function returnJson($app, $callbackFn, $retObj) {
|
function returnJson($app, $callbackFn, $retObj) {
|
||||||
if ($callbackFn) {
|
if ($callbackFn) {
|
||||||
$app->contentType('application/javascript; Charset=UTF-8');
|
$app->contentType('application/javascript; Charset=UTF-8');
|
||||||
echo $callbackFn . "(" . (json_encode(utf8json($retObj))) . ")";
|
echo $callbackFn . "(" . (json_encode(utf8json($retObj))) . ")";
|
||||||
} else {
|
} else {
|
||||||
$app->contentType('application/x-json; Charset=UTF-8');
|
$app->contentType('application/x-json; Charset=UTF-8');
|
||||||
echo (json_encode(utf8json($retObj)));
|
echo (json_encode(utf8json($retObj)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeThumbnail($im) {
|
function makeThumbnail($im) {
|
||||||
$final_width_of_image = 300;
|
$final_width_of_image = 300;
|
||||||
$ox = imagesx($im);
|
$ox = imagesx($im);
|
||||||
$oy = imagesy($im);
|
$oy = imagesy($im);
|
||||||
|
|
||||||
$nx = $final_width_of_image;
|
$nx = $final_width_of_image;
|
||||||
$ny = floor($oy * ($final_width_of_image / $ox));
|
$ny = floor($oy * ($final_width_of_image / $ox));
|
||||||
|
|
||||||
$nm = imagecreatetruecolor($nx, $ny);
|
$nm = imagecreatetruecolor($nx, $ny);
|
||||||
|
|
||||||
imagecopyresized($nm, $im, 0, 0, 0, 0, $nx, $ny, $ox, $oy);
|
imagecopyresized($nm, $im, 0, 0, 0, 0, $nx, $ny, $ox, $oy);
|
||||||
|
|
||||||
return $nm;
|
return $nm;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getContentFromResources($res) {
|
function getContentFromResources($res) {
|
||||||
ob_start(); //Start output buffer.
|
ob_start(); //Start output buffer.
|
||||||
imagejpeg($res); //This will normally output the image, but because of ob_start(), it won't.
|
imagejpeg($res); //This will normally output the image, but because of ob_start(), it won't.
|
||||||
$contents = ob_get_contents(); //Instead, output above is saved to $contents
|
$contents = ob_get_contents(); //Instead, output above is saved to $contents
|
||||||
ob_end_clean(); //End the output buffer.
|
ob_end_clean(); //End the output buffer.
|
||||||
|
|
||||||
return $contents;
|
return $contents;
|
||||||
}
|
}
|
||||||
|
|
||||||
function resizeImage($dropBoxObj, $layer, $size, $dir, $fileName, $dirDropBox)
|
?>
|
||||||
{
|
|
||||||
$fullPath = $dir . "/" . $fileName;
|
|
||||||
$layer->resizeByLargestSideInPixel($size, true);
|
|
||||||
$layer->save($dir, $fileName);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$dropBoxObj->CreateFolder($dirDropBox);
|
|
||||||
} catch (DropboxException $ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
$dropBoxObj->UploadFile($fullPath, $dirDropBox . "/" . $fileName);
|
|
||||||
|
|
||||||
echo $dropBoxObj->GetLink($dirDropBox . "/" . $fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeThumbImage($dropBoxObj, $layer, $size, $dir, $fileName, $dirDropBox)
|
|
||||||
{
|
|
||||||
$fileName = str_replace(".jpg", ".png", $fileName);
|
|
||||||
$fileName = str_replace(".jpeg", ".png", $fileName);
|
|
||||||
$fullPath = $dir . "/" . $fileName;
|
|
||||||
$layer->resizeInPixel($size, $size, true, 0, 0, 'MM');
|
|
||||||
$layer->save($dir, $fileName);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$dropBoxObj->CreateFolder($dirDropBox);
|
|
||||||
} catch (DropboxException $ex) {
|
|
||||||
}
|
|
||||||
|
|
||||||
$dropBoxObj->UploadFile($fullPath, $dirDropBox . "/" . $fileName);
|
|
||||||
echo $dropBoxObj->GetLink($dirDropBox . "/" . $fileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
?>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user