Merge branch 'seeddms-5.1.x' into seeddms-6.0.x

This commit is contained in:
Uwe Steinmann 2020-12-14 10:52:10 +01:00
commit 63c0804e07
15 changed files with 116 additions and 29 deletions

View File

@ -206,6 +206,7 @@
- reindex document after it was edited
- show preview images in drop folder menu after mouse over
- add support for indexing folders
- always call hook postAddSubFolder and postEditDocument
--------------------------------------------------------------------------------
Changes in version 5.1.20

View File

@ -72,8 +72,10 @@ class SeedDMS_Lucene_Search {
*/
function search($term, $fields=array(), $limit=array()) { /* {{{ */
$querystr = '';
if($term)
$querystr .= trim($term);
$term = trim($term);
if($term) {
$querystr = substr($term, -1) != '*' ? $term.'*' : $term;
}
if(!empty($fields['owner'])) {
if(is_string($owner)) {
if($querystr)

View File

@ -72,8 +72,10 @@ class SeedDMS_SQliteFTS_Search {
*/
function search($term, $fields=array(), $limit=array()) { /* {{{ */
$querystr = '';
if($term)
$querystr .= trim($term);
$term = trim($term);
if($term) {
$querystr = substr($term, -1) != '*' ? $term.'*' : $term;
}
if(!empty($fields['owner'])) {
if(is_string($fields['owner'])) {
if($querystr)

View File

@ -153,7 +153,7 @@ class SeedDMS_Controller_AddDocument extends SeedDMS_Controller_Common {
if($document->getGroupAccessMode($notgroup) >= M_READ)
$res = $document->addNotify($notgroup->getID(), false);
}
} elseif($result === false) {
} elseif($document === false) {
if(empty($this->errormsg))
$this->errormsg = 'hook_addDocument_failed';
return false;
@ -167,7 +167,10 @@ class SeedDMS_Controller_AddDocument extends SeedDMS_Controller_Common {
}
}
if(!$this->callHook('postAddDocument', $document)) {
if(false ==== $this->callHook('postAddDocument', $document)) {
if(empty($this->errormsg))
$this->errormsg = 'hook_postAddDocument_failed';
return false;
}
return $document;

View File

@ -25,6 +25,7 @@ class SeedDMS_Controller_AddSubFolder extends SeedDMS_Controller_Common {
public function run() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$fulltextservice = $this->params['fulltextservice'];
$folder = $this->params['folder'];
/* Call preAddSubFolder early, because it might need to modify some
@ -33,7 +34,7 @@ class SeedDMS_Controller_AddSubFolder extends SeedDMS_Controller_Common {
if(false === $this->callHook('preAddSubFolder')) {
if(empty($this->errormsg))
$this->errormsg = 'hook_preAddSubFolder_failed';
return null;
return false;
}
$name = $this->getParam('name');
@ -61,8 +62,8 @@ class SeedDMS_Controller_AddSubFolder extends SeedDMS_Controller_Common {
$notificationgroups = $this->getParam('notificationgroups');
$notificationusers = $this->getParam('notificationusers');
$result = $this->callHook('addSubFolder');
if($result === null) {
$subFolder = $this->callHook('addSubFolder');
if($subFolder === null) {
$subFolder = $folder->addSubFolder($name, $comment, $user, $sequence, $attributes);
if (!is_object($subFolder)) {
$this->errormsg = "error_occured";
@ -77,13 +78,27 @@ class SeedDMS_Controller_AddSubFolder extends SeedDMS_Controller_Common {
if($subFolder->getGroupAccessMode($notgroup) >= M_READ)
$res = $subFolder->addNotify($notgroup->getID(), false);
}
if(!$this->callHook('postAddSubFolder', $subFolder)) {
}
$result = $subFolder;
} elseif($subFolder === false) {
if(empty($this->errormsg))
$this->errormsg = 'hook_addFolder_failed';
return false;
}
return $result;
if($fulltextservice && ($index = $fulltextservice->Indexer()) && $subFolder) {
$idoc = $fulltextservice->IndexedDocument($subFolder);
if(false !== $this->callHook('preIndexFolder', $subFolder, $idoc)) {
$index->addDocument($idoc);
$index->commit();
}
}
if(false === $this->callHook('postAddSubFolder', $subFolder)) {
if(empty($this->errormsg))
$this->errormsg = 'hook_postAddSubFoder_failed';
return false;
}
return $subFolder;
} /* }}} */
}

View File

@ -165,11 +165,14 @@ class SeedDMS_Controller_EditDocument extends SeedDMS_Controller_Common {
}
}
if(!$this->callHook('postEditDocument')) {
}
} elseif($result === false) {
if(empty($this->errormsg))
$this->errormsg = 'hook_editDocument_failed';
return false;
}
} else
return $result;
if(!$this->callHook('postEditDocument')) {
}
return true;
}

View File

@ -26,6 +26,7 @@ class SeedDMS_Controller_EditFolder extends SeedDMS_Controller_Common {
$dms = $this->params['dms'];
$user = $this->params['user'];
$settings = $this->params['settings'];
$fulltextservice = $this->params['fulltextservice'];
$folder = $this->params['folder'];
if(false === $this->callHook('preEditFolder')) {
@ -89,6 +90,14 @@ class SeedDMS_Controller_EditFolder extends SeedDMS_Controller_Common {
}
}
if($fulltextservice && ($index = $fulltextservice->Indexer()) && $folder) {
$idoc = $fulltextservice->IndexedDocument($folder);
if(false !== $this->callHook('preIndexFolder', $folder, $idoc)) {
$index->addDocument($idoc);
$index->commit();
}
}
} elseif($result === false) {
if(empty($this->errormsg))
$this->errormsg = 'hook_editFolder_failed';

View File

@ -44,17 +44,25 @@ class SeedDMS_Controller_RemoveFolder extends SeedDMS_Controller_Common {
/* Register a callback which removes each document from the fulltext index
* The callback must return null other the removal will be canceled.
*/
function removeFromIndex($fulltextservice, $document) {
function removeFromIndex($arr, $document) {
$fulltextservice = $arr[0];
$lucenesearch = $fulltextservice->Search();
if($hit = $lucenesearch->getDocument($document->getID())) {
$hit = null;
if($document->isType('document'))
$hit = $lucenesearch->getDocument($document->getID());
elseif($document->isType('folder'))
$hit = $lucenesearch->getFolder($document->getID());
if($hit) {
$index = $fulltextservice->Indexer();
$index->delete($hit->id);
$index->commit();
}
return null;
}
if($fulltextservice && ($index = $fulltextservice->Indexer()))
$dms->setCallback('onPreRemoveDocument', 'removeFromIndex', array($fulltextservice));
if($fulltextservice && ($index = $fulltextservice->Indexer())) {
$dms->addCallback('onPreRemoveDocument', 'removeFromIndex', array($fulltextservice));
$dms->addCallback('onPreRemoveFolder', 'removeFromIndex', array($fulltextservice));
}
function removePreviews($arr, $document) {
$previewer = $arr[0];

View File

@ -108,6 +108,7 @@ if(!$settings->_enableDuplicateSubFolderNames) {
}
}
$controller->setParam('fulltextservice', $fulltextservice);
$controller->setParam('folder', $folder);
$controller->setParam('name', $name);
$controller->setParam('comment', $comment);

View File

@ -74,6 +74,7 @@ $oldattributes = array();
foreach($folder->getAttributes() as $ai=>$aa)
$oldattributes[$ai] = clone $aa;
$controller->setParam('fulltextservice', $fulltextservice);
$controller->setParam('folder', $folder);
$controller->setParam('name', $name);
$controller->setParam('comment', $comment);

View File

@ -55,12 +55,12 @@ if (isset($_GET["navBar"])) {
header("Location: ../op/op.SearchFulltext.php?folderid=".$folderid."&query=".$_GET["query"]);
}
}
*/
*/
}
$accessop = new SeedDMS_AccessOperation($dms, null, $user, $settings);
if(isset($_GET["fullsearch"]) && $_GET["fullsearch"] && $settings->_enableFullSearch) {
if(((!isset($_GET["fullsearch"]) && $settings->_defaultSearchMethod == 'fulltext') || !empty($_GET["fullsearch"])) && $settings->_enableFullSearch) {
// Search in Fulltext {{{
if (isset($_GET["query"]) && is_string($_GET["query"])) {
$query = $_GET["query"];
@ -188,6 +188,7 @@ if(isset($_GET["fullsearch"]) && $_GET["fullsearch"] && $settings->_enableFullSe
$session->setSplashMsg(array('type'=>'error', 'msg'=>getMLText('splash_invalid_searchterm')));
$dcount = 0;
$fcount = 0;
$total = 0;
$totalPages = 0;
$entries = array();
$facets = array();
@ -227,6 +228,7 @@ if(isset($_GET["fullsearch"]) && $_GET["fullsearch"] && $settings->_enableFullSe
$totalPages = 1;
}
}
$total = $searchresult['total'];
$searchTime = getTime() - $startTime;
$searchTime = round($searchTime, 2);
} else {
@ -496,6 +498,7 @@ if(isset($_GET["fullsearch"]) && $_GET["fullsearch"] && $settings->_enableFullSe
'reception'=>$reception,
'orderby'=>$orderby
));
$total = $resArr['totalDocs'] + $res['totalFolders'];
$searchTime = getTime() - $startTime;
$searchTime = round($searchTime, 2);
@ -565,12 +568,13 @@ if($settings->_showSingleSearchHit && count($entries) == 1) {
$view->setParam('showtree', showtree());
$view->setParam('enableRecursiveCount', $settings->_enableRecursiveCount);
$view->setParam('maxRecursiveCount', $settings->_maxRecursiveCount);
$view->setParam('total', $total);
$view->setParam('totaldocs', $dcount /*resArr['totalDocs']*/);
$view->setParam('totalfolders', $fcount /*resArr['totalFolders']*/);
$view->setParam('fullsearch', (isset($_GET["fullsearch"]) && $_GET["fullsearch"] && $settings->_enableFullSearch) ? true : false);
$view->setParam('fullsearch', (!empty($_GET["fullsearch"]) && $settings->_enableFullSearch) ? true : false);
$view->setParam('mode', isset($mode) ? $mode : '');
$view->setParam('orderby', isset($orderby) ? $orderby : '');
$view->setParam('defaultsearchmethod', $settings->_defaultSearchMethod);
$view->setParam('defaultsearchmethod', !empty($_GET["fullsearch"]) || $settings->_defaultSearchMethod);
$view->setParam('resultmode', isset($resultmode) ? $resultmode : '');
$view->setParam('searchin', isset($searchin) ? $searchin : array());
$view->setParam('startfolder', isset($startFolder) ? $startFolder : null);

View File

@ -132,7 +132,6 @@ $(document).ready( function() {
* it to set the document location. The passed value is the string
* set in data-value of the list items. */
updater: function (item) {
console.log(item);
document.location = "../out/out.Search.php?query=" + encodeURIComponent(item);
return item;
},

View File

@ -516,7 +516,7 @@ background-image: linear-gradient(to bottom, #882222, #111111);;
echo " <input type=\"hidden\" name=\"folderid\" value=\"".$folder->getID()."\" />";
}
echo " <input type=\"hidden\" name=\"navBar\" value=\"1\" />";
echo " <input name=\"query\" class=\"search-query\" ".($this->params['defaultsearchmethod'] == 'fulltext' ? "" : "id=\"searchfield\"")." data-provide=\"typeahead\" type=\"search\" style=\"width: 150px;\" placeholder=\"".getMLText("search")."\"/>";
echo " <input name=\"query\" class=\"search-query\" ".($this->params['defaultsearchmethod'] == 'fulltext_' ? "" : "id=\"searchfield\"")." data-provide=\"typeahead\" type=\"search\" style=\"width: 150px;\" placeholder=\"".getMLText("search")."\"/>";
if($this->params['defaultsearchmethod'] == 'fulltext')
echo " <input type=\"hidden\" name=\"fullsearch\" value=\"1\" />";
// if($this->params['enablefullsearch']) {

View File

@ -44,7 +44,10 @@ class SeedDMS_View_OpensearchDesc extends SeedDMS_Bootstrap_Style {
<Description><?= $sitename ?></Description>
<Image height="16" width="16" type="image/x-icon"><?= "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot ?>styles/<?= $this->theme ?>/favicon.ico</Image>
<Url type="text/html" method="get" template="<?= "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.Search.php?query={searchTerms}" ?>" />
<Url type="application/x-suggestions+xml" rel="suggestions" method="get" template="<?= "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.Search.php?action=opensearchsuggestion&query={searchTerms}" ?>" />
<moz:SearchForm><?= "http".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.Search.php" ?></moz:SearchForm>
<OutputEncoding>UTF-8</OutputEncoding>
<InputEncoding>UTF-8</InputEncoding>
</OpenSearchDescription>
<?php
} /* }}} */

View File

@ -112,7 +112,37 @@ $(document).ready( function() {
unlink($filename);
} /* }}} */
function typeahead() { /* {{{ */
function opensearchsuggestion() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$query = $this->params['query'];
$entries = $this->params['searchhits'];
$recs = array();
$content = "<?xml version=\"1.0\"?>\n";
$content .= "<SearchSuggestion version=\"2.0\" xmlns=\"http://opensearch.org/searchsuggest2\">\n";
$content .= "<Query xml:space=\"preserve\">".$query."</Query>";
if($entries) {
$content .= "<Section>\n";
foreach ($entries as $entry) {
$content .= "<Item>\n";
if($entry->isType('document')) {
$content .= "<Text xml:space=\"preserve\">".$entry->getName()."</Text>\n";
$content .= "<Url xml:space=\"preserve\">http:".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewDocument.php?documentid=".$entry->getId()."</Url>\n";
} elseif($entry->isType('folder')) {
$content .= "<Text xml:space=\"preserve\">".$entry->getName()."</Text>\n";
$content .= "<Url xml:space=\"preserve\">http:".((isset($_SERVER['HTTPS']) && (strcmp($_SERVER['HTTPS'],'off')!=0)) ? "s" : "")."://".$_SERVER['HTTP_HOST'].$settings->_httpRoot."out/out.ViewFolder.php?folderid=".$entry->getId()."</Url>\n";
}
$content .= "</Item>\n";
}
$content .= "</Section>\n";
}
$content .= "</SearchSuggestion>";
header("Content-Disposition: attachment; filename=\"search.xml\"; filename*=UTF-8''search.xml");
header('Content-Type: application/x-suggestions+xml');
echo $content;
} /* }}} */
function typeahead() { /* {{{ */
$dms = $this->params['dms'];
$user = $this->params['user'];
$query = $this->params['query'];
@ -217,6 +247,7 @@ $(document).ready( function() {
<div class="tab-content">
<div class="tab-pane <?php echo ($fullsearch == false) ? 'active' : ''; ?>" id="database">
<form action="../out/out.Search.php" name="form1">
<input type="hidden" name="fullsearch" value="0" />
<?php
// Database search Form {{{
$this->contentContainerStart();
@ -746,6 +777,10 @@ foreach($facets as $facetname=>$values) {
print $this->documentListRow($document, $previewer, false, 0, $extracontent);
}
} elseif($entry->isType('folder')) {
$txt = $this->callHook('folderListItem', $entry, false, 'search');
if(is_string($txt))
echo $txt;
else {
$folder = $entry;
$owner = $folder->getOwner();
if (in_array(2, $searchin)) {
@ -769,6 +804,7 @@ foreach($facets as $facetname=>$values) {
if($attrstr)
$extracontent['bottom_title'] = '<br />'.$this->printPopupBox('<span class="btn btn-mini btn-secondary">'.getMLText('attributes').'</span>', $attrstr, true);
print $this->folderListRow($folder, false, $extracontent);
}
}
}
print "</tbody></table>\n";