[ Index ]
 

Code source de CMS made simple 1.0.5

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/modules/ModuleManager/ -> ModuleManager.module.php (source)

   1  <?php
   2  #-------------------------------------------------------------------------
   3  # Module: ModuleManager - A client for the ModuleRepository, this module allows previewing, 
   4  # and installing modules from remote sites without the need for ftping, or unzipping archives.  
   5  # Module XML files are downloaded using SOAP, integrity verified, and then expanded automatically.
   6  #
   7  # Version: 1.1.3, Robert Campbell <rob@techcom.dyndns.org>
   8  #
   9  #-------------------------------------------------------------------------
  10  # CMS - CMS Made Simple is (c) 2006 by Ted Kulp (wishy@cmsmadesimple.org)
  11  # This project's homepage is: http://www.cmsmadesimple.org
  12  #
  13  # This file originally created by ModuleMaker module, version 0.2
  14  # Copyright (c) 2006 by Samuel Goldstein (sjg@cmsmadesimple.org) 
  15  #
  16  #-------------------------------------------------------------------------
  17  #
  18  # This program is free software; you can redistribute it and/or modify
  19  # it under the terms of the GNU General Public License as published by
  20  # the Free Software Foundation; either version 2 of the License, or
  21  # (at your option) any later version.
  22  #
  23  # This program is distributed in the hope that it will be useful,
  24  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  25  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26  # GNU General Public License for more details.
  27  # You should have received a copy of the GNU General Public License
  28  # along with this program; if not, write to the Free Software
  29  # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  30  # Or read it online: http://www.gnu.org/licenses/licenses.html#GPL
  31  #
  32  #-------------------------------------------------------------------------
  33  
  34  #-------------------------------------------------------------------------
  35  # For Help building modules:
  36  # - Read the Documentation as it becomes available at
  37  #   http://dev.cmsmadesimple.org/
  38  # - Check out the Skeleton Module for a commented example
  39  # - Look at other modules, and learn from the source
  40  # - Check out the forums at http://forums.cmsmadesimple.org
  41  # - Chat with developers on the #cms IRC channel
  42  #-------------------------------------------------------------------------
  43  
  44  define('MINIMUM_REPOSITORY_VERSION','1.0.2');
  45  
  46  function uasort_cmp_details( $e1, $e2 )
  47  {
  48    if( strtolower($e1['name']) < strtolower($e2['name']) )
  49      {
  50        return -1;
  51      }
  52    else if( strtolower($e1['name']) > strtolower($e2['name']) )
  53      {
  54        return 1;
  55      }
  56    return version_compare( $e2['version'], $e1['version'] );
  57  }
  58  
  59  class ModuleManager extends CMSModule
  60  {
  61  
  62    function GetName()
  63    {
  64      return 'ModuleManager';
  65    }
  66  
  67  
  68    /*---------------------------------------------------------
  69     GetFriendlyName()
  70     ---------------------------------------------------------*/
  71    function GetFriendlyName()
  72    {
  73      return $this->Lang('friendlyname');
  74    }
  75  
  76      
  77    /*---------------------------------------------------------
  78     GetVersion()
  79     ---------------------------------------------------------*/
  80    function GetVersion()
  81    {
  82      return '1.1.4';
  83    }
  84  
  85  
  86    /*---------------------------------------------------------
  87     GetHelp()
  88     ---------------------------------------------------------*/
  89    function GetHelp()
  90    {
  91      return $this->Lang('help');
  92    }
  93  
  94  
  95    /*---------------------------------------------------------
  96     GetAuthor()
  97     ---------------------------------------------------------*/
  98    function GetAuthor()
  99    {
 100      return 'calguy1000';
 101    }
 102  
 103  
 104    /*---------------------------------------------------------
 105     GetAuthorEmail()
 106     ---------------------------------------------------------*/
 107    function GetAuthorEmail()
 108    {
 109      return 'calguy1000@hotmail.com';
 110    }
 111  
 112  
 113    /*---------------------------------------------------------
 114     GetChangeLog()
 115     ---------------------------------------------------------*/
 116    function GetChangeLog()
 117    {
 118      return $this->Lang('changelog');
 119    }
 120  
 121  
 122    /*---------------------------------------------------------
 123     IsPluginModule()
 124     ---------------------------------------------------------*/
 125    function IsPluginModule()
 126    {
 127      return false;
 128    }
 129  
 130  
 131    /*---------------------------------------------------------
 132     HasAdmin()
 133     ---------------------------------------------------------*/
 134    function HasAdmin()
 135    {
 136      return true;
 137    }
 138  
 139  
 140    /*---------------------------------------------------------
 141     IsAdminOnly()
 142     ---------------------------------------------------------*/
 143    function IsAdminOnly()
 144    {
 145      return true;
 146    }
 147  
 148  
 149    /*---------------------------------------------------------
 150     GetAdminSection()
 151     ---------------------------------------------------------*/
 152    function GetAdminSection()
 153    {
 154      return 'extensions';
 155    }
 156  
 157  
 158    /*---------------------------------------------------------
 159     GetAdminDescription()
 160     ---------------------------------------------------------*/
 161    function GetAdminDescription()
 162    {
 163      return $this->Lang('admindescription');
 164    }
 165  
 166  
 167    /*---------------------------------------------------------
 168     VisibleToAdminUser()
 169     ---------------------------------------------------------*/
 170    function VisibleToAdminUser()
 171    {
 172      if( $this->CheckPermission('Modify Site Preferences') ||
 173      $this->CheckPermission('Modify Modules') )
 174        {
 175      return true;
 176        }
 177      return false;
 178    }
 179      
 180  
 181    /*---------------------------------------------------------
 182     CheckAccess()
 183     ---------------------------------------------------------*/
 184    function CheckAccess($id, $params, $returnid,$perm = 'Modify Modules')
 185    {
 186      if (! $this->CheckPermission($perm))
 187        {
 188      $this->_DisplayErrorPage($id, $params, $returnid,
 189                  $this->Lang('accessdenied'));
 190      return false;
 191        }
 192      return true;
 193    }
 194      
 195    /*---------------------------------------------------------
 196     _DisplayErrorPage()
 197     This is a simple function for generating error pages.
 198     ---------------------------------------------------------*/
 199    function _DisplayErrorPage($id, &$params, $returnid, $message='')
 200    {
 201      $this->smarty->assign('title_error', $this->Lang('error'));
 202      $this->smarty->assign_by_ref('message', $message);
 203        
 204      // Display the populated template
 205      echo $this->ProcessTemplate('error.tpl');
 206    }
 207      
 208  
 209  
 210    /*---------------------------------------------------------
 211     GetDependencies()
 212     ---------------------------------------------------------*/
 213    function GetDependencies()
 214    {
 215      return array('nuSOAP'=>'1.0.1');
 216    }
 217  
 218  
 219    /*---------------------------------------------------------
 220     MinimumCMSVersion()
 221     ---------------------------------------------------------*/
 222    function MinimumCMSVersion()
 223    {
 224      // TODO: THIS SHOULD BE 1.0.4-svn OR SOMETHING
 225      return "1.0.4";
 226    }
 227  
 228  
 229    /*---------------------------------------------------------
 230     Install()
 231     ---------------------------------------------------------*/
 232    function Install()
 233    {
 234      $this->SetPreference('module_repository','http://modules.cmsmadesimple.org/soap.php?module=ModuleRepository');
 235  
 236      // put mention into the admin log
 237      $this->Audit( 0, $this->Lang('friendlyname'), $this->Lang('installed',$this->GetVersion()));
 238    }
 239  
 240    /*---------------------------------------------------------
 241     InstallPostMessage()
 242     ---------------------------------------------------------*/
 243    function InstallPostMessage()
 244    {
 245      return $this->Lang('postinstall');
 246    }
 247  
 248  
 249    /*---------------------------------------------------------
 250     UninstallPostMessage()
 251     ---------------------------------------------------------*/
 252    function UninstallPostMessage()
 253    {
 254      return $this->Lang('postuninstall');
 255    }
 256  
 257  
 258    /*---------------------------------------------------------
 259     Upgrade()
 260     ---------------------------------------------------------*/
 261    function Upgrade($oldversion, $newversion)
 262    {
 263      $current_version = $oldversion;
 264      switch($current_version)
 265        {
 266        case "1.0":
 267      $this->SetPreference('module_repository','http://modules.cmsmadesimple.org/soap.php?module=ModuleRepository');
 268      break;
 269        }
 270          
 271      // put mention into the admin log
 272      $this->Audit( 0, $this->Lang('friendlyname'), $this->Lang('upgraded',$this->GetVersion()));
 273    }
 274  
 275  
 276    /**
 277     * UninstallPreMessage()
 278     */
 279    function UninstallPreMessage()
 280    {
 281      return $this->Lang('really_uninstall');
 282    }
 283  
 284      
 285    /*---------------------------------------------------------
 286     Uninstall()
 287     ---------------------------------------------------------*/
 288    function Uninstall()
 289    {
 290      $this->RemovePreference('module_repository');
 291  
 292      // put mention into the admin log
 293      $this->Audit( 0, $this->Lang('friendlyname'), $this->Lang('uninstalled'));
 294    }
 295  
 296  
 297    /*---------------------------------------------------------
 298     DoAction($action, $id, $params, $returnid)
 299     ---------------------------------------------------------*/
 300    function DoAction($action, $id, $params, $returnid=-1)
 301    {
 302      switch ($action)
 303        {
 304        case 'installmodule':
 305      {
 306        if ($this->CheckAccess($id, $params, $returnid,'Modify Modules'))
 307          {
 308            $this->_DoAdminInstallModule( $id, $params, $returnid );
 309          }
 310        break;
 311      }
 312  
 313        case 'modulehelp':
 314      {
 315        $this->_DisplayAdminSoapModuleHelp( $id, $params, $returnid );
 316      }
 317      break;
 318  
 319        case 'moduleabout':
 320      {
 321        $this->_DisplayAdminSoapModuleAbout( $id, $params, $returnid );
 322      }
 323      break;
 324  
 325        // fallback through to call the action.xxxx.php file
 326        default:
 327      parent::DoAction( $action, $id, $params, $returnid );
 328      break;
 329        }
 330    }
 331  
 332  
 333    /*----------------------------------------------------------
 334     _BuildModuleData( $xmldetails, $installdetails );
 335     build a hash of info about the installed modules.
 336     ---------------------------------------------------------*/
 337    function _BuildModuleData( &$xmldetails, &$installdetails )
 338    {
 339      $results = array();
 340      foreach( $xmldetails as $det1 )
 341        {
 342      $found = 0;
 343      foreach( $installdetails as $det2 )
 344        {
 345          if( $det1['name'] == $det2['name'] )
 346            {
 347          $found = 1;
 348          // if the version of the xml file is greater than that of the
 349          // installed module, we have an upgrade
 350          $res = version_compare( $det1['version'], $det2['version'] );
 351          if( $res == 1 )
 352            {
 353              $det1['status'] = 'upgrade';
 354            }
 355          else if( $res == 0 )
 356            {
 357              $det1['status'] = 'uptodate';
 358            }
 359          else
 360            {
 361              $det1['status'] = 'newerversion';
 362            }
 363          $results[] = $det1;
 364            }
 365        }
 366      if( $found == 0 )
 367        {
 368          // we don't have this module installed
 369          $det1['status'] = 'notinstalled';
 370          $results[] = $det1;
 371        }
 372        }
 373  
 374      // now we have everything
 375      // let's try sorting it
 376      uasort( $results, 'uasort_cmp_details' );
 377      return $results;
 378    }
 379  
 380  
 381    /*---------------------------------------------------------
 382     _DisplayAdminModulesTab()
 383     ---------------------------------------------------------*/
 384    function _DisplayAdminModulesTab($id, &$params, $returnid)
 385    {
 386      global $session;
 387  
 388      $caninstall = true;
 389      if( FALSE == can_admin_upload() )
 390        {
 391      echo '<div class="pageerrorcontainer"><div class="pageoverflow"><p class="pageerror">'.$this->Lang('error_permissions').'</p></div></div>';
 392      $caninstall = false;
 393        }
 394  
 395      if( !isset( $params['curletter'] ) )
 396        {
 397      $sess_keys = array_keys( $_SESSION );
 398      foreach( $sess_keys as $sess_key )
 399        {
 400          if( preg_match( '/modulemanager_cache/', $sess_key ) )
 401            {
 402          unset( $_SESSION[$sess_key] );
 403            }
 404        }
 405        }
 406  
 407      // get the modules available in the repository
 408      $repmodules = '';
 409      {
 410        $result = $this->_GetRepositoryModules();
 411        if( ! $result[0] )
 412      {
 413        $this->_DisplayErrorPage( $id, $params, $returnid, $result[1] );
 414        return;
 415      }
 416        $repmodules = $result[1];
 417      }
 418  
 419      // get the modules that are already installed
 420      $instmodules = '';
 421      {
 422        $result = $this->_GetInstalledModules();
 423        if( ! $result[0] )
 424      {
 425        $this->_DisplayErrorPage( $id, $params, $returnid, $result[1] );
 426        return;
 427      }
 428        
 429        $instmodules = $result[1];
 430      }
 431  
 432      // cross reference them
 433      $data = $this->_BuildModuleData( $repmodules, $instmodules );
 434  
 435      if( count( $data ) )
 436        {
 437      $size = count($data);
 438  
 439      // check for permissions
 440      $moduledir = dirname(dirname(dirname(__FILE__))).DIRECTORY_SEPARATOR."modules";
 441      $writable = is_writable( $moduledir );    
 442  
 443      $letters = array();
 444      if( count( $data ) > get_preference(get_userid(),'page_limit'))
 445        {
 446          // we gotta do alphabetic pagination
 447          $pagination = true;
 448        }
 449        
 450      // build the table
 451      $rowarray = array();
 452      $rowclass = 'row1';
 453      $letters = array();
 454      $firstletter = '';
 455      foreach( $data as $row )
 456        {
 457  
 458          $onerow = new stdClass();
 459          
 460          $letter = strtoupper($row['name'][0]);
 461          $firstletter = ($firstletter == '') ? $letter : $firstletter;
 462          $curletter = isset($params['curletter']) ? $params['curletter'] : $firstletter;
 463          $letters[$letter] = 
 464              ($letter == $curletter) ? '<strong>'.$letter .'</strong>' 
 465              : $this->CreateLink($id,'defaultadmin',$returnid, $letter, array('curletter'=>$letter));
 466          if ($letter != $curletter)
 467            {
 468          continue;
 469            }
 470  
 471          $onerow->name = $row['name'];
 472          $onerow->version = $row['version'];
 473  
 474          $onerow->helplink = $this->CreateLink( $id, 'modulehelp', $returnid,
 475                             $this->Lang('helptxt'), 
 476                             array('name' => $row['name'],
 477                               'version' => $row['version'],
 478                               'filename' => $row['filename']));
 479          $onerow->aboutlink = $this->CreateLink( $id, 'moduleabout', $returnid,
 480                              $this->Lang('abouttxt'), 
 481                              array('name' => $row['name'],
 482                                'version' => $row['version'],
 483                                'filename' => $row['filename']));
 484  
 485          switch( $row['status'] ) 
 486            {
 487            case 'uptodate':
 488          $onerow->status = $this->Lang('uptodate');
 489          break;
 490            case 'newerversion':
 491          $onerow->status = $this->Lang('newerversion');
 492          break;
 493            case 'notinstalled':
 494          {
 495            $mod = $moduledir.DIRECTORY_SEPARATOR.$row['name'];
 496            if( (($writable && is_dir($mod) && is_directory_writable( $mod )) ||
 497                 ($writable && !file_exists( $mod ) )) && $caninstall )
 498              {
 499                $onerow->status = $this->CreateLink( $id, 'installmodule', $returnid,
 500                                 $this->Lang('download'), 
 501                                 array('name' => $row['name'],
 502                                   'version' => $row['version'],
 503                                   'filename' => $row['filename'],
 504                                   'size' => $row['size']));
 505              }
 506  
 507            else
 508              {
 509                $onerow->status = $this->Lang('cantdownload');
 510              }
 511            break;
 512          }
 513            case 'upgrade':
 514          {
 515            $mod = $moduledir.DIRECTORY_SEPARATOR.$row['name'];
 516            if( (($writable && is_dir($mod) && is_directory_writable( $mod )) ||
 517                 ($writable && !file_exists( $mod ) )) && $caninstall )
 518              {
 519                $onerow->status = $this->CreateLink( $id, 'upgrademodule', $returnid,
 520                                 $this->Lang('download'), 
 521                                 array('name' => $row['name'],
 522                                   'version' => $row['version'],
 523                                   'filename' => $row['filename'],
 524                                   'size' => $row['size']));
 525              }
 526            else
 527              {
 528                $onerow->status = $this->Lang('cantdownload');
 529              }
 530            break;
 531          }
 532            }
 533          
 534          $onerow->size = (int)((float) $row['size'] / 1024.0 + 0.5);
 535          $onerow->rowclass = $rowclass;
 536          if( isset( $row['description'] ) )
 537            {
 538          $onerow->description=$row['description'];
 539            }
 540          $rowarray[] = $onerow;
 541          ($rowclass == "row1" ? $rowclass = "row2" : $rowclass = "row1");
 542        } // for
 543  
 544      // and display our page
 545      $this->smarty->assign('letters', implode('&nbsp;',array_values($letters)));
 546      $this->smarty->assign('nametext',$this->Lang('nametext'));
 547      $this->smarty->assign('vertext',$this->Lang('vertext'));
 548      $this->smarty->assign('sizetext',$this->Lang('sizetext'));
 549      $this->smarty->assign('statustext',$this->Lang('statustext'));
 550      $this->smarty->assign('items', $rowarray);
 551      $this->smarty->assign('itemcount', count($rowarray));
 552        }
 553      else
 554        {
 555      $this->smarty->assign('message', $this->Lang('error_connectnomodules'));
 556        }
 557      echo $this->processTemplate('adminpanel.tpl');
 558    }
 559  
 560  
 561    /*---------------------------------------------------------
 562     _DisplayAdminModulesTab()
 563     ---------------------------------------------------------*/
 564    function _DisplayAdminPrefsTab($id, &$params, $returnid)
 565    {
 566      $this->smarty->assign('formstart',$this->CreateFormStart( $id, 'setprefs', $returnid ));
 567      $this->smarty->assign('formend',$this->CreateFormEnd());
 568      $this->smarty->assign('prompt_url',$this->Lang('prompt_repository_url'));
 569      $this->smarty->assign('input_url',$this->CreateInputText($id, 'url', 
 570                                 $this->GetPreference('module_repository'),
 571                                 80, 255 ));
 572      $this->smarty->assign('extratext_url',$this->Lang('text_repository_url'));
 573      
 574      $this->smarty->assign('prompt_reseturl',$this->Lang('prompt_reseturl'));
 575      $this->smarty->assign('input_reseturl',$this->CreateInputSubmit($id,'reseturl',$this->Lang('reset')));
 576  
 577      $this->smarty->assign('prompt_chunksize',$this->Lang('prompt_dl_chunksize'));
 578      $this->smarty->assign('input_chunksize',$this->CreateInputText($id, 'input_dl_chunksize',
 579                                     $this->GetPreference('dl_chunksize',256),3,3));
 580      $this->smarty->assign('extratext_chunksize',$this->Lang('text_dl_chunksize'));
 581  
 582      $this->smarty->assign('prompt_resetcache',$this->Lang('prompt_resetcache'));
 583      $this->smarty->assign('input_resetcache',$this->CreateInputSubmit($id,'resetcache',$this->Lang('reset')));
 584                
 585      $this->smarty->assign('submit',$this->CreateInputSubmit( $id, 'submit', $this->Lang('submit')));
 586      $this->smarty->assign('prompt_otheroptions',$this->Lang('prompt_otheroptions'));
 587      $this->smarty->assign('prompt_settings',$this->Lang('prompt_settings'));
 588      echo $this->ProcessTemplate('adminprefs.tpl');
 589    }
 590  
 591    /*---------------------------------------------------------
 592     _DisplayAdminSoapModuleHelp()
 593     Display the help for an a module on the repository
 594     ---------------------------------------------------------*/
 595    function _DisplayAdminSoapModuleHelp($id, &$params, $returnid)
 596    {
 597      if( !isset( $params['name'] ) )
 598        {
 599      $this->_DisplayErrorPage( $id, $params, $returnid,
 600                    $this->Lang('error_insufficientparams'));
 601      return;
 602        }
 603      $name = $params['name'];
 604  
 605      if( !isset( $params['version'] ) )
 606        {
 607      $this->_DisplayErrorPage( $id, $params, $returnid,
 608                    $this->Lang('error_insufficientparams'));
 609      return;
 610        }
 611      $version = $params['version'];
 612  
 613      $url = $this->GetPreference('module_repository');
 614      if( $url == '' )
 615        {
 616      $this->_DisplayErrorPage( $id, $params, $returnid,
 617                    $this->Lang('error_norepositoryurl'));
 618      return;
 619        }
 620  
 621      if( !isset($params['filename'] ) )
 622        {
 623      $this->_DisplayErrorPage( $id, $params, $returnid,
 624                    $this->Lang('error_nofilename'));
 625      return;
 626        }
 627      $xmlfile = $params['filename'];
 628  
 629      $nusoap =& $this->GetModuleInstance('nuSOAP');
 630      $nusoap->Load();
 631      $nu_soapclient =& new nu_soapclient($url,false,false,false,false,false,90,90);
 632      if( $err = $nu_soapclient->GetError() )
 633        {
 634      $this->_DisplayErrorPage( $id, $params, $returnid,
 635                    'SOAP Error: '.$err);
 636      return;
 637        }
 638      $help = $nu_soapclient->call('ModuleRepository.soap_modulehelp',array('name' => $xmlfile ));
 639      if( $err = $nu_soapclient->GetError() )
 640        {
 641      $this->_DisplayErrorPage( $id, $params, $returnid,
 642                    'SOAP Error: '.$err);
 643      echo htmlspecialchars($nu_soapclient->response);
 644      return;
 645        }
 646      if( $help[0] == false )
 647        {
 648      $this->_DisplayErrorPage( $id, $params, $returnid,
 649                    $help[1] );
 650      return;
 651        }
 652      $this->smarty->assign('title',$this->Lang('helptxt'));
 653      $this->smarty->assign('moduletext',$this->Lang('nametext'));
 654      $this->smarty->assign('vertext',$this->Lang('vertext'));
 655      $this->smarty->assign('xmltext',$this->Lang('xmltext'));
 656      $this->smarty->assign('modulename',$name);
 657      $this->smarty->assign('moduleversion',$version);
 658      $this->smarty->assign('xmlfile',$xmlfile);
 659      $this->smarty->assign('content',$help[1]);
 660      echo $this->ProcessTemplate('remotecontent.tpl');
 661    }
 662  
 663  
 664    /*---------------------------------------------------------
 665     _DisplayAdminSoapModuleAbout()
 666     Display the about info for an a module on the repository
 667     ---------------------------------------------------------*/
 668    function _DisplayAdminSoapModuleAbout($id, &$params, $returnid)
 669    {
 670      if( !isset( $params['name'] ) )
 671        {
 672      $this->_DisplayErrorPage( $id, $params, $returnid,
 673                    $this->Lang('error_insufficientparams'));
 674      return;
 675        }
 676      $name = $params['name'];
 677  
 678      if( !isset( $params['version'] ) )
 679        {
 680      $this->_DisplayErrorPage( $id, $params, $returnid,
 681                    $this->Lang('error_insufficientparams'));
 682      return;
 683        }
 684      $version = $params['version'];
 685  
 686      $url = $this->GetPreference('module_repository');
 687      if( $url == '' )
 688        {
 689      $this->_DisplayErrorPage( $id, $params, $returnid,
 690                    $this->Lang('error_norepositoryurl'));
 691      return;
 692        }
 693  
 694      if( !isset($params['filename'] ) )
 695        {
 696      $this->_DisplayErrorPage( $id, $params, $returnid,
 697                    $this->Lang('error_nofilename'));
 698      return;
 699        }
 700      $xmlfile = $params['filename'];
 701  
 702      $nusoap =& $this->GetModuleInstance('nuSOAP');
 703      $nusoap->Load();
 704      $nu_soapclient =& new nu_soapclient($url,false,false,false,false,false,90,90);
 705      if( $err = $nu_soapclient->GetError() )
 706        {
 707      $this->_DisplayErrorPage( $id, $params, $returnid,
 708                    'SOAP Error: '.$err);
 709      return;
 710        }
 711      $about = $nu_soapclient->call('ModuleRepository.soap_moduleabout',array('name' => $xmlfile ));
 712      if( $err = $nu_soapclient->GetError() )
 713        {
 714      $this->_DisplayErrorPage( $id, $params, $returnid,
 715                    'SOAP Error: '.$err);
 716      echo htmlspecialchars($nu_soapclient->response);
 717      return;
 718        }
 719      if( $about[0] == false )
 720        {
 721      $this->_DisplayErrorPage( $id, $params, $returnid,
 722                    $about[1] );
 723      return;
 724        }
 725      $this->smarty->assign('title',$this->Lang('abouttxt'));
 726      $this->smarty->assign('moduletext',$this->Lang('nametext'));
 727      $this->smarty->assign('vertext',$this->Lang('vertext'));
 728      $this->smarty->assign('xmltext',$this->Lang('xmltext'));
 729      $this->smarty->assign('modulename',$name);
 730      $this->smarty->assign('moduleversion',$version);
 731      $this->smarty->assign('xmlfile',$xmlfile);
 732      $this->smarty->assign('content',$about[1]);
 733      echo $this->ProcessTemplate('remotecontent.tpl');
 734    }
 735  
 736  
 737    /*----------------------------------------------------------
 738     _DoAdminInstallModule( $id, &$params, $returnid )
 739     do a module installation
 740     ---------------------------------------------------------*/
 741    function _DoAdminInstallModule($id, &$params, $returnid)
 742    {
 743      global $gCms;
 744  
 745      if( !isset( $params['name'] ) )
 746        {
 747      $this->_DisplayErrorPage( $id, $params, $returnid,
 748                    $this->Lang('error_insufficientparams'));
 749      return;
 750        }
 751      $name = $params['name'];
 752  
 753      if( !isset( $params['version'] ) )
 754        {
 755      $this->_DisplayErrorPage( $id, $params, $returnid,
 756                    $this->Lang('error_insufficientparams'));
 757      return;
 758        }
 759      $version = $params['version'];
 760  
 761      $url = $this->GetPreference('module_repository');
 762      if( $url == '' )
 763        {
 764      $this->_DisplayErrorPage( $id, $params, $returnid,
 765                    $this->Lang('error_norepositoryurl'));
 766      return;
 767        }
 768  
 769      if( !isset($params['size'] ) )
 770        {
 771      $this->_DisplayErrorPage( $id, $params, $returnid,
 772                    $this->Lang('error_nofilesize'));
 773      return;
 774        }
 775      $size = $params['size'];
 776  
 777      if( !isset($params['filename'] ) )
 778        {
 779      $this->_DisplayErrorPage( $id, $params, $returnid,
 780                    $this->Lang('error_nofilename'));
 781      return;
 782        }
 783      $xmlfile = $params['filename'];
 784  
 785      $nusoap =& $this->GetModuleInstance('nuSOAP');
 786      $nusoap->Load();
 787      $nu_soapclient =& new nu_soapclient($url,false,false,false,false,false,90,90);
 788      if( $err = $nu_soapclient->GetError() )
 789        {
 790      $this->_DisplayErrorPage( $id, $params, $returnid,
 791                    'SOAP Error: '.$err);
 792      return;
 793        }
 794  
 795      // get the xml file from soap
 796      $xml = '';
 797      $result = $this->_GetRepositoryXML($nu_soapclient,$xmlfile,$size,$xml);
 798  //     $xml = $nu_soapclient->call('ModuleRepository.soap_modulexml',array('name' => $xmlfile ));
 799      if( $err = $nu_soapclient->GetError() )
 800        {
 801      echo "<pre>".htmlspecialchars($nu_soapclient->response)."</pre><br/>";
 802      $this->_DisplayErrorPage( $id, $params, $returnid,
 803                    'SOAP Error: '.$err);
 804      return;
 805        }
 806  
 807      // get the md5sum from soap
 808      $svrmd5 = $nu_soapclient->call('ModuleRepository.soap_modulemd5sum',array('name' => $xmlfile));
 809      if( $err = $nu_soapclient->GetError() )
 810        {
 811      
 812      $this->_DisplayErrorPage( $id, $params, $returnid,
 813                    'SOAP Error: '.$err);
 814      return;
 815        }
 816  
 817  
 818      // calculate our own md5sum
 819      // and compare
 820      $clientmd5 = md5( $xml );
 821  
 822      if( $clientmd5 != $svrmd5 )
 823        {
 824      $this->_DisplayErrorPage( $id, $params, $returnid,
 825                    $this->Lang('error_checksum'));
 826      echo "expected: $svrmd5 and got $clientmd5<br/>";
 827      return;
 828        }
 829  
 830      // woohoo, we're ready to rock and roll now
 831      // just gotta expand the module
 832      $modoperations = $gCms->GetModuleOperations();
 833      if( !$modoperations->ExpandXMLPackage( $xml ) )
 834        {
 835      $this->_DisplayErrorPage( $id, $params, $returnid,
 836                    $modoperations->GetLastError());
 837      return;
 838        }
 839  
 840      // and install it
 841      $result = $modoperations->InstallModule( $name, true );
 842      if( $result[0] == true )
 843        {
 844      if( !isset( $gCms->modules[$name]['object'] ) )
 845        {
 846          // hopefully this will never happen
 847          $this->_DisplayErrorPage($id, $params, $returnid,
 848                       $this->Lang('error_moduleinstallfailed'));
 849        }
 850      else
 851        {
 852          $cmsmodules = &$gCms->modules;
 853          $msg = $cmsmodules[$name]['object']->InstallPostMessage();
 854          if( $msg != FALSE )
 855            {
 856          echo $msg;
 857            }
 858          else
 859            {
 860          $this->Redirect( $id, 'defaultadmin', $returnid );
 861            }
 862        }
 863        }
 864      else
 865        {
 866      $this->_DisplayErrorPage($id, $params, $returnid,
 867                   $this->Lang('error_moduleinstallfailed')."&nbsp;:".$result[1]);
 868        }
 869    }
 870  
 871  
 872    /*----------------------------------------------------------
 873     _GetInstalledModules
 874     build a hash of info about the installed modules.
 875     ---------------------------------------------------------*/
 876    function _GetInstalledModules()
 877    {
 878      global $gCms;
 879      $results = array();
 880      foreach( $gCms->modules as $key => $value )
 881        {
 882      $modinstance = $value['object'];
 883      $details = array();
 884      $details['name'] = $modinstance->GetName();
 885      $details['description'] = $modinstance->GetDescription();
 886      $details['version'] = $modinstance->GetVersion();
 887      // todo, here, check to see if there's write permission
 888      // for the httpd user to every one of the files
 889      // in the module's directory.
 890      $results[] = $details;
 891        }
 892      return array(true,$results);
 893    }
 894  
 895  
 896    /*----------------------------------------------------------
 897     _GetRepositoryXML
 898     Get the xml file for a specific module from the repository
 899     
 900     if the expected file size is less than the block size
 901     then the file will be downloaded in it's entirety
 902     otherwise it will be downloaded in chunks
 903     ---------------------------------------------------------*/
 904    function _GetRepositoryXML( &$nu_soapclient, $filename, $size, &$xml )
 905    {
 906      $orig_chunksize = $this->GetPreference('dl_chunksize',256);
 907      $chunksize = $orig_chunksize * 1024;
 908      if( $size <= $chunksize ) 
 909        {
 910      // we're downloading at one shot
 911      $xml = $nu_soapclient->call('ModuleRepository.soap_modulexml',
 912                      array('name' => $filename ));
 913      if( $nu_soapclient->GetError() )
 914        {
 915          return false;
 916        }
 917        }
 918      else
 919        {
 920      global $gCms;
 921      $dir = $gCms->config['root_path'].DIRECTORY_SEPARATOR.'tmp'.DIRECTORY_SEPARATOR;
 922      $tmpname = tempnam($dir,'modmgr_');
 923      if( $tmpname === FALSE )
 924        {
 925          return false;
 926        }
 927  
 928      // we're downloading in chunks
 929      // to a temporary file someplace
 930      // that we will delete afterwards
 931      $fh = fopen($tmpname,'w');
 932      $nchunks = (int)($size / $chunksize) + 1;
 933      for( $i = 0; $i < $nchunks; $i++ )
 934        {
 935           $data = $nu_soapclient->call('ModuleRepository.soap_modulegetpart',
 936                        array('name' => $filename,
 937                              'partnum' => $i,
 938                              'sizekb' => $orig_chunksize));
 939           if( $nu_soapclient->GetError() )
 940             {
 941          echo $nu_soapclient->GetError()."<br/><br/>";
 942          echo htmlspecialchars($nu_soapclient->response);
 943           @fclose($fh);
 944           @unlink($tmpname);
 945           return false;
 946             }
 947          $data = base64_decode( $data );
 948           $nbytes = @fwrite($fh,$data);
 949  //         if( $nbytes != strlen($data) )
 950  //           {
 951  //         // ugh-oh
 952  //           }
 953        }
 954      // we got here so everything theoretically worked
 955      @fflush($fh);
 956      @fclose($fh);
 957      $xml = @file_get_contents($tmpname);
 958        }
 959      return true;
 960    }
 961  
 962  
 963    /*----------------------------------------------------------
 964     _GetRepositoryModules
 965     Get the xml modules from the repository, in an array of
 966     hashes, each hash has name and version keys
 967     
 968     This routine filters out modules that are incompatible,
 969     i.e: the minimum cms version is larger than the current cms
 970     version, or the maximum cms version is smaller than the
 971     current cms version
 972     ---------------------------------------------------------*/
 973    function _GetRepositoryModules()
 974    {
 975      global $_SESSION;
 976      global $CMS_VERSION;
 977  
 978      $url = $this->GetPreference('module_repository');
 979      if( $url == '' )
 980        {
 981      return array(false,$this->Lang('error_norepositoryurl'));
 982        }
 983  
 984      $nusoap =& $this->GetModuleInstance('nuSOAP');
 985      $nusoap->Load();
 986      $nu_soapclient =& new nu_soapclient($url,false,false,false,false,false,90,90);
 987      if( $err = $nu_soapclient->GetError() )
 988        {
 989      return array(false,$this->Lang('error_nosoapconnect'));
 990        }
 991  
 992      $allmoduledetails = array();
 993      if( !isset($_SESSION['modulemanager_cache']) )
 994        {
 995      $repversion = $nu_soapclient->call('ModuleRepository.soap_version');
 996      if( $err = $nu_soapclient->GetError() )
 997        {
 998          return array(false,$this->Lang('error_soaperror').' ('.$url.'): '.$err);
 999        }
1000      if( version_compare( $repversion, MINIMUM_REPOSITORY_VERSION ) < 0 )
1001        {
1002          return array(false,$this->Lang('error_minimumrepository'));
1003        }
1004      
1005      $modules = $nu_soapclient->call('ModuleRepository.soap_listmodules');
1006      if( $err = $nu_soapclient->GetError() )
1007        {
1008          return array(false,$this->Lang('error_soaperror').' ('.$url.'): '.$err);
1009        }
1010  
1011  
1012      $allmoduledetails = $nu_soapclient->call('ModuleRepository.soap_moduledetailsgetall');
1013      if( $err = $nu_soapclient->GetError() )
1014        {
1015          return array(false,$this->Lang('error_soaperror').' ('.$url.'): '.$err);
1016        }
1017      if( !is_array( $allmoduledetails ) || count( $allmoduledetails ) == 0 )
1018        {
1019          return array(false,$this->Lang('error_connectnomodules').' ('.$url.'): '.$err);
1020        }
1021      $_SESSION['modulemanager_cache'] = $allmoduledetails;
1022        }
1023      else
1024        {
1025      $allmoduledetails = $_SESSION['modulemanager_cache'];
1026        }
1027      return array(true,$allmoduledetails);
1028    }
1029  }
1030  
1031  ?>


Généré le : Tue Apr 3 18:50:37 2007 par Balluche grâce à PHPXref 0.7