function introspect_config_item($name, &$propbag)
 {
     switch ($name) {
         case 'locking':
             $propbag->add('type', 'boolean');
             $propbag->add('name', PLUGIN_EVENT_ENTRYCHECK_LOCKING);
             $propbag->add('description', '');
             $propbag->add('default', false);
             break;
         case 'emptyCategories':
             $propbag->add('type', 'boolean');
             $propbag->add('name', PLUGIN_EVENT_ENTRYCHECK_EMPTYCATEGORIES);
             $propbag->add('description', PLUGIN_EVENT_ENTRYCHECK_EMPTYCATEGORIES_DESC);
             $propbag->add('default', false);
             break;
         case 'emptyTitle':
             $propbag->add('type', 'boolean');
             $propbag->add('name', PLUGIN_EVENT_ENTRYCHECK_EMPTYTITLE);
             $propbag->add('description', PLUGIN_EVENT_ENTRYCHECK_EMPTYTITLE_DESC);
             $propbag->add('default', false);
             break;
         case 'emptyBody':
             $propbag->add('type', 'boolean');
             $propbag->add('name', PLUGIN_EVENT_ENTRYCHECK_EMPTYBODY);
             $propbag->add('description', PLUGIN_EVENT_ENTRYCHECK_EMPTYBODY_DESC);
             $propbag->add('default', false);
             break;
         case 'emptyExtended':
             $propbag->add('type', 'boolean');
             $propbag->add('name', PLUGIN_EVENT_ENTRYCHECK_EMPTYEXTENDED);
             $propbag->add('description', PLUGIN_EVENT_ENTRYCHECK_EMPTYEXTENDED_DESC);
             $propbag->add('default', false);
             break;
         case 'defaultCat':
             $cats = serendipity_fetchCategories($serendipity['authorid']);
             if (!is_array($cats)) {
                 return false;
             }
             $catlist = serendipity_generateCategoryList($cats, array(0), 4);
             $tmp_select_cats = explode('@@@', $catlist);
             if (!is_array($tmp_select_cats)) {
                 return false;
             }
             $select_cats = array();
             $select_cats['none'] = NONE;
             foreach ($tmp_select_cats as $cidx => $tmp_select_cat) {
                 $select_cat = explode('|||', $tmp_select_cat);
                 if (!empty($select_cat[0]) && !empty($select_cat[1])) {
                     $select_cats[$select_cat[0]] = $select_cat[1];
                 }
             }
             $propbag->add('type', 'select');
             $propbag->add('select_values', $select_cats);
             $propbag->add('name', PLUGIN_EVENT_ENTRYCHECK_DEFAULTCAT);
             $propbag->add('description', PLUGIN_EVENT_ENTRYCHECK_DEFAULTCAT_DESC);
             $propbag->add('default', 'none');
             break;
     }
     return true;
 }
 function introspect_config_item($name, &$propbag)
 {
     global $serendipity;
     switch ($name) {
         case 'base_category':
             if (version_compare($serendipity['version'], '0.8', '>=')) {
                 $base_cats = serendipity_fetchCategories();
                 $base_cats = serendipity_walkRecursive($base_cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
                 $select['none'] = NONE;
                 foreach ($base_cats as $cat) {
                     $select[$cat['categoryid']] = str_repeat('-', $cat['depth']) . ' ' . $cat['category_name'];
                 }
                 $propbag->add('type', 'select');
                 $propbag->add('name', PLUGIN_EVENT_STARTCAT_CATEGORY_NAME);
                 $propbag->add('description', PLUGIN_EVENT_STARTCAT_CATEGORY_DESC);
                 $propbag->add('select_values', $select);
             }
             break;
         case 'base_categories':
             $propbag->add('type', 'string');
             $propbag->add('name', PLUGIN_EVENT_STARTCAT_MULTICATEGORY_NAME);
             $propbag->add('description', PLUGIN_EVENT_STARTCAT_MULTICATEGORY_DESC);
             $propbag->add('default', '');
             break;
         case 'remembercat':
             $propbag->add('type', 'boolean');
             $propbag->add('name', PLUGIN_EVENT_STARTCAT_REMEMBERCAT_NAME);
             $propbag->add('description', PLUGIN_EVENT_STARTCAT_REMEMBERCAT_DESC);
             $propbag->add('default', false);
             break;
         case 'hide_category':
             if (version_compare($serendipity['version'], '0.8', '>=')) {
                 $base_cats = serendipity_fetchCategories();
                 $base_cats = serendipity_walkRecursive($base_cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
                 $select['none'] = NONE;
                 foreach ($base_cats as $cat) {
                     $select[$cat['categoryid']] = str_repeat('-', $cat['depth']) . ' ' . $cat['category_name'];
                 }
                 $propbag->add('type', 'select');
                 $propbag->add('name', PLUGIN_EVENT_STARTCAT_HIDECATEGORY_NAME);
                 $propbag->add('description', PLUGIN_EVENT_STARTCAT_HIDECATEGORY_DESC);
                 $propbag->add('select_values', $select);
             }
             break;
         case 'hide_categories':
             $propbag->add('type', 'string');
             $propbag->add('name', PLUGIN_EVENT_STARTCAT_MULTIHIDECATEGORY_NAME);
             $propbag->add('description', PLUGIN_EVENT_STARTCAT_MULTIHIDECATEGORY_DESC);
             $propbag->add('default', '');
             break;
         default:
             return false;
     }
     return true;
 }
Example #3
0
 function _getCategoryList()
 {
     $res = serendipity_fetchCategories('all');
     $ret = array(0 => NO_CATEGORY);
     if (is_array($res)) {
         foreach ($res as $v) {
             $ret[$v['categoryid']] = $v['category_name'];
         }
     }
     return $ret;
 }
 function introspect_config_item($name, &$propbag)
 {
     switch ($name) {
         case 'phoneblogz_notifyurl':
             $propbag->add('type', 'string');
             $propbag->add('name', PLUGIN_EVENT_PHONEBLOGZ_NOTIFYURL);
             $propbag->add('description', '');
             $propbag->add('default', PLUGIN_EVENT_PHONEBLOGZ_NOTIFYURL_DEFAULT);
             break;
         case 'phoneblogz_accesscode':
             $propbag->add('type', 'string');
             $propbag->add('name', PLUGIN_EVENT_PHONEBLOGZ_ACCESSCODE);
             $propbag->add('description', '');
             $propbag->add('default', '');
             break;
         case 'phoneblogz_password':
             $propbag->add('type', 'string');
             $propbag->add('name', PLUGIN_EVENT_PHONEBLOGZ_PASSWORD);
             $propbag->add('description', '');
             $propbag->add('default', '');
             break;
         case 'phoneblogz_subject':
             $propbag->add('type', 'string');
             $propbag->add('name', PLUGIN_EVENT_PHONEBLOGZ_SUBJECT);
             $propbag->add('description', '');
             $propbag->add('default', PLUGIN_EVENT_PHONEBLOGZ_SUBJECT_DEFAULT);
             break;
         case 'phoneblogz_text':
             $propbag->add('type', 'html');
             $propbag->add('name', PLUGIN_EVENT_PHONEBLOGZ_TEXT);
             $propbag->add('description', '');
             $propbag->add('default', PLUGIN_EVENT_PHONEBLOGZ_TEXT_DEFAULT);
             break;
         case 'categoryid':
             $base_cats = serendipity_fetchCategories();
             $base_cats = serendipity_walkRecursive($base_cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
             $select['none'] = NONE;
             foreach ($base_cats as $cat) {
                 $select[$cat['categoryid']] = str_repeat('-', $cat['depth']) . ' ' . $cat['category_name'];
             }
             $propbag->add('type', 'select');
             $propbag->add('name', CATEGORY);
             $propbag->add('description', '');
             $propbag->add('select_values', $select);
             break;
         default:
             return false;
     }
     return true;
 }
 function performConfig(&$bag)
 {
     if (is_object($bag)) {
         $conf = $bag->get('configuration');
     }
     $this->data['categories'] = serendipity_fetchCategories('all');
     if (!is_array($this->data['categories'])) {
         return false;
     }
     foreach ($this->data['categories'] as $cat) {
         $conf[] = 'category_' . $cat['categoryid'];
         $this->data['cat'][$cat['categoryid']] = $cat;
     }
     if (is_object($bag)) {
         $bag->add('configuration', $conf);
     }
 }
 function introspect_config_item($name, &$propbag)
 {
     global $serendipity;
     switch ($name) {
         case 'category':
             $raw_cat = serendipity_fetchCategories();
             $raw_cat = serendipity_walkRecursive($raw_cat, 'categoryid', 'parentid', VIEWMODE_THREADED);
             $categories = array('' => NONE);
             if (is_array($raw_cat)) {
                 foreach ($raw_cat as $cat) {
                     $categories[$cat['categoryid']] = str_repeat('-', $cat['depth']) . $cat['category_name'];
                 }
             }
             $propbag->add('type', 'select');
             $propbag->add('name', PLUGIN_COMICS_CAT);
             $propbag->add('description', PLUGIN_COMICS_CAT_DESC);
             $propbag->add('select_values', $categories);
             $propbag->add('default', '');
             break;
         case 'show_title':
             $propbag->add('type', 'boolean');
             $propbag->add('name', PLUGIN_COMICS_TITLE);
             $propbag->add('description', PLUGIN_COMICS_TITLE_DESC);
             $propbag->add('default', 'true');
             break;
         case 'raw':
             $propbag->add('type', 'boolean');
             $propbag->add('name', PLUGIN_COMICS_RAW);
             $propbag->add('description', PLUGIN_COMICS_RAW_DESC);
             $propbag->add('default', 'true');
             break;
         case 'hide':
             $propbag->add('type', 'boolean');
             $propbag->add('name', PLUGIN_COMICS_HIDE);
             $propbag->add('description', PLUGIN_COMICS_HIDE_DESC);
             $propbag->add('default', 'true');
             break;
         default:
             return false;
     }
     return true;
 }
 function introspect_config_item($name, &$propbag)
 {
     switch ($name) {
         case 'beginningOfWeek':
             $options = array();
             for ($i = 1; $i <= 7; $i++) {
                 $options[] = serendipity_formatTime('%A', mktime(0, 0, 0, 3, $i - 1, 2004));
             }
             $propbag->add('type', 'select');
             $propbag->add('select_values', $options);
             $propbag->add('name', CALENDAR_BEGINNING_OF_WEEK);
             $propbag->add('description', CALENDAR_BOW_DESC);
             $propbag->add('default', 1);
             break;
         case 'enableExtEvents':
             $propbag->add('type', 'boolean');
             $propbag->add('name', CALENDAR_ENABLE_EXTERNAL_EVENTS);
             $propbag->add('description', CALENDAR_EXTEVENT_DESC);
             $propbag->add('default', false);
             break;
             // Event Calendar: Support category!
         // Event Calendar: Support category!
         case 'category':
             $categories = array('all' => ALL_CATEGORIES);
             $cats = serendipity_fetchCategories();
             if (is_array($cats)) {
                 $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
                 foreach ($cats as $cat) {
                     $categories[$cat['categoryid']] = str_repeat(' . ', $cat['depth']) . $cat['category_name'];
                 }
             }
             $propbag->add('type', 'select');
             $propbag->add('name', CATEGORIES_PARENT_BASE);
             $propbag->add('description', CATEGORIES_PARENT_BASE_DESC);
             $propbag->add('select_values', $categories);
             $propbag->add('default', 'all');
             break;
         default:
             return false;
     }
     return true;
 }
 function &makeCategorySelector()
 {
     global $serendipity;
     $selector = '';
     // We start in our own, column-spanning row
     $selector .= '</td></tr>';
     $selector .= '<tr><td style="border-bottom: 1px solid #000; vertical-align: top">';
     $selector .= '<strong>' . PLUGIN_EVENT_NEWSBOX_NEWSCATS . '</strong><br />';
     $selector .= '<span style="color: rgb(94, 122, 148); font-size: 8pt;">';
     $selector .= PLUGIN_EVENT_NEWSBOX_NEWSCATS_DESC . '</span><br />';
     $selector .= '</td><td style="border-bottom: 1px solid #000">';
     $selector .= '<strong>' . CATEGORIES . '</strong><br />';
     // $selected_cats is used to set up the selections;
     // 'news_cats' holds the value when it's set.
     if (is_array($serendipity['POST']['plugin']['newscats'])) {
         // Someone has already selected categories
         $selected_cats = array();
         foreach ($serendipity['POST']['plugin']['newscats'] as $idx => $id) {
             $selected_cats[$id] = true;
         }
         $catlist = implode(',', array_keys($selected_cats));
         $this->set_config('news_cats', $catlist);
     } else {
         // Form is just being displayed; get previously selected categories
         // Must use default value! 'false' is very fast.
         $catlist = $this->get_config('news_cats', false);
         if (!$catlist) {
             $selected_cats = array();
         } else {
             $cat_ids = explode(',', $catlist);
             foreach ($cat_ids as $id) {
                 $selected_cats[$id] = true;
             }
         }
     }
     $selector .= '<select name="serendipity[plugin][newscats][]" multiple="true" size="5">';
     if (is_array($cats = serendipity_fetchCategories())) {
         $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
         foreach ($cats as $cat) {
             $catid = $cat['categoryid'];
             $selector .= '<option value="' . $catid . '"' . (isset($selected_cats[$catid]) ? ' selected="selected"' : '') . '>' . str_repeat('&nbsp;', $cat['depth']) . $cat['category_name'] . '</option>' . "\n";
         }
     }
     $selector .= '</select>';
     $selector .= '</td></tr>';
     return $selector;
 }
Example #9
0
 function import()
 {
     global $serendipity;
     $max_import = 9999;
     $serendipity['noautodiscovery'] = true;
     if (!is_dir($this->data['pivot_path']) || !is_readable($this->data['pivot_path'])) {
         $check_dir = $serendipity['serendipityPath'] . $this->data['pivot_path'];
         if (!is_dir($check_dir) || !is_readable($check_dir)) {
             return sprintf(ERROR_NO_DIRECTORY, serendipity_specialchars($this->data['pivot_path']));
         }
         $this->data['pivot_path'] = $check_dir;
     }
     printf('<span class="block_level">' . CHECKING_DIRECTORY . ': ', $this->data['pivot_path']) . '</span>';
     if ($root = opendir($this->data['pivot_path'])) {
         // Fetch category data:
         $s9y_categories = serendipity_fetchCategories('all');
         $categories = $this->unserialize($this->data['pivot_path'] . '/ser-cats.php');
         $pivot_to_s9y = array('categories' => array());
         echo '<ul>';
         foreach ($categories as $pivot_category_id => $category) {
             $found = false;
             $pivot_category = trim(stripslashes($category[0]));
             foreach ($s9y_categories as $idx => $item) {
                 if ($pivot_category == $item['category_name']) {
                     $found = $item['categoryid'];
                     break;
                 }
             }
             if ($found) {
                 echo '<li>Pivot Category "' . serendipity_specialchars($pivot_category) . '" mapped to Serendipity ID ' . $found . '</li>';
                 $pivot_to_s9y['categories'][$pivot_category] = $found;
             } else {
                 echo '<li>Created Pivot Category "' . serendipity_specialchars($pivot_category) . '".</li>';
                 $cat = array('category_name' => $pivot_category, 'category_description' => '', 'parentid' => 0, 'category_left' => 0, 'category_right' => 0);
                 serendipity_db_insert('category', $cat);
                 $pivot_to_s9y['categories'][$pivot_category] = serendipity_db_insert_id('category', 'categoryid');
             }
         }
         $i = 0;
         while (false !== ($dir = readdir($root))) {
             if ($dir[0] == '.') {
                 continue;
             }
             if (substr($dir, 0, 8) == 'standard') {
                 printf('<li>' . CHECKING_DIRECTORY . '...</li>', $dir);
                 $data = $this->unserialize($this->data['pivot_path'] . '/' . $dir . '/index-' . $dir . '.php');
                 if (empty($data) || !is_array($data) || count($data) < 1) {
                     echo '<li><span class="msg_error">FATAL: File <em>' . $dir . '/index-' . $dir . '.php</em> has no data!</span></li>';
                     flush();
                     ob_flush();
                     continue;
                 }
                 foreach ($data as $entry) {
                     $entryid = str_pad($entry['code'], 5, '0', STR_PAD_LEFT);
                     if ($i >= $max_import) {
                         echo '<li>Skipping entry data for #' . $entryid . '</li>';
                         continue;
                     }
                     echo '<li>Fetching entry data for #' . $entryid . '</li>';
                     $entrydata = $this->unserialize($this->data['pivot_path'] . '/' . $dir . '/' . $entryid . '.php');
                     if (empty($entrydata) || !is_array($entrydata) || count($entrydata) < 1) {
                         echo '<li><span class="msg_error">FATAL: File <em>' . $dir . '/' . $entryid . '.php</em> has no data!</span></li>';
                         flush();
                         ob_flush();
                         continue;
                     }
                     $entry = array();
                     $entry['title'] = trim(stripslashes($entrydata['title']));
                     $entry['categories'] = array();
                     if (is_array($entrydata['category'])) {
                         foreach ($entrydata['category'] as $pivot_category) {
                             $entry['categories'][] = $pivot_to_s9y['categories'][$pivot_category];
                         }
                     }
                     $entry['timestamp'] = $this->toTimestamp($entrydata['date']);
                     $entry['last_modified'] = !empty($entrydata['edit_date']) ? $this->toTimestamp($entrydata['edit_date']) : $entry['timestamp'];
                     $entry['isdraft'] = $entrydata['status'] == 'publish' ? 'false' : 'true';
                     $entry['body'] = stripslashes($entrydata['introduction']);
                     $entry['extended'] = stripslashes($entrydata['body']);
                     $entry['title'] = stripslashes($entrydata['title']);
                     $entry['authorid'] = $serendipity['authorid'];
                     $entry['author'] = $serendipity['serendipityUser'];
                     $entry['allow_comments'] = $entrydata['allow_comments'] ? 'true' : 'false';
                     $entry['moderate_comments'] = 'false';
                     $entry['exflag'] = !empty($entry['extended']) ? 1 : 0;
                     $entry['trackbacks'] = 0;
                     $entry['comments'] = isset($entrydata['comments']) ? count($entrydata['comments']) : 0;
                     serendipity_updertEntry($entry);
                     $i++;
                     if (isset($entrydata['comments']) && count($entrydata['comments']) > 0) {
                         foreach ($entrydata['comments'] as $comment) {
                             $comment = array('entry_id ' => $entry['id'], 'parent_id' => 0, 'timestamp' => $this->toTimestamp($comment['date']), 'author' => stripslashes($comment['name']), 'email' => stripslashes($comment['email']), 'url' => stripslashes($comment['url']), 'ip' => stripslashes($comment['ip']), 'status' => 'approved', 'body' => stripslashes($comment['comment']), 'subscribed' => $comment['notify'] ? 'true' : 'false', 'type' => 'NORMAL');
                             serendipity_db_insert('comments', $comment);
                         }
                     }
                     echo '<li><span class="msg_success">Entry #' . $entryid . ' imported</span></li>';
                     flush();
                     ob_flush();
                 }
             }
         }
         echo '</ul>';
     } else {
         return sprintf(ERROR_NO_DIRECTORY, serendipity_specialchars($this->data['pivot_path']));
     }
     return true;
 }
 /**
  * Creates a DHTML menu of serendipity categories.
  *
  * The menu is echoed out.
  *
  * @param  string $title  (Serves as the top level menu item if present)
  * @return void
  * @see    http://pear.php.net/HTML_TreeMenu  PEAR::HTML_TreeMenu
  */
 function generate_content(&$title)
 {
     global $serendipity;
     $title = $this->get_config('title', $this->title);
     // may want to put this in bundled_libs or a sub directory of this directory
     $pear = false;
     if (@(include_once 'HTML/TreeMenu.php')) {
         $pear = true;
     } elseif (@(include_once 'HTML_TreeMenu/TreeMenu.php')) {
         $pear = true;
     }
     if ($pear) {
         $which_category = $this->get_config('authorid');
         // build an accessible array of categories
         foreach (serendipity_fetchCategories(empty($which_category) ? 'all' : $which_category) as $cat) {
             if (!is_array($cat) || !isset($cat['categoryid'])) {
                 continue;
             }
             $categories[$cat['categoryid']] = $cat;
         }
         // create an array of numbers of entries per category
         $cat_count = array();
         if (serendipity_db_bool($this->get_config('show_count'))) {
             $cat_sql = "SELECT c.categoryid, c.category_name, count(e.id) as postings\n                                                FROM {$serendipity['dbPrefix']}entrycat ec,\n                                                     {$serendipity['dbPrefix']}category c,\n                                                     {$serendipity['dbPrefix']}entries e\n                                                WHERE ec.categoryid = c.categoryid\n                                                  AND ec.entryid = e.id\n                                                  AND e.isdraft = 'false'\n                                                      " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp  <= " . serendipity_db_time() : '') . "\n                                                GROUP BY c.categoryid, c.category_name\n                                                ORDER BY postings DESC";
             $category_rows = serendipity_db_query($cat_sql);
             if (is_array($category_rows)) {
                 foreach ($category_rows as $cat) {
                     $cat_count[$cat['categoryid']] = $cat['postings'];
                 }
             }
         }
         $image = $this->get_config('image', serendipity_getTemplateFile('img/xml.gif'));
         $image = $image == "'none'" || $image == 'none' ? '' : $image;
         // create nodes
         foreach ($categories as $cid => $cat) {
             if (function_exists('serendipity_categoryURL')) {
                 $link = serendipity_categoryURL($cat, 'serendipityHTTPPath');
             } else {
                 $link = serendipity_rewriteURL(PATH_CATEGORIES . '/' . serendipity_makePermalink(PERM_CATEGORIES, array('id' => $cat['categoryid'], 'title' => $cat['category_name'])), 'serendipityHTTPPath');
             }
             if (!empty($cat_count[$cat['categoryid']])) {
                 // $categories[$cid]['true_category_name'] = $cat['category_name'];
                 $cat['category_name'] .= ' (' . $cat_count[$cat['categoryid']] . ')';
                 // $categories[$cid]['article_count'] = $cat_count[$cat['categoryid']];
             }
             if (!empty($image)) {
                 $feedURL = serendipity_feedCategoryURL($cat, 'serendipityHTTPPath');
                 $feed = '<a class="serendipity_xml_icon" href="' . $feedURL . '"><img src="' . $image . '" alt="XML" style="border: 0px;vertical-align:middle"/></a> ';
                 $link = '<a href="' . $link . '" target="_self"><span>' . $cat['category_name'] . '</span></a>';
                 // work around a problem in HTML_TreeNode: when there is a href in 'text', 'link' is not converted to a link.
                 $cat_nodes[$cat['categoryid']] = new HTML_TreeNode(array('text' => $feed . $link));
             } else {
                 $cat_nodes[$cat['categoryid']] = new HTML_TreeNode(array('text' => $feed . $cat['category_name'], 'link' => $link));
             }
         }
         // create a top level for "all categories"
         // this serves as the title
         $cat_nodes[0] = new HTML_TreeNode(array('text' => ALL_CATEGORIES, 'link' => $serendipity['baseURL']));
         // nest nodes (thanks to PHP references)
         foreach ($categories as $category) {
             $cat_nodes[$category['parentid']]->addItem($cat_nodes[$category['categoryid']]);
         }
         // nest the "all categories" category
         $menu = new HTML_TreeMenu();
         $menu->addItem($cat_nodes[0]);
         $tree = new HTML_TreeMenu_DHTML($menu, array('images' => $serendipity['baseURL'] . $this->get_config('image_path')));
         // Add heading for block
         #$output = '<h2 class="serendipitySideBarTitle" style="font-weight: bold;">'.$title.'</h2><br />';
         // Put inside a div with "overflow:hidden" to avoid items of the sidebar plugin running outside the blog
         // Maybe we can put a config setting to choose if the block should be displayed with or without overflow setting.
         $output .= '<div style="overflow: hidden;">';
         $output .= $tree->toHTML();
         $output .= '</div>';
         echo '<script type="text/javascript" src="' . $serendipity['baseURL'] . $this->get_config('script_path') . '"></script>';
     } else {
         $output .= "Please install PEAR package HTML_TreeMenu to enable this plugin.";
     }
     echo $output;
 }
Example #11
0
/**
 * Shows the entry panel overview
 *
 * Shows a list of existing entries, with pagination and cookie-remember settings.
 *
 * @access public
 * @return null
 */
function serendipity_drawList()
{
    global $serendipity, $sort_order, $per_page;
    $filter_import = array('author', 'category', 'isdraft');
    $sort_import = array('perPage', 'ordermode', 'order');
    foreach ($filter_import as $f_import) {
        serendipity_restoreVar($serendipity['COOKIE']['entrylist_filter_' . $f_import], $serendipity['GET']['filter'][$f_import]);
        serendipity_JSsetCookie('entrylist_filter_' . $f_import, $serendipity['GET']['filter'][$f_import]);
    }
    foreach ($sort_import as $s_import) {
        serendipity_restoreVar($serendipity['COOKIE']['entrylist_sort_' . $s_import], $serendipity['GET']['sort'][$s_import]);
        serendipity_JSsetCookie('entrylist_sort_' . $s_import, $serendipity['GET']['sort'][$s_import]);
    }
    $perPage = !empty($serendipity['GET']['sort']['perPage']) ? $serendipity['GET']['sort']['perPage'] : $per_page[0];
    $page = (int) $serendipity['GET']['page'];
    $offSet = $perPage * $page;
    if (empty($serendipity['GET']['sort']['ordermode']) || $serendipity['GET']['sort']['ordermode'] != 'ASC') {
        $serendipity['GET']['sort']['ordermode'] = 'DESC';
    }
    if (!empty($serendipity['GET']['sort']['order']) && !empty($sort_order[$serendipity['GET']['sort']['order']])) {
        $orderby = serendipity_db_escape_string($serendipity['GET']['sort']['order'] . ' ' . $serendipity['GET']['sort']['ordermode']);
    } else {
        $orderby = 'timestamp ' . serendipity_db_escape_string($serendipity['GET']['sort']['ordermode']);
    }
    $filter = array();
    if (!empty($serendipity['GET']['filter']['author'])) {
        $filter[] = "e.authorid = '" . serendipity_db_escape_string($serendipity['GET']['filter']['author']) . "'";
    }
    if (!empty($serendipity['GET']['filter']['category'])) {
        $filter[] = "ec.categoryid = '" . serendipity_db_escape_string($serendipity['GET']['filter']['category']) . "'";
    }
    if (!empty($serendipity['GET']['filter']['isdraft'])) {
        if ($serendipity['GET']['filter']['isdraft'] == 'draft') {
            $filter[] = "e.isdraft = 'true'";
        } elseif ($serendipity['GET']['filter']['isdraft'] == 'publish') {
            $filter[] = "e.isdraft = 'false'";
        }
    }
    if (!empty($serendipity['GET']['filter']['body'])) {
        if ($serendipity['dbType'] == 'mysql') {
            $filter[] = "MATCH (title,body,extended) AGAINST ('" . serendipity_db_escape_string($serendipity['GET']['filter']['body']) . "')";
            $full = true;
        }
    }
    $filter_sql = implode(' AND ', $filter);
    // Fetch the entries
    $entries = serendipity_fetchEntries(false, false, serendipity_db_limit($offSet, $perPage + 1), true, false, $orderby, $filter_sql);
    ?>
<div class="serendipity_admin_list">
<form action="?" method="get">
    <input type="hidden" name="serendipity[action]"      value="admin"      />
    <input type="hidden" name="serendipity[adminModule]" value="entries"    />
    <input type="hidden" name="serendipity[adminAction]" value="editSelect" />
    <table width="100%" class="serendipity_admin_filters">
        <tr>
            <td class="serendipity_admin_filters_headline" colspan="6"><strong><?php 
    echo FILTERS;
    ?>
</strong> - <?php 
    echo FIND_ENTRIES;
    ?>
</td>
        </tr>
        <tr>
            <td valign="top" width="80"><?php 
    echo AUTHOR;
    ?>
</td>
            <td valign="top">
                <select name="serendipity[filter][author]">
                    <option value="">--</option>
<?php 
    $users = serendipity_fetchUsers('', null, true);
    if (is_array($users)) {
        foreach ($users as $user) {
            if (isset($user['artcount']) && $user['artcount'] < 1) {
                continue;
            }
            echo '<option value="' . $user['authorid'] . '" ' . (isset($serendipity['GET']['filter']['author']) && $serendipity['GET']['filter']['author'] == $user['authorid'] ? 'selected="selected"' : '') . '>' . htmlspecialchars($user['realname']) . '</option>' . "\n";
        }
    }
    ?>
              </select> <select name="serendipity[filter][isdraft]">
                    <option value="all"><?php 
    echo COMMENTS_FILTER_ALL;
    ?>
</option>
                    <option value="draft"   <?php 
    echo isset($serendipity['GET']['filter']['isdraft']) && $serendipity['GET']['filter']['isdraft'] == 'draft' ? 'selected="selected"' : '';
    ?>
><?php 
    echo DRAFT;
    ?>
</option>
                    <option value="publish" <?php 
    echo isset($serendipity['GET']['filter']['isdraft']) && $serendipity['GET']['filter']['isdraft'] == 'publish' ? 'selected="selected"' : '';
    ?>
><?php 
    echo PUBLISH;
    ?>
</option>
                </select>
            </td>
            <td valign="top" width="80"><?php 
    echo CATEGORY;
    ?>
</td>
            <td valign="top">
                <select name="serendipity[filter][category]">
                    <option value="">--</option>
<?php 
    $categories = serendipity_fetchCategories();
    $categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED);
    foreach ($categories as $cat) {
        echo '<option value="' . $cat['categoryid'] . '"' . ($serendipity['GET']['filter']['category'] == $cat['categoryid'] ? ' selected="selected"' : '') . '>' . str_repeat('&nbsp;', $cat['depth']) . htmlspecialchars($cat['category_name']) . '</option>' . "\n";
    }
    ?>
              </select>
            </td>
            <td valign="top" width="80"><?php 
    echo CONTENT;
    ?>
</td>
            <td valign="top"><input class="input_textbox" size="10" type="text" name="serendipity[filter][body]" value="<?php 
    echo isset($serendipity['GET']['filter']['body']) ? htmlspecialchars($serendipity['GET']['filter']['body']) : '';
    ?>
" /></td>
        </tr>
        <tr>
            <td class="serendipity_admin_filters_headline" colspan="6"><strong><?php 
    echo SORT_ORDER;
    ?>
</strong></td>
        </tr>
        <tr>
            <td>
                <?php 
    echo SORT_BY;
    ?>
            </td>
            <td>
                <select name="serendipity[sort][order]">
<?php 
    foreach ($sort_order as $so_key => $so_val) {
        echo '<option value="' . $so_key . '" ' . (isset($serendipity['GET']['sort']['order']) && $serendipity['GET']['sort']['order'] == $so_key ? 'selected="selected"' : '') . '>' . $so_val . '</option>' . "\n";
    }
    ?>
              </select>
            </td>
            <td><?php 
    echo SORT_ORDER;
    ?>
</td>
            <td>
                <select name="serendipity[sort][ordermode]">
                    <option value="DESC" <?php 
    echo isset($serendipity['GET']['sort']['ordermode']) && $serendipity['GET']['sort']['ordermode'] == 'DESC' ? 'selected="selected"' : '';
    ?>
><?php 
    echo SORT_ORDER_DESC;
    ?>
</option>
                    <option value="ASC" <?php 
    echo isset($serendipity['GET']['sort']['ordermode']) && $serendipity['GET']['sort']['ordermode'] == 'ASC' ? 'selected="selected"' : '';
    ?>
><?php 
    echo SORT_ORDER_ASC;
    ?>
</option>
                </select>
            </td>
            <td><?php 
    echo ENTRIES_PER_PAGE;
    ?>
</td>
            <td>
                <select name="serendipity[sort][perPage]">
<?php 
    foreach ($per_page as $per_page_nr) {
        echo '<option value="' . $per_page_nr . '"   ' . (isset($serendipity['GET']['sort']['perPage']) && $serendipity['GET']['sort']['perPage'] == $per_page_nr ? 'selected="selected"' : '') . '>' . $per_page_nr . '</option>' . "\n";
    }
    ?>
                </select>
            </td>
        </tr>
        <tr>
            <td align="right" colspan="6"><input type="submit" name="go" value="<?php 
    echo GO;
    ?>
" class="serendipityPrettyButton input_button" /></td>
        </tr>
    </table>
    </form>

    <table class="serendipity_admin_list" cellpadding="5" width="100%">
<?php 
    if (is_array($entries)) {
        $count = count($entries);
        $qString = '?serendipity[adminModule]=entries&amp;serendipity[adminAction]=editSelect';
        foreach ((array) $serendipity['GET']['sort'] as $k => $v) {
            $qString .= '&amp;serendipity[sort][' . $k . ']=' . $v;
        }
        foreach ((array) $serendipity['GET']['filter'] as $k => $v) {
            $qString .= '&amp;serendipity[filter][' . $k . ']=' . $v;
        }
        $linkPrevious = $qString . '&amp;serendipity[page]=' . ($page - 1);
        $linkNext = $qString . '&amp;serendipity[page]=' . ($page + 1);
        ?>
        <tr>
            <td>
                <?php 
        if ($offSet > 0) {
            ?>
                    <a href="<?php 
            echo $linkPrevious;
            ?>
" class="serendipityIconLink"><img src="<?php 
            echo serendipity_getTemplateFile('admin/img/previous.png');
            ?>
" /><?php 
            echo PREVIOUS;
            ?>
</a>
                <?php 
        }
        ?>
            </td>
            <td align="right">
                <?php 
        if ($count > $perPage) {
            ?>
                    <a href="<?php 
            echo $linkNext;
            ?>
" class="serendipityIconLinkRight"><?php 
            echo NEXT;
            ?>
<img src="<?php 
            echo serendipity_getTemplateFile('admin/img/next.png');
            ?>
" /></a>
                <?php 
        }
        ?>
            </td>
        </tr>
    </table>
    <script type="text/javascript">
    function invertSelection() {
        var f = document.formMultiDelete;
        for (var i = 0; i < f.elements.length; i++) {
            if (f.elements[i].type == 'checkbox') {
                f.elements[i].checked = !(f.elements[i].checked);
            }
        }
    }
    </script>
    <form action="?" method="post" name="formMultiDelete" id="formMultiDelete">
        <?php 
        echo serendipity_setFormToken();
        ?>
        <input type="hidden" name="serendipity[action]" value="admin" />
        <input type="hidden" name="serendipity[adminModule]" value="entries" />
        <input type="hidden" name="serendipity[adminAction]" value="multidelete" />
<?php 
        // Print the entries
        $rows = 0;
        foreach ($entries as $entry) {
            $rows++;
            if ($rows > $perPage) {
                continue;
            }
            // Find out if the entry has been modified later than 30 minutes after creation
            if ($entry['timestamp'] <= $entry['last_modified'] - 60 * 30) {
                $lm = '<a href="#" title="' . LAST_UPDATED . ': ' . serendipity_formatTime(DATE_FORMAT_SHORT, $entry['last_modified']) . '" onclick="alert(this.title)"><img src="' . serendipity_getTemplateFile('admin/img/clock.png') . '" alt="*" style="border: 0px none ; vertical-align: bottom;" /></a>';
            } else {
                $lm = '';
            }
            if (!$serendipity['showFutureEntries'] && $entry['timestamp'] >= serendipity_serverOffsetHour()) {
                $entry_pre = '<a href="#" title="' . ENTRY_PUBLISHED_FUTURE . '" onclick="alert(this.title)"><img src="' . serendipity_getTemplateFile('admin/img/clock_future.png') . '" alt="*" style="border: 0px none ; vertical-align: bottom;" /></a> ';
            } else {
                $entry_pre = '';
            }
            if (serendipity_db_bool($entry['properties']['ep_is_sticky'])) {
                $entry_pre .= ' ' . STICKY_POSTINGS . ': ';
            }
            if (serendipity_db_bool($entry['isdraft'])) {
                $entry_pre .= ' ' . DRAFT . ': ';
            }
            ?>
<!--            <div class="serendipity_admin_list_item serendipity_admin_list_item_<?php 
            echo $rows % 2 ? 'even' : 'uneven';
            ?>
"> -->
            <div class="serendipity_admin_list_item serendipity_admin_list_item_<?php 
            echo $rows % 2 ? 'even' : 'uneven';
            ?>
">

                <table width="100%" cellspacing="0" cellpadding="3">
                    <tr>
                        <td>
                            <strong><?php 
            echo $entry_pre;
            ?>
<a href="?serendipity[action]=admin&amp;serendipity[adminModule]=entries&amp;serendipity[adminAction]=edit&amp;serendipity[id]=<?php 
            echo $entry['id'];
            ?>
" title="#<?php 
            echo $entry['id'];
            ?>
"><?php 
            echo serendipity_truncateString(htmlspecialchars($entry['title']), 50);
            ?>
</a></strong>
                        </td>
                        <td align="right">
                            <?php 
            echo serendipity_formatTime(DATE_FORMAT_SHORT, $entry['timestamp']) . ' ' . $lm;
            ?>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <?php 
            echo POSTED_BY . ' ' . htmlspecialchars($entry['author']);
            if (count($entry['categories'])) {
                echo ' ' . IN . ' ';
                $cats = array();
                foreach ($entry['categories'] as $cat) {
                    $caturl = serendipity_categoryURL($cat);
                    $cats[] = '<a href="' . $caturl . '">' . htmlspecialchars($cat['category_name']) . '</a>';
                }
                echo implode(', ', $cats);
            }
            $entry['link'] = serendipity_archiveURL($entry['id'], $entry['title'], 'serendipityHTTPPath', true, array('timestamp' => $entry['timestamp']));
            $entry['preview_link'] = '?serendipity[noBanner]=true&amp;serendipity[noSidebar]=true&amp;serendipity[action]=admin&amp;serendipity[adminModule]=entries&amp;serendipity[adminAction]=preview&amp;serendipity[id]=' . $entry['id'];
            ?>

                        </td>
                        <td align="right">
                            <?php 
            if (serendipity_db_bool($entry['isdraft']) || !$serendipity['showFutureEntries'] && $entry['timestamp'] >= serendipity_serverOffsetHour()) {
                ?>
                            <a target="_blank" href="<?php 
                echo $entry['preview_link'];
                ?>
" title="<?php 
                echo PREVIEW . ' #' . $entry['id'];
                ?>
" class="serendipityIconLink"><img src="<?php 
                echo serendipity_getTemplateFile('admin/img/zoom.png');
                ?>
" alt="<?php 
                echo PREVIEW;
                ?>
" /><?php 
                echo PREVIEW;
                ?>
</a>
                            <?php 
            } else {
                ?>
                            <a target="_blank" href="<?php 
                echo $entry['link'];
                ?>
" title="<?php 
                echo VIEW . ' #' . $entry['id'];
                ?>
" class="serendipityIconLink"><img src="<?php 
                echo serendipity_getTemplateFile('admin/img/zoom.png');
                ?>
" alt="<?php 
                echo VIEW;
                ?>
" /><?php 
                echo VIEW;
                ?>
</a>
                            <?php 
            }
            ?>
                            <a href="?serendipity[action]=admin&amp;serendipity[adminModule]=entries&amp;serendipity[adminAction]=edit&amp;serendipity[id]=<?php 
            echo $entry['id'];
            ?>
" title="<?php 
            echo EDIT . ' #' . $entry['id'];
            ?>
" class="serendipityIconLink"><img src="<?php 
            echo serendipity_getTemplateFile('admin/img/edit.png');
            ?>
" alt="<?php 
            echo EDIT;
            ?>
" /><?php 
            echo EDIT;
            ?>
</a>
                            <a href="?<?php 
            echo serendipity_setFormToken('url');
            ?>
&amp;serendipity[action]=admin&amp;serendipity[adminModule]=entries&amp;serendipity[adminAction]=delete&amp;serendipity[id]=<?php 
            echo $entry['id'];
            ?>
" title="<?php 
            echo DELETE . ' #' . $entry['id'];
            ?>
" class="serendipityIconLink"><img src="<?php 
            echo serendipity_getTemplateFile('admin/img/delete.png');
            ?>
" alt="<?php 
            echo DELETE;
            ?>
" /><?php 
            echo DELETE;
            ?>
</a>
                            <input class="input_checkbox" type="checkbox" name="serendipity[multiDelete][]" value="<?php 
            echo $entry['id'];
            ?>
" />
                        </td>
                    </tr>
                </table>
            </div>
<?php 
        }
        // end entries output
        ?>
        <table class="serendipity_admin_list" cellpadding="5" width="100%">
            <tr>
                <td>
                    <?php 
        if ($offSet > 0) {
            ?>
                        <a href="<?php 
            echo $linkPrevious;
            ?>
" class="serendipityIconLink"><img src="<?php 
            echo serendipity_getTemplateFile('admin/img/previous.png');
            ?>
" /><?php 
            echo PREVIOUS;
            ?>
</a>
                    <?php 
        }
        ?>
                </td>
                <td align="right">
                    <?php 
        if ($count > $perPage) {
            ?>
                        <a href="<?php 
            echo $linkNext;
            ?>
" class="serendipityIconLinkRight"><?php 
            echo NEXT;
            ?>
<img src="<?php 
            echo serendipity_getTemplateFile('admin/img/next.png');
            ?>
" /></a>
                    <?php 
        }
        ?>
                </td>
            </tr>
        </table>

        <table class="serendipity_admin_list" cellpadding="0" width="100%">
            <tr>
                <td align="right">
                    <input type="button" name="toggle" value="<?php 
        echo INVERT_SELECTIONS;
        ?>
" onclick="invertSelection()" class="serendipityPrettyButton input_button" />
                    <input type="submit" name="toggle" value="<?php 
        echo DELETE_SELECTED_ENTRIES;
        ?>
" class="serendipityPrettyButton input_button" />
                </td>
            </tr>
        </table>
        </form>

        <div class="serendipity_admin_list_item serendipity_admin_list_item_<?php 
        echo ($rows + 1) % 2 ? 'even' : 'uneven';
        ?>
">
            <table width="100%" cellspacing="0" cellpadding="3">
                    <tr>
                        <td>
                            <form action="?" method="get">
                                <input type="hidden" name="serendipity[action]"      value="admin"      />
                                <input type="hidden" name="serendipity[adminModule]" value="entries"    />
                                <input type="hidden" name="serendipity[adminAction]" value="editSelect" />
                            <?php 
        echo EDIT_ENTRY;
        ?>
: #<input class="input_textbox" type="text" size="3" name="serendipity[id]" /> <input type="submit" name="serendipity[editSubmit]" value="<?php 
        echo GO;
        ?>
" class="serendipityPrettyButton input_button" />
                            </form>
                        </td>
                    </tr>
            </table>
        </div>
 <?php 
    } else {
        // We've got nothing
        ?>
        <tr>
            <td align="center" class="serendipityAdminMsgNote">
                <img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="<?php 
        echo serendipity_getTemplateFile('admin/img/admin_msg_note.png');
        ?>
" alt="" />
                <?php 
        echo NO_ENTRIES_TO_PRINT;
        ?>
            </td>
        </tr>
    </table>
<?php 
    }
    ?>
</div>
<?php 
}
/**
 * Prints the form for editing/creating new blog entries
 *
 * This is the core file where your edit form appears. The Heart Of Gold, so to say.
 *
 * @access public
 * @param   string      The URL where the entry form is submitted to
 * @param   array       An array of hidden input fields that should be passed on to the HTML FORM
 * @param   array       The entry superarray with your entry's contents
 * @param   string      Any error messages that might have occured on the last run
 * @return null
 */
function serendipity_printEntryForm($targetURL, $hiddens = array(), $entry = array(), $errMsg = "")
{
    global $serendipity;
    $serendipity['EditorBrowsers'] = '@(IE|Mozilla|Opera)@i';
    $draftD = '';
    $draftP = '';
    $categoryselector_expanded = false;
    $template_vars = array();
    serendipity_plugin_api::hook_event('backend_entryform', $entry);
    if (isset($entry['isdraft']) && serendipity_db_bool($entry['isdraft']) || !isset($entry['isdraft']) && $serendipity['publishDefault'] == 'draft') {
        $draftD = ' selected="selected"';
        $template_vars['draft_mode'] = 'draft';
    } else {
        $draftP = ' selected="selected"';
        $template_vars['draft_mode'] = 'publish';
    }
    if (isset($entry['moderate_comments']) && serendipity_db_bool($entry['moderate_comments'])) {
        $template_vars['moderate_comments'] = true;
        $moderate_comments = ' checked="checked"';
    } elseif (!isset($entry['moderate_comments']) && ($serendipity['moderateCommentsDefault'] == 'true' || $serendipity['moderateCommentsDefault'] === true)) {
        // This is the default on creation of a new entry and depends on the "moderateCommentsDefault" variable of the configuration.
        $moderate_comments = ' checked="checked"';
        $template_vars['moderate_comments'] = true;
    } else {
        $moderate_comments = '';
        $template_vars['moderate_comments'] = false;
    }
    if (isset($entry['allow_comments']) && serendipity_db_bool($entry['allow_comments'])) {
        $template_vars['allow_comments'] = true;
        $allow_comments = ' checked="checked"';
    } elseif ((!isset($entry['allow_comments']) || $entry['allow_comments'] !== 'false') && (!isset($serendipity['allowCommentsDefault']) || $serendipity['allowCommentsDefault'] == 'true' || $serendipity['allowCommentsDefault'] === true)) {
        // This is the default on creation of a new entry and depends on the "allowCommentsDefault" variable of the configuration.
        $template_vars['allow_comments'] = true;
        $allow_comments = ' checked="checked"';
    } else {
        $template_vars['allow_comments'] = false;
        $allow_comments = '';
    }
    // Fix category list. If the entryForm is displayed after a POST request, the additional category information is lost.
    if (is_array($entry['categories']) && !is_array($entry['categories'][0])) {
        $categories = (array) $entry['categories'];
        $entry['categories'] = array();
        foreach ($categories as $catid) {
            $entry['categories'][] = serendipity_fetchCategoryInfo($catid);
        }
    }
    $n = "\n";
    $cat_list = '<select id="categoryselector" name="serendipity[categories][]" style="vertical-align: middle;" multiple="multiple">' . $n;
    $cat_list .= '    <option value="0">[' . NO_CATEGORY . ']</option>' . $n;
    $selected = array();
    if (is_array($entry['categories'])) {
        if (count($entry['categories']) > 1) {
            $categoryselector_expanded = true;
        }
        foreach ($entry['categories'] as $cat) {
            $selected[] = $cat['categoryid'];
        }
    }
    if (count($selected) > 1 || isset($serendipity['POST']['categories']) && is_array($serendipity['POST']['categories']) && sizeof($serendipity['POST']['categories']) > 1) {
        $categoryselector_expanded = true;
    }
    if (is_array($cats = serendipity_fetchCategories())) {
        $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
        foreach ($cats as $cat) {
            if (in_array($cat['categoryid'], $selected)) {
                $cat['is_selected'] = true;
            }
            $cat['depth_pad'] = str_repeat('&nbsp;', $cat['depth']);
            $template_vars['category_options'][] = $cat;
            $cat_list .= '<option value="' . $cat['categoryid'] . '"' . ($cat['is_selected'] ? ' selected="selected"' : '') . '>' . $cat['depth_pad'] . $cat['category_name'] . '</option>' . "\n";
        }
    }
    $cat_list .= '</select>' . $n;
    if (!empty($serendipity['GET']['title'])) {
        $entry['title'] = utf8_decode(urldecode($serendipity['GET']['title']));
    }
    if (!empty($serendipity['GET']['body'])) {
        $entry['body'] = utf8_decode(urldecode($serendipity['GET']['body']));
    }
    if (!empty($serendipity['GET']['url'])) {
        $entry['body'] .= "\n" . '<br /><a href="' . htmlspecialchars(utf8_decode(urldecode($serendipity['GET']['url']))) . '">' . $entry['title'] . '</a>';
    }
    $hidden = '';
    foreach ($hiddens as $key => $value) {
        $hidden .= '        <input type="hidden" name="' . $key . '" value="' . $value . '" />' . $n;
    }
    $hidden .= '        <input type="hidden" id="entryid" name="serendipity[id]" value="' . (isset($entry['id']) ? $entry['id'] : '') . '" />' . $n;
    $hidden .= '        <input type="hidden" name="serendipity[timestamp]" value="' . (isset($entry['timestamp']) ? serendipity_serverOffsetHour($entry['timestamp']) : serendipity_serverOffsetHour(time())) . '" />' . $n;
    $hidden .= '        <input type="hidden" name="serendipity[preview]" value="false" />';
    $hidden .= '        ' . serendipity_setFormToken();
    if (is_object($serendipity['smarty']) || !$_SESSION['no_smarty'] && serendipity_smarty_init()) {
        $use_smarty = true;
    } else {
        $use_smarty = false;
    }
    if (is_object($serendipity['smarty'])) {
        if (isset($serendipity['allowDateManipulation']) && $serendipity['allowDateManipulation']) {
            $template_vars['allowDateManipulation'] = true;
        }
        if ((!empty($entry['extended']) || !empty($serendipity['COOKIE']['toggle_extended'])) && !$serendipity['wysiwyg']) {
            $template_vars['show_wysiwyg'] = true;
        }
        if (preg_match($serendipity['EditorBrowsers'], $_SERVER['HTTP_USER_AGENT'])) {
            $template_vars['wysiwyg_advanced'] = true;
        }
        $template_vars['timestamp'] = serendipity_serverOffsetHour(isset($entry['timestamp']) && $entry['timestamp'] > 0 ? $entry['timestamp'] : time());
        $template_vars['reset_timestamp'] = serendipity_serverOffsetHour(time());
        $template_vars['hidden'] = $hidden;
        $template_vars['errMsg'] = $errMsg;
        $template_vars['entry'] =& $entry;
        $template_vars['targetURL'] = $targetURL;
        $template_vars['cat_count'] = count($cats) + 1;
        $template_vars['cat_state'] = $categoryselector_expanded ? 'on' : 'off';
        $template_vars['wysiwyg'] = $serendipity['wysiwyg'];
        $template_vars['serendipityRightPublish'] = $_SESSION['serendipityRightPublish'];
        $template_vars['wysiwyg_blocks'] = array('body' => 'serendipity[body]', 'extended' => 'serendipity[extended]');
        $template_vars['entry_template'] = serendipity_getTemplateFile('admin/entries.tpl', 'serendipityPath');
        $serendipity['smarty']->registerPlugin('modifier', 'emit_htmlarea_code', 'serendipity_emit_htmlarea_code');
        $serendipity['smarty']->assign('admin_view', 'entryform');
        serendipity_plugin_api::hook_event('backend_entryform_smarty', $template_vars);
        $serendipity['smarty']->assignByRef('entry_vars', $template_vars);
        $serendipity['smarty']->display($template_vars['entry_template']);
        return true;
    }
    /* HTML CODE BELOW IS FOR FALLBACK PORTABILITY ONLY - MODIFY CODE IN TEMPLATE ADMIN/ENTRIES.TPL INSTEAD! */
    if (!empty($errMsg)) {
        ?>
        <div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="<?php 
        echo serendipity_getTemplateFile('admin/img/admin_msg_error.png');
        ?>
" alt="" /><?php 
        echo $errMsg;
        ?>
</div>
<?php 
    }
    ?>
        <form <?php 
    echo $entry['entry_form'];
    ?>
 action="<?php 
    echo $targetURL;
    ?>
" method="post" id="serendipityEntry" style="margin-top: 0px; margin-bottom: 0px; padding-top: 0px; padding-bottom: 0px">
        <?php 
    echo $hidden;
    ?>

        <table class="serendipityEntryEdit" border="0" width="100%">
            <tr>
                <td>
                   <b><?php 
    echo TITLE;
    ?>
:</b>
                </td>
                <td colspan="2">
                    <table width="100%" cellspacing="0" cellpadding="0" border="0">
                        <tr>
                            <td><input class="input_textbox" type="text" id="entryTitle" name="serendipity[title]" value="<?php 
    echo isset($entry['title']) ? htmlspecialchars($entry['title']) : '';
    ?>
" size="60" /></td>
                            <td align="right">
                                <select name="serendipity[isdraft]">
                                    <?php 
    if ($_SESSION['serendipityRightPublish']) {
        ?>
<option  value="false" <?php 
        echo $draftP;
        ?>
><?php 
        echo PUBLISH;
        ?>
</option><?php 
    }
    ?>
                                    <option  value="true"  <?php 
    echo $draftD;
    ?>
><?php 
    echo DRAFT;
    ?>
</option>
                                </select>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
            <tr>
<?php 
    if (isset($serendipity['allowDateManipulation']) && $serendipity['allowDateManipulation']) {
        ?>
                <td>
                    <b><?php 
        echo DATE;
        ?>
:</b>
                </td>
                <td>
                    <input type="hidden" name="serendipity[chk_timestamp]" value="<?php 
        echo serendipity_serverOffsetHour(isset($entry['timestamp']) && $entry['timestamp'] > 0 ? $entry['timestamp'] : time());
        ?>
" />
                    <input class="input_textbox" type="text" name="serendipity[new_timestamp]" id="serendipityNewTimestamp" value="<?php 
        echo date(DATE_FORMAT_2, serendipity_serverOffsetHour(isset($entry['timestamp']) && $entry['timestamp'] > 0 ? $entry['timestamp'] : time()));
        ?>
" />
                    <a href="#" onclick="document.getElementById('serendipityNewTimestamp').value = '<?php 
        echo date(DATE_FORMAT_2, serendipity_serverOffsetHour(time()));
        ?>
'; return false;" title="<?php 
        echo RESET_DATE_DESC;
        ?>
"><img src="<?php 
        echo serendipity_getTemplateFile('admin/img/clock.png');
        ?>
" border="0"  style="vertical-align: text-top;" alt="<?php 
        echo RESET_DATE;
        ?>
" /></a>
                </td>
                <td align="right">
<?php 
    } else {
        ?>
                <td align="right" colspan="3">
<?php 
    }
    ?>
                    <a style="border:0; text-decoration: none" href="#" onclick="showItem('categoryselector'); return false" title="<?php 
    echo TOGGLE_OPTION;
    ?>
"><img src="<?php 
    echo serendipity_getTemplateFile('img/plus.png');
    ?>
" id="option_categoryselector" style="border: 20px" alt="" border="0" /></a> <b><?php 
    echo CATEGORY;
    ?>
:</b> <?php 
    echo $cat_list;
    ?>
                    <script type="text/javascript" language="JavaScript">

                    function toggle_extended(setCookie) {
                        var textarea = document.getElementById('serendipity[extended]');
                        var button   = document.getElementById('option_extended');
                        var tools    = document.getElementById('tools_extended');
                        if ( textarea.style.display == 'none' ) {
                            textarea.style.display = '';
                            tools.style.display = '';
                            button.src = '<?php 
    echo serendipity_getTemplateFile('img/minus.png');
    ?>
';
                            if (setCookie == true) {
                                document.cookie = 'serendipity[toggle_extended]=true;';
                            }
                        } else {
                            textarea.style.display = 'none';
                            tools.style.display = 'none';
                            button.src = '<?php 
    echo serendipity_getTemplateFile('img/plus.png');
    ?>
';
                            if (setCookie == true) {
                                document.cookie = 'serendipity[toggle_extended]=;';
                            }
                        }
                    }

                    var selector_toggle  = new Array();
                    var selector_store   = new Array();
                    var selector_restore = new Array();

                    function showItem(id) {
                        var selected = 0;
                        if (typeof(id) == 'undefined' || typeof(id) == 'object') {
                            id = 'categoryselector';
                        }

                        if (document.getElementById) {
                            el = document.getElementById(id);
                            if (selector_toggle[id] && selector_toggle[id] == 'off') {
                                selector_restore[id] = new Array();
                                selector_toggle[id]  = 'on';

                                /* Hack to make sure that when the single dropdown is shown, don't have multiple selections */
                                last = 0;

                                for (i=0; i < el.options.length; i++) {
                                    if (el.options[i].selected == true) {
                                        selected++;
                                        last = i;
                                        selector_restore[id][last] = 'on';
                                    }

                                    if (selected > 1) {
                                        /* If there is more than one selected, we reset all those to false
                                           This is because otherwise the label will say 'No Category', but the categories will still be selected */
                                        for (j=0; j < el.options.length; j++) {
                                            /* Save selection in array to later restore them */
                                            if (el.options[j].selected == true) {
                                                el.options[j].selected = false;
                                                selector_restore[id][j] = 'on';
                                                last = j;
                                            } else {
                                                selector_restore[id][j] = false;
                                            }
                                        }
                                        break;
                                    }
                                }

                                el.selectedIndex = null;
                                if (last > 0) {
                                    el.selectedIndex = last;
                                }

                                el.size = 1;

                                /* Show a normal dropdown */
                                if (el.multiple) {
                                    el.multiple = false;
                                }

                                document.getElementById('option_' + id).src = '<?php 
    echo serendipity_getTemplateFile('img/plus.png');
    ?>
';
                            } else {
                                selector_store[id] = el.size;
                                if (selector_store[id] == 0) {
                                    selector_store[id] = 5;
                                }

                                last = 0;
                                if (el.selectedIndex > 0) {
                                    if (!selector_restore[id]) {
                                        selector_restore[id] = new Array();
                                    }

                                    for (j=0; j < el.options.length; j++) {
                                        /* Save selection in array to later restore them */
                                        if (el.options[j].selected == true) {
                                            selector_restore[id][j] = 'on';
                                            last = j;
                                        }
                                    }
                                }
                                el.selectedIndex = -1;
                                el.size = <?php 
    echo count($cats) + 1;
    ?>
;
                                selector_toggle[id] = 'off';

                                /* Show multiple items */
                                el.multiple = true;

                                /* Restore previously selected items? */
                                last = 0;
                                for (i = 0; i < el.options.length; i++) {
                                    if (selector_restore && selector_restore[id] && selector_restore[id][i] && selector_restore[id][i] == 'on') {
                                        val = el.options[i].value;
                                        if (el.options[i].selected != true) {
                                            el.options[i].selected = true;
                                            last = i;
                                            // [TODO] IE Bug: Don't ask me why, but this restoring only works in Internet Explorer if you put this:
                                            // alert('it doesnt matter what, just the alert is important');
                                        }
                                    }
                                }

                                document.getElementById('option_' + id).src = '<?php 
    echo serendipity_getTemplateFile('img/minus.png');
    ?>
';
                            }
                        }
                    }

                    function checkSave() {
<?php 
    $void = null;
    serendipity_plugin_api::hook_event('backend_entry_checkSave', $void);
    ?>
                        return true;
                    }

                    selector_toggle['categoryselector'] = '<?php 
    echo $categoryselector_expanded ? 'on' : 'off';
    ?>
';
                    addLoadEvent(showItem);
                    </script>
                    </td>
            </tr>
            <tr>
<?php 
    if (!$serendipity['wysiwyg']) {
        ?>
                <td colspan="2"><b><?php 
        echo ENTRY_BODY;
        ?>
</b></td>
                <td align="right">
<?php 
        /* Since the user has WYSIWYG editor disabled, we want to check if we should use the "better" non-WYSIWYG editor */
        if (!$serendipity['wysiwyg'] && preg_match($serendipity['EditorBrowsers'], $_SERVER['HTTP_USER_AGENT'])) {
            ?>
                  <script type="text/javascript" language="JavaScript">
                        document.write('<input type="button" class="serendipityPrettyButton input_button" name="insI" value="I" accesskey="i" style="font-style: italic" onclick="wrapSelection(document.forms[\'serendipityEntry\'][\'serendipity[body]\'],\'<em>\',\'</em>\')" />');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" name="insB" value="B" accesskey="b" style="font-weight: bold" onclick="wrapSelection(document.forms[\'serendipityEntry\'][\'serendipity[body]\'],\'<strong>\',\'</strong>\')" />');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" name="insU" value="U" accesskey="u" style="text-decoration: underline;" onclick="wrapSelection(document.forms[\'serendipityEntry\'][\'serendipity[body]\'],\'<u>\',\'</u>\')" />');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" name="insQ" value="<?php 
            echo QUOTE;
            ?>
" accesskey="q" style="font-style: italic" onclick="wrapSelection(document.forms[\'serendipityEntry\'][\'serendipity[body]\'],\'<blockquote>\',\'</blockquote>\')" />');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" name="insJ" value="img" accesskey="j" onclick="wrapInsImage(document.forms[\'serendipityEntry\'][\'serendipity[body]\'])" />');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" name="insImage" value="<?php 
            echo MEDIA;
            ?>
" style="" onclick="window.open(\'serendipity_admin_image_selector.php?serendipity[textarea]=body\', \'ImageSel\', \'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1\');" />');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" name="insURL" value="URL" accesskey="l" onclick="wrapSelectionWithLink(document.forms[\'serendipityEntry\'][\'serendipity[body]\'])" />');
                  </script>
<?php 
            /* Do the "old" non-WYSIWYG editor */
        } elseif (!$serendipity['wysiwyg']) {
            ?>
                  <script type="text/javascript" language="JavaScript">
                        document.write('<input type="button" class="serendipityPrettyButton input_button" value=" B " onclick="serendipity_insBasic(document.forms[\'serendipityEntry\'][\'serendipity[body]\'], \'b\')">');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" value=" U " onclick="serendipity_insBasic(document.forms[\'serendipityEntry\'][\'serendipity[body]\'], \'u\')">');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" value=" I " onclick="serendipity_insBasic(document.forms[\'serendipityEntry\'][\'serendipity[body]\'], \'i\')">');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" value="<img>" onclick="serendipity_insImage(document.forms[\'serendipityEntry\'][\'serendipity[body]\'])">');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" value="<?php 
            echo MEDIA;
            ?>
" onclick="window.open(\'serendipity_admin_image_selector.php?serendipity[textarea]=body\', \'ImageSel\', \'width=800,height=600,toolbar=no\');">');
                        document.write('<input type="button" class="serendipityPrettyButton input_button" value="Link" onclick="serendipity_insLink(document.forms[\'serendipityEntry\'][\'serendipity[body]\'])">');
                </script>
<?php 
        }
        serendipity_plugin_api::hook_event('backend_entry_toolbar_body', $entry);
    } else {
        ?>
            <td colspan="2"><b><?php 
        echo ENTRY_BODY;
        ?>
</b></td>
            <td><?php 
        serendipity_plugin_api::hook_event('backend_entry_toolbar_body', $entry);
        ?>

<?php 
    }
    ?>
                </td>
            </tr>

            <tr>
                <td colspan="3">
                    <textarea style="width: 100%" name="serendipity[body]" id="serendipity[body]" cols="80" rows="20"><?php 
    echo isset($entry['body']) ? htmlspecialchars($entry['body']) : '';
    ?>
</textarea>
                </td>
            </tr>

            <tr>
                <td colspan="3">
                    <table width="100%" cellpadding="0" cellspacing="0">
                        <tr>
                            <td align="left" width="70%">
                                <input class="input_checkbox" id="checkbox_allow_comments" type="checkbox" name="serendipity[allow_comments]" value="true" <?php 
    echo $allow_comments;
    ?>
 /><label for="checkbox_allow_comments"><?php 
    echo COMMENTS_ENABLE;
    ?>
</label><br />
                                <input class="input_checkbox" id="checkbox_moderate_comments" type="checkbox" name="serendipity[moderate_comments]" value="true" <?php 
    echo $moderate_comments;
    ?>
 /><label for="checkbox_moderate_comments"><?php 
    echo COMMENTS_MODERATE;
    ?>
</label>
                            </td>
                            <td align="right" rowspan="2" valign="middle" width="30%">
                                <input accesskey="p" type="submit" value="- <?php 
    echo PREVIEW;
    ?>
 -" class="serendipityPrettyButton input_button"  style="width: 150px" onclick="document.forms['serendipityEntry'].elements['serendipity[preview]'].value='true';" /><br />
                                <input accesskey="s" type="submit" onclick="return checkSave();" value="- <?php 
    echo SAVE;
    ?>
 -" class="serendipityPrettyButton input_button" style="width: 150px" />
                            </td>
                        </tr>
                    </table>
                    <br />
                </td>
            </tr>

            <tr>
                <td colspan="2">
<?php 
    if (!$serendipity['wysiwyg']) {
        ?>
                    <a style="border:0; text-decoration: none" href="#" onclick="toggle_extended(true); return false;" title="<?php 
        echo TOGGLE_OPTION;
        ?>
"><img src="<?php 
        echo serendipity_getTemplateFile('img/plus.png');
        ?>
" id="option_extended" alt="+/-" border="0" /></a>
<?php 
    }
    ?>
 <b><?php 
    echo EXTENDED_BODY;
    ?>
</b></td>
                <td align="right">
                <?php 
    if (!$serendipity['wysiwyg']) {
        ?>
                    <div id="tools_extended" style="display: none">
<?php 
        /* Since the user has WYSIWYG editor disabled, we want to check if we should use the "better" non-WYSIWYG editor */
        if (preg_match($serendipity['EditorBrowsers'], $_SERVER['HTTP_USER_AGENT'])) {
            ?>
                        <input type="button" class="serendipityPrettyButton input_button" name="insI" value="I" accesskey="i" style="font-style: italic" onclick="wrapSelection(document.forms['serendipityEntry']['serendipity[extended]'],'<em>','</em>')" />
                        <input type="button" class="serendipityPrettyButton input_button" name="insB" value="B" accesskey="b" style="font-weight: bold" onclick="wrapSelection(document.forms['serendipityEntry']['serendipity[extended]'],'<strong>','</strong>')" />
                        <input type="button" class="serendipityPrettyButton input_button" name="insU" value="U" accesskey="u" style="text-decoration: underline;" onclick="wrapSelection(document.forms['serendipityEntry']['serendipity[extended]'],'<u>','</u>')" />
                        <input type="button" class="serendipityPrettyButton input_button" name="insQ" value="<?php 
            echo QUOTE;
            ?>
" accesskey="q" style="font-style: italic" onclick="wrapSelection(document.forms['serendipityEntry']['serendipity[extended]'],'<blockquote>','</blockquote>')" />
                        <input type="button" class="serendipityPrettyButton input_button" name="insJ" value="img" accesskey="j" onclick="wrapInsImage(document.forms['serendipityEntry']['serendipity[extended]'])" />
                        <input type="button" class="serendipityPrettyButton input_button" name="insImage" value="<?php 
            echo MEDIA;
            ?>
" onclick="window.open('serendipity_admin_image_selector.php?serendipity[textarea]=extended', 'ImageSel', 'width=800,height=600,toolbar=no,scrollbars=1,scrollbars,resize=1,resizable=1');" />
                        <input type="button" class="serendipityPrettyButton input_button" name="insURL" value="URL" accesskey="l" onclick="wrapSelectionWithLink(document.forms['serendipityEntry']['serendipity[extended]'])" />
<?php 
            /* Do the "old" non-WYSIWYG editor */
        } else {
            ?>
                        <input type="button" class="serendipityPrettyButton input_button" value=" B " onclick="serendipity_insBasic(document.forms['serendipityEntry']['serendipity[extended]'], 'b')">
                        <input type="button" class="serendipityPrettyButton input_button" value=" U " onclick="serendipity_insBasic(document.forms['serendipityEntry']['serendipity[extended]'], 'u')">
                        <input type="button" class="serendipityPrettyButton input_button" value=" I " onclick="serendipity_insBasic(document.forms['serendipityEntry']['serendipity[extended]'], 'i')">
                        <input type="button" class="serendipityPrettyButton input_button" value="<img>" onclick="serendipity_insImage(document.forms['serendipityEntry']['serendipity[extended]'])">
                        <input type="button" class="serendipityPrettyButton input_button" value="<?php 
            echo MEDIA;
            ?>
" onclick="window.open('serendipity_admin_image_selector.php?serendipity[textarea]=extended', 'ImageSel', 'width=800,height=600,toolbar=no');">
                        <input type="button" class="serendipityPrettyButton input_button" value="Link" onclick="serendipity_insLink(document.forms['serendipityEntry']['serendipity[extended]'])">
<?php 
        }
        serendipity_plugin_api::hook_event('backend_entry_toolbar_extended', $entry);
        ?>
                    </div>
<?php 
    } else {
        serendipity_plugin_api::hook_event('backend_entry_toolbar_extended', $entry);
    }
    ?>
               </td>
            </tr>

            <tr>
                <td colspan="3">
                    <textarea style="width: 100%;" name="serendipity[extended]" id="serendipity[extended]" cols="80" rows="20"><?php 
    echo isset($entry['extended']) ? htmlspecialchars($entry['extended']) : '';
    ?>
</textarea>
<?php 
    if (!$serendipity['wysiwyg']) {
        ?>
                    <script type="text/javascript" language="JavaScript">
                       toggle_extended();
                    </script>
<?php 
    }
    ?>
                </td>
            </tr>

            <tr>
                <td colspan="3">
                    <br />
                    <fieldset>
                        <legend><b><?php 
    echo ADVANCED_OPTIONS;
    ?>
</b></legend>
<?php 
    serendipity_plugin_api::hook_event('backend_display', $entry);
    ?>
                    </fieldset>
                </td>
            </tr>
        </table>
    </form>
<?php 
    if ((!empty($entry['extended']) || !empty($serendipity['COOKIE']['toggle_extended'])) && !$serendipity['wysiwyg']) {
        ?>
    <script type="text/javascript" language="JavaScript">
        toggle_extended();
    </script>
<?php 
    }
    if ($serendipity['wysiwyg']) {
        $fields = array('body' => 'serendipity[body]', 'extended' => 'serendipity[extended]');
        foreach ($fields as $f_jsname => $f_item) {
            serendipity_emit_htmlarea_code($f_item, $f_jsname);
        }
        serendipity_plugin_api::hook_event('backend_wysiwyg_finish', $fields);
    }
    echo '    <script type="text/javascript" language="JavaScript" src="serendipity_define.js.php"></script>';
    echo '    <script type="text/javascript" language="JavaScript" src="serendipity_editor.js"></script>';
}
 function getRelatedCategories()
 {
     global $serendipity;
     $res = serendipity_fetchCategories($serendipity['authorid']);
     $ret[0] = NONE;
     if (is_array($res)) {
         foreach ($res as $value) {
             $ret[$value['categoryid']] = $value['category_name'];
         }
     }
     return $ret;
 }
 function &getCategories()
 {
     global $serendipity;
     $html = ($serendipity['version'][0] < 2 ? '<strong>' . CATEGORIES . '</strong><br />' : '<span class="wrap_legend"><legend>' . CATEGORIES . '</legend></span>') . "\n";
     $all_valid = false;
     if (is_array($serendipity['POST']['plugin']['enabled_categories'])) {
         $valid = $this->enabled_categories = array();
         foreach ($serendipity['POST']['plugin']['enabled_categories'] as $idx => $id) {
             $valid[$id] = true;
             $this->enabled_categories[$id] = true;
         }
     } else {
         $valid =& $this->enabled_categories;
         if (count($valid) == 0) {
             $all_valid = true;
         }
     }
     $html .= '<select id="staticblock_enabled_categories" name="serendipity[plugin][enabled_categories][]" multiple="true" size="5">' . "\n";
     $html .= '    <option value="-front-" ' . ($all_valid || isset($valid['-front-']) ? "selected='selected'" : '') . '>[' . NO_CATEGORY . ']</option>' . "\n";
     if (is_array($cats = serendipity_fetchCategories())) {
         $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
         foreach ($cats as $cat) {
             $html .= '    <option value="' . $cat['categoryid'] . '"' . ($all_valid || isset($valid[$cat['categoryid']]) ? ' selected="selected"' : '') . '>' . str_repeat(' ', $cat['depth']) . $cat['category_name'] . '</option>' . "\n";
         }
     }
     $html .= '</select>' . "\n";
     return $html;
 }
 function generate_content(&$title)
 {
     global $serendipity;
     $title = $this->get_config('title');
     $smarty = serendipity_db_bool($this->get_config('smarty', false));
     $which_category = $this->get_config('authorid');
     $sort = $this->get_config('sort_order');
     if ($sort == 'none') {
         $sort = '';
     } else {
         $sort .= ' ' . $this->get_config('sort_method');
     }
     $is_form = serendipity_db_bool($this->get_config('allow_select'));
     if ($which_category === "login") {
         $which_category = (int) $serendipity['authorid'];
         if ($which_category === 0) {
             $which_category = -1;
             // Set to -1 for anonymous authors to get a proper match.
         }
     }
     $categories = serendipity_fetchCategories(empty($which_category) ? 'all' : $which_category, '', $sort, 'read');
     $cat_count = array();
     if (serendipity_db_bool($this->get_config('show_count'))) {
         $cat_sql = "SELECT c.categoryid, c.category_name, count(e.id) as postings\n                                            FROM {$serendipity['dbPrefix']}entrycat ec,\n                                                 {$serendipity['dbPrefix']}category c,\n                                                 {$serendipity['dbPrefix']}entries e\n                                            WHERE ec.categoryid = c.categoryid\n                                              AND ec.entryid = e.id\n                                              AND e.isdraft = 'false'\n                                                  " . (!serendipity_db_bool($serendipity['showFutureEntries']) ? " AND e.timestamp  <= " . serendipity_db_time() : '') . "\n                                            GROUP BY c.categoryid, c.category_name\n                                            ORDER BY postings DESC";
         $category_rows = serendipity_db_query($cat_sql);
         if (is_array($category_rows)) {
             foreach ($category_rows as $cat) {
                 $cat_count[$cat['categoryid']] = $cat['postings'];
             }
         }
     }
     $html = '';
     if (!$smarty && $is_form) {
         $html .= '<form action="' . $serendipity['baseURL'] . $serendipity['indexFile'] . '?frontpage" method="post">
           <div id="serendipity_category_form_content">';
     }
     if (!$smarty) {
         $html .= '<ul id="serendipity_categories_list" style="list-style: none; margin: 0px; padding: 0px">';
     }
     $image = $this->get_config('image', serendipity_getTemplateFile('img/xml.gif'));
     $image = $image == "'none'" || $image == 'none' ? '' : $image;
     $use_parent = $this->get_config('parent_base');
     $hide_parent = serendipity_db_bool($this->get_config('hide_parent'));
     $parentdepth = 0;
     $hide_parallel = serendipity_db_bool($this->get_config('hide_parallel'));
     $hidedepth = 0;
     if (is_array($categories) && count($categories)) {
         $categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED);
         foreach ($categories as $cid => $cat) {
             // Hide parents not wanted
             if ($use_parent && $use_parent != 'all') {
                 if ($parentdepth == 0 && $cat['parentid'] != $use_parent && $cat['categoryid'] != $use_parent) {
                     unset($categories[$cid]);
                     continue;
                 } else {
                     if ($hide_parent && $cat['categoryid'] == $use_parent) {
                         unset($categories[$cid]);
                         continue;
                     }
                     if ($cat['depth'] < $parentdepth) {
                         $parentdepth = 0;
                         unset($categories[$cid]);
                         continue;
                     }
                     if ($parentdepth == 0) {
                         $parentdepth = $cat['depth'];
                     }
                 }
             }
             // Hide parents outside of our tree
             if ($hide_parallel && $serendipity['GET']['category']) {
                 if ($hidedepth == 0 && $cat['parentid'] != $serendipity['GET']['category'] && $cat['categoryid'] != $serendipity['GET']['category']) {
                     unset($categories[$cid]);
                     continue;
                 } else {
                     if ($cat['depth'] < $hidedepth) {
                         $hidedepth = 0;
                         unset($categories[$cid]);
                         continue;
                     }
                     if ($hidedepth == 0) {
                         $hidedepth = $cat['depth'];
                     }
                 }
             }
             $categories[$cid]['feedCategoryURL'] = serendipity_feedCategoryURL($cat, 'serendipityHTTPPath');
             $categories[$cid]['categoryURL'] = serendipity_categoryURL($cat, 'serendipityHTTPPath');
             $categories[$cid]['paddingPx'] = $cat['depth'] * 6;
             $categories[$cid]['catdepth'] = $cat['depth'];
             if (!empty($cat_count[$cat['categoryid']])) {
                 $categories[$cid]['true_category_name'] = $cat['category_name'];
                 $categories[$cid]['category_name'] .= ' (' . $cat_count[$cat['categoryid']] . ')';
                 $categories[$cid]['article_count'] = $cat_count[$cat['categoryid']];
             }
             if (!$smarty) {
                 $html .= '<li class="category_depth' . $cat['depth'] . ' category_' . $cat['categoryid'] . '" style="display: block;">';
                 if ($is_form) {
                     $html .= '<input style="width: 15px" type="checkbox" name="serendipity[multiCat][]" value="' . $cat['categoryid'] . '" />';
                 }
                 if (!empty($image)) {
                     $html .= '<a class="serendipity_xml_icon" href="' . $categories[$cid]['feedCategoryURL'] . '"><img src="' . $image . '" alt="XML" style="border: 0px" /></a> ';
                 }
                 $html .= '<a href="' . $categories[$cid]['categoryURL'] . '" title="' . htmlspecialchars($cat['category_description']) . '" style="padding-left: ' . $categories[$cid]['paddingPx'] . 'px">' . htmlspecialchars($categories[$cid]['category_name']) . '</a>';
                 $html .= '</li>' . "\n";
             }
         }
     }
     if (!$smarty) {
         $html .= '</ul>';
     }
     if (!$smarty && $is_form) {
         $html .= '<div class="category_submit"><br /><input type="submit" name="serendipity[isMultiCat]" value="' . GO . '" /></div>';
     }
     if (!$smarty) {
         $html .= sprintf('<div class="category_link_all"><br /><a href="%s" title="%s">%s</a></div>', $serendipity['serendipityHTTPPath'] . $serendipity['indexFile'] . '?frontpage', ALL_CATEGORIES, ALL_CATEGORIES);
     }
     if (!$smarty && $is_form) {
         $html .= '</div></form>';
     }
     if (!$smarty) {
         echo $html;
     } else {
         $plugin_categories_data = array('is_form' => $is_form, 'category_image' => $image, 'form_url' => $serendipity['baseURL'] . $serendipity['indexFile'] . '?frontpage', 'categories' => is_array($categories) ? $categories : array());
         $serendipity['smarty']->assign($plugin_categories_data);
         echo serendipity_smarty_fetch('CATEGORIES', 'plugin_categories.tpl');
     }
 }
Example #16
0
 function import_wpxrss()
 {
     // TODO: Backtranscoding to NATIVE charset. Currently only works with UTF-8.
     $dry_run = false;
     $serendipity['noautodiscovery'] = 1;
     $uri = $this->data['url'];
     require_once S9Y_PEAR_PATH . 'HTTP/Request.php';
     serendipity_request_start();
     $req = new HTTP_Request($uri, array('allowRedirects' => true, 'maxRedirects' => 5));
     $res = $req->sendRequest();
     if (PEAR::isError($res) || $req->getResponseCode() != '200') {
         serendipity_request_end();
         echo IMPORT_FAILED . ': ' . htmlspecialchars($this->data['url']);
         echo "<br />\n";
         return false;
     }
     $fContent = $req->getResponseBody();
     serendipity_request_end();
     echo strlen($fContent) . " Bytes<br />\n";
     if (version_compare(PHP_VERSION, '5.0') === -1) {
         printf(UNMET_REQUIREMENTS, 'PHP >= 5.0');
         echo "<br />\n";
         return false;
     }
     $xml = simplexml_load_string($fContent);
     unset($fContent);
     /* ************* USERS **********************/
     $_s9y_users = serendipity_fetchUsers();
     $s9y_users = array();
     if (is_array($s9y_users)) {
         foreach ($_s9y_users as $v) {
             $s9y_users[$v['realname']] = $v;
         }
     }
     /* ************* CATEGORIES **********************/
     $_s9y_cat = serendipity_fetchCategories('all');
     $s9y_cat = array();
     if (is_array($s9y_cat)) {
         foreach ($_s9y_cat as $v) {
             $s9y_cat[$v['category_name']] = $v['categoryid'];
         }
     }
     $wp_ns = 'http://wordpress.org/export/1.0/';
     $dc_ns = 'http://purl.org/dc/elements/1.1/';
     $content_ns = 'http://purl.org/rss/1.0/modules/content/';
     $wp_core = $xml->channel->children($wp_ns);
     foreach ($wp_core->category as $idx => $cat) {
         //TODO: Parent generation unknown.
         $cat_name = (string) $cat->cat_name;
         if (!isset($s9y_cat[$cat_name])) {
             $cat = array('category_name' => $cat_name, 'category_description' => '', 'parentid' => 0, 'category_left' => 0, 'category_right' => 0);
             printf(CREATE_CATEGORY, htmlspecialchars($cat_name));
             echo "<br />\n";
             if ($dry_run) {
                 $s9y_cat[$cat_name] = time();
             } else {
                 serendipity_db_insert('category', $cat);
                 $s9y_cat[$cat_name] = serendipity_db_insert_id('category', 'categoryid');
             }
         }
     }
     /* ************* ITEMS **********************/
     foreach ($xml->channel->item as $idx => $item) {
         $wp_items = $item->children($wp_ns);
         $dc_items = $item->children($dc_ns);
         $content_items = $item->children($content_ns);
         // TODO: Attachments not handled
         if ((string) $wp_items->post_type == 'attachment' or (string) $wp_items->post_type == 'page') {
             continue;
         }
         $entry = array('title' => (string) $item->title, 'isdraft' => (string) $wp_items->status == 'publish' ? 'false' : 'true', 'allow_comments' => (string) $wp_items->comment_status == 'open' ? true : false, 'categories' => array(), 'body' => (string) $content_items->encoded);
         if (preg_match('@^([0-9]{4})\\-([0-9]{2})\\-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$@', (string) $wp_items->post_date, $timematch)) {
             $entry['timestamp'] = mktime($timematch[4], $timematch[5], $timematch[6], $timematch[2], $timematch[3], $timematch[1]);
         } else {
             $entry['timestamp'] = time();
         }
         if (isset($item->category[1])) {
             foreach ($item->category as $idx => $category) {
                 $cstring = (string) $category;
                 if (!isset($s9y_cat[$cstring])) {
                     echo "WARNING: {$category} unset!<br />\n";
                 } else {
                     $entry['categories'][] = $s9y_cat[$cstring];
                 }
             }
         } else {
             $cstring = (string) $item->category;
             $entry['categories'][] = $s9y_cat[$cstring];
         }
         $wp_user = (string) $dc_items->creator;
         if (!isset($s9y_users[$wp_user])) {
             if ($dry_run) {
                 $s9y_users[$wp_user]['authorid'] = time();
             } else {
                 $s9y_users[$wp_user]['authorid'] = serendipity_addAuthor($wp_user, md5(time()), $wp_user, '', USERLEVEL_EDITOR);
             }
             printf(CREATE_AUTHOR, htmlspecialchars($wp_user));
             echo "<br />\n";
         }
         $entry['authorid'] = $s9y_users[$wp_user]['authorid'];
         if ($dry_run) {
             $id = time();
         } else {
             $id = serendipity_updertEntry($entry);
         }
         $s9y_cid = array();
         // Holds comment ids to s9y ids association.
         $c_i = 0;
         foreach ($wp_items->comment as $comment) {
             $c_i++;
             $c_id = (string) $comment->comment_id;
             $c_pid = (string) $comment->comment_parent;
             $c_type = (string) $comment->comment_type;
             if ($c_type == 'pingback') {
                 $c_type2 = 'PINGBACK';
             } elseif ($c_type == 'trackback') {
                 $c_type2 = 'TRACKBACK';
             } else {
                 $c_type2 = 'NORMAL';
             }
             $s9y_comment = array('entry_id ' => $id, 'parent_id' => $s9y_cid[$c_pd], 'author' => (string) $comment->comment_author, 'email' => (string) $comment->comment_author_email, 'url' => (string) $comment->comment_author_url, 'ip' => (string) $comment->comment_author_IP, 'status' => empty($comment->comment_approved) || $comment->comment_approved == '1' ? 'approved' : 'pending', 'subscribed' => 'false', 'body' => (string) $comment->comment_content, 'type' => $c_type2);
             if (preg_match('@^([0-9]{4})\\-([0-9]{2})\\-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})$@', (string) $comment->comment_date, $timematch)) {
                 $s9y_comment['timestamp'] = mktime($timematch[4], $timematch[5], $timematch[6], $timematch[2], $timematch[3], $timematch[1]);
             } else {
                 $s9y_comment['timestamp'] = time();
             }
             if ($dry_run) {
                 $cid = time();
             } else {
                 serendipity_db_insert('comments', $s9y_comment);
                 $cid = serendipity_db_insert_id('comments', 'id');
                 if ($s9y_comment['status'] == 'approved') {
                     serendipity_approveComment($cid, $id, true);
                 }
             }
             $s9y_cid[$c_id] = $cid;
         }
         echo "Entry '" . htmlspecialchars($entry['title']) . "' ({$c_i} comments) imported.<br />\n";
     }
     return true;
 }
Example #17
0
    $data['cat'] = $this_cat;
    if (!is_array($this_cat) || isset($this_cat['authorid']) && $this_cat['authorid'] == '0' || isset($read_groups[0])) {
        $data['selectAllReadAuthors'] = true;
    }
    if (!is_array($this_cat) || isset($this_cat['authorid']) && $this_cat['authorid'] == '0' || isset($write_groups[0])) {
        $data['selectAllWriteAuthors'] = true;
    }
    $categories = serendipity_fetchCategories('all');
    $categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED);
    $data['categories'] = $categories;
    // hook content as var to category.inc.tpl, to place inside the form
    ob_start();
    serendipity_plugin_api::hook_event('backend_category_showForm', $cid, $this_cat);
    $data['category_showForm'] = ob_get_contents();
    ob_end_clean();
}
if ($serendipity['GET']['adminAction'] == 'view') {
    if (empty($admin_category)) {
        $cats = serendipity_fetchCategories('all');
    } else {
        $cats = serendipity_fetchCategories(null, null, null, 'write');
    }
    $data['view'] = true;
    $data['viewCats'] = $cats;
    if (is_array($cats)) {
        $categories = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
        $data['viewCategories'] = $categories;
    }
}
echo serendipity_smarty_show('admin/category.inc.tpl', $data);
/* vim: set sts=4 ts=4 expandtab : */
/**
 * Prints the form for editing/creating new blog entries
 *
 * This is the core file where your edit form appears. The Heart Of Gold, so to say.
 *
 * @access public
 * @param   string      The URL where the entry form is submitted to
 * @param   array       An array of hidden input fields that should be passed on to the HTML FORM
 * @param   array       The entry superarray with your entry's contents
 * @param   string      Any error messages that might have occured on the last run
 * @return null
 */
function serendipity_printEntryForm($targetURL, $hiddens = array(), $entry = array(), $errMsg = "")
{
    global $serendipity;
    $draftD = '';
    $draftP = '';
    $categoryselector_expanded = false;
    $template_vars = array();
    serendipity_plugin_api::hook_event('backend_entryform', $entry);
    if (isset($entry['isdraft']) && serendipity_db_bool($entry['isdraft']) || !isset($entry['isdraft']) && $serendipity['publishDefault'] == 'draft') {
        $draftD = ' selected="selected"';
        $template_vars['draft_mode'] = 'draft';
    } else {
        $draftP = ' selected="selected"';
        $template_vars['draft_mode'] = 'publish';
    }
    if (isset($entry['moderate_comments']) && serendipity_db_bool($entry['moderate_comments'])) {
        $template_vars['moderate_comments'] = true;
        $moderate_comments = ' checked="checked"';
    } elseif (!isset($entry['moderate_comments']) && ($serendipity['moderateCommentsDefault'] == 'true' || $serendipity['moderateCommentsDefault'] === true)) {
        // This is the default on creation of a new entry and depends on the "moderateCommentsDefault" variable of the configuration.
        $moderate_comments = ' checked="checked"';
        $template_vars['moderate_comments'] = true;
    } else {
        $moderate_comments = '';
        $template_vars['moderate_comments'] = false;
    }
    if (isset($entry['allow_comments']) && serendipity_db_bool($entry['allow_comments'])) {
        $template_vars['allow_comments'] = true;
        $allow_comments = ' checked="checked"';
    } elseif ((!isset($entry['allow_comments']) || $entry['allow_comments'] !== 'false') && (!isset($serendipity['allowCommentsDefault']) || $serendipity['allowCommentsDefault'] == 'true' || $serendipity['allowCommentsDefault'] === true)) {
        // This is the default on creation of a new entry and depends on the "allowCommentsDefault" variable of the configuration.
        $template_vars['allow_comments'] = true;
        $allow_comments = ' checked="checked"';
    } else {
        $template_vars['allow_comments'] = false;
        $allow_comments = '';
    }
    // Fix category list. If the entryForm is displayed after a POST request, the additional category information is lost.
    if (is_array($entry['categories']) && !is_array($entry['categories'][0])) {
        $categories = (array) $entry['categories'];
        $entry['categories'] = array();
        foreach ($categories as $catid) {
            $entry['categories'][] = serendipity_fetchCategoryInfo($catid);
        }
    }
    $selected = array();
    if (is_array($entry['categories'])) {
        if (count($entry['categories']) > 1) {
            $categoryselector_expanded = true;
        }
        foreach ($entry['categories'] as $cat) {
            $selected[] = $cat['categoryid'];
        }
    }
    if (count($selected) > 1 || isset($serendipity['POST']['categories']) && is_array($serendipity['POST']['categories']) && sizeof($serendipity['POST']['categories']) > 1) {
        $categoryselector_expanded = true;
    }
    if (is_array($cats = serendipity_fetchCategories())) {
        $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
        foreach ($cats as $cat) {
            if (in_array($cat['categoryid'], $selected)) {
                $cat['is_selected'] = true;
            }
            $cat['depth_pad'] = str_repeat('&nbsp;', $cat['depth']);
            $template_vars['category_options'][] = $cat;
        }
    }
    if (!empty($serendipity['GET']['title'])) {
        $entry['title'] = utf8_decode(urldecode($serendipity['GET']['title']));
    }
    if (!empty($serendipity['GET']['body'])) {
        $entry['body'] = utf8_decode(urldecode($serendipity['GET']['body']));
    }
    if (!empty($serendipity['GET']['url'])) {
        $entry['body'] .= "\n" . '<a class="block_level" href="' . serendipity_specialchars(utf8_decode(urldecode($serendipity['GET']['url']))) . '">' . $entry['title'] . '</a>';
    }
    $template_vars['formToken'] = serendipity_setFormToken();
    if (isset($serendipity['allowDateManipulation']) && $serendipity['allowDateManipulation']) {
        $template_vars['allowDateManipulation'] = true;
    }
    if ((!empty($entry['extended']) || !empty($serendipity['COOKIE']['toggle_extended'])) && !$serendipity['wysiwyg']) {
        $template_vars['show_wysiwyg'] = true;
    }
    $template_vars['wysiwyg_advanced'] = true;
    $template_vars['timestamp'] = serendipity_serverOffsetHour(isset($entry['timestamp']) && $entry['timestamp'] > 0 ? $entry['timestamp'] : time());
    $template_vars['reset_timestamp'] = serendipity_serverOffsetHour(time());
    $template_vars['hiddens'] = $hiddens;
    $template_vars['errMsg'] = $errMsg;
    $template_vars['entry'] =& $entry;
    $template_vars['targetURL'] = $targetURL;
    $template_vars['cat_count'] = count($cats) + 1;
    $template_vars['wysiwyg'] = $serendipity['wysiwyg'];
    $template_vars['serendipityRightPublish'] = $_SESSION['serendipityRightPublish'];
    $template_vars['wysiwyg_blocks'] = array('body' => 'serendipity[body]', 'extended' => 'serendipity[extended]');
    $template_vars['entry_template'] = serendipity_getTemplateFile('admin/entries.tpl', 'serendipityPath');
    if (!is_object($serendipity['smarty'])) {
        serendipity_smarty_init();
    }
    $serendipity['smarty']->registerPlugin('modifier', 'emit_htmlarea_code', 'serendipity_emit_htmlarea_code');
    $serendipity['smarty']->assign('admin_view', 'entryform');
    serendipity_plugin_api::hook_event('backend_entryform_smarty', $template_vars);
    $serendipity['smarty']->assignByRef('entry_vars', $template_vars);
    return serendipity_smarty_show('admin/entries.tpl');
}
    function event_hook($event, &$bag, &$eventData, $addData = null)
    {
        global $serendipity;
        $hooks =& $bag->get('event_hooks');
        if (isset($hooks[$event])) {
            switch ($event) {
                case 'backend_delete_entry':
                    $this->deleteTagsForEntry((int) $eventData);
                    return true;
                case 'frontend_header':
                    if (serendipity_db_bool($this->get_config('use_flash'))) {
                        echo '<script type="text/javascript" src="';
                        echo $serendipity['serendipityHTTPPath'];
                        echo 'plugins/serendipity_event_freetag/swfobject.js"></script>' . "\n";
                        echo '<script type="text/javascript">' . "\n";
                        echo 'swfobject.registerObject("tagcloud", "9.0.0", "expressInstall.swf");' . "\n";
                        echo '</script>' . "\n";
                    }
                    $this->displayMetaKeywords($serendipity['GET']['id'], $this->displayTag);
                    return true;
                case 'frontend_display:rss-2.0:per_entry':
                case 'frontend_display:rss-0.91:per_entry':
                    $eventData['display_dat'] .= $this->getFeedXmlForTags('category', $eventData['properties']['freetag_tags']);
                    return true;
                case 'frontend_display:rss-1.0:per_entry':
                case 'frontend_display:rss-0.91:per_entry':
                case 'frontend_display:atom-0.3:per_entry':
                case 'frontend_display:atom-1.0:per_entry':
                    $eventData['display_dat'] .= $this->getFeedXmlForTags('dc:subject', $eventData['properties']['freetag_tags']);
                    return true;
                case 'external_plugin':
                    $uri_parts = explode('?', str_replace(array('&amp;', '%FF'), array('&', '.'), $eventData));
                    $taglist = serendipity_db_bool($this->get_config('taglist', false));
                    $param = $taglist ? explode('/', str_replace('/taglist', '', $uri_parts[0])) : explode('/', $uri_parts[0]);
                    $plugincode = array_shift($param);
                    $tagged_as_list = false;
                    // By option or manually added blogdomain.com/plugin/taglist/Serendipity/Blog/Plums - see below
                    if ($plugincode == "taglist") {
                        $plugincode = "tags";
                    }
                    if ($plugincode == "tag" || $plugincode == "tags" || $plugincode == "freetag") {
                        // Manually added (last) parameter 'taglist" to view tags by list for certain taglinks eg. blogdomain.com/plugin/tag/Serendipity/Blog/Plums/taglist - both need a modified entries.tpl
                        if ($taglist && in_array('taglist', $serendipity['uriArguments'])) {
                            $param = array_map('urldecode', $param);
                            $param = array_map('urldecode', $param);
                            // for doubled encoded tag umlauts via searchengines backlinks
                            $param = is_array($param) ? array_map('strip_tags', $param) : strip_tags($param);
                            $param = array_filter($param);
                            // empty removed XSS by strip_tags
                            if (!is_object($serendipity['smarty'])) {
                                serendipity_smarty_init();
                                // to avoid member function assign() on a non-object error, start Smarty templating
                            }
                            if (false === serendipity_db_bool($this->get_config('show_tagcloud', true))) {
                                // Since this is extra stuff, we need to regular assign the subtitle header and not use $serendipity['head_subtitle'] !
                                if (count($param) > 1) {
                                    if (function_exists('serendipity_specialchars')) {
                                        $serendipity['smarty']->assign('head_subtitle', sprintf(PLUGIN_EVENT_FREETAG_USING, implode(' + ', array_map('serendipity_specialchars', $param))));
                                    } else {
                                        $serendipity['smarty']->assign('head_subtitle', sprintf(PLUGIN_EVENT_FREETAG_USING, implode(' + ', array_map('htmlspecialchars', $param))));
                                    }
                                } else {
                                    $serendipity['smarty']->assign('head_subtitle', sprintf(PLUGIN_EVENT_FREETAG_USING, function_exists('serendipity_specialchars') ? serendipity_specialchars($param[0]) : htmlspecialchars($param[0], ENT_COMPAT, LANG_CHARSET)));
                                }
                            }
                            $serendipity['smarty']->assign('taglist', true);
                            foreach ($serendipity['uriArguments'] as $uak => $uav) {
                                if ($uav == 'taglist') {
                                    unset($serendipity['uriArguments'][$uak]);
                                }
                            }
                            $tagged_as_list = true;
                        }
                        /* Attempt to locate hidden variables within the URI */
                        foreach ($serendipity['uriArguments'] as $k => $v) {
                            if ($v[0] == 'P') {
                                /* Page */
                                $page = substr($v, 1);
                                if (is_numeric($page)) {
                                    $serendipity['GET']['page'] = $page;
                                    unset($serendipity['uriArguments'][$k]);
                                    if ($param[count($param) - 1] == "P{$page}.html") {
                                        array_pop($param);
                                        // knock it off of the param array as well
                                    }
                                }
                            }
                        }
                        if (count($param) == 0 || empty($param[0])) {
                            $serendipity['head_subtitle'] = PLUGIN_EVENT_FREETAG_ALLTAGS;
                            $this->displayTag = true;
                            $param = null;
                        } else {
                            if (count($param) == 1) {
                                $param = urldecode($param[0]);
                                $param = urldecode($param);
                                // for doubled encoded tag umlauts via searchengines backlinks
                                $param = strip_tags($param);
                                $serendipity['head_subtitle'] = sprintf(PLUGIN_EVENT_FREETAG_USING, function_exists('serendipity_specialchars') ? serendipity_specialchars($param) : htmlspecialchars($param, ENT_COMPAT, LANG_CHARSET));
                                $emit_404 = true;
                            } else {
                                if (!$tagged_as_list) {
                                    $param = array_map('urldecode', $param);
                                    $param = array_map('urldecode', $param);
                                    // for doubled encoded tag umlauts via searchengines backlinks in sprintf
                                }
                                $param = array_map('strip_tags', $param);
                                $param = array_filter($param);
                                // empty removed XSS by strip_tags
                                if (function_exists('serendipity_specialchars')) {
                                    $serendipity['head_subtitle'] = sprintf(PLUGIN_EVENT_FREETAG_USING, implode(' + ', array_map('serendipity_specialchars', $param)));
                                } else {
                                    $serendipity['head_subtitle'] = sprintf(PLUGIN_EVENT_FREETAG_USING, implode(' + ', array_map('htmlspecialchars', $param)));
                                }
                                $emit_404 = true;
                            }
                        }
                        // for XSS secureness, while using doubled decode
                        $param = is_array($param) ? array_map('strip_tags', $param) : strip_tags($param);
                        if (is_array($param)) {
                            array_filter($param);
                            // empty removed XSS by strip_tags
                        }
                        if (function_exists('serendipity_specialchars')) {
                            $param = is_array($param) ? array_map('serendipity_specialchars', $param) : serendipity_specialchars($param);
                        } else {
                            $param = is_array($param) ? array_map('htmlspecialchars', $param) : htmlspecialchars($param, ENT_COMPAT, LANG_CHARSET);
                        }
                        $this->tags['show'] = $param;
                        $serendipity['plugin_vars']['tag'] = $param;
                        if (is_array($param)) {
                            @define('PLUGIN_VARS_TAG', implode(',', $param));
                        } else {
                            @define('PLUGIN_VARS_TAG', $param);
                        }
                        $serendipity['GET']['subpage'] = $eventData;
                        unset($serendipity['GET']['category']);
                        // No restriction should be enforced here.
                        include_once S9Y_INCLUDE_PATH . 'include/genpage.inc.php';
                        if ($emit_404 && $this->TaggedEntries !== null && $this->TaggedEntries < 1) {
                            @header('HTTP/1.0 404 Not found');
                            @header('Status: 404 Not found');
                            if (serendipity_db_bool($this->get_config('send_http_header', true))) {
                                @header('X-FreeTag: not found');
                            }
                        } else {
                            if (serendipity_db_bool($this->get_config('send_http_header', true))) {
                                @header('X-FreeTag: ' . $this->TaggedEntries);
                            }
                        }
                        $raw_data = ob_get_contents();
                        ob_end_clean();
                        $serendipity['smarty']->assign('raw_data', $raw_data);
                        serendipity_gzCompression();
                        $serendipity['smarty']->display(serendipity_getTemplateFile($serendipity['smarty_file'], 'serendipityPath'));
                        @define('NO_EXIT', true);
                    }
                    break;
                case 'backend_sidebar_entries':
                    if ($serendipity['version'][0] < 2) {
                        ?>
                            <li class="serendipitySideBarMenuLink serendipitySideBarMenuEntryLinks"><a href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=managetags"><?php 
                        echo PLUGIN_EVENT_FREETAG_MANAGETAGS;
                        ?>
</a></li>
<?php 
                    } else {
                        ?>
                            <li><a href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=managetags"><?php 
                        echo PLUGIN_EVENT_FREETAG_MANAGETAGS;
                        ?>
</a></li>
<?php 
                    }
                    return true;
                    break;
                case 'backend_sidebar_entries_event_display_managetags':
                    $this->eventData = $eventData;
                    $this->displayManageTags($event, $bag, $eventData, $addData);
                    return true;
                    break;
                case 'backend_publish':
                case 'backend_save':
                    if (function_exists('mb_internal_encoding')) {
                        mb_internal_encoding(LANG_CHARSET);
                    }
                    if (!isset($eventData['id'])) {
                        return true;
                    }
                    $to_lower = serendipity_db_bool($this->get_config('lowercase_tags'));
                    $keylist = serendipity_db_query("SELECT tag, keywords FROM {$serendipity['dbPrefix']}tagkeywords", false, 'assoc');
                    $automatted = array(array());
                    if (is_array($keylist)) {
                        foreach ($keylist as $key) {
                            $keywords = explode(',', $key['keywords']);
                            foreach ($keywords as $keyword) {
                                $automatted[trim($keyword)][$key['tag']] = true;
                            }
                        }
                    }
                    // When this variable is not set, the entry might be saved i.e. by recreating cache or automatted trackback.
                    // Do not loose such tags. :)
                    if (!isset($serendipity['POST']['properties']['freetag_tagList'])) {
                        $serendipity['POST']['properties']['freetag_tagList'] = implode(',', $this->getTagsForEntry($eventData['id']));
                    }
                    $tags = $this->makeTagsFromTagList($serendipity['POST']['properties']['freetag_tagList']);
                    if (serendipity_db_bool($this->get_config('keyword2tag'))) {
                        $searchtext = strip_tags($eventData['body'] . $eventData['extended']);
                        foreach ($automatted as $keyword => $ktags) {
                            $keyword = trim($keyword);
                            if (empty($keyword)) {
                                continue;
                            }
                            if (!is_array($ktags) || count($ktags) < 1) {
                                continue;
                            }
                            $regex = sprintf("/((\\s+|[\\(\\[-]+)%s([-\\/,\\.\\?!'\";\\)\\]]*+|[\\/-]+))/i", $keyword);
                            if (preg_match($regex, $searchtext) > 0) {
                                foreach ($ktags as $tag => $is_assigned) {
                                    if (!is_array($tags) || !in_array(strtolower($tag), $tags) && !in_array($tag, $tags)) {
                                        if ($to_lower) {
                                            if (function_exists("mb_strtolower")) {
                                                $tag = mb_strtolower($tag);
                                            } else {
                                                $tag = strtolower($tag);
                                            }
                                        }
                                        $tags[] = $tag;
                                        printf(PLUGIN_EVENT_FREETAG_KEYWORDS_ADD, function_exists('serendipity_specialchars') ? serendipity_specialchars($keyword) : htmlspecialchars($keyword, ENT_COMPAT, LANG_CHARSET), function_exists('serendipity_specialchars') ? serendipity_specialchars($tag) : htmlspecialchars($tag, ENT_COMPAT, LANG_CHARSET));
                                    }
                                }
                            }
                        }
                    }
                    if (empty($tags)) {
                        $tags = array();
                    }
                    if (serendipity_db_bool($this->get_config('cat2tag'))) {
                        if (is_array($cats = serendipity_fetchCategories())) {
                            $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
                            foreach ($cats as $cat) {
                                if ($to_lower) {
                                    if (function_exists("mb_strtolower")) {
                                        $cat['category_name'] = mb_strtolower($cat['category_name']);
                                    } else {
                                        $cat['category_name'] = strtolower($cat['category_name']);
                                    }
                                }
                                $names = explode(',', $cat['category_name']);
                                foreach ($names as $name) {
                                    $name = trim($name);
                                    if (is_array($eventData['categories']) && in_array($cat['categoryid'], $eventData['categories']) && !in_array($name, $tags)) {
                                        $tags[] = $name;
                                    }
                                }
                            }
                        }
                    }
                    $serendipity['POST']['properties']['freetag_tagList'] = implode(',', $tags);
                    $this->deleteTagsForEntry($eventData['id']);
                    $this->addTagsToEntry($eventData['id'], $tags);
                    if ($serendipity['POST']['properties']['freetag_kill']) {
                        $this->deleteTagsForEntry($eventData['id']);
                    }
                    return true;
                    break;
                case 'css_backend':
                    if ($serendipity['version'][0] > 1) {
                        ?>

.freetagMenu li {
    display: block;
    margin: 0 0 .5em;
}

.freetags_manage {
    border: 1px solid #aaa;
    border-bottom: 0 none;
    width: 100%;
}

.freetags_manage thead tr {
    background-color: #eee;
}

.freetags_manage tr {
    border-bottom: 1px solid #aaa;
}

.freetags_manage th,
.freetags_manage td {
    padding: .125em .25em;
}

.freetags_list li {
    margin: 0 0 .25em;
}

@media only screen and (min-width: 768px) {
    .freetagMenu li {
        display: inline-block;
        margin: 0 .25em .5em 0;
    }
}

<?php 
                    }
                    return true;
                    break;
                case 'js_backend':
                    // autocomplete with serendipity 2.0
                    if ($this->get_config('admin_ftayt')) {
                        echo '
function enableAutocomplete() {
    if (typeof(tags) != "undefined") {
        $("#properties_freetag_tagList").autocomplete(tags, {
            minChars: 0,
            multiple: true,
            scrollHeight: 200,
            matchContains: "word",
            autoFill: false
        });
    }
};

addLoadEvent(enableAutocomplete);

';
                    }
                    break;
                case 'backend_display':
                    if (function_exists('mb_internal_encoding')) {
                        mb_internal_encoding(LANG_CHARSET);
                    }
                    if (!empty($serendipity['POST']['properties']['freetag_tagList'])) {
                        $tagList = $serendipity['POST']['properties']['freetag_tagList'];
                    } else {
                        if (isset($eventData['id'])) {
                            $tagList = implode(',', $this->getTagsForEntry($eventData['id']));
                        } else {
                            $tagList = '';
                        }
                    }
                    if (serendipity_db_bool($this->get_config('lowercase_tags', true))) {
                        if (function_exists("mb_strtolower")) {
                            $tagList = mb_strtolower($tagList);
                        } else {
                            $tagList = strtolower($tagList);
                        }
                    }
                    $freetags = $this->makeTagsFromTagList($tagList);
                    if (!empty($freetags)) {
                        $tagList = implode(',', $freetags);
                    }
                    $taglist = (array) $this->getAllTags();
                    if ($this->get_config('admin_ftayt')) {
                        foreach ($taglist as $k => $v) {
                            $wicktags[] = '\'' . addslashes($k) . '\'';
                        }
                        // jQuery Migrate is used due to $.browser of autocomplete plugin not being available in jquery 1.9+
                        echo '
                        ' . ($serendipity['version'][0] < 2 ? '<script src="' . $serendipity['baseURL'] . 'plugins/serendipity_event_freetag/jquery-1.11.1.min.js" type="text/javascript"></script>' : '') . '
                        <link rel="stylesheet" type="text/css" href="' . $serendipity['baseURL'] . 'plugins/serendipity_event_freetag/jquery.autocomplete.css" />
                        <script src="' . $serendipity['baseURL'] . 'plugins/serendipity_event_freetag/jquery-migrate-1.2.1.min.js"></script>
                        <script type="text/javascript" src="' . $serendipity['baseURL'] . 'plugins/serendipity_event_freetag/jquery.autocomplete.min.js"></script>
                        <script type="text/javascript">
                        var tags = [' . implode(',', $wicktags) . '];
                         ' . ($serendipity['version'][0] < 2 ? '
                        function enableAutocomplete() {
                            $("#properties_freetag_tagList").autocomplete(tags, {
                                        minChars: 0,
                                        multiple: true,
                                        scrollHeight: 200,
                                        matchContains: "word",
                                        autoFill: false
                                    })};
                            addLoadEvent(enableAutocomplete);
                         ' : '') . '
                        </script>';
                    }
                    if ($this->get_config('admin_show_taglist')) {
                        ?>
                        <script type="text/javascript">
                        function addTag(addTag)
                        {
                            var freetags = document.getElementById("properties_freetag_tagList").value.split(',');

                            inList = false;
                            for (var freetag = 0; freetag < freetags.length; freetag++) {
                                if (freetags[freetag] && trim(freetags[freetag].toLowerCase()) == addTag.toLowerCase()) {
                                    inList = true;
                                }
                            }

                            if (!inList) {
                                if (document.getElementById("properties_freetag_tagList").value.lastIndexOf(',') == (document.getElementById("properties_freetag_tagList").value.length-1)) {
                                    sepChar = '';
                                } else {
                                    sepChar = ',';
                                }

                                document.getElementById("properties_freetag_tagList").value = document.getElementById("properties_freetag_tagList").value + sepChar + addTag;
                            }
                        }

                        function trim(str)
                        {
                            if (str) return str.replace(/^\s*|\s*$/g,"");
                             else return '';
                        }
                        </script>
<?php 
                    }
                    if ($serendipity['version'][0] < 2) {
                        ?>
                        <fieldset style="margin: 5px">
                            <legend><?php 
                        echo PLUGIN_EVENT_FREETAG_TITLE;
                        ?>
</legend>
                            <label for="serendipity[properties][freetag_tagList]" title="<?php 
                        echo PLUGIN_EVENT_FREETAG_TITLE;
                        ?>
"><?php 
                        echo PLUGIN_EVENT_FREETAG_ENTERDESC;
                        ?>
:</label><br/>
                            <input type="text" name="serendipity[properties][freetag_tagList]" id="properties_freetag_tagList" class="wickEnabled input_textbox" value="<?php 
                        echo function_exists('serendipity_specialchars') ? serendipity_specialchars($tagList) : htmlspecialchars($tagList, ENT_COMPAT, LANG_CHARSET);
                        ?>
" style="width: 100%" />

                            <input type="checkbox" name="serendipity[properties][freetag_kill]" id="properties_freetag_kill" class="input_checkbox" />
                            <label for="serendipity[properties][freetag_kill]" title="<?php 
                        echo PLUGIN_EVENT_FREETAG_KILL;
                        ?>
"><?php 
                        echo PLUGIN_EVENT_FREETAG_KILL;
                        ?>
</label><br/>
<?php 
                        if ($this->get_config('admin_show_taglist')) {
                            ?>
                            <a name="tagListAnchor"></a>
                            <div id="backend_freetag_list" style="margin: 5px; border: 1px dotted #000; padding: 5px; font-size: 9px;">
<?php 
                        }
                    } else {
                        ?>
                        <fieldset id="edit_entry_freetags" class="entryproperties_freetag">
                            <span class="wrap_legend"><legend><?php 
                        echo PLUGIN_EVENT_FREETAG_TITLE;
                        ?>
</legend></span>
                            <div class="form_field">
                                <label for="properties_freetag_tagList" class="block_level"><?php 
                        echo PLUGIN_EVENT_FREETAG_ENTERDESC;
                        ?>
:</label>
                                <input id="properties_freetag_tagList" type="text" name="serendipity[properties][freetag_tagList]" class="wickEnabled" value="<?php 
                        echo function_exists('serendipity_specialchars') ? serendipity_specialchars($tagList) : htmlspecialchars($tagList, ENT_COMPAT, LANG_CHARSET);
                        ?>
">
                            </div>
                            <div class="form_check">
                                <input id="properties_freetag_kill" type="checkbox" name="serendipity[properties][freetag_kill]">
                                <label for="properties_freetag_kill"><?php 
                        echo PLUGIN_EVENT_FREETAG_KILL;
                        ?>
</label>
                            </div>
<?php 
                        if ($this->get_config('admin_show_taglist')) {
                            ?>
                            <a name="tagListAnchor"></a>
                            <div id="backend_freetag_list">
<?php 
                        }
                    }
                    if ($this->get_config('admin_show_taglist')) {
                        $lastletter = '';
                        foreach ($taglist as $tag => $count) {
                            if (function_exists('mb_strtoupper')) {
                                $upc = mb_strtoupper(mb_substr($tag, 0, 1, LANG_CHARSET), LANG_CHARSET);
                            } else {
                                $upc = strtoupper(substr($tag, 0, 1));
                            }
                            if ($upc != $lastletter) {
                                if ($serendipity['version'][0] < 2) {
                                    echo " <b>|" . $upc . ':</b> ';
                                }
                            }
                            if ($serendipity['version'][0] < 2) {
                                echo "<a href=\"#tagListAnchor\" style=\"text-decoration: none\" onClick=\"addTag('{$tag}')\">{$tag}</a>, ";
                            } else {
                                echo "<a href=\"#tagListAnchor\" onClick=\"addTag('{$tag}')\">{$tag}</a> ";
                            }
                            $lastletter = $upc;
                        }
                        echo "</div>";
                    }
                    ?>
                        </fieldset>
<?php 
                    return true;
                    break;
                case 'frontend_entryproperties':
                    $this->importEntryTagsIntoProperties($eventData, $addData);
                    return true;
                    break;
                case 'frontend_fetchentries':
                case 'frontend_fetchentry':
                    if (!empty($this->tags['show'])) {
                        if (is_array($this->tags['show'])) {
                            $showtag = array_map('serendipity_db_escape_string', $this->tags['show']);
                        } else {
                            $showtag = serendipity_db_escape_string($this->tags['show']);
                        }
                    } else {
                        if (!empty($serendipity['GET']['tag'])) {
                            $showtag = serendipity_db_escape_string(urldecode($serendipity['GET']['tag']));
                        }
                    }
                    if (is_array($showtag)) {
                        $arr_showtag = $showtag;
                    } else {
                        $arr_showtag = explode(';', $showtag);
                    }
                    $multimode = 'and';
                    if (count($arr_showtag) > 1) {
                        $showtag = $arr_showtag;
                        $multimode = 'or';
                    }
                    if (!empty($show_tag) && is_string($show_tag) && serendipity_db_bool($this->get_config('lowercase_tags', true))) {
                        if (function_exists("mb_strtolower")) {
                            if (function_exists('mb_internal_encoding')) {
                                mb_internal_encoding(LANG_CHARSET);
                            }
                            $showtag = mb_strtolower($showtag);
                        } else {
                            $showtag = strtolower($showtag);
                        }
                    }
                    $coll_target = $this->get_config('collation', '');
                    if (empty($coll_target) && stristr($serendipity['dbType'], 'mysql')) {
                        $cd = serendipity_db_query("SHOW FULL COLUMNS FROM {$serendipity['dbPrefix']}entrytags LIKE 'tag'");
                        if (!empty($cd[0]['Collation'])) {
                            $coll_target = $cd[0]['Collation'];
                            $this->set_config('collation', $coll_target);
                        }
                    }
                    if (!empty($showtag)) {
                        if (LANG_CHARSET == 'UTF-8' && stristr($serendipity['dbType'], 'mysql') && !stristr($coll_target, 'utf8')) {
                            $collate = "COLLATE utf8_general_ci";
                            $collateP = '_utf8 ';
                        } else {
                            $collate = $collateP = "";
                        }
                        $cond = $join = '';
                        if (is_string($showtag)) {
                            $join = "INNER JOIN {$serendipity['dbPrefix']}entrytags AS entrytags ON (e.id = entrytags.entryid) ";
                            $cond = "entrytags.tag = {$collateP} '{$showtag}' {$collate}";
                        } else {
                            if (is_array($showtag)) {
                                $_taglist = array();
                                $cond = '(1=2 ';
                                foreach ($showtag as $_showtag) {
                                    $_taglist[] = serendipity_db_escape_string($_showtag);
                                    $cond .= " OR entrytags.tag = {$collateP} '" . serendipity_db_escape_string($_showtag) . "' {$collate} ";
                                }
                                $cond .= ' ) ';
                                $total = count($showtag);
                                $join = "INNER JOIN {$serendipity['dbPrefix']}entrytags AS entrytags " . "ON e.id = entrytags.entryid ";
                                if ($multimode == 'and') {
                                    $eventData['having'] = " HAVING count(entrytags.tag) = {$total}";
                                }
                            }
                        }
                        if (empty($eventData['and'])) {
                            $eventData['and'] = " WHERE {$cond} ";
                        } else {
                            $eventData['and'] .= " AND {$cond} ";
                        }
                        if (empty($eventData['joins'])) {
                            $eventData['joins'] = $join;
                        } else {
                            $eventData['joins'] .= $join;
                        }
                        $this->displayTag = $showtag;
                        $serendipity['plugin_vars']['displayTag'] = $showtag;
                        @define('PLUGIN_VARS_DISPLAYTAG', $showtag);
                    }
                    return true;
                    break;
                case 'frontend_rss':
                    if (!empty($this->displayTag)) {
                        $eventData['title'] .= serendipity_utf8_encode(function_exists('serendipity_specialchars') ? serendipity_specialchars(' (' . sprintf(PLUGIN_EVENT_FREETAG_USING, $this->displayTag) . ')') : htmlspecialchars(' (' . sprintf(PLUGIN_EVENT_FREETAG_USING, $this->displayTag) . ')', ENT_COMPAT, LANG_CHARSET));
                    }
                    return true;
                    break;
                case 'entries_header':
                    if (isset($eventData['plugin_vars']['tag']) && serendipity_db_bool($this->get_config('show_tagcloud'))) {
                        $this->displayTagCloud($eventData['plugin_vars']['tag']);
                    }
                    return true;
                    break;
                case 'css':
                    if (strpos($eventData, '.serendipity_freeTag')) {
                        // class exists in CSS, so a user has customized it and we don't need default
                        return true;
                    }
                    $this->addToCSS($eventData);
                    return true;
                    break;
                case 'entry_display':
                    // Don't display entries if we are getting a full tag list
                    if (is_array($eventData)) {
                        $this->TaggedEntries = count($eventData);
                        if (serendipity_db_bool($this->get_config('send_http_header', true))) {
                            @header('X-FreeTag-Count: Array');
                        }
                    } else {
                        if (serendipity_db_bool($this->get_config('send_http_header', true))) {
                            @header('X-FreeTag-Count: Empty');
                        }
                        $this->TaggedEntries = 0;
                    }
                    if ($this->displayTag === true) {
                        $eventData['clean_page'] = true;
                        return true;
                    }
                    $this->displayEntry($eventData, $addData);
                    return true;
                    break;
                case 'xmlrpc_updertEntry':
                    if (isset($eventData['id']) && isset($eventData['mt_keywords'])) {
                        //XMLRPC call
                        $tags = $this->makeTagsFromTagList($eventData['mt_keywords']);
                        if (!empty($tags)) {
                            $this->deleteTagsForEntry($eventData['id']);
                            $this->addTagsToEntry($eventData['id'], $tags);
                        }
                    }
                    return true;
                    break;
                case 'xmlrpc_fetchEntry':
                    $eventData['mt_keywords'] = implode(',', $this->getTagsForEntry($eventData['id']));
                    return true;
                    break;
                case 'xmlrpc_deleteEntry':
                    if (isset($eventData["id"])) {
                        $this->deleteTagsForEntry($eventData["id"]);
                    }
                    return true;
                    break;
                default:
                    return false;
                    break;
            }
        } else {
            return false;
        }
    }
 /**
  * event hook: 'backend_publish' and 'backend_save'
  *      old tags, automated tags, category tags
  *
  * CLARIFY STATEMENT:
  *      TAGS are stored to the database entrytags table like they are written by the user or being tagged already:
  *      uppercased, mixed, lowercased, capitalised, etc. To change older tags, use the backend tag administration rename button function.
  *      The 'lowercase_tags' option sets TAGS lowercased in every frontend related output at runtime and is used for comparison matters.
  *
  * @param   array   $eventData as copy
  */
 function backend_fetch_tags_for_saving($eventData)
 {
     global $serendipity;
     if (function_exists('mb_internal_encoding')) {
         mb_internal_encoding(LANG_CHARSET);
     }
     #$to_lower  = serendipity_db_bool($this->get_config('lowercase_tags', 'true')); // see clarify statement!
     $keylist = serendipity_db_query("SELECT tag, keywords FROM {$serendipity['dbPrefix']}tagkeywords", false, 'assoc');
     $automated = array(array());
     if (is_array($keylist)) {
         foreach ($keylist as $key) {
             $keywords = explode(',', $key['keywords']);
             foreach ($keywords as $keyword) {
                 $automated[trim($keyword)][$key['tag']] = true;
             }
         }
     }
     $automated = array_filter($automated);
     // filter out all left BOOL, NULL and EMPTY elements
     // When this variable is not set, the entry might be saved i.e. by recreating cache or automated trackback.
     // Do not loose such tags. :)
     // And do not use it with multiple entry cases, since this would always get the first of multiple IDs!!
     if (!isset($serendipity['POST']['properties']['freetag_tagList']) && $serendipity['GET']['tagview'] != 'tagupdate' && $serendipity['GET']['tagview'] != 'cat2tag') {
         $serendipity['POST']['properties']['freetag_tagList'] = implode(',', $this->getTagsForEntry($eventData['id']));
         // as STRING
     }
     if (!empty($serendipity['POST']['properties']['freetag_tagList'])) {
         $tags = self::makeTagsFromTagList($serendipity['POST']['properties']['freetag_tagList']);
     }
     // check for keyword2tag empty or set cases
     if (!is_array($tags) && empty($tags)) {
         $tags = array();
     }
     if (empty($tags) && serendipity_db_bool($this->get_config('keyword2tag', 'false'))) {
         $searchtext = strip_tags($eventData['body'] . $eventData['extended']);
         // fetch oldtags AS ARRAY for each entry, valid to be checked for keywords
         $oldtags = self::makeTagsFromTagList(implode(',', $this->getTagsForEntry($eventData['id'])));
         // as ARRAY
         foreach ($automated as $keyword => $ktags) {
             $keyword = trim($keyword);
             if (empty($keyword)) {
                 continue;
             }
             if (!is_array($ktags) || count($ktags) < 1) {
                 continue;
             }
             $keywordtag = array_pop(array_keys($ktags));
             // get type key as string
             if (is_array($oldtags) && in_array($keywordtag, $oldtags)) {
                 continue;
                 // if automated keyword-tag already is in oldtags, do next
             }
             // only match check those, which have no keyword-tag yet
             if (!is_array($key2tagIDs)) {
                 $key2tagIDs = array();
             }
             $regex = sprintf("/((\\s+|[\\(\\[-]+)%s([-\\/,\\.\\?!'\";\\)\\]]*+|[\\/-]+))/i", $keyword);
             if (preg_match($regex, $searchtext) > 0) {
                 foreach ($ktags as $tag => $is_assigned) {
                     if (!is_array($tags) || !in_array($tag, $tags) && !in_array($tag, $tags)) {
                         if (!is_array($tags) && !empty($tag)) {
                             $tags = array();
                             // avoid having "[] operator not supported for strings" errors
                         }
                         $tags[] = $tag;
                         printf("\n - " . PLUGIN_EVENT_FREETAG_KEYWORDS_ADD . "\n<br>", self::specialchars_mapper($keyword), self::specialchars_mapper($tag));
                         if (!empty($tags)) {
                             $key2tagIDs[] = $eventData['id'];
                             // gather ids to updertEntries
                         }
                     }
                 }
             } else {
                 // get the other entries tags
                 if (is_array($key2tagIDs) && !in_array($eventData['id'], $key2tagIDs)) {
                     unset($key2tagIDs);
                     $tags = $oldtags;
                 }
             }
         }
     }
     // check for cat2tag empty or set cases
     if (!is_array($tags) && empty($tags)) {
         $tags = array();
     }
     // In this case, tags are just added to the tags array
     if (serendipity_db_bool($this->get_config('cat2tag', 'false'))) {
         if (is_array($cats = serendipity_fetchCategories())) {
             $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
             foreach ($cats as $cat) {
                 $names = explode(',', $cat['category_name']);
                 foreach ($names as $name) {
                     $name = trim($name);
                     if (is_array($eventData['categories']) && in_array($cat['categoryid'], $eventData['categories']) && !in_array($name, $tags)) {
                         $tags[] = $name;
                     }
                 }
             }
         }
     }
     // Merge kept oldtags with automated and/or category tags into tagList - may partly be or look a little redundant, but catches every case
     if (is_array($tags) && !empty($tags)) {
         if (!is_array($oldtags) && empty($oldtags)) {
             $oldtags = self::makeTagsFromTagList(implode(',', $this->getTagsForEntry($eventData['id'])));
             // as ARRAY
         }
         if (!is_array($oldtags)) {
             $oldtags = array();
         }
         // Condition could be used with checking the given arrays before, with ' && $oldtags !== $tags',
         // but our tags arrays are so small, that this merge and unique does not really matter for performance
         if (!empty($oldtags)) {
             $tags = array_merge($oldtags, $tags);
             // merge
         }
         if (count($tags) > 1) {
             $tags = $this->array_iunique($tags);
             // remove (last added) duplicates (and possible strtolowered added tags)
         }
     }
     $key2tagIDs = is_array($key2tagIDs) && !empty($key2tagIDs) ? array_unique($key2tagIDs) : array();
     // ACTIONS - Only do this to entries which really changed tags!!
     if (is_array($tags) && !empty($tags) && $oldtags !== $tags || is_array($key2tagIDs) && in_array($eventData['id'], $key2tagIDs) && $oldtags !== $tags) {
         $this->deleteTagsForEntry($eventData['id']);
         $this->addTagsToEntry($eventData['id'], $tags);
     }
     if (isset($serendipity['POST']['properties']['freetag_kill'])) {
         $this->deleteTagsForEntry($eventData['id']);
     }
     unset($key2tagIDs);
     unset($oldtags);
     unset($tags);
 }
 function assignCategories(&$serendipity)
 {
     // add accesskey ids (1-9)
     $categories = serendipity_fetchCategories('all');
     $plugin_categories_data = array();
     $i = 1;
     foreach ($categories as $k => $v) {
         $plugin_categories_data[] = array('access_key' => $i++, 'category_name' => $v['category_name'], 'categoryURL' => serendipity_categoryURL($v, 'serendipityHTTPPath'));
     }
     $serendipity['smarty']->assign(array('categories' => $plugin_categories_data));
 }
Example #22
0
         $filter[] = "(lower(title) LIKE '%{$term}%' OR lower(body) LIKE '%{$term}%' OR lower(extended) LIKE '%{$term}%')";
         $full = true;
     } else {
         if (preg_match('@["\\+\\-\\*~<>\\(\\)]+@', $term)) {
             $filter[] = "MATCH (title,body,extended) AGAINST ('" . $term . "' IN BOOLEAN MODE)";
         } else {
             $filter[] = "MATCH (title,body,extended) AGAINST ('" . $term . "')";
         }
         $full = true;
     }
 }
 $filter_sql = implode(' AND ', $filter);
 // Fetch the entries
 $entries = serendipity_fetchEntries(false, false, serendipity_db_limit($offSet, $perPage + 1), true, false, $orderby, $filter_sql);
 $users = serendipity_fetchUsers('', 'hidden', true);
 $categories = serendipity_fetchCategories();
 $categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED);
 $data['drawList'] = true;
 $data['sort_order'] = $sort_order;
 $data['perPage'] = $perPage;
 $data['per_page'] = $per_page;
 $data['urltoken'] = serendipity_setFormToken('url');
 $data['formtoken'] = serendipity_setFormToken();
 $data['users'] = $users;
 $data['categories'] = $categories;
 $data['offSet'] = $offSet;
 $data['use_iframe'] = $serendipity['use_iframe'];
 $data['page'] = $page;
 $data['totalEntries'] = serendipity_getTotalEntries();
 $data['simpleFilters'] = $serendipity['simpleFilters'];
 if (is_array($entries)) {
function universal_fetchCategories($post_categories)
{
    global $serendipity;
    $categories = array();
    if (is_array($post_categories)) {
        if (is_array($post_categories[0])) {
            // if it is a cat_id hash
            foreach ($post_categories as $cat_id => $cat_obj) {
                if (is_object($cat_obj)) {
                    $cat_name = $cat_obj->getval();
                    if (!empty($cat_name)) {
                        $cat = serendipity_fetchCategories(null, $cat_name);
                        if (isset($cat[0]['categoryid'])) {
                            $categories[$cat[0]['categoryid']] = $cat[0]['categoryid'];
                        }
                    }
                } elseif (is_array($cat_obj) && isset($cat_obj['categoryId'])) {
                    $cat_id = $cat_obj['categoryId'];
                    //->getval();
                    if (!empty($cat_id)) {
                        $categories[$cat_id] = $cat_id;
                    }
                }
            }
        } else {
            // Just an array with names, has to be resolved to ids
            foreach ($post_categories as $cat_name) {
                $info = serendipity_fetchCategoryInfo(0, $cat_name);
                if (is_array($info)) {
                    $cat_id = $info['categoryid'];
                    $categories[$cat_id] = $cat_id;
                }
            }
        }
    }
    return $categories;
}
 function event_hook($event, &$bag, &$eventData, $addData = null)
 {
     global $serendipity;
     if ($event == 'frontend_header') {
         $start_url = $serendipity['baseURL'];
         $start_title = $serendipity['blogTitle'];
         echo '<link rel="start" href="' . $start_url . '" title="' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($start_title) : htmlspecialchars($start_title, ENT_COMPAT, LANG_CHARSET)) . '" />' . "\n";
         if ($serendipity['GET']['action'] == 'read' && !empty($serendipity['GET']['id'])) {
             // Article detail view
             echo '<link rel="up" href="' . $start_url . '" title="' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($start_title) : htmlspecialchars($start_title, ENT_COMPAT, LANG_CHARSET)) . '" />' . "\n";
             $this->backAndForth($this->showPaging($serendipity['GET']['id']));
             // END article detail view
             echo '<link rel="canonical" href="' . $this->getEntry($serendipity['GET']['id']) . '" />' . "\n";
         } elseif ($serendipity['GET']['action'] == 'read' && is_array($serendipity['range'])) {
             // Specific Date Archives view
             echo '<link rel="up" href="' . serendipity_rewriteURL(PATH_ARCHIVE) . '" title="' . ARCHIVES . '" />' . "\n";
             echo '<link rel="canonical" href="' . $this->getArchiveParameters() . '" />' . "\n";
             $links = array();
             $add_query = '';
             $year = date('Y', $serendipity['range'][0]);
             $month = date('m', $serendipity['range'][0]);
             $day = date('d', $serendipity['range'][0]);
             $pageMonthNext = array('day' => '1', 'month' => $month + 1, 'year' => $year);
             $pageMonthPrev = array('day' => '1', 'month' => $month - 1, 'year' => $year);
             $pageDayNext = array('day' => $day + 1, 'month' => $month, 'year' => $year);
             $pageDayPrev = array('day' => $day - 1, 'month' => $month, 'year' => $year);
             $diff = $serendipity['range'][1] - $serendipity['range'][0];
             if (isset($serendipity['GET']['category'])) {
                 $categoryid = (int) serendipity_db_escape_string($serendipity['GET']['category']);
                 $add_query = '/C' . $categoryid;
             }
             if ($diff < 86400) {
                 // Paging day by day
                 $ts = mktime(0, 0, 0, $pageDayPrev['month'], $pageDayPrev['day'], $pageDayPrev['year']);
                 $links['prev'] = array('link' => serendipity_archiveDateUrl(sprintf('%4d/%02d/%02d', date('Y', $ts), date('m', $ts), date('d', $ts))), 'title' => sprintf(ENTRIES_FOR, serendipity_formatTime(DATE_FORMAT_ENTRY, $ts, false)));
                 $ts = mktime(0, 0, 0, $pageDayNext['month'], $pageDayNext['day'], $pageDayNext['year']);
                 $links['next'] = array('link' => serendipity_archiveDateUrl(sprintf('%4d/%02d/%02d', date('Y', $ts), date('m', $ts), date('d', $ts))), 'title' => sprintf(ENTRIES_FOR, serendipity_formatTime(DATE_FORMAT_ENTRY, $ts, false)));
             } elseif ($diff < 86400 * 28) {
                 // Paging by week
                 // TODO - Don't know :-)
             } else {
                 // Paging by month
                 $ts = mktime(0, 0, 0, $pageMonthPrev['month'], $pageMonthPrev['day'], $pageMonthPrev['year']);
                 $links['prev'] = array('link' => serendipity_archiveDateUrl(sprintf('%4d/%02d', date('Y', $ts), date('m', $ts))), 'title' => sprintf(ENTRIES_FOR, serendipity_formatTime('%B %Y', $ts, false)));
                 $ts = mktime(0, 0, 0, $pageMonthNext['month'], $pageMonthNext['day'], $pageMonthNext['year']);
                 $links['next'] = array('link' => serendipity_archiveDateUrl(sprintf('%4d/%02d', date('Y', $ts), date('m', $ts))), 'title' => sprintf(ENTRIES_FOR, serendipity_formatTime('%B %Y', $ts, false)));
             }
             $this->backAndForth($links);
             // END Specific Date Archives view
         } elseif ($serendipity['GET']['action'] == 'archives') {
             // Full month/year archives overview
             echo '<link rel="up" href="' . serendipity_rewriteURL(PATH_ARCHIVE) . '" title="' . ARCHIVES . '" />' . "\n";
             // END Full month/year archives overview
             echo '<link rel="canonical" href="' . $this->getArchiveParameters() . '" />' . "\n";
         } elseif (!empty($serendipity['GET']['category'])) {
             // Category based view
             $cInfo = serendipity_fetchCategoryInfo($serendipity['GET']['category']);
             if (function_exists('serendipity_categoryURL')) {
                 $categories_url = serendipity_categoryURL($cInfo, 'serendipityHTTPPath');
             } else {
                 $categories_url = serendipity_rewriteURL(PATH_CATEGORIES . '/' . serendipity_makePermalink(PERM_CATEGORIES, array('id' => $cInfo['categoryid'], 'title' => $cInfo['category_name'])), 'serendipityHTTPPath');
             }
             echo '<link rel="up" href="' . $categories_url . '" title="' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($cInfo['category_name']) : htmlspecialchars($cInfo['category_name'], ENT_COMPAT, LANG_CHARSET)) . '" />' . "\n";
             echo '<link rel="canonical" href="' . $categories_url . '" />' . "\n";
             $categories = serendipity_fetchCategories('all');
             $links = array();
             if (is_array($categories) && count($categories)) {
                 $categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED);
                 $capture_next = false;
                 foreach ($categories as $cat) {
                     if ($capture_next) {
                         $links['next'] = $this->getCat($cat);
                         break;
                     }
                     if (is_array($prev_cat) && $cat['categoryid'] == $serendipity['GET']['category']) {
                         $links['prev'] = $this->getCat($prev_cat);
                         $capture_next = true;
                     }
                     $prev_cat = $cat;
                 }
             }
             $this->backAndForth($links);
             // END Category based view
         } elseif (!empty($serendipity['GET']['viewAuthor'])) {
             // User view
             $uInfo = serendipity_fetchUsers();
             $links = array();
             if (is_array($uInfo)) {
                 $capture_next = false;
                 foreach ($uInfo as $user) {
                     if ($capture_next) {
                         $links['next'] = $this->getUser($user);
                         break;
                     }
                     if ($user['authorid'] == $serendipity['GET']['viewAuthor']) {
                         $authors_url = $this->getUser($user);
                         echo '<link rel="up" href="' . $authors_url['link'] . '" title="' . $authors_url['title'] . '" />' . "\n";
                         echo '<link rel="canonical" href="' . $authors_url['link'] . '" />' . "\n";
                         if (is_array($prev_user)) {
                             $links['prev'] = $this->getUser($prev_user);
                             $capture_next = true;
                         }
                     }
                     $prev_user = $user;
                 }
                 $this->backAndForth($links);
             }
             // END User view
         } else {
             // Frontpage
             $this->backAndForth();
             // END Frontpage
             if ($serendipity['view'] == 'start') {
                 echo '<link rel="canonical" href="' . $serendipity['baseURL'] . '" />' . "\n";
             }
         }
     }
 }
    function event_hook($event, &$bag, &$eventData, $addData = null)
    {
        global $serendipity;
        $hooks =& $bag->get('event_hooks');
        if (isset($hooks[$event])) {
            switch ($event) {
                case 'backend_image_addform':
                    if ($serendipity['version'][0] < 2) {
                        if (class_exists('ZipArchive')) {
                            $checkedY = "";
                            $checkedN = "";
                            $this->get_config('unzipping') ? $checkedY = ' checked="checked"' : ($checkedN = ' checked="checked"');
                            ?>
            <br />
            <div>
                <strong><?php 
                            echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FILES;
                            ?>
</strong><br />
                <?php 
                            echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FILES_DESC;
                            ?>
                <div>
                    <input type="radio" class="input_radio" id="unzip_yes" name="serendipity[unzip_archives]" value="<?php 
                            echo YES;
                            ?>
"<?php 
                            echo $checkedY;
                            ?>
><label for="unzip_yes"><?php 
                            echo YES;
                            ?>
</label>
                    <input type="radio" class="input_radio" id="unzip_no" name="serendipity[unzip_archives]" value="<?php 
                            echo NO;
                            ?>
"<?php 
                            echo $checkedN;
                            ?>
><label for="unzip_no"><?php 
                            echo NO;
                            ?>
</label>
                </div>
            </div>
<?php 
                        }
                        ?>
            <br />
            <strong><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_QUICKBLOG;
                        ?>
:</strong><br />
            <em><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_QUICKBLOG_DESC;
                        ?>
</em>
            <table id="quickblog_table" style="width: 50%">
                <tr>
                    <td nowrap="nowrap"><?php 
                        echo TITLE;
                        ?>
</td>
                    <td><input class="input_textbox" name="serendipity[quickblog][title]" type="text" style="width: 90%" /></td>
                </tr>

                <tr>
                    <td nowrap="nowrap"><?php 
                        echo ENTRY_BODY;
                        ?>
</td>
                    <td><textarea name="serendipity[quickblog][body]" style="width: 90%; height: 200px"></textarea></td>
                </tr>

                <tr>
                    <td nowrap="nowrap"><?php 
                        echo CATEGORY;
                        ?>
</td>
                    <td><select name="serendipity[quickblog][category]">
                        <option value=""><?php 
                        echo NO_CATEGORY;
                        ?>
</option>
                    <?php 
                        if (is_array($cats = serendipity_fetchCategories())) {
                            $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
                            foreach ($cats as $cat) {
                                echo '<option value="' . $cat['categoryid'] . '">' . str_repeat('&nbsp;', $cat['depth']) . $cat['category_name'] . '</option>' . "\n";
                            }
                        }
                        ?>
                    </select></td>
                </tr>

                <tr>
                    <td nowrap="nowrap"><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET;
                        ?>
</td>
                    <td><select id="select_image_target" name="serendipity[quickblog][target]">
                        <option value="none"<?php 
                        echo serendipity_ifRemember('target', 'none', false, 'selected');
                        ?>
><?php 
                        echo NONE;
                        ?>
</option>
                        <option value="js"<?php 
                        echo serendipity_ifRemember('target', 'js', false, 'selected');
                        ?>
><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET_JS;
                        ?>
</option>
                        <option value="plugin"<?php 
                        echo serendipity_ifRemember('target', 'plugin', false, 'selected');
                        ?>
><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET_ENTRY;
                        ?>
</option>
                        <option value="_blank"<?php 
                        echo serendipity_ifRemember('target', '_blank', false, 'selected');
                        ?>
><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET_BLANK;
                        ?>
</option>
                    </select></td>
                </tr>

                <tr>
                    <td nowrap="nowrap"><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_ASOBJECT;
                        ?>
</td>
                    <td>
                        <input type="radio" class="input_radio" id="image_yes" name="serendipity[quickblog][isobject]" value="<?php 
                        echo YES;
                        ?>
"><label for="image_yes"><?php 
                        echo YES;
                        ?>
</label>
                        <input type="radio" class="input_radio" id="image_no" name="serendipity[quickblog][isobject]" value="<?php 
                        echo NO;
                        ?>
" checked="checked"><label for="image_no"><?php 
                        echo NO;
                        ?>
</label>
                    </td>
                </tr>

                <tr>
                    <td nowrap="nowrap"><?php 
                        echo IMAGE_SIZE;
                        ?>
</td>
                    <td><input class="input_textbox" name="serendipity[quickblog][size]" value="<?php 
                        echo $serendipity['thumbSize'];
                        ?>
" type="text" style="width: 50px" /></td>
                </tr>

                <tr>
                    <td align="center" colspan="2"><br /></td>
                </tr>
            </table>
            <div>
                <em><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_IMAGE_SIZE_DESC;
                        ?>
</em>
            </div>
<?php 
                    } else {
                        ?>

        <div id="imageselectorplus">

<?php 
                        if (class_exists('ZipArchive')) {
                            $checkedY = "";
                            $checkedN = "";
                            $this->get_config('unzipping') ? $checkedY = ' checked="checked"' : ($checkedN = ' checked="checked"');
                            ?>
            <div class="clearfix radio_field">
                <h4><?php 
                            echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FILES;
                            ?>
</h4>
                <?php 
                            echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FILES_DESC;
                            ?>
                <div>
                    <input type="radio" class="input_radio" id="unzip_yes" name="serendipity[unzip_archives]" value="<?php 
                            echo YES;
                            ?>
"<?php 
                            echo $checkedY;
                            ?>
><label for="unzip_yes"><?php 
                            echo YES;
                            ?>
</label>
                    <input type="radio" class="input_radio" id="unzip_no" name="serendipity[unzip_archives]" value="<?php 
                            echo NO;
                            ?>
"<?php 
                            echo $checkedN;
                            ?>
><label for="unzip_no"><?php 
                            echo NO;
                            ?>
</label>
                </div>
            </div>
<?php 
                        }
                        ?>
            <h4><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_QUICKBLOG;
                        ?>
:</h4>
            <em><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_QUICKBLOG_DESC;
                        ?>
</em>
            <div id="quickblog_tablefield" class="clearfix">
                <div class="quickblog_form_field">
                    <label for="quickblog_titel"><?php 
                        echo TITLE;
                        ?>
</label>
                    <input id="quickblog_title" class="input_textbox" name="serendipity[quickblog][title]" type="text">
                </div>

                <div class="quickblog_textarea_field">
                    <label for="nuggets2"><?php 
                        echo ENTRY_BODY;
                        ?>
</label>
                    <textarea id="nuggets2" class="quickblog_nugget" data-tarea="nuggets2" name="serendipity[quickblog][body]" rows="10" cols="80"></textarea>
<?php 
                        if ($serendipity['wysiwyg']) {
                            $plugins = serendipity_plugin_api::enum_plugins('*', false, 'serendipity_event_nl2br');
                            ?>
                    <input name="serendipity[properties][disable_markups][]" type="hidden" value="<?php 
                            echo $plugins[0]['name'];
                            ?>
">
<?php 
                            if (!class_exists('serendipity_event_ckeditor')) {
                                ?>
                    <script src="<?php 
                                echo $serendipity['serendipityHTTPPath'];
                                ?>
htmlarea/ckeditor/ckeditor/ckeditor.js"></script>
<?php 
                            }
                            // just add a simple basic toolbar, since we cannot use embedded plugins here
                            ?>
                    <script>
                        CKEDITOR.replace( 'nuggets2',
                        {
                            toolbar : [['Format'],['Bold','Italic','Underline','Superscript','-','NumberedList','BulletedList','Outdent','Blockquote'],['JustifyBlock','JustifyCenter','JustifyRight'],['Link','Unlink'],['Source']],
                            toolbarGroups: null
                        });
                    </script>
<?php 
                        }
                        ?>
                </div>

                <div class="quickblog_form_field">
                    <label for="quickblog_select"><?php 
                        echo CATEGORY;
                        ?>
</label>
                    <select id="quickblog_select" name="serendipity[quickblog][category]">
                        <option value=""><?php 
                        echo NO_CATEGORY;
                        ?>
</option>
                    <?php 
                        if (is_array($cats = serendipity_fetchCategories())) {
                            $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
                            foreach ($cats as $cat) {
                                echo '<option value="' . $cat['categoryid'] . '">' . str_repeat('&nbsp;', $cat['depth']) . $cat['category_name'] . '</option>' . "\n";
                            }
                        }
                        ?>
                    </select>
                </div>

                <div class="quickblog_form_select">
                    <label for="select_image_target"><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_TARGET;
                        ?>
</label>
                    <select id="select_image_target" name="serendipity[quickblog][target]">
                        <option value="none"<?php 
                        echo serendipity_ifRemember('target', 'none', false, 'selected');
                        ?>
><?php 
                        echo NONE;
                        ?>
</option>
                        <option value="js"<?php 
                        echo serendipity_ifRemember('target', 'js', false, 'selected');
                        ?>
><?php 
                        echo MEDIA_TARGET_JS;
                        ?>
</option>
                        <option value="plugin"<?php 
                        echo serendipity_ifRemember('target', 'plugin', false, 'selected');
                        ?>
><?php 
                        echo MEDIA_ENTRY;
                        ?>
</option>
                        <option value="_blank"<?php 
                        echo serendipity_ifRemember('target', '_blank', false, 'selected');
                        ?>
><?php 
                        echo MEDIA_TARGET_BLANK;
                        ?>
</option>
                    </select>
                </div>

                <div class="clearfix radio_field quickblog_radio_field">
                    <label><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_ASOBJECT;
                        ?>
</label>
                    <div>
                        <input type="radio" class="input_radio" id="image_yes" name="serendipity[quickblog][isobject]" value="<?php 
                        echo YES;
                        ?>
"><label for="image_yes"><?php 
                        echo YES;
                        ?>
</label>
                        <input type="radio" class="input_radio" id="image_no" name="serendipity[quickblog][isobject]" value="<?php 
                        echo NO;
                        ?>
" checked="checked"><label for="image_no"><?php 
                        echo NO;
                        ?>
</label>
                    </div>
                </div>

                <div class="quickblog_form_field">
                    <label for="quickblog_isize"><?php 
                        echo IMAGE_SIZE;
                        ?>
</label>
                    <input id="quickblog_isize" class="input_textbox" name="serendipity[quickblog][size]" value="<?php 
                        echo $serendipity['thumbSize'];
                        ?>
" type="text">
                </div>
            </div>
            <em><?php 
                        echo PLUGIN_EVENT_IMAGESELECTORPLUS_IMAGE_SIZE_DESC;
                        ?>
</em>
        </div>
<?php 
                    }
                    break;
                case 'backend_image_add':
                    global $new_media;
                    // if file is zip archive and unzipping enabled
                    // unzip file and add all images to database
                    // retrieve file type
                    $target_zip = $eventData;
                    preg_match('@(^.*/)+(.*)\\.+(\\w*)@', $target_zip, $matches);
                    $target_dir = $matches[1];
                    $basename = $matches[2];
                    $extension = $matches[3];
                    $authorid = isset($serendipity['POST']['all_authors']) && $serendipity['POST']['all_authors'] == 'true' ? '0' : $serendipity['authorid'];
                    // only if unzipping function exists, we have archive file and unzipping set to yes
                    if (class_exists('ZipArchive') && $extension == 'zip' && $serendipity['POST']['unzip_archives'] == YES) {
                        // now unzip
                        $zip = new ZipArchive();
                        $res = $zip->open($target_zip);
                        if ($res === TRUE) {
                            $files_to_unzip = array();
                            $extracted_images = array();
                            for ($i = 0; $i < $zip->numFiles; $i++) {
                                $file_to_extract = $zip->getNameIndex($i);
                                if (file_exists($target_dir . $file_to_extract)) {
                                    echo '(' . $file_to_extract . ') ' . ERROR_FILE_EXISTS_ALREADY . '<br />';
                                } else {
                                    $files_to_unzip[] = $file_to_extract;
                                    $extracted_images[] = $target_dir . $file_to_extract;
                                }
                            }
                            $zip->extractTo($target_dir, $files_to_unzip);
                            $zip->close();
                            echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_OK;
                        } else {
                            echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_FAILED;
                        }
                        // now proceed all unzipped images
                        foreach ($extracted_images as $target) {
                            preg_match('@(^.*/)+(.*)\\.+(\\w*)@', $target, $matches);
                            $real_dir = $matches[1];
                            $basename = $matches[2];
                            $extension = $matches[3];
                            $tfile = $basename . "." . $extension;
                            preg_match('@' . $serendipity['uploadPath'] . '(.*/)@', $target, $matches);
                            $image_directory = $matches[1];
                            // make thumbnails for new images
                            $thumbs = array(array('thumbSize' => $serendipity['thumbSize'], 'thumb' => $serendipity['thumbSuffix']));
                            serendipity_plugin_api::hook_event('backend_media_makethumb', $thumbs);
                            foreach ($thumbs as $thumb) {
                                // Create thumbnail
                                if ($created_thumbnail = serendipity_makeThumbnail($tfile, $image_directory, $thumb['thumbSize'], $thumb['thumb'])) {
                                    echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_IMAGE_FROM_ARCHIVE . " - " . THUMB_CREATED_DONE . '<br />';
                                }
                            }
                            // Insert into database
                            $image_id = serendipity_insertImageInDatabase($tfile, $image_directory, $authorid, null, $realname);
                            echo PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_IMAGE_FROM_ARCHIVE . " ({$tfile}) " . PLUGIN_EVENT_IMAGESELECTORPLUS_UNZIP_ADD_TO_DB . "<br />";
                            $new_media[] = array('image_id' => $image_id, 'target' => $target, 'created_thumbnail' => $created_thumbnail);
                        }
                    }
                case 'backend_image_addHotlink':
                    // Re-Scale thumbnails?
                    $max_scale = array('width' => (int) $this->get_config('thumb_max_width'), 'height' => (int) $this->get_config('thumb_max_height'));
                    if ($max_scale['width'] > 0 || $max_scale['height'] > 0) {
                        $this->resizeThumb($max_scale, $eventData);
                    }
                    if (empty($serendipity['POST']['quickblog']['title'])) {
                        break;
                    }
                    $file = basename($eventData);
                    $directory = str_replace($serendipity['serendipityPath'] . $serendipity['uploadPath'], '', dirname($eventData) . '/');
                    $size = (int) $serendipity['POST']['quickblog']['size'];
                    // check default Serendipity thumbSize, to make this happen like standard image uploads, and to get one "fullsize" image instance only,
                    // else create another quickblog image "resized" instance, to use as entries thumbnail image
                    if ($serendipity['thumbSize'] != $size) {
                        $oldSuffix = $serendipity['thumbSuffix'];
                        $serendipity['thumbSuffix'] = 'quickblog';
                        serendipity_makeThumbnail($file, $directory, $size);
                        $serendipity['thumbSuffix'] = $oldSuffix;
                    }
                    // Non-image object link generation
                    if ($serendipity['POST']['quickblog']['isobject'] == YES) {
                        $objfile = serendipity_parseFileName($file);
                        $filename = $objfile[0];
                        $suffix = $objfile[1];
                        $obj_mime = serendipity_guessMime($suffix);
                        $objpath = $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $directory . $filename . '.' . $suffix;
                        // try to know about a working environment for imagemagicks pdf preview generation
                        if ($serendipity['magick'] === true && strtolower($suffix) == 'pdf' && $serendipity['thumbSize'] == $size) {
                            $objpreview = $serendipity['serendipityHTTPPath'] . $serendipity['uploadPath'] . $directory . $filename . '.' . $serendipity['thumbSuffix'] . '.' . $suffix . '.png';
                        } else {
                            $objpreview = serendipity_getTemplateFile('admin/img/mime_' . preg_replace('@[^0-9a-z_\\-]@i', '-', $obj_mime) . '.png');
                        }
                        if (!$objpreview || empty($objpreview)) {
                            $objpreview = serendipity_getTemplateFile('admin/img/mime_unknown.png');
                        }
                    }
                    // New draft post
                    $entry = array();
                    $entry['isdraft'] = 'false';
                    $entry['title'] = function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['quickblog']['title']) : htmlspecialchars($serendipity['POST']['quickblog']['title'], ENT_COMPAT, LANG_CHARSET);
                    if (isset($objpath) && !empty($objpath)) {
                        $entry['body'] = '<a href="' . $objpath . '"><img alt="" class="serendipity_image_left serendipity_quickblog_image" src="' . $objpreview . '">' . $filename . '</a> (-' . $obj_mime . '-)<p>' . $serendipity['POST']['quickblog']['body'] . '</p>';
                    } else {
                        $entry['body'] = '<!--quickblog:' . $serendipity['POST']['quickblog']['target'] . '|' . $eventData . '-->' . $serendipity['POST']['quickblog']['body'];
                    }
                    $entry['authorid'] = $serendipity['authorid'];
                    $entry['exflag'] = false;
                    $entry['categories'][0] = function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['POST']['quickblog']['category']) : htmlspecialchars($serendipity['POST']['quickblog']['category'], ENT_COMPAT, LANG_CHARSET);
                    #$entry['allow_comments']    = 'true'; // both disabled
                    #$entry['moderate_comments'] = 'false'; // to take default values
                    $serendipity['POST']['properties']['fake'] = 'fake';
                    $id = serendipity_updertEntry($entry);
                    break;
                case 'frontend_display':
                    // auto resizing images based on width and/or height attributes in img tag
                    if (serendipity_db_bool($this->get_config('autoresize'))) {
                        if (!empty($eventData['body'])) {
                            $eventData['body'] = $this->substituteImages($eventData['body']);
                        }
                        if (!empty($eventData['extended'])) {
                            $eventData['extended'] = $this->substituteImages($eventData['extended']);
                        }
                    }
                    if (empty($eventData['body'])) {
                        return;
                    }
                    // displaying quickblog posts
                    if (is_object($serendipity['smarty']) && preg_match('@<!--quickblog:(.+)-->@imsU', $eventData['body'], $filematch)) {
                        $eventData['body'] = $this->parse_quickblog_post($filematch[1], $eventData['body']);
                    }
                    // displaying galleries introduced by markup
                    foreach ($this->markup_elements as $temp) {
                        if (serendipity_db_bool($this->get_config($temp['name'], true)) && isset($eventData[$temp['element']]) && !$eventData['properties']['ep_disable_markup_' . $this->instance] && !isset($serendipity['POST']['properties']['disable_markup_' . $this->instance])) {
                            $element = $temp['element'];
                            $eventData[$element] = $this->media_insert($eventData[$element], $eventData);
                        }
                    }
                    return true;
                    break;
                case 'backend_entry_presave':
                    if (is_numeric($eventData['id'])) {
                        $eventData['body'] = str_replace('{{s9yisp_entryid}}', $eventData['id'], $eventData['body']);
                        $eventData['extended'] = str_replace('{{s9yisp_entryid}}', $eventData['id'], $eventData['extended']);
                        $this->gotMilk = true;
                    } else {
                        $this->cache['body'] = $eventData['body'];
                        $this->cache['extended'] = $eventData['extended'];
                    }
                    break;
                case 'backend_publish':
                case 'backend_save':
                    if ($this->gotMilk === false) {
                        $old = md5($this->cache['body']) . md5($this->cache['extended']);
                        $this->cache['body'] = str_replace('{{s9yisp_entryid}}', $eventData['id'], $this->cache['body']);
                        $this->cache['extended'] = str_replace('{{s9yisp_entryid}}', $eventData['id'], $this->cache['extended']);
                        $new = md5($this->cache['body']) . md5($this->cache['extended']);
                        if ($old != $new) {
                            serendipity_db_query("UPDATE {$serendipity['dbPrefix']}entries\n                                                     SET body     = '" . serendipity_db_escape_string($this->cache['body']) . "',\n                                                         extended = '" . serendipity_db_escape_string($this->cache['extended']) . "'\n                                                   WHERE       id = " . (int) $eventData['id']);
                        }
                    }
                    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);
                        }
                    }
                    break;
                case 'entries_header':
                    if (!$this->selected()) {
                        return true;
                    }
                    if ($serendipity['version'][0] > 1) {
                        return true;
                    }
                    if (!headers_sent()) {
                        header('HTTP/1.0 200');
                        header('Status: 200 OK');
                    }
                    $entry = serendipity_fetchEntry('id', $serendipity['GET']['id']);
                    $imageid = $serendipity['GET']['image'];
                    $imgsrc = '';
                    if (preg_match('@<a title="([^"]+)" id="s9yisp' . $imageid . '"></a>@imsU', $entry['body'], $imgmatch)) {
                        $imgsrc = $imgmatch[1];
                    } elseif (preg_match('@<a title="([^"]+)" id="s9yisp' . $imageid . '"></a>@imsU', $entry['extended'], $imgmatch)) {
                        $imgsrc = $imgmatch[1];
                    } else {
                        return;
                    }
                    $link = '<a href="' . serendipity_archiveURL($serendipity['GET']['id'], $entry['title'], 'baseURL', true, array('timestamp' => $entry['timestamp'])) . '#s9yisp' . $imageid . '">';
                    echo '<div class="serendipity_Entry_Date">
                             <h3 class="serendipity_date">' . serendipity_formatTime(DATE_FORMAT_ENTRY, $entry['timestamp']) . '</h3>';
                    echo '<h4 class="serendipity_title"><a href="#">' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($entry['title']) : htmlspecialchars($entry['title'], ENT_COMPAT, LANG_CHARSET)) . '</a></h4>';
                    echo '<div class="serendipity_entry"><div class="serendipity_entry_body">';
                    echo '<div class="serendipity_center">' . $link . '<!-- s9ymdb:' . $entry['id'] . ' --><img src="' . $imgsrc . '" /></a></div>';
                    echo '<br />';
                    echo $link . '&lt;&lt; ' . BACK . '</a>';
                    echo "</div>\n</div>\n</div>\n";
                    return true;
                    break;
                case 'frontend_image_add_unknown':
                case 'frontend_image_add_filenameonly':
                case 'frontend_image_selector_submit':
                case 'frontend_image_selector_more':
                case 'frontend_image_selector_imagecomment':
                case 'frontend_image_selector_imagealign':
                case 'frontend_image_selector_imagesize':
                case 'frontend_image_selector_hiddenfields':
                case 'frontend_image_selector_imagelink':
                    return true;
                    break;
                case 'css_backend':
                    if ($serendipity['version'][0] > 1) {
                        ?>

#imageselectorplus .radio_field input {
    margin: 0 0.5em;
}
#quickblog_tablefield {
   display: table-cell;
}
#uploadform .quickblog_nugget {
    margin-left: 0;
    padding: 0;
}
#quickblog_tablefield .quickblog_form_field {
    margin: .375em 0;
}
#quickblog_tablefield .quickblog_radio_field div label,
#quickblog_tablefield .radio_field label {
    padding-left: .5em;
}
#quickblog_tablefield .quickblog_form_select {
    margin-top: 0.75em;
    margin-bottom: 0.75em;
}
#quickblog_tablefield .quickblog_radio_field label {
    padding-left: 0;
}
#quickblog_tablefield .quickblog_radio_field div {
    display: inline;
}
#quickblog_tablefield .quickblog_radio_field input {
    margin-left: 0.5em;
}

