query('SELECT id FROM '.$db->prefix.'smilies ORDER BY disp_position') or error('Unable to retrieve smilies', __FILE__, __LINE__, $db->error()); while ($db_smilies = $db->fetch_assoc($result)) { if (!preg_match('#^\d+$#', $smilies_order[$db_smilies['id']])) message($lang_smiley['Must int']); $db->query('UPDATE '.$db->prefix.'smilies SET disp_position='.$smilies_order[$db_smilies['id']].' WHERE id='.$db_smilies['id']) or error('Unable to change smilies positions', __FILE__, __LINE__, $db->error()); } require_once PUN_ROOT.'include/cache_smilies.php'; generate_smiley_cache(); redirect(PLUGIN_URL, $lang_smiley['Positions changed']); } // Retirer des smileys elseif (isset($_POST['remove'])) { $rem_smilies = array_map('trim', $_POST['rem_smilies']); foreach (array_keys($rem_smilies) as $id) $db->query('DELETE FROM '.$db->prefix."smilies WHERE id = '".$id."'") or error('Unable to delete smiley', __FILE__, __LINE__, $db->error()); require_once PUN_ROOT.'include/cache_smilies.php'; generate_smiley_cache(); redirect(PLUGIN_URL, $lang_smiley['Delete Smiley Redirect']); } // Supprimer des images elseif (isset($_POST['delete'])) { $del_smilies = array_map('trim', $_POST['del_smilies']); $to_delete = array(); $images_affected = array(); $not_deleted = array(); foreach (array_keys($del_smilies) as $img) { if (!in_array($img, $smiley_img)) $to_delete[] = $img; else $images_affected[] = $img; } if (!empty($images_affected)) message(sprintf($lang_smiley['Images affected'], implode(', ', $images_affected))); else { foreach ($to_delete as $img) { if (!@unlink(PUN_ROOT.'img/smilies/'.$img)) $not_deleted[] = $img; } } if (!empty($not_deleted)) $message = sprintf($lang_smiley['Images not deleted'], implode(', ', $not_deleted)); else $message = $lang_smiley['Images deleted']; redirect(PLUGIN_URL, $message); } // Ajouter une image elseif (isset($_POST['add_image'])) { if (!isset($_FILES['req_file'])) message($lang_smiley['No file']); $uploaded_file = $_FILES['req_file']; // Make sure the upload went smooth if (isset($uploaded_file['error'])) { switch ($uploaded_file['error']) { case 1: // UPLOAD_ERR_INI_SIZE case 2: // UPLOAD_ERR_FORM_SIZE message($lang_smiley['Too large ini']); break; case 3: // UPLOAD_ERR_PARTIAL message($lang_smiley['Partial upload']); break; case 4: // UPLOAD_ERR_NO_FILE message($lang_smiley['No file']); break; case 6: // UPLOAD_ERR_NO_TMP_DIR message($lang_smiley['No tmp directory']); break; default: // No error occured, but was something actually uploaded? if ($uploaded_file['size'] == 0) message($lang_smiley['No file']); break; } } if (is_uploaded_file($uploaded_file['tmp_name'])) { $filename = substr($uploaded_file['name'], 0, strpos($uploaded_file['name'], '.')); $allowed_types = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png'); if (!in_array($uploaded_file['type'], $allowed_types)) message($lang_smiley['Bad type']); // Make sure the file isn't too big if ($uploaded_file['size'] > $smilies_config_image_size) message($lang_smiley['Too large'].' '.$smilies_config_image_size.' '.$lang_smiley['bytes'].'.'); // Determine type $extensions = null; if ($uploaded_file['type'] == 'image/gif') $extensions = array('.gif', '.jpg', '.png'); else if ($uploaded_file['type'] == 'image/jpeg' || $uploaded_file['type'] == 'image/pjpeg') $extensions = array('.jpg', '.gif', '.png'); else $extensions = array('.png', '.gif', '.jpg'); // Move the file to the avatar directory. We do this before checking the width/height to circumvent open_basedir restrictions. if (!@move_uploaded_file($uploaded_file['tmp_name'], PUN_ROOT.'img/smilies/'.$filename.'.tmp')) message($lang_smiley['Move failed']); // Now check the width/height list($width, $height, $type,) = getimagesize(PUN_ROOT.'img/smilies/'.$filename.'.tmp'); if (empty($width) || empty($height) || $width > $smilies_config_image_width || $height > $smilies_config_image_height) { @unlink(PUN_ROOT.'img/smilies/'.$filename.'.tmp'); message($lang_smiley['Too wide or high'].' '.$smilies_config_image_width.'x'.$smilies_config_image_height.' '.$lang_profile['pixels'].'.'); } else if ($type == 1 && $uploaded_file['type'] != 'image/gif') // Prevent dodgy uploads { @unlink(PUN_ROOT.'img/smilies/'.$filename.'.tmp'); message($lang_smiley['Bad type']); } // Delete any old avatars and put the new one in place @unlink(PUN_ROOT.'img/smilies/'.$filename.$extensions[0]); @unlink(PUN_ROOT.'img/smilies/'.$filename.$extensions[1]); @unlink(PUN_ROOT.'img/smilies/'.$filename.$extensions[2]); @rename(PUN_ROOT.'img/smilies/'.$filename.'.tmp', PUN_ROOT.'img/smilies/'.$filename.$extensions[0]); @chmod(PUN_ROOT.'img/smilies/'.$filename.$extensions[0], 0644); } else message($lang_smiley['Unknown failure']); redirect(PLUGIN_URL, $lang_smiley['Successful Upload']); } // Ajouter un smiley à la liste elseif (isset($_POST['add_smiley'])) { $smiley_code = trim($_POST['smiley_code']); $smiley_image = trim($_POST['smiley_image']); if ($smiley_code == '') message($lang_smiley['Create Smiley Code None']); if ($smiley_image == '') message($lang_smiley['Create Smiley Image None']); if (in_array($smiley_code, $smiley_text)) message($lang_smiley['Code already exists']); $db->query('INSERT INTO '.$db->prefix."smilies (image, text) VALUES ('".$smiley_image."', '".$db->escape($smiley_code)."')") or error('Unable to add smiley', __FILE__, __LINE__, $db->error()); require_once PUN_ROOT.'include/cache_smilies.php'; generate_smiley_cache(); redirect(PLUGIN_URL, $lang_smiley['Successful Creation']); } // Affichage else { // Display the admin navigation menu generate_admin_menu($plugin); ?>