Vanilla 1 is no longer supported or maintained. If you need a copy, you can get it here.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.
Extension update Checker
I worked on an api to check the availability of update for extensions. Hope it can help.
The api:
The checker (Framework.Control.UpdateCheck.php):
and settings_update_check_validpostback.php:
the RequestbyPost function:
The api:
<?php
include('../appg/settings.php');
include('../appg/init_ajax.php');
// Mode of this api. Serialize only available. Is xml neccessary?
$ValideMode = array('php');
$ApiMode = ForceIncomingString('mode', 'php');
if (!in_array($ApiMode, $ValideMode)) echo $Context->GetDefinition('WrongApiMode');
else {
$ApiExtension = ForceIncomingString('extensions', '');
if($ApiMode == 'php') $ApiExtension = @unserialize($ApiExtension);
$return = GetExtensionByName($Context, $ApiExtension);
if ($ApiMode == 'php') $return = serialize($return);
echo $return;
}
$Context->Unload();
function GetExtensionByName(&$Context, $ApiExtension){
$return = array('Status' => 0, 'Warnings' => array(), 'Extensions' => array());
if(!is_array($ApiExtension) && !count($ApiExtension)) $Context->WarningCollector->Add($Context->GetDefinition('NotValidData'));
else {
// Guess of want would be the names and structure of the extension database of lussumo
$s = $Context->ObjectFactory->NewContextObject($Context, "SqlBuilder");
$s->SetMainTable('Extension', 'ext');
$s->AddSelect(array('ExtensionID', 'ExtensionName', 'ExtensionVersion', 'ExtensionComment'), 'ext');
foreach ($ApiExtension as $Name) {
$Name = FormatStringForDatabaseInput($Name);
$s->AddWhere('ext', 'ExtensionName', '', $Name, '=', 'or', '', 1);
}
$Data = $Context->Database->Select($s, 'Api', 'UpdateInfo', 'An error occurred while attempting to retrieve the extension informations.');
while ($Row = $Context->Database->GetRow($Data)) {
$return['Extensions'][ForceString($Row['ExtensionName'], '')] = array(
'ExtensionID' => ForceInt($Row['ExtensionID'], 0),
'ExtensionVersion' => ForceString($Row['ExtensionVersion'], ''),
'ExtensionComment' => ForceString($Row['ExtensionComment'], ''));
}
}
if($Context->ErrorManager->Iif()) {
if ($Context->WarningCollector->Iif() == "0") $return['Warnings'] = $Context->WarningCollector->aMessages;
else $return['Status'] = 1;
}
return $return;
}
?>
The checker (Framework.Control.UpdateCheck.php):
...
function UpdateCheck(&$Context) {
$this->Name = 'UpdateCheck';
$this->ValidActions = array('UpdateCheck', 'ProcessUpdateCheck', 'ProcessUpdateReminder');
$this->Constructor($Context);
if (!$this->Context->Session->User->Permission('PERMISSION_CHECK_FOR_UPDATES')) {
$this->IsPostBack = 0;
}
if ($this->IsPostBack) {
$this->Context->PageTitle = $this->Context->GetDefinition('UpdatesAndReminders');
$this->ReminderSelect = $this->Context->ObjectFactory->NewObject($this->Context, 'Select');
$this->ReminderSelect->Name = 'ReminderRange';
$this->ReminderSelect->AddOption('', $this->Context->GetDefinition('Never'));
$this->ReminderSelect->AddOption('Weekly', $this->Context->GetDefinition('Weekly'));
$this->ReminderSelect->AddOption('Monthly', $this->Context->GetDefinition('Monthly'));
$this->ReminderSelect->AddOption('Quarterly', $this->Context->GetDefinition('Quarterly'));
$this->ReminderSelect->SelectedValue = $this->Context->Configuration['UPDATE_REMINDER'];
$SettingsFile = $this->Context->Configuration['APPLICATION_PATH'].'conf/settings.php';
}
if ($this->IsPostBack && $this->PostBackAction == 'ProcessUpdateCheck') {
// Ping lussumo.com for update information
$this->LussumoMessage = OpenUrl($this->Context->Configuration['UPDATE_URL']
.'?Application='.APPLICATION
.'&Version='.APPLICATION_VERSION
.'&Language='.$this->Context->Configuration['LANGUAGE']
.'&RequestUrl='.$this->Context->Configuration['BASE_URL'],
$this->Context);
// Get list of extensions
$Extension = $this->Context->ObjectFactory->CreateControl($this->Context, "ExtensionForm");
$Extension->Extensions = array();
$Extension->DefineExtensions();
$Extensions = array();
foreach ($Extension->Extensions as $Ext) {
$Extensions[] = $Ext->Name;
}
// Request info for these extensions to Lussomo.com
$Data = 'mode=php&extensions='.urlencode(serialize($Extensions));
$LussumoExtAnswer = RequestbyPost($Context, 'tcp://', 'lussumo.com', '/api/CheckExtensionUpdate.php', $Data, 80);
$LussumoExtAnswer = unserialize($LussumoExtAnswer[1]);
// Compare last version number of extension with the ones on the forum
if ($LussumoExtAnswer['Status'] == 1 && isset($LussumoExtAnswer['Status'])){
$this->ExtensionsToUpdate = array();
$this->ExtensionsToCheck = array();
foreach ($Extension->Extensions as $Extension) {
if (isset($LussumoExtAnswer['Extensions'][$Extension->Name])) {
if(version_compare($Extension->Version, $LussumoExtAnswer['Extensions'][$Extension->Name]['ExtensionVersion'], '<')) {
$this->ExtensionsToUpdate[$Extension->Name] = $LussumoExtAnswer['Extensions'][$Extension->Name];
$this->ExtensionsToUpdate[$Extension->Name]['InstalledVersion'] = $Extension->Version;
}
}
else $this->ExtensionsToCheck[$Extension->Name] = array(
'Url' => $Extension->Url,
'InstalledVersion' => $Extension->Version,
'ExtensionComment' => $Extension->Description
);
}
}
if ($this->Context->WarningCollector->Count() == 0 && $this->LussumoMessage) {
$this->PostBackValidated = 1;
// Also record that the check occurred
$ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context, "ConfigurationManager");
$ConfigurationManager->DefineSetting('LAST_UPDATE', mktime(), 1);
$ConfigurationManager->SaveSettingsToFile($SettingsFile);
}
} elseif ($this->IsPostBack && $this->PostBackAction == 'ProcessUpdateReminder') {
$ReminderRange = ForceIncomingString('ReminderRange', '');
if (!in_array($ReminderRange, array('Weekly','Monthly','Quarterly'))) $ReminderRange = '';
// Set the Reminder configuration option
$ConfigurationManager = $this->Context->ObjectFactory->NewContextObject($this->Context, "ConfigurationManager");
$ConfigurationManager->DefineSetting('UPDATE_REMINDER', $ReminderRange, 1);
if ($ConfigurationManager->SaveSettingsToFile($SettingsFile)) {
// If everything was successful, Redirect back with saved changes message
if ($this->Context->WarningCollector->Iif()) {
header("Location:".GetUrl($this->Context->Configuration, $this->Context->SelfUrl, "", "", "", "", "PostBackAction=UpdateCheck&Saved=1"));
die();
}
}
}
$this->CallDelegate('Constructor');
}
and settings_update_check_validpostback.php:
<?php
// Note: This file is included from the library/Framework/Framework.Control.UpdateCheck.php control.
echo '<div id="Form" class="Account UpdateCheck">
<fieldset>
<legend>'.$this->Context->GetDefinition('UpdateCheck').'</legend>
<form id="frmUpdateCheck" method="post" action="">
<h3>'.$this->Context->GetDefinition('VanillaCore').'</h3>
<p class="Description">'.$this->LussumoMessage.'</p>
<h3>'.$this->Context->GetDefinition('Extensions').'</h3>';
if (count($this->ExtensionsToUpdate)) {
echo '<ul><h4>'.$this->Context->GetDefinition('ExtensionToUpdate').'</h4>';
foreach ($this->ExtensionsToUpdate as $Name => $Property) {
$href = 'href="http://lussumo.com/addons/index.php?PostBackAction=AddOn&AddOnID='.$Property['ExtensionID'].'"';
echo '<li><p class="Description"><a '.$href.'>'.$Name.' '.$Property['ExtensionVersion'].'</a> ('.$this->Context->GetDefinition('CurrentInstalledVersion').': '.$Property['InstalledVersion'].'): '.$Property['ExtensionComment'].'</p></li>';
}
echo '</ul>';
}
if (count($this->ExtensionsToCheck)){
echo '<ul><h4>'.$this->Context->GetDefinition('ExtensionToCheck').'</h4>';
foreach ($this->ExtensionsToCheck as $Name => $Property) {
$href = 'href='.$Property['Url'].'"';
echo '<li><p class="Description"><a '.$href.'>'.$Name.'</a> ('.$this->Context->GetDefinition('CurrentInstalledVersion').': '.$Property['InstalledVersion'].'): '.$Property['ExtensionComment'].'</p></li>';
}
echo '</ul>';
}
if (!count($this->ExtensionsToUpdate) && !count($this->ExtensionsToCheck))
echo '<p class="Description">'.$this->Context->GetDefinition('YourExtensionAreUpToDate').'</p>';
echo ' </form>
</fieldset>
</div>';
?>
the RequestbyPost function:
function RequestbyPost(&$Context, $Protocol, $Host, $Path, $Data, $Port = 80){
$sock = fsockopen($Protocol.$Host, $Port, $errno, $errstr, 30);
if (!$sock) {
$Context->WarningCollector->Add($Context->GetDefinition('CannotGetConnection').': '.$errstr.' ('.$errno.').');
return false;
}
else {
fwrite($sock, "POST $Path HTTP/1.0\r\n");
fwrite($sock, "Host: $Host\r\n");
fwrite($sock, "Content-type: application/x-www-form-urlencoded\r\n");
fwrite($sock, "Content-length: " . strlen($Data) . "\r\n");
fwrite($sock, "Accept: */*\r\n");
fwrite($sock, "\r\n");
fwrite($sock, "$Data\r\n");
fwrite($sock, "\r\n");
$headers = "";
while ($str = trim(fgets($sock, 4096))) $headers .= "$str\n";
echo "\n";
$body = "";
while (!feof($sock)) $body .= fgets($sock, 4096);
fclose($sock);
return array($headers, $body);
}
}
0
This discussion has been closed.
Comments
No, there is nothing to download. I hope that it will be soon available.
To work, the checker on vanilla would have to be more complicate: the response from the api can't use the name of the extension as a key, and the checker would have to check if there is not two answers for the same extesnion (if there is, the extension is in the list of extensions to check manually).
Quote from Mark's mail to all extension developers:
"I have been working on a method whereby the update checker
in Vanilla will not only check for updates to the core
Vanilla files, but it will also look up the extensions in
the installation and see if there are new versions available
at the addons site."
I think it is one of the most wanted and useful functions that the next Vanilla release should contain