Author: Shea Dawson (shea@livesource.co.nz)
Inheritance: extends Object
Esempio n. 1
0
 /**
  * Transforms the registered blocks into a discriminatorMap
  *
  * @return array
  */
 public function getDiscriminatorMap()
 {
     $map = array();
     foreach ($this->blockManager->getValues() as $alias => $value) {
         $map[$alias] = $value->getEntity();
     }
     return $map;
 }
Esempio n. 2
0
 function Execute(rObjectRouter $router, WaxBlock $appblock, WaxBlock $ddmblock, array $view_args)
 {
     $view_name = $router->DetermineViewname();
     $vr_ctx = new ViewRenderCtx();
     /**
      * When extending the DDM block, the views are then looked for in the same block
      * as the child object (IE: Users extends DDM will look for Users/action, even though
      * we want it to load the DDM/action view).
      *
      * This try/catch here redirects the view request to the DDM views if it is not
      * found in the current block.
      */
     $content_for_layout = '';
     try {
         // Try finding the view in the application block
         $v = BlockManager::Lookup("views", $view_name);
         $content_for_layout = $vr_ctx->Execute(new View($v), $view_args);
     } catch (ResourceNotFoundException $vnfe) {
         try {
             // Try finding the view in the DDM block
             // IE: Admin/viewname
             //     ACL/viewname
             $view_name = $router->DetermineViewname();
             $content_for_layout = $vr_ctx->Execute(new View($view_name, $ddmblock), $view_args);
         } catch (ViewNotFoundException $vnfe) {
             // Try finding the view in the DDM block under the DDM object
             // Dynamic Models eventually end up here if there's no overrides
             $router->data['objectname'] = 'DDM';
             $view_name = $router->DetermineViewname();
             $content_for_layout = $vr_ctx->Execute(new View($view_name, $ddmblock), $view_args);
         }
     }
     return $content_for_layout;
 }
Esempio n. 3
0
 static function Render(rRenderable $self, $arguments = array())
 {
     $viewfile = "";
     $block = $self->GetViewBlock();
     $viewname = $self->GetViewName();
     try {
         if (!is_null($block)) {
             $viewfile = $block->views[$viewname];
         } else {
             if (!file_exists($viewname)) {
                 $viewfile = BlockManager::Lookup("views", $viewname);
             } else {
                 $viewfile = $viewname;
             }
         }
     } catch (ResourceNotFoundException $rnfe) {
         throw new ViewNotFoundException($self->GetViewName(), $block);
     }
     if (file_exists($viewfile)) {
         if (is_array($arguments)) {
             extract($arguments);
         }
         ob_start();
         include $viewfile;
         $rendered_view = ob_get_contents();
         ob_end_clean();
         return $rendered_view;
     } else {
         throw new ViewNotFoundException($viewname, $block->views);
     }
 }
Esempio n. 4
0
 /**
  * CSS Classes to apply to block element in template
  * @return string $classes
  */
 public function CSSClasses($stopAtClass = 'DataObject')
 {
     $classes = strtolower(parent::CSSClasses($stopAtClass));
     if ($this->blockManager->getUseExtraCSSClasses()) {
         $classes = $this->ExtraCSSClasses ? $classes . " {$this->ExtraCSSClasses}" : $classes;
     }
     return $classes;
 }
Esempio n. 5
0
/**
 * Gets a resource out of the Wax runtime.
 *
 * @param mixed $block Either a WaxBlock or the name of the block that the resource should be retrieved from.
 * @param string $resource_type One of the WaxBlock resource types (js/lib/views/css/etc...)
 * @param string $resource_name The name of the resource to retrieve
 * @return string
 */
