Compare commits
20
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6754a2060b | ||
|
|
9533309b58 | ||
|
|
d20b6a6758 | ||
|
|
b3bbd9d1f6 | ||
|
|
4170597626 | ||
|
|
7a8491c572 | ||
|
|
cfb61898b3 | ||
|
|
7533f86035 | ||
|
|
98cd15fad6 | ||
|
|
5b0e7d9aa9 | ||
|
|
ccdece692a | ||
|
|
5792cd88ee | ||
|
|
89bb1a17d7 | ||
|
|
0f64cd747d | ||
|
|
b371156b94 | ||
|
|
b64172c2e9 | ||
|
|
4e871bdbd3 | ||
|
|
50c0032f02 | ||
|
|
42837e9ee9 | ||
|
|
d7010a19ca |
@@ -3,10 +3,3 @@
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^(.*)$ serviceapp.php [QSA,L]
|
||||
</ifModule>
|
||||
|
||||
<Limit GET POST PUT DELETE>
|
||||
Allow from *.gruppolapastamadre.it
|
||||
</Limit>
|
||||
|
||||
Header set Access-Control-Allow-Origin *.gruppolapastamadre.it
|
||||
Header set Access-Control-Allow-Methods: "GET,POST,OPTIONS,DELETE,PUT"
|
||||
@@ -0,0 +1,672 @@
|
||||
<?php
|
||||
/**
|
||||
* DropPHP - A simple Dropbox client that works without cURL.
|
||||
*
|
||||
* http://fabi.me/en/php-projects/dropphp-dropbox-api-client/
|
||||
*
|
||||
*
|
||||
* @author Fabian Schlieper <[email protected]>
|
||||
* @copyright Fabian Schlieper 2014
|
||||
* @version 1.7.1
|
||||
* @license See LICENSE
|
||||
*
|
||||
*/
|
||||
|
||||
require_once(dirname(__FILE__)."/OAuthSimple.php");
|
||||
|
||||
class DropboxClient {
|
||||
|
||||
const API_URL = "https://api.dropbox.com/1/";
|
||||
const API_CONTENT_URL = "https://api-content.dropbox.com/1/";
|
||||
|
||||
const BUFFER_SIZE = 4096;
|
||||
|
||||
const MAX_UPLOAD_CHUNK_SIZE = 150000000; // 150MB
|
||||
|
||||
const UPLOAD_CHUNK_SIZE = 4000000; // 4MB
|
||||
|
||||
private $appParams;
|
||||
private $consumerToken;
|
||||
|
||||
private $requestToken;
|
||||
private $accessToken;
|
||||
|
||||
private $locale;
|
||||
private $rootPath;
|
||||
|
||||
private $useCurl;
|
||||
|
||||
function __construct ($app_params, $locale = "en"){
|
||||
$this->appParams = $app_params;
|
||||
if(empty($app_params['app_key']))
|
||||
throw new DropboxException("App Key is empty!");
|
||||
|
||||
$this->consumerToken = array('t' => $this->appParams['app_key'], 's' => $this->appParams['app_secret']);
|
||||
$this->locale = $locale;
|
||||
$this->rootPath = empty($app_params['app_full_access']) ? "sandbox" : "dropbox";
|
||||
|
||||
$this->requestToken = null;
|
||||
$this->accessToken = null;
|
||||
|
||||
$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
|
||||
*
|
||||
* @access public
|
||||
* @return boolean Whether to actually use cURL (always false if not installed)
|
||||
*/
|
||||
public function SetUseCUrl($use_it)
|
||||
{
|
||||
return ($this->useCurl = ($use_it && function_exists('curl_init')));
|
||||
}
|
||||
|
||||
// ##################################################
|
||||
// Authorization
|
||||
|
||||
/**
|
||||
* Step 1 of authentication process. Retrieves a request token or returns a previously retrieved one.
|
||||
*
|
||||
* @access public
|
||||
* @param boolean $get_new_token Optional (default false). Wether to retrieve a new request token.
|
||||
* @return array Request Token array.
|
||||
*/
|
||||
public function GetRequestToken($get_new_token=false)
|
||||
{
|
||||
if(!empty($this->requestToken) && !$get_new_token)
|
||||
return $this->requestToken;
|
||||
|
||||
$rt = $this->authCall("oauth/request_token");
|
||||
if(empty($rt) || empty($rt['oauth_token']))
|
||||
throw new DropboxException('Could not get request token!');
|
||||
|
||||
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
|
||||
*
|
||||
* @access public
|
||||
* @param string $return_url URL users are redirected after authorization
|
||||
* @return string URL
|
||||
*/
|
||||
public function BuildAuthorizeUrl($return_url)
|
||||
{
|
||||
$rt = $this->GetRequestToken();
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* Step 3. Acquires an access token. This is the final step of authentication.
|
||||
*
|
||||
* @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.
|
||||
* @return array Access Token array.
|
||||
*/
|
||||
public function GetAccessToken($request_token = null)
|
||||
{
|
||||
if(!empty($this->accessToken)) return $this->accessToken;
|
||||
|
||||
if(empty($request_token)) $request_token = $this->requestToken;
|
||||
if(empty($request_token)) throw new DropboxException('Request token required!');
|
||||
|
||||
$at = $this->authCall("oauth/access_token", $request_token);
|
||||
if(empty($at))
|
||||
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']));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a previously retrieved (and stored) access token.
|
||||
*
|
||||
* @access public
|
||||
* @param string|object $token The Access Token
|
||||
* @return none
|
||||
*/
|
||||
public function SetAccessToken($token)
|
||||
{
|
||||
if(empty($token['t']) || empty($token['s'])) throw new DropboxException('Passed invalid access token.');
|
||||
$this->accessToken = $token;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if an access token has been set.
|
||||
*
|
||||
* @access public
|
||||
* @return boolean Authorized or not
|
||||
*/
|
||||
public function IsAuthorized()
|
||||
{
|
||||
if(empty($this->accessToken)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// ##################################################
|
||||
// API Functions
|
||||
|
||||
|
||||
/**
|
||||
* Retrieves information about the user's account.
|
||||
*
|
||||
* @access public
|
||||
* @return object Account info object. See https://www.dropbox.com/developers/reference/api#account-info
|
||||
*/
|
||||
public function GetAccountInfo()
|
||||
{
|
||||
return $this->apiCall("account/info", "GET");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get file list of a dropbox folder.
|
||||
*
|
||||
* @access public
|
||||
* @param string|object $dropbox_path Dropbox path of the folder
|
||||
* @return array An array with metadata of files/folders keyed by paths
|
||||
*/
|
||||
public function GetFiles($dropbox_path='', $recursive=false, $include_deleted=false)
|
||||
{
|
||||
if(is_object($dropbox_path) && !empty($dropbox_path->path)) $dropbox_path = $dropbox_path->path;
|
||||
return $this->getFileTree($dropbox_path, $include_deleted, $recursive ? 1000 : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get file or folder metadata
|
||||
*
|
||||
* @access public
|
||||
* @param $dropbox_path string Dropbox path of the file or folder
|
||||
*/
|
||||
public function GetMetadata($dropbox_path, $include_deleted=false, $rev=null)
|
||||
{
|
||||
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'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Download a file to the webserver
|
||||
*
|
||||
* @access public
|
||||
* @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 $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
|
||||
* @return object Dropbox file metadata
|
||||
*/
|
||||
public function DownloadFile($dropbox_file, $dest_path='', $rev=null, $progress_changed_callback = null)
|
||||
{
|
||||
if(is_object($dropbox_file) && !empty($dropbox_file->path))
|
||||
$dropbox_file = $dropbox_file->path;
|
||||
|
||||
if(empty($dest_path)) $dest_path = basename($dropbox_file);
|
||||
|
||||
$url = $this->cleanUrl(self::API_CONTENT_URL."/files/$this->rootPath/$dropbox_file")
|
||||
. (!empty($rev) ? ('?'.http_build_query(array('rev' => $rev),'','&')) : '');
|
||||
$context = $this->createRequestContext($url, "GET");
|
||||
|
||||
$fh = @fopen($dest_path, 'wb'); // write binary
|
||||
if($fh === false) {
|
||||
@fclose($rh);
|
||||
throw new DropboxException("Could not create file $dest_path !");
|
||||
}
|
||||
|
||||
if($this->useCurl) {
|
||||
curl_setopt($context, CURLOPT_BINARYTRANSFER, true);
|
||||
curl_setopt($context, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($context, CURLOPT_FILE, $fh);
|
||||
$response_headers = array();
|
||||
self::execCurlAndClose($context, $response_headers);
|
||||
fclose($fh);
|
||||
$meta = self::getMetaFromHeaders($response_headers, true);
|
||||
$bytes_loaded = filesize($dest_path);
|
||||
} else {
|
||||
$rh = @fopen($url, 'rb', false, $context); // read binary
|
||||
if($rh === false)
|
||||
throw new DropboxException("HTTP request to $url failed!");
|
||||
|
||||
|
||||
// get file meta from HTTP header
|
||||
$s_meta = stream_get_meta_data($rh);
|
||||
$meta = self::getMetaFromHeaders($s_meta['wrapper_data'], true);
|
||||
$bytes_loaded = 0;
|
||||
while (!feof($rh)) {
|
||||
if(($s=fwrite($fh, fread($rh, self::BUFFER_SIZE))) === false) {
|
||||
@fclose($rh);
|
||||
@fclose($fh);
|
||||
throw new DropboxException("Writing to file $dest_path failed!'");
|
||||
}
|
||||
$bytes_loaded += $s;
|
||||
if(!empty($progress_changed_callback)) {
|
||||
call_user_func($progress_changed_callback, $bytes_loaded, $meta->bytes);
|
||||
}
|
||||
}
|
||||
|
||||
fclose($rh);
|
||||
fclose($fh);
|
||||
}
|
||||
|
||||
if($meta->bytes != $bytes_loaded)
|
||||
throw new DropboxException("Download size mismatch! (header:{$meta->bytes} vs actual:{$bytes_loaded}; curl:{$this->useCurl})");
|
||||
|
||||
return $meta;
|
||||
}
|
||||
|
||||
/**
|
||||
* Upload a file to dropbox
|
||||
*
|
||||
* @access public
|
||||
* @param $src_file string Local file to upload
|
||||
* @param $dropbox_path string Dropbox path for destination
|
||||
* @return object Dropbox file metadata
|
||||
*/
|
||||
public function UploadFile($src_file, $dropbox_path='', $overwrite=true, $parent_rev=null)
|
||||
{
|
||||
if(empty($dropbox_path)) $dropbox_path = basename($src_file);
|
||||
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
|
||||
$dropbox_bn = basename($dropbox_path);
|
||||
if(strpos($dropbox_bn,'.') === false) { // check if ext. is missing -> could be a directory!
|
||||
try {
|
||||
$meta = $this->GetMetadata($dropbox_path);
|
||||
if($meta && $meta->is_dir)
|
||||
$dropbox_path = $dropbox_path . '/'. basename($src_file);
|
||||
} catch(Exception $e) {}
|
||||
}
|
||||
|
||||
$file_size = filesize($src_file);
|
||||
|
||||
if($file_size > self::MAX_UPLOAD_CHUNK_SIZE)
|
||||
{
|
||||
$fh = fopen($src_file,'rb');
|
||||
if($fh === false)
|
||||
throw new DropboxException();
|
||||
|
||||
$upload_id = null;
|
||||
$offset = 0;
|
||||
|
||||
|
||||
while(!feof($fh)) {
|
||||
$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) {
|
||||
curl_setopt($context, CURLOPT_BINARYTRANSFER, true);
|
||||
$response = json_decode(self::execCurlAndClose($context));
|
||||
} else {
|
||||
$response = json_decode(file_get_contents($url, false, $context));
|
||||
}
|
||||
$offset += strlen($content);
|
||||
unset($content);
|
||||
unset($context);
|
||||
|
||||
self::checkForError($response);
|
||||
|
||||
if(empty($upload_id)) {
|
||||
$upload_id = $response->upload_id;
|
||||
if(empty($upload_id)) throw new DropboxException("Upload ID empty!");
|
||||
}
|
||||
if($offset >= $file_size)
|
||||
break;
|
||||
}
|
||||
|
||||
@fclose($fh);
|
||||
|
||||
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)),'','&');
|
||||
$url = $this->cleanUrl(self::API_CONTENT_URL."/files_put/$this->rootPath/$dropbox_path")."?$query";
|
||||
|
||||
if($this->useCurl) {
|
||||
$context = $this->createRequestContext($url, "PUT");
|
||||
curl_setopt($context, CURLOPT_BINARYTRANSFER, true);
|
||||
$fh = fopen($src_file, 'rb');
|
||||
curl_setopt($context, CURLOPT_PUT, 1);
|
||||
curl_setopt($context, CURLOPT_INFILE, $fh); // file pointer
|
||||
curl_setopt($context, CURLOPT_INFILESIZE, filesize($src_file));
|
||||
$meta = json_decode(self::execCurlAndClose($context));
|
||||
fclose($fh);
|
||||
return self::checkForError($meta);
|
||||
} else {
|
||||
$content = file_get_contents($src_file);
|
||||
if(strlen($content) == 0)
|
||||
throw new DropboxException("Could not read file $src_file or file is empty!");
|
||||
|
||||
$context = $this->createRequestContext($url, "PUT", $content);
|
||||
|
||||
return self::checkForError(json_decode(file_get_contents($url, false, $context)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get thumbnail for a specified image
|
||||
*
|
||||
* @access public
|
||||
* @param $dropbox_file string Path to the image
|
||||
* @param $format string Image format of the thumbnail (jpeg or png)
|
||||
* @param $size string Thumbnail size (xs, s, m, l, xl)
|
||||
* @return mime/* Returns the thumbnail as binary image data
|
||||
*/
|
||||
public function GetThumbnail($dropbox_file, $size = 's', $format = 'jpeg', $echo = false)
|
||||
{
|
||||
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")
|
||||
. '?' . http_build_query(array('format' => $format, 'size' => $size),'','&');
|
||||
$context = $this->createRequestContext($url, "GET");
|
||||
|
||||
if($this->useCurl) {
|
||||
curl_setopt($context, CURLOPT_BINARYTRANSFER, true);
|
||||
curl_setopt($context, CURLOPT_RETURNTRANSFER, true);
|
||||
}
|
||||
|
||||
$thumb = $this->useCurl ? self::execCurlAndClose($context) : file_get_contents($url, NULL, $context);
|
||||
|
||||
if($echo) {
|
||||
header('Content-type: image/'.$format);
|
||||
echo $thumb;
|
||||
unset($thumb);
|
||||
return;
|
||||
}
|
||||
|
||||
return $thumb;
|
||||
}
|
||||
|
||||
|
||||
function GetLink($dropbox_file, $preview=true, $short=true, &$expires=null)
|
||||
{
|
||||
if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
|
||||
$url = $this->apiCall(($preview?"shares":"media")."/$this->rootPath/$dropbox_file", "POST", array('locale' => null, 'short_url'=> $preview ? $short : null));
|
||||
$expires = strtotime($url->expires);
|
||||
return $url->url;
|
||||
}
|
||||
|
||||
function Delta($cursor)
|
||||
{
|
||||
return $this->apiCall("delta", "POST", compact('cursor'));
|
||||
}
|
||||
|
||||
function GetRevisions($dropbox_file, $rev_limit=10)
|
||||
{
|
||||
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'));
|
||||
}
|
||||
|
||||
function Restore($dropbox_file, $rev)
|
||||
{
|
||||
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'));
|
||||
}
|
||||
|
||||
function Search($path, $query, $file_limit=1000, $include_deleted=false)
|
||||
{
|
||||
return $this->apiCall("search/$this->rootPath/$path", "POST", compact('query','file_limit','include_deleted'));
|
||||
}
|
||||
|
||||
function GetCopyRef($dropbox_file, &$expires=null)
|
||||
{
|
||||
if(is_object($dropbox_file) && !empty($dropbox_file->path)) $dropbox_file = $dropbox_file->path;
|
||||
$ref = $this->apiCall("copy_ref/$this->rootPath/$dropbox_file", "GET", array('locale' => null));
|
||||
$expires = strtotime($ref->expires);
|
||||
return $ref->copy_ref;
|
||||
}
|
||||
|
||||
|
||||
function Copy($from_path, $to_path, $copy_ref=false)
|
||||
{
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new folder in the DropBox
|
||||
*
|
||||
* @access public
|
||||
* @param $path string The path to the new folder to create
|
||||
* @return object Dropbox folder metadata
|
||||
*/
|
||||
function CreateFolder($path)
|
||||
{
|
||||
return $this->apiCall("fileops/create_folder", "POST", array('root'=> $this->rootPath, 'path' => $path));
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete file or folder
|
||||
*
|
||||
* @access public
|
||||
* @param $path mixed The path or metadata of the file/folder to be deleted.
|
||||
* @return object Dropbox metadata of deleted file or folder
|
||||
*/
|
||||
function Delete($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));
|
||||
}
|
||||
|
||||
function Move($from_path, $to_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));
|
||||
}
|
||||
|
||||
function getFileTree($path="", $include_deleted = false, $max_depth = 0, $depth=0)
|
||||
{
|
||||
static $files;
|
||||
if($depth == 0) $files = array();
|
||||
|
||||
$dir = $this->apiCall("metadata/$this->rootPath/$path", "GET", compact('include_deleted'));
|
||||
|
||||
if(empty($dir) || !is_object($dir)) return false;
|
||||
|
||||
if(!empty($dir->error)) throw new DropboxException($dir->error);
|
||||
|
||||
foreach($dir->contents as $item)
|
||||
{
|
||||
$files[trim($item->path,'/')] = $item;
|
||||
if($item->is_dir && $depth < $max_depth)
|
||||
{
|
||||
$this->getFileTree($item->path, $include_deleted, $max_depth, $depth+1);
|
||||
}
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
function createCurl($url, $http_context)
|
||||
{
|
||||
$ch = curl_init($url);
|
||||
|
||||
$curl_opts = array(
|
||||
CURLOPT_HEADER => false, // exclude header from output
|
||||
//CURLOPT_MUTE => true, // no output!
|
||||
CURLOPT_RETURNTRANSFER => true, // but return!
|
||||
CURLOPT_SSL_VERIFYPEER => false,
|
||||
);
|
||||
|
||||
$curl_opts[CURLOPT_CUSTOMREQUEST] = $http_context['method'];
|
||||
|
||||
if(!empty($http_context['content'])) {
|
||||
$curl_opts[CURLOPT_POSTFIELDS] =& $http_context['content'];
|
||||
if(defined("CURLOPT_POSTFIELDSIZE"))
|
||||
$curl_opts[CURLOPT_POSTFIELDSIZE] = strlen($http_context['content']);
|
||||
}
|
||||
|
||||
$curl_opts[CURLOPT_HTTPHEADER] = array_map('trim',explode("\n",$http_context['header']));
|
||||
|
||||
curl_setopt_array($ch, $curl_opts);
|
||||
return $ch;
|
||||
}
|
||||
|
||||
static private $_curlHeadersRef;
|
||||
static function _curlHeaderCallback($ch, $header)
|
||||
{
|
||||
self::$_curlHeadersRef[] = trim($header);
|
||||
return strlen($header);
|
||||
}
|
||||
|
||||
static function &execCurlAndClose($ch, &$out_response_headers = null)
|
||||
{
|
||||
if(is_array($out_response_headers)) {
|
||||
self::$_curlHeadersRef =& $out_response_headers;
|
||||
curl_setopt($ch, CURLOPT_HEADERFUNCTION, array(__CLASS__, '_curlHeaderCallback'));
|
||||
}
|
||||
$res = curl_exec($ch);
|
||||
$err_no = curl_errno($ch);
|
||||
$err_str = curl_error($ch);
|
||||
curl_close($ch);
|
||||
if($err_no || $res === false) {
|
||||
throw new DropboxException("cURL-Error ($err_no): $err_str");
|
||||
}
|
||||
|
||||
return $res;
|
||||
}
|
||||
|
||||
private function createRequestContext($url, $method, &$content=null, $oauth_token=-1)
|
||||
{
|
||||
if($oauth_token === -1)
|
||||
$oauth_token = $this->accessToken;
|
||||
|
||||
$method = strtoupper($method);
|
||||
$http_context = array('method'=>$method, 'header'=> '');
|
||||
|
||||
$oauth = new OAuthSimple($this->consumerToken['t'],$this->consumerToken['s']);
|
||||
|
||||
if(empty($oauth_token) && !empty($this->accessToken))
|
||||
$oauth_token = $this->accessToken;
|
||||
|
||||
if(!empty($oauth_token)) {
|
||||
$oauth->setParameters(array('oauth_token' => $oauth_token['t']));
|
||||
$oauth->signatures(array('oauth_secret'=>$oauth_token['s']));
|
||||
}
|
||||
|
||||
if(!empty($content)) {
|
||||
$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-Type: application/".($post_vars?"x-www-form-urlencoded":"octet-stream")."\r\n";
|
||||
$http_context['content'] =& $content;
|
||||
if($method == "POST" && $post_vars)
|
||||
$oauth->setParameters($content);
|
||||
} elseif($method == "POST") {
|
||||
// make sure that content-length is always set when post request (otherwise some wrappers fail!)
|
||||
$http_context['content'] = "";
|
||||
$http_context['header'] .= "Content-Length: 0\r\n";
|
||||
}
|
||||
|
||||
|
||||
// check for query vars in url and add them to oauth parameters (and remove from path)
|
||||
$path = $url;
|
||||
$query = strrchr($url,'?');
|
||||
if(!empty($query)) {
|
||||
$oauth->setParameters(substr($query,1));
|
||||
$path = substr($url, 0, -strlen($query));
|
||||
}
|
||||
|
||||
|
||||
$signed = $oauth->sign(array(
|
||||
'action' => $method,
|
||||
'path'=> $path));
|
||||
//print_r($signed);
|
||||
|
||||
$http_context['header'] .= "Authorization: ".$signed['header']."\r\n";
|
||||
|
||||
return $this->useCurl ? $this->createCurl($url, $http_context) : stream_context_create(array('http'=>$http_context));
|
||||
}
|
||||
|
||||
private function authCall($path, $request_token=null)
|
||||
{
|
||||
$url = $this->cleanUrl(self::API_URL.$path);
|
||||
$dummy = null;
|
||||
$context = $this->createRequestContext($url, "POST", $dummy, $request_token);
|
||||
|
||||
$contents = $this->useCurl ? self::execCurlAndClose($context) : file_get_contents($url, false, $context);
|
||||
$data = array();
|
||||
parse_str($contents, $data);
|
||||
return $data;
|
||||
}
|
||||
|
||||
private static function checkForError($resp)
|
||||
{
|
||||
if(!empty($resp->error))
|
||||
throw new DropboxException($resp->error);
|
||||
return $resp;
|
||||
}
|
||||
|
||||
|
||||
private function apiCall($path, $method, $params=array(), $content_call=false)
|
||||
{
|
||||
$url = $this->cleanUrl(($content_call ? self::API_CONTENT_URL : self::API_URL).$path);
|
||||
$content = http_build_query(array_merge(array('locale'=>$this->locale), $params),'','&');
|
||||
|
||||
if($method == "GET") {
|
||||
$url .= "?".$content;
|
||||
$content = null;
|
||||
}
|
||||
|
||||
$context = $this->createRequestContext($url, $method, $content);
|
||||
$json = $this->useCurl ? self::execCurlAndClose($context) : file_get_contents($url, false, $context);
|
||||
//if($json === false)
|
||||
// throw new DropboxException();
|
||||
$resp = json_decode($json);
|
||||
return self::checkForError($resp);
|
||||
}
|
||||
|
||||
|
||||
private static function getMetaFromHeaders(&$header_array, $throw_on_error=false)
|
||||
{
|
||||
$obj = json_decode(substr(@array_shift(array_filter($header_array, create_function('$s', 'return stripos($s, "x-dropbox-metadata:") === 0;'))), 20));
|
||||
if($throw_on_error && (empty($obj)||!is_object($obj)))
|
||||
throw new DropboxException("Could not retrieve meta data from header data: ".print_r($header_array,true));
|
||||
if($throw_on_error)
|
||||
self::checkForError ($obj);
|
||||
return $obj;
|
||||
}
|
||||
|
||||
|
||||
function cleanUrl($url) {
|
||||
$p = substr($url,0,8);
|
||||
$url = str_replace('//','/', str_replace('\\','/',substr($url,8)));
|
||||
$url = rawurlencode($url);
|
||||
$url = str_replace('%2F', '/', $url);
|
||||
return $p.$url;
|
||||
}
|
||||
}
|
||||
|
||||
class DropboxException extends Exception {
|
||||
|
||||
public function __construct($err = null, $isDebug = FALSE)
|
||||
{
|
||||
if(is_null($err)) {
|
||||
$el = error_get_last();
|
||||
$this->message = $el['message'];
|
||||
$this->file = $el['file'];
|
||||
$this->line = $el['line'];
|
||||
} else
|
||||
$this->message = $err;
|
||||
self::log_error($err);
|
||||
if ($isDebug)
|
||||
{
|
||||
self::display_error($err, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
public static function log_error($err)
|
||||
{
|
||||
error_log($err, 0);
|
||||
}
|
||||
|
||||
public static function display_error($err, $kill = FALSE)
|
||||
{
|
||||
print_r($err);
|
||||
if ($kill === FALSE)
|
||||
{
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,532 @@
|
||||
<?php
|
||||
/**
|
||||
* OAuthSimple - A simpler version of OAuth
|
||||
*
|
||||
* https://github.com/jrconlin/oauthsimple
|
||||
*
|
||||
* @author jr conlin <[email protected]>
|
||||
* @copyright unitedHeroes.net 2011
|
||||
* @version 1.3
|
||||
* @license See OAuthSimple_license.txt
|
||||
*
|
||||
*/
|
||||
|
||||
class OAuthSimple {
|
||||
private $_secrets;
|
||||
private $_default_signature_method;
|
||||
private $_action;
|
||||
private $_nonce_chars;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @access public
|
||||
* @param api_key (String) The API Key (sometimes referred to as the consumer key) This value is usually supplied by the site you wish to use.
|
||||
* @param shared_secret (String) The shared secret. This value is also usually provided by the site you wish to use.
|
||||
* @return OAuthSimple (Object)
|
||||
*/
|
||||
function __construct ($APIKey = "", $sharedSecret=""){
|
||||
|
||||
if (!empty($APIKey))
|
||||
{
|
||||
$this->_secrets['consumer_key'] = $APIKey;
|
||||
}
|
||||
|
||||
if (!empty($sharedSecret))
|
||||
{
|
||||
$this->_secrets['shared_secret'] = $sharedSecret;
|
||||
}
|
||||
|
||||
$this->_default_signature_method = "HMAC-SHA1";
|
||||
$this->_action = "GET";
|
||||
$this->_nonce_chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the parameters and URL
|
||||
*
|
||||
* @access public
|
||||
* @return OAuthSimple (Object)
|
||||
*/
|
||||
public function reset() {
|
||||
$this->_parameters = Array();
|
||||
$this->path = NULL;
|
||||
$this->sbs = NULL;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the parameters either from a hash or a string
|
||||
*
|
||||
* @access public
|
||||
* @param(string, object) List of parameters for the call, this can either be a URI string (e.g. "foo=bar&gorp=banana" or an object/hash)
|
||||
* @return OAuthSimple (Object)
|
||||
*/
|
||||
public function setParameters ($parameters=Array()) {
|
||||
|
||||
if (is_string($parameters))
|
||||
{
|
||||
$parameters = $this->_parseParameterString($parameters);
|
||||
}
|
||||
if (empty($this->_parameters))
|
||||
{
|
||||
$this->_parameters = $parameters;
|
||||
}
|
||||
else if (!empty($parameters))
|
||||
{
|
||||
$this->_parameters = array_merge($this->_parameters,$parameters);
|
||||
}
|
||||
if (empty($this->_parameters['oauth_nonce']))
|
||||
{
|
||||
$this->_getNonce();
|
||||
}
|
||||
if (empty($this->_parameters['oauth_timestamp']))
|
||||
{
|
||||
$this->_getTimeStamp();
|
||||
}
|
||||
if (empty($this->_parameters['oauth_consumer_key']))
|
||||
{
|
||||
$this->_getApiKey();
|
||||
}
|
||||
if (empty($this->_parameters['oauth_token']))
|
||||
{
|
||||
$this->_getAccessToken();
|
||||
}
|
||||
if (empty($this->_parameters['oauth_signature_method']))
|
||||
{
|
||||
$this->setSignatureMethod();
|
||||
}
|
||||
if (empty($this->_parameters['oauth_version']))
|
||||
{
|
||||
$this->_parameters['oauth_version']="1.0";
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for setParameters
|
||||
*
|
||||
* @access public
|
||||
* @see setParameters
|
||||
*/
|
||||
public function setQueryString ($parameters)
|
||||
{
|
||||
return $this->setParameters($parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the target URL (does not include the parameters)
|
||||
*
|
||||
* @param path (String) the fully qualified URI (excluding query arguments) (e.g "http://example.org/foo")
|
||||
* @return OAuthSimple (Object)
|
||||
*/
|
||||
public function setURL ($path)
|
||||
{
|
||||
if (empty($path))
|
||||
{
|
||||
throw new OAuthSimpleException('No path specified for OAuthSimple.setURL');
|
||||
}
|
||||
$this->_path=$path;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for setURL
|
||||
*
|
||||
* @param path (String)
|
||||
* @see setURL
|
||||
*/
|
||||
public function setPath ($path)
|
||||
{
|
||||
return $this->_path=$path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the "action" for the url, (e.g. GET,POST, DELETE, etc.)
|
||||
*
|
||||
* @param action (String) HTTP Action word.
|
||||
* @return OAuthSimple (Object)
|
||||
*/
|
||||
public function setAction ($action)
|
||||
{
|
||||
if (empty($action))
|
||||
{
|
||||
$action = 'GET';
|
||||
}
|
||||
$action = strtoupper($action);
|
||||
if (preg_match('/[^A-Z]/',$action))
|
||||
{
|
||||
throw new OAuthSimpleException('Invalid action specified for OAuthSimple.setAction');
|
||||
}
|
||||
$this->_action = $action;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the signatures (as well as validate the ones you have)
|
||||
*
|
||||
* @param signatures (object) object/hash of the token/signature pairs {api_key:, shared_secret:, oauth_token: oauth_secret:}
|
||||
* @return OAuthSimple (Object)
|
||||
*/
|
||||
public function signatures ($signatures)
|
||||
{
|
||||
if (!empty($signatures) && !is_array($signatures))
|
||||
{
|
||||
throw new OAuthSimpleException('Must pass dictionary array to OAuthSimple.signatures');
|
||||
}
|
||||
if (!empty($signatures))
|
||||
{
|
||||
if (empty($this->_secrets))
|
||||
{
|
||||
$this->_secrets=Array();
|
||||
}
|
||||
$this->_secrets=array_merge($this->_secrets,$signatures);
|
||||
}
|
||||
if (isset($this->_secrets['api_key']))
|
||||
{
|
||||
$this->_secrets['consumer_key'] = $this->_secrets['api_key'];
|
||||
}
|
||||
if (isset($this->_secrets['access_token']))
|
||||
{
|
||||
$this->_secrets['oauth_token'] = $this->_secrets['access_token'];
|
||||
}
|
||||
if (isset($this->_secrets['access_secret']))
|
||||
{
|
||||
$this->_secrets['oauth_secret'] = $this->_secrets['access_secret'];
|
||||
}
|
||||
if (isset($this->_secrets['access_token_secret']))
|
||||
{
|
||||
$this->_secrets['oauth_secret'] = $this->_secrets['access_token_secret'];
|
||||
}
|
||||
if (empty($this->_secrets['consumer_key']))
|
||||
{
|
||||
throw new OAuthSimpleException('Missing required consumer_key in OAuthSimple.signatures');
|
||||
}
|
||||
if (empty($this->_secrets['shared_secret']))
|
||||
{
|
||||
throw new OAuthSimpleException('Missing requires shared_secret in OAuthSimple.signatures');
|
||||
}
|
||||
if (!empty($this->_secrets['oauth_token']) && empty($this->_secrets['oauth_secret']))
|
||||
{
|
||||
throw new OAuthSimpleException('Missing oauth_secret for supplied oauth_token in OAuthSimple.signatures');
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTokensAndSecrets($signatures)
|
||||
{
|
||||
return $this->signatures($signatures);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the signature method (currently only Plaintext or SHA-MAC1)
|
||||
*
|
||||
* @param method (String) Method of signing the transaction (only PLAINTEXT and SHA-MAC1 allowed for now)
|
||||
* @return OAuthSimple (Object)
|
||||
*/
|
||||
public function setSignatureMethod ($method="")
|
||||
{
|
||||
if (empty($method))
|
||||
{
|
||||
$method = $this->_default_signature_method;
|
||||
}
|
||||
$method = strtoupper($method);
|
||||
switch($method)
|
||||
{
|
||||
case 'PLAINTEXT':
|
||||
case 'HMAC-SHA1':
|
||||
$this->_parameters['oauth_signature_method']=$method;
|
||||
break;
|
||||
default:
|
||||
throw new OAuthSimpleException ("Unknown signing method $method specified for OAuthSimple.setSignatureMethod");
|
||||
break;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/** sign the request
|
||||
*
|
||||
* note: all arguments are optional, provided you've set them using the
|
||||
* other helper functions.
|
||||
*
|
||||
* @param args (Array) hash of arguments for the call {action, path, parameters (array), method, signatures (array)} all arguments are optional.
|
||||
* @return (Array) signed values
|
||||
*/
|
||||
public function sign($args=array())
|
||||
{
|
||||
if (!empty($args['action']))
|
||||
{
|
||||
$this->setAction($args['action']);
|
||||
}
|
||||
if (!empty($args['path']))
|
||||
{
|
||||
$this->setPath($args['path']);
|
||||
}
|
||||
if (!empty($args['method']))
|
||||
{
|
||||
$this->setSignatureMethod($args['method']);
|
||||
}
|
||||
if (!empty($args['signatures']))
|
||||
{
|
||||
$this->signatures($args['signatures']);
|
||||
}
|
||||
if (empty($args['parameters']))
|
||||
{
|
||||
$args['parameters']=array();
|
||||
}
|
||||
$this->setParameters($args['parameters']);
|
||||
$normParams = $this->_normalizedParameters();
|
||||
$this->_parameters['oauth_signature'] = $this->_generateSignature($normParams);
|
||||
|
||||
return Array (
|
||||
'parameters' => $this->_parameters,
|
||||
'signature' => self::_oauthEscape($this->_parameters['oauth_signature']),
|
||||
'signed_url' => $this->_path . '?' . $this->_normalizedParameters(),
|
||||
'header' => $this->getHeaderString(),
|
||||
'sbs'=> $this->sbs
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a formatted "header" string
|
||||
*
|
||||
* NOTE: This doesn't set the "Authorization: " prefix, which is required.
|
||||
* It's not set because various set header functions prefer different
|
||||
* ways to do that.
|
||||
*
|
||||
* @param args (Array)
|
||||
* @return $result (String)
|
||||
*/
|
||||
public function getHeaderString ($args=array())
|
||||
{
|
||||
if (empty($this->_parameters['oauth_signature']))
|
||||
{
|
||||
$this->sign($args);
|
||||
}
|
||||
$result = 'OAuth ';
|
||||
|
||||
foreach ($this->_parameters as $pName => $pValue)
|
||||
{
|
||||
if (strpos($pName,'oauth_') !== 0 || $pName == 'oauth_token_secret2')
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (is_array($pValue))
|
||||
{
|
||||
foreach ($pValue as $val)
|
||||
{
|
||||
$result .= $pName .'="' . self::_oauthEscape($val) . '", ';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$result .= $pName . '="' . self::_oauthEscape($pValue) . '", ';
|
||||
}
|
||||
}
|
||||
|
||||
return preg_replace('/, $/','',$result);
|
||||
}
|
||||
|
||||
private function _parseParameterString ($paramString)
|
||||
{
|
||||
$elements = explode('&',$paramString);
|
||||
$result = array();
|
||||
foreach ($elements as $element)
|
||||
{
|
||||
list ($key,$token) = explode('=',$element);
|
||||
if ($token)
|
||||
{
|
||||
$token = urldecode($token);
|
||||
}
|
||||
if (!empty($result[$key]))
|
||||
{
|
||||
if (!is_array($result[$key]))
|
||||
{
|
||||
$result[$key] = array($result[$key],$token);
|
||||
}
|
||||
else
|
||||
{
|
||||
array_push($result[$key],$token);
|
||||
}
|
||||
}
|
||||
else
|
||||
$result[$key]=$token;
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
private static function _oauthEscape($string)
|
||||
{
|
||||
if ($string === 0) { return 0; }
|
||||
if ($string == '0') { return '0'; }
|
||||
if (strlen($string) == 0) { return ''; }
|
||||
if (is_array($string)) {
|
||||
throw new OAuthSimpleException('Array passed to _oauthEscape');
|
||||
}
|
||||
$string = rawurlencode($string);
|
||||
|
||||
$string = str_replace('+','%20',$string);
|
||||
$string = str_replace('!','%21',$string);
|
||||
$string = str_replace('*','%2A',$string);
|
||||
$string = str_replace('\'','%27',$string);
|
||||
$string = str_replace('(','%28',$string);
|
||||
$string = str_replace(')','%29',$string);
|
||||
|
||||
return $string;
|
||||
}
|
||||
|
||||
private function _getNonce($length=5)
|
||||
{
|
||||
$result = '';
|
||||
$cLength = strlen($this->_nonce_chars);
|
||||
for ($i=0; $i < $length; $i++)
|
||||
{
|
||||
$rnum = rand(0,$cLength);
|
||||
$result .= substr($this->_nonce_chars,$rnum,1);
|
||||
}
|
||||
$result = md5($result);
|
||||
$this->_parameters['oauth_nonce'] = $result;
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function _getApiKey()
|
||||
{
|
||||
if (empty($this->_secrets['consumer_key']))
|
||||
{
|
||||
throw new OAuthSimpleException('No consumer_key set for OAuthSimple');
|
||||
}
|
||||
$this->_parameters['oauth_consumer_key']=$this->_secrets['consumer_key'];
|
||||
|
||||
return $this->_parameters['oauth_consumer_key'];
|
||||
}
|
||||
|
||||
private function _getAccessToken()
|
||||
{
|
||||
if (!isset($this->_secrets['oauth_secret']))
|
||||
{
|
||||
return '';
|
||||
}
|
||||
if (!isset($this->_secrets['oauth_token']))
|
||||
{
|
||||
throw new OAuthSimpleException('No access token (oauth_token) set for OAuthSimple.');
|
||||
}
|
||||
$this->_parameters['oauth_token'] = $this->_secrets['oauth_token'];
|
||||
|
||||
return $this->_parameters['oauth_token'];
|
||||
}
|
||||
|
||||
private function _getTimeStamp()
|
||||
{
|
||||
return $this->_parameters['oauth_timestamp'] = time();
|
||||
}
|
||||
|
||||
private function _normalizedParameters()
|
||||
{
|
||||
$normalized_keys = array();
|
||||
$return_array = array();
|
||||
|
||||
foreach ( $this->_parameters as $paramName=>$paramValue) {
|
||||
if (!preg_match('/\w+_secret/',$paramName) OR (strpos($paramValue, '@') !== 0 && !file_exists(substr($paramValue, 1))) )
|
||||
{
|
||||
if (is_array($paramValue))
|
||||
{
|
||||
$normalized_keys[self::_oauthEscape($paramName)] = array();
|
||||
foreach($paramValue as $item)
|
||||
{
|
||||
array_push($normalized_keys[self::_oauthEscape($paramName)], self::_oauthEscape($item));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$normalized_keys[self::_oauthEscape($paramName)] = self::_oauthEscape($paramValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ksort($normalized_keys);
|
||||
|
||||
foreach($normalized_keys as $key=>$val)
|
||||
{
|
||||
if (is_array($val))
|
||||
{
|
||||
sort($val);
|
||||
foreach($val as $element)
|
||||
{
|
||||
array_push($return_array, $key . "=" . $element);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
array_push($return_array, $key .'='. $val);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return join("&", $return_array);
|
||||
}
|
||||
|
||||
|
||||
private function _generateSignature ()
|
||||
{
|
||||
$secretKey = '';
|
||||
if(isset($this->_secrets['shared_secret']))
|
||||
{
|
||||
$secretKey = self::_oauthEscape($this->_secrets['shared_secret']);
|
||||
}
|
||||
|
||||
$secretKey .= '&';
|
||||
if(isset($this->_secrets['oauth_secret']))
|
||||
{
|
||||
$secretKey .= self::_oauthEscape($this->_secrets['oauth_secret']);
|
||||
}
|
||||
|
||||
switch($this->_parameters['oauth_signature_method'])
|
||||
{
|
||||
case 'PLAINTEXT':
|
||||
return urlencode($secretKey);;
|
||||
case 'HMAC-SHA1':
|
||||
$this->sbs = self::_oauthEscape($this->_action).'&'.self::_oauthEscape($this->_path).'&'.self::_oauthEscape($this->_normalizedParameters());
|
||||
|
||||
return base64_encode(hash_hmac('sha1',$this->sbs,$secretKey,TRUE));
|
||||
default:
|
||||
throw new OAuthSimpleException('Unknown signature method for OAuthSimple');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class OAuthSimpleException extends Exception {
|
||||
|
||||
public function __construct($err, $isDebug = FALSE)
|
||||
{
|
||||
self::log_error($err);
|
||||
if ($isDebug)
|
||||
{
|
||||
self::display_error($err, TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
public static function log_error($err)
|
||||
{
|
||||
error_log($err, 0);
|
||||
}
|
||||
|
||||
public static function display_error($err, $kill = FALSE)
|
||||
{
|
||||
print_r($err);
|
||||
if ($kill === FALSE)
|
||||
{
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
error_reporting(E_ALL);
|
||||
require_once("DropboxClient.php");
|
||||
|
||||
// you have to create an app at https://www.dropbox.com/developers/apps and enter details below:
|
||||
$dropbox = new DropboxClient(array(
|
||||
'app_key' => "ft0zodv89xx804e",
|
||||
'app_secret' => "ut43sn7m9wufy3s",
|
||||
'app_full_access' => true,
|
||||
),'it');
|
||||
|
||||
handle_dropbox_auth($dropbox); // see below
|
||||
|
||||
// if there is no upload, show the form
|
||||
if(empty($_FILES['the_upload'])) {
|
||||
?>
|
||||
<form enctype="multipart/form-data" method="POST" action="">
|
||||
<p>
|
||||
<label for="file">Upload File</label>
|
||||
<input type="file" name="the_upload" />
|
||||
</p>
|
||||
<p><input type="submit" name="submit-btn" value="Upload!"></p>
|
||||
</form>
|
||||
<?php } else {
|
||||
|
||||
$upload_name = $_FILES["the_upload"]["name"];
|
||||
echo "<pre>";
|
||||
echo "\r\n\r\n<b>Uploading $upload_name:</b>\r\n";
|
||||
$meta = $dropbox->UploadFile($_FILES["the_upload"]["tmp_name"], $upload_name);
|
||||
print_r($meta);
|
||||
echo "\r\n done!";
|
||||
echo "</pre>";
|
||||
}
|
||||
|
||||
|
||||
// ================================================================================
|
||||
// store_token, load_token, delete_token are SAMPLE functions! please replace with your own!
|
||||
function store_token($token, $name)
|
||||
{
|
||||
file_put_contents("tokens/$name.token", serialize($token));
|
||||
}
|
||||
|
||||
function load_token($name)
|
||||
{
|
||||
if(!file_exists("tokens/$name.token")) return null;
|
||||
return @unserialize(@file_get_contents("tokens/$name.token"));
|
||||
}
|
||||
|
||||
function delete_token($name)
|
||||
{
|
||||
@unlink("tokens/$name.token");
|
||||
}
|
||||
// ================================================================================
|
||||
|
||||
function handle_dropbox_auth($dropbox)
|
||||
{
|
||||
// first try to load existing access token
|
||||
$access_token = load_token("access");
|
||||
if(!empty($access_token)) {
|
||||
$dropbox->SetAccessToken($access_token);
|
||||
}
|
||||
elseif(!empty($_GET['auth_callback'])) // are we coming from dropbox's auth page?
|
||||
{
|
||||
// then load our previosly created request token
|
||||
$request_token = load_token($_GET['oauth_token']);
|
||||
if(empty($request_token)) die('Request token not found!');
|
||||
|
||||
// get & store access token, the request token is not needed anymore
|
||||
$access_token = $dropbox->GetAccessToken($request_token);
|
||||
store_token($access_token, "access");
|
||||
delete_token($_GET['oauth_token']);
|
||||
}
|
||||
|
||||
// checks if access token is required
|
||||
if(!$dropbox->IsAuthorized())
|
||||
{
|
||||
// redirect user to dropbox auth page
|
||||
$return_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?auth_callback=1";
|
||||
$auth_url = $dropbox->BuildAuthorizeUrl($return_url);
|
||||
$request_token = $dropbox->GetRequestToken();
|
||||
store_token($request_token, $request_token['t']);
|
||||
die("Authentication required. <a href='$auth_url'>Click here.</a>");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
/**
|
||||
* DropPHP sample
|
||||
*
|
||||
* http://fabi.me/en/php-projects/dropphp-dropbox-api-client/
|
||||
*
|
||||
* @author Fabian Schlieper <[email protected]>
|
||||
* @copyright Fabian Schlieper 2012
|
||||
* @version 1.1
|
||||
* @license See license.txt
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
// these 2 lines are just to enable error reporting and disable output buffering (don't include this in you application!)
|
||||
error_reporting(E_ALL);
|
||||
enable_implicit_flush();
|
||||
// -- end of unneeded stuff
|
||||
|
||||
// if there are many files in your Dropbox it can take some time, so disable the max. execution time
|
||||
set_time_limit(0);
|
||||
|
||||
require_once("DropboxClient.php");
|
||||
|
||||
// you have to create an app at https://www.dropbox.com/developers/apps and enter details below:
|
||||
$dropbox = new DropboxClient(array(
|
||||
'app_key' => "ft0zodv89xx804e",
|
||||
'app_secret' => "ut43sn7m9wufy3s",
|
||||
'app_full_access' => true,
|
||||
),'it');
|
||||
|
||||
|
||||
// first try to load existing access token
|
||||
$access_token = load_token("access");
|
||||
if(!empty($access_token)) {
|
||||
$dropbox->SetAccessToken($access_token);
|
||||
echo "loaded access token:";
|
||||
print_r($access_token);
|
||||
}
|
||||
elseif(!empty($_GET['auth_callback'])) // are we coming from dropbox's auth page?
|
||||
{
|
||||
// then load our previosly created request token
|
||||
$request_token = load_token($_GET['oauth_token']);
|
||||
if(empty($request_token)) die('Request token not found!');
|
||||
|
||||
// get & store access token, the request token is not needed anymore
|
||||
$access_token = $dropbox->GetAccessToken($request_token);
|
||||
store_token($access_token, "access");
|
||||
delete_token($_GET['oauth_token']);
|
||||
}
|
||||
|
||||
// checks if access token is required
|
||||
if(!$dropbox->IsAuthorized())
|
||||
{
|
||||
// redirect user to dropbox auth page
|
||||
$return_url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?auth_callback=1";
|
||||
$auth_url = $dropbox->BuildAuthorizeUrl($return_url);
|
||||
$request_token = $dropbox->GetRequestToken();
|
||||
store_token($request_token, $request_token['t']);
|
||||
die("Authentication required. <a href='$auth_url'>Click here.</a>");
|
||||
}
|
||||
|
||||
echo "<pre>";
|
||||
echo "<b>Account:</b>\r\n";
|
||||
print_r($dropbox->GetAccountInfo());
|
||||
|
||||
$files = $dropbox->GetFiles("",false);
|
||||
|
||||
echo "\r\n\r\n<b>Files:</b>\r\n";
|
||||
print_r(array_keys($files));
|
||||
|
||||
if(!empty($files)) {
|
||||
$file = reset($files);
|
||||
$test_file = "test_download_".basename($file->path);
|
||||
|
||||
echo "\r\n\r\n<b>Meta data of <a href='".$dropbox->GetLink($file)."'>$file->path</a>:</b>\r\n";
|
||||
print_r($dropbox->GetMetadata($file->path));
|
||||
|
||||
echo "\r\n\r\n<b>Downloading $file->path:</b>\r\n";
|
||||
print_r($dropbox->DownloadFile($file, $test_file));
|
||||
|
||||
echo "\r\n\r\n<b>Uploading $test_file:</b>\r\n";
|
||||
print_r($dropbox->UploadFile($test_file));
|
||||
echo "\r\n done!";
|
||||
|
||||
echo "\r\n\r\n<b>Revisions of $test_file:</b>\r\n";
|
||||
print_r($dropbox->GetRevisions($test_file));
|
||||
}
|
||||
|
||||
echo "\r\n\r\n<b>Searching for JPG files:</b>\r\n";
|
||||
$jpg_files = $dropbox->Search("/", ".jpg", 5);
|
||||
if(empty($jpg_files))
|
||||
echo "Nothing found.";
|
||||
else {
|
||||
print_r($jpg_files);
|
||||
$jpg_file = reset($jpg_files);
|
||||
|
||||
echo "\r\n\r\n<b>Thumbnail of $jpg_file->path:</b>\r\n";
|
||||
$img_data = base64_encode($dropbox->GetThumbnail($jpg_file->path));
|
||||
echo "<img src=\"data:image/jpeg;base64,$img_data\" alt=\"Generating PDF thumbnail failed!\" style=\"border: 1px solid black;\" />";
|
||||
}
|
||||
|
||||
|
||||
function store_token($token, $name)
|
||||
{
|
||||
if(!file_put_contents("tokens/$name.token", serialize($token)))
|
||||
die('<br />Could not store token! <b>Make sure that the directory `tokens` exists and is writable!</b>');
|
||||
}
|
||||
|
||||
function load_token($name)
|
||||
{
|
||||
if(!file_exists("tokens/$name.token")) return null;
|
||||
return @unserialize(@file_get_contents("tokens/$name.token"));
|
||||
}
|
||||
|
||||
function delete_token($name)
|
||||
{
|
||||
@unlink("tokens/$name.token");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
function enable_implicit_flush()
|
||||
{
|
||||
@apache_setenv('no-gzip', 1);
|
||||
@ini_set('zlib.output_compression', 0);
|
||||
@ini_set('implicit_flush', 1);
|
||||
for ($i = 0; $i < ob_get_level(); $i++) { ob_end_flush(); }
|
||||
ob_implicit_flush(1);
|
||||
echo "<!-- ".str_repeat(' ', 2000)." -->";
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"error": "File not found"}
|
||||
@@ -0,0 +1 @@
|
||||
a:2:{s:1:"t";s:16:"2lfmugdr7rp3yp2q";s:1:"s";s:15:"i3nrl13aduhhufw";}
|
||||
+37
-40
@@ -2,88 +2,85 @@
|
||||
class MysqlClass
|
||||
{
|
||||
// parametri per la connessione al database
|
||||
/*private $nomehost = "mysql.hostinger.it";
|
||||
private $nomeuser = "u766568765_lpm";
|
||||
private $password = "8zX2gTIjfwXEdEgaSaWe";
|
||||
private $mydb = "u766568765_lpm";
|
||||
*/
|
||||
private $nomehost = "localhost";
|
||||
private $nomeuser = "root";
|
||||
private $password = "root";
|
||||
private $mydb = "w18092_ricettario";
|
||||
/*
|
||||
private $nomehost = "sql.gruppolapastamadre.it";
|
||||
private $nomeuser = "w18092_ricuser";
|
||||
private $password = "RTvg0o6IESoqQyx8CCJn";
|
||||
private $mydb = "w18092_ricettario";
|
||||
|
||||
*/
|
||||
// controllo sulle connessioni attive
|
||||
private $attiva = false;
|
||||
private $connessione = null;
|
||||
|
||||
// funzione per la connessione a MySQL
|
||||
public function connetti()
|
||||
{
|
||||
if(!$this->attiva)
|
||||
{
|
||||
$this->connessione = mysql_connect($this->nomehost,$this->nomeuser,$this->password);
|
||||
public function connetti() {
|
||||
if (!$this->attiva) {
|
||||
$this->connessione = mysqli_connect($this->nomehost, $this->nomeuser, $this->password);
|
||||
if ($this->connessione == FALSE)
|
||||
die(mysql_error());
|
||||
mysql_select_db($this->mydb, $this->connessione) or die ("Errore nella selezione del database. Verificare i parametri nel file config.inc.php");
|
||||
die(mysqli_error());
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function executeQuery($queryStr)
|
||||
{
|
||||
public function executeQuery($queryStr) {
|
||||
$this->connetti();
|
||||
|
||||
if (!$res = mysql_query($queryStr, $this->connessione)) die(mysql_error());
|
||||
if (!$res = mysqli_query($this->connessione, $queryStr))
|
||||
die(mysqli_error());
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public function insertRecord($queryStr)
|
||||
{
|
||||
public function insertRecord($queryStr) {
|
||||
$this->connetti();
|
||||
|
||||
if (!$res = mysql_query($queryStr, $this->connessione)) die(mysql_error());
|
||||
return mysql_insert_id();
|
||||
if (!$res = mysqli_query($this->connessione, $queryStr))
|
||||
die(mysqli_error());
|
||||
return mysqli_insert_id($this->connessione);
|
||||
}
|
||||
|
||||
public function queryToObject($queryStr)
|
||||
{
|
||||
public function queryToObject($queryStr, $encode = true) {
|
||||
$this->connetti();
|
||||
|
||||
$sth = mysql_query($queryStr, $this->connessione) or die(mysql_error());
|
||||
$sth = mysqli_query($this->connessione, $queryStr) or die(mysqli_error());
|
||||
|
||||
if($encode){
|
||||
$rows = array();
|
||||
while($r = mysql_fetch_assoc($sth)) {
|
||||
while ($r = mysqli_fetch_assoc($sth)) {
|
||||
array_push($rows, array_map('utf8_encode', $r));
|
||||
}
|
||||
mysql_free_result($sth);
|
||||
mysqli_free_result($sth);
|
||||
return $rows;
|
||||
}
|
||||
|
||||
// funzione per la chiusura della connessione
|
||||
public function disconnetti()
|
||||
{
|
||||
if($this->attiva)
|
||||
{
|
||||
if(mysql_close($this->connessione))
|
||||
{
|
||||
$this->attiva = false;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return mysqli_fetch_array($sth);
|
||||
}
|
||||
}
|
||||
|
||||
// funzione per la chiusura della connessione
|
||||
public function disconnetti() {
|
||||
if ($this->attiva) {
|
||||
if (mysqli_close($this->connessione)) {
|
||||
$this->attiva = false;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function __destruct()
|
||||
{
|
||||
public function __destruct() {
|
||||
$this->disconnetti();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Binary file not shown.
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
@@ -140,7 +140,10 @@ class Environment implements \ArrayAccess, \IteratorAggregate
|
||||
$env['SCRIPT_NAME'] = rtrim($physicalPath, '/'); // <-- Remove trailing slashes
|
||||
|
||||
// Virtual path
|
||||
$env['PATH_INFO'] = substr_replace($requestUri, '', 0, strlen($physicalPath)); // <-- Remove physical path
|
||||
$env['PATH_INFO'] = $requestUri;
|
||||
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'] = '/' . ltrim($env['PATH_INFO'], '/'); // <-- Ensure leading slash
|
||||
|
||||
@@ -151,7 +154,8 @@ class Environment implements \ArrayAccess, \IteratorAggregate
|
||||
$env['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
|
||||
|
||||
//Number of server port that is running the script
|
||||
$env['SERVER_PORT'] = $_SERVER['SERVER_PORT'];
|
||||
//Fixes: https://github.com/slimphp/Slim/issues/962
|
||||
$env['SERVER_PORT'] = isset($_SERVER['SERVER_PORT']) ? $_SERVER['SERVER_PORT'] : 80;
|
||||
|
||||
//HTTP request headers (retains HTTP_ prefix to match $_SERVER)
|
||||
$headers = \Slim\Http\Headers::extract($_SERVER);
|
||||
@@ -191,9 +195,9 @@ class Environment implements \ArrayAccess, \IteratorAggregate
|
||||
{
|
||||
if (isset($this->properties[$offset])) {
|
||||
return $this->properties[$offset];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
|
||||
+5
-5
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
@@ -160,7 +160,7 @@ class Set implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
|
||||
public function __unset($key)
|
||||
{
|
||||
return $this->remove($key);
|
||||
$this->remove($key);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -216,7 +216,7 @@ class Set implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
/**
|
||||
* Ensure a value or object will remain globally unique
|
||||
* @param string $key The value or object name
|
||||
* @param Closure The closure that defines the object
|
||||
* @param \Closure $value The closure that defines the object
|
||||
* @return mixed
|
||||
*/
|
||||
public function singleton($key, $value)
|
||||
@@ -234,8 +234,8 @@ class Set implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
|
||||
/**
|
||||
* Protect closure from being directly invoked
|
||||
* @param Closure $callable A closure to keep from being invoked and evaluated
|
||||
* @return Closure
|
||||
* @param \Closure $callable A closure to keep from being invoked and evaluated
|
||||
* @return \Closure
|
||||
*/
|
||||
public function protect(\Closure $callable)
|
||||
{
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
@@ -169,9 +169,9 @@ class Request
|
||||
return true;
|
||||
} elseif (isset($this->headers['X_REQUESTED_WITH']) && $this->headers['X_REQUESTED_WITH'] === 'XMLHttpRequest') {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+10
-2
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
@@ -85,6 +85,7 @@ class Response implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
204 => '204 No Content',
|
||||
205 => '205 Reset Content',
|
||||
206 => '206 Partial Content',
|
||||
226 => '226 IM Used',
|
||||
//Redirection 3xx
|
||||
300 => '300 Multiple Choices',
|
||||
301 => '301 Moved Permanently',
|
||||
@@ -116,13 +117,20 @@ class Response implements \ArrayAccess, \Countable, \IteratorAggregate
|
||||
418 => '418 I\'m a teapot',
|
||||
422 => '422 Unprocessable Entity',
|
||||
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
|
||||
500 => '500 Internal Server Error',
|
||||
501 => '501 Not Implemented',
|
||||
502 => '502 Bad Gateway',
|
||||
503 => '503 Service Unavailable',
|
||||
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
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
@@ -60,9 +60,9 @@ class Util
|
||||
$strip = is_null($overrideStripSlashes) ? get_magic_quotes_gpc() : $overrideStripSlashes;
|
||||
if ($strip) {
|
||||
return self::stripSlashes($rawData);
|
||||
} else {
|
||||
return $rawData;
|
||||
}
|
||||
|
||||
return $rawData;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+6
-1
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
@@ -306,7 +306,12 @@ class Log
|
||||
if (!isset(self::$levels[$level])) {
|
||||
throw new \InvalidArgumentException('Invalid log level supplied to function');
|
||||
} else if ($this->enabled && $this->writer && $level <= $this->level) {
|
||||
if (is_array($object) || (is_object($object) && !method_exists($object, "__toString"))) {
|
||||
$message = print_r($object, true);
|
||||
} else {
|
||||
$message = (string) $object;
|
||||
}
|
||||
|
||||
if (count($context) > 0) {
|
||||
if (isset($context['exception']) && $context['exception'] instanceof \Exception) {
|
||||
$message .= ' - ' . $context['exception'];
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
@@ -116,7 +116,7 @@ class ContentTypes extends \Slim\Middleware
|
||||
{
|
||||
if (function_exists('json_decode')) {
|
||||
$result = json_decode($input, true);
|
||||
if ($result) {
|
||||
if(json_last_error() === JSON_ERROR_NONE) {
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
@@ -89,7 +89,7 @@ class PrettyExceptions extends \Slim\Middleware
|
||||
$message = $exception->getMessage();
|
||||
$file = $exception->getFile();
|
||||
$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 .= '<p>The application could not run because of the following error:</p>';
|
||||
$html .= '<h2>Details</h2>';
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
@@ -119,15 +119,10 @@ class SessionCookie extends \Slim\Middleware
|
||||
if (session_id() === '') {
|
||||
session_start();
|
||||
}
|
||||
|
||||
$value = $this->app->getCookie($this->settings['name']);
|
||||
|
||||
if ($value) {
|
||||
try {
|
||||
$_SESSION = unserialize($value);
|
||||
} catch (\Exception $e) {
|
||||
$this->app->getLog()->error('Error unserializing session cookie value! ' . $e->getMessage());
|
||||
}
|
||||
$value = json_decode($value, true);
|
||||
$_SESSION = is_array($value) ? $value : array();
|
||||
} else {
|
||||
$_SESSION = array();
|
||||
}
|
||||
@@ -138,7 +133,7 @@ class SessionCookie extends \Slim\Middleware
|
||||
*/
|
||||
protected function saveSession()
|
||||
{
|
||||
$value = serialize($_SESSION);
|
||||
$value = json_encode($_SESSION);
|
||||
|
||||
if (strlen($value) > 4096) {
|
||||
$this->app->getLog()->error('WARNING! Slim\Middleware\SessionCookie data size is larger than 4KB. Content save failed.');
|
||||
|
||||
+7
-1
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
@@ -288,6 +288,9 @@ class Route
|
||||
public function appendHttpMethods()
|
||||
{
|
||||
$args = func_get_args();
|
||||
if(count($args) && is_array($args[0])){
|
||||
$args = $args[0];
|
||||
}
|
||||
$this->methods = array_merge($this->methods, $args);
|
||||
}
|
||||
|
||||
@@ -298,6 +301,9 @@ class Route
|
||||
public function via()
|
||||
{
|
||||
$args = func_get_args();
|
||||
if(count($args) && is_array($args[0])){
|
||||
$args = $args[0];
|
||||
}
|
||||
$this->methods = array_merge($this->methods, $args);
|
||||
|
||||
return $this;
|
||||
|
||||
+3
-3
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
@@ -232,9 +232,9 @@ class Router
|
||||
$this->getNamedRoutes();
|
||||
if ($this->hasNamedRoute($name)) {
|
||||
return $this->namedRoutes[(string) $name];
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+42
-10
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
@@ -54,7 +54,7 @@ class Slim
|
||||
/**
|
||||
* @const string
|
||||
*/
|
||||
const VERSION = '2.4.2';
|
||||
const VERSION = '2.6.1';
|
||||
|
||||
/**
|
||||
* @var \Slim\Helper\Set
|
||||
@@ -231,22 +231,22 @@ class Slim
|
||||
|
||||
public function __get($name)
|
||||
{
|
||||
return $this->container[$name];
|
||||
return $this->container->get($name);
|
||||
}
|
||||
|
||||
public function __set($name, $value)
|
||||
{
|
||||
$this->container[$name] = $value;
|
||||
$this->container->set($name, $value);
|
||||
}
|
||||
|
||||
public function __isset($name)
|
||||
{
|
||||
return isset($this->container[$name]);
|
||||
return $this->container->has($name);
|
||||
}
|
||||
|
||||
public function __unset($name)
|
||||
{
|
||||
unset($this->container[$name]);
|
||||
$this->container->remove($name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -906,7 +906,12 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1100,6 +1105,18 @@ class Slim
|
||||
$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
|
||||
*******************************************************************************/
|
||||
@@ -1138,6 +1155,16 @@ class Slim
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all flash messages
|
||||
*/
|
||||
public function flashData()
|
||||
{
|
||||
if (isset($this->environment['slim.flash'])) {
|
||||
return $this->environment['slim.flash']->getMessages();
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************************
|
||||
* Hooks
|
||||
*******************************************************************************/
|
||||
@@ -1161,9 +1188,9 @@ class Slim
|
||||
/**
|
||||
* Invoke hook
|
||||
* @param string $name The hook name
|
||||
* @param mixed $hookArg (Optional) Argument for hooked functions
|
||||
* @param mixed ... (Optional) Argument(s) for hooked functions, can specify multiple arguments
|
||||
*/
|
||||
public function applyHook($name, $hookArg = null)
|
||||
public function applyHook($name)
|
||||
{
|
||||
if (!isset($this->hooks[$name])) {
|
||||
$this->hooks[$name] = array(array());
|
||||
@@ -1173,10 +1200,14 @@ class Slim
|
||||
if (count($this->hooks[$name]) > 1) {
|
||||
ksort($this->hooks[$name]);
|
||||
}
|
||||
|
||||
$args = func_get_args();
|
||||
array_shift($args);
|
||||
|
||||
foreach ($this->hooks[$name] as $priority) {
|
||||
if (!empty($priority)) {
|
||||
foreach ($priority as $callable) {
|
||||
call_user_func($callable, $hookArg);
|
||||
call_user_func_array($callable, $args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1344,6 +1375,7 @@ class Slim
|
||||
throw $e;
|
||||
} else {
|
||||
try {
|
||||
$this->response()->write(ob_get_clean());
|
||||
$this->error($e);
|
||||
} catch (\Slim\Exception\Stop $e) {
|
||||
// Do nothing
|
||||
|
||||
+4
-4
@@ -6,7 +6,7 @@
|
||||
* @copyright 2011 Josh Lockhart
|
||||
* @link http://www.slimframework.com
|
||||
* @license http://www.slimframework.com/license
|
||||
* @version 2.4.2
|
||||
* @version 2.6.1
|
||||
* @package Slim
|
||||
*
|
||||
* MIT LICENSE
|
||||
@@ -108,7 +108,7 @@ class View
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
*/
|
||||
public function keep($key, Closure $value)
|
||||
public function keep($key, \Closure $value)
|
||||
{
|
||||
$this->data->keep($key, $value);
|
||||
}
|
||||
@@ -152,9 +152,9 @@ class View
|
||||
{
|
||||
if (!is_null($key)) {
|
||||
return isset($this->data[$key]) ? $this->data[$key] : null;
|
||||
} else {
|
||||
return $this->data->all();
|
||||
}
|
||||
|
||||
return $this->data->all();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,13 @@
|
||||
|
||||
$allowedHost = array(
|
||||
"localhost",
|
||||
"denisnotebook",
|
||||
"app.gruppolapastamadre.it",
|
||||
"dev.gruppolapastamadre.it",
|
||||
"blog.gruppolapastamadre.it",
|
||||
"management.gruppolapastamadre.it"
|
||||
);
|
||||
|
||||
$dirRicetteDropBox = "IlLievitario/Images/Ricette";
|
||||
|
||||
?>
|
||||
@@ -1,103 +1,97 @@
|
||||
<?php
|
||||
|
||||
// inclusione del file contenente la classe
|
||||
require_once "./include.php";
|
||||
use PHPImageWorkshop\ImageWorkshop;
|
||||
require_once('PHPImageWorkshop/ImageWorkshop.php'); // Be sure of the path to the class
|
||||
|
||||
require_once "./myDropBoxObj.php";
|
||||
//include "./SimpleImage.php";
|
||||
|
||||
$app->get('/photos/thumbnail/:imageID(/:createImgTag)', function ($imageID, $createImgTag = 0) use ($app) {
|
||||
$app->get('/photo/thumbnail/:imageID(/:noRedirect)', function ($imageID, $noRedirect = 0) use ($app, $dirRicetteDropBox) {
|
||||
$mysqlconnetion = new MysqlClass;
|
||||
|
||||
$retObj = $mysqlconnetion->queryToObject("select type_format, image_thumbnail from immagini where id=" . $imageID, false);
|
||||
$retObj = $mysqlconnetion->queryToObject("select type_format, id_ricette, thumb_link from immagini where id=" . $imageID, false);
|
||||
$mysqlconnetion->disconnetti();
|
||||
|
||||
if($createImgTag)
|
||||
echo '<img src="data:' . $retObj["type_format"] . ';base64,' . base64_encode($retObj['image_thumbnail']) . '"/>';
|
||||
else
|
||||
{
|
||||
$app->contentType($retObj["type_format"]);
|
||||
echo $retObj['image_thumbnail'];
|
||||
|
||||
$ext = "png";
|
||||
|
||||
$retLink = $retObj["thumb_link"];
|
||||
|
||||
if($retLink == ""){
|
||||
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
||||
|
||||
$imageFileName = $imageID . "_thumb_ricetta." . $ext;
|
||||
|
||||
$dropBoxObj = new myDropBox();
|
||||
|
||||
$retLink = $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
||||
}
|
||||
|
||||
if ($noRedirect) {
|
||||
echo $retLink;
|
||||
}
|
||||
else
|
||||
$app->response->redirect($retLink, 303);
|
||||
});
|
||||
|
||||
$app->get('/photos/:imageID(/:createImgTag)', function ($imageID, $createImgTag = 0) use ($app) {
|
||||
|
||||
$app->get('/photo/medium/:imageID(/:noRedirect)', function ($imageID, $noRedirect = 0) use ($app, $dirRicetteDropBox) {
|
||||
$mysqlconnetion = new MysqlClass;
|
||||
|
||||
$retObj = $mysqlconnetion->queryToObject("select type_format, image from immagini where id=" . $imageID, false);
|
||||
$retObj = $mysqlconnetion->queryToObject("select type_format, id_ricette, medium_link from immagini where id=" . $imageID, false);
|
||||
$mysqlconnetion->disconnetti();
|
||||
$ext = "";
|
||||
if ($retObj["type_format"] == "image/jpeg") {
|
||||
$ext = "jpeg";
|
||||
} else if ($retObj["type_format"] == "image/png") {
|
||||
$ext = "png";
|
||||
}
|
||||
|
||||
if($createImgTag)
|
||||
echo '<img src="';
|
||||
echo 'data:' . $retObj["type_format"] . ';base64,'.base64_encode( $retObj['image'] );
|
||||
if($createImgTag)
|
||||
echo '"/>';
|
||||
$retLink = $retObj["medium_link"];
|
||||
|
||||
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->put('/photos/publish/:imageID', function ($imageID) use ($app) {
|
||||
$app->get('/photo/:imageID(/:noRedirect)', function ($imageID, $noRedirect = 0) use ($app, $dirRicetteDropBox) {
|
||||
$mysqlconnetion = new MysqlClass;
|
||||
|
||||
$query = "update immagini set published = 1, published_date = NOW() where ProfiloID = " . $imageID;
|
||||
$mysqlconnetion->disconnetti();
|
||||
$mysqlconnetion->insertRecord($query);
|
||||
$retObj = $mysqlconnetion->queryToObject("select type_format, id_ricette, full_link from immagini where id=" . $imageID, false);
|
||||
$mysqlconnetion->disconnetti();
|
||||
});
|
||||
$ext = "";
|
||||
if ($retObj["type_format"] == "image/jpeg") {
|
||||
$ext = "jpeg";
|
||||
} else if ($retObj["type_format"] == "image/png") {
|
||||
$ext = "png";
|
||||
}
|
||||
|
||||
$app->post('/photos', function () use ($app) {
|
||||
$idRicette = $app->request()->post('ricetta_id');
|
||||
$profileID = $app->request()->post('keyStore');
|
||||
$imageFileName = $_FILES['image']["tmp_name"];
|
||||
$retLink = $retObj["full_link"];
|
||||
|
||||
$layer = ImageWorkshop::initFromPath($imageFileName);
|
||||
$layer->resizeByLargestSideInPixel(640, true);
|
||||
if($retLink == ""){
|
||||
$folder = $dirRicetteDropBox . "/" . $retObj["id_ricette"];
|
||||
|
||||
$layer->save(dirname($imageFileName), basename($imageFileName));
|
||||
$imageFileName = $imageID . "_full_ricetta." . $ext;
|
||||
|
||||
$imgData = addslashes(file_get_contents($imageFileName));
|
||||
$dropBoxObj = new myDropBox();
|
||||
|
||||
$layer->resizeByLargestSideInPixel(300, true);
|
||||
$retLink = $dropBoxObj->GetLink($folder . "/" . $imageFileName);
|
||||
}
|
||||
|
||||
$layer->save(dirname($imageFileName), basename($imageFileName));
|
||||
|
||||
$ThumbImageData = addslashes(file_get_contents($imageFileName));
|
||||
|
||||
// istanza della classe
|
||||
$mysqlconnetion = new MysqlClass;
|
||||
//$mysqlconneti on->connetti();
|
||||
$query = "insert into immagini(id_ricette, type_format, image_thumbnail, image, from_profile_id, uploaded_date) " .
|
||||
"values(" . $idRicette . ", '" . image_type_to_mime_type($image->image_type) .
|
||||
"', '" . $ThumbImageData . "', '" . $imgData . "', '" . $profileID . "', NOW())";
|
||||
$newID = $mysqlconnetion->insertRecord($query);
|
||||
$mysqlconnetion->disconnetti();
|
||||
|
||||
echo $newID;
|
||||
});
|
||||
|
||||
$app->put('/photos/:imageID', function ($imageID) use ($app) {
|
||||
$imageFileName = $_FILES['image']["tmp_name"];
|
||||
|
||||
$layer = ImageWorkshop::initFromPath($imageFileName);
|
||||
$layer->resizeByLargestSideInPixel(640, true);
|
||||
|
||||
$layer->save(dirname($imageFileName), basename($imageFileName));
|
||||
|
||||
$imgData = addslashes(file_get_contents($imageFileName));
|
||||
|
||||
$layer->resizeByLargestSideInPixel(300, true);
|
||||
|
||||
$layer->save(dirname($imageFileName), basename($imageFileName));
|
||||
|
||||
$ThumbImageData = addslashes(file_get_contents($imageFileName));
|
||||
|
||||
// istanza della classe
|
||||
$mysqlconnetion = new MysqlClass;
|
||||
//$mysqlconneti on->connetti();
|
||||
$query = "update immagini set (type_format = '" . image_type_to_mime_type($image->image_type) . "', " .
|
||||
"image_thumbnail = '" . $ThumbImageData . "', " .
|
||||
"image = '" . $imgData . "' where id=" . $imageID;
|
||||
|
||||
$newID = $mysqlconnetion->insertRecord($query);
|
||||
$mysqlconnetion->disconnetti();
|
||||
|
||||
return $newID;
|
||||
if ($noRedirect) {
|
||||
echo $retLink;
|
||||
}
|
||||
else
|
||||
$app->response->redirect($retLink, 303);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,197 @@
|
||||
<?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->get('/photo/set_cover/:imageID', function ($imageID) use ($app) {
|
||||
$mysqlconnetion = new MysqlClass;
|
||||
|
||||
$query = "select id_ricette from immagini where id = " . $imageID;
|
||||
$retObj = $mysqlconnetion->queryToObject($query, false);
|
||||
|
||||
$query = "update immagini set bCover = 0 where id_ricette = " . $retObj["id_ricette"];
|
||||
$mysqlconnetion->insertRecord($query);
|
||||
|
||||
$query = "update immagini set bCover = 1 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, bCover) " .
|
||||
"values(" . $idRicette . ", '" . image_type_to_mime_type(exif_imagetype($tmpFileName)) .
|
||||
"', '" . $profileID . "', NOW(), 0)";
|
||||
$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();
|
||||
});
|
||||
+12
-2
@@ -12,19 +12,29 @@ require_once 'Slim/Slim.php';
|
||||
|
||||
$app = new \Slim\Slim();
|
||||
|
||||
date_default_timezone_set('Europe/Rome');
|
||||
|
||||
$app->hook('slim.before.router', function () use ($app, $allowedHost) {
|
||||
$currentRefererRequest = $app->request()->getReferer();
|
||||
$currentRefererRequest = substr(substr($currentRefererRequest, 7), 0, strpos(substr($currentRefererRequest, 7), '/'));
|
||||
/*$currentRefererRequest = $app->request()->getReferer();
|
||||
$currentRefererRequest = substr($currentRefererRequest, 7); //Senza http://
|
||||
$indexDoublePoint = strpos($currentRefererRequest, ':');
|
||||
$indexFirstSlash = strpos($currentRefererRequest, '/');
|
||||
$currentRefererRequest = substr($currentRefererRequest, 0, $indexDoublePoint > 0 && $indexDoublePoint < $indexFirstSlash ? $indexDoublePoint : $indexFirstSlash );
|
||||
if(!in_array($currentRefererRequest, $allowedHost))
|
||||
{
|
||||
$app->halt(500, "Generic error occurred");
|
||||
return;
|
||||
}
|
||||
|
||||
$currentHostRequest = $app->request()->getHost();
|
||||
if(!in_array($currentHostRequest, $allowedHost))
|
||||
{
|
||||
$app->halt(403, "Request arrive from host not allowed " . $currentHostRequest );
|
||||
return;
|
||||
}
|
||||
*/
|
||||
if(isset($_SERVER['HTTP_ORIGIN']))
|
||||
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
|
||||
});
|
||||
|
||||
|
||||
|
||||
+90
-4
@@ -30,7 +30,7 @@ $app->get('/typeqtys', function () use ($app) {
|
||||
returnJsonWithDecode($app, $callbackFn, $retObj);
|
||||
});
|
||||
|
||||
$app->get('/categoryitems/:catID', function ($categoryID) use ($app) {
|
||||
$app->get('/ricette/:catID', function ($categoryID) use ($app) {
|
||||
$callbackFn = $app->request()->get('callback');
|
||||
$mysqlconnetion = new MysqlClass;
|
||||
//$mysqlconnetion->connetti();
|
||||
@@ -55,6 +55,10 @@ $app->get('/ricetta/body/:itemID', function ($itemID) use ($app) {
|
||||
|
||||
$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]["procedimento"] = html_entity_decode($retObj[0]["procedimento"],ENT_COMPAT | ENT_HTML401,'ISO-8859-1');
|
||||
$retObj[0]["ingredienti"] = $retObj2;
|
||||
@@ -98,6 +102,10 @@ $app->post('/ricetta/body', function () use ($app) {
|
||||
$mysqlconnetion->executeQuery($query);
|
||||
$queryDelete = "DELETE FROM ingredienti where ID_RICETTE = " . $json_data_body->ricettaID;
|
||||
$mysqlconnetion->executeQuery($queryDelete);
|
||||
|
||||
$queryUpdDataMod = "UPDATE ricette SET data_modifica = NOW() where ID = " . $json_data_body->ricettaID;
|
||||
$mysqlconnetion->executeQuery($queryUpdDataMod);
|
||||
|
||||
$retNewID = $json_data_body->ricettaID;
|
||||
} else {
|
||||
|
||||
@@ -113,18 +121,48 @@ $app->post('/ricetta/body', function () use ($app) {
|
||||
foreach ($json_data_body->ingredienti as $arr) {
|
||||
$note = "";
|
||||
if ($arr->note != "") {
|
||||
$note = str_replace("'", "''", htmlentities($arr->note));
|
||||
$note = str_replace("'", "''", htmlentities($arr->note, null, "UTF-8"));
|
||||
}
|
||||
|
||||
$query = "insert into ingredienti(ID_TIPO_INGREDIENTI, ID_RICETTE, Quantita, ID_TIPO_QUANTITA, Note, Posizione) values (" .
|
||||
$arr->ingrediente_id . "," . $retNewID . "," . ($arr->quantita == "" ? "0" : $arr->quantita) . "," . ($arr->tipo_quantita_id == "" ? "NULL" : $arr->tipo_quantita_id) . ",'" . $note . "'," . $pos . ")";
|
||||
$arr->ingrediente_id . "," . $retNewID . ",'" . ($arr->quantita == "" ? "0" : $arr->quantita) . "'," . ($arr->tipo_quantita_id == "" ? "NULL" : $arr->tipo_quantita_id) . ",'" . $note . "'," . $pos . ")";
|
||||
|
||||
$mysqlconnetion->insertRecord($query);
|
||||
$pos = $pos + 1;
|
||||
}
|
||||
|
||||
$retValue["ricettaID"] = $retNewID;
|
||||
$retValue["message"] = "Ricetta inserita con successo";
|
||||
} catch (Exception $e) {
|
||||
$retValue["result"] = false;
|
||||
$retValue["message"] = $e->getMessage();
|
||||
}
|
||||
|
||||
$mysqlconnetion->disconnetti();
|
||||
|
||||
returnJson($app, $callbackFn, $retValue);
|
||||
});
|
||||
|
||||
$app->delete('/ricetta/:itemID', function ($itemID) use ($app) {
|
||||
$callbackFn = $app->request()->get('callback');
|
||||
$retValue["result"] = true;
|
||||
$retValue["message"] = "";
|
||||
$mysqlconnetion = new MysqlClass;
|
||||
try {
|
||||
$queryDelete = "DELETE FROM immagini where id_ricette = " . $itemID;
|
||||
$mysqlconnetion->executeQuery($queryDelete);
|
||||
|
||||
$queryDelete = "DELETE FROM blocco_note where ricetta_id = " . $itemID;
|
||||
$mysqlconnetion->executeQuery($queryDelete);
|
||||
|
||||
$queryDelete = "DELETE FROM ingredienti where ID_RICETTE = " . $itemID;
|
||||
$mysqlconnetion->executeQuery($queryDelete);
|
||||
|
||||
$queryDelete = "DELETE FROM ricette where ID = " . $itemID;
|
||||
$mysqlconnetion->executeQuery($queryDelete);
|
||||
$retValue["message"] = "Ricetta cancellata con successo";
|
||||
} catch (Exception $e) {
|
||||
$retValue["result"] = false;
|
||||
$retValue["message"] = $e->getMessage();
|
||||
}
|
||||
|
||||
@@ -153,7 +191,7 @@ $app->get('/photos/', function () use ($app) {
|
||||
$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" .
|
||||
$query = "SELECT id as id_photo, type_format, from_profile_id, uploaded_date, profilo.Name as profile_name, published, bCover from immagini" .
|
||||
" INNER JOIN profilo ON profilo.ProfiloID = immagini.from_profile_id".
|
||||
" WHERE id_ricette = " . $itemID;
|
||||
|
||||
@@ -163,3 +201,51 @@ $app->get('/ricetta/:itemID/photos', function ($itemID) use ($app) {
|
||||
$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,86 @@
|
||||
<?php
|
||||
|
||||
require_once("./DropBoxPhp/DropboxClient.php");
|
||||
|
||||
class myDropBox {
|
||||
|
||||
private $dropbox = null;
|
||||
|
||||
// costruttore
|
||||
public function __construct() {
|
||||
// you have to create an app at https://www.dropbox.com/developers/apps and enter details below:
|
||||
$this->dropbox = new DropboxClient(
|
||||
array(
|
||||
'app_key' => "ft0zodv89xx804e",
|
||||
'app_secret' => "ut43sn7m9wufy3s",
|
||||
'app_full_access' => true
|
||||
), 'it');
|
||||
$this->internalLoad();
|
||||
}
|
||||
|
||||
protected function internalLoad() {
|
||||
// first try to load existing access token
|
||||
$access_token = $this->load_token("access");
|
||||
if (!empty($access_token)) {
|
||||
$this->dropbox->SetAccessToken($access_token);
|
||||
//echo "loaded access token:";
|
||||
//print_r($access_token);
|
||||
} elseif (!empty($_GET['auth_callback'])) { // are we coming from dropbox's auth page?
|
||||
// then load our previosly created request token
|
||||
$request_token = $this->load_token($_GET['oauth_token']);
|
||||
if (empty($request_token))
|
||||
die('Request token not found!');
|
||||
// get & store access token, the request token is not needed anymore
|
||||
$access_token = $this->dropbox->GetAccessToken($request_token);
|
||||
$this->store_token($access_token, "access");
|
||||
$this->delete_token($_GET['oauth_token']);
|
||||
}
|
||||
// checks if access token is required
|
||||
if (!$this->dropbox->IsAuthorized()) {
|
||||
// redirect user to dropbox auth page
|
||||
$return_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['SCRIPT_NAME'] . "?auth_callback=1";
|
||||
$auth_url = $this->dropbox->BuildAuthorizeUrl($return_url);
|
||||
$request_token = $this->dropbox->GetRequestToken();
|
||||
$this->store_token($request_token, $request_token['t']);
|
||||
die("Authentication required. <a href='$auth_url'>Click here.</a>");
|
||||
}
|
||||
}
|
||||
|
||||
public function UploadFile($fileToUpload, $dropBoxPath) {
|
||||
$ret = $this->dropbox->UploadFile($fileToUpload, $dropBoxPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function GetLink($dropBoxPathFile) {
|
||||
$exp = null;
|
||||
$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) {
|
||||
$ret = $this->dropbox->CreateFolder($dropBoxPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function Delete($dropBoxPath) {
|
||||
$ret = $this->dropbox->Delete($dropBoxPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
private function store_token($token, $name) {
|
||||
if (!file_put_contents("tokens/$name.token", serialize($token)))
|
||||
die('<br />Could not store token! <b>Make sure that the directory `tokens` exists and is writable!</b>');
|
||||
}
|
||||
|
||||
private function load_token($name) {
|
||||
if (!file_exists("tokens/$name.token"))
|
||||
return null;
|
||||
return @unserialize(@file_get_contents("tokens/$name.token"));
|
||||
}
|
||||
|
||||
private function delete_token($name) {
|
||||
@unlink("tokens/$name.token");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
copy.src.files=false
|
||||
copy.src.on.open=false
|
||||
copy.src.target=
|
||||
index.file=
|
||||
run.as=LOCAL
|
||||
url=http://localhost:8081/Service_Manut/
|
||||
@@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
|
||||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
|
||||
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
|
||||
<group/>
|
||||
</open-files>
|
||||
</project-private>
|
||||
@@ -0,0 +1,7 @@
|
||||
include.path=${php.global.include.path}
|
||||
php.version=PHP_54
|
||||
source.encoding=UTF-8
|
||||
src.dir=.
|
||||
tags.asp=false
|
||||
tags.short=false
|
||||
web.root=.
|
||||
@@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||
<type>org.netbeans.modules.php.project</type>
|
||||
<configuration>
|
||||
<data xmlns="http://www.netbeans.org/ns/php-project/1">
|
||||
<name>Service_Manut</name>
|
||||
</data>
|
||||
</configuration>
|
||||
</project>
|
||||
+76
-5
@@ -4,6 +4,19 @@
|
||||
//include "./MySqlClass.php";
|
||||
//include "./utility.php";
|
||||
|
||||
$app->get('/profile/statusCache', function () use ($app) {
|
||||
$callbackFn = $app->request()->get('callback');
|
||||
$mysqlconnetion = new MysqlClass;
|
||||
$query = "select 0 as ID_CATEGORIA, MAX(data_creazione) as LastDateModified from categorie" .
|
||||
" UNION" .
|
||||
" select ID_CATEGORIA, MAX(Data_modifica) as LastDateModified from ricette" .
|
||||
" GROUP BY ID_CATEGORIA";
|
||||
$retObj = $mysqlconnetion->queryToObject($query);
|
||||
$mysqlconnetion->disconnetti();
|
||||
|
||||
returnJson($app, $callbackFn, $retObj);
|
||||
});
|
||||
|
||||
$app->get('/profile/:keyStore/ricetta/:ricetta_id', function ($keyStore, $ricetta_id) use ($app) {
|
||||
$callbackFn = $app->request()->get('callback');
|
||||
$mysqlconnetion = new MysqlClass;
|
||||
@@ -18,10 +31,11 @@ $app->post('/profile/ricetta', function () use ($app) {
|
||||
$callbackFn = $app->request()->get('callback');
|
||||
$json_data_body = json_decode($app->request()->post('dataPair'));
|
||||
$mysqlconnetion = new MysqlClass;
|
||||
$query = "update profilo set BloccoNoteUpdated = CURRENT_TIMESTAMP WHERE ProfiloID = '" . $json_data_body->keyStore . "'";
|
||||
$retNewID = $mysqlconnetion->insertRecord($query);
|
||||
$query = "insert into blocco_note(ricetta_id, ProfiloID) values (" . $json_data_body->ricetta_id . ", '" . $json_data_body->keyStore . "')";
|
||||
$retNewID = $mysqlconnetion->insertRecord($query);
|
||||
$mysqlconnetion->disconnetti();
|
||||
|
||||
returnJson($app, $callbackFn, $retNewID);
|
||||
});
|
||||
|
||||
@@ -67,10 +81,17 @@ $app->get('/profile/:keyStore/ricette', function ($keyStore) use ($app) {
|
||||
$app->get('/profile/:keyStore', function ($keyStore) use ($app) {
|
||||
$callbackFn = $app->request()->get('callback');
|
||||
$mysqlconnetion = new MysqlClass;
|
||||
$query = "select ProfiloID, TipoAccesso, RisultatiRicerca, TemaUI, Name, Gender, 0 as NumRicette from profilo" .
|
||||
$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" .
|
||||
" where ProfiloID = '" . $keyStore . "'";
|
||||
$retObj = $mysqlconnetion->queryToObject($query);
|
||||
|
||||
if($retObj != false)
|
||||
{
|
||||
$retObj[0]["Name"] = html_entity_decode($retObj[0]["Name"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
||||
$retObj[0]["Note"] = html_entity_decode($retObj[0]["Note"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
||||
$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');
|
||||
|
||||
$query = "update profilo set PenultimoAccesso = UltimoAccesso, UltimoAccesso = NOW() where ProfiloID = '" . $keyStore . "'";
|
||||
$mysqlconnetion->insertRecord($query);
|
||||
|
||||
@@ -80,15 +101,53 @@ $app->get('/profile/:keyStore', function ($keyStore) use ($app) {
|
||||
$retObj2 = $mysqlconnetion->queryToObject($query);
|
||||
|
||||
$retObj[0]["NumRicette"] = $retObj2[0]["NumRicette"];
|
||||
}
|
||||
returnJson($app, $callbackFn, $retObj);
|
||||
});
|
||||
|
||||
$app->get('/profile/province(/:iniz)', function ($iniz = "") use ($app) {
|
||||
$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 . "', '" . $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())";
|
||||
$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();
|
||||
@@ -100,8 +159,20 @@ $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 . "' where ProfiloID = '" . $json_data_body->keyStore . "'";
|
||||
|
||||
$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();
|
||||
|
||||
|
||||
+63
-18
@@ -33,11 +33,32 @@ $app->get('/typeqtys', function () use ($app) {
|
||||
returnJson($app, $callbackFn, $retObj);
|
||||
});
|
||||
|
||||
$app->get('/categoryitems/:catID', function ($categoryID) use ($app) {
|
||||
$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) {
|
||||
$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";
|
||||
$query = "select * from (select ID as ricetta_id, titolo, autore, valutazione, difficolta, " .
|
||||
"(select id from immagini where immagini.id_ricette = ricette.id and bCover = 1) as firstImage, " .
|
||||
"(select count(id) from immagini where immagini.id_ricette = ricette.id) as countImages " .
|
||||
"from ricette where ricette.ID_CATEGORIA = " . $categoryID . " order by titolo, autore) as TMP";
|
||||
$retObj = $mysqlconnetion->queryToObject($query);
|
||||
$mysqlconnetion->disconnetti();
|
||||
|
||||
@@ -48,7 +69,7 @@ $app->get('/categoryitems/:catID', function ($categoryID) use ($app) {
|
||||
returnJson($app, $callbackFn, $retObj);
|
||||
});
|
||||
|
||||
$app->get('/categoryitems/:categoryID/mostvote(/:numItems)', function ($categoryID, $numItems = 10) use ($app) {
|
||||
$app->get('/ricette/:categoryID/mostvote(/:numItems)', function ($categoryID, $numItems = 10) use ($app) {
|
||||
$callbackFn = $app->request()->get('callback');
|
||||
$mysqlconnetion = new MysqlClass;
|
||||
//$mysqlconnetion->connetti();
|
||||
@@ -63,7 +84,7 @@ $app->get('/categoryitems/:categoryID/mostvote(/:numItems)', function ($category
|
||||
returnJson($app, $callbackFn, $retObj);
|
||||
});
|
||||
|
||||
$app->get('/categoryitems/:categoryID/lastinserted(/:numItems)', function ($categoryID, $numItems = 10) use ($app) {
|
||||
$app->get('/ricette/:categoryID/lastinserted(/:numItems)', function ($categoryID, $numItems = 10) use ($app) {
|
||||
$callbackFn = $app->request()->get('callback');
|
||||
$mysqlconnetion = new MysqlClass;
|
||||
//$mysqlconnetion->connetti();
|
||||
@@ -78,31 +99,46 @@ $app->get('/categoryitems/:categoryID/lastinserted(/:numItems)', function ($cate
|
||||
returnJson($app, $callbackFn, $retObj);
|
||||
});
|
||||
|
||||
$app->get('/categoryitems/search/:numItems(/:categoryId(/:difficolta(/:titolo)))',
|
||||
function ($numItems = 10, $categoryId = 0, $difficolta = 0, $titolo = "") use ($app) {
|
||||
$app->get('/ricette/search/:numItems/:startItem(/:categoryId(/:difficolta/:autore(/:titolo)))',
|
||||
function ($numItems = 10, $startItem = 0, $categoryId = 0, $difficolta = 0,$autore="_", $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"
|
||||
$queryBase = " from ricette"
|
||||
. " INNER JOIN categorie ON categorie.ID = ricette.id_categoria"
|
||||
. " where 1 = 1";
|
||||
if ($categoryId > 0) {
|
||||
$query = $query . " AND ID_CATEGORIA = " . $categoryId;
|
||||
$queryBase = $queryBase . " AND ID_CATEGORIA = " . $categoryId;
|
||||
}
|
||||
if ($autore != null && $autore != "_") {
|
||||
foreach (explode(" ", htmlentities(urldecode($autore))) as $ele)
|
||||
$queryBase = $queryBase . " AND autore like '%" . urldecode($ele) . "%'";
|
||||
}
|
||||
if ($titolo != null && $titolo != "") {
|
||||
foreach (explode(" ", $titolo) as $ele)
|
||||
$query = $query . " AND titolo like '%" . $ele . "%'";
|
||||
foreach (explode(" ", htmlentities(urldecode($titolo))) as $ele)
|
||||
$queryBase = $queryBase . " AND titolo like '%" . $ele . "%'";
|
||||
}
|
||||
if ($difficolta > 0) {
|
||||
$query = $query . " AND difficolta = " . $difficolta;
|
||||
$queryBase = $queryBase . " AND difficolta = " . $difficolta;
|
||||
}
|
||||
$query = $query . " order by titolo, autore LIMIT " . $numItems;
|
||||
$queryBase = $queryBase . " order by titolo, autore";
|
||||
|
||||
$query = "select * from (select ricette.ID as ricetta_id, categorie.name AS categoria_name, titolo, autore, valutazione, difficolta, " .
|
||||
"(select id from immagini where immagini.id_ricette = ricette.id and bCover = 1) as firstImage, " .
|
||||
"(select count(id) from immagini where immagini.id_ricette = ricette.id) as countImages" .
|
||||
$queryBase . " LIMIT " . $numItems * $startItem . " , " . $numItems . ") as TMP";
|
||||
|
||||
$retObj2 = $mysqlconnetion->queryToObject($query);
|
||||
|
||||
$query = "select COUNT(*) as TotalRecords" . $queryBase;
|
||||
$retObj = $mysqlconnetion->queryToObject($query);
|
||||
|
||||
$mysqlconnetion->disconnetti();
|
||||
|
||||
foreach ($retObj as $ele) {
|
||||
foreach ($retObj2 as $ele) {
|
||||
$ele["titolo"] = html_entity_decode($ele["titolo"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
||||
}
|
||||
|
||||
$retObj["records"] = $retObj2;
|
||||
returnJson($app, $callbackFn, $retObj);
|
||||
});
|
||||
|
||||
@@ -123,6 +159,10 @@ $app->get('/ricetta/body/:itemID', function ($itemID) use ($app) {
|
||||
|
||||
$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]["procedimento"] = html_entity_decode($retObj[0]["procedimento"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
||||
$retObj[0]["ingredienti"] = $retObj2;
|
||||
@@ -137,11 +177,16 @@ $app->get('/ricetta/header/:itemID', function ($itemID) use ($app) {
|
||||
$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;
|
||||
$query = "SELECT ID from immagini WHERE published = 1 AND ID_RICETTE = " . $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[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"];
|
||||
$retObj[0]["foto"] = $photos;
|
||||
$output = array();
|
||||
if ($data != "") {
|
||||
$d = explode(";", $data);
|
||||
@@ -167,9 +212,9 @@ $app->get('/ricetta/ingredienti/:itemID', function ($itemID) use ($app) {
|
||||
|
||||
$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;
|
||||
foreach ($retObj2 as $ele) {
|
||||
$ele["note"] = html_entity_decode($ele["note"], ENT_COMPAT | ENT_HTML401, 'ISO-8859-1');
|
||||
}
|
||||
|
||||
$mysqlconnetion->disconnetti();
|
||||
|
||||
|
||||
+4
-2
@@ -2,14 +2,16 @@
|
||||
|
||||
include_once "./include.php";
|
||||
|
||||
$app->group('/api', function () use ($app) {
|
||||
$app->group('/api', function () use ($app, $dirRicetteDropBox) {
|
||||
include "./ricette.php";
|
||||
include "./profile.php";
|
||||
include "./image.php";
|
||||
include "./spacciatoripm.php";
|
||||
});
|
||||
|
||||
$app->group('/backend', function () use ($app) {
|
||||
$app->group('/backend', function () use ($app, $dirRicetteDropBox) {
|
||||
include "./management.php";
|
||||
include "./image_backend.php";
|
||||
});
|
||||
//include "./image.php";
|
||||
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
<?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 ";
|
||||
if($ToLat < $FromLat)
|
||||
$query = $query . "Latitudine BETWEEN " . $ToLat . " AND " . $FromLat . " AND ";
|
||||
else
|
||||
$query = $query . "Latitudine BETWEEN " . $FromLat . " AND " . $ToLat . " AND ";
|
||||
|
||||
if($ToLng < $FromLng)
|
||||
$query = $query . "Longitudine BETWEEN " . $ToLng . " AND " . $FromLng;
|
||||
else
|
||||
$query = $query . "Longitudine BETWEEN " . $FromLng . " AND " . $ToLng;
|
||||
|
||||
$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);
|
||||
});
|
||||
@@ -0,0 +1,178 @@
|
||||
<?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);
|
||||
});
|
||||
?>
|
||||
@@ -0,0 +1 @@
|
||||
a:2:{s:1:"t";s:16:"s1ti76srenx4b7aj";s:1:"s";s:15:"qshrdehad4dzz6n";}
|
||||
+44
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
if ( ! function_exists( 'exif_imagetype' ) ) {
|
||||
function exif_imagetype ( $filename ) {
|
||||
if ( ( list($width, $height, $type, $attr) = getimagesize( $filename ) ) !== false ) {
|
||||
return $type;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function utf8json($inArray) {
|
||||
|
||||
if (is_array($inArray)) {
|
||||
@@ -75,4 +84,39 @@ function getContentFromResources($res) {
|
||||
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);
|
||||
|
||||
return $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);
|
||||
return $dropBoxObj->GetLink($dirDropBox . "/" . $fileName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user