public function create() { $this->f3->set('page_head', 'Create Bookmark'); //template $this->f3->set('view', 'item/create.htm'); //menu $this->f3->set('topmenu', 'i'); if ($this->f3->exists('POST.title')) { if ($this->f3->get('POST.title') != '') { //strip all tags and unsafe characters $t = $this->f3->get('POST.title'); $this->f3->set('POST.title', $this->f3->scrub($t)); $t = $this->f3->get('POST.url'); $this->f3->set('POST.url', $this->f3->scrub($t)); $t = $this->f3->get('POST.note'); $this->f3->set('POST.note', $this->f3->scrub($t)); $t = $this->f3->get('POST.cid'); $this->f3->set('POST.cid', $this->f3->scrub($t)); $t = $this->f3->get('POST.tags'); $this->f3->set('POST.tags', $this->f3->scrub($t)); //server side validation //if too long title if (strlen($this->f3->get('POST.title')) > 256) { $this->f3->set('COOKIE.message', 'the title cannot be longer than 256 chars!'); $this->f3->set('COOKIE.messagetype', 'alert-danger hide10s'); $this->f3->reroute('/i/create'); } //if too long url if (strlen($this->f3->get('POST.url')) > 256) { $this->f3->set('COOKIE.message', 'the url cannot be longer than 256 chars!'); $this->f3->set('COOKIE.messagetype', 'alert-danger hide10s'); $this->f3->reroute('/i/create'); } //if too long note if (strlen($this->f3->get('POST.note')) > 20000) { $this->f3->set('COOKIE.message', 'the note cannot be longer than 20000 chars!'); $this->f3->set('COOKIE.messagetype', 'alert-danger hide10s'); $this->f3->reroute('/i/create'); } //if cat is not numeric if (!is_numeric($this->f3->get('POST.cid'))) { //$this->f3->set('COOKIE.message','the category ID must be numeric!'); //$this->f3->set('COOKIE.messagetype','alert-danger hide10s'); //$this->f3->reroute('/i/create'); $this->f3->set('POST.cid', 0); } //if too long tags if (strlen($this->f3->get('POST.tags')) > 5000) { $this->f3->set('COOKIE.message', 'tags cannot be longer than 5000 chars!'); $this->f3->set('COOKIE.messagetype', 'alert-danger hide10s'); $this->f3->reroute('/i/create'); } //get unique tok $utok = new Item($this->db); $randtok = rand(100000000, 999999999); while ($utok->itemcountByTok($randtok) > 0) { $randtok = rand(100000000, 999999999); } //variables $item = new Item($this->db); $item->tok = $randtok; $item->add(); //last inserted id $iid = $item->_id; //add tags if ($this->f3->exists('POST.tags')) { $tid = 0; $tags = explode(',', $this->f3->get('POST.tags')); foreach ($tags as $t) { $t = trim($t); if ($t != '') { $this->f3->clear('TAGS'); $ifexists = new Tag($this->db); $ifexists->getByName(strtolower($t)); //get id if ($this->f3->exists('TAGS.id')) { $tid = $this->f3->get('TAGS.id'); } else { //insert new tag $newtag = new Tag($this->db); $newtag->title = strtolower(preg_replace('|[^0-9A-Za-z \\-\\/+]|', '', $t)); $newtag->label = preg_replace('|[^0-9A-Za-z \\-\\/+]|', '', $t); $newtag->url = toUrl($t); //get unique tok $utok = new Tag($this->db); $randtok = rand(100000000, 999999999); while ($utok->tagcountByTok($randtok) > 0) { $randtok = rand(100000000, 999999999); } $newtag->tok = $randtok; $newtag->add(); //get last inserted id $tid = $newtag->_id; } //add to Tag2Item $t2i = new Tag2Item($this->db); //insert lastinsertedid $t2i->tid = $tid; $t2i->iid = $iid; $t2i->add(); } } } } if ($this->f3->get('POST.title') != '') { $this->f3->set('COOKIE.message', 'Bookmark was created'); $this->f3->set('COOKIE.messagetype', 'alert-success hide5s'); $this->f3->reroute('/'); } else { //if not valid $this->f3->set('message', 'The field title is required!'); $this->f3->set('messagetype', 'alert-error hide5s'); } } //breadcrumbs $this->f3->set('breadcrumb', array(array("url" => NULL, "name" => "Create bookmark"))); }