function _wppa_edit_photo()
{
    // Check input
    wppa_vfy_arg('photo');
    // Edit one Photo
    if (isset($_GET['photo'])) {
        $photo = $_GET['photo'];
        $thumb = wppa_cache_thumb($photo);
        if ($thumb['owner'] == wppa_get_user()) {
            echo '<div class="wrap">' . '<h2>' . __('Edit photo', 'wp-photo-album-plus') . '</h2>' . wppa_album_photos('', $photo) . '</div>';
        } else {
            wp_die('You do not have the rights to do this');
        }
    } else {
        echo '<div class="wrap">' . '<h2>' . __('Edit photos', 'wp-photo-album-plus') . '</h2>' . wppa_album_photos('', '', wppa_get_user()) . '</div>';
    }
}
function _wppa_edit_photo()
{
    // Check input
    wppa_vfy_arg('photo');
    // Edit Photo
    if (isset($_GET['photo'])) {
        $photo = $_GET['photo'];
        $thumb = wppa_cache_thumb($photo);
        if ($thumb['owner'] == wppa_get_user()) {
            ?>
			<div class="wrap">
				<h2><?php 
            _e('Edit photo', 'wp-photo-album-plus');
            ?>
</h2>
				<?php 
            wppa_album_photos('', $photo);
            ?>
			</div>
<?php 
        } else {
            wp_die('You do not have the rights to do this');
        }
    } else {
        // Edit all photos owned by current user
        ?>
			<div class="wrap">
				<h2><?php 
        _e('Edit photos', 'wp-photo-album-plus');
        ?>
</h2>
				<?php 
        wppa_album_photos('', '', wppa_get_user());
        ?>
			</div>
		<?php 
    }
}
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     global $wpdb;
     require_once dirname(__FILE__) . '/wppa-links.php';
     require_once dirname(__FILE__) . '/wppa-styles.php';
     require_once dirname(__FILE__) . '/wppa-functions.php';
     require_once dirname(__FILE__) . '/wppa-thumbnails.php';
     require_once dirname(__FILE__) . '/wppa-boxes-html.php';
     require_once dirname(__FILE__) . '/wppa-slideshow.php';
     wppa_initialize_runtime();
     wppa('in_widget', 'alb');
     wppa_bump_mocc();
     extract($args);
     $instance = wp_parse_args((array) $instance, array('title' => '', 'parent' => 'none', 'name' => 'no', 'skip' => 'yes'));
     $widget_title = apply_filters('widget_title', $instance['title']);
     $page = in_array(wppa_opt('album_widget_linktype'), wppa('links_no_page')) ? '' : wppa_get_the_landing_page('album_widget_linkpage', __('Photo Albums', 'wp-photo-album-plus'));
     $max = wppa_opt('album_widget_count');
     if (!$max) {
         $max = '10';
     }
     $parent = $instance['parent'];
     $name = $instance['name'];
     $skip = $instance['skip'];
     if (is_numeric($parent)) {
         $albums = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_ALBUMS . '` WHERE `a_parent` = %s ' . wppa_get_album_order($parent), $parent), ARRAY_A);
     } else {
         switch ($parent) {
             case 'all':
                 $albums = $wpdb->get_results('SELECT * FROM `' . WPPA_ALBUMS . '` ' . wppa_get_album_order(), ARRAY_A);
                 break;
             case 'last':
                 $albums = $wpdb->get_results('SELECT * FROM `' . WPPA_ALBUMS . '` ORDER BY `timestamp` DESC', ARRAY_A);
                 break;
             default:
                 wppa_dbg_msg('Error, unimplemented album selection: ' . $parent . ' in Album widget.', 'red', true);
         }
     }
     $widget_content = "\n" . '<!-- WPPA+ album Widget start -->';
     $maxw = wppa_opt('album_widget_size');
     $maxh = $maxw;
     if ($name == 'yes') {
         $maxh += 18;
     }
     $count = 0;
     if ($albums) {
         foreach ($albums as $album) {
             if ($count < $max) {
                 $imageid = wppa_get_coverphoto_id($album['id']);
                 if ($imageid) {
                     $image = wppa_cache_thumb($imageid);
                     //$wpdb->get_row( $wpdb->prepare( 'SELECT * FROM `'.WPPA_PHOTOS.'` WHERE `id` = %s', $imageid ), ARRAY_A );
                 } else {
                     $image = false;
                 }
                 $imgcount = $wpdb->get_var($wpdb->prepare('SELECT COUNT(*) FROM ' . WPPA_PHOTOS . ' WHERE `album` = %s', $album['id']));
                 $subalbumcount = wppa_has_children($album['id']);
                 // $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM `".WPPA_ALBUMS."` WHERE `a_parent` = %s", $album['id'] ) );
                 $thumb = $image;
                 // Make the HTML for current picture
                 if ($image && ($imgcount > wppa_opt('min_thumbs') || $subalbumcount)) {
                     $link = wppa_get_imglnk_a('albwidget', $image['id']);
                     $file = wppa_get_thumb_path($image['id']);
                     $imgevents = wppa_get_imgevents('thumb', $image['id'], true);
                     $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'albthumb');
                     $imgstyle = $imgstyle_a['style'];
                     $width = $imgstyle_a['width'];
                     $height = $imgstyle_a['height'];
                     $cursor = $imgstyle_a['cursor'];
                     if (wppa_switch('show_albwidget_tooltip')) {
                         $title = esc_attr(strip_tags(wppa_get_album_desc($album['id'])));
                     } else {
                         $title = '';
                     }
                     $imgurl = wppa_get_thumb_url($image['id'], '', $width, $height);
                 } else {
                     $link = '';
                     $file = '';
                     $imgevents = '';
                     $imgstyle = 'width:' . $maxw . ';height:' . $maxh . ';';
                     $width = $maxw;
                     $height = $maxw;
                     // !!
                     $cursor = 'default';
                     $title = sprintf(__('Upload at least %d photos to this album!', 'wp-photo-album-plus'), wppa_opt('min_thumbs') - $imgcount + 1);
                     if ($imageid) {
                         // The 'empty album has a cover image
                         $file = wppa_get_thumb_path($image['id']);
                         $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'albthumb');
                         $imgstyle = $imgstyle_a['style'];
                         $width = $imgstyle_a['width'];
                         $height = $imgstyle_a['height'];
                         $imgurl = wppa_get_thumb_url($image['id'], '', $width, $height);
                     } else {
                         $imgurl = wppa_get_imgdir() . 'album32.png';
                     }
                 }
                 if ($imageid) {
                     $imgurl = wppa_fix_poster_ext($imgurl, $image['id']);
                 }
                 if ($imgcount > wppa_opt('min_thumbs') || $skip == 'no') {
                     $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">';
                     if ($link) {
                         if ($link['is_url']) {
                             // Is a href
                             $widget_content .= "\n\t" . '<a href="' . $link['url'] . '" title="' . $title . '" target="' . $link['target'] . '" >';
                             if ($imageid && wppa_is_video($image['id'])) {
                                 $widget_content .= wppa_get_video_html(array('id' => $image['id'], 'width' => $width, 'height' => $height, 'controls' => false, 'margin_top' => $imgstyle_a['margin-top'], 'margin_bottom' => $imgstyle_a['margin-bottom'], 'cursor' => 'pointer', 'events' => $imgevents, 'tagid' => 'i-' . $image['id'] . '-' . wppa('mocc'), 'title' => $title));
                             } else {
                                 $widget_content .= "\n\t\t" . '<img id="i-' . $image['id'] . '-' . wppa('mocc') . '" title="' . $title . '" src="' . $imgurl . '" width="' . $width . '" height="' . $height . '" style="' . $imgstyle . ' cursor:pointer;" ' . $imgevents . ' ' . wppa_get_imgalt($image['id']) . ' >';
                             }
                             $widget_content .= "\n\t" . '</a>';
                         } elseif ($link['is_lightbox']) {
                             $thumbs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s " . wppa_get_photo_order($album['id']), $album['id']), 'ARRAY_A');
                             if ($thumbs) {
                                 foreach ($thumbs as $thumb) {
                                     $title = wppa_get_lbtitle('alw', $thumb['id']);
                                     if (wppa_is_video($thumb['id'])) {
                                         $siz['0'] = wppa_get_videox($thumb['id']);
                                         $siz['1'] = wppa_get_videoy($thumb['id']);
                                     } else {
                                         $siz['0'] = wppa_get_photox($thumb['id']);
                                         $siz['1'] = wppa_get_photoy($thumb['id']);
                                     }
                                     $link = wppa_fix_poster_ext(wppa_get_photo_url($thumb['id'], '', $siz['0'], $siz['1']), $thumb['id']);
                                     $is_video = wppa_is_video($thumb['id']);
                                     $has_audio = wppa_has_audio($thumb['id']);
                                     $widget_content .= "\n\t" . '<a href="' . $link . '"' . ($is_video ? ' data-videohtml="' . esc_attr(wppa_get_video_body($thumb['id'])) . '"' . ' data-videonatwidth="' . wppa_get_videox($thumb['id']) . '"' . ' data-videonatheight="' . wppa_get_videoy($thumb['id']) . '"' : '') . ($has_audio ? ' data-audiohtml="' . esc_attr(wppa_get_audio_body($thumb['id'])) . '"' : '') . ' ' . wppa('rel') . '="' . wppa_opt('lightbox_name') . '[alw-' . wppa('mocc') . '-' . $album['id'] . ']"' . ' ' . wppa('lbtitle') . '="' . $title . '"' . ' data-alt="' . esc_attr(wppa_get_imgalt($thumb['id'], true)) . '"' . ' >';
                                     if ($thumb['id'] == $image['id']) {
                                         // the cover image
                                         if (wppa_is_video($image['id'])) {
                                             $widget_content .= wppa_get_video_html(array('id' => $image['id'], 'width' => $width, 'height' => $height, 'controls' => false, 'margin_top' => $imgstyle_a['margin-top'], 'margin_bottom' => $imgstyle_a['margin-bottom'], 'cursor' => $cursor, 'events' => $imgevents, 'tagid' => 'i-' . $image['id'] . '-' . wppa('mocc'), 'title' => wppa_zoom_in($image['id'])));
                                         } else {
                                             $widget_content .= "\n\t\t" . '<img' . ' id="i-' . $image['id'] . '-' . wppa('mocc') . '"' . ' title="' . wppa_zoom_in($image['id']) . '"' . ' src="' . $imgurl . '"' . ' width="' . $width . '"' . ' height="' . $height . '"' . ' style="' . $imgstyle . $cursor . '" ' . $imgevents . ' ' . wppa_get_imgalt($image['id']) . ' >';
                                         }
                                     }
                                     $widget_content .= "\n\t" . '</a>';
                                 }
                             }
                         } else {
                             // Is an onclick unit
                             if ($imageid && wppa_is_video($image['id'])) {
                                 $widget_content .= wppa_get_video_html(array('id' => $image['id'], 'width' => $width, 'height' => $height, 'controls' => false, 'margin_top' => $imgstyle_a['margin-top'], 'margin_bottom' => $imgstyle_a['margin-bottom'], 'cursor' => 'pointer', 'events' => $imgevents . ' onclick="' . $link['url'] . '"', 'tagid' => 'i-' . $image['id'] . '-' . wppa('mocc'), 'title' => $title));
                             } else {
                                 $widget_content .= "\n\t" . '<img' . ' id="i-' . $image['id'] . '-' . wppa('mocc') . '"' . ' title="' . $title . '"' . ' src="' . $imgurl . '"' . ' width="' . $width . '"' . ' height="' . $height . '"' . ' style="' . $imgstyle . ' cursor:pointer;" ' . $imgevents . ' onclick="' . $link['url'] . '" ' . wppa_get_imgalt($image['id']) . ' >';
                             }
                         }
                     } else {
                         if ($imageid && wppa_is_video($image['id'])) {
                             $widget_content .= wppa_get_video_html(array('id' => $image['id'], 'width' => $width, 'height' => $height, 'controls' => false, 'margin_top' => $imgstyle_a['margin-top'], 'margin_bottom' => $imgstyle_a['margin-bottom'], 'cursor' => 'pointer', 'events' => $imgevents, 'tagid' => 'i-' . $image['id'] . '-' . wppa('mocc'), 'title' => $title));
                         } else {
                             $widget_content .= "\n\t" . '<img' . ' id="i-' . $image['id'] . '-' . wppa('mocc') . '"' . ' title="' . $title . '"' . ' src="' . $imgurl . '"' . ' width="' . $width . '"' . ' height="' . $height . '"' . ' style="' . $imgstyle . '" ' . $imgevents . ' ' . ($imageid ? wppa_get_imgalt($image['id']) : '') . ' >';
                         }
                     }
                     if ($name == 'yes') {
                         $widget_content .= "\n\t" . '<span style="font-size:' . wppa_opt('fontsize_widget_thumb') . 'px; min-height:100%;">' . __(stripslashes($album['name']), 'wp-photo-album-plus') . '</span>';
                     }
                     $widget_content .= "\n" . '</div>';
                     $count++;
                 }
             }
         }
     } else {
         $widget_content .= 'There are no albums (yet).';
     }
     $widget_content .= '<div style="clear:both"></div>';
     $widget_content .= "\n" . '<!-- WPPA+ thumbnail Widget end -->';
     echo "\n" . $before_widget;
     if (!empty($widget_title)) {
         echo $before_title . $widget_title . $after_title;
     }
     echo $widget_content . $after_widget;
     wppa('in_widget', false);
 }
Exemplo n.º 4
0
function wppa_get_imgstyle_a($id, $file, $xmax_size, $xvalign = '', $type = '')
{
    global $wppa;
    $result = array('style' => '', 'width' => '', 'height' => '', 'cursor' => '', 'margin-top' => '', 'margin-bottom' => '');
    // Init
    wppa_cache_thumb($id);
    if (!$id) {
        return $result;
    }
    // no image: no dimensions
    if ($file == '') {
        return $result;
    }
    // no image: no dimensions
    if (wppa_has_audio($id)) {
        $file = wppa_fix_poster_ext($file, $id);
    }
    if (!wppa_is_video($id) && !is_file($file)) {
        wppa_dbg_msg('Please check file ' . $file . ' it is missing while expected. Id=' . $id, 'red');
        return $result;
        // no file: no dimensions ( 2.3.0 )
    }
    if (strpos($file, '/wppa/thumbs/')) {
        $image_attr = wppa_get_imagexy($id, 'thumb');
    } else {
        $image_attr = wppa_get_imagexy($id, 'photo');
    }
    //	if ( wppa_is_video( $id ) ) {
    //		$image_attr = array( '0' => wppa_get_videox( $id ), '1' => wppa_get_videoy( $id ) );
    //	}
    //	else {
    //		$image_attr = array( '0' => wppa_get_photox( $id ), '1' => wppa_get_photoy( $id ) );
    //	}
    if (!$image_attr || !isset($image_attr['0']) || !$image_attr['0'] || !isset($image_attr['1']) || !$image_attr['1']) {
        // File is corrupt
        wppa_dbg_msg('Please check file ' . $file . ' it is corrupted. If it is a thumbnail image,' . ' regenerate them using Table VIII-A4 of the Photo Albums -> Settings admin page.', 'red');
        return $result;
    }
    // Adjust for 'border'
    if ($type == 'fullsize' && !$wppa['in_widget']) {
        switch (wppa_opt('wppa_fullimage_border_width')) {
            case '':
                $max_size = $xmax_size;
                break;
            case '0':
                $max_size = $xmax_size - '2';
                break;
            default:
                $max_size = $xmax_size - '2' - 2 * wppa_opt('wppa_fullimage_border_width');
        }
    } else {
        $max_size = $xmax_size;
    }
    $ratioref = wppa_opt('wppa_maxheight') / wppa_opt('wppa_fullsize');
    $max_height = round($max_size * $ratioref);
    if ($type == 'fullsize') {
        if ($wppa['portrait_only']) {
            $width = $max_size;
            $height = round($width * $image_attr[1] / $image_attr[0]);
        } else {
            if (wppa_is_wider($image_attr[0], $image_attr[1])) {
                $width = $max_size;
                $height = round($width * $image_attr[1] / $image_attr[0]);
            } else {
                $height = round($ratioref * $max_size);
                $width = round($height * $image_attr[0] / $image_attr[1]);
            }
            if ($image_attr[0] < $width && $image_attr[1] < $height) {
                if (!$wppa['enlarge']) {
                    $width = $image_attr[0];
                    $height = $image_attr[1];
                }
            }
        }
    } else {
        if ($type == 'cover' && wppa_switch('wppa_coversize_is_height') && (wppa_opt('wppa_coverphoto_pos') == 'top' || wppa_opt('wppa_coverphoto_pos') == 'bottom')) {
            $height = $max_size;
            $width = round($max_size * $image_attr[0] / $image_attr[1]);
        } else {
            if (wppa_is_landscape($image_attr)) {
                $width = $max_size;
                $height = round($max_size * $image_attr[1] / $image_attr[0]);
            } else {
                $height = $max_size;
                $width = round($max_size * $image_attr[0] / $image_attr[1]);
            }
        }
    }
    switch ($type) {
        case 'cover':
            if (wppa_opt('wppa_bcolor_img') != '') {
                // There is a border color given
                $result['style'] .= ' border: 1px solid ' . wppa_opt('wppa_bcolor_img') . ';';
            } else {
                // No border color: no border
                $result['style'] .= ' border-width: 0px;';
            }
            $result['style'] .= ' width:' . $width . 'px; height:' . $height . 'px;';
            if (wppa_switch('wppa_use_cover_opacity') && !is_feed()) {
                $opac = wppa_opt('wppa_cover_opacity');
                $result['style'] .= ' opacity:' . $opac / 100 . '; filter:alpha( opacity=' . $opac . ' );';
            }
            if (wppa_opt('wppa_coverimg_linktype') == 'lightbox') {
                $result['cursor'] = ' cursor:url( ' . wppa_get_imgdir() . wppa_opt('wppa_magnifier') . ' ),pointer;';
            }
            break;
        case 'thumb':
            // Normal
        // Normal
        case 'ttthumb':
            // Topten
        // Topten
        case 'comthumb':
            // Comment widget
        // Comment widget
        case 'fthumb':
            // Filmthumb
        // Filmthumb
        case 'twthumb':
            // Thumbnail widget
        // Thumbnail widget
        case 'ltthumb':
            // Lasten widget
        // Lasten widget
        case 'albthumb':
            // Album widget
            if ($type == 'thumb' && wppa_get_get('hilite') == $id) {
                $result['style'] .= ' border:2px solid blue;box-sizing:border-box;';
            } else {
                $result['style'] .= ' border-width: 0px;';
            }
            $result['style'] .= ' width:' . $width . 'px; height:' . $height . 'px;';
            if ($xvalign == 'optional') {
                $valign = wppa_opt('wppa_valign');
            } else {
                $valign = $xvalign;
            }
            if ($valign != 'default') {
                // Center horizontally
                $delta = floor(($max_size - $width) / 2);
                if (is_numeric($valign)) {
                    $delta += $valign;
                }
                if ($delta < '0') {
                    $delta = '0';
                }
                if ($delta > '0') {
                    $result['style'] .= ' margin-left:' . $delta . 'px; margin-right:' . $delta . 'px;';
                }
            }
            switch ($valign) {
                case 'top':
                    $delta = $max_size - $height;
                    if ($delta < '0') {
                        $delta = '0';
                    }
                    $result['style'] .= ' margin-bottom: ' . $delta . 'px;';
                    $result['margin-bottom'] = $delta;
                    break;
                case 'center':
                    $delta = round(($max_size - $height) / 2);
                    if ($delta < '0') {
                        $delta = '0';
                    }
                    $result['style'] .= ' margin-top: ' . $delta . 'px; margin-bottom: ' . $delta . 'px;';
                    $result['margin-top'] = $delta;
                    $result['margin-bottom'] = $delta;
                    break;
                case 'bottom':
                    $delta = $max_size - $height;
                    if ($delta < '0') {
                        $delta = '0';
                    }
                    $result['style'] .= ' margin-top: ' . $delta . 'px;';
                    $result['margin-top'] = $delta;
                    break;
                default:
                    if (is_numeric($valign)) {
                        $delta = $valign;
                        $result['style'] .= ' margin-top: ' . $delta . 'px;';
                        $result['style'] .= ' margin-bottom: ' . $delta . 'px;';
                        $result['margin-top'] = $delta;
                        $result['margin-bottom'] = $delta;
                    }
            }
            if (wppa_switch('wppa_use_thumb_opacity') && !is_feed()) {
                $opac = wppa_opt('wppa_thumb_opacity');
                $result['style'] .= ' opacity:' . $opac / 100 . '; filter:alpha( opacity=' . $opac . ' );';
            }
            // Cursor
            $linktyp = '';
            switch ($type) {
                case 'thumb':
                    // Normal
                    $linktyp = wppa_opt('wppa_thumb_linktype');
                    break;
                case 'ttthumb':
                    // Topten	v
                    $linktyp = wppa_opt('wppa_topten_widget_linktype');
                    break;
                case 'comthumb':
                    // Comment widget	v
                    $linktyp = wppa_opt('wppa_comment_widget_linktype');
                    break;
                case 'fthumb':
                    // Filmthumb
                    $linktyp = wppa_opt('wppa_film_linktype');
                    break;
                case 'twthumb':
                    // Thumbnail widget	v
                    $linktyp = wppa_opt('wppa_thumbnail_widget_linktype');
                    break;
                case 'ltthumb':
                    // Lasten widget	v
                    $linktyp = wppa_opt('wppa_lasten_widget_linktype');
                    break;
                case 'albthumb':
                    // Album widget
                    $linktyp = wppa_opt('wppa_album_widget_linktype');
            }
            if ($linktyp == 'none') {
                $result['cursor'] = ' cursor:default;';
            } elseif ($linktyp == 'lightbox') {
                $result['cursor'] = ' cursor:url(' . wppa_get_imgdir() . wppa_opt('wppa_magnifier') . '),pointer;';
            } else {
                $result['cursor'] = ' cursor:pointer;';
            }
            break;
        case 'fullsize':
            if ($wppa['auto_colwidth']) {
                // These sizes fit within the rectangle define by Table I-B1,2
                // times 2 for responsive themes,
                // and are supplied for ver 4 browsers as they have undefined natural sizes.
                $result['style'] .= ' max-width:' . $width * 2 . 'px;';
                $result['style'] .= ' max-height:' . $height * 2 . 'px;';
            } else {
                // These sizes fit within the rectangle define by Table I-B1,2
                // and are supplied for ver 4 browsers as they have undefined natural sizes.
                $result['style'] .= ' max-width:' . $width . 'px;';
                $result['style'] .= ' max-height:' . $height . 'px;';
                $result['style'] .= ' width:' . $width . 'px;';
                $result['style'] .= ' height:' . $height . 'px;';
            }
            if ($wppa['is_slideonly'] == '1') {
                if ($wppa['ss_widget_valign'] != '') {
                    $valign = $wppa['ss_widget_valign'];
                } else {
                    $valign = 'fit';
                }
            } elseif ($xvalign == 'optional') {
                $valign = wppa_opt('wppa_fullvalign');
            } else {
                $valign = $xvalign;
            }
            // Margin
            if ($valign != 'default') {
                $m_left = '0';
                $m_right = '0';
                $m_top = '0';
                $m_bottom = '0';
                // Center horizontally
                $delta = round(($max_size - $width) / 2);
                if ($delta < '0') {
                    $delta = '0';
                }
                if ($wppa['auto_colwidth']) {
                    $m_left = 'auto';
                    $m_right = 'auto';
                } else {
                    $m_left = $delta;
                    $m_right = '0';
                }
                // Position vertically
                if ($wppa['in_widget'] == 'ss' && $wppa['in_widget_frame_height'] > '0') {
                    $max_height = $wppa['in_widget_frame_height'];
                }
                $delta = '0';
                if (!$wppa['auto_colwidth'] && !wppa_page('oneofone')) {
                    switch ($valign) {
                        case 'top':
                        case 'fit':
                            $delta = '0';
                            break;
                        case 'center':
                            $delta = round(($max_height - $height) / 2);
                            if ($delta < '0') {
                                $delta = '0';
                            }
                            break;
                        case 'bottom':
                            $delta = $max_height - $height;
                            if ($delta < '0') {
                                $delta = '0';
                            }
                            break;
                    }
                }
                $m_top = $delta;
                $result['style'] .= wppa_combine_style('margin', $m_top, $m_left, $m_right, $m_bottom);
            }
            // Border and padding
            if (!$wppa['in_widget']) {
                switch (wppa_opt('wppa_fullimage_border_width')) {
                    case '':
                        break;
                    case '0':
                        $result['style'] .= ' border: 1px solid ' . wppa_opt('wppa_bcolor_fullimg') . ';';
                        break;
                    default:
                        $result['style'] .= ' border: 1px solid ' . wppa_opt('wppa_bcolor_fullimg') . ';';
                        $result['style'] .= ' background-color:' . wppa_opt('wppa_bgcolor_fullimg') . ';';
                        $result['style'] .= ' padding:' . wppa_opt('wppa_fullimage_border_width') . 'px;';
                        // If we do round corners...
                        if (wppa_opt('wppa_bradius') > '0') {
                            // then also here
                            $result['style'] .= ' border-radius:' . wppa_opt('wppa_fullimage_border_width') . 'px;';
                        }
                }
            }
            break;
        default:
            $wppa['out'] .= 'Error wrong "$type" argument: ' . $type . ' in wppa_get_imgstyle_a';
    }
    $result['width'] = $width;
    $result['height'] = $height;
    return $result;
}
Exemplo n.º 5
0
function wppa_get_photo_desc($id, $do_shortcodes = false, $do_geo = false)
{
    // Verify args
    if (!is_numeric($id) || $id < '1') {
        wppa_dbg_msg('Invalid arg wppa_get_photo_desc( ' . $id . ' )', 'red');
        return '';
    }
    // Get data
    $thumb = wppa_cache_thumb($id);
    $desc = $thumb['description'];
    // Raw data
    $desc = stripslashes($desc);
    // Unescape
    $desc = __($desc);
    // qTranslate
    // To prevent recursive rendering of scripts or shortcodes:
    $desc = str_replace(array('%%wppa%%', '[wppa', '[/wppa]'), array('%-wppa-%', '{wppa', '{/wppa}'), $desc);
    // Geo
    if ($thumb['location'] && !wppa('in_widget') && strpos(wppa_opt('custom_content'), 'w#location') !== false && $do_geo == 'do_geo') {
        wppa_do_geo($id, $thumb['location']);
    }
    // Other keywords
    if (strpos($desc, 'w#') !== false) {
        // Is there any 'w#' ?
        // Keywords
        $desc = str_replace('w#albumname', wppa_get_album_name($thumb['album']), $desc);
        $desc = str_replace('w#albumid', $thumb['album'], $desc);
        $keywords = array('name', 'filename', 'owner', 'id', 'tags', 'views', 'album');
        foreach ($keywords as $keyword) {
            $replacement = __(trim(stripslashes($thumb[$keyword])));
            if ($replacement == '') {
                $replacement = '&lsaquo;' . __a('none', 'wppa') . '&rsaquo;';
            }
            $desc = str_replace('w#' . $keyword, $replacement, $desc);
        }
        $desc = str_replace('w#url', wppa_get_lores_url($id), $desc);
        $desc = str_replace('w#hrurl', esc_attr(wppa_get_hires_url($id)), $desc);
        $desc = str_replace('w#tnurl', wppa_get_tnres_url($id), $desc);
        $desc = str_replace('w#pl', wppa_get_source_pl($id), $desc);
        // Art monkey sizes
        if (strpos($desc, 'w#amx') !== false || strpos($desc, 'w#amy') !== false || strpos($desc, 'w#amfs') !== false) {
            $amxy = wppa_get_artmonkey_size_a($id);
            if (is_array($amxy)) {
                $desc = str_replace('w#amx', $amxy['x'], $desc);
                $desc = str_replace('w#amy', $amxy['y'], $desc);
                $desc = str_replace('w#amfs', $amxy['s'], $desc);
            } else {
                $desc = str_replace('w#amx', 'N.a.', $desc);
                $desc = str_replace('w#amy', 'N.a.', $desc);
                $desc = str_replace('w#amfs', 'N.a.', $desc);
            }
        }
        // Timestamps
        $timestamps = array('timestamp', 'modified');
        foreach ($timestamps as $timestamp) {
            if ($thumb[$timestamp]) {
                $desc = str_replace('w#' . $timestamp, wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $thumb[$timestamp]), $desc);
            } else {
                $desc = str_replace('w#' . $timestamp, '&lsaquo;' . __a('unknown') . '&rsaquo;', $desc);
            }
        }
        // Custom data fields
        if (wppa_switch('custom_fields')) {
            $custom = $thumb['custom'];
            $custom_data = $custom ? unserialize($custom) : array('', '', '', '', '', '', '', '', '', '');
            for ($i = '0'; $i < '10'; $i++) {
                if (wppa_opt('custom_caption_' . $i)) {
                    // Field defined
                    if (wppa_switch('custom_visible_' . $i)) {
                        // May be displayed
                        $desc = str_replace('w#cc' . $i, __(wppa_opt('custom_caption_' . $i)) . ':', $desc);
                        // Caption
                        $desc = str_replace('w#cd' . $i, __(stripslashes($custom_data[$i])), $desc);
                        // Data
                    } else {
                        // May not be displayed
                        $desc = str_replace('w#cc' . $i, '', $desc);
                        // Remove
                        $desc = str_replace('w#cd' . $i, '', $desc);
                        // Remove
                    }
                } else {
                    // Field not defined
                    $desc = str_replace('w#cc' . $i, '', $desc);
                    // Remove
                    $desc = str_replace('w#cd' . $i, '', $desc);
                    // Remove
                }
            }
        }
    }
    // Shortcodes
    if ($do_shortcodes) {
        $desc = do_shortcode($desc);
    } else {
        $desc = strip_shortcodes($desc);
    }
    // Remove shortcodes if not wanted
    $desc = wppa_html($desc);
    // Enable html
    $desc = balanceTags($desc, true);
    // Balance tags
    $desc = wppa_filter_iptc($desc, $id);
    // Render IPTC tags
    $desc = wppa_filter_exif($desc, $id);
    // Render EXIF tags
    $desc = make_clickable($desc);
    // Auto make a tags for links
    $desc = convert_smilies($desc);
    // Make smilies visible
    // CMTooltipGlossary on board?
    $desc = wppa_filter_glossary($desc);
    return $desc;
}
function wppa_get_cloudinary_url($id, $test_only = false)
{
    global $blog_id;
    $thumb = wppa_cache_thumb($id);
    $ext = $thumb['ext'] == 'xxx' ? 'jpg' : $thumb['ext'];
    $prefix = is_multisite() && !WPPA_MULTISITE_GLOBAL ? $blog_id . '-' : '';
    $size = $test_only ? 'h_32/' : '';
    $s = is_ssl() ? 's' : '';
    $url = 'http' . $s . '://res.cloudinary.com/' . get_option('wppa_cdn_cloud_name') . '/image/upload/' . $size . $prefix . $id . '.' . $ext;
    return $url;
}
function wppa_add_metatags()
{
    global $wpdb;
    // Share info for sm that uses og
    $id = wppa_get_get('photo');
    if (!wppa_photo_exists($id)) {
        $id = false;
    }
    if ($id) {
        // SM may not accept images from the cloud.
        wppa('for_sm', true);
        $imgurl = wppa_get_photo_url($id);
        wppa('for_sm', false);
        if (wppa_is_video($id)) {
            $imgurl = wppa_fix_poster_ext($imgurl, $id);
        }
    } else {
        $imgurl = '';
    }
    if ($id) {
        if (wppa_switch('og_tags_on')) {
            $thumb = wppa_cache_thumb($id);
            if ($thumb) {
                $title = wppa_get_photo_name($id);
                $desc = wppa_get_og_desc($id);
                $url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                $site = get_bloginfo('name');
                $mime = wppa_get_mime_type($id);
                echo '
<!-- WPPA+ Og Share data -->
<meta property="og:site_name" content="' . esc_attr(sanitize_text_field($site)) . '" />
<meta property="og:type" content="article" />
<meta property="og:url" content="' . $url . '" />
<meta property="og:title" content="' . esc_attr(sanitize_text_field($title)) . '" />';
                if ($mime) {
                    echo '
<meta property="og:image" content="' . esc_url(sanitize_text_field($imgurl)) . '" />
<meta property="og:image:type" content="' . $mime . '" />
<meta property="og:image:width" content="' . wppa_get_photox($id) . '" />
<meta property="og:image:height" content="' . wppa_get_photoy($id) . '" />';
                }
                if ($desc) {
                    echo '
<meta property="og:description" content="' . esc_attr(sanitize_text_field($desc)) . '" />';
                }
                echo '
<!-- WPPA+ End Og Share data -->
';
            }
        }
        if (wppa_switch('share_twitter') && wppa_opt('twitter_account')) {
            $thumb = wppa_cache_thumb($id);
            // Twitter wants at least 280px in width, and at least 150px in height
            if ($thumb) {
                $x = wppa_get_photo_item($id, 'photox');
                $y = wppa_get_photo_item($id, 'photoy');
            }
            if ($thumb && $x >= 280 && $y >= 150) {
                $title = wppa_get_photo_name($id);
                $desc = wppa_get_og_desc($id);
                $url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                $site = get_bloginfo('name');
                echo '
<!-- WPPA+ Twitter Share data -->
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:site" content="' . wppa_opt('twitter_account') . '">
<meta name="twitter:creator" content="' . wppa_opt('twitter_account') . '">
<meta name="twitter:title" content="' . esc_attr(sanitize_text_field($title)) . '">
<meta name="twitter:description" content="' . esc_attr(sanitize_text_field($desc)) . '">
<meta name="twitter:image" content="' . esc_url(sanitize_text_field($imgurl)) . '">
<!-- WPPA+ End Twitter Share data -->
';
            } elseif ($thumb && $x >= 120 && $y >= 120) {
                $title = wppa_get_photo_name($id);
                $desc = wppa_get_og_desc($id);
                $url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                $site = get_bloginfo('name');
                echo '
<!-- WPPA+ Twitter Share data -->
<meta name="twitter:card" content="summary">
<meta name="twitter:site" content="' . wppa_opt('twitter_account') . '">
<meta name="twitter:title" content="' . esc_attr(sanitize_text_field($title)) . '">
<meta name="twitter:description" content="' . esc_attr(sanitize_text_field($desc)) . '">
<meta name="twitter:image" content="' . esc_url(sanitize_text_field($imgurl)) . '">
<!-- WPPA+ End Twitter Share data -->
';
            }
        }
    }
    // To make sure we are on a page that contains at least [wppa] we check for Get var 'wppa-album'.
    // This also narrows the selection of featured photos to those that exist in the current album.
    $done = array();
    $album = '';
    if (isset($_REQUEST['album'])) {
        $album = $_REQUEST['album'];
    } elseif (isset($_REQUEST['wppa-album'])) {
        $album = $_REQUEST['wppa-album'];
    }
    $album = strip_tags($album);
    if (strlen($album == 12)) {
        $album = wppa_get_get('album');
    }
    if ($album) {
        if (wppa_switch('meta_page')) {
            $photos = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s AND `status` = 'featured'", $album), ARRAY_A);
            wppa_cache_photo('add', $photos);
            if ($photos) {
                echo "\n<!-- WPPA+ BEGIN Featured photos on this page -->";
                foreach ($photos as $photo) {
                    $id = $photo['id'];
                    $content = esc_attr(sanitize_text_field(wppa_get_keywords($id)));
                    if ($content && !in_array($content, $done)) {
                        echo '
<meta name="keywords" content="' . $content . '" >';
                        $done[] = $content;
                    }
                }
                echo "\n<!-- WPPA+ END Featured photos on this page -->\n";
            }
        }
    } elseif (wppa_switch('meta_all')) {
        $photos = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` = 'featured'", ARRAY_A);
        wppa_cache_photo('add', $photos);
        if ($photos) {
            echo "\n<!-- WPPA+ BEGIN Featured photos on this site -->";
            foreach ($photos as $photo) {
                $thumb = $photo;
                // Set to global to reduce queries when getting the name
                $id = $photo['id'];
                $content = esc_attr(sanitize_text_field(wppa_get_keywords($id)));
                if ($content && !in_array($content, $done)) {
                    echo '
<meta name="keywords" content="' . $content . '" >';
                    $done[] = $content;
                }
            }
            echo "\n<!-- WPPA+ END Featured photos on this site -->\n";
        }
    }
    // Facebook Admin and App
    if ((wppa_switch('share_on') || wppa_switch('share_on_widget')) && (wppa_switch('facebook_comments') || wppa_switch('facebook_like') || wppa_switch('share_facebook'))) {
        echo "\n<!-- WPPA+ BEGIN Facebook meta tags -->";
        if (wppa_opt('facebook_admin_id')) {
            echo "\n\t<meta property=\"fb:admins\" content=\"" . wppa_opt('facebook_admin_id') . "\" />";
        }
        if (wppa_opt('facebook_app_id')) {
            echo "\n\t<meta property=\"fb:app_id\" content=\"" . wppa_opt('facebook_app_id') . "\" />";
        }
        if ($imgurl) {
            echo '
<link rel="image_src" href="' . esc_url($imgurl) . '" />';
        }
        echo '
<!-- WPPA+ END Facebook meta tags -->
';
    }
}
Exemplo n.º 8
0
function wppa_set_owner_to_name($id)
{
    global $wpdb;
    static $usercache;
    // Feature enabled?
    if (wppa_switch('owner_to_name')) {
        // Get photo data.
        $p = wppa_cache_thumb($id);
        // Find user of whose display name equals photoname
        if (isset($usercache[$p['name']])) {
            $user = $usercache[$p['name']];
        } else {
            $user = $wpdb->get_var($wpdb->prepare("SELECT `user_login` FROM `" . $wpdb->users . "` WHERE `display_name` = %s", $p['name']));
            if ($user) {
                $usercache[$p['name']] = $user;
            } else {
                $usercache[$p['name']] = false;
                // NULL is equal to ! isset() !!!
            }
        }
        if ($user) {
            if ($p['owner'] != $user) {
                wppa_update_photo(array('id' => $id, 'owner' => $user));
                wppa_cache_thumb('invalidate', $id);
                wppa_log('Obs', 'Owner of photo ' . $id . ' in album ' . wppa_get_photo_item($id, 'album') . ' set to: ' . $user);
                return true;
            } else {
                return '0';
            }
        }
    }
    return false;
}
Exemplo n.º 9
0
function wppa_recuperate($id)
{
    global $thumb;
    global $wpdb;
    wppa_cache_thumb($id);
    $iptcfix = false;
    $exiffix = false;
    $file = wppa_get_source_path($id);
    if (!is_file($file)) {
        $file = wppa_get_photo_path($id);
    }
    if (is_file($file)) {
        // Not a dir
        $attr = getimagesize($file, $info);
        if (is_array($attr)) {
            // Is a picturefile
            if ($attr[2] == IMAGETYPE_JPEG) {
                // Is a jpg
                if (wppa_switch('wppa_save_iptc')) {
                    // Save iptc
                    if (isset($info["APP13"])) {
                        // There is IPTC data
                        $is_iptc = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_IPTC . "` WHERE `photo` = %s", $id));
                        if (!$is_iptc) {
                            // No IPTC yet and there is: Recuperate
                            wppa_import_iptc($id, $info, 'nodelete');
                            $iptcfix = true;
                        }
                    }
                }
                if (wppa_switch('wppa_save_exif')) {
                    // Save exif
                    $image_type = exif_imagetype($file);
                    if ($image_type == IMAGETYPE_JPEG) {
                        // EXIF supported by server
                        $is_exif = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_EXIF . "` WHERE `photo`=%s", $id));
                        if (!$is_exif) {
                            // No EXIF yet
                            $exif = @exif_read_data($file, 'EXIF');
                            //@
                            if (is_array($exif)) {
                                // There is exif data present
                                wppa_import_exif($id, $file, 'nodelete');
                                $exiffix = true;
                            }
                        }
                    }
                }
            }
        }
    }
    return array('iptcfix' => $iptcfix, 'exiffix' => $exiffix);
}
function wppa_the_coverphoto($albumid, $image, $src, $photo_pos, $photolink, $title, $imgattr_a, $events)
{
    global $wpdb;
    if (!$image) {
        return;
    }
    if (wppa_has_audio($image['id'])) {
        $src = wppa_fix_poster_ext($src, $image['id']);
    }
    $imgattr = $imgattr_a['style'];
    $imgwidth = $imgattr_a['width'];
    $imgheight = $imgattr_a['height'];
    $frmwidth = $imgwidth + '10';
    // + 2 * 1 border + 2 * 4 padding
    // Find the photo frame style
    if (wppa_in_widget()) {
        $photoframestyle = 'style="text-align:center; "';
    } else {
        switch ($photo_pos) {
            case 'left':
                $photoframestyle = 'style="float:left; margin-right:5px;width:' . $frmwidth . 'px;"';
                break;
            case 'right':
                $photoframestyle = 'style="float:right; margin-left:5px;width:' . $frmwidth . 'px;"';
                break;
            case 'top':
                $photoframestyle = 'style="text-align:center;"';
                break;
            case 'bottom':
                $photoframestyle = 'style="text-align:center;"';
                break;
            default:
                $photoframestyle = '';
                wppa_dbg_msg('Illegal $photo_pos in wppa_the_coverphoto');
        }
    }
    // Open the coverphoto frame
    wppa_out('<div' . ' id="coverphoto_frame_' . $albumid . '_' . wppa('mocc') . '"' . ' class="coverphoto-frame" ' . $photoframestyle . ' >');
    // The link from the coverphoto
    if ($photolink) {
        // If lightbox, we need all the album photos to set up a lightbox set
        if ($photolink['is_lightbox']) {
            $thumbs = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s " . wppa_get_photo_order($albumid), $albumid), ARRAY_A);
            wppa_dbg_q('Q-CovPlB');
            // Report the query
            wppa_cache_thumb('add', $thumbs);
            // Save rsult in 2nd level cache
            if ($thumbs) {
                foreach ($thumbs as $thumb) {
                    $id = $thumb['id'];
                    $title = wppa_get_lbtitle('cover', $id);
                    if (wppa_is_video($id)) {
                        $siz['0'] = wppa_get_videox($id);
                        $siz['1'] = wppa_get_videoy($id);
                    } else {
                        $siz['0'] = wppa_get_photox($id);
                        $siz['1'] = wppa_get_photoy($id);
                    }
                    $link = wppa_get_photo_url($id, '', $siz['0'], $siz['1']);
                    if (wppa_has_audio($id)) {
                        $link = wppa_fix_poster_ext($link, $id);
                    }
                    $is_video = wppa_is_video($id);
                    $has_audio = wppa_has_audio($id);
                    // Open the anchor tag for lightbox
                    wppa_out("\n\t" . '<a' . ' href="' . $link . '"' . ($is_video ? ' data-videohtml="' . esc_attr(wppa_get_video_body($id)) . '"' . ' data-videonatwidth="' . wppa_get_videox($id) . '"' . ' data-videonatheight="' . wppa_get_videoy($id) . '"' : '') . ($has_audio ? ' data-audiohtml="' . esc_attr(wppa_get_audio_body($id)) . '"' : '') . ' ' . wppa('rel') . '="' . wppa_opt('lightbox_name') . '[alw-' . wppa('mocc') . '-' . $albumid . ']"' . ' ' . wppa('lbtitle') . '="' . $title . '"' . ' >');
                    // the cover image
                    if ($id == $image['id']) {
                        if (wppa_is_video($image['id'])) {
                            wppa_out('<video preload="metadata" class="image wppa-img" id="i-' . $image['id'] . '-' . wppa('mocc') . '" title="' . wppa_zoom_in($image['id']) . '" width="' . $imgwidth . '" height="' . $imgheight . '" style="' . __wcs('wppa-img') . $imgattr . $imgattr_a['cursor'] . '" ' . $events . ' >' . wppa_get_video_body($image['id']) . '</video>');
                        } else {
                            wppa_out('<img class="image wppa-img" id="i-' . $image['id'] . '-' . wppa('mocc') . '" title="' . wppa_zoom_in($image['id']) . '" src="' . $src . '" width="' . $imgwidth . '" height="' . $imgheight . '" style="' . __wcs('wppa-img') . $imgattr . $imgattr_a['cursor'] . '" ' . $events . ' ' . wppa_get_imgalt($image['id']) . ' />');
                        }
                    }
                    // Close the lightbox anchor tag
                    wppa_out("\n\t" . '</a>');
                }
            }
        } else {
            $href = $photolink['url'] == '#' ? '' : 'href="' . wppa_convert_to_pretty($photolink['url']) . '" ';
            wppa_out('<a' . ' ' . $href . ' target="' . $photolink['target'] . '"' . ' title="' . $photolink['title'] . '"' . ' onclick="' . $photolink['onclick'] . '"' . ' >');
            // A video?
            if (wppa_is_video($image['id'])) {
                wppa_out('<video preload="metadata" ' . $title . '" class="image wppa-img" width="' . $imgwidth . '" height="' . $imgheight . '" style="' . __wcs('wppa-img') . $imgattr . '" ' . $events . ' >' . wppa_get_video_body($image['id']) . '</video>');
            } else {
                wppa_out('<img src="' . $src . '" ' . wppa_get_imgalt($image['id']) . ' class="image wppa-img" width="' . $imgwidth . '" height="' . $imgheight . '" style="' . __wcs('wppa-img') . $imgattr . '" ' . $events . ' />');
            }
            wppa_out('</a>');
        }
    } else {
        // A video?
        if (wppa_is_video($image['id'])) {
            wppa_out('<video preload="metadata" class="image wppa-img" width="' . $imgwidth . '" height="' . $imgheight . '" style="' . __wcs('wppa-img') . $imgattr . '" ' . $events . ' >' . wppa_get_video_body($image['id']) . '</video>');
        } else {
            wppa_out('<img src="' . $src . '" ' . wppa_get_imgalt($image['id']) . ' class="image wppa-img" width="' . $imgwidth . '" height="' . $imgheight . '" style="' . __wcs('wppa-img') . $imgattr . '" ' . $events . ' />');
        }
    }
    // Close the coverphoto frame
    wppa_out('</div>');
}
function wppa_update_photo($args)
{
    global $wpdb;
    if (!is_array($args)) {
        return false;
    }
    if (!$args['id']) {
        return false;
    }
    $thumb = wppa_cache_thumb($args['id']);
    if (!$thumb) {
        return false;
    }
    $id = $args['id'];
    // If Timestamp update, make sure modified is updated to now
    if (isset($args['timestamp'])) {
        $args['modified'] = time();
    }
    foreach (array_keys($args) as $itemname) {
        $itemvalue = $args[$itemname];
        $doit = false;
        // Sanitize input
        switch ($itemname) {
            case 'id':
                break;
            case 'name':
                $itemvalue = wppa_strip_tags($itemvalue, 'all');
                $doit = true;
                break;
            case 'description':
                $itemvalue = balanceTags($itemvalue, true);
                $itemvalue = wppa_strip_tags($itemvalue, 'script&style');
                $doit = true;
                break;
            case 'timestamp':
            case 'modified':
                if (!$itemvalue) {
                    $itemvalue = time();
                }
                $doit = true;
                break;
            case 'scheduledtm':
            case 'exifdtm':
            case 'page_id':
                $doit = true;
                break;
            case 'status':
                $doit = true;
                break;
            case 'tags':
                $itemvalue = wppa_sanitize_tags($itemvalue);
                $doit = true;
                break;
            case 'thumbx':
            case 'thumby':
            case 'photox':
            case 'photoy':
            case 'videox':
            case 'videoy':
                $itemvalue = intval($itemvalue);
                $doit = true;
                break;
            case 'ext':
                $doit = true;
                break;
            case 'filename':
                $itemvalue = wppa_sanitize_file_name($itemvalue);
                $doit = true;
                break;
            case 'custom':
            case 'stereo':
                $doit = true;
                break;
            default:
                wppa_log('Error', 'Not implemented in wppa_update_photo(): ' . $itemname);
                return false;
        }
        if ($doit) {
            if ($wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `" . $itemname . "` = %s WHERE `id` = %s LIMIT 1", $itemvalue, $id))) {
                wppa_cache_photo('invalidate', $id);
            }
        }
    }
    return true;
}
function wppa_recuperate($id)
{
    global $wpdb;
    $thumb = wppa_cache_thumb($id);
    $iptcfix = false;
    $exiffix = false;
    $file = wppa_get_source_path($id);
    if (!is_file($file)) {
        $file = wppa_get_photo_path($id);
    }
    if (is_file($file)) {
        // Not a dir
        $attr = getimagesize($file, $info);
        if (is_array($attr)) {
            // Is a picturefile
            if ($attr[2] == IMAGETYPE_JPEG) {
                // Is a jpg
                // Save iptc is on?
                if (wppa_switch('save_iptc')) {
                    // There is IPTC data
                    if (isset($info["APP13"])) {
                        // If this is a cron prcess, the table is not pre-emptied
                        if (wppa_is_cron()) {
                            // Replace or add data
                            wppa_import_iptc($id, $info);
                        } else {
                            wppa_import_iptc($id, $info, 'nodelete');
                        }
                        $iptcfix = true;
                    }
                }
                // Save exif is on?
                if (wppa_switch('save_exif')) {
                    $image_type = exif_imagetype($file);
                    // EXIF supported by server
                    if ($image_type == IMAGETYPE_JPEG) {
                        // Get exif data
                        $exif = exif_read_data($file, 'EXIF');
                        // Exif data found
                        if ($exif) {
                            // If this is a cron prcess, the table is not pre-emptied
                            if (wppa_is_cron()) {
                                // Replace or add data
                                wppa_import_exif($id, $file);
                            } else {
                                wppa_import_exif($id, $file, 'nodelete');
                            }
                            $exiffix = true;
                        }
                    }
                }
            }
        }
    }
    return array('iptcfix' => $iptcfix, 'exiffix' => $exiffix);
}
Exemplo n.º 13
0
function wppa_translate_photo_keywords($id, $text)
{
    $result = $text;
    // Is there any 'w#' ?
    if (strpos($result, 'w#') !== false) {
        $thumb = wppa_cache_thumb($id);
        // Keywords
        $result = str_replace('w#albumname', wppa_get_album_name($thumb['album']), $result);
        $result = str_replace('w#albumid', $thumb['album'], $result);
        $keywords = array('name', 'filename', 'owner', 'id', 'tags', 'views', 'album');
        foreach ($keywords as $keyword) {
            $replacement = __(trim(stripslashes($thumb[$keyword])), 'wp-photo-album-plus');
            if ($keyword == 'tags') {
                $replacement = trim($replacement, ',');
            }
            if ($replacement == '') {
                $replacement = '&lsaquo;' . __('none', 'wp-photo-album-plus') . '&rsaquo;';
            }
            $result = str_replace('w#' . $keyword, $replacement, $result);
        }
        $result = str_replace('w#url', wppa_get_lores_url($id), $result);
        $result = str_replace('w#hrurl', esc_attr(wppa_get_hires_url($id)), $result);
        $result = str_replace('w#tnurl', wppa_get_tnres_url($id), $result);
        $result = str_replace('w#pl', wppa_get_source_pl($id), $result);
        $result = str_replace('w#rating', wppa_get_rating_by_id($id, 'nolabel'), $result);
        $user = get_user_by('login', $thumb['owner']);
        if ($user) {
            $result = str_replace('w#displayname', $user->display_name, $result);
        } else {
            $owner = wppa_get_photo_item($id, 'owner');
            if (strpos($owner, '.') == false && strpos($owner, ':') == false) {
                // Not an ip, a deleted user
                $result = str_replace('w#displayname', __('Nomen Nescio', 'wp-photo-album-plus'), $result);
            } else {
                // An ip
                $result = str_replace('w#displayname', __('Anonymus', 'wp-photo-album-plus'), $result);
            }
        }
        // Art monkey sizes
        if (strpos($result, 'w#amx') !== false || strpos($result, 'w#amy') !== false || strpos($result, 'w#amfs') !== false) {
            $amxy = wppa_get_artmonkey_size_a($id);
            if (is_array($amxy)) {
                $result = str_replace('w#amx', $amxy['x'], $result);
                $result = str_replace('w#amy', $amxy['y'], $result);
                $result = str_replace('w#amfs', $amxy['s'], $result);
            } else {
                $result = str_replace('w#amx', 'N.a.', $result);
                $result = str_replace('w#amy', 'N.a.', $result);
                $result = str_replace('w#amfs', 'N.a.', $result);
            }
        }
        // Timestamps
        $timestamps = array('timestamp', 'modified');
        foreach ($timestamps as $timestamp) {
            if ($thumb[$timestamp]) {
                $result = str_replace('w#' . $timestamp, wppa_local_date(get_option('date_format', "F j, Y,") . ' ' . get_option('time_format', "g:i a"), $thumb[$timestamp]), $result);
            } else {
                $result = str_replace('w#' . $timestamp, '&lsaquo;' . __('unknown', 'wp-photo-album-plus') . '&rsaquo;', $result);
            }
        }
        // Custom data fields
        if (wppa_switch('custom_fields')) {
            $custom = $thumb['custom'];
            $custom_data = $custom ? unserialize($custom) : array('', '', '', '', '', '', '', '', '', '');
            for ($i = '0'; $i < '10'; $i++) {
                if (wppa_opt('custom_caption_' . $i)) {
                    // Field defined
                    if (wppa_switch('custom_visible_' . $i)) {
                        // May be displayed
                        $result = str_replace('w#cc' . $i, __(wppa_opt('custom_caption_' . $i), 'wp-photo-album-plus') . ':', $result);
                        // Caption
                        $result = str_replace('w#cd' . $i, __(stripslashes($custom_data[$i]), 'wp-photo-album-plus'), $result);
                        // Data
                    } else {
                        // May not be displayed
                        $result = str_replace('w#cc' . $i, '', $result);
                        // Remove
                        $result = str_replace('w#cd' . $i, '', $result);
                        // Remove
                    }
                } else {
                    // Field not defined
                    $result = str_replace('w#cc' . $i, '', $result);
                    // Remove
                    $result = str_replace('w#cd' . $i, '', $result);
                    // Remove
                }
            }
        }
    }
    return $result;
}
function wppa_get_videoy($id)
{
    if (!wppa_is_video($id)) {
        return '0';
    }
    $thumb = wppa_cache_thumb($id);
    if ($thumb['videoy']) {
        return $thumb['videoy'];
    }
    return wppa_opt('video_height');
}
Exemplo n.º 15
0
function wppa_get_the_bestof($count, $period, $sortby, $what)
{
    global $wppa_opt;
    global $wpdb;
    global $thumb;
    // Phase 1, find the period we are talking about
    // find $start and $end
    switch ($period) {
        case 'lastweek':
            $start = wppa_get_timestamp('lastweekstart');
            $end = wppa_get_timestamp('lastweekend');
            break;
        case 'thisweek':
            $start = wppa_get_timestamp('thisweekstart');
            $end = wppa_get_timestamp('thisweekend');
            break;
        case 'lastmonth':
            $start = wppa_get_timestamp('lastmonthstart');
            $end = wppa_get_timestamp('lastmonthend');
            break;
        case 'thismonth':
            $start = wppa_get_timestamp('thismonthstart');
            $end = wppa_get_timestamp('thismonthend');
            break;
        case 'lastyear':
            $start = wppa_get_timestamp('lastyearstart');
            $end = wppa_get_timestamp('lastyearend');
            break;
        case 'thisyear':
            $start = wppa_get_timestamp('thisyearstart');
            $end = wppa_get_timestamp('thisyearend');
            break;
        default:
            return 'Unimplemented period: ' . $period;
    }
    // Phase 2, get the ratings of the period
    // find $ratings, ordered by photo id
    $ratings = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_RATING . "` WHERE `timestamp` >= %s AND `timestamp` < %s ORDER BY `photo`", $start, $end), ARRAY_A);
    // Phase 3, set up an array with data we need
    // There are two methods: photo oriented and owner oriented, depending on
    // Each element reflects a photo ( key = photo id ) and is an array with items: maxratings, meanrating, ratings, totvalue.
    $ratmax = $wppa_opt['wppa_rating_max'];
    $data = array();
    foreach ($ratings as $rating) {
        $key = $rating['photo'];
        if (!isset($data[$key])) {
            $data[$key] = array();
            $data[$key]['ratingcount'] = '1';
            $data[$key]['maxratingcount'] = $rating['value'] == $ratmax ? '1' : '0';
            $data[$key]['totvalue'] = $rating['value'];
        } else {
            $data[$key]['ratingcount'] += '1';
            $data[$key]['maxratingcount'] += $rating['value'] == $ratmax ? '1' : '0';
            $data[$key]['totvalue'] += $rating['value'];
        }
    }
    foreach (array_keys($data) as $key) {
        wppa_cache_thumb($key);
        $data[$key]['meanrating'] = $data[$key]['totvalue'] / $data[$key]['ratingcount'];
        $user = get_user_by('login', $thumb['owner']);
        if ($user) {
            $data[$key]['user'] = $user->display_name;
        } else {
            // user deleted
            $data[$key]['user'] = $thumb['owner'];
        }
        $data[$key]['owner'] = $thumb['owner'];
    }
    // Now we split into search for photos and search for owners
    if ($what == 'photo') {
        // Pase 4, sort to the required sequence
        $data = wppa_array_sort($data, $sortby, SORT_DESC);
    } else {
        // $what == 'owner'
        // Phase 4, combine all photos of the same owner
        wppa_array_sort($data, 'user');
        $temp = $data;
        $data = array();
        foreach (array_keys($temp) as $key) {
            if (!isset($data[$temp[$key]['user']])) {
                $data[$temp[$key]['user']]['photos'] = '1';
                $data[$temp[$key]['user']]['ratingcount'] = $temp[$key]['ratingcount'];
                $data[$temp[$key]['user']]['maxratingcount'] = $temp[$key]['maxratingcount'];
                $data[$temp[$key]['user']]['totvalue'] = $temp[$key]['totvalue'];
                $data[$temp[$key]['user']]['owner'] = $temp[$key]['owner'];
            } else {
                $data[$temp[$key]['user']]['photos'] += '1';
                $data[$temp[$key]['user']]['ratingcount'] += $temp[$key]['ratingcount'];
                $data[$temp[$key]['user']]['maxratingcount'] += $temp[$key]['maxratingcount'];
                $data[$temp[$key]['user']]['totvalue'] += $temp[$key]['totvalue'];
            }
        }
        foreach (array_keys($data) as $key) {
            $data[$key]['meanrating'] = $data[$key]['totvalue'] / $data[$key]['ratingcount'];
        }
        $data = wppa_array_sort($data, $sortby, SORT_DESC);
    }
    // Phase 5, truncate to the desired length
    $c = '0';
    foreach (array_keys($data) as $key) {
        $c += '1';
        if ($c > $count) {
            unset($data[$key]);
        }
    }
    // Phase 6, return the result
    if (count($data)) {
        return $data;
    } else {
        return 'There are no ratings between <br />' . wppa_local_date('F j, Y, H:i s', $start) . ' and <br />' . wppa_local_date('F j, Y, H:i s', $end) . '.';
    }
}
function wppa_get_lbtitle($type, $id)
{
    if (!is_numeric($id) || $id < '1') {
        wppa_dbg_msg('Invalid arg wppa_get_lbtitle( ' . $id . ' )', 'red');
    }
    $thumb = wppa_cache_thumb($id);
    $do_download = wppa_is_video($id) ? false : wppa_switch('art_monkey_on_lightbox');
    if ($type == 'xphoto') {
        $type = 'mphoto';
    }
    $do_name = wppa_switch('ovl_' . $type . '_name') || wppa_switch('ovl_add_owner');
    $do_desc = wppa_switch('ovl_' . $type . '_desc');
    $do_sm = wppa_switch('share_on_lightbox');
    $result = '';
    if ($do_download) {
        if (wppa_opt('art_monkey_display') == 'button') {
            $result .= '<input' . ' type="button"' . ' title="' . __('Download', 'wp-photo-album-plus') . '"' . ' style="cursor:pointer; margin-bottom:0px; max-width:500px;"' . ' class="wppa-download-button wppa-ovl-button"' . ' onclick="wppaAjaxMakeOrigName( ' . wppa('mocc') . ', \'' . wppa_encrypt_photo($id) . '\' );"' . ' value="' . rtrim(__('Download', 'wp-photo-album-plus') . ' ' . wppa_get_photo_name($id, wppa_switch('ovl_add_owner'), false, false, wppa_switch('ovl_' . $type . '_name'))) . '"' . ' />';
        } else {
            $result .= '<a' . ' title="' . __('Download', 'wp-photo-album-plus') . '"' . ' style="cursor:pointer;"' . ' onclick="wppaAjaxMakeOrigName( ' . wppa('mocc') . ', \'' . wppa_encrypt_photo($id) . '\' );"' . ' >' . rtrim(__('Download', 'wp-photo-album-plus') . ' ' . wppa_get_photo_name($id, wppa_switch('ovl_add_owner'), false, false, wppa_switch('ovl_' . $type . '_name'))) . '</a>';
        }
    } else {
        if ($do_name) {
            $result .= wppa_get_photo_name($id, wppa_switch('ovl_add_owner'), false, false, wppa_switch('ovl_' . $type . '_name'));
        }
    }
    if ($do_name && $do_desc) {
        $result .= '<br />';
    }
    if ($do_desc) {
        $result .= wppa_get_photo_desc($thumb['id']);
    }
    if (($do_name || $do_desc) && $do_sm) {
        $result .= '<br />';
    }
    if (wppa_opt('rating_max') != '1' && wppa_opt('rating_display_type') == 'graphic') {
        $result .= wppa_get_rating_range_html($id, true);
    } elseif (wppa_opt('rating_display_type') == 'likes' && wppa_switch('ovl_rating')) {
        $result .= wppa_get_slide_rating_vote_only('always', $id, 'is_lightbox');
    }
    if ($do_sm) {
        $result .= wppa_get_share_html($thumb['id'], 'lightbox');
    }
    if (wppa_may_user_fe_edit($id)) {
        if ($type == 'slide') {
            $parg = esc_js('\'' . wppa_encrypt_photo($id) . '\'');
        } else {
            $parg = '\'' . wppa_encrypt_photo($id) . '\'';
        }
        if (wppa_opt('upload_edit') == 'classic') {
            $result .= '
			<input' . ' type="button"' . ' style="float:right; margin-right:6px;"' . ' class="wppa-ovl-button"' . ' onclick="' . ($type == 'slide' ? '_wppaStop( ' . wppa('mocc') . ' );' : '') . 'wppaEditPhoto( ' . wppa('mocc') . ', ' . $parg . ' );"' . ' value="' . esc_attr(__(wppa_opt('fe_edit_button'))) . '"' . ' />';
        }
    }
    $result = esc_attr($result);
    return $result;
}
function wppa_index_quick_remove($type, $id)
{
    global $wpdb;
    if ($type == 'album') {
        $album = wppa_cache_album($id);
        $words = stripslashes($album['name']) . ' ' . stripslashes($album['description']) . ' ' . $album['cats'];
        $words = wppa_index_raw_to_words($words);
        foreach ($words as $word) {
            $indexline = $wpdb->get_row("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` = '" . $word . "'", ARRAY_A);
            $array = wppa_index_string_to_array($indexline['albums']);
            foreach (array_keys($array) as $k) {
                if ($array[$k] == $id) {
                    unset($array[$k]);
                    $string = wppa_index_array_to_string($array);
                    if ($string || $indexline['photos']) {
                        $wpdb->query("UPDATE `" . WPPA_INDEX . "` SET `albums` = '" . $string . "' WHERE `id` = " . $indexline['id']);
                    } else {
                        $wpdb->query("DELETE FROM `" . WPPA_INDEX . "` WHERE `id` = " . $indexline['id']);
                    }
                }
            }
        }
    } elseif ($type == 'photo') {
        $thumb = wppa_cache_thumb($id);
        // Find the raw text
        $words = stripslashes($thumb['name']) . ' ' . $thumb['filename'] . ' ' . stripslashes($thumb['description']) . ' ' . $thumb['tags'];
        $coms = $wpdb->get_results($wpdb->prepare("SELECT `comment` FROM `" . WPPA_COMMENTS . "` WHERE `photo` = %s AND `status` = 'approved'", $thumb['id']), ARRAY_A);
        if ($coms) {
            foreach ($coms as $com) {
                $words .= ' ' . stripslashes($com['comment']);
            }
        }
        $words = wppa_index_raw_to_words($words, 'noskips');
        foreach ($words as $word) {
            $indexline = $wpdb->get_row("SELECT * FROM `" . WPPA_INDEX . "` WHERE `slug` = '" . $word . "'", ARRAY_A);
            $array = wppa_index_string_to_array($indexline['photos']);
            foreach (array_keys($array) as $k) {
                if ($array[$k] == $id) {
                    unset($array[$k]);
                    $string = wppa_index_array_to_string($array);
                    if ($string || $indexline['albums']) {
                        $wpdb->query("UPDATE `" . WPPA_INDEX . "` SET `photos` = '" . $string . "' WHERE `id` = " . $indexline['id']);
                    } else {
                        $wpdb->query("DELETE FROM `" . WPPA_INDEX . "` WHERE `id` = " . $indexline['id']);
                    }
                }
            }
        }
    }
}
function wppa_get_lbtitle($type, $id)
{
    if (!is_numeric($id) || $id < '1') {
        wppa_dbg_msg('Invalid arg wppa_get_lbtitle( ' . $id . ' )', 'red');
    }
    $thumb = wppa_cache_thumb($id);
    $do_download = wppa_is_video($id) ? false : wppa_switch('art_monkey_on_lightbox');
    $do_name = wppa_switch('ovl_' . $type . '_name') || wppa_switch('ovl_add_owner');
    $do_desc = wppa_switch('ovl_' . $type . '_desc');
    $do_sm = wppa_switch('share_on_lightbox');
    $result = '';
    if ($do_download) {
        if (wppa_opt('art_monkey_display') == 'button') {
            $result .= '<input' . ' type="button"' . ' title="' . __('Download', 'wp-photo-album-plus') . '"' . ' style="cursor:pointer; margin-bottom:0px; max-width:500px;"' . ' class="wppa-download-button"' . ' onclick="wppaAjaxMakeOrigName( ' . wppa('mocc') . ', ' . $id . ' );"' . ' value="' . __('Download:', 'wp-photo-album-plus') . ' ' . wppa_get_photo_name($id, wppa_switch('ovl_add_owner'), false, false, wppa_switch('ovl_' . $type . '_name')) . '"' . ' />';
        } else {
            $result .= '<a' . ' title="' . __('Download', 'wp-photo-album-plus') . '"' . ' style="cursor:pointer;"' . ' onclick="wppaAjaxMakeOrigName( ' . wppa('mocc') . ', ' . $id . ' );"' . ' >' . __('Download:', 'wp-photo-album-plus') . ' ' . wppa_get_photo_name($id, wppa_switch('ovl_add_owner'), false, false, wppa_switch('ovl_' . $type . '_name')) . '</a>';
        }
    } else {
        if ($do_name) {
            $result .= wppa_get_photo_name($id, wppa_switch('ovl_add_owner'), false, false, wppa_switch('ovl_' . $type . '_name'));
        }
    }
    if ($do_name && $do_desc) {
        $result .= '<br />';
    }
    if ($do_desc) {
        $result .= wppa_get_photo_desc($thumb['id']);
    }
    if (($do_name || $do_desc) && $do_sm) {
        $result .= '<br />';
    }
    if ($do_sm) {
        $result .= wppa_get_share_html($thumb['id'], 'lightbox');
    }
    $result = esc_attr($result);
    return $result;
}
function wppa_get_date_time_select_html($type, $id, $selectable = true)
{
    $type = strtoupper(substr($type, 0, 1)) . strtolower(substr($type, 1));
    if ($type == 'Photo') {
        $thumb = wppa_cache_thumb($id);
    } elseif ($type == 'Album') {
        $album = wppa_cache_album($id);
    } else {
        wppa_error_message('Uniplemented type: ' . $type . ' in wppa_get_date_time_select_html()');
    }
    $opt_months = array('1' => __('Jan', 'wp-photo-album-plus'), '2' => __('Feb', 'wp-photo-album-plus'), '3' => __('Mar', 'wp-photo-album-plus'), '4' => __('Apr', 'wp-photo-album-plus'), '5' => __('May', 'wp-photo-album-plus'), '6' => __('Jun', 'wp-photo-album-plus'), '7' => __('Jul', 'wp-photo-album-plus'), '8' => __('Aug', 'wp-photo-album-plus'), '9' => __('Sep', 'wp-photo-album-plus'), '10' => __('Oct', 'wp-photo-album-plus'), '11' => __('Nov', 'wp-photo-album-plus'), '12' => __('Dec', 'wp-photo-album-plus'));
    $val_months = array('1' => '01', '2' => '02', '3' => '03', '4' => '04', '5' => '05', '6' => '06', '7' => '07', '8' => '08', '9' => '09', '10' => '10', '11' => '11', '12' => '12');
    $opt_years = array('2014', '2015', '2016', '2017', '2018', '2019', '2020');
    $val_years = $opt_years;
    $opt_days = array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31');
    $val_days = $opt_days;
    $opt_hours = array('00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23');
    $val_hours = $opt_hours;
    $opt_mins = array('00', '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36', '37', '38', '39', '40', '41', '42', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59');
    $val_mins = $opt_mins;
    $curval = $type == 'Photo' ? $thumb['scheduledtm'] : $album['scheduledtm'];
    if (!$curval) {
        $curval = wppa_get_default_scheduledtm();
    }
    $temp = explode(',', $curval);
    $cur_day = $temp[2];
    $cur_month = $temp[1];
    $cur_year = $temp[0];
    $cur_hour = $temp[3];
    $cur_min = $temp[4];
    $result = '';
    if ($selectable) {
        $result .= '<select name="wppa-day" id="wppa-day-' . $id . '" class="wppa-datetime-' . $id . '" onchange="wppaAjaxUpdate' . $type . '(' . $id . ', \'day\', this);" >';
        foreach (array_keys($opt_days) as $key) {
            $sel = $val_days[$key] == $cur_day ? 'selected="selected"' : '';
            $result .= '<option value="' . $val_days[$key] . '" ' . $sel . ' >' . $opt_days[$key] . '</option>';
        }
        $result .= '</select >';
        $result .= '<select name="wppa-month" id="wppa-month-' . $id . '" class="wppa-datetime-' . $id . '" onchange="wppaAjaxUpdate' . $type . '(' . $id . ', \'month\', this);" >';
        foreach (array_keys($opt_months) as $key) {
            $sel = $val_months[$key] == $cur_month ? 'selected="selected"' : '';
            $result .= '<option value="' . $val_months[$key] . '" ' . $sel . ' >' . $opt_months[$key] . '</option>';
        }
        $result .= '</select >';
        $result .= '<select name="wppa-year" id="wppa-year-' . $id . '" class="wppa-datetime-' . $id . '" onchange="wppaAjaxUpdate' . $type . '(' . $id . ', \'year\', this);" >';
        foreach (array_keys($opt_years) as $key) {
            $sel = $val_years[$key] == $cur_year ? 'selected="selected"' : '';
            $result .= '<option value="' . $val_years[$key] . '" ' . $sel . ' >' . $opt_years[$key] . '</option>';
        }
        $result .= '</select >@';
        $result .= '<select name="wppa-hour" id="wppa-hour-' . $id . '" class="wppa-datetime-' . $id . '" onchange="wppaAjaxUpdate' . $type . '(' . $id . ', \'hour\', this);" >';
        foreach (array_keys($opt_hours) as $key) {
            $sel = $val_hours[$key] == $cur_hour ? 'selected="selected"' : '';
            $result .= '<option value="' . $val_hours[$key] . '" ' . $sel . ' >' . $opt_hours[$key] . '</option>';
        }
        $result .= '</select >:';
        $result .= '<select name="wppa-min" id="wppa-min-' . $id . '" class="wppa-datetime-' . $id . '" onchange="wppaAjaxUpdate' . $type . '(' . $id . ', \'min\', this);">';
        foreach (array_keys($opt_mins) as $key) {
            $sel = $val_mins[$key] == $cur_min ? 'selected="selected"' : '';
            $result .= '<option value="' . $val_mins[$key] . '" ' . $sel . ' >' . $opt_mins[$key] . '</option>';
        }
        $result .= '</select >';
    } else {
        $result .= '<span class="wppa-datetime-' . $id . '" >' . $cur_day . ' ' . $opt_months[strval(intval($cur_month))] . ' ' . $cur_year . '@' . $cur_hour . ':' . $cur_min . '</span>';
    }
    return $result;
}
Exemplo n.º 20
0
function wppa_get_imglnk_a($wich, $id, $lnk = '', $tit = '', $onc = '', $noalb = false, $album = '')
{
    global $wpdb;
    // make sure the photo data ia available
    $thumb = wppa_cache_thumb($id);
    if (!$thumb) {
        return false;
    }
    // Is it a video?
    $is_video = wppa_is_video($id, true);
    // Photo Specific Overrule?
    if ($wich == 'sphoto' && wppa_switch('sphoto_overrule') || $wich == 'mphoto' && wppa_switch('mphoto_overrule') || $wich == 'thumb' && wppa_switch('thumb_overrule') || $wich == 'topten' && wppa_switch('topten_overrule') || $wich == 'featen' && wppa_switch('featen_overrule') || $wich == 'lasten' && wppa_switch('lasten_overrule') || $wich == 'sswidget' && wppa_switch('sswidget_overrule') || $wich == 'potdwidget' && wppa_switch('potdwidget_overrule') || $wich == 'coverimg' && wppa_switch('coverimg_overrule') || $wich == 'comten' && wppa_switch('comment_overrule') || $wich == 'slideshow' && wppa_switch('slideshow_overrule') || $wich == 'tnwidget' && wppa_switch('thumbnail_widget_overrule')) {
        // Look for a photo specific link
        if ($thumb) {
            // If it is there...
            if ($thumb['linkurl']) {
                // Use it. It superceeds other settings
                $result['url'] = esc_attr($thumb['linkurl']);
                $result['title'] = esc_attr(__(stripslashes($thumb['linktitle'])));
                $result['is_url'] = true;
                $result['is_lightbox'] = false;
                $result['onclick'] = '';
                $result['target'] = $thumb['linktarget'];
                return $result;
            }
        }
    }
    $result['target'] = '_self';
    $result['title'] = '';
    $result['onclick'] = '';
    switch ($wich) {
        case 'sphoto':
            $type = wppa_opt('sphoto_linktype');
            $page = wppa_opt('sphoto_linkpage');
            if ($page == '0') {
                $page = '-1';
            }
            if (wppa_switch('sphoto_blank')) {
                $result['target'] = '_blank';
            }
            break;
        case 'mphoto':
            $type = wppa_opt('mphoto_linktype');
            $page = wppa_opt('mphoto_linkpage');
            if ($page == '0') {
                $page = '-1';
            }
            if (wppa_switch('mphoto_blank')) {
                $result['target'] = '_blank';
            }
            break;
        case 'thumb':
            $type = wppa_opt('thumb_linktype');
            $page = wppa_opt('thumb_linkpage');
            if (wppa_switch('thumb_blank')) {
                $result['target'] = '_blank';
            }
            break;
        case 'topten':
            $type = wppa_opt('topten_widget_linktype');
            $page = wppa_opt('topten_widget_linkpage');
            if ($page == '0') {
                $page = '-1';
            }
            if (wppa_switch('topten_blank')) {
                $result['target'] = '_blank';
            }
            break;
        case 'featen':
            $type = wppa_opt('featen_widget_linktype');
            $page = wppa_opt('featen_widget_linkpage');
            if ($page == '0') {
                $page = '-1';
            }
            if (wppa_switch('featen_blank')) {
                $result['target'] = '_blank';
            }
            break;
        case 'lasten':
            $type = wppa_opt('lasten_widget_linktype');
            $page = wppa_opt('lasten_widget_linkpage');
            if ($page == '0') {
                $page = '-1';
            }
            if (wppa_switch('lasten_blank')) {
                $result['target'] = '_blank';
            }
            break;
        case 'comten':
            $type = wppa_opt('comment_widget_linktype');
            $page = wppa_opt('comment_widget_linkpage');
            if ($page == '0') {
                $page = '-1';
            }
            if (wppa_switch('comment_blank')) {
                $result['target'] = '_blank';
            }
            break;
        case 'sswidget':
            $type = wppa_opt('slideonly_widget_linktype');
            $page = wppa_opt('slideonly_widget_linkpage');
            if ($page == '0') {
                $page = '-1';
            }
            if (wppa_switch('sswidget_blank')) {
                $result['target'] = '_blank';
            }
            $result['url'] = '';
            if ($type == 'lightbox' || $type == 'lightboxsingle' || $type == 'file') {
                $result['title'] = wppa_zoom_in($id);
                $result['target'] = '';
                return $result;
            }
            break;
        case 'potdwidget':
            $type = wppa_opt('widget_linktype');
            $page = wppa_opt('widget_linkpage');
            if ($page == '0') {
                $page = '-1';
            }
            if (wppa_switch('potd_blank')) {
                $result['target'] = '_blank';
            }
            break;
        case 'coverimg':
            $type = wppa_opt('coverimg_linktype');
            $page = wppa_opt('coverimg_linkpage');
            if ($page == '0') {
                $page = '-1';
            }
            if (wppa_switch('coverimg_blank')) {
                $result['target'] = '_blank';
            }
            if ($type == 'slideshowstartatimage') {
                $result['url'] = wppa_get_slideshow_url($album, $page, $id);
                $result['is_url'] = true;
                $result['is_lightbox'] = false;
                return $result;
            }
            break;
        case 'tnwidget':
            $type = wppa_opt('thumbnail_widget_linktype');
            $page = wppa_opt('thumbnail_widget_linkpage');
            if ($page == '0') {
                $page = '-1';
            }
            if (wppa_switch('thumbnail_widget_blank')) {
                $result['target'] = '_blank';
            }
            break;
        case 'slideshow':
            $type = wppa_opt('slideshow_linktype');
            //'';
            $page = wppa_opt('slideshow_linkpage');
            $result['url'] = '';
            if ($type == 'lightbox' || $type == 'lightboxsingle' || $type == 'file') {
                $result['title'] = wppa_zoom_in($id);
                $result['target'] = '';
                return $result;
            }
            if ($type == 'thumbs') {
                $result['url'] = wppa_get_ss_to_tn_link($page, $id);
                $result['title'] = __('View thumbnails', 'wp-photo-album-plus');
                $result['is_url'] = true;
                $result['is_lightbox'] = false;
                if (wppa_switch('slideshow_blank')) {
                    $result['target'] = '_blank';
                }
                return $result;
            }
            if ($type == 'none') {
                return;
            }
            // Continue for 'single'
            break;
        case 'albwidget':
            $type = wppa_opt('album_widget_linktype');
            $page = wppa_opt('album_widget_linkpage');
            if ($page == '0') {
                $page = '-1';
            }
            if (wppa_switch('album_widget_blank')) {
                $result['target'] = '_blank';
            }
            break;
        default:
            return false;
            break;
    }
    if (!$album) {
        $album = wppa('start_album');
    }
    if ($album == '' && !wppa('is_upldr')) {
        /**/
        $album = wppa_get_album_id_by_photo_id($id);
    }
    if (is_numeric($album)) {
        $album_name = wppa_get_album_name($album);
    } else {
        $album_name = '';
    }
    if (!$album) {
        $album = '0';
    }
    if ($wich == 'comten') {
        $album = '0';
    }
    if (wppa('is_tag')) {
        $album = '0';
    }
    if (wppa('supersearch')) {
        $album = '0';
    }
    if (wppa('calendar')) {
        $album = wppa('start_album') ? wppa('start_album') : '0';
    }
    //	if ( wppa( 'is_upldr' ) ) $album = '0';	// probeersel upldr parent
    if ($id) {
        $photo_name = wppa_get_photo_name($id);
    } else {
        $photo_name = '';
    }
    $photo_name_js = esc_js($photo_name);
    $photo_name = esc_attr($photo_name);
    if ($id) {
        $photo_desc = esc_attr(wppa_get_photo_desc($id));
    } else {
        $photo_desc = '';
    }
    $title = __($photo_name, 'wp-photo-album-plus');
    $result['onclick'] = '';
    // Init
    switch ($type) {
        case 'none':
            // No link at all
            return false;
            break;
        case 'file':
            // The plain file
            if ($is_video) {
                $siz = array(wppa_get_videox($id), wppa_get_videoy($id));
                $result['url'] = wppa_get_photo_url($id, '', $siz['0'], $siz['1']);
                reset($is_video);
                $result['url'] = str_replace('xxx', current($is_video), $result['url']);
            } else {
                $siz = array(wppa_get_photox($id), wppa_get_photoy($id));
                $result['url'] = wppa_get_photo_url($id, '', $siz['0'], $siz['1']);
            }
            $result['title'] = $title;
            $result['is_url'] = true;
            $result['is_lightbox'] = false;
            return $result;
            break;
        case 'lightbox':
        case 'lightboxsingle':
            if ($is_video) {
                $siz = array(wppa_get_videox($id), wppa_get_videoy($id));
                $result['url'] = wppa_get_photo_url($id, '', $siz['0'], $siz['1']);
                //$result['url'] = str_replace( 'xxx', $is_video['0'], $result['url'] );
            } else {
                if (wppa_switch('lb_hres')) {
                    $result['url'] = wppa_get_hires_url($id);
                } else {
                    $siz = array(wppa_get_photox($id), wppa_get_photoy($id));
                    $result['url'] = wppa_get_photo_url($id, '', $siz['0'], $siz['1']);
                }
            }
            $result['title'] = $title;
            $result['is_url'] = false;
            $result['is_lightbox'] = true;
            $result['url'] = wppa_fix_poster_ext($result['url'], $id);
            return $result;
        case 'widget':
            // Defined at widget activation
            $result['url'] = wppa('in_widget_linkurl');
            $result['title'] = esc_attr(wppa('in_widget_linktitle'));
            $result['is_url'] = true;
            $result['is_lightbox'] = false;
            return $result;
            break;
        case 'album':
            // The albums thumbnails
        // The albums thumbnails
        case 'content':
            // For album widget
            switch ($page) {
                case '-1':
                    return false;
                    break;
                case '0':
                    if ($noalb) {
                        $result['url'] = wppa_get_permalink() . 'wppa-album=0&amp;wppa-cover=0';
                        $result['title'] = '';
                        // $album_name;
                        $result['is_url'] = true;
                        $result['is_lightbox'] = false;
                    } else {
                        $result['url'] = wppa_get_permalink() . 'wppa-album=' . $album . '&amp;wppa-cover=0';
                        $result['title'] = $album_name;
                        $result['is_url'] = true;
                        $result['is_lightbox'] = false;
                    }
                    break;
                default:
                    if ($noalb) {
                        $result['url'] = wppa_get_permalink($page) . 'wppa-album=0&amp;wppa-cover=0';
                        $result['title'] = '';
                        //$album_name;//'a++';
                        $result['is_url'] = true;
                        $result['is_lightbox'] = false;
                    } else {
                        $result['url'] = wppa_get_permalink($page) . 'wppa-album=' . $album . '&amp;wppa-cover=0';
                        $result['title'] = $album_name;
                        //'a++';
                        $result['is_url'] = true;
                        $result['is_lightbox'] = false;
                    }
                    break;
            }
            break;
        case 'thumbalbum':
            $album = $thumb['album'];
            $album_name = wppa_get_album_name($album);
            switch ($page) {
                case '-1':
                    return false;
                    break;
                case '0':
                    $result['url'] = wppa_get_permalink() . 'wppa-album=' . $album . '&amp;wppa-cover=0';
                    $result['title'] = $album_name;
                    $result['is_url'] = true;
                    $result['is_lightbox'] = false;
                    break;
                default:
                    $result['url'] = wppa_get_permalink($page) . 'wppa-album=' . $album . '&amp;wppa-cover=0';
                    $result['title'] = $album_name;
                    //'a++';
                    $result['is_url'] = true;
                    $result['is_lightbox'] = false;
                    break;
            }
            break;
        case 'photo':
            // This means: The fullsize photo in a slideshow
        // This means: The fullsize photo in a slideshow
        case 'slphoto':
            // This means: The single photo in the style of a slideshow
            if ($type == 'slphoto') {
                $si = '&amp;wppa-single=1';
            } else {
                $si = '';
            }
            switch ($page) {
                case '-1':
                    return false;
                    break;
                case '0':
                    if ($noalb) {
                        $result['url'] = wppa_get_permalink() . 'wppa-album=0&amp;wppa-photo=' . $id . $si;
                        $result['title'] = $title;
                        $result['is_url'] = true;
                        $result['is_lightbox'] = false;
                    } else {
                        $result['url'] = wppa_get_permalink() . 'wppa-album=' . $album . '&amp;wppa-photo=' . $id . $si;
                        $result['title'] = $title;
                        $result['is_url'] = true;
                        $result['is_lightbox'] = false;
                    }
                    break;
                default:
                    if ($noalb) {
                        $result['url'] = wppa_get_permalink($page) . 'wppa-album=0&amp;wppa-photo=' . $id . $si;
                        $result['title'] = $title;
                        $result['is_url'] = true;
                        $result['is_lightbox'] = false;
                    } else {
                        $result['url'] = wppa_get_permalink($page) . 'wppa-album=' . $album . '&amp;wppa-photo=' . $id . $si;
                        $result['title'] = $title;
                        $result['is_url'] = true;
                        $result['is_lightbox'] = false;
                    }
                    break;
            }
            break;
        case 'single':
            switch ($page) {
                case '-1':
                    return false;
                    break;
                case '0':
                    $result['url'] = wppa_get_permalink() . 'wppa-photo=' . $id;
                    $result['title'] = $title;
                    $result['is_url'] = true;
                    $result['is_lightbox'] = false;
                    break;
                default:
                    $result['url'] = wppa_get_permalink($page) . 'wppa-photo=' . $id;
                    $result['title'] = $title;
                    $result['is_url'] = true;
                    $result['is_lightbox'] = false;
                    break;
            }
            break;
        case 'same':
            $result['url'] = $lnk;
            $result['title'] = $tit;
            $result['is_url'] = true;
            $result['is_lightbox'] = false;
            $result['onclick'] = $onc;
            return $result;
            break;
        case 'fullpopup':
            if ($is_video) {
                // A video can not be printed or downloaded
                $result['url'] = esc_attr('alert( "' . esc_js(__('A video can not be printed or downloaded', 'wp-photo-album-plus')) . '" )');
            } else {
                $wid = wppa_get_photox($id);
                $hig = wppa_get_photoy($id);
                /*
                $imgsize = getimagesize( wppa_get_photo_path( $id ) );
                if ( $imgsize ) {
                	$wid = $imgsize['0'];
                	$hig = $imgsize['1'];
                }
                else {
                	$wid = '0';
                	$hig = '0';
                }
                */
                $url = wppa_fix_poster_ext(wppa_get_photo_url($id, '', $wid, $hig), $id);
                $result['url'] = esc_attr('wppaFullPopUp( ' . wppa('mocc') . ', ' . $id . ', "' . $url . '", ' . $wid . ', ' . $hig . ' )');
            }
            $result['title'] = $title;
            $result['is_url'] = false;
            $result['is_lightbox'] = false;
            return $result;
            break;
        case 'custom':
            if ($wich == 'potdwidget') {
                $result['url'] = wppa_opt('widget_linkurl');
                $result['title'] = wppa_opt('widget_linktitle');
                $result['is_url'] = true;
                $result['is_lightbox'] = false;
                return $result;
            }
            break;
        case 'slide':
            // for album widget
            $result['url'] = wppa_get_permalink(wppa_opt('album_widget_linkpage')) . 'wppa-album=' . $album . '&amp;slide';
            $result['title'] = '';
            $result['is_url'] = true;
            $result['is_lightbox'] = false;
            break;
        case 'autopage':
            if (!wppa_switch('auto_page')) {
                wppa_dbg_msg('Auto page has been switched off, but there are still links to it (' . $wich . ')', 'red', 'force');
                $result['url'] = '';
            } else {
                $result['url'] = wppa_get_permalink(wppa_get_the_auto_page($id));
            }
            $result['title'] = '';
            $result['is_url'] = true;
            $result['is_lightbox'] = false;
            break;
        case 'plainpage':
            $result['url'] = get_permalink($page);
            $result['title'] = $wpdb->get_var($wpdb->prepare("SELECT `post_title` FROM `" . $wpdb->prefix . "posts` WHERE `ID` = %s", $page));
            $result['is_url'] = true;
            $result['is_lightbox'] = false;
            return $result;
            break;
        default:
            wppa_dbg_msg('Error, wrong type: ' . $type . ' in wppa_get_imglink_a', 'red');
            return false;
            break;
    }
    if ($type != 'thumbalbum') {
        if (wppa('calendar')) {
            $result['url'] .= '&amp;wppa-calendar=' . wppa('calendar') . '&amp;wppa-caldate=' . wppa('caldate');
        }
        if (wppa('supersearch')) {
            $result['url'] .= '&amp;wppa-supersearch=' . urlencode(wppa('supersearch'));
        }
        if (wppa('src') && !wppa('is_related') && !wppa_in_widget()) {
            $result['url'] .= '&amp;wppa-searchstring=' . urlencode(wppa('searchstring'));
        }
        if ($wich == 'topten') {
            $result['url'] .= '&amp;wppa-topten=' . wppa_opt('topten_count');
        } elseif (wppa('is_topten')) {
            $result['url'] .= '&amp;wppa-topten=' . wppa('topten_count');
        }
        if ($wich == 'lasten') {
            $result['url'] .= '&amp;wppa-lasten=' . wppa_opt('lasten_count');
        } elseif (wppa('is_lasten')) {
            $result['url'] .= '&amp;wppa-lasten=' . wppa('lasten_count');
        }
        if ($wich == 'comten') {
            $result['url'] .= '&amp;wppa-comten=' . wppa_opt('comten_count');
        } elseif (wppa('is_comten')) {
            $result['url'] .= '&amp;wppa-comten=' . wppa('comten_count');
        }
        if ($wich == 'featen') {
            $result['url'] .= '&amp;wppa-featen=' . wppa_opt('featen_count');
        } elseif (wppa('is_featen')) {
            $result['url'] .= '&amp;wppa-featen=' . wppa('featen_count');
        }
        if (wppa('is_related')) {
            $result['url'] .= '&amp;wppa-rel=' . wppa('is_related') . '&amp;wppa-relcount=' . wppa('related_count');
        } elseif (wppa('is_tag')) {
            $result['url'] .= '&amp;wppa-tag=' . wppa('is_tag');
        }
        if (wppa('is_upldr')) {
            $result['url'] .= '&amp;wppa-upldr=' . wppa('is_upldr');
        }
        if (wppa('is_inverse')) {
            $result['url'] .= '&amp;wppa-inv=1';
        }
    }
    if ($page != '0') {
        // on a different page
        $occur = '1';
        $w = '';
    } else {
        // on the same page, post or widget
        $occur = wppa_in_widget() ? wppa('widget_occur') : wppa('occur');
        $w = wppa_in_widget() ? 'w' : '';
    }
    $result['url'] .= '&amp;wppa-' . $w . 'occur=' . $occur;
    $result['url'] = wppa_convert_to_pretty($result['url']);
    if ($result['title'] == '') {
        $result['title'] = $tit;
    }
    // If still nothing, try arg
    return $result;
}
function wppa_reset_occurrance()
{
    global $wppa;
    global $wppa_revno;
    global $wppa_api_version;
    global $thumbs;
    $thumbs = false;
    wppa_cache_thumb('invalidate');
    wppa_cache_album('invalidate');
    $mocc = isset($wppa['mocc']) ? $wppa['mocc'] : '0';
    $occ = isset($wppa['occur']) ? $wppa['occur'] : '0';
    $wocc = isset($wppa['widget_occur']) ? $wppa['widget_occur'] : '0';
    $rend = isset($wppa['rendering_enabled']) ? $wppa['rendering_enabled'] : false;
    $debug = isset($wppa['debug']) ? $wppa['debug'] : false;
    $wppa = array('debug' => $debug, 'revno' => $wppa_revno, 'api_version' => $wppa_api_version, 'fullsize' => '', 'enlarge' => false, 'occur' => $occ, 'mocc' => $mocc, 'widget_occur' => $wocc, 'in_widget' => false, 'is_cover' => '0', 'is_slide' => '0', 'is_slideonly' => '0', 'is_slideonlyf' => '0', 'is_filmonly' => '0', 'film_on' => '0', 'browse_on' => '0', 'name_on' => '0', 'desc_on' => '0', 'numbar_on' => '0', 'single_photo' => '', 'is_mphoto' => '0', 'is_xphoto' => '0', 'start_album' => '', 'align' => '', 'src' => false, 'portrait_only' => false, 'in_widget_linkurl' => '', 'in_widget_linktitle' => '', 'in_widget_timeout' => '0', 'ss_widget_valign' => '', 'album_count' => '0', 'thumb_count' => '0', 'out' => '', 'auto_colwidth' => false, 'permalink' => '', 'rendering_enabled' => $rend, 'tabcount' => '0', 'comment_id' => '', 'comment_photo' => '0', 'comment_user' => '', 'comment_email' => '', 'comment_text' => '', 'no_default' => false, 'in_widget_frame_height' => '', 'in_widget_frame_width' => '', 'current_album' => '0', 'searchstring' => wppa_test_for_search(), 'searchresults' => '', 'any' => false, 'ajax' => false, 'error' => false, 'iptc' => false, 'exif' => false, 'is_topten' => false, 'topten_count' => '0', 'is_lasten' => false, 'lasten_count' => '0', 'is_featen' => false, 'featen_count' => '0', 'start_photo' => '0', 'is_single' => false, 'is_landing' => '0', 'is_comten' => false, 'comten_count' => '0', 'is_tag' => false, 'photos_only' => false, 'albums_only' => false, 'medals_only' => false, 'page' => '', 'geo' => '', 'continue' => '', 'is_upload' => false, 'ajax_import_files' => false, 'ajax_import_files_done' => false, 'ajax_import_files_error' => '', 'last_albums' => false, 'last_albums_parent' => '0', 'is_multitagbox' => false, 'is_tagcloudbox' => false, 'taglist' => '', 'tagcols' => '2', 'is_related' => false, 'related_count' => '0', 'is_owner' => '', 'is_upldr' => '', 'no_esc' => false, 'front_edit' => false, 'is_autopage' => false, 'is_cat' => false, 'bestof' => false, 'is_subsearch' => false, 'is_rootsearch' => false, 'is_superviewbox' => false, 'is_searchbox' => false, 'may_sub' => false, 'may_root' => false, 'links_no_page' => array('none', 'file', 'lightbox', 'lightboxsingle', 'fullpopup'), 'shortcode_content' => '', 'is_remote' => false, 'is_supersearch' => false, 'supersearch' => '', 'is_mobile' => wppa_is_mobile(), 'rel' => get_option('wppa_lightbox_name') == 'wppa' ? 'data-rel' : 'rel', 'lbtitle' => get_option('wppa_lightbox_name') == 'wppa' ? 'data-lbtitle' : 'title', 'alt' => 'even', 'is_wppa_tree' => false, 'is_calendar' => false, 'calendar' => '', 'caldate' => '', 'calendarall' => false, 'reverse' => false, 'current_photo' => false, 'is_stereobox' => false, 'npages' => '', 'curpage' => '', 'ss_pag' => false, 'slideframewidth' => '', 'slideframeheight' => '', 'ajax_import_files_error' => '', 'src_script' => '', 'is_url' => false, 'is_inverse' => false, 'coverphoto_pos' => '', 'forceroot' => '', 'landingpage' => '', 'is_admins_choice' => false, 'admins_choice_users' => '', 'for_sm' => false, 'max_width' => false);
}
 /** @see WP_Widget::widget */
 function widget($args, $instance)
 {
     global $wpdb;
     require_once dirname(__FILE__) . '/wppa-links.php';
     require_once dirname(__FILE__) . '/wppa-styles.php';
     require_once dirname(__FILE__) . '/wppa-functions.php';
     require_once dirname(__FILE__) . '/wppa-thumbnails.php';
     require_once dirname(__FILE__) . '/wppa-boxes-html.php';
     require_once dirname(__FILE__) . '/wppa-slideshow.php';
     wppa_initialize_runtime();
     wppa('in_widget', 'com');
     wppa_bump_mocc();
     // Hide widget if not logged in and login required to see comments
     if (wppa_switch('comment_view_login') && !is_user_logged_in()) {
         return;
     }
     extract($args);
     $page = in_array(wppa_opt('comment_widget_linktype'), wppa('links_no_page')) ? '' : wppa_get_the_landing_page('wppa_comment_widget_linkpage', __('Recently commented photos', 'wp-photo-album-plus'));
     $max = wppa_opt('comten_count');
     $widget_title = apply_filters('widget_title', $instance['title']);
     $photo_ids = wppa_get_comten_ids($max);
     $widget_content = "\n" . '<!-- WPPA+ Comment Widget start -->';
     $maxw = wppa_opt('comten_size');
     $maxh = $maxw + 18;
     if ($photo_ids) {
         foreach ($photo_ids as $id) {
             // Make the HTML for current comment
             $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">';
             $image = wppa_cache_thumb($id);
             if ($image) {
                 $link = wppa_get_imglnk_a('comten', $id, '', '', true);
                 $file = wppa_get_thumb_path($id);
                 $imgstyle_a = wppa_get_imgstyle_a($id, $file, $maxw, 'center', 'comthumb');
                 $imgstyle = $imgstyle_a['style'];
                 $width = $imgstyle_a['width'];
                 $height = $imgstyle_a['height'];
                 $cursor = $imgstyle_a['cursor'];
                 $imgurl = wppa_get_thumb_url($id, '', $width, $height);
                 $imgevents = wppa_get_imgevents('thumb', $id, true);
                 $title = '';
                 $comments = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_COMMENTS . "` WHERE `photo` = %s ORDER BY `timestamp` DESC", $id), ARRAY_A);
                 if ($comments) {
                     $first_comment = $comments['0'];
                     foreach ($comments as $comment) {
                         $title .= $comment['user'] . ' ' . __('wrote', 'wp-photo-album-plus') . ' ' . wppa_get_time_since($comment['timestamp']) . ":\n";
                         $title .= $comment['comment'] . "\n\n";
                     }
                 }
                 $title = esc_attr(strip_tags(trim($title)));
                 $album = '0';
                 $display = 'thumbs';
                 $widget_content .= wppa_get_the_widget_thumb('comten', $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents);
             } else {
                 $widget_content .= __('Photo not found.', 'wp-photo-album-plus');
             }
             $widget_content .= "\n\t" . '<span style="font-size:' . wppa_opt('fontsize_widget_thumb') . 'px; cursor:pointer;" title="' . esc_attr($first_comment['comment']) . '" >' . $first_comment['user'] . '</span>';
             $widget_content .= "\n" . '</div>';
         }
     } else {
         $widget_content .= 'There are no commented photos (yet).';
     }
     $widget_content .= '<div style="clear:both"></div>';
     $widget_content .= "\n" . '<!-- WPPA+ comment Widget end -->';
     echo "\n" . $before_widget;
     if (!empty($widget_title)) {
         echo $before_title . $widget_title . $after_title;
     }
     echo $widget_content . $after_widget;
     wppa('in_widget', false);
 }
