Exemple #1
0
 /**
  *
  * @param <string> $filearray    # $_FILES array posted from your form
  * @param <string> $location     # location of the file you want to save in. This is with respect to home of the user in file matrix.
  * @param <array>  $thumbsarray  # Array of thumbs you want to create
  */
 public function izap_upload_generate_thumbs($filearray, $thumbsarray = array('tiny' => '25', 'small' => '40', 'medium' => '100x100', 'large' => '200x200', 'master' => '550x550'), $location = false)
 {
     $location = !$location ? strtolower(get_class($this)) . '/' : $location;
     foreach ($filearray as $fkey => $fvalue) {
         $fieldname = $fkey;
         $original_name = $fvalue['name'];
         $type = $fvalue['type'];
     }
     $filename = $this->izap_remove_special_characters($original_name);
     $this->setFilename($location . $filename);
     $this->open('write');
     $this->write(get_uploaded_file($fieldname));
     $this->close();
     $stored_file = $this->getFilenameOnFilestore();
     $array_to_be_stored = array('file_name' => $filename, 'file_type' => $type);
     if ($thumbsarray) {
         foreach ($thumbsarray as $key => $val) {
             $size = preg_split('/[Xx]/', $val);
             $thumb_index = strtolower(is_string($key) ? $key : $val);
             $thumb_name = $thumb_index . "_" . $filename;
             $thumbnail = get_resized_image_from_existing_file($stored_file, $size[0], $size[1] ? $size[1] : $size[0], $size[1] ? false : true);
             $this->setFilename($location . $thumb_name);
             if ($this->open("write")) {
                 $this->write($thumbnail);
                 $thumbs[$thumb_index] = $thumb_name;
             }
             $this->close();
         }
         $array_to_be_stored['thumbs'] = $thumbs;
     }
     $this->{$fieldname} = serialize($array_to_be_stored);
 }
Exemple #2
0
 public function saveArchive($name)
 {
     $uf = get_uploaded_file($name);
     if (!$uf) {
         return FALSE;
     }
     $this->open("write");
     $this->write($uf);
     $this->close();
     return true;
 }
 public function savePluginFile($name)
 {
     $uf = get_uploaded_file($name);
     if (!$uf) {
         return FALSE;
     }
     $this->open("write");
     $this->write($uf);
     $this->close();
     return TRUE;
 }
Exemple #4
0
 /**
  * Process the file
  *
  * @param $file
  * @return boolean
  */
 function openFile($file)
 {
     if (!($contents = get_uploaded_file($file))) {
         register_error(elgg_echo('upload_users:error:cannot_open_file'));
         return false;
     }
     /// Check the encoding
     if ($this->encoding == 'ISO-8859-1') {
         $contents = utf8_encode($contents);
     }
     $this->raw_data = $contents;
     return true;
 }
Exemple #5
0
function uploadCK($page, $identifier, $obj)
{
    $funcNum2 = get_Input('CKEditorFuncNum', 'CKEditorFuncNum');
    $file = new ElggFile();
    $filestorename = strtolower(time() . $_FILES['upload']['name']);
    $file->setFilename($filestorename);
    $file->setMimeType($_FILES['upload']['type']);
    $file->owner_guid = elgg_get_logged_in_user_guid();
    $file->subtype = "file";
    $file->originalfilename = $filestorename;
    $file->access_id = ACCESS_PUBLIC;
    $file->open("write");
    $file->write(get_uploaded_file('upload'));
    $file->close();
    $result = $file->save();
    if ($result) {
        $master = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 550, 550);
        if ($master !== false) {
            $_SESSION['UPLOAD_DATA']['file_save'] = "started";
            $filehandler = new ElggFile();
            $filehandler->setFilename($filestorename);
            $filehandler->setMimeType($_FILES['upload']['type']);
            $filehandler->owner_guid = $user->guid;
            $filehandler->subtype = "file";
            $filehandler->originalfilename = $filestorename;
            $filehandler->access_id = ACCESS_PUBLIC;
            $filehandler->open("write");
            $filehandler->write($master);
            $filehandler->close();
            $filehandler->save();
            // Dev URL
            $url = elgg_get_site_url() . 'CKEditorView?file_guid=' . $filehandler->guid;
            //Production URL
            //$url ='/CKEditorView?file_guid='.$filehandler->guid;
            echo '<script type="text/javascript">
		window.parent.CKEDITOR.tools.callFunction(' . $funcNum2 . ', "' . $url . '","");
		</script>';
            exit;
        } else {
            echo '<script type="text/javascript">
		window.parent.CKEDITOR.tools.callFunction(' . $funcNum2 . ', "","");
		</script>';
            exit;
        }
    }
    return true;
}
 public function saveImage($name, $title, $index)
 {
     if ($_FILES[$name]['error'] != 0) {
         return FALSE;
     }
     $info = $_FILES[$name];
     // delete original image if exists
     $options = array('relationship_guid' => $this->getGUID(), 'relationship' => 'image', 'metadata_name_value_pair' => array('name' => 'project_image', 'value' => "{$index}"));
     if ($old_image = elgg_get_entities_from_relationship($options)) {
         if ($old_image[0] instanceof ElggFile) {
             $old_image[0]->delete();
         }
     }
     $image = new ElggFile();
     $prefix = "plugins/";
     $store_name_base = $prefix . strtolower($this->getGUID() . "_{$name}");
     $image->title = $title;
     $image->access_id = $this->access_id;
     $image->setFilename($store_name_base . '.jpg');
     $image->setMimetype('image/jpeg');
     $image->originalfilename = $info['name'];
     $image->project_image = $index;
     // used for deletion on replacement
     $image->save();
     $uf = get_uploaded_file($name);
     if (!$uf) {
         return FALSE;
     }
     $image->open("write");
     $image->write($uf);
     $image->close();
     add_entity_relationship($this->guid, 'image', $image->guid);
     // create a thumbnail
     if ($this->saveThumbnail($image, $store_name_base . '_thumb.jpg') != TRUE) {
         $image->delete();
         return FALSE;
     }
     return TRUE;
 }
Exemple #7
0
/**
 * Process an uploaded CSV file to find new recipients.
 *
 * @param array $recipients previous recipients, to prevent duplicates
 * Contains:
 *
 * user_guids => array() existing users
 * emails => array() extra email addresses
 *
 * @return array
 */
function newsletter_process_csv_upload(array $recipients)
{
    // is a file uploaded
    if (get_uploaded_file("csv")) {
        // open the file as CSV
        $fh = fopen($_FILES["csv"]["tmp_name"], "r");
        if (!empty($fh)) {
            $email_column = false;
            // try to find an email column (in the first 2 rows)
            for ($i = 0; $i < 2; $i++) {
                $row = fgetcsv($fh, null, ";", "\"");
                if ($row) {
                    foreach ($row as $index => $field) {
                        if (newsletter_is_email_address($field)) {
                            $email_column = $index;
                            break;
                        }
                    }
                }
            }
            // found an email column
            if ($email_column !== false) {
                $counter = 0;
                // start at the beginning
                if (rewind($fh)) {
                    $row = fgetcsv($fh, null, ";", "\"");
                    while ($row !== false) {
                        // get the email address
                        $email = @$row[$email_column];
                        // make sure it's a valid email address
                        if (newsletter_is_email_address($email)) {
                            $counter++;
                            $exists = false;
                            // is this email address already in the recipients list
                            if (in_array($email, $recipients["emails"])) {
                                $exists = true;
                            } else {
                                // check for an existing user
                                $ia = elgg_set_ignore_access(true);
                                $users = get_user_by_email($email);
                                if (!empty($users)) {
                                    foreach ($users as $user) {
                                        if (in_array($user->getGUID(), $recipients["user_guids"])) {
                                            $exists = true;
                                        }
                                    }
                                }
                                elgg_set_ignore_access($ia);
                            }
                            if ($exists === false) {
                                // email address wasn't added yet
                                // so add to the list
                                $ia = elgg_set_ignore_access(true);
                                $users = get_user_by_email($email);
                                if (!empty($users)) {
                                    $recipients["user_guids"][] = $users[0]->getGUID();
                                } else {
                                    $recipients["emails"][] = $email;
                                }
                                elgg_set_ignore_access($ia);
                            }
                        }
                        // go to the next row
                        $row = fgetcsv($fh, null, ";", "\"");
                    }
                    // done, report the added emails
                    system_message(elgg_echo("newsletter:csv:added", array($counter)));
                }
            } else {
                // no email column found, report this
                system_message(elgg_echo("newsletter:csv:no_email"));
            }
        }
    }
    return $recipients;
}
Exemple #8
0
<?php