<?php 
                    }
                    break;
                case 'css':
                    ?>

#content .serendipity_quickblog_image {
    border: medium none transparent;
}
.serendipity_mediainsert_gallery {
    border: 1px solid #C0C0C0;
    margin: 0px;
    overflow: auto;
    padding: 0.4em;
}

<?php 
                    break;
                case 'frontend_image_selector':
                    if ($serendipity['version'][0] < 2) {
                        $eventData['finishJSFunction'] = 'serendipity_imageSelectorPlus_done(\'' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['GET']['textarea']) : htmlspecialchars($serendipity['GET']['textarea'], ENT_COMPAT, LANG_CHARSET)) . '\')';
                    } else {
                        $eventData['finishJSFunction'] = 'serendipity.serendipity_imageSelector_done(\'' . (function_exists('serendipity_specialchars') ? serendipity_specialchars($serendipity['GET']['textarea']) : htmlspecialchars($serendipity['GET']['textarea'], ENT_COMPAT, LANG_CHARSET)) . '\')';
                    }
                    return true;
                    break;
                default:
                    return false;
            }
        } else {
            return false;
        }
    }
    function event_hook($event, &$bag, &$eventData, $addData = null)
    {
        global $serendipity;
        $hooks =& $bag->get('event_hooks');
        $this->debug = serendipity_db_bool($this->get_config('debug'));
        if (isset($hooks[$event])) {
            switch ($event) {
                case 'backend_sidebar_entries':
                    if ($serendipity['serendipityUserlevel'] >= USERLEVEL_CHIEF) {
                        if ($serendipity['version'][0] == '1') {
                            ?>
                        <li class="serendipitySideBarMenuLink serendipitySideBarMenuEntryLinks"><a href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=aggregator"><?php 
                            echo PLUGIN_AGGREGATOR_TITLE;
                            ?>
</a></li>
<?php 
                        } else {
                            ?>
                        <li><a href="?serendipity[adminModule]=event_display&amp;serendipity[adminAction]=aggregator"><?php 
                            echo PLUGIN_AGGREGATOR_TITLE;
                            ?>
</a></li>
<?php 
                        }
                    }
                    break;
                case 'backend_sidebar_entries_event_display_aggregator':
                    $this->showFeeds();
                    break;
                case 'cronjob':
                    if ($this->get_config('cronjob') == $eventData) {
                        serendipity_event_cronjob::log('Aggregator', 'plugin');
                        $this->fetchFeeds();
                        # Fetch first, expire later (some feeds offer old stuff)
                        $this->expireFeeds();
                    }
                    return true;
                    break;
                case 'aggregator_feedlist':
                    $this->parseShowFeed($eventData);
                    return true;
                    break;
                case 'external_plugin':
                    if ($eventData == 'opmlfeeds.xml') {
                        header('Content-Type: text/xml; charset=utf-8');
                        echo '<?xml version="1.0" encoding="utf-8" ?>' . "\n";
                        $modified = gmdate('D, d M Y H:i:s \\G\\M\\T', serendipity_serverOffsetHour(time(), true));
                        print <<<EOF
<opml version="1.0">
<head>
    <title>{$serendipity['blogTitle']}</title>
    <dateModified>{$modified}</dateModified>
    <ownerName>Serendipity - http://www.s9y.org/</ownerName>
</head>
<body>
EOF;
                        $feeds = serendipity_db_Query("\n                                    SELECT c.categoryid,\n                                           f.feedname,\n                                           f.feedurl,\n                                           f.htmlurl\n                                     FROM {$serendipity['dbPrefix']}category AS c\n                                LEFT JOIN {$serendipity['dbPrefix']}aggregator_feedcat AS fc\n                                       ON fc.categoryid = c.categoryid\n                                LEFT JOIN {$serendipity['dbPrefix']}aggregator_feeds AS f\n                                       ON fc.feedid = f.feedid", false, 'assoc');
                        $xml = array();
                        if (is_array($feeds)) {
                            foreach ($feeds as $feed) {
                                $xml[$feed['categoryid']][] = $feed;
                            }
                        }
                        if (is_array($cats = serendipity_fetchCategories())) {
                            $cats = $this->showRecursive($cats, $xml, 'categoryid', 'parentid', VIEWMODE_THREADED);
                        }
                        print "</body>\n</opml>";
                        return;
                    }
                    if ($eventData != 'aggregator') {
                        return;
                    }
                    $this->fetchFeeds();
                    # Fetch first, expire later (some feeds offer old stuff)
                    $this->expireFeeds();
                    break;
            }
        }
        return true;
    }
Example #27
0
<?php

if (IN_serendipity !== true) {
    die("Don't hack!");
}
$probelang = dirname(__FILE__) . '/' . $serendipity['charset'] . 'lang_' . $serendipity['lang'] . '.inc.php';
if (file_exists($probelang)) {
    include $probelang;
}
include dirname(__FILE__) . '/lang_en.inc.php';
$serendipity['smarty']->assign(array('currpage' => "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']));
if ($serendipity['GET']['adminModule'] == 'templates' || $serendipity['POST']['adminModule'] == 'templates') {
    if (is_array($all_cats = serendipity_fetchCategories('all'))) {
        $categories = serendipity_walkRecursive($categories, 'categoryid', 'parentid', VIEWMODE_THREADED);
        $catsel = array();
        foreach ($all_cats as $cat) {
            $catsel[$cat['categoryid']] = str_repeat('&nbsp;', $cat['depth']) . $cat['category_name'];
        }
    }
}
$template_config = array(array('var' => 'infoxxx1', 'name' => 'infoxxx1', 'type' => 'custom', 'custom' => MIMBO_INSTR), array('var' => 'catlead', 'name' => MIMBO_CAT_LEAD, 'type' => 'select', 'default' => '', 'select_values' => $catsel), array('var' => 'catfeat', 'name' => MIMBO_CAT_FEAT, 'type' => 'select', 'default' => '', 'select_values' => $catsel), array('var' => 'catx1', 'name' => MIMBO_CAT_X1, 'type' => 'select', 'default' => '', 'select_values' => $catsel), array('var' => 'catx2', 'name' => MIMBO_CAT_X2, 'type' => 'select', 'default' => '', 'select_values' => $catsel), array('var' => 'catx3', 'name' => MIMBO_CAT_X3, 'type' => 'select', 'default' => '', 'select_values' => $catsel), array('var' => 'amount', 'name' => NAVLINK_AMOUNT, 'type' => 'string', 'default' => '5'));
$template_config_groups = NULL;
$template_loaded_config = serendipity_loadThemeOptions($template_config, $serendipity['smarty_vars']['template_option']);
$navlinks = array();
for ($i = 0; $i < $template_loaded_config['amount']; $i++) {
    $navlinks[] = array('title' => $template_loaded_config['navlink' . $i . 'text'], 'href' => $template_loaded_config['navlink' . $i . 'url'], 'pos' => $template_loaded_config['navlink' . $i . 'posi']);
    $template_config[] = array('var' => 'navlink' . $i . 'text', 'name' => NAV_LINK_TEXT . ' #' . $i, 'type' => 'string', 'default' => 'Link #' . $i);
    $template_config[] = array('var' => 'navlink' . $i . 'url', 'name' => NAV_LINK_URL . ' #' . $i, 'type' => 'string', 'default' => '#');
    $template_config[] = array('var' => 'navlink' . $i . 'posi', 'name' => NAV_LINK_POS . ' #' . $i, 'type' => 'select', 'default' => 'none', 'select_values' => array('left' => SITENAV_LEFT, 'right' => SITENAV_RIGHT));
}
$serendipity['smarty']->assign_by_ref('navlinks', $navlinks);
    function admin_print_sidebar(&$sidebar, $side, $plugin_list)
    {
        global $serendipity;
        $i = 0;
        $viewlist = unserialize($this->get_config('view_list'));
        $category_viewlist = unserialize($this->get_config('category_view_list'));
        $usergroups_viewlist = unserialize($this->get_config('usergroups_view_list'));
        $mygroups = serendipity_getGroups($serendipity['authorid']);
        $enabled = serendipity_db_bool($this->get_config('enable'));
        foreach ($sidebar as $plugin_data) {
            $plugin =& serendipity_plugin_api::load_plugin($plugin_data['name'], $plugin_data['authorid'], $plugin_data['path']);
            if (is_object($plugin)) {
                $checked = "";
                $checked_member = "";
                $checked_myself = "";
                $checked_everyone = "";
                if ($plugin_list[$side] && !$plugin_list[$side][$i]) {
                    $checked = "checked='checked'";
                }
                if ($viewlist[$plugin->instance] == 'member') {
                    $checked_member = "checked='checked'";
                } elseif ($viewlist[$plugin->instance] == 'myself' || $viewlist[$plugin->instance] == $serendipity['authorid']) {
                    $checked_myself = "checked='checked'";
                } elseif ($viewlist[$plugin->instance] == 'everyone') {
                    $checked_everyone = "checked='checked'";
                } else {
                    $checked_everyone = "checked='checked'";
                }
                $title = '';
                ob_start();
                $show_plugin = $plugin->generate_content($title);
                $content = ob_get_contents();
                ob_end_clean();
                if (empty($title)) {
                    $title = $plugin->get_config('backend_title');
                }
                echo "<div class='serendipitySideBarItem' style='margin-top:10px;margin-bottom:20px;'>\n";
                echo "<h3 class='serendipitySideBarTitle'>{$title}</h3>\n";
                echo "<div class='serendipitySideBarContent'><table>";
                if ($enabled) {
                    echo "<tr>\n";
                    echo "<td>" . PLUGIN_SIDEBAR_HIDER_CONF_HIDDEN . "</td>\n";
                    echo "<td><input class='input_checkbox' type='checkbox' name='plugin_" . $side . "_" . $i . "' {$checked} /></td>\n";
                    echo "</tr>";
                }
                //--JAM: 2005-10-18 Added "everyone" value to clear members and myself values
                echo "<tr>\n";
                echo "<td>" . PLUGIN_SIDEBAR_HIDER_CONF_EVERYONE . "</td>\n";
                echo "<td><input class='input_radio' type='radio' name='plugin_view[" . base64_encode($plugin->instance) . "]' value='everyone' {$checked_everyone} /></td>\n";
                echo "</tr>";
                echo "<tr>\n";
                echo "<td>" . PLUGIN_SIDEBAR_HIDER_CONF_MEMBERS . "</td>\n";
                echo "<td><input class='input_radio' type='radio' name='plugin_view[" . base64_encode($plugin->instance) . "]' value='member' {$checked_member} /></td>\n";
                echo "</tr>";
                echo "<tr>\n";
                echo "<td>" . PLUGIN_SIDEBAR_HIDER_CONF_MYSELF . "</td>\n";
                echo "<td><input class='input_radio' type='radio' name='plugin_view[" . base64_encode($plugin->instance) . "]' value='myself' {$checked_myself} /></td>\n";
                echo "</tr>";
                echo "<tr>\n";
                echo "<td colspan='2'>" . GROUP . "<br >\n";
                echo "<select name='plugin_usergroups_view[" . base64_encode($plugin->instance) . "][]' multiple='multiple'>\n";
                $selected_groups = explode(',', $usergroups_viewlist[$plugin->instance]);
                foreach ($mygroups as $group) {
                    if ('USERLEVEL_' == substr($group['confvalue'], 0, 10)) {
                        $group['name'] = constant($group['confvalue']);
                    }
                    ?>
                    <option value="<?php 
                    echo $group['id'];
                    ?>
" <?php 
                    echo in_array($group['id'], $selected_groups) ? 'selected="selected"' : '';
                    ?>
><?php 
                    echo function_exists('serendipity_specialchars') ? serendipity_specialchars($group['name']) : htmlspecialchars($group['name'], ENT_COMPAT, LANG_CHARSET);
                    ?>
</option>
<?php 
                }
                echo "</select></td>\n";
                echo "</tr>";
                echo "<tr>\n";
                echo "<td colspan='2'>" . PLUGIN_SIDEBAR_HIDER_CONF_CATEGORIES . "<br />\n";
                echo "\n";
                $selected = explode(',', $category_viewlist[$plugin->instance]);
                echo "<select name='plugin_category_view[" . base64_encode($plugin->instance) . "][]' multiple='multiple'>\n";
                // --JAM: 2005-10-18: The front page selection goes on the top
                echo '<option value="" ' . (in_array('', $selected) ? 'selected="selected"' : '') . '>' . (function_exists('serendipity_specialchars') ? serendipity_specialchars(ALL_CATEGORIES) : htmlspecialchars(ALL_CATEGORIES, ENT_COMPAT, LANG_CHARSET)) . '</option>' . "\n";
                echo '<option value="' . PLUGIN_SIDEBAR_HIDER_FRONTPAGE_ID . '" ' . (in_array(PLUGIN_SIDEBAR_HIDER_FRONTPAGE_ID, $selected) ? 'selected="selected"' : '') . '>' . (function_exists('serendipity_specialchars') ? serendipity_specialchars(PLUGIN_SIDEBAR_HIDER_FRONTPAGE_DESC) : htmlspecialchars(PLUGIN_SIDEBAR_HIDER_FRONTPAGE_DESC, ENT_COMPAT, LANG_CHARSET)) . '</option>' . "\n";
                // Now add regular categories to the selection list
                $cats = serendipity_fetchCategories();
                if (is_array($cats)) {
                    $cats = serendipity_walkRecursive($cats, 'categoryid', 'parentid', VIEWMODE_THREADED);
                    foreach ($cats as $cat) {
                        echo '<option value="' . $cat['categoryid'] . '" ' . (in_array($cat['categoryid'], $selected) ? 'selected="selected"' : '') . '>' . str_repeat('&nbsp;', $cat['depth']) . (function_exists('serendipity_specialchars') ? serendipity_specialchars($cat['category_name']) : htmlspecialchars($cat['category_name'], ENT_COMPAT, LANG_CHARSET)) . '</option>' . "\n";
                    }
                }
                echo "</select></td>\n";
                echo "</tr>";
                echo "</table></div>\n";
                echo "</div>\n";
            } else {
                echo ERROR . ': ' . $plugin_data['name'] . '<br />';
            }
            $i++;
        }
    }
 function introspect_config_item($name, &$propbag)
 {
     global $serendipity;
     switch ($name) {
         case 'title':
             $propbag->add('type', 'string');
             $propbag->add('name', TITLE);
             $propbag->add('description', TITLE_FOR_NUGGET);
             $propbag->add('default', PLUGIN_RECENTENTRIES_TITLE);
             break;
         case 'number':
             $propbag->add('type', 'string');
             $propbag->add('name', PLUGIN_RECENTENTRIES_NUMBER);
             $propbag->add('description', PLUGIN_RECENTENTRIES_NUMBER_BLAHBLAH);
             $propbag->add('default', 10);
             break;
         case 'number_from':
             $propbag->add('type', 'radio');
             $propbag->add('name', PLUGIN_RECENTENTRIES_NUMBER_FROM);
             $propbag->add('description', PLUGIN_RECENTENTRIES_NUMBER_FROM_DESC);
             $propbag->add('radio', array('value' => array('all', 'skip'), 'desc' => array(PLUGIN_RECENTENTRIES_NUMBER_FROM_RADIO_ALL, PLUGIN_RECENTENTRIES_NUMBER_FROM_RADIO_RECENT)));
             $propbag->add('default', 'all');
             break;
         case 'randomize':
             $propbag->add('type', 'radio');
             $propbag->add('name', PLUGIN_RECENTENTRIES_RANDOMIZE);
             $propbag->add('description', PLUGIN_RECENTENTRIES_RANDOMIZE_DESC);
             $propbag->add('radio', array('value' => array('yes', 'no'), 'desc' => array(YES, NO)));
             $propbag->add('default', 'no');
             break;
         case 'dateformat':
             $propbag->add('type', 'string');
             $propbag->add('name', GENERAL_PLUGIN_DATEFORMAT);
             $propbag->add('description', sprintf(GENERAL_PLUGIN_DATEFORMAT_BLAHBLAH, '%A, %B %e %Y') . '. ' . PLUGIN_RECENTENTRIES_DATEFORMAT_WIN);
             $propbag->add('default', '%A, %B %e %Y');
             break;
         case 'category':
             $cats = serendipity_fetchCategories($serendipity['authorid']);
             if (!is_array($cats)) {
                 break;
             }
             $catlist = serendipity_generateCategoryList($cats, array(0), 4, 0, 0, '', ' . ');
             $tmp_select_cats = explode('@@@', $catlist);
             if (!is_array($tmp_select_cats)) {
                 break;
             }
             $select_cats = array();
             $select_cats['none'] = ALL_CATEGORIES;
             $select_cats['_cur'] = PARENT_CATEGORY;
             foreach ($tmp_select_cats as $cidx => $tmp_select_cat) {
                 $select_cat = explode('|||', $tmp_select_cat);
                 if (!empty($select_cat[0]) && !empty($select_cat[1])) {
                     $select_cats[$select_cat[0]] = $select_cat[1];
                 }
             }
             $propbag->add('type', 'multiselect');
             $propbag->add('select_values', $select_cats);
             $propbag->add('select_size', 5);
             $propbag->add('name', CATEGORY);
             $propbag->add('description', CATEGORIES_TO_FETCH);
             $propbag->add('default', 'none');
             break;
         case 'show_where':
             $select = array('extended' => PLUGIN_ITEM_DISPLAY_EXTENDED, 'overview' => PLUGIN_ITEM_DISPLAY_OVERVIEW, 'both' => PLUGIN_ITEM_DISPLAY_BOTH);
             $propbag->add('type', 'select');
             $propbag->add('select_values', $select);
             $propbag->add('name', PLUGIN_ITEM_DISPLAY);
             $propbag->add('description', '');
             $propbag->add('default', 'both');
             break;
         default:
             return false;
     }
     return true;
 }
 function import()
 {
     global $serendipity;
     $force = $this->data['mt_force'] == 'true';
     if ($this->data['autodiscovery'] == 'false') {
         $serendipity['noautodiscovery'] = 1;
     }
     // Rewritten to parse the file line by line. Can save quite some
     // memory on large blogs
     //$contents   = file_get_contents($_FILES['serendipity']['tmp_name']['import']['mt_dat']);
     $this->categories = serendipity_fetchCategories();
     $tasks = array();
     $entries = array();
     if (empty($_FILES['serendipity']['tmp_name']['import']['mt_dat'])) {
         $fh = fopen('/tmp/mt.dat', 'r');
     } else {
         $fh = fopen($_FILES['serendipity']['tmp_name']['import']['mt_dat'], 'r');
     }
     $entry = array();
     $el = "";
     $c_el = "";
     $skip = false;
     $is_comment = false;
     $is_trackback = false;
     $nofetch = false;
     while (!feof($fh)) {
         if ($nofetch === false) {
             $this->debug('Next line');
             $line = $this->decode(fgets($fh, 8192));
         } else {
             $this->debug('NO Next line');
             // Keep line from previous run.
             $nofetch = false;
         }
         if ($is_comment || $is_trackback) {
             $this->debug("COMMENT/TRACKBACK mode is active.");
             if (preg_match('/^--------/', $line)) {
                 $this->debug("Next full section requested.");
                 $is_comment = $is_trackback = false;
             } elseif (preg_match('/^-----/', $line)) {
                 $this->debug("Next partial section requested.");
                 if ($is_trackback) {
                     $this->debug("Parsing trackback.");
                     $entry['s9y_comments'][] = $this->doCommentWork($comment, $tasks, 'TRACKBACK');
                 } elseif ($is_comment) {
                     $this->debug("Parsing comment.");
                     $entry['s9y_comments'][] = $this->doCommentWork($comment, $tasks, 'NORMAL');
                 }
                 $el = $c_el = "";
             }
         }
         if ($skip && !preg_match('/^--------/', $line)) {
             $this->debug("No next section match, and skip is activated. Skipping '{$line}'");
             continue;
         }
         if (preg_match('/^--------/', $line)) {
             // We found the end marker of the current entry. Add to entries-Array
             $this->debug("End marker found. Parsing full entry.");
             $entries[] = $this->doEntryWork($entry, $tasks);
             $entry = array();
             $el = "";
             $c_el = "";
             $skip = false;
             $is_comment = false;
             $is_trackback = false;
         } elseif (preg_match('/^-----/', $line)) {
             $this->debug("New section match. Current EL: {$el}");
             unset($el);
             # DEBUG!
             if (empty($el)) {
                 $line = $this->decode(fgets($fh, 8192));
                 $this->debug("Inspecting next line: {$line}");
                 $tline = trim($line);
                 while (($is_comment || $is_trackback) && empty($tline)) {
                     $line = $this->decode(fgets($fh, 8192));
                     $tline = trim($line);
                     $this->debug("Continuing inspecting next line: {$line}");
                 }
                 if (preg_match('/^--------/', $line)) {
                     $this->debug('Next line is new element. End marker found. Parsing full entry.');
                     $entries[] = $this->doEntryWork($entry, $tasks);
                     $entry = array();
                     $el = "";
                     $c_el = "";
                     $skip = false;
                     $is_comment = false;
                     $is_trackback = false;
                 } elseif (preg_match('/^([A-Z\\s]+):/', $line, $matches)) {
                     $this->debug("Match result: {$matches['1']}");
                     if ($matches[1] == 'COMMENT') {
                         $this->debug("Marking COMMENT.");
                         $is_comment = true;
                         $is_trackback = false;
                         $comment = array();
                         $skip = false;
                     } elseif ($matches[1] == 'PING') {
                         $this->debug("Marking TRACKBACK");
                         $is_comment = false;
                         $is_trackback = true;
                         $comment = array();
                         $skip = false;
                     }
                     $this->debug("Setting EL to {$matches[1]}");
                     $el = $matches[1];
                     $c_el = "";
                 } else {
                     $this->debug("Could not parse next line. Keeping it for next cycle.");
                     $nofetch = true;
                 }
             } else {
                 $this->debug("Resetting EL to an empty string");
                 $el = $c_el = "";
             }
         } elseif (empty($el)) {
             $this->debug("EL is empty. Line is '{$line}'");
             $content = "";
             if (preg_match('/^([A-Z\\s]+):\\s+(.*)$/s', $line, $matches)) {
                 $this->debug("Section match {$matches[1]} found, input: {$matches[2]}");
                 $c_el = $matches[1];
                 $content = $matches[2];
             } elseif (!empty($c_el)) {
                 $this->debug("Still in subsection of previous run: {$c_el}.");
                 $content = trim($line);
             }
             if (!empty($content)) {
                 if ($is_comment || $is_trackback) {
                     $this->debug("Appending to comments: {$line}");
                     $comment[$c_el] = $content;
                 } else {
                     $this->debug("Appending to entry: {$line}");
                     if (isset($entry[$c_el])) {
                         $entry[$c_el] .= "" . $content;
                     } else {
                         $entry[$c_el] = $content;
                     }
                 }
             }
         } elseif ($is_comment || $is_trackback) {
             $this->debug("Appending Line in current Element {$el} to comments: {$line}");
             $comment[$el] .= $line;
         } else {
             $this->debug("Appending Line in current Element {$el} to entries: {$line}");
             $entry[$el] .= $line;
         }
     }
     fclose($fh);
     if (!sizeof($tasks) || $force == true) {
         serendipity_db_begin_transaction();
         foreach ($entries as $entry) {
             #echo '<pre>' . printR_($entry, true) . '</pre><br />';
             #continue;
             if (empty($entry['authorid'])) {
                 $entry['authorid'] = $serendipity['authorid'];
                 $entry['author'] = $serendipity['realname'];
             }
             if (!isset($entry['isdraft'])) {
                 $entry['isdraft'] = 'false';
             }
             if (!isset($entry['allow_comments'])) {
                 $entry['allow_comments'] = 'true';
             }
             $comments = $entry['s9y_comments'];
             $entryprops = $entry['props'];
             unset($entry['props']);
             unset($entry['s9y_comments']);
             if (!is_int($r = serendipity_updertEntry($entry))) {
                 echo '<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />' . $r . '</div>';
             } else {
                 $this->debug('Saved entry ' . $r . ' (' . $entry['title'] . ')');
                 $entry['id'] = $r;
                 foreach ((array) $comments as $comment) {
                     $comment['entry_id'] = $r;
                     if ($rc = serendipity_db_insert('comments', $comment)) {
                         $cid = serendipity_db_insert_id('comments', 'id');
                         serendipity_approveComment($cid, $entry['id'], true);
                     } else {
                         echo '<div class="serendipityAdminMsgError"><img style="width: 22px; height: 22px; border: 0px; padding-right: 4px; vertical-align: middle" src="' . serendipity_getTemplateFile('admin/img/admin_msg_error.png') . '" alt="" />' . $rc . '</div>';
                     }
                 }
                 // Let the plugins do some additional stuff. Here it's used with
                 // event_entryproperties in mind to setup the nl2br-stuff
                 serendipity_plugin_api::hook_event('backend_import_entry', $entry, $entryprops);
             }
         }
         serendipity_db_end_transaction(true);
         return true;
     } else {
         return '<ul><li>' . implode('</li><li>', array_unique($tasks)) . '</li></ul>';
     }
 }