示例#1
0
 /**
  * Get the item tinyslug. If not exists -> create new
  *
  * @return string|boolean tinyslug on success, false otherwise
  */
 function get_tinyslug()
 {
     global $preview;
     $tinyslug_ID = $this->tiny_slug_ID;
     if ($tinyslug_ID != NULL) {
         // the tiny slug for this item was already created
         $SlugCache =& get_SlugCache();
         $Slug =& $SlugCache->get_by_ID($tinyslug_ID, false, false);
         return $Slug === false ? false : $Slug->get('title');
     } elseif ($this->ID > 0 && !$preview) {
         // create new tiny Slug for this item
         // Note: This may happen only in case of posts created before the tiny slug was introduced
         global $DB;
         load_funcs('slugs/model/_slug.funcs.php');
         $Slug = new Slug();
         $Slug->set('title', getnext_tinyurl());
         $Slug->set('itm_ID', $this->ID);
         $Slug->set('type', 'item');
         $DB->begin();
         if (!$Slug->dbinsert()) {
             // Slug dbinsert failed
             $DB->rollback();
             return false;
         }
         $this->set('tiny_slug_ID', $Slug->ID);
         // Update Item preserving mod date:
         if (!$this->dbupdate(false)) {
             // Item dbupdate failed
             $DB->rollback();
             return false;
         }
         $DB->commit();
         // update last tinyurl value on database
         // Note: This doesn't have to be part of the above transaction, no problem if it doesn't succeed to update, or if override a previously updated value.
         global $Settings;
         $Settings->set('tinyurl', $Slug->get('title'));
         $Settings->dbupdate();
         return $Slug->get('title');
     }
     return false;
 }