function _resource($block, $resource_type, $resource_name)
{
    if (!$block instanceof WaxBlock) {
        $block = BlockManager::GetBlock($block);
    }
    $resource = $block->GetResource($resource_type, $resource_name);
    return $resource;
}
Esempio n. 6
0
 /**
  * CSS Classes to apply to block element in template
  * @return string $classes
  */
 public function CSSClasses($stopAtClass = 'DataObject')
 {
     $classes = strtolower(parent::CSSClasses($stopAtClass));
     if (!empty($classes) && ($prefix = $this->blockManager->getPrefixDefaultCSSClasses())) {
         $classes = $prefix . str_replace(" ", " {$prefix}", $classes);
     }
     if ($this->blockManager->getUseExtraCSSClasses()) {
         $classes = $this->ExtraCSSClasses ? $classes . " {$this->ExtraCSSClasses}" : $classes;
     }
     return $classes;
 }
Esempio n. 7
0
 static function Init($dir)
 {
     if (!WaxConf::$init) {
         set_exception_handler("wax_exception_handler");
         // register block directories
         WaxConf::BlocksAt($dir . "/blocks");
         WaxConf::BlocksAt(dirname(__FILE__) . "/../../blocks");
         // require Wax core
         $dir = dirname(__FILE__) . "/..";
         if (is_dir($dir)) {
             require_dir("{$dir}");
         }
         // perform block auto-loading operations
         BlockManager::Init();
         // ready to go
         WaxConf::$init = true;
     }
 }
Esempio n. 8
0
 static function Render(rRenderableAttribute $self, $action, array $xtra_args)
 {
     // model getters are dynamic.
     // an attributenotfoundexception is thrown if one of these isn't found
     $type = $self->GetType();
     $args = array("id" => $self->GetID(), "name" => $self->GetName(), "type" => $self->GetType(), "default" => $self->GetDefault(), "label" => $self->GetLabel(), "value" => $self->GetValue(), "options" => $self->GetOptions());
     foreach ($xtra_args as $arg => $value) {
         if (!isset($args[$arg])) {
             $args[$arg] = $value;
         } else {
             trigger_error("Error-- {$arg} already set in args array");
         }
     }
     $block = BlockManager::GetBlockFromContext(__FILE__);
     $view = new View("{$type}/{$action}", $block);
     $vrctx = new ViewRenderCtx();
     // render the attributes views
     return $vrctx->Execute($view, $args);
 }
 /**
  * Block manager for Pages.
  * */
 public function updateCMSFields(FieldList $fields)
 {
     if ($fields->fieldByName('Root.Blocks') || in_array($this->owner->ClassName, $this->blockManager->getExcludeFromPageTypes()) || !$this->owner->exists()) {
         return;
     }
     if (!Permission::check('BLOCK_EDIT')) {
         return;
     }
     $areas = $this->blockManager->getAreasForPageType($this->owner->ClassName);
     if ($areas && count($areas)) {
         $fields->addFieldToTab('Root', new Tab('Blocks', _t('Block.PLURALNAME')));
         if (BlockManager::config()->get('block_area_preview')) {
             $fields->addFieldToTab('Root.Blocks', LiteralField::create('PreviewLink', $this->areasPreviewButton()));
         }
         // Blocks related directly to this Page
         $gridConfig = GridFieldConfig_BlockManager::create(true, true, true, true)->addExisting($this->owner->class)->addComponent(new GridFieldOrderableRows());
         // TODO it seems this sort is not being applied...
         $gridSource = $this->owner->Blocks();
         // ->sort(array(
         // 	"FIELD(SiteTree_Blocks.BlockArea, '" . implode("','", array_keys($areas)) . "')" => '',
         // 	'SiteTree_Blocks.Sort' => 'ASC',
         // 	'Name' => 'ASC'
         // ));
         $fields->addFieldToTab('Root.Blocks', GridField::create('Blocks', _t('Block.PLURALNAME', 'Blocks'), $gridSource, $gridConfig));
         // Blocks inherited from BlockSets
         if ($this->blockManager->getUseBlockSets()) {
             $inheritedBlocks = $this->getBlocksFromAppliedBlockSets(null, true);
             if ($inheritedBlocks->count()) {
                 $activeInherited = $this->getBlocksFromAppliedBlockSets(null, false);
                 if ($activeInherited->count()) {
                     $fields->addFieldsToTab('Root.Blocks', array(GridField::create('InheritedBlockList', _t('BlocksSiteTreeExtension.BlocksInheritedFromBlockSets', 'Blocks Inherited from Block Sets'), $activeInherited, GridFieldConfig_BlockManager::create(false, false, false)), LiteralField::create('InheritedBlockListTip', "<p class='message'>" . _t('BlocksSiteTreeExtension.InheritedBlocksEditLink', 'Tip: Inherited blocks can be edited in the {link_start}Block Admin area{link_end}', '', array('link_start' => '<a href="admin/block-admin">', 'link_end' => '</a>')) . '<p>')));
                 }
                 $fields->addFieldToTab('Root.Blocks', ListBoxField::create('DisabledBlocks', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), $inheritedBlocks->map('ID', 'Title'), null, null, true)->setDescription(_t('BlocksSiteTreeExtension.DisableInheritedBlocksDescription', 'Select any inherited blocks that you would not like displayed on this page.')));
             } else {
                 $fields->addFieldToTab('Root.Blocks', ReadonlyField::create('DisabledBlocksReadOnly', _t('BlocksSiteTreeExtension.DisableInheritedBlocks', 'Disable Inherited Blocks'), _t('BlocksSiteTreeExtension.NoInheritedBlocksToDisable', 'This page has no inherited blocks to disable.')));
             }
             $fields->addFieldToTab('Root.Blocks', CheckboxField::create('InheritBlockSets', _t('BlocksSiteTreeExtension.InheritBlocksFromBlockSets', 'Inherit Blocks from Block Sets')));
         }
     } else {
         $fields->addFieldToTab('Root.Blocks', LiteralField::create('Blocks', _t('BlocksSiteTreeExtension.NoBlockAreasConfigured', 'This page type has no Block Areas configured.')));
     }
 }
