? pu-coder.patch
Index: private_upload.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/private_upload/private_upload.install,v
retrieving revision 1.1.2.1
diff -u -p -r1.1.2.1 private_upload.install
--- private_upload.install 29 Nov 2009 17:14:25 -0000 1.1.2.1
+++ private_upload.install 29 Nov 2009 18:11:03 -0000
@@ -2,11 +2,24 @@
// $Id: private_upload.install,v 1.1.2.1 2009/11/29 17:14:25 lynn Exp $
/**
-* Implementation of hook_install().
-*
-* Ensures private_upload runs after module upload
-*/
+ * @file
+ * Install, update and uninstall functions for the private_upload module.
+ */
+
+/**
+ * Implementation of hook_install().
+ *
+ * Ensures private_upload runs after module upload
+ */
function private_upload_install() {
$weight = (int)db_result(db_query("SELECT weight FROM {system} WHERE name = 'upload'"));
db_query("UPDATE {system} SET weight = %d WHERE name = 'private_upload'", $weight+1);
+}
+
+/**
+ * Implementation of hook_uninstall().
+ */
+function private_upload_uninstall() {
+ variable_del('private_upload_path');
+ variable_del('private_upload_default');
}
\ No newline at end of file
Index: private_upload.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/private_upload/private_upload.module,v
retrieving revision 1.13.2.10
diff -u -p -r1.13.2.10 private_upload.module
--- private_upload.module 29 Nov 2009 17:31:06 -0000 1.13.2.10
+++ private_upload.module 29 Nov 2009 18:11:03 -0000
@@ -103,7 +103,7 @@ function _private_upload_requirements($p
$t = get_t(); // Ensure translations don't break at install time.
$requirements = array();
- if(module_exists('uploadpath')) {
+ if (module_exists('uploadpath')) {
$requirements['private_upload_conflict'] = array(
'title' => t('Private Upload'),
'severity' => REQUIREMENT_ERROR,
@@ -121,7 +121,7 @@ function _private_upload_requirements($p
'title' => t('Private Upload'),
'severity' => REQUIREMENT_WARNING,
'value' => $t('Private Downloads directory is not writable'),
- 'description' => $t('Please make sure directory !dir exists and is writable.', array('!dir'=>$private_path)),
+ 'description' => $t('Please make sure directory !dir exists and is writable.', array('!dir' => $private_path)),
);
$status[] = '
'. $requirements['private_upload_writable']['description'] .'
';
}
@@ -130,7 +130,7 @@ function _private_upload_requirements($p
}
// Write out a .htaccess file if one doesn't already exist in the private folder.
- if (!file_exists($private_path.'/.htaccess')) {
+ if (!file_exists($private_path .'/.htaccess')) {
_private_upload_add_htacess();
}
else {
@@ -138,7 +138,7 @@ function _private_upload_requirements($p
}
// Write a test file to the private folder to test public access.
- $test_file = $private_path.'/privacy_test.txt';
+ $test_file = $private_path .'/privacy_test.txt';
if (!file_exists($test_file)) {
$test_path = file_create_path($test_file);
file_save_data( "This is just a test.", $test_path, FILE_EXISTS_REPLACE );
@@ -154,11 +154,11 @@ function _private_upload_requirements($p
'value' => $t('Private directory is publically accessable!'),
'description' => $t('Very bad! Your private files are not private!'),
);
- $status[] = ''. $requirements['private_upload_readable']['description']. '
';
+ $status[] = ''. $requirements['private_upload_readable']['description'] . '
';
}
else {
- $secure = true; // good can't read files in private folder
- $status[] = ''. $t("Your private folder is not accessable. Great!"). "
";
+ $secure = TRUE; // good can't read files in private folder
+ $status[] = ''. $t("Your private folder is not accessable. Great!") .'
';
}
}
else { // unable to write the test file
@@ -181,17 +181,16 @@ function _private_upload_requirements($p
$status[] = ''. $requirements['private_upload_method']['description'] .'
';
}
else {
- $status[] = ''. $t("File download method is set to public. Great."). '
';
+ $status[] = ''. $t("File download method is set to public. Great.") .'
';
}
$old_file_count = db_result( db_query("SELECT COUNT(fid) FROM {files} WHERE filepath REGEXP '^private_upload'") );
- if( $old_file_count ) {
+ if ($old_file_count) {
$requirements['private_upload_old'] = array(
'title' => t('Private Upload'),
'severity' => REQUIREMENT_WARNING,
'value' => $t('Private Downloads'),
- 'description' => $t('You have !count old style file(s) listed in the database. ', array('!count'=>$old_file_count) ).
- l( 'Click here to migrate', 'admin/private_upload/migrate_old'),
+ 'description' => $t('You have !count old style file(s) listed in the database. ', array('!count' => $old_file_count) ) . l('Click here to migrate', 'admin/private_upload/migrate_old'),
);
$status[] = ''. $requirements['private_upload_old']['description'] .'
';
}
@@ -199,9 +198,9 @@ function _private_upload_requirements($p
$status[] = ''. $t("There are no old-style private files hanging around. Great.") . '
';
}
- if( count($requirements) ) { // failed
+ if (count($requirements)) { // failed
if ($phase == 'runtime') {
- foreach( $requirements as $key => $req ) {
+ foreach ($requirements as $key => $req) {
if ($requirements[$key]['severity'] == REQUIREMENT_WARNING) {
$requirements[$key]['severity'] = REQUIREMENT_ERROR; // bump up to error if after install
}
@@ -235,11 +234,11 @@ function _private_upload_requirements($p
*/
function private_upload_file_download($file) {
$private_dir = variable_get('private_upload_path', 'private');
- if(_private_upload_starts_with($file, $private_dir)) {
+ if (_private_upload_starts_with($file, $private_dir)) {
$filepath = file_create_path($file);
$result = db_query("SELECT DISTINCT(u.nid) FROM {upload} u INNER JOIN {files} f ON u.fid = f.fid ".
"WHERE f.filepath = '%s'", $filepath);
- while($row = db_fetch_array($result)) {
+ while ($row = db_fetch_array($result)) {
$node = node_load($row['nid']);
if (node_access('view', $node)) {
return; // Access is ok as far as we are concerned.
@@ -261,34 +260,34 @@ function private_upload_nodeapi(&$node,
// *** Move a file from public to private, or vise-verse
// ******************************************************
if (user_access('upload files')) {
- if(is_array($node->files)) {
+ if (is_array($node->files)) {
foreach ($node->files as $fid => $file) {
$file = (object)$file; // Convert file to object for compatibility
$fid = $file->fid; // for the cases where we have temp fid for uploaded files
- $success = false;
+ $success = FALSE;
$filepath = $file->filepath; // need copy if file_move fails.
// save original name
$filepath_orig = $filepath;
$public = file_directory_path();
$private_path = _private_upload_path(); // actual path of private files
$file_is_private = _private_upload_is_file_private($filepath);
- if( $file->private && !$file_is_private ) {
+ if ($file->private && !$file_is_private) {
// private flag is set, but file NOT yet listed as being in private repo,
// so try and move it from public area to private repo
- if( file_move($filepath, $private_path, FILE_EXISTS_RENAME) ) {
+ if (file_move($filepath, $private_path, FILE_EXISTS_RENAME)) {
// check whether the file was renamed
if ($filepath_orig != $filepath) {
// update the filename in the object if so
$file->filename = basename($filepath);
$file->filepath = $filepath;
}
- $success = true;
+ $success = TRUE;
}
else {
drupal_set_message( "Could not move the file ($file->filepath) to the private directory ($private_path).", 'error' );
}
}
- else if (!$file->private && $file_is_private) {
+ elseif (!$file->private && $file_is_private) {
// private flag is false, but file IS g in private repo
// so try and move it from private repo to public area
if (file_move($filepath, $public, FILE_EXISTS_RENAME)) {
@@ -299,17 +298,17 @@ function private_upload_nodeapi(&$node,
// update the filename in the object if so
$file->filename = basename($filepath);
}
- $success = true;
+ $success = TRUE;
}
else {
drupal_set_message( "Could not move the file ($file->filepath) to the public directory ($public).", 'error' );
}
}
- if( $success ) { // we were able to move the file, so update filepath in db.
+ if ($success) { // we were able to move the file, so update filepath in db.
_private_upload_update_filepath($file);
$row_count = db_affected_rows();
- if( $row_count != 1 ) {
+ if ($row_count != 1) {
drupal_set_message( "Error: Unable to make uploaded file private! (". $row_count .")", 'error' );
}
}
@@ -364,7 +363,7 @@ function private_upload_form_alter(&$for
'#type' => 'checkbox',
'#default_value' => $default_value,
);
- if( !realpath($file->filepath) ) {
+ if (!realpath($file->filepath)) {
$form['attachments']['wrapper']['files'][$fid]['msg'] = array(
'#value' => ' *Missing*',
);
@@ -384,21 +383,21 @@ function private_upload_form_alter(&$for
}
}
}
- elseif( $form_id == 'upload_js' ) {
+ elseif ($form_id == 'upload_js') {
$form['files']['#theme'] = 'private_upload_form';
// $form['#submit'][] = 'private_upload_form_submit'; // ???
foreach ($form['files'] as $fid => $file) {
- if( !_private_upload_starts_with( $fid, '#' ) ) { // Ignore the properties.
- if( $_POST['files'][$fid] ) {
+ if (!_private_upload_starts_with($fid, '#')) { // Ignore the properties.
+ if ($_POST['files'][$fid]) {
$private = $_POST['files'][$fid]['private'];
// While I am here lets fix the problem with delete and list as well.
// Q: Do I still need this fix in D6?
$form['files'][$fid]['list']['#default_value'] = $_POST['files'][$fid]['list'];
$form['files'][$fid]['remove']['#default_value'] = $_POST['files'][$fid]['remove'];
}
- else { // File is a newly uploaded so set private to default.
- $private = ( variable_get( 'private_upload_default', 'private' ) == 'private' );
+ else { // File is newly uploaded so set private to default.
+ $private = (variable_get('private_upload_default', 'private') == 'private');
}
$form['files'][$fid]['private'] = array(
@@ -422,8 +421,8 @@ function private_upload_form_validate($f
$upload_weight = (int)db_result(db_query("SELECT weight FROM {system} WHERE name = 'upload'"));
$private_weight = (int)db_result(db_query("SELECT weight FROM {system} WHERE name = 'private_upload'"));
if ($private_weight <= $upload_weight) {
- $new_weight = $upload_weight+1;
- drupal_set_message( t("Adjusting private_upload's weight to "). $new_weight, 'warning');
+ $new_weight = $upload_weight + 1;
+ drupal_set_message(t("Adjusting private_upload's weight to !new_weight", array('!new_weight' => $new_weight)), 'warning');
db_query("UPDATE {system} SET weight = '%d' WHERE name = 'private_upload'", $new_weight);
}
else {
@@ -452,7 +451,7 @@ function private_upload_form_submit($for
$private = $_POST['files'][$fid]['private'];
}
else {
- $private = (variable_get( 'private_upload_default', 'private' ) == 'private'); // Sumbit before Attach
+ $private = (variable_get('private_upload_default', 'private') == 'private'); // Sumbit before Attach
}
$form_state['values']['files'][$fid]['private'] = $private;
}
@@ -489,7 +488,7 @@ function private_upload_admin() {
'#type' => 'select',
'#title' => t('Default Upload Privacy Setting'),
'#default_value' => variable_get('private_upload_default', 'private' ),
- '#options' => array ( 'private' => 'private', 'public' => 'public' ),
+ '#options' => array('private' => 'private', 'public' => 'public'),
'#description' => t('Are uploads public or private by default?'),
);
@@ -513,19 +512,17 @@ function private_upload_admin() {
// loop through all the file in private folder & collect stats.
$private_file_count = 0;
$d = opendir( $private_path );
- if( $d ) {
- while( $f = readdir($d) ) {
- if( $f != '.' && $f != '..' && $f != '.htaccess' && $f != 'privacy_test.txt') {
+ if ($d) {
+ while ($f = readdir($d)) {
+ if ($f != '.' && $f != '..' && $f != '.htaccess' && $f != 'privacy_test.txt') {
$private_file_count++;
}
}
closedir( $d );
$db_private_file_count = db_result( db_query("SELECT COUNT(fid) FROM {files} WHERE filepath REGEXP '^%s'", $private_path) );
- $output = t( "There are '!fs_count' files in the private folder, ".
- " and the DB thinks there are '!db_count' private files.",
- array( '!fs_count'=>$private_file_count, '!db_count'=>$db_private_file_count) );
- if( $db_private_file_count != $private_file_count ) {
+ $output = t("There are !fs_count files in the private folder, and the DB thinks there are !db_count private files.", array('!fs_count' => $private_file_count, '!db_count' => $db_private_file_count));
+ if ($db_private_file_count != $private_file_count) {
$status[] = ''. $output .'
';
}
else {
@@ -533,19 +530,15 @@ function private_upload_admin() {
}
}
else { // unable to open folder!
- $status[] = ''.
- t("'!private_path' is not a valid directory (!is).",
- array('!private_path'=>$private_path, '!is'=>is_dir($private_path))) .
- '
';
+ $status[] = ''. t("!private_path is not a valid directory (!is).", array('!private_path' => $private_path, '!is' => is_dir($private_path))) .'
';
}
// check for public files attached to private nodes.
$count = db_result( db_query('SELECT COUNT(DISTINCT(f.fid)) '.
'FROM {files} f INNER JOIN {upload} u ON f.fid=u.fid INNER JOIN {node_access} na ON u.nid=na.nid '.
'WHERE na.gid != 0 AND f.filepath NOT REGEXP "^%s"', $private_path));
- if( $count ) {
- $status[] = t("There are !count public files attached to private nodes. ", array('!count'=>$count)).
- l( 'Click here to make them all private.', 'admin/private_upload/migrate_private');
+ if ($count) {
+ $status[] = t("There are !count public files attached to private nodes. ", array('!count' => $count)) . l( 'Click here to make them all private.', 'admin/private_upload/migrate_private');
}
else {
$status[] = t("There are no public files attached to private nodes. Great.");
@@ -553,11 +546,10 @@ function private_upload_admin() {
$result = db_fetch_array( db_query('SELECT COUNT(f.fid) as fids, COUNT(DISTINCT(u.nid)) as nids '.
'FROM {files} f INNER JOIN {upload} u ON f.fid = u.fid') );
- $status[] = t("Uploaded files in db: '!files' files attached to '!nodes' nodes.",
- array( '!files'=>$result['fids'], '!nodes'=>$result['nids']));
+ $status[] = t("Uploaded files in db: !files files attached to !nodes nodes.", array('!files' => $result['fids'], '!nodes' => $result['nids']));
- $form['status']['info'] = array (
- '#value' => '- ' . implode( '
- ', $status ) . '
',
+ $form['status']['info'] = array(
+ '#value' => '- ' . implode('
- ', $status) . '
',
);
return system_settings_form($form);
@@ -572,7 +564,7 @@ function private_upload_admin_validate($
// FILE_CREATE_DIRECTORY and FILE_MODIFY_PERMISSIONS
if (!file_check_directory($private_upload_path, TRUE, 'private_upload_path')) {
- return false;
+ return FALSE;
}
}
@@ -600,11 +592,11 @@ function _private_upload_migrate_private
$result = db_query('SELECT f.* FROM {files} f, {node_access} na '.
' WHERE f.nid = na.nid AND na.gid != 0 AND f.filepath NOT REGEXP "^%s" '.
' GROUP BY f.fid', $private_path );
- while( $file = db_fetch_object($result) ) {
+ while ($file = db_fetch_object($result)) {
// file is attached to a private node, but is a public file, so move it.
$filepath = $file->filepath;
$filepath_orig = $filepath;
- if( file_move($filepath, $private_path, FILE_EXISTS_RENAME) ) {
+ if (file_move($filepath, $private_path, FILE_EXISTS_RENAME)) {
// update the file path
$file->filepath = $filepath;
// check whether the file was renamed
@@ -612,12 +604,11 @@ function _private_upload_migrate_private
// update the filename in the object if so
$file->filename = basename($filepath);
}
- $output .= t("Making !filename private", array('!filename'=>$file->filename)). "
";
+ $output .= t("Making !filename private", array('!filename' => $file->filename)) . "
";
_private_upload_update_filepath($file);
}
else {
- $output .= t("Could not move %filepath to private directory (fid: %fid attached to node: nid).",
- array('%filepath'=>$file->filepath, '%fid'=>$file->fid, 'nid'=>$file->nid)). "
";
+ $output .= t("Could not move %filepath to private directory (fid: %fid attached to node: !nid).", array('%filepath' => $file->filepath, '%fid' => $file->fid, '!nid' => $file->nid)) . "
";
}
}
return $output;
@@ -686,7 +677,7 @@ function theme_private_upload_form(&$for
function theme_private_upload_attachments($files) {
$header = array(t('Attachment'), t('Size'));
$rows = array();
- if(is_array($files)) {
+ if (is_array($files)) {
foreach ($files as $file) {
$file = (object)$file;
if ($file->list && !$file->remove) {
@@ -719,7 +710,7 @@ function _private_upload_path() {
* @return bool: does str1 start with str2
*/
function _private_upload_starts_with( $str, $start ) {
- if( count($str) == 0 ) return false; // avoid false positive.
+ if (count($str) == 0) return FALSE; // avoid false positive.
return strstr($str, $start) == $str;
}
@@ -785,32 +776,32 @@ function _private_upload_is_url_protecte
$socket_open_timeout = 30;
$read_data_timeout = 10;
$max_chunk = 1024;
- $status_codes = array("200","302"); // see function header for code details
+ $status_codes = array("200", "302"); // see function header for code details
// parse and open a socket to the requested resource
$url_info=parse_url($url);
$port=isset($url_info['port']) ? $url_info['port'] : 80;
$fp=fsockopen($url_info['host'], $port, $errno, $errstr, $socket_open_timeout);
- if(!$fp) {
- drupal_set_message( t("Unable to test file access: "). $errstr, 'error' );
+ if (!$fp) {
+ drupal_set_message( t("Unable to test file access: !errstr", array('!errstr' => $errstr)), 'error' );
return FALSE; // Failure - file status is unknown.
}
stream_set_timeout($fp, $read_data_timeout);
// Request resource headers
- $head = "HEAD ".@$url_info['path']."?".@$url_info['query'];
- $head .= " HTTP/1.0\r\nHost: ".@$url_info['host']."\r\n\r\n";
+ $head = "HEAD ". @$url_info['path'] ."?". @$url_info['query'];
+ $head .= " HTTP/1.0\r\nHost: ". @$url_info['host'] ."\r\n\r\n";
fputs($fp, $head);
// Read resource headers
- if($header=trim(fgets($fp, $max_chunk))) {
- $header_array = explode(': ',$header);
+ if ($header=trim(fgets($fp, $max_chunk))) {
+ $header_array = explode(': ', $header);
$header_type = $header_array[0];
foreach ($status_codes as $status_code) {
- if( strstr($header_type, $status_code)) {
+ if (strstr($header_type, $status_code)) {
fclose($fp);
return FALSE; // Falure - file is publically accessable.
}
@@ -844,7 +835,7 @@ function private_upload_views_tables_alt
function private_upload_views_handler_filepath($fieldinfo, $fielddata, $value, $data) {
if ($fielddata['options'] == 'usable') {
- if(_private_upload_is_file_private($value)) {
+ if (_private_upload_is_file_private($value)) {
$value = _private_upload_replace_start_with($value, _private_upload_path(), 'system/files' );
}
}
@@ -854,7 +845,7 @@ function private_upload_views_handler_fi
/**
* Display all files attached to a given node.
*/
-function private_upload_views_handler_all_files($fieldinfo, $fielddata, $value, $data, $listed = false) {
+function private_upload_views_handler_all_files($fieldinfo, $fielddata, $value, $data, $listed = FALSE) {
if ($listed) {
$and = " AND list = 1";
}
@@ -866,12 +857,14 @@ function private_upload_views_handler_al
// link/nolink use file filename; linkdesc/nolinkdesc use file description
if ($fielddata['options'] == 'link' || $fielddata['options'] == 'nolink') {
$display_string = $file->filename;
- } else {
+ }
+ else {
$display_string = $file->description;
}
if ($fielddata['options'] == 'nolink' || $fielddata['options'] == 'nolinkdesc') {
$links[] = check_plain($display_string);
- } else {
+ }
+ else {
// $links[] = l($display_string, check_url(file_create_url($file->filepath))); // original
$links[] = l($display_string, _private_upload_create_url($file)); // the change
}