<?php

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

$_IMAGE_TYPE = 'jpeg';

$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['customlogin'] = 'customlogin-header.thtml,customlogin-footer.thtml';
$_BLOCK_TEMPLATE['whats_related_block'] = 'blockheader-related.thtml,blockfooter-related.thtml';
$_BLOCK_TEMPLATE['story_options_block'] = 'blockheader-related.thtml,blockfooter-related.thtml';

function _MOBILE_disabled() {
	if( function_exists( 'CUSTOM_MOBILE_is_cellular' ) && CUSTOM_MOBILE_is_cellular()) {
		return "この機能は携帯からは使用できません。";
	}
}



function mobile_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 . "'" );
        $class = $class . ' utility-' . $class;

        if (!empty($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 ---->
}



function mobile_siteFooter( $rightblock = -1, $custom = '' )
{
     global $_USER, $_CONF, $_TABLES, $LANG01, $_PAGE_TIMER, $topic;


    if( $rightblock < 0 )
    {
        if( isset( $_CONF['show_right_blocks'] ))
        {
            $rightblock = $_CONF['show_right_blocks'];
        }
        else
        {
            $rightblock = false;
        }
    }

    // Set template directory
    $footer = new Template( $_CONF['path_layout'] );

    // Set template file
    $footer->set_file( array(
            'footer'      => 'footer.thtml',
            'rightblocks' => 'blocks_2.thtml',
            'leftblocks'  => 'blocks_1.thtml'
            ));

    // Do variable assignments
    DB_change( $_TABLES['vars'], 'value', 'value + 1', 'name', 'totalhits', '', true );

    $footer->set_var( 'site_url', $_CONF['site_url']);
    $footer->set_var( 'layout_url',$_CONF['layout_url']);
    $footer->set_var( 'site_mail', "mailto:{$_CONF['site_mail']}" );
    $footer->set_var( 'site_name', $_CONF['site_name'] );
    $footer->set_var( 'site_slogan', $_CONF['site_slogan'] );
    $rdf = substr_replace( $_CONF['rdf_file'], $_CONF['site_url'], 0,
                           strlen( $_CONF['path_html'] ) - 1 );
    $footer->set_var( 'rdf_file', $rdf );
    $footer->set_var( 'rss_url', $rdf );

    $year = date( 'Y' );
    $copyrightyear = $year;
    if( !empty( $_CONF['copyrightyear'] ))
    {
        $copyrightyear = $_CONF['copyrightyear'];
    }
    $footer->set_var( 'copyright_notice', '&nbsp;' . $LANG01[93] . ' &copy; '
            . $copyrightyear . ' ' . $_CONF['site_name'] . '<br>&nbsp;'
            . $LANG01[94] );
    $footer->set_var( 'copyright_msg', $LANG01[93] . ' &copy; '
            . $copyrightyear . ' ' . $_CONF['site_name'] );
    $footer->set_var( 'current_year', $year );
    $footer->set_var( 'lang_copyright', $LANG01[93] );
    $footer->set_var( 'trademark_msg', $LANG01[94] );
    $footer->set_var( 'powered_by', $LANG01[95] );
    $footer->set_var( 'geeklog_url', 'http://www.geeklog.net/' );
    $footer->set_var( 'geeklog_version', VERSION );

    /* Check if an array has been passed that includes the name of a plugin
     * function or custom function.
     * This can be used to take control over what blocks are then displayed
     */
    if( is_array( $custom ))
    {
        $function = $custom['0'];
        if( function_exists( $function ))
        {
            $rblocks = $function( $custom['1'], 'right' );
        }
    }
    elseif( $rightblock )
    {
        $rblocks = COM_showBlocks( 'right', $topic );
    }
    if( $rightblock && !empty( $rblocks ))
    {
        $footer->set_var( 'geeklog_blocks', $rblocks );
        $footer->parse( 'right_blocks', 'rightblocks', true );
    }
    else
    {
        $footer->set_var( 'geeklog_blocks', '' );
        $footer->set_var( 'right_blocks', '' );
    }

    if( $_CONF['left_blocks_in_footer'] == 1 )
    {
        $lblocks = '';

        /* Check if an array has been passed that includes the name of a plugin
         * function or custom function
         * This can be used to take control over what blocks are then displayed
         */
        if( is_array( $custom ))
        {
            $function = $custom[0];
            if( function_exists( $function ))
            {
                $lblocks = $function( $custom[1], 'left' );
            }
        }
        else
        {
            $lblocks = COM_showBlocks( 'left', $topic );
        }

        if( empty( $lblocks ))
        {
            $footer->set_var( 'geeklog_blocks', '' );
            $footer->set_var( 'left_blocks', '' );
        }
        else
        {
            $footer->set_var( 'geeklog_blocks', $lblocks );
            $footer->parse( 'left_blocks', 'leftblocks', true );
        }
    }

    // Global centerspan variable set in index.php
    if( isset( $GLOBALS['centerspan'] ))
    {
        $footer->set_var( 'centerblockfooter-span', '</td></tr></table>' );
    }

    $exectime = $_PAGE_TIMER->stopTimer();
    $exectext = $LANG01[91] . ' ' . $exectime . ' ' . $LANG01[92];

    $footer->set_var( 'execution_time', $exectime );
    $footer->set_var( 'execution_textandtime', $exectext );
    $footer->set_var( 'tohome', '<a href="'. $_CONF['site_url'] . '/" accesskey="1">' . $LANG01['68'] . '</a>' );

    if (!empty ($_USER['uid']) && ($_USER['uid'] > 1)) {
        //ログアウト
        	$footer->set_var( 'login_or_logout',
						  '<a href="'. $_CONF['site_url'] . '/users.php?mode=logout" accesskey="2">' . $LANG01['19'] . '</a>' );
        //マイアカウント
        	$footer->set_var( 'regist_or_myaccount',
						  '<a href="'. $_CONF['site_url'] . '/usersettings.php?mode=edit" accesskey="3">' . $LANG01['48'] . '</a>' );
	} else {
        //ログイン
		$footer->set_var( 'login_or_logout',
						  '<a href="'. $_CONF['site_url'] . '/users.php?mode=login" accesskey="2">' . $LANG01['47'] . '</a>' );
        //新規登録
        	$footer->set_var( 'regist_or_myaccount',
						  '<a href="'. $_CONF['site_url'] . '/users.php?mode=new" accesskey="3">' . $LANG01['61'] . '</a>' );
    }

    // Call to plugins to set template variables in the footer
    PLG_templateSetVars( 'footer', $footer );

    // Actually parse the template and make variable substitutions
    $footer->parse( 'index_footer', 'footer' );

    // Return resulting HTML
    return $footer->finish( $footer->get_var( 'index_footer' ));
}

$_BASE_TEMPLATE = 'ProfessionalCSS';

?>