Changeset 860 for trunk


Ignore:
Timestamp:
Jan 21, 2016, 2:49:19 PM (9 years ago)
Author:
chronos
Message:
  • Modified: Now application modules are started according configuration file.
  • Added: Each module which want to show something in main page bars needs to register its callback.
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Modules/Error/Error.php

    r838 r860  
    2323  function DoStart()
    2424  {
     25    if(isset($this->System->Config['Web']['ShowPHPError']))
     26      $this->ErrorHandler->ShowError = $this->System->Config['Web']['ShowPHPError'];
     27      else $this->ErrorHandler->ShowError = true;
    2528    $this->ErrorHandler->Start();
    2629  }
  • trunk/Modules/Referrer/Referrer.php

    r838 r860  
    2020  function DoStart()
    2121  {
     22    $this->Excludes[] = $this->System->Config['Web']['Host'];
    2223    $this->Log();
    2324    $this->System->RegisterPage('referrer', 'PageReferrer');
  • trunk/Modules/Translation/Translation.php

    r859 r860  
    2424  function DoStart()
    2525  {
    26     $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
    27 
    2826    $this->System->RegisterPage('comparison.php', 'PageTranslationComparison');
    2927    $this->System->RegisterPage('form.php', 'PageTranslationForm');
     
    5149    if(array_key_exists('Search', $this->System->ModuleManager->Modules))
    5250    {
     51      $TranslationTree = $this->System->ModuleManager->Modules['Translation']->GetTranslationTree();
    5352      foreach($TranslationTree as $Group)
    5453      {
  • trunk/Modules/User/Profile.php

    r852 r860  
    163163        T('Number of translated:').' <a href="'.$this->System->Link('/TranslationList.php?user='.$UserLine['ID'].'&amp;state=2&amp;group=0').'" title="Zobrazit Všechny jeho přeložené texty"><strong>'.$UserLine['TranslatedCount'].'</strong></a><br />'.
    164164        T('Level:').' <strong>'.$XP['Level'].'</strong> '.T('experience:').' '.ProgressBar(150, round($XP['XP'] / $XP['MaxXP'] * 100, 2), $XP['XP'].' / '.$XP['MaxXP']).'<br/>';
    165       if($UserLine['TeamName'] != '')
     165      if($this->System->ModuleManager->ModuleRunning('Team') and ($UserLine['TeamName'] != ''))
    166166        $Output .= T('Member of team:').' <a href="'.$this->System->Link('/team/?action=team&amp;id='.$UserLine['Team']).'"><strong>'.htmlspecialchars($UserLine['TeamName']).'</strong></a><br />';
    167167
  • trunk/Modules/User/User.php

    r843 r860  
    3737      $this->System->ModuleManager->Modules['Search']->RegisterSearch('user',
    3838      T('Translators'), array('Name'), '`User`', $this->System->Link('/users/?search='));
     39    $this->System->RegisterPageBarItem('Top', 'User', array($this, 'TopBarCallback'));
    3940  }
    4041
     
    5152      $Name = '<a href="'.$this->System->Link('/user/?user='.$DbUser['ID']).'">'.$DbUser['Name'].'</a>';
    5253      $Output .= $Name.'<br />';
     54    }
     55    return($Output);
     56  }
     57
     58  function TopBarCallback()
     59  {
     60    $Output = '';
     61    if($this->System->User->Licence(LICENCE_USER))
     62    {
     63      //$DbResult =$this->Database->query('SELECT `Id`, `Name` FROM `Team` WHERE `Id`='.$this->System->User->Team);
     64      //$Team = $DbResult->fetch_assoc();
     65      //$Output .= ''<span class="MenuItem">Moje překlady: <a href="">Dokončené</a> <a href="">Rozpracované</a> <a href="">Exporty</a> Tým: <a href="">'.$Team['name'].'</a></span>';
     66      $Output .= $this->System->User->Name.' <a href="'.$this->System->Link('/?action=logout').'">'.T('Logout').'</a>'.
     67          ' <a href="'.$this->System->Link('/user/?user='.$this->System->User->Id).'">'.T('My page').'</a>'.
     68          ' <a href="'.$this->System->Link('/options/').'">'.T('Options').'</a>'.
     69          ' <a title="Vámi přeložené texty" href="'.$this->System->Link('/TranslationList.php?user='.
     70          $this->System->User->Id.'&amp;group=0&amp;state=2&amp;text=&amp;entry=').'">'.T('Translated').'</a>'.
     71          ' <a title="Vaše rozpracované text" href="'.$this->System->Link('/TranslationList.php?user='.
     72          $this->System->User->Id.'&amp;group=0&amp;state=3&amp;text=&amp;entry=').'">'.T('Unfinished').'</a>'.
     73          ' <a title="Nikým nepřeložené texty" href="'.
     74          $this->System->Link('/TranslationList.php?user=0&amp;group=0&amp;state=1&amp;text=&amp;entry=').'">'.T('Untranslated').'</a>';
     75    } else
     76    {
     77      $Output .= '<a href="'.$this->System->Link('/login/').'">'.T('Login').'</a>&nbsp;'.
     78        '<a href="'.$this->System->Link('/registration/').'">'.T('Registration').'</a>';
    5379    }
    5480    return($Output);
  • trunk/Packages/Common/AppModule.php

    r858 r860  
    197197    $this->Modules = array();
    198198    $this->System = &$System;
    199     $this->FileName = 'Config/Modules.php';
     199    $this->FileName = dirname(__FILE__).'/../../Config/ModulesConfig.php';
    200200    $this->ModulesDir = dirname(__FILE__).'/../../Modules';
    201201  }
     
    318318  }
    319319
     320  function ModuleEnabled($Name)
     321  {
     322    return(array_key_exists($Name, $this->Modules) and $this->Modules[$Name]->Enabled);
     323  }
     324
     325  function ModuleRunning($Name)
     326  {
     327    return(array_key_exists($Name, $this->Modules) and $this->Modules[$Name]->Running);
     328  }
     329
    320330  /* @return Module */
    321331  function SearchModuleById($Id)
  • trunk/Packages/Common/Setup.php

    r858 r860  
    362362  {
    363363    $Output = '';
    364     if(!$this->Database->Connected()) $Output .= 'Nelze se připojit k databázi.<br>';
     364    if(!$this->Database->Connected()) $Output .= T('Can\'t connect to database').'<br>';
    365365    else {
    366366      if(!$this->System->Setup->UpdateManager->IsInstalled())
    367         $Output .= 'Systém vyžaduje instalaci databáze.<br>';
     367        $Output .= T('System requires database initialization').'<br>';
    368368      else
    369369      if(!$this->System->Setup->UpdateManager->IsUpToDate())
    370         $Output .= 'Systém vyžaduje aktualizaci databáze.<br>';
    371     }
    372     $Output .= 'Pokračujte <a href="'.$this->System->Link('/setup/').'">zde</a>';
     370        $Output .= T('System requires database upgrade').'<br>';
     371    }
     372    $Output .= sprintf(T('Front page was not configured. Continue to %s'), '<a href="'.$this->System->Link('/setup/').'">'.T('setup').'</a>');
    373373    return($Output);
    374374  }
  • trunk/includes/Global.php

    r859 r860  
    99include_once(dirname(__FILE__).'/../Application/Version.php');
    1010require_once(dirname(__FILE__).'/../HTML/BBCodeParser2.php');
    11 
    12 // Include application modules
    13 // TODO: Make modules configurable
    14 include_once(dirname(__FILE__).'/../Modules/Error/Error.php');
    15 include_once(dirname(__FILE__).'/../Modules/Log/Log.php');
    16 include_once(dirname(__FILE__).'/../Modules/Translation/Translation.php');
    17 include_once(dirname(__FILE__).'/../Modules/AoWoW/AoWoW.php');
    18 include_once(dirname(__FILE__).'/../Modules/Referrer/Referrer.php');
    19 include_once(dirname(__FILE__).'/../Modules/Team/Team.php');
    20 include_once(dirname(__FILE__).'/../Modules/User/User.php');
    21 include_once(dirname(__FILE__).'/../Modules/Dictionary/Dictionary.php');
    22 include_once(dirname(__FILE__).'/../Modules/Import/Import.php');
    23 include_once(dirname(__FILE__).'/../Modules/Export/Export.php');
    24 include_once(dirname(__FILE__).'/../Modules/Server/Server.php');
    25 include_once(dirname(__FILE__).'/../Modules/ClientVersion/ClientVersion.php');
    26 include_once(dirname(__FILE__).'/../Modules/ShoutBox/ShoutBox.php');
    27 include_once(dirname(__FILE__).'/../Modules/News/News.php');
    28 include_once(dirname(__FILE__).'/../Modules/Wiki/Wiki.php');
    29 include_once(dirname(__FILE__).'/../Modules/Search/Search.php');
    30 include_once(dirname(__FILE__).'/../Modules/FrontPage/FrontPage.php');
    31 include_once(dirname(__FILE__).'/../Modules/Download/Download.php');
    32 include_once(dirname(__FILE__).'/../Modules/Forum/Forum.php');
    33 include_once(dirname(__FILE__).'/../Modules/Redirection/Redirection.php');
    34 include_once(dirname(__FILE__).'/../Modules/Admin/Admin.php');
    35 include_once(dirname(__FILE__).'/../Modules/Info/Info.php');
    36 
    3711
    3812// Back compatibility, will be removed
  • trunk/includes/System.php

    r859 r860  
    1111  /* @var LocaleManager */
    1212  var $LocaleManager;
     13  var $Bars;
    1314
    1415  function __construct()
     
    2122    $this->OnPageNotFound = array();
    2223    $this->Pages = array();
     24    $this->Bars = array();
    2325  }
    2426
     
    2830
    2931    $this->Config = $Config;
    30     date_default_timezone_set($this->Config['Web']['Timezone']);
     32    if(isset($this->Config['Web']['Timezone']))
     33      date_default_timezone_set($this->Config['Web']['Timezone']);
    3134    mb_internal_encoding("UTF-8");
    3235
     
    7881       'Icon' => '',
    7982      ),
    80     */
     83
    8184      array(
    8285        'Title' => T('IRC chat'),
     
    8689        'Icon' => '',
    8790      ),
     91      */
    8892    );
    8993  }
     
    106110    foreach($_GET as $Index => $Item) $_GET[$Index] = addslashes($_GET[$Index]);
    107111
     112    $this->RegisterPageBar('Top');
     113    $this->RegisterPageBar('Left');
     114    $this->RegisterPageBar('Right');
    108115    $this->Init();
    109116
     
    116123      $this->ModuleManager->Start();
    117124    }
    118 
    119     // Initialize application modules
    120     $this->ModuleManager->RegisterModule(new ModuleError($this));
    121     $this->ModuleManager->Modules['Error']->ErrorHandler->ShowError = $this->Config['Web']['ShowPHPError'];
    122     $this->ModuleManager->RegisterModule(new ModuleLog($this));
    123     $this->ModuleManager->RegisterModule(new ModuleUser($this));
    124     $this->ModuleManager->RegisterModule(new ModuleAoWoW($this));
    125     $this->ModuleManager->RegisterModule(new ModuleReferrer($this));
    126     $this->ModuleManager->Modules['Referrer']->Excludes[] = $this->Config['Web']['Host'];
    127     $this->ModuleManager->RegisterModule(new ModuleTeam($this));
    128     $this->ModuleManager->RegisterModule(new ModuleDictionary($this));
    129     $this->ModuleManager->RegisterModule(new ModuleTranslation($this));
    130     $this->ModuleManager->RegisterModule(new ModuleImport($this));
    131     $this->ModuleManager->RegisterModule(new ModuleExport($this));
    132     $this->ModuleManager->RegisterModule(new ModuleServer($this));
    133     $this->ModuleManager->RegisterModule(new ModuleClientVersion($this));
    134     $this->ModuleManager->RegisterModule(new ModuleShoutBox($this));
    135     $this->ModuleManager->RegisterModule(new ModuleNews($this));
    136     $this->ModuleManager->RegisterModule(new ModuleWiki($this));
    137     $this->ModuleManager->RegisterModule(new ModuleSearch($this));
    138     $this->ModuleManager->RegisterModule(new ModuleFrontPage($this));
    139     $this->ModuleManager->RegisterModule(new ModuleDownload($this));
    140     $this->ModuleManager->RegisterModule(new ModuleForum($this));
    141     $this->ModuleManager->RegisterModule(new ModuleRedirection($this));
    142     $this->ModuleManager->RegisterModule(new ModuleAdmin($this));
    143     $this->ModuleManager->RegisterModule(new ModuleInfo($this));
    144     $this->ModuleManager->FileName = dirname(__FILE__).'/../Config/ModulesConfig.php';
    145     // TODO: Allow control from web which modules should be installed
    146     $this->ModuleManager->InstallAll();
    147     $this->ModuleManager->StartAll();
    148125
    149126    $this->BaseView = new BaseView($this);
     
    327304    echo($Output);
    328305  }
     306
     307  function RegisterPageBar($Name)
     308  {
     309    $this->Bars[$Name] = array();
     310  }
     311
     312  function UnregisterPageBar($Name)
     313  {
     314    unset($this->Bars[$Name]);
     315  }
     316
     317  function RegisterPageBarItem($BarName, $ItemName, $Callback)
     318  {
     319    $this->Bars[$BarName][$ItemName] = $Callback;
     320  }
    329321}
    330322
     
    357349  {
    358350    $Output = '<div class="Menu">';
    359     if(!$this->System->User->Licence(LICENCE_USER))
    360       $Output .= '<div class="advert">'.$this->System->Config['Web']['Advertisement'].'</div>';
     351    if(isset($this->System->User))
     352    {
     353      if(!$this->System->User->Licence(LICENCE_USER))
     354        $Output .= '<div class="advert">'.$this->System->Config['Web']['Advertisement'].'</div>';
     355    }
    361356    $Output .= '<span class="MenuItem"></span><span class="MenuItem2">';
    362     if($this->System->User->Licence(LICENCE_USER))
    363     {
    364       //$DbResult =$this->Database->query('SELECT `Id`, `Name` FROM `Team` WHERE `Id`='.$this->System->User->Team);
    365       //$Team = $DbResult->fetch_assoc();
    366       //$Output .= ''<span class="MenuItem">Moje překlady: <a href="">Dokončené</a> <a href="">Rozpracované</a> <a href="">Exporty</a> Tým: <a href="">'.$Team['name'].'</a></span>';
    367       $Output .= $this->System->User->Name.' <a href="'.$this->System->Link('/?action=logout').'">'.T('Logout').'</a>'.
    368           ' <a href="'.$this->System->Link('/user/?user='.$this->System->User->Id).'">'.T('My page').'</a>'.
    369           ' <a href="'.$this->System->Link('/options/').'">'.T('Options').'</a>'.
    370           ' <a title="Vámi přeložené texty" href="'.$this->System->Link('/TranslationList.php?user='.
    371           $this->System->User->Id.'&amp;group=0&amp;state=2&amp;text=&amp;entry=').'">'.T('Translated').'</a>'.
    372           ' <a title="Vaše rozpracované text" href="'.$this->System->Link('/TranslationList.php?user='.
    373           $this->System->User->Id.'&amp;group=0&amp;state=3&amp;text=&amp;entry=').'">'.T('Unfinished').'</a>'.
    374           ' <a title="Nikým nepřeložené texty" href="'.
    375           $this->System->Link('/TranslationList.php?user=0&amp;group=0&amp;state=1&amp;text=&amp;entry=').'">'.T('Untranslated').'</a>';
    376     } else
    377     {
    378       $Output .= '<a href="'.$this->System->Link('/login/').'">'.T('Login').'</a>&nbsp;'.
    379         '<a href="'.$this->System->Link('/registration/').'">'.T('Registration').'</a>';
    380     }
     357
     358    // Show bars items
     359    $Bar = '';
     360    foreach($this->System->Bars['Top'] as $BarItem)
     361      $Bar .= call_user_func($BarItem);
     362      if(trim($Bar) != '') $Output .= $Bar;
     363      else $Output .= '&nbsp;';
     364
    381365    $Output .= $this->ShowLocaleSelector();
    382366    //$Output .= '</form>';
     
    432416      '<div class="verticalmenu"><ul>';
    433417    foreach($this->System->Menu as $MenuItem)
    434       if($this->System->User->Licence($MenuItem['Permission']))
     418      if(!isset($this->System->User) or $this->System->User->Licence($MenuItem['Permission']))
    435419      {
    436420        if(isset($MenuItem['Click'])) $OnClick = ' onclick="'.$MenuItem['Click'].'"';
     
    466450        '&nbsp;<a title="Přeložené texty, můžete zde hlasovat, nebo opravovat překlady" href="'.
    467451        $this->System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;state=2&amp;user=0&amp;entry=&amp;text=').'">'.T('Translated').'</a><br />';
    468       if($this->System->User->Licence(LICENCE_USER))
     452      if(isset($this->System->User) and $this->System->User->Licence(LICENCE_USER))
    469453      {
    470454        $Output .= '&nbsp;<a title="'.T('Unfinished translations').'" href="'.$this->System->Link('/TranslationList.php?group='.$Group['Id'].'&amp;state=3').'">'.T('Unfinished').'</a><br />'.
Note: See TracChangeset for help on using the changeset viewer.