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.14');
$propbag->add('author', 'Garvin Hicking, Matthias Mees');
$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_admin' => true,
'backend_sidebar_entries_event_display_adminnotes' => true,
'js_backend' => true,
'backend_dashboard' => 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;
if ($serendipity['version'][0] < 2) {
echo '
' . PLUGIN_ADMINNOTES_TITLE . '
';
} else {
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'];
$q = 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");
$q = serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}adminnotes_to_groups WHERE noteid = $noteid");
foreach($targets AS $target) {
$q = serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}adminnotes_to_groups (noteid, groupid) VALUES ($noteid, $target)");
}
if (is_string($q)) {
echo $q . "
\n";
}
} 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)");
}
}
if ($serendipity['version'][0] < 2) {
echo '' . DONE . ': '. sprintf(SETTINGS_SAVED_AT, serendipity_strftime('%H:%M:%S')) . '
';
} else {
echo ' ' . DONE . ': '. sprintf(SETTINGS_SAVED_AT, serendipity_strftime('%H:%M:%S')) . '';
}
}
echo '' . PLUGIN_ADMINNOTES_FEEDBACK_INFO . '
';
echo '';
break;
case 'delete':
$newLoc = '?' . serendipity_setFormToken('url') . '&serendipity[adminModule]=event_display&serendipity[adminAction]=adminnotes&action=isdelete¬e=' . (int)$_REQUEST['note'];
$entry = $this->getMyNotes((int)$_REQUEST['note']);
if ($serendipity['version'][0] > 1) {
echo ' ';
}
printf(DELETE_SURE, $entry['noteid'] . ' - ' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['subject']) : htmlspecialchars($entry['subject'], ENT_COMPAT, LANG_CHARSET)));
if ($serendipity['version'][0] > 1) {
echo '';
}
if ($serendipity['version'][0] < 2) {
?>
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']);
}
if ($serendipity['version'][0] > 1) {
echo ' ';
}
printf(RIP_ENTRY, $entry['noteid'] . ' - ' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['subject']) : htmlspecialchars($entry['subject'], ENT_COMPAT, LANG_CHARSET)));
if ($serendipity['version'][0] > 1) {
echo '';
}
break;
default:
$notes = $this->getMyNotes(false);
echo '';
if (is_array($notes)) {
foreach($notes AS $note) {
if ($serendipity['version'][0] < 2) {
echo '- ' . $note['subject'] . ' ' . POSTED_BY . ' ' . $note['realname'] . ' ' . ON . ' ' . serendipity_strftime(DATE_FORMAT_SHORT, $note['notetime']) . '
';
echo '' . EDIT . ' ';
echo '' . DELETE . ' ';
echo '
';
} else {
echo '' . $note['subject'] . '
' . POSTED_BY . ' ' . $note['realname'] . ' ' . ON . ' ' . serendipity_strftime(DATE_FORMAT_SHORT, $note['notetime']) . '
';
echo ' ';
}
}
}
echo '
';
if ($serendipity['version'][0] < 2) {
echo '' . NEW_ENTRY . '';
} else {
echo '';
}
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 = (function_exists('serendipity_specialchars') ? serendipity_specialchars($string) : htmlspecialchars($string, ENT_COMPAT, LANG_CHARSET));
}
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':
if ($serendipity['version'][0] < 2) {
?>
1) {
?>
shownotes();
break;
case 'js_backend':
?>
/* serendipity_event_adminnotes (quicknotes) start */
function fulltext_toggle(id) {
if ( document.getElementById(id + '_full').style.display == '' ) {
document.getElementById(id + '_full').style.display='none';
document.getElementById(id + '_summary').style.display='';
document.getElementById(id + '_text').innerHTML = '';
} else {
document.getElementById(id + '_full').style.display='';
document.getElementById(id + '_summary').style.display='none';
document.getElementById(id + '_text').innerHTML = '';
}
return false;
}
/* serendipity_event_adminnotes (quicknotes) end */
1) break;
?>
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 . ' ' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($note['realname']) : htmlspecialchars($note['realname'], ENT_COMPAT, LANG_CHARSET)) . ' ' . ON . ' ' . serendipity_strftime(DATE_FORMAT_SHORT, $note['notetime']) . '
' . "\n";
if (strlen($note['body']) > $cutoff) {
$output = $this->output($note['body']);
echo '
' . $output . '
' . "\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 'backend_dashboard':
$cutoff = $this->get_config('cutoff');
$notes = $this->getMyNotes();
if (is_array($notes)) {
?>
.note_subject { margin: 0px 0px 1em; }
.note_subject h3 { line height: 1.6; margin: 0; }
.note_new { border: 2px solid rgb(0, 255, 0); margin: -0.2em; padding: 0.2em; }