<?php
/* $Id: install.anjel.php 44 2005-12-01 03:49:19Z schmalls $ */
/**
* install.anjel.php
*
* <p>Install file for ANJEL. Includes {@link com_install} function.</p>
*
* @package ANJEL
* @subpackage backend
* @copyright © 2004-2005 Schmalls / Joshua Thompson / All Rights Reserved
* @license http://www.gnu.org/copyleft/gpl.html GNU/GPL
* @author Schmalls / Joshua Thompson <hide@address.com>
* @version 0.6.1
* @since 0.4.3
* @link http://www.schmalls.com
*/
/**
* Ensures this file is being included by a parent file
*/
defined('_VALID_MOS') or die('Direct Access to this location is not allowed.');
/**
* Joomla install function
*
* <p>Creates the newsletter directory in /images/stories and gives it the
* correct permissions.</p>
*
* @version 0.6.1
* @since 0.4.3
* @global string filesystem path to main site directory
*/
function com_install(){
global $mosConfig_absolute_path;
$return = '';
// create newsletter directory if it doesn't exist'
if (!file_exists($mosConfig_absolute_path . '/images/stories/newsletter/')){
umask(0);
@mkdir($mosConfig_absolute_path . '/images/stories/newsletter/');
}
// make newsletter directory writeable if it isn't
if (!is_writable($mosConfig_absolute_path . '/images/stories/newsletter/')){
@chmod($mosConfig_absolute_path . '/images/stories/newsletter/', 0777);
}
// make sure the anjel.php and admin.anjel.php files were copied
if (!is_file($mosConfig_absolute_path . '/components/com_anjel/anjel.php') || !is_file($mosConfig_absolute_path . '/administrator/components/com_anjel/admin.anjel.php')) {
// if not, output error message
$return .= '<span style="color:red;font-weight:bold;">There was an error during installation.</span>';
} // end if
// install bots
$return .= anjel_install_bots();
return $return;
} // end function
/**
* Installs the bots included with ANJEL
*
* <p>Creates the anjel bot group directory if it doesn't exist. Then copies
* the bot files to this directory. Then updates the database with the bot
* information.</p>
*
* @version 0.6.1
* @since 0.6.1
* @global string filesystem path to main site directory
* @global class access to the database
*/
function anjel_install_bots() {
global $mosConfig_absolute_path, $database;
$return = '';
// create the directory
if(!mosMakePath($mosConfig_absolute_path . '/mambots/', 'anjel')) {
$return .= '<p><b>Error (install.anjel.php-> line ' . __LINE__ . '):</b> Error adding bot directory.</p>';
} // end if
// copy files
$bot_files = array('bot_anjel_content.php', 'bot_anjel_content.xml', 'index.html');
foreach ($bot_files as $bot_file) {
// check if destination file exist
if (is_file($mosConfig_absolute_path . '/mambots/anjel/' . $bot_file)) {
// if so delete source file
unlink($mosConfig_absolute_path . '/administrator/components/com_anjel/bots/' . $bot_file);
} else if (!rename($mosConfig_absolute_path . '/administrator/components/com_anjel/bots/' . $bot_file, $mosConfig_absolute_path . '/mambots/anjel/' . $bot_file)) {
// if not try to move file
$return .= '<p><b>Error (install.anjel.php-> line ' . __LINE__ . '):</b> Error copying bot file ' . $bot_file . ' to bot directory.</p>';
} // end if
} // end foreach
if (!rmdir($mosConfig_absolute_path . '/administrator/components/com_anjel/bots/')) {
$return .= '<p><b>Error (install.anjel.php-> line ' . __LINE__ . '):</b> Error deleting the temporary bot directory.</p>';
} // end if
// update database
$bot_infos = array( array('ANJEL Content Bot', 'bot_anjel_content'));
foreach ($bot_infos as $bot_info) {
$query = 'SELECT id FROM `#__mambots` WHERE element = \'' . $bot_info[1] . '\'';
$database->setQuery($query);
$database->query();
$error = $database->getErrorMsg();
if (!empty($error)) {
$return .= '<p><b>Error (install.anjel.php-> line ' . __LINE__ . '):</b> Error getting bot information from bot table for "' . $bot_info[0] . '". Database error: <br />' . $error . '</p>';
} else {
$id = $database->loadResult();
if (!$id) {
$row = new mosMambot($database);
$row->name = $bot_info[0];
$row->ordering = 0;
$row->folder = 'anjel';
$row->iscore = 0;
$row->access = 0;
$row->client_id = 0;
$row->element = $bot_info[1];
$row->published = 1;
if (!$row->store()) {
$return .= '<p><b>Error (install.anjel.php-> line ' . __LINE__ . '):</b> Error adding bot information to bot table for "' . $bot_info[0] . '".</p>';
} // end if
} // end if
} // end if
} // end foreach
return $return;
} // end function
?>