Example #1
0
 /**
  * Process the form
  *
  * @param array $clean reference to validated $_POST
  */
 function formProcess(&$clean)
 {
     // Check $module, assign $table
     $table = $this->getTable($clean['module']);
     if (!$table) {
         throw new Exception('Unsuported $module');
     }
     // --------------------------------------------------------------------
     // Get image from database
     // --------------------------------------------------------------------
     $query = "SELECT users_id, image FROM {$table} WHERE id = ? ";
     $db = suxDB::get();
     $st = $db->prepare($query);
     $st->execute(array($clean['id']));
     $image = $st->fetch(PDO::FETCH_ASSOC);
     if (!$image['image']) {
         throw new Exception('$image not found');
     }
     if ($image['users_id'] != $_SESSION['users_id']) {
         // Security check
         if (!$this->user->isRoot()) {
             $access = $this->user->getAccess($clean['module']);
             if (!isset($GLOBALS['CONFIG']['ACCESS'][$module]['admin'])) {
                 suxFunct::redirect(suxFunct::getPreviousURL('cropper'));
             } elseif ($access < $GLOBALS['CONFIG']['ACCESS'][$clean['module']]['admin']) {
                 suxFunct::redirect(suxFunct::getPreviousURL('cropper'));
             }
         }
     }
     $path_to_dest = "{$GLOBALS['CONFIG']['PATH']}/data/{$clean['module']}/{$image['image']}";
     $path_to_source = suxPhoto::t2fImage($path_to_dest);
     if (!is_writable($path_to_dest)) {
         die('Destination is not writable? ' . $path_to_dest);
     }
     // ----------------------------------------------------------------------------
     // Manipulate And Rewrite Image
     // ----------------------------------------------------------------------------
     // $image
     $format = explode('.', $path_to_source);
     $format = mb_strtolower(end($format));
     if ($format == 'jpg') {
         $format = 'jpeg';
     }
     // fix stupid mistake
     if (!($format == 'jpeg' || $format == 'gif' || $format == 'png')) {
         die('Invalid image format');
     }
     // Try to adjust memory for big files
     suxPhoto::fudgeFactor($format, $path_to_source);
     $func = 'imagecreatefrom' . $format;
     $image = $func($path_to_source);
     if (!$image) {
         die('Invalid image format');
     }
     // $thumb
     $thumb = imagecreatetruecolor($clean['x2'], $clean['y2']);
     $white = imagecolorallocate($thumb, 255, 255, 255);
     ImageFilledRectangle($thumb, 0, 0, $clean['x2'], $clean['y2'], $white);
     imagealphablending($thumb, true);
     // Output
     imagecopyresampled($thumb, $image, 0, 0, $clean['x1'], $clean['y1'], $clean['x2'], $clean['y2'], $clean['width'], $clean['height']);
     $func = 'image' . $format;
     $func($thumb, $path_to_dest);
     // Free memory
     imagedestroy($image);
     imagedestroy($thumb);
     $this->log->write($_SESSION['users_id'], "sux0r::cropper()  {$table}, id: {$clean['id']}", 1);
     // Private
 }
Example #2
0
// Error checking
// ---------------------------------------------------------------------------
if (!isset($_SESSION['users_id'])) {
    exit;
}
if (!isset($_POST['id']) || !filter_var($_POST['id'], FILTER_VALIDATE_INT)) {
    exit;
}
if (!isset($_POST['description'])) {
    exit;
}
// ---------------------------------------------------------------------------
// Secondary error checking
// ---------------------------------------------------------------------------
$log = new suxLog();
$photo = new suxPhoto();
$text = suxFunct::gtext('photos');
// Verify if user is allowed to edit this photo.
if (!$photo->isPhotoOwner($_POST['id'], $_SESSION['users_id'])) {
    exit;
}
$clean = array('id' => $_POST['id'], 'description' => $_POST['description']);
try {
    $photo->savePhoto($_SESSION['users_id'], $clean);
    $tmp = $photo->getPhotoByID($clean['id']);
    if ($tmp['description']) {
        echo $tmp['description'];
    } else {
        echo $text['clickme'];
    }
    $log->write($_SESSION['users_id'], "sux0r::photos::describe() photos_id: {$clean['id']}", 1);
Example #3
0
/**
* Render edit links
*
* @param array $params smarty {insert} parameters
* @return string html
*/
function insert_editLinks($params)
{
    if (!isset($_SESSION['users_id'])) {
        return null;
    }
    if (empty($params['album_id'])) {
        return null;
    }
    if (!filter_var($params['album_id'], FILTER_VALIDATE_INT) || $params['album_id'] < 1) {
        return null;
    }
    $br = null;
    if (isset($params['br'])) {
        $br = '<br />';
    }
    // Check that the user is allowed to edit this album
    $u = new suxUser();
    if (!$u->isRoot()) {
        $photo = new suxPhoto();
        $access = $u->getAccess('photos');
        if ($access < $GLOBALS['CONFIG']['ACCESS']['photos']['admin']) {
            if ($access < $GLOBALS['CONFIG']['ACCESS']['photos']['publisher']) {
                return null;
            } elseif (!$photo->isAlbumOwner($params['album_id'], $_SESSION['users_id'])) {
                return null;
            }
        }
    }
    $edit = suxFunct::makeUrl('/photos/album/edit/' . $params['album_id']);
    $annotate = suxFunct::makeUrl('/photos/album/annotate/' . $params['album_id']);
    $upload = suxFunct::makeUrl('/photos/upload/' . $params['album_id']);
    $text = suxFunct::gtext('photos');
    $html = '';
    $html .= "<a href='{$edit}'>{$text['edit_2']}</a>{$br}";
    $html .= "<a href='{$upload}'>{$text['upload']}</a>{$br}";
    $html .= "<a href='{$annotate}'>{$text['annotate_2']}</a>{$br}";
    if (isset($params['div'])) {
        return '<div class="editLinks">' . $html . '</div>';
    } else {
        return $html;
    }
}
Example #4
0
foreach ($image_dirs as $dir => $table) {
    $path = $CONFIG['PATH'] . "/data/{$dir}";
    if (is_dir($path)) {
        foreach (new DirectoryIterator($path) as $file) {
            $pattern = '/[^_fullsize](\\.jpe?g|\\.gif|\\.png)$/i';
            if ($file->isFile() && preg_match($pattern, $file)) {
                // Query
                $query = "SELECT id FROM {$table} WHERE image = " . $db->quote("{$file}");
                $st = $db->query($query);
                if ($st->fetchColumn() <= 0) {
                    $not_found[] = "{$path}/{$file}";
                }
            }
        }
    }
}
// Purge
$count = 0;
foreach ($not_found as $file) {
    if (!$debug) {
        if (is_file($file)) {
            unlink($file);
        }
        if (is_file(suxPhoto::t2fImage($file))) {
            unlink(suxPhoto::t2fImage($file));
        }
        ++$count;
    }
    echo "unlink() {$file} <br />\n";
}
echo "> {$count} images deleted <br /> \n";
Example #5
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']);
     }
 }