Esempio n. 10
0
 static function modify(rDynamicModelHandler $self)
 {
     $ddm = DSM::Get();
     $view = array();
     $dmodel = $ddm->ExamineType($self->GetType(), true);
     foreach ($dmodel as $name => $details) {
         if (is_array($details['options'])) {
             $dmodel[$name]['options'] = $details['options'];
         }
     }
     $view['model'] = $dmodel;
     // scan attributes dirs
     $attr_types = array();
     $attr_block = BlockManager::GetBlock("attributes");
     foreach (scandir($attr_block->GetBaseDir() . "/views/") as $attr_type) {
         if ($attr_type[0] == '.' || $attr_type[0] == '_') {
             continue;
         }
         $attr_types[] = $attr_type;
     }
     $view['attr_types'] = $attr_types;
     return $view;
 }
Esempio n. 11
0
 function Execute(rRenderable $layout, $contents)
 {
     $dhtml = BlockManager::GetDHTMLResources();
     $args = array("content_for_layout" => $contents, "css" => $dhtml['css'], 'js' => $dhtml['js']);
     return $layout->Render($args);
 }
Esempio n. 12
0
 private function loadResources($dir, $include_files = false)
 {
     $dhtml = array("js", "css", "images");
     // creates web-relative path refs
     $php = array("blocks", "include", "roles", "views", "lib", "contexts");
     // creates fs-absolute path refs
     // resource loading loop--
     // determines all javascript, css, and image resources
     // in the current block.
     foreach ($dhtml as $resourcedir) {
         if (is_dir("{$dir}/{$resourcedir}")) {
             foreach (scandir("{$dir}/{$resourcedir}") as $file) {
                 if ($file[0] == '.' || $file[0] == '_') {
                     continue;
                 } else {
                     $path = str_replace($_SERVER['DOCUMENT_ROOT'], '', $this->_blockdir . "/{$resourcedir}/{$file}");
                     $fileparts = explode(".", $file);
                     $title = array_shift($fileparts);
                     $this->_resources[$resourcedir][$title] = $path;
                 }
             }
         }
     }
     // library loading loop--
     // determines all libraries, objects, roles, contexts, etc.
     // that need to be require()'d for this block to work like
     // it should.
     foreach ($php as $resourcedir) {
         if (is_dir("{$dir}/{$resourcedir}")) {
             switch ($resourcedir) {
                 // these are all treated the same --
                 // the only thing that matters is the order,
                 // which is specified in the $php array.
                 case "lib":
                 case "contexts":
                 case "include":
                     require_dir("{$dir}/{$resourcedir}");
                     break;
                 case "views":
                     $this->analyzeViewDir("{$dir}/{$resourcedir}");
                     break;
                     // the idea behind the blocks and roles directories
                     // is pretty much the same
                 // the idea behind the blocks and roles directories
                 // is pretty much the same
                 case "blocks":
                 case "roles":
                     foreach (scandir("{$dir}/{$resourcedir}") as $obj) {
                         if ($obj[0] == '.' || $obj[0] == '_') {
                             continue;
                         }
                         $objname = explode(".", $obj);
                         $key = array_shift($objname);
                         $objval = "{$dir}/{$resourcedir}/{$obj}";
                         if ($resourcedir == "roles") {
                             require_once "{$dir}/{$resourcedir}/{$obj}";
                         } else {
                             $objval = BlockManager::LoadBlockAt("{$dir}/{$resourcedir}/{$obj}");
                         }
                         $this->_resources[$resourcedir][$key] = $objval;
                     }
                     break;
             }
         }
     }
 }
