Example #1
0
/**
 * stencil_parse_data 
 * 
 * @param array $pMatches 
 * @access public
 * @return TRUE on success, FALSE on failure - mErrors will contain reason for failure
 */
function stencil_parse_data($pMatches)
{
    static $sStencilObjects = array();
    $output = $pMatches[0];
    if (!empty($pMatches[2])) {
        $output = '';
        $templateName = $pMatches[1];
        if (empty($sStencilObjects[$templateName])) {
            if ($stencilContentId = BitStencil::findByTitle($templateName, NULL, BITSTENCIL_CONTENT_TYPE_GUID)) {
                $sStencilObjects[$templateName] = new BitStencil(NULL, $stencilContentId);
                if ($sStencilObjects[$templateName]->load()) {
                    $output = $sStencilObjects[$templateName]->getField('data');
                }
            }
        } else {
            $output = $sStencilObjects[$templateName]->getField('data');
        }
        if ($lines = explode('|', $pMatches[2])) {
            foreach ($lines as $line) {
                if (strpos($line, '=')) {
                    list($name, $value) = explode('=', trim($line), 2);
                    // if the value is empty, we remove all the conditional stuff surrounding it
                    if (empty($value) && !is_numeric($value)) {
                        $output = preg_replace("!\\{{3}{$name}>.*?<{$name}\\}{3}!s", "", $output);
                    } else {
                        $pattern = array("!\\{{3}{$name}\\}{3}!", "!\\{{3}{$name}>!", "!<{$name}\\}{3}!");
                        $replace = array($value, "", "");
                        $output = preg_replace($pattern, $replace, $output);
                    }
                }
            }
            // any remaining {{{vars}}} will be removed
            $pattern = array("!\\{{3}\\w+?>.*?<\\w+\\}{3}!s", "!\\{{3}\\w+?\\}{3}!");
            $output = preg_replace($pattern, "", $output);
            //Process conditional statements ie. "{{#functionName}}"
            $output = preg_replace_callback("/{{#.*?}}/", 'post_process', $output);
        }
    }
    return $output;
}
Example #2
0
// Copyright (c) 2004 bitweaver Stencil
// All Rights Reserved. See below for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See http://www.gnu.org/copyleft/lesser.html for details.
// Initialization
require_once '../kernel/setup_inc.php';
// Is package installed and enabled
$gBitSystem->verifyPackage('stencil');
// Now check permissions to access this page
$gBitSystem->verifyPermission('p_stencil_read');
// doesn't seem to do much -- laetzer 25.09.2008 03:08
/* 
if( !isset( $_REQUEST['stencil_id'] ) ) {
	$_REQUEST['stencil_id'] = $gBitSystem->getConfig( "home_stencil" );
}

require_once( STENCIL_PKG_PATH.'lookup_stencil_inc.php' );

$gContent->addHit();

// Display the template
$gBitSystem->display( 'bitpackage:stencil/stencil_display.tpl', tra( 'Stencil' ) , array( 'display_mode' => 'display' ));
*/
// pasted from list_stencils.php -- laetzer 25.09.2008 03:09
// create new stencil object
$stencil = new BitStencil();
$stencilsList = $stencil->getList($_REQUEST);
$gBitSmarty->assign_by_ref('stencilsList', $stencilsList);
// getList() has now placed all the pagination information in $_REQUEST['listInfo']
$gBitSmarty->assign_by_ref('listInfo', $_REQUEST['listInfo']);
// Display the template
$gBitSystem->display('bitpackage:stencil/list_stencils.tpl', tra('Stencil'), array('display_mode' => 'list'));
Example #3
0
function stencil_content_edit($pObject = NULL)
{
    global $gBitSystem, $gBitSmarty;
    $stencils = new BitStencil();
    $listHash = array('sort_mode' => 'title_asc', 'get_usage' => TRUE);
    $gBitSmarty->assign('stencilList', $stencils->getList($listHash));
}
<?php

global $gContent;
require_once STENCIL_PKG_PATH . 'BitStencil.php';
require_once LIBERTY_PKG_PATH . 'lookup_content_inc.php';
// if we already have a gContent, we assume someone else created it for us, and has properly loaded everything up.
if (empty($gContent) || !is_object($gContent) || !$gContent->isValid()) {
    if (@BitBase::verifyId($_REQUEST['stencil_id'])) {
        // if stencil_id supplied, use that
        $gContent = new BitStencil($_REQUEST['stencil_id']);
    } elseif (@BitBase::verifyId($_REQUEST['content_id'])) {
        // if content_id supplied, use that
        $gContent = new BitStencil(NULL, $_REQUEST['content_id']);
    } elseif (@BitBase::verifyId($_REQUEST['stencil']['stencil_id'])) {
        $gContent = new BitStencil($_REQUEST['stencil']['stencil_id']);
    } else {
        // otherwise create new object
        $gContent = new BitStencil();
    }
    $gContent->load();
    $gBitSmarty->assign_by_ref("gContent", $gContent);
}