? gallerix-617038.patch Index: build.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/gallerix/build.inc,v retrieving revision 1.9 diff -u -p -r1.9 build.inc --- build.inc 18 Oct 2008 18:25:04 -0000 1.9 +++ build.inc 30 Oct 2009 04:50:23 -0000 @@ -14,25 +14,25 @@ function gallerix_rebuild() { $output = ''; - //Load common.js. - gallerix_load_js(); - + //Load common.js. + gallerix_load_js(); + //Include rebuilding JavaScript and CSS. $path = drupal_get_path('module', 'gallerix'); drupal_add_js($path . '/js/rebuild.js'); - + drupal_add_js(array('gallerixRebuild' => array( 'rebuildURL' => url('admin/gallerix/rebuild/build/'), - 'finalizeURL' => url('admin/gallerix/rebuild/finalize/'), + 'finalizeURL' => url('admin/gallerix/rebuild/finalize/'), 'progressBar' => theme('progress_bar', 0, t('Rebuilding')), )), 'setting'); - - - $output .= '

' . t("By clicking Rebuild, Drupal will go through every picture in the database and perform the selected action. + + + $output .= '

' . t("By clicking Rebuild, Drupal will go through every picture in the database and perform the selected action. Note that servers may limit your script execution time. To avoid exceeding this limit, Gallerix uses a threshold and breaks up the operation into batches.") . '

'; - $output .= '

' . t('Do not navigate away from this page during a rebuild operation. - Some of these operations are very intensive and can take a very long time. - As long as the progress bar increases ocassionally, everything is working smoothly.') . '

'; + $output .= '

' . t('Do not navigate away from this page during a rebuild operation. + Some of these operations are very intensive and can take a very long time. + As long as the progress bar increases ocassionally, everything is working smoothly.') . '

'; $output .= drupal_get_form('gallerix_rebuild_form'); $output .= '
'; @@ -52,18 +52,18 @@ function gallerix_rebuild_form() { $form['threshold'] = array( '#type' => 'select', '#title' => t('Threshold'), - '#description' => t("To avoid a script timeout, or a database connection timeout, set the threshold value to something conservative. + '#description' => t("To avoid a script timeout, or a database connection timeout, set the threshold value to something conservative. The bigger the pictures uploaded, the lower this threshold should be. The threshold is usually dependent on your host's capabilities."), '#options' => drupal_map_assoc(array(5, 10, 15, 20, 30, 40, 50, 60, 70, 80, 90, 100)), '#default_value' => variable_get('gallerix_rebuild_threshold', 10), - + ); $form['derivatives'] = array( '#type' => 'fieldset', '#title' => t('Derivatives'), - '#description' => t('If you have added new sizes, changed resolutions of existing sizes, or changed the image quality to be used, + '#description' => t('If you have added new sizes, changed resolutions of existing sizes, or changed the image quality to be used, you should rebuild all derivatives. This process can take a long time and will practically monopolize the server.'), - '#attributes' => array('id' => 'gallerix-fieldset-derivatives'), + '#attributes' => array('id' => 'gallerix-fieldset-derivatives'), ); $form['derivatives']['submit'] = array( '#type' => 'button', @@ -75,70 +75,70 @@ function gallerix_rebuild_form() { $form['exif'] = array( '#type' => 'fieldset', '#title' => t('EXIF Data'), - '#description' => t("You should rebuild EXIF data if you've added new fields to extract. If you have just turned on extraction for the first time, you must rebuild as well."), - '#attributes' => array('id' => 'gallerix-fieldset-exif'), + '#description' => t("You should rebuild EXIF data if you've added new fields to extract. If you have just turned on extraction for the first time, you must rebuild as well."), + '#attributes' => array('id' => 'gallerix-fieldset-exif'), ); $form['exif']['submit'] = array( '#type' => 'button', '#value' => t('Rebuild'), '#id' => 'gallerix-rebuild-exif', - '#attributes' => array('class' => 'gallerix-rebuild'), + '#attributes' => array('class' => 'gallerix-rebuild'), ); - + $form['iptc'] = array( '#type' => 'fieldset', '#title' => t('IPTC Data'), '#description' => t("You should rebuild IPTC data after activating the feature for the first time."), - '#attributes' => array('id' => 'gallerix-fieldset-iptc'), + '#attributes' => array('id' => 'gallerix-fieldset-iptc'), ); $form['iptc']['submit'] = array( '#type' => 'button', '#value' => t('Rebuild'), '#id' => 'gallerix-rebuild-iptc', - '#attributes' => array('class' => 'gallerix-rebuild'), + '#attributes' => array('class' => 'gallerix-rebuild'), ); - + $form['sort'] = array( '#type' => 'fieldset', '#title' => t('Sorting'), - '#description' => t("Resort albums if you have changed the default order. This will not affect albums set to custom sorting."), - '#attributes' => array('id' => 'gallerix-fieldset-sort'), + '#description' => t("Resort albums if you have changed the default order. This will not affect albums set to custom sorting."), + '#attributes' => array('id' => 'gallerix-fieldset-sort'), ); $form['sort']['submit'] = array( '#type' => 'button', '#value' => t('Rebuild'), '#id' => 'gallerix-rebuild-sort', - '#attributes' => array('class' => 'gallerix-rebuild'), + '#attributes' => array('class' => 'gallerix-rebuild'), ); $form['names'] = array( '#type' => 'fieldset', '#title' => t('Secure/Restore Names'), '#description' => t("If you want to remove security, disable secure mode, and this will restore original names to your files. Similarly, if you want to - transition to secure mode, enable it, and this will secure file names."), - '#attributes' => array('id' => 'gallerix-fieldset-names'), - ); + transition to secure mode, enable it, and this will secure file names."), + '#attributes' => array('id' => 'gallerix-fieldset-names'), + ); $form['names']['submit'] = array( '#type' => 'button', '#value' => t('Rebuild'), '#id' => 'gallerix-rebuild-names', - '#attributes' => array('class' => 'gallerix-rebuild'), + '#attributes' => array('class' => 'gallerix-rebuild'), - ); + ); $form['all'] = array( '#type' => 'fieldset', '#title' => t('Everything'), - '#description' => t("Rebuild everything in the catalog. This does not include restoring secure names or original names."), - '#attributes' => array('id' => 'gallerix-fieldset-all'), - ); + '#description' => t("Rebuild everything in the catalog. This does not include restoring secure names or original names."), + '#attributes' => array('id' => 'gallerix-fieldset-all'), + ); $form['all']['submit'] = array( '#type' => 'button', '#value' => t('Rebuild All'), '#id' => 'gallerix-rebuild-all', - '#attributes' => array('class' => 'gallerix-rebuild'), - ); - - + '#attributes' => array('class' => 'gallerix-rebuild'), + ); + + return $form; } @@ -147,7 +147,7 @@ function gallerix_rebuild_form() { function gallerix_build_restore_name($pid) { $secure = variable_get('gallerix_secure_mode', 0); - + $picture = gallerix_load_picture($pid); @@ -155,30 +155,30 @@ function gallerix_build_restore_name($pi if ($secure) { foreach($sizes as $size => $properties) { _gallerix_secure_file($picture->$size); - } + } $secure_path = _gallerix_secure_file($picture->original); $secure_name = basename($secure_path); - + db_query("UPDATE {gallerix_pictures} SET name = '%s', path = '%s' WHERE pid = %d", $secure_name, $secure_path, $pid); - + } else { - + //Add in the dummy original size. $sizes['original'] = TRUE; - + foreach($sizes as $size => $properties) { - + $directory = dirname($picture->$size); $renamed_path = $directory . '/' . $picture->original_name; rename($picture->$size, $renamed_path); - - - $picture->$size = $renamed_path; + + + $picture->$size = $renamed_path; } - + db_query("UPDATE {gallerix_pictures} SET name = '%s', path = '%s' WHERE pid = %d", $picture->original_name, $picture->original, $pid); - + } @@ -186,37 +186,37 @@ function gallerix_build_restore_name($pi /** - * AJAX call that rebuilds a number of pictures. + * AJAX call that rebuilds a number of pictures. * * @param pid specifies where to start rebuilding. * */ function gallerix_rebuild_build($pid, $threshold = 10) { - + //Load the requested operations. $operations = explode('|#|', $_POST['gallerix_operations']); - - $pictures = db_query_range('SELECT pid FROM {gallerix_pictures} WHERE pid > %d ORDER BY pid', $pid, 0, $threshold); + + $pictures = db_query_range('SELECT pid FROM {gallerix_pictures} WHERE pid > %d ORDER BY pid', $pid, 0, $threshold); $remaining = db_affected_rows(); - - + + if (!$remaining) { $response = array( 'percentage' => 100, 'status' => 'done', 'current' => -1, - ); + ); } else { - $completed = db_result(db_query('SELECT COUNT(pid) FROM {gallerix_pictures} WHERE pid < %d', $pid)); + $completed = db_result(db_query('SELECT COUNT(pid) FROM {gallerix_pictures} WHERE pid < %d', $pid)); $total = db_result(db_query('SELECT COUNT(pid) FROM {gallerix_pictures}')); - - + + $count = 0; - + while ($pid = db_fetch_object($pictures)) { $current = $pid->pid; - + //Securing names is a special operation. if ($operations[0] == 'names') { gallerix_build_restore_name($current); @@ -226,25 +226,25 @@ function gallerix_rebuild_build($pid, $t } $count++; } - + //Factor in the pictures we just processed. $completed += $count; - + $percentage = ceil(($completed/$total) * 100); - $percentage = (int) $percentage; - + $percentage = (int) $percentage; + $response = array( 'completed' => $completed, 'total' => $total, - 'percentage' => $percentage, - 'status' => 'continue', + 'percentage' => $percentage, + 'status' => 'continue', 'current' => $current, ); - + } - - - print gallerix_to_js($response); + + + drupal_json($response); exit(); @@ -283,21 +283,21 @@ function gallerix_build_album($node) { drupal_set_title(t('Building Album')); - //Load common.js. - gallerix_load_js(); - + //Load common.js. + gallerix_load_js(); + //Include rebuilding JavaScript and CSS. $path = drupal_get_path('module', 'gallerix'); drupal_add_js($path . '/js/build.js'); - + drupal_add_js(array('gallerixBuild' => array( 'buildURL' => url('node/' . $node->nid . '/pictures/build/picture/'), - 'finalizeURL' => url('node/' . $node->nid . '/pictures/build/finalize'), + 'finalizeURL' => url('node/' . $node->nid . '/pictures/build/finalize'), )), 'setting'); $output .= theme('progress_bar', 0, t('Building')); - $output .= drupal_get_form('gallerix_build_album_form'); - + $output .= drupal_get_form('gallerix_build_album_form'); + return $output; } @@ -313,13 +313,13 @@ function gallerix_build_album_form() { $form = array( '#action' => url('node/' . arg(1) . '/pictures/build/finalize'), ); - + $form['submit'] = array( '#type' => 'submit', '#value' => t('Rebuild'), '#id' => 'gallerix-rebuild', '#attributes' => array('style' => 'display: none;'), - ); + ); return $form; } @@ -331,11 +331,11 @@ function gallerix_build_album_form() { */ function gallerix_build_album_form_submit($form_id, &$form_state) { $nid = arg(1); - + $node = node_load($nid); gallerix_sort_album($node); - + $form_state['redirect'] = 'node/' . $nid . '/pictures/manage'; } @@ -351,54 +351,54 @@ function gallerix_build_album_picture($p $threshold = variable_get('gallerix_rebuild_threshold', 10); $built = variable_get('gallerix_rebuild', 0); $nid = arg(1); - - - $pictures = db_query_range('SELECT pid FROM {gallerix_pictures} WHERE pid > %d AND built <= %d AND nid = %d ORDER BY pid', $pid, $built, $nid, 0, $threshold); + + + $pictures = db_query_range('SELECT pid FROM {gallerix_pictures} WHERE pid > %d AND built <= %d AND nid = %d ORDER BY pid', $pid, $built, $nid, 0, $threshold); $remaining = db_affected_rows(); - - + + if (!$remaining) { $response = array( 'percentage' => 100, 'status' => 'done', 'current' => -1, - ); + ); } - else { + else { $remaining = db_result(db_query('SELECT COUNT(pid) FROM {gallerix_pictures} WHERE nid = %d AND built <= %d', $nid, 0)); $count = 0; - + while ($pid = db_fetch_object($pictures)) { //DO STUFF HERE. $current = $pid->pid; - + gallerix_build_picture($current); $count++; } - - $total = $completed + $remaining; - + + $total = $completed + $remaining; + //Factor in the pictures we just processed. $completed += $count; - + $percentage = ceil(($completed/$total) * 100); - $percentage = (int) $percentage; - + $percentage = (int) $percentage; + $response = array( 'completed' => $completed, 'total' => $total, 'remaining' => $remaining, - 'percentage' => $percentage, - 'status' => 'continue', + 'percentage' => $percentage, + 'status' => 'continue', 'current' => $current, ); - + } - - - print gallerix_to_js($response); + + + drupal_json($response); exit(); @@ -423,18 +423,18 @@ function gallerix_build_album_picture($p * */ function gallerix_build_picture($pid, $operations = array('derivatives', 'iptc', 'exif', 'sort'), $source = 'original') { - + $picture = gallerix_load_picture($pid); - + // Build derivatives. if (in_array('derivatives', $operations)) { $sizes = gallerix_sizes(); - + $album_path = file_directory_path() . '/gallerix/albums/' . $picture->uid . '/' . $picture->nid; - + // Delete old derivatives. $directory = dir($album_path); - + while (FALSE !== ($entry = $directory->read())) { if ($entry == '.' || $entry == '..' || isset($sizes[$entry]) || $entry == 'original') { continue; @@ -443,19 +443,19 @@ function gallerix_build_picture($pid, $o } $directory->close(); - + foreach ($sizes as $size => $properties) { - + // Don't rebuild the source. if ($size == $source) { continue; } - + file_check_directory(dirname($picture->$size), FILE_CREATE_DIRECTORY); - + // Check if resizing is necessary. $info = image_get_info($picture->$source); - + if ($properties['width'] >= $info['width'] && $properties['height'] >= $info['height']) { $success = file_copy($picture->$source, $picture->$size, FILE_EXISTS_REPLACE); } @@ -463,96 +463,96 @@ function gallerix_build_picture($pid, $o $success = gallerix_ratio_resize($picture->$source, $picture->$size, $properties['width'], $properties['height']); } else { - $success = image_scale($picture->$source, $picture->$size, $properties['width'], $properties['height']); - db_query("UPDATE {gallerix_pictures} SET built = %d WHERE pid = %d", time(), $pid); - + $success = image_scale($picture->$source, $picture->$size, $properties['width'], $properties['height']); + db_query("UPDATE {gallerix_pictures} SET built = %d WHERE pid = %d", time(), $pid); + } - + if (!$success) { watchdog('gallerix', 'Error rebuilding !picture into size "!size"', array('!picture' => $picture->pid, '!size' => $size), WATCHDOG_ERROR); } else { - chmod($picture->$size, 0777); + chmod($picture->$size, 0777); } - + } } - - - + + + $caption = ''; - + //Extract EXIF data. if (in_array('exif', $operations) && variable_get('gallerix_extract_exif', 0)) { $exif = gallerix_extract_exif($pid); - - + + //Caption handling. Can be overriden by an IPTC caption below. if (isset($exif['ImageDescription']) && in_array('iptc', $operations)) { $caption = $exif['ImageDescription']; } - + //If the picture contains the time taken, update the database to reflect this time. if (isset($exif['EXIF']['DateTimeOriginal'])) { - + $created = _gallerix_exif_date($exif['EXIF']['DateTimeOriginal']); $exif = serialize($exif); - - db_query("UPDATE {gallerix_pictures} SET exif = '%s', created = %d WHERE pid = %d", $exif, $created, $pid); + + db_query("UPDATE {gallerix_pictures} SET exif = '%s', created = %d WHERE pid = %d", $exif, $created, $pid); } else { - + $exif = serialize($exif); - db_query("UPDATE {gallerix_pictures} SET exif = '%s' WHERE pid = %d", $exif, $pid); + db_query("UPDATE {gallerix_pictures} SET exif = '%s' WHERE pid = %d", $exif, $pid); } - - - } - - + + + } + + //Extract IPTC data. if (in_array('iptc', $operations) && variable_get('gallerix_extract_iptc', 0)) { $tags = gallerix_extract_iptc($pid); - - //Caption handling. + + //Caption handling. if (isset($tags['2#120'])) { //First try the standard 2#120 caption tag. $caption = $tags['2#120'][0]; } elseif (isset($tags['2#005'])) { //Then try the less standard 2#005 tag. $caption = $tags['2#005'][0]; } - + $tags = serialize($tags); - - db_query("UPDATE {gallerix_pictures} SET iptc = '%s' WHERE pid = %d", $tags, $pid); + + db_query("UPDATE {gallerix_pictures} SET iptc = '%s' WHERE pid = %d", $tags, $pid); } - - + + $caption = check_plain($caption); $caption = trim($caption); - + //Update the caption if necessary. if (!$picture->caption && $caption) { - + db_query("UPDATE {gallerix_pictures} SET caption = '%s' WHERE pid = %d", $caption, $pid); - + } - - + + //Only sort if it's been requested AND this is the last picture in the album. if (in_array('sort', $operations) && !db_result(db_query("SELECT pid FROM {gallerix_pictures} WHERE nid = %d AND pid > %d", $picture->nid, $picture->pid))) { $node = node_load($picture->nid); gallerix_sort_album($node); - - + + } - + //Clear messages. drupal_get_messages('status'); - - + + return $success; } @@ -563,23 +563,23 @@ function gallerix_build_picture($pid, $o /** - * Maintains source ratio of the original picture when resizing. + * Maintains source ratio of the original picture when resizing. * It then crops it into the correct width and height. Although some content * might be cut out, this system has aesthetical advantages. * By default, thumbnails use this system. * * @param source indicates where to find the picture. - * + * * @param destination indicates where to save the picture. - * + * * @param width the exact horizontal length of the derivative. - * + * * @param height the exact vertical length of the derivative. - * + * * @param x the offset to use horizontally when cropping. - * + * * @param y the offset to use vertically when cropping. - * + * */ function gallerix_ratio_resize($source, $destination, $width, $height, $x = 0, $y = 0) { @@ -592,7 +592,7 @@ function gallerix_ratio_resize($source, $success = false; $success = image_scale($source, $destination, $scaleWidth, $scaleHeight); - $success = image_crop($destination, $destination, $x, $y, $width, $height); + $success = image_crop($destination, $destination, $x, $y, $width, $height); return $success; @@ -607,7 +607,7 @@ function gallerix_ratio_resize($source, /** * Rotate an image and rebuild all derivatives. Note that the actual original * image is not rotated, instead, the Frame derivative is used as the source. - * + * * @param pid the picture to be rotated. * * @param angle the amount to rotate the picture. @@ -617,8 +617,8 @@ function gallerix_ratio_resize($source, */ function gallerix_rotate_picture($pid, $angle) { $picture = gallerix_load_picture($pid); - - + + $success = image_rotate($picture->frame, $picture->frame, $angle); $success = gallerix_build_picture($picture->pid, array('derivatives'), 'frame'); @@ -639,30 +639,30 @@ function gallerix_rotate_picture($pid, $ */ function gallerix_extract_exif($pid) { $picture = gallerix_load_picture($pid); - + $unprocessed = @exif_read_data($picture->original, '', TRUE); $exif = array(); - - //Can't parse marker notes. + + //Can't parse marker notes. unset($unprocessed['EXIF']['MakerNote']); - + //Remove undefined tags from each section. foreach($unprocessed as $section => $section_data) { - + foreach($section_data as $key => $data) { - + //Only include defined tags. if (!preg_match('/^UndefinedTag.*/', $key)) { $exif[$section][$key] = utf8_encode($data); - } - + } + } - + } - + return $exif; - -} + +} @@ -676,28 +676,28 @@ function gallerix_extract_iptc($pid) { $size = getimagesize($picture->original, $data); $tags = array(); - - if(is_array($data)) { - + + if(is_array($data)) { + $iptc = iptcparse($data["APP13"]); - + if (is_array($iptc)) { foreach ($iptc as $key => $type) { - + foreach ($type as $tag) { - $tags[$key][] = utf8_encode($tag); + $tags[$key][] = utf8_encode($tag); } - + } } - + } - + //We never want the 2#000 tag, which does not contain useful information. - unset($tags['2#000']); + unset($tags['2#000']); - return $tags; -} + return $tags; +} @@ -713,12 +713,12 @@ function _gallerix_exif_date($date) { $date = split(" ", $date); $first_half = $date[0]; $second_half = $date[1]; - + $first_half = str_replace(":", "-", $first_half); $date = $first_half . ' ' . $second_half; - + return strtotime($date); - + } Index: gallerix.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/gallerix/gallerix.module,v retrieving revision 1.14 diff -u -p -r1.14 gallerix.module --- gallerix.module 18 Oct 2008 18:25:04 -0000 1.14 +++ gallerix.module 30 Oct 2009 04:50:23 -0000 @@ -6,16 +6,17 @@ * Provides a photo gallery. */ - - -/** - * Implementation of hook_caches(). - * - */ -function gallerix_flush_caches() { - return array('cache_gallerix'); -} - + + +/** + * Implementation of hook_caches(). + * + */ +function gallerix_flush_caches() { + return array('cache_gallerix'); +} + + /** * Implementation of hook_perm(). @@ -46,10 +47,10 @@ function gallerix_access($op, $node) { function gallerix_boot() { global $user; - - // This is for Mosso users. + + // This is for Mosso users. if (isset($_SERVER['HTTP_X_CLUSTER_CLIENT_IP'])) { - $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; + $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_CLUSTER_CLIENT_IP']; $user->hostname = $_SERVER['REMOTE_ADDR']; } @@ -62,10 +63,10 @@ function gallerix_init() { $path = drupal_get_path('module', 'gallerix'); - + // Includes include_once($path . '/management.inc'); - include_once($path . '/build.inc'); + include_once($path . '/build.inc'); } @@ -78,35 +79,35 @@ function gallerix_menu() { $items = array(); $items['admin/gallerix'] = array( - 'title' => 'Gallerix', + 'title' => 'Gallerix', 'description' => 'Administer Gallerix Settings.', 'page callback' => 'system_admin_menu_block_page', 'position' => 'left', 'access arguments' => array('configure gallerix'), 'file' => 'system.admin.inc', - 'file path' => drupal_get_path('module', 'system'), + 'file path' => drupal_get_path('module', 'system'), ); $items['admin/gallerix/general'] = array( - 'title' => 'General Settings', + 'title' => 'General Settings', 'description' => 'Configure your galleries.', 'page callback' => 'drupal_get_form', 'page arguments' => array('gallerix_admin_settings'), 'access arguments' => array('configure gallerix'), ); $items['admin/gallerix/display'] = array( - 'title' => 'Display Settings', + 'title' => 'Display Settings', 'description' => 'Change display options.', 'page callback' => 'drupal_get_form', 'page arguments' => array('gallerix_display_settings'), 'access arguments' => array('configure gallerix'), ); $items['admin/gallerix/rebuild'] = array( - 'title' => 'Rebuild Pictures', + 'title' => 'Rebuild Pictures', 'description' => "Rebuild the entire picture collection on this site.", 'page callback' => 'gallerix_rebuild', 'access arguments' => array('configure gallerix'), - ); - + ); + // AJAX Rebuild Functions $items['admin/gallerix/rebuild/build'] = array( 'page callback' => 'gallerix_rebuild_build', @@ -118,21 +119,21 @@ function gallerix_menu() { 'page callback' => 'gallerix_rebuild_finalize', 'type' => MENU_CALLBACK, 'access arguments' => array('configure gallerix'), - ); - + ); + $items['node/%node/pictures'] = array( 'title' => 'Pictures', 'page callback' => 'drupal_get_form', 'page arguments' => array('gallerix_add_pictures_form', 1), 'type' => MENU_LOCAL_TASK, 'access callback' => '_gallerix_menu_access', - 'access arguments' => array(1), - ); + 'access arguments' => array(1), + ); $items['node/%node/pictures/add'] = array( 'title' => 'Add', 'type' => MENU_DEFAULT_LOCAL_TASK, 'access callback' => '_gallerix_menu_access', - 'access arguments' => array(1), + 'access arguments' => array(1), ); $items['node/%node/pictures/manage'] = array( @@ -141,21 +142,21 @@ function gallerix_menu() { 'page arguments' => array('gallerix_manage_pictures_form', 1), 'type' => MENU_LOCAL_TASK, 'access callback' => '_gallerix_menu_access', - 'access arguments' => array(1, 'manage'), - ); + 'access arguments' => array(1, 'manage'), + ); $items['node/%node/pictures/manage/submit'] = array( 'page callback' => 'gallerix_manage_form_submit', 'type' => MENU_CALLBACK, 'access callback' => '_gallerix_menu_access', - 'access arguments' => array(1, 'manage'), - ); + 'access arguments' => array(1, 'manage'), + ); $items['node/%node/pictures/manage/delete'] = array( 'page callback' => 'gallerix_manage_form_delete', 'type' => MENU_CALLBACK, 'access callback' => '_gallerix_menu_access', - 'access arguments' => array(1, 'manage'), + 'access arguments' => array(1, 'manage'), ); - + // Album Building. $items['node/%node/pictures/build'] = array( 'page callback' => 'gallerix_build_album', @@ -163,41 +164,41 @@ function gallerix_menu() { 'title' => t('Build'), 'type' => MENU_LOCAL_TASK, 'access callback' => '_gallerix_menu_access', - 'access arguments' => array(1, 'build'), + 'access arguments' => array(1, 'build'), ); $items['node/%node/pictures/build/picture'] = array( 'page callback' => 'gallerix_build_album_picture', 'type' => MENU_CALLBACK, 'access callback' => '_gallerix_menu_access', 'access arguments' => array(1), - ); + ); $items['node/%node/pictures/build/finalize'] = array( 'type' => MENU_CALLBACK, 'access callback' => '_gallerix_menu_access', - 'access arguments' => array(1), - ); - - - + 'access arguments' => array(1), + ); + + + // Used by the finalize form. $items['node/%node/pictures/build/finalize'] = array( 'type' => MENU_CALLBACK, 'access callback' => '_gallerix_menu_access', - 'access arguments' => array(1), - ); - + 'access arguments' => array(1), + ); + // AJAX Functions $items['gallerix/grid'] = array( 'page callback' => 'gallerix_fetch_grid', 'type' => MENU_CALLBACK, 'access arguments' => array('access content'), - ); + ); $items['gallerix/picture'] = array( 'page callback' => 'gallerix_fetch_picture', 'type' => MENU_CALLBACK, 'access arguments' => array('access content'), ); - + return $items; } @@ -215,7 +216,7 @@ function _gallerix_menu_access($node, $o } $access = node_access('update', $node); - + // If the user can't update the node, none of these actions can be performed anyway. if (!$access) { return FALSE; @@ -234,7 +235,7 @@ function _gallerix_menu_access($node, $o default: return $access; } -} +} @@ -248,7 +249,7 @@ function _gallerix_menu_access($node, $o function gallerix_node_info() { // We return an array since a module can define multiple node types. // We're only defining one node type, type 'gallerix'. - + return array( 'album' => array( 'name' => t('Album'), // Required. @@ -262,7 +263,7 @@ function gallerix_node_info() { 'locked' => TRUE ) ); - + } @@ -281,62 +282,62 @@ function gallerix_theme($existing, $type ), 'gallerix_components' => array( 'arguments' => array('components' => NULL), - ), + ), 'gallerix_album_teaser' => array( 'arguments' => array('node' => NULL), - ), + ), 'gallerix_grid' => array( 'arguments' => array('node' => NULL), - ), + ), 'gallerix_links' => array( 'arguments' => array('node' => NULL), - ), + ), 'gallerix_frame' => array( 'arguments' => array('node' => NULL), - ), + ), 'gallerix_empty_album' => array( 'arguments' => array('node' => NULL), - ), + ), 'gallerix_user_pictures_block' => array( 'arguments' => array(), - ), + ), 'gallerix_latest_pictures_block' => array( 'arguments' => array(), ), 'gallerix_random_pictures_block' => array( 'arguments' => array(), - ), + ), 'gallerix_component_settings' => array( 'arguments' => array('form' => NULL), - ), + ), 'gallerix_sizes_table' => array( 'arguments' => array('form' => NULL), - ), + ), 'gallerix_add_pictures_form' => array( 'arguments' => array('form' => NULL), - ), + ), 'gallerix_manage_pictures_form' => array( 'arguments' => array('form' => NULL), - ), + ), 'gallerix_manage_pictures_help' => array( 'arguments' => array(), - ), - 'gallerix_albums_grid' => array( - 'arguments' => array('node' => NULL, 'size' => 'thumbnail'), - ), - ); -} - - -/** - * Implementation of hook_views_api(). - * - */ -function gallerix_views_api() { - return array( - 'api' => 2, - 'path' => drupal_get_path('module', 'gallerix'), - ); + ), + 'gallerix_albums_grid' => array( + 'arguments' => array('node' => NULL, 'size' => 'thumbnail'), + ), + ); +} + + +/** + * Implementation of hook_views_api(). + * + */ +function gallerix_views_api() { + return array( + 'api' => 2, + 'path' => drupal_get_path('module', 'gallerix'), + ); } @@ -345,37 +346,37 @@ function gallerix_views_api() { * The main AJAX function for Gallerix. * @param pid the key of the picture to load. * - * @param json whether to print the final array to JSON or just return it. + * @param json whether to print the final array to JSON or just return it. * */ function gallerix_fetch_picture($pid, $json = TRUE) { if (!gallerix_verify($pid)) { - print gallerix_to_js(array( + drupal_json(array( 'success' => FALSE, 'message' => t('Access Denied'), - + )); - exit(); + exit(); } - + $cache = variable_get('gallerix_cache', 0); - + // Return cached data, if any. if ($cache && $picture = cache_get($pid, 'cache_gallerix')) { print "From Cache \n"; - print gallerix_to_js($picture->data); + drupal_json($picture->data); exit(); - } + } $picture = gallerix_load_picture($pid, FALSE); - + $album = db_query('SELECT nid, path FROM {gallerix_albums} WHERE nid = %d', $picture->nid); $album = db_fetch_object($album); $node = node_load($picture->nid); $paths = _gallerix_album_paths($node); - + $data = array( 'success' => TRUE, 'caption' => $picture->caption, @@ -385,23 +386,23 @@ function gallerix_fetch_picture($pid, $j 'key' => $pid, 'count' => $picture->count, ); - - + + $components = module_invoke_all('gallerix_component', 'load', $picture); foreach ($components as $component) { $data = array_merge($data, $component); } - - + + // Cache all the picture information. if ($cache) { cache_set($pid, $data, 'cache_gallerix', CACHE_TEMPORARY); } - + if ($json) { - print gallerix_to_js($data); - exit(); + drupal_json($data); + exit(); } else { return $data; @@ -417,9 +418,9 @@ function gallerix_fetch_picture($pid, $j function _gallerix_load_frame($picture) { $local = gallerix_load_picture($picture->pid); - - list($width, $height) = @getimagesize($local->frame); - + + list($width, $height) = @getimagesize($local->frame); + return array( 'framePath' => $picture->frame, 'frameWidth' => $width, @@ -450,14 +451,14 @@ function _gallerix_load_thumbnails($pict ); $previous_count = 0; - + for ($x = $current; $x > 0; $x--) { - + $previous_sort = $picture->sort - $x; - + if ($previous_sort <= 0) { $previous_sort += $picture->count; - } + } $previous_pid = db_result(db_query('SELECT pid FROM {gallerix_pictures} WHERE nid = %d AND sort = %d', $picture->nid, $previous_sort)); $previous = gallerix_load_picture($previous_pid, $picture->local); @@ -466,51 +467,51 @@ function _gallerix_load_thumbnails($pict 'path' => $previous->thumbnail, 'link' => gallerix_url($previous->pid), 'caption' => $previous->caption, - 'key' => gallerix_url($previous->pid, 'fragment'), - ); + 'key' => gallerix_url($previous->pid, 'fragment'), + ); $previous_count++; } for ($x = $current + 1; $x < $thumbnail_number; $x++) { $next_sort = $picture->sort + ($x - $current); - + if ($next_sort > $picture->count) { $next_sort -= $picture->count; } - + $next_pid = db_result(db_query('SELECT pid FROM {gallerix_pictures} WHERE nid = %d AND sort = %d', $picture->nid, $next_sort)); $next = gallerix_load_picture($next_pid, $picture->local); - + $thumbnails['gallerix-thumbnail-link-' . $x] = array( 'path' => $next->thumbnail, 'link' => gallerix_url($next->pid), 'caption' => $next->caption, - 'key' => gallerix_url($next->pid, 'fragment'), - ); + 'key' => gallerix_url($next->pid, 'fragment'), + ); } - - + + return array( 'thumbnails' => $thumbnails, 'thumbnails_count' => $thumbnail_number, ); - + } function gallerix_fetch_grid($nid) { - + //Make sure it's a valid grid request. $nid = gallerix_verify($nid, 'grid'); - + if ($nid) { $node = node_load($nid); - + $output = ''; $output .= theme('gallerix_grid', $node); - + print $output; } @@ -528,7 +529,7 @@ function gallerix_block($op = 'list', $d $blocks[0]['info'] = t('Latest Pictures'); $blocks[1]['info'] = t('Random Pictures'); - return $blocks; + return $blocks; } elseif ($op == 'configure') { switch ($delta) { @@ -540,7 +541,7 @@ function gallerix_block($op = 'list', $d If viewing a profile, only pictures posted by that user will show. If set to "User Pages", the block will only show when viewing a profile.'), '#default_value' => variable_get('gallerix_block_user_pictures_block_mode', 'all'), '#options' => array('all' => t('All Pages'), 'user' => t('User Pages')), - ); + ); $form['latest'] = array( '#type' => 'select', '#title' => t('Number of Pictures'), @@ -554,16 +555,16 @@ function gallerix_block($op = 'list', $d '#type' => 'select', '#title' => t('Number of Pictures'), '#default_value' => variable_get('gallerix_block_random_pictures_block', 5), - '#options' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), + '#options' => array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), ); break; } - - - } - - return $form; - + + + } + + return $form; + } elseif ($op == 'save') { switch ($delta) { @@ -571,13 +572,13 @@ function gallerix_block($op = 'list', $d variable_set('gallerix_block_user_pictures_block_mode', $edit['latest_mode']); variable_set('gallerix_block_user_pictures_block', $edit['latest']); break; - } + } case 1: { variable_set('gallerix_block_random_pictures_block', $edit['random']); break; } - } - + } + } elseif ($op == 'view') { switch ($delta) { @@ -597,14 +598,14 @@ function gallerix_block($op = 'list', $d $block['subject'] = t('Random Pictures'); $block['content'] = theme('gallerix_random_pictures_block'); } - } - break; + } + break; } - + return $block; } - - + + } @@ -616,40 +617,40 @@ function gallerix_block($op = 'list', $d function theme_gallerix_user_pictures_block() { gallerix_load_js(); gallerix_load_style(); - + $output = ''; $output .= '
'; - + $count = variable_get('gallerix_block_user_pictures_block', 5) + 1; - + $sql = db_rewrite_sql("SELECT g.pid FROM {gallerix_pictures} g INNER JOIN {node} n ON g.nid = n.nid WHERE g.uid = %d GROUP BY g.pid ORDER BY added DESC"); $pictures = db_query_range($sql, arg(1), 0, $count); - + $count = 0; - + $translucent = variable_get('gallerix_translucence', 1) ? ' translucent' : ''; - + while ($pid = db_fetch_object($pictures)) { $picture = gallerix_load_picture($pid->pid); - + $thumbnail = theme('image', $picture->thumbnail, '', $picture->caption, array('class' => 'gallerix-external-thumbnail' . $translucent)); - + $link = 'node/' . $picture->nid; $fragment = gallerix_url($picture, 'fragment'); $fetch_link = gallerix_url($picture, 'link', false); - + $output .= l($thumbnail, $link, array('attributes' => array('class' => 'gallerix-external-picture-link'), 'query' => 'picture=' . $picture->pid, 'html' => TRUE)); $count++; } - + $output .= '
'; - + if ($count) { return $output; } - + return ''; } @@ -660,39 +661,39 @@ function theme_gallerix_latest_pictures_ $output = ''; $output .= '
'; - + $count = variable_get('gallerix_block_user_pictures_block', 5) + 1; - - + + $sql = db_rewrite_sql("SELECT g.pid FROM {gallerix_pictures} g INNER JOIN {node} n ON g.nid = n.nid GROUP BY g.pid ORDER BY added DESC"); $pictures = db_query_range($sql, 0, $count); - + $count = 0; $translucent = variable_get('gallerix_translucence', 1) ? ' translucent' : ''; - + while ($pid = db_fetch_object($pictures)) { - + $picture = gallerix_load_picture($pid->pid); - + $thumbnail = theme('image', $picture->thumbnail, '', $picture->caption, array('class' => 'gallerix-external-thumbnail' . $translucent)); - + $link = 'node/' . $picture->nid; $fragment = gallerix_url($picture, 'fragment'); - $fetch_link = gallerix_url($picture, 'link', false); - + $fetch_link = gallerix_url($picture, 'link', false); + $output .= l($thumbnail, $link, array('attributes' => array('class' => 'gallerix-external-picture-link'), 'query' => 'picture=' . $picture->pid, 'html' => TRUE)); $count++; } - + $output .= '
'; - - + + if ($count) { return $output; } - + return ''; } @@ -706,20 +707,20 @@ function theme_gallerix_latest_pictures_ function theme_gallerix_random_pictures_block() { gallerix_load_js(); gallerix_load_style(); - + $output = ''; $output .= '
'; - - + + $count = variable_get('gallerix_block_random_pictures_block', 5) + 1; $translucent = variable_get('gallerix_translucence', 1) ? ' translucent' : ''; $sql = db_rewrite_sql("SELECT g.pid FROM {gallerix_pictures} g INNER JOIN {node} n ON g.nid = n.nid GROUP BY g.pid ORDER BY added DESC"); $pictures = db_query($sql); - + $temp = array(); - - + + while ($picture = db_fetch_object($pictures)) { $temp[] = $picture->pid; } @@ -727,28 +728,28 @@ function theme_gallerix_random_pictures_ $pictures = array_slice($temp, 0, $count); $count = 0; - + foreach($pictures as $pid) { $picture = gallerix_load_picture($pid); - + $thumbnail = theme('image', $picture->thumbnail, '', $picture->caption, array('class' => 'gallerix-external-thumbnail' . $translucent)); $link = 'node/' . $picture->nid; $fragment = gallerix_url($picture, 'fragment'); - $fetch_link = gallerix_url($picture, 'link', false); - + $fetch_link = gallerix_url($picture, 'link', false); + $output .= l($thumbnail, $link, array('attributes' => array('class' => 'gallerix-external-picture-link'), 'query' => 'picture=' . $picture->pid, 'html' => TRUE)); $count++; } - + $output .= '
'; - + if ($count) { return $output; } - + return ''; } @@ -770,19 +771,19 @@ function gallerix_prepare(&$node) { * */ function gallerix_form($node) { - + //First time we're entering the form. - if (!isset($node->nid)) { + if (!isset($node->nid)) { $settings = array(); $settings['gallerix']['sort'] = 'default'; } else { $settings = $node->gallerix; } - - + + $form['#attributes'] = array("enctype" => "multipart/form-data"); - + $form['title'] = array( '#type' => 'textfield', @@ -799,7 +800,7 @@ function gallerix_form($node) { '#description' => t('Override the selected default sort order in the Gallerix Settings Page.'), '#options' => array('ascending' => t('Date Taken Ascending'), 'descending' => t('Date Taken Descending'), 'random' => t('Random'), 'filename' => t('Filename'), 'default' => t('Default'), 'custom' => t('Custom')), '#default_value' => $settings['sort'], - ); + ); $form['body_filter']['body'] = array( '#type' => 'textarea', '#title' => t('Album Description'), @@ -808,8 +809,8 @@ function gallerix_form($node) { '#rows' => 5, ); $form['body_filter']['filter'] = filter_form($node->format); - - + + return $form; } @@ -835,25 +836,25 @@ function gallerix_validate(&$node) { function gallerix_insert($node) { $path = file_directory_path() . '/gallerix/albums/' . $node->uid; - + if (!file_exists($path)) { mkdir($path); - chmod($path, 0777); + chmod($path, 0777); } - - $path .= '/' . $node->nid; - + + $path .= '/' . $node->nid; + if (!file_exists($path)) { mkdir($path); chmod($path, 0777); mkdir($path . '/original'); - chmod($path . '/original', 0777); + chmod($path . '/original', 0777); } $paths = _gallerix_album_paths($node); $path = $paths['album']; - + $settings['sort'] = $node->sort_order; $settings = serialize($settings); db_query("INSERT INTO {gallerix_albums} (nid, path, settings) VALUES (%d, '%s', '%s')", $node->nid, $path, $settings); @@ -867,17 +868,17 @@ function gallerix_insert($node) { * * Resave the settings if they have been changed. */ -function gallerix_update($node) { +function gallerix_update($node) { $settings['sort'] = $node->sort_order; $settings = serialize($settings); - + db_query("UPDATE {gallerix_albums} SET settings = '%s' WHERE nid = %d", $settings, $node->nid); - - + + //If the sort order has been changed, resort the album. if ($node->sort_order != $node->gallerix['sort']) { gallerix_sort_album($node); - } + } } @@ -889,15 +890,15 @@ function gallerix_update($node) { * Only needs to load in the settings, and the default image/ */ function gallerix_load($node) { - + $settings = db_fetch_array(db_query('SELECT settings FROM {gallerix_albums} WHERE nid = %d', $node->nid)); $settings = unserialize($settings['settings']); - + $node->gallerix = $settings; - + $default = db_result(db_query("SELECT pid FROM {gallerix_pictures} WHERE nid = %d AND sort = %d", $node->nid, 1)); - $node->gallerix['count'] = db_result(db_query('SELECT COUNT(pid) FROM {gallerix_pictures} WHERE nid = %d', $node->nid)); + $node->gallerix['count'] = db_result(db_query('SELECT COUNT(pid) FROM {gallerix_pictures} WHERE nid = %d', $node->nid)); $node->gallerix['default'] = $default ? $default : 0; @@ -911,24 +912,24 @@ function gallerix_load($node) { * The node is being deleted, remove all images associated with this node. */ function gallerix_delete($node) { - + $pictures = db_query('SELECT pid FROM {gallerix_pictures} WHERE nid = %d', $node->nid); - + //Delete each picture in the album. while ($pid = db_fetch_object($pictures)) { gallerix_delete_picture($pid->pid); } - + $paths = _gallerix_album_paths($node, true); - $path = $paths['album']; - - db_query("DELETE FROM {gallerix_albums} WHERE nid = %d", $node->nid); - + $path = $paths['album']; + + db_query("DELETE FROM {gallerix_albums} WHERE nid = %d", $node->nid); + if (file_exists($path)) { - gallerix_delete_directory($path); - } - -} + gallerix_delete_directory($path); + } + +} @@ -937,7 +938,7 @@ function gallerix_delete($node) { function gallerix_album_settings($node) { $settings = db_fetch_array(db_query('SELECT settings FROM {gallerix_albums} WHERE nid = %d', $node->nid)); $settings = unserialize($settings['settings']); - + return $settings; } @@ -955,20 +956,20 @@ function gallerix_link($type, $node = NU $links = array(); - if ($type == 'node' && !$teaser && $node->type == 'album' && $node->gallerix['default']) { - + if ($type == 'node' && !$teaser && $node->type == 'album' && $node->gallerix['default']) { + if ($node->gallerix['mode'] == 'grid') { $title = t('Single Photo'); $href = 'node/' . $node->nid; - $query = "picture=" . $node->gallerix['default']; + $query = "picture=" . $node->gallerix['default']; } else { - $title = t('All Photos'); + $title = t('All Photos'); $href = gallerix_url($node->nid, 'grid', false); - $query = "picture=grid"; + $query = "picture=grid"; } - + $links['grid_view'] = array( 'title' => $title, 'href' => $href, @@ -976,7 +977,7 @@ function gallerix_link($type, $node = NU 'attributes' => array('id' => 'gallerix-grid-link', 'class' => 'gallerix-grid-link'), ); } - + return $links; } @@ -1005,18 +1006,18 @@ function gallerix_link_alter(&$links, $n function gallerix_view($node, $teaser = FALSE, $page = FALSE) { $path = drupal_get_path('module', 'gallerix'); - + $get = url('gallerix_fetch/'); - + $thumbnail_size = variable_get('gallerix_thumbnail_resolution', array(100, 70)); - + $thumbnail_number = variable_get('gallerix_thumbnail_number', 5); $display_thumbnails = variable_get('gallerix_display_thumbnails', 1); $default_view = variable_get('gallerix_default_view', 'viewer'); - + if (!$teaser && $node->gallerix['default']) { - + gallerix_load_js(TRUE); drupal_add_js(array('gallerix' => array( 'defaultImage' => gallerix_url($node->gallerix['default'], 'fragment'), @@ -1025,7 +1026,7 @@ function gallerix_view($node, $teaser = )), 'setting'); } - + $content = ''; // Album is empty. @@ -1033,7 +1034,7 @@ function gallerix_view($node, $teaser = $content .= theme('gallerix_empty_album', $node); } elseif ($teaser) { - $content .= theme('gallerix_album_teaser', $node); + $content .= theme('gallerix_album_teaser', $node); } else { $node->gallerix['current'] = _gallerix_current(); @@ -1041,8 +1042,8 @@ function gallerix_view($node, $teaser = if ($node->gallerix['current'] == 'grid') { $node->gallerix['mode'] = 'grid'; - $node->gallerix['current'] = $node->gallerix['default']; - + $node->gallerix['current'] = $node->gallerix['default']; + } elseif (!$node->gallerix['current']) { $node->gallerix['mode'] = $default_view; @@ -1051,19 +1052,19 @@ function gallerix_view($node, $teaser = else { $node->gallerix['mode'] = 'viewer'; } - - + + // Load the sorted components. $node->gallerix['components'] = _gallerix_load_components('view', $node); - + $components = $node->gallerix['components']; - + //Register component preparations and callbacks. $preparations = array(); $callbacks = array(); $preparations_count = 0; $callbacks_count = 0; - + foreach($components as $component) { if (isset($component['#prepare'])) { $preparations[$component['#id']] = $component['#prepare']; @@ -1072,9 +1073,9 @@ function gallerix_view($node, $teaser = if (isset($component['#callback'])) { $callbacks[$component['#id']] = $component['#callback']; $callbacks_count++; - } + } } - + drupal_add_js(array('gallerix' => array( @@ -1082,33 +1083,33 @@ function gallerix_view($node, $teaser = 'loaderImage' => base_path() . theme('gallerix_icon', 'loader.gif'), 'currentData' => gallerix_fetch_picture($node->gallerix['current'], false), 'mode' => $node->gallerix['mode'], - 'preparations' => $preparations, + 'preparations' => $preparations, 'callbacks' => $callbacks, 'preparationsCount' => $preparations_count, 'callbacksCount' => $callbacks_count, ), - ), + ), 'setting'); - + //Load styles. gallerix_load_style(); - + $hide_viewer = $node->gallerix['mode'] == 'grid' ? 'style="display: none;"' : ''; $hide_grid = $node->gallerix['mode'] == 'viewer' ? 'style="display: none;"' : ''; - - $content .= theme('gallerix_message_box'); + + $content .= theme('gallerix_message_box'); $content .= '
'; $content .= '
' . "\n"; $content .= theme('gallerix_components', $components); $content .= "
\n"; //End Div Gallerix Viewer - + $content .= '
'; - $content .= theme('gallerix_grid', $node); - $content .= '
'; + $content .= theme('gallerix_grid', $node); + $content .= '
'; //End Div Gallerix Grid $content .= ''; - //End Div Gallerix + //End Div Gallerix } @@ -1117,7 +1118,7 @@ function gallerix_view($node, $teaser = '#value' => $content, '#weight' => -1, ); - + return $node; } @@ -1129,38 +1130,38 @@ function gallerix_view($node, $teaser = * */ function _gallerix_load_components($op = 'view', $node = NULL) { - $components = array(); - $unprocessed = module_invoke_all('gallerix_component', $op, $node); + $components = array(); + $unprocessed = module_invoke_all('gallerix_component', $op, $node); $weights = variable_get('gallerix_layout_weights', array()); $display = variable_get('gallerix_layout_display', array()); - + foreach($unprocessed as $component) { - + //If an access parameter exists, and the user doesn't have access, skip entirely. if (isset($component['#access']) && !$component['#access']) { continue; } - + //Only show components that haven't been flagged otherwise. if ($op == 'configure' || !isset($display[$component['#id']]) || $display[$component['#id']]) { $component['#weight'] = isset($weights[$component['#id']]) ? $weights[$component['#id']] : $component['#weight']; $component['#display'] = !isset($display[$component['#id']]) ? 1 : $display[$component['#id']]; $components[] = $component; - } + } } //Sort by weight. usort($components, '_gallerix_compare_components'); - + $keyed = array(); - + foreach($components as $component) { $keyed[$component['#id']] = $component; } - + return $keyed; - + } @@ -1171,13 +1172,13 @@ function _gallerix_load_components($op = */ function _gallerix_compare_components($a, $b) { $weights = variable_get('gallerix_layout_weights', array()); - + if ($a['#weight'] == $b['#weight']) { return 0; } return ($a['#weight'] < $b['#weight']) ? -1 : 1; - + } @@ -1187,7 +1188,7 @@ function _gallerix_compare_components($a * Implementation of hook_gallerix_component(). * * This renders the default components of Gallerix, including the thumbnails and the main image. - * + * * @param op * The operation being performed. Can be either 'view', 'load' or 'configure'. * @@ -1199,14 +1200,14 @@ function _gallerix_compare_components($a function gallerix_gallerix_component($op, $data = NULL) { $thumbnails = variable_get('gallerix_thumbnail_number', 5); - + if ($op == 'load') { $components = array(); - + $node = node_load($data->nid); - + $components[0] = _gallerix_load_frame($data); - + //Only load thumbnails if there are enough pictures to populate them. if ($node->gallerix['count'] >= floor($thumbnails/2)) { $components[1] = _gallerix_load_thumbnails($data); @@ -1214,9 +1215,9 @@ function gallerix_gallerix_component($op return $components; } - + $components = array(); - + $components[0] = array( '#id' => 'gallerix_frame', '#title' => t('Image'), @@ -1230,18 +1231,18 @@ function gallerix_gallerix_component($op '#weight' => 2, '#callback' => 'updateThumbnails', ); - - + + if ($op == 'view') { $components[0]['#content'] = theme('gallerix_frame', $data); - + //Only show thumbnails if there are enough pictures to populate them. if ($data->gallerix['count'] >= floor($thumbnails/2)) { $components[1]['#content'] = theme('gallerix_links', $data); } } - + return $components; } @@ -1250,7 +1251,7 @@ function gallerix_gallerix_component($op function theme_gallerix_empty_album($node) { $output = ''; $output .= t('This album is currently empty.'); - + return $output; } @@ -1274,14 +1275,14 @@ function theme_gallerix_frame($node) { $source = $picture->frame; $output = ''; - $output .= '
' . "\n" ; - $output .= '
' . "\n" ; + $output .= '
' . "\n" ; + $output .= '
' . "\n" ; $output .= theme('image', $source,'', $picture->caption, array('id' => 'gallerix-frame')); $output .= '
' . "\n" ; $output .= '
' . "\n" ; - + return $output; - + } @@ -1303,16 +1304,16 @@ function theme_gallerix_links($node) { $thumbnails = _gallerix_load_thumbnails($current); $thumbnails = $thumbnails['thumbnails']; ksort($thumbnails); - + $translucent = variable_get('gallerix_translucence', 1) ? ' translucent' : ''; - + $output = ''; $output .= '' . "\n"; - + return $output; -} +} /** @@ -1334,17 +1335,17 @@ function theme_gallerix_links($node) { * */ function theme_gallerix_grid($node) { - + $translucent = variable_get('gallerix_translucence', 1) ? ' translucent' : ''; - + $paths = _gallerix_album_paths($node, true); $output = ''; - + $pictures = db_query("SELECT pid FROM {gallerix_pictures} WHERE nid = %d ORDER BY sort", $node->nid); - + while ($pid = db_fetch_object($pictures)) { $picture = gallerix_load_picture($pid->pid); - + $thumbnail = theme('image', $picture->thumbnail, '', $picture->caption, array('class' => 'gallerix-thumbnail' . $translucent)); $output .= l($thumbnail, 'node/' . $picture->nid, array( 'attributes' => array( @@ -1363,7 +1364,7 @@ function theme_gallerix_grid($node) { /** - * Themes a single picture to be displayed as a teaser. + * Themes a single picture to be displayed as a teaser. * Usually, this method will not be used since Views is used instead. * */ @@ -1371,16 +1372,16 @@ function theme_gallerix_album_teaser($no gallerix_load_style(); $paths = _gallerix_album_paths($node, true); - + $default = gallerix_load_picture($node->gallerix['default']); - + $output = '
'; $teaser_image .= theme('image', $default->frame,'', $default->caption, array('class' => 'gallerix-teaser'), TRUE); - $output .= l($teaser_image, 'node/' . $node->nid, array('html' => TRUE)); - + $output .= l($teaser_image, 'node/' . $node->nid, array('html' => TRUE)); + $output .= '
'; - + return $output; } @@ -1396,10 +1397,10 @@ function theme_gallerix_album_teaser($no */ function theme_gallerix_components($components) { $output = ''; - + foreach($components as $component) { $output .= $component['#content']; - + } return $output; @@ -1417,7 +1418,7 @@ function theme_gallerix_components($comp function theme_gallerix_message_box() { $output = ''; $output .= '
'; - + return $output; } @@ -1429,7 +1430,7 @@ function theme_gallerix_message_box() { */ function theme_gallerix_icon($icon) { $path = path_to_theme() . '/gallerix/' . $icon; - + if (is_file($path)) { return $path; } @@ -1439,7 +1440,7 @@ function theme_gallerix_icon($icon) { return $path . '/images/' . $icon; } - + } @@ -1447,13 +1448,13 @@ function theme_gallerix_icon($icon) { /************************ Security Functions **************************/ -/** +/** * URL generation for all Gallerix AJAX links. All calls to generate a link should * be wrapped in this function to ensure that it's a valid URL. * * @param mixed is a pid or a picture object if parameter type is set to 'link' or 'fragment'. * If type is set to 'grid', then mixed must be an nid or a node. - * + * * @param type indicates what the URL is for. Set to link if you want a full AJAX call url. * If set to fragment, only the key will be returned to append to an existing URL. * Finally, if set to grid, a completely different key will be returned, used to generate a grid. @@ -1465,36 +1466,36 @@ function theme_gallerix_icon($icon) { * */ function gallerix_url($mixed, $type = 'link', $url = TRUE) { - + $secure = variable_get('gallerix_secure_mode', 0); - + // Completely different handling for grid requests. if ($type == 'grid') { - + $node = is_numeric($mixed) ? node_load($mixed) : $mixed; $path = 'node/' . $node->nid; - - return $url ? url($path, array('query' => "picture=grid")) : $path; + + return $url ? url($path, array('query' => "picture=grid")) : $path; } - - + + $picture = is_numeric($mixed) ? gallerix_load_picture($mixed) : $mixed; $key = $picture->pid; - + switch ($type) { case 'link': { $path = 'node/' . $picture->nid; $query = 'picture=' . $picture->pid; - + return $url ? url($path, array('query' => $query)) : $path; } case 'fragment': { return $key; } } - - + + } @@ -1504,8 +1505,8 @@ function gallerix_url($mixed, $type = 'l /** * Verifies an AJAX request. Verification is necessary to prevent unauthorized * users from modifying an AJAX call client side to access pictures they - * are not allowed to view. Additionally, extra measures must be implemented - * to ensure that any AJAX edit request is authorized. + * are not allowed to view. Additionally, extra measures must be implemented + * to ensure that any AJAX edit request is authorized. * * @param key contains either a pid, or an nid. For view and edit requests, * key will be a pid; for grid requests, key will be an nid. @@ -1519,25 +1520,25 @@ function gallerix_url($mixed, $type = 'l function gallerix_verify($key, $type = 'view') { switch ($type) { - case 'view': - $picture = gallerix_load_picture($key); + case 'view': + $picture = gallerix_load_picture($key); $node = node_load($picture->nid); - - return (node_access('view', $node)) ? $picture->pid : 0; - + + return (node_access('view', $node)) ? $picture->pid : 0; + case 'edit': - $picture = gallerix_load_picture($key); + $picture = gallerix_load_picture($key); $node = node_load($picture->nid); - - return (node_access('update', $node)) ? $picture->pid : 0; - + + return (node_access('update', $node)) ? $picture->pid : 0; + case 'grid': { - $node = node_load($key); - - return (node_access('view', $node)) ? $node->nid : 0; + $node = node_load($key); + + return (node_access('view', $node)) ? $node->nid : 0; } - - } + + } } @@ -1557,16 +1558,16 @@ function _gallerix_secure_file($filename $directory = dirname($filename); $basename = basename($filename); - + $length = strlen($basename); $root = substr($basename, 0, $length - 4); $extension = substr($basename, -4); $encrypted_root = sha1($root); - + $new_filename = file_create_filename($encrypted_root . $extension, $directory ); - + rename($filename, $new_filename); - + return $new_filename; } } @@ -1601,11 +1602,11 @@ function gallerix_to_js($data) { */ function gallerix_load_style() { $setting = variable_get('gallerix_style', 'standard.css'); - + if ($setting == 'custom') { $path = variable_get('gallerix_style_path', ''); drupal_add_css($path); - + } else { $path = drupal_get_path('module', 'gallerix'); @@ -1617,14 +1618,14 @@ function gallerix_load_style() { /** - * Loads all common functions without the full Gallerix JavaScript. + * Loads all common functions without the full Gallerix JavaScript. * If full is true, it'll load all the Gallerix JavaScript. * */ function gallerix_load_js($full = FALSE) { $path = drupal_get_path('module', 'gallerix'); - drupal_add_js($path . '/js/common.js'); - + drupal_add_js($path . '/js/common.js'); + if ($full) { drupal_add_js($path . '/js/gallerix.js'); } @@ -1638,7 +1639,7 @@ function gallerix_load_js($full = FALSE) * */ function gallerix_sizes() { - + if ($sizes = variable_get('gallerix_sizes', '')) { return $sizes; } @@ -1674,14 +1675,14 @@ function _gallerix_album_paths(&$node, $ if (!$local) { $base_path .= base_path(); } - + $base_path .= file_directory_path() . '/gallerix/albums/' . $node->uid . '/' . $node->nid; - + $paths = array(); $paths['original'] = $base_path . '/original'; $paths['thumbnail'] = $base_path . '/thumbnails'; $paths['frame'] = $base_path . '/frame'; - $paths['album'] = $base_path; + $paths['album'] = $base_path; return $paths; } @@ -1695,7 +1696,7 @@ function _gallerix_album_paths(&$node, $ */ function _gallerix_picture_paths(&$picture, $local = FALSE) { $paths = _gallerix_album_paths($picture, $local); - + $paths['paths'] = array( 'original' => $paths['original'], 'frame' => $paths['frame'], @@ -1716,50 +1717,50 @@ function _gallerix_picture_paths(&$pictu /** - * Loads a picture object along with all it's information. + * Loads a picture object along with all it's information. * */ function gallerix_load_picture($pid, $local = TRUE) { // Caching. static $pictures = array(); - + $cacheable = ($local == FALSE); - + if ($cacheable && isset($pictures[$pid])) { return $pictures[$pid]; } - - + + $picture = db_fetch_object(db_query("SELECT * FROM {gallerix_pictures} WHERE pid = %d", $pid)); - + $node = node_load($picture->nid); - + $paths = _gallerix_picture_paths($picture, $local); $picture->original = $paths['original']; - + $sizes = gallerix_sizes(); - + foreach ($sizes as $size => $properties) { $picture->$size = $paths['album'] . '/' . $size . '/' . $picture->name; } - $picture->paths = $paths['paths']; + $picture->paths = $paths['paths']; $picture->exif = unserialize($picture->exif); $picture->iptc = unserialize($picture->iptc); $links = db_query('SELECT nid FROM {gallerix_pictures} WHERE nid = %d', $picture->nid); $picture->count = db_affected_rows(); - + $picture->local = $local; - $picture->key = gallerix_url($picture, 'fragment'); - + $picture->key = gallerix_url($picture, 'fragment'); + if ($cacheable) { $pictures[$pid] = $picture; } - return $picture; + return $picture; } @@ -1771,9 +1772,9 @@ function gallerix_load_picture($pid, $lo * */ function _gallerix_current() { - + if (isset($_GET['picture']) && is_numeric($_GET['picture'])) { - + if ($pid = gallerix_verify($_GET['picture'])) { return $pid; } @@ -1798,30 +1799,30 @@ function _gallerix_current() { function gallerix_delete_picture($pid) { $picture = gallerix_load_picture($pid); - + $sizes = gallerix_sizes(); - + foreach ($sizes as $size => $properties) { file_delete($picture->$size); } - + file_delete($picture->original); - + $node = node_load($picture->nid); - + db_query("DELETE FROM {gallerix_pictures} WHERE pid = %d", $picture->pid); - - watchdog('gallerix', 'Picture !picture has been deleted.', array('!picture' => $picture->pid), WATCHDOG_NOTICE); - + + watchdog('gallerix', 'Picture !picture has been deleted.', array('!picture' => $picture->pid), WATCHDOG_NOTICE); + gallerix_sort_album($node); - + module_invoke_all('gallerix_picture', $pid, 'delete'); - + cache_clear_all($pid, 'cache_gallerix'); - + return $success; - - + + } @@ -1846,31 +1847,31 @@ function gallerix_delete_picture($pid) { function gallerix_process_file($source, $destination, $delete = FALSE) { $extension = strtolower(substr($source,-4)); $basename = basename($source); - $directory = dirname($destination); - $archive_allowed = variable_get('gallerix_allow_archives', false); - + $directory = dirname($destination); + $archive_allowed = variable_get('gallerix_allow_archives', false); + $file_info = array( 'basename' => $basename, 'source' => $source, 'directory' => $directory, 'destination' => $destination, - 'extension' => $extension + 'extension' => $extension ); - + $files = array(); - + if ($extension == '.zip' && $archive_allowed) { $files = gallerix_unzip($source, $destination); - + if ($delete) { file_delete($source); } - + return $files; } elseif ($extension == '.jpg' || $extension == '.gif' || $extension == '.png') { - $path = file_create_filename($basename, $destination); + $path = file_create_filename($basename, $destination); if ($delete) { $success = file_move($source, $path); @@ -1878,13 +1879,13 @@ function gallerix_process_file($source, else { $success = file_copy($source, $path); } - + if ($success) { $files[] = $path; return $files; } else { - drupal_set_message(t('Error Uploading File'), 'error'); + drupal_set_message(t('Error Uploading File'), 'error'); return false; } } @@ -1892,7 +1893,7 @@ function gallerix_process_file($source, drupal_set_message(t('Invalid File Upload'), 'error'); return false; } - + } @@ -1907,32 +1908,32 @@ function gallerix_unzip($source, $destin $files = array(); if (version_compare(PHP_VERSION, '5') >= 0) { - - $zip = new ZipArchive(); - if ($zip->open($source)) { - + + $zip = new ZipArchive(); + if ($zip->open($source)) { + for ($x = 0; $x < $zip->numFiles; $x++) { $info = $zip->statIndex($x); - + $extension = strtolower(substr($info['name'], -4)); - + if ($extension == '.jpg' || $extension == '.gif' || $extension == '.png') { $path = file_create_filename($info['name'], $destination); - - $image = fopen($path, 'w'); + + $image = fopen($path, 'w'); fwrite($image, $zip->getFromIndex($x)); - fclose($image); - + fclose($image); + $files[] = $path; - } + } } - $zip->close(); + $zip->close(); } else { drupal_set_message(t('Extraction failed!'), 'error'); - return false; - } + return false; + } } else { @@ -1940,38 +1941,38 @@ function gallerix_unzip($source, $destin while ($file = zip_read($zip)) { - $filename = zip_entry_name($file); + $filename = zip_entry_name($file); $extension = strtolower(substr($filename, -4)); if (($extension == '.jpg' || $extension == '.gif' || $extension == '.png') && zip_entry_open($zip, $file, "r")) { - + $path = file_create_filename($filename, $destination); $size = zip_entry_filesize($file); - - $image = fopen($path, 'w'); + + $image = fopen($path, 'w'); $content = zip_entry_read($file, $size); - + fwrite($image, $content); fclose($image); - + zip_entry_close($file); $files[] = $path; - + } } - + zip_close($zip); - + } else { drupal_set_message(t('Extraction failed!'), 'error'); - return false; + return false; } } - - + + return $files; } @@ -1990,14 +1991,14 @@ function gallerix_delete_directory($dire } $d = dir($directory); - + while (FALSE !== ($entry = $d->read())) { if ($entry == '.' || $entry == '..') { continue; } $entry = $directory . '/' . $entry; if (is_dir($entry)) { - + if (!gallerix_delete_directory($entry)) { return FALSE; } Index: management.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/gallerix/management.inc,v retrieving revision 1.9 diff -u -p -r1.9 management.inc --- management.inc 18 Oct 2008 18:25:04 -0000 1.9 +++ management.inc 30 Oct 2009 04:50:23 -0000 @@ -6,7 +6,7 @@ * @file * Contains all picture management functions for Gallerix, and all settings pages. */ - + /** @@ -26,7 +26,7 @@ function gallerix_display_settings() { '#description' => t("Select which view to default to. Grid view will display all the images in an album. Single View will display the first image of the album, along with thumbnails if enabled below. A link is provided to switch between the two."), '#options' => array('grid' => 'Grid', 'viewer' => 'Single'), '#default_value' => variable_get('gallerix_default_view', 'grid'), - ); + ); $form['gallerix_display']['gallerix_default_sort'] = array( '#type' => 'select', '#title' => t('Default Sort Order'), @@ -40,40 +40,40 @@ function gallerix_display_settings() { '#description' => t('This number controls the amount of thumbnails displayed in each album for browsing. Raising this might decrease performance since there will be more database queries.'), '#size' => 2, '#default_value' => variable_get('gallerix_thumbnail_number', 5), - ); + ); $form['gallerix_display']['gallerix_translucence'] = array( - '#type' => 'checkbox', + '#type' => 'checkbox', '#title' => t("Thumbnail Translucence"), - '#description' => t('When enabled, thumbnails will be made translucent until the mouse hovers over them.'), + '#description' => t('When enabled, thumbnails will be made translucent until the mouse hovers over them.'), '#default_value' => variable_get('gallerix_translucence', 1), - ); - - + ); + + $form['gallerix_layout'] = array( '#type' => 'fieldset', '#tree' => TRUE, '#title' => t('Layout Options'), '#theme' => 'gallerix_component_settings' ); - + $components = _gallerix_load_components('configure'); - + foreach($components as $component) { $form['gallerix_layout'][$component['#id']]['title'] = array( '#type' => 'value', - '#value' => $component['#title'], - ); + '#value' => $component['#title'], + ); $form['gallerix_layout'][$component['#id']]['weight'] = array( '#type' => 'weight', - '#delta' => 5, + '#delta' => 5, '#title' => $component['#title'], '#default_value' => $component['#weight'], ); $form['gallerix_layout'][$component['#id']]['display'] = array( - '#type' => 'checkbox', + '#type' => 'checkbox', '#title' => t("Enabled"), '#default_value' => $component['#display'], - ); + ); } $form['gallerix_style'] = array( @@ -83,32 +83,32 @@ function gallerix_display_settings() { $form['gallerix_style']['gallerix_style'] = array( '#type' => 'select', '#title' => t('CSS Stylesheet'), - '#description' => t('Select a style to use for Gallerix. Two styles are included by default, but select custom if you wish to use your own stylesheet'), - '#options' => array('standard.css' => t('Standard'), 'edgeless.css' => t('Edgeless'), 'custom' => t('Custom')), + '#description' => t('Select a style to use for Gallerix. Two styles are included by default, but select custom if you wish to use your own stylesheet'), + '#options' => array('standard.css' => t('Standard'), 'edgeless.css' => t('Edgeless'), 'custom' => t('Custom')), '#default_value' => variable_get('gallerix_style', 'standard.css'), ); $form['gallerix_style']['gallerix_style_path'] = array( '#type' => 'textfield', '#title' => t('Custom Stylesheet Path'), - '#description' => t("If you choose to use your own stylesheet, enter the path where the stylesheet can be found. Don't forget that icons need to be relative to the stylesheet, - so copy those over if necesssary, unless you are providing your own."), + '#description' => t("If you choose to use your own stylesheet, enter the path where the stylesheet can be found. Don't forget that icons need to be relative to the stylesheet, + so copy those over if necesssary, unless you are providing your own."), '#disabled' => (variable_get('gallerix_style', 'standard.css') != 'custom'), '#default_value' => variable_get('gallerix_style_path', ''), - ); + ); + - $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit') ); - - + + return $form; } function theme_gallerix_component_settings($form) { - + $header = array(t('Component'), t('Weight'), t('Display')); $rows = array(); @@ -116,19 +116,19 @@ function theme_gallerix_component_settin //Remove titles from the select boxes. unset($form[$key]['weight']['#title']); unset($form[$key]['display']['#title']); - + //Extrac the title for each component, then unset it. $title = $form[$key]['title']['#value']; unset($form[$key]['title']); - - + + $rows[] = array ( $title, drupal_render($form[$key]['weight']), drupal_render($form[$key]['display']), ); } - + return theme('table', $header, $rows); } @@ -139,31 +139,31 @@ function gallerix_display_settings_valid form_set_error('gallerix_thumbnail_number', t('You must enter an number.')); } elseif (intval($form_state['values']['gallerix_thumbnail_number']) == 1 || intval($form_state['values']['gallerix_thumbnail_number']) == 2 || intval($form_state['values']['gallerix_thumbnail_number']) < 0) { - form_set_error('gallerix_thumbnail_number', t('You must use at least 3 thumbnails. You may set to 0 to disable thumbnails.')); + form_set_error('gallerix_thumbnail_number', t('You must use at least 3 thumbnails. You may set to 0 to disable thumbnails.')); } } function gallerix_display_settings_submit($form, &$form_state) { - + $weights = array(); $display = array(); - + foreach($form_state['values']['gallerix_layout'] as $key => $component) { $weights[$key] = $component['weight']; $display[$key] = $component['display']; } - - + + unset($form_state['values']['gallerix_layout']); - + variable_set('gallerix_layout_weights', $weights); variable_set('gallerix_layout_display', $display); cache_clear_all(NULL, 'cache_gallerix'); - + system_settings_form_submit($form, $form_state); - + } @@ -172,13 +172,13 @@ function gallerix_admin_settings() { $sizes = gallerix_sizes(); // Dummy to add a blank at the bottom of the table. - $sizes[''] = array( + $sizes[''] = array( 'name' => '', 'width' => '', 'height' => '', 'ratio' => 0, ); - + // Resolution Options $form['gallerix_sizes'] = array( '#type' => 'fieldset', @@ -187,9 +187,9 @@ function gallerix_admin_settings() { '#tree' => TRUE, '#description' => t("You may add more sizes to build for each picture submitted. If you want the picture to be resized exactly to the proportions, check the Maintain Ratio box. If you don't check the box, pictures will only be scaled to fit given proportions."), - ); - - + ); + + foreach ($sizes as $name => $size) { $entry = array(); @@ -212,17 +212,17 @@ function gallerix_admin_settings() { $entry['height'] = array( '#type' => 'textfield', '#size' => 5, - '#default_value' => $size['height'], - ); + '#default_value' => $size['height'], + ); $entry['ratio'] = array( '#type' => 'checkbox', - '#default_value' => $size['ratio'], - ); - - $form['gallerix_sizes'][] = $entry; - + '#default_value' => $size['ratio'], + ); + + $form['gallerix_sizes'][] = $entry; + } - + // Source Options $form['gallerix_sources'] = array( '#type' => 'fieldset', @@ -233,21 +233,21 @@ function gallerix_admin_settings() { '#title' => t('Number of Upload Fields'), '#description' => t('Controls the number of file upload fields available to users at the same time. Set to 0 to disable file upload.'), '#size' => 2, - '#default_value' => variable_get('gallerix_upload_number', 1) - ); + '#default_value' => variable_get('gallerix_upload_number', 1) + ); $form['gallerix_sources']['gallerix_allow_archives'] = array( '#type' => 'checkbox', '#title' => t('Allow ZIP'), '#disabled' => !extension_loaded ('zip'), '#description' => t('When enabled, users will be able to upload ZIP archive files as well as images. This option is disabled if your PHP installation does not have the ZIP library.'), '#size' => 2, - '#default_value' => variable_get('gallerix_allow_archives', false) - ); + '#default_value' => variable_get('gallerix_allow_archives', false) + ); $form['gallerix_sources']['gallerix_repository'] = array( '#type' => 'checkbox', '#title' => t('Enable Repository.'), - '#description' => t('Enabling the repository will provide a common place to upload your pictures using FTP. - This is very useful if you are not using per-user albums, or you have a site with a controlled set of a few trusted users. + '#description' => t('Enabling the repository will provide a common place to upload your pictures using FTP. + This is very useful if you are not using per-user albums, or you have a site with a controlled set of a few trusted users. When enabled, simply place picture files inside files/gallerix/repository, and they will show up whenever you are adding pictures to your albums. '), '#default_value' => variable_get('gallerix_repository', 0) ); @@ -256,35 +256,35 @@ function gallerix_admin_settings() { '#title' => t('Delete From Repository.'), '#description' => t('When enabled, files will be moved to the repository to the album folder. If disabled, a copy will be made instead and the original files will be left untouched in the repository folder.'), '#default_value' => variable_get('gallerix_delete_repository', FALSE) - ); - - + ); + + // Insertion Options $form['gallerix_metadata'] = array( '#type' => 'fieldset', '#title' => t('Metadata Options'), - ); + ); $form['gallerix_metadata']['gallerix_extract_exif'] = array( '#type' => 'checkbox', '#title' => t('Extract EXIF Data'), '#disabled' => !function_exists('exif_read_data'), - '#description' => t('Information such as Date Taken and Image Description are stored inside each file. If you enable this option, Gallerix will try to extract EXIF data from pictures. + '#description' => t('Information such as Date Taken and Image Description are stored inside each file. If you enable this option, Gallerix will try to extract EXIF data from pictures. Sorting by dates only works if this feature is enabled. Note that this feature is automatically disabled if your PHP installation does not support EXIF extraction.'), '#default_value' => variable_get('gallerix_extract_exif', 0) ); $form['gallerix_metadata']['gallerix_extract_iptc'] = array( '#type' => 'checkbox', '#title' => t('Extract IPTC Tags'), - '#description' => t("Use this option to have Gallerix attempt to extract IPTC keywords from the files. This is very useful if you use Photoshop Elements or Photoshop to tag your files. + '#description' => t("Use this option to have Gallerix attempt to extract IPTC keywords from the files. This is very useful if you use Photoshop Elements or Photoshop to tag your files. Captions for pictures will be extracted from IPTC data and linked to pictures. Users can then override this caption if they wish to do so."), '#default_value' => variable_get('gallerix_extract_iptc', 0) ); - + // Security Options $form['gallerix_security'] = array( '#type' => 'fieldset', '#title' => t('Gallerix Security'), - ); + ); $form['gallerix_security']['gallerix_secure_mode'] = array( '#type' => 'checkbox', '#title' => t('Secure Mode'), @@ -292,13 +292,13 @@ function gallerix_admin_settings() { '#default_value' => variable_get('gallerix_secure_mode', 0) ); - + $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit') ); - - + + return $form; } @@ -307,10 +307,10 @@ function theme_gallerix_sizes_table($for $header = array(t('Label'), t('Name'), t('Width'), t('Height'), t('Maintain Ratio')); $rows = array(); - + foreach (element_children($form) as $key) { $rows[] = array( - drupal_render($form[$key]['label']), + drupal_render($form[$key]['label']), drupal_render($form[$key]['name']), drupal_render($form[$key]['width']), drupal_render($form[$key]['height']), @@ -328,7 +328,7 @@ function theme_gallerix_sizes_table($for function gallerix_admin_settings_validate($form_id, &$form_state) { $names = array(); - + foreach ($form_state['values']['gallerix_sizes'] as $key => $size) { if ($size['name'] && $size['label']) { @@ -344,16 +344,16 @@ function gallerix_admin_settings_validat if (!preg_match("|^[a-z]+$|", $size['name'])) { form_set_error('gallerix_sizes][' . $key . '][name', t('Names can only contain lowercase letters. No spaces, underscores, or dashes.')); } - + $names[] = $size['name']; } elseif ($size['name']) { - form_set_error('gallerix_sizes][' . $key . '][label', t('A label is required.')); + form_set_error('gallerix_sizes][' . $key . '][label', t('A label is required.')); } elseif ($size['label']) { - form_set_error('gallerix_sizes][' . $key . '][name', t('An internal name is required.')); + form_set_error('gallerix_sizes][' . $key . '][name', t('An internal name is required.')); } - + } } @@ -365,19 +365,19 @@ function gallerix_admin_settings_submit( if ($size['name']) { $name = $size['name']; unset($size['name']); - + $sizes[$name] = $size; } } - + variable_set('gallerix_sizes', $sizes); unset($form_state['values']['gallerix_sizes']); - + cache_clear_all(NULL, 'cache_gallerix'); - + system_settings_form_submit($form_id, $form_state); - + } @@ -403,7 +403,7 @@ function gallerix_form_alter($form_id, & '#options' => array(t('Disabled'), t('Enabled')), '#default_value' => variable_get('gallerix_cache', 0), ); - + } } @@ -417,53 +417,53 @@ function gallerix_form_alter($form_id, & function gallerix_add_pictures_form(&$form_state, $node) { drupal_set_title(t('Add Pictures')); - + //Repositories. $common_repository = file_directory_path() . '/gallerix/repository' ; - - $upload_files = variable_get('gallerix_upload_number', 1); + + $upload_files = variable_get('gallerix_upload_number', 1); $archive_allowed = variable_get('gallerix_allow_archives', false); $extensions = $archive_allowed ? 'ZIP|zip' : ''; $allowed_files = '.+\.(jpe?g|png|gif|JPE?G|PNG|GIF' . $extensions . ')'; - + $common_files = variable_get('gallerix_repository', 0) ? file_scan_directory($common_repository, $allowed_files) : 0; - + $album_pictures = db_query('SELECT pid, path, name, caption, original_name FROM {gallerix_pictures} WHERE nid = %d ORDER BY sort', $node->nid); - - $form = array(); + + $form = array(); $form['#tree'] = TRUE; - + // We use this as a placeholder to tell the submit function what to do. $actions = array(); - + // We want to pass the node ID. $form['node_id'] = array( '#type' => 'value', '#value' => $node->nid, ); $form['#attributes'] = array("enctype" => "multipart/form-data"); - - // Manual Upload + + // Manual Upload if ($upload_files) { $form['gallerix_upload'] = array( '#type' => 'fieldset', '#title' => t('From Upload'), '#tree' => FALSE, ); - - + + for ($x = 1; $x <= $upload_files; $x++) { - + if ($upload_files == 1) { $upload_text = t('Upload File'); } else { $upload_text = t('Upload File !field_number', array('!field_number' => $x)); } - + $form['gallerix_upload']['upload_' . $x] = array( '#type' => 'file', '#title' => $upload_text, @@ -476,7 +476,7 @@ function gallerix_add_pictures_form(&$fo // Only display the "Add From Common Repository" form if there are any files to add. if ($common_files) { $actions['repository'] = TRUE; //Process repository. - foreach($common_files as $file) { + foreach($common_files as $file) { $form['gallerix_repository']['checkboxes'][] = array( '#type' => 'checkbox', '#title' => $file->basename, @@ -485,22 +485,22 @@ function gallerix_add_pictures_form(&$fo $form['gallerix_repository']['files'][] = array( '#type' => 'value', '#value' => array('filename' => $file->filename, 'basename' => $file->basename, 'filesize' => filesize($file->filename)), - ); + ); } } - - + + //Let the submit function know what to process. $form['actions'] = array( '#type' => 'value', '#value' => $actions ); - - + + $form['submit'] = array( '#type' => 'submit', '#value' => t('Submit') - ); + ); return $form; @@ -513,22 +513,22 @@ function gallerix_add_pictures_form(&$fo * */ function theme_gallerix_add_pictures_form($form) { - + $node = node_load($form['node_id']['#value']); - $upload_files = variable_get('gallerix_upload_number', 1); + $upload_files = variable_get('gallerix_upload_number', 1); $paths = _gallerix_album_paths($node, true); - + $header = array(theme('table_select_header_cell'), t('Picture'), t('Caption')); $rows = array(); - + $header = array(theme('table_select_header_cell'), t('File Name'), t('File Size')); $rowsAdd = array(); - + foreach(element_children($form['gallerix_repository']['files']) as $key) { $basename = $form['gallerix_repository']['files'][$key]['#value']['basename']; $filesize = $form['gallerix_repository']['files'][$key]['#value']['filesize']; $filesize = format_size($filesize); - + unset($form['gallerix_repository']['checkboxes'][$key]['#title']); $rows[] = array( @@ -537,20 +537,20 @@ function theme_gallerix_add_pictures_for $filesize ); } - + $output = ''; - + if ($form['actions']['#value']['repository']) { $output .= '

Repository Files

'; - $output .= theme('table', $header, $rows); + $output .= theme('table', $header, $rows); } - + $output .= drupal_render($form['submit']); - + //Put the upload field on top. - return drupal_render($form) . $output; - + return drupal_render($form) . $output; + } @@ -565,41 +565,41 @@ function gallerix_add_pictures_form_subm $paths = _gallerix_album_paths($node, true); $album_directory = $paths['album']; - + $rebuild = FALSE; $rebuild = FALSE; - - // Load in the settings. + + // Load in the settings. $extract_exif = variable_get('gallerix_extract_exif', 0); $fields_to_extract = $extract_exif ? variable_get('gallerix_fields_to_extract', 0) : array(); $delete_repository_files = variable_get('gallerix_delete_repository', FALSE); - $upload_files = variable_get('gallerix_upload_number', 1); + $upload_files = variable_get('gallerix_upload_number', 1); $archive_allowed = variable_get('gallerix_allow_archives', false); - + $files = array(); - + if ($upload_files) { for ($x = 1; $x <= $upload_files; $x++) { - - - if ($file = file_save_upload('upload_' . $x, array(), file_directory_path(), FILE_EXISTS_RENAME)) { - + + + if ($file = file_save_upload('upload_' . $x, array(), file_directory_path(), FILE_EXISTS_RENAME)) { + // We don't want to use Drupal's file system. db_query('DELETE FROM {files} WHERE fid = %d', $file->fid); - + if ($temp_files = gallerix_process_file($file->filepath, $paths['original'], TRUE)) { - $files = array_merge($temp_files, $files); + $files = array_merge($temp_files, $files); } else { - file_delete($file->filepath); - } - + file_delete($file->filepath); + } + } - } - - - } - + } + + + } + // Move files from repository to album. if ($form_state['values']['actions']['repository']) { foreach($form_state['values']['gallerix_repository']['checkboxes'] as $key => $checked) { @@ -607,13 +607,13 @@ function gallerix_add_pictures_form_subm $source = $form_state['values']['gallerix_repository']['files'][$key]['filename']; $destination = $paths['original'] . '/' . $form_state['values']['gallerix_repository']['files'][$key]['basename']; - - $file = new stdClass(); + + $file = new stdClass(); $file->filename = $form_state['values']['gallerix_repository']['files'][$key]['basename']; $file->filepath = $source; - + if ($temp_files = gallerix_process_file($source, $paths['original'], $delete_repository_files)) { - $files = array_merge($temp_files, $files); + $files = array_merge($temp_files, $files); } @@ -621,24 +621,24 @@ function gallerix_add_pictures_form_subm } } - - - + + + // For each added file, make a new entry in the database. foreach($files as $file) { $original_name = basename($file); - + $secure_path = _gallerix_secure_file($file); $secure_name = basename($secure_path); - - db_query("INSERT INTO {gallerix_pictures} (nid, uid, path, name, original_name, added, created, caption) VALUES (%d, %d, '%s', '%s', '%s', %d, %d, '%s')", $node->nid, $node->uid, + + db_query("INSERT INTO {gallerix_pictures} (nid, uid, path, name, original_name, added, created, caption) VALUES (%d, %d, '%s', '%s', '%s', %d, %d, '%s')", $node->nid, $node->uid, $secure_path, $secure_name, $original_name, time(), time(), ''); - - + + } - + cache_clear_all(NULL, 'cache_gallerix'); - + if (count($files)) { $form_state['redirect'] = 'node/' . $node->nid . '/pictures/build'; } @@ -654,23 +654,23 @@ function gallerix_add_pictures_form_subm function gallerix_manage_pictures_form(&$form_state, $node) { drupal_set_title(t('Manage Pictures')); - - //Load common.js. - gallerix_load_js(); - + + //Load common.js. + gallerix_load_js(); + //Include management JavaScript and CSS. $path = drupal_get_path('module', 'gallerix'); drupal_add_js($path . '/js/management.js'); drupal_add_css($path . '/management.css'); $album_pictures = db_query('SELECT pid, path, name, caption, original_name FROM {gallerix_pictures} WHERE nid = %d ORDER BY sort', $node->nid); - - $form = array(); + + $form = array(); $form['#tree'] = TRUE; - + //We use this as a placeholder to tell the submit function what to do. $actions = array(); - + //We want to pass the node ID. $form['node_id'] = array( '#type' => 'value', @@ -682,7 +682,7 @@ function gallerix_manage_pictures_form(& ); $count = 0; - + $index = array(); $pictures = array(); $captions = array(); @@ -690,32 +690,32 @@ function gallerix_manage_pictures_form(& $sort = $node->gallerix['sort']; $sort = ($sort == 'default') ? variable_get('gallerix_default_sort', 'ascending') : $sort; - + while($picture = db_fetch_object($album_pictures)) { - $actions['album'] = TRUE; //Process album. - + $actions['album'] = TRUE; //Process album. + $form['gallerix_album']['files'][] = array( '#type' => 'value', '#value' => array( - 'filename' => $picture->path, - 'basename' => $picture->name, - 'pid' => $picture->pid, - 'caption' => $picture->caption, + 'filename' => $picture->path, + 'basename' => $picture->name, + 'pid' => $picture->pid, + 'caption' => $picture->caption, 'original_name' => $picture->original_name, ), - ); + ); $form['gallerix_album']['captions'][] = array( '#type' => 'textfield', '#title' => 'Caption', '#id' => 'gallerix-caption-field-' . $picture->pid, '#attributes' => array('class' => 'gallerix-caption-field'), ); - + $index[] = $picture->pid; $pictures[$picture->pid] = $count; $captions[$picture->pid] = $picture->caption; - $count++; + $count++; } drupal_add_js(array('gallerixManager' => array( @@ -725,30 +725,30 @@ function gallerix_manage_pictures_form(& 'count' => $count, 'settings' => array( 'deleteURL' => url('node/' . $node->nid . '/pictures/manage/delete/'), - 'submitURL' => url('node/' . $node->nid . '/pictures/manage/submit'), + 'submitURL' => url('node/' . $node->nid . '/pictures/manage/submit'), 'reloadURL' => url('node/' . $node->nid . '/pictures', array('absolute' => TRUE)), 'allowSorting' => $sort == 'custom', - ), - + ), + )), 'setting'); - - - - + + + + //Let the submit function know what to process. $form['actions'] = array( '#type' => 'value', '#value' => $actions ); - + $form['save'] = array( '#type' => 'button', '#value' => t('Save Changes'), '#attributes' => array('class' => 'gallerix-management-save'), - ); + ); - - return $form; + + return $form; } @@ -761,80 +761,80 @@ function theme_gallerix_manage_pictures_ $node = node_load($form['node_id']['#value']); - $upload_files = variable_get('gallerix_upload_number', 1); + $upload_files = variable_get('gallerix_upload_number', 1); $paths = _gallerix_album_paths($node, true); $save = drupal_render($form['save']); - + $sort = $node->gallerix['sort']; $sort = ($sort == 'default') ? variable_get('gallerix_default_sort', 'ascending') : $sort; - + if ($sort == 'custom') { $up = theme('image', theme('gallerix_icon', 'up.png'), t('Up'), t('Click to shift up.')); $down = theme('image', theme('gallerix_icon', 'down.png'), t('Down'), t('Click to shift down.')); $top = theme('image', theme('gallerix_icon', 'top.png'), t('Top'), t('Click to shift to the top.')); - $bottom = theme('image', theme('gallerix_icon', 'bottom.png'), t('Bottom'), t('Click to shift to the bottom.')); + $bottom = theme('image', theme('gallerix_icon', 'bottom.png'), t('Bottom'), t('Click to shift to the bottom.')); } - + $delete = theme('image', theme('gallerix_icon', 'delete.png'), t('Delete'), t('Click to mark for deletion.')); $restore = theme('image', theme('gallerix_icon', 'restore.png'), t('Restore'), t('Click to restore this picture.')); - + $header = array(t('Picture'), t('Caption'), t('Actions')); $rows = array(); - + $count = 0; - + foreach(element_children($form['gallerix_album']['files']) as $key) { - $pid = $form['gallerix_album']['files'][$key]['#value']['pid']; + $pid = $form['gallerix_album']['files'][$key]['#value']['pid']; $basename = $form['gallerix_album']['files'][$key]['#value']['basename']; - + $picture = gallerix_load_picture($pid); - + $thumbnail_attributes = array( - 'class' => 'gallerix-thumbnail-field', - 'id' => 'gallerix-thumbnail-field-' . $pid, + 'class' => 'gallerix-thumbnail-field', + 'id' => 'gallerix-thumbnail-field-' . $pid, 'height' => '40', 'style' => 'margin: 2px; cursor: pointer;' ); - - $thumbnail = theme('image', $picture->thumbnail, $alt = '', $basename, $thumbnail_attributes, FALSE); + + $thumbnail = theme('image', $picture->thumbnail, $alt = '', $basename, $thumbnail_attributes, FALSE); unset($form['gallerix_album']['checkboxes'][$key]['#title']); unset($form['gallerix_album']['captions'][$key]['#title']); unset($form['gallerix_album']['checkboxes'][$key]); - + $actions = ''; - $actions .= l($top, '#', array('attributes' => array('id' => 'gallerix-top-field-' . $pid, 'class' => 'gallerix-top-field gallerix-action'), 'html' => TRUE)); - $actions .= l($up, '#', array('attributes' => array('id' => 'gallerix-up-field-' . $pid, 'class' => 'gallerix-up-field gallerix-action'), 'html' => TRUE)); + $actions .= l($top, '#', array('attributes' => array('id' => 'gallerix-top-field-' . $pid, 'class' => 'gallerix-top-field gallerix-action'), 'html' => TRUE)); + $actions .= l($up, '#', array('attributes' => array('id' => 'gallerix-up-field-' . $pid, 'class' => 'gallerix-up-field gallerix-action'), 'html' => TRUE)); $actions .= l($down, '#', array('attributes' => array('id' => 'gallerix-down-field-' . $pid, 'class' => 'gallerix-down-field gallerix-action'), 'html' => TRUE)); - $actions .= l($bottom, '#', array('attributes' => array('id' => 'gallerix-bottom-field-' . $pid, 'class' => 'gallerix-bottom-field gallerix-action'), 'html' => TRUE)); + $actions .= l($bottom, '#', array('attributes' => array('id' => 'gallerix-bottom-field-' . $pid, 'class' => 'gallerix-bottom-field gallerix-action'), 'html' => TRUE)); $actions .= l($delete, '#', array('attributes' => array('id' => 'gallerix-delete-field-' . $pid, 'class' => 'gallerix-delete-field gallerix-action'), 'html' => TRUE)); $actions .= l($restore, '#', array('attributes' => array('id' => 'gallerix-restore-field-' . $pid, 'class' => 'gallerix-restore-field gallerix-action', 'style' => 'display: none;'), 'html' => TRUE)); - + $row_data = array( $thumbnail, drupal_render($form['gallerix_album']['captions'][$key]), - $actions, + $actions, ); - + $rows[] = array( 'data' => $row_data, 'class' => 'gallerix-management-row', 'id' => 'gallerix-management-row-' . $pid, ); - + $count++; } $output = ''; $output .= theme('gallerix_message_box'); - - $output .= theme('gallerix_manage_pictures_help'); + + $output .= theme('gallerix_manage_pictures_help'); $output .= $save; $output .= theme('table', $header, $rows); $output .= $save; - + return drupal_render($form) . $output; } @@ -849,7 +849,7 @@ function theme_gallerix_manage_pictures_ $output .= '
'; $output .= t('Remember to save changes!'); $output .= '

'; - + return $output; } @@ -860,91 +860,91 @@ function theme_gallerix_manage_pictures_ * */ function gallerix_manage_form_submit() { - - + + global $user; - + cache_clear_all(NULL, 'cache_gallerix'); - - + + foreach ($_POST as $pid => $content) { $content = explode("|#|", $content); - + //Sanity check. $pid = check_plain($pid); $action = $content[0]; - - + + $picture = gallerix_load_picture($pid); //Unauthorized request. if ($user->uid != $picture->uid) { - + $result = array( 'status' => 'error', 'message' => t("Unauthorized picture modification attempt. Your IP has been logged."), ); - + watchdog('gallerix', 'Unauthorized picture modification attempt for picture !picture', array('!picture' => $picture->pid), WATCHDOG_WARNING); - - print gallerix_to_js($result); + + drupal_json($result); exit(); } - - + + if ($action == 'sort') { $sort = (int) check_plain($content[1]); $caption = check_plain($content[2]); $caption = trim($caption); - + //Sorting starts at 1, not 0. $sort++; - - db_query("UPDATE {gallerix_pictures} SET caption = '%s', sort = %d WHERE pid = %s", $caption, $sort, $picture->pid); + + db_query("UPDATE {gallerix_pictures} SET caption = '%s', sort = %d WHERE pid = %s", $caption, $sort, $picture->pid); } else if ($action == 'delete') { gallerix_delete_picture($pid); - } - + } + } - - + + db_query('SELECT nid FROM {gallerix_pictures} WHERE nid = %d', $picture->nid); $count = db_affected_rows(); - + if ($count) { $result = array( 'status' => 'success', 'message' => t("Pictures updated successfully."), - ); + ); } else { $result = array( 'status' => 'reload', 'message' => t("All pictures have been deleted."), - ); + ); } - - - print gallerix_to_js($result); - + + + drupal_json($result); + exit(); } -/** +/** * Deletes a picture from an album through the management form. * */ function gallerix_manage_form_delete($pid) { $picture = gallerix_load_picture($pid); - + gallerix_delete_picture($picture); - + } @@ -985,7 +985,7 @@ function gallerix_sort_album(&$node) { _gallerix_sort_pictures_custom($node->nid); break; } - + cache_clear_all(NULL, 'cache_gallerix'); } @@ -998,11 +998,11 @@ function gallerix_sort_album(&$node) { function _gallerix_sort_pictures_ascending($nid) { $pictures = db_query("SELECT pid FROM {gallerix_pictures} WHERE nid = %d ORDER BY created", $nid); $counter = 1; - + while($picture = db_fetch_object($pictures)) { - db_query("UPDATE {gallerix_pictures} SET sort = %d WHERE pid = %d", $counter, $picture->pid); + db_query("UPDATE {gallerix_pictures} SET sort = %d WHERE pid = %d", $counter, $picture->pid); $counter++; - } + } } @@ -1013,11 +1013,11 @@ function _gallerix_sort_pictures_ascendi function _gallerix_sort_pictures_descending($nid) { $pictures = db_query("SELECT pid FROM {gallerix_pictures} WHERE nid = %d ORDER BY created DESC", $nid); $counter = 1; - + while($picture = db_fetch_object($pictures)) { - db_query("UPDATE {gallerix_pictures} SET sort = %d WHERE pid = %d", $counter, $picture->pid); + db_query("UPDATE {gallerix_pictures} SET sort = %d WHERE pid = %d", $counter, $picture->pid); $counter++; - } + } } @@ -1028,12 +1028,12 @@ function _gallerix_sort_pictures_descend function _gallerix_sort_pictures_random($nid) { $pictures = db_query("SELECT pid FROM {gallerix_pictures} WHERE nid = %d ORDER BY created DESC", $nid); $collisions = array(); - + while($picture = db_fetch_object($pictures)) { $random = rand() % 100; - db_query("UPDATE {gallerix_pictures} SET sort = %d WHERE pid = %d", $random, $picture->pid); - } - + db_query("UPDATE {gallerix_pictures} SET sort = %d WHERE pid = %d", $random, $picture->pid); + } + _gallerix_sort_pictures_custom($nid); } @@ -1046,11 +1046,11 @@ function _gallerix_sort_pictures_random( function _gallerix_sort_pictures_filename($nid) { $pictures = db_query("SELECT pid FROM {gallerix_pictures} WHERE nid = %d ORDER BY name", $nid); $counter = 1; - + while($picture = db_fetch_object($pictures)) { - db_query("UPDATE {gallerix_pictures} SET sort = %d WHERE pid = %d", $counter, $picture->pid); + db_query("UPDATE {gallerix_pictures} SET sort = %d WHERE pid = %d", $counter, $picture->pid); $counter++; - } + } } @@ -1062,11 +1062,11 @@ function _gallerix_sort_pictures_custom( $pictures = db_query("SELECT pid FROM {gallerix_pictures} WHERE nid = %d ORDER BY sort", $nid); $counter = 1; - + while($picture = db_fetch_object($pictures)) { - db_query("UPDATE {gallerix_pictures} SET sort = %d WHERE pid = %d", $counter, $picture->pid); + db_query("UPDATE {gallerix_pictures} SET sort = %d WHERE pid = %d", $counter, $picture->pid); $counter++; - } + } }