Exemple #1
0
 /**
  *  Load module-info into the current DB
  *
  *  @param  string  Any valid directory(-path)
  *  @param  boolean Call the install-script of the module? Default: false
  *
  *  THIS METHOD WAS MOVED TO CAT_Helper_Addons!
  *
  */
 function load_module($directory, $install = false)
 {
     if (!class_exists('CAT_Helper_Addons')) {
         @(require_once dirname(__FILE__) . '/CAT/Helper/Addons.php');
     }
     $addons_helper = new CAT_Helper_Addons();
     $addons_helper->loadModuleIntoDB($directory, 'install');
     if ($install == true) {
         if (file_exists($directory . '/install.php')) {
             require $directory . '/install.php';
         }
     }
 }
}
// validate
$path = CAT_Helper_Directory::sanitizePath(CAT_PATH . '/' . $type . '/' . $module . ($type == 'languages' ? '.php' : ''));
$info = CAT_Helper_Addons::checkInfo($path);
if (!is_array($info) || !count($info)) {
    $backend->print_error($backend->lang()->translate('Unable to {{ action }} {{ type }} {{ module }}!', array('action' => $action, 'type' => substr($type, 0, -1), 'module' => $path)) . ': <tt>"' . htmlentities(basename($path)) . '/' . $action . '.php"</tt> ' . $backend->lang()->translate('does not exist'), $js_back);
}
if ($type != 'languages') {
    // this prints an error page if prerequisites are not met
    $precheck_errors = CAT_Helper_Addons::preCheckAddon(NULL, $path, false);
    if ($precheck_errors != '' && !is_bool($precheck_errors)) {
        $backend->print_error($backend->lang()->translate('Invalid installation file. {{error}}', array('error' => $precheck_errors)));
        return false;
    }
    $admin =& $backend;
    // Run the modules install // upgrade script if there is one
    if (file_exists($path . '/' . $action . '.php')) {
        require $path . '/' . $action . '.php';
    }
}
CAT_Helper_Addons::loadModuleIntoDB($path, $action, $info);
switch ($action) {
    case 'install':
    case 'upgrade':
        $backend->print_success(str_replace('deed', 'ded', 'Addon successfully ' . $action . 'ed'), $js_back);
        break;
    default:
        $backend->print_error('Action not supported', $js_back);
}
// Print admin footer
$backend->print_footer();
Exemple #3
0
}
// if it's a template...
if ($type == 'template') {
    $contents = file_get_contents($full . '/index.php');
    $contents .= "\n\$dwoodata\t= array(); // if you need to set some additional template vars, add them here\nglobal \$page_id;\n\$variant = CAT_Helper_Page::getPageSettings(\$page_id,'internal','template_variant');\nif ( \$variant == '' ) \$variant = DEFAULT_TEMPLATE_VARIANT;\nif ( \$variant == '' || !file_exists(CAT_PATH.'/templates/bootstrap/templates/'.\$variant.'/index.tpl' ) )\n    \$variant = 'default';\n\$parser->setPath(CAT_TEMPLATE_DIR.'/templates/'.\$variant);\n\$parser->setFallbackPath(CAT_TEMPLATE_DIR.'/templates/default');\n\$parser->output('index.tpl',\$dwoodata);\n";
    file_put_contents($full . '/index.php', $contents);
    CAT_Helper_Directory::createDirectory($full . '/templates/default');
    CAT_Helper_Directory::recursiveCreateIndex($full . '/templates');
}
// insert module into DB
foreach ($info as $key => $value) {
    $key = str_replace($pre, 'module_', $key);
    $info[$key] = $value;
}
$info['addon_function'] = $type;
CAT_Helper_Addons::loadModuleIntoDB($dir, 'install', $info);
$success = true;
$message = $backend->lang()->translate('Module created successfully!');
printResult();
function printResult()
{
    global $message, $success;
    $ajax = array('message' => $message, 'success' => $success);
    print json_encode($ajax);
    exit;
}
function writeHeader($fh, $name, $author, $type)
{
    fwrite($fh, '<' . '?' . 'php

/**
Exemple #4
0
/**
 * installs all modules, templates, and languages
 **/
function install_modules($cat_path, $database)
{
    global $admin, $bundled, $mandatory;
    write2log('> [install_modules()]');
    $errors = array();
    require $cat_path . '/framework/initialize.php';
    // Load addons into DB
    $dirs = array('modules' => $cat_path . '/modules/', 'templates' => $cat_path . '/templates/', 'languages' => $cat_path . '/languages/');
    $ignore_files = array('admin.php', 'index.php', 'edit_module_files.php');
    write2log('------------------------------------');
    write2log('-----    installing addons     -----');
    write2log('------------------------------------');
    foreach ($dirs as $type => $dir) {
        $subs = $type == 'languages' ? CAT_Helper_Directory::getInstance()->setRecursion(false)->getPHPFiles($dir, $dir . '/') : CAT_Helper_Directory::getInstance()->setRecursion(false)->getDirectories($dir, $dir . '/');
        natsort($subs);
        foreach ($subs as $item) {
            if (in_array($item, $ignore_files)) {
                continue;
            }
            if ($type == 'languages') {
                write2log('installing language [' . $item . ']');
                $info = CAT_Helper_Addons::checkInfo($dir . '/' . $item);
                if (!CAT_Helper_Addons::loadModuleIntoDB($dir . '/' . $item, 'install', $info)) {
                    $errors[$dir] = sprintf('Unable to add language [%s] to database!', $item);
                    write2log(sprintf('Unable to add language [%s] to database!', $item));
                } else {
                    write2log(sprintf('%s [%s] sucessfully installed', ucfirst(substr($type, 0, -1)), $item));
                }
            } else {
                write2log('installing module/template [' . $item . ']');
                $addon_info = CAT_Helper_Addons::checkInfo($dir . '/' . $item);
                // load the module info into the database
                if (!CAT_Helper_Addons::loadModuleIntoDB($dir . '/' . $item, 'install', $addon_info)) {
                    $errors[$dir] = sprintf('Unable to add %s [%s] to database!', $type, $item);
                    write2log(sprintf('Unable to add %s [%s] to database!', $type, $item));
                } else {
                    write2log('running ' . $item . '/install.php');
                    // Run the install script if there is one
                    if (file_exists($dir . '/' . $item . '/install.php')) {
                        require $dir . '/' . $item . '/install.php';
                    }
                    write2log(sprintf('%s [%s] sucessfully installed', ucfirst(substr($type, 0, -1)), $item));
                }
            }
        }
    }
    // mark bundled modules
    foreach ($bundled as $module) {
        $database->query(sprintf('UPDATE `%saddons` SET bundled="Y" WHERE directory="%s"', CAT_TABLE_PREFIX, $module));
    }
    // mark mandatory modules
    foreach ($mandatory as $module) {
        $database->query(sprintf('UPDATE `%saddons` SET removable="N" WHERE directory="%s"', CAT_TABLE_PREFIX, $module));
    }
    write2log('< [install_modules()]');
    return array(count($errors) ? false : true, $errors);
}