/** * Main shortcode function * * @since 0.1 */ function file_gallery_shortcode($content = false, $attr = false) { global $file_gallery, $wpdb, $post; // if the function is called directly, not via shortcode if (false !== $content && false === $attr) { $attr = wp_parse_args($content); } if (!isset($file_gallery->gallery_id)) { $file_gallery->gallery_id = 1; } else { $file_gallery->gallery_id++; } $options = get_option('file_gallery'); if (isset($options['cache']) && true == $options['cache']) { if ('html' == $attr['output_type'] || isset($options['cache_non_html_output']) && true == $options['cache_non_html_output']) { $transient = 'filegallery_' . md5($post->ID . "_" . serialize($attr)); $cache = get_transient($transient); if ($cache) { return $cache; } } } // if option to show galleries in excerpts is set to false... // ...replace [gallery] with user selected text if (!is_singular() && (!isset($options['in_excerpt']) || true != $options['in_excerpt'])) { return $options['in_excerpt_replace_content']; } $default_templates = unserialize(FILE_GALLERY_DEFAULT_TEMPLATES); // We're trusting author input, so let's at least make sure it looks like a valid orderby statement if (isset($attr['orderby'])) { $attr['orderby'] = sanitize_sql_orderby($attr['orderby']); if (!$attr['orderby']) { unset($attr['orderby']); } } $defaults = array('order' => 'ASC', 'orderby' => '', 'id' => $post->ID, 'columns' => 3, 'size' => 'thumbnail', 'link' => 'attachment', 'include' => '', 'ids' => '', 'exclude' => '', 'template' => 'default', 'linkclass' => '', 'imageclass' => '', 'galleryclass' => '', 'rel' => 1, 'tags' => '', 'tags_from' => 'current', 'output_type' => 'html', 'output_params' => 1, 'attachment_ids' => '', 'mimetype' => '', 'limit' => -1, 'offset' => -1, 'paginate' => 0, 'link_size' => 'full', 'include_meta' => false); if (floatval(get_bloginfo('version')) >= 3.5) { $defaults['link'] = 'post'; } // extract the defaults... extract(shortcode_atts($defaults, $attr)); if (!in_array($template, $default_templates)) { $template_file = FILE_GALLERY_THEME_TEMPLATES_ABSPATH . '/' . $template . '/gallery.php'; if (!is_readable($template_file)) { $template_file = FILE_GALLERY_CONTENT_TEMPLATES_ABSPATH . '/' . $template . '/gallery.php'; } } else { if ('default' == $template) { $template_file = FILE_GALLERY_DEFAULT_TEMPLATE_ABSPATH . '/gallery.php'; $template = FILE_GALLERY_DEFAULT_TEMPLATE_NAME; } else { $template_file = FILE_GALLERY_ABSPATH . '/templates/' . $template . '/gallery.php'; } } // check if template exists and replace with default if it does not if (!is_readable($template_file)) { $template_file = FILE_GALLERY_ABSPATH . '/templates/default/gallery.php'; $template = 'default'; } // get overriding variables from the template file $overriding = true; ob_start(); include $template_file; ob_end_clean(); $overriding = false; if (is_array($file_gallery->overrides) && !empty($file_gallery->overrides)) { extract($file_gallery->overrides); $file_gallery->overrides = NULL; } $limit = (int) $limit; $offset = (int) $offset; $page = (int) get_query_var('page'); if ('false' === $rel || is_numeric($rel) && 0 === (int) $rel) { $_rel = false; } elseif (1 === $rel) { $_rel = true; } else { $_rel = $rel; } if ('false' === $output_params || is_numeric($output_params) && 0 === (int) $output_params) { $output_params = false; } else { $output_params = true; } if ('false' === $paginate || is_numeric($paginate) && 0 === (int) $paginate || 0 > $limit) { $paginate = false; $found_rows = ''; } else { $paginate = true; $found_rows = 'SQL_CALC_FOUND_ROWS'; if (0 === $page) { $page = 1; } if (is_singular() && 1 < $page) { $offset = $limit * ($page - 1); } } $file_gallery->debug_add('pagination', compact('paginate', 'page')); /**/ $_attachment_ids = explode(',', trim($attachment_ids, ',')); $_include = explode(',', trim($include, ',')); $_ids = explode(',', trim($ids, ',')); $attachment_ids = array_merge($_attachment_ids, $_include, $_ids); $attachment_ids = array_unique($attachment_ids); $attachment_ids = implode(',', $attachment_ids); $attachment_ids = trim($attachment_ids, ','); $attachment_ids = trim($attachment_ids); /**/ if (!isset($linkto)) { $linkto = $link; } $sql_mimetype = ''; if ('' != $mimetype) { $mimetype = file_gallery_get_mime_type($mimetype); $sql_mimetype = wp_post_mime_type_where($mimetype); } $approved_attachment_post_statuses = apply_filters('file_gallery_approved_attachment_post_statuses', array('inherit')); $ignored_attachment_post_statuses = apply_filters('file_gallery_ignored_attachment_post_statuses', array('trash', 'private', 'pending', 'future')); if (!empty($approved_attachment_post_statuses)) { $post_statuses = " AND (post_status IN ('" . implode("', '", $approved_attachment_post_statuses) . "') ) "; } elseif (!empty($ignored_attachment_post_statuses)) { $post_statuses = " AND (post_status NOT IN ('" . implode("', '", $ignored_attachment_post_statuses) . "') ) "; } else { $post_statuses = ""; } $file_gallery_query = new stdClass(); // start with tags because they negate everything else if ('' != $tags) { if ('' == $orderby || 'file_gallery' == $orderby) { $orderby = "menu_order ID"; } $query = array('post_status' => implode(',', $approved_attachment_post_statuses), 'post_type' => 'attachment', 'order' => $order, 'orderby' => $orderby, 'posts_per_page' => $limit, 'post_mime_type' => $mimetype, FILE_GALLERY_MEDIA_TAG_NAME => $tags); if ('current' == $tags_from) { $query['post_parent'] = $id; } if (!empty($exclude)) { $query['post__not_in'] = explode(',', preg_replace('/[^0-9,]+/', '', $exclude)); } if (0 < $offset) { $query['offset'] = $offset; } $file_gallery_query = new WP_Query($query); $attachments = $file_gallery_query->posts; unset($query); } elseif ('' != $attachment_ids) { $attachment_ids = explode(',', $attachment_ids); $sql_limit = count($attachment_ids); if ('rand' == $orderby) { shuffle($attachment_ids); } $attachment_ids = implode(',', $attachment_ids); if ('' == $orderby || 'rand' == $orderby || $orderby == 'post__in') { $orderby = sprintf("FIELD(ID, %s)", $attachment_ids); $order = ''; } elseif ('title' == $orderby) { $orderby = "post_title"; } $query = sprintf("SELECT " . $found_rows . " * FROM {$wpdb->posts} \n\t\t\t WHERE ID IN (%s) \n\t\t\t AND post_type = 'attachment' \n\t\t\t" . $post_statuses . " ", $attachment_ids); $query .= $sql_mimetype; $query .= sprintf(" ORDER BY %s %s ", $orderby, $order); if (true !== $paginate) { $limit = $sql_limit; } } else { if ('' == $orderby) { $orderby = "menu_order ID"; } $query = array('post_parent' => $id, 'post_status' => implode(',', $approved_attachment_post_statuses), 'post_type' => 'attachment', 'order' => $order, 'orderby' => $orderby, 'posts_per_page' => $limit, 'post_mime_type' => $mimetype); if (!empty($exclude)) { $query['post__not_in'] = explode(',', preg_replace('/[^0-9,]+/', '', $exclude)); } if (0 < $offset) { $query['offset'] = $offset; } $file_gallery_query = new WP_Query($query); $attachments = $file_gallery_query->posts; unset($query); } if (isset($query)) { if (0 < $limit) { $query .= " LIMIT " . $limit; } if (0 < $offset) { $query .= " OFFSET " . $offset; } $attachments = $wpdb->get_results($query); if ('' != $found_rows) { $file_gallery_query->found_posts = $wpdb->get_var("SELECT FOUND_ROWS()"); $file_gallery_query->max_num_pages = ceil($file_gallery_query->found_posts / $limit); } } $file_gallery->debug_add('attachments_query', compact('file_gallery_query')); if (empty($attachments)) { return '<!-- "File Gallery" plugin says: - No attachments found for the following shortcode arguments: "' . json_encode($attr) . '" -->'; } // feed if (is_feed()) { $output = "\n"; foreach ($attachments as $attachment) { $output .= wp_get_attachment_link($attachment->ID, $size, true) . "\n"; } return $output; } $i = 0; $unique_ids = array(); $gallery_items = ''; if ('object' == $output_type || 'array' == $output_type) { $gallery_items = array(); } $autoqueueclasses = array(); if (defined('FILE_GALLERY_LIGHTBOX_CLASSES')) { $autoqueueclasses = maybe_unserialize(FILE_GALLERY_LIGHTBOX_CLASSES); } else { $autoqueueclasses = explode(',', $options['auto_enqueued_scripts']); } $file_gallery_this_template_counter = 1; // create output foreach ($attachments as $attachment) { $param = array('image_class' => $imageclass, 'link_class' => $linkclass, 'rel' => $_rel, 'title' => '', 'caption' => '', 'description' => '', 'thumb_alt' => ''); $attachment_file = get_attached_file($attachment->ID); $attachment_is_image = file_gallery_file_is_displayable_image($attachment_file); $startcol = ''; $endcol = ''; $x = ''; if ($output_params) { $plcai = array_intersect($autoqueueclasses, explode(' ', trim($linkclass))); if (!empty($plcai)) { if ($attachment_is_image) { if (true === $param['rel']) { $param['rel'] = $plcai[0] . '[' . $file_gallery->gallery_id . ']'; } elseif (!is_bool($param['rel'])) { if (false !== strpos($_rel, '$GID$')) { $param['rel'] = str_replace('$GID$', $file_gallery->gallery_id, $_rel); } else { $param['rel'] = $_rel . '[' . $file_gallery->gallery_id . ']'; } } $filter_args = array('gallery_id' => $file_gallery->gallery_id, 'linkrel' => $param['rel'], 'linkclass' => $param['link_class'], 'imageclass' => $param['image_class']); if ($param['rel']) { $param['rel'] = apply_filters('file_gallery_lightbox_linkrel', $param['rel'], 'linkrel', $filter_args); } $param['link_class'] = apply_filters('file_gallery_lightbox_linkclass', $param['link_class'], 'linkclass', $filter_args); $param['image_class'] = apply_filters('file_gallery_lightbox_imageclass', $param['image_class'], 'imageclass', $filter_args); } else { $param['link_class'] = str_replace(trim(implode(' ', $plcai)), '', trim($linkclass)); } } // if rel is still true or false if (is_bool($param['rel'])) { $param['rel'] = ''; } switch ($linkto) { case 'parent_post': $param['link'] = get_permalink($wpdb->get_var("SELECT post_parent FROM {$wpdb->posts} WHERE ID = '" . $attachment->ID . "'")); break; case 'file': $param['link'] = wp_get_attachment_url($attachment->ID); break; case 'attachment': case 'post': $param['link'] = get_attachment_link($attachment->ID); break; case 'none': $param['link'] = ''; break; default: // external url $param['link'] = urldecode($linkto); break; } $param['title'] = $attachment->post_title; $param['caption'] = $attachment->post_excerpt; $param['description'] = $attachment->post_content; if ($attachment_is_image) { $thumb_src = wp_get_attachment_image_src($attachment->ID, $size); $param['thumb_link'] = $thumb_src[0]; $param['thumb_width'] = 0 == $thumb_src[1] ? file_gallery_get_image_size($param['thumb_link']) : $thumb_src[1]; $param['thumb_height'] = 0 == $thumb_src[2] ? file_gallery_get_image_size($param['thumb_link'], true) : $thumb_src[2]; if ('' != $param['link'] && 'full' != $link_size && in_array($link_size, file_gallery_get_intermediate_image_sizes())) { $full_src = wp_get_attachment_image_src($attachment->ID, $link_size); $param['link'] = $full_src[0]; } } else { $param['thumb_link'] = wp_mime_type_icon($attachment->ID); $param['thumb_link'] = apply_filters('file_gallery_non_image_thumb_link', $param['thumb_link'], $attachment->post_mime_type, $attachment->ID); $param['thumb_width'] = '46'; $param['thumb_height'] = '60'; } if ($thumb_alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true)) { $param['thumb_alt'] = $thumb_alt; } $param['attachment_id'] = $attachment->ID; } $param = array_map('trim', $param); if ($include_meta) { $meta = get_post_custom($attachment->ID); } if ('object' == $output_type) { if ($output_params) { $attachment->params = (object) $param; } if ($include_meta) { $attachment->meta = (object) $meta; } $gallery_items[] = $attachment; } elseif ('array' == $output_type || 'json' == $output_type) { if ($output_params) { $attachment->params = $param; } if ($include_meta) { $attachment->meta = $meta; } $gallery_items[] = get_object_vars($attachment); } else { if ($columns > 0) { if (0 === $i || 0 === $i % $columns) { $startcol = ' gallery-startcol'; } elseif (($i + 1) % $columns == 0) { // add the column break class $endcol = ' gallery-endcol'; } } // parse template ob_start(); extract($param); include $template_file; $x = ob_get_contents(); ob_end_clean(); $file_gallery_this_template_counter++; if ($columns > 0 && $i + 1 % $columns == 0) { $x .= $cleartag; } $gallery_items .= $x; $i++; } } // handle data types if ('object' == $output_type || 'array' == $output_type) { $output = $gallery_items; } elseif ('json' == $output_type) { $output = json_encode($gallery_items); } else { $stc = ''; $cols = ''; $pagination_html = ''; if (0 < (int) $columns) { $cols = ' columns_' . $columns; } if (isset($starttag_class) && '' != $starttag_class) { $stc = ' ' . $starttag_class; } $trans_append = "\n<!-- file gallery output cached on " . date('Y.m.d @ H:i:s', time()) . "-->\n"; if (is_singular() && isset($file_gallery_query->max_num_pages) && 1 < $file_gallery_query->max_num_pages) { $pagination_html = file_gallery_do_pagination($file_gallery_query->max_num_pages, $page); } $gallery_class = apply_filters('file_gallery_galleryclass', 'gallery ' . str_replace(' ', '-', $template) . $cols . $stc . ' ' . $galleryclass); $output = '<' . $starttag . ' id="gallery-' . $file_gallery->gallery_id . '" class="' . $gallery_class . '">' . "\n" . $gallery_items . "\n" . $pagination_html . "\n</" . $starttag . '>'; } if (isset($options['cache']) && true == $options['cache']) { if ('html' == $output_type) { set_transient($transient, $output . $trans_append, $options['cache_time']); } elseif (isset($options['cache_non_html_output']) && true == $options['cache_non_html_output']) { set_transient($transient, $output, $options['cache_time']); } } return apply_filters('file_gallery_output', $output, $post->ID, $file_gallery->gallery_id); }
/** * Displays the main form for inserting shortcodes / single images. * also handles attachments edit/delete/detach response * and displays atachment thumbnails on post edit screen in admin */ function file_gallery_main($ajax = true) { global $wpdb; check_ajax_referer('file-gallery'); $post_id = isset($_POST['post_id']) ? $_POST['post_id'] : ''; $attachment_order = isset($_POST['attachment_order']) ? $_POST['attachment_order'] : ''; $attachment_orderby = isset($_POST['attachment_orderby']) ? $_POST['attachment_orderby'] : ''; $files_or_tags = isset($_POST['files_or_tags']) ? $_POST["files_or_tags"] : ''; $tags_from = isset($_POST['tags_from']) ? $_POST["tags_from"] : ''; $action = isset($_POST['action']) ? $_POST['action'] : ''; $attachment_ids = isset($_POST['attachment_ids']) ? $_POST['attachment_ids'] : ''; $attachment_data = isset($_POST['attachment_data']) ? $_POST['attachment_data'] : ''; $delete_what = isset($_POST['delete_what']) ? $_POST['delete_what'] : ''; $checked_attachments = isset($_POST['checked_attachments']) ? explode(',', $_POST['checked_attachments']) : array(); $normals = isset($_POST['normals']) ? $_POST['normals'] : ''; $copies = isset($_POST['copies']) ? $_POST['copies'] : ''; $originals = isset($_POST['originals']) ? $_POST['originals'] : ''; $fieldsets = isset($_POST['fieldsets']) ? $_POST['fieldsets'] : ''; $file_gallery_options = get_option('file_gallery'); $gallery_state = isset($file_gallery_options['insert_options_state']) && true == $file_gallery_options['insert_options_state'] ? true : false; $single_state = isset($file_gallery_options['insert_single_options_state']) && true == $file_gallery_options['insert_single_options_state'] ? true : false; $output = " "; $count_attachments = 0; $hide_form = ''; $sizes = file_gallery_get_intermediate_image_sizes(); $normals = explode(',', $normals); $copies = explode(',', $copies); $originals = explode(',', $originals); $attachment_ids = explode(',', $attachment_ids); if (empty_array($normals)) { $normals = array(); } if (empty_array($copies)) { $copies = array(); } if (empty_array($originals)) { $originals = array(); } if (empty_array($attachment_ids)) { $attachment_ids = array(); } if ('file_gallery_main_delete' == $action) { if (!empty($copies) && !empty($originals)) { $cpluso = array_merge($copies, $originals); $normals = array_xor((array) $attachment_ids, $cpluso); } elseif (!empty($copies)) { $normals = array_xor((array) $attachment_ids, $copies); } elseif (!empty($originals)) { $normals = array_xor((array) $attachment_ids, $originals); } else { $normals = $attachment_ids; } // cancel our own 'wp_delete_attachment' filter define("FILE_GALLERY_SKIP_DELETE_CANCEL", true); foreach ($normals as $normal) { if (current_user_can('delete_post', $normal)) { wp_delete_attachment($normal); $fully_deleted[] = $normal; } } foreach ($copies as $copy) { if (current_user_can('delete_post', $copy)) { file_gallery_delete_attachment($copy); $partially_deleted[] = $copy; } } foreach ($originals as $original) { if ("all" == $delete_what && current_user_can('delete_post', $original)) { file_gallery_delete_all_attachment_copies($original); wp_delete_attachment($original); $fully_deleted[] = $original; } elseif ("data_only" == $delete_what && current_user_can('delete_post', $original)) { file_gallery_promote_first_attachment_copy($original); file_gallery_delete_attachment($original); $partially_deleted[] = $original; } } if (empty($fully_deleted) && empty($partially_deleted)) { $output = __("No attachments were deleted (capabilities?)", "file-gallery"); } else { $output = __("Attachment(s) deleted", "file-gallery"); } } elseif ("file_gallery_main_detach" == $action) { foreach ($attachment_ids as $attachment_id) { if (false === $wpdb->query(sprintf("UPDATE {$wpdb->posts} SET `post_parent`='0' WHERE `ID`='%d'", $attachment_id))) { $detach_errors[] = $attachment_id; } } if (empty($detach_errors)) { $output = __("Attachment(s) detached", "file-gallery"); } else { $output = __("Error detaching attachment(s)", "file-gallery"); } } elseif ("file_gallery_main_update" == $action) { $attachment_id = (int) $_POST['attachment_id']; $attachment_data['ID'] = $attachment_id; $attachment_data['post_alt'] = $_POST['post_alt']; $attachment_data['post_title'] = $_POST['post_title']; $attachment_data['post_content'] = $_POST['post_content']; $attachment_data['post_excerpt'] = $_POST['post_excerpt']; $attachment_data['menu_order'] = $_POST['menu_order']; // attachment custom fields $custom = get_post_custom($attachment_id); $custom_fields = isset($_POST['custom_fields']) ? $_POST['custom_fields'] : ''; if (!empty($custom) && !empty($custom_fields)) { foreach ($custom_fields as $key => $val) { if (isset($custom[$key]) && $custom[$key][0] != $val) { update_post_meta($attachment_id, $key, $val); } } } // media_tag taxonomy - attachment tags $tax_input = ""; $old_media_tags = ""; $get_old_media_tags = wp_get_object_terms((int) $_POST['attachment_id'], FILE_GALLERY_MEDIA_TAG_NAME); if (!empty($get_old_media_tags)) { foreach ($get_old_media_tags as $mt) { $old_media_tags[] = $mt->name; } $old_media_tags = implode(", ", $old_media_tags); } if ("" != $_POST['tax_input'] && $old_media_tags != $_POST['tax_input']) { $tax_input = preg_replace("#\\s+#", " ", $_POST['tax_input']); $tax_input = preg_replace("#,+#", ",", $_POST['tax_input']); $tax_input = trim($tax_input, " "); $tax_input = trim($tax_input, ","); $tax_input = explode(", ", $tax_input); $media_tags_result = wp_set_object_terms($attachment_id, $tax_input, FILE_GALLERY_MEDIA_TAG_NAME); } elseif ("" == $_POST['tax_input']) { $media_tags_result = wp_set_object_terms($attachment_id, NULL, FILE_GALLERY_MEDIA_TAG_NAME); } // check if there were any changes $old_attachment_data = get_object_vars(get_post($attachment_id)); if (file_gallery_file_is_displayable_image(get_attached_file($attachment_id))) { $old_attachment_data['post_alt'] = get_post_meta($attachment_id, "_wp_attachment_image_alt", true); } if (isset($old_attachment_data['post_alt']) && $old_attachment_data['post_alt'] != $attachment_data['post_alt'] || $old_attachment_data['post_title'] != $attachment_data['post_title'] || $old_attachment_data['post_content'] != $attachment_data['post_content'] || $old_attachment_data['post_excerpt'] != $attachment_data['post_excerpt'] || $old_attachment_data['menu_order'] != $attachment_data['menu_order'] || is_array($tax_input)) { if (0 !== wp_update_post($attachment_data)) { update_post_meta($attachment_id, "_wp_attachment_image_alt", $attachment_data['post_alt']); $output = __("Attachment data updated", "file-gallery"); } else { $output = __("Error updating attachment data!", "file-gallery"); } } else { $output = __("No change.", "file-gallery"); } } elseif ("file_gallery_set_post_thumb" == $action) { update_post_meta($post_id, "_thumbnail_id", $attachment_ids[0]); exit(_wp_post_thumbnail_html($attachment_ids[0], $post_id)); } elseif ("file_gallery_unset_post_thumb" == $action) { exit; } include_once "main-form.php"; exit; }
/** * Creates select option dropdowns * * @since 1.7 */ function file_gallery_dropdown($name, $type) { $output = ''; $options = get_option('file_gallery'); $current = $options[$name]; if ('image_size' == $type) { $keys['image_size'] = file_gallery_get_intermediate_image_sizes(); } if ('template' == $type) { $keys['template'] = file_gallery_get_templates('file_gallery_dropdown'); } $keys['align'] = array('none' => __('none', 'file-gallery'), 'left' => __('left', 'file-gallery'), 'right' => __('right', 'file-gallery'), 'center' => __('center', 'file-gallery')); $keys['linkto'] = array("none" => __("nothing (do not link)", "file-gallery"), "file" => __("file", "file-gallery"), "attachment" => __("attachment page", "file-gallery"), "parent_post" => __("parent post", "file-gallery"), "external_url" => __("external url", "file-gallery")); $keys['orderby'] = array("default" => __("file gallery", "file-gallery"), "rand" => __("random", "file-gallery"), "menu_order" => __("menu order", "file-gallery"), "post_title" => __("title", "file-gallery"), "ID" => __("date / time", "file-gallery")); $keys['order'] = array("ASC" => __("ascending", "file-gallery"), "DESC" => __("descending", "file-gallery")); $keys['align'] = array("none" => __("none", "file-gallery"), "left" => __("left", "file-gallery"), "right" => __("right", "file-gallery"), "center" => __("center", "file-gallery")); $keys['columns'] = array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9); if ('image_size' == $type) { $output .= '<option value="thumbnail"'; if ($current == 'thumbnail') { $output .= ' selected="selected"'; } $output .= '>' . __('thumbnail', 'file-gallery') . '</option>'; $output .= '<option value="medium"'; if ($current == 'medium') { $output .= ' selected="selected"'; } $output .= '>' . __('medium', 'file-gallery') . '</option>'; $output .= '<option value="large"'; if ($current == 'large') { $output .= ' selected="selected"'; } $output .= '>' . __('large', 'file-gallery') . '</option>'; $output .= '<option value="full"'; if ($current == 'full') { $output .= ' selected="selected"'; } $output .= '>' . __('full', 'file-gallery') . '</option>'; } foreach ($keys[$type] as $name => $description) { if (is_numeric($name)) { $name = $description; } if ('image_size' == $type && in_array($name, array('thumbnail', 'medium', 'large', 'full'))) { continue; } $output .= '<option value="' . $name . '"'; if ($current == $name) { $output .= ' selected="selected"'; } $output .= '>' . $description . '</option>'; } return $output; }