Beispiel #1
0
/**
 * use this to insert a new object into the table
 * 
 * @param String $table - the name of the table
 * @param Object $obj - any object to be put in the table
 */
function insert_object($table, $obj)
{
    // we have to get the number of rows to generate an id
    //$result = mysql_query("SELECT * FROM `$table`");
    ///$id = mysql_num_rows($result);
    //$obj->uid = $id + 1;
    //serialize the object
    $table = addslashes($table);
    $objstr = base64_encode(serialize($obj));
    $insert_query = "INSERT INTO `{$table}` (`id`, `obj`) \n            VALUES ('', '" . $objstr . "');";
    $insert_result = mysql_query($insert_query);
    $obj->uid = mysql_insert_id();
    update_object($table, $obj);
}
<?php

require_once '../boot.php';
#print_r($_REQUEST);
#die();
$supporter_groups = $_REQUEST['supporter_groups'];
unset($_REQUEST['$supporter_groups']);
$x = 0;
foreach ($supporter_groups as $key) {
    $x++;
    $_REQUEST['Last_Modified'] = date('Y-m-d H:i:s');
    update_object('supporter_groups', $key, $_REQUEST);
}
header("Location: ../" . $_REQUEST['jaguar_redirect']);
        mysql_query("{$RackObject_statement}");
        mysql_query("{$RackObjectHistory_statement}");
        echo "RackObject statement: {$RackObject_statement}\n";
        echo "RackObjectHistory statement: {$RackObjectHistory_statement}\n";
    }
}
function update_master_object($master_object_id)
{
    global $master_object_name;
    global $object_name;
    global $name;
    if ($name != $object_name) {
        $master_object_name_new = preg_replace("/{$object_name}/", $name, $master_object_name);
        //UPDATE ************ mysql update
        $master_object_update_query = "update RackObject set name=\"" . $master_object_name_new . "\" where id=" . $master_object_id;
        mysql_query("{$master_object_update_query}");
    }
}
lookup();
if (authenticate() == 0) {
    exit("incorrect username and/or password");
}
if ($object_id) {
    //if lookup() set $object_id, there was a successfull object lookup
    update_object($object_id);
}
if ($master_object_id) {
    //if lookup() set $master_object_id, there was a successfull master object lookup
    update_master_object($master_object_id);
}
mysql_close();
/**
 *	set the user-defined css file
 *
 *	@param array $args arguments
 *		key 'page' is the page (i.e. page.rev) or false the global css
 *		key 'css' is the content of the css file
 *	@return array response
 *		true if successful
 */
function user_css_set_css($args)
{
    if (!isset($args['page']) || $args['page'] !== false && !page_exists($args['page'])) {
        return response('Required argument "page" missing or invalid', 400);
    }
    if (!isset($args['css'])) {
        return response('Required argument "css" missing', 400);
    }
    if ($args['page'] === false) {
        // TODO (later): drop_cache()
        if (empty($args['css'])) {
            // empty stylesheet
            @unlink(CONTENT_DIR . '/usercss');
            return response(true);
        } else {
            $m = umask(0111);
            if (!@file_put_contents(CONTENT_DIR . '/usercss', $args['css'])) {
                umask($m);
                return response('Error saving stylesheet', 500);
            } else {
                umask($m);
                return response(true);
            }
        }
    } else {
        drop_cache('page', $args['page']);
        load_modules('glue');
        if (empty($args['css'])) {
            delete_object(array('name' => $args['page'] . '.usercss'));
            return response(true);
        } else {
            return update_object(array('name' => $args['page'] . '.usercss', 'type' => 'usercss', 'module' => 'user_css', 'content' => $args['css']));
        }
    }
}
/**
 *	set the user-defined code files
 *
 *	@param array $args arguments
 *		key 'page' is the page (i.e. page.rev) or false the global code
 *		key 'head' is the content of the head file
 *		key 'body' is the content of the body file
 *	@return array response
 *		true if successful
 */
