예제 #1
0
     // Slug edit form...:
     // Make sure we got a slug_ID:
     param('slug_ID', 'string', true);
     break;
 case 'create':
     // Create new slug...
     $edited_Slug = new Slug();
     // Check that this action request is not a CSRF hacked request:
     $Session->assert_received_crumb('slug');
     // Check that current user has permission to create slugs:
     $current_User->check_perm('slugs', 'edit', true);
     // load data from request
     if ($edited_Slug->load_from_Request()) {
         // We could load data from form without errors:
         // Insert in DB:
         $edited_Slug->dbinsert();
         $Messages->add(T_('New slug created.'), 'success');
         // Redirect so that a reload doesn't write to the DB twice:
         header_redirect('?ctrl=slugs', 303);
         // Will EXIT
         // We have EXITed already at this point!!
     }
     $action = 'new';
     break;
 case 'update':
     // Update slug...
     // Check that this action request is not a CSRF hacked request:
     $Session->assert_received_crumb('slug');
     // Check that current user has permission to edit slugs:
     $current_User->check_perm('slugs', 'edit', true);
     // Make sure we got an slug_ID:
예제 #2
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;
 }