Changes between Initial Version and Version 1 of phpgwapi/how_does_API_work


Ignore:
Timestamp:
03/29/10 15:16:02 (14 years ago)
Author:
rodsouza
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • phpgwapi/how_does_API_work

    v1 v1  
     1Tendo como base uma requisição inicial para o script '''/index.php''' 
     2 
     3A primeira verificação é a existência do script '''/header.inc.php''', caso não exista então há um redirecionamento para '''/setup/index.php'''. 
     4 
     5{{{ 
     6#!php 
     7    if ( ! file_exists('header.inc.php' ) ) 
     8    { 
     9        Header( 'Location: setup/index.php' ); 
     10        exit; 
     11    } 
     12}}} 
     13 
     14Caso exista o script '''/header.inc.php''' o próximo passo é obter o '''id''' da sesssão. Caso não exista então há um redirecionamento para '''/login.php'''. 
     15 
     16{{{ 
     17#!php 
     18    if ( ! $GLOBALS[ 'sessionid' ] ) 
     19    {    
     20        Header( 'Location: login.php'. 
     21            ( isset( $_SERVER[ 'QUERY_STRING' ] ) && ! empty( $_SERVER[ 'QUERY_STRING' ] ) ? 
     22                '?phpgw_forward=' . urlencode( '/index.php?' . $_SERVER[ 'QUERY_STRING' ] ) : '' ) ); 
     23        exit; 
     24    } 
     25}}} 
     26 
     27A seguir é realizada a verificação se a existe a opção '''menuaction'''. Caso a opção exista ela deve estar no formato '''APP.CLASS.METHOD'''. 
     28 
     29{{{ 
     30#!php 
     31    if ( isset( $_GET[ 'menuaction'] ) ) 
     32    { 
     33        list( $app, $class, $method ) = explode( '.', @$_GET[ 'menuaction' ] ); 
     34        if ( ! $app || ! $class || ! $method ) 
     35        { 
     36            $invalid_data = true; 
     37        } 
     38    } 
     39}}} 
     40 
     41Se a opção não existir então assume-se que a requisição deve ser redirecionada para o script '''home.php'''. O mesmo ocorre se a opção existir porém a parte '''APP''' referencie-se a '''phpgwapi'''. 
     42 
     43{{{ 
     44#!php 
     45    else 
     46    { 
     47        $app = 'home'; 
     48        $invalid_data = true; 
     49    } 
     50 
     51    if ( $app == 'phpgwapi' ) 
     52    { 
     53        $app = 'home'; 
     54        $api_requested = true; 
     55    } 
     56}}} 
     57 
     58Após é configurada algumas variáveis globais e é incluido o script '''/header.inc.php'''. 
     59 
     60{{{ 
     61#!php 
     62    $GLOBALS[ 'phpgw_info' ][ 'flags' ] = array( 
     63        'noheader'   => true, 
     64        'nonavbar'   => true, 
     65        'currentapp' => $app 
     66    ); 
     67 
     68    include('./header.inc.php'); 
     69}}} 
     70 
     71O script '''/header.inc.php''' começa definindo o path do ExpressoLivre, o nome do usuário com permissão para realizar alterações na configuração básica e a senha do mesmo no formato md5. 
     72 
     73{{{ 
     74#!php 
     75    define( 'PHPGW_SERVER_ROOT', '/var/www/expresso' ); 
     76    define( 'PHPGW_INCLUDE_ROOT', '/var/www/expresso' ); 
     77    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'header_admin_user' ] = 'expresso-admin'; 
     78    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'header_admin_password' ] = 'e8d95a51f3af4a3b134bf6bb680a213a'; 
     79    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'setup_acl' ] = ''; 
     80}}} 
     81 
     82Após algumas outras variáveis são populadas. 
     83 
     84{{{ 
     85#!php 
     86    // Opcoes exclusivas a partir da versão 2.0 :: Configurar via setup/header 
     87    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'captcha' ] = 0; 
     88    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'num_badlogin' ] = 0; 
     89    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'atributoexpiracao' ] = ''; 
     90    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'atributousuarios' ] = ''; 
     91    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'certificado' ] = 0; 
     92    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'use_assinar_criptografar' ] = 0; 
     93    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'num_max_certs_to_cipher' ] = 0; 
     94 
     95    // Opcoes exlusivas para o Expresso Livre 
     96    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'use_https' ] = 0; 
     97    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'sugestoes_email_to' ] = ''; 
     98    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'domain_name' ] = ''; 
     99    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'use_prefix_organization' ] = false; 
     100}}} 
     101 
     102Posteriormente existe as informações referentes à base de dados. 
     103 
     104{{{ 
     105#!php 
     106    $GLOBALS['phpgw_domain']['default'] = array( 
     107        'db_host' => 'localhost', 
     108        'db_port' => '5432', 
     109        'db_name' => 'expresso', 
     110        'db_user' => 'postgres', 
     111        'db_pass' => '', 
     112        'db_type' => 'pgsql', 
     113    ); 
     114}}} 
     115 
     116Em seguida é definido o diretório das classes da API e incluido o script '''/phpgwapi/setup/setup.inc.php'''. 
     117 
     118{{{ 
     119#!php 
     120    define( 'PHPGW_API_INC', PHPGW_INCLUDE_ROOT . '/phpgwapi/inc' ); 
     121    include( PHPGW_SERVER_ROOT . '/phpgwapi/setup/setup.inc.php' ); 
     122}}} 
     123 
     124O script '''/phpgwapi/setup/setup.inc.php''' define dados sobre a API, além das tabelas utiliadas. 
     125 
     126 
     127{{{ 
     128#!php 
     129    /* Basic information about this app */ 
     130    $setup_info[ 'phpgwapi' ][ 'name' ] = 'phpgwapi'; 
     131    $setup_info[ 'phpgwapi' ][ 'title' ] = 'phpgwapi'; 
     132    $setup_info[ 'phpgwapi' ][ 'version' ] = '2.2.000'; 
     133    $setup_info[ 'phpgwapi' ][ 'versions' ][ 'current_header' ] = '2.0'; 
     134    $setup_info[ 'phpgwapi' ][ 'enable' ] = 3; 
     135    $setup_info[ 'phpgwapi' ][ 'app_order' ] = 1; 
     136 
     137    /* The tables this app creates */ 
     138    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_config'; 
     139    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_applications'; 
     140    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_acl'; 
     141    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_accounts'; 
     142    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_preferences'; 
     143    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_sessions'; 
     144    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_app_sessions'; 
     145    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_access_log'; 
     146    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_hooks'; 
     147    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_languages'; 
     148    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_lang'; 
     149    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_nextid'; 
     150    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_categories'; 
     151    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_log'; 
     152    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_log_msg'; 
     153    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_vfs'; 
     154    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_history_log'; 
     155    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_async'; 
     156}}}