Пример #1
0
 public function __construct()
 {
     parent::__construct();
     $this->design_page_name = '';
     $this->add_event(PAGE_INIT, 'check_login');
     $this->add_event(PAGE_INIT, 'on_init');
     if ($dh = opendir(CMS . 'modules/')) {
         while (($name = readdir($dh)) !== false) {
             if (is_dir(CMS . 'modules/' . $name)) {
                 if (@file_exists(CMS . 'modules/' . $name . '/admin.php')) {
                     require_once CMS . 'modules/' . $name . '/admin.php';
                     $class_name = Cms::capitalize_words($name) . 'AdminModule';
                     $this->modules[$name] = new $class_name();
                     $this->modules[$name]->owner = $this;
                 }
             }
         }
         closedir($dh);
     }
     uasort($this->modules, create_function('$a,$b', 'return Cms::path_parts_count($b->get_tree_subpath())-Cms::path_parts_count($a->get_tree_subpath());'));
 }
Пример #2
0
 public function __construct()
 {
     parent::__construct();
     $this->design_page_name = '';
     $this->add_event(PAGE_INIT, 'check_login');
     $this->add_event(PAGE_INIT, 'on_init');
     $this->add_event(AJ_INIT, 'ajax_check_login');
     if ($dh = opendir(CMS . 'modules/')) {
         while (($name = readdir($dh)) !== false) {
             if (is_dir(CMS . 'modules/' . $name)) {
                 if (@file_exists(CMS . 'modules/' . $name . '/admin.php')) {
                     require_once CMS . 'modules/' . $name . '/admin.php';
                     $class_name = Cms::capitalize_words($name) . 'AdminModule';
                     $this->modules[$name] = new $class_name();
                     $this->modules[$name]->owner = $this;
                 }
             }
         }
         closedir($dh);
         foreach ($this->modules as $module) {
             $module->register();
         }
     }
 }
Пример #3
0
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * Zame CMS
 */
require_once dirname(__FILE__) . '/../../s/s.php';
require_once BASE . 'inc/core/core.php';
require_once CMS . 'core/base_command.php';
if (!isset($argc) || $argc < 2) {
    echo "Usage: php run.php <command> [command-arguments]\n";
    exit;
}
$command_path = CMS . "modules/{$argv[1]}/command.php";
if (!is_readable($command_path)) {
    echo "{$command_path} not found\n";
    exit;
}
require_once $command_path;
$class_name = Cms::capitalize_words($argv[1]) . 'Command';
$command = new $class_name();
if (!$command instanceof BaseCommand) {
    echo "{$class_name} does not extend BaseCommand\n";
    exit;
}
echo "[+ {$class_name}]\n";
$command->run(array_slice($argv, 2));
echo "[- {$class_name}]\n";
Пример #4
0
 protected function install($module)
 {
     $node = Node::get_node('site');
     if (!$node) {
         $this->message('Creating root node');
         Node::create_node(Node::Folder, 'site', conf_get('sitename'), Node::Visible | Node::System);
     } else {
         $this->message('Updating root node');
         $node->title = conf_get('sitename');
         $node->save();
     }
     if ($module) {
         $this->call_module_method($module, 'module_install', 'Installing');
         return;
     }
     if (!($dh = opendir(CMS . 'modules/'))) {
         $this->message('"' . CMS . 'modules/" not found');
         return;
     }
     $avail_modules = array();
     while (($module = readdir($dh)) !== false) {
         if (!is_dir(CMS . "modules/{$module}") || !is_readable(CMS . "modules/{$module}/admin.php")) {
             continue;
         }
         require_once CMS . "modules/{$module}/admin.php";
         $class_name = Cms::capitalize_words($module) . 'AdminModule';
         if (!is_callable(array($class_name, 'module_install'))) {
             continue;
         }
         $before = array();
         $after = array();
         if (is_callable(array($class_name, '_before'))) {
             $before = call_user_func(array($class_name, '_before'));
             if (!is_array($before)) {
                 $before = array($before);
             }
         }
         if (is_callable(array($class_name, '_after'))) {
             $after = call_user_func(array($class_name, '_after'));
             if (!is_array($after)) {
                 $after = array($after);
             }
         }
         $avail_modules[$module] = array('class' => $class_name, 'before' => $before, 'after' => $after);
     }
     closedir($dh);
     foreach ($avail_modules as $mod_name => $item) {
         foreach ($item['after'] as $name) {
             if (!array_key_exists($name, $avail_modules)) {
                 $this->message("\"{$mod_name}\" depends on \"{$name}\", but \"{$name}\" not found");
                 return;
             }
         }
     }
     foreach ($avail_modules as $mod_name => $item) {
         foreach ($item['before'] as $name) {
             if (array_key_exists($name, $avail_modules)) {
                 if (!in_array($mod_name, $avail_modules[$name]['after'])) {
                     $avail_modules[$name]['after'][] = $mod_name;
                 }
             }
         }
     }
     $modules_list = array();
     $modules_hash = array();
     for (;;) {
         $has_changes = false;
         $has_modules = false;
         foreach ($avail_modules as $mod_name => $item) {
             if (array_key_exists($mod_name, $modules_hash)) {
                 continue;
             }
             $has_modules = true;
             $can_insert = true;
             foreach ($item['after'] as $name) {
                 if (!array_key_exists($name, $modules_hash)) {
                     $can_insert = false;
                     break;
                 }
             }
             if (!$can_insert) {
                 continue;
             }
             $class_name = $item['class'];
             $modules_hash[$mod_name] = true;
             $modules_list[] = $mod_name;
             $has_changes = true;
         }
         if (!$has_modules) {
             break;
         }
         if (!$has_changes) {
             $this->message("Can't resolve modules dependencies");
             return;
         }
     }
     foreach ($modules_list as $module) {
         $this->call_module_method($module, 'module_install', 'Installing');
     }
 }
