Changeset 668


Ignore:
Timestamp:
Jul 15, 2014, 9:48:54 PM (10 years ago)
Author:
chronos
Message:
  • Přidáno: Přístup k RSS kanálům přes přístupový token.
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/Application/Version.php

    r664 r668  
    11<?php
    22
    3 $Revision = 664; // Subversion revision
    4 $DatabaseRevision = 662; // SQL structure revision
    5 $ReleaseTime = strtotime('2014-06-13');
     3$Revision = 668; // Subversion revision
     4$DatabaseRevision = 668; // SQL structure revision
     5$ReleaseTime = strtotime('2014-07-15');
  • trunk/Common/Global.php

    r659 r668  
    1818include_once(dirname(__FILE__).'/Setup/Setup.php');
    1919include_once(dirname(__FILE__).'/PrefixMultiplier.php');
     20include_once(dirname(__FILE__).'/VCL/General.php');
     21include_once(dirname(__FILE__).'/VCL/Database.php');
    2022
    2123//define('NEW_PERMISSION', '1');
  • trunk/Common/Setup/Updates.php

    r662 r668  
    781781  $IconId = $Manager->Database->insert_id;
    782782  $Manager->Execute('UPDATE `Action` SET `Icon` = '.$IconId.' WHERE `Title`="Kontakty"');
    783 
     783}
     784
     785function UpdateTo668($Manager)
     786{
     787  $Manager->Execute('CREATE TABLE IF NOT EXISTS `APIToken` (
     788  `Id` int(11) NOT NULL AUTO_INCREMENT,
     789  `User` int(11) NOT NULL,
     790  `Token` varchar(255) NOT NULL,
     791  PRIMARY KEY (`Id`),
     792  KEY `User` (`User`)
     793) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;');
     794
     795  $Manager->Execute('ALTER TABLE `APIToken`
     796  ADD CONSTRAINT `APIToken_ibfk_1` FOREIGN KEY (`User`) REFERENCES `User` (`Id`);');
     797  $Manager->Execute('INSERT INTO `Module` (`Id` ,`Name` ,`Title`)
     798VALUES (NULL , "RSS", "RSS kanály");');
    784799}
    785800
     
    826841      657 => array('Revision' => 661, 'Function' => 'UpdateTo661'),
    827842      661 => array('Revision' => 662, 'Function' => 'UpdateTo662'),
     843      662 => array('Revision' => 668, 'Function' => 'UpdateTo668'),
    828844    ));
    829845  }
  • trunk/Modules/Log/Log.php

    r661 r668  
    1111    $this->License = 'GNU/GPLv3';
    1212    $this->Description = 'Logging user actions';
    13     $this->Dependencies = array('User');
     13    $this->Dependencies = array('User', 'RSS');
    1414  }
    1515
     
    3838      ),
    3939    ));
    40 
     40    $this->System->ModuleManager->Modules['RSS']->RegisterRSS(array('Title' => 'Logs',
     41      'Channel' => 'log', 'Callback' => array('ModuleLog', 'ShowRSS'),
     42      'Permission' => array('Module' => 'Log', 'Operation' => 'RSS')));
    4143  }
    4244
     
    5759      'Operation' => $Operation, 'Value' => $Value, 'IPAddress' => $IPAddress));
    5860  }
     61
     62  function ShowRSS()
     63  {
     64    $this->ClearPage = true;
     65    $this->FormatHTML = false;
     66    Header('Content-Type: text/xml');
     67    $Count = 20;
     68
     69    $Output = '';
     70    $Items = array();
     71    if(array_key_exists('type', $_GET)) $Where = ' WHERE `Type` = "'.($_GET['type'] * 1).'"';
     72      else $Where = '';
     73    $sql = 'SELECT *, UNIX_TIMESTAMP(`Time`) AS `TimeCreate`, (SELECT `User`.`Name` FROM `User` WHERE `User`.`Id` = `Log`.`User`) AS `UserName`, `Time` FROM `Log`'.
     74      $Where.' ORDER BY `Time` DESC LIMIT '.$Count;
     75    $DbResult = $this->System->Database->query($sql);
     76    while($Line = $DbResult->fetch_assoc())
     77    {
     78      $Line['Value'] = htmlspecialchars($Line['Value']);
     79      $Line['Value'] = str_replace("\n", '<br>', $Line['Value']);
     80
     81      $Items[] = array
     82      (
     83        'Title' => $Line['Module'].' '.$Line['Operation'].' ('.$Line['UserName'].', '.$Line['IPAddress'].')',
     84        'Link' => 'http://'.$this->System->Config['Web']['Host'].$this->System->Link('/log.php'),
     85        'Description' => $Line['Module'].' '.$Line['Operation'].': '.$Line['Value'].' ('.$Line['UserName'].
     86          ', '.$Line['IPAddress'].', '.HumanDate($Line['Time']).')',
     87        'Time' => $Line['TimeCreate'],
     88      );
     89    }
     90
     91    $RSS = new RSS();
     92    $RSS->Title = $this->System->Config['Web']['Title'].' - Záznamy';
     93    $RSS->Link = 'http://'.$this->System->Config['Web']['Host'].'/';
     94    $RSS->Description = 'Aktuality '.$this->System->Config['Web']['Description'];
     95    $RSS->WebmasterEmail = $this->System->Config['Web']['AdminEmail'];
     96    $RSS->Items = $Items;
     97    return($RSS->Generate());
     98  }
    5999}
  • trunk/Modules/User/User.php

    r662 r668  
    285285    {
    286286      // If no permission combination exists in cache, do new check of database items
    287       $DbResult = $this->Database->select('PermissionGroupAssignment', '*', '`Group`="'.$GroupId.'" AND `AssignedGroup` IS NOT NULL');
     287      $DbResult = $this->Database->select('PermissionGroupAssignment', '*', '(`Group`="'.$GroupId.
     288        '") AND (`AssignedGroup` IS NOT NULL)');
    288289      $DbRow = array();
    289290      while($DbRow[] = $DbResult->fetch_array());
    290       $this->PermissionGroupCache[$GroupId] = $DbRow;
     291        $this->PermissionGroupCache[$GroupId] = $DbRow;
    291292      $PermissionExists = true;
    292293    }
     
    337338    {
    338339      // If no permission combination exists in cache, do new check of database items
    339       $DbResult = $this->Database->select('PermissionOperation', 'Id', '`Module`="'.$ModuleId.'" AND `Item`="'.$ItemType.'" AND `ItemId`='.$ItemIndex.' AND `Operation`="'.$Operation.'"');
     340      $DbResult = $this->Database->select('PermissionOperation', 'Id', '(`Module`="'.$ModuleId.
     341        '") AND (`Item`="'.$ItemType.'") AND (`ItemId`='.$ItemIndex.') AND (`Operation`="'.$Operation.'")');
    340342      if($DbResult->num_rows > 0)
    341343      {
     
    414416    } else $Output = USER_NOT_FOUND;
    415417    return($Output);
     418  }
     419
     420  function CheckToken($Module, $Operation, $Token)
     421  {
     422    $DbResult = $this->Database->select('APIToken', 'User', '`Token`="'.$Token.'"');
     423    if($DbResult->num_rows > 0)
     424    {
     425      $DbRow = $DbResult->fetch_assoc();
     426      $User = new User($this->System);
     427      $User->User = array('Id' => $DbRow['User']);
     428      return($User->CheckPermission($Module, $Operation));
     429    } else return(false);
    416430  }
    417431}
     
    583597      ),
    584598    ));
     599    $this->System->FormManager->RegisterClass('APIToken', array(
     600      'Title' => 'Přístupový token',
     601      'Table' => 'APIToken',
     602      'Items' => array(
     603        'User' => array('Type' => 'TUser', 'Caption' => 'Uživatel', 'Default' => ''),
     604        'Token' => array('Type' => 'String', 'Caption' => 'Token', 'Default' => ''),
     605      ),
     606    ));
    585607    $this->System->FormManager->RegisterClass('User', array(
    586608      'Title' => 'Uživatelé',
Note: See TracChangeset for help on using the changeset viewer.