add('name', PLUGIN_ADMINNOTES_TITLE); $propbag->add('description', PLUGIN_ADMINNOTES_DESC); $propbag->add('requirements', array( 'serendipity' => '0.9', 'smarty' => '2.6.7', 'php' => '4.1.0' )); $propbag->add('version', '0.7'); $propbag->add('author', 'Garvin Hicking'); $propbag->add('stackable', false); $propbag->add('configuration', array('feedback', 'limit', 'html', 'markup', 'cutoff')); $propbag->add('event_hooks', array( 'backend_frontpage_display' => true, 'backend_sidebar_entries' => true, 'backend_sidebar_entries_event_display_adminnotes' => true, 'css_backend' => true, ) ); $propbag->add('groups', array('BACKEND_FEATURES')); } function introspect_config_item($name, &$propbag) { switch($name) { case 'feedback': $propbag->add('type', 'boolean'); $propbag->add('name', PLUGIN_ADMINNOTES_FEEDBACK); $propbag->add('description', PLUGIN_ADMINNOTES_FEEDBACK_DESC); $propbag->add('default', 'true'); break; case 'html': $radio = array(); $radio['value'][] = 'true'; $radio['desc'][] = YES; $radio['value'][] = 'false'; $radio['desc'][] = NO; $radio['value'][] = 'admin'; $radio['desc'][] = USERLEVEL_ADMIN_DESC; $propbag->add('type', 'radio'); $propbag->add('radio', $radio); $propbag->add('name', PLUGIN_ADMINNOTES_HTML); $propbag->add('description', PLUGIN_ADMINNOTES_HTML_DESC); $propbag->add('default', 'false'); break; case 'limit': $propbag->add('type', 'string'); $propbag->add('name', LIMIT_TO_NUMBER); $propbag->add('description', ''); $propbag->add('default', '15'); break; case 'cutoff': $propbag->add('type', 'string'); $propbag->add('name', PLUGIN_ADMINNOTES_CUTOFF); $propbag->add('description', PLUGIN_ADMINNOTES_CUTOFF_DESC); $propbag->add('default', '1500'); break; case 'markup': $propbag->add('type', 'boolean'); $propbag->add('name', DO_MARKUP); $propbag->add('description', DO_MARKUP_DESCRIPTION); $propbag->add('default', 'true'); break; default: return false; } return true; } function setupDB() { global $serendipity; if (serendipity_db_bool($this->get_config('db_built_1', false))) { return true; } $sql = "CREATE TABLE {$serendipity['dbPrefix']}adminnotes ( noteid {AUTOINCREMENT} {PRIMARY}, authorid int(10) {UNSIGNED} default null, notetime int(10) {UNSIGNED} default null, subject varchar(255), body text, notetype varchar(255) NOT NULL default '' );"; serendipity_db_schema_import($sql); $sql = "CREATE TABLE {$serendipity['dbPrefix']}adminnotes_to_groups ( noteid int(10) {UNSIGNED} default null, groupid int(10) {UNSIGNED} default null );"; serendipity_db_schema_import($sql); $this->set_config('db_built_1', 'true'); } function getMyNotes($limited = true) { global $serendipity; $this->setupDB(); $sql = "SELECT a.noteid, a.authorid, a.notetime, a.subject, a.body, a.notetype, ar.realname FROM {$serendipity['dbPrefix']}adminnotes AS a JOIN {$serendipity['dbPrefix']}adminnotes_to_groups AS atg ON atg.noteid = a.noteid JOIN {$serendipity['dbPrefix']}authorgroups AS ag ON (ag.groupid = atg.groupid AND ag.authorid = {$serendipity['authorid']}) JOIN {$serendipity['dbPrefix']}authors AS axs ON axs.authorid = ag.authorid JOIN {$serendipity['dbPrefix']}authors AS ar ON ar.authorid = a.authorid " . (is_int($limited) ? 'WHERE a.noteid = ' . (int)$limited : '') . " GROUP BY a.noteid ORDER BY a.notetime DESC"; if ($limited) { $sql .= ' ' . serendipity_db_limit_sql($this->get_config('limit')); } return serendipity_db_query($sql, (is_int($limited) ? true : false), 'assoc'); } function generate_content(&$title) { $title = PLUGIN_ADMINNOTES_TITLE; } function shownotes() { global $serendipity; echo '

' . PLUGIN_ADMINNOTES_TITLE . '

'; if (!serendipity_db_bool($this->get_config('feedback')) && $serendipity['serendipityUserlevel'] < USERLEVEL_CHIEF) { return false; } switch($_REQUEST['action']) { case 'edit': $entry = $this->getMyNotes((int)$_REQUEST['note']); $mode = 'update'; case 'new': if (!isset($mode)) { $mode = 'insert'; } if (!is_array($entry)) { $entry = array(); } if ($_REQUEST['submit'] /* && serendipity_checkFormToken() */) { $valid_groups = serendipity_getAllGroups($serendipity['authorid']); $targets = array(); if (is_array($_REQUEST['note_target'])) { foreach($_REQUEST['note_target'] AS $groupid) { $found = false; foreach($valid_groups AS $group) { if ($group['confkey'] == $groupid) { $found = true; break; } } if ($found) { $targets[] = (int)$groupid; } } } if ($mode == 'update') { $noteid = (int)$_REQUEST['note']; echo serendipity_db_query("UPDATE {$serendipity['dbPrefix']}adminnotes SET authorid = {$serendipity['authorid']}, subject = '" . serendipity_db_escape_string($_REQUEST['note_subject']) . "', body = '" . serendipity_db_escape_string($_REQUEST['note_body']) . "', notetype = '" . serendipity_db_escape_string($_REQUEST['note_notetype']) . "' WHERE noteid = $noteid"); echo serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}adminnotes_to_groups WHERE noteid = $noteid"); foreach($targets AS $target) { echo serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}adminnotes_to_groups (noteid, groupid) VALUES ($noteid, $target)"); } } else { serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}adminnotes (authorid, notetime, subject, body, notetype) VALUES ('" . $serendipity['authorid'] . "', " . time() . ", '" . serendipity_db_escape_string($_REQUEST['note_subject']) . "', '" . serendipity_db_escape_string($_REQUEST['note_body']) . "', '" . serendipity_db_escape_string($_REQUEST['note_notetype']) . "')"); $noteid = serendipity_db_insert_id('adminnotes', 'noteid'); foreach($targets AS $target) { serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}adminnotes_to_groups (noteid, groupid) VALUES ($noteid, $target)"); } } echo '
' . DONE . ': '. sprintf(SETTINGS_SAVED_AT, serendipity_strftime('%H:%M:%S')) . '
'; } echo '

' . PLUGIN_ADMINNOTES_FEEDBACK_INFO . '

'; echo '
'; echo serendipity_setFormToken(); echo ''; echo ''; echo ''; echo ''; echo ''; echo TITLE . '
'; echo '

'; echo USERCONF_GROUPS . '
'; $valid_groups = serendipity_getAllGroups($serendipity['authorid']); if (isset($_REQUEST['note_target'])) { $selected = $_REQUEST['note_target']; } elseif ($mode == 'update') { $sql = serendipity_db_query("SELECT * FROM {$serendipity['dbPrefix']}adminnotes_to_groups"); $selected = array(); foreach($sql AS $row) { $selected[] = $row['groupid']; } } echo '

'; echo ENTRY_BODY . '
'; echo ''; echo '

'; echo ''; echo '
'; break; case 'delete': $newLoc = '?' . serendipity_setFormToken('url') . '&serendipity[adminModule]=event_display&serendipity[adminAction]=adminnotes&action=isdelete&note=' . (int)$_REQUEST['note']; $entry = $this->getMyNotes((int)$_REQUEST['note']); printf(DELETE_SURE, $entry['noteid'] . ' - ' . htmlspecialchars($entry['subject'])); ?>

" class="serendipityPrettyButton">
getMyNotes((int)$_REQUEST['note']); if (isset($entry['noteid'])) { serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}adminnotes WHERE noteid = " . (int)$_REQUEST['note']); serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}adminnotes_to_groups WHERE noteid = " . (int)$_REQUEST['note']); } printf(RIP_ENTRY, $entry['noteid'] . ' - ' . htmlspecialchars($entry['subject'])); break; default: $notes = $this->getMyNotes(false); echo '
    '; if (is_array($notes)) { foreach($notes AS $note) { echo '
  1. ' . $note['subject'] . ' ' . POSTED_BY . ' ' . $note['realname'] . ' ' . ON . ' ' . serendipity_strftime(DATE_FORMAT_SHORT, $note['notetime']) . '
    '; echo '' . EDIT . ' '; echo '' . DELETE . ' '; echo '

  2. '; } } echo '
