【问题标题】:Joomla plugin to display github code into articles [closed]将 github 代码显示到文章中的 Joomla 插件 [关闭]
【发布时间】:2012-05-26 04:59:41
【问题描述】:

是否有任何可用于 joomla 2.5 的插件来嵌入来自 github 存储库的代码。对于 word press,有一个插件可以实现相同的功能(http://wordpress.org/extend/plugins/github-code-viewer-2/)。我想使用

之类的东西将我的 github 存储库中的代码包含到我的 joomla/k2 文章中
{github url='https://github.com/jamescarr/spring-integration/blob/master/spring-integration-file/src/main/java/org/springframework/integration/file/filters/AbstractFileListFilter.java'} 

通过查看 wp 插件,我想编写自己的 joomla 插件,但 WP 插件正在使用 *wp_remote_fopen* 功能,我在 joomla 中没有找到相同类型的功能,并阅读了一些关于使用此类 remote_open 函数的漏洞。这是 WP 插件正在做的事情

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;
    }  

【问题讨论】:

  • Wordpress 的 wp_remote_fopen 方法相当于在 Joomla 中使用 cURL。查看 php.net 以获取有关如何使用它的信息。如果服务器上禁用了 cURL,请尝试使用 fopen() 或 file_get_contents();
  • 我们有没有相同的 joomla api 而不是使用 php api?
  • 我不知道。 JFile 类仅用于本地文件。

标签: joomla github embed code-view


【解决方案1】:

编辑:我已经解决了下面提到的问题&published a new plugin on github for Joomla 2.5 & 3.0 - 插件作者应该很快更新JED


Joomla 2.5 有一个Github Repo 插件,它使用@Jean-Marie Favre 提到的repojs

要在 Joomla 3 上运行此功能,您需要编辑 githubrepo.php 并更改:

   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');
   }

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

根据您的服务器设置,您可能还会在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 对我不起作用,所以我通过将 repo.js 中的所有字体上传到我的网络服务器并编辑 repo.js 中的 4 个路径来修复这些问题。

【讨论】:

    【解决方案2】:

    您可能想试试http://darcyclarke.me/dev/repojs/ 我已经设法将它包含在一篇 joomla 文章中(通过将 javascript 代码直接包含在页面中),以便人们可以从 joomla 文章中浏览 github 存储库。

    【讨论】:

      猜你喜欢
      • 2012-12-09
      • 1970-01-01
      • 2011-04-20
      • 1970-01-01
      • 2014-09-07
      • 2010-09-09
      • 2012-12-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多