| 1 | <?php |
|---|
| 2 | // load configuration variables from database, plog-globals, & plog-includes/plog-functions |
|---|
| 3 | require_once(dirname(dirname(__FILE__)).'/plog-load-config.php'); |
|---|
| 4 | require(PLOGGER_DIR.'plog-admin/plog-admin.php'); |
|---|
| 5 | |
|---|
| 6 | global $config, $thumbnail_config; |
|---|
| 7 | |
|---|
| 8 | function read_dir($path) { |
|---|
| 9 | static $dir_arr = array (); |
|---|
| 10 | $handle = opendir($path); |
|---|
| 11 | |
|---|
| 12 | while ($file = readdir($handle)) { |
|---|
| 13 | if (is_dir($path.$file) && substr($file, 0, 1) != '.') { |
|---|
| 14 | $dir_arr[] = $path.$file.'/' ; |
|---|
| 15 | } |
|---|
| 16 | } |
|---|
| 17 | |
|---|
| 18 | return $dir_arr; |
|---|
| 19 | |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | function check_theme_token($theme) { |
|---|
| 23 | global $config; |
|---|
| 24 | $content = ''; |
|---|
| 25 | |
|---|
| 26 | $comment_file = $config['basedir'].'plog-content/themes/'.$theme.'/comments.php'; |
|---|
| 27 | $content = implode('', file($comment_file)); |
|---|
| 28 | if (strpos($content, 'plogger_get_form_token') === false) { |
|---|
| 29 | return false; |
|---|
| 30 | } |
|---|
| 31 | return true; |
|---|
| 32 | } |
|---|
| 33 | |
|---|
| 34 | $output = "\n\t" . '<h1>'.plog_tr('Manage Themes').'</h1>'; |
|---|
| 35 | |
|---|
| 36 | $theme_dir = $config['basedir'].'plog-content/themes/'; |
|---|
| 37 | |
|---|
| 38 | // scan list of folders within theme directory |
|---|
| 39 | $theme_list = read_dir($theme_dir); |
|---|
| 40 | sort($theme_list); |
|---|
| 41 | |
|---|
| 42 | // activate new theme by setting configuration dir |
|---|
| 43 | if (isset($_REQUEST['activate'])) { |
|---|
| 44 | // insert into database |
|---|
| 45 | $new_theme_dir = basename($_REQUEST['activate']); |
|---|
| 46 | $metafile = $config['basedir'].'plog-content/themes/'.$new_theme_dir.'/meta.php'; |
|---|
| 47 | |
|---|
| 48 | if (file_exists($metafile)) { |
|---|
| 49 | include($metafile); |
|---|
| 50 | $sql = 'UPDATE '.PLOGGER_TABLE_PREFIX.'config SET `theme_dir` = \''.$new_theme_dir.'\''; |
|---|
| 51 | $name = $theme_name.' '.$version; |
|---|
| 52 | if (mysql_query($sql)) { |
|---|
| 53 | $output .= "\n\n\t\t" . '<p class="success">'.sprintf(plog_tr('Activated new theme %s'), '<strong>'.$name.'</strong>').'</p>'; |
|---|
| 54 | } else { |
|---|
| 55 | $output .= "\n\n\t\t" . '<p class="errors">'.plog_tr('Error activating theme').'!</p>'; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | // update config variable if page doesn't refresh |
|---|
| 59 | $config['theme_dir'] = $new_theme_dir; |
|---|
| 60 | } else { |
|---|
| 61 | $output .= "\n\n\t\t" . '<p class="errors">'.plog_tr('No such theme').'</p>'; |
|---|
| 62 | } |
|---|
| 63 | } |
|---|
| 64 | |
|---|
| 65 | $output .= "\n\n\t\t" . '<div class="info"> |
|---|
| 66 | |
|---|
| 67 | <p class="no-margin-top">'.plog_tr('Themes allow you to change the appearance of your Plogger gallery. New themes should be uploaded to the <span style="color: #800; font-weight: bold;">/plog-content/themes/</span> directory.').'</p> |
|---|
| 68 | |
|---|
| 69 | <p class="no-margin-bottom">'.plog_tr('To switch to a different theme, click the <span style="color: #800; font-weight: bold;">Activate</span> link in the <strong>Status</strong> column. You will need to reload your gallery page to see the changes.').'</p> |
|---|
| 70 | |
|---|
| 71 | </div><!-- /info-->'; |
|---|
| 72 | |
|---|
| 73 | // Output table header |
|---|
| 74 | $output .= "\n\n\t\t" . '<table id="theme-table" cellpadding="3" cellspacing="0" width="100%"> |
|---|
| 75 | <tr class="header"> |
|---|
| 76 | <th class="table-header-left align-center width-175">'.plog_tr('Preview').'</th> |
|---|
| 77 | <th class="table-header-middle align-left width-100">'.plog_tr('Theme').'</th> |
|---|
| 78 | <th class="table-header-middle align-left">'.plog_tr('Description').'</th> |
|---|
| 79 | <th class="table-header-middle align-left width-100">'.plog_tr('Author').'</th> |
|---|
| 80 | <th class="table-header-right align-left width-100">'.plog_tr('Status').'</th> |
|---|
| 81 | </tr>'; |
|---|
| 82 | $counter = 0; |
|---|
| 83 | |
|---|
| 84 | foreach($theme_list as $theme_folder_name) { |
|---|
| 85 | $meta_file = $theme_folder_name.'meta.php'; |
|---|
| 86 | |
|---|
| 87 | $theme_folder_basename = basename($theme_folder_name); |
|---|
| 88 | |
|---|
| 89 | // only display theme as available if meta information exists for it |
|---|
| 90 | if (is_file($meta_file)) { |
|---|
| 91 | // pull in meta information |
|---|
| 92 | include($meta_file); |
|---|
| 93 | |
|---|
| 94 | if ($counter%2 == 0) { |
|---|
| 95 | $table_row_color = 'color-1'; |
|---|
| 96 | } else { |
|---|
| 97 | $table_row_color = 'color-2'; |
|---|
| 98 | } |
|---|
| 99 | |
|---|
| 100 | // generate small preview thumb, update thumb if preview.png has been updated |
|---|
| 101 | $timestamp = @filemtime($theme_dir.$theme_folder_basename.'/preview.png'); |
|---|
| 102 | $thumbnail_config[THUMB_THEME]['timestamp'] = $timestamp; |
|---|
| 103 | $preview_thumb = generate_thumb($theme_folder_name.'preview.png', $theme_name, THUMB_THEME); |
|---|
| 104 | |
|---|
| 105 | // generate large Lightbox preview thumb, update thumb if preview.png has been updated |
|---|
| 106 | $thumbnail_config[THUMB_LARGE]['timestamp'] = $timestamp; |
|---|
| 107 | $thumbnail_config[THUMB_LARGE]['disabled'] = 0; |
|---|
| 108 | $preview_thumb_large = generate_thumb($theme_folder_name.'preview.png', $theme_name, THUMB_LARGE); |
|---|
| 109 | |
|---|
| 110 | // start a new table row (alternating colors) |
|---|
| 111 | if ($config['theme_dir'] == $theme_folder_basename) { |
|---|
| 112 | $table_class = 'activated'; |
|---|
| 113 | } else { |
|---|
| 114 | $table_class = $table_row_color; |
|---|
| 115 | } |
|---|
| 116 | $output .= "\n\t\t\t" . '<tr class="'.$table_class.'">'; |
|---|
| 117 | |
|---|
| 118 | $output .= "\n\t\t\t\t" . '<td class="width-175">'; |
|---|
| 119 | |
|---|
| 120 | if ($preview_thumb) { |
|---|
| 121 | $output .= '<div class="img-shadow"><a rel="lightbox" href="'.$preview_thumb_large.'"><img src="'.$preview_thumb.'" alt="'.$theme_name.'" /></a></div>'; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | $output .= '</td> |
|---|
| 125 | <td class="align-left width-100"><strong>'.$theme_name.'</strong><br />Version '.$version.'</td> |
|---|
| 126 | <td style="padding-right: 50px;">'.$description.'<br />• '.plog_tr('Released under the').' '.$license.'.</td> |
|---|
| 127 | <td class="align-left width-100"><a href="'.$url.'">'.$author.'</a></td>'; |
|---|
| 128 | |
|---|
| 129 | if ($config['theme_dir'] == $theme_folder_basename) { |
|---|
| 130 | $output .= "\n\t\t\t\t" . '<td class="active width-100">'.plog_tr('Current').'</td>'; |
|---|
| 131 | } else { |
|---|
| 132 | $output .= "\n\t\t\t\t" . '<td class="width-100"><a href="'.$config['gallery_url'].'plog-admin/plog-themes.php?activate='.$theme_folder_basename.'">'.plog_tr('Activate').'</a></td>'; |
|---|
| 133 | } |
|---|
| 134 | |
|---|
| 135 | $output .= "\n\t\t\t" . '</tr>'; |
|---|
| 136 | |
|---|
| 137 | if (!check_theme_token($theme_folder_basename)) { |
|---|
| 138 | $output .= "\n\t\t\t" . '<tr class="'.$table_class.'" id="'.$theme_folder_basename.'-error"> |
|---|
| 139 | <td class="align-left" colspan="5"> |
|---|
| 140 | <div class="errors"> |
|---|
| 141 | <p class="no-margin-top no-margin-bottom">'.sprintf(plog_tr('The spam token could not be found in this theme. Please include the code %s between the opening %s tag and the closing %s tag in the theme file %s'), ' <span style="color: #264e75; font-weight: bold;"><?php plogger_get_spam_token(); ?></span>', '<form>', '</form>', '<strong>'.'plog-content/themes/'.$theme_folder_basename.'/comments.php</strong>').'</p> |
|---|
| 142 | </div> |
|---|
| 143 | </td> |
|---|
| 144 | </tr>'; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | $counter++; |
|---|
| 148 | } |
|---|
| 149 | |
|---|
| 150 | } |
|---|
| 151 | |
|---|
| 152 | $output .= "\n\t\t\t" . '<tr class="footer"> |
|---|
| 153 | <td colspan="5" style="padding: 1px;"> </td> |
|---|
| 154 | </tr> |
|---|
| 155 | </table>' . "\n"; |
|---|
| 156 | |
|---|
| 157 | display($output, 'themes'); |
|---|
| 158 | |
|---|
| 159 | ?> |
|---|