예제 #1
0
 function test_set()
 {
     $conf = Appconf::set('admin', 'Admin', 'handler', 'admin/versions2');
     $this->assertEquals('admin/versions2', $conf);
     $conf = Appconf::get('admin', 'Admin', 'handler');
     $this->assertEquals('admin/versions2', $conf);
     $conf = Appconf::set('admin', 'Admin', 'handler', 'admin/versions');
     $this->assertEquals('admin/versions', $conf);
     $conf = Appconf::get('admin', 'Admin', 'handler');
     $this->assertEquals('admin/versions', $conf);
 }
예제 #2
0
/**
 * Returns a list of pages that are not in the navigation.
 */
function navigation_get_other_pages($ids)
{
    $pages = array();
    $res = DB::fetch("select id, title, menu_title, access from #prefix#webpage where access != 'private'");
    //Adds apps to Navigation, the new way
    $nav = Appconf::options('nav');
    foreach ($nav as $id => $title) {
        $appObj = new StdClass();
        $appObj->id = $id;
        $appObj->title = $title;
        $res[] = $appObj;
    }
    // Add apps to Navigation, the old way
    $apps = glob('apps/*');
    foreach ($apps as $app) {
        $app = str_replace('apps/', '', $app);
        $ini = Appconf::get($app);
        foreach ($ini as $section) {
            if (array_key_exists('include_in_nav', $section) && $section['include_in_nav'] && array_key_exists('title', $section) && $section['title'] != '') {
                $appObj = new stdClass();
                if (!in_array($section['include_in_nav'], array('1', 1, true), true)) {
                    $appObj->id = ltrim($section['include_in_nav'], '/');
                } else {
                    $appPath = explode('/', $app);
                    $appObj->id = $appPath[0];
                }
                $appObj->title = $section['title'];
                $appObj->menu_title = array_key_exists('menu_title', $section) ? $section['menu_title'] : $section['title'];
                $res[] = $appObj;
                break;
            }
        }
    }
    foreach ($res as $p) {
        if (in_array($p->id, $ids)) {
            // skip if in tree
            continue;
        }
        if (!empty($p->menu_title)) {
            $pages[$p->id] = $p->menu_title;
        } else {
            $pages[$p->id] = $p->title;
        }
    }
    uasort($pages, function ($a, $b) {
        if ($a === $b) {
            return 0;
        }
        return $a < $b ? -1 : 1;
    });
    return $pages;
}
예제 #3
0
$apply = array();
foreach ($files as $k => $file) {
    if (preg_match('/^apps\\/' . $this->app . '\\/conf\\/upgrade_([0-9.]+)_' . $driver . '\\.sql$/', $file, $regs)) {
        if (version_compare($regs[1], $base_current, '>') && version_compare($regs[1], $base_version, '<=')) {
            $apply[$regs[1]] = $file;
        }
    }
}
// begin the transaction
DB::beginTransaction();
// apply the upgrade scripts
foreach ($apply as $ver => $file) {
    // parse the database schema into individual queries
    $sql = sql_split(file_get_contents($file));
    // execute each query in turn
    foreach ($sql as $query) {
        if (!DB::execute($query)) {
            // show error and rollback on failures
            printf('<p>%s</p><p class="visible-notice">%s: %s</p>', __('Upgrade failed on version %s. Rolling back changes.', $ver), __('Error'), DB::error());
            DB::rollback();
            return;
        }
    }
    // add any custom upgrade logic here
}
// commit the transaction
DB::commit();
// mark the new version installed
$this->mark_installed($this->app, $version);
printf('<p><a href="/%s">%s</a>', Appconf::get($this->app, 'Admin', 'handler'), __('Done.'));
예제 #4
0
            Cli::out('Invalid section name: ' . $section, 'error');
            return;
        }
        $settings = Appconf::get($app, $section);
        $names = array_keys($settings);
        sort($names);
        echo join(', ', $names) . "\n";
        // show specific setting (encoded as JSON value)
    } elseif (count($parts) === 3) {
        list($app, $section, $setting) = $parts;
        if (!preg_match($valid_app_name, $app) || !is_dir('apps/' . $app)) {
            Cli::out('Invalid app name: ' . $app, 'error');
            return;
        }
        if (!preg_match($valid_section_name, $section)) {
            Cli::out('Invalid section name: ' . $section, 'error');
            return;
        }
        if (!preg_match($valid_setting_name, $setting)) {
            Cli::out('Invalid setting name: ' . $setting, 'error');
            return;
        }
        $value = Appconf::get($app, $section, $setting);
        if (!defined('JSON_PRETTY_PRINT')) {
            define('JSON_PRETTY_PRINT', 0);
        }
        echo json_encode($value, JSON_PRETTY_PRINT) . "\n";
    } else {
        Cli::out('Invalid setting value: ' . $_SERVER['argv'][2], 'error');
    }
}
예제 #5
0
 /**
  * Looks for an override of the current handler in the app
  * configuration in a `[Custom Handlers]` section. Overrides
  * are handlers that should be called transparently in place
  * of the current handler, overriding its behaviour without
  * modifying the original handler.
  *
  * An override setting's key should be the app/handler name,
  * and the value can be either the same app/handler name
  * (meaning no override), another app/handler name (meaning
  * override with that handler), or Off (meaning disable the
  * handler). A handler that has been disabled will return a
  * 404 error.
  *
  * If the response is false, there was no override or disabling,
  * and the handler should continue running, otherwise the
  * response will contain the output of the override handler
  * which should be echoed and the original handler should
  * return and stop further execution.
  */
 public function override($handler)
 {
     static $overridden = array();
     if (in_array($handler, $overridden)) {
         // don't override the same handler
         // twice to prevent infinite loops
         return false;
     }
     $overridden[] = $handler;
     list($app) = explode('/', $handler);
     $custom = Appconf::get($app, 'Custom Handlers', $handler);
     if (!$custom) {
         // disable this handler
         return $this->error(404, __('Not found'), __('The page you requested could not be found.'));
     }
     if ($custom !== $handler) {
         // override the handler
         $override = count($this->params) ? $custom . '/' . join('/', $this->params) : $custom;
         return $this->run($override, $this->data, $this->internal);
     }
     // no override
     return false;
 }