Exemplo n.º 23
0
function wppa_get_masonry_title($id)
{
    $result = '';
    $thumb = wppa_cache_thumb($id);
    // Name
    if (wppa_switch('thumb_text_name') || wppa_switch('thumb_text_owner')) {
        $result .= wppa_get_photo_name($id, wppa_switch('thumb_text_owner'), false, false, wppa_switch('thumb_text_name')) . "\n";
    }
    // Description
    if (wppa_switch('thumb_text_desc') || $thumb['status'] == 'pending' || $thumb['status'] == 'scheduled') {
        $result .= wppa_get_photo_desc($id, wppa_switch('allow_foreign_shortcodes_thumbs')) . "\n";
    }
    // Rating
    if (wppa_switch('thumb_text_rating')) {
        $rating = wppa_get_rating_by_id($id);
        if ($rating && wppa_switch('show_rating_count')) {
            $result .= ' ( ' . wppa_get_rating_count_by_id($id) . ' )' . "\n";
        }
    }
    // Viewcount
    if (wppa_switch('thumb_text_viewcount')) {
        $result .= __a('Views:') . ' ' . $thumb['views'];
    }
    $result = strip_tags(rtrim($result, "\n"));
    return $result;
}
Exemplo n.º 24
0
function wppa_do_filmthumb($id, $idx, $do_for_feed = false, $glue = false)
{
    $thumb = wppa_cache_thumb($id);
    $result = '';
    $src = wppa_fix_poster_ext(wppa_get_thumb_path($thumb['id']), $thumb['id']);
    $max_size = wppa_opt('thumbsize');
    if (wppa_in_widget()) {
        $max_size /= 2;
    }
    $com_alt = wppa('is_comten') && wppa_switch('comten_alt_display') && !wppa_in_widget();
    $imgattr_a = wppa_get_imgstyle_a($thumb['id'], $src, $max_size, 'optional', 'fthumb');
    $imgstyle = $imgattr_a['style'];
    $imgwidth = $imgattr_a['width'];
    $imgheight = $imgattr_a['height'];
    $cursor = $imgattr_a['cursor'];
    $url = wppa_fix_poster_ext(wppa_get_thumb_url($thumb['id'], '', $imgwidth, $imgheight), $thumb['id']);
    $furl = str_replace('/thumbs', '', $url);
    $events = wppa_get_imgevents('film', $thumb['id'], 'nopopup', $idx);
    $thumbname = wppa_get_photo_name($thumb['id']);
    $target = wppa_switch('film_blank') || $thumb['linktarget'] == '_blank' ? 'target="_blank" ' : '';
    $psotitle = $thumb['linktitle'] ? 'title="' . esc_attr($thumb['linktitle']) . '" ' : '';
    $psourl = wppa_switch('film_overrule') && $thumb['linkurl'] ? 'href="' . $thumb['linkurl'] . '" ' . $target . $psotitle : '';
    $imgalt = wppa_get_imgalt($thumb['id']);
    if (wppa_opt('film_linktype') == 'lightbox') {
        //		$title = esc_attr( wppa_zoom_in( $thumb['id'] ) );
    } else {
        $events .= ' onclick="wppaGotoKeepState( ' . wppa('mocc') . ', ' . $idx . ' )"';
        $events .= ' ondblclick="wppaStartStop( ' . wppa('mocc') . ', -1 )"';
    }
    if (is_feed()) {
        if ($do_for_feed) {
            $style_a = wppa_get_imgstyle_a($thumb['id'], $src, '100', '4', 'thumb');
            $style = $style_a['style'];
            $result .= '<a href="' . get_permalink() . '">' . '<img' . ' src="' . $url . '"' . ' ' . $imgalt . ' title="' . $thumbname . '"' . ' style="' . $style . '"' . ' />' . '</a>';
        }
    } else {
        // If ! $do_for_feed: pre-or post-ambule. To avoid dup id change it in that case
        $tmp = $do_for_feed ? 'film' : 'pre';
        $style = $glue ? 'style="' . wppa_get_thumb_frame_style($glue, 'film') . '"' : '';
        $result .= '<div' . ' id="' . $tmp . '_wppatnf_' . $thumb['id'] . '_' . wppa('mocc') . '"' . ' class="thumbnail-frame"' . ' ' . $style . ' >';
        if ($psourl) {
            // True only when pso activated and data present
            $result .= '<a ' . $psourl . '>';
            // $psourl contains url, target and title
        } elseif (wppa_opt('film_linktype') == 'lightbox' && $tmp == 'film') {
            $title = wppa_get_lbtitle('slide', $thumb['id']);
            $videohtml = esc_attr(wppa_get_video_body($thumb['id']));
            $audiohtml = esc_attr(wppa_get_audio_body($thumb['id']));
            $result .= '<a href="' . $furl . '"' . ($videohtml ? ' data-videohtml="' . $videohtml . '"' . ' data-videonatwidth="' . wppa_get_videox($thumb['id']) . '"' . ' data-videonatheight="' . wppa_get_videoy($thumb['id']) . '"' : '') . ($audiohtml ? ' data-audiohtml="' . $audiohtml . '"' : '') . ' ' . wppa('rel') . '="' . wppa_opt('lightbox_name') . '[occ' . wppa('mocc') . ']"' . ($title ? ' ' . wppa('lbtitle') . '="' . $title . '"' : '') . ' >';
        }
        if ($tmp == 'pre' && wppa_opt('film_linktype') == 'lightbox') {
            $cursor = 'cursor:default;';
        }
        if ($tmp == 'film' && !$com_alt && !wppa_cdn('front') && !wppa_switch('lazy_or_htmlcomp')) {
            $result .= '<!--';
        }
        if (wppa_is_video($thumb['id'])) {
            $result .= wppa_get_video_html(array('id' => $thumb['id'], 'width' => $imgattr_a['width'], 'height' => $imgattr_a['height'], 'controls' => false, 'margin_top' => $imgattr_a['margin-top'], 'margin_bottom' => $imgattr_a['margin-bottom'], 'cursor' => $imgattr_a['cursor'], 'events' => $events, 'tagid' => 'wppa-' . $tmp . '-' . $idx . '-' . wppa('mocc')));
        } else {
            $result .= '<img' . ' id="wppa-' . $tmp . '-' . $idx . '-' . wppa('mocc') . '"' . ' class="wppa-' . $tmp . '-' . wppa('mocc') . '"' . ' src="' . $url . '"' . ' ' . $imgalt . ' style="' . $imgstyle . $cursor . '"' . ' ' . $events . ' data-title="' . ($psourl ? esc_attr($thumb['linktitle']) : '') . '"' . ' />';
        }
        if ($tmp == 'film' && !$com_alt && !wppa_cdn('front') && !wppa_switch('lazy_or_htmlcomp')) {
            $result .= '-->';
        }
        if ($psourl) {
            // True only when pso activated and data present
            $result .= '</a>';
            // $psourl contains url, target and title
        } elseif (wppa_opt('film_linktype') == 'lightbox' && $tmp == 'film') {
            $result .= '</a>';
        }
        $result .= '</div>';
    }
    wppa_out($result);
}
Exemplo n.º 25
0
function wppa_ajax_callback()
{
    global $wpdb;
    global $wppa_session;
    wppa('ajax', true);
    wppa('error', '0');
    wppa('out', '');
    $wppa_session['page']--;
    $wppa_session['ajax']++;
    wppa_save_session();
    // ALTHOUGH IF WE ARE HERE AS FRONT END VISITOR, is_admin() is true.
    // So, $wppa_opt switches are 'yes' or 'no' and not true or false.
    // So, always use the function wppa_switch( $slug ) to test on a bool setting
    // Globally check query args to prevent php injection
    $wppa_args = array('album', 'photo', 'slide', 'cover', 'occur', 'woccur', 'searchstring', 'topten', 'lasten', 'comten', 'featen', 'single', 'photos-only', 'debug', 'relcount', 'upldr', 'owner', 'rootsearch');
    foreach ($_REQUEST as $arg) {
        if (in_array(str_replace('wppa-', '', $arg), $wppa_args)) {
            if (strpos($arg, '<?') !== false) {
                die('Security check failure #91');
            }
            if (strpos($arg, '?>') !== false) {
                die('Security check failure #92');
            }
        }
    }
    wppa_vfy_arg('wppa-action', true);
    wppa_vfy_arg('photo-id');
    wppa_vfy_arg('comment-id');
    wppa_vfy_arg('moccur');
    wppa_vfy_arg('comemail', true);
    wppa_vfy_arg('comname', true);
    wppa_vfy_arg('tag', true);
    $wppa_action = $_REQUEST['wppa-action'];
    switch ($wppa_action) {
        case 'getssiptclist':
            $tag = str_replace('H', '#', $_REQUEST['tag']);
            $mocc = $_REQUEST['moccur'];
            $oldvalue = '';
            if (strpos($wppa_session['supersearch'], ',') !== false) {
                $ss_data = explode(',', $wppa_session['supersearch']);
                if (count($ss_data) == '4') {
                    if ($ss_data['0'] == 'p') {
                        if ($ss_data['1'] == 'i') {
                            if ($ss_data['2'] == $_REQUEST['tag']) {
                                $oldvalue = $ss_data['3'];
                            }
                        }
                    }
                }
            }
            $iptcdata = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_IPTC . "` WHERE `photo` > '0' AND `tag` = %s ORDER BY `description`", $tag), ARRAY_A);
            $last = '';
            $any = false;
            if (is_array($iptcdata)) {
                foreach ($iptcdata as $item) {
                    $desc = sanitize_text_field($item['description']);
                    $desc = str_replace(array(chr(0), chr(1), chr(2), chr(3), chr(4), chr(5), chr(6), chr(7)), '', $desc);
                    if ($desc != $last) {
                        $sel = $oldvalue && $oldvalue == $desc ? 'selected="selected"' : '';
                        if ($sel) {
                            echo 'selected:' . $oldvalue;
                        }
                        $ddesc = strlen($desc) > '32' ? substr($desc, 0, 30) . '...' : $desc;
                        echo '<option' . ' value="' . esc_attr($desc) . '"' . ' class="wppa-iptclist-' . $mocc . '"' . ' ' . $sel . ' >' . $ddesc . '</option>';
                        $last = $desc;
                        $any = true;
                    }
                }
            }
            if (!$any) {
                $query = $wpdb->prepare("DELETE FROM `" . WPPA_IPTC . "` WHERE `photo` = '0' AND `tag` = %s", $tag);
                $wpdb->query($query);
                //				wppa_log( 'dbg', $query );
            }
            wppa_exit();
            break;
        case 'getssexiflist':
            $tag = str_replace('H', '#', $_REQUEST['tag']);
            $mocc = $_REQUEST['moccur'];
            $oldvalue = '';
            if (strpos($wppa_session['supersearch'], ',') !== false) {
                $ss_data = explode(',', $wppa_session['supersearch']);
                if (count($ss_data) == '4') {
                    if ($ss_data['0'] == 'p') {
                        if ($ss_data['1'] == 'e') {
                            if ($ss_data['2'] == $_REQUEST['tag']) {
                                $oldvalue = $ss_data['3'];
                            }
                        }
                    }
                }
            }
            $exifdata = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_EXIF . "` WHERE `photo` > '0' AND `tag` = %s ORDER BY `description`", $tag), ARRAY_A);
            $last = '';
            $any = false;
            if (is_array($exifdata)) {
                foreach ($exifdata as $item) {
                    $desc = sanitize_text_field($item['description']);
                    $desc = str_replace(array(chr(0), chr(1), chr(2), chr(3), chr(4), chr(5), chr(6), chr(7)), '', $desc);
                    if ($desc != $last) {
                        $sel = $oldvalue && $oldvalue == $desc ? 'selected="selected"' : '';
                        $ddesc = strlen($desc) > '32' ? substr($desc, 0, 30) . '...' : $desc;
                        echo '<option' . ' value="' . esc_attr($desc) . '"' . ' class="wppa-exiflist-' . $mocc . '"' . ' ' . $sel . ' >' . $ddesc . '</option>';
                        $last = $desc;
                        $any = true;
                    }
                }
            }
            if (!$any) {
                $query = $wpdb->prepare("DELETE FROM `" . WPPA_EXIF . "` WHERE `photo` = '0' AND `tag` = %s", $tag);
                $wpdb->query($query);
                //				wppa_log( 'dbg', $query );
            }
            wppa_exit();
            break;
        case 'front-edit':
            if (!isset($_REQUEST['photo-id'])) {
                die('Missing required argument');
            }
            $photo = $_REQUEST['photo-id'];
            $ok = false;
            if (current_user_can('wppa_admin')) {
                $ok = true;
            }
            if (wppa_get_user() == wppa_get_photo_owner($photo) && (current_user_can('wppa_upload') || is_user_logged_in() && wppa_switch('upload_edit'))) {
                $ok = true;
            }
            if (!$ok) {
                die('You do not have sufficient rights to do this');
            }
            require_once 'wppa-photo-admin-autosave.php';
            wppa('front_edit', true);
            echo '	<div style="padding-bottom:4px;height:24px;" >
						<span style="color:#777;" >
							<i>' . __('All modifications are instantly updated on the server. The <b style="color:#070" >Remark</b> field keeps you informed on the actions taken at the background.', 'wp-photo-album-plus') . '</i>
						</span>
						<input id="wppa-fe-exit" type="button" style="float:right;color:red;font-weight:bold;" onclick="window.opener.location.reload( true );window.close();" value="' . __('Exit & Refresh', 'wp-photo-album-plus') . '" />
						<div id="wppa-fe-count" style="float:right;" ></div>
					</div><div style="clear:both;"></div>';
            wppa_album_photos('', $photo);
            wppa_exit();
            break;
        case 'do-comment':
            // Security check
            $mocc = $_REQUEST['moccur'];
            $nonce = $_REQUEST['wppa-nonce'];
            if (!wp_verify_nonce($nonce, 'wppa-nonce-' . $mocc)) {
                _e('Security check failure', 'wp-photo-album-plus');
                wppa_exit();
            }
            // Correct the fact that this is a non-admin operation, if it is only
            if (is_admin()) {
                require_once 'wppa-non-admin.php';
            }
            wppa('mocc', $_REQUEST['moccur']);
            wppa('comment_photo', isset($_REQUEST['photo-id']) ? $_REQUEST['photo-id'] : '0');
            wppa('comment_id', isset($_REQUEST['comment-edit']) ? $_REQUEST['comment-edit'] : '0');
            $comment_allowed = !wppa_switch('comment_login') || is_user_logged_in();
            if (wppa_switch('show_comments') && $comment_allowed) {
                //				if ( wppa_switch( 'search_comments' ) ) wppa_index_remove( 'photo', $_REQUEST['photo-id'] );
                wppa_do_comment($_REQUEST['photo-id']);
                // Process the comment
                if (wppa_switch('search_comments')) {
                    wppa_index_update('photo', $_REQUEST['photo-id']);
                }
            }
            wppa('no_esc', true);
            echo wppa_comment_html($_REQUEST['photo-id'], $comment_allowed);
            // Retrieve the new commentbox content
            wppa_exit();
            break;
        case 'import':
            require_once 'wppa-upload.php';
            _wppa_page_import();
            wppa_exit();
            break;
        case 'approve':
            $iret = '0';
            if (!current_user_can('wppa_moderate') && !current_user_can('wppa_comments')) {
                _e('You do not have the rights to moderate photos this way', 'wp-photo-album-plus');
                wppa_exit();
            }
            if (isset($_REQUEST['photo-id']) && current_user_can('wppa_moderate')) {
                $iret = $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `status` = 'publish' WHERE `id` = %s", $_REQUEST['photo-id']));
                wppa_flush_upldr_cache('photoid', $_REQUEST['photo-id']);
                $alb = $wpdb->get_var($wpdb->prepare("SELECT `album` FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s", $_REQUEST['photo-id']));
                wppa_clear_taglist();
                wppa_flush_treecounts($alb);
            }
            if (isset($_REQUEST['comment-id'])) {
                $iret = $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_COMMENTS . "` SET `status` = 'approved' WHERE `id` = %s", $_REQUEST['comment-id']));
            }
            if ($iret) {
                echo 'OK';
            } else {
                if (isset($_REQUEST['photo-id'])) {
                    if (current_user_can('wppa_moderate')) {
                        echo sprintf(__('Failed to update stutus of photo %s', 'wp-photo-album-plus'), $_REQUEST['photo-id']) . "\n" . __('Please refresh the page', 'wp-photo-album-plus');
                    } else {
                        _e('Security check failure', 'wp-photo-album-plus');
                    }
                }
                if (isset($_REQUEST['comment-id'])) {
                    echo sprintf(__('Failed to update stutus of comment %s', 'wp-photo-album-plus'), $_REQUEST['comment-id']) . "\n" . __('Please refresh the page', 'wp-photo-album-plus');
                }
            }
            wppa_exit();
        case 'remove':
            if (isset($_REQUEST['photo-id'])) {
                // Remove photo
                if (wppa_user_is('administrator') || current_user_can('wppa_moderate') || wppa_get_user() == wppa_get_photo_owner($_REQUEST['photo-id']) && wppa_switch('upload_edit')) {
                    // Frontend delete?
                    wppa_delete_photo($_REQUEST['photo-id']);
                    echo 'OK||' . __('Photo removed', 'wp-photo-album-plus');
                    wppa_exit();
                }
            }
            if (!current_user_can('wppa_moderate') && !current_user_can('wppa_comments')) {
                _e('You do not have the rights to moderate photos this way', 'wp-photo-album-plus');
                wppa_exit();
            }
            if (isset($_REQUEST['photo-id'])) {
                // Remove photo
                if (!current_user_can('wppa_moderate')) {
                    _e('Security check failure', 'wp-photo-album-plus');
                    wppa_exit();
                }
                wppa_delete_photo($_REQUEST['photo-id']);
                echo 'OK||' . __('Photo removed', 'wp-photo-album-plus');
                wppa_exit();
            }
            if (isset($_REQUEST['comment-id'])) {
                // Remove comment
                $iret = $wpdb->query($wpdb->prepare("DELETE FROM `" . WPPA_COMMENTS . "` WHERE `id`= %s", $_REQUEST['comment-id']));
                if ($iret) {
                    echo 'OK||' . __('Comment removed', 'wp-photo-album-plus');
                } else {
                    _e('Could not remove comment', 'wp-photo-album-plus');
                }
                wppa_exit();
            }
            _e('Unexpected error', 'wp-photo-album-plus');
            wppa_exit();
        case 'downloadalbum':
            // Feature enabled?
            if (!wppa_switch('allow_download_album')) {
                echo '||ER||' . __('This feature is not enabled on this website', 'wp-photo-album-plus');
                wppa_exit();
            }
            // Validate args
            $alb = $_REQUEST['album-id'];
            $status = "`status` <> 'pending' AND `status` <> 'scheduled'";
            if (!is_user_logged_in()) {
                $status .= " AND `status` <> 'private'";
            }
            $photos = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s AND ( ( " . $status . " ) OR owner = %s ) " . wppa_get_photo_order($alb), $alb, wppa_get_user()), ARRAY_A);
            if (!$photos) {
                echo '||ER||' . __('The album is empty', 'wp-photo-album-plus');
                wppa_exit();
            }
            // Remove obsolete files
            wppa_delete_obsolete_tempfiles();
            // Open zipfile
            if (!class_exists('ZipArchive')) {
                echo '||ER||' . __('Unable to create zip archive', 'wp-photo-album-plus');
                wppa_exit();
            }
            $zipfilename = wppa_get_album_name($alb);
            $zipfilename = wppa_sanitize_file_name($zipfilename . '.zip');
            // Remove illegal chars
            $zipfilepath = WPPA_UPLOAD_PATH . '/temp/' . $zipfilename;
            if (is_file($zipfilepath)) {
                //		unlink( $zipfilepath );	// Debug
            }
            $wppa_zip = new ZipArchive();
            $iret = $wppa_zip->open($zipfilepath, 1);
            if ($iret !== true) {
                echo '||ER||' . sprintf(__('Unable to create zip archive. code = %s', 'wp-photo-album-plus'), $iret);
                wppa_exit();
            }
            // Add photos to zip
            $stop = false;
            foreach ($photos as $p) {
                if (wppa_is_time_up()) {
                    wppa_log('obs', 'Time up during album to zip creation');
                    $stop = true;
                } else {
                    $id = $p['id'];
                    if (!wppa_is_multi($id)) {
                        $source = wppa_switch('download_album_source') && is_file(wppa_get_source_path($id)) ? wppa_get_source_path($id) : wppa_get_photo_path($id);
                        if (is_file($source)) {
                            $dest = $p['filename'] ? wppa_sanitize_file_name($p['filename']) : wppa_sanitize_file_name(wppa_strip_ext($p['name']) . '.' . $p['ext']);
                            $dest = wppa_fix_poster_ext($dest, $id);
                            $iret = $wppa_zip->addFile($source, $dest);
                            // To prevent too may files open, and to have at least a file when there are too many photos, close and re-open
                            $wppa_zip->close();
                            $wppa_zip->open($zipfilepath);
                            // wppa_log( 'dbg', 'Added ' . basename($source) . ' to ' . basename($zipfilepath));
                        }
                    }
                }
                if ($stop) {
                    break;
                }
            }
            // Close zip and return
            $zipcount = $wppa_zip->numFiles;
            $wppa_zip->close();
            // A zip is created
            $desturl = WPPA_UPLOAD_URL . '/temp/' . $zipfilename;
            echo $desturl . '||OK||';
            if ($zipcount != count($photos)) {
                echo sprintf(__('Only %s out of %s photos could be added to the zipfile', 'wp-photo-album-plus'), $zipcount, count($photos));
            }
            wppa_exit();
            break;
        case 'getalbumzipurl':
            $alb = $_REQUEST['album-id'];
            $zipfilename = wppa_get_album_name($alb);
            $zipfilename = wppa_sanitize_file_name($zipfilename . '.zip');
            // Remove illegal chars
            $zipfilepath = WPPA_UPLOAD_PATH . '/temp/' . $zipfilename;
            $zipfileurl = WPPA_UPLOAD_URL . '/temp/' . $zipfilename;
            if (is_file($zipfilepath)) {
                echo $zipfileurl;
            } else {
                echo 'ER';
            }
            wppa_exit();
            break;
        case 'makeorigname':
            $photo = $_REQUEST['photo-id'];
            $from = $_REQUEST['from'];
            if ($from == 'fsname') {
                $type = wppa_opt('art_monkey_link');
            } elseif ($from == 'popup') {
                $type = wppa_opt('art_monkey_popup_link');
            } else {
                echo '||7||' . __('Unknown source of request', 'wp-photo-album-plus');
                wppa_exit();
            }
            $data = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s", $photo), ARRAY_A);
            if ($data) {
                // The photo is supposed to exist
                // Make the name
                if ($data['filename']) {
                    $name = $data['filename'];
                } else {
                    $name = __($data['name'], 'wp-photo-album-plus');
                }
                $name = wppa_sanitize_file_name($name);
                // Remove illegal chars
                $name = preg_replace('/\\.[^.]*$/', '', $name);
                // Remove file extension
                if (strlen($name) == '0') {
                    echo '||1||' . __('Empty filename', 'wp-photo-album-plus');
                    wppa_exit();
                }
                // Make the file
                if (wppa_switch('artmonkey_use_source')) {
                    if (is_file(wppa_get_source_path($photo))) {
                        $source = wppa_get_source_path($photo);
                    } else {
                        $source = wppa_get_photo_path($photo);
                    }
                } else {
                    $source = wppa_get_photo_path($photo);
                }
                $source = wppa_fix_poster_ext($source, $photo);
                // Fix the extension for mm items.
                if ($data['ext'] == 'xxx') {
                    $data['ext'] = wppa_get_ext($source);
                }
                $dest = WPPA_UPLOAD_PATH . '/temp/' . $name . '.' . $data['ext'];
                $zipfile = WPPA_UPLOAD_PATH . '/temp/' . $name . '.zip';
                $tempdir = WPPA_UPLOAD_PATH . '/temp';
                if (!is_dir($tempdir)) {
                    @mkdir($tempdir);
                }
                if (!is_dir($tempdir)) {
                    echo '||2||' . __('Unable to create tempdir', 'wp-photo-album-plus');
                    wppa_exit();
                }
                // Remove obsolete files
                wppa_delete_obsolete_tempfiles();
                // Make the files
                if ($type == 'file') {
                    copy($source, $dest);
                    $ext = $data['ext'];
                } elseif ($type == 'zip') {
                    if (!class_exists('ZipArchive')) {
                        echo '||8||' . __('Unable to create zip archive', 'wp-photo-album-plus');
                        wppa_exit();
                    }
                    $ext = 'zip';
                    $wppa_zip = new ZipArchive();
                    $wppa_zip->open($zipfile, 1);
                    $wppa_zip->addFile($source, basename($dest));
                    $wppa_zip->close();
                } else {
                    echo '||6||' . __('Unknown type', 'wp-photo-album-plus');
                    wppa_exit();
                }
                $desturl = WPPA_UPLOAD_URL . '/temp/' . $name . '.' . $ext;
                echo '||0||' . $desturl;
                // No error: return url
                wppa_exit();
            } else {
                echo '||9||' . __('The photo does no longer exist', 'wp-photo-album-plus');
                wppa_exit();
            }
            wppa_exit();
            break;
        case 'tinymcedialog':
            $result = wppa_make_tinymce_dialog();
            echo $result;
            wppa_exit();
            break;
        case 'bumpviewcount':
            $nonce = $_REQUEST['wppa-nonce'];
            if (wp_verify_nonce($nonce, 'wppa-check')) {
                wppa_bump_viewcount('photo', $_REQUEST['wppa-photo']);
            } else {
                _e('Security check failure', 'wp-photo-album-plus');
            }
            wppa_exit();
            break;
        case 'rate':
            // Get commandline args
            $photo = $_REQUEST['wppa-rating-id'];
            $rating = $_REQUEST['wppa-rating'];
            $occur = $_REQUEST['wppa-occur'];
            $index = $_REQUEST['wppa-index'];
            $nonce = $_REQUEST['wppa-nonce'];
            // Make errortext
            $errtxt = __('An error occurred while processing you rating request.', 'wp-photo-album-plus');
            $errtxt .= "\n" . __('Maybe you opened the page too long ago to recognize you.', 'wp-photo-album-plus');
            $errtxt .= "\n" . __('You may refresh the page and try again.', 'wp-photo-album-plus');
            $wartxt = __('Althoug an error occurred while processing your rating, your vote has been registered.', 'wp-photo-album-plus');
            $wartxt .= "\n" . __('However, this may not be reflected in the current pageview', 'wp-photo-album-plus');
            // Check on validity
            if (!wp_verify_nonce($nonce, 'wppa-check')) {
                echo '0||100||' . $errtxt;
                wppa_exit();
                // Nonce check failed
            }
            if (wppa_opt('rating_max') == '1' && $rating != '1') {
                echo '0||106||' . $errtxt . ':' . $rating;
                wppa_exit();
                // Value out of range
            } elseif (wppa_opt('rating_max') == '5' && !in_array($rating, array('-1', '1', '2', '3', '4', '5'))) {
                echo '0||106||' . $errtxt . ':' . $rating;
                wppa_exit();
                // Value out of range
            } elseif (wppa_opt('rating_max') == '10' && !in_array($rating, array('-1', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'))) {
                echo '0||106||' . $errtxt . ':' . $rating;
                wppa_exit();
                // Value out of range
            }
            // Get other data
            if (!$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s", $photo))) {
                echo '0||999||' . __('Photo has been removed.', 'wp-photo-album-plus');
                wppa_exit();
            }
            $user = wppa_get_user();
            $mylast = $wpdb->get_row($wpdb->prepare('SELECT * FROM `' . WPPA_RATING . '` WHERE `photo` = %s AND `user` = %s ORDER BY `id` DESC LIMIT 1', $photo, $user), ARRAY_A);
            $myavgrat = '0';
            // Init
            // Rate own photo?
            if (wppa_get_photo_item($photo, 'owner') == $user && !wppa_switch('allow_owner_votes')) {
                echo '0||900||' . __('Sorry, you can not rate your own photos', 'wp-photo-album-plus');
                wppa_exit();
            }
            // Already a pending one?
            $pending = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_RATING . "` WHERE `photo` = %s AND `user` = %s AND `status` = %s", $photo, $user, 'pending'));
            // Has user motivated his vote?
            $hascommented = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "` WHERE `photo` = %s AND `user` = %s", $photo, wppa_get_user('display')));
            if ($pending) {
                if (!$hascommented) {
                    echo '0||900||' . __('Please enter a comment.', 'wp-photo-album-plus');
                    wppa_exit();
                } else {
                    $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_RATING . "` SET `status` = 'publish' WHERE `photo` = %s AND `user` = %s", $photo, $user));
                }
            }
            if (wppa_switch('vote_needs_comment')) {
                $ratingstatus = $hascommented ? 'publish' : 'pending';
            } else {
                $ratingstatus = 'publish';
            }
            // When done, we have to echo $occur.'||'.$photo.'||'.$index.'||'.$myavgrat.'||'.$allavgrat.'||'.$discount.||.$hascommented.||.$message;
            // So we have to do: process rating and find new $myavgrat, $allavgrat and $discount ( $occur, $photo and $index are known )
            // Case 0: Illegal second vote. Frontend takes care of this, but a hacker could enter an ajaxlink manually
            if ($mylast && (!(wppa_switch('rating_change') || wppa_switch('rating_multi')) || $mylast['value'] < '0' || $mylast['value'] > '0' && $rating == '-1')) {
                echo '0||109||' . __('Security check failure.', 'wp-photo-album-plus');
                wppa_exit();
            }
            // Case 1: value = -1 this is a legal dislike vote
            if ($rating == '-1') {
                // Add my dislike
                $iret = wppa_create_rating_entry(array('photo' => $photo, 'value' => $rating, 'user' => $user, 'status' => $ratingstatus));
                if (!$iret) {
                    echo '0||101||' . $errtxt;
                    wppa_exit();
                    // Fail on storing vote
                }
                // Add points
                wppa_add_credit_points(wppa_opt('cp_points_rating'), __('Photo rated', 'wp-photo-album-plus'), $photo, $rating);
                wppa_dislike_check($photo);
                // Check for email to be sent every .. dislikes
                if (!is_file(wppa_get_thumb_path($photo))) {
                    // Photo is removed
                    echo $occur . '||' . $photo . '||' . $index . '||-1||-1|0||' . wppa_opt('dislike_delete');
                    wppa_exit();
                }
            } elseif (!$mylast) {
                // Add my vote
                $iret = wppa_create_rating_entry(array('photo' => $photo, 'value' => $rating, 'user' => $user, 'status' => $ratingstatus));
                if (!$iret) {
                    echo '0||102||' . $errtxt;
                    wppa_exit();
                    // Fail on storing vote
                }
                // Add points
                wppa_add_credit_points(wppa_opt('cp_points_rating'), __('Photo rated', 'wp-photo-album-plus'), $photo, $rating);
            } elseif (wppa_switch('rating_change')) {
                // Votechanging is allowed
                $iret = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_RATING . '` SET `value` = %s WHERE `photo` = %s AND `user` = %s LIMIT 1', $rating, $photo, $user));
                if ($iret === false) {
                    echo '0||103||' . $errtxt;
                    wppa_exit();
                    // Fail on update
                }
            } elseif (wppa_switch('rating_multi')) {
                // Rating multi is allowed
                $iret = wppa_create_rating_entry(array('photo' => $photo, 'value' => $rating, 'user' => $user, 'status' => $ratingstatus));
                if (!$iret) {
                    echo '0||104||' . $errtxt;
                    wppa_exit();
                    // Fail on storing vote
                }
            } else {
                // Should never get here....
                echo '0||110||' . __('Unexpected error', 'wp-photo-album-plus');
                wppa_exit();
            }
            // Compute my avg rating
            $myrats = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_RATING . '`  WHERE `photo` = %s AND `user` = %s AND `status` = %s ', $photo, $user, 'publish'), ARRAY_A);
            if ($myrats) {
                $sum = 0;
                $cnt = 0;
                foreach ($myrats as $rat) {
                    if ($rat['value'] == '-1') {
                        $sum += wppa_opt('dislike_value');
                    } else {
                        $sum += $rat['value'];
                    }
                    $cnt++;
                }
                $myavgrat = $sum / $cnt;
                $i = wppa_opt('rating_prec');
                $j = $i + '1';
                $myavgrat = sprintf('%' . $j . '.' . $i . 'f', $myavgrat);
            } else {
                $myavgrat = '0';
            }
            // Compute new allavgrat
            $ratings = $wpdb->get_results($wpdb->prepare('SELECT * FROM ' . WPPA_RATING . ' WHERE `photo` = %s AND `status` = %s', $photo, 'publish'), ARRAY_A);
            if ($ratings) {
                $sum = 0;
                $cnt = 0;
                foreach ($ratings as $rat) {
                    if ($rat['value'] == '-1') {
                        $sum += wppa_opt('dislike_value');
                    } else {
                        $sum += $rat['value'];
                    }
                    $cnt++;
                }
                $allavgrat = $sum / $cnt;
                if ($allavgrat == '10') {
                    $allavgrat = '9.99999999';
                }
                // For sort order reasons text field
            } else {
                $allavgrat = '0';
            }
            // Store it in the photo info
            $iret = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_PHOTOS . '` SET `mean_rating` = %s WHERE `id` = %s', $allavgrat, $photo));
            if ($iret === false) {
                echo '0||106||' . $wartxt;
                wppa_exit();
                // Fail on save
            }
            // Compute rating_count and store in the photo info
            $ratcount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_RATING . "` WHERE `photo` = %s", $photo));
            if ($ratcount !== false) {
                $iret = $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `rating_count` = %s WHERE `id` = %s", $ratcount, $photo));
                if ($iret === false) {
                    echo '0||107||' . $wartxt;
                    wppa_exit();
                    // Fail on save
                }
            }
            // Format $allavgrat for output
            $allavgratcombi = $allavgrat . '|' . $ratcount;
            // Compute dsilike count
            $discount = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_RATING . "` WHERE `photo` = %s AND `value` = -1 AND `status` = %s", $photo, 'publish'));
            if ($discount === false) {
                echo '0||108||' . $wartxt;
                wppa_exit();
                // Fail on save
            }
            // Test for possible medal
            wppa_test_for_medal($photo);
            // Success!
            wppa_clear_cache();
            if (wppa_switch('vote_needs_comment') && !$hascommented) {
                $message = __("Please explain your vote in a comment.\nYour vote will be discarded if you don't.\n\nAfter completing your comment,\nyou can refresh the page to see\nyour vote became effective.", 'wp-photo-album-plus');
            } else {
                $message = '';
            }
            echo $occur . '||' . $photo . '||' . $index . '||' . $myavgrat . '||' . $allavgratcombi . '||' . $discount . '||' . $hascommented . '||' . $message;
            break;
        case 'render':
            $tim_1 = microtime(true);
            $nq_1 = get_num_queries();
            // Correct the fact that this is a non-admin operation, if it is
            if (is_admin()) {
                require_once 'wppa-non-admin.php';
            }
            wppa_load_theme();
            // Register geo shortcode if google-maps-gpx-vieuwer is on board. GPX does it in wp_head(), what is not done in an ajax call
            //			if ( function_exists( 'gmapv3' ) ) add_shortcode( 'map', 'gmapv3' );
            // Get the post we are working for
            if (isset($_REQUEST['wppa-fromp'])) {
                $p = $_REQUEST['wppa-fromp'];
                if (wppa_is_int($p)) {
                    $GLOBALS['post'] = get_post($p);
                }
            }
            // Render
            echo wppa_albums();
            $tim_2 = microtime(true);
            $nq_2 = get_num_queries();
            $mem = memory_get_peak_usage(true) / 1024 / 1024;
            $msg = sprintf('WPPA Ajax render: db queries: WP:%d, WPPA+: %d in %4.2f seconds, using %4.2f MB memory max', $nq_1, $nq_2 - $nq_1, $tim_2 - $tim_1, $mem);
            echo '<script type="text/javascript">wppaConsoleLog( \'' . $msg . '\', \'force\' )</script>';
            break;
        case 'delete-photo':
            $photo = $_REQUEST['photo-id'];
            $nonce = $_REQUEST['wppa-nonce'];
            // Check validity
            if (!wp_verify_nonce($nonce, 'wppa_nonce_' . $photo)) {
                echo '||0||' . __('You do not have the rights to delete a photo', 'wp-photo-album-plus');
                wppa_exit();
                // Nonce check failed
            }
            if (!is_numeric($photo)) {
                echo '||0||' . __('Security check failure', 'wp-photo-album-plus');
                wppa_exit();
                // Nonce check failed
            }
            $album = $wpdb->get_var($wpdb->prepare('SELECT `album` FROM `' . WPPA_PHOTOS . '` WHERE `id` = %s', $photo));
            wppa_delete_photo($photo);
            wppa_clear_cache();
            echo '||1||<span style="color:red" >' . sprintf(__('Photo %s has been deleted', 'wp-photo-album-plus'), $photo) . '</span>';
            echo '||';
            $a = wppa_allow_uploads($album);
            if (!$a) {
                echo 'full';
            } else {
                echo 'notfull||' . $a;
            }
            break;
        case 'update-album':
            $album = $_REQUEST['album-id'];
            $nonce = $_REQUEST['wppa-nonce'];
            $item = $_REQUEST['item'];
            $value = $_REQUEST['value'];
            $value = wppa_decode($value);
            // Check validity
            if (!wp_verify_nonce($nonce, 'wppa_nonce_' . $album)) {
                echo '||0||' . __('You do not have the rights to update album information', 'wp-photo-album-plus') . $nonce;
                wppa_exit();
                // Nonce check failed
            }
            switch ($item) {
                case 'clear_ratings':
                    $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `album` = %s', $album), ARRAY_A);
                    if ($photos) {
                        foreach ($photos as $photo) {
                            $iret1 = $wpdb->query($wpdb->prepare('DELETE FROM `' . WPPA_RATING . '` WHERE `photo` = %s', $photo['id']));
                            $iret2 = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_PHOTOS . '` SET `mean_rating` = %s WHERE `id` = %s', '', $photo['id']));
                        }
                    }
                    if ($photos && $iret1 !== false && $iret2 !== false) {
                        echo '||97||' . __('<b>Ratings cleared</b>', 'wp-photo-album-plus') . '||' . __('No ratings for this photo.', 'wp-photo-album-plus');
                    } elseif ($photos) {
                        echo '||1||' . __('An error occurred while clearing ratings', 'wp-photo-album-plus');
                    } else {
                        echo '||97||' . __('<b>No photos in this album</b>', 'wp-photo-album-plus') . '||' . __('No ratings for this photo.', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'set_deftags':
                    // to be changed for large albums
                    $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `album` = %s', $album), ARRAY_A);
                    $deftag = $wpdb->get_var($wpdb->prepare('SELECT `default_tags` FROM `' . WPPA_ALBUMS . '` WHERE `id` = %s', $album));
                    if (is_array($photos)) {
                        foreach ($photos as $photo) {
                            $tags = wppa_sanitize_tags(wppa_filter_iptc(wppa_filter_exif($deftag, $photo['id']), $photo['id']));
                            $iret = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_PHOTOS . '` SET `tags` = %s WHERE `id` = %s', $tags, $photo['id']));
                            wppa_index_update('photo', $photo['id']);
                        }
                    }
                    if ($photos && $iret !== false) {
                        echo '||97||' . __('<b>Tags set to defaults</b> (reload)', 'wp-photo-album-plus');
                    } elseif ($photos) {
                        echo '||1||' . __('An error occurred while setting tags', 'wp-photo-album-plus');
                    } else {
                        echo '||97||' . __('<b>No photos in this album</b>', 'wp-photo-album-plus');
                    }
                    wppa_clear_taglist();
                    wppa_exit();
                    break;
                case 'add_deftags':
                    $photos = $wpdb->get_results($wpdb->prepare('SELECT * FROM `' . WPPA_PHOTOS . '` WHERE `album` = %s', $album), ARRAY_A);
                    $deftag = $wpdb->get_var($wpdb->prepare('SELECT `default_tags` FROM `' . WPPA_ALBUMS . '` WHERE `id` = %s', $album));
                    if (is_array($photos)) {
                        foreach ($photos as $photo) {
                            $tags = wppa_sanitize_tags(wppa_filter_iptc(wppa_filter_exif($photo['tags'] . ',' . $deftag, $photo['id']), $photo['id']));
                            $iret = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_PHOTOS . '` SET `tags` = %s WHERE `id` = %s', $tags, $photo['id']));
                            wppa_index_update('photo', $photo['id']);
                        }
                    }
                    if ($photos && $iret !== false) {
                        echo '||97||' . __('<b>Tags added width defaults</b> (reload)', 'wp-photo-album-plus');
                    } elseif ($photos) {
                        echo '||1||' . __('An error occurred while adding tags', 'wp-photo-album-plus');
                    } else {
                        echo '||97||' . __('<b>No photos in this album</b>', 'wp-photo-album-plus');
                    }
                    wppa_clear_taglist();
                    wppa_exit();
                    break;
                case 'name':
                    $value = trim(strip_tags($value));
                    if (!wppa_sanitize_file_name($value)) {
                        // Empty album name is not allowed
                        $value = 'Album-#' . $album;
                        echo '||5||' . sprintf(__('Album name may not be empty.<br />Reset to <b>%s</b>', 'wp-photo-album-plus'), $value);
                    }
                    $itemname = __('Name', 'wp-photo-album-plus');
                    break;
                case 'description':
                    $itemname = __('Description', 'wp-photo-album-plus');
                    if (wppa_switch('check_balance')) {
                        $value = str_replace(array('<br/>', '<br>'), '<br />', $value);
                        if (balanceTags($value, true) != $value) {
                            echo '||3||' . __('Unbalanced tags in album description!', 'wp-photo-album-plus');
                            wppa_exit();
                        }
                    }
                    $value = trim($value);
                    break;
                case 'a_order':
                    $itemname = __('Album order #', 'wp-photo-album-plus');
                    break;
                case 'main_photo':
                    $itemname = __('Cover photo', 'wp-photo-album-plus');
                    break;
                case 'a_parent':
                    $itemname = __('Parent album', 'wp-photo-album-plus');
                    wppa_flush_treecounts($album);
                    // Myself and my parents
                    wppa_flush_treecounts($value);
                    // My new parent
                    break;
                case 'p_order_by':
                    $itemname = __('Photo order', 'wp-photo-album-plus');
                    break;
                case 'alt_thumbsize':
                    $itemname = __('Use Alt thumbsize', 'wp-photo-album-plus');
                    break;
                case 'cover_type':
                    $itemname = __('Cover Type', 'wp-photo-album-plus');
                    break;
                case 'cover_linktype':
                    $itemname = __('Link type', 'wp-photo-album-plus');
                    break;
                case 'cover_linkpage':
                    $itemname = __('Link to', 'wp-photo-album-plus');
                    break;
                case 'owner':
                    $itemname = __('Owner', 'wp-photo-album-plus');
                    if ($value != '--- public ---' && !get_user_by('login', $value)) {
                        echo '||4||' . sprintf(__('User %s does not exist', 'wp-photo-album-plus'), $value);
                        wppa_exit();
                    }
                    break;
                case 'upload_limit_count':
                    wppa_ajax_check_range($value, false, '0', false, __('Upload limit count', 'wp-photo-album-plus'));
                    if (wppa('error')) {
                        wppa_exit();
                    }
                    $oldval = $wpdb->get_var($wpdb->prepare('SELECT `upload_limit` FROM ' . WPPA_ALBUMS . ' WHERE `id` = %s', $album));
                    $temp = explode('/', $oldval);
                    $value = $value . '/' . $temp[1];
                    $item = 'upload_limit';
                    $itemname = __('Upload limit count', 'wp-photo-album-plus');
                    break;
                case 'upload_limit_time':
                    $oldval = $wpdb->get_var($wpdb->prepare('SELECT `upload_limit` FROM ' . WPPA_ALBUMS . ' WHERE `id` = %s', $album));
                    $temp = explode('/', $oldval);
                    $value = $temp[0] . '/' . $value;
                    $item = 'upload_limit';
                    $itemname = __('Upload limit time', 'wp-photo-album-plus');
                    break;
                case 'default_tags':
                    $value = wppa_sanitize_tags($value, false, true);
                    $itemname = __('Default tags', 'wp-photo-album-plus');
                    break;
                case 'cats':
                    $value = wppa_sanitize_cats($value);
                    wppa_clear_catlist();
                    $itemname = __('Categories', 'wp-photo-album-plus');
                    break;
                case 'suba_order_by':
                    $itemname = __('Sub albums sort order', 'wp-photo-album-plus');
                    break;
                case 'year':
                case 'month':
                case 'day':
                case 'hour':
                case 'min':
                    $itemname = __('Schedule date/time', 'wp-photo-album-plus');
                    $scheduledtm = $wpdb->get_var($wpdb->prepare("SELECT `scheduledtm` FROM`" . WPPA_ALBUMS . "` WHERE `id` = %s", $album));
                    if (!$scheduledtm) {
                        $scheduledtm = wppa_get_default_scheduledtm();
                    }
                    $temp = explode(',', $scheduledtm);
                    if ($item == 'year') {
                        $temp[0] = $value;
                    }
                    if ($item == 'month') {
                        $temp[1] = $value;
                    }
                    if ($item == 'day') {
                        $temp[2] = $value;
                    }
                    if ($item == 'hour') {
                        $temp[3] = $value;
                    }
                    if ($item == 'min') {
                        $temp[4] = $value;
                    }
                    $scheduledtm = implode(',', $temp);
                    wppa_update_album(array('id' => $album, 'scheduledtm' => $scheduledtm));
                    echo '||0||' . sprintf(__('<b>%s</b> of album %s updated', 'wp-photo-album-plus'), $itemname, $album);
                    wppa_exit();
                    break;
                case 'setallscheduled':
                    $scheduledtm = $wpdb->get_var($wpdb->prepare("SELECT `scheduledtm` FROM `" . WPPA_ALBUMS . "` WHERE `id` = %s", $album));
                    if ($scheduledtm) {
                        $iret = $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `status` = 'scheduled', `scheduledtm` = %s WHERE `album` = %s", $scheduledtm, $album));
                        echo '||0||' . __('All photos set to scheduled per date', 'wp-photo-album-plus') . ' ( ' . $iret . ' ) ' . wppa_format_scheduledtm($scheduledtm);
                    }
                    wppa_exit();
                    break;
                default:
                    $itemname = $item;
            }
            $query = $wpdb->prepare('UPDATE ' . WPPA_ALBUMS . ' SET `' . $item . '` = %s WHERE `id` = %s', $value, $album);
            $iret = $wpdb->query($query);
            if ($iret !== false) {
                if ($item == 'name' || $item == 'description' || $item == 'cats') {
                    wppa_index_update('album', $album);
                }
                if ($item == 'name') {
                    wppa_create_pl_htaccess();
                }
                echo '||0||' . sprintf(__('<b>%s</b> of album %s updated', 'wp-photo-album-plus'), $itemname, $album);
                if ($item == 'upload_limit') {
                    echo '||';
                    $a = wppa_allow_uploads($album);
                    if (!$a) {
                        echo 'full';
                    } else {
                        echo 'notfull||' . $a;
                    }
                }
            } else {
                echo '||2||' . sprintf(__('An error occurred while trying to update <b>%s</b> of album %s', 'wp-photo-album-plus'), $itemname, $album);
                echo '<br>' . __('Press CTRL+F5 and try again.', 'wp-photo-album-plus');
            }
            wppa_clear_cache();
            wppa_exit();
            break;
        case 'update-comment-status':
            $photo = $_REQUEST['wppa-photo-id'];
            $nonce = $_REQUEST['wppa-nonce'];
            $comid = $_REQUEST['wppa-comment-id'];
            $comstat = $_REQUEST['wppa-comment-status'];
            // Check validity
            if (!wp_verify_nonce($nonce, 'wppa_nonce_' . $photo)) {
                echo '||0||' . __('You do not have the rights to update comment status', 'wp-photo-album-plus') . $nonce;
                wppa_exit();
                // Nonce check failed
            }
            //			if ( wppa_switch( 'search_comments' ) ) wppa_index_remove( 'photo', $photo );
            $iret = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_COMMENTS . '` SET `status` = %s WHERE `id` = %s', $comstat, $comid));
            if (wppa_switch('search_comments')) {
                wppa_index_update('photo', $photo);
            }
            if ($iret !== false) {
                echo '||0||' . sprintf(__('Status of comment #%s updated', 'wp-photo-album-plus'), $comid);
            } else {
                echo '||1||' . sprintf(__('Error updating status comment #%s', 'wp-photo-album-plus'), $comid);
            }
            wppa_exit();
            break;
        case 'watermark-photo':
            $photo = $_REQUEST['photo-id'];
            $nonce = $_REQUEST['wppa-nonce'];
            // Check validity
            if (!wp_verify_nonce($nonce, 'wppa_nonce_' . $photo)) {
                echo '||1||' . __('You do not have the rights to change photos', 'wp-photo-album-plus');
                wppa_exit();
                // Nonce check failed
            }
            wppa_cache_thumb($photo);
            if (wppa_add_watermark($photo)) {
                if (wppa_switch('watermark_thumbs')) {
                    wppa_create_thumbnail($photo);
                    // create new thumb
                }
                echo '||0||' . __('Watermark applied', 'wp-photo-album-plus');
                wppa_exit();
            } else {
                echo '||1||' . __('An error occured while trying to apply a watermark', 'wp-photo-album-plus');
                wppa_exit();
            }
        case 'update-photo':
            $photo = $_REQUEST['photo-id'];
            $nonce = $_REQUEST['wppa-nonce'];
            $item = $_REQUEST['item'];
            $value = isset($_REQUEST['value']) ? $_REQUEST['value'] : '';
            $value = wppa_decode($value);
            // Check validity
            if (!wp_verify_nonce($nonce, 'wppa_nonce_' . $photo)) {
                echo '||0||' . __('You do not have the rights to update photo information', 'wp-photo-album-plus');
                wppa_exit();
                // Nonce check failed
            }
            if (substr($item, 0, 20) == 'wppa_watermark_file_' || substr($item, 0, 19) == 'wppa_watermark_pos_') {
                wppa_update_option($item, $value);
                echo '||0||' . sprintf(__('%s updated to %s.', 'wp-photo-album-plus'), $item, $value);
                wppa_exit();
            }
            switch ($item) {
                case 'exifdtm':
                    $format = '0000:00:00 00:00:00';
                    $err = '0';
                    // Length ok?
                    if (strlen($value) != 19) {
                        $err = '1';
                    }
                    // Check on digits, colons and space
                    for ($i = 0; $i < 19; $i++) {
                        $d = substr($value, $i, 1);
                        $f = substr($format, $i, 1);
                        switch ($f) {
                            case '0':
                                if (!in_array($d, array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9'))) {
                                    $err = '2';
                                }
                                break;
                            case ':':
                            case ' ':
                                if ($d != $f) {
                                    $err = '3';
                                }
                                break;
                        }
                    }
                    // Check on values if format correct, report first error only
                    if (!$err) {
                        $temp = explode(':', str_replace(' ', ':', $value));
                        if ($temp['0'] < '1970') {
                            $err = '11';
                        }
                        // Before UNIX epoch
                        if (!$err && $temp['0'] > date('Y')) {
                            $err = '12';
                        }
                        // Future
                        if (!$err && $temp['1'] < '1') {
                            $err = '13';
                        }
                        // Before january
                        if (!$err && $temp['1'] > '12') {
                            $err = '14';
                        }
                        // After december
                        if (!$err && $temp['2'] < '1') {
                            $err = '15';
                        }
                        // Before first of month
                        if (!$err && $temp['2'] > '31') {
                            $err = '17';
                        }
                        // After 31st ( forget about feb and months with 30 days )
                        if (!$err && $temp['3'] < '1') {
                            $err = '18';
                        }
                        // Before first hour
                        if (!$err && $temp['3'] > '24') {
                            $err = '19';
                        }
                        // Hour > 24
                        if (!$err && $temp['4'] < '1') {
                            $err = '20';
                        }
                        // Min < 1
                        if (!$err && $temp['4'] > '59') {
                            $err = '21';
                        }
                        // Min > 59
                        if (!$err && $temp['5'] < '1') {
                            $err = '22';
                        }
                        // Sec < 1
                        if (!$err && $temp['5'] > '59') {
                            $err = '23';
                        }
                        // Sec > 59
                    }
                    if ($err) {
                        echo '||1||' . sprintf(__('Format error %s. Must be yyyy:mm:dd hh:mm:ss', 'wp-photo-album-plus'), $err);
                    } else {
                        wppa_update_photo(array('id' => $photo, 'exifdtm' => $value));
                        echo '||0||' . __('Exif date/time updated', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'lat':
                    if (!is_numeric($value) || $value < '-90.0' || $value > '90.0') {
                        echo '||1||' . __('Enter a value > -90 and < 90', 'wp-photo-album-plus');
                        wppa_exit();
                    }
                    $photodata = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPPA_PHOTOS . ' WHERE `id` = %s', $photo), ARRAY_A);
                    $geo = $photodata['location'] ? $photodata['location'] : '///';
                    $geo = explode('/', $geo);
                    $geo = wppa_format_geo($value, $geo['3']);
                    $iret = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_PHOTOS . '` SET `location` = %s WHERE `id` = %s', $geo, $photo));
                    if ($iret) {
                        echo '||0||' . __('Lattitude updated', 'wp-photo-album-plus');
                    } else {
                        echo '||1||' . __('Could not update lattitude', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'lon':
                    if (!is_numeric($value) || $value < '-180.0' || $value > '180.0') {
                        echo '||1||' . __('Enter a value > -180 and < 180', 'wp-photo-album-plus');
                        wppa_exit();
                    }
                    $photodata = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPPA_PHOTOS . ' WHERE `id` = %s', $photo), ARRAY_A);
                    $geo = $photodata['location'] ? $photodata['location'] : '///';
                    $geo = explode('/', $geo);
                    $geo = wppa_format_geo($geo['2'], $value);
                    $iret = $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_PHOTOS . '` SET `location` = %s WHERE `id` = %s', $geo, $photo));
                    if ($iret) {
                        echo '||0||' . __('Longitude updated', 'wp-photo-album-plus');
                    } else {
                        echo '||1||' . __('Could not update longitude', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'remake':
                    if (wppa_remake_files('', $photo)) {
                        wppa_bump_photo_rev();
                        wppa_bump_thumb_rev();
                        echo '||0||' . __('Photo files remade', 'wp-photo-album-plus');
                    } else {
                        echo '||2||' . __('Could not remake files', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'remakethumb':
                    if (wppa_create_thumbnail($photo)) {
                        echo '||0||' . __('Thumbnail remade', 'wp-photo-album-plus');
                    } else {
                        echo '||0||' . __('Could not remake thumbnail', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'rotright':
                case 'rot180':
                case 'rotleft':
                    switch ($item) {
                        case 'rotleft':
                            $angle = '90';
                            $dir = __('left', 'wp-photo-album-plus');
                            break;
                        case 'rot180':
                            $angle = '180';
                            $dir = __('180&deg;', 'wp-photo-album-plus');
                            break;
                        case 'rotright':
                            $angle = '270';
                            $dir = __('right', 'wp-photo-album-plus');
                            break;
                    }
                    wppa('error', wppa_rotate($photo, $angle));
                    if (!wppa('error')) {
                        wppa_update_modified($photo);
                        wppa_bump_photo_rev();
                        wppa_bump_thumb_rev();
                        echo '||0||' . sprintf(__('Photo %s rotated %s', 'wp-photo-album-plus'), $photo, $dir);
                    } else {
                        echo '||' . wppa('error') . '||' . sprintf(__('An error occurred while trying to rotate photo %s', 'wp-photo-album-plus'), $photo);
                    }
                    wppa_exit();
                    break;
                case 'moveto':
                    $photodata = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPPA_PHOTOS . ' WHERE `id` = %s', $photo), ARRAY_A);
                    if (wppa_switch('void_dups')) {
                        // Check for already exists
                        $exists = wppa_file_is_in_album($photodata['filename'], $value);
                        if ($exists) {
                            // Already exists
                            echo '||3||' . sprintf(__('A photo with filename %s already exists in album %s.', 'wp-photo-album-plus'), $photodata['filename'], $value);
                            wppa_exit();
                            break;
                        }
                    }
                    wppa_flush_treecounts($photodata['album']);
                    // Current album
                    wppa_flush_treecounts($value);
                    // New album
                    $iret = $wpdb->query($wpdb->prepare('UPDATE ' . WPPA_PHOTOS . ' SET `album` = %s WHERE `id` = %s', $value, $photo));
                    if ($iret !== false) {
                        wppa_move_source($photodata['filename'], $photodata['album'], $value);
                        echo '||99||' . sprintf(__('Photo %s has been moved to album %s (%s)', 'wp-photo-album-plus'), $photo, wppa_get_album_name($value), $value);
                    } else {
                        echo '||3||' . sprintf(__('An error occurred while trying to move photo %s', 'wp-photo-album-plus'), $photo);
                    }
                    wppa_exit();
                    break;
                case 'copyto':
                    $photodata = $wpdb->get_row($wpdb->prepare('SELECT * FROM ' . WPPA_PHOTOS . ' WHERE `id` = %s', $photo), ARRAY_A);
                    if (wppa_switch('void_dups')) {
                        // Check for already exists
                        $exists = wppa_file_is_in_album($photodata['filename'], $value);
                        if ($exists) {
                            // Already exists
                            echo '||4||' . sprintf(__('A photo with filename %s already exists in album %s.', 'wp-photo-album-plus'), $photodata['filename'], $value);
                            wppa_exit();
                            break;
                        }
                    }
                    wppa('error', wppa_copy_photo($photo, $value));
                    wppa_flush_treecounts($value);
                    // New album
                    if (!wppa('error')) {
                        echo '||0||' . sprintf(__('Photo %s copied to album %s (%s)', 'wp-photo-album-plus'), $photo, wppa_get_album_name($value), $value);
                    } else {
                        echo '||4||' . sprintf(__('An error occurred while trying to copy photo %s', 'wp-photo-album-plus'), $photo);
                        echo '<br>' . __('Press CTRL+F5 and try again.', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'status':
                    if (!current_user_can('wppa_moderate') && !current_user_can('wppa_admin')) {
                        die('Security check failure #78');
                    }
                    wppa_flush_treecounts(wppa_get_photo_item($photo, 'album'));
                    // $wpdb->get_var( $wpdb->prepare( "SELECT `album` FROM `".WPPA_PHOTOS."` WHERE `id` = %s", $photo ) ) );
                // $wpdb->get_var( $wpdb->prepare( "SELECT `album` FROM `".WPPA_PHOTOS."` WHERE `id` = %s", $photo ) ) );
                case 'owner':
                case 'name':
                case 'description':
                case 'p_order':
                case 'linkurl':
                case 'linktitle':
                case 'linktarget':
                case 'tags':
                case 'alt':
                case 'videox':
                case 'videoy':
                    switch ($item) {
                        case 'name':
                            $value = strip_tags($value);
                            $itemname = __('Name', 'wp-photo-album-plus');
                            break;
                        case 'description':
                            $itemname = __('Description', 'wp-photo-album-plus');
                            if (wppa_switch('check_balance')) {
                                $value = str_replace(array('<br/>', '<br>'), '<br />', $value);
                                if (balanceTags($value, true) != $value) {
                                    echo '||3||' . __('Unbalanced tags in photo description!', 'wp-photo-album-plus');
                                    wppa_exit();
                                }
                            }
                            break;
                        case 'p_order':
                            $itemname = __('Photo order #', 'wp-photo-album-plus');
                            break;
                        case 'owner':
                            $usr = get_user_by('login', $value);
                            if (!$usr) {
                                echo '||4||' . sprintf(__('User %s does not exists', 'wp-photo-album-plus'), $value);
                                wppa_exit();
                            }
                            $value = $usr->user_login;
                            // Correct possible case mismatch
                            wppa_flush_upldr_cache('photoid', $photo);
                            // Current owner
                            wppa_flush_upldr_cache('username', $value);
                            // New owner
                            $itemname = __('Owner', 'wp-photo-album-plus');
                            break;
                        case 'linkurl':
                            $itemname = __('Link url', 'wp-photo-album-plus');
                            break;
                        case 'linktitle':
                            $itemname = __('Link title', 'wp-photo-album-plus');
                            break;
                        case 'linktarget':
                            $itemname = __('Link target', 'wp-photo-album-plus');
                            break;
                        case 'tags':
                            $value = wppa_sanitize_tags($value, false, true);
                            $value = wppa_sanitize_tags(wppa_filter_iptc(wppa_filter_exif($value, $photo), $photo));
                            wppa_clear_taglist();
                            $itemname = __('Photo Tags', 'wp-photo-album-plus');
                            break;
                        case 'status':
                            wppa_clear_taglist();
                            wppa_flush_upldr_cache('photoid', $photo);
                            $itemname = __('Status', 'wp-photo-album-plus');
                            break;
                        case 'alt':
                            $itemname = __('HTML Alt', 'wp-photo-album-plus');
                            $value = strip_tags(stripslashes($value));
                            break;
                        case 'videox':
                            $itemname = __('Video width', 'wp-photo-album-plus');
                            if (!wppa_is_int($value) || $value < '0') {
                                echo '||3||' . __('Please enter an integer value >= 0', 'wp-photo-album-plus');
                                wppa_exit();
                            }
                            break;
                        case 'videoy':
                            $itemname = __('Video height', 'wp-photo-album-plus');
                            if (!wppa_is_int($value) || $value < '0') {
                                echo '||3||' . __('Please enter an integer value >= 0', 'wp-photo-album-plus');
                                wppa_exit();
                            }
                            break;
                        default:
                            $itemname = $item;
                    }
                    //				if ( $item == 'name' || $item == 'description' || $item == 'tags' ) wppa_index_quick_remove( 'photo', $photo );
                    $iret = $wpdb->query($wpdb->prepare('UPDATE ' . WPPA_PHOTOS . ' SET `' . $item . '` = %s WHERE `id` = %s', $value, $photo));
                    if ($item == 'name' || $item == 'description' || $item == 'tags') {
                        wppa_index_update('photo', $photo);
                    }
                    if ($item == 'status' && $value != 'scheduled') {
                        wppa_update_photo(array('id' => $photo, 'scheduledtm' => ''));
                    }
                    if ($item == 'status') {
                        wppa_flush_treecounts(wppa_get_photo_item($photo, 'album'));
                    }
                    if ($iret !== false) {
                        wppa_update_modified($photo);
                        if (wppa_is_video($photo)) {
                            echo '||0||' . sprintf(__('<b>%s</b> of video %s updated', 'wp-photo-album-plus'), $itemname, $photo);
                        } else {
                            echo '||0||' . sprintf(__('<b>%s</b> of photo %s updated', 'wp-photo-album-plus'), $itemname, $photo);
                        }
                    } else {
                        echo '||2||' . sprintf(__('An error occurred while trying to update <b>%s</b> of photo %s', 'wp-photo-album-plus'), $itemname, $photo);
                        echo '<br>' . __('Press CTRL+F5 and try again.', 'wp-photo-album-plus');
                        wppa_exit();
                    }
                    break;
                case 'year':
                case 'month':
                case 'day':
                case 'hour':
                case 'min':
                    $itemname = __('Schedule date/time', 'wp-photo-album-plus');
                    $scheduledtm = $wpdb->get_var($wpdb->prepare("SELECT `scheduledtm` FROM`" . WPPA_PHOTOS . "` WHERE `id` = %s", $photo));
                    if (!$scheduledtm) {
                        $scheduledtm = wppa_get_default_scheduledtm();
                    }
                    $temp = explode(',', $scheduledtm);
                    if ($item == 'year') {
                        $temp[0] = $value;
                    }
                    if ($item == 'month') {
                        $temp[1] = $value;
                    }
                    if ($item == 'day') {
                        $temp[2] = $value;
                    }
                    if ($item == 'hour') {
                        $temp[3] = $value;
                    }
                    if ($item == 'min') {
                        $temp[4] = $value;
                    }
                    $scheduledtm = implode(',', $temp);
                    wppa_update_photo(array('id' => $photo, 'scheduledtm' => $scheduledtm, 'status' => 'scheduled'));
                    wppa_flush_treecounts($wpdb->get_var($wpdb->prepare("SELECT `album` FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s", $photo)));
                    wppa_flush_upldr_cache('photoid', $photo);
                    if (wppa_is_video($photo)) {
                        echo '||0||' . sprintf(__('<b>%s</b> of video %s updated', 'wp-photo-album-plus'), $itemname, $photo);
                    } else {
                        echo '||0||' . sprintf(__('<b>%s</b> of photo %s updated', 'wp-photo-album-plus'), $itemname, $photo);
                    }
                    break;
                case 'custom_0':
                case 'custom_1':
                case 'custom_2':
                case 'custom_3':
                case 'custom_4':
                case 'custom_5':
                case 'custom_6':
                case 'custom_7':
                case 'custom_8':
                case 'custom_9':
                    $index = substr($item, -1);
                    $custom = wppa_get_photo_item($photo, 'custom');
                    if ($custom) {
                        $custom_data = unserialize($custom);
                    } else {
                        $custom_data = array('', '', '', '', '', '', '', '', '', '');
                    }
                    $custom_data[$index] = strip_tags($value);
                    $custom = serialize($custom_data);
                    wppa_update_photo(array('id' => $photo, 'custom' => $custom, 'modified' => time()));
                    wppa_index_update('photo', $photo);
                    echo '||0||' . sprintf(__('<b>Custom field %s</b> of photo %s updated', 'wp-photo-album-plus'), wppa_opt('custom_caption_' . $index), $photo);
                    break;
                case 'file':
                    // Check on upload error
                    if ($_FILES['photo']['error']) {
                        echo '||' . $_FILES['photo']['error'] . '||' . __('<b>Error during upload.</b>', 'wp-photo-album-plus');
                        wppa_exit();
                    }
                    // Save new source
                    wppa_save_source($_FILES['photo']['tmp_name'], wppa_get_photo_item($photo, 'filename'), wppa_get_photo_item($photo, 'album'));
                    // Make the files
                    $bret = wppa_make_the_photo_files($_FILES['photo']['tmp_name'], $photo, strtolower(wppa_get_ext($_FILES['photo']['name'])));
                    if ($bret) {
                        // Update timestamps and sizes
                        $alb = wppa_get_photo_item($photo, 'album');
                        wppa_update_album(array('id' => $alb, 'modified' => time()));
                        wppa_update_photo(array('id' => $photo, 'modified' => time(), 'thumbx' => '0', 'thumby' => '0', 'photox' => '0', 'photoy' => '0'));
                        // Report success
                        echo '||0||' . __('Photo files updated.', 'wp-photo-album-plus');
                    } else {
                        // Report fail
                        echo '||1||' . __('Could not update files.', 'wp-photo-album-plus');
                    }
                    wppa_exit();
                    break;
                case 'stereo':
                    $t = microtime(true);
                    wppa_update_photo(array('id' => $photo, 'stereo' => $value));
                    wppa_create_stereo_images($photo);
                    wppa_create_thumbnail($photo);
                    $t = microtime(true) - $t;
                    echo '||0||' . sprintf(__('Stereo mode updated in %d milliseconds', 'wp-photo-album-plus'), floor($t * 1000));
                    wppa_exit();
                    break;
                default:
                    echo '||98||This update action is not implemented yet( ' . $item . ' )';
                    wppa_exit();
            }
            wppa_clear_cache();
            break;
            // The wppa-settings page calls ajax with $wppa_action == 'update-option';
        // The wppa-settings page calls ajax with $wppa_action == 'update-option';
        case 'update-option':
            // Verify that we are legally here
            $nonce = $_REQUEST['wppa-nonce'];
            if (!wp_verify_nonce($nonce, 'wppa-nonce')) {
                echo '||1||' . __('You do not have the rights to update settings', 'wp-photo-album-plus');
                wppa_exit();
                // Nonce check failed
            }
            // Initialize
            $old_minisize = wppa_get_minisize();
            // Remember for later, maybe we do something that requires regen
            $option = $_REQUEST['wppa-option'];
            // The option to be processed
            $value = isset($_REQUEST['value']) ? wppa_decode($_REQUEST['value']) : '';
            // The new value, may also contain & # and +
            $value = stripslashes($value);
            $value = trim($value);
            // Remaove surrounding spaces
            $alert = '';
            // Init the return string data
            wppa('error', '0');
            //
            $title = '';
            //
            // If it is a font family, change all double quotes into single quotes as this destroys much more than you would like
            if (strpos($option, 'wppa_fontfamily_') !== false) {
                $value = str_replace('"', "'", $value);
            }
            $option = wppa_decode($option);
            // Dispatch on option
            if (substr($option, 0, 16) == 'wppa_iptc_label_') {
                $tag = substr($option, 16);
                $q = $wpdb->prepare("UPDATE `" . WPPA_IPTC . "` SET `description`=%s WHERE `tag`=%s AND `photo`='0'", $value, $tag);
                $bret = $wpdb->query($q);
                // Produce the response text
                if ($bret) {
                    $output = '||0||' . $tag . ' updated to ' . $value . '||';
                } else {
                    $output = '||1||Failed to update ' . $tag . '||';
                }
                echo $output;
                wppa_exit();
            } elseif (substr($option, 0, 17) == 'wppa_iptc_status_') {
                $tag = substr($option, 17);
                $q = $wpdb->prepare("UPDATE `" . WPPA_IPTC . "` SET `status`=%s WHERE `tag`=%s AND `photo`='0'", $value, $tag);
                $bret = $wpdb->query($q);
                // Produce the response text
                if ($bret) {
                    $output = '||0||' . $tag . ' updated to ' . $value . '||';
                } else {
                    $output = '||1||Failed to update ' . $tag . '||';
                }
                echo $output;
                wppa_exit();
            } elseif (substr($option, 0, 16) == 'wppa_exif_label_') {
                $tag = substr($option, 16);
                $q = $wpdb->prepare("UPDATE `" . WPPA_EXIF . "` SET `description`=%s WHERE `tag`=%s AND `photo`='0'", $value, $tag);
                $bret = $wpdb->query($q);
                // Produce the response text
                if ($bret) {
                    $output = '||0||' . $tag . ' updated to ' . $value . '||';
                } else {
                    $output = '||1||Failed to update ' . $tag . '||';
                }
                echo $output;
                wppa_exit();
            } elseif (substr($option, 0, 17) == 'wppa_exif_status_') {
                $tag = substr($option, 17);
                $q = $wpdb->prepare("UPDATE `" . WPPA_EXIF . "` SET `status`=%s WHERE `tag`=%s AND `photo`='0'", $value, $tag);
                $bret = $wpdb->query($q);
                // Produce the response text
                if ($bret) {
                    $output = '||0||' . $tag . ' updated to ' . $value . '||';
                } else {
                    $output = '||1||Failed to update ' . $tag . '||';
                }
                echo $output;
                wppa_exit();
            } elseif (substr($option, 0, 5) == 'caps-') {
                // Is capability setting
                global $wp_roles;
                //$R = new WP_Roles;
                $setting = explode('-', $option);
                if ($value == 'yes') {
                    $wp_roles->add_cap($setting[2], $setting[1]);
                    echo '||0||' . __('Capability granted', 'wp-photo-album-plus') . '||';
                    wppa_exit();
                } elseif ($value == 'no') {
                    $wp_roles->remove_cap($setting[2], $setting[1]);
                    echo '||0||' . __('Capability withdrawn', 'wp-photo-album-plus') . '||';
                    wppa_exit();
                } else {
                    echo '||1||Invalid value: ' . $value . '||';
                    wppa_exit();
                }
            } else {
                switch ($option) {
                    case 'wppa_colwidth':
                        //	 ??	  fixed   low	high	title
                        wppa_ajax_check_range($value, 'auto', '100', false, __('Column width.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_initial_colwidth':
                        wppa_ajax_check_range($value, false, '100', false, __('Initial width.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_fullsize':
                        wppa_ajax_check_range($value, false, '100', false, __('Full size.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_maxheight':
                        wppa_ajax_check_range($value, false, '100', false, __('Max height.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_thumbsize':
                        wppa_ajax_check_range($value, false, '50', false, __('Thumbnail size.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_tf_width':
                        wppa_ajax_check_range($value, false, '50', false, __('Thumbnail frame width', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_tf_height':
                        wppa_ajax_check_range($value, false, '50', false, __('Thumbnail frame height', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_tn_margin':
                        wppa_ajax_check_range($value, false, '0', false, __('Thumbnail Spacing', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_min_thumbs':
                        wppa_ajax_check_range($value, false, '0', false, __('Photocount treshold.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_thumb_page_size':
                        wppa_ajax_check_range($value, false, '0', false, __('Thumb page size.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_smallsize':
                        wppa_ajax_check_range($value, false, '50', false, __('Cover photo size.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_album_page_size':
                        wppa_ajax_check_range($value, false, '0', false, __('Album page size.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_topten_count':
                        wppa_ajax_check_range($value, false, '2', false, __('Number of TopTen photos', 'wp-photo-album-plus'), '40');
                        break;
                    case 'wppa_topten_size':
                        wppa_ajax_check_range($value, false, '32', false, __('Widget image thumbnail size', 'wp-photo-album-plus'), wppa_get_minisize());
                        break;
                    case 'wppa_max_cover_width':
                        wppa_ajax_check_range($value, false, '150', false, __('Max Cover width', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_text_frame_height':
                        wppa_ajax_check_range($value, false, '0', false, __('Minimal description height', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_cover_minheight':
                        wppa_ajax_check_range($value, false, '0', false, __('Minimal cover height', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_head_and_text_frame_height':
                        wppa_ajax_check_range($value, false, '0', false, __('Minimal text frame height', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_bwidth':
                        wppa_ajax_check_range($value, '', '0', false, __('Border width', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_bradius':
                        wppa_ajax_check_range($value, '', '0', false, __('Border radius', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_box_spacing':
                        wppa_ajax_check_range($value, '', '-20', '100', __('Box spacing', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_popupsize':
                        $floor = wppa_opt('thumbsize');
                        $temp = wppa_opt('smallsize');
                        if ($temp > $floor) {
                            $floor = $temp;
                        }
                        wppa_ajax_check_range($value, false, $floor, wppa_opt('fullsize'), __('Popup size', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_fullimage_border_width':
                        wppa_ajax_check_range($value, '', '0', false, __('Fullsize border width', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_lightbox_bordersize':
                        wppa_ajax_check_range($value, false, '0', false, __('Lightbox Bordersize', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_ovl_border_width':
                        wppa_ajax_check_range($value, false, '0', '16', __('Lightbox Borderwidth', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_ovl_border_radius':
                        wppa_ajax_check_range($value, false, '0', '16', __('Lightbox Borderradius', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_comment_count':
                        wppa_ajax_check_range($value, false, '2', '40', __('Number of Comment widget entries', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_comment_size':
                        wppa_ajax_check_range($value, false, '32', wppa_get_minisize(), __('Comment Widget image thumbnail size', 'wp-photo-album-plus'), wppa_get_minisize());
                        break;
                    case 'wppa_thumb_opacity':
                        wppa_ajax_check_range($value, false, '0', '100', __('Opacity.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_cover_opacity':
                        wppa_ajax_check_range($value, false, '0', '100', __('Opacity.', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_star_opacity':
                        wppa_ajax_check_range($value, false, '0', '50', __('Opacity.', 'wp-photo-album-plus'));
                        break;
                        //				case 'wppa_filter_priority':
                        //					wppa_ajax_check_range( $value, false, wppa_opt( 'shortcode_priority' ), false, __( 'Filter priority' ,'wp-photo-album-plus' ) );
                        //					break;
                        //				case 'wppa_shortcode_priority':
                        //					wppa_ajax_check_range( $value, false, '0', wppa_opt( 'filter_priority' ) - '1', __( 'Shortcode_priority', 'wp-photo-album-plus' ) );
                        //					break;
                    //				case 'wppa_filter_priority':
                    //					wppa_ajax_check_range( $value, false, wppa_opt( 'shortcode_priority' ), false, __( 'Filter priority' ,'wp-photo-album-plus' ) );
                    //					break;
                    //				case 'wppa_shortcode_priority':
                    //					wppa_ajax_check_range( $value, false, '0', wppa_opt( 'filter_priority' ) - '1', __( 'Shortcode_priority', 'wp-photo-album-plus' ) );
                    //					break;
                    case 'wppa_gravatar_size':
                        wppa_ajax_check_range($value, false, '10', '256', __('Avatar size', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_watermark_opacity':
                        wppa_ajax_check_range($value, false, '0', '100', __('Watermark opacity', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_watermark_opacity_text':
                        wppa_ajax_check_range($value, false, '0', '100', __('Watermark opacity', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_ovl_txt_lines':
                        wppa_ajax_check_range($value, 'auto', '0', '24', __('Number of text lines', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_ovl_opacity':
                        wppa_ajax_check_range($value, false, '0', '100', __('Overlay opacity', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_upload_limit_count':
                        wppa_ajax_check_range($value, false, '0', false, __('Upload limit', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_dislike_mail_every':
                        wppa_ajax_check_range($value, false, '0', false, __('Notify inappropriate', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_dislike_set_pending':
                        wppa_ajax_check_range($value, false, '0', false, __('Dislike pending', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_dislike_delete':
                        wppa_ajax_check_range($value, false, '0', false, __('Dislike delete', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_max_execution_time':
                        wppa_ajax_check_range($value, false, '0', '900', __('Max execution time', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_cp_points_comment':
                    case 'wppa_cp_points_rating':
                    case 'wppa_cp_points_upload':
                        wppa_ajax_check_range($value, false, '0', false, __('Cube Points points', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_jpeg_quality':
                        wppa_ajax_check_range($value, false, '20', '100', __('JPG Image quality', 'wp-photo-album-plus'));
                        if (wppa_cdn('admin') == 'cloudinary' && !wppa('out')) {
                            wppa_delete_derived_from_cloudinary();
                        }
                        break;
                    case 'wppa_imgfact_count':
                        wppa_ajax_check_range($value, false, '1', '24', __('Number of coverphotos', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_dislike_value':
                        wppa_ajax_check_range($value, false, '-10', '0', __('Dislike value', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_slideshow_pagesize':
                        wppa_ajax_check_range($value, false, '0', false, __('Slideshow pagesize', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_pagelinks_max':
                        wppa_ajax_check_range($value, false, '0', false, __('Max Pagelinks', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_start_pause_symbol_size':
                        wppa_ajax_check_range($value, false, '0', false, __('Start/pause symbol size', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_start_pause_symbol_bradius':
                        wppa_ajax_check_range($value, false, '0', false, __('Start/pause symbol border radius', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_stop_symbol_size':
                        wppa_ajax_check_range($value, false, '0', false, __('Stop symbol size', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_stop_symbol_bradius':
                        wppa_ajax_check_range($value, false, '0', false, __('Stop symbol border radius', 'wp-photo-album-plus'));
                        break;
                    case 'wppa_rating_clear':
                        $iret1 = $wpdb->query('TRUNCATE TABLE ' . WPPA_RATING);
                        $iret2 = $wpdb->query('UPDATE ' . WPPA_PHOTOS . ' SET mean_rating="0", rating_count="0" WHERE id > -1');
                        if ($iret1 !== false && $iret2 !== false) {
                            delete_option('wppa_' . WPPA_RATING . '_lastkey');
                            $title = __('Ratings cleared', 'wp-photo-album-plus');
                        } else {
                            $title = __('Could not clear ratings', 'wp-photo-album-plus');
                            $alert = $title;
                            wppa('error', '1');
                        }
                        break;
                    case 'wppa_viewcount_clear':
                        $iret = $wpdb->query("UPDATE `" . WPPA_PHOTOS . "` SET `views` = '0'") && $wpdb->query("UPDATE `" . WPPA_ALBUMS . "` SET `views` = '0'");
                        if ($iret !== false) {
                            $title = __('Viewcounts cleared', 'wp-photo-album-plus');
                        } else {
                            $title = __('Could not clear viewcounts', 'wp-photo-album-plus');
                            $alert = $title;
                            wppa('error', '1');
                        }
                        break;
                    case 'wppa_iptc_clear':
                        $iret = $wpdb->query('TRUNCATE TABLE ' . WPPA_IPTC);
                        if ($iret !== false) {
                            delete_option('wppa_' . WPPA_IPTC . '_lastkey');
                            $title = __('IPTC data cleared', 'wp-photo-album-plus');
                            $alert = __('Refresh this page to clear table X', 'wp-photo-album-plus');
                            update_option('wppa_index_need_remake', 'yes');
                        } else {
                            $title = __('Could not clear IPTC data', 'wp-photo-album-plus');
                            $alert = $title;
                            wppa('error', '1');
                        }
                        break;
                    case 'wppa_exif_clear':
                        $iret = $wpdb->query('TRUNCATE TABLE ' . WPPA_EXIF);
                        if ($iret !== false) {
                            delete_option('wppa_' . WPPA_EXIF . '_lastkey');
                            $title = __('EXIF data cleared', 'wp-photo-album-plus');
                            $alert = __('Refresh this page to clear table XI', 'wp-photo-album-plus');
                            update_option('wppa_index_need_remake', 'yes');
                        } else {
                            $title = __('Could not clear EXIF data', 'wp-photo-album-plus');
                            $alert = $title;
                            wppa('error', '1');
                        }
                        break;
                    case 'wppa_recup':
                        $result = wppa_recuperate_iptc_exif();
                        echo '||0||' . __('Recuperation performed', 'wp-photo-album-plus') . '||' . $result;
                        wppa_exit();
                        break;
                    case 'wppa_bgcolor_thumbnail':
                        $value = trim(strtolower($value));
                        if (strlen($value) != '7' || substr($value, 0, 1) != '#') {
                            wppa('error', '1');
                        } else {
                            for ($i = 1; $i < 7; $i++) {
                                if (!in_array(substr($value, $i, 1), array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'))) {
                                    wppa('error', '1');
                                }
                            }
                        }
                        if (!wppa('error')) {
                            $old_minisize--;
                        } else {
                            $alert = __('Illegal format. Please enter a 6 digit hexadecimal color value. Example: #77bbff', 'wp-photo-album-plus');
                        }
                        break;
                    case 'wppa_thumb_aspect':
                        $old_minisize--;
                        // Trigger regen message
                        break;
                    case 'wppa_rating_max':
                        if ($value == '5' && wppa_opt('rating_max') == '10') {
                            $rats = $wpdb->get_results('SELECT `id`, `value` FROM `' . WPPA_RATING . '`', ARRAY_A);
                            if ($rats) {
                                foreach ($rats as $rat) {
                                    $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_RATING . '` SET `value` = %s WHERE `id` = %s', $rat['value'] / 2, $rat['id']));
                                }
                            }
                        }
                        if ($value == '10' && wppa_opt('rating_max') == '5') {
                            $rats = $wpdb->get_results('SELECT `id`, `value` FROM `' . WPPA_RATING . '`', ARRAY_A);
                            if ($rats) {
                                foreach ($rats as $rat) {
                                    $wpdb->query($wpdb->prepare('UPDATE `' . WPPA_RATING . '` SET `value` = %s WHERE `id` = %s', $rat['value'] * 2, $rat['id']));
                                }
                            }
                        }
                        update_option('wppa_rerate_status', 'Required');
                        $alert .= __('You just changed a setting that requires the recalculation of ratings.', 'wp-photo-album-plus');
                        $alert .= ' ' . __('Please run the appropriate action in Table VIII.', 'wp-photo-album-plus');
                        wppa_update_option($option, $value);
                        wppa('error', '0');
                        break;
                    case 'wppa_newphoto_description':
                        if (wppa_switch('check_balance') && balanceTags($value, true) != $value) {
                            $alert = __('Unbalanced tags in photo description!', 'wp-photo-album-plus');
                            wppa('error', '1');
                        } else {
                            wppa_update_option($option, $value);
                            wppa('error', '0');
                            $alert = '';
                            wppa_index_compute_skips();
                        }
                        break;
                    case 'wppa_keep_source':
                        $dir = wppa_opt('source_dir');
                        if (!is_dir($dir)) {
                            @mkdir($dir);
                        }
                        if (!is_dir($dir) || !is_writable($dir)) {
                            wppa('error', '1');
                            $alert = sprintf(__('Unable to create or write to %s', 'wp-photo-album-plus'), $dir);
                        }
                        break;
                    case 'wppa_source_dir':
                        $olddir = wppa_opt('source_dir');
                        $value = rtrim($value, '/');
                        if (strpos($value . '/', WPPA_UPLOAD_PATH . '/') !== false) {
                            wppa('error', '1');
                            $alert = sprintf(__('Source can not be inside the wppa folder.', 'wp-photo-album-plus'));
                        } else {
                            $dir = $value;
                            if (!is_dir($dir)) {
                                @mkdir($dir);
                            }
                            if (!is_dir($dir) || !is_writable($dir)) {
                                wppa('error', '1');
                                $alert = sprintf(__('Unable to create or write to %s', 'wp-photo-album-plus'), $dir);
                            } else {
                                @rmdir($olddir);
                                // try to remove when empty
                            }
                        }
                        break;
                    case 'wppa_newpag_content':
                        if (strpos($value, 'w#album') === false) {
                            $alert = __('The content must contain w#album', 'wp-photo-album-plus');
                            wppa('error', '1');
                        }
                        break;
                    case 'wppa_gpx_shortcode':
                        if (strpos($value, 'w#lat') === false || strpos($value, 'w#lon') === false) {
                            $alert = __('The content must contain w#lat and w#lon', 'wp-photo-album-plus');
                            wppa('error', '1');
                        }
                        break;
                    case 'wppa_i_responsive':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_colwidth', 'auto');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_colwidth', '640');
                        }
                        break;
                    case 'wppa_i_downsize':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_resize_on_upload', 'yes');
                            if (wppa_opt('resize_to') == '0') {
                                wppa_update_option('wppa_resize_to', '1024x768');
                            }
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_resize_on_upload', 'no');
                        }
                        break;
                    case 'wppa_i_source':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_keep_source_admin', 'yes');
                            wppa_update_option('wppa_keep_source_frontend', 'yes');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_keep_source_admin', 'no');
                            wppa_update_option('wppa_keep_source_frontend', 'no');
                        }
                        break;
                    case 'wppa_i_userupload':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_user_upload_on', 'yes');
                            wppa_update_option('wppa_user_upload_login', 'yes');
                            wppa_update_option('wppa_owner_only', 'yes');
                            wppa_update_option('wppa_upload_moderate', 'yes');
                            wppa_update_option('wppa_upload_edit', 'yes');
                            wppa_update_option('wppa_upload_notify', 'yes');
                            wppa_update_option('wppa_grant_an_album', 'yes');
                            $grantparent = wppa_opt('grant_parent');
                            if (!wppa_album_exists($grantparent)) {
                                $id = wppa_create_album_entry(array('name' => __('Members', 'wp-photo-album-plus'), 'description' => __('Parent of the member albums', 'wp-photo-album-plus'), 'a_parent' => '-1', 'upload_limit' => '0/0'));
                                if ($id) {
                                    wppa_index_add('album', $id);
                                    wppa_update_option('wppa_grant_parent', $id);
                                }
                                $my_post = array('post_title' => __('Members', 'wp-photo-album-plus'), 'post_content' => '[wppa type="content" album="' . $id . '"][/wppa]', 'post_status' => 'publish', 'post_type' => 'page');
                                $pagid = wp_insert_post($my_post);
                            }
                            wppa_update_option('wppa_alt_is_restricted', 'yes');
                            wppa_update_option('wppa_link_is_restricted', 'yes');
                            wppa_update_option('wppa_covertype_is_restricted', 'yes');
                            wppa_update_option('wppa_porder_restricted', 'yes');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_user_upload_on', 'no');
                        }
                        break;
                    case 'wppa_i_rating':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_rating_on', 'yes');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_rating_on', 'no');
                        }
                        break;
                    case 'wppa_i_comment':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_show_comments', 'yes');
                            wppa_update_option('wppa_comment_moderation', 'all');
                            wppa_update_option('wppa_comment_notify', 'admin');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_show_comments', 'no');
                        }
                        break;
                    case 'wppa_i_share':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_share_on', 'yes');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_share_on', 'no');
                        }
                        break;
                    case 'wppa_i_iptc':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_show_iptc', 'yes');
                            wppa_update_option('wppa_save_iptc', 'yes');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_show_iptc', 'no');
                            wppa_update_option('wppa_save_iptc', 'no');
                        }
                        break;
                    case 'wppa_i_exif':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_show_exif', 'yes');
                            wppa_update_option('wppa_save_exif', 'yes');
                        }
                        if ($value == 'no') {
                            wppa_update_option('wppa_show_exif', 'no');
                            wppa_update_option('wppa_save_exif', 'no');
                        }
                        break;
                    case 'wppa_i_gpx':
                        if ($value == 'yes') {
                            $custom_content = wppa_opt('custom_content');
                            if (strpos($custom_content, 'w#location') === false) {
                                $custom_content = $custom_content . ' w#location';
                                wppa_update_option('wppa_custom_content', $custom_content);
                            }
                            if (!wppa_switch('custom_on')) {
                                wppa_update_option('wppa_custom_on', 'yes');
                            }
                            if (wppa_opt('gpx_implementation') == 'none') {
                                wppa_update_option('wppa_gpx_implementation', 'wppa-plus-embedded');
                            }
                        }
                        break;
                    case 'wppa_i_fotomoto':
                        if ($value == 'yes') {
                            $custom_content = wppa_opt('custom_content');
                            if (strpos($custom_content, 'w#fotomoto') === false) {
                                $custom_content = 'w#fotomoto ' . $custom_content;
                                wppa_update_option('wppa_custom_content', $custom_content);
                            }
                            if (!wppa_switch('custom_on')) {
                                wppa_update_option('wppa_custom_on', 'yes');
                            }
                            wppa_update_option('wppa_fotomoto_on', 'yes');
                            wppa_update_option('wppa_custom_on', 'yes');
                        }
                        break;
                    case 'wppa_i_video':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_enable_video', 'yes');
                        } else {
                            wppa_update_option('wppa_enable_video', 'no');
                        }
                        break;
                    case 'wppa_i_audio':
                        if ($value == 'yes') {
                            wppa_update_option('wppa_enable_audio', 'yes');
                        } else {
                            wppa_update_option('wppa_enable_audio', 'no');
                        }
                        break;
                    case 'wppa_i_done':
                        $value = 'done';
                        break;
                    case 'wppa_search_tags':
                    case 'wppa_search_cats':
                    case 'wppa_search_comments':
                        update_option('wppa_index_need_remake', 'yes');
                        break;
                    case 'wppa_blacklist_user':
                        // Does user exist?
                        $value = trim($value);
                        $user = get_user_by('login', $value);
                        // seems to be case insensitive
                        if ($user && $user->user_login === $value) {
                            $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `status` = 'pending' WHERE `owner` = %s", $value));
                            $black_listed_users = get_option('wppa_black_listed_users', array());
                            if (!in_array($value, $black_listed_users)) {
                                $black_listed_users[] = $value;
                                update_option('wppa_black_listed_users', $black_listed_users);
                            }
                            $alert = esc_js(sprintf(__('User %s has been blacklisted.', 'wp-photo-album-plus'), $value));
                        } else {
                            $alert = esc_js(sprintf(__('User %s does not exist.', 'wp-photo-album-plus'), $value));
                        }
                        $value = '';
                        break;
                    case 'wppa_un_blacklist_user':
                        $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_PHOTOS . "` SET `status` = 'publish' WHERE `owner` = %s", $value));
                        $black_listed_users = get_option('wppa_black_listed_users', array());
                        if (in_array($value, $black_listed_users)) {
                            foreach (array_keys($black_listed_users) as $usr) {
                                if ($black_listed_users[$usr] == $value) {
                                    unset($black_listed_users[$usr]);
                                }
                            }
                            update_option('wppa_black_listed_users', $black_listed_users);
                        }
                        $value = '0';
                        break;
                    case 'wppa_fotomoto_on':
                        if ($value == 'yes') {
                            $custom_content = wppa_opt('custom_content');
                            if (strpos($custom_content, 'w#fotomoto') === false) {
                                $custom_content = 'w#fotomoto ' . $custom_content;
                                wppa_update_option('wppa_custom_content', $custom_content);
                                $alert = __('The content of the Custom box has been changed to display the Fotomoto toolbar.', 'wp-photo-album-plus') . ' ';
                            }
                            if (!wppa_switch('custom_on')) {
                                wppa_update_option('wppa_custom_on', 'yes');
                                $alert .= __('The display of the custom box has been enabled', 'wp-photo-album-plus');
                            }
                        }
                        break;
                    case 'wppa_gpx_implementation':
                        if ($value != 'none') {
                            $custom_content = wppa_opt('custom_content');
                            if (strpos($custom_content, 'w#location') === false) {
                                $custom_content = $custom_content . ' w#location';
                                wppa_update_option('wppa_custom_content', $custom_content);
                                $alert = __('The content of the Custom box has been changed to display maps.', 'wp-photo-album-plus') . ' ';
                            }
                            if (!wppa_switch('custom_on')) {
                                wppa_update_option('wppa_custom_on', 'yes');
                                $alert .= __('The display of the custom box has been enabled', 'wp-photo-album-plus');
                            }
                        }
                        break;
                    case 'wppa_regen_thumbs_skip_one':
                        $last = get_option('wppa_regen_thumbs_last', '0');
                        $skip = $last + '1';
                        update_option('wppa_regen_thumbs_last', $skip);
                        break;
                    case 'wppa_remake_skip_one':
                        $last = get_option('wppa_remake_last', '0');
                        $skip = $last + '1';
                        update_option('wppa_remake_last', $skip);
                        break;
                    case 'wppa_errorlog_purge':
                        @unlink(WPPA_CONTENT_PATH . '/wppa-depot/admin/error.log');
                        break;
                    case 'wppa_pl_dirname':
                        $value = wppa_sanitize_file_name($value);
                        $value = trim($value, ' /');
                        if (!$value) {
                            wppa('error', '714');
                            wppa_out(__('This value can not be empty', 'wp-photo-album-plus'));
                        } else {
                            wppa_create_pl_htaccess($value);
                        }
                        break;
                    case 'wppa_new_tag_value':
                        $value = wppa_sanitize_tags($value, false, true);
                        break;
                    case 'wppa_up_tagselbox_content_1':
                    case 'wppa_up_tagselbox_content_2':
                    case 'wppa_up_tagselbox_content_3':
                        $value = wppa_sanitize_tags($value);
                        break;
                    case 'wppa_wppa_set_shortcodes':
                        $value = str_replace(' ', '', $value);
                        break;
                    case 'wppa_enable_video':
                        // if off: set all statusses of videos to pending
                        break;
                    default:
                        wppa('error', '0');
                        $alert = '';
                }
            }
            if (wppa('error')) {
                if (!$title) {
                    $title = sprintf(__('Failed to set %s to %s', 'wp-photo-album-plus'), $option, $value);
                }
                if (!$alert) {
                    $alert .= wppa('out');
                }
            } else {
                wppa_update_option($option, $value);
                if (!$title) {
                    $title = sprintf(__('Setting %s updated to %s', 'wp-photo-album-plus'), $option, $value);
                }
            }
            // Save possible error
            $error = wppa('error');
            // Something to do after changing the setting?
            wppa_initialize_runtime(true);
            // force reload new values
            // .htaccess
            wppa_create_wppa_htaccess();
            // Thumbsize
            $new_minisize = wppa_get_minisize();
            if ($old_minisize != $new_minisize) {
                update_option('wppa_regen_thumbs_status', 'Required');
                $alert .= __('You just changed a setting that requires the regeneration of thumbnails.', 'wp-photo-album-plus');
                $alert .= ' ' . __('Please run the appropriate action in Table VIII.', 'wp-photo-album-plus');
            }
            // Produce the response text
            $output = '||' . $error . '||' . esc_attr($title) . '||' . esc_js($alert);
            echo $output;
            wppa_clear_cache();
            wppa_exit();
            break;
            // End update-option
        // End update-option
        case 'maintenance':
            $slug = $_POST['slug'];
            $nonce = $_REQUEST['wppa-nonce'];
            if (!wp_verify_nonce($nonce, 'wppa-nonce')) {
                echo 'Security check failure||' . $slug . '||Error||0';
                wppa_exit();
            }
            echo wppa_do_maintenance_proc($slug);
            wppa_exit();
            break;
        case 'maintenancepopup':
            $slug = $_POST['slug'];
            $nonce = $_REQUEST['wppa-nonce'];
            if (!wp_verify_nonce($nonce, 'wppa-nonce')) {
                echo 'Security check failure||' . $slug . '||Error||0';
                wppa_exit();
            }
            echo wppa_do_maintenance_popup($slug);
            wppa_exit();
            break;
        case 'do-fe-upload':
            if (is_admin()) {
                require_once 'wppa-non-admin.php';
            }
            wppa_user_upload();
            echo wppa('out');
            wppa_exit();
            break;
        case 'sanitizetags':
            $tags = isset($_GET['tags']) ? $_GET['tags'] : '';
            $album = isset($_GET['album']) ? $_GET['album'] : '0';
            $deftags = $album ? wppa_get_album_item($album, 'default_tags') : '';
            $tags = $deftags ? $tags . ',' . $deftags : $tags;
            echo wppa_sanitize_tags($tags, false, true);
            wppa_exit();
            break;
        case 'destroyalbum':
            $album = isset($_GET['album']) ? $_GET['album'] : '0';
            if (!$album) {
                _e('Missing album id', 'wp-photo-album-plus');
                wppa_exit();
            }
            $nonce = isset($_GET['nonce']) ? $_GET['nonce'] : '';
            if (!$nonce || !wp_verify_nonce($nonce, 'wppa_nonce_' . $album)) {
                echo 'Security check failure #798';
                wppa_exit();
            }
            // May I?
            $imay = true;
            if (!wppa_switch('user_destroy_on')) {
                $may = false;
            }
            if (wppa_switch('user_create_login')) {
                if (!is_user_logged_in()) {
                    $may = false;
                }
                // Must login
            }
            if (!wppa_have_access($album)) {
                $may = false;
                // No album access
            }
            if (wppa_is_user_blacklisted()) {
                $may = false;
            }
            if (!$imay) {
                _e('You do not have the rights to delete this album', 'wp-photo-album-plus');
                wppa_exit();
            }
            // I may
            require_once 'wppa-album-admin-autosave.php';
            wppa_del_album($album, '');
            wppa_exit();
            break;
        default:
            // Unimplemented $wppa-action
            die('-1');
    }
    wppa_exit();
}
function wppa_make_the_photo_files($file, $id, $ext)
{
    global $wpdb;
    $thumb = wppa_cache_thumb($id);
    $src_size = @getimagesize($file, $info);
    // If the given file is not an image file, log error and exit
    if (!$src_size) {
        if (is_admin()) {
            wppa_error_message(sprintf(__('ERROR: File %s is not a valid picture file.', 'wp-photo-album-plus'), $file));
        } else {
            wppa_alert(sprintf(__('ERROR: File %s is not a valid picture file.', 'wp-photo-album-plus'), $file));
        }
        return false;
    }
    // Find output path photo file
    $newimage = wppa_get_photo_path($id);
    if ($ext) {
        $newimage = wppa_strip_ext($newimage) . '.' . strtolower($ext);
    }
    // If Resize on upload is checked
    if (wppa_switch('resize_on_upload')) {
        // Picture sizes
        $src_width = $src_size[0];
        // Temp convert to logical width if stereo
        if ($thumb['stereo']) {
            $src_width /= 2;
        }
        $src_height = $src_size[1];
        // Max sizes
        if (wppa_opt('resize_to') == '0') {
            // from fullsize
            $max_width = wppa_opt('fullsize');
            $max_height = wppa_opt('maxheight');
        } else {
            // from selection
            $screen = explode('x', wppa_opt('resize_to'));
            $max_width = $screen[0];
            $max_height = $screen[1];
        }
        // If orientation needs +/- 90 deg rotation, swap max x and max y
        $ori = wppa_get_exif_orientation($file);
        if ($ori >= 5 && $ori <= 8) {
            $t = $max_width;
            $max_width = $max_height;
            $max_height = $t;
        }
        // Is source more landscape or more portrait than max window
        if ($src_width / $src_height > $max_width / $max_height) {
            // focus on width
            $focus = 'W';
            $need_downsize = $src_width > $max_width;
        } else {
            // focus on height
            $focus = 'H';
            $need_downsize = $src_height > $max_height;
        }
        // Convert back to physical size
        if ($thumb['stereo']) {
            $src_width *= 2;
        }
        // Downsize required ?
        if ($need_downsize) {
            // Find mime type
            $mime = $src_size[2];
            // Create the source image
            switch ($mime) {
                // mime type
                case 1:
                    // gif
                    $temp = @imagecreatefromgif($file);
                    if ($temp) {
                        $src = imagecreatetruecolor($src_width, $src_height);
                        imagecopy($src, $temp, 0, 0, 0, 0, $src_width, $src_height);
                        imagedestroy($temp);
                    } else {
                        $src = false;
                    }
                    break;
                case 2:
                    // jpeg
                    if (!function_exists('wppa_imagecreatefromjpeg')) {
                        wppa_log('Error', 'Function wppa_imagecreatefromjpeg does not exist.');
                    }
                    $src = @wppa_imagecreatefromjpeg($file);
                    break;
                case 3:
                    // png
                    $src = @imagecreatefrompng($file);
                    break;
            }
            if (!$src) {
                wppa_log('Error', 'Image file ' . $file . ' is corrupt while downsizing photo');
                return false;
            }
            // Create the ( empty ) destination image
            if ($focus == 'W') {
                if ($thumb['stereo']) {
                    $max_width *= 2;
                }
                $dst_width = $max_width;
                $dst_height = round($max_width * $src_height / $src_width);
            } else {
                $dst_height = $max_height;
                $dst_width = round($max_height * $src_width / $src_height);
            }
            $dst = imagecreatetruecolor($dst_width, $dst_height);
            // If Png, save transparancy
            if ($mime == 3) {
                imagealphablending($dst, false);
                imagesavealpha($dst, true);
            }
            // Do the copy
            imagecopyresampled($dst, $src, 0, 0, 0, 0, $dst_width, $dst_height, $src_width, $src_height);
            // Remove source image
            imagedestroy($src);
            // Save the photo
            switch ($mime) {
                // mime type
                case 1:
                    imagegif($dst, $newimage);
                    break;
                case 2:
                    imagejpeg($dst, $newimage, wppa_opt('jpeg_quality'));
                    break;
                case 3:
                    imagepng($dst, $newimage, 6);
                    break;
            }
            // Remove destination image
            imagedestroy($dst);
        } else {
            // No downsize needed, picture is small enough
            copy($file, $newimage);
        }
    } else {
        copy($file, $newimage);
    }
    // File successfully created ?
    if (is_file($newimage)) {
        // Make sure file is accessable
        wppa_chmod($newimage);
        // Optimize file
        wppa_optimize_image_file($newimage);
    } else {
        if (is_admin()) {
            wppa_error_message(__('ERROR: Resized or copied image could not be created.', 'wp-photo-album-plus'));
        } else {
            wppa_alert(__('ERROR: Resized or copied image could not be created.', 'wp-photo-album-plus'));
        }
        return false;
    }
    // Process the iptc data
    wppa_import_iptc($id, $info);
    // Process the exif data
    wppa_import_exif($id, $file);
    // GPS
    wppa_get_coordinates($file, $id);
    // Set ( update ) exif date-time if available
    $exdt = wppa_get_exif_datetime($file);
    if ($exdt) {
        wppa_update_photo(array('id' => $id, 'exifdtm' => $exdt));
    }
    // Check orientation
    wppa_orientate_image($id, wppa_get_exif_orientation($file));
    // Compute and save sizes
    wppa_get_photox($id, 'force');
    // Show progression
    if (is_admin() && !wppa('ajax')) {
        echo '.';
    }
    // Update CDN
    $cdn = wppa_cdn('admin');
    if ($cdn) {
        switch ($cdn) {
            case 'cloudinary':
                wppa_upload_to_cloudinary($id);
                break;
            default:
                wppa_dbg_msg('Missing upload instructions for ' . $cdn, 'red', 'force');
        }
    }
    // Create stereo images
    wppa_create_stereo_images($id);
    // Create thumbnail...
    wppa_create_thumbnail($id);
    // Clear (super)cache
    wppa_clear_cache();
    return true;
}
Exemplo n.º 27
0
function wppa_bestof_html($args, $widget = true)
{
    // Copletify args
    $args = wp_parse_args((array) $args, array('page' => '0', 'count' => '1', 'sortby' => 'maxratingcount', 'display' => 'photo', 'period' => 'thisweek', 'maxratings' => 'yes', 'meanrat' => 'yes', 'ratcount' => 'yes', 'linktype' => 'none', 'size' => wppa_opt('widget_width'), 'fontsize' => wppa_opt('fontsize_widget_thumb'), 'lineheight' => wppa_opt('fontsize_widget_thumb') * 1.5, 'height' => '200'));
    // Make args into seperate vars
    extract($args);
    // Validate args
    if (!in_array($sortby, array('maxratingcount', 'meanrating', 'ratingcount'))) {
        wppa_dbg_msg('Invalid arg sortby "' . $sortby . '" must be "maxratingcount", "meanrating" or "ratingcount"', 'red', 'force');
    }
    if (!in_array($display, array('photo', 'owner'))) {
        wppa_dbg_msg('Invalid arg display "' . $display . '" must be "photo" or "owner"', 'red', 'force');
    }
    if (!in_array($period, array('lastweek', 'thisweek', 'lastmonth', 'thismonth', 'lastyear', 'thisyear'))) {
        wppa_dbg_msg('Invalid arg period "' . $period . '" must be "lastweek", "thisweek", "lastmonth", "thismonth", "lastyear" or "thisyear"', 'red', 'force');
    }
    if (!$widget) {
        $size = $height;
    }
    $result = '';
    $data = wppa_get_the_bestof($count, $period, $sortby, $display);
    if ($display == 'photo') {
        if (is_array($data)) {
            foreach (array_keys($data) as $id) {
                $thumb = wppa_cache_thumb($id);
                if ($thumb) {
                    $imgsize = array(wppa_get_photox($id), wppa_get_photoy($id));
                    if ($widget) {
                        $maxw = $size;
                        $maxh = round($maxw * $imgsize['1'] / $imgsize['0']);
                    } else {
                        $maxh = $size;
                        $maxw = round($maxh * $imgsize['0'] / $imgsize['1']);
                    }
                    $totalh = $maxh + $lineheight;
                    if ($maxratings == 'yes') {
                        $totalh += $lineheight;
                    }
                    if ($meanrat == 'yes') {
                        $totalh += $lineheight;
                    }
                    if ($ratcount == 'yes') {
                        $totalh += $lineheight;
                    }
                    if ($widget) {
                        $clear = 'clear:both; ';
                    } else {
                        $clear = '';
                    }
                    $result .= "\n" . '<div' . ' class="wppa-widget"' . ' style="' . $clear . 'width:' . $maxw . 'px; height:' . $totalh . 'px; margin:4px; display:inline; text-align:center; float:left;"' . ' >';
                    // The medal if at the top
                    $result .= wppa_get_medal_html_a(array('id' => $id, 'size' => 'M', 'where' => 'top'));
                    // The link if any
                    if ($linktype != 'none') {
                        switch ($linktype) {
                            case 'owneralbums':
                                $href = wppa_get_permalink($page) . 'wppa-cover=1&amp;wppa-owner=' . $thumb['owner'] . '&amp;wppa-occur=1';
                                $title = __('See the authors albums', 'wp-photo-album-plus');
                                break;
                            case 'ownerphotos':
                                $href = wppa_get_permalink($page) . 'wppa-cover=0&amp;wppa-owner=' . $thumb['owner'] . '&photos-only&amp;wppa-occur=1';
                                $title = __('See the authors photos', 'wp-photo-album-plus');
                                break;
                            case 'upldrphotos':
                                $href = wppa_get_permalink($page) . 'wppa-cover=0&amp;wppa-upldr=' . $thumb['owner'] . '&amp;wppa-occur=1';
                                $title = __('See all the authors photos', 'wp-photo-album-plus');
                                break;
                        }
                        $result .= '<a href="' . wppa_convert_to_pretty($href) . '" title="' . $title . '" >';
                    }
                    // The image
                    $result .= '<img' . ' style="height:' . $maxh . 'px; width:' . $maxw . 'px;"' . ' src="' . wppa_fix_poster_ext(wppa_get_photo_url($id, '', $maxw, $maxh), $id) . '"' . ' ' . wppa_get_imgalt($id) . ' />';
                    // The /link
                    if ($linktype != 'none') {
                        $result .= '</a>';
                    }
                    // The medal if near the bottom
                    $result .= wppa_get_medal_html_a(array('id' => $id, 'size' => 'M', 'where' => 'bot'));
                    // The subtitles
                    $result .= "\n\t" . '<div style="font-size:' . $fontsize . 'px; line-height:' . $lineheight . 'px; position:absolute; width:' . $maxw . 'px; ">';
                    $result .= sprintf(__('Photo by: %s', 'wp-photo-album-plus'), $data[$id]['user']) . '<br />';
                    if ($maxratings == 'yes') {
                        $n = $data[$id]['maxratingcount'];
                        $result .= sprintf(_n('%d max rating', '%d max ratings', $n, 'wp-photo-album-plus'), $n) . '<br />';
                    }
                    if ($ratcount == 'yes') {
                        $n = $data[$id]['ratingcount'];
                        $result .= sprintf(_n('%d vote', '%d votes', 'wp-photo-album-plus'), $n) . '<br />';
                    }
                    if ($meanrat == 'yes') {
                        $m = $data[$id]['meanrating'];
                        $result .= sprintf(__('Rating: %4.2f.', 'wp-photo-album-plus'), $m) . '<br />';
                    }
                    $result .= '</div>';
                    $result .= '<div style="clear:both" ></div>';
                    $result .= "\n" . '</div>';
                } else {
                    // No image
                    $result .= '<div>' . sprintf(__('Photo %s not found.', 'wp-photo-album-plus'), $id) . '</div>';
                }
            }
        } else {
            $result .= $data;
            // No array, print message
        }
    } else {
        // Display = owner
        if (is_array($data)) {
            $result .= '<ul>';
            foreach (array_keys($data) as $author) {
                $result .= '<li>';
                // The link if any
                if ($linktype != 'none') {
                    switch ($linktype) {
                        case 'owneralbums':
                            $href = wppa_get_permalink($page) . 'wppa-cover=1&amp;wppa-owner=' . $data[$author]['owner'] . '&amp;wppa-occur=1';
                            $title = __('See the authors albums', 'wp-photo-album-plus');
                            break;
                        case 'ownerphotos':
                            $href = wppa_get_permalink($page) . 'wppa-cover=0&amp;wppa-owner=' . $data[$author]['owner'] . '&amp;photos-only&amp;wppa-occur=1';
                            $title = __('See the authors photos', 'wp-photo-album-plus');
                            break;
                        case 'upldrphotos':
                            $href = wppa_get_permalink($page) . 'wppa-cover=0&amp;wppa-upldr=' . $data[$author]['owner'] . '&amp;wppa-occur=1';
                            $title = __('See all the authors photos', 'wp-photo-album-plus');
                            break;
                    }
                    $result .= '<a href="' . $href . '" title="' . $title . '" >';
                }
                // The name
                $result .= $author;
                // The /link
                if ($linktype != 'none') {
                    $result .= '</a>';
                }
                $result .= '<br/>';
                // The subtitles
                $result .= "\n" . '<div style="font-size:' . wppa_opt('fontsize_widget_thumb') . 'px; line-height:' . $lineheight . 'px; ">';
                if ($maxratings == 'yes') {
                    $n = $data[$author]['maxratingcount'];
                    $result .= sprintf(_n('%d max rating', '%d max ratings', $n, 'wp-photo-album-plus'), $n) . '<br />';
                }
                if ($ratcount == 'yes') {
                    $n = $data[$author]['ratingcount'];
                    $result .= sprintf(_n('%d vote', '%d votes', 'wp-photo-album-plus'), $n) . '<br />';
                }
                if ($meanrat == 'yes') {
                    $m = $data[$author]['meanrating'];
                    $result .= sprintf(__('Mean value: %4.2f.', 'wp-photo-album-plus'), $m) . '<br />';
                }
                $result .= '</div>';
                $result .= '</li>';
            }
            $result .= '</ul>';
        } else {
            $result .= $data;
            // No array, print message
        }
    }
    return $result;
}
Exemplo n.º 28
0
function wppa_add_metatags()
{
    global $wpdb;
    global $thumb;
    // Share info for sm that uses og
    $id = wppa_get_get('photo');
    if ($id) {
        $imgurl = wppa_get_photo_url($id);
        if (wppa_is_video($id)) {
            $imgurl = wppa_fix_poster_ext($imgurl, $id);
        }
    } else {
        $imgurl = '';
    }
    if ($id) {
        if (wppa_switch('wppa_og_tags_on')) {
            wppa_cache_thumb($id);
            if ($thumb) {
                $title = wppa_get_photo_name($id);
                $desc = wppa_get_og_desc($id);
                $url = (is_ssl() ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
                $site = get_bloginfo('name');
                echo '
<!-- WPPA+ Share data -->
<meta property="og:site_name" content="' . esc_attr(sanitize_text_field($site)) . '" />
<meta property="og:type" content="article" />
<meta property="og:url" content="' . esc_url(sanitize_text_field($url)) . '" />
<meta property="og:title" content="' . esc_attr(sanitize_text_field($title)) . '" />
<meta property="og:image" content="' . esc_url(sanitize_text_field($imgurl)) . '" />
<meta property="og:description" content="' . esc_attr(sanitize_text_field($desc)) . '" />
<!-- WPPA+ End Share data -->
';
            }
        }
    }
    // To make sure we are on a page that contains at least %%wppa%% we check for Get var 'wppa-album'.
    // This also narrows the selection of featured photos to those that exist in the current album.
    $done = array();
    if (wppa_get_get('album')) {
        if (wppa_switch('wppa_meta_page')) {
            $album = wppa_get_get('album');
            $photos = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s AND `status` = 'featured'", $album), ARRAY_A);
            wppa_dbg_q('Q-meta1');
            wppa_cache_photo('add', $photos);
            if ($photos) {
                echo "\n<!-- WPPA+ BEGIN Featured photos on this page -->";
                foreach ($photos as $photo) {
                    $thumb = $photo;
                    // Set to global to reduce queries when getting the name
                    $id = $photo['id'];
                    $content = esc_attr(sanitize_text_field(wppa_get_keywords($id)));
                    if ($content && !in_array($content, $done)) {
                        echo '
<meta name="keywords" content="' . $content . '" >';
                        $done[] = $content;
                    }
                }
                echo "\n<!-- WPPA+ END Featured photos on this page -->\n";
            }
        }
    } elseif (wppa_switch('wppa_meta_all')) {
        $photos = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` = 'featured'", ARRAY_A);
        wppa_dbg_q('Q-meta2');
        wppa_cache_photo('add', $photos);
        if ($photos) {
            echo "\n<!-- WPPA+ BEGIN Featured photos on this site -->";
            foreach ($photos as $photo) {
                $thumb = $photo;
                // Set to global to reduce queries when getting the name
                $id = $photo['id'];
                $content = esc_attr(sanitize_text_field(wppa_get_keywords($id)));
                if ($content && !in_array($content, $done)) {
                    echo '
<meta name="keywords" content="' . $content . '" >';
                    $done[] = $content;
                }
            }
            echo "\n<!-- WPPA+ END Featured photos on this site -->\n";
        }
    }
    // Facebook Admin and App
    if ((wppa_switch('wppa_share_on') || wppa_switch('wppa_share_on_widget')) && (wppa_switch('wppa_facebook_comments') || wppa_switch('wppa_facebook_like') || wppa_switch('wppa_share_facebook'))) {
        echo "\n<!-- WPPA+ BEGIN Facebook meta tags -->";
        if (wppa_opt('wppa_facebook_admin_id')) {
            echo "\n\t<meta property=\"fb:admins\" content=\"" . wppa_opt('wppa_facebook_admin_id') . "\" />";
        }
        if (wppa_opt('wppa_facebook_app_id')) {
            echo "\n\t<meta property=\"fb:app_id\" content=\"" . wppa_opt('wppa_facebook_app_id') . "\" />";
        }
        if ($imgurl) {
            echo '
<link rel="image_src" href="' . esc_url($imgurl) . '" />';
        }
        echo '
<!-- WPPA+ END Facebook meta tags -->
';
    }
}
function wppa_too_old_for_cloud($id)
{
    $thumb = wppa_cache_thumb($id);
    $is_old = wppa_cdn('admin') && wppa_opt('max_cloud_life') && time() > $thumb['timestamp'] + wppa_opt('max_cloud_life');
    return $is_old;
}