Example #1
0
function annotate_page_start()
{
    global $CONFIG, $lang_meta_album_names, $valid_meta_albums;
    require_once './plugins/annotate/init.inc.php';
    $annotate_init_array = annotate_initialize();
    $lang_plugin_annotate = $annotate_init_array['language'];
    $annotate_icon_array = $annotate_init_array['icon'];
    $superCage = Inspekt::MakeSuperCage();
    $note = $superCage->get->keyExists('note') ? $superCage->get->getRaw('note') : $superCage->cookie->getRaw($CONFIG['cookie_name'] . 'note');
    $lang_meta_album_names['lastnotes'] = $lang_plugin_annotate['lastnotes'];
    $lang_meta_album_names['shownotes'] = $lang_plugin_annotate['shownotes'] . " '{$note}'";
    $valid_meta_albums[] = 'lastnotes';
    $valid_meta_albums[] = 'shownotes';
    $superCage = Inspekt::makeSuperCage();
    if ($superCage->get->getAlpha('plugin') == "annotate" && $superCage->get->keyExists('delete_orphans')) {
        global $CONFIG;
        require_once './plugins/annotate/init.inc.php';
        $annotate_init_array = annotate_initialize();
        $lang_plugin_annotate = $annotate_init_array['language'];
        $annotate_icon_array = $annotate_init_array['icon'];
        load_template();
        pageheader($lang_plugin_annotate['delete_orphaned_entries']);
        if (version_compare(cpg_phpinfo_mysql_version(), '4.1', '>=')) {
            // we can use subqueries here
            cpg_db_query("DELETE FROM {$CONFIG['TABLE_PREFIX']}plugin_annotate WHERE pid NOT IN (SELECT pid FROM {$CONFIG['TABLE_PICTURES']})");
        } else {
            $result = cpg_db_query("SELECT pid FROM {$CONFIG['TABLE_PICTURES']}");
            $pids = array();
            while ($row = mysql_fetch_row($result)) {
                $pids[] = $row[0];
            }
            $pids = implode(",", $pids);
            mysql_free_result($result);
            // cpg_db_query can cause browser to crash if debug output is enabled
            mysql_query("DELETE FROM {$CONFIG['TABLE_PREFIX']}plugin_annotate WHERE pid NOT IN ({$pids})");
        }
        $count = mysql_affected_rows();
        if ($count == 1) {
            $count_output = $lang_plugin_annotate['1_orphaned_entry_deleted'];
        } else {
            $count_output = sprintf($lang_plugin_annotate['x_orphaned_entries_deleted'], $count);
        }
        starttable('-1', $annotate_icon_array['delete'] . $lang_plugin_annotate['delete_orphaned_entries']);
        echo <<<EOT
        <tr>
            <td class="tableb">
                {$count_output}
            </td>
        </tr>
EOT;
        endtable();
        pagefooter();
        exit;
    }
    if ($superCage->get->getAlpha('plugin') == "annotate" && $superCage->get->keyExists('import')) {
        global $CONFIG;
        require_once './plugins/annotate/init.inc.php';
        $annotate_init_array = annotate_initialize();
        $lang_plugin_annotate = $annotate_init_array['language'];
        $annotate_icon_array = $annotate_init_array['icon'];
        load_template();
        pageheader($lang_plugin_annotate['import']);
        starttable('-1', $annotate_icon_array['import'] . $lang_plugin_annotate['import']);
        if ($superCage->get->keyExists('do') && $CONFIG['plugin_annotate_import'] != "1") {
            if (!mysql_query("SELECT user_time FROM {$CONFIG['TABLE_PREFIX']}notes")) {
                cpg_db_query("INSERT INTO {$CONFIG['TABLE_PREFIX']}plugin_annotate (pid, posx, posy, width, height, note, user_id, user_time) \n                              SELECT pid, posx, posy, width, height, note, user_id, UNIX_TIMESTAMP() FROM {$CONFIG['TABLE_PREFIX']}notes");
            } else {
                cpg_db_query("INSERT INTO {$CONFIG['TABLE_PREFIX']}plugin_annotate (pid, posx, posy, width, height, note, user_id, user_time) \n                              SELECT pid, posx, posy, width, height, note, user_id, user_time FROM {$CONFIG['TABLE_PREFIX']}notes");
            }
            echo '<tr><td class="tableb">' . sprintf($lang_plugin_annotate['import_success'], mysql_affected_rows()) . '</td></tr>';
            cpg_db_query("INSERT INTO {$CONFIG['TABLE_CONFIG']} (name, value) VALUES ('plugin_annotate_import', '1')");
        } else {
            $notes_to_import = mysql_result(cpg_db_query("SELECT COUNT(*) FROM {$CONFIG['TABLE_PREFIX']}notes"), 0);
            if (!$notes_to_import) {
                echo '<tr><td class="tableb">' . sprintf($lang_plugin_annotate['import_found'], $notes_to_import) . '</td></tr>';
            } elseif ($CONFIG['plugin_annotate_import'] == "1") {
                echo '<tr><td class="tableb">' . $lang_plugin_annotate['imported_already'] . '</td></tr>';
            } else {
                echo '<tr><td class="tableb">' . sprintf($lang_plugin_annotate['import_found'], $notes_to_import) . ' <a href="index.php?plugin=annotate&import&do" class="admin_menu">' . $lang_plugin_annotate['import'] . '</a></td></tr>';
            }
        }
        endtable();
        pagefooter();
        exit;
    }
    if ($superCage->get->getAlpha('plugin') == "annotate" && $superCage->get->keyExists('update_database')) {
        global $CONFIG;
        require_once './plugins/annotate/init.inc.php';
        $annotate_init_array = annotate_initialize();
        $lang_plugin_annotate = $annotate_init_array['language'];
        $annotate_icon_array = $annotate_init_array['icon'];
        load_template();
        pageheader($lang_plugin_annotate['update_database']);
        require 'include/sql_parse.php';
        $db_schema = './plugins/annotate/update.sql';
        $sql_query = fread(fopen($db_schema, 'r'), filesize($db_schema));
        $sql_query = preg_replace('/CPG_/', $CONFIG['TABLE_PREFIX'], $sql_query);
        $sql_query = remove_remarks($sql_query);
        $sql_query = split_sql_file($sql_query, ';');
        foreach ($sql_query as $q) {
            @mysql_query($q);
        }
        starttable('-1', $annotate_icon_array['update_database'] . $lang_plugin_annotate['update_database']);
        echo <<<EOT
        <tr>
            <td class="tableb">
                {$lang_plugin_annotate['update_database_success']}
            </td>
        </tr>
EOT;
        endtable();
        pagefooter();
        exit;
    }
    if ($superCage->get->getAlpha('plugin') == "annotate" && $superCage->get->keyExists('manage')) {
        if (!GALLERY_ADMIN_MODE) {
            return;
        }
        global $CONFIG;
        require_once './plugins/annotate/init.inc.php';
        $annotate_init_array = annotate_initialize();
        $lang_plugin_annotate = $annotate_init_array['language'];
        $annotate_icon_array = $annotate_init_array['icon'];
        load_template();
        if ($superCage->post->keyExists('submit')) {
            if (!checkFormToken()) {
                global $lang_errors;
                cpg_die(ERROR, $lang_errors['invalid_form_token'], __FILE__, __LINE__);
            }
            if ($superCage->get->keyExists('batch_rename')) {
                if (strlen($superCage->post->getRaw('note_new')) < 1) {
                    header("Location: index.php?plugin=annotate&manage&batch_rename&status=0&note_old=" . $superCage->post->getRaw('note_old') . "&note_new=" . $superCage->post->getRaw('note_new'));
                } else {
                    cpg_db_query("UPDATE {$CONFIG['TABLE_PREFIX']}plugin_annotate SET note = '" . addslashes(addslashes($superCage->post->getRaw('note_new'))) . "' WHERE note = '" . addslashes(addslashes($superCage->post->getRaw('note_old'))) . "'");
                    header("Location: index.php?plugin=annotate&manage&batch_rename&status=1&note_old=" . $superCage->post->getRaw('note_old') . "&note_new=" . $superCage->post->getRaw('note_new'));
                }
            }
            if ($superCage->get->keyExists('batch_delete')) {
                cpg_db_query("DELETE FROM {$CONFIG['TABLE_PREFIX']}plugin_annotate WHERE note = '" . addslashes(addslashes($superCage->post->getRaw('note_old'))) . "'");
                header("Location: index.php?plugin=annotate&manage&batch_delete&status=1&note_old=" . $superCage->post->getRaw('note_old'));
            }
        }
        pageheader($lang_plugin_annotate['manage']);
        if ($superCage->get->keyExists('batch_rename')) {
            starttable("100%", $lang_plugin_annotate['batch_rename']);
        } elseif ($superCage->get->keyExists('batch_delete')) {
            starttable("100%", $lang_plugin_annotate['batch_delete']);
        } else {
            starttable("100%", $lang_plugin_annotate['manage']);
        }
        if ($superCage->post->keyExists('sure')) {
            if ($superCage->get->keyExists('batch_rename')) {
                global $lang_common;
                $note_new = $superCage->post->getRaw('note_new');
                if (strlen($note_new) < 1) {
                    echo '<tr><td class="tableb">' . $lang_plugin_annotate['note_empty'] . ' <a href="javascript:history.back();">' . $lang_common['back'] . '</a></td></tr>';
                    endtable();
                    pagefooter();
                    die;
                }
                list($timestamp, $form_token) = getFormToken();
                echo '
                    <tr><td class="tableb">
                    <form method="post" action="index.php?plugin=annotate&manage&batch_rename">
                    ' . sprintf($lang_plugin_annotate['sure_rename'], $superCage->post->getRaw('note_old'), $note_new) . '
                    <input type="hidden" name="note_old" class="textinput" value="' . $superCage->post->getRaw('note_old') . '" readonly="readonly">
                    <input type="hidden" name="note_new" class="textinput" value="' . $note_new . '" readonly="readonly">
                    <input type="hidden" name="form_token" value="' . $form_token . '" />
                    <input type="hidden" name="timestamp" value="' . $timestamp . '" />
                    <input type="submit" name="submit" class="button" value="' . $lang_common['go'] . '">
                    <a href="javascript:history.back();">' . $lang_common['back'] . '</a>
                    </form>
                    </td></tr>
                ';
            }
            if ($superCage->get->keyExists('batch_delete')) {
                global $lang_common;
                list($timestamp, $form_token) = getFormToken();
                echo '
                    <tr><td class="tableb">
                    <form method="post" action="index.php?plugin=annotate&manage&batch_delete">
                    ' . sprintf($lang_plugin_annotate['sure_delete'], $superCage->post->getRaw('note_old')) . '
                    <input type="hidden" name="note_old" class="textinput" value="' . $superCage->post->getRaw('note_old') . '" readonly="readonly">
                    <input type="hidden" name="form_token" value="' . $form_token . '" />
                    <input type="hidden" name="timestamp" value="' . $timestamp . '" />
                    <input type="submit" name="submit" class="button" value="' . $lang_common['go'] . '">
                    <a href="javascript:history.back();">' . $lang_common['back'] . '</a>
                    </form>
                    </td></tr>
                ';
            }
        }
        if (!$superCage->post->keyExists('note_old')) {
            if ($superCage->get->keyExists('status')) {
                if ($superCage->get->keyExists('batch_rename')) {
                    if ($superCage->get->getInt('status') == 1) {
                        echo '<tr><td class="tableb">' . sprintf($lang_plugin_annotate['rename_success'], $superCage->get->getRaw('note_old'), $superCage->get->getRaw('note_new')) . ' </td></tr>';
                    }
                    if ($superCage->get->getInt('status') == 0) {
                        echo '<tr><td class="tableb">"' . sprintf($lang_plugin_annotate['rename_fail'], $superCage->get->getRaw('note_old'), $superCage->get->getRaw('note_new')) . '. ' . $lang_plugin_annotate['note_empty'] . '</td></tr>';
                    }
                }
                if ($superCage->get->keyExists('batch_delete') && $superCage->get->getInt('status') == 1) {
                    echo '<tr><td class="tableb">' . sprintf($lang_plugin_annotate['delete_success'], $superCage->get->getRaw('note_old'), $superCage->get->getRaw('note_new')) . ' </td></tr>';
                }
            }
            if ($superCage->get->keyExists('note')) {
                if ($superCage->get->keyExists('batch_rename')) {
                    global $lang_common;
                    echo '
                        <tr><td class="tableb">
                        <form method="post">
                        <input type="text" name="note_old" size="40" class="textinput" value="' . $superCage->get->getRaw('note') . '" readonly="readonly"> ' . $lang_plugin_annotate['rename_to'] . '
                        <input type="text" name="note_new" size="40" class="textinput" id="note_new">
                        <input type="submit" name="sure" class="button" value="' . $lang_common['go'] . '">
                        </form> <script type="text/javascript"> document.getElementById("note_new").select(); </script>
                        </td></tr>
                    ';
                }
                if ($superCage->get->keyExists('batch_delete')) {
                    global $lang_common;
                    echo '
                        <tr><td class="tableb">
                        <form method="post">
                        ' . $lang_common['delete'] . '
                        <input type="text" name="note_old" class="textinput" value="' . $superCage->get->getRaw('note') . '" readonly="readonly">
                        <input type="submit" name="sure" class="button" value="' . $lang_common['go'] . '">
                        </form>
                        </td></tr>
                    ';
                }
            }
            $result = cpg_db_query("SELECT DISTINCT(note) FROM {$CONFIG['TABLE_PREFIX']}plugin_annotate ORDER BY note");
            if (mysql_num_rows($result)) {
                $person_array = array();
                while ($row = mysql_fetch_assoc($result)) {
                    $person_array[] = stripslashes($row['note']);
                }
                echo '<tr><td class="tableb" align="left">';
                for ($i = 0; $i < count($person_array); $i++) {
                    $note = str_replace(array("#", "&"), array("%23", "%26"), $person_array[$i]);
                    echo "\n                        <a href=\"index.php?plugin=annotate&amp;manage&amp;batch_delete&amp;note={$note}\" title=\"{$lang_plugin_annotate['batch_delete']}\"><img src=\"images/icons/delete.png\" border=\"0\" /></a>\n                        <a href=\"index.php?plugin=annotate&amp;manage&amp;batch_rename&amp;note={$note}\" title=\"{$lang_plugin_annotate['batch_rename']}\"><img src=\"images/icons/edit.png\" border=\"0\" /></a>\n                        {$person_array[$i]}<br />\n                    ";
                }
                echo '</td></tr>';
            }
            mysql_free_result($result);
        }
        endtable();
        pagefooter();
        exit;
    }
}
function cpg_debug_output()
{
    global $HTTP_GET_VARS, $HTTP_POST_VARS, $HTTP_SERVER_VARS;
    global $USER, $USER_DATA, $ALBUM_SET, $CONFIG, $time_start, $query_stats, $queries, $lang_cpg_debug_output;
    $time_end = cpgGetMicroTime();
    $time = round($time_end - $time_start, 3);
    $query_count = count($query_stats);
    $query_times = '';
    $total_query_time = 0;
    foreach ($query_stats as $qtime) {
        $query_times .= round($qtime, 3) . "s ";
        $total_query_time += $qtime;
    }
    $total_query_time = round($total_query_time, 3);
    $debug_underline = '&#0010;------------------&#0010;';
    $debug_separate = '&#0010;==========================&#0010;';
    echo '<form name="debug">';
    starttable('100%', $lang_cpg_debug_output['debug_info'], 2);
    echo '<tr><td align="center" valign="middle" class="tableh2">';
    echo '<script language="Javascript">
<!--

function HighlightAll(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
}
//-->
</script>';
    echo '
        <div class="admin_menu"><a href="javascript:HighlightAll(\'debug.debugtext\')" class="adm_menu">' . $lang_cpg_debug_output['select_all'] . '</a></div>';
    echo '</td><td align="left" valign="middle" class="tableh2">';
    if (GALLERY_ADMIN_MODE) {
        echo '<span class="album_stat">(' . $lang_cpg_debug_output['copy_and_paste_instructions'] . ')</span>';
    }
    echo '</td></tr>';
    echo '<tr><td class="tableb" colspan="2">';
    echo '<textarea  rows="10" class="debug_text" name="debugtext">';
    echo "USER: "******"USER DATA:";
    echo $debug_underline;
    print_r($USER_DATA);
    echo $debug_separate;
    echo "Queries:";
    echo $debug_underline;
    print_r($queries);
    echo $debug_separate;
    echo "GET :";
    echo $debug_underline;
    print_r($HTTP_GET_VARS);
    echo $debug_separate;
    echo "POST :";
    echo $debug_underline;
    print_r($HTTP_POST_VARS);
    echo $debug_separate;
    if (GALLERY_ADMIN_MODE) {
        echo "VERSION INFO :";
        echo $debug_underline;
        $version_comment = ' - OK';
        if (strcmp('4.0.0', phpversion()) == 1) {
            $version_comment = ' - your PHP version isn\'t good enough! Minimum requirements: 4.x';
        }
        echo 'PHP version: ' . phpversion() . $version_comment;
        echo $debug_underline;
        $version_comment = '';
        $mySqlVersion = cpg_phpinfo_mysql_version();
        if (strcmp('3.23.23', $mySqlVersion) == 1) {
            $version_comment = ' - your mySQL version isn\'t good enough! Minimum requirements: 3.23.23';
        }
        echo 'mySQL version: ' . $mySqlVersion . $version_comment;
        echo $debug_underline;
        echo 'Coppermine version: ';
        echo COPPERMINE_VERSION;
        echo $debug_separate;
        error_reporting(E_ERROR | E_WARNING | E_PARSE);
        echo cpg_phpinfo_mod_output('gd', 'text');
        echo cpg_phpinfo_mod_output('mysql', 'text');
        echo cpg_phpinfo_mod_output('zlib', 'text');
        echo 'Server restrictions (safe mode)?';
        echo $debug_underline;
        echo 'Directive | Local Value | Master Value';
        echo cpg_phpinfo_conf_output("safe_mode");
        echo cpg_phpinfo_conf_output("safe_mode_exec_dir");
        echo cpg_phpinfo_conf_output("safe_mode_gid");
        echo cpg_phpinfo_conf_output("safe_mode_include_dir");
        echo cpg_phpinfo_conf_output("safe_mode_exec_dir");
        echo cpg_phpinfo_conf_output("sql.safe_mode");
        echo cpg_phpinfo_conf_output("disable_functions");
        echo cpg_phpinfo_conf_output("file_uploads");
        echo cpg_phpinfo_conf_output("include_path");
        echo cpg_phpinfo_conf_output("open_basedir");
        echo $debug_separate;
        echo 'email';
        echo $debug_underline;
        echo 'Directive | Local Value | Master Value';
        echo cpg_phpinfo_conf_output("sendmail_from");
        echo cpg_phpinfo_conf_output("sendmail_path");
        echo cpg_phpinfo_conf_output("SMTP");
        echo cpg_phpinfo_conf_output("smtp_port");
        echo $debug_separate;
        echo 'Size and Time';
        echo $debug_underline;
        echo 'Directive | Local Value | Master Value';
        echo cpg_phpinfo_conf_output("max_execution_time");
        echo cpg_phpinfo_conf_output("max_input_time");
        echo cpg_phpinfo_conf_output("upload_max_filesize");
        echo cpg_phpinfo_conf_output("post_max_size");
        echo $debug_separate;
    }
    echo <<<EOT
Page generated in {$time} seconds - {$query_count} queries in {$total_query_time} seconds - Album set : {$ALBUM_SET}
EOT;
    echo "</textarea>";
    echo "</td>";
    echo "</tr>";
    if (GALLERY_ADMIN_MODE) {
        echo "<tr><td class=\"tableb\" colspan=\"2\">";
        echo "<a href=\"phpinfo.php\">" . $lang_cpg_debug_output['phpinfo'] . "</a>";
        error_reporting(E_ERROR | E_WARNING | E_PARSE);
        echo "</td></tr>";
    }
    endtable();
    echo "</form>";
}
/**
 * cpg_debug_output()
 *
 * defined new debug_output function here in functions.inc.php instead of theme.php with different function names to avoid incompatibilities with users not updating their themes as required. Advanced info is only output if (GALLERY_ADMIN_MODE == TRUE)
 *
 **/
