2017-04-21 72 views
0

如果有任何更新可用,Joomla會在登錄後臺後進行檢查。如果是,您可以點擊「查看更新」查看概覽。但是我想顯示一個類似的消息,關於由我開發的擴展的更新('有更新可用')。我嘗試了一些東西,但到目前爲止我沒有管理。有什麼建議麼?如何爲Joomla擴展程序創建消息「更新可用」?

+0

也許檢查Akeeba備份代碼,它具有您描述的功能。 –

回答

1

這是我爲我的組件遵循的代碼。您可以使用相同的,則須─> 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> 
+0

謝謝,這工作正常 – Franky

+0

仍然是一個問題:我的更新xml和更新文件是在一個網站與https,這似乎沒有問題,當我在當地工作。然後腳本工作正常。當我使用https在實際站點上嘗試腳本時,出現無法讀取來自我的updatesite的XML文件的錯誤。另一方面,Joomla確實在更新列表中顯示更新正確。腳本中可以解決這個問題嗎? – Franky

+0

@Franky在'$ url ='http://example.com/downloads/mycomponent.xml';'你使用的是http還是https?正如你所說這是https,所以你需要改變這個變量爲https。所以你的網址應該是'url ='https://example.com/downloads/mycomponent.xml';' –

相關問題