Dotclear

source: plugins/popularityContest/index.php @ 2295

Revision 2295, 6.5 KB checked in by Moe, 14 years ago (diff)

Popularity Contest 1.4 :

  • added data in XML file :
    • display plugins URLs
    • display global results
  • added CSS rules, from the popcon website
  • make xml/ directory
  • switched to GPL v2
Line 
1<?php 
2# ***** BEGIN LICENSE BLOCK *****
3#
4# This file is part of Popularity Contest, a plugin for Dotclear 2
5# Copyright (C) 2007,2009,2010 Moe (http://gniark.net/)
6#
7# Popularity Contest is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License v2.0
9# as published by the Free Software Foundation.
10#
11# Popularity Contest is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public
17# License along with this program. If not, see
18# <http://www.gnu.org/licenses/>.
19#
20# Icon (icon.png) and images are from Silk Icons :
21# <http://www.famfamfam.com/lab/icons/silk/>
22#
23# ***** END LICENSE BLOCK *****
24
25if (!defined('DC_CONTEXT_ADMIN')) {exit;}
26
27l10n::set(dirname(__FILE__).'/locales/'.$_lang.'/admin');
28
29$settings =& $core->blog->settings;
30
31$msg = '';
32$tab = 'popularityContest';
33$tab = 'results';
34
35$time_interval_last_try =
36     $_SERVER['REQUEST_TIME'] - $settings->popularityContest_last_report;
37$can_send_report = ($time_interval_last_try >= (30*60));
38
39$hidden_plugins = array();
40if (strlen($settings->popularityContest_hidden_plugins) > 0)
41{
42     $hidden_plugins = unserialize(base64_decode($settings->popularityContest_hidden_plugins));
43}
44if (!is_array($hidden_plugins)) {$hidden_plugins = array();}
45
46require_once(dirname(__FILE__).'/php-xhtml-table/class.table.php');
47require_once(dirname(__FILE__).'/inc/lib.popularityContest.php');
48
49$popularityContest_time_interval = 
50     (is_int($settings->popularityContest_time_interval)) ? 
51          $settings->popularityContest_time_interval : (24*3600);
52$popularityContest_sent = false;
53
54# actions
55if (!empty($_POST['saveconfig']))
56{
57     try
58     {
59          $settings->setNameSpace('popularitycontest');
60          # Time interval in seconds between sends to Popularity Contest
61          $popularityContest_time_interval =
62               (empty($_POST['popularityContest_time_interval']))
63               ? 604800:abs($_POST['popularityContest_time_interval']);
64          $settings->put('popularityContest_time_interval',
65               $popularityContest_time_interval,'integer',
66               'Time interval in seconds between submissions to Popularity Contest',
67               true,true);
68          # Hide plugins
69          $popularityContest_hidden_plugins =
70               (!empty($_POST['hidden_plugins'])) 
71               ? base64_encode(serialize($_POST['hidden_plugins']))
72               : base64_encode(serialize(array('')));
73          $settings->put('popularityContest_hidden_plugins',
74               $popularityContest_hidden_plugins,'text','Hidden plugins',
75               true,true);
76          $hidden_plugins = $_POST['hidden_plugins'];
77
78          http::redirect($p_url.'&saveconfig=1');
79     }
80     catch (Exception $e)
81     {
82          $core->error->add($e->getMessage());
83     }
84}
85elseif (isset($_POST['send_report']))
86{
87     if (!$can_send_report)
88     {
89          http::redirect($p_url.'&wait=1');
90     }
91     elseif (popularityContest::send() === true)
92     {
93          http::redirect($p_url.'&report_sent=1');
94     }
95     else
96     {
97          http::redirect($p_url.'&wait=1');
98     }
99}
100
101if (isset($_GET['saveconfig']))
102{
103     $msg = __('Configuration successfully updated.');
104     $tab = 'settings';
105}
106elseif (isset($_GET['report_sent']))
107{
108     $msg = __('Report successfully sent.');
109}
110elseif (isset($_GET['wait']))
111{
112     $core->error->add(sprintf(
113          __('please wait %s before sending a report'),
114          popularityContest::getDiff((30*60)- $time_interval_last_try)));
115}
116?>
117<html>
118<head>
119  <title><?php echo __('Popularity Contest'); ?></title>
120  <?php 
121          echo(dcPage::jsPageTabs($tab).
122          dcPage::jsLoad('js/_posts_list.js').
123          dcPage::jsLoad('js/filter-controls.js'));
124  ?>
125  <style type="text/css">
126     /*tr:hover {background:#eee none;}*/
127          .icon {text-align:center;}
128          .default {background:transparent url(/images/template/default.png) repeat;}
129          .popularityContest {background:transparent url(/images/template/popularityContest.png) repeat;}
130  </style>
131</head>
132<body>
133
134<h2><?php echo __('Popularity Contest'); ?></h2>
135
136<?php 
137     if (!empty($msg)) {echo '<p class="message">'.$msg.'</p>';}
138     
139     if (is_int($settings->popularityContest_last_report))
140     {
141          printf('<h3>'.__('Last successful report: %s ago').'</h3>',
142               popularityContest::getDiff(
143               $_SERVER['REQUEST_TIME']-$settings->popularityContest_last_report));
144     }
145     if (is_int($settings->popularityContest_last_try))
146     {
147          printf('<h3>'.__('Last try: %s ago').'</h3>',
148               popularityContest::getDiff(
149               $_SERVER['REQUEST_TIME']-$settings->popularityContest_last_try));
150     }
151?>
152
153<div class="multi-part" id="popularityContest"
154     title="<?php echo __('Popularity Contest'); ?>">
155     <p><?php echo(__('This plugin only send the following informations to Dotclear Popularity Contest:')); ?></p>
156     <ul>
157          <?php 
158          $infos = array(
159               __('the names of installed and activated plugins'),
160               sprintf(__('the value of md5(DC_ADMIN_URL) (%s) identify the Dotclear installation with an unique and anonym hash'),
161                    '<strong>'.md5(DC_ADMIN_URL).'</strong>'),
162               sprintf(__('the Dotclear version (%s)'),
163                    '<strong>'.DC_VERSION.'</strong>')
164          );
165          foreach ($infos as $k)
166          {
167               echo('<li>'.$k.'</li>');
168          }
169          ?>
170     </ul>
171
172     <p><?php echo(__('In the settings, you can hide some plugins and they will be ignored by Dotclear Popularity Contest.')); ?></p>
173     <form method="post" action="<?php echo(http::getSelfURI()); ?>">
174          <p><input type="submit" name="send_report"value="<?php echo
175               __('Send a report to Dotclear Popularity Contest'); ?>" /></p>
176          <p><?php echo $core->formNonce(); ?></p>
177     </form>
178     <h3><?php echo(__('Installed plugins:')); ?></h3>
179     <?php echo(popularityContest::getPluginsTable()); ?>
180</div>
181
182<div class="multi-part" id="settings" title="<?php echo __('settings'); ?>">
183     <form method="post" action="<?php echo(http::getSelfURI()); ?>">
184          <fieldset>
185               <legend><?php echo(__('Popularity Contest')); ?></legend>
186               <p>
187                    <label for="popularityContest_time_interval">
188                         <?php echo(__('Send a report:')); ?>
189                    <?php echo(form::combo('popularityContest_time_interval',
190                     popularityContest::getComboOptions(),
191                     $popularityContest_time_interval)); ?>
192                    </label>
193               </p>
194          </fieldset>
195
196          <h2><?php echo(__('Hide plugins:')); ?></h2>
197          <?php echo(popularityContest::getPluginsTable(true)); ?>
198          <p class="col checkboxes-helpers"></p>
199          <p><?php echo $core->formNonce(); ?></p>
200          <p><input type="submit" name="saveconfig" value="<?php echo __('Save configuration'); ?>" /></p>
201     </form>
202</div>
203
204<div class="multi-part" id="results" title="<?php echo __('results'); ?>">
205     <p><a href="http://popcon.gniark.net/"><?php echo(__('Click here to see results.')); ?></a></p>
206     <h3><?php echo(__('Plugins:')); ?></h3>
207     <?php echo(popularityContest::getResultsTable()); ?>
208</div>
209
210</body>
211</html>
Note: See TracBrowser for help on using the repository browser.

Sites map