Пример #5
0
 protected function load_modules()
 {
     $cached_list_path = conf('cache.path') . 'modules.list';
     if (@file_exists($cached_list_path)) {
         $cached_list = unserialize(file_get_contents($cached_list_path));
         foreach ($cached_list as $name) {
             require_once CMS . 'modules/' . $name . '/module.php';
             $class_name = Cms::capitalize_words($name) . 'Module';
             $this->modules[$name] = new $class_name($this);
         }
         return;
     }
     $avail_modules = array();
     if ($dh = opendir(CMS . 'modules/')) {
         while (($name = readdir($dh)) !== false) {
             if (is_dir(CMS . 'modules/' . $name)) {
                 if (@file_exists(CMS . 'modules/' . $name . '/module.php')) {
                     require_once CMS . 'modules/' . $name . '/module.php';
                     $class_name = Cms::capitalize_words($name) . 'Module';
                     $before = array();
                     $after = array();
                     if (is_callable(array($class_name, '_before'))) {
                         $before = call_user_func(array($class_name, '_before'));
                         if (!is_array($before)) {
                             $before = array($before);
                         }
                     }
                     if (is_callable(array($class_name, '_after'))) {
                         $after = call_user_func(array($class_name, '_after'));
                         if (!is_array($after)) {
                             $after = array($after);
                         }
                     }
                     $avail_modules[$name] = array('class' => $class_name, 'before' => $before, 'after' => $after);
                 }
             }
         }
         closedir($dh);
     }
     foreach ($avail_modules as $mod_name => $item) {
         foreach ($item['after'] as $name) {
             if (!array_key_exists($name, $avail_modules)) {
                 throw new Exception("\"{$mod_name}\" depends on \"{$name}\", but \"{$name}\" not found");
             }
         }
     }
     foreach ($avail_modules as $mod_name => $item) {
         foreach ($item['before'] as $name) {
             if (array_key_exists($name, $avail_modules)) {
                 if (!in_array($mod_name, $avail_modules[$name]['after'])) {
                     $avail_modules[$name]['after'][] = $mod_name;
                 }
             }
         }
     }
     $cached_list = array();
     for (;;) {
         $has_changes = false;
         $has_modules = false;
         foreach ($avail_modules as $mod_name => $item) {
             if (array_key_exists($mod_name, $this->modules)) {
                 continue;
             }
             $has_modules = true;
             $can_insert = true;
             foreach ($item['after'] as $name) {
                 if (!array_key_exists($name, $this->modules)) {
                     $can_insert = false;
                     break;
                 }
             }
             if (!$can_insert) {
                 continue;
             }
             $class_name = $item['class'];
             $this->modules[$mod_name] = new $class_name($this);
             $cached_list[] = $mod_name;
             $has_changes = true;
         }
         if (!$has_modules) {
             break;
         }
         if (!$has_changes) {
             throw new Exception("Can't resolve modules dependencies");
         }
     }
     if ($fp = @fopen($cached_list_path, 'wb')) {
         fwrite($fp, serialize($cached_list));
         fclose($fp);
         chmod($cached_list_path, 0555 + 0111);
     }
     $avail_modules = null;
 }
 public function fill_def_form_data(&$data, $node, $title_label = null, $path_type = 0, $separate_title = false)
 {
     $data['title'] = strlen($node->title) ? htmlspecialchars($node->title) : '<em>' . $this->get_new_name_for_node($node) . '</em>';
     $data['rows'] = array();
     if ($path_type != self::PATH_TYPE_HIDDEN_ALL) {
         $data['rows'][] = array('id' => '_title', 'label' => $title_label === null ? Loc::get('cms/admin/title-label') : $title_label, 'type' => 'text', 'value' => $node->title, 'validate' => 'SValidators.required');
     }
     if ($path_type == self::PATH_TYPE_EDITABLE) {
         $data['rows'][] = array('id' => '_name', 'label' => Loc::get('cms/admin/path'), 'type' => 'html', 'value' => join('', array('<table cellspacing="0" cellpadding="0" width="100%" class="s-form-e"><tr>', '<td nowrap="nowrap"><strong>', htmlspecialchars($node->parent_path), '/</strong></td>', '<td width="100%"><input class="s-inp" type="text" name="_name" value="', htmlspecialchars($node->name), '" /></td>', '</tr></table>')));
     } elseif ($path_type == self::PATH_TYPE_READONLY) {
         if ($node->name != '') {
             $data['rows'][] = array('id' => '_name', 'label' => Loc::get('cms/admin/path'), 'type' => 'html', 'value' => htmlspecialchars($node->parent_path) . '/<strong>' . htmlspecialchars($node->name) . '</strong>');
         }
     } elseif ($path_type == self::PATH_TYPE_NAME) {
         if ($node->name != '') {
             $data['rows'][] = array('id' => '_name', 'label' => Loc::get('cms/admin/system-name'), 'type' => 'html', 'value' => htmlspecialchars($node->name));
         }
     }
     if ($path_type != self::PATH_TYPE_HIDDEN_ALL && $separate_title) {
         $data['rows'][] = array('id' => '_title_separator', 'label' => false, 'type' => 'html', 'value' => '<hr />');
     }
     foreach ($node->editable_fields as $field => $options) {
         if (!is_array($options)) {
             $options = array('type' => $options);
         }
         $options = $options + array('id' => $field, 'value' => $node->attr($field), 'label' => Cms::capitalize_words($field, ' '));
         $data['rows'][] = $options;
     }
     if (_SESSION('s.cms.admin.just-saved')) {
         $_SESSION['s.cms.admin.just-saved'] = false;
         $data['info'] = Loc::get('cms/admin/saved');
         $data['extra']['update_tree'] = true;
         $data['extra']['select_node'] = $node->id;
     }
 }
