root/trunk/plog-admin/plog-themes.php

Revision 588, 4.1 KB (checked in by kimparsell, 8 weeks ago)

+ Minor markup changes for install/upgrade process.
+ Minor admin section changes to make action notices consistent.
+ Miscellaneous cleanup.

Line 
1<?php
2// load configuration variables from database, plog-globals, & plog-includes/plog-functions
3require_once(dirname(dirname(__FILE__))."/plog-load-config.php");
4require(PLOGGER_DIR."plog-admin/plog-admin.php");
5
6global $inHead, $config, $thumbnail_config;
7
8function read_dir($path){
9
10    static $dir_arr = array () ;
11
12    $handle = opendir($path);
13
14    while ($file = readdir($handle)) {
15        if (is_dir($path.$file) && substr($file,0,1) != '.') {
16            $dir_arr[] = $path . $file . "/" ;
17        };
18    }
19
20    return $dir_arr ;
21
22}
23
24$output = "\n\t<h1>" . plog_tr("Manage Themes") . "</h1>";
25
26// what is this?
27//$output.= "<p>$theme_url</p>";
28
29$theme_dir = $config['basedir'] . 'plog-content/themes/';
30
31// scan list of folders within theme directory
32$theme_list = read_dir($theme_dir);
33
34// activate new theme by setting configuration dir
35if (isset($_REQUEST['activate'])) {
36    // insert into database
37    $new_theme_dir = basename($_REQUEST["activate"]);
38    $metafile = $config['basedir'] . 'plog-content/themes/' . $new_theme_dir . '/meta.php';
39    if (file_exists($metafile)) {
40        include($metafile);
41        $sql = 'UPDATE '.TABLE_PREFIX.'config SET `theme_dir` = \''.$new_theme_dir.'\'';
42        $name = $theme_name . ' ' . $version;
43        if (mysql_query($sql)) {
44            $output .= "\n\n\t\t" . '<p class="actions">' . sprintf(plog_tr("Activated New Theme <strong>%s</strong>"),$name). '</p>';
45        } else {
46            $output .= "\n\n\t\t" . '<p class="errors">' . plog_tr("Error Activating Theme!") . '</p>';
47        }
48
49        // update config variable if page doesn't refresh
50        $config["theme_dir"] = $new_theme_dir;
51    } else {
52        $output .= "\n\n\t\t" . '<p class="errors">' . plog_tr("No such theme") . '</p>';
53    }
54}
55
56// Output table header
57$output .= "\n\n\t\t" . '<table id="theme-table" cellpadding="1" width="100%">
58            <tr class="header">
59                <th class="table-header-left">' . plog_tr("Preview") . '</th>
60                <th class="table-header-middle">' . plog_tr("Theme") . '</th>
61                <th class="table-header-middle">' . plog_tr("Description") . '</th>
62                <th class="table-header-middle">' . plog_tr("Author") . '</th>
63                <th class="table-header-right">' . plog_tr("Status") . '</th>
64            </tr>' . "\n";
65$counter = 0;
66
67foreach($theme_list as $theme_folder_name) {
68    $meta_file = $theme_folder_name . "meta.php";
69
70    $theme_folder_basename = basename($theme_folder_name);
71
72    // only display theme as available if meta information exists for it
73    if (is_file($meta_file)) {
74
75        // pull in meta information
76        include($meta_file);
77
78        if ($counter%2 == 0) $table_row_color = "color-1";
79        else $table_row_color = "color-2";
80
81        // generate small preview thumb, update thumb if preview.png has been updated
82        $timestamp = @filemtime($theme_dir . $theme_folder_basename . "/preview.png");
83        $thumbnail_config[THUMB_THEME]['timestamp'] = $timestamp;
84        $preview_thumb = generate_thumb($theme_folder_name . "preview.png", $theme_name, THUMB_THEME);
85
86        // generate large Lightbox preview thumb, update thumb if preview.png has been updated
87        $thumbnail_config[THUMB_LARGE]['timestamp'] = $timestamp;
88        $thumbnail_config[THUMB_LARGE]['disabled'] = 0;
89        $preview_thumb_large = generate_thumb($theme_folder_name . "preview.png", $theme_name, THUMB_LARGE);
90
91        // start a new table row (alternating colors)
92        if ($config["theme_dir"] == $theme_folder_basename)
93            $output .= "\t\t\t<tr class=\"activated\">\n";
94        else
95            $output .= "\t\t\t<tr class=\"$table_row_color\">\n";
96
97        $output .= "\t\t\t\t<td>";
98
99        if ($preview_thumb)
100            $output .= "<div class=\"img-shadow\"><a rel=\"lightbox\" href=\"$preview_thumb_large\"><img src=\"$preview_thumb\" alt=\"$theme_name\" /></a></div>";
101
102        $output .= "</td>
103                <td><strong>$theme_name</strong><br /> Version $version</td>
104                <td>$description</td>
105                <td><a href=\"$url\">$author</a></td>\n";
106
107        if ($config["theme_dir"] == $theme_folder_basename)
108        $output .= "\t\t\t\t<td>" .plog_tr("Active Theme") . "</td>\n";
109        else
110        $output .= "\t\t\t\t<td><a href=\"${_SERVER['PHP_SELF']}?activate=$theme_folder_basename\">" . plog_tr('Activate') . "</a></td>\n";
111
112        $output .= "\t\t\t</tr>\n";
113
114        $counter++;
115    }
116
117}
118
119$output .= "\t\t\t<tr class=\"footer\">
120                <td colspan=\"5\" style=\"padding: 6px;\"></td>
121            </tr>
122        </table>\n";
123
124display($output, "themes");
125
126?>
Note: See TracBrowser for help on using the browser.