Example #6
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
 }
Example #7
0
<?php

// Ajax
// TinyMCE external image list url
// http://wiki.moxiecode.com/index.php/TinyMCE:Configuration/external_image_list_url
require_once dirname(__FILE__) . '/../../config.php';
require_once dirname(__FILE__) . '/../../initialize.php';
if (!isset($_SESSION['users_id'])) {
    exit;
}
$photo = new suxPhoto();
$images = $photo->getPhotosByUser(null, 0, $_SESSION['users_id']);
$output = 'var tinyMCEImageList = new Array(';
if ($images) {
    foreach ($images as $image) {
        $output .= "\n" . '["' . utf8_encode($image['image']) . '", "' . utf8_encode("{$GLOBALS['CONFIG']['URL']}/data/photos/" . suxPhoto::t2fImage($image['image'])) . '"],';
    }
}
if ($images) {
    $output = substr($output, 0, -1);
}
// remove last comma
$output .= "\n" . ');';
header('Content-type: text/javascript');
// Make output a real JavaScript file
echo $output;
Example #8
0
 /**
  * View photo
  */
 function view($id)
 {
     // Get nickname
     if (isset($_SESSION['nickname'])) {
         $nn = $_SESSION['nickname'];
     } else {
         $nn = 'nobody';
     }
     // "Cache Groups" using a vertical bar |
     $cache_id = "{$nn}|view|{$id}";
     $this->tpl->caching = 1;
     if (!$this->tpl->isCached('view.tpl', $cache_id)) {
         $this->r->arr['photos'] = $this->photo->getPhotoByID($id);
         if ($this->r->arr['photos'] == false || !count($this->r->arr['photos'])) {
             suxFunct::redirect(suxFunct::getPreviousURL());
         } else {
             $this->r->arr['photos']['image'] = suxPhoto::t2fImage($this->r->arr['photos']['image']);
             // Fullsize
             // Album info
             $this->r->arr['album'] = $this->photo->getAlbumByID($this->r->arr['photos']['photoalbums_id']);
             $tmp = $this->user->getByID($this->r->arr['album']['users_id']);
             $this->r->arr['album']['nickname'] = $tmp['nickname'];
             // Previous, next, and page number
             $prev_id = null;
             $next_id = null;
             $page = 1;
             $query = 'SELECT id FROM photos WHERE photoalbums_id = ? ORDER BY image ';
             // Same order as suxPhoto->getPhotos()
             $db = suxDB::get();
             $st = $db->prepare($query);
             $st->execute(array($this->r->arr['photos']['photoalbums_id']));
             $i = 0;
             while ($prev_next = $st->fetch(PDO::FETCH_ASSOC)) {
                 ++$i;
                 if ($prev_next['id'] == $id) {
                     break;
                 }
                 if ($i >= $this->per_page) {
                     $i = 0;
                     ++$page;
                 }
                 $prev_id = $prev_next['id'];
             }
             $prev_next = $st->fetch(PDO::FETCH_ASSOC);
             $next_id = $prev_next['id'];
             $this->r->text['prev_id'] = $prev_id;
             $this->r->text['next_id'] = $next_id;
             $this->r->text['back_url'] = suxFunct::makeUrl('photos/album/' . $this->r->arr['photos']['photoalbums_id'], array('page' => $page));
             $this->r->title .= " | {$this->r->gtext['photos']} | {$this->r->arr['album']['title']}";
         }
     }
     $this->tpl->display('view.tpl', $cache_id);
 }
Example #9
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']);
 }