Esempio n. 1
0
 }
 // ---
 if (empty($Blog)) {
     $Messages->add(T_('No destination blog is selected.'), 'error');
     break;
 }
 //$Blog->disp('name');
 // Get default status (includes PERM CHECK):
 $item_status = $Blog->get_allowed_item_status();
 if (empty($item_status)) {
     $Messages->add(T_('Sorry, you have no permission to post into this blog.'), 'error');
     break;
 }
 //print_r($_POST);die();
 load_class('files/model/_filelist.class.php', 'FileList');
 $selected_Filelist = new Filelist($fm_FileRoot, false);
 $fm_selected = param("fm_selected", "array");
 //		print_r($fm_selected);
 foreach ($fm_selected as $l_source_path) {
     // echo '<br>'.$l_source_path;
     $selected_Filelist->add_by_subpath(urldecode($l_source_path), true);
 }
 // make sure we have loaded metas for all files in selection!
 $selected_Filelist->load_meta();
 // Ready to create post(s):
 load_class('items/model/_item.class.php', 'Item');
 $fileNum = 0;
 $cat_Array = param("category", "array");
 $title_Array = param("post_title", "array");
 while ($l_File =& $selected_Filelist->get_next()) {
     // Create a post:
Esempio n. 2
0
/**
 * Create links between users and image files from the users profile_pictures folder
 */
function create_profile_picture_links()
{
    global $DB;
    load_class('files/model/_filelist.class.php', 'Filelist');
    load_class('files/model/_fileroot.class.php', 'FileRoot');
    $path = 'profile_pictures';
    $FileRootCache =& get_FileRootCache();
    $UserCache =& get_UserCache();
    // SQL query to get all users and limit by page below
    $users_SQL = new SQL();
    $users_SQL->SELECT('*');
    $users_SQL->FROM('T_users');
    $users_SQL->ORDER_BY('user_ID');
    $page = 0;
    $page_size = 100;
    while (count($UserCache->cache) > 0 || $page == 0) {
        // Load users by 100 at one time to avoid errors about memory exhausting
        $users_SQL->LIMIT($page * $page_size . ', ' . $page_size);
        $UserCache->clear();
        $UserCache->load_by_sql($users_SQL);
        while (($iterator_User =& $UserCache->get_next()) != NULL) {
            // Iterate through UserCache)
            $FileRootCache->clear();
            $user_FileRoot =& $FileRootCache->get_by_type_and_ID('user', $iterator_User->ID);
            if (!$user_FileRoot) {
                // User FileRoot doesn't exist
                continue;
            }
            $ads_list_path = get_canonical_path($user_FileRoot->ads_path . $path);
            // Previously uploaded avatars
            if (!is_dir($ads_list_path)) {
                // profile_picture folder doesn't exists in the user root dir
                continue;
            }
            $user_avatar_Filelist = new Filelist($user_FileRoot, $ads_list_path);
            $user_avatar_Filelist->load();
            if ($user_avatar_Filelist->count() > 0) {
                // profile_pictures folder is not empty
                $info_content = '';
                $LinkOwner = new LinkUser($iterator_User);
                while ($lFile =& $user_avatar_Filelist->get_next()) {
                    // Loop through all Files:
                    $fileName = $lFile->get_name();
                    if (process_filename($fileName)) {
                        // The file has invalid file name, don't create in the database
                        // TODO: asimo> we should collect each invalid file name here, and send an email to the admin
                        continue;
                    }
                    $lFile->load_meta(true);
                    if ($lFile->is_image()) {
                        $lFile->link_to_Object($LinkOwner);
                    }
                }
            }
        }
        // Increase page number to get next portion of users
        $page++;
    }
    // Clear cache data
    $UserCache->clear();
    $FileRootCache->clear();
}
Esempio n. 3
0
                     $Messages->add(sprintf(T_('&laquo;%s&raquo; has been attached.'), $l_File->dget('name')), 'success');
                 } while ($l_File =& $selected_Filelist->get_next());
                 $DB->commit();
             } else {
                 $Messages->add(T_('Couldn\'t create the new post'), 'error');
                 $DB->rollback();
             }
             header_redirect($dispatcher . '?ctrl=items&action=edit&p=' . $edited_Item->ID);
             // Will save $Messages
             break;
     }
     // Note: we should have EXITED here. In case we don't (error, or sth...)
     // Reset stuff so it doesn't interfere with upcomming display
     unset($edited_Item);
     unset($edited_Link);
     $selected_Filelist = new Filelist($fm_Filelist->get_FileRoot(), false);
     break;
 case 'edit_file':
     // TODO: We don't need the Filelist, move UP!
     // Edit Text File
     // Check that this action request is not a CSRF hacked request:
     $Session->assert_received_crumb('file');
     // Check permission!
     $current_User->check_perm('files', 'edit_allowed', true, $blog ? $blog : NULL);
     // Get the file we want to edit:
     $edited_File =& $selected_Filelist->get_by_idx(0);
     // Check that the file is editable:
     if (!$edited_File->is_editable($current_User->check_perm('files', 'all'))) {
         $Messages->add(sprintf(T_('You are not allowed to edit &laquo;%s&raquo;.'), $edited_File->dget('name')), 'error');
         // Leave special display mode:
         $action = 'list';
Esempio n. 4
0
 /**
  * Rename the file in its current directory on disk.
  *
  * Also update meta data in DB.
  *
  * @access public
  * @param string new name (without path!)
  * @return boolean true on success, false on failure
  */
 function rename_to($newname)
 {
     $old_file_name = $this->get_name();
     // rename() will fail if newname already exists on windows
     // if it doesn't work that way on linux we need the extra check below
     // but then we have an integrity issue!! :(
     if (file_exists($this->_dir . $newname)) {
         syslog_insert(sprintf('File %s could not be renamed to %s', '<b>' . $old_file_name . '</b>', '<b>' . $newname . '</b>'), 'info', 'file', $this->ID);
         return false;
     }
     global $DB;
     $DB->begin();
     $oldname = $this->get_name();
     if ($this->is_dir()) {
         // modify folder content file paths in db
         $rel_dir = dirname($this->_rdfp_rel_path) . '/';
         if ($rel_dir == './') {
             $rel_dir = '';
         }
         $rel_dir = $rel_dir . $newname . '/';
         $full_dir = $this->_dir . $newname . '/';
         $temp_Filelist = new Filelist($this->_FileRoot, $this->_adfp_full_path);
         $temp_Filelist->load();
         while ($temp_File = $temp_Filelist->get_next()) {
             $temp_File->modify_path($rel_dir, $full_dir);
         }
     }
     if (!@rename($this->_adfp_full_path, $this->_dir . $newname)) {
         // Rename will fail if $newname already exists (at least on windows)
         syslog_insert(sprintf('File %s could not be renamed to %s', '<b>' . $old_file_name . '</b>', '<b>' . $newname . '</b>'), 'info', 'file', $this->ID);
         $DB->rollback();
         return false;
     }
     // Delete thumb caches for old name:
     // Note: new name = new usage : there is a fair chance we won't need the same cache sizes in the new loc.
     $this->rm_cache();
     // Get Meta data (before we change name) (we may need to update it later):
     $this->load_meta();
     $this->_name = $newname;
     $this->Filetype = NULL;
     // depends on name
     $rel_dir = dirname($this->_rdfp_rel_path) . '/';
     if ($rel_dir == './') {
         $rel_dir = '';
     }
     $this->_rdfp_rel_path = $rel_dir . $this->_name;
     $this->_adfp_full_path = $this->_dir . $this->_name;
     $this->_md5ID = md5($this->_adfp_full_path);
     if ($this->meta == 'loaded') {
         // We have meta data, we need to deal with it:
         // unchanged : $this->set( 'root_type', $this->_FileRoot->type );
         // unchanged : $this->set( 'root_ID', $this->_FileRoot->in_type_ID );
         $this->set('path', $this->_rdfp_rel_path);
         // Record to DB:
         if (!$this->dbupdate()) {
             // Update failed, try to rollback the rename on disk:
             if (!@rename($this->_adfp_full_path, $this->_dir . $oldname)) {
                 // rename failed
                 $DB->rollback();
                 syslog_insert(sprintf('File %s could not be renamed to %s', '<b>' . $old_file_name . '</b>', '<b>' . $newname . '</b>'), 'info', 'file', $this->ID);
                 return false;
             }
             // Maybe needs a specific error message here, the db and the disk is out of sync
             syslog_insert(sprintf('File %s could not be renamed to %s', '<b>' . $old_file_name . '</b>', '<b>' . $newname . '</b>'), 'info', 'file', $this->ID);
             return false;
         }
     } else {
         // There might be some old meta data to *recycle* in the DB...
         // This can happen if there has been a file in the same location in the past and if that file
         // has been manually deleted or moved since then. When the new file arrives here, we'll recover
         // the zombie meta data and we don't reset it on purpose. Actually, we consider that the meta data
         // has been *accidentaly* lost and that the user is attempting to recover it by putting back the
         // file where it was before. Of course the logical way would be to put back the file manually, but
         // experience proves that users are inconsistent!
         $this->load_meta();
     }
     $DB->commit();
     syslog_insert(sprintf('File %s was renamed to %s', '<b>' . $old_file_name . '</b>', '<b>' . $newname . '</b>'), 'info', 'file', $this->ID);
     return true;
 }
Esempio n. 5
0
            fwrite($rsc_handle, $file_content);
            fclose($rsc_handle);
            $Messages->add(sprintf(T_('The file &laquo;%s&raquo; has been updated.'), $edit_File->dget('name')), 'success');
        } else {
            $Messages->add(sprintf(T_('The file &laquo;%s&raquo; could not be updated.'), $edit_File->dget('name')), 'error');
        }
        header_redirect(regenerate_url('', '', '', '&'));
        // $action = 'list';
        break;
}
// Do we want to display the directory tree next to the files table
$UserSettings->param_Request('fm_hide_dirtree', 'fm_hide_dirtree', 'integer', 0, true);
/**
 * Filelist
 */
