/**
  * Locates and renders the album based on the template
  * Will look in the following locations
  *  wp-content/themes/{child-theme}/foogallery/album-{template}.php
  *    wp-content/themes/{theme}/foogallery/album-{template}.php
  *  wp-content/plugins/foogallery/templates/album-{template}.php
  *
  * @param $args array       Arguments passed in from the shortcode
  */
 public function render_template($args)
 {
     //do some work before we locate the template
     global $current_foogallery_album;
     global $current_foogallery_album_arguments;
     global $current_foogallery_album_template;
     //set the arguments
     $current_foogallery_album_arguments = $args;
     //load our album
     $current_foogallery_album = $this->find_album($args);
     if (false === $current_foogallery_album) {
         _e('Could not load the album!', 'foogallery');
         return;
     }
     //find the gallery template we will use to render the gallery
     $current_foogallery_album_template = $this->get_arg($args, 'template', $current_foogallery_album->album_template);
     //set a default if we have no gallery template
     if (empty($current_foogallery_album_template)) {
         $current_foogallery_album_template = foogallery_get_default('album_template');
     }
     //if we still have not default, then use the first one we can find
     if (empty($current_foogallery_album_template)) {
         $available_templates = foogallery_album_templates();
         $current_foogallery_album_template = $available_templates[0]['slug'];
     }
     //check if we have any galleries
     if (!$current_foogallery_album->has_galleries()) {
         //no galleries!
         do_action("foogallery_album_template_no_galleries-({$current_foogallery_album_template})", $current_foogallery_album);
     } else {
         //create locator instance
         $instance_name = FOOGALLERY_SLUG . '_album_templates';
         $loader = new Foo_Plugin_File_Locator_v1($instance_name, FOOGALLERY_FILE, 'templates', FOOGALLERY_SLUG);
         //allow extensions to very easily add pickup locations for their files
         $this->add_extension_pickup_locations($loader, apply_filters($instance_name . '_files', array()));
         if (false !== ($template_location = $loader->locate_file("album-{$current_foogallery_album_template}.php"))) {
             //we have found a template!
             do_action('foogallery_located_album_template', $current_foogallery_album);
             do_action("foogallery_located_album_template-{$current_foogallery_album_template}", $current_foogallery_album);
             //try to include some JS
             if (false !== ($js_location = $loader->locate_file("album-{$current_foogallery_album_template}.js"))) {
                 wp_enqueue_script("foogallery-album-template-{$current_foogallery_album_template}", $js_location['url']);
             }
             //try to include some CSS
             if (false !== ($css_location = $loader->locate_file("album-{$current_foogallery_album_template}.css"))) {
                 wp_enqueue_style("foogallery-album-template-{$current_foogallery_album_template}", $css_location['url']);
             }
             //finally include the actual php template!
             if ($template_location) {
                 load_template($template_location['path'], false);
             }
             //we have loaded all files, now let extensions do some stuff
             do_action("foogallery_loaded_album_template", $current_foogallery_album);
             do_action("foogallery_loaded_album_template-({$current_foogallery_album_template})", $current_foogallery_album);
         } else {
             //we could not find a template!
             _e('No album template found!', 'foogallery');
         }
     }
 }
コード例 #2
0
 public function album_template_details()
 {
     if (!empty($this->album_template)) {
         foreach (foogallery_album_templates() as $template) {
             if ($this->album_template == $template['slug']) {
                 return $template;
             }
         }
     }
     return false;
 }
コード例 #3
0
        public function render_settings_metabox($post)
        {
            $album = $this->get_album($post);
            $available_templates = foogallery_album_templates();
            $album_template = foogallery_default_album_template();
            if (!empty($album->album_template)) {
                $album_template = $album->album_template;
            }
            if (false === $album_template) {
                $album_template = $available_templates[0]['slug'];
            }
            $hide_help = 'on' == foogallery_get_setting('hide_gallery_template_help');
            ?>
			<table class="foogallery-album-metabox-settings">
				<tbody>
				<tr class="gallery_template_field gallery_template_field_selector">
					<th>
						<label for="FooGallerySettings_AlbumTemplate"><?php 
            _e('Album Template', 'foogallery');
            ?>
</label>
					</th>
					<td>
						<select id="FooGallerySettings_AlbumTemplate" name="<?php 
            echo FOOGALLERY_ALBUM_META_TEMPLATE;
            ?>
">
							<?php 
            foreach ($available_templates as $template) {
                $selected = $album_template === $template['slug'] ? 'selected' : '';
                echo "<option {$selected} value=\"{$template['slug']}\">{$template['name']}</option>";
            }
            ?>
						</select>
						<br />
						<small><?php 
            _e('The album template that will be used when the album is output to the frontend.', 'foogallery');
            ?>
</small>
					</td>
				</tr>
				<?php 
            foreach ($available_templates as $template) {
                $field_visibility = $album_template !== $template['slug'] ? 'style="display:none"' : '';
                $section = '';
                $fields = isset($template['fields']) ? $template['fields'] : array();
                foreach ($fields as $field) {
                    //allow for the field to be altered by extensions.
                    $field = apply_filters('foogallery_alter_gallery_template_field', $field, $album);
                    $class = "gallery_template_field gallery_template_field-{$template['slug']} gallery_template_field-{$template['slug']}-{$field['id']}";
                    if (isset($field['section']) && $field['section'] !== $section) {
                        $section = $field['section'];
                        ?>
							<tr class="<?php 
                        echo $class;
                        ?>
" <?php 
                        echo $field_visibility;
                        ?>
>
								<td colspan="2"><h4><?php 
                        echo $section;
                        ?>
</h4></td>
							</tr>
						<?php 
                    }
                    if (isset($field['type']) && 'help' == $field['type'] && $hide_help) {
                        continue;
                        //skip help if the 'hide help' setting is turned on
                    }
                    ?>
						<tr class="<?php 
                    echo $class;
                    ?>
" <?php 
                    echo $field_visibility;
                    ?>
>
							<?php 
                    if (isset($field['type']) && 'help' == $field['type']) {
                        ?>
								<td colspan="2">
									<div class="foogallery-help">
										<?php 
                        echo $field['desc'];
                        ?>
									</div>
								</td>
							<?php 
                    } else {
                        ?>
								<th>
									<label for="FooGallerySettings_<?php 
                        echo $template['slug'] . '_' . $field['id'];
                        ?>
"><?php 
                        echo $field['title'];
                        ?>
</label>
								</th>
								<td>
									<?php 
                        do_action('foogallery_render_gallery_template_field', $field, $album, $template);
                        ?>
								</td>
							<?php 
                    }
                    ?>
						</tr>
					<?php 
                }
            }
            ?>
				</tbody>
			</table>
		<?php 
        }