Communiware.pm


NAME

  Communiware.pm - Communiware base module.


SYNOPSIS

  Communiware::Init(alternate_config)
  PerlChildInitHandler Communiware::ChildInit
  <Perl>
     Communiware::InitApache;
  </Perl>   
  
=head1 DESCRIPTION

Provides some things, essential for all communiware scripts


GLOBAL VARIABLES

There are set of global variables defined in this module.

$Communiware::CGI
Object of type CGI which holds parameters of query, given to Communiware. It may be sayed it contains global context of Communiware.

$Communiware::DEBUG
Boolean flag. If true then more debug messages are printed into Communiware server error logfile.

$Communiware::MaxItemSize
Max lenght of item text. It is taken from Communiware config file, parameter MAXSIZE.

$Communiware::VERSION
Version number of this Communiware instance.

$Communiware::cache_timestamp
Time in standard Communiware format, the moment of last database data caching. If this value is less than field timestamp in metainfo table, then data must be recached.

$Communiware::dbh
Object of Communiware::SQL::Server descendant type. Current connection to database.

$Communiware::defaultConfig
Full name of default Communiware config file. It is used unless another config file name is given.

$Communiware::rtfconverter
Full name of rtf2html program used for Microsoft RTF to HTML text format converting.

$Communiware::self_url
Full url of current Communiware page with query string, but without ERROR nor REFERER parameters in query string.

$Communiware::server
The name of current Communiware server, the same as CURRENT_SERVER attribute.

$Communiware::template_id
Template id, used to process current item, the same as CURRENT_TEMPLATE attribute.

$Communiware::translationTables
Full name of directory contains charset converting files.

%Communiware::AttrDomain
Keys are names of attributes having lookup tables for possible values, ie 'SEX'. Values - references to array with some information about tables and attributes.

%Communiware::AttrQualified
Keys are names of qualified attributes, values - just 1 for all.

%Communiware::AttrQuery
SQL-queries for getting attribute value from ITEM_ID.

%Communiware::AttrTable
Mapping attribute names to names of database tables which hold values of these attributes.

%Communiware::AttrType
Type of each known attribute.

%Communiware::TypeTable
Maps item types to thier extended attr tables (if any).

%Communiware::Authorize
Keys are Communiware servers, values are authorize level for this server.

%Communiware::BackendHosts
Keys are Communiware servers, values are names of backend host for this server. They are, as a rule, 'localhost' when frontend is used.

%Communiware::CookieDefault
Default values for COOKIE attributes.

%Communiware::Hostname
Keys are Communiware servers, values are names of hosts, corresponding to this server.

%Communiware::LinkHierarchy
Keys are link names, values are types of this link. 0 - one-level link, 1 - hierarchical link and 2 - metalink.

%Communiware::LinkAuthorizing
Keys are link names values are 1 if link is authorizing and 0 otherwise.

%Communiware::MetaLinksRel
Keys are metalink type names, values are hash references where keys are linktype names into those metalinks.

%Communiware::LocalType
Extra information about types of attributes. If set for some attribute then overrides values from %Communiware::AttrType

%Communiware::Magic
Short description of MAGIC attributes.

%Communiware::MagicType
Types of MAGIC attributes

%Communiware::Prefix
Hash contains some important url prefixes. In particularry: URL (url prefix for this Communiware server items), PIC (pictures) and SCRIPT (scripts). Remember, the same values are contained in URL_PREFIX, PIC_PREFIX and SCRIPT_PREFIX attributes.

%Communiware::SystemLocale
Maps short names of languages (en, ru) to long locale names (en_US, ru_RU.KOI-8).

%Communiware::UrlPrefix
Maps server names to url prefixes for this server.

%Communiware::Urldir
Maps url prefixes to server names.

%Communiware::config
Keeps values of Communiware config file, which default name is $Communiware::defaultConfig.

$Communiware::configtree
Object of Communiware::Config class, holds all the information read from cmw.conf.

@Communiware::Attrs
Stack of contexts. [0] is the most earlyest, etc. Each frame in this stack is reference to hash of ATTRNAME => ATTRVALUE pairs.

@Communiware::Context::attributes_to_pass
List of attribute names, which must be passed through url

@Communiware::CookieArgs
Names of attribute whis was taken from cookie.

BEGIN section


FUNCTIONS

loging functions

SYNOPSIS

log_crit('some critical information'); ... log_debug('some debug information');

DESCRIPTION

