Add option THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD for logo indexing
This commit is contained in:
parent
7cf7bf6e45
commit
d8bf553ea9
@ -4116,6 +4116,7 @@ abstract class CommonObject
|
|||||||
* @param int $hideref 1 to hide product reference. 0 by default
|
* @param int $hideref 1 to hide product reference. 0 by default
|
||||||
* @param null|array $moreparams Array to provide more information
|
* @param null|array $moreparams Array to provide more information
|
||||||
* @return int >0 if OK, <0 if KO
|
* @return int >0 if OK, <0 if KO
|
||||||
|
* @see addFileIntoDatabaseIndex
|
||||||
*/
|
*/
|
||||||
protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
|
protected function commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
|
||||||
{
|
{
|
||||||
@ -4354,6 +4355,7 @@ abstract class CommonObject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Build thumb
|
* Build thumb
|
||||||
|
* @TODO Move this into files.lib.php
|
||||||
*
|
*
|
||||||
* @param string $file Path file in UTF8 to original file to create thumbs from.
|
* @param string $file Path file in UTF8 to original file to create thumbs from.
|
||||||
* @return void
|
* @return void
|
||||||
|
|||||||
@ -950,7 +950,7 @@ function dolCheckVirus($src_file)
|
|||||||
* Note:
|
* Note:
|
||||||
* - This function can be used only into a HTML page context. Use dol_move if you are outside.
|
* - This function can be used only into a HTML page context. Use dol_move if you are outside.
|
||||||
* - Test on antivirus is always done (if antivirus set).
|
* - Test on antivirus is always done (if antivirus set).
|
||||||
* - Database of files is NOT updated.
|
* - Database of files is NOT updated (this is done by dol_add_file_process() that calls this function).
|
||||||
*
|
*
|
||||||
* @param string $src_file Source full path filename ($_FILES['field']['tmp_name'])
|
* @param string $src_file Source full path filename ($_FILES['field']['tmp_name'])
|
||||||
* @param string $dest_file Target full path filename ($_FILES['field']['name'])
|
* @param string $dest_file Target full path filename ($_FILES['field']['name'])
|
||||||
@ -1554,28 +1554,10 @@ function dol_add_file_process($upload_dir, $allowoverwrite=0, $donotupdatesessio
|
|||||||
// Update table of files
|
// Update table of files
|
||||||
if ($donotupdatesession)
|
if ($donotupdatesession)
|
||||||
{
|
{
|
||||||
$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $upload_dir);
|
$result = addFileIntoDatabaseIndex($upload_dir, basename($destfile), $TFile['name'][$i], 'uploaded', 0);
|
||||||
|
|
||||||
if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir
|
|
||||||
{
|
|
||||||
$filename = basename($destfile);
|
|
||||||
$rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
|
|
||||||
$rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
|
|
||||||
|
|
||||||
include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
|
|
||||||
$ecmfile=new EcmFiles($db);
|
|
||||||
$ecmfile->filepath = $rel_dir;
|
|
||||||
$ecmfile->filename = $filename;
|
|
||||||
$ecmfile->label = md5_file(dol_osencode($destfull)); // MD5 of file content
|
|
||||||
$ecmfile->fullpath_orig = $TFile['name'][$i];
|
|
||||||
$ecmfile->gen_or_uploaded = 'uploaded';
|
|
||||||
$ecmfile->description = ''; // indexed content
|
|
||||||
$ecmfile->keyword = ''; // keyword content
|
|
||||||
$result = $ecmfile->create($user);
|
|
||||||
if ($result < 0)
|
if ($result < 0)
|
||||||
{
|
{
|
||||||
setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings');
|
setEventMessages('FailedToAddFileIntoDatabaseIndex', '', 'warnings');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1679,6 +1661,114 @@ function dol_remove_file_process($filenb,$donotupdatesession=0,$donotdeletefile=
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add a file into database index.
|
||||||
|
* Called by dol_add_file_process when uploading a file and on other cases.
|
||||||
|
* See also commonGenerateDocument that also add/update database index when a file is generated.
|
||||||
|
*
|
||||||
|
* @param string $dir Directory name (full real path without ending /)
|
||||||
|
* @param string $file File name
|
||||||
|
* @param string $fullpathorig Full path of origin for file (can be '')
|
||||||
|
* @param string $mode How file was created ('uploaded', 'generated', ...)
|
||||||
|
* @param int $setsharekey Set also the share key
|
||||||
|
* @return int <0 if KO, 0 if nothing done, >0 if OK
|
||||||
|
*/
|
||||||
|
function addFileIntoDatabaseIndex($dir, $file, $fullpathorig='', $mode='uploaded', $setsharekey=0)
|
||||||
|
{
|
||||||
|
global $db, $user;
|
||||||
|
|
||||||
|
$result = 0;
|
||||||
|
|
||||||
|
$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir);
|
||||||
|
|
||||||
|
if (! preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) // If not a tmp dir
|
||||||
|
{
|
||||||
|
$filename = basename($file);
|
||||||
|
$rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
|
||||||
|
$rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
|
||||||
|
|
||||||
|
include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
|
||||||
|
$ecmfile=new EcmFiles($db);
|
||||||
|
$ecmfile->filepath = $rel_dir;
|
||||||
|
$ecmfile->filename = $filename;
|
||||||
|
$ecmfile->label = md5_file(dol_osencode($dir.'/'.$file)); // MD5 of file content
|
||||||
|
$ecmfile->fullpath_orig = $fullpathorig;
|
||||||
|
$ecmfile->gen_or_uploaded = $mode;
|
||||||
|
$ecmfile->description = ''; // indexed content
|
||||||
|
$ecmfile->keyword = ''; // keyword content
|
||||||
|
if ($setsharekey)
|
||||||
|
{
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
|
||||||
|
$ecmfile->share = getRandomPassword(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $ecmfile->create($user);
|
||||||
|
if ($result < 0)
|
||||||
|
{
|
||||||
|
dol_syslog($ecmfile->error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete files into database index using search criterias.
|
||||||
|
*
|
||||||
|
* @param string $dir Directory name (full real path without ending /)
|
||||||
|
* @param string $file File name
|
||||||
|
* @param string $mode How file was created ('uploaded', 'generated', ...)
|
||||||
|
* @return int <0 if KO, 0 if nothing done, >0 if OK
|
||||||
|
*/
|
||||||
|
function deleteFilesIntoDatabaseIndex($dir, $file, $mode='uploaded')
|
||||||
|
{
|
||||||
|
global $conf, $db, $user;
|
||||||
|
|
||||||
|
$error = 0;
|
||||||
|
|
||||||
|
if (empty($dir))
|
||||||
|
{
|
||||||
|
dol_syslog("deleteFilesIntoDatabaseIndex: dir parameter can't be empty", LOG_ERR);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db->begin();
|
||||||
|
|
||||||
|
$rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT,'/').'/', '', $dir);
|
||||||
|
|
||||||
|
$filename = basename($file);
|
||||||
|
$rel_dir = preg_replace('/[\\/]$/', '', $rel_dir);
|
||||||
|
$rel_dir = preg_replace('/^[\\/]/', '', $rel_dir);
|
||||||
|
|
||||||
|
if (! $error)
|
||||||
|
{
|
||||||
|
$sql = 'DELETE FROM ' . MAIN_DB_PREFIX . 'ecm_files';
|
||||||
|
$sql.= ' WHERE entity = '.$conf->entity;
|
||||||
|
$sql.= " AND filepath = '" . $db->escape($rel_dir) . "'";
|
||||||
|
if ($file) $sql.= " AND filename = '" . $db->escape($file) . "'";
|
||||||
|
if ($mode) $sql.= " AND gen_or_uploaded = '" . $db->escape($mode) . "'";
|
||||||
|
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if (!$resql)
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
dol_syslog(__METHOD__ . ' ' . $db->lasterror(), LOG_ERR);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Commit or rollback
|
||||||
|
if ($error) {
|
||||||
|
$db->rollback();
|
||||||
|
return - 1 * $error;
|
||||||
|
} else {
|
||||||
|
$db->commit();
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an image file into another format.
|
* Convert an image file into another format.
|
||||||
* This need Imagick php extension.
|
* This need Imagick php extension.
|
||||||
|
|||||||
@ -713,13 +713,18 @@ if (empty($reshook))
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Create small thumbs for company (Ratio is near 16/9)
|
// Create thumbs
|
||||||
// Used on logon for example
|
$object->addThumbs($newfile);
|
||||||
$imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
|
|
||||||
|
|
||||||
// Create mini thumbs for company (Ratio is near 16/9)
|
// Index file in database
|
||||||
// Used on menu or for setup page for example
|
if (! empty($conf->global->THIRDPARTY_LOGO_ALLOW_EXTERNAL_DOWNLOAD))
|
||||||
$imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
|
{
|
||||||
|
require_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php';
|
||||||
|
// the dir dirname($newfile) is directory of logo, so we should have only one file at once into index, so we delete indexes for the dir
|
||||||
|
deleteFilesIntoDatabaseIndex(dirname($newfile), '', '', 'uploaded', 1);
|
||||||
|
// now we index the uploaded logo file
|
||||||
|
addFileIntoDatabaseIndex(dirname($newfile), basename($newfile), '', 'uploaded', 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1121,10 +1121,11 @@ class Societe extends CommonObject
|
|||||||
* @param string $idprof4 Prof id 4 of third party (Warning, this can return several records)
|
* @param string $idprof4 Prof id 4 of third party (Warning, this can return several records)
|
||||||
* @param string $idprof5 Prof id 5 of third party (Warning, this can return several records)
|
* @param string $idprof5 Prof id 5 of third party (Warning, this can return several records)
|
||||||
* @param string $idprof6 Prof id 6 of third party (Warning, this can return several records)
|
* @param string $idprof6 Prof id 6 of third party (Warning, this can return several records)
|
||||||
* @param string $email Email (Warning, this can return several records)
|
* @param string $email Email of third party (Warning, this can return several records)
|
||||||
|
* @param string $ref_alias Name_alias of third party (Warning, this can return several records)
|
||||||
* @return int >0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found.
|
* @return int >0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found.
|
||||||
*/
|
*/
|
||||||
function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idprof5='',$idprof6='', $email='')
|
function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idprof5='',$idprof6='', $email='', $ref_alias='')
|
||||||
{
|
{
|
||||||
global $langs;
|
global $langs;
|
||||||
global $conf;
|
global $conf;
|
||||||
@ -1168,6 +1169,7 @@ class Societe extends CommonObject
|
|||||||
$sql .= ' WHERE s.entity IN ('.getEntity($this->element).')';
|
$sql .= ' WHERE s.entity IN ('.getEntity($this->element).')';
|
||||||
if ($rowid) $sql .= ' AND s.rowid = '.$rowid;
|
if ($rowid) $sql .= ' AND s.rowid = '.$rowid;
|
||||||
if ($ref) $sql .= " AND s.nom = '".$this->db->escape($ref)."'";
|
if ($ref) $sql .= " AND s.nom = '".$this->db->escape($ref)."'";
|
||||||
|
if ($ref_alias) $sql .= " AND s.nom_alias = '".$this->db->escape($nom_alias)."'";
|
||||||
if ($ref_ext) $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'";
|
if ($ref_ext) $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'";
|
||||||
if ($ref_int) $sql .= " AND s.ref_int = '".$this->db->escape($ref_int)."'";
|
if ($ref_int) $sql .= " AND s.ref_int = '".$this->db->escape($ref_int)."'";
|
||||||
if ($idprof1) $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'";
|
if ($idprof1) $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'";
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user