function cpg_debug_output()
{
    global $USER, $USER_DATA, $CONFIG, $cpg_time_start, $query_stats, $queries, $lang_cpg_debug_output, $CPG_PHP_SELF, $superCage, $CPG_PLUGINS, $LINEBREAK;
    if ($CONFIG['performance_timestamp'] == 0 || date('Y-m-d', $CONFIG['performance_timestamp']) < date('Y-m-d')) {
        // The metering data in the config table are outdated, let's write fresh values.
        // Currently happens each day. To extend the metering period to a whole week,
        // use 'Y-m-W' for both date functions above. Use 'Y-m' to extend the period over
        // one month and subsequently 'Y' for an entire year.
        $CONFIG['performance_timestamp'] = time();
        cpg_config_set('performance_timestamp', $CONFIG['performance_timestamp']);
        $CONFIG['performance_page_generation_time'] = 0;
        $CONFIG['performance_page_query_time'] = 0;
        $CONFIG['performance_page_query_count'] = 0;
    }
    $time_end = cpgGetMicroTime();
    $time = round(($time_end - $cpg_time_start) * 1000, 2);
    if ($CONFIG['performance_page_generation_time'] < $time) {
        $CONFIG['performance_page_generation_time'] = $time;
        cpg_config_set('performance_page_generation_time', $CONFIG['performance_page_generation_time']);
    }
    $query_count = count($query_stats);
    $total_query_time = round(array_sum($query_stats), 2);
    if ($CONFIG['performance_page_query_time'] < $total_query_time) {
        $CONFIG['performance_page_query_time'] = $total_query_time;
        cpg_config_set('performance_page_query_time', $CONFIG['performance_page_query_time']);
    }
    if ($CONFIG['performance_page_query_count'] < $query_count) {
        $CONFIG['performance_page_query_count'] = $query_count;
        cpg_config_set('performance_page_query_count', $CONFIG['performance_page_query_count']);
    }
    $debug_underline = '&#0010;------------------&#0010;';
    $debug_separate = '&#0010;==========================&#0010;';
    $debug_toggle_link = $lang_cpg_debug_output['debug_output'] . ': <span class="detail_head_collapsed">' . $lang_cpg_debug_output['show_hide'] . '</span>';
    $debug_help = '&nbsp;' . cpg_display_help('f=empty.htm&amp;h=lang_cpg_debug_output[debug_output_explain]&amp;t=lang_cpg_debug_output[copy_and_paste_instructions]', 470, 245);
    $debug_phpinfo_link = GALLERY_ADMIN_MODE ? '<a href="phpinfo.php" class="admin_menu">' . cpg_fetch_icon('phpinfo', 1) . $lang_cpg_debug_output['phpinfo'] . '</a> ' : '';
    echo <<<EOT
    <script language="javascript" type="text/javascript">
<!--
        addonload("document.getElementById('debug_output_select_all').style.display = 'inline'");
//-->
        </script>
    <form name="debug" action="{$CPG_PHP_SELF}" id="debug">
EOT;
    starttable('100%', cpg_fetch_icon('bug', 2) . $lang_cpg_debug_output['debug_info'] . $debug_help, 2);
    echo <<<EOT
    <tr>
        <td>

        </td>
    </tr>
    <tr>
        <td valign="top" align="left" class="tableb">
            {$debug_phpinfo_link}{$debug_toggle_link}
            <span class="detail_body">
                <button type="button" class="button" name="debug_output_select_all" style="display:none" id="debug_output_select_all" value="{$lang_cpg_debug_output['select_all']}" onclick="HighlightAll('debug.debugtext');">{$lang_cpg_debug_output['select_all']}</button><br />
                <textarea  rows="30" cols="60" class="debug_text" name="debugtext">
EOT;
    echo "USER: "******"USER DATA:";
    echo $debug_underline;
    echo htmlentities(print_r($USER_DATA, true));
    echo $debug_separate;
    echo "Queries:";
    echo $debug_underline;
    echo htmlentities(print_r($queries, true));
    echo $debug_separate;
    echo "GET :";
    echo $debug_underline;
    echo htmlentities(print_r($superCage->get->_source, true));
    echo $debug_separate;
    echo "POST :";
    echo $debug_underline;
    echo htmlentities(print_r($superCage->post->_source, true));
    echo $debug_separate;
    echo "COOKIE :";
    echo $debug_underline;
    echo htmlentities(print_r($superCage->cookie->_source, true));
    echo $debug_separate;
    if ($superCage->cookie->keyExists('PHPSESSID')) {
        echo "SESSION :";
        echo $debug_underline;
        if (!isset($_SESSION)) {
            session_id($superCage->cookie->getAlnum('PHPSESSID'));
            session_start();
        }
        echo htmlentities(print_r($_SESSION, true));
        echo $debug_separate;
    }
    if (GALLERY_ADMIN_MODE) {
        $table = array();
        echo "VERSION INFO :";
        echo $debug_underline;
        $my_php_version = phpversion();
        if ($my_php_version == '') {
            $my_php_version = PHP_VERSION;
        }
        if (version_compare($my_php_version, '4.3.0', '>=')) {
            $version_comment = 'OK';
        } else {
            $version_comment = 'Your PHP version isn\'t good enough! Minimum requirements: 4.3.0';
        }
        $table[] = array('PHP version', $my_php_version, $version_comment);
        $mySqlVersion = cpg_phpinfo_mysql_version();
        if (version_compare($mySqlVersion, '3.23.23', '>=')) {
            $version_comment = 'OK';
        } else {
            $version_comment = 'Your MySQL version isn\'t good enough! Minimum requirements: 3.23.23';
        }
        $table[] = array('MySQL version', $mySqlVersion, $version_comment);
        $table[] = array('Coppermine version', COPPERMINE_VERSION, COPPERMINE_VERSION_STATUS);
        echo cpg_fill_string_array_with_spaces($table, ' ', 'left', 'string');
        unset($table);
        echo $debug_separate;
        if (function_exists('gd_info') == true) {
            echo 'Module: GD';
            echo $debug_underline;
            $gd_array = gd_info();
            $table = array();
            if (array_key_exists('GD Version', $gd_array) == TRUE) {
                $table[] = array('Exact version', preg_replace('/[[:alpha:][:space:]()]+/', '', $gd_array['GD Version']));
            }
            foreach ($gd_array as $key => $value) {
                $table[] = array($key, $value);
            }
            echo cpg_fill_string_array_with_spaces($table, ' ', 'left', 'string');
            unset($gd_array);
            unset($table);
            echo $debug_separate;
        } else {
            echo cpg_phpinfo_mod_output('gd', 'text', '|');
        }
        echo 'Key config settings';
        echo $debug_underline;
        $table = array();
        $table[] = array('site_url', $CONFIG['site_url']);
        $table[] = array('charset', $CONFIG['charset']);
        $table[] = array('allow_private_albums', $CONFIG['allow_private_albums']);
        $table[] = array('cookie_name', $CONFIG['cookie_name']);
        $table[] = array('cookie_path', $CONFIG['cookie_path']);
        $table[] = array('impath', $CONFIG['impath']);
        $table[] = array('lang', $CONFIG['lang']);
        $table[] = array('main_page_layout', $CONFIG['main_page_layout']);
        $table[] = array('silly_safe_mode', $CONFIG['silly_safe_mode']);
        $table[] = array('smtp_host', $CONFIG['smtp_host']);
        $table[] = array('theme', $CONFIG['theme']);
        $table[] = array('thumb_method', $CONFIG['thumb_method']);
        echo cpg_fill_string_array_with_spaces($table, ' ', 'left', 'string');
        unset($table);
        echo $debug_separate;
        echo 'Plugins';
        echo $debug_underline;
        $table = array();
        foreach ($CPG_PLUGINS as $plugin) {
            $table[] = array('Name', $plugin->name);
            $table[] = array('Actions', implode(', ', array_keys($plugin->actions)));
            $table[] = array('Filters', implode(', ', array_keys($plugin->filters)));
            $table[] = array('--------------');
        }
        echo cpg_fill_string_array_with_spaces($table, ' ', 'left', 'string');
        unset($table);
        echo $debug_separate;
        echo 'Server restrictions';
        echo $debug_underline;
        $table = array();
        $table[] = array('safe_mode', ini_get('safe_mode'));
        $table[] = array('safe_mode_exec_dir', ini_get('safe_mode_exec_dir'));
        $table[] = array('safe_mode_gid', ini_get('safe_mode_gid'));
        $table[] = array('safe_mode_include_dir', ini_get('safe_mode_include_dir'));
        $table[] = array('sql.safe_mode', ini_get('sql.safe_mode'));
        $table[] = array('disable_functions', ini_get('disable_functions'));
        $table[] = array('file_uploads', ini_get('file_uploads'));
        $table[] = array('include_path', ini_get('include_path'));
        $table[] = array('open_basedir', ini_get('open_basedir'));
        $table[] = array('allow_url_fopen', ini_get('allow_url_fopen'));
        $table[] = array('max_execution_time', ini_get('max_execution_time'));
        $table[] = array('max_input_time', ini_get('max_input_time'));
        $table[] = array('upload_max_filesize', ini_get('upload_max_filesize'));
        $table[] = array('post_max_size', ini_get('post_max_size'));
        $table[] = array('memory_limit', ini_get('memory_limit'));
        $table[] = array('suhosin.post.max_vars', ini_get('suhosin.post.max_vars'));
        $table[] = array('suhosin.request.max_vars', ini_get('suhosin.request.max_vars'));
        echo cpg_fill_string_array_with_spaces($table, ' ', 'left', 'string');
        unset($table);
        echo $LINEBREAK . $debug_separate;
        echo 'Page (performance)';
        echo $debug_underline;
        $table = array();
        $table[] = array('Parameter', 'Current', 'Peak');
        if (function_exists('memory_get_peak_usage')) {
            $peak_memory_usage = cpg_format_bytes(memory_get_peak_usage());
        } else {
            $peak_memory_usage = 'n/a';
        }
        $table[] = array('Memory usage', cpg_format_bytes(memory_get_usage()), $peak_memory_usage);
        $table[] = array('Page generation', $time . ' ms', $CONFIG['performance_page_generation_time'] . ' ms');
        $table[] = array('Page query time', $total_query_time . ' ms', $CONFIG['performance_page_query_time'] . ' ms');
        $table[] = array('Page query count', $query_count, $CONFIG['performance_page_query_count']);
        echo cpg_fill_string_array_with_spaces($table, ' ', 'left', 'string');
        unset($table);
        echo $LINEBREAK . $debug_separate;
    }
    echo <<<EOT
                </textarea>
            </span>
        </td>
    </tr>

EOT;
    if ($CONFIG['debug_notice'] != 0) {
        // Maze's error report system
        global $cpgdebugger;
        $report = $cpgdebugger->stop();
        //$debug_notices_icon = cpg_fetch_icon('text_left', 2);
        if (GALLERY_ADMIN_MODE) {
            $notices_help = 'notices_help_admin';
        } else {
            $notices_help = 'notices_help_non_admin';
        }
        $notices_help = '&nbsp;' . cpg_display_help('f=empty.htm&amp;h=lang_cpg_debug_output[notices]&amp;t=lang_cpg_debug_output[' . $notices_help . ']', 470, 245);
        if (is_array($report)) {
            echo <<<EOT
            <tr>
                <td class="tableh2">
                    {$lang_cpg_debug_output['notices']}{$notices_help}
                </td>
            </tr>
EOT;
            $noticesLoopCounter = 0;
            foreach ($report as $file => $errors) {
                if ($noticesLoopCounter / 2 == floor($noticesLoopCounter / 2)) {
                    $cellstyle = 'tableb tableb_alternate';
                } else {
                    $cellstyle = 'tableb';
                }
                echo <<<EOT
            <tr>
                <td class="{$cellstyle}">
EOT;
                //echo '<strong>' . substr($file, $strstart) . '</strong><ul>'; //$strstart does not exist
                echo '<strong>' . $file . '</strong><ul>';
                foreach ($errors as $error) {
                    echo "<li>{$error}</li>";
                }
                echo <<<EOT
                    </ul>
                </td>
            </tr>
EOT;
                $noticesLoopCounter++;
            }
        }
    }
    endtable();
    echo '</form>';
}
Example #4
0
/**
 * cpg_debug_output()
 *
 * defined new debug_output function here in functions.inc.php instead of theme.php with different function names to avoid incompatibilities with users not updating their themes as required. Advanced info is only output if (GALLERY_ADMIN_MODE == TRUE)
 *
 **/
