0

Is there any plugin available for joomla 2.5 to embed code from github repository. For word press there is a plugin to achieve the same (http://wordpress.org/extend/plugins/github-code-viewer-2/). I wanted to do include code from my github repository into my joomla/k2 articles using something like

{github url='https://github.com/jamescarr/spring-integration/blob/master/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractFileListFilter.java'} 

By looking at the wp plugin I thought of writing my own joomla plugin but WP plugin is using *wp_remote_fopen* function and i did not find the same kind of function in joomla and read some articles about vulnerabilities using such remote_open functions. Here is what WP plugin is doing

function getGitHubFile($url, $ttl = null){
        self::__loadCache($url, $ttl);

        if (isset(self::$cache[$url])) {
            $code = self::$cache[$url];
        } else {
            $code = wp_remote_fopen($url . '?raw=true');
            if ($code == '') {
                return 'You need cURL installed to use GitHub_Code_Viewer';
            }
            $code = str_replace('<', '&lt;', $code);
            self::__setCache($url, $code);
        }

        return $code;
    }  
springpress
  • 134
  • 2
  • 3
  • 10
  • 1
    The wp_remote_fopen method of Wordpress would be equivalent to using cURL in Joomla. Look at the php.net for info about how to use this. If cURL is disabled on the server, then try with fopen() or file_get_contents(); – Stilero May 20 '12 at 08:07
  • Do we have any joomla api for the same instead of using php api? – springpress May 22 '12 at 15:53
  • Not that I know of. The JFile classes are for local files only. – Stilero May 23 '12 at 11:27

2 Answers2

1

EDIT: I've fixed the problems mentioned below & published a new plugin on github for Joomla 2.5 & 3.0 - the plugin author should be updating JED soon.


There is a Github Repo plugin for Joomla 2.5 which uses the repojs mentioned by @Jean-Marie Favre.

To get this working on Joomla 3 you need to edit githubrepo.php & change:

   if ( version_compare( JVERSION, '3.0', '<' ) == 1) { 
        if($jquery){
                $document->addScript('//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js');
        }
   } else {
        JHtml::_('jquery.framework');
   }

To just JHtml::_('jquery.framework');

Depending on your server setup you may also see the following errors in firebug:

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://raw.github.com/darcyclarke/Repo.js/master/fonts/repo.woff.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://raw.github.com/darcyclarke/Repo.js/master/fonts/repo.ttf.

Enabling Cross Domain Requests did not work for me so I fixed these by uploading all the fonts in repo.js to my webserver & editing the 4 paths in repo.js.

Community
  • 1
  • 1
Stuart Cardall
  • 1,513
  • 17
  • 14
0

You might want to have a try with http://darcyclarke.me/dev/repojs/ I've managed to include it in a joomla article (by including the javascript code directly in the page) so that one can browse a github repository from within a joomla article.