具有 JFactory 访问权限的 Joomla 图像渲染扩展

发布于 2024-08-07 16:36:07 字数 147 浏览 2 评论 0原文

是否可以为 joomla 编写扩展或使用一些类似于 jumi 的现有插件来渲染 png 图像,但可以完全访问用户数据(使用 JFactory)? 换句话说,今天创建一个根据传递的参数呈现公共图像的 php 脚本不是问题。但如果我想访问用户数据并检查用户是否登录,这就成了一个问题。

Is it possible to write an extension for joomla or use some existing plugin similar to jumi to be able to render for instance a png image but with full access to user data (with JFactory)?
In other words today it's not a problem to create a php script that renders a public image based on parameters passed. But if I want to access user data and check wether the user logged in or not it becomes a problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

谈场末日恋爱 2024-08-14 16:36:07

您将需要创建一个在查询字符串中使用 format=raw 的组件(或组件的一部分)。您还需要使用 JDocument 对象将 MIME 类型设置为 image/png。为此,请在名为 image 的组件中创建一个视图(或您想要的任何名称)。然后,创建 view.raw.php,而不是创建 view.html.php 文件。在该文件内,添加如下代码:

<?php

defined( '_JEXEC' ) or die;

jimport( 'joomla.application.component.view');

class YourcomponentnamehereViewImage extends JView
{
    public function display($tpl = null)
    {
        $document =& JFactory::getDocument();
        $document->setMimeEncoding('image/png');

        // your image processing & output here
    }
}

不需要需要使用 default.php 创建一个 tmpl 文件夹,因为您不输出任何内容标记。

You will want to create a component (or a part of one) that uses format=raw in the query string. You'll also want to use the JDocument object to set the MIME type to image/png. To do this, create a view in the component called image (or whatever you'd like). Then, instead of creating a view.html.php file, create view.raw.php. Inside that file, add code like this:

<?php

defined( '_JEXEC' ) or die;

jimport( 'joomla.application.component.view');

class YourcomponentnamehereViewImage extends JView
{
    public function display($tpl = null)
    {
        $document =& JFactory::getDocument();
        $document->setMimeEncoding('image/png');

        // your image processing & output here
    }
}

You do not need to create a tmpl folder with default.php as you're not outputting any markup.

柳若烟 2024-08-14 16:36:07

我非常确定这是可能的。我讨厌周围没有任何可以绝对确定的东西,但我突然想到(已经有一段时间了!)我认为你正在寻找“原始输出”。

您应该能够在 URL 的查询字符串上添加一些内容来控制 Joomla“内容”的输出,而这些内容不完全是您的代码。据我记得,您需要在查询字符串中添加类似“&output=raw&no_html=1”的内容。

希望这至少能让你到达某个地方......

I am pretty sure that this is possible. I hate not having anything around me to be absolutely sure, but off the top of my head (and it's been a while!) I think you're looking for 'raw output'.

You should be able to add something on the URL's query string to control the output of the Joomla 'stuff' that is not your code exactly. From what I remember, you need to add something like '&output=raw&no_html=1' to the query string.

Hopefully that will at least get you somewhere...

孤独岁月 2024-08-14 16:36:07

感谢所有答案,尤其是jlleblanc。在他们的帮助下,我最终得到了一个使用现有众所周知的扩展的解决方案。

我们所需要的只是生成 php 输出的任何组件。我尝试过使用 Jumi,但它也应该适用于任何其他。

我们在 Jumi 组件(在 Jumi 应用程序管理器中)中创建一个项目,该项目会生成图像,例如填充矩形。

 <?php
     defined( '_JEXEC' ) or die( 'Restricted access' );

     $im = imagecreatetruecolor(300, 200);

     $bkgcolor = imagecolorallocate($im, 134, 134, 134);
     imagefilledrectangle($im, 0, 0, 300, 200, $bkgcolor);

     $document =& JFactory::getDocument();
     $document->setMimeEncoding('image/png');

     imagepng($im); 
     imagedestroy($im);
 ?>

根据组件规则添加后,我们有一个到该组件项目的链接

someoursite.com/index.php?option=com_jumi&fileid=3

其中 fileid=3 是基于实际 id 的字符串物品
如果我们只是按原样使用这个 url,我们将得到通常的 Joomla 布局,其中扭曲的页面将 png 流显示为文本(实际上视觉上不太舒服),但最后的一个小技巧“format=raw”会给我们这样的结果:需要。

someoursite.com/index.php?option=com_jumi&fileid=3&format=raw

就这样。之后浏览器中就会显示正确的图像。
再次感谢

Thanks to all answers, especially jlleblanc. With the help of them I ended up with a solution using existing well-known extension(s).

All we need is any component that produces php-output. I tried with Jumi, but also it should work with any other.

We create an item in Jumi component (in Jumi Applications Manager ) that produces an image, for example filled rectangle

 <?php
     defined( '_JEXEC' ) or die( 'Restricted access' );

     $im = imagecreatetruecolor(300, 200);

     $bkgcolor = imagecolorallocate($im, 134, 134, 134);
     imagefilledrectangle($im, 0, 0, 300, 200, $bkgcolor);

     $document =& JFactory::getDocument();
     $document->setMimeEncoding('image/png');

     imagepng($im); 
     imagedestroy($im);
 ?>

After adding according to the component rule we have a link to this component item

someoursite.com/index.php?option=com_jumi&fileid=3

Where fileid=3 is the string based on actual id of the item
If we just use this url as it is we will get usual Joomla layout with distorted page showing png stream as text (not so visually comfort actually), but a little trick "format=raw" at the end will give us the result that we need.

someoursite.com/index.php?option=com_jumi&fileid=3&format=raw

That's all. After that the correct image is displayed in the browser.
Thanks again

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文