Пример #7
0
 protected function on_after_save($was_new)
 {
     if ($this->_attr !== null) {
         $res_attr = array();
         foreach ($this->_attr as $attrs) {
             foreach ($attrs as $attr) {
                 if ($attr['v'] === null) {
                     if ($attr['i'] != 0) {
                         SRecord::remove_by_id('Attribute', $attr['i']);
                     }
                 } else {
                     $attr['v']->node_id = $this->id;
                     if ($attr['v']->is_dirty()) {
                         $attr['v']->save();
                     }
                     if (!array_key_exists('n' . $attr['v']->name, $res_attr)) {
                         $res_attr['n' . $attr['v']->name] = array();
                     }
                     $res_attr['n' . $attr['v']->name]['n' . $attr['v']->lang] = array('i' => $attr['v']->id, 'v' => $attr['v']);
                 }
             }
         }
         $this->_attr = $res_attr;
         $res_attr = null;
     }
     if ($this->_acl !== null) {
         $existing_acl = array();
         foreach ($this->acl as $acl) {
             $existing_acl[urlencode($acl->action) . ':' . urlencode($acl->ident)] = true;
             if (!array_key_exists($acl->action, $this->_acl) || !array_key_exists($this->_acl[$acl->action], $acl->ident) || !$this->_acl[$acl->action][$acl->ident]) {
                 $acl->remove();
             }
         }
         foreach ($this->_acl as $action) {
             foreach ($this->_acl[$action] as $ident) {
                 if ($this->_acl[$action][$ident] && !array_key_exists(urlencode($action) . ':' . urlencode($ident))) {
                     $acl = new Acl();
                     $acl->node_id = $this->id;
                     $acl->action = $action;
                     $acl->ident = $ident;
                     $acl->save();
                 }
             }
         }
     }
     $path = CMS . "modules/{$this->type}/model.php";
     if (is_readable($path)) {
         require_once $path;
         $class_name = Cms::capitalize_words($this->type);
         if (is_callable(array($class_name, '_saved'))) {
             call_user_func(array($class_name, '_saved'), $this, $was_new);
         }
     }
 }