Esempio n. 13
0
 function Execute($layout_override = NULL, $target_override = NULL, $action_override = NULL, $view_override = NULL, $block_override = NULL)
 {
     // try the application block first
     $block = BlockManager::LoadBlockAt(getcwd());
     $appblock = $block;
     if (!is_null($block_override) && $block_override instanceof WaxBlock) {
         // designate a different block as the holder of the necessary files
         $block = $block_override;
     }
     $router = new QueryString();
     $route = $router->Analyze($_SERVER['QUERY_STRING']);
     $context_name = 'Default';
     if (!is_null($target_override)) {
         $context_name = $target_override;
     } else {
         if (isset($route['context']) && !empty($route['context'])) {
             $context_name = $route['context'];
             unset($route['context']);
         }
     }
     $action = 'index';
     if (!is_null($action_override)) {
         $action = $action_override;
     } else {
         if (isset($route['action']) && !empty($route['action'])) {
             $action = $route['action'];
             unset($route['action']);
         }
     }
     $context = $context_name . "Ctx";
     // verify that the controllercontext is in the same block as the views
     if (!file_exists($block->GetBaseDir() . "/contexts/" . $context . ".php")) {
         throw new TargetContextNotFoundException($context);
     } else {
         if (class_exists($context)) {
             $ctrl = new $context();
             if (!$ctrl instanceof ControllerCtx) {
                 throw new InvalidContextException($context);
             }
         } else {
             throw new TargetContextNotFoundException($context);
         }
     }
     $data_for_view = $ctrl->Execute($action, $route);
     $view_ctx = new ViewRenderCtx();
     $viewname = "{$context_name}/{$action}";
     if (!is_null($view_override)) {
         $viewname = $view_override;
     }
     $content_for_layout = $view_ctx->Execute(new View($block, $viewname), $data_for_view);
     $layoutctx = new LayoutRenderCtx();
     $layout = "layout";
     if (!is_null($layout_override)) {
         $layout = $layout_override;
     }
     try {
         return $layoutctx->Execute(new View($block, $layout), $content_for_layout);
     } catch (ViewNotFoundException $vnfe) {
         return $layoutctx->Execute(new View($appblock, $layout), $content_for_layout);
     }
 }
Esempio n. 14
0
/**
 * Setups each block the main menubar.
 */
