Example #1
0
/**
 * Obtain the value of one block variable or all block variables for a specified block.
 *
 * Note: If the name of the block variable is not set, then the assign parameter
 * must be set since an array of block variables will be returned.
 *
 * Available attributes:
 *   - bid      (numeric)   The block id
 *   - name     (string)    The name of the block variable to get, otherwise the
 *                          entire block array is assigned is returned.
 *                          (required, if the assign attribute is not specified,
 *                          otherwise, optional)
 *   - assign   (string)    The name of the template variable to which the value
 *                          is assigned, instead of being output to the template.
 *                          (optional if the name attribute is set, otherwise
 *                          required)
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the {@link Zikula_View} object.
 *
 * @return mixed the value of the block variable specified by the name attribute,
 *               or an array containing the full block information.
 */
function smarty_function_blockgetinfo($params, Zikula_View $view)
{
    $bid = isset($params['bid']) ? (int) $params['bid'] : 0;
    $name = isset($params['name']) ? $params['name'] : null;
    $assign = isset($params['assign']) ? $params['assign'] : null;
    if (!$bid) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockgetinfo', 'bid')));
    }
    // get the block info array
    $blockinfo = BlockUtil::getBlockInfo($bid);
    if ($name) {
        if ($assign) {
            $view->assign($assign, $blockinfo[$name]);
        } else {
            return $blockinfo[$name];
        }
    } else {
        // handle the full blockinfo array
        if ($assign) {
            $view->assign($assign, $blockinfo);
        } else {
            $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified to get the full block information.', array('pnblockgetinfo', 'assign')));
        }
    }
    return;
}
Example #2
0
    /**
     * Toggleblock.
     *
     * This function toggles active/inactive.
     *
     * @param bid int  id of block to toggle.
     *
     * @return mixed true or Ajax error
     */
    public function toggleblock()
    {
        $this->checkAjaxToken();
        $this->throwForbiddenUnless(SecurityUtil::checkPermission('Blocks::', '::', ACCESS_ADMIN));

        $bid = $this->request->request->get('bid', -1);

        if ($bid == -1) {
            throw new Zikula_Exception_Fatal($this->__('No block ID passed.'));
        }

        // read the block information
        $blockinfo = BlockUtil::getBlockInfo($bid);
        if ($blockinfo == false) {
            throw new Zikula_Exception_Fatal($this->__f('Error! Could not retrieve block information for block ID %s.', DataUtil::formatForDisplay($bid)));
        }

        if ($blockinfo['active'] == 1) {
            ModUtil::apiFunc('Blocks', 'admin', 'deactivate', array('bid' => $bid));
        } else {
            ModUtil::apiFunc('Blocks', 'admin', 'activate', array('bid' => $bid));
        }

        return new Zikula_Response_Ajax(array('bid' => $bid));
    }
Example #3
0
/**
 * Renders and displays a single Zikula block by blockinfo array or block id.
 *
 * Available attributes:
 *  - module    (string)    The internal name of the module that defines the block.
 *  - blockname (string)    The internal name of the block.
 *  - block     (int|array) Either the integer block id (bid) of the block, or
 *                          an array containing the blockinfo for the block.
 *  - position  (string)    The position of the block.
 *  - assign    (string)    If set, the results are assigned to the corresponding
 *                          template variable instead of being returned to the template (optional)
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the {@link Zikula_View} object.
 *
 * @return string The rendered output of the specified block.
 */
function smarty_function_blockshow($params, Zikula_View $view)
{
    $module = isset($params['module']) ? $params['module'] : null;
    $blockname = isset($params['blockname']) ? $params['blockname'] : null;
    $block = isset($params['block']) ? $params['block'] : null;
    $position = isset($params['position']) ? $params['position'] : null;
    $assign = isset($params['assign']) ? $params['assign'] : null;
    if (!$module) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockshow', 'module')));
        return;
    }
    if (!$blockname) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockshow', 'blockname')));
        return;
    }
    if (!$block) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockshow', 'id/info')));
        return;
    }
    if (!$position) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('blockshow', 'position')));
        return;
    }
    if (!is_array($block)) {
        $block = BlockUtil::getBlockInfo($block);
    }
    $block['position'] = $position;
    $output = BlockUtil::show($module, $blockname, $block);
    if ($assign) {
        $view->assign($assign, $output);
    } else {
        return $output;
    }
}
Example #4
0
 public function showBlock($block, $blockname, $module)
 {
     if (!is_array($block)) {
         $block = \BlockUtil::getBlockInfo($block);
     }
     return \BlockUtil::show($module, $blockname, $block);
 }
Example #5
0
 function displayEditing()
 {
     $id = $this->blockid;
     $blockinfo = BlockUtil::getBlockInfo($id);
     $output = $blockinfo['title'] . ' (ID=' . $this->blockid . ')';
     return $output;
 }
Example #6
0
 function display()
 {
     $id = $this->blockid;
     $blockinfo = BlockUtil::getBlockInfo($id);
     $modinfo = ModUtil::getInfo($blockinfo['mid']);
     $text = BlockUtil::show($modinfo['name'], $blockinfo['bkey'], $blockinfo);
     $this->view->assign('content', $text);
     return $this->view->fetch($this->getTemplate());
 }
Example #7
0
/**
 * Display an existing Zikula block.
 *
 *  The block is choosen by its id.
 *  The block state is ignored, so even deactivated blocks can be shown.
 *  The parameters specific to the block can be overridden.
 *
 * Available parameters:
 *  - id        (numeric)   ID of the block to be displayed
 *  - name      (string)    Name of the block to be displayed (not used)
 *  - title     (string)    Overrides the block title
 *  - position  (string)    Overrides the block position
 *  - assign    (string)    The name of a template variable to which the output
 *                          of the block is assigned, instead of sending the
 *                          output to the template (optional)
 * - Any additional parameters are passed to the block as block variables,
 *   overriding any existing values.
 *
 * Examples:
 *
 * Insert the block with block ID (bid) 4 at the current position in the template
 *
 * <samp>{block id=4}</samp>
 *
 * Insert the block with block ID (bid) 5 at the current position in the
 * template, overriding the block's title.
 *
 * <samp>{block id=5 title='My Block 5'}</samp>
 *
 * Store the output generated by retrieving the block with ID 6 in the template
 * variable $myBlockContents.
 *
 * <samp>{block id=6 assign='myBlockContents'}</samp>
 *
 * @param array       $params All attributes passed to this function from the template.
 * @param Zikula_View $view   Reference to the {@link Zikula_View} object.
 *
 * @return string The block.
 *
 * @todo the attribute 'name' is not used.
 *
 */
function smarty_function_block($params, Zikula_View $view)
{
    $bid = isset($params['bid']) ? (int) $params['bid'] : 0;
    $name = isset($params['name']) ? $params['name'] : null;
    $title = isset($params['title']) ? $params['title'] : null;
    $position = isset($params['position']) ? $params['position'] : null;
    $assign = isset($params['assign']) ? $params['assign'] : null;
    // unset the variables for the function, leaving the ones for the block
    unset($params['bid']);
    unset($params['name']);
    unset($params['title']);
    unset($params['position']);
    unset($params['assign']);
    if (!$bid) {
        $view->trigger_error(__f('Error! in %1$s: the %2$s parameter must be specified.', array('pnblock', 'bid')));
        return false;
    }
    //  render the block
    $blockinfo = BlockUtil::getBlockInfo($bid);
    // overwrite block title
    if ($title) {
        $blockinfo['title'] = $title;
    }
    if ($position) {
        $blockinfo['position'] = $position;
    }
    $blockinfo['bid'] = $bid;
    // bid is not return by BlockGetInfo.
    // Overwrite block specific config vars.
    // Only the new style is supported.
    if (count($params) > 0) {
        $_vars = BlockUtil::varsFromContent($blockinfo['content']);
        $_vars = array_merge($_vars, $params);
        $blockinfo['content'] = BlockUtil::varsToContent($_vars);
    }
    // We need the module name.
    $modinfo = ModUtil::getInfo($blockinfo['mid']);
    if (!is_array($modinfo) || !isset($modinfo['name'])) {
        $modinfo = array('name' => 'core');
    }
    // show the block and capture its contents
    $content = BlockUtil::show($modinfo['name'], $blockinfo['bkey'], $blockinfo);
    if ($assign) {
        $view->assign($assign, $content);
    } else {
        return $content;
    }
}
Example #8
0
 public function deleteBlock($bid)
 {
     // Ensure that $bid is 1 or higher.
     if (!is_numeric($bid) || $bid < 1) {
         $this->setError(__('Block ID Invalid'));
         return false;
     }
     // Ensure block exists.
     if (!BlockUtil::getBlockInfo($bid)) {
         $this->setError(__('No Such Block Exists'));
         return false;
     }
     // Delete block placements for this block.
     if (!DBUtil::deleteObjectByID('block_placements', $bid, 'bid')) {
         $this->setError(__('Block Placements Not Removed'));
         return false;
     }
     // Delete the block itself.
     if (!DBUtil::deleteObjectByID('blocks', $bid, 'bid')) {
         $this->setError(__('Block Not Deleted'));
         return false;
     }
     // Let other modules know we have deleted an item.
     ModUtil::callHooks('item', 'delete', $bid, array('module' => 'Blocks'));
     // Success.
     return true;
 }
Example #9
0
 /**
  * Set a block's active state.
  *
  * @param int $args ['bid'] the ID of the block to deactivate.
  *
  * @return bool true on success, false on failure.
  */
 public function setActiveState($block)
 {
     if (!isset($block['bid']) || !is_numeric($block['bid'])) {
         return LogUtil::registerArgsError();
     }
     if (!isset($block['active']) || !is_numeric($block['active'])) {
         return LogUtil::registerArgsError();
     }
     $blockinfo = BlockUtil::getBlockInfo($block['bid']);
     if (!SecurityUtil::checkPermission('Blocks::', "{$blockinfo['bkey']}:{$blockinfo['title']}:{$block['bid']}", ACCESS_EDIT)) {
         return LogUtil::registerPermissionError();
     }
     // create a new object to ensure that we only update the 'active' field
     $obj = array();
     $obj['bid'] = $block['bid'];
     $obj['active'] = $block['active'];
     $res = DBUtil::updateObject($obj, 'blocks', '', 'bid');
     return $res;
 }
Example #10
0
    /**
     * Convert data of selected menu to menutree style
     * Used to import menus
     */
    private function _import_menu($bid)
    {
        if ((!isset($bid)) || (isset($bid) && !is_numeric($bid))) {
            return;
        }

        $menu = BlockUtil::getBlockInfo($bid);
        $menuVars = BlockUtil::varsFromContent($menu['content']);

        $userlanguage = ZLanguage::getLanguageCode();

        $menuType = strtolower($menu['bkey']);
        switch ($menuType) {
            case 'menutree':
                $data = isset($menuVars['menutree_content']) ? $menuVars['menutree_content'] : array();
                break;

            case 'menu':
                if (isset($menuVars['content']) && !empty($menuVars['content'])) {
                    $reflang = $userlanguage;
                    $pid = 1;
                    $data = array();
                    $contentlines = explode('LINESPLIT', $menuVars['content']);
                    foreach ($contentlines as $lineno => $contentline) {
                        list($href, $name, $title) = explode('|', $contentline);
                        if (!empty($name)) {
                            $className = '';
                            $parent = 0;
                            $state = 1;
                            $lang = $reflang;
                            $id = $pid;
                            $data[$lineno][$reflang] = compact('href','name','title','className','parent','state','lang','lineno','id');
                            $pid++;
                        }
                    }
                    $langs = (array)$reflang;
                    $lineno++;
                }
                break;

            case 'extmenu':
                if (isset($menuVars['links']) && !empty($menuVars['links'])) {
                    $langs = array_keys($menuVars['links']);
                    $data = array();
                    foreach ($langs as $lang) {
                        foreach ($menuVars['links'][$lang] as $id => $link) {
                            $data[$id][$lang] = array(
                                    'id'        => $id + 1,
                                    'name'      => isset($link['name']) && !empty($link['name']) ? $link['name'] : $this->__('no name'),
                                    'href'      => isset($link['url']) ? $link['url'] : '',
                                    'title'     => isset($link['title']) ? $link['title'] : '',
                                    'className' => '',
                                    'state'     => isset($link['active']) && $link['active'] && $link['name'] ? 1 : 0,
                                    'lang'      => $lang,
                                    'lineno'    => $id,
                                    'parent'    => 0
                            );
                        }
                    }
                    ksort($data);
                    $pid = $id + 2;
                    $lineno = count($data);
                }
                break;
        }

        if (!empty($menuVars['displaymodules'])) {
            $mods = ModUtil::getUserMods();

            if (is_array($mods) && count($mods)>0) {
                foreach ($mods as $mod) {
                    $tmp = array('name'  => $mod['displayname'],
                                 'href'  => DataUtil::formatForDisplay(ModUtil::url($mod['name'], 'user', 'main')),
                                 'title' => $mod['description']);

                    foreach ($langs as $lang) {
                        $tmp = array_merge($tmp, array('className' => '',
                                                       'parent' => 0,
                                                       'lang' => $lang,
                                                       'state' => 1,
                                                       'lineno' => $lineno,
                                                       'id' => $pid));
                        $tmparray[$lang] = $tmp;
                    }

                    $data[] = $tmparray;
                    $pid++;
                    $lineno++;
                }
            }
        }

        return $data;
    }
Example #11
0
 /**
  * Display a form to create a new block position.
  *
  * @return string HTML output string.
  */
 public function modifyposition()
 {
     // get our input
     $pid = FormUtil::getPassedValue('pid');
     // get the block position
     $position = ModUtil::apiFunc('Blocks', 'user', 'getposition', array('pid' => $pid));
     // Security check
     if (!SecurityUtil::checkPermission("Blocks::{$position['name']}", '::', ACCESS_ADMIN)) {
         return LogUtil::registerPermissionError();
     }
     // assign the item
     $this->view->assign($position);
     // get all blocks in the position
     $block_placements = ModUtil::apiFunc('blocks', 'user', 'getblocksinposition', array('pid' => $pid));
     // get all defined blocks
     $allblocks = ModUtil::apiFunc('Blocks', 'user', 'getall', array('active_status' => 0));
     foreach ($allblocks as $key => $allblock) {
         // set the module that holds the block
         $modinfo = ModUtil::getInfo($allblock['mid']);
         $allblocks[$key]['modname'] = $modinfo['name'];
     }
     // loop over arrays forming a list of blocks not in the block positon and obtaining
     // full details on those that are
     $blocks = array();
     foreach ($block_placements as $blockplacement) {
         $block = BlockUtil::getBlockInfo($blockplacement['bid']);
         $block['order'] = $blockplacement['order'];
         foreach ($allblocks as $key => $allblock) {
             if ($allblock['bid'] == $blockplacement['bid']) {
                 unset($allblocks[$key]);
                 $block['modname'] = $allblock['modname'];
             }
         }
         $blocks[] = $block;
     }
     $this->view->assign('assignedblocks', $blocks)->assign('unassignedblocks', $allblocks);
     // Return the output that has been generated by this function
     return $this->view->fetch('blocks_admin_modifyposition.tpl');
 }
Example #12
0
 /**
  * Get the html output from the block's `modify` method.
  *
  * @deprecated This method is not required in Core-2.0. Simply use
  *   `$output = $blockClassInstance->modify($request, $blockEntity->getContent());`
  * @param $blockClassInstance
  * @param BlockEntity $blockEntity
  * @param Request $request
  * @return mixed|string
  */
 private function getBlockModifyOutput($blockClassInstance, BlockEntity $blockEntity, Request $request)
 {
     $output = '';
     if ($blockClassInstance instanceof BlockControllerInterface) {
         $output = $blockClassInstance->modify($request, $blockEntity->getContent());
     } elseif ($blockClassInstance instanceof \Zikula_Controller_AbstractBlock) {
         // @todo remove this BC at Core-2.0
         $blockInfo = \BlockUtil::getBlockInfo($blockEntity->getBid());
         $blockInfo = $blockInfo ? $blockInfo : ['content' => ''];
         $output = call_user_func([$blockClassInstance, 'modify'], $blockInfo);
     }
     return $output;
 }
Example #13
0
/**
 * get block information
 *
 * @deprecated
 * @see BlockUtil::getBlockInfo()
 *
 * @param value the value to search for
 * @param assocKey the field in which we look for the value (optional) (default='bid')
 * @return array array of block information
 */
function pnBlockGetInfo($value, $assocKey = 'bid')
{
    LogUtil::log(__f('Warning! Function %1$s is deprecated. Please use %2$s instead.', array(__FUNCTION__, 'BlockUtil::getBlockInfo()')), E_USER_DEPRECATED);
    return BlockUtil::getBlockInfo($value, $assocKey);
}
Example #14
0
 /**
  * get a specific block
  *
  * @param    $args['bid']  id of block to get
  * @return   array         item array, or false on failure
  */
 public function get($args)
 {
     // Argument check
     if (!isset($args['bid']) || !is_numeric($args['bid'])) {
         return LogUtil::registerArgsError();
     }
     // Return the item array
     return BlockUtil::getBlockInfo($args['bid']);
 }
Example #15
0
 /**
  * Display one block.
  *
  * @param BlockEntity $block
  * @param string $positionName @deprecated argument. remove at Core-2.0
  * @return string
  */
 public function showBlock(BlockEntity $block, $positionName = '')
 {
     $blockInstance = $this->blockApi->createInstanceFromBKey($block->getBkey());
     $legacy = false;
     $content = '';
     if ($blockInstance instanceof BlockControllerInterface) {
         $content = $blockInstance->display($block->getContent());
     } elseif ($blockInstance instanceof \Zikula_Controller_AbstractBlock) {
         // @todo remove at Core-2.0
         $legacy = true;
         $args = \BlockUtil::getBlockInfo($block->getBid());
         $args['position'] = $positionName;
         $content = $blockInstance->display($args);
     }
     if (!$legacy) {
         if (null !== ($moduleInstance = $this->extensionApi->getModuleInstanceOrNull($block->getModule()->getName()))) {
             // @todo can remove check for null at Core-2.0
             // add module stylesheet to page - legacy blocks load stylesheets automatically on ModUtil::load()
             $moduleInstance->addStylesheet();
         }
     }
     return $this->themeEngine->wrapBlockContentInTheme($content, $block->getTitle(), $block->getBlocktype(), $block->getBid(), $positionName, $legacy);
 }