function init_post_fichier() { //no $mode : it's always admin. // on edit : get file info from form if (isset($_POST['is_it_edit']) and $_POST['is_it_edit'] == 'yes') { $file_id = htmlspecialchars($_POST['file_id']); $filename = pathinfo(htmlspecialchars($_POST['filename']), PATHINFO_FILENAME); $ext = strtolower(pathinfo(htmlspecialchars($_POST['filename']), PATHINFO_EXTENSION)); $checksum = htmlspecialchars($_POST['sha1_file']); $size = htmlspecialchars($_POST['filesize']); $type = detection_type_fichier($ext); $dossier = htmlspecialchars($_POST['dossier']); $path = htmlspecialchars($_POST['path']); // on new post, get info from the file itself } else { $file_id = date('YmdHis'); $dossier = htmlspecialchars($_POST['dossier']); // ajout de fichier par upload if (!empty($_FILES['fichier']) and $_FILES['fichier']['error'] == 0) { $filename = pathinfo($_FILES['fichier']['name'], PATHINFO_FILENAME); $ext = strtolower(pathinfo($_FILES['fichier']['name'], PATHINFO_EXTENSION)); $checksum = sha1_file($_FILES['fichier']['tmp_name']); $size = $_FILES['fichier']['size']; $type = detection_type_fichier($ext); $path = ''; // ajout par une URL d’un fichier distant } elseif (!empty($_POST['fichier'])) { $filename = pathinfo(parse_url($_POST['fichier'], PHP_URL_PATH), PATHINFO_FILENAME); $ext = strtolower(pathinfo(parse_url($_POST['fichier'], PHP_URL_PATH), PATHINFO_EXTENSION)); $checksum = sha1_file($_POST['fichier']); // works with URL files $size = ''; // same (even if we could use "filesize" with the URL, it would over-use data-transfer) $path = ''; $type = detection_type_fichier($ext); } else { // ERROR redirection(basename($_SERVER['PHP_SELF']) . '?errmsg=error_image_add'); return FALSE; } } // nom du fichier : si nom donné, sinon nom du fichier inchangé $filename = diacritique(htmlspecialchars(!empty($_POST['nom_entree']) ? $_POST['nom_entree'] : $filename), '', '0') . '.' . $ext; $statut = (isset($_POST['statut']) and $_POST['statut'] == 'on') ? '0' : '1'; $fichier = array('bt_id' => $file_id, 'bt_type' => $type, 'bt_fileext' => $ext, 'bt_filesize' => $size, 'bt_filename' => $filename, 'bt_content' => stripslashes(protect_markup(clean_txt($_POST['description']))), 'bt_wiki_content' => stripslashes(protect_markup(clean_txt($_POST['description']))), 'bt_checksum' => $checksum, 'bt_statut' => $statut, 'bt_dossier' => empty($dossier) ? 'default' : $dossier, 'bt_path' => empty($path) ? '/' . substr($checksum, 0, 2) : $path); return $fichier; }
function init_post_link2() { // second init : the whole link data needs to be stored $id = htmlspecialchars(stripslashes(protect_markup(clean_txt($_POST['bt_id'])))); $author = htmlspecialchars(stripslashes(protect_markup(clean_txt($_POST['bt_author'])))); if (empty($_POST['url'])) { $url = $GLOBALS['racine'] . '?mode=links&id=' . $id; } else { $url = htmlspecialchars(stripslashes(protect_markup(clean_txt($_POST['url'])))); } $statut = isset($_POST['statut']) ? 0 : 1; $link = array('bt_id' => $id, 'bt_type' => htmlspecialchars($_POST['type']), 'bt_content' => formatage_links(htmlspecialchars(stripslashes(protect_markup(clean_txt($_POST['description']))), ENT_NOQUOTES)), 'bt_wiki_content' => htmlspecialchars(stripslashes(protect_markup(clean_txt($_POST['description'])))), 'bt_author' => $author, 'bt_title' => htmlspecialchars(stripslashes(protect_markup(clean_txt($_POST['title'])))), 'bt_link' => $url, 'bt_tags' => htmlspecialchars(traiter_tags($_POST['categories'])), 'bt_statut' => $statut); if (isset($_POST['ID']) and is_numeric($_POST['ID'])) { // ID only added on edit. $link['ID'] = $_POST['ID']; } return $link; }