wiki:phpgwapi/how_does_API_work

Version 1 (modified by rodsouza, 14 years ago) (diff)

--

Tendo como base uma requisição inicial para o script /index.php

A primeira verificação é a existência do script /header.inc.php, caso não exista então há um redirecionamento para /setup/index.php.

    if ( ! file_exists('header.inc.php' ) )
    {
        Header( 'Location: setup/index.php' );
        exit;
    }

Caso 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.

    if ( ! $GLOBALS[ 'sessionid' ] )
    {   
        Header( 'Location: login.php'.
            ( isset( $_SERVER[ 'QUERY_STRING' ] ) && ! empty( $_SERVER[ 'QUERY_STRING' ] ) ?
                '?phpgw_forward=' . urlencode( '/index.php?' . $_SERVER[ 'QUERY_STRING' ] ) : '' ) );
        exit;
    }

A 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.

    if ( isset( $_GET[ 'menuaction'] ) )
    {
        list( $app, $class, $method ) = explode( '.', @$_GET[ 'menuaction' ] );
        if ( ! $app || ! $class || ! $method )
        {
            $invalid_data = true;
        }
    }

Se 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.

    else
    {
        $app = 'home';
        $invalid_data = true;
    }

    if ( $app == 'phpgwapi' )
    {
        $app = 'home';
        $api_requested = true;
    }

Após é configurada algumas variáveis globais e é incluido o script /header.inc.php.

    $GLOBALS[ 'phpgw_info' ][ 'flags' ] = array(
        'noheader'   => true,
        'nonavbar'   => true,
        'currentapp' => $app
    );

    include('./header.inc.php');

O 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.

    define( 'PHPGW_SERVER_ROOT', '/var/www/expresso' );
    define( 'PHPGW_INCLUDE_ROOT', '/var/www/expresso' );
    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'header_admin_user' ] = 'expresso-admin';
    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'header_admin_password' ] = 'e8d95a51f3af4a3b134bf6bb680a213a';
    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'setup_acl' ] = '';

Após algumas outras variáveis são populadas.

    // Opcoes exclusivas a partir da versão 2.0 :: Configurar via setup/header
    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'captcha' ] = 0;
    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'num_badlogin' ] = 0;
    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'atributoexpiracao' ] = '';
    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'atributousuarios' ] = '';
    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'certificado' ] = 0;
    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'use_assinar_criptografar' ] = 0;
    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'num_max_certs_to_cipher' ] = 0;

    // Opcoes exlusivas para o Expresso Livre
    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'use_https' ] = 0;
    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'sugestoes_email_to' ] = '';
    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'domain_name' ] = '';
    $GLOBALS[ 'phpgw_info' ][ 'server' ][ 'use_prefix_organization' ] = false;

Posteriormente existe as informações referentes à base de dados.

    $GLOBALS['phpgw_domain']['default'] = array(
        'db_host' => 'localhost',
        'db_port' => '5432',
        'db_name' => 'expresso',
        'db_user' => 'postgres',
        'db_pass' => '',
        'db_type' => 'pgsql',
    );

Em seguida é definido o diretório das classes da API e incluido o script /phpgwapi/setup/setup.inc.php.

    define( 'PHPGW_API_INC', PHPGW_INCLUDE_ROOT . '/phpgwapi/inc' );
    include( PHPGW_SERVER_ROOT . '/phpgwapi/setup/setup.inc.php' );

O script /phpgwapi/setup/setup.inc.php define dados sobre a API, além das tabelas utiliadas.

    /* Basic information about this app */
    $setup_info[ 'phpgwapi' ][ 'name' ] = 'phpgwapi';
    $setup_info[ 'phpgwapi' ][ 'title' ] = 'phpgwapi';
    $setup_info[ 'phpgwapi' ][ 'version' ] = '2.2.000';
    $setup_info[ 'phpgwapi' ][ 'versions' ][ 'current_header' ] = '2.0';
    $setup_info[ 'phpgwapi' ][ 'enable' ] = 3;
    $setup_info[ 'phpgwapi' ][ 'app_order' ] = 1;

    /* The tables this app creates */
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_config';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_applications';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_acl';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_accounts';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_preferences';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_sessions';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_app_sessions';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_access_log';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_hooks';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_languages';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_lang';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_nextid';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_categories';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_log';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_log_msg';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_vfs';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_history_log';
    $setup_info[ 'phpgwapi' ][ 'tables' ][ ] = 'phpgw_async';