News:

Support for jDownloads 3 has been ended
Since 17 August 2023 Joomla.org has discontinued support for Joomla 3.x. Therefore, we will no longer offer official support for our Joomla 3 jDownloads version 3.9.x from January 2024.
Please update your website to the latest Joomla version (Joomla 4 or Joomla 5) as soon as possible. Afterwards, please update jDownloads to the latest published version. The longer you delay, the more difficult the upgrade process for your website is likely to be.

Main Menu
Support-Forum

Pre-process smart search results with "onContentPrepare" of Content Plugin

Started by Tom68, 05.06.2025 21:08:51

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Tom68

In jD 4.0.47 the results of a smart search are not pre-processed with the function "onContentPrepare" of the Content Plugin. In fact, I did not find any trigger in the code of jD 4.0.47 to accomplish this. As a result, the search results contain unresolved {jd_file} code.

I would highly appreciate, if this missing feature could be added.

Thanks & Regards
Tom
  •  

ColinM

Tom
I have just looked at the code in the jD Content Plugin. At line line 119 there is code
        function onContentPrepare($context, &$article, &$article_params)
It then goes on to check if there are any instances of {jd_file are in the article. If none exist it exits.
Best wishes
Colin
 
Colin M
  •  

Tom68

Colin,

in order to check, if "onContentPrepare" of the Content Plugin is really executed, I had added some code to "jdownloads.php" (into the function "onContentPrepare") of jDownloads Content Plugin that would log any execution of this function in a log file. I ran some tests opening articles, running searches and after each test inspected the log file.

While "onContentPrepare" is called, when an article including {jd_file} statements is displayed, it is not called when the results (not the articles) of a smart search are displayed that also include {jd_file} statements.

I am afraid, we have do dig deeper. Unfortunately, I am not familiar with setting triggers on smart searches. So, I cannot give a hint how to solve this problem, I can just report it.

Regards
Tom
  •  

ColinM

Tom
Thanks for input. I am also puzzled!!
You wrote
  ' While "onContentPrepare" is called, when an article including {jd_file} statements is displayed, it is not called when the results (not the articles) of a smart search are displayed that also include {jd_file} statements.'

My understanding of Smart Search is it detects when a new item such as a  Download or an Article is "created" so if an Article or a Downloaded is changed I would not expect Smart searches Plugins to detect such a change. So adding another jd-file in an existing article would not trigger smart search.

But I am unsure!!! Any further thoughts or critic is appreciated.
Best wishes
Colin
Colin M
  •  

Tom68

Colin

I think, what is needed is a trigger on the search results. I have searched a bit and found

https://docs.joomla.org/Plugin/Events/Finder#onFinderResult

This plugin/event is evaluated e.g. by sourcerer from regularlabs per public function onFinderResult, but it is not used by jDownloads at all.

To me the name of the event suggests that the corresponding function onFinderResult (if existing) is called before the results of a search are displayed. Maybe this is the missing piece of the puzzle?

Regards
Tom
  •  

ColinM

Tom
I will ask Arno to look at that solution.
Personally I am still of the view that the Joomla Search only indexes new items.  The content Plugin is an edit of an existing article - so not a new item, it is already indexed.

The index will still point to the article.  Joomla is not concerned about the actual contents of the article.
 
So I do not understand what you are trying to do.
Best wishes
Colin
Colin M
  •  

Tom68

Colin
I am not an expert in the field of "Smart Search", but from an observer's point of view I see two general tasks addressed by Smart Search. The first is indexing of the contents. The second is displaying the results of a search. My problem is related to the second task.

I have now modified the file "plugins/content/jdownloads/jdownloads.php" as follows:

  • I have added a public function onFinderResult before the function onContentPrepare
  • I have added into both functions code to write some debug information into a log file so that I can tell what contents (article or search results) triggered what function
  • In public function onFinderResult I have replaced the $result->description per regular expression "#{jd_file (.*?)==(.*?)}#s" and preg_replace_callback and logged the contents of $result->description before and after the replacement.

This is just a "quick and dirty" check of the purpose of the function "onFinderResult", but for a single search hit, it does work. After having introduced this code, the search result does no longer include {jd_file} tags but the contents they are pointing to.

Tomorrow, I will send you the modified code per email. It should be straightforward to find the modifications by running a diff.

Regards
Tom
  •  

ColinM

Tom
Thanks for update.  I have just been upating an article about seeting .htaccess protection
Are you aware that the Content Plugin is able to show multiple Downloads in a singlee call?
See article at
https://www.jdownloads.net/documentation?view=article&id=269&catid=30
Colin
Colin M
  •  

Tom68

Colin

Thanks for the article, but I do not see how it is related to the missing feature reported above. I have no "htaccess protection" problem and I do not need to show multiple downloads in a single call. Maybe these are interesting news for other users.

As promised I have sent you the modified code of "plugins/content/jdownloads/jdownloads.php" together with some screenshots of my demo site. I hope, this helps to understand and fix the problem.

Regards
Tom
  •