예제 #6
0
파일: upgrade.php 프로젝트: techborn/polls
<?php

// keep unauthorized users out
$this->require_acl('admin', $this->app);
// set the layout
$page->layout = 'admin';
// get the version and check if the app installed
$version = Appconf::get($this->app, 'Admin', 'version');
$current = $this->installed($this->app, $version);
if ($current === true) {
    // app is already installed and up-to-date, stop here
    $page->title = __('Already up-to-date');
    printf('<p><a href="/%s/admin">%s</a>', $this->app, __('Home'));
    return;
}
$page->title = sprintf('%s: %s', __('Upgrading App'), Appconf::get($this->app, 'Admin', 'name'));
// grab the database driver
$conn = conf('Database', 'master');
$driver = $conn['driver'];
// check if upgrade script exists and if so, run it
$base_version = preg_replace('/-.*$/', '', $version);
$file = 'apps/' . $this->app . '/conf/upgrade_' . $base_version . '_' . $driver . '.sql';
if (file_exists($file)) {
    // begin the transaction
    DB::beginTransaction();
    // parse the database schema into individual queries
    $sql = sql_split(file_get_contents($file));
    // execute each query in turn
    foreach ($sql as $query) {
        if (!DB::execute($query)) {
            // show error and rollback on failures
예제 #7
0
파일: upgrade.php 프로젝트: R-J/elefant
// get the version and check if the app installed
$version = Appconf::get ($this->app, 'Admin', 'version');
$current = $this->installed ($this->app, $version);

if ($current === true) {
    // app is already installed and up-to-date, stop here
    $page->title = __ ('Already up-to-date');
    printf ('<p><a href="/%s/admin">%s</a>', $this->app, __ ('Home'));
    return;
}

$page->title = sprintf (
    '%s: %s',
    __ ('Upgrading App'),
    Appconf::get ($this->app, 'Admin', 'name')
);

// grab the database driver
$conn = conf ('Database', 'master');
$driver = $conn['driver'];

// check if upgrade script exists and if so, run it
$base_version = preg_replace ('/-.*$/', '', $version);
$file = 'apps/' . $this->app . '/conf/upgrade_' . $base_version . '_' . $driver . '.sql';
if (file_exists ($file)) {
    // begin the transaction
    DB::beginTransaction ();

    // parse the database schema into individual queries
    $sql = sql_split (file_get_contents ($file));