function user_code_set_code($args)
{
    if (!isset($args['page']) || $args['page'] !== false && !page_exists($args['page'])) {
        return response('Required argument "page" missing or invalid', 400);
    }
    if (!isset($args['head'])) {
        return response('Required argument "head" missing', 400);
    }
    if (!isset($args['body'])) {
        return response('Required argument "body" missing', 400);
    }
    if ($args['page'] === false) {
        drop_cache('page');
        foreach (array('head', 'body') as $x) {
            if (empty($args[$x])) {
                @unlink(CONTENT_DIR . '/user' . $x);
            } else {
                $m = umask(0111);
                if (!@file_put_contents(CONTENT_DIR . '/user' . $x, $args[$x])) {
                    umask($m);
                    return response('Error saving user ' . $x, 500);
                } else {
                    umask($m);
                }
            }
        }
        return response(true);
    } else {
        drop_cache('page', $args['page']);
        load_modules('glue');
        foreach (array('head', 'body') as $x) {
            if (empty($args[$x])) {
                delete_object(array('name' => $args['page'] . '.user' . $x));
            } else {
                update_object(array('name' => $args['page'] . '.user' . $x, 'type' => 'user' . $x, 'module' => 'user_code', 'content' => $args[$x]));
            }
        }
        return response(true);
    }
}
Beispiel #6
0
function page_upload($args)
{
    // only handle the file if the frontend wants us to
    if (empty($args['preferred_module']) || $args['preferred_module'] != 'page') {
        return false;
    }
    // check if supported file
    if (!in_array($args['mime'], array('image/jpeg', 'image/png', 'image/gif')) || $args['mime'] == '' && !in_array(filext($args['file']), array('jpg', 'jpeg', 'png', 'gif'))) {
        return false;
    }
    // check if there is already a background-image and delete it
    $obj = load_object(array('name' => $args['page'] . '.page'));
    if (!$obj['#error']) {
        $obj = $obj['#data'];
        if (!empty($obj['page-background-file'])) {
            delete_upload(array('pagename' => array_shift(expl('.', $args['page'])), 'file' => $obj['page-background-file'], 'max_cnt' => 1));
        }
    }
    // set as background-image in page object
    $obj = array();
    $obj['name'] = $args['page'] . '.page';
    $obj['page-background-file'] = $args['file'];
    $obj['page-background-mime'] = $args['mime'];
    // update page object
    load_modules('glue');
    $ret = update_object($obj);
    if ($ret['#error']) {
        log_msg('page_upload: error updating page object: ' . quot($ret['#data']));
        return false;
    } else {
        // we don't actually render the object here, but signal the
        // frontend that everything went okay
        return true;
    }
}
function update_author_obj($author_obj)
{
    return update_object($author_obj, 'authors', author_columns());
}
/**
 *	resize an image object
 *
 *	this function drops the reference to any currently resized version, 
 *	saves the resized image together with the original image in the page's 
 *	shared folder and updates the object file to use the resized version.
 *	@param array $args arguments
 *		key 'name' name of the objects
 *		key 'width' width in px
 *		key 'height' height in px
 *	@return array response
 *		true if the client is advised to reload the image, false if not
 */