function cpg_debug_output()
{
    global $USER, $USER_DATA, $META_ALBUM_SET, $ALBUM_SET, $CONFIG, $cpg_time_start, $query_stats, $queries, $lang_cpg_debug_output;
    $time_end = cpgGetMicroTime();
    $time = round($time_end - $cpg_time_start, 3);
    $query_count = count($query_stats);
    $total_query_time = array_sum($query_stats);
    $debug_underline = '&#0010;------------------&#0010;';
    $debug_separate = '&#0010;==========================&#0010;';
    $debug_toggle_link = ' <a href="javascript:;" onclick="show_section(\'debug_output_rows\');" class="admin_menu" id="debug_output_toggle" style="display:none;">' . $lang_cpg_debug_output['show_hide'] . '</a>';
    echo '<form name="debug" action="' . $_SERVER['PHP_SELF'] . '" id="debug">';
    starttable('100%', $lang_cpg_debug_output['debug_info'] . $debug_toggle_link, 2);
    //echo '<div name="debug_output_rows" id="debug_output_rows" style="display:block;">';
    echo '<tr><td align="center" valign="top" width="100%" colspan="2">';
    echo '<table border="0" cellspacing="0" cellpadding="0" width="100%" id="debug_output_rows">';
    echo '<tr><td align="center" valign="middle" class="tableh2" width="100">';
    echo '<script language="javascript" type="text/javascript">
<!--

function HighlightAll(theField) {
var tempval=eval("document."+theField)
tempval.focus()
tempval.select()
}
// only hide the debug_output if the user is capable to display it, i.e. if JavaScript is enabled. If JavaScript is off, debug_output will be displayed and the toggle will remain invisible (as it would not do anything anyway with JS off)
addonload("document.getElementById(\'debug_output_rows\').style.display = \'none\'");
addonload("document.getElementById(\'debug_output_toggle\').style.display = \'inline\'");
//-->
</script>';
    echo '
        <a href="javascript:HighlightAll(\'debug.debugtext\')" class="admin_menu">' . $lang_cpg_debug_output['select_all'] . '</a>';
    echo '</td><td align="left" valign="middle" class="tableh2">';
    if (GALLERY_ADMIN_MODE) {
        echo '<span class="album_stat">' . $lang_cpg_debug_output['copy_and_paste_instructions'] . '</span>';
    }
    echo '</td></tr>';
    echo '<tr><td class="tableb" colspan="2">';
    echo '<textarea  rows="10" cols="60" class="debug_text" name="debugtext">';
    echo "USER: "******"USER DATA:";
    echo $debug_underline;
    print_r($USER_DATA);
    echo $debug_separate;
    echo "Queries:";
    echo $debug_underline;
    print_r($queries);
    echo $debug_separate;
    echo "GET :";
    echo $debug_underline;
    print_r($_GET);
    echo $debug_separate;
    echo "POST :";
    echo $debug_underline;
    print_r($_POST);
    echo $debug_separate;
    if (GALLERY_ADMIN_MODE) {
        echo "VERSION INFO :";
        echo $debug_underline;
        $version_comment = ' - OK';
        if (strcmp('4.0.0', phpversion()) == 1) {
            $version_comment = ' - your PHP version isn\'t good enough! Minimum requirements: 4.x';
        }
        echo 'PHP version: ' . phpversion() . $version_comment;
        echo $debug_underline;
        $version_comment = '';
        $mySqlVersion = cpg_phpinfo_mysql_version();
        if (strcmp('3.23.23', $mySqlVersion) == 1) {
            $version_comment = ' - your mySQL version isn\'t good enough! Minimum requirements: 3.23.23';
        }
        echo 'mySQL version: ' . $mySqlVersion . $version_comment;
        echo $debug_underline;
        echo 'Coppermine version: ';
        echo COPPERMINE_VERSION . '(' . COPPERMINE_VERSION_STATUS . ')';
        echo $debug_separate;
        //        error_reporting  (E_ERROR | E_WARNING | E_PARSE); // New maze's error report system
        if (function_exists('gd_info') == true) {
            echo 'Module: GD';
            echo $debug_underline;
            $gd_array = gd_info();
            foreach ($gd_array as $key => $value) {
                echo $key . ': ' . $value . "\n";
            }
            echo $debug_separate;
        } else {
            echo cpg_phpinfo_mod_output('gd', 'text');
        }
        echo cpg_phpinfo_mod_output('mysql', 'text');
        echo cpg_phpinfo_mod_output('zlib', 'text');
        echo 'Server restrictions (safe mode)?';
        echo $debug_underline;
        echo 'Directive | Local Value | Master Value';
        echo cpg_phpinfo_conf_output("safe_mode");
        echo cpg_phpinfo_conf_output("safe_mode_exec_dir");
        echo cpg_phpinfo_conf_output("safe_mode_gid");
        echo cpg_phpinfo_conf_output("safe_mode_include_dir");
        echo cpg_phpinfo_conf_output("safe_mode_exec_dir");
        echo cpg_phpinfo_conf_output("sql.safe_mode");
        echo cpg_phpinfo_conf_output("disable_functions");
        echo cpg_phpinfo_conf_output("file_uploads");
        echo cpg_phpinfo_conf_output("include_path");
        echo cpg_phpinfo_conf_output("open_basedir");
        echo $debug_separate;
        echo 'email';
        echo $debug_underline;
        echo 'Directive | Local Value | Master Value';
        echo cpg_phpinfo_conf_output("sendmail_from");
        echo cpg_phpinfo_conf_output("sendmail_path");
        echo cpg_phpinfo_conf_output("SMTP");
        echo cpg_phpinfo_conf_output("smtp_port");
        echo $debug_separate;
        echo 'Size and Time';
        echo $debug_underline;
        echo 'Directive | Local Value | Master Value';
        echo cpg_phpinfo_conf_output("max_execution_time");
        echo cpg_phpinfo_conf_output("max_input_time");
        echo cpg_phpinfo_conf_output("upload_max_filesize");
        echo cpg_phpinfo_conf_output("post_max_size");
        echo $debug_separate;
    }
    echo <<<EOT
Page generated in {$time} seconds - {$query_count} queries in {$total_query_time} seconds - Album set : {$ALBUM_SET}; Meta set: {$META_ALBUM_SET};
EOT;
    echo '</textarea>';
    echo '</td>';
    echo '</tr>';
    echo '</table>';
    echo '</td></tr>';
    if (GALLERY_ADMIN_MODE) {
        echo "<tr><td class=\"tablef\" colspan=\"2\">";
        echo "<a href=\"phpinfo.php\" class=\"admin_menu\">" . $lang_cpg_debug_output['phpinfo'] . "</a>";
        //          error_reporting  (E_ERROR | E_WARNING | E_PARSE); // New maze's error report system
        echo "</td></tr>";
    }
    // Maze's new error report system
    global $cpgdebugger;
    $report = $cpgdebugger->stop();
    if (is_array($report) && $CONFIG['debug_notice'] != 0) {
        echo '<tr><td class="tableh1" colspan="2">';
        echo '<b>';
        echo $lang_cpg_debug_output['notices'];
        echo '</b>';
        echo '</td></tr>';
        echo '<tr><td class="tableb" colspan="2">';
        foreach ($report as $file => $errors) {
            echo '<b>' . substr($file, $strstart) . '</b><ul>';
            foreach ($errors as $error) {
                echo "<li>{$error}</li>";
            }
            echo '</ul>';
        }
        echo '</td></tr>';
    }
    endtable();
    echo "</form>";
}
Example #5
0
/**
 * cpg_debug_output()
 *
 * defined new debug_output function here in functions.inc.php instead of theme.php with different function names to avoid incompatibilities with users not updating their themes as required. Advanced info is only output if (GALLERY_ADMIN_MODE == TRUE)
 *
 **/
