...

View Full Version : Creating displayed text to show returns in text



DJ Hands3
03-06-2009, 06:14 PM
On the display of file descriptions on my pages the information the user has submitted should convert line breaks in to <br> but it just outputs rn rather than converting the text, iv looked through the .php coding on the relevant pages and the best I could find is this to see if theres the correct function,



// Are we converting new lines to <br />?
if (intval($file['convert_newlines']) === 1)
{
$file['description_small'] = nl2br($file['description_small']);
$file['description_big'] = nl2br($file['description_big']);
}


I'm sure the above is where the process takes place but only displays rn rather than corrcting the displayed text. Any reason why this happens?:confused:

_Aerospace_Eng_
03-06-2009, 07:57 PM
What do you do to the data before it goes into the database? Do you change it in any way?

DJ Hands3
03-07-2009, 12:21 PM
This is the page that deals with the users submission form to get all the info to the database.



<?php

/**********************************
* Olate Download 3.4.1
* http://www.olate.co.uk/od3
**********************************
* Copyright Olate Ltd 2005
*
* @author $Author: dsalisbury $ (Olate Ltd)
* @version $Revision: 259 $
* @package od
*
* Updated: $Date: 2006-10-10 20:27:12 +0100 (Tue, 10 Oct 2006) $
*/

// Initialisation
require('./includes/init.php');

// Show categories
$fcm->show_cats();

validate_types($input, array('name' => 'STR', 'description_small' => 'STR',
'description_big' => 'STR', 'category' => 'INT',
'downloads' => 'INT', 'size' => 'INT',
'agreement' => 'INT', 'password' => 'STR', 'upload' => 'INT',
'convert_newlines' => 'INT', 'filesize_format' => 'STR'));

if ($site_config['enable_useruploads'] == 1)
{
// Upload file
if (isset($_FILES['uploadfile']))
{
$ext = strrchr($_FILES['uploadfile']['name'], '.');
$allowed_ext = explode(',', $site_config['uploads_allowed_ext']);

// It's like finding a needle in a haystack...
if (in_array($ext, $allowed_ext))
{
$time = time();

if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], './uploads/upload-'.$time.'-'.basename($_FILES['uploadfile']['name'])))
{
// Get various variables
if (!empty($input['password']))
{
$password = md5($input['password']);
}
else
{
$password = '';
}

if (!empty($input['convert_newlines']) && $input['convert_newlines'] === 1)
{
$convert_newlines = $input['convert_newlines'];
}
else
{
$convert_newlines = 0;
}

// Gigabyte?
if ($input['filesize_format'] == 'gb')
{
$filesize = $input['size'] * pow(1024,3);
}
// Megabyte?
elseif ($input['filesize_format'] == 'mb')
{
$filesize = $input['size'] * pow(1024,2);
}
// Kilobyte?
elseif ($input['filesize_format'] == 'kb')
{
$filesize = $input['size'] * 1024;
}
// Byte, or otherwise
else
{
$filesize = $input['size'];
}

$dbim->query('INSERT INTO '.DB_PREFIX.'files
SET category_id = "'.$input['category'].'",
name = "'.$input['name'].'",
description_small = "'.$input['description_small'].'",
description_big = "'.$input['description_big'].'",
downloads = "'.$input['downloads'].'",
size = "'.$input['size'].'",
date = "'.$time.'",
agreement_id = "'.$input['agreement'].'",
password = "'.$password.'",
status = 0,
convert_newlines = '.$convert_newlines);

$file_id = $dbim->insert_id();

// File was uploaded successfully - add as a mirror
$dbim->query('INSERT INTO '.DB_PREFIX.'mirrors
SET file_id = '.$file_id.',
name = "Mirror 1",
location = "Earth",
url = "'.$site_config['url'].'uploads/upload-'.$time.'-'.basename($_FILES['uploadfile']['name']).'"');

// Get filesize in bytes
$filesize = filesize('./uploads/upload-'.$time.'-'.basename($_FILES['uploadfile']['name']));

// Update file size
$dbim->query('UPDATE '.DB_PREFIX.'files
SET size = '.$filesize.'
WHERE id = '.$file_id);

// Template
$add_file = $uim->fetch_template('files/userupload_add');

if ($site_config['userupload_always_approve'])
{
// Set file as active
$dbim->query('UPDATE '.DB_PREFIX.'files
SET status = 1
WHERE id = '.$file_id);

$success = true; // For redirect EOF
$add_file->assign_var('id', $file_id);
$add_file->assign_var('success', true);

}
else
{
$error = $lm->language('admin', 'upload_error_0');
}

// E-mail admin to let them know
$message = "Hello,\n\nA user (".$_SERVER['REMOTE_ADDR'].") has just added a file to your site.";

if ($site_config['userupload_always_approve'] == 0)
{
$message .= " For security reasons, it is not yet viewable - you must first enable it by editing the file at \n\n".$site_config['url']."admin.php?cmd=files_edit_file&action=file_select&file_id=".$file_id;
}
else
{
$message .= " You can see it at \n\n".$site_config['url']."details.php?file=".$file_id;

$dbim->query('UPDATE '.DB_PREFIX.'files
SET status = 1
WHERE id = '.$file_id);
}

// Send
mail($site_config['admin_email'], 'New File Added', $message, 'From: '.$site_config['admin_email']);
}
else
{
switch ($_FILES['uploadfile']['error'])
{
case 1:
$error = $lm->language('admin', 'upload_error_1');
break;
case 3:
$error = $lm->language('admin', 'upload_error_3');
break;
case 4:
$error = $lm->language('admin', 'upload_error_4');
break;
}
}
}
else
{
$error = $lm->language('admin', 'upload_error_ext');
}

if (!isset($add_file))
{
// Template
$add_file = $uim->fetch_template('files/userupload_upload');

// Any error?
if (!empty($error))
{
$add_file->assign_var('error', $error);
$add_file->assign_var('success', false);
}

}
}

// Has the form been submitted?
if (isset($input['submit']) && !empty($input['name']) && !isset($_FILES['uploadfile']))
{
if (isset($input['upload']))
{
// Use this in place of an ID for the time being... (no pun)
$time = time();

// Template
$add_file = $uim->fetch_template('files/userupload_upload');

// These are the fields we need to pass on to the upload section
$wanted_elements = array('name', 'description_small', 'description_big',
'convert_newlines', 'category', 'size',
'filesize_format');

foreach ($input as $key => $value)
{
if (in_array($key, $wanted_elements) || (strpos($key, 'custom_field') !== false))
{
$add_file->assign_var('key', $key);
$add_file->assign_var('value', $value);
$add_file->use_block('submitted_data');
}
}

// Display the max filesize that can be uploaded
$max_upload_size = ini_get('upload_max_filesize');
$add_file->assign_var('max_upload_size', $max_upload_size);
}
else
{
for ($i = 1; $i <= $site_config['mirrors']; $i++)
{
validate_types($input, array('mirror'.$i.'_name' => 'STR', 'mirror'.$i.'_location' => 'STR', 'mirror'.$i.'_url' => 'STR'));

if (!empty($input['mirror'.$i.'_name']) && !empty($input['mirror'.$i.'_location'])&& !empty($input['mirror'.$i.'_url']))
{
// Have we inserted into the database yet?
if (empty($inserted))
{
// Get various variables
if (!empty($input['password']))
{
$password = md5($input['password']);
}
else
{
$password = '';
}

if (!empty($input['convert_newlines']) && $input['convert_newlines'] === 1)
{
$convert_newlines = $input['convert_newlines'];
}
else
{
$convert_newlines = 0;
}

// Gigabyte
if ($input['filesize_format'] == 'gb')
{
$filesize = floatval($input['size'] * pow(1024,3));
}
// Megabyte
elseif ($input['filesize_format'] == 'mb')
{
$filesize = floatval($input['size'] * pow(1024,2));
}
// Kilobyte
elseif ($input['filesize_format'] == 'kb')
{
$filesize = floatval($input['size'] * 1024);
}
// Byte, or otherwise
else
{
$filesize = floatval($input['size']);
}

$dbim->query('INSERT INTO '.DB_PREFIX.'files
SET category_id = "'.$input['category'].'",
name = "'.$input['name'].'",
description_small = "'.$input['description_small'].'",
description_big = "'.$input['description_big'].'",
downloads = "'.$input['downloads'].'",
size = "'.$filesize.'",
date = "'.time().'",
agreement_id = "'.$input['agreement'].'",
password = "'.$password.'",
status = 0,
convert_newlines = '.$convert_newlines);

$file_id = $dbim->insert_id();

// We have now, and don't want to do it again
$inserted = true;
}

$dbim->query('INSERT INTO '.DB_PREFIX.'mirrors
SET file_id = '.$file_id.',
name = "'.$input['mirror'.$i.'_name'].'",
location = "'.$input['mirror'.$i.'_location'].'",
url = "'.$input['mirror'.$i.'_url'].'"');
$success = true;
}
}

// Don't do anything unless row has been inserted
if (!empty($inserted))
{
// Add the new custom field value
for ($i = 1; $i <= $input['custom_field_total']; $i++)
{
if (!empty($input['custom_field_'.$i.'_value']))
{
validate_types($input, array('custom_field_'.$i.'_value' => 'STR'));

// Add
$dbim->query('INSERT INTO '.DB_PREFIX.'customfields_data
SET field_id = '.$input['custom_field_'.$i.'_field_id'].',
file_id = '.$file_id.',
value = "'.$input['custom_field_'.$i.'_value'].'"');
}
}

// E-mail admin to let them know
$message = "Hello,\n\nA user (".$_SERVER['REMOTE_ADDR'].") has just added a file to your site.";

if ($site_config['userupload_always_approve'] == 0)
{
$message .= " For security reasons, it is not yet viewable - you must first enable it by editing the file at \n\n".$site_config['url']."admin.php?cmd=files_edit_file&action=file_select&file_id=".$file_id;
}
else
{
$message .= " You can see it at \n\n".$site_config['url']."details.php?file=".$file_id;

$dbim->query('UPDATE '.DB_PREFIX.'files
SET status = 1
WHERE id = '.$file_id);
}

// Send
mail($site_config['admin_email'], 'New File Added', $message, 'From: '.$site_config['admin_email']);
}
else
{
$success = false;
}

// Template
$add_file = $uim->fetch_template('files/userupload_add');

#$success = true; // For redirect EOF
$add_file->assign_var('id', $file_id);
$add_file->assign_var('success', $success);
}
}

if (!isset($add_file))
{
// Template
$add_file = $uim->fetch_template('files/userupload_add');
}

$fcm->generate_category_list($add_file, 'category', 'cats');

// Get the agreements
$agreements_result = $dbim->query('SELECT id, name, contents
FROM '.DB_PREFIX.'agreements');

while ($agreement = $dbim->fetch_array($agreements_result))
{
$add_file->assign_var('agreement', $agreement);
$add_file->use_block('agreements');
}

// Custom fields
$custom_query = $dbim->query('SELECT id, label, value
FROM '.DB_PREFIX.'customfields');

$rows = $dbim->num_rows($custom_query);
$add_file->assign_var('custom_field_total', $rows);
$id = 1;

while ($custom_fields = $dbim->fetch_array($custom_query))
{
$custom_fields['uid'] = $id;
$add_file->assign_var('custom_field', $custom_fields);
$add_file->use_block('custom_fields');
$id++;
}

// Show mirror entry forms
$mirror_amount = $site_config['mirrors'];
$current_mirror = 1;

while ($current_mirror <= $mirror_amount)
{
$add_file->assign_var('mirror', $current_mirror);
$add_file->use_block('mirror');

$current_mirror++;
}

// Use FCKeditor or not?
if (use_fckeditor())
{
$add_file->assign_var('use_fckeditor', true);

// Module
include_once ('FCKeditor/fckeditor.php');

// Small description
$fck_desc_small = new FCKeditor('description_small');
$fck_desc_small->BasePath = $site_config['url'].'FCKeditor/';
$fck_desc_small->ToolbarSet = 'od';
$fck_desc_small->Width = '90%';
$fck_desc_small->Height = '200';
$desc_small_html = $fck_desc_small->CreateHtml();
$add_file->assign_var('desc_small_html', $desc_small_html);

// Big description
$fck_desc_big = new FCKeditor('description_big');
$fck_desc_big->BasePath = $site_config['url'].'FCKeditor/';
$fck_desc_big->ToolbarSet = 'od';
$fck_desc_big->Width = '90%';
$fck_desc_big->Height = '200';
$desc_big_html = $fck_desc_big->CreateHtml();
$add_file->assign_var('desc_big_html', $desc_big_html);
}
else
{
$add_file->assign_var('use_fckeditor', false);
}

$add_file->show();
}
else
{
$add_file = $uim->fetch_template('files/userupload_disabled');
$add_file->show();
}

// End table
$end = $uim->fetch_template('global/end');
$end->show();

// Show everything
$uim->generate(TITLE_PREFIX.$lm->language('admin', 'add_file'));

?>

DJ Hands3
03-07-2009, 01:32 PM
still having a go at this but cant get the text to be updated keeps placing rnrn instead of <br />

exmaple text:
1. Shy FX & T Power - Diary of a digital Soundboyrnrn2. 3RD Party Fire & Theft - Cubik Music productionsrnrn3. Spy Catcher - Wickman & j majikrnrn4. Desperado - VRecordsrnrn5. Eric Prydz - Slammin' Remixes (Artificial Intelligence Drum & Bass Mixrnrn6. Sexy Beast E.P. - Sexy Beastrnrn7. Liquid V JuJu - Bag Of Wirernrn8. VRecords - Through The gaternrn9. VRecords - Thunderrnrn10. High Contrast - Twilights last gleamingrnrn

real shame need it to work to format the tracklistings like below

1. Shy FX & T Power - Diary of a digital Soundboy
2. 3RD Party Fire & Theft - Cubik Music productions
3. Spy Catcher - Wickman & j majik ... etc

the other page which shows the mixed page tracklists php is



<?php

/**********************************
* Olate Download 3.4.1
* http://www.olate.co.uk/od3
**********************************
* Copyright Olate Ltd 2005
*
* @author $Author: dsalisbury $ (Olate Ltd)
* @version $Revision: 262 $
* @package od
*
* Updated: $Date: 2006-10-10 20:51:48 +0100 (Tue, 10 Oct 2006) $
*/


// Initialisation
require('./includes/init.php');

// Meow
$fcm->show_cats();

// Start sessions
session_start();
$_SESSION['valid_user'] = true;

if (isset($input['file']))
{
validate_types($input, array('file' => 'INT', 'cmd' => 'STR', 'password' => 'STR', 'name' => 'STR', 'email' => 'STR', 'comment' => 'STR', 'rating' => 'INT', 'page' => 'INT'));

// Get file details
$details = $fldm->get_details($input['file'], false);

// Meta data
if (!empty($details['description_small']))
{
$uim->add_meta_data('description', strip_tags($details['description_small']));
}
if (!empty($details['keywords']))
{
$uim->add_meta_data('keywords', $details['keywords']);
}

// *ding dong* let me in please
if (isset($input['password']))
{
if ($details['password'] == md5($input['password']))
{
$_SESSION[$input['file'].'_auth'] = true;
}
}

if (!empty($details) && !empty($input['file']) && intval($details['activate_at']) <= time())
{
// Increment file view count
$details['views'] = $details['views'] + 1;
$dbim->query('UPDATE '.DB_PREFIX.'files
SET views = '.$details['views'].'
WHERE (id = '.$input['file'].')');

if (empty($details['password']) || isset($_SESSION[$input['file'].'_auth']))
{
// Get template
$details_files = $uim->fetch_template('files/file');

// Add comment
if ($input['cmd'] == 'addcomment')
{
// Check all fields are filled out
if (!empty($input['name']) && !empty($input['comment']))
{
$status = $site_config['approve_comments'] ? 0 : 1;

$dbim->query('INSERT INTO '.DB_PREFIX.'comments
SET file_id = '.$input['file'].',
timestamp = '.time().',
name = "'.$input['name'].'",
email = "'.$input['email'].'",
comment = "'.$input['comment'].'",
status = '.$status.'');

// Get success message ready
$success = 'Comments';

// What response shall I display?
$success_template = $uim->fetch_template('files/comments_success');

if ($site_config['approve_comments'] == 1)
{
$success_template->assign_var('response', $lm->language('frontend', 'comment_approval'));
}
else
{
$success_template->assign_var('response', $lm->language('frontend', 'comment_added'));
}
}
else
{
// Get error ready
$error = 'Comments';
$error_message = $lm->language('frontend', 'fill_out_fields');
}
}

// Rate file
if ($input['cmd'] == 'rate')
{
if (!empty($input['rating']) && !isset($_SESSION['file_rating_'.$input['file']]))
{
$new_count = ($details['rating_votes'] + 1);

// Calculate new rating
$file_rating = ($details['rating_value'] * $details['rating_votes']);
$new_rating = (($input['rating'] + $file_rating) / ($new_count));
$new_rating_formatted = number_format($new_rating, 2, '.', '');

// Update
$dbim->query('UPDATE '.DB_PREFIX.'files
SET rating_votes = '.$new_count.',
rating_value = "'.$new_rating_formatted.'"
WHERE (id = '.$input['file'].')');

$_SESSION['file_rating_'.$input['file']] = true;

// Get the success message ready
$success = 'Rating';
$success_template = $uim->fetch_template('files/rate_success');

// Update the $file var so the changes are immediately apparent
$details['rating_votes'] = $new_count;
$details['rating_value'] = $new_rating_formatted;
}
else
{
if (empty($input['rating']))
{
$error_message = $lm->language('frontend', 'rating_enter');
}
elseif (isset($_SESSION['file_rating_'.$input['file']]))
{
$error_message = $lm->language('frontend', 'rating_once');
}

// Get the error ready
$error = 'Rating';
}
}

// Formatting
$details['date'] = format_date($details['date']);

// Are we converting new lines to <br />?
if (intval($details['convert_newlines']) === 1)
{
$details['description_small'] = nl2br($details['description_small']);
$details['description_big'] = nl2br($details['description_big']);
}

// Assigning template variables
$details_files->assign_var('description_big', nl2br($details['description_big']));

$filesize = $fldm->format_size($details['size']);

$details['size'] = $filesize['size'];

$details_files->assign_var('filesize_format', $filesize['unit']);
$details_files->assign_var('file', $details);
$details_files->use_block('file');

// Custom fields
$custom_query = $dbim->query('SELECT cf.label AS label, cfd.value AS value
FROM '.DB_PREFIX.'customfields_data AS cfd,
'.DB_PREFIX.'customfields AS cf
WHERE (cfd.file_id = '.$input['file'].')
AND (cfd.field_id = cf.id)');

$i = 0;
while ($custom_fields_data = $dbim->fetch_array($custom_query))
{
$custom_fields[$i.'_label'] = $custom_fields_data['label'];
$custom_fields[$i.'_value'] = $custom_fields_data['value'];
$i++;

// Assigning template variables
$details_files->assign_var('custom_field_label', $custom_fields_data['label']);
$details_files->assign_var('custom_field_value', $custom_fields_data['value']);
$details_files->use_block('custom_fields');
}

$details_files->assign_var('custom_fields', $custom_fields);

// Meta data?


// Show template
$details_files->show();

// Success message if they've just rated a file
if (isset($success) && $success == 'Rating')
{
$success_template->show();
}

// Show the error message if it's a rating error
if (isset($error) && $error == 'Rating')
{
$rating_error = $uim->fetch_template('global/error');
$rating_error->assign_var('error_message', $error_message);
$rating_error->show();
}

// Success message
if (isset($success) && $success == 'Comments')
{
$success_template->show();
}

// Check for valid page
if ($input['page'] < 1)
{
$input['page'] = 1;
}

// If there was an error when adding a comment
// display the currently filled out fields
if (isset($error) && $error == 'Comments')
{
// Show the error
$comments_error = $uim->fetch_template('global/error');
$comments_error->assign_var('error_message', $error_message);
$comments_error->show();

// Show toolbox with submitted data
$fldm->display_toolbox($input['file'], $input, $input['page']);
}
else
{
// Show toolbox
$fldm->display_toolbox($input['file'], false, $input['page']);
}
}
else
{
// Get template
$details_files = $uim->fetch_template('files/protected');
$details_files->assign_var('file_id', $input['file']);

// Show template
$details_files->show();
}
}
elseif (!empty($details) && !empty($input['file']) && $details['activate_at'] > time())
{
// Get template
$details_files = $uim->fetch_template('files/file');

$details_files->assign_var('empty', $lm->language('frontend', 'file_not_active'));
$details['name'] = $lm->language('frontend', 'none');

// Show template
$details_files->show();
}
else
{
// Get template
$details_files = $uim->fetch_template('files/file');

$details_files->assign_var('empty', $lm->language('frontend', 'no_files'));

// Show template
$details_files->show();
}
}
else
{
// Get template
$details_files = $uim->fetch_template('files/file');

$details_files->assign_var('empty', $lm->language('frontend', 'no_files'));
$details['name'] = $lm->language('frontend', 'none');

// Show template
$details_files->show();
}

// End table
$end = $uim->fetch_template('global/end');
$end->show();

// Show everything
$uim->generate(TITLE_PREFIX.$lm->language('frontend', 'viewing').' '.$details['name']);
?>

DJ Hands3
03-07-2009, 05:17 PM
Problem solved



{
$details['description_small'] = str_replace(array("rn", "\rn", "\r\n", "\r", "\n"), "<br />", $details['description_small']);
$details['description_big'] = str_replace(array("rn", "\rn", "\r\n", "\r", "\n"), "<br />", $details['description_big']);
}

// Assigning template variables
$details_files->assign_var('description_big', str_replace(array("rn", "\rn", "\r\n", "\r", "\n"), "<br />", $details['description_big']));




With thanks to http://uk2.php.net/nl2br



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum