Commit 7d847f07 authored by Carsten  Rose's avatar Carsten Rose
Browse files

WIP: Implements #12085 Persistent download links. 1) Doku fehlt, 2) Nur eine...

WIP: Implements #12085 Persistent download links. 1) Doku fehlt, 2) Nur eine SQL in der Config ist vermutlich viel zu wenig (es fehlt ein Konzept), 3) AS _link Class sollte diese Modus auch unterstuetzen, 4) symlink dl.php muss aktuell noch manuell angelegt werden.
parent 28191449
Pipeline #5028 passed with stages
in 4 minutes and 36 seconds
......@@ -7,6 +7,7 @@
.. ^^
.. ""
.. ;;
.. ;;
.. ,,
..
.. --------------------------------------------used to the update the records specified ------
......
......@@ -679,6 +679,7 @@ const DOWNLOAD_POPUP_REQUEST = 'true';
const DOWNLOAD_POPUP_REPLACE_TEXT = '#downloadPopupReplaceText#';
const DOWNLOAD_POPUP_REPLACE_TITLE = '#downloadPopupReplaceTitle#';
const SYSTEM_DRAG_AND_DROP_JS = 'hasDragAndDropJS';
const SYSTEM_SQL_DIRECT_DOWNLOAD = 'sqlDirectDownload';
const SYSTEM_PARAMETER_LANGUAGE_FIELD_NAME = 'parameterLanguageFieldName';
const CSS_REQUIRED_RIGHT = 'required-right';
......
......@@ -9,8 +9,6 @@
namespace IMATHUZH\Qfq\Core\Helper;
/**
* Class OnString
* @package qfq
......@@ -237,7 +235,7 @@ class OnString {
}
// Empty? do nothing
if ($pathInfo == '') {
if ($pathInfo == '') {
return '';
}
......@@ -252,16 +250,16 @@ class OnString {
$rcArrId = array();
$rcArrForm = array();
while (count($param)>0) {
while (count($param) > 0) {
$form= array_shift($param);
$form = array_shift($param);
if (!ctype_alnum($form)) {
throw new \UserFormException('Expect alphanumeric string', ERROR_BROKEN_PARAMETER);
}
$rcArrForm[]=$form;
$rcArrForm[] = $form;
$id = array_shift($param);
if (!ctype_digit((string) $id)) {
if (!ctype_digit((string)$id)) {
throw new \UserFormException('Expect numerical id', ERROR_BROKEN_PARAMETER);
}
$rcArrId[] = $id;
......@@ -270,6 +268,23 @@ class OnString {
return $form;
}
/**
* Splits a path '/name1/name2/' to [ 'name1', 'name2' ]
*
* @param $pathInfo
* @return array
*/
public static function splitPathToArray($pathInfo) {
$arr = explode('/', $pathInfo);
$final = array();
foreach ($arr as $item) {
if ($item != '') {
$final[] = $item;
}
}
return $final;
}
/**
* Returns true if the subject string contains any of the given words in targets.
* Case insensitive!
......@@ -278,10 +293,8 @@ class OnString {
* @param string $subject
* @return bool
*/
public static function containsOneOfWords(array $words, string $subject): bool
{
foreach($words as $word)
{
public static function containsOneOfWords(array $words, string $subject): bool {
foreach ($words as $word) {
if (preg_match("/\b" . $word . "\b/i", $subject)) {
return true;
}
......@@ -297,8 +310,7 @@ class OnString {
* @param string $needle
* @return bool
*/
public static function strStartsWith(string $haystack , string $needle) : bool
{
public static function strStartsWith(string $haystack, string $needle): bool {
return substr_compare($haystack, $needle, 0, strlen($needle)) === 0;
}
......@@ -310,8 +322,7 @@ class OnString {
* @param string $needle
* @return bool
*/
public static function strEndsWith(string $haystack , string $needle) : bool
{
public static function strEndsWith(string $haystack, string $needle): bool {
return substr_compare($haystack, $needle, -strlen($needle)) === 0;
}
......@@ -323,8 +334,7 @@ class OnString {
* @param string $needle
* @return bool
*/
public static function strContains(string $haystack , string $needle) : bool
{
public static function strContains(string $haystack, string $needle): bool {
return strpos($haystack, $needle) !== false;
}
}
......@@ -680,6 +680,44 @@ class Download {
return $pathFilenameThumbnail;
}
/**
* @return int[]
* @throws \CodeException
* @throws \DbException
* @throws \UserFormException
* @throws \UserReportException
*/
private function getDirectDownloadModeDetails() {
$sql = $this->store->getVar(SYSTEM_SQL_DIRECT_DOWNLOAD, STORE_SYSTEM);
// Get, Clean: with http://loclhost/qfq/typo3conf/ext/qfq/Classes/Api/download.php/help is $_SERVER['PATH_INFO']='/help'.
$pathInfo = Sanitize::sanitize(urldecode($_SERVER['PATH_INFO'] ?? ''), SANITIZE_ALLOW_ALNUMX);
$param = OnString::splitPathToArray($pathInfo);
// In case there are more question mark than parameter, duplicate the last parameter until enough parameter filled.
$last = end($param);
$questionMark = substr_count($sql, '?');
while ($questionMark > count($param)) {
$param[] = $last;
}
// Get cmd which defines the download
$param = $this->db->sql($sql, ROW_EXPECT_1, $param);
// In case there are more than on column: implode
$cmd = implode('', $param);
// Use the link class only to reuse the parsing code of the download element.
$link = new Link(Store::getSipInstance());
$s = $link->renderLink($cmd, 'r:8|s:1');
// Retrieve the generated vars
$vars = Store::getSipInstance()->getVarsFromSip($s);
$vars[SIP_DOWNLOAD_PARAMETER] = base64_decode($vars[SIP_DOWNLOAD_PARAMETER]);
$vars[SIP_SIP] = $s;
return $vars;
}
/**
* Process download as requested in $vars. Output is either directly send to the browser, or a file which has to be deleted later.
*
......@@ -702,7 +740,13 @@ class Download {
public function process($vars, $outputMode = OUTPUT_MODE_DIRECT) {
if (!is_array($vars)) {
$vars = $this->store->getStore(STORE_SIP);
if ($vars === array()) {
// No SIP >> this seems to be a DirectDownloadMode
$vars = $this->getDirectDownloadModeDetails();
}
}
$this->setOutputFormat(empty($vars[DOWNLOAD_OUTPUT_FORMAT]) ? DOWNLOAD_OUTPUT_FORMAT_RAW : $vars[DOWNLOAD_OUTPUT_FORMAT]);
......
......@@ -688,7 +688,7 @@ class Link {
throw new \UserReportException ("Mode not implemented. internal render mode=$mode", ERROR_UNKNOWN_MODE);
break;
case '8':
$link = substr($vars[FINAL_HREF], 12); // strip 'index.php?s='
$link = substr($vars[FINAL_HREF], -SIP_TOKEN_LENGTH); // get only the last 13 characters (the sip)
break;
default:
......
......@@ -117,6 +117,15 @@ class RestClient {
return $param;
}
/**
* @param string $method
* @param string $url
* @param string $data
* @param array $header
* @param int $timeout
* @return array
* @throws Exception
*/
public static function callApiCurl(string $method, string $url, string $data = '', array $header = [], int $timeout = 5) {
// Header: Set content-type if not set
......
......@@ -387,6 +387,5 @@ custom29 =
# cat=custom/layout; type=string; label=Custom variable 30
custom30 =
# cat=file/file; type=string; label=Query for direct download mode. No default.: SELECT CONCAT('d:output.pdf|F:', n.pathFileName) FROM notiz AS n WHERE n.id=? AND NOW()<n.expire
sqlDirectDownload =
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment