/**
  * Generate the permalink for the item.
  *
  * Note: Each item has an unique permalink at any given time.
  * Some admin settings may however change the permalinks for previous items.
  * Note: This actually only returns the URL, to get a real link, use {@link Item::get_permanent_link()}
  *
  * @todo archives modes in clean URL mode
  *
  * @param string single, archive, subchap
  * @param string base url to use
  * @param string glue between url params
  */
 function get_permanent_url($permalink_type = '', $blogurl = '', $glue = '&')
 {
     global $DB, $cacheweekly, $Settings, $posttypes_specialtypes, $posttypes_nopermanentURL, $posttypes_catpermanentURL;
     $this->get_Blog();
     if ($this->Blog->get_setting('front_disp') == 'page' && $this->Blog->get_setting('front_post_ID') == $this->ID) {
         // This item is used as front specific page on the blog's home
         $permalink_type = 'none';
     } elseif (in_array($this->ityp_ID, $posttypes_specialtypes)) {
         // This is not an "in stream" post:
         if (in_array($this->ityp_ID, $posttypes_nopermanentURL)) {
             // This type of post is not allowed to have a permalink:
             $permalink_type = 'none';
         } elseif (in_array($this->ityp_ID, $posttypes_catpermanentURL)) {
             // This post has a permanent URL as url to main chapter:
             $permalink_type = 'cat';
         } else {
             // allowed to have a permalink:
             // force use of single url:
             $permalink_type = 'single';
         }
     } elseif (empty($permalink_type)) {
         // Normal "in stream" post:
         // Use default from collection settings (may be an "in stream" URL):
         $permalink_type = $this->Blog->get_setting('permalinks');
     }
     switch ($permalink_type) {
         case 'archive':
             return $this->get_archive_url($blogurl, $glue);
         case 'subchap':
             return $this->get_chapter_url($blogurl, $glue);
         case 'none':
             // This is a silent fallback when we try to permalink to an Item that cannot be addressed directly:
             // Link to blog home:
             return $this->Blog->gen_blogurl();
         case 'cat':
             // Link to permanent url of main chapter:
             $this->get_main_Chapter();
             return $this->main_Chapter->get_permanent_url(NULL, $blogurl, 1, NULL, $glue);
         case 'single':
         default:
             return $this->get_single_url(true, $blogurl, $glue);
     }
 }