mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 06:53:15 +00:00
Merge pull request #1960 from jygaulier/PHRAS-1192_quarantaine-by-filenames_4.0
PHRAS-1192_quarantaine-by-filenames_4.0
This commit is contained in:
@@ -160,12 +160,11 @@ class caption_record implements cache_cacheableInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $highlight
|
||||
* @param array $grep_fields
|
||||
* @param bool $includeBusiness
|
||||
* @return array
|
||||
*/
|
||||
public function get_highlight_fields($highlight = '', array $grep_fields = null, $includeBusiness = false)
|
||||
public function get_highlight_fields(array $grep_fields = null, $includeBusiness = false)
|
||||
{
|
||||
$fields = [];
|
||||
|
||||
@@ -177,11 +176,6 @@ class caption_record implements cache_cacheableInterface
|
||||
'from_thesaurus' => false,
|
||||
'qjs' => null,
|
||||
];
|
||||
if ($highlight) {
|
||||
$v->highlight_thesaurus();
|
||||
$values[$metaId]['from_thesaurus'] = $v->isThesaurusValue();
|
||||
$values[$metaId]['qjs'] = $v->getQjs();
|
||||
}
|
||||
}
|
||||
$fields[$field->get_name()] = [
|
||||
'values' => $values,
|
||||
|
@@ -416,16 +416,14 @@ class media_Permalink_Adapter implements cache_cacheableInterface
|
||||
$data[] = [
|
||||
'subdef_id' => $media_subdef->get_subdef_id(),
|
||||
'token' => $generator->generateString(64, TokenManipulator::LETTERS_AND_NUMBERS),
|
||||
'label' => $records[$media_subdef->get_record_id()]->get_title(false, null, true),
|
||||
'label' => $records[$media_subdef->get_record_id()]->get_title(['removeExtension' => true]),
|
||||
];
|
||||
}
|
||||
|
||||
try {
|
||||
$databox->get_connection()->transactional(function (Connection $connection) use ($data) {
|
||||
$sql = <<<'SQL'
|
||||
INSERT INTO permalinks (subdef_id, token, activated, created_on, last_modified, label)
|
||||
VALUES (:subdef_id, :token, 1, NOW(), NOW(), :label)
|
||||
SQL;
|
||||
$sql = "INSERT INTO permalinks (subdef_id, token, activated, created_on, last_modified, label)\n"
|
||||
. " VALUES (:subdef_id, :token, 1, NOW(), NOW(), :label)";
|
||||
|
||||
$statement = $connection->prepare($sql);
|
||||
|
||||
|
@@ -387,6 +387,14 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
return \collection::getByCollectionId($this->app, $this->getDatabox(), $this->collection_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string the name of the collection to which the record belongs to.
|
||||
*/
|
||||
public function getCollectionName()
|
||||
{
|
||||
return $this->getCollection()->get_name();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns record_id of the record
|
||||
*
|
||||
@@ -795,15 +803,20 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $highlight
|
||||
* @param SearchEngineInterface $searchEngine
|
||||
* @param null $removeExtension
|
||||
* @param SearchEngineOptions $options
|
||||
* get the title (concat "thumbtitle" fields which match locale, with "-")
|
||||
* fallback to the filename, possibly with extension removed
|
||||
*
|
||||
* @param string $locale
|
||||
* @param $options[]
|
||||
* 'removeExtension' : boolean
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title($highlight = false, SearchEngineInterface $searchEngine = null, $removeExtension = null, SearchEngineOptions $options = null)
|
||||
public function getTitle($locale = null, Array $options = [])
|
||||
{
|
||||
$cache = !$highlight && !$searchEngine && !$removeExtension;
|
||||
$removeExtension = !!igorw\get_in($options, ['removeExtension'], false);
|
||||
|
||||
$cache = !$removeExtension;
|
||||
|
||||
if ($cache) {
|
||||
try {
|
||||
@@ -820,13 +833,13 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
$fields_to_retrieve = [];
|
||||
|
||||
foreach ($fields as $field) {
|
||||
if (in_array($field->get_thumbtitle(), ['1', $this->app['locale']])) {
|
||||
if (in_array($field->get_thumbtitle(), ['1', $locale])) {
|
||||
$fields_to_retrieve [] = $field->get_name();
|
||||
}
|
||||
}
|
||||
|
||||
if (count($fields_to_retrieve) > 0) {
|
||||
$retrieved_fields = $this->get_caption()->get_highlight_fields($highlight, $fields_to_retrieve);
|
||||
$retrieved_fields = $this->get_caption()->get_highlight_fields($fields_to_retrieve);
|
||||
$titles = [];
|
||||
foreach ($retrieved_fields as $value) {
|
||||
foreach ($value['values'] as $v) {
|
||||
@@ -849,6 +862,16 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
return $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Array $options
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function get_title(Array $options = [])
|
||||
{
|
||||
return $this->getTitle($this->app['locale'], $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return media_subdef
|
||||
*/
|
||||
@@ -1524,12 +1547,12 @@ class record_adapter implements RecordInterface, cache_cacheableInterface
|
||||
* @param int $offset_start
|
||||
* @param int $how_many
|
||||
*
|
||||
* @return array
|
||||
* @return record_adapter[]
|
||||
*/
|
||||
public static function get_records_by_originalname(databox $databox, $original_name, $caseSensitive = false, $offset_start = 0, $how_many = 10)
|
||||
{
|
||||
$offset_start = (int)($offset_start < 0 ? 0 : $offset_start);
|
||||
$how_many = (int)(($how_many > 20 || $how_many < 1) ? 10 : $how_many);
|
||||
$offset_start = max(0, (int)$offset_start);
|
||||
$how_many = max(1, (int)$how_many);
|
||||
|
||||
$sql = sprintf(
|
||||
'SELECT record_id FROM record WHERE originalname = :original_name COLLATE %s LIMIT %d, %d',
|
||||
|
@@ -252,7 +252,7 @@ class record_preview extends record_adapter
|
||||
*
|
||||
* @return String
|
||||
*/
|
||||
public function get_title($highlight = false, SearchEngineInterface $searchEngine = null, $removeExtension = null, SearchEngineOptions $options = null)
|
||||
public function get_title(Array $options = [])
|
||||
{
|
||||
if ($this->title) {
|
||||
return $this->title;
|
||||
@@ -264,14 +264,14 @@ class record_preview extends record_adapter
|
||||
|
||||
case "RESULT":
|
||||
$this->title .= $this->app->trans('resultat numero %number%', ['%number%' => '<span id="current_result_n">' . ($this->getNumber() + 1) . '</span> : ']);
|
||||
$this->title .= parent::get_title($highlight, $searchEngine);
|
||||
$this->title .= parent::get_title($options);
|
||||
break;
|
||||
case "BASK":
|
||||
$this->title .= $this->name . ' - ' . parent::get_title($highlight, $searchEngine)
|
||||
$this->title .= $this->name . ' - ' . parent::get_title($options)
|
||||
. ' (' . $this->getNumber() . '/' . $this->total . ') ';
|
||||
break;
|
||||
case "REG":
|
||||
$title = parent::get_title();
|
||||
$title = parent::get_title($options);
|
||||
if ($this->getNumber() == 0) {
|
||||
$this->title .= $title;
|
||||
} else {
|
||||
@@ -281,7 +281,7 @@ class record_preview extends record_adapter
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$this->title .= parent::get_title($highlight, $searchEngine);
|
||||
$this->title .= parent::get_title($options);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@@ -130,7 +130,7 @@ class set_export extends set_abstract
|
||||
$app,
|
||||
$child_basrec->getDataboxId(),
|
||||
$record_id,
|
||||
$record->get_title(null, null, true) . '_' . $n,
|
||||
$record->get_title(['removeExtension' => true]) . '_' . $n,
|
||||
$remain_hd[$base_id]
|
||||
);
|
||||
$this->add_element($current_element);
|
||||
@@ -256,18 +256,17 @@ class set_export extends set_abstract
|
||||
$types['usr_id'] = PDO::PARAM_INT;
|
||||
}
|
||||
|
||||
$sql = <<<SQL
|
||||
SELECT Users.id AS usr_id ,Users.login AS usr_login ,Users.email AS usr_mail, FtpCredential.*
|
||||
FROM (
|
||||
FtpCredential INNER JOIN Users ON (FtpCredential.active = 1 AND FtpCredential.user_id = Users.id)
|
||||
INNER JOIN basusr ON (
|
||||
Users.id=basusr.usr_id
|
||||
${userFilterSQL}
|
||||
AND (basusr.base_id IN (:baseIds))
|
||||
)
|
||||
)
|
||||
GROUP BY Users.id
|
||||
SQL;
|
||||
$sql = "SELECT Users.id AS usr_id ,Users.login AS usr_login ,Users.email AS usr_mail, FtpCredential.*\n"
|
||||
. "FROM (\n"
|
||||
. " FtpCredential INNER JOIN Users ON (FtpCredential.active = 1 AND FtpCredential.user_id = Users.id)\n"
|
||||
. "INNER JOIN\n"
|
||||
. " basusr\n"
|
||||
. "ON (Users.id=basusr.usr_id"
|
||||
. $userFilterSQL
|
||||
. " AND (basusr.base_id IN (:baseIds)))\n"
|
||||
. ")\n"
|
||||
. "GROUP BY Users.id\n";
|
||||
|
||||
$params['baseIds'] = $lst_base_id;
|
||||
$types['baseIds'] = Connection::PARAM_INT_ARRAY;
|
||||
|
||||
@@ -440,7 +439,7 @@ SQL;
|
||||
substr($files[$id]['original_name'], 0 - strrpos($files[$id]['original_name'], '.'));
|
||||
|
||||
if ($rename_title) {
|
||||
$title = strip_tags($download_element->get_title(null, null, true));
|
||||
$title = strip_tags($download_element->get_title(['removeExtension' => true]));
|
||||
$files[$id]['export_name'] = $unicode->remove_nonazAZ09($title, true, true, true);
|
||||
} else {
|
||||
$files[$id]["export_name"] = $infos['filename'];
|
||||
@@ -458,10 +457,15 @@ SQL;
|
||||
continue;
|
||||
}
|
||||
|
||||
$subdef = $download_element->get_subdef($name);
|
||||
|
||||
if (!in_array($name, ['caption', 'caption-yaml']) && !isset($subdef)) {
|
||||
continue;
|
||||
$subdef = null;
|
||||
if (!in_array($name, ['caption', 'caption-yaml'])) {
|
||||
try {
|
||||
// get_subdef() can throw a 404
|
||||
$subdef = $download_element->get_subdef($name);
|
||||
}
|
||||
catch(\Exception $e) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
set_time_limit(100);
|
||||
@@ -691,7 +695,7 @@ SQL;
|
||||
public static function build_zip(Application $app, Token $token, array $list, $zipFile)
|
||||
{
|
||||
if (isset($list['complete']) && $list['complete'] === true) {
|
||||
return;
|
||||
return $zipFile;
|
||||
}
|
||||
|
||||
$files = $list['files'];
|
||||
@@ -786,9 +790,7 @@ SQL;
|
||||
$list_base = array_unique(array_keys($tmplog));
|
||||
|
||||
if (!$anonymous && null !== $app->getAuthenticatedUser()) {
|
||||
$sql = "UPDATE basusr
|
||||
SET remain_dwnld = :remain_dl
|
||||
WHERE base_id = :base_id AND usr_id = :usr_id";
|
||||
$sql = "UPDATE basusr SET remain_dwnld = :remain_dl WHERE base_id = :base_id AND usr_id = :usr_id";
|
||||
|
||||
$stmt = $app->getApplicationBox()->get_connection()->prepare($sql);
|
||||
|
||||
|
Reference in New Issue
Block a user