<?php

// this file can't be used on its own
if (strpos ($_SERVER['PHP_SELF'], 'functions.php') !== false) {
    die ('This file can not be used on its own!');
}

$_CONF['show_right_blocks'] = 1;
$_CONF['r_transform_text'] = 1;  // 記事投稿(テキストモード)時にテキストをp要素化する? (0 = しない, 1 = する)

$_IMAGE_TYPE = 'png';

$result = DB_query ("SELECT onleft,name FROM {$_TABLES['blocks']} WHERE is_enabled = 1");
$nrows = DB_numRows ($result);
for ($i = 0; $i < $nrows; $i++) {
    $A = DB_fetchArray ($result);
        if ($A['onleft'] == 1) {
            $_BLOCK_TEMPLATE[$A['name']] = 'blockheader-sub.thtml,blockfooter-sub.thtml';
        } else {
            $_BLOCK_TEMPLATE[$A['name']] = 'blockheader-sub.thtml,blockfooter-sub.thtml';
    }
}

$_BLOCK_TEMPLATE['_msg_block'] = 'blockheader-message.thtml,blockfooter-message.thtml';
$_BLOCK_TEMPLATE['whats_related_block'] = 'blockheader-related.thtml,blockfooter-related.thtml';
$_BLOCK_TEMPLATE['story_options_block'] = 'blockheader-related.thtml,blockfooter-related.thtml';



function Admin_startBlock( $title='', $helpfile='', $template='blockheader.thtml' )
{
    global $_CONF, $LANG01, $_IMAGE_TYPE;

    // Added by Phize <----
    global $_TABLES, $LANG11;
    // Added by Phize ---->

    // Added by Phize <----
    $value_class_help = 'icon help icon-help';
    // Added by Phize ---->

    $block = new Template( $_CONF['path_layout'] );
    $block->set_file( 'block', $template );
    $block->set_var( 'site_url', $_CONF['site_url'] );
    $block->set_var( 'layout_url', $_CONF['layout_url'] );
    $block->set_var( 'block_title', stripslashes( $title ));

    // Added by Phize <----
    if (strtolower($template) == 'blockheader-sub.thtml') {
        $class = DB_getItem( $_TABLES['blocks'] , 'name', "title = '" . $title . "'" );

        if (!empty($class)) {
            $class = $class . ' utility-' . $class;
            $block->set_var( 'attr_class', ' class="' . $class . '"' );
            $block->set_var( 'value_class', ' ' . $class );
        }
    }

    if (strtolower($template) == 'blockheader-related.thtml') {
        if ($title == $LANG11[1]) {
            $block->set_var( 'attr_class', ' class="related"' );
            $block->set_var( 'value_class', 'related' );
        }

        if ($title == $LANG11[4]) {
            $block->set_var( 'attr_class', ' class="option"' );
            $block->set_var( 'value_class', 'option' );
        }
    }
    // Added by Phize ---->

    if( !empty( $helpfile ))
    {
        // Added by Phize <----
        $img_help = $_CONF['layout_url'] . '/images/button_help.' . $_IMAGE_TYPE;
        $img_size = getimagesize($img_help);
        // Added by Phize ---->

        if( !stristr( $helpfile, 'http://' ))
        {
            // Changed by Phize <----
            $help = '<a class="blocktitle" href="' . $_CONF['site_url'] . '/help/' . $helpfile
                . '"><img src="' . $img_help
                . '" ' . $img_size[3] . ' alt="?" class="' . $value_class_help . '"></a>';
            // Changed by Phize ---->
        }
        else
        {
            // Changed by Phize <----
            $help = '<a class="blocktitle" href="' . $helpfile
                . '"><img src="' . $img_help
                . '" ' . $img_size[3] . ' alt="?" class="' . $value_class_help . '"></a>';
            // Changed by Phize ---->
        }

        $block->set_var( 'block_help', $help );
    }

    // Changed by Phize <----
    // Return resulting HTML
    return $block->finish( $block->parse( 'startHTML', 'block' ) );
    // Changed by Phize ---->
}
?>
