imagepicker/ 0000755 0000765 0000765 00000000000 10611752350 015040 5 ustar tspencer tspencer 0000000 0000000 imagepicker/.htaccess 0000755 0000765 0000765 00000000020 10611752123 016627 0 ustar tspencer tspencer 0000000 0000000 Options -Indexes imagepicker/.svn/ 0000755 0000765 0000765 00000000000 10613171713 015724 5 ustar tspencer tspencer 0000000 0000000 imagepicker/.svn/entries 0000644 0000765 0000765 00000002244 10613171713 017322 0 ustar tspencer tspencer 0000000 0000000 8 dir 138 svn://192.168.0.12/svnrepos/downtownraleighnc/www/modules/imagepicker svn://192.168.0.12/svnrepos 2007-04-19T20:42:59.500599Z 125 root svn:special svn:externals svn:needs-lock 88a8a4c0-c262-4b6c-8fd3-f9c2b6af9608 imagepicker.module file 2007-04-19T20:42:59.000000Z 9fcd6142b7b9385eb65d8ff690dd54f4 2007-04-19T20:42:59.500599Z 125 root has-props imagepicker.tpl.php file 2007-04-19T20:42:59.000000Z 788de11a660d68146ae372a2d0107cba 2007-04-19T20:42:59.500599Z 125 root has-props imagepicker.install file 2007-04-19T20:42:59.000000Z 3df741b43f804d1d43acecdf263a80b5 2007-04-19T20:42:59.500599Z 125 root has-props imagepicker.css file 2007-04-19T20:42:59.000000Z 82811b70702a68aec48d6efb44412655 2007-04-19T20:42:59.500599Z 125 root has-props imagepicker.info file 2007-04-19T20:42:59.000000Z 39ccf0c16928358c40528059b4d31815 2007-04-19T20:42:59.500599Z 125 root has-props .htaccess file 2007-04-19T20:42:59.000000Z 99d22d1d8cc37a6376ff8d7b4023a894 2007-04-19T20:42:59.500599Z 125 root has-props readme.txt file 2007-04-19T20:42:59.000000Z 1df0a564d3960318d0345a8b5147ac29 2007-04-19T20:42:59.500599Z 125 root has-props imagepicker/.svn/format 0000644 0000765 0000765 00000000002 10611752347 017135 0 ustar tspencer tspencer 0000000 0000000 8 imagepicker/.svn/prop-base/ 0000755 0000765 0000765 00000000000 10611752347 017622 5 ustar tspencer tspencer 0000000 0000000 imagepicker/.svn/prop-base/.htaccess.svn-base 0000644 0000765 0000765 00000000035 10611752347 023133 0 ustar tspencer tspencer 0000000 0000000 K 14 svn:executable V 0 END imagepicker/.svn/prop-base/imagepicker.css.svn-base 0000644 0000765 0000765 00000000035 10611752347 024327 0 ustar tspencer tspencer 0000000 0000000 K 14 svn:executable V 0 END imagepicker/.svn/prop-base/imagepicker.info.svn-base 0000644 0000765 0000765 00000000035 10611752347 024472 0 ustar tspencer tspencer 0000000 0000000 K 14 svn:executable V 0 END imagepicker/.svn/prop-base/imagepicker.install.svn-base 0000644 0000765 0000765 00000000035 10611752347 025205 0 ustar tspencer tspencer 0000000 0000000 K 14 svn:executable V 0 END imagepicker/.svn/prop-base/imagepicker.module.svn-base 0000644 0000765 0000765 00000000035 10611752347 025024 0 ustar tspencer tspencer 0000000 0000000 K 14 svn:executable V 0 END imagepicker/.svn/prop-base/imagepicker.tpl.php.svn-base 0000644 0000765 0000765 00000000035 10611752347 025124 0 ustar tspencer tspencer 0000000 0000000 K 14 svn:executable V 0 END imagepicker/.svn/prop-base/readme.txt.svn-base 0000644 0000765 0000765 00000000035 10611752347 023333 0 ustar tspencer tspencer 0000000 0000000 K 14 svn:executable V 0 END imagepicker/.svn/props/ 0000755 0000765 0000765 00000000000 10611752347 017075 5 ustar tspencer tspencer 0000000 0000000 imagepicker/.svn/text-base/ 0000755 0000765 0000765 00000000000 10611752350 017620 5 ustar tspencer tspencer 0000000 0000000 imagepicker/.svn/text-base/.htaccess.svn-base 0000644 0000765 0000765 00000000020 10611752347 023131 0 ustar tspencer tspencer 0000000 0000000 Options -Indexes imagepicker/.svn/text-base/imagepicker.css.svn-base 0000644 0000765 0000765 00000001347 10611752347 024342 0 ustar tspencer tspencer 0000000 0000000 body { background-color: white!important; } tbody { border-top: 0; } #imgp { clear: both; padding-top: 10px; } .imgp_holder { float: left; margin: 10px; border: 1px solid #cbd3d8; width: 100px; height: 100px; text-align: center; padding: 2px; } .imgp_holder a { display: block; height: 100px; width: 100px; } .imgp_img_options { width: 120px; float: left; } .imgp_img_options .form-item { margin-top: 0; } #imgp_img_holder { float: left; margin-right: 40px; margin-left: 20px; } #imgp_controls { padding-top: 10px; clear: both; } #imgp_page_img { text-align: center; margin: 15px; } #imgp_edit_form { float: left; } #imgp_edit_form .form-item { margin-top: 0; } imagepicker/.svn/text-base/imagepicker.info.svn-base 0000644 0000765 0000765 00000000137 10611752347 024501 0 ustar tspencer tspencer 0000000 0000000 name = Imagepicker description = Upload, browse and add images to your nodes. package = Other imagepicker/.svn/text-base/imagepicker.install.svn-base 0000644 0000765 0000765 00000003464 10611752347 025222 0 ustar tspencer tspencer 0000000 0000000 '. t('Adds an advanced image upload form under the node body part.') .'
'; return $output; } } function imagepicker_get_access() { global $user; if (1 == $user->uid) { return true; } $where = array(); foreach ($user->roles as $role => $name) { $where[] = 'ff.roles LIKE \'%,'.$role.',%\''; } $where = implode(' OR ', $where); if ($where) { $sq = ' SELECT f.format, f.delta FROM filter_formats AS ff LEFT JOIN filters AS f USING (format) WHERE ('.$where.') '; $result = db_query($sq); if (db_num_rows($result)) { $format = array(); while ($res = db_fetch_array($result)) { $format[ $res['format'] ][] = $res['delta']; } foreach ($format as $k => $v) { $format[$k] = !in_array(0, $format[$k]); } return in_array(1, $format); } } return false; } function imagepicker_menu($may_cache) { $items = array(); if ($may_cache) { $access = imagepicker_get_access(); $items[] = array( 'path' => 'imagepicker', 'title' => t('Image picker'), 'callback' => 'imagepicker_upload', 'access' => $access, 'type' => MENU_CALLBACK ); $items[] = array( 'path' => 'imagepicker/upload', 'title' => t('Upload'), 'access' => $access, 'type' => MENU_DEFAULT_LOCAL_TASK, 'weight' => 1 ); $items[] = array( 'path' => 'imagepicker/browse', 'title' => t('Browse All'), 'callback' => 'imagepicker_browse', 'access' => $access, 'type' => MENU_LOCAL_TASK, 'weight' => 2 ); $items[] = array( 'path' => 'imagepicker/edit', 'title' => t('Edit image'), 'callback' => 'imagepicker_image_edit', 'access' => $access, 'type' => MENU_CALLBACK ); $items[] = array( 'path' => 'imagepicker/image', 'title' => t('Imagepicker'), 'callback' => 'imagepicker_image_page', 'access' => true, 'type' => MENU_CALLBACK ); } return $items; } function imagepicker_form_alter($form_id, &$form) { if (imagepicker_get_access()) { if (preg_match('/node_form$/i', $form_id)) { $form['body_filter']['file_upload'] = array( '#type' => 'fieldset', '#title' => 'Image picker', '#collapsible' => 1, '#collapsed' => 0, '#weight' => 1, '#validate' => array(), '#theme' => 'imagepicker_iframe', 1 => array() ); } } } function theme_imagepicker_iframe() { return ''; } function imagepicker_upload() { $content = drupal_get_form('imagepicker_upload_form'); theme('imagepicker', $content); } function imagepicker_upload_form() { $form['#attributes']['enctype'] = 'multipart/form-data'; $form['file_upload'] = array( '#type' => 'file', '#title' => t('Image file'), '#description' => t('Browse your computer for image file'), '#required' => true, '#value' => 1 ); $form['thumb'] = array( '#type' => 'textfield', '#title' => t('Thumbnail size'), '#size' => 10, '#default_value' => 100, '#description' => t('Size in pixels of thumbnail\'s bigger side'), '#required' => true ); $form['scale'] = array( '#type' => 'textfield', '#title' => t('Scale image'), '#size' => 10, '#description' => t('Scale image to this size in pixels if not left empty') ); $form['title'] = array( '#type' => 'textfield', '#title' => t('Title'), '#description' => t('Add title for your image') ); $form['description'] = array( '#type' => 'textarea', '#title' => t('Description'), '#rows' => 2, '#cols' => 80, '#description' => t('Add description for your image') ); $form['submit'] = array( '#type' => 'submit', '#value' => t('Upload'), ); return $form; } function imagepicker_upload_form_validate($form_id, $form_values) { foreach ($form_values as $name => $value) { $value = trim($value); switch ($name) { case 'file_upload': if (empty($_FILES['files']['name']['file_upload'])) { form_set_error($name, t('Image file field is required.')); } elseif (!isset($_FILES['files']['tmp_name']['file_upload']) || !file_exists($_FILES['files']['tmp_name']['file_upload'])) { form_set_error($name, t('Error while uploading file.')); } elseif (!image_get_info($_FILES['files']['tmp_name']['file_upload'])) { form_set_error($name, t('Uploaded file is not an image.')); } elseif (!imagepicker_get_uploaded_file_extension('file_upload')) { form_set_error($name, t('Only .jpg, .gif and .png image files are accepted.')); } break; case 'thumb': if (!preg_match('/^[0-9]{1,3}$/', $value) || $value <= 0) { form_set_error($name, t('Thumbnail size should be an integer between 1 and 999.')); } break; case 'scale': if (!preg_match('/^[0-9]{0,3}$/', $value)) { form_set_error($name, t('Scale value should be an integer between 1 and 999 or leave it empty if you don\'t want to scale your image.')); } break; } } } function imagepicker_upload_form_submit($form_id, $form_values) { global $user; if (t('Upload') == $form_values['op']) { $destination = imagepicker_get_path(false, true); $thumbsDir = $destination.'thumbs'; $browserDir = $destination.'browser'; if (file_check_directory($destination, true) && file_check_directory($thumbsDir, true) && file_check_directory($browserDir, true)) { // Add DIRECTORY_SEPARATORS here because drupals' functions remove trailing slashes $destination .= DIRECTORY_SEPARATOR; $thumbsDir = $thumbsDir.DIRECTORY_SEPARATOR; $browserDir = $browserDir.DIRECTORY_SEPARATOR; $maxThumbSize = $form_values['thumb'] ? $form_values['thumb'] : 100; $scaleTo = $form_values['scale'] ? $form_values['scale'] : false; if (!$scaleTo) { // Use $path instead of original $destination variable cause this // variable's value will be changed during copying file, so we won't // loose it. $path = $destination; $imageMoved = imagepicker_copy_uploaded_file($path, 'file_upload'); $file = basename($path); } else { $source = $_FILES['files']['tmp_name']['file_upload']; $file = imagepicker_get_uploaded_file_name($destination, 'file_upload'); $imageScaled = imagepicker_scale_image($source, $destination.$file, $scaleTo); } if (!$scaleTo && $imageMoved || $scaleTo && $imageScaled) { // Source file should still be an uploaded one, as scaled image // might have some watermarks etc. from drupal's filters/hooks. $source = $_FILES['files']['tmp_name']['file_upload']; if (imagepicker_scale_image($source, $thumbsDir.$file, $maxThumbSize)) { imagepicker_scale_image($source, $browserDir.$file, 100); $nextImgId = db_next_id('{imagepicker}_img_id'); $title = htmlspecialchars($form_values['title']); $description = htmlspecialchars($form_values['description']); if (db_query("INSERT INTO {imagepicker} (img_id, uid, img_name, img_title, img_description) VALUES ('%d', '%d', '%s', '%s', '%s')", array($nextImgId, $user->uid, $file, $title, $description))) { drupal_set_message(t('Image was successfully uploaded.')); drupal_goto('imagepicker/browse/'.$nextImgId, null, null, 302); } else { file_delete($thumbsDir.$file); file_delete($browserDir.$file); drupal_set_message(t('Error while saving information to database for uploaded image.'), 'error'); } } else { drupal_set_message(t('Error while creating a thumbnail for uploaded image.'), 'error'); } } else { if (!$scaleTo && !$imageMoved) { drupal_set_message(t('Error while moving uploaded file to its destination.'), 'error'); } else { drupal_set_message(t('Error while scaling uploaded file.'), 'error'); } } file_delete($destination.$file); drupal_goto('imagepicker', null, null, 302); } else { drupal_set_message(t('Unable to create a directory structure for your images.'), 'error'); drupal_goto('imagepicker', null, null, 302); } } } function imagepicker_get_path($url = false, $userDir = false) { global $user, $base_url; $dirSep = !$url ? DIRECTORY_SEPARATOR : '/'; if (!$url) { $path = str_replace('/', DIRECTORY_SEPARATOR, getcwd()); } else { $path = $base_url; } $path .= $dirSep.file_directory_path().$dirSep.'imagepicker'.$dirSep; if ($userDir) { $userName = !is_array($userDir) ? $user->name : $userDir['name']; $firstLetter = strtolower(substr($userName, 0, 1)); $firstLetter = preg_match('/^[a-z]$/', $firstLetter) ? $firstLetter : 'others'; $path .= $firstLetter.$dirSep.$userName.$dirSep; } return $path; } function imagepicker_copy_uploaded_file(&$destination, $name) { $source = $_FILES['files']['tmp_name'][$name]; if (file_copy($source, $destination, FILE_EXISTS_RENAME)) { // Fix bug in drupal's file_copy function which uses '/' instead of // DIRECTORY_SEPARATOR for making directories. This causes problems on // Windows mashines. $source = str_replace('/', DIRECTORY_SEPARATOR, $source); $file = imagepicker_get_uploaded_file_name($destination, $name); $destination = $destination.$file; return @rename($source, $destination); } return false; } function imagepicker_get_uploaded_file_extension($name) { switch ($_FILES['files']['type'][$name]) { case 'image/pjpeg': // "What genius at microsoft decided to rename the mime type for jpgs?" // Thats a nice phrase I have found about this mime type :) Wonder what // am I talking about? Try to upload some type of jpg image via IE7. // Don't know if it's the same with IE6, but IE7 might give you a mime // type of image/pjpeg. So lets just treat this 'progressive jpg' as a // normal jpg image. case 'image/jpeg': $fileExt = '.jpg'; break; case 'image/gif': $fileExt = '.gif'; break; case 'image/png': $fileExt = '.png'; break; default: $fileExt = ''; } return $fileExt; } function imagepicker_get_uploaded_file_name($destination, $name) { $fileExt = imagepicker_get_uploaded_file_extension($name); if (false !== strpos($_FILES['files']['name'][$name], '.')) { $fileName = substr($_FILES['files']['name'][$name], 0, strrpos($_FILES['files']['name'][$name], '.')); } else { $fileName = $_FILES['files']['name'][$name]; } $file = $fileName.$fileExt; $i = 0; while (file_exists($destination.$file)) { $i++; $file = $fileName.'_'.$i.$fileExt; } return $file; } function imagepicker_get_image_path($img, $type = 'browser') { $imgBaseDir = imagepicker_get_path(false, true); switch ($type) { case 'browser': if (file_exists($imgBaseDir.'browser'.DIRECTORY_SEPARATOR.$img['img_name'])) { $imgPath = imagepicker_get_path(true, true).'browser/'.$img['img_name']; } elseif (file_exists($imgBaseDir.'thumbs'.DIRECTORY_SEPARATOR.$img['img_name'])) { $imgPath = imagepicker_get_path(true, true).'thumbs/'.$img['img_name']; } break; case 'full': if (file_exists($imgBaseDir.$img['img_name'])) { $imgPath = imagepicker_get_path(true, true).$img['img_name']; } break; case 'thumb': default: if (file_exists($imgBaseDir.'thumbs'.DIRECTORY_SEPARATOR.$img['img_name'])) { $imgPath = imagepicker_get_path(true, true).'thumbs/'.$img['img_name']; } elseif (file_exists($imgBaseDir.'browser'.DIRECTORY_SEPARATOR.$img['img_name'])) { $imgPath = imagepicker_get_path(true, true).'browser/'.$img['img_name']; } break; } return $imgPath ? $imgPath : ''; } function imagepicker_scale_image($source, $destination, $maxSize) { $info = image_get_info($source); $width = ($maxSize >= $info['width']) ? $info['width'] : $maxSize; $height = ($maxSize >= $info['height']) ? $info['height'] : $maxSize; $aspect = $info['height'] / $info['width']; if ($aspect < $height / $width) { $width = (int)min($width, $info['width']); $height = (int)round($width * $aspect); } else { $height = (int)min($height, $info['height']); $width = (int)round($height / $aspect); } return image_toolkit_invoke('resize', array($source, $destination, $width, $height)); } function imagepicker_browse() { if (arg(2)) { imagepicker_image_select(); exit(); } global $user, $base_url; $imgList = db_query("SELECT * FROM {imagepicker} WHERE uid = '%d' ORDER BY img_date DESC", array($user->uid)); if (db_num_rows($imgList)) { $content = ''; while ($img = db_fetch_array($imgList)) { $imgPath = imagepicker_get_image_path($img, 'browser'); if ($imgPath) { $formLink = url('imagepicker/browse/'.$img['img_id']); $content .= ''; } } } else { $content = ' '; } theme('imagepicker', $content); } function imagepicker_image_select() { global $user; $result = db_query("SELECT * FROM {imagepicker} WHERE uid = '%d' AND img_id = '%d' LIMIT 1", array($user->uid, arg(2))); if (db_num_rows($result)) { $img = db_fetch_array($result); drupal_add_js(imagepicker_js($img), 'inline'); $imgPath = imagepicker_get_image_path($img, 'browser'); $content = ''; $content .= drupal_get_form('imagepicker_image_form'); } theme('imagepicker', $content); } function imagepicker_image_form() { $showOptions = array('thumb' => t('Thumbnail'), 'full' => t('Full size'), 'title' => t('Title')); $linkOptions = array('file' => t('File'), 'page' => t('Page'), 'none' => t('None')); $alignOptions = array('none' => t('None'), 'fleft' => t('Float Left'), 'fright' => t('Float right')); $form['align'] = array( '#type' => 'radios', '#title' => t('Align'), '#default_value' => t('none'), '#options' => $alignOptions, '#description' => '', '#prefix' => ' ' ); $form['show'] = array( '#type' => 'radios', '#id' => 'show', '#title' => t('Show'), '#default_value' => t('thumb'), '#options' => $showOptions, '#description' => '', '#prefix' => ' ' ); $form['link'] = array( '#type' => 'radios', '#title' => t('Link'), '#default_value' => t('file'), '#options' => $linkOptions, '#description' => '', '#prefix' => ' ' ); $form['insert'] = array( '#type' => 'button', '#value' => t('Insert image'), '#prefix' => '
|