'; echo '' . NEW_ENTRY . ''; break; } } function output($string) { global $serendipity; static $allow_html = null; static $do_markup = null; if ($allow_html == null) { $allow_html = $this->get_config('html'); if ($allow_html === 'admin') { if ($serendipity['serendipityUserlevel'] >= USERLEVEL_ADMIN) { $allow_html = true; } else { $allow_html = false; } } else { $allow_html = serendipity_db_bool($allow_html); } $do_markup = serendipity_db_bool($this->get_config('markup')); } if ($allow_html) { $body = $string; } else { $body = htmlspecialchars($string); } if ($do_markup) { $entry = array('html_nugget' => $body); serendipity_plugin_api::hook_event('frontend_display', $entry); $body = $entry['html_nugget']; } return $body; } function event_hook($event, &$bag, &$eventData, $addData = null) { global $serendipity; $hooks = &$bag->get('event_hooks'); if (isset($hooks[$event])) { switch($event) { case 'backend_sidebar_entries': ?> shownotes(); break; case 'backend_frontpage_display': ?> get_config('cutoff'); $notes = $this->getMyNotes(); $zoom = serendipity_getTemplateFile('admin/img/zoom.png'); if (is_array($notes)) { foreach($notes AS $id => $note) { echo '
' . "\n"; echo '
' . $this->output($note['subject']) . ' ' . POSTED_BY . ' ' . htmlspecialchars($note['realname']) . ' ' . ON . ' ' . serendipity_strftime(DATE_FORMAT_SHORT, $note['notetime']) . '
' . "\n"; if (strlen($note['body']) > $cutoff) { $output = $this->output($note['body']); echo '' . "\n"; echo '
' . serendipity_mb('substr', $output, 0, $cutoff) . '...
' . "\n"; echo ''; } else { echo '
' . $this->output($note['body']) . '
' . "\n"; } echo "
\n"; } serendipity_JSsetCookie('lastnote', $notes[0]['noteid']); } break; case 'css_backend': if (!strpos($eventData, '.note_')) { // class exists in CSS, so a user has customized it and we don't need default echo file_get_contents(dirname(__FILE__) . '/notes.css'); } break; } } return true; } } /* vim: set sts=4 ts=4 expandtab : */