From a3e13092cbbc150531e9bebb95bb5af6b9eff28f Mon Sep 17 00:00:00 2001
From: wonder95 <killshot91@gmail.com>
Date: Tue, 26 Feb 2013 17:14:10 -0800
Subject: [PATCH] Adding the following enhancements to add flexibility and
 increase code quality: 1) Use loop in theme-settings.php to generate
 fieldsets for slideshow slides 2) Move fields to ['theme_settings'] in
 theme-settings.php 3) Move creation of slideshow variables from page
 templates to template.php 4) Added use of theme_image_style to take advantage
 of automatic resizing if images so that slideshow images don't have to be
 manually resized prior to upload.

---
 template.php                  | 38 +++++++++++++++++
 templates/page--front.tpl.php | 17 ++------
 theme-settings.php            | 97 +++++++++++++++++--------------------------
 3 files changed, 78 insertions(+), 74 deletions(-)

diff --git a/template.php b/template.php
index 35847ae..5a29ecb 100644
--- a/template.php
+++ b/template.php
@@ -81,6 +81,44 @@ function business_preprocess_page(&$vars) {
   else {
     $vars['secondary_menu'] = FALSE;
   }
+	
+	// Create URLs for slideshow images using theme_image_style.  This allows Drupal to
+	// handle the resizing of images instead of making the user manually resize them.
+	if ($vars['is_front']) {
+	  $settings = variable_get('theme_business_settings', array());
+    $slideshow_images_dir = variable_get('file_public_path', conf_path() . '/files') . '/slideshow/';
+    for ($i = 1; $i <= 5; $i++) {
+			$slides[$i]['url'] = $settings['slide' . $i . '_url'];
+			$slides[$i]['desc'] = $settings['slide' . $i . '_desc'];
+			$slides[$i]['image'] = $settings['slide' . $i . '_image'];
+    }
+	
+		//Initialize output variables.
+		$image_reel_output = '';
+		$image_descriptions = '';
+		$paging_buttons = ''; 
+		foreach ($slides as $id => $slide) {
+			//$image_path = base_path() . $slideshow_images_dir . $slide['image'];
+			// Get image style for image;
+			$settings = array();
+			$settings['style_name'] = 'slideshow';
+			$settings['path'] = 'slideshow/' . $slide['image'];
+			$settings['alt'] = $slide['desc'];
+			$settings['title'] = $slide['desc'];
+			
+			$image_tag = theme('image_style', $settings);
+						
+			$image_reel_output .= '<a href="' . url($slide['url']) . '">' . $image_tag . '</a>';
+			// Get description for slide.
+			$image_description = $slide['desc'];
+			$image_descriptions .= '<div class="desc" style="display: none">' . check_markup($image_description) . '</div>';
+			//Create paging buttons
+			$paging_buttons .= '<a rel="' . $id . '" href="#">' . $id . '</a>';
+		}
+		$vars['image_reel'] = $image_reel_output;
+		$vars['image_descriptions'] = $image_descriptions;
+	  $vars['paging_buttons'] = $paging_buttons;
+	}
 }
 
 /**
diff --git a/templates/page--front.tpl.php b/templates/page--front.tpl.php
index f2fab1c..c7fde09 100644
--- a/templates/page--front.tpl.php
+++ b/templates/page--front.tpl.php
@@ -97,30 +97,19 @@
   <?php print render($page['header']); ?>
   
     <?php if (theme_get_setting('slideshow_display','business')): ?>
-    <?php 
-    $url1 = check_plain(theme_get_setting('slide1_url','business'));
-    $url2 = check_plain(theme_get_setting('slide2_url','business'));
-    $url3 = check_plain(theme_get_setting('slide3_url','business'));
-    ?>
       <div id="slider">
         <div class="main_view">
             <div class="window">
                 <div class="image_reel">
-                    <a href="<?php print url($url1); ?>"><img src="<?php print base_path() . drupal_get_path('theme', 'business') . '/images/slide-image-1.jpg'; ?>"></a>
-                    <a href="<?php print url($url2); ?>"><img src="<?php print base_path() . drupal_get_path('theme', 'business') . '/images/slide-image-2.jpg'; ?>"></a>
-                    <a href="<?php print url($url3); ?>"><img src="<?php print base_path() . drupal_get_path('theme', 'business') . '/images/slide-image-3.jpg'; ?>"></a>
+                  <?php print $image_reel; ?>
                 </div>
                 <div class="descriptions">
-                    <div class="desc" style="display: none;"><?php print check_markup(theme_get_setting('slide1_desc','business')); ?></div>
-                    <div class="desc" style="display: none;"><?php print check_markup(theme_get_setting('slide2_desc','business')); ?></div>
-                    <div class="desc" style="display: none;"><?php print check_markup(theme_get_setting('slide3_desc','business')); ?></div>
+                  <?php print $image_descriptions; ?>
                 </div>
             </div>
         
             <div class="paging">
-                <a rel="1" href="#">1</a>
-                <a rel="2" href="#">2</a>
-                <a rel="3" href="#">3</a>
+              <?php print $paging_buttons; ?>
             </div>
         </div>
       </div><!-- EOF: #banner -->
diff --git a/theme-settings.php b/theme-settings.php
index af73a90..15886b4 100644
--- a/theme-settings.php
+++ b/theme-settings.php
@@ -9,103 +9,80 @@
  */
 function business_form_system_theme_settings_alter(&$form, &$form_state) {
 
-  $form['busi_settings'] = array(
+  $form['theme_settings'] = array(
     '#type' => 'fieldset',
     '#title' => t('Business Theme Settings'),
     '#collapsible' => FALSE,
     '#collapsed' => FALSE,
   );
-  $form['busi_settings']['show_front_content'] = array(
+  $form['theme_settings']['show_front_content'] = array(
     '#type' => 'checkbox',
     '#title' => t('Show content and sidebar on front page'),
     '#default_value' => theme_get_setting('show_front_content','business'),
     '#description' => t('Check this option to show content and sidebar on the front page.'),
   );
-  $form['busi_settings']['breadcrumbs'] = array(
+  $form['theme_settings']['breadcrumbs'] = array(
     '#type' => 'checkbox',
     '#title' => t('Show breadcrumbs in a page'),
     '#default_value' => theme_get_setting('breadcrumbs','business'),
     '#description'   => t("Check this option to show breadcrumbs in page. Uncheck to hide."),
   );
-  $form['busi_settings']['slideshow'] = array(
+  $form['theme_settings']['slideshow'] = array(
     '#type' => 'fieldset',
     '#title' => t('Front Page Slideshow'),
     '#collapsible' => TRUE,
     '#collapsed' => FALSE,
   );
-  $form['busi_settings']['slideshow']['slideshow_display'] = array(
+  $form['theme_settings']['slideshow']['slideshow_display'] = array(
     '#type' => 'checkbox',
     '#title' => t('Show slideshow'),
     '#default_value' => theme_get_setting('slideshow_display','business'),
     '#description'   => t("Check this option to show Slideshow in front page. Uncheck to hide."),
   );
-    $form['busi_settings']['slideshow']['slide'] = array(
+    $form['theme_settings']['slideshow']['slide'] = array(
     '#markup' => t('You can change the description and URL of each slide in the following Slide Setting fieldsets.'),
   );
-  $form['busi_settings']['slideshow']['slide1'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Slide 1'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-  $form['busi_settings']['slideshow']['slide1']['slide1_desc'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Slide Description'),
-    '#default_value' => theme_get_setting('slide1_desc','business'),
-  );
-  $form['busi_settings']['slideshow']['slide1']['slide1_url'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Slide URL'),
-    '#default_value' => theme_get_setting('slide1_url','business'),
-  );
-  $form['busi_settings']['slideshow']['slide2'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Slide 2'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-  $form['busi_settings']['slideshow']['slide2']['slide2_desc'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Slide Description'),
-    '#default_value' => theme_get_setting('slide2_desc','business'),
-  );
-  $form['busi_settings']['slideshow']['slide2']['slide2_url'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Slide URL'),
-    '#default_value' => theme_get_setting('slide2_url','business'),
-  );
-  $form['busi_settings']['slideshow']['slide3'] = array(
-    '#type' => 'fieldset',
-    '#title' => t('Slide 3'),
-    '#collapsible' => TRUE,
-    '#collapsed' => TRUE,
-  );
-  $form['busi_settings']['slideshow']['slide3']['slide3_desc'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Slide Description'),
-    '#default_value' => theme_get_setting('slide3_desc','business'),
-  );
-  $form['busi_settings']['slideshow']['slide3']['slide3_url'] = array(
-    '#type' => 'textfield',
-    '#title' => t('Slide URL'),
-    '#default_value' => theme_get_setting('slide3_url','business'),
-  );
-  $form['busi_settings']['slideshow']['slideimage'] = array(
-    '#markup' => t('To change the Slide Images, Replace the slide-image-1.jpg, slide-image-2.jpg and slide-image-3.jpg in the images folder of the Business theme folder.'),
-  );
-  $form['busi_settings']['footer'] = array(
+  //Generate fieldsets for images.  
+  for ($i = 1; $i <= 5; $i++) { 
+    $form['theme_settings']['slideshow']['slide' . $i] = array(
+      '#type' => 'fieldset',
+      '#title' => t('Slide ' . $i),
+      '#collapsible' => TRUE,
+      '#collapsed' => TRUE,
+    );
+    $form['theme_settings']['slideshow']['slide' . $i]['slide' . $i . '_desc'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Slide Description'),
+      '#default_value' => theme_get_setting('slide' . $i . '_desc','business'),
+    );
+    $form['theme_settings']['slideshow']['slide' . $i]['slide' . $i . '_url'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Slide URL'),
+      '#default_value' => theme_get_setting('slide' . $i . '_url','business'),
+    );
+    $form['theme_settings']['slideshow']['slide' . $i]['slide' . $i . '_image'] = array(
+      '#type' => 'textfield',
+      '#title' => t('Slide Image'),
+      '#description' => t('The file name of the image.'),
+      '#default_value' => theme_get_setting('slide' . $i . '_image','business'),
+    );
+  }
+  $form['theme_settings']['slideshow']['slideimage'] = array(
+    '#markup' => t('Images referenced in the Slide Image field must be placed in the /sites/default/files/slideshow directory.'),
+  );
+  $form['theme_settings']['footer'] = array(
     '#type' => 'fieldset',
     '#title' => t('Footer'),
     '#collapsible' => TRUE,
     '#collapsed' => FALSE,
   );
-  $form['busi_settings']['footer']['footer_copyright'] = array(
+  $form['theme_settings']['footer']['footer_copyright'] = array(
     '#type' => 'checkbox',
     '#title' => t('Show copyright text in footer'),
     '#default_value' => theme_get_setting('footer_copyright','business'),
     '#description'   => t("Check this option to show copyright text in footer. Uncheck to hide."),
   );
-  $form['busi_settings']['footer']['footer_credits'] = array(
+  $form['theme_settings']['footer']['footer_credits'] = array(
     '#type' => 'checkbox',
     '#title' => t('Show theme credits in footer'),
     '#default_value' => theme_get_setting('footer_credits','business'),
-- 
1.8.1

