Vai al contenuto

Script verifica aggiornamenti di hook

Featured Replies

Inviato

7734fc853b1244b081ad863865b9717a.png

Ogni sviluppatore di Invision Power Board per sfruttare il sistema di aggiornamento interno della piattaforma deve realizzare uno script per permettere ai clienti di controllare nuove versioni del plugin.

 

Per permettere allo sviluppatore ciò il team IPS ha predisposto, dalla 3.1.x, il metodo $_GET.

 

Il codice

/* PATH (IPS_ROOT_PATH, DOC_IPS_ROOT_PATH) */define('MY_IPB_LOCATION', '/home/****/public_html/forum/');require_once( MY_IPB_LOCATION . '/initdata.php' );require_once( MY_IPB_LOCATION . CP_DIRECTORY  . '/sources/base/ipsRegistry.php' );$registry = ipsRegistry::instance();$registry->init();/******* INIZIO CLASSE *******//**  * Class versionCheck for IPB Hooks & Apps * @version 1.0.0 * @author Amged Osman * @link http://amgedosman.com/ * @date 11:19 PM Friday, December 6, 2013 */ class versionCheck{   private $ipb30x = array ( '30001', '30003','30004', '30005', '30008', '30009', '30010', '30011', '30012');  private $ipb31x = array ( '31000','31003', '31004', '31005', '31006','31007');  private $ipb32x = array ( '32000', '32001', '32002', '32003', '32004', '32005', '32006', '32007');  private $ipb33x = array ( '33000','33007', '33009', '33010', '33012', '33013', '33014', '33015', '33016');  private $ipb34x = array ( '34000', '34005', '34007', '34008', '34009', '34010', '34011', '34012' );    public $TRUEorFALSE = array (true => 1, false => 0);  public $theReturn = true;  public $debug = 0;  public $TRUEorFALSE_debug = array (true => 'Update Available', false => "You're up-to-date");                  /**       * @access public       * autoRun for the class & switch       */      public function autoRun(){          $this->boardVersion = isset($_GET['boardVersion']) ? $_GET['boardVersion'] : 00000;          $this->version = isset($_GET['version']) ? $_GET['version'] : 00000;          $this->fileId = isset($_GET['fileid']) ? $_GET['fileid'] : 000;                    switch ($this->fileId){              case '000':               default:               $this->showNone();               break;                              case '6766':               $this->pmod_all();	               break;          }        return $this->results;        $this->_returnResults();        exit();      }   /**    * @access protected    * later on this will return the public functions return to the index.php    */   protected function _returnResults(){      return $this->results;   }      /**    * @return (advanced) HTML & the update status    * @access public    */   public function showNone(){               $this->theReturn = false;     $html =  "No Id Passed";     $this->results = array ('html' => $html, 'return' => $this->theReturn );    }       /**    * @return (advanced) HTML & the update status    * @access public    */   public function pmod_all(){          $latestFileVersion = 20001;          if (in_array($this->boardVersion ,  $this->ipb30x) ){ $latestFileVersion = 10000; }          if (in_array($this->boardVersion ,  $this->ipb31x) ){ $latestFileVersion = 10000; }                    if ($latestFileVersion <= $this->version ){               $this->theReturn = false;          }                    $html = $this->TRUEorFALSE[$this->theReturn];          if ($this->debug === 1){             $html =  "Latest File: {$latestFileVersion}<br />Current Version: {$this->version}<br />{$this->TRUEorFALSE_debug[$this->theReturn]}";          }         $this->results = array ('html' => $html, 'return' => $this->theReturn );  }    }/******* FINE CLASSE *******/$versionCheckClass = new versionCheck();$versionCheckClass->debug = 0;$results = $versionCheckClass->autoRun();echo $results['html'];return $results['return'];

Funzionamento

La richiesta passa nello script chiamando la classe versionCheck e stampa a video 1 se c'è un aggiornamento e 0 se non presente.

 

Configurazione

Per inserire un nuovo elemento nel processo bisogna creare un "case" nella funzione autoRun esempio

               case '6766':               $this->pmod_all();	               break;

quindi bisogna creare un metodo/funzione esempio

   public function pmod_all(){          $latestFileVersion = 20001;          if (in_array($this->boardVersion ,  $this->ipb30x) ){ $latestFileVersion = 10000; }          if (in_array($this->boardVersion ,  $this->ipb31x) ){ $latestFileVersion = 10000; }                    if ($latestFileVersion <= $this->version ){               $this->theReturn = false;          }                    $html = $this->TRUEorFALSE[$this->theReturn];          if ($this->debug === 1){             $html =  "Latest File: {$latestFileVersion}<br />Current Version: {$this->version}<br />{$this->TRUEorFALSE_debug[$this->theReturn]}";          }         $this->results = array ('html' => $html, 'return' => $this->theReturn );  }

È possibile effettuare un debug (controllo delle variabili passate dall'url) cambiando il valore a 1, abilitatelo per un analisi e reimpostate 0 quanto possibile...

$versionCheckClass->debug = 1;

 e ricordatevi di specificare i parametri di get boardVersion e version esempio

http://vostrosito.it/check.php?&boardVersion=34000&version=20000&fileid=6766

Utilizzo

Salvate il codice in una pagina di ip.content o creando un file nell'ftp, nel mio caso check.php, in una directory a piacere...

Recatevi presso le impostazioni della hook creata e aggiungete in "Update URL" la pagina web esempio

http://www.invisionita.it/bomale/hook/check.php?&fileid=6766

ricordandovi di specificare il "fileid" passato nello switch di autoRun()

infine per controllare gli aggiornamenti delle hook seguite il link di seguito...

http://vostrosito.it/admin/index.php?&app=core&module=applications&section=hooks&do=hooks_overview&checkUpdates=1

Ringrazio amgedosman per l'articolo originale in inglese, e per le istruzioni passo passo di Michael (2011)

Per favore accedi per lasciare un commento

Potrai lasciare un commento dopo aver effettuato l'accesso

Accedi Ora

Chi sta navigando 0

  • Nessun utente registrato visualizza questa pagina.

Informazioni importanti

Abbiamo inserito dei cookies nel tuo dispositivo per aiutarti a migliorare la tua esperienza su questo sito. Puoi modificare le impostazioni dei cookie, altrimenti puoi accettarli cliccando su continua. to insert a cookie message.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.