Benvenuto,
Ospite
|
|
Hi.
I have a feature request for JiFile. I want to use the K2 plugin, which allows me to add attachments to an article. I would like to use JiFile to be able to search for those attachments. I can do this already simply by setting JiFile to use the K2 uploads folder. But the search results will take me to the file; I want them to take me to the article that has the file attached. To change this would require that when JiFile outputs its results links, it look in the K2 data to see if that file is linked to an article, and if so, then change the link to point to the article instead. Would this be possible to do? |
L\'Amministratore ha disattivato l\'accesso in scrittura al pubblico.
|
|
Hi.
So I've done some research, and I've written some code to do this. I hope this can be incorporated into the main JiFile product? You need to edit jifile.php in the the search plugin as follows: 1. Add the following function to this class: private function k2Integration($title, $href) {
require_once(JPATH_SITE.'/components/com_k2/helpers/route.php');
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('i.id, i.alias, i.catid, c.alias as catalias')
->from($db->quoteName('#__k2_attachments','a'))
->where($db->quoteName('filename').' = '.$db->quote($title))
->join('INNER', $db->quoteName('#__k2_items', 'i').' ON '.$db->quoteName('i.id').' = '.$db->quoteName('a.itemID'))
->join('INNER', $db->quoteName('#__k2_categories', 'c').' ON '.$db->quoteName('c.id').' = '.$db->quoteName('i.catid'))
->where('i.published = 1');
$db->setQuery($query);
$db->execute();
$num_rows = $db->getNumRows();
if ($num_rows) {
$k2Item = $db->loadObject();
$href = JRoute::_(K2HelperRoute::getItemRoute($k2Item->id.':'.urlencode($k2Item->alias), $k2Item->catid.':'.urlencode($k2Item->catalias)));
}
return $href;
} 2. At the end of the onContentSearch() function, there is a block that sets $row = array( ... ). This needs to be changed as follows: $href = 'index.php?option=com_jifile&task=download&filename='.JFilterOutput::stringURLSafe($title).'&key='.$key;
if (JComponentHelper::getComponent('com_k2', true)->enabled) {
$href = $this->k2Integration($title, $href);
}
$row = array('title' => $title,
'href' => $href,
'created' => $created,
'browsernav' => 0,
'section' => 'JiFile / '.$extension,
'text' => $text);
$rows[] = JArrayHelper::toObject($row); ie, the 'href' => '....' value is extracted and moved above the $row = array( ... ) block, and an if() block inserted in between to check if K2 is installed, and if so, to get $href from there instead. This should allow JiFile to continue working as normal if K2 is not installed, but if K2 is installed, it will try to give a link to the article which has the item attached rather than just linking direct to the article. Known issues: - This patch assumes that JiFile is configured to search for files in K2's attachments folder. But I haven't checked for that. - This patch assumes that if you have K2 installed then you want this behaviour (ideally it would be optional, so you could revert to JiFile's normal behaviour) - Requires you to manually index the files after attaching them in K2. A good additional feature would be to hook into K2's attachment uploader so it could automatically index new attachments. Despite these points, I hope someone will find this useful, and I hope the JiFile developers will consider implementing it in the mainline plugin. |
Ultima modifica: 12/11/2015 10:06 da Simon C.
L\'Amministratore ha disattivato l\'accesso in scrittura al pubblico.
I seguenti utenti ringraziano:: Giampaolo
|
|
Thank you very much for your fantastic topic
![]() We hope to integrate this feature in the next version of JiFile (for now we have integrate this in the TODO list). Thanks again. |
If you like, if it was useful, consider a donation, Thanks
Se vuoi, se ti siamo stati utili, considera una donazione, Grazie Help us by voting our extensions on Joomla.org: JiFile JoomPhoto Mobile Easy Language
L\'Amministratore ha disattivato l\'accesso in scrittura al pubblico.
I seguenti utenti ringraziano:: Simon C
|
|
It's a pleasure. Do you know when the next version will be released? (so that I know whether I should implement my patch locally or wait for you to release it)
Also, is your code posted on Github? I looked for it so I could post this as a pull request, but I didn't find it. Finally, the mechanism I've used here would probably work for other plugins as well (eg Kunena forums allow attachments); with a bit more work it could be made generic so you could integrate with loads of things. Exciting possibilities. |
Ultima modifica: 12/11/2015 10:11 da Simon C.
L\'Amministratore ha disattivato l\'accesso in scrittura al pubblico.
|
Facendo click su qualunque link della pagina si accetta il loro utilizzo. Per saperne di piu'