File: base.php

package info (click to toggle)
turba2 2.2.1-2
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 7,332 kB
  • ctags: 2,927
  • sloc: php: 11,046; xml: 1,690; sql: 507; makefile: 62; perl: 17; sh: 1
file content (119 lines) | stat: -rw-r--r-- 4,112 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
 * Turba base inclusion file.
 *
 * $Horde: turba/lib/base.php,v 1.62.10.20 2008/05/25 17:40:02 chuck Exp $
 *
 * This file brings in all of the dependencies that every Turba script will
 * need, and sets up objects that all scripts use.
 */

// Check for a prior definition of HORDE_BASE (perhaps by an auto_prepend_file
// definition for site customization).
if (!defined('HORDE_BASE')) {
    define('HORDE_BASE', dirname(__FILE__) . '/../..');
}

// Load the Horde Framework core, and set up inclusion paths.
require_once HORDE_BASE . '/lib/core.php';

// Registry.
$registry = &Registry::singleton();
if (is_a(($pushed = $registry->pushApp('turba', !defined('AUTH_HANDLER'))), 'PEAR_Error')) {
    if ($pushed->getCode() == 'permission_denied') {
        Horde::authenticationFailureRedirect();
    }
    Horde::fatal($pushed, __FILE__, __LINE__, false);
}
$conf = $GLOBALS['conf'];
define('TURBA_TEMPLATES', $registry->get('templates'));

// Horde framework libraries.
require_once 'Horde/Help.php';
require_once 'Horde/History.php';

// Notification system.
$notification = &Notification::singleton();
$notification->attach('status');

// Find the base file path of Turba.
if (!defined('TURBA_BASE')) {
    define('TURBA_BASE', dirname(__FILE__) . '/..');
}

// Turba base libraries.
require_once TURBA_BASE . '/lib/Turba.php';
require_once TURBA_BASE . '/lib/Driver.php';
require_once TURBA_BASE . '/lib/Object.php';

// Turba source and attribute configuration.
include TURBA_BASE . '/config/attributes.php';
include TURBA_BASE . '/config/sources.php';

// Ensure we have cfgSources in global scope since base.php might be loaded
// within a function scope and the share hooks require access to cfgSources.
$GLOBALS['cfgSources'] = $cfgSources;

// See if any of our sources are configured to use Horde_Share.
foreach ($cfgSources as $key => $cfg) {
    if (!empty($cfg['use_shares'])) {
        $_SESSION['turba']['has_share'] = true;
        break;
    }
}
if (!empty($_SESSION['turba']['has_share'])) {
    // Create a share instance.
    require_once 'Horde/Share.php';
    $GLOBALS['turba_shares'] = &Horde_Share::singleton($registry->getApp());
    $GLOBALS['cfgSources'] = Turba::getConfigFromShares($cfgSources);
}
$GLOBALS['cfgSources'] = Turba::permissionsFilter($GLOBALS['cfgSources']);
$GLOBALS['attributes'] = $attributes;

// Check for any upgrade/maintenance needed
$res = Turba::doMaintenance();
if (is_a($res, 'PEAR_Error')) {
    Horde::logMessage($res, __FILE__, __LINE__, PEAR_LOG_ERR);
}

// Build the directory sources select widget.
$default_source = Util::nonInputVar('source');
if (empty($default_source)) {
    $default_source = empty($_SESSION['turba']['source']) ? Turba::getDefaultAddressBook() : $_SESSION['turba']['source'];
    $default_source = Util::getFormData('source', $default_source);
}
$browse_source_options = '';
$browse_source_count = 0;
foreach (Turba::getAddressBooks() as $key => $curSource) {
    if (!empty($curSource['browse'])) {
        $selected = ($key == $default_source) ? ' selected="selected"' : '';
        $browse_source_options .= '<option value="' . htmlspecialchars($key) . '" ' . $selected . '>' .
            htmlspecialchars($curSource['title']) . '</option>';

        $browse_source_count++;

        if (empty($default_source)) {
            $default_source = $key;
        }
    }
}
if (empty($cfgSources[$default_source]['browse'])) {
    $default_source = Turba::getDefaultAddressBook();
}
$_SESSION['turba']['source'] = $default_source;

// Only set $add_source_options if there is at least one editable address book
// that is not the current address book.
$addSources = Turba::getAddressBooks(PERMS_EDIT);
$copymove_source_options = '';
$copymoveSources = $addSources;
unset($copymoveSources[$default_source]);
foreach ($copymoveSources as $key => $curSource) {
    if ($key != $default_source) {
        $copymove_source_options .= '<option value="' . htmlspecialchars($key) . '">' .
            htmlspecialchars($curSource['title']) . '</option>';
    }
}

// Start compression, if requested.
Horde::compressOutput();