如果有可用的更新,Joomla会在登录后端后进行检查。如果是,您可以在点击“查看更新”时看到概述。但是我想显示一条关于我开发的扩展程序更新的类似消息('有可用的更新')。我尝试了一些东西,但到目前为止我还没有管理。有什么建议吗?
答案 0 :(得分:1)
这是我为我的组件所遵循的代码。您可以在views-> tmpl-> default.php文件中使用相同的文件
<?php $user = JFactory::getUser(); ?>
<div class="UpdatesPage" style="margin-top: 8px">
<?php
$xml = JFactory::getXML(JPATH_ADMINISTRATOR .'/components/com_mycomponent/manifest.xml');//Path to your existing manifest file.
$existingversion = (string)$xml->version;
$url = 'http://example.com/downloads/mycomponent.xml';
//$url is path to your xml file which stores the latest version.
$ch = curl_init($url);//Execute curl and get the xml data available in my server
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$retcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
// 400 means not found, 200 means found.
curl_close($ch);
if($retcode == 200){
$xml2 = JFactory::getXML($url,true);
$latestversion = $xml2->update->version;
} else {
$latestversion = "";
}
?>
<h2>Version Update</h2>
<?php
if ( version_compare($latestversion, $existingversion) > 0) {
echo "<span style='color:#AFA;text-align:center;'>The version installed is ".$existingversion."</span><br />";
echo "<span style='color:red;text-align:center;'>The latest version is ".$latestversion."</span><br />";
} else {
echo "<span style='color:green;text-align:center;'>You have the Latest version</span>";
}
?>
</div>
这是我服务器中的xml文件,我更新它,以便我的组件用户可以看到他们何时访问我的组件更新页面
<?xml version="1.0" encoding="utf-8"?>
<updates>
<update>
<name><![CDATA[My Component]]></name>
<description><![CDATA[Download Component]]></description>
<element>pkg_mycomponent</element>
<type>package</type>
<client>0</client>
<version>1.1.1</version>
<infourl title="example.com">http://www.example.com</infourl>
<downloads>
<downloadurl type="full" format="zip">https://example.com/index.php?option=com_mycomponent</downloadurl>
</downloads>
<tags>
<tag>stable</tag>
</tags>
<maintainer><![CDATA[Amit Ray]]></maintainer>
<maintainerurl>http://www.example.com</maintainerurl>
<section>Testing</section>
<targetplatform name="joomla" version="3"/>
</update>
</updates>