예제 #1
0
function template_auto_files()
{
    global $txt, $scripturl, $settings, $context, $arcSettings;
    if ($context['arcade']['sub_action'] == "massinstall") {
        echo '
            <div class="cat_bar">
                    <h3 class="catbg">
                    ', $txt['arcade_admin_auto_install'], '
                    </h3>
            </div>

        <table border="0" width="100%" cellspacing="1" cellpadding="5" class="bordercolor">
            <tr class="windowbg2">
                <td colspan="2" class="windowbg2" align="left" valign="middle" width="16"><br />', $txt['arcade_description_help'], ' <a href="', $scripturl, '?action=helpadmin;help=arcade_admin_auto_install_text" onclick="return reqWin(this.href);" class="help"><img src="', $settings['images_url'], '/helptopics.gif" alt="', $txt['help'], '" border="0" align="top" /></a><br /><br /></td>
            </tr>';
        if (isset($context['arcade']['toinstall'])) {
            echo '<tr class="windowbg2">
                <td colspan="2" class="windowbg2" align="left" valign="middle" width="16">
                <b>', $txt['arcade_admin_ai_waiting'], '</b><br />';
            foreach ($context['arcade']['toinstall'] as $key => $file) {
                echo $file . '<br />';
            }
            echo '</td>
            </tr>';
        }
        echo '
            <tr class="windowbg">
                <td>
                    <b>', $txt['arcade_upload'], '</b>
                </td>
                <td>
                    <form action="', $scripturl, '?action=admin;area=managearcade;sa=upload" method="post" id="upload" enctype="multipart/form-data">
                    <input type="file" name="package" /> (<i>', $txt['arcade_supported_filetypes_tar'], '</i>)
                    <input type="submit" name="install_games" value="', $txt['arcade_upload'], '" />
                    </form>
                </td>
            </tr>
            <tr class="windowbg">
                <td>
                    <b>', $txt['arcade_category'], ':</b>
                </td>
                <td>
                    <form name="whatta" action="', $scripturl, '?action=admin;area=managearcade;sa=autofiles;sub=massi1" method="post">
                    <select size="1" name="category">';
        $cats = prepareCategories();
        foreach ($cats as $i => $temp) {
            echo '<option value=', $temp['id'], '>', $temp['name'], '</option>';
        }
        echo '</select>&nbsp;<input type="submit" value="', $txt['arcade_title_install_games'], '" name="massinstall" />
                    </form>
                </td>
            </tr>
            <tr class="titlebg">
                <td colspan="2">&nbsp;</td>
            </tr>
        </table>';
    } else {
        echo '<table border="0" width="100%" cellspacing="1" cellpadding="5" class="bordercolor">
                <tr class="catbg">
                    <td>', $txt['arcade_admin_auto_install_done'], '</td>
                </tr>

                <tr class="windowbg2">
                    <td>';
        foreach ($context['arcade']['installed_games'] as $key => $value) {
            echo $value, '<br />';
        }
        echo '
            </td>
        </tr>
                    <tr class="catbg">
                    <td>', $txt['arcade_admin_auto_install_fail'], '</td>
                </tr>

                <tr class="windowbg2">
                    <td>';
        foreach ($context['arcade']['failed_games'] as $key1 => $value1) {
            echo $value1, '<br />';
        }
        echo '
            </td>
        </tr>
    </table><br />';
    }
}
예제 #2
0
function GamesAdminInstall()
{
    global $scripturl, $txt, $smcFunc, $arcSettings, $context, $sourcedir, $boarddir;
    // Make list of files to be installed
    if (isset($_REQUEST['file']) || isset($_REQUEST['directory'])) {
        // We don't want to install games more than once
        $installed = array();
        $result = $smcFunc['db_query']('', '
			SELECT game_file
			FROM {db_prefix}arcade_games', array());
        while ($file = $smcFunc['db_fetch_assoc']($result)) {
            $installed[$file['game_file']] = true;
        }
        $smcFunc['db_free_result']($result);
        // We need write permission to games directory
        if (!is_writable($arcSettings['gamesDirectory'])) {
            fatal_lang_error('arcade_not_writable', false, array($arcSettings['gamesDirectory']));
        }
        // We will need this to extract files
        require_once $sourcedir . '/Subs-Package.php';
        // One file
        if (isset($_REQUEST['file']) && !is_array($_REQUEST['file'])) {
            $files = array($_REQUEST['file']);
        } elseif (isset($_REQUEST['file']) && is_array($_REQUEST['file'])) {
            $files =& $_REQUEST['file'];
        } else {
            $files = array();
        }
        // Remove invalid games
        foreach ($files as $key => $value) {
            if (!file_exists($arcSettings['gamesDirectory'] . '/' . $value)) {
                unset($files[$key]);
            }
        }
        // Files from directories
        if (isset($_REQUEST['directory']) && is_array($_REQUEST['directory'])) {
            chdir($arcSettings['gamesDirectory']);
            foreach ($_REQUEST['directory'] as $directory) {
                $files = array_merge($files, glob($directory . '/*.swf'));
            }
        }
        if (count($files) == 0) {
            fatal_lang_error('arcade_no_files_selected');
        }
        $games = array();
        // Let's make array with basic settings
        foreach ($files as $file) {
            $path = $file;
            $file = basename($file);
            $dot = strrpos($file, '.');
            if ($dot !== false) {
                $internal_name = substr($file, 0, $dot);
            } else {
                fatal_lang_error('arcade_invalid_file', false, array($path));
            }
            if (substr($file, -3) == 'swf') {
                // Is it already installed?
                if (isset($installed[$file])) {
                    continue;
                }
                $name = str_replace('_', ' ', $internal_name);
                $games[$internal_name] = array('internal_name' => $internal_name, 'name' => ucwords($name), 'path' => $path, 'file' => $file, 'type' => substr($file, -3));
            } elseif (substr($file, -3) == 'zip') {
                $data = file_get_contents($arcSettings['gamesDirectory'] . $path);
                if ($data === false) {
                    continue;
                }
                // Unable to read file :(
                $destination = $arcSettings['gamesDirectory'] . $internal_name . '/';
                $ret = read_zip_data($data, $destination);
                unset($data);
                unlink($arcSettings['gamesDirectory'] . $file);
                $folder = $internal_name;
                if ($ret == false) {
                    continue;
                }
                // Files that were extracted
                foreach ($ret as $file_pack) {
                    $basename = basename($file_pack['filename']);
                    // Is it already installed?
                    if (isset($installed[$basename])) {
                        continue;
                    }
                    $path = $folder . '/' . $basename;
                    $dot = strpos($file_pack['filename'], '.');
                    if ($dot !== false) {
                        $internal_name = substr($basename, 0, $dot);
                    } else {
                        fatal_lang_error('arcade_invalid_file', false, array($path));
                    }
                    if (substr($basename, -3) == 'swf') {
                        $name = str_replace('_', ' ', $internal_name);
                        $games[$internal_name] = array('internal_name' => $internal_name, 'name' => ucwords($name), 'path' => $path, 'file' => $basename, 'type' => substr($file_pack['filename'], -3));
                    }
                }
            }
        }
        // There were packages with errors or no games...
        if (count($games) == 0) {
            fatal_lang_error('arcade_no_files_selected');
        }
        // Session will store data
        $_SESSION['install'] = array('to_check' => $games, 'games' => array(), 'done' => 0, 'total' => count($files), 'begin' => time(), 'end' => 0);
        redirectexit('action=admin;area=managearcade;sa=files;do=stageone');
    } elseif (isset($_SESSION['install'])) {
        //use getid...it works!!
        require_once $boarddir . '/getid3/getid3.php';
        $install =& $_SESSION['install'];
        $context['arcade']['install'] = array();
        // Games that needs to be checked
        foreach ($install['to_check'] as $key => $file) {
            //we need meta-data such as width and height
            $swf = new getID3();
            $swf->analyze($arcSettings['gamesDirectory'] . $file['path']);
            $file['width'] = $swf->info['video']['resolution_x'];
            $file['height'] = $swf->info['video']['resolution_y'];
            $file['bgcolor'] = $swf->info['swf']['bgcolor'];
            // Change working directory and try to find thumbails
            $directory = substr($file['path'], 0, strrpos($file['path'], '/'));
            chdir($arcSettings['gamesDirectory'] . $directory);
            $thumbnail = glob($file['internal_name'] . '.{png,gif,jpg}', GLOB_BRACE);
            if (!$thumbnail) {
                $thumbnail = glob($file['internal_name'] . '1.{png,gif,jpg}', GLOB_BRACE);
            }
            // Build array
            $context['arcade']['install'][] = array('game_name' => $file['name'], 'internal_name' => $file['internal_name'], 'directory' => $directory, 'file' => $file['file'], 'thumbnail' => isset($thumbnail[0]) ? $thumbnail[0] : '', 'score_type' => 0, 'width' => isset($file['width']) ? $file['width'] : '400', 'height' => isset($file['height']) ? $file['height'] : '300', 'bgcolor' => $file['bgcolor']);
        }
        $_SESSION['install2'] = $context['arcade']['install'];
        $context['arcade']['categories'] = prepareCategories();
        // Template
        $context['page_title'] = $txt['arcade_title_install_games'];
        $context['sub_template'] = 'games_install';
    } else {
        fatal_lang_error('arcade_no_files_selected');
    }
}