function cpg_debug_output()
{
    global $USER, $USER_DATA, $META_ALBUM_SET, $ALBUM_SET, $CONFIG, $cpg_time_start, $query_stats, $queries, $lang_cpg_debug_output, $CPG_PHP_SELF, $superCage, $CPG_PLUGINS;
    $time_end = cpgGetMicroTime();
    $time = round($time_end - $cpg_time_start, 3);
    $query_count = count($query_stats);
    $total_query_time = array_sum($query_stats);
    $debug_underline = '&#0010;------------------&#0010;';
    $debug_separate = '&#0010;==========================&#0010;';
    $debug_toggle_link = ' <a href="javascript:;" onclick="show_section(\'debug_output_rows\');" class="admin_menu" id="debug_output_toggle" style="display:none;">' . $lang_cpg_debug_output['show_hide'] . '</a>';
    echo '<form name="debug" action="' . $CPG_PHP_SELF . '" id="debug">';
    starttable('100%', $lang_cpg_debug_output['debug_info'] . $debug_toggle_link, 2);
    //echo '<div name="debug_output_rows" id="debug_output_rows" style="display:block;">';
    echo '<tr><td align="center" valign="top" width="100%" colspan="2">';
    echo '<table border="0" cellspacing="0" cellpadding="0" width="100%" id="debug_output_rows">';
    echo '<tr><td align="center" valign="middle" class="tableh2" width="100">';
    echo '<script language="javascript" type="text/javascript">
<!--

// only hide the debug_output if the user is capable to display it, i.e. if JavaScript is enabled. If JavaScript is off, debug_output will be displayed and the toggle will remain invisible (as it would not do anything anyway with JS off)
addonload("document.getElementById(\'debug_output_rows\').style.display = \'none\'");
addonload("document.getElementById(\'debug_output_toggle\').style.display = \'inline\'");
//-->
</script>';
    echo <<<EOT
        <script type="text/javascript">
            document.write('<a href="javascript:HighlightAll(\\'debug.debugtext\\')" class="admin_menu">');
            document.write("{$lang_cpg_debug_output['select_all']}");
            document.write('</a>');
        </script>
        </td><td align="left" valign="middle" class="tableh2">
EOT;
    if (GALLERY_ADMIN_MODE) {
        echo '<span class="album_stat">' . $lang_cpg_debug_output['copy_and_paste_instructions'] . '</span>';
    }
    echo '</td></tr>';
    echo '<tr><td class="tableb" colspan="2">';
    echo '<textarea  rows="10" cols="60" class="debug_text" name="debugtext">';
    echo "USER: "******"USER DATA:";
    echo $debug_underline;
    print_r($USER_DATA);
    echo $debug_separate;
    echo "Queries:";
    echo $debug_underline;
    print_r($queries);
    echo $debug_separate;
    echo "GET :";
    echo $debug_underline;
    print_r($superCage->get->_source);
    echo $debug_separate;
    echo "POST :";
    echo $debug_underline;
    print_r($superCage->post->_source);
    echo $debug_separate;
    echo "COOKIE :";
    echo $debug_underline;
    print_r($superCage->cookie->_source);
    echo $debug_separate;
    if ($superCage->cookie->keyExists('PHPSESSID')) {
        echo "SESSION :";
        echo $debug_underline;
        session_id($superCage->cookie->getAlnum('PHPSESSID'));
        session_start();
        print_r($_SESSION);
        echo $debug_separate;
    }
    if (GALLERY_ADMIN_MODE) {
        echo "VERSION INFO :";
        echo $debug_underline;
        $version_comment = ' - OK';
        if (strcmp('4.2.0', phpversion()) == 1) {
            $version_comment = ' - your PHP version isn\'t good enough! Minimum requirements: 4.2.0';
        }
        echo 'PHP version: ' . phpversion() . $version_comment;
        echo "\n";
        $version_comment = ' - OK';
        $mySqlVersion = cpg_phpinfo_mysql_version();
        if (strcmp('3.23.23', $mySqlVersion) == 1) {
            $version_comment = ' - your MySQL version isn\'t good enough! Minimum requirements: 3.23.23';
        }
        echo 'MySQL version: ' . $mySqlVersion . $version_comment;
        echo "\n";
        echo 'Coppermine version: ';
        echo COPPERMINE_VERSION . '(' . COPPERMINE_VERSION_STATUS . ')';
        echo "\n";
        echo $debug_separate;
        //        error_reporting  (E_ERROR | E_WARNING | E_PARSE); // New maze's error report system
        if (function_exists('gd_info') == true) {
            echo 'Module: GD';
            echo $debug_underline;
            $gd_array = gd_info();
            foreach ($gd_array as $key => $value) {
                echo $key . ': ' . $value . "\n";
            }
            echo $debug_separate;
        } else {
            echo cpg_phpinfo_mod_output('gd', 'text');
        }
        echo 'Key config settings';
        echo $debug_underline;
        echo cpg_config_output("allow_private_albums");
        echo cpg_config_output("cookie_name");
        echo cpg_config_output("cookie_path");
        echo cpg_config_output("ecards_more_pic_target");
        echo cpg_config_output("impath");
        echo cpg_config_output("lang");
        echo cpg_config_output("language_fallback");
        echo cpg_config_output("main_page_layout");
        echo cpg_config_output("silly_safe_mode");
        echo cpg_config_output("smtp_host");
        echo cpg_config_output("theme");
        echo cpg_config_output("thumb_method");
        echo $debug_separate;
        echo 'Plugins';
        echo $debug_underline;
        foreach ($CPG_PLUGINS as $plugin) {
            echo 'Plugin: ' . $plugin->name . "\n";
            echo 'Actions: ' . implode(', ', array_keys($plugin->actions)) . "\n";
            echo 'Filters: ' . implode(', ', array_keys($plugin->filters));
            echo $debug_underline;
        }
        echo $debug_separate;
        echo 'Server restrictions';
        echo $debug_underline;
        echo 'Directive | Local Value | Master Value';
        echo cpg_phpinfo_conf_output("safe_mode");
        echo cpg_phpinfo_conf_output("safe_mode_exec_dir");
        echo cpg_phpinfo_conf_output("safe_mode_gid");
        echo cpg_phpinfo_conf_output("safe_mode_include_dir");
        echo cpg_phpinfo_conf_output("safe_mode_exec_dir");
        echo cpg_phpinfo_conf_output("sql.safe_mode");
        echo cpg_phpinfo_conf_output("disable_functions");
        echo cpg_phpinfo_conf_output("file_uploads");
        echo cpg_phpinfo_conf_output("include_path");
        echo cpg_phpinfo_conf_output("open_basedir");
        echo cpg_phpinfo_conf_output("allow_url_fopen");
        echo "\n{$debug_separate}";
        echo 'Resource limits';
        echo $debug_underline;
        echo 'Directive | Local Value | Master Value';
        echo cpg_phpinfo_conf_output("max_execution_time");
        echo cpg_phpinfo_conf_output("max_input_time");
        echo cpg_phpinfo_conf_output("upload_max_filesize");
        echo cpg_phpinfo_conf_output("post_max_size");
        echo cpg_phpinfo_conf_output("memory_limit");
        echo "\n{$debug_separate}";
    }
    echo <<<EOT
Page generated in {$time} seconds - {$query_count} queries in {$total_query_time} seconds - Album set : {$ALBUM_SET}; Meta set: {$META_ALBUM_SET};
EOT;
    echo '</textarea>';
    echo '</td>';
    echo '</tr>';
    echo '</table>';
    echo '</td></tr>';
    if (GALLERY_ADMIN_MODE) {
        echo "<tr><td class=\"tablef\" colspan=\"2\">";
        echo "<a href=\"phpinfo.php\" class=\"admin_menu\">" . $lang_cpg_debug_output['phpinfo'] . "</a>";
        //          error_reporting  (E_ERROR | E_WARNING | E_PARSE); // New maze's error report system
        echo "</td></tr>";
    }
    // Maze's new error report system
    global $cpgdebugger;
    $report = $cpgdebugger->stop();
    if (is_array($report) && $CONFIG['debug_notice'] != 0) {
        echo '<tr><td class="tableh1" colspan="2">';
        echo '<b>';
        echo $lang_cpg_debug_output['notices'];
        echo '</b>';
        echo '</td></tr>';
        echo '<tr><td class="tableb" colspan="2">';
        foreach ($report as $file => $errors) {
            echo '<b>' . substr($file, $strstart) . '</b><ul>';
            foreach ($errors as $error) {
                echo "<li>{$error}</li>";
            }
            echo '</ul>';
        }
        echo '</td></tr>';
    }
    endtable();
    echo "</form>";
}