function image_resize($args)
{
    // check for gd
    if (!_gd_available()) {
        return response('Host does not have gd', 500);
    }
    // set requested width & height
    if (($width = @intval($args['width'])) == 0) {
        return response('Required argument "width" is zero or does not exist', 400);
    }
    if (($height = @intval($args['height'])) == 0) {
        return response('Required argument "height" is zero or does not exist', 400);
    }
    load_modules('glue');
    // resolve symlinks
    $ret = object_get_symlink($args);
    if ($ret['#error']) {
        return $ret;
    } elseif ($ret['#data'] !== false) {
        log_msg('debug', 'image_resize: resolved object ' . quot($args['name']) . ' into ' . quot($ret['#data']));
        $args['name'] = $ret['#data'];
    }
    // load object
    $obj = load_object($args);
    if ($obj['#error']) {
        return $obj;
    } else {
        $obj = $obj['#data'];
    }
    if (@intval($obj['image-file-width']) == 0 || @intval($obj['image-file-height']) == 0) {
        return response('Original dimensions are not available', 500);
    }
    // set pagename
    $pn = array_shift(expl('.', $obj['name']));
    // resizing might not be necessary at all
    if (!empty($obj['image-resized-file']) && @intval($obj['image-resized-width']) == $width && @intval($obj['image-resized-height'] == $height)) {
        log_msg('debug', 'image_resize: width and height match the current resized file, no resize necessary');
        return response(false);
    }
    // else remove any currently resized file
    if (!empty($obj['image-resized-file'])) {
        log_msg('info', 'image_resize: dropping reference to previous resized file ' . quot($obj['image-resized-file']));
        delete_upload(array('pagename' => $pn, 'file' => $obj['image-resized-file'], 'max_cnt' => 1));
        unset($obj['image-resized-file']);
        unset($obj['image-resized-width']);
        unset($obj['image-resized-height']);
        // update object file as well
        $ret = object_remove_attr(array('name' => $obj['name'], 'attr' => array('image-resized-file', 'image-resized-width', 'image-resized-height')));
        if ($ret['#error']) {
            return $ret;
        }
        $was_resized = true;
    } else {
        $was_resized = false;
    }
    // check if width or height are larger than the original
    if (@intval($obj['image-file-width']) <= $width || @intval($obj['image-file-height']) <= $height) {
        log_msg('debug', 'image_resize: dimensions requested are larger or equal than the original file is, no resize necessary');
        // the client need not reload the the image if we were using the
        // original before
        if (!$was_resized) {
            return response(false);
        } else {
            return response(true);
        }
    }
    // check if we really have a source image
    if (empty($obj['image-file-mime']) && empty($obj['image-file'])) {
        return response(false);
    }
    // TODO (later): make this a generic function
    // load source file
    $ext = filext($obj['image-file']);
    $fn = CONTENT_DIR . '/' . $pn . '/shared/' . $obj['image-file'];
    if ($obj['image-file-mime'] == 'image/jpeg' || in_array($ext, array('jpg', 'jpeg'))) {
        $orig = @imagecreatefromjpeg($fn);
        $dest_ext = 'jpg';
    } elseif ($obj['image-file-mime'] == 'image/png' || $ext == 'png') {
        $orig = @imagecreatefrompng($fn);
        $dest_ext = 'png';
    } elseif (is_ani($fn)) {
        // animated images shall not be resized
        log_msg('debug', 'image_resize: animated image, not resizing');
        return response(true);
    } elseif ($obj['image-file-mime'] == 'image/gif' || $ext == 'gif') {
        $orig = @imagecreatefromgif($fn);
        // save gifs as png
        // TODO (later): check for animated gif (see php.net/manual/en/function.imagecreatefromgif.php)
        $dest_ext = 'png';
    } else {
        return response('Unsupported source file format ' . quot($obj['image-file']), 500);
    }
    if ($orig === false) {
        return response('Error loading source file ' . quot($obj['image-file']), 500);
    }
    // get source file dimensions
    $orig_size = @getimagesize($fn);
    // create resized image
    if (($resized = @imagecreatetruecolor($width, $height)) === false) {
        @imagedestroy($orig);
        return response('Error creating the resized image', 500);
    }
    // preserve any alpha channel
    @imagealphablending($resized, false);
    @imagesavealpha($resized, true);
    // try to resize
    if (!@imagecopyresampled($resized, $orig, 0, 0, 0, 0, $width, $height, $orig_size[0], $orig_size[1])) {
        @imagedestroy($resized);
        @imagedestroy($orig);
        return response('Error resizing the source image', 500);
    }
    // setup destination filename
    $a = expl('.', $obj['image-file']);
    if (1 < count($a)) {
        // throw the previous extension away
        $fn = CONTENT_DIR . '/' . $pn . '/shared/' . implode('.', array_slice($a, 0, -1)) . '-' . $width . 'x' . $height . '.' . $dest_ext;
    } else {
        $fn = CONTENT_DIR . '/' . $pn . '/shared/' . $a[0] . '-' . $width . 'x' . $height . '.' . $dest_ext;
    }
    $m = umask(0111);
    if ($dest_ext == 'jpg') {
        $ret = @imagejpeg($resized, $fn, IMAGE_JPEG_QUAL);
    } else {
        if ($dest_ext == 'png') {
            // preserve any alpha channel
            @imagealphablending($resized, false);
            @imagesavealpha($resized, true);
            $ret = @imagepng($resized, $fn, IMAGE_PNG_QUAL);
        }
    }
    umask($m);
    // destroy images again
    @imagedestroy($resized);
    @imagedestroy($orig);
    if (!$ret) {
        return response('Error saving the resized image', 500);
    } else {
        log_msg('info', 'image_resize: created a resized image of ' . quot($obj['name']) . ' -> ' . quot(basename($fn)));
    }
    // the code above can take a while, so read in the object anew via
    // update_object()
    $update = array();
    $update['name'] = $obj['name'];
    $update['image-resized-file'] = basename($fn);
    $update['image-resized-width'] = $width;
    $update['image-resized-height'] = $height;
    // we change width and height here as well since we are racing with the
    // save_object from the frontend after resize
    $update['object-width'] = $width . 'px';
    $update['object-height'] = $height . 'px';
    return update_object($update);
}
Beispiel #9
0
function update_book_obj($book_obj)
{
    return update_object($book_obj, 'books', book_columns());
}
Beispiel #10
0
 function deleteProject($pid)
 {
     connect_db();
     // delete the project from this array
     $id = array_search($pid, $this->projects);
     if ($id !== false) {
         array_splice($this->projects, $id, 1);
         update_object('Director', $this);
     }
     $proj = get_object('Project', $pid);
     if ($proj !== false) {
         $proj->cleanDelete();
     }
     //close_db();
 }