Wrappers for using in Communiware modules.

Init

Reads given config file and performs common initialization applicable to both HTTP-server and scripts. Obsolete, please use init.

If called from main HTTPD instance, do not forget to disconnect Communiware::dbh after it (or, better call InitApache). If no config file is provided as procedure parameter, values of Communiware::defaultConfig, defined in the BEGIN section of this module is used.

init

Reads given config file and performs common initialization applicable to both HTTP-server and scripts.

        use Communiware;
        Communiware::init(config => '/path/to/config/file', charset => 'server', loglevel => 'debug');

Accepts following options: 1. config - path to config file. 2. charset - charset for data manipulations (by default guessed from environment). 3. loglevel - level of messages to set (default - 'warn').

If no config file is provided as procedure parameter, values of Communiware::defaultConfig, defined in the BEGIN section of this module is used.

If called from main HTTPD instance, do not forget to disconnect Communiware::dbh after it (or, better call InitApache).

init_cache procedure

Init caching infrastructure of communiware. Should by run on start stage. For example in Init.

Initializes $Communiware::fragcache, $Communiware::doccache.

InitApache procedure

Reads config file and configures Apache appropriatedly. Should be called from <Perl> section in httpd.conf Optionally takes an argument which specifies config location, if differs from $Communiware::defaultConfig.

Example:

  <Perl>
        use Communiware;
    Communiware::InitApache();
  </Perl>

ChildInit

Procedure ChildInit is called as Apache PerlChildInitHandler (see mod_perl). Its main job is to open connection to database and cache some data from database in memory - list of virtual servers, arrays of Communiware::DB module and attributes.

prepare_standard_queries

Prepares and stores in the Communiware::SQL::Server object a lot of SQL queries which are used unchanged throuqgout Communiware. See also cache_queries for queries, which are loaded from database.

Warning! Use of this routine for console apps is obsoleted. Please use direct call to methods of Communiware::dbhi get_cached or cache_standard_queries.

cache_queries

Prepares query for all non-qualified Communiware attributes.

Internal procedure cache_attributes caches types of attributes in Communiware::AttrTypes and sql queries which can be used to get attribute values in Communiware::AttrQuery. This queries typically obtain more than one attribute from database. They get all, which can be extracted from single row of single table

Cleanup procedure

Is called after communiware request have been processed. It destroys module variables used by init_context which can otherwise affect subsequent queries.


localize

Syntax

   localize(locale_shortname)

Sets neccessary localization parameters for system (gettext) and database (cmw_lang package)

guess_server

Gets uri and hostname If host is omitted, uses global default

returns array of server, item, template and undef value


get_logger

Returns logger object or creates new Logger with 'debug' level.

guess_browser

Parser user agent string as given by browser, and tries to return exact name (MSIE, Mozilla (if it is actually Netscape or Mozilla), Opera)

If user agent is identified as version of MSIE, tries to recognize Windows version

Syntax:

  ($name,$version,$windows_version) =  guess_browser($cgi->user_agent)
  
=cut

sub guess_browser { local $_ = shift; return ( 'BROWSER_NAME' => 'Opera', 'BROWSER_VERSION' => $1, 'OS_VERSION' => undef ) if /^Mozilla.*Opera\s+(\d+\.\d+)/; return ( 'BROWSER_NAME' => 'MSIE', 'BROWSER_VERSION' => $1, 'OS_VERSION' => win_version($_) ) if /MSIE\s*(\d+\.\d+)/; return ( 'BROWSER_NAME' => $1, 'BROWSER_VERSION' => $2, 'OS_VERSION' => undef ) if /^([^\/]+)\/(\d+(\.\d+))/; return ( 'BROWSER_NAME' => $1, 'BROWSER_VERSION' => 0, 'OS_VERSION' => undef ) if /^(\S+)\b/; }

define_address_magic

Creates magic attributes REMOTE_ADDR and FORWARDED_FOR, which contain remote IPs.

setup_communiware_prefixes

This is an internal procedure setting up elements of Communiware::Prefix.

validate_cache

This is an internal proc called from init_context

win_version

THis procedure parses browser string comparing to windows versions

PREFIX

        Communiware::PREFIX($site_id, 'URL')
        Communiware::PREFIX($site_id, 'PIC')

Returns full URL for urlprefix of picprefix of specified site. Return value(s) is(are) the same as in assemble_prefix.

Uses global variables only.

16 октябрь 2007 13:45