Beispiel #1
0
 /**
  * Process the form
  *
  * @param array $clean reference to validated $_POST
  */
 function formProcess(&$clean)
 {
     // --------------------------------------------------------------------
     // Sanity check
     // --------------------------------------------------------------------
     // Date
     $clean['published_on'] = "{$clean['Date']} {$clean['Time_Hour']}:{$clean['Time_Minute']}:{$clean['Time_Second']}";
     $clean['published_on'] = date('Y-m-d H:i:s', strtotime($clean['published_on']));
     // Sanitize
     // Unset image?
     if (!empty($clean['unset_image'])) {
         $clean['image'] = '';
     }
     // Set to empty string
     // Image?
     if (isset($_FILES['image']) && is_uploaded_file($_FILES['image']['tmp_name'])) {
         $format = explode('.', $_FILES['image']['name']);
         $format = strtolower(end($format));
         // Extension
         list($resize, $fullsize) = suxPhoto::renameImage($_FILES['image']['name']);
         $clean['image'] = $resize;
         // Add image to clean array
         $resize = suxFunct::dataDir($this->module) . "/{$resize}";
         $fullsize = suxFunct::dataDir($this->module) . "/{$fullsize}";
         suxPhoto::resizeImage($format, $_FILES['image']['tmp_name'], $resize, $this->tpl->getConfigVars('thumbnailWidth'), $this->tpl->getConfigVars('thumbnailHeight'));
         move_uploaded_file($_FILES['image']['tmp_name'], $fullsize);
     }
     // Draft
     $clean['draft'] = isset($clean['draft']) && $clean['draft'] ? true : false;
     // --------------------------------------------------------------------
     // Create $msg array
     // --------------------------------------------------------------------
     $msg = array('title' => $clean['title'], 'image' => @$clean['image'], 'body' => $clean['body'], 'published_on' => $clean['published_on'], 'draft' => $clean['draft'], 'blog' => true);
     if (isset($clean['id'])) {
         $msg['id'] = $clean['id'];
     }
     // --------------------------------------------------------------------
     // Put $msg in database
     // --------------------------------------------------------------------
     // New
     $clean['id'] = $this->msg->save($_SESSION['users_id'], $msg, true);
     $this->msg->setPublished(true);
     $tmp = $this->msg->getByID($clean['id']);
     // Is actually published?
     $this->msg->setPublished(null);
     // Revert
     if ($tmp) {
         // Clear all caches, cheap and easy
         $this->tpl->clearAllCache();
         // Log message
         $log = '';
         $url = suxFunct::makeUrl("/user/profile/{$_SESSION['nickname']}", null, true);
         $log .= "<a href='{$url}'>{$_SESSION['nickname']}</a> ";
         $log .= mb_strtolower($this->r->gtext['posted_blog']);
         $url = suxFunct::makeUrl("/blog/view/{$tmp['thread_id']}", null, true);
         $log .= " <a href='{$url}'>{$tmp['title']}</a>";
         // Log
         $this->log->write($_SESSION['users_id'], $log);
         // Clear cache
         $tpl = new suxTemplate('user');
         $tpl->clearCache('profile.tpl', $_SESSION['nickname']);
     }
     $this->log->write($_SESSION['users_id'], "sux0r::blogEdit()  messages_id: {$clean['id']}", 1);
     // Private
     // --------------------------------------------------------------------
     // Tags procedure
     // --------------------------------------------------------------------
     // Parse tags
     $tags = @suxTags::parse($clean['tags']);
     // Save tags into database
     $tag_ids = array();
     foreach ($tags as $tag) {
         $tag_ids[] = $this->tags->save($_SESSION['users_id'], $tag);
     }
     //Delete current links
     $this->link->deleteLink('link__messages__tags', 'messages', $clean['id']);
     // Reconnect links
     foreach ($tag_ids as $id) {
         $this->link->saveLink('link__messages__tags', 'messages', $clean['id'], 'tags', $id);
     }
     // --------------------------------------------------------------------
     // Naive Bayesian procedure
     // --------------------------------------------------------------------
     /*
             `link__bayes_documents__messages` asserts that a message was trained and copied into
             a bayes document, it does not imply that it's the same document
     When a user edits their own document we can assume that we want
             the updated document to represent their selected categories
     However, we cannot assume this for the catgories of others.
     Example:
     I write and classify a 5000 word message.
             Several other users find my post and classify it too.
             Time passes, I'm drunk, I reduce the post to "Eat shit."
     Course of action:
     Deleting all links to a message for which I can train the vector seems
             the safest bet. Other users get to keep what they already classified,
             and can reclassify the modified document at a later date if they wish.
             They can also manually adjust the eroneous documents in the bayes module.
     Problem / TODO:
     I write and classify a 5000 word blog. Someone with permission to edit
             my blog, but who does not share my Bayesian vectors reduces the post to
             "Eat shit." Author's categories are now meaningless as blog tags.
     Now what?
     */
     // Get all the bayes_documents linked to this message where user is trainer
     // untrain it, delete links
     $innerjoin = "\n        INNER JOIN link__bayes_documents__messages ON link__bayes_documents__messages.bayes_documents_id = bayes_documents.id\n        INNER JOIN messages ON link__bayes_documents__messages.messages_id = messages.id\n        INNER JOIN bayes_categories ON bayes_categories.id = bayes_documents.bayes_categories_id\n        INNER JOIN bayes_auth ON bayes_categories.bayes_vectors_id = bayes_auth.bayes_vectors_id\n        ";
     $query = "\n        SELECT bayes_documents.id FROM bayes_documents\n        {$innerjoin}\n        WHERE messages.id = ?\n        AND bayes_auth.users_id = ? AND (bayes_auth.owner = true OR bayes_auth.trainer = true)\n        ";
     // Note: bayes_auth WHERE condition equivilant to nb->isCategoryTrainer()
     $db = suxDB::get();
     $st = $db->prepare($query);
     $st->execute(array($clean['id'], $_SESSION['users_id']));
     $tmp = $st->fetchAll(PDO::FETCH_ASSOC);
     foreach ($tmp as $val) {
         $this->nb->untrainDocument($val['id']);
     }
     // Regcategorize
     // category ids submitted by the form
     if (isset($clean['category_id'])) {
         foreach ($clean['category_id'] as $val) {
             if (!empty($val) && $this->nb->isCategoryTrainer($val, $_SESSION['users_id'])) {
                 $doc_id = $this->nb->trainDocument("{$clean['title']} \n\n {$clean['body']}", $val);
                 $this->link->saveLink('link__bayes_documents__messages', 'bayes_documents', $doc_id, 'messages', $clean['id']);
             }
         }
     }
     $this->id = $clean['id'];
     // Remember this id
 }
Beispiel #2
0
 /**
  * Process the form
  *
  * @param array $clean reference to validated $_POST
  */
 function formProcess(&$clean)
 {
     // --------------------------------------------------------------------
     // Sanity check
     // --------------------------------------------------------------------
     // Date
     $clean['published_on'] = "{$clean['Date']} {$clean['Time_Hour']}:{$clean['Time_Minute']}:{$clean['Time_Second']}";
     $clean['published_on'] = date('Y-m-d H:i:s', strtotime($clean['published_on']));
     // Sanitize
     // Draft
     $clean['draft'] = isset($clean['draft']) && $clean['draft'] ? true : false;
     // --------------------------------------------------------------------
     // Create $bookmark array
     // --------------------------------------------------------------------
     $bookmark = array('url' => $clean['url'], 'title' => $clean['title'], 'body' => $clean['body'], 'published_on' => $clean['published_on'], 'draft' => $clean['draft']);
     // --------------------------------------------------------------------
     // Id
     // --------------------------------------------------------------------
     if (isset($clean['id']) && filter_var($clean['id'], FILTER_VALIDATE_INT) && $clean['id'] > 0) {
         $bookmark['id'] = $clean['id'];
     }
     // --------------------------------------------------------------------
     // Put $bookmark in database
     // --------------------------------------------------------------------
     $clean['id'] = $this->bm->save($_SESSION['users_id'], $bookmark);
     // --------------------------------------------------------------------
     // Tags procedure
     // --------------------------------------------------------------------
     // Parse tags
     $tags = suxTags::parse($clean['tags']);
     // Save tags into database
     $tag_ids = array();
     foreach ($tags as $tag) {
         $tag_ids[] = $this->tags->save($_SESSION['users_id'], $tag);
     }
     //Delete current links
     $this->link->deleteLink('link__bookmarks__tags', 'bookmarks', $clean['id']);
     // Reconnect links
     foreach ($tag_ids as $id) {
         $this->link->saveLink('link__bookmarks__tags', 'bookmarks', $clean['id'], 'tags', $id);
     }
     $this->log->write($_SESSION['users_id'], "sux0r::bookmarksEdit() bookmarks_id: {$clean['id']}", 1);
     // Private
 }