function initialize_menu()
{
    global $page, $conf, $user, $template, $filter;
    $menu = new BlockManager("menubar");
    $menu->load_registered_blocks();
    $menu->prepare_display();
    if (@$page['section'] == 'search' and isset($page['qsearch_details'])) {
        $template->assign('QUERY_SEARCH', htmlspecialchars($page['qsearch_details']['q']));
    }
    //--------------------------------------------------------------- external links
    if ($block = $menu->get_block('mbLinks') and !empty($conf['links'])) {
        $block->data = array();
        foreach ($conf['links'] as $url => $url_data) {
            if (!is_array($url_data)) {
                $url_data = array('label' => $url_data);
            }
            if (!isset($url_data['eval_visible']) or eval($url_data['eval_visible'])) {
                $tpl_var = array('URL' => $url, 'LABEL' => $url_data['label']);
                if (!isset($url_data['new_window']) or $url_data['new_window']) {
                    $tpl_var['new_window'] = array('NAME' => isset($url_data['nw_name']) ? $url_data['nw_name'] : '', 'FEATURES' => isset($url_data['nw_features']) ? $url_data['nw_features'] : '');
                }
                $block->data[] = $tpl_var;
            }
        }
        if (!empty($block->data)) {
            $block->template = 'menubar_links.tpl';
        }
    }
    //-------------------------------------------------------------- categories
    $block = $menu->get_block('mbCategories');
    //------------------------------------------------------------------------ filter
    if ($conf['menubar_filter_icon'] and !empty($conf['filter_pages']) and get_filter_page_value('used')) {
        if ($filter['enabled']) {
            $template->assign('U_STOP_FILTER', add_url_params(make_index_url(array()), array('filter' => 'stop')));
        } else {
            $template->assign('U_START_FILTER', add_url_params(make_index_url(array()), array('filter' => 'start-recent-' . $user['recent_period'])));
        }
    }
    if ($block != null) {
        $block->data = array('NB_PICTURE' => $user['nb_total_images'], 'MENU_CATEGORIES' => get_categories_menu(), 'U_CATEGORIES' => make_index_url(array('section' => 'categories')));
        $block->template = 'menubar_categories.tpl';
    }
    //------------------------------------------------------------------------ tags
    $block = $menu->get_block('mbTags');
    if ($block != null and !empty($page['items']) and 'picture' != script_basename()) {
        if ('tags' == @$page['section']) {
            $tags = get_common_tags($page['items'], $conf['menubar_tag_cloud_items_number'], $page['tag_ids']);
            $tags = add_level_to_tags($tags);
            foreach ($tags as $tag) {
                $block->data[] = array_merge($tag, array('U_ADD' => make_index_url(array('tags' => array_merge($page['tags'], array($tag)))), 'URL' => make_index_url(array('tags' => array($tag)))));
            }
        } else {
            $selection = array_slice($page['items'], $page['start'], $page['nb_image_page']);
            $tags = add_level_to_tags(get_common_tags($selection, $conf['content_tag_cloud_items_number']));
            foreach ($tags as $tag) {
                $block->data[] = array_merge($tag, array('URL' => make_index_url(array('tags' => array($tag)))));
            }
        }
        if (!empty($block->data)) {
            $block->template = 'menubar_tags.tpl';
        }
    }
    //----------------------------------------------------------- special categories
    if (($block = $menu->get_block('mbSpecials')) != null) {
        if (!is_a_guest()) {
            // favorites
            $block->data['favorites'] = array('URL' => make_index_url(array('section' => 'favorites')), 'TITLE' => l10n('display your favorites photos'), 'NAME' => l10n('Your favorites'));
        }
        $block->data['most_visited'] = array('URL' => make_index_url(array('section' => 'most_visited')), 'TITLE' => l10n('display most visited photos'), 'NAME' => l10n('Most visited'));
        if ($conf['rate']) {
            $block->data['best_rated'] = array('URL' => make_index_url(array('section' => 'best_rated')), 'TITLE' => l10n('display best rated photos'), 'NAME' => l10n('Best rated'));
        }
        $block->data['recent_pics'] = array('URL' => make_index_url(array('section' => 'recent_pics')), 'TITLE' => l10n('display most recent photos'), 'NAME' => l10n('Recent photos'));
        $block->data['recent_cats'] = array('URL' => make_index_url(array('section' => 'recent_cats')), 'TITLE' => l10n('display recently updated albums'), 'NAME' => l10n('Recent albums'));
        $block->data['random'] = array('URL' => get_root_url() . 'random.php', 'TITLE' => l10n('display a set of random photos'), 'NAME' => l10n('Random photos'), 'REL' => 'rel="nofollow"');
        $block->data['calendar'] = array('URL' => make_index_url(array('chronology_field' => $conf['calendar_datefield'] == 'date_available' ? 'posted' : 'created', 'chronology_style' => 'monthly', 'chronology_view' => 'calendar')), 'TITLE' => l10n('display each day with photos, month per month'), 'NAME' => l10n('Calendar'), 'REL' => 'rel="nofollow"');
        $block->template = 'menubar_specials.tpl';
    }
    //---------------------------------------------------------------------- summary
    if (($block = $menu->get_block('mbMenu')) != null) {
        // quick search block will be displayed only if data['qsearch'] is set
        // to "yes"
        $block->data['qsearch'] = true;
        // tags link
        $block->data['tags'] = array('TITLE' => l10n('display available tags'), 'NAME' => l10n('Tags'), 'URL' => get_root_url() . 'tags.php', 'COUNTER' => get_nb_available_tags());
        // search link
        $block->data['search'] = array('TITLE' => l10n('search'), 'NAME' => l10n('Search'), 'URL' => get_root_url() . 'search.php', 'REL' => 'rel="search"');
        if ($conf['activate_comments']) {
            // comments link
            $block->data['comments'] = array('TITLE' => l10n('display last user comments'), 'NAME' => l10n('Comments'), 'URL' => get_root_url() . 'comments.php', 'COUNTER' => get_nb_available_comments());
        }
        // about link
        $block->data['about'] = array('TITLE' => l10n('About Piwigo'), 'NAME' => l10n('About'), 'URL' => get_root_url() . 'about.php');
        // notification
        $block->data['rss'] = array('TITLE' => l10n('RSS feed'), 'NAME' => l10n('Notification'), 'URL' => get_root_url() . 'notification.php', 'REL' => 'rel="nofollow"');
        $block->template = 'menubar_menu.tpl';
    }
    //--------------------------------------------------------------- identification
    if (is_a_guest()) {
        $template->assign(array('U_LOGIN' => get_root_url() . 'identification.php', 'U_LOST_PASSWORD' => get_root_url() . 'password.php', 'AUTHORIZE_REMEMBERING' => $conf['authorize_remembering']));
        if ($conf['allow_user_registration']) {
            $template->assign('U_REGISTER', get_root_url() . 'register.php');
        }
    } else {
        $template->assign('USERNAME', stripslashes($user['username']));
        if (is_autorize_status(ACCESS_CLASSIC)) {
            $template->assign('U_PROFILE', get_root_url() . 'profile.php');
        }
        // the logout link has no meaning with Apache authentication : it is not
        // possible to logout with this kind of authentication.
        if (!$conf['apache_authentication']) {
            $template->assign('U_LOGOUT', get_root_url() . '?act=logout');
        }
        if (is_admin()) {
            $template->assign('U_ADMIN', get_root_url() . 'admin.php');
        }
    }
    if (($block = $menu->get_block('mbIdentification')) != null) {
        $block->template = 'menubar_identification.tpl';
    }
    $menu->apply('MENUBAR', 'menubar.tpl');
}
Esempio n. 15
0
function abs_fn_cmp($a, $b)
{
    return abs($a) - abs($b);
}
function make_consecutive(&$orders, $step = 50)
{
    uasort($orders, 'abs_fn_cmp');
    $crt = 1;
    foreach ($orders as $id => $pos) {
        $orders[$id] = $step * ($pos < 0 ? -$crt : $crt);
        $crt++;
    }
}
global $template;
include_once PHPWG_ROOT_PATH . 'include/block.class.php';
$menu = new BlockManager('menubar');
$menu->load_registered_blocks();
$reg_blocks = $menu->get_registered_blocks();
$mb_conf = @$conf['blk_' . $menu->get_id()];
if (is_string($mb_conf)) {
    $mb_conf = unserialize($mb_conf);
}
if (!is_array($mb_conf)) {
    $mb_conf = array();
}
foreach ($mb_conf as $id => $pos) {
    if (!isset($reg_blocks[$id])) {
        unset($mb_conf[$id]);
    }
}
if (isset($_POST['reset'])) {