$container_guid = (int) get_input('container_guid', 0);
$parent_guid = get_input('parent_guid');
set_time_limit(0);
$forward_url = REFERER;
if (empty($container_guid) || !get_uploaded_file('zip_file')) {
    register_error(elgg_echo('file:cannotload'));
    forward(REFERER);
}
$extension_array = explode('.', $_FILES['zip_file']['name']);
if (strtolower(end($extension_array)) !== 'zip') {
    register_error(elgg_echo('file:uploadfailed'));
    forward(REFERER);
}
$file = $_FILES['zip_file'];
// disable notifications of new objects
elgg_unregister_notification_event('object', 'file');
if (file_tools_unzip($file, $container_guid, $parent_guid)) {
    system_message(elgg_echo('file:saved'));
    $container = get_entity($container_guid);
    if ($container instanceof ElggGroup) {
        $forward_url = "file/group/{$container->getGUID()}/all#{$parent_guid}";
    } else {
        $forward_url = "file/owner/{$container->username}#{$parent_guid}";
    }
} else {
    register_error(elgg_echo('file:uploadfailed'));
}
// reenable notifications of new objects
elgg_register_notification_event('object', 'file');
Exemple #9
0
// group creator needs to be member of new group and river entry created
if ($is_new_group) {
    // @todo this should not be necessary...
    elgg_set_page_owner_guid($group->guid);
    $group->join($user);
    add_to_river('river/group/create', 'create', $user->guid, $group->guid, $group->access_id);
}
$has_uploaded_icon = !empty($_FILES['icon']['type']) && substr_count($_FILES['icon']['type'], 'image/');
if ($has_uploaded_icon) {
    $icon_sizes = elgg_get_config('icon_sizes');
    $prefix = "groups/" . $group->guid;
    $filehandler = new ElggFile();
    $filehandler->owner_guid = $group->owner_guid;
    $filehandler->setFilename($prefix . ".jpg");
    $filehandler->open("write");
    $filehandler->write(get_uploaded_file('icon'));
    $filehandler->close();
    $filename = $filehandler->getFilenameOnFilestore();
    $sizes = array('tiny', 'small', 'medium', 'large');
    $thumbs = array();
    foreach ($sizes as $size) {
        $thumbs[$size] = get_resized_image_from_existing_file($filename, $icon_sizes[$size]['w'], $icon_sizes[$size]['h'], $icon_sizes[$size]['square']);
    }
    if ($thumbs['tiny']) {
        // just checking if resize successful
        $thumb = new ElggFile();
        $thumb->owner_guid = $group->owner_guid;
        $thumb->setMimeType('image/jpeg');
        foreach ($sizes as $size) {
            $thumb->setFilename("{$prefix}{$size}.jpg");
            $thumb->open("write");
Exemple #10
0
<?php

$forward_url = REFERER;
if (($csv = get_uploaded_file("csv")) && !empty($csv)) {
    $tmp_location = $_FILES["csv"]["tmp_name"];
    if ($fh = fopen($tmp_location, "r")) {
        if (($data = fgetcsv($fh, 0, ";")) !== false) {
            $new_location = tempnam(sys_get_temp_dir(), "subsite_import_" . get_config("site_guid"));
            move_uploaded_file($tmp_location, $new_location);
            $_SESSION["subsite_manager_import"] = array("location" => $new_location, "sample" => $data);
            $forward_url = elgg_get_site_url() . "admin/users/import?step=2";
            system_message(elgg_echo("subsite_manager:action:import:step1:success"));
        } else {
            register_error(elgg_echo("subsite_manager:action:import:step1:error:content"));
        }
    } else {
        register_error(elgg_echo("subsite_manager:action:import:step1:error:file"));
    }
} else {
    register_error(elgg_echo("subsite_manager:action:import:step1:error:csv"));
}
forward($forward_url);
 $error = false;
 //timelinefile
 // if use current
 if (get_input('timeline-image')) {
     $image = get_input('timeline-image');
     // custom image?
     // right file type and not to big?
     if ($image == 'customtimeline') {
         if (substr_count($_FILES['timelinefile']['type'], 'image/') && isset($_FILES['timelinefile']) && $_FILES['timelinefile']['error'] == 0) {
             $filename = "customtimeline";
             $extension = pathinfo($_FILES['timelinefile']['name']);
             $extension = $extension['extension'];
             $filehandler = new ElggFile();
             $filehandler->setFilename($filename);
             $filehandler->open("write");
             $filehandler->write(get_uploaded_file('timelinefile'));
             $filehandler->close();
             $thumbnail = new ElggFile();
             $thumbnail->setFilename($filename . "_thumb");
             $thumbnail->open("write");
             $thumbnail->write(get_resized_image_from_uploaded_file('timelinefile', 150, 150, false));
             $thumbnail->close();
             $timelineURL = 'pg/timeline_theme/getbackground?id=' . $current_user;
         } else {
             register_error(elgg_echo('timelinestyle:timeline:error:image'));
             forward($_SERVER['HTTP_REFERER']);
         }
     } else {
         $timelineURL = $image;
     }
     if (create_metadata($timelinestyle_object->guid, 'timeline-image', $timelineURL, 'string', $_SESSION['guid'], $access_id) == false || empty($timelineURL)) {
Exemple #12
0
/**
 * Uploads an image.
 *
 * Can be used to upload a new image or replace an existing one.
 * If $id is specified, the image will be replaced. If $uploaded is set FALSE,
 * $file can take a local file instead of HTTP file upload variable.
 *
 * All uploaded files will included on the Images panel.
 *
 * @param   array        $file     HTTP file upload variables
 * @param   array        $meta     Image meta data, allowed keys 'caption', 'alt', 'category'
 * @param   int          $id       Existing image's ID
 * @param   bool         $uploaded If FALSE, $file takes a filename instead of upload vars
 * @return  array|string An array of array(message, id) on success, localized error string on error
 * @package Image
 * @example
 * print_r(image_data(
 *     $_FILES['myfile'],
 *     array(
 *         'caption' => '',
 *         'alt' => '',
 *         'category' => '',
 *     )
 * ));
 */
function image_data($file, $meta = array(), $id = 0, $uploaded = true)
{
    global $txp_user, $event;
    $name = $file['name'];
    $error = $file['error'];
    $file = $file['tmp_name'];
    if ($uploaded) {
        $file = get_uploaded_file($file);
        if (get_pref('file_max_upload_size') < filesize($file)) {
            unlink($file);
            return upload_get_errormsg(UPLOAD_ERR_FORM_SIZE);
        }
    }
    if (empty($file)) {
        return upload_get_errormsg(UPLOAD_ERR_NO_FILE);
    }
    list($w, $h, $extension) = getimagesize($file);
    $ext = get_safe_image_types($extension);
    if (!$ext) {
        return gTxt('only_graphic_files_allowed');
    }
    $name = substr($name, 0, strrpos($name, '.')) . $ext;
    $safename = doSlash($name);
    $meta = lAtts(array('category' => '', 'caption' => '', 'alt' => ''), (array) $meta, false);
    extract(doSlash($meta));
    $q = "\n        name = '{$safename}',\n        ext = '{$ext}',\n        w = {$w},\n        h = {$h},\n        alt = '{$alt}',\n        caption = '{$caption}',\n        category = '{$category}',\n        date = now(),\n        author = '" . doSlash($txp_user) . "'\n    ";
    if (empty($id)) {
        $rs = safe_insert('txp_image', $q);
        if ($rs) {
            $id = $GLOBALS['ID'] = $rs;
        }
        $update = false;
    } else {
        $id = assert_int($id);
        $rs = safe_update('txp_image', $q, "id = {$id}");
        $update = true;
    }
    if (!$rs) {
        return gTxt('image_save_error');
    }
    $newpath = IMPATH . $id . $ext;
    if (shift_uploaded_file($file, $newpath) == false) {
        if (!$update) {
            safe_delete('txp_image', "id = {$id}");
        }
        unset($GLOBALS['ID']);
        return $newpath . sp . gTxt('upload_dir_perms');
    }
    @chmod($newpath, 0644);
    // GD is supported
    if (check_gd($ext)) {
        // Auto-generate a thumbnail using the last settings
        if (get_pref('thumb_w') > 0 || get_pref('thumb_h') > 0) {
            $t = new txp_thumb($id);
            $t->crop = (bool) get_pref('thumb_crop');
            $t->hint = '0';
            $t->width = (int) get_pref('thumb_w');
            $t->height = (int) get_pref('thumb_h');
            $t->write();
        }
    }
    $message = gTxt('image_uploaded', array('{name}' => $name));
    update_lastmod('image_uploaded', compact('id', 'name', 'ext', 'w', 'h', 'alt', 'caption', 'category', 'txpuser'));
    // call post-upload plugins with new image's $id
    callback_event('image_uploaded', $event, false, $id);
    return array($message, $id);
}
Exemple #13
0
<?php

$file_input = elgg_extract('file', $_FILES);
$filename = $file_input['name'];
if (empty($filename) || elgg_extract('error', $file_input) !== 0) {
    register_error(elgg_echo('upload:error:unknown'));
    forward(REFERER);
}
$file = new \AssetFile();
$file->setFilename('asset_library/' . $filename);
$file->open('write');
$file->write(get_uploaded_file('file'));
$file->close();
$file->save();
$file->mimetype = (new \Elgg\Filesystem\MimeTypeDetector())->getType($file->getFilenameOnFilestore(), $file->getMimeType());
$file->simpletype = elgg_get_file_simple_type($file->mimetype);
$file->save();
forward(REFERER);
<?php

/**
 * Plugin Installer - installer
 * 
 * @package plugin_installer
 * @author ColdTrick IT Solutions
 * @copyright Coldtrick IT Solutions 2009
 * @link http://www.coldtrick.com/
 */
// Make sure action is secure
admin_gatekeeper();
action_gatekeeper();
$package = get_uploaded_file('module_package');
$overwrite = get_input('overwrite', false);
if ($package) {
    global $CONFIG;
    $filename = time() . $_FILES['module_package']['name'];
    $filehandler = new ElggFile();
    $filehandler->setFilename($filename);
    $filehandler->open("write");
    $filehandler->write($package);
    $zip = new ZipArchive();
    $res = $zip->open($filehandler->getFilenameOnFilestore());
    if ($res === TRUE) {
        $plugin_name = false;
        $manifest = false;
        $start = false;
        for ($i = 0; $i < $zip->numFiles; $i++) {
            $entry = $zip->statIndex($i);
            if (stristr($entry['name'], "manifest.xml") && substr_count($entry['name'], "/") == 1) {
Exemple #15
0
 $error = false;
 //backgroundfile
 // if use current
 if (get_input('background-image')) {
     $image = get_input('background-image');
     // custom image?
     // right file type and not to big?
     if ($image == 'custombackground') {
         if (substr_count($_FILES['backgroundfile']['type'], 'image/') && isset($_FILES['backgroundfile']) && $_FILES['backgroundfile']['error'] == 0) {
             $filename = "custombackground";
             $extension = pathinfo($_FILES['backgroundfile']['name']);
             $extension = $extension['extension'];
             $filehandler = new ElggFile();
             $filehandler->setFilename($filename);
             $filehandler->open("write");
             $filehandler->write(get_uploaded_file('backgroundfile'));
             $filehandler->close();
             $thumbnail = new ElggFile();
             $thumbnail->setFilename($filename . "_thumb");
             $thumbnail->open("write");
             $thumbnail->write(get_resized_image_from_existing_file($filehandler->getFilenameOnFilestore(), 150, 150, false));
             $thumbnail->close();
             $backgroundURL = 'mod/customstyle/getbackground?id=' . $current_user;
         } else {
             register_error(elgg_echo('customstyle:background:error:image'));
             forward($_SERVER['HTTP_REFERER']);
         }
     } else {
         $backgroundURL = $image;
     }
     if (create_metadata($customstyle_object->guid, 'background-image', $backgroundURL, 'string', $_SESSION['guid'], $access_id) == false || empty($backgroundURL)) {
Exemple #16
0
<?php

if (!publications_bibtex_enabled()) {
    register_error(elgg_echo('publication:error:bibtext:enabled'));
    forward(REFERER);
}
// Get input data
$data = get_uploaded_file('bibtex_import');
if (empty($data)) {
    register_error(elgg_echo('publication:bibtex:fileerror'));
    forward(REFERER);
}
$forward_to_edit = (bool) get_input('forward_to_edit', 1);
// import behaviour
$import_behaviour = elgg_get_plugin_setting('bibtex_import_behaviour', 'publications', 'skip');
// default: skip
$skip_duplicates = true;
switch ($import_behaviour) {
    case 'update':
        // always update
        $skip_duplicates = false;
        break;
    case 'user_skip':
    case 'user_update':
        // user can shoose to update/skip
        $user_update_setting = get_input('user_update_setting');
        $skip_duplicates = $user_update_setting !== 'update';
        break;
}
// load lib
publications_load_bibtex_browser();
Exemple #17
0
            } elseif (!is_array($group_guids)) {
                $group_guids = array($group_guids);
            }
            // filter duplicates
            $group_guids = array_unique($group_guids);
            if (empty($emails)) {
                $emails = array();
            } elseif (!is_array($emails)) {
                $emails = array($emails);
            }
            // filter duplicates
            $emails = array_unique($emails);
            // prepare save
            $tmp = array("user_guids" => $user_guids, "group_guids" => $group_guids, "emails" => $emails, "subscribers" => $subscribers, "members" => $members);
            // check for an uploaded CSV
            if (get_uploaded_file("csv")) {
                $tmp = newsletter_process_csv_upload($tmp);
            }
            // save results
            $entity->setRecipients($tmp);
            system_message(elgg_echo("newsletter:action:recipients:success"));
            elgg_clear_sticky_form("newsletter_recipients");
        } else {
            register_error(elgg_echo("ClassException:ClassnameNotClass", array($guid, elgg_echo("item:object:" . Newsletter::SUBTYPE))));
        }
    } else {
        register_error(elgg_echo("InvalidParameterException:NoEntityFound"));
    }
} else {
    register_error(elgg_echo("InvalidParameterException:MissingParameter"));
}
Exemple #18
0
        $site = elgg_get_site_entity();
        $options = ['limit' => false, 'callback' => 'group_tools_guid_only_callback'];
        $user_guids = $site->getMembers($options);
    }
    // add users directly?
    if (get_input('submit') == elgg_echo('group_tools:add_users')) {
        $adding = true;
    }
}
$group_guid = (int) get_input('group_guid');
$text = get_input('comment');
$emails = get_input('user_guid_email');
if (!empty($emails) && !is_array($emails)) {
    $emails = array($emails);
}
$csv = get_uploaded_file('csv');
if (get_input('resend') == 'yes') {
    $resend = true;
} else {
    $resend = false;
}
elgg_entity_gatekeeper($group_guid, 'group');
$group = get_entity($group_guid);
if (empty($user_guids) && empty($emails) && empty($csv)) {
    register_error(elgg_echo('error:missing_data'));
    forward(REFERER);
}
if (!$group->canEdit() && !group_tools_allow_members_invite($group)) {
    register_error(elgg_echo('actionunauthorized'));
    forward(REFERER);
}
Exemple #19
0
function file_get_uploaded()
{
    return get_uploaded_file($_FILES['thefile']['tmp_name']);
}
Exemple #20
0
function image_data($file, $category = '', $id = '', $uploaded = true)
{
    global $txpcfg, $extensions, $txp_user;
    extract($txpcfg);
    $name = $file['name'];
    $error = $file['error'];
    $file = $file['tmp_name'];
    if ($uploaded) {
        $file = get_uploaded_file($file);
    }
    list($w, $h, $extension) = getimagesize($file);
    if ($file !== false && @$extensions[$extension]) {
        $ext = $extensions[$extension];
        $name = substr($name, 0, strrpos($name, '.'));
        $name .= $ext;
        $name2db = doSlash($name);
        $q = "w        = '{$w}',\n\t\t\t\t h        = '{$h}',\n\t\t\t\t ext      = '{$ext}',\n\t\t\t\t name   = '{$name2db}',\n\t\t\t\t date   = now(),\n\t\t\t\t caption  = '',\n\t\t\t\t author   = '{$txp_user}'";
        if (empty($id)) {
            $q .= ", category = '{$category}'";
            $rs = safe_insert("txp_image", $q);
            $id = mysql_insert_id();
        } else {
            $id = doSlash($id);
            $rs = safe_update('txp_image', $q, "id = {$id}");
        }
        if (!$rs) {
            return gTxt('image_save_error');
        } else {
            $newpath = IMPATH . $id . $ext;
            if (shift_uploaded_file($file, $newpath) == false) {
                safe_delete("txp_image", "id='{$id}'");
                safe_alter("txp_image", "auto_increment={$id}");
                return $newpath . sp . gTxt('upload_dir_perms');
            } else {
                chmod($newpath, 0755);
                return array(messenger('image', $name, 'uploaded'), $id);
            }
        }
    } else {
        if ($file === false) {
            return upload_get_errormsg($error);
        } else {
            return gTxt('only_graphic_files_allowed');
        }
    }
}
     $filename = $file->getFilenameOnFilestore();
     if (file_exists($filename)) {
         unlink($filename);
     }
     // use same filename on the disk - ensures thumbnails are overwritten
     $filestorename = $file->getFilename();
     $filestorename = substr($filestorename, strlen($prefix));
 } else {
     $filestorename = strtolower(time() . $_FILES['upload']['name']);
 }
 $file->setFilename($prefix . $filestorename);
 $file->setMimeType($_FILES['upload']['type']);
 $file->originalfilename = $_FILES['upload']['name'];
 $file->simpletype = get_general_file_type($_FILES['upload']['type']);
 $file->open("write");
 $file->write(get_uploaded_file('upload'));
 $file->close();
 $guid = $file->save();
 // if image, we need to create thumbnails (this should be moved into a function)
 if ($guid && $file->simpletype == "image") {
     $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true);
     if ($thumbnail) {
         $thumb = new ElggFile();
         $thumb->setMimeType($_FILES['upload']['type']);
         $thumb->setFilename($prefix . "thumb" . $filestorename);
         $thumb->open("write");
         $thumb->write($thumbnail);
         $thumb->close();
         $file->thumbnail = $prefix . "thumb" . $filestorename;
         unset($thumbnail);
     }
Exemple #22
0
<?php

$menu_name = get_input('menu_name');
$contents = get_uploaded_file('import');
if (empty($contents)) {
    register_error(elgg_echo('menu_builder:actions:import:error:upload'));
    forward(REFERER);
}
$config = json_decode($contents, true);
if (!is_array($config) || empty($config)) {
    register_error(elgg_echo('menu_builder:actions:import:error:invalid:content'));
    forward(REFERER);
}
// assume we're good at this point, delete current menu
$menu = new \ColdTrick\MenuBuilder\Menu($menu_name);
$menu->setMenuConfig();
// removes the current config
foreach ($config as $item) {
    // convert old export to new format
    if (isset($item['guid'])) {
        $item['name'] = $item['guid'];
        unset($item['guid']);
    }
    if (isset($item['title'])) {
        $item['text'] = $item['title'];
        unset($item['title']);
    }
    if (isset($item['url'])) {
        $item['href'] = $item['url'];
        unset($item['url']);
    }
function create_file($container_guid, $title, $desc, $access_id, $guid, $tags, $new_file)
{
    // register_error("Creating file: " . $container_guid . ", vars: " . print_r(array($title, $desc, $access_id, $guid, $tags, $new_file), true));
    if ($new_file) {
        // must have a file if a new file upload
        if (empty($_FILES['upload']['name'])) {
            // cache information in session
            $_SESSION['uploadtitle'] = $title;
            $_SESSION['uploaddesc'] = $desc;
            $_SESSION['uploadtags'] = $tags;
            $_SESSION['uploadaccessid'] = $access_id;
            register_error(elgg_echo('file:nofile') . "no file new");
            forward($_SERVER['HTTP_REFERER']);
        }
        $file = new FilePluginFile();
        $file->subtype = "file";
        // if no title on new upload, grab filename
        if (empty($title)) {
            $title = $_FILES['upload']['name'];
        }
    } else {
        // load original file object
        $file = get_entity($guid);
        if (!$file) {
            register_error(elgg_echo('file:cannotload') . 'can"t load existing');
            forward($_SERVER['HTTP_REFERER']);
        }
        // user must be able to edit file
        if (!$file->canEdit()) {
            register_error(elgg_echo('file:noaccess') . 'no access to existing');
            forward($_SERVER['HTTP_REFERER']);
        }
    }
    $file->title = $title;
    $file->description = $desc;
    $file->access_id = $access_id;
    $file->container_guid = $container_guid;
    $tags = explode(",", $tags);
    $file->tags = $tags;
    // we have a file upload, so process it
    if (isset($_FILES['upload']['name']) && !empty($_FILES['upload']['name'])) {
        $prefix = "file/";
        // if previous file, delete it
        if ($new_file == false) {
            $filename = $file->getFilenameOnFilestore();
            if (file_exists($filename)) {
                unlink($filename);
            }
            // use same filename on the disk - ensures thumbnails are overwritten
            $filestorename = $file->getFilename();
            $filestorename = elgg_substr($filestorename, elgg_strlen($prefix));
        } else {
            $filestorename = elgg_strtolower(time() . $_FILES['upload']['name']);
        }
        $file->setFilename($prefix . $filestorename);
        $file->setMimeType($_FILES['upload']['type']);
        $file->originalfilename = $_FILES['upload']['name'];
        $file->simpletype = get_general_file_type($_FILES['upload']['type']);
        $file->open("write");
        $file->write(get_uploaded_file('upload'));
        $file->close();
        $guid = $file->save();
        // if image, we need to create thumbnails (this should be moved into a function)
        if ($guid && $file->simpletype == "image") {
            $thumbnail = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 60, 60, true);
            if ($thumbnail) {
                $thumb = new ElggFile();
                $thumb->setMimeType($_FILES['upload']['type']);
                $thumb->setFilename($prefix . "thumb" . $filestorename);
                $thumb->open("write");
                $thumb->write($thumbnail);
                $thumb->close();
                $file->thumbnail = $prefix . "thumb" . $filestorename;
                unset($thumbnail);
            }
            $thumbsmall = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 153, 153, true);
            if ($thumbsmall) {
                $thumb->setFilename($prefix . "smallthumb" . $filestorename);
                $thumb->open("write");
                $thumb->write($thumbsmall);
                $thumb->close();
                $file->smallthumb = $prefix . "smallthumb" . $filestorename;
                unset($thumbsmall);
            }
            $thumblarge = get_resized_image_from_existing_file($file->getFilenameOnFilestore(), 600, 600, false);
            if ($thumblarge) {
                $thumb->setFilename($prefix . "largethumb" . $filestorename);
                $thumb->open("write");
                $thumb->write($thumblarge);
                $thumb->close();
                $file->largethumb = $prefix . "largethumb" . $filestorename;
                unset($thumblarge);
            }
        }
    } else {
        // not saving a file but still need to save the entity to push attributes to database
        $file->save();
    }
    return array($file, $guid);
}
Exemple #24
0
function thumbnail_insert()
{
    global $txpcfg, $extensions, $txp_user, $img_dir, $path_to_site;
    extract($txpcfg);
    $id = assert_int(gps('id'));
    $author = fetch('author', 'txp_image', 'id', $id);
    if (!has_privs('image.edit') && !($author === $txp_user && has_privs('image.edit.own'))) {
        image_list(gTxt('restricted_area'));
        return;
    }
    $file = $_FILES['thefile']['tmp_name'];
    $name = $_FILES['thefile']['name'];
    $file = get_uploaded_file($file);
    if (empty($file)) {
        image_edit(array(upload_get_errormsg(UPLOAD_ERR_NO_FILE), E_ERROR), $id);
        return;
    }
    list($w, $h, $extension) = getimagesize($file);
    if ($file !== false && @$extensions[$extension]) {
        $ext = $extensions[$extension];
        $newpath = IMPATH . $id . 't' . $ext;
        if (shift_uploaded_file($file, $newpath) == false) {
            image_list(array($newpath . sp . gTxt('upload_dir_perms'), E_ERROR));
        } else {
            chmod($newpath, 0644);
            safe_update("txp_image", "thumbnail = 1, thumb_w = {$w}, thumb_h = {$h}, date = now()", "id = {$id}");
            $message = gTxt('image_uploaded', array('{name}' => $name));
            update_lastmod();
            image_edit($message, $id);
        }
    } else {
        if ($file === false) {
            image_list(array(upload_get_errormsg($_FILES['thefile']['error']), E_ERROR));
        } else {
            image_list(array(gTxt('only_graphic_files_allowed'), E_ERROR));
        }
    }
}
Exemple #25
0
$publication->access_id = $access;
$publication->title = $title;
if (!$publication->save()) {
    register_error(elgg_echo('publication:error'));
    forward(REFERER);
}
$publication->tags = $tags;
$publication->pubtype = $type;
// save custom data
foreach ($data as $key => $value) {
    $publication->{$key} = $value;
}
// trigger event to save other custom data
elgg_trigger_event('save:data', 'publications', $publication);
// files
$file_contents = get_uploaded_file('attachment');
if (!empty($file_contents)) {
    $fh = new ElggFile();
    $fh->owner_guid = $publication->getGUID();
    $file_name = $_FILES['attachment']['name'];
    $mime = $_FILES['attachment']['type'];
    $fh->setFilename($file_name);
    if ($fh->open('write')) {
        $fh->write($file_contents);
        $fh->close();
        $publication->attached_file = $file_name;
        $publication->attached_file_mime_type = $mime;
    }
}
$publication->save();
if ($new_entity) {
Exemple #26
0
 if (elgg_instanceof($group, "group") && $group->canEdit()) {
     $existing = false;
     if ($layout = group_custom_layout_get_layout($group)) {
         $existing = true;
     } else {
         $layout = new ElggObject();
         $layout->subtype = GROUP_CUSTOM_LAYOUT_SUBTYPE;
         $layout->owner_guid = $group->getGUID();
         $layout->container_guid = $group->getGUID();
         $layout->access_id = ACCESS_PUBLIC;
         $layout->save();
     }
     $enable_background = get_input("enable_background", "no");
     $layout->enable_background = $enable_background;
     if ($enable_background == "yes") {
         if ($file_contents = get_uploaded_file("backgroundFile")) {
             $background = $_FILES["backgroundFile"];
             if (stristr($background["type"], "image")) {
                 if (!is_dir($dataroot . "group_custom_layout/")) {
                     mkdir($dataroot . "group_custom_layout/");
                 }
                 if (!is_dir($dataroot . "group_custom_layout/backgrounds/")) {
                     mkdir($dataroot . "group_custom_layout/backgrounds/");
                 }
                 if (file_put_contents($dataroot . "group_custom_layout/backgrounds/" . $group->getGUID() . ".jpg", $file_contents)) {
                     system_message(elgg_echo("group_custom_layout:action:save:success:background"));
                 }
             } else {
                 register_error(elgg_echo("group_custom_layout:action:save:error:background"));
             }
         }
Exemple #27
0
<?php

/**
 * Profile Manager
 * 
 * Restore of profile fields backup
 * 
 * @package profile_manager
 * @author ColdTrick IT Solutions
 * @copyright Coldtrick IT Solutions 2009
 * @link http://www.coldtrick.com/
 */
action_gatekeeper();
admin_gatekeeper();
global $CONFIG;
if ($json = get_uploaded_file("restoreFile")) {
    if ($data = json_decode($json, true)) {
        $requestedfieldtype = get_input("fieldtype");
        $fieldtype = $data['info']['fieldtype'];
        $md5 = $data['info']['md5'];
        $fields = $data['fields'];
        // check if field data is corrupted
        if ($fieldtype && $md5 && $fields && md5(print_r($fields, true)) == $md5) {
            // check if selected file is same type as requested
            if ($requestedfieldtype == $fieldtype) {
                // remove existing fields
                if (delete_entities("object", $fieldtype)) {
                    // add new fields with configured metadata
                    foreach ($fields as $index => $field) {
                        // create new field
                        $object = new ElggObject();
Exemple #28
0
 function thumbnail_insert_post()
 {
     global $img_dir;
     $id = $this->psi('id');
     $file = $_FILES['thefile']['tmp_name'];
     $name = $_FILES['thefile']['name'];
     $file = get_uploaded_file($file);
     list(, , $extension) = @getimagesize($file);
     if ($file !== false && $this->extensions[$extension]) {
         $ext = $this->extensions[$extension];
         $newpath = IMPATH . $id . 't' . $ext;
         if (shift_uploaded_file($file, $newpath) == false) {
             image_list($newpath . sp . gTxt('upload_dir_perms'));
         } else {
             chmod($newpath, 0644);
             safe_update("txp_image", "thumbnail = 1", "id = {$id}");
             update_lastmod();
             $this->_message(gTxt('image_uploaded', array('{name}' => $name)));
             $this->_set_view('edit', $id);
         }
     } else {
         if ($file === false) {
             $this->_error(upload_get_errormsg($_FILES['thefile']['error']));
             $this->_set_view('edit', $id);
         } else {
             $this->_error(gTxt('only_graphic_files_allowed'));
             $this->_set_view('edit', $id);
         }
     }
 }
Exemple #29
0
        $site = elgg_get_site_entity();
        $options = array("limit" => false, "callback" => "group_tools_guid_only_callback");
        $user_guids = $site->getMembers($options);
    }
    // add users directly?
    if (get_input("submit") == elgg_echo("group_tools:add_users")) {
        $adding = true;
    }
}
$group_guid = (int) get_input("group_guid");
$text = get_input("comment");
$emails = get_input("user_guid_email");
if (!empty($emails) && !is_array($emails)) {
    $emails = array($emails);
}
$csv = get_uploaded_file("csv");
if (get_input("resend") == "yes") {
    $resend = true;
} else {
    $resend = false;
}
$group = get_entity($group_guid);
if ((!empty($user_guids) || !empty($emails) || !empty($csv)) && !empty($group)) {
    if ($group instanceof ElggGroup && ($group->canEdit() || group_tools_allow_members_invite($group))) {
        // show hidden (unvalidated) users
        $hidden = access_get_show_hidden_status();
        access_show_hidden_entities(true);
        // counters
        $already_invited = 0;
        $invited = 0;
        $member = 0;
Exemple #30
0
function profile_manager_profileupdate_user_event($event, $object_type, $user)
{
    if (!empty($user) && $user instanceof ElggUser) {
        // upload a file to your profile
        $accesslevel = get_input('accesslevel');
        if (!is_array($accesslevel)) {
            $accesslevel = array();
        }
        $options = array("type" => "object", "subtype" => CUSTOM_PROFILE_FIELDS_PROFILE_SUBTYPE, "limit" => false, "metadata_name_value_pairs" => array("name" => "metadata_type", "value" => "pm_file"));
        if ($configured_fields = elgg_get_entities_from_metadata($options)) {
            foreach ($configured_fields as $field) {
                // check for uploaded files
                $metadata_name = $field->metadata_name;
                $current_file_guid = $user->{$metadata_name};
                if (isset($accesslevel[$metadata_name])) {
                    $access_id = (int) $accesslevel[$metadata_name];
                } else {
                    // this should never be executed since the access level should always be set
                    $access_id = ACCESS_PRIVATE;
                }
                if (isset($_FILES[$metadata_name]) && $_FILES[$metadata_name]['error'] == 0) {
                    // uploaded file exists so, save it to an ElggFile object
                    // use current_file_guid to overwrite previously uploaded files
                    $filehandler = new ElggFile($current_file_guid);
                    $filehandler->owner_guid = $user->getGUID();
                    $filehandler->container_guid = $user->getGUID();
                    $filehandler->subtype = "file";
                    $filehandler->access_id = $access_id;
                    $filehandler->title = $field->getTitle();
                    $filehandler->setFilename("profile_manager/" . $_FILES[$metadata_name]["name"]);
                    $filehandler->setMimeType($_FILES[$metadata_name]["type"]);
                    $filehandler->open("write");
                    $filehandler->write(get_uploaded_file($metadata_name));
                    $filehandler->close();
                    if ($filehandler->save()) {
                        $filehandler->profile_manager_metadata_name = $metadata_name;
                        // used to retrieve user file when deleting
                        $filehandler->originalfilename = $_FILES[$metadata_name]["name"];
                        create_metadata($user->guid, $metadata_name, $filehandler->getGUID(), 'text', $user->guid, $access_id);
                    }
                } else {
                    // if file not uploaded should it be deleted???
                    if (empty($current_file_guid)) {
                        // find the previously uploaded file and if exists... delete it
                        $options = array("type" => "object", "subtype" => "file", "owner_guid" => $user->getGUID(), "limit" => 1, "metadata_name_value_pairs" => array("name" => "profile_manager_metadata_name", "value" => $metadata_name));
                        if ($files = elgg_get_entities_from_metadata($options)) {
                            $file = $files[0];
                            $file->delete();
                        }
                    } else {
                        if ($file = get_entity($current_file_guid)) {
                            // maybe we need to update the access id
                            $file->access_id = $access_id;
                            $file->save();
                        }
                    }
                }
            }
        }
        // update profile completeness
        profile_manager_profile_completeness($user);
    }
}