| 1 |
<?php
|
| 2 |
// $Id: zend.module,v 1.1.2.1.2.10 2008/06/01 18:01:21 robloach Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* The Zend module for Drupal ensures that the Zend Framework is installed.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Determines whether or not the Zend Framework include path has been
|
| 11 |
* manually set yet.
|
| 12 |
*/
|
| 13 |
global $_ZEND_INCLUDE_PATH_SET;
|
| 14 |
|
| 15 |
/**
|
| 16 |
* Implementation of hook_help().
|
| 17 |
*/
|
| 18 |
function zend_help($path, $arg) {
|
| 19 |
switch ($path) {
|
| 20 |
case 'admin/help#zend':
|
| 21 |
return '<p>'. t('The Zend Framework is an open source web application framework for developing PHP 5 web applications.') .'</p>';
|
| 22 |
case 'admin/settings/zend':
|
| 23 |
return '<p>'. t('The Zend Framework is an open source web application framework for developing PHP 5 web applications. The following are configruation options for its installation.') .'</p>';
|
| 24 |
}
|
| 25 |
}
|
| 26 |
|
| 27 |
/**
|
| 28 |
* Implementation of hook_menu().
|
| 29 |
*/
|
| 30 |
function zend_menu() {
|
| 31 |
$items['admin/settings/zend'] = array(
|
| 32 |
'title' => 'Zend Framework',
|
| 33 |
'description' => 'Configuration options for the Zend Framework',
|
| 34 |
'page callback' => 'drupal_get_form',
|
| 35 |
'page arguments' => array('zend_admin'),
|
| 36 |
'access arguments' => array('access administration pages'),
|
| 37 |
'type' => MENU_NORMAL_ITEM,
|
| 38 |
'file' => 'zend.admin.inc',
|
| 39 |
);
|
| 40 |
$items['admin/settings/zend/settings'] = array(
|
| 41 |
'title' => 'Settings',
|
| 42 |
'description' => 'General settings relating to the Zend Framework.',
|
| 43 |
'type' => MENU_DEFAULT_LOCAL_TASK,
|
| 44 |
'weight' => -10,
|
| 45 |
);
|
| 46 |
return $items;
|
| 47 |
}
|
| 48 |
|
| 49 |
/**
|
| 50 |
* Implementation of hook_requirements().
|
| 51 |
*/
|
| 52 |
function zend_requirements($phrase) {
|
| 53 |
$requirements = array();
|
| 54 |
if ($phrase == 'runtime') {
|
| 55 |
$requirements['zend'] = array('title' => 'Zend Framework');
|
| 56 |
$version = zend_get_version();
|
| 57 |
if ($version == FALSE) {
|
| 58 |
$requirements['zend']['value'] = t('Not installed');
|
| 59 |
$requirements['zend']['description'] = t('The <a href="@url" target="_blank">Zend Framework</a> was not found. Please <a href="@configure">configure it</a> correctly.', array('@url' => 'http://framework.zend.com', '@configure' => url('admin/settings/zend')));
|
| 60 |
$requirements['zend']['severity'] = REQUIREMENT_WARNING;
|
| 61 |
}
|
| 62 |
else {
|
| 63 |
$requirements['zend']['value'] = $version;
|
| 64 |
$requirements['zend']['severity'] = REQUIREMENT_OK;
|
| 65 |
}
|
| 66 |
}
|
| 67 |
return $requirements;
|
| 68 |
}
|
| 69 |
|
| 70 |
/**
|
| 71 |
* Ensures that the Zend Framework is installed and ready for use.
|
| 72 |
*
|
| 73 |
* @param $display_message
|
| 74 |
* TRUE or FALSE depending on whether or not to display a message.
|
| 75 |
* @return
|
| 76 |
* FALSE if the Zend Framework was not found, the version number otherwise.
|
| 77 |
*/
|
| 78 |
function zend_ready($display_message = TRUE) {
|
| 79 |
static $zend_version = NULL;
|
| 80 |
if ($zend_version !== NULL) { // Use cached version.
|
| 81 |
return $zend_version;
|
| 82 |
}
|
| 83 |
|
| 84 |
// Get the version number.
|
| 85 |
if (zend_initialize('Zend_Version')) {
|
| 86 |
return $zend_version = Zend_Version::VERSION;
|
| 87 |
}
|
| 88 |
else {
|
| 89 |
if ($display_message) {
|
| 90 |
drupal_set_message(t('The <a href="@url" target="_blank">Zend Framework</a> was not found. Please <a href="@configure">configure it</a> correctly.', array('@url' => 'http://framework.zend.com', '@configure' => url('admin/settings/zend'))), 'error');
|
| 91 |
}
|
| 92 |
return FALSE;
|
| 93 |
}
|
| 94 |
}
|
| 95 |
|
| 96 |
/**
|
| 97 |
* Retrive the currently installed Zend Framework version number.
|
| 98 |
*
|
| 99 |
* @return
|
| 100 |
* The version number of the currently installed Zend Framework.
|
| 101 |
* FALSE otherwise.
|
| 102 |
*/
|
| 103 |
function zend_get_version() {
|
| 104 |
return zend_ready(FALSE);
|
| 105 |
}
|
| 106 |
|
| 107 |
/**
|
| 108 |
* Retrieve the expected path to the Zend Framework.
|
| 109 |
*
|
| 110 |
* @return
|
| 111 |
* The path where the Zend Framework is to be expected to be installed.
|
| 112 |
*/
|
| 113 |
function zend_get_path() {
|
| 114 |
return variable_get('zend_path', '');
|
| 115 |
}
|
| 116 |
|
| 117 |
/**
|
| 118 |
* Set the include path to include the Zend Framework.
|
| 119 |
*/
|
| 120 |
function zend_set_include_path() {
|
| 121 |
global $_ZEND_INCLUDE_PATH_SET;
|
| 122 |
if ($_ZEND_INCLUDE_PATH_SET === TRUE) {
|
| 123 |
return TRUE;
|
| 124 |
}
|
| 125 |
$path = zend_get_path();
|
| 126 |
$include_path = get_include_path() . PATH_SEPARATOR . realpath($path);
|
| 127 |
return $_ZEND_INCLUDE_PATH_SET = (set_include_path($include_path) === FALSE) ? FALSE : TRUE;
|
| 128 |
}
|
| 129 |
|
| 130 |
/**
|
| 131 |
* Includes a file from the Zend Framework.
|
| 132 |
*
|
| 133 |
* @param $file
|
| 134 |
* The file to include.
|
| 135 |
* Some examples are: "Zend/Gdata.php", "Zend/Version.php", etc.
|
| 136 |
* @return
|
| 137 |
* TRUE or FALSE depending on if the file was included successfully.
|
| 138 |
*/
|
| 139 |
function zend_include($file) {
|
| 140 |
static $included = array();
|
| 141 |
if (isset($included[$file])) {
|
| 142 |
return $included[$file];
|
| 143 |
}
|
| 144 |
if (zend_set_include_path()) {
|
| 145 |
try {
|
| 146 |
$included[$file] = @include_once($file);
|
| 147 |
}
|
| 148 |
catch (Exception $e) {
|
| 149 |
$included[$file] = FALSE;
|
| 150 |
}
|
| 151 |
}
|
| 152 |
return isset($included[$file]) ? $included[$file] : FALSE;
|
| 153 |
}
|
| 154 |
|
| 155 |
/**
|
| 156 |
* Includes a file from the Zend Framework. Results in a fatal error on fail.
|
| 157 |
*/
|
| 158 |
function zend_require($file) {
|
| 159 |
if (zend_set_include_path()) {
|
| 160 |
require_once $file;
|
| 161 |
}
|
| 162 |
return TRUE;
|
| 163 |
}
|
| 164 |
|
| 165 |
/**
|
| 166 |
* Loads a class from the Zend Framework.
|
| 167 |
*
|
| 168 |
* @param $class
|
| 169 |
* The class to load ("Zend_Gdata", "Zend_Session", etc).
|
| 170 |
* @return
|
| 171 |
* TRUE or FALSE depending on if the class was loaded successfully.
|
| 172 |
*/
|
| 173 |
function zend_initialize($class) {
|
| 174 |
if (zend_include('Zend/Loader.php')) {
|
| 175 |
try {
|
| 176 |
Zend_Loader::loadClass($class);
|
| 177 |
}
|
| 178 |
catch (Zend_Exception $e) {
|
| 179 |
return FALSE;
|
| 180 |
}
|
| 181 |
return TRUE;
|
| 182 |
}
|
| 183 |
return FALSE;
|
| 184 |
}
|