$fm_Filelist = new Filelist($fm_FileRoot, $ads_list_path);
$Debuglog->add('FM _rds_list_path: ' . var_export($fm_Filelist->_rds_list_path, true), 'files');
param('fm_filter', '', NULL, true);
param('fm_filter_regex', 'integer', 0, true);
$fm_Filelist->set_Filter($fm_filter, $fm_filter_regex);
if ($UserSettings->param_Request('fm_dirsnotattop', 'fm_dirsnotattop', 'integer', 0)) {
    $fm_Filelist->_dirs_not_at_top = true;
}
if ($UserSettings->param_Request('fm_recursivedirsize', 'fm_recursivedirsize', 'integer', 0)) {
    $fm_Filelist->_use_recursive_dirsize = true;
}
if ($UserSettings->param_Request('fm_showhidden', 'fm_showhidden', 'integer', 0)) {
    $fm_Filelist->_show_hidden_files = true;
}
if (param('fm_flatmode', '', NULL, true)) {
    $fm_Filelist->flatmode = true;
Esempio n. 6
0
                     $Messages->add(sprintf(T_('&laquo;%s&raquo; has been attached.'), $l_File->dget('name')), 'success');
                 } while ($l_File =& $selected_Filelist->get_next());
                 $DB->commit();
             } else {
                 $Messages->add(T_('Couldn\'t create the new post'), 'error');
                 $DB->rollback();
             }
             header_redirect($dispatcher . '?ctrl=items&action=edit&p=' . $edited_Item->ID);
             // Will save $Messages
             break;
     }
     // Note: we should have EXITED here. In case we don't (error, or sth...)
     // Reset stuff so it doesn't interfere with upcomming display
     unset($edited_Item);
     unset($edited_Link);
     $selected_Filelist = new Filelist($fm_Filelist->get_FileRoot(), false);
     break;
 case 'edit_file':
     // TODO: We don't need the Filelist, move UP!
     // Edit Text File
     // Check that this action request is not a CSRF hacked request:
     $Session->assert_received_crumb('file');
     // Check permission!
     $current_User->check_perm('files', 'edit', true, $blog ? $blog : NULL);
     // Get the file we want to edit:
     $edited_File =& $selected_Filelist->get_by_idx(0);
     // Check that the file is editable:
     if (!$edited_File->is_editable($current_User->check_perm('files', 'all'))) {
         $Messages->add(sprintf(T_('You are not allowed to edit &laquo;%s&raquo;.'), $edited_File->dget('name')), 'error');
         // Leave special display mode:
         $action = 'list';