add('name', PLUGIN_ASSIGNCATEGORIES_NAME); $propbag->add('description', PLUGIN_ASSIGNCATEGORIES_DESC); $propbag->add('stackable', false); $propbag->add('author', 'Garvin Hicking, Matthias Mees'); $propbag->add('version', '1.4.2'); $propbag->add('requirements', array( 'serendipity' => '0.8', 'php' => '4.1.0' )); $propbag->add('event_hooks', array( 'backend_sidebar_entries' => true, 'backend_sidebar_entries_event_display_assigncategories' => true, 'frontend_generate_plugins' => true )); $propbag->add('groups', array('BACKEND_FEATURES')); } 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 ($this->check()) { if ($serendipity['version'][0] == '1') { echo ''; } else { echo '
  • ' . PLUGIN_ASSIGNCATEGORIES_NAME . '
  • '; } } return true; break; case 'backend_sidebar_entries_event_display_assigncategories': $this->showAssignment(); return true; break; default: return true; break; } } else { return false; } } function &getAllEntries() { global $serendipity; $rows = serendipity_db_query("SELECT e.id, e.title, c.categoryid FROM {$serendipity['dbPrefix']}entries AS e LEFT OUTER JOIN {$serendipity['dbPrefix']}entrycat AS ec ON e.id = ec.entryid LEFT OUTER JOIN {$serendipity['dbPrefix']}category AS c ON ec.categoryid = c.categoryid ORDER BY e.title ASC"); $entries = array(); foreach($rows AS $row) { $entries[$row['id']]['title'] = $row['title']; if (!empty($row['categoryid'])) { $entries[$row['id']]['categories'][] = $row['categoryid']; } } return $entries; } function check() { global $serendipity; if (function_exists('serendipity_checkPermission')) { return serendipity_checkPermission('adminCategories'); } elseif ($serendipity['serendipityUserlevel'] < USERLEVEL_CHIEF) { return false; } else { return true; } } function updateCategories(&$entries) { global $serendipity; foreach($entries AS $entryid => $entry) { $entries[$entryid]['categories'] = array(); } foreach($serendipity['POST']['assigncat'] AS $categoryid => $entrylist) { serendipity_db_query("DELETE FROM {$serendipity['dbPrefix']}entrycat WHERE categoryid = " . (int)$categoryid); foreach($entrylist AS $entry) { serendipity_db_query("INSERT INTO {$serendipity['dbPrefix']}entrycat (entryid, categoryid) VALUES (" . (int)$entry . ", " . (int)$categoryid . ")"); $entries[$entry]['categories'][] = $categoryid; } } if ($serendipity['version'][0] == '1') { echo '
    '. CATEGORY_SAVED .'
    '; } else { echo ' '. CATEGORY_SAVED .''; } } function showAssignment() { global $serendipity; if (!$this->check()) { return false; } if ($serendipity['version'][0] == '2') { echo '

    ' . PLUGIN_ASSIGNCATEGORIES_NAME . '

    '; } $entries = $this->getAllEntries(); if (!empty($serendipity['POST']['submit'])) { $this->updateCategories($entries); } echo '
    ' . "\n"; echo '' . "\n"; echo '' . "\n"; $cats = serendipity_fetchCategories('all'); if ($serendipity['version'][0] == '1') { echo ''; foreach ($cats as $cat_data) { echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; echo '' . "\n"; } echo '
    ' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($cat_data['category_name']) : htmlspecialchars($cat_data['category_name'], ENT_COMPAT, LANG_CHARSET)) . '
    ' . "\n"; echo ''; } else { foreach ($cats as $cat_data) { echo '
    '; echo ''; echo '
    '; } echo '
    '; } echo '
    '; } } ?>