add('name', PLUGIN_POLL_TITLE); $propbag->add('description', PLUGIN_POLL_TITLE_BLAHBLAH); $propbag->add('event_hooks', array( 'backend_sidebar_entries_event_display_poll' => true, 'backend_sidebar_entries' => true, 'entries_header' => true, 'entry_display' => true, 'genpage' => true)); $propbag->add('configuration', array('permalink', "articleformat", "pagetitle", "articleformattitle")); $propbag->add('author', 'Garvin Hicking, Matthias Mees'); $propbag->add('groups', array('STATISTICS')); $propbag->add('version', '2.15'); $propbag->add('requirements', array( 'serendipity' => '0.8', 'smarty' => '2.6.7', 'php' => '4.1.0' )); $propbag->add('stackable', false); $this->dependencies = array('serendipity_plugin_pollbox' => 'keep'); } function introspect_config_item($name, &$propbag) { global $serendipity; switch($name) { case 'permalink': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_POLL_PERMALINK); $propbag->add('description', PLUGIN_POLL_PERMALINK_BLAHBLAH); $propbag->add('default', $serendipity['rewrite'] != 'none' ? $serendipity['serendipityHTTPPath'] . 'pages/poll.html' : $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?/pages/poll.html'); break; case 'pagetitle': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_POLL_PAGETITLE); $propbag->add('description', ''); $propbag->add('default', PLUGIN_POLL_TITLE); break; case 'articleformat': $propbag->add('type', 'boolean'); $propbag->add('name', PLUGIN_POLL_ARTICLEFORMAT); $propbag->add('description', PLUGIN_POLL_ARTICLEFORMAT_BLAHBLAH); $propbag->add('default', 'true'); break; case 'articleformattitle': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_POLL_ARTICLEFORMAT_PAGETITLE); $propbag->add('description', PLUGIN_POLL_ARTICLEFORMAT_PAGETITLE_BLAHBLAH); $propbag->add('default', $serendipity['blogTitle'] . ' :: ' . $this->pagetitle); break; default: return false; } return true; } function setupDB() { global $serendipity; $built = $this->get_config('db_built', null); if (empty($built) && !defined('PLUGIN_POLL_UPGRADE_DONE')) { serendipity_db_schema_import("CREATE TABLE {$serendipity['dbPrefix']}polls ( id {AUTOINCREMENT} {PRIMARY}, title varchar(255) not null default '', content text, active int(1) default '1', votes int(4) default '0', timestamp int(10) {UNSIGNED} default null);"); serendipity_db_schema_import("CREATE TABLE {$serendipity['dbPrefix']}polls_options ( id {AUTOINCREMENT} {PRIMARY}, pollid int(10) {UNSIGNED}, title varchar(255) not null default '', votes int(4) default '0', timestamp int(10) {UNSIGNED} default null);"); serendipity_db_schema_import("CREATE INDEX pollidx ON {PREFIX}polls_options (pollid);"); $this->set_config('db_built', '1'); @define('PLUGIN_POLL_UPGRADE_DONE', true); // No further static pages may be called! } } function &get_polldata($key, $default = null) { if (isset($this->poll[$key])) { return $this->poll[$key]; } else { return $default; } } function show() { global $serendipity; if ($this->selected()) { if (!headers_sent()) { header('HTTP/1.0 200'); header('Status: 200'); } if (!is_object($serendipity['smarty'])) { serendipity_smarty_init(); } $_ENV['staticpage_pagetitle'] = preg_replace('@[^a-z0-9]@i', '_',$this->get_config('pagetitle')); $serendipity['smarty']->assign('staticpage_pagetitle', $_ENV['staticpage_pagetitle']); echo '
'; if (serendipity_db_bool($this->get_config('articleformat'))) { echo '

' . $this->get_config('articleformattitle') . '

'; } echo '

' . $this->get_polldata('title') . '

'; if (serendipity_db_bool($this->get_config('articleformat'))) { echo '
'; } echo '
'; if (isset($serendipity['GET']['voteId'])) { serendipity_common_pollbox::poll($serendipity['GET']['voteId']); } else { serendipity_common_pollbox::poll(); } echo '
'; echo '
'; PLUGIN_POLL_ARCHIVE . '
'; $polls =& $this->fetchPolls(); if (is_array($polls)) { foreach($polls AS $poll) { echo '' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($poll['title']) : htmlspecialchars($poll['title'], ENT_COMPAT, LANG_CHARSET)) . ', ' . serendipity_strftime(DATE_FORMAT_ENTRY, $poll['timestamp']) . '
'; } } echo '
'; if (serendipity_db_bool($this->get_config('articleformat'))) { echo '
'; } echo '
'; } } function selected() { global $serendipity; if ($serendipity['GET']['subpage'] == 'votearchive' || $serendipity['GET']['subpage'] == $this->get_config('permalink') || $serendipity['GET']['subpage'] == $this->get_config('pagetitle')) { return true; } return false; } function fetchPolls() { global $serendipity; return serendipity_db_query("SELECT title, active, timestamp, id FROM {$serendipity['dbPrefix']}polls ORDER BY timestamp DESC"); } function insertPoll() { global $serendipity; $now = time(); $q = serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}polls ( title, active, timestamp ) VALUES ( '" . serendipity_db_escape_string($serendipity['POST']['currentPoll']['title']) . "', 0, '" . $now . "')"); if ($q) { return serendipity_db_insert_id('polls', 'id'); } } function updatePoll($id) { global $serendipity; $q = serendipity_db_query("UPDATE {$serendipity['dbPrefix']}polls SET title = '" . serendipity_db_escape_string($serendipity['POST']['currentPoll']['title']) . "' WHERE id = " . (int)$id); return $q; } function addOption($pollid, $data) { global $serendipity; $q = serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}polls_options ( pollid, title, votes ) VALUES ( " . (int)$pollid . ", '" . serendipity_db_escape_string($data['title']) . "', 0)"); return $q; } function deleteOption($optid) { global $serendipity; return serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}polls_options WHERE id = " . (int)$optid); } function updateOptions($pollid, $data) { global $serendipity; foreach($data AS $optid => $values) { if (empty($values['title'])) { $this->deleteOption($optid); } else { serendipity_db_query("UPDATE {$serendipity['dbPrefix']}polls_options SET title = '" . serendipity_db_escape_string($values['title']) . "' WHERE id = " . (int)$optid); } } } function showBackend() { global $serendipity; if ($serendipity['POST']['pollSave'] || $serendipity['POST']['pollOptionAdd'] || is_array($serendipity['POST']['pollOptionRemove'])) { $serendipity['POST']['pollSubmit'] = true; if ($serendipity['POST']['poll'] == '__new') { $serendipity['POST']['poll'] = $this->insertPoll(); } else { $this->updatePoll($serendipity['POST']['poll']); $this->updateOptions($serendipity['POST']['poll'], $serendipity['POST']['pollOptions']); } } if ($serendipity['POST']['pollOptionAdd']) { $serendipity['POST']['pollSubmit'] = true; $this->addOption($serendipity['POST']['poll'], $serendipity['POST']['pollNewOption']); } if (is_array($serendipity['POST']['pollOptionRemove'])) { $serendipity['POST']['pollSubmit'] = true; foreach($serendipity['POST']['pollOptionRemove'] AS $optid => $optval) { $this->deleteOption($optid); } } if ($serendipity['POST']['poll'] != '__new') { $this->poll = serendipity_common_pollbox::fetchPoll($serendipity['POST']['poll']); } if ($serendipity['version'][0] == '2') { echo '

' . PLUGIN_POLL_SELECT . '

'; } if (!empty($serendipity['POST']['pollDelete']) && $serendipity['POST']['poll'] != '__new') { serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}polls WHERE id = " . (int)$serendipity['POST']['poll']); serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}polls_options WHERE pollid = " . (int)$serendipity['POST']['poll']); if ($serendipity['version'][0] == '1') { ?>
'; echo '
'; echo ' '; echo ' '; echo '
'; if ($serendipity['version'][0] == '1') { echo '
'; } else { echo '
'; } if ($serendipity['version'][0] == '1') { echo '' . PLUGIN_POLL_SELECT . '

'; } echo ' '; echo ' -' . WORD_OR . '- '; echo ' -' . WORD_OR . '- '; } else { echo ''; echo ' '; echo ' '; echo ' '; } echo '
'; if ($serendipity['POST']['pollSubmit']) { if ($serendipity['version'][0] == '1') { echo '
'; } else { echo '
'; } $this->showForm(); echo '
'; } echo ''; } function showForm() { global $serendipity; if ($serendipity['version'][0] == '1') { echo '


'; echo TITLE . ' '; } else { echo '
'; echo ''; echo ''; echo '
'; } if ($serendipity['version'][0] == '1') { echo '

'; echo ''; echo ''; echo ''; echo ''; foreach((array)$this->poll['options'] AS $optid => $option) { echo ''; echo ''; echo ''; echo ''; echo ''; } echo ''; echo ''; echo ''; echo ''; echo '
' . TITLE . '  
' . (int)$option['votes'] . ' ' . PLUGIN_POLL_VOTES . '
'; } else { echo '

' . CREATE . '

'; echo '
    '; foreach((array)$this->poll['options'] AS $optid => $option) { echo '
  1. '; echo ''; echo ' '; echo ' '; echo ' ' . (int)$option['votes'] . ' ' . PLUGIN_POLL_VOTES . ''; echo '
  2. '; } echo '
  3. '; echo ''; echo ' '; echo ' '; echo '
  4. '; echo '
'; } if ($serendipity['version'][0] == '1') { echo ' '; } else { echo '
'; echo ' '; echo '
'; } } function generate_content(&$title) { $title = PLUGIN_POLL_TITLE; } function install() { $this->setupDB(); } function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks = &$bag->get('event_hooks'); if (isset($hooks[$event])) { switch($event) { case 'genpage': $args = implode('/', serendipity_getUriArguments($eventData, true)); if ($serendipity['rewrite'] != 'none') { $nice_url = $serendipity['serendipityHTTPPath'] . $args; } else { $nice_url = $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?/' . $args; } if (empty($serendipity['GET']['subpage'])) { $serendipity['GET']['subpage'] = $nice_url; } break; case 'entry_display': if ($this->selected()) { if (is_array($eventData)) { $eventData['clean_page'] = true; // This is important to not display an entry list! } else { $eventData = array('clean_page' => true); } } return true; break; case 'backend_sidebar_entries': if ($serendipity['serendipityUserlevel'] >= USERLEVEL_CHIEF) { if ($serendipity['version'][0] == '1') { echo ''; } else { echo '
  • ' . PLUGIN_POLL_TITLE . '
  • '; } } return true; break; case 'backend_sidebar_entries_event_display_poll': $this->showBackend(); return true; break; case 'entries_header': $this->show(); return true; break; default: return false; break; } } else { return false; } } } /* vim: set sts=4 ts=4 expandtab : */