Forum

JiFile for Joomla!

JIFile
JiFile is a component for Joomla! that allows you to index file contents (PDF, DOC, etc..) to perform searches in them.

Learn more...  Demo

JoomPhoto Mobile

JPhotoMobile
JoomPhoto Mobile is a component for Joomla! that allows you to share the photos from your Android device to your site Joomla.

Learn more...  Demo

iFile Framework

IFile
IFile is an open source framework written entirely in PHP, allows the indexing of textual content of a document (DOC, PDF, EXCEL, etc.) and a quick search within them.

Learn more...  Demo

Easy Language

EasyLanguage
Easy Language is a plugin for easy and immediate management of multilingual texts in every possible area of joomla, articles, components, modules, metadata, template, other components(example K2) etc.

Learn more...

Article Book Effect

Article Book Effect
View Joomla articles with the effect turns the page of a book. This plugin will display the contents of an article in Joomla as a real book or magazine, using all the benefits of HTML5

Learn more...  Demo

 

Passport photo

Passport photo
The most popular Android app that allows you to print photos cards for your documents with your Android smartphone, in a simple and intuitive way.

Learn more...

 

Crazy Shadow

Crazy Shadow
Crazy Shadow is the 3D fast-paced and fun puzzle Android game! Try to rotate and drag shapes in the position of their shadows without fail! Solve in succession all combinations of levels of the game.

Learn more...

 

Admin Countdown

Admin Countdown
Module for Joomla! 2.5 and 3.x displays in the administration part of the site, a timer with countdown of the time remaining in your session.

Learn more...  Demo

 
Welcome, Guest
Username: Password: Remember me

TOPIC: K2 Integration

K2 Integration 11 Nov 2015 14:46 #2104

  • Simon C
  • Simon C's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Thank you received: 1
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?
The administrator has disabled public write access.

K2 Integration 11 Nov 2015 18:08 #2105

  • Simon C
  • Simon C's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Thank you received: 1
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.
Last Edit: 12 Nov 2015 10:06 by Simon C.
The administrator has disabled public write access.
The following user(s) said Thank You: Giampaolo

K2 Integration 11 Nov 2015 20:03 #2106

  • Giampaolo
  • Giampaolo's Avatar
  • OFFLINE
  • Administrator
  • Posts: 465
  • Thank you received: 42
Thank you very much for your fantastic topic :woohoo:

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
The administrator has disabled public write access.
The following user(s) said Thank You: Simon C

K2 Integration 12 Nov 2015 10:09 #2107

  • Simon C
  • Simon C's Avatar
  • OFFLINE
  • Fresh Boarder
  • Posts: 3
  • Thank you received: 1
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.
Last Edit: 12 Nov 2015 10:11 by Simon C.
The administrator has disabled public write access.