PocketsPlugin::pocketString PHP Method

pocketString() public static method

public static pocketString ( $Name, null $Data = null ) : mixed | string
$Name
$Data null
return mixed | string
    public static function pocketString($Name, $Data = null)
    {
        $Inst = Gdn::pluginManager()->getPluginInstance('PocketsPlugin', Gdn_PluginManager::ACCESS_CLASSNAME);
        $Pockets = $Inst->getPockets($Name);
        if (val('random', $Data)) {
            $Pockets = array(array_rand($Pockets));
        }
        $Result = '';
        $ControllerName = Gdn::controller()->ControllerName;
        foreach ($Pockets as $Pocket) {
            if (val('Location', $Pocket) == 'Custom') {
                $Data['PageName'] = Pocket::pageName($ControllerName);
                if ($Pocket->canRender($Data)) {
                    $Result .= $Pocket->toString();
                }
            } else {
                $Result .= $Pocket->toString();
            }
        }
        if (is_array($Data)) {
            $Data = array_change_key_case($Data);
            self::pocketStringCb($Data, true);
            $Result = preg_replace_callback('`{{(\\w+)}}`', array('PocketsPlugin', 'PocketStringCb'), $Result);
        }
        return $Result;
    }

Usage Example

コード例 #1
0
/**
 * Writes a pocket to the page
 *
 * @param array $Params The parameters passed into the function.
 * The parameters that can be passed to this function are as follows.
 * - <b>name</b>: The name of the pocket.
 * @param Smarty $Smarty The smarty object rendering the template.
 * @return string The pocket string.
 */
function smarty_function_pocket($Params, $Smarty)
{
    if (!class_exists('PocketsPlugin')) {
        return '';
    }
    $Name = val('name', $Params);
    unset($Params['name']);
    $Result = PocketsPlugin::pocketString($Name, $Params);
    return $Result;
}