? 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 .= '