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)
 {
     if (!isset($_FILES['image']) || !is_uploaded_file($_FILES['image']['tmp_name'])) {
         throw new Exception('No file uploaded?');
     }
     // Check that the user is allowed to upload photos / Security check #2
     if (!$this->user->isRoot()) {
         $access = $this->user->getAccess($this->module);
         if ($access < $GLOBALS['CONFIG']['ACCESS'][$this->module]['admin']) {
             if ($access < $GLOBALS['CONFIG']['ACCESS'][$this->module]['publisher']) {
                 suxFunct::redirect(suxFunct::makeURL('/photos'));
             } elseif (!$this->photo->isAlbumOwner($clean['album'], $_SESSION['users_id'])) {
                 suxFunct::redirect(suxFunct::makeURL('/photos'));
             }
         }
     }
     // Commence collecting $photo array
     $photo['photoalbums_id'] = $clean['album'];
     // Get extension
     $format = explode('.', $_FILES['image']['name']);
     $format = strtolower(end($format));
     // Set the data dir
     $data_dir = suxFunct::dataDir($this->module);
     if ($format != 'zip') {
         // ----------------------------------------------------------------
         // Image file
         // ----------------------------------------------------------------
         list($resize, $fullsize) = suxPhoto::renameImage($_FILES['image']['name']);
         $photo['image'] = $resize;
         // Add image to $photo array
         $resize = $data_dir . "/{$resize}";
         $fullsize = $data_dir . "/{$fullsize}";
         $md5 = md5_file($_FILES['image']['tmp_name']);
         if (!$this->photo->isDupe($md5, $_SESSION['users_id'], $photo['photoalbums_id'])) {
             suxPhoto::resizeImage($format, $_FILES['image']['tmp_name'], $resize, $this->tpl->getConfigVars('thumbnailWidth'), $this->tpl->getConfigVars('thumbnailHeight'));
             move_uploaded_file($_FILES['image']['tmp_name'], $fullsize);
             // Insert $photo into database
             $photo['md5'] = $md5;
             $this->photo->savePhoto($_SESSION['users_id'], $photo);
         }
     } else {
         // ----------------------------------------------------------------
         // Zip file
         // ----------------------------------------------------------------
         $tmp_dir = $GLOBALS['CONFIG']['PATH'] . '/temporary/' . md5(uniqid(mt_rand(), true));
         if (!is_dir($tmp_dir) && !mkdir($tmp_dir, 0777, true)) {
             throw new Exception('Can\'t create temp dir ' . $tmp_dir);
         }
         if (suxFunct::unzip($_FILES['image']['tmp_name'], $tmp_dir)) {
             $valid_formats = array('jpg', 'jpeg', 'png', 'gif');
             $files = array();
             foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($tmp_dir)) as $file) {
                 if (!$file->isFile()) {
                     continue;
                 }
                 if (mb_strpos($file->getPathname(), '__MACOSX') !== false) {
                     continue;
                 }
                 $files[$file->getPathname()] = $file->getFilename();
             }
             foreach ($files as $filepath => $file) {
                 $format = explode('.', $file);
                 $format = strtolower(end($format));
                 if (!in_array($format, $valid_formats)) {
                     continue;
                 }
                 // Skip
                 list($resize, $fullsize) = suxPhoto::renameImage($file);
                 $photo['image'] = $resize;
                 // Add image to $photo array
                 $resize = $data_dir . "/{$resize}";
                 $fullsize = $data_dir . "/{$fullsize}";
                 $md5 = md5_file($filepath);
                 if (!$this->photo->isDupe($md5, $_SESSION['users_id'], $photo['photoalbums_id'])) {
                     suxPhoto::resizeImage($format, $filepath, $resize, $this->tpl->getConfigVars('thumbnailWidth'), $this->tpl->getConfigVars('thumbnailHeight'));
                     copy($filepath, $fullsize);
                     // Insert $photo into database
                     $photo['md5'] = $md5;
                     $this->photo->savePhoto($_SESSION['users_id'], $photo);
                 }
             }
         }
         suxFunct::obliterateDir($tmp_dir);
     }
     $this->log->write($_SESSION['users_id'], "sux0r::photosUpload() photoalbums_id: {$photo['photoalbums_id']}", 1);
     // Private
     $this->photo->setPublished(true);
     $tmp = $this->photo->getAlbumByID($photo['photoalbums_id']);
     // Is actually published?
     $this->photo->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['uploaded_images']);
         $url = suxFunct::makeUrl("/photos/album/{$tmp['id']}", null, true);
         $log .= " <a href='{$url}'>{$tmp['title']}</a>";
         // Log
         $this->log->write($_SESSION['users_id'], $log);
         // Clear caches, cheap and easy
         $tpl = new suxTemplate('user');
         $tpl->clearCache(null, $_SESSION['nickname']);
     }
 }
Beispiel #3
0
 /**
  * Process the form
  *
  * @param array $clean reference to validated $_POST
  */
 function formProcess(&$clean)
 {
     // Commence $clean array
     $user['users_id'] = $clean['users_id'];
     $user['image'] = false;
     // Unset image?
     if (!empty($clean['unset_image'])) {
         $user['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']);
         $user['image'] = $resize;
         // Add image to user 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);
     }
     // Update $user into database
     if ($user['image'] !== false) {
         $this->user->saveImage($user['users_id'], $user['image']);
     }
     // Log
     if ($user['users_id'] == $_SESSION['users_id']) {
         // Self edit
         $log = '';
         $url = suxFunct::makeUrl("/user/profile/{$_SESSION['nickname']}", null, true);
         $log .= "<a href='{$url}'>{$_SESSION['nickname']}</a> ";
         $log .= mb_strtolower($this->r->gtext['changed_avatar']);
         $this->log->write($_SESSION['users_id'], $log);
     } else {
         // Administrator edit
         $this->log->write($_SESSION['users_id'], "sux0r::userAvatar() users_id: {$user['users_id']}", 1);
         // Log, private
     }
     // Clear caches, cheap and easy
     $this->tpl->clearCache(null, $_SESSION['nickname']);
 }