/** @see WP_Widget::widget */ function widget($args, $instance) { global $widget_content; 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', 'tagcloud'); wppa_bump_mocc(); extract($args); $instance = wp_parse_args((array) $instance, array('title' => __('Photo Tags', 'wp-photo-album-plus'), 'tags' => array())); if (empty($instance['tags'])) { $instance['tags'] = array(); } $widget_title = apply_filters('widget_title', $instance['title']); // Display the widget echo $before_widget; if (!empty($widget_title)) { echo $before_title . $widget_title . $after_title; } echo '<div class="wppa-tagcloud-widget" >' . wppa_get_tagcloud_html(implode(',', $instance['tags']), wppa_opt('tagcloud_min'), wppa_opt('tagcloud_max')) . '</div>'; echo '<div style="clear:both"></div>'; echo $after_widget; wppa('in_widget', false); }
function wppa_add_admin() { global $wp_roles; global $wpdb; // Make sure admin has access rights if (wppa_user_is('administrator')) { $wp_roles->add_cap('administrator', 'wppa_admin'); $wp_roles->add_cap('administrator', 'wppa_upload'); $wp_roles->add_cap('administrator', 'wppa_import'); $wp_roles->add_cap('administrator', 'wppa_moderate'); $wp_roles->add_cap('administrator', 'wppa_export'); $wp_roles->add_cap('administrator', 'wppa_settings'); $wp_roles->add_cap('administrator', 'wppa_potd'); $wp_roles->add_cap('administrator', 'wppa_comments'); $wp_roles->add_cap('administrator', 'wppa_help'); } // See if there are comments pending moderation $com_pending = ''; $com_pending_count = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "` WHERE `status` = 'pending' OR `status` = 'spam'"); if ($com_pending_count) { $com_pending = '<span class="update-plugins"><span class="plugin-count">' . $com_pending_count . '</span></span>'; } // See if there are uploads pending moderation $upl_pending = ''; $upl_pending_count = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `status` = 'pending'"); if ($upl_pending_count) { $upl_pending = '<span class="update-plugins"><span class="plugin-count">' . $upl_pending_count . '</span></span>'; } // Compute total pending moderation $tot_pending = ''; $tot_pending_count = '0'; if (current_user_can('wppa_comments') || current_user_can('wppa_moderate')) { $tot_pending_count += $com_pending_count; } if (current_user_can('wppa_admin') || current_user_can('wppa_moderate')) { $tot_pending_count += $upl_pending_count; } if ($tot_pending_count) { $tot_pending = '<span class="update-plugins"><span class="plugin-count">' . '<b>' . $tot_pending_count . '</b>' . '</span></span>'; } $icon_url = WPPA_URL . '/img/camera16.png'; // page_title menu_title capability menu_slug function icon_url position add_menu_page('WP Photo Album', __('Photo Albums', 'wp-photo-album-plus') . $tot_pending, 'wppa_admin', 'wppa_admin_menu', 'wppa_admin', $icon_url); //,'10' ); // parent_slug page_title menu_title capability menu_slug function add_submenu_page('wppa_admin_menu', __('Album Admin', 'wp-photo-album-plus'), __('Album Admin', 'wp-photo-album-plus') . $upl_pending, 'wppa_admin', 'wppa_admin_menu', 'wppa_admin'); add_submenu_page('wppa_admin_menu', __('Upload Photos', 'wp-photo-album-plus'), __('Upload Photos', 'wp-photo-album-plus'), 'wppa_upload', 'wppa_upload_photos', 'wppa_page_upload'); // Uploader without album admin rights, but when the upload_edit switch set, may edit his own photos if (!current_user_can('wppa_admin') && wppa_opt('upload_edit') != 'none') { add_submenu_page('wppa_admin_menu', __('Edit Photos', 'wp-photo-album-plus'), __('Edit Photos', 'wp-photo-album-plus'), 'wppa_upload', 'wppa_edit_photo', 'wppa_edit_photo'); } add_submenu_page('wppa_admin_menu', __('Import Photos', 'wp-photo-album-plus'), __('Import Photos', 'wp-photo-album-plus'), 'wppa_import', 'wppa_import_photos', 'wppa_page_import'); add_submenu_page('wppa_admin_menu', __('Moderate Photos', 'wp-photo-album-plus'), __('Moderate Photos', 'wp-photo-album-plus') . $tot_pending, 'wppa_moderate', 'wppa_moderate_photos', 'wppa_page_moderate'); add_submenu_page('wppa_admin_menu', __('Export Photos', 'wp-photo-album-plus'), __('Export Photos', 'wp-photo-album-plus'), 'wppa_export', 'wppa_export_photos', 'wppa_page_export'); add_submenu_page('wppa_admin_menu', __('Settings', 'wp-photo-album-plus'), __('Settings', 'wp-photo-album-plus'), 'wppa_settings', 'wppa_options', 'wppa_page_options'); add_submenu_page('wppa_admin_menu', __('Photo of the day Widget', 'wp-photo-album-plus'), __('Photo of the day', 'wp-photo-album-plus'), 'wppa_potd', 'wppa_photo_of_the_day', 'wppa_sidebar_page_options'); add_submenu_page('wppa_admin_menu', __('Manage comments', 'wp-photo-album-plus'), __('Comments', 'wp-photo-album-plus') . $com_pending, 'wppa_comments', 'wppa_manage_comments', 'wppa_comment_admin'); add_submenu_page('wppa_admin_menu', __('Help & Info', 'wp-photo-album-plus'), __('Documentation', 'wp-photo-album-plus'), 'wppa_help', 'wppa_help', 'wppa_page_help'); }
/** @see WP_Widget::widget */ function widget($args, $instance) { global $wpdb; global $widget_content; 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(); extract($args); $title = apply_filters('widget_title', empty($instance['title']) ? __('QR Widget', 'wp-photo-album-plus') : $instance['title']); $qrsrc = 'http://api.qrserver.com/v1/create-qr-code/' . '?data=' . site_url() . '&size=' . wppa_opt('qr_size') . 'x' . wppa_opt('qr_size') . '&color=' . trim(wppa_opt('qr_color'), '#') . '&bgcolor=' . trim(wppa_opt('qr_bgcolor')); $widget_content = ' <div style="text-align:center;" ><img id="wppa-qr-img" src="' . $qrsrc . '" title="" alt="' . __('QR code', 'wp-photo-album-plus') . '" /></div> <div style="clear:both" ></div>'; $widget_content .= ' <script type="text/javascript"> /*[CDATA[*/ var wppaQRData = document.location.href; var wppaQRDataOld = ""; var wppaQRSrc = ""; var workData = ""; wppaConsoleLog( "doc.loc.href = " + wppaQRData ); function wppaQRUpdate( arg ) { if ( arg ) wppaQRData = arg; if ( wppaQRData != wppaQRDataOld ) { wppaQRDataOld = wppaQRData; workData = wppaQRData; wppaQRSrc = "http://api.qrserver.com/v1/create-qr-code/?data=" + encodeURIComponent( workData ) + "&size=' . wppa_opt('qr_size') . 'x' . wppa_opt('qr_size') . '&color=' . trim(wppa_opt('qr_color'), '#') . '&bgcolor=' . trim(wppa_opt('qr_bgcolor'), '#') . '"; document.getElementById( "wppa-qr-img" ).src = wppaQRSrc; document.getElementById( "wppa-qr-img" ).title = workData; } return; } jQuery(document).ready(function(){ wppaQRUpdate(); }); /*]]*/ </script>'; echo $before_widget . $before_title . $title . $after_title . $widget_content . $after_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(); extract($args); $instance = wp_parse_args((array) $instance, array('title' => '', 'album' => '0')); $title = apply_filters('widget_title', $instance['title']); $album = $instance['album']; if (!$wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_ALBUMS . "` WHERE `id` = %d", $album))) { $album = '0'; // Album vanished } wppa_user_upload(); // Do the upload if required wppa('in_widget', 'upload'); wppa_bump_mocc(); $mocc = wppa('mocc'); $is_responsive = wppa_opt('colwidth') == 'auto'; if ($is_responsive) { // Responsive widgetwppaAutoColumnWidth[1] = true; $js = wppa_get_responsive_widget_js_html($mocc); } else { $js = ''; } $create = wppa_get_user_create_html($album, wppa_opt('widget_width'), 'widget'); $upload = wppa_get_user_upload_html($album, wppa_opt('widget_width'), 'widget', $is_responsive); if (!$create && !$upload) { return; } // Nothing to do $text = '<div id="wppa-container-' . $mocc . '" class="wppa-upload-widget" style="margin-top:2px; margin-left:2px;" >' . $js . $create . $upload . '</div>'; echo $before_widget; if (!empty($title)) { echo $before_title . $title . $after_title; } echo $text; echo '<div style="clear:both"></div>'; echo $after_widget; wppa('in_widget', false); }
function wppa_create_pl_htaccess($pl_dirname = '') { global $wpdb; // Only supported on single sites at the moment if (is_multisite() && !WPPA_MULTISITE_GLOBAL) { return false; } // Where are the photo source files? $source_root = str_replace(ABSPATH, '', wppa_opt('wppa_source_dir')); // Find permalink root name if (!$pl_dirname) { $pl_dirname = wppa_opt('wppa_pl_dirname'); } // If no pl_dirname, feature is disabled if (!$pl_dirname) { return false; } // Create pl root directory $pl_root = WPPA_CONTENT_PATH . '/' . $pl_dirname; if (!wppa_mktree($pl_root)) { wppa_log('Error', 'Can not create ' . $pl_root); return false; } // Create .htaccess file $file = fopen($pl_root . '/.htaccess', 'wb'); if (!$file) { wppa_log('Error', 'Can not create ' . $pl_root . '/.htaccess'); return false; } fwrite($file, '<IfModule mod_rewrite.c>'); fwrite($file, "\n" . 'RewriteEngine On'); // RewriteBase /wp-content/wppa-pl fwrite($file, "\n" . 'RewriteBase /' . str_replace(ABSPATH, '', $pl_root)); $albs = $wpdb->get_results("SELECT `id`, `name` FROM `" . WPPA_ALBUMS . "` ORDER BY `name` DESC", ARRAY_A); if ($albs) { foreach ($albs as $alb) { $fm = wppa_sanitize_file_name($alb['name'], false); $to = $source_root . '/album-' . $alb['id']; fwrite($file, "\n" . 'RewriteRule ^' . $fm . '/(.*) /' . $to . '/$1 [NC]'); } } fwrite($file, "\n" . '</IfModule>'); fclose($file); return true; }
function wppa_save_source($file, $name, $alb) { $doit = true; // Frontend not enabled and not ajax ? if (!is_admin() && !wppa_switch('keep_source_frontend')) { $doit = false; } // Frontend not enabled and ajax ? if (isset($_REQUEST['wppa-action']) && $_REQUEST['wppa-action'] == 'do-fe-upload' && !wppa_switch('keep_source_frontend')) { $doit = false; } // Backend not enabled ? if ((!isset($_REQUEST['wppa-action']) || $_REQUEST['wppa-action'] != 'do-fe-upload') && is_admin() && !wppa_switch('keep_source_admin')) { $doit = false; } if ($doit) { if (!is_dir(wppa_opt('source_dir'))) { @wppa_mktree(wppa_opt('source_dir')); } $sourcedir = wppa_get_source_dir(); if (!is_dir($sourcedir)) { @wppa_mktree($sourcedir); } $albdir = wppa_get_source_album_dir($alb); if (!is_dir($albdir)) { @wppa_mktree($albdir); } if (!is_dir($albdir)) { wppa_log('Err', 'Could not create source directory ' . $albdir); } $dest = $albdir . '/' . wppa_sanitize_file_name($name); if ($file != $dest) { @copy($file, $dest); } // Do not copy to self, and do not bother on failure if (is_file($dest)) { wppa_chmod($dest); } else { wppa_log('Err', 'Could not save ' . $dest, true); } } }
/** @see WP_Widget::widget */ function widget($args, $instance) { global $wpdb; global $wppa; global $widget_content; global $thumb; 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'] = 'bestof'; $wppa['mocc']++; extract($args); $instance = wp_parse_args((array) $instance, array('title' => '', 'count' => '1', 'sortby' => 'maxratingcount', 'display' => 'photo', 'period' => 'thisweek', 'maxratings' => 'yes', 'meanrat' => 'yes', 'ratcount' => 'yes', 'linktype' => 'none')); $widget_title = apply_filters('widget_title', $instance['title']); $page = in_array($instance['linktype'], $wppa['links_no_page']) ? '' : wppa_get_the_landing_page('wppa_bestof_widget_linkpage', __a('Best Of Photos')); $count = $instance['count']; $sortby = $instance['sortby']; $display = $instance['display']; $period = $instance['period']; $maxratings = $instance['maxratings']; $meanrat = $instance['meanrat']; $ratcount = $instance['ratcount']; $linktype = $instance['linktype']; $size = wppa_opt('wppa_widget_width'); // $data = wppa_get_the_bestof( $count, $period, $sortby, $display ); $lineheight = wppa_opt('wppa_fontsize_widget_thumb') * 1.5; $widget_content = "\n" . '<!-- WPPA+ BestOf Widget start -->'; $widget_content .= wppa_bestof_html(array('page' => $page, 'count' => $count, 'sortby' => $sortby, 'display' => $display, 'period' => $period, 'maxratings' => $maxratings, 'meanrat' => $meanrat, 'ratcount' => $ratcount, 'linktype' => $linktype, 'size' => $size, 'lineheight' => $lineheight)); $widget_content .= '<div style="clear:both"></div>'; $widget_content .= "\n" . '<!-- WPPA+ BestOf Widget end -->'; echo "\n" . $before_widget; if (!empty($widget_title)) { echo $before_title . $widget_title . $after_title; } echo $widget_content . $after_widget; }
function do_album_navigator($parent, $page, $skip, $propclass, $extraclause = '') { global $wpdb; static $level; static $ca; if (!$level) { $level = '1'; if (isset($_REQUEST['wppa-album'])) { $ca = $_REQUEST['wppa-album']; } elseif (isset($_REQUEST['album'])) { $ca = $_REQUEST['album']; } else { $ca = '0'; } $ca = wppa_force_numeric_else($ca, '0'); if ($ca && !wppa_album_exists($ca)) { // wppa_log('dbg', 'Non-existent album '.$ca.' in url. Referrer= '.$_ENV["HTTP_REFERER"].', Request uri= '.$_ENV["REQUEST_URI"]); $ca = '0'; } } else { $level++; } $slide = wppa_opt('album_navigator_widget_linktype') == 'slide' ? '&wppa-slide=1' : ''; $w = $this->get_widget_id(); $p = $parent; $result = ''; $albums = $wpdb->get_results($wpdb->prepare("SELECT * FROM `" . WPPA_ALBUMS . "` WHERE `a_parent` = %s " . $extraclause . wppa_get_album_order(max('0', $parent)), $parent), ARRAY_A); if (!empty($albums)) { wppa_cache_album('add', $albums); $result .= '<ul>'; foreach ($albums as $album) { $a = $album['id']; $treecount = wppa_treecount_a($a); if ($treecount['albums'] || $treecount['photos'] > wppa_opt('min_thumbs') || $skip == 'no') { $result .= ' <li class="anw-' . $w . '-' . $p . $propclass . '" style="list-style:none; display:' . ($level == '1' ? '' : 'none') . ';">'; if (wppa_has_children($a)) { $result .= ' <div style="cursor:default;width:12px;float:left;text-align:center;font-weight:bold;" class="anw-' . $w . '-' . $a . '-" onclick="jQuery(\'.anw-' . $w . '-' . $a . '\').css(\'display\',\'\'); jQuery(\'.anw-' . $w . '-' . $a . '-\').css(\'display\',\'none\');" >' . ($a == $ca ? '»' : '+') . '</div> <div style="cursor:default;width:12px;float:left;text-align:center;font-weight:bold;display:none;" class="anw-' . $w . '-' . $a . '" onclick="jQuery(\'.anw-' . $w . '-' . $a . '-\').css(\'display\',\'\'); jQuery(\'.anw-' . $w . '-' . $a . '\').css(\'display\',\'none\'); jQuery(\'.p-' . $w . '-' . $a . '\').css(\'display\',\'none\');" >' . ($a == $ca ? '»' : '-') . '</div>'; } else { $result .= ' <div style="width:12px;float:left;" > ' . ($a == $ca ? '»' : '') . '</div>'; } $result .= ' <a href="' . wppa_encrypt_url(wppa_get_permalink($page) . '&wppa-album=' . $a . '&wppa-cover=0&wppa-occur=1' . $slide) . '">' . wppa_get_album_name($a) . '</a> </li>'; $newpropclass = $propclass . ' p-' . $w . '-' . $p; $result .= '<li class="anw-' . $w . '-' . $p . $propclass . '" style="list-style:none;" >' . $this->do_album_navigator($a, $page, $skip, $newpropclass, $extraclause) . '</li>'; } } $result .= '</ul>'; if ($level == '1' && $ca) { // && $parent != '-1' ) { $result .= '<script type="text/javascript" >'; while ($ca != '0' && $ca != '-1') { $result .= ' jQuery(\'.anw-' . $w . '-' . $ca . '\').css(\'display\',\'\'); jQuery(\'.anw-' . $w . '-' . $ca . '-\').css(\'display\',\'none\');'; $ca = wppa_get_parentalbumid($ca); } $result .= '</script>'; } } $level--; return str_replace('<ul></ul>', '', $result); }
function wppa_get_medal_html_a($args) { // Completize args $args = wp_parse_args((array) $args, array('id' => '0', 'size' => 'M', 'where' => '')); // Validate args if ($args['id'] == '0') { return ''; } // Missing required id if (!in_array($args['size'], array('S', 'M', 'L', 'XL'))) { return ''; } // Missing or not implemented size spec if (!in_array($args['where'], array('top', 'bot'))) { return ''; } // Missing or not implemented where // Do it here? if (strpos(wppa_opt('medal_position'), $args['where']) === false) { return ''; } // No // Get rquired photo and config data $id = $args['id']; $new = wppa_is_photo_new($id); $mod = wppa_is_photo_modified($id); $status = wppa_get_photo_item($id, 'status'); $medal = in_array($status, array('gold', 'silver', 'bronze')) ? $status : ''; // Have a medal to show? if (!$new && !$medal && !$mod) { return ''; // No } // Init local vars $result = ''; $color = wppa_opt('medal_color'); $left = strpos(wppa_opt('medal_position'), 'left') !== false; $ctop = strpos(wppa_opt('medal_position'), 'top') === false ? '-32' : '0'; $sizes = array('S' => '16', 'M' => '20', 'L' => '24', 'XL' => '32'); $nsizes = array('S' => '14', 'M' => '16', 'L' => '20', 'XL' => '24'); $fsizes = array('S' => '9', 'M' => '10', 'L' => '14', 'XL' => '20'); $smargs = array('S' => '4', 'M' => '5', 'L' => '6', 'XL' => '8'); $lmargs = array('S' => '22', 'M' => '28', 'L' => '36', 'XL' => '48'); $tops = array('S' => '8', 'M' => '8', 'L' => '6', 'XL' => '0'); $ntops = array('S' => '10', 'M' => '10', 'L' => '8', 'XL' => '0'); $titles = array('gold' => __('Gold medal', 'wp-photo-album-plus'), 'silver' => __('Silver medal', 'wp-photo-album-plus'), 'bronze' => __('Bronze medal', 'wp-photo-album-plus')); $size = $sizes[$args['size']]; $nsize = $nsizes[$args['size']]; $fsize = $fsizes[$args['size']]; $smarg = $smargs[$args['size']]; $lmarg = $lmargs[$args['size']]; $top = $tops[$args['size']]; $ntop = $ntops[$args['size']]; $title = $medal ? esc_attr($titles[$medal]) : ''; $sstyle = $left ? 'left:' . $smarg . 'px;' : 'right:' . $smarg . 'px;'; $lstyle = $left ? 'left:' . $lmarg . 'px;' : 'right:' . $lmarg . 'px;'; // The medal container $result .= '<div style="position:relative;top:' . $ctop . 'px;z-index:10;">'; // The medal if ($medal) { $result .= '<img' . ' src="' . WPPA_URL . '/images/medal_' . $medal . '_' . $color . '.png"' . ' title="' . $title . '"' . ' alt="' . $title . '"' . ' style="' . $sstyle . 'top:4px;' . 'position:absolute;' . 'border:none;' . 'margin:0;' . 'padding:0;' . 'box-shadow:none;' . 'height:' . $size . 'px;' . 'top:' . $top . 'px;' . '"' . ' />'; } // Is there a new or modified indicator to display? if ($new) { $type = 'new'; } elseif ($mod) { $type = 'mod'; } else { $type = ''; } // Style adjustment if only a new/modified without a real medal if (!$medal) { $lstyle = $sstyle; } $do_image = !wppa_switch('wppa_new_mod_label_is_text'); // Yes there is one to display if ($type) { if ($do_image) { $result .= '<img' . ' src="' . wppa_opt($type . '_label_url') . '"' . ' title="' . esc_attr(__('New', 'wp-photo-album-plus')) . '"' . ' alt="' . esc_attr(__('New', 'wp-photo-album-plus')) . '"' . ' class="wppa-thumbnew"' . ' style="' . $lstyle . 'top:' . $ntop . 'px;' . 'position:absolute;' . 'border:none;' . 'margin:0;' . 'padding:0;' . 'box-shadow:none;' . 'height:' . $nsize . 'px;' . '"' . ' />'; } else { $result .= '<div' . ' style="' . $lstyle . 'position:absolute;' . 'top:' . $ntop . 'px;' . 'box-sizing:border-box;' . 'float:' . ($left ? 'left;' : 'right;') . 'font-size:' . $fsize . 'px;' . 'line-height:' . $fsize . 'px;' . 'font-family:\'Arial Black\', Gadget, sans-serif;' . 'border-radius:2px;' . 'border-width:1px;' . 'border-style:solid;' . 'padding:1px;' . wppa_get_text_medal_color_style($type) . '"' . ' >' . ' ' . __(wppa_opt($type . '_label_text')) . ' ' . '</div>'; } } // Close container $result .= '</div>'; return $result; }
function _wppa_comment_admin() { global $wpdb; $continue = true; // Check input wppa_vfy_arg('tab', true); wppa_vfy_arg('edit_id'); wppa_vfy_arg('wppa-page'); wppa_vfy_arg('commentid'); wppa_vfy_arg('delete_id'); if (isset($_GET['tab'])) { if ($_GET['tab'] == 'edit') { $id = $_GET['edit_id']; $comment = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WPPA_COMMENTS . " WHERE id = %s LIMIT 1", $id), ARRAY_A); if ($comment) { ?> <div class="wrap"> <?php $iconurl = WPPA_URL . '/img/comment.png'; ?> <div id="icon-album" class="icon32" style="background: transparent url(<?php echo $iconurl; ?> ) no-repeat"> <br /> </div> <h2><?php _e('Photo Albums -> Edit Comment', 'wp-photo-album-plus'); ?> </h2> <?php $action = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_manage_comments'); if (isset($_GET['wppa-page'])) { $action .= '&compage=' . strval(intval($_GET['wppa-page'])); } if (isset($_GET['commentid'])) { $action .= '&commentid=' . strval(intval($_GET['commentid'])); } ?> <form action="<?php echo $action; ?> " method="post"> <?php wp_nonce_field('$wppa_nonce', WPPA_NONCE); ?> <input type="hidden" name="edit_comment" value="<?php echo $comment['id']; ?> " /> <table class="form-table albumtable"> <tbody> <tr style="vertical-align:top" > <th> <?php $photo = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WPPA_PHOTOS . " WHERE id = %s", $comment['photo']), "ARRAY_A"); ?> <?php $url = wppa_fix_poster_ext(wppa_get_thumb_url($comment['photo']), $comment['photo']); ?> <img src="<?php echo $url; ?> " /> </th> <td> <?php echo __($photo['name']) . '<br/><br/>' . __(stripslashes($photo['description'])); ?> </td> </tr> <tr> <th scope="row"><label ><?php _e('Photo:', 'wp-photo-album-plus'); ?> </label></th> <td><?php echo $comment['photo']; ?> </td> </tr> <tr> <th scope="row"><label ><?php _e('Album:', 'wp-photo-album-plus'); ?> </label></th> <td><?php echo wppa_get_album_name($photo['album']); ?> </td> </tr> <tr> <th scope="row"><label ><?php _e('User:'******'wp-photo-album-plus'); ?> </label></th> <td><input style="width:300px;" type="text" name="user" value="<?php echo $comment['user']; ?> " /></td> </tr> <tr> <th scope="row"><label ><?php _e('Email:', 'wp-photo-album-plus'); ?> </label></th> <td><input style="width:300px;" type="text" name="email" value="<?php echo $comment['email']; ?> " /></td> </tr> <tr> <th scope="row"><label><?php _e('Comment:', 'wp-photo-album-plus'); ?> </label></th> <td><textarea style="width:300px; height:150px;" name="comment"><?php echo esc_textarea(stripslashes($comment['comment'])); ?> </textarea></td> </tr> </tbody> </table> <p> <input type="submit" class="button-primary" name="wppa_submit" value="<?php _e('Save Changes', 'wp-photo-album-plus'); ?> " /> </p> </form> <?php } $continue = false; } if ($_GET['tab'] == 'delete') { $id = strval(intval($_GET['delete_id'])); $photo = $wpdb->get_var($wpdb->prepare("SELECT `photo` FROM `" . WPPA_COMMENTS . "` WHERE `id` = %s", $id)); $iret = $wpdb->query($wpdb->prepare("DELETE FROM `" . WPPA_COMMENTS . "` WHERE `id` = %s LIMIT 1", $id)); if ($iret !== false) { if (wppa_switch('search_comments')) { wppa_index_update('photo', $photo); } wppa_update_message(__('Comment deleted', 'wp-photo-album-plus')); } else { wppa_error_message('Error deleting comment'); } $continue = true; } } if ($continue) { // Update anything or do bulkaction if (isset($_POST['wppa_submit'])) { // Security check check_admin_referer('$wppa_nonce', WPPA_NONCE); // Updates $iret = true; if (isset($_POST['wppa_comadmin_show'])) { wppa_update_option('wppa_comadmin_show', $_POST['wppa_comadmin_show']); } if (isset($_POST['wppa_comadmin_linkpage'])) { wppa_update_option('wppa_comadmin_linkpage', $_POST['wppa_comadmin_linkpage']); } if (isset($_POST['wppa_comadmin_order'])) { wppa_update_option('wppa_comadmin_order', $_POST['wppa_comadmin_order']); } if (isset($_POST['edit_comment'])) { $iret = wppa_edit_comment($_POST['edit_comment']); } // Bulk actions if (isset($_POST['bulkaction'])) { switch ($_POST['bulkaction']) { case 'approveall': $coms_to_proc = $wpdb->get_results("SELECT `id` FROM `" . WPPA_COMMENTS . "` WHERE status = 'pending'", ARRAY_A); $query = "UPDATE " . WPPA_COMMENTS . " SET status = 'approved' WHERE status = 'pending'"; if ($wpdb->query($query) === false) { wppa_error_message(__('Could not bulk update status', 'wp-photo-album-plus')); $iret = false; } else { if ($coms_to_proc) { foreach ($coms_to_proc as $item) { wppa_send_comment_approved_email($item['id']); } } $iret = true; } break; case 'spamall': $query = "UPDATE " . WPPA_COMMENTS . " SET status = 'spam' WHERE status = 'pending'"; if ($wpdb->query($query) === false) { wppa_error_message(__('Could not bulk update status', 'wp-photo-album-plus')); $iret = false; } else { $iret = true; } break; case 'delspam': $query = "DELETE FROM " . WPPA_COMMENTS . " WHERE status = 'spam'"; if ($wpdb->query($query) === false) { wppa_error_message(__('Could not bulk delete spam', 'wp-photo-album-plus')); $iret = false; } break; } } if ($iret) { wppa_update_message(__('Changes Saved', 'wp-photo-album-plus')); } // Clear (super)cache wppa_clear_cache(); } // Submit // Delete trash $query = "DELETE FROM " . WPPA_COMMENTS . " WHERE status = 'trash'"; $wpdb->query($query); // Initialize normal display $wppa_comadmin_linkpage = get_option('wppa_comadmin_linkpage', '0'); if ($wppa_comadmin_linkpage) { $exists = $wpdb->get_var("SELECT `post_title` FROM `" . $wpdb->posts . "` WHERE `ID` = " . $wppa_comadmin_linkpage); if (!$exists) { $wppa_comadmin_linkpage = '0'; update_option('wppa_comadmin_linkpage', '0'); } } $moderating = isset($_REQUEST['commentid']); ?> <div class="wrap"> <?php $iconurl = WPPA_URL . '/img/comment.png'; ?> <div id="icon-album" class="icon32" style="background: transparent url(<?php echo $iconurl; ?> ) no-repeat"> <br /> </div> <h2> <?php if ($moderating) { _e('Photo Albums -> Moderate Comment', 'wp-photo-album-plus'); } else { _e('Photo Albums -> Comment admin', 'wp-photo-album-plus'); } ?> </h2> <?php if (!wppa_switch('show_comments')) { _e('<h3>The Comment system is not activated</h3><p>To activate: check Table II item 18 on the <b>Photo Albums -> Settings</b> screen and press <b>Save Changes</b>', 'wp-photo-album-plus'); } ?> <?php if (!$moderating) { ?> <!-- Statistics --> <table> <tbody> <tr> <td><h3 style="margin:0; color:#777777;"><?php _e('Total:', 'wp-photo-album-plus'); ?> </h3></td> <td><h3 style="margin:0;"><?php $count = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "`"); echo $count; ?> </h3></td> </tr> <tr> <td><h3 style="margin:0; color:green;"><?php _e('Approved:', 'wp-photo-album-plus'); ?> </h3></td> <td><h3 style="margin:0;"><?php $count = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "` WHERE `status` = 'approved'"); echo $count; ?> </h3></td> </tr> <tr> <td><h3 style="margin:0; color:#e66f00;"><?php _e('Pending:', 'wp-photo-album-plus'); ?> </h3></td> <td><h3 style="margin:0;"><?php $count = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "` WHERE `status` = 'pending'"); echo $count; ?> </h3></td> </tr> <tr> <td><h3 style="margin:0; color:red;"><?php _e('Spam:', 'wp-photo-album-plus'); ?> </h3></td> <td><h3 style="margin:0;"><?php $count = $wpdb->get_var("SELECT COUNT(*) FROM `" . WPPA_COMMENTS . "` WHERE `status` = 'spam'"); echo $count; ?> </h3></td> </tr> <?php if (wppa_opt('spam_maxage') != 'none') { ?> <tr> <td><h3 style="margin:0; color:red;"><?php _e('Auto deleted spam:', 'wp-photo-album-plus'); ?> </h3></td> <td><h3 style="margin:0;"><?php echo get_option('wppa_spam_auto_delcount', '0'); ?> </h3></td> </tr> <?php } ?> </tbody> </table> <!-- end statistics --> <!-- Settings --> <div style="border:1px solid #ccc; padding:4px; margin:4px 0" > <h3><?php _e('Settings', 'wp-photo-album-plus'); ?> </h3> <form action="<?php echo wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_manage_comments'); ?> " method="post"> <p> <?php wp_nonce_field('$wppa_nonce', WPPA_NONCE); _e('Linkpage:', 'wp-photo-album-plus'); ?> <select name="wppa_comadmin_linkpage"> <option value="0" <?php if ($wppa_comadmin_linkpage == '0') { echo 'selected="selected"'; } ?> disabled="disabled" ><?php _e('--- Please select a page ---', 'wp-photo-album-plus'); ?> </option> <?php $query = "SELECT `ID`, `post_title`, `post_content` FROM `" . $wpdb->posts . "` WHERE `post_type` = 'page' AND `post_status` = 'publish' ORDER BY `post_title` ASC"; $pages = $wpdb->get_results($query, ARRAY_A); if ($pages) { foreach ($pages as $page) { if (stripos($page['post_content'], '%%wppa%%') !== false || stripos($page['post_content'], '[wppa') !== false) { if ($wppa_comadmin_linkpage == $page['ID']) { $sel = 'selected="selected"'; } else { $sel = ''; } echo '<option value="' . $page['ID'] . '" ' . $sel . '>' . __($page['post_title'], 'wp-photo-album-plus') . '</option>'; } } } ?> </select> <?php _e('You can see the photo and all its comments on the selected page by clicking on the thumbnail image', 'wp-photo-album-plus'); ?> </p> <?php $comment_show = wppa_opt('comadmin_show'); ?> <p> <?php _e('Display status:', 'wp-photo-album-plus'); ?> <select name="wppa_comadmin_show"> <option value="all" <?php if ($comment_show == 'all') { echo 'selected="selected"'; } ?> ><?php _e('all', 'wp-photo-album-plus'); ?> </option> <option value="pending" <?php if ($comment_show == 'pending') { echo 'selected="selected"'; } ?> ><?php _e('pending', 'wp-photo-album-plus'); ?> </option> <option value="approved" <?php if ($comment_show == 'approved') { echo 'selected="selected"'; } ?> ><?php _e('approved', 'wp-photo-album-plus'); ?> </option> <option value="spam" <?php if ($comment_show == 'spam') { echo 'selected="selected"'; } ?> ><?php _e('spam', 'wp-photo-album-plus'); ?> </option> </select> <?php $comment_order = wppa_opt('comadmin_order'); ?> <?php _e('Display order:', 'wp-photo-album-plus'); ?> <select name="wppa_comadmin_order"> <option value="timestamp" <?php if ($comment_order == 'timestamp') { echo 'selected="selected"'; } ?> ><?php _e('timestamp', 'wp-photo-album-plus'); ?> </option> <option value="photo" <?php if ($comment_order == 'photo') { echo 'selected="selected"'; } ?> ><?php _e('photo', 'wp-photo-album-plus'); ?> </option> </select> <?php _e('Bulk action:', 'wp-photo-album-plus'); ?> <select name="bulkaction"> <option value=""><?php ?> </option> <option value="approveall"><?php _e('Approve all pending', 'wp-photo-album-plus'); ?> </option> <option value="spamall"><?php _e('Move all pending to spam', 'wp-photo-album-plus'); ?> </option> <option value="delspam"><?php _e('Delete all spam', 'wp-photo-album-plus'); ?> </option> </select> <input type="submit" class="button-primary" name="wppa_submit" value="<?php _e('Save Settings / Perform bulk action', 'wp-photo-album-plus'); ?> " /> </p> </form> </div> <!-- End Settings --> <?php } if ($moderating) { $pagesize = '1'; $where = " WHERE `id` = '" . $_REQUEST['commentid'] . "'"; $order = ''; $curpage = '1'; $limit = ''; } else { $pagsize = wppa_opt('comment_admin_pagesize'); $where = $comment_show == 'all' ? '' : " WHERE `status` = '" . $comment_show . "'"; $order = " ORDER BY `" . $comment_order . "`"; if ($comment_order == 'timestamp') { $order .= " DESC"; } if (isset($_GET['wppa-page'])) { $curpage = strval(intval($_GET['wppa-page'])); $offset = (strval(intval($_GET['wppa-page'])) - 1) * $pagsize; $limit = " LIMIT " . $offset . "," . $pagsize; } else { $limit = ' LIMIT 0,' . $pagsize; $curpage = '1'; } if ($pagsize == '0') { $limit = ''; } // Paginating is off $nitems = $wpdb->get_var("SELECT COUNT(*) FROM " . WPPA_COMMENTS . $where); $link = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_manage_comments'); wppa_admin_page_links($curpage, $pagsize, $nitems, $link); } ?> <table class="widefat"> <thead style="font-weight: bold" class=""> <tr> <th scope="col"><?php _e('Photo', 'wp-photo-album-plus'); ?> <br /> <?php _e('(Album)', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('#', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('IP', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('User', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('Email', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('Time since', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('Comment', 'wp-photo-album-plus'); ?> </th> <th scope="col" style="width: 130px;" ><?php _e('Status', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('Edit', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('Delete', 'wp-photo-album-plus'); ?> </th> </tr> </thead> <tbody class="wppa_table_1"> <?php $comments = $wpdb->get_results("SELECT * FROM `" . WPPA_COMMENTS . "`" . $where . $order . $limit, ARRAY_A); if ($comments) { foreach ($comments as $com) { ?> <tr> <?php $photo = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WPPA_PHOTOS . " WHERE id = %s", $com['photo']), 'ARRAY_A'); if ($photo) { $alb = $photo['album']; $pname = __($photo['name'], 'wp-photo-album-plus'); $albname = '(' . wppa_get_album_name($alb) . ')'; } else { $alb = ''; $pname = ''; $albname = ''; } if ($wppa_comadmin_linkpage == '0') { ?> <td style="text-align:center"> <img src="<?php echo wppa_fix_poster_ext(wppa_get_thumb_url($com['photo']), $com['photo']); ?> " style="max-height:64px;max-width:64px;" /> <br /> <?php echo $albname; ?> </td><?php } else { $url = get_page_link($wppa_comadmin_linkpage); if (strpos($url, '?')) { $url .= '&'; } else { $url .= '?'; } $url .= 'wppa-album=' . $alb . '&wppa-photo=' . $com['photo'] . '&wppa-occur=1'; ?> <td style="text-align:center"> <a href="<?php echo $url; ?> " target="_blank"> <img title="<?php _e('Click to see the fullsize photo and all comments', 'wp-photo-album-plus'); ?> " src="<?php echo wppa_fix_poster_ext(wppa_get_thumb_url($com['photo']), $com['photo']); ?> " style="max-height:64px;max-width:64px;" /> </a> <br /> <?php echo $albname; ?> </td><?php } ?> <td><?php echo $com['photo']; ?> </td> <td><?php echo $com['ip']; ?> </td> <td><?php echo $com['user']; ?> </td> <td><?php if ($com['email']) { $subject = str_replace(' ', '%20', sprintf(__('Reply to your comment on photo: %s on %s', 'wp-photo-album-plus'), $pname, get_bloginfo('name'))); echo '<a href="mailto:' . $com['email'] . '?Subject=' . $subject . '" title="' . __('Reply', 'wp-photo-album-plus') . '" >' . $com['email'] . '</a>'; } else { echo $com['email']; } ?> </td> <td><?php echo wppa_get_time_since($com['timestamp']); ?> </td> <td><?php echo stripslashes($com['comment']); ?> </td> <td> <input type="hidden" id="photo-nonce-<?php echo $com['photo']; ?> " value="<?php echo wp_create_nonce('wppa_nonce_' . $com['photo']); ?> " /> <select name="status['<?php echo $com['id']; ?> ']" onchange="jQuery('#wppa-comment-spin-<?php echo $com['id']; ?> ').css('visibility', 'visible'); wppaAjaxUpdateCommentStatus(<?php echo $com['photo']; ?> , <?php echo $com['id']; ?> , this.value)"> <option value="pending" <?php if ($com['status'] == 'pending') { echo 'selected="selected"'; } ?> ><?php _e('Pending', 'wp-photo-album-plus'); ?> </option> <option value="approved" <?php if ($com['status'] == 'approved') { echo 'selected="selected"'; } ?> ><?php _e('Approved', 'wp-photo-album-plus'); ?> </option> <option value="spam" <?php if ($com['status'] == 'spam') { echo 'selected="selected"'; } ?> ><?php _e('Spam', 'wp-photo-album-plus'); ?> </option> </select> <img id="wppa-comment-spin-<?php echo $com['id']; ?> " src="<?php echo wppa_get_imgdir() . 'spinner.gif'; ?> " style="visibility:hidden" /> </td> <?php $url = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_manage_comments&tab=edit&edit_id=' . $com['id']); if (isset($_GET['wppa-page'])) { $url .= '&compage=' . strval(intval($_GET['wppa-page'])); } if (isset($_GET['commentid'])) { $url .= '&commentid=' . strval(intval($_GET['commentid'])); } ?> <?php $delurl = wppa_dbg_url(get_admin_url() . 'admin.php?page=wppa_manage_comments&tab=delete&delete_id=' . $com['id']); ?> <td style="color:green; cursor:pointer;" onclick="document.location='<?php echo $url; ?> '"><b><?php _e('Edit', 'wp-photo-album-plus'); ?> </b></td> <td style="color:red; cursor:pointer;" onclick="if (confirm('<?php _e('Are you sure you want to delete this comment?', 'wp-photo-album-plus'); ?> ')) document.location = '<?php echo $delurl; ?> ';"><b><?php _e('Delete', 'wp-photo-album-plus'); ?> </b></td> </tr> <?php } } ?> </tbody> <tfoot style="font-weight: bold" class=""> <tr> <th scope="col"><?php _e('Photo', 'wp-photo-album-plus'); ?> <br /> <?php _e('(Album)', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('#', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('IP', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('User', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('Email', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('Time since', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('Comment', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('Status', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('Edit', 'wp-photo-album-plus'); ?> </th> <th scope="col"><?php _e('Delete', 'wp-photo-album-plus'); ?> </th> </tr> </tfoot> </table> <?php if (!$moderating) { wppa_admin_page_links($curpage, $pagsize, $nitems, $link); } ?> </form> </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', '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); }
function wppa_get_potd() { global $wpdb; $image = ''; switch (wppa_opt('widget_method')) { case '1': // Fixed photo $id = wppa_opt('widget_photo'); if ($id != '') { $image = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s LIMIT 0,1", $id), ARRAY_A); wppa_dbg_q('Q-Potd'); wppa_cache_photo('add', $image); } break; case '2': // Random $album = wppa_opt('widget_album'); if ($album == 'topten') { $images = wppa_get_widgetphotos($album); if (count($images) > 1) { // Select a random first from the current selection $idx = rand(0, count($images) - 1); $image = $images[$idx]; } } elseif ($album != '') { $images = wppa_get_widgetphotos($album, "ORDER BY RAND() LIMIT 0,1"); $image = $images[0]; } break; case '3': // Last upload $album = wppa_opt('widget_album'); if ($album == 'topten') { $images = wppa_get_widgetphotos($album); if ($images) { // fid last uploaded image in the $images pool $temp = 0; foreach ($images as $img) { if ($img['timestamp'] > $temp) { $temp = $img['timestamp']; $image = $img; } } } } elseif ($album != '') { $images = wppa_get_widgetphotos($album, "ORDER BY timestamp DESC LIMIT 0,1"); $image = $images[0]; } break; case '4': // Change every $album = wppa_opt('widget_album'); if ($album != '') { $per = wppa_opt('widget_period'); $photos = wppa_get_widgetphotos($album); if ($per == '0') { if ($photos) { $image = $photos[rand(0, count($photos) - 1)]; } else { $image = ''; } } elseif ($per == 'day-of-week') { $image = ''; if ($photos) { $d = date_i18n("w"); $d -= get_option('wppa_potd_offset', '0'); while ($d < '1') { $d += '7'; } foreach ($photos as $img) { if ($img['p_order'] == $d) { $image = $img; } } } } elseif ($per == 'day-of-month') { $image = ''; if ($photos) { $d = strval(intval(date_i18n("d"))); $d -= get_option('wppa_potd_offset', '0'); while ($d < '1') { $d += '31'; } foreach ($photos as $img) { if ($img['p_order'] == $d) { $image = $img; } } } } elseif ($per == 'day-of-year') { $image = ''; if ($photos) { $d = strval(intval(date_i18n("z"))); $d -= get_option('wppa_potd_offset', '0'); while ($d < '0') { $d += '366'; } foreach ($photos as $img) { if ($img['p_order'] == $d) { $image = $img; } } } } else { $u = date_i18n("U"); // Seconds since 1-1-1970, local $u /= 3600; // hours since $u = floor($u); $u /= $per; $u = floor($u); // Find the right photo out of the photos found by wppa_get_widgetphotos(), // based on the Change every { any timeperiod } algorithm. if ($photos) { $p = count($photos); $idn = fmod($u, $p); // If from topten,... if ($album == 'topten') { // Do a re-read of the same to order by rand, reproduceable // This can not be done by wppa_get_widgetphotos(), // it does already ORDER BY for the top selection criterium. // So we save the ids, and do a SELECT WHERE id IN ( array of found ids ) ORDER BY RAND( seed ) $ids = array(); foreach ($photos as $photo) { $ids[] = $photo['id']; } $photos = $wpdb->get_results("SELECT `id`, `p_order` " . "FROM `" . WPPA_PHOTOS . "` " . "WHERE `id` IN (" . implode(',', $ids) . ") " . "ORDER BY RAND(" . $idn . ")", ARRAY_A); } else { $photos = wppa_get_widgetphotos($album, " ORDER BY RAND(" . $idn . ")"); } // Image found $image = $photos[$idn]; } else { $image = ''; } } } else { $image = ''; } break; default: $image = ''; } if ($image) { $image = wppa_cache_photo($image['id']); } return $image; }
function wppa_zoom_in($id) { if ($id === false) { return ''; } if (wppa_switch('show_zoomin')) { if (wppa_opt('magnifier')) { return __('Zoom in', 'wp-photo-album-plus'); } else { return esc_attr(stripslashes(wppa_get_photo_name($id))); } } else { return ''; } }
function wppa_numberbar($opt = '') { // A single image slideshow needs no navigation if (wppa('is_single')) { return; } if (is_feed()) { return; } $do_it = false; if (wppa_switch('show_slideshownumbar') && !wppa('is_slideonly')) { $do_it = true; } if (wppa('numbar_on')) { $do_it = true; } if (!$do_it) { return; } // get the data $thumbs = wppa_get_thumbs(); if (empty($thumbs)) { return; } // get the sizes $size_given = is_numeric(wppa_opt('fontsize_numbar')); if ($size_given) { $size = wppa_opt('fontsize_numbar'); if (wppa_in_widget()) { $size /= 2; } } else { $size = wppa_in_widget() ? '9' : '12'; } if ($size < '9') { $size = '9'; } $size_2 = floor($size / 2); $size_4 = floor($size_2 / 2); $size_32 = floor($size * 3 / 2); // make the numbar style $style = 'position:absolute; bottom:' . $size . 'px; right:0; margin-right:' . $size_2 . 'px; '; // start the numbar wppa_out('<div class="wppa-numberbar" style="' . $style . '">'); $numid = 0; // make the elementstyles $style = 'display:block;' . 'float:left;' . 'padding:0 ' . $size_4 . 'px;' . 'margin-right:' . $size_2 . 'px;' . 'font-weight:' . wppa_opt('fontweight_numbar') . ';'; if (wppa_opt('fontfamily_numbar')) { $style .= 'font-family:' . wppa_opt('fontfamily_numbar') . ';'; } if (wppa_opt('fontcolor_numbar')) { $style .= 'color:' . wppa_opt('fontcolor_numbar') . ';'; } if ($size_given) { $style .= 'font-size:' . $size . 'px;line-height:' . $size_32 . 'px;'; } $style_active = $style; if (wppa_opt('bgcolor_numbar')) { $style .= 'background-color:' . wppa_opt('bgcolor_numbar') . ';'; } if (wppa_opt('bgcolor_numbar_active')) { $style_active .= 'background-color:' . wppa_opt('bgcolor_numbar_active') . ';'; } if (wppa_opt('bcolor_numbar')) { $style .= 'border:1px solid ' . wppa_opt('bcolor_numbar') . ';'; } if (wppa_opt('bcolor_numbar_active')) { $style_active .= 'border:1px solid ' . wppa_opt('bcolor_numbar_active') . ';'; } // if the number of photos is larger than a certain number, only the active ph displays a number, other are dots $count = count($thumbs); $high = wppa_opt('numbar_max'); // do the numbers foreach ($thumbs as $tt) { $title = sprintf(__('Photo %s of %s', 'wp-photo-album-plus'), $numid + '1', $count); wppa_out('<a' . ' id="wppa-numbar-' . wppa('mocc') . '-' . $numid . '"' . ' title="' . $title . '"' . ' ' . ($numid == 0 ? ' class="wppa-numbar-current" ' : '') . ' style="' . ($numid == 0 ? $style_active : $style) . '"' . ' onclick="wppaGotoKeepState(' . wppa('mocc') . ',' . $numid . ');return false;"' . ' >' . ($count > $high ? '.' : $numid + 1) . '</a>'); $numid++; } wppa_out('</div>'); }
function wppa_bcitem($value = '', $href = '', $title = '', $class = '', $ajax = '') { static $sep; // Convert url to pretty $href = wppa_convert_to_pretty($href); // Has content? if (!$value) { return; } // No content if ($href) { wppa_out('<a' . ($ajax && wppa_switch('allow_ajax') ? ' onclick="wppaDoAjaxRender(' . wppa('mocc') . ', \'' . $ajax . '\', \'' . $href . '\' );"' : ' href="' . $href . '"') . ' class="wppa-nav-text ' . $class . '"' . ' style="' . __wcs('wppa-nav-text') . '"' . ' title="' . esc_attr($title) . '" >' . $value . '</a>'); } else { // No link, its the last item wppa_out('<span' . ' id="bc-pname-' . wppa('mocc') . '"' . ' class="wppa-nav-text ' . $class . '"' . ' style="' . ($title ? 'cursor:pointer;' : '') . __wcs('wppa-nav-text') . '"' . ' title="' . esc_attr($title) . '"' . ' >' . $value . '</span>'); return; } // Add seperator if (!$sep) { // Compute the seperator $temp = wppa_opt('bc_separator'); switch ($temp) { case 'url': $size = wppa_opt('fontsize_nav'); if ($size == '') { $size = '12'; } $style = 'height:' . $size . 'px;'; $sep = ' ' . '<img' . ' src="' . wppa_opt('bc_url') . '"' . ' class="no-shadow"' . ' style="' . $style . '"' . ' />' . ' '; break; case 'txt': $sep = ' ' . html_entity_decode(stripslashes(wppa_opt('bc_txt')), ENT_QUOTES) . ' '; break; default: $sep = ' &' . $temp . '; '; } } wppa_out('<span' . ' class="wppa-nav-text ' . $class . '"' . ' style="' . __wcs('wppa-nav-text') . '"' . ' >' . $sep . '</span>'); }
function __wcs($class) { global $wppa; if (!wppa_switch('wppa_inline_css')) { return ''; // No inline styles } $opt = ''; $result = ''; switch ($class) { case 'wppa-box': $opt = wppa_opt('wppa_bwidth'); if ($opt > '0') { $result .= 'border-style: solid; border-width:' . $opt . 'px; '; } $opt = wppa_opt('wppa_bradius'); if ($opt > '0') { $result .= 'border-radius:' . $opt . 'px; '; $result .= '-moz-border-radius:' . $opt . 'px; '; $result .= '-khtml-border-radius:' . $opt . 'px; '; $result .= '-webkit-border-radius:' . $opt . 'px; '; } $opt = wppa_opt('wppa_box_spacing'); if ($opt != '') { $result .= 'margin-bottom:' . $opt . 'px; '; } break; case 'wppa-mini-box': $opt = wppa_opt('wppa_bwidth'); if ($opt > '0') { $opt = floor(($opt + 2) / 3); $result .= 'border-style: solid; border-width:' . $opt . 'px; '; } $opt = wppa_opt('wppa_bradius'); if ($opt > '0') { $opt = floor(($opt + 2) / 3); $result .= 'border-radius:' . $opt . 'px; '; $result .= '-moz-border-radius:' . $opt . 'px; '; $result .= '-khtml-border-radius:' . $opt . 'px; '; $result .= '-webkit-border-radius:' . $opt . 'px; '; } break; case 'wppa-cover-box': $opt = wppa_opt('wppa_cover_minheight'); if ($opt) { $result .= 'min-height:' . $opt . 'px; '; } break; case 'wppa-cover-text-frame': $opt = wppa_opt('wppa_head_and_text_frame_height'); if ($opt) { $result .= 'min-height:' . $opt . 'px; '; } break; case 'wppa-thumb-text': $opt = wppa_opt('wppa_fontfamily_thumb'); if ($opt) { $result .= 'font-family:' . $opt . '; '; } $opt = wppa_opt('wppa_fontsize_thumb'); if ($opt) { $ls = floor($opt * 1.29); $result .= 'font-size:' . $opt . 'px; line-height:' . $ls . 'px; '; } $opt = wppa_opt('wppa_fontcolor_thumb'); if ($opt) { $result .= 'color:' . $opt . '; '; } $opt = wppa_opt('wppa_fontweight_thumb'); if ($opt) { $result .= 'font-weight:' . $opt . '; '; } break; case 'wppa-box-text': $opt = wppa_opt('wppa_fontcolor_box'); if ($opt) { $result .= 'color:' . $opt . '; '; } case 'wppa-box-text-nocolor': $opt = wppa_opt('wppa_fontfamily_box'); if ($opt) { $result .= 'font-family:' . $opt . '; '; } $opt = wppa_opt('wppa_fontsize_box'); if ($opt) { $result .= 'font-size:' . $opt . 'px; '; } $opt = wppa_opt('wppa_fontweight_box'); if ($opt) { $result .= 'font-weight:' . $opt . '; '; } break; case 'wppa-comments': $opt = wppa_opt('wppa_bgcolor_com'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_com'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-iptc': $opt = wppa_opt('wppa_bgcolor_iptc'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_iptc'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-exif': $opt = wppa_opt('wppa_bgcolor_exif'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_exif'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-share': $opt = wppa_opt('wppa_bgcolor_share'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_share'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-name-desc': $opt = wppa_opt('wppa_bgcolor_namedesc'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_namedesc'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-nav': $opt = wppa_opt('wppa_bgcolor_nav'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_nav'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-nav-text': $opt = wppa_opt('wppa_fontfamily_nav'); if ($opt) { $result .= 'font-family:' . $opt . '; '; } $opt = wppa_opt('wppa_fontsize_nav'); if ($opt) { $result .= 'font-size:' . $opt . 'px; '; } $opt = wppa_opt('wppa_fontcolor_nav'); if ($opt) { $result .= 'color:' . $opt . '; '; } $opt = wppa_opt('wppa_fontweight_nav'); if ($opt) { $result .= 'font-weight:' . $opt . '; '; } break; case 'wppa-even': $opt = wppa_opt('wppa_bgcolor_even'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_even'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-alt': $opt = wppa_opt('wppa_bgcolor_alt'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_alt'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-img': $opt = wppa_opt('wppa_bgcolor_img'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } break; case 'wppa-title': $opt = wppa_opt('wppa_fontfamily_title'); if ($opt) { $result .= 'font-family:' . $opt . '; '; } $opt = wppa_opt('wppa_fontsize_title'); if ($opt) { $result .= 'font-size:' . $opt . 'px; '; } $opt = wppa_opt('wppa_fontcolor_title'); if ($opt) { $result .= 'color:' . $opt . '; '; } $opt = wppa_opt('wppa_fontweight_title'); if ($opt) { $result .= 'font-weight:' . $opt . '; '; } break; case 'wppa-fulldesc': $opt = wppa_opt('wppa_fontfamily_fulldesc'); if ($opt) { $result .= 'font-family:' . $opt . '; '; } $opt = wppa_opt('wppa_fontsize_fulldesc'); if ($opt) { $result .= 'font-size:' . $opt . 'px; '; } $opt = wppa_opt('wppa_fontcolor_fulldesc'); if ($opt) { $result .= 'color:' . $opt . '; '; } $opt = wppa_opt('wppa_fontweight_fulldesc'); if ($opt) { $result .= 'font-weight:' . $opt . '; '; } break; case 'wppa-fulltitle': $opt = wppa_opt('wppa_fontfamily_fulltitle'); if ($opt) { $result .= 'font-family:' . $opt . '; '; } $opt = wppa_opt('wppa_fontsize_fulltitle'); if ($opt) { $result .= 'font-size:' . $opt . 'px; '; } $opt = wppa_opt('wppa_fontcolor_fulltitle'); if ($opt) { $result .= 'color:' . $opt . '; '; } $opt = wppa_opt('wppa_fontweight_fulltitle'); if ($opt) { $result .= 'font-weight:' . $opt . '; '; } break; case 'wppa-custom': $opt = wppa_opt('wppa_bgcolor_cus'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_cus'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-upload': $opt = wppa_opt('wppa_bgcolor_upload'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_upload'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-multitag': $opt = wppa_opt('wppa_bgcolor_multitag'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_multitag'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-bestof': $opt = wppa_opt('wppa_bgcolor_bestof'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_bestof'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-tagcloud': $opt = wppa_opt('wppa_bgcolor_tagcloud'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_tagcloud'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-superview': $opt = wppa_opt('wppa_bgcolor_superview'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_superview'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-search': $opt = wppa_opt('wppa_bgcolor_search'); if ($opt) { $result .= 'background-color:' . $opt . '; '; } $opt = wppa_opt('wppa_bcolor_search'); if ($opt) { $result .= 'border-color:' . $opt . '; '; } break; case 'wppa-black': // $opt = wppa_opt( 'wppa_black' ); // if ( $opt ) $result .= 'color:' . $opt . '; '; // break; break; case 'wppa-arrow': $opt = wppa_opt('wppa_arrow_color'); if ($opt) { $result .= 'color:' . $opt . '; '; } break; case 'wppa-td': $result .= 'padding: 3px 2px 3px 0; border: 0'; break; default: wppa_dbg_msg('Unexpected error in __wcs, unknown class: ' . $class, 'red'); wppa_log('Err', 'Unexpected error in __wcs, unknown class: ' . $class); } return $result; }
function wppa_insert_photo($file = '', $alb = '', $name = '', $desc = '', $porder = '0', $id = '0', $linkurl = '', $linktitle = '') { global $wpdb; global $warning_given_small; $album = wppa_cache_album($alb); if (!wppa_allow_uploads($alb)) { if (is_admin() && !wppa('ajax')) { wppa_error_message(sprintf(__('Album %s is full', 'wp-photo-album-plus'), wppa_get_album_name($alb))); } else { wppa_alert(sprintf(__('Album %s is full', 'wp-photo-album-plus'), wppa_get_album_name($alb))); } return false; } if ($file != '' && $alb != '') { // Get the name if not given if ($name == '') { $name = basename($file); } // Sanitize name $filename = wppa_sanitize_file_name($name); $name = wppa_sanitize_photo_name($name); // If not dups allowed and its already here, quit if (isset($_POST['wppa-nodups']) || wppa_switch('void_dups')) { $exists = wppa_file_is_in_album($filename, $alb); if ($exists) { if (isset($_POST['del-after-p'])) { unlink($file); $msg = __('Photo %s already exists in album number %s. Removed from depot.', 'wp-photo-album-plus'); } else { $msg = __('Photo %s already exists in album number %s.', 'wp-photo-album-plus'); } wppa_warning_message(sprintf($msg, $name, $alb)); return false; } } // Verify file exists if (!wppa('is_remote') && !file_exists($file)) { if (!is_dir(dirname($file))) { wppa_error_message('Error: Directory ' . dirname($file) . ' does not exist.'); return false; } if (!is_writable(dirname($file))) { wppa_error_message('Error: Directory ' . dirname($file) . ' is not writable.'); return false; } wppa_error_message('Error: File ' . $file . ' does not exist.'); return false; } // else { // wppa_ok_message( 'Good: File '.$file.' exists.' ); // } // Get and verify the size $img_size = getimagesize($file); if ($img_size) { if (wppa_check_memory_limit('', $img_size['0'], $img_size['1']) === false) { wppa_error_message(sprintf(__('ERROR: Attempt to upload a photo that is too large to process (%s).', 'wp-photo-album-plus'), $name) . wppa_check_memory_limit()); wppa('ajax_import_files_error', __('Too big', 'wp-photo-album-plus')); return false; } if (!$warning_given_small && ($img_size['0'] < wppa_get_minisize() && $img_size['1'] < wppa_get_minisize())) { wppa_warning_message(__('WARNING: You are uploading photos that are too small. Photos must be larger than the thumbnail size and larger than the coverphotosize.', 'wp-photo-album-plus')); wppa('ajax_import_files_error', __('Too small', 'wp-photo-album-plus')); $warning_given_small = true; } } else { wppa_error_message(__('ERROR: Unable to retrieve image size of', 'wp-photo-album-plus') . ' ' . $name . ' ' . __('Are you sure it is a photo?', 'wp-photo-album-plus')); wppa('ajax_import_files_error', __('No imagesize', 'wp-photo-album-plus')); return false; } // Get ext based on mimetype, regardless of ext switch ($img_size[2]) { // mime type case 1: $ext = 'gif'; break; case 2: $ext = 'jpg'; break; case 3: $ext = 'png'; break; default: wppa_error_message(__('Unsupported mime type encountered:', 'wp-photo-album-plus') . ' ' . $img_size[2] . '.'); return false; } // Get an id if not yet there if ($id == '0') { $id = wppa_nextkey(WPPA_PHOTOS); } // Get opt deflt desc if empty if ($desc == '' && wppa_switch('apply_newphoto_desc')) { $desc = stripslashes(wppa_opt('newphoto_description')); } // Reset rating $mrat = '0'; // Find ( new ) owner $owner = wppa_get_user(); // Validate album if (!is_numeric($alb) || $alb < '1') { wppa_error_message(__('Album not known while trying to add a photo', 'wp-photo-album-plus')); return false; } if (!wppa_have_access($alb)) { wppa_error_message(sprintf(__('Album %s does not exist or is not accessable while trying to add a photo', 'wp-photo-album-plus'), $alb)); return false; } $status = wppa_switch('upload_moderate') && !current_user_can('wppa_admin') ? 'pending' : 'publish'; // Add photo to db $id = wppa_create_photo_entry(array('id' => $id, 'album' => $alb, 'ext' => $ext, 'name' => $name, 'p_order' => $porder, 'description' => $desc, 'linkurl' => $linkurl, 'linktitle' => $linktitle, 'owner' => $owner, 'status' => $status, 'filename' => $filename)); if (!$id) { wppa_error_message(__('Could not insert photo.', 'wp-photo-album-plus')); } else { // Save the source wppa_save_source($file, $filename, $alb); wppa_flush_treecounts($alb); wppa_update_album(array('id' => $alb, 'modified' => time())); wppa_flush_upldr_cache('photoid', $id); } // Make the photo files if (wppa_make_the_photo_files($file, $id, $ext)) { // Repair photoname if not supplied and not standard wppa_set_default_name($id, $name); // Tags wppa_set_default_tags($id); // Index wppa_index_add('photo', $id); // and add watermark ( optionally ) to fullsize image only wppa_add_watermark($id); // also to thumbnail? if (wppa_switch('watermark_thumbs')) { wppa_create_thumbnail($id); } // Is it a default coverimage? wppa_check_coverimage($id); return $id; } } else { wppa_error_message(__('ERROR: Unknown file or album.', 'wp-photo-album-plus')); return false; } }
function wppa_make_tinymce_dialog() { global $wpdb; $result = '<div id="wppagallery-form">' . '<div style="height:158px; background-color:#eee; overflow:auto; margin-top:10px;" >' . '<div id="wppagallery-album-preview" style="text-align:center;font-size:48px; line-height:21px; color:#fff;" class="wppagallery-album" ><br /><br /><br />' . __('Album Preview', 'wp-photo-album-plus') . '<br /><span style="font-size:12px; color:#777" ><br/>' . __('A maximum of 100 photos can be previewd', 'wp-photo-album-plus') . '</span></div>' . '<div id="wppagallery-photo-preview" style="text-align:center;font-size:48px; line-height:21px; color:#fff; display:none;" class="wppagallery-photo" ><br /><br /><br />' . __('Photo Preview', 'wp-photo-album-plus') . '</div>' . '</div>' . '<table id="wppagallery-table" class="form-table">' . '<tr>' . '<th><label for="wppagallery-type">' . __('Type of Gallery display:', 'wp-photo-album-plus') . '</label></th>' . '<td>' . '<select id="wppagallery-type" name="type" onchange="wppaGalleryTypeChange(this.value)">' . '<option value="cover">' . __('The cover of an album', 'wp-photo-album-plus') . '</option>' . '<option value="album">' . __('The sub-albums and/or thumbnails in an album', 'wp-photo-album-plus') . '</option>' . '<option value="slide">' . __('A slideshow of the photos in an album', 'wp-photo-album-plus') . '</option>' . '<option value="slideonly">' . __('A slideshow without supporting boxes', 'wp-photo-album-plus') . '</option>' . '<option value="slideonlyf">' . __('A slideshow with a filmstrip only', 'wp-photo-album-plus') . '</option>' . '<option value="photo">' . __('A single photo', 'wp-photo-album-plus') . '</option>' . '<option value="mphoto">' . __('A single photo with caption', 'wp-photo-album-plus') . '</option>' . '<option value="slphoto">' . __('A single photo in the style of a slideshow', 'wp-photo-album-plus') . '</option>' . '<option value="generic">' . __('A generic albums display', 'wp-photo-album-plus') . '</option>' . '</select>' . '<br />' . '<small>' . __('Specify the type of gallery', 'wp-photo-album-plus') . '</small>' . '</td>' . '</tr>' . '<tr class="wppagallery-help" style="display:none;" >' . '<th><label for="wppagallery-album" class="wppagallery-help" >' . __('Explanation:', 'wp-photo-album-plus') . '</label></th>' . '<td>' . __('Use this gallerytype to display all the top-level album covers.', 'wp-photo-album-plus') . '</td>' . '</tr>' . '<tr class="wppagallery-album" >' . '<th><label for="wppagallery-album" class="wppagallery-album" >' . __('The Album to be used:', 'wp-photo-album-plus') . '</label></th>' . '<td>' . '<select id="wppagallery-album" name="album" style=width:270px;" class="wppagallery-album" onchange="wppaGalleryAlbumChange(this.value); wppaTinyMceAlbumPreview(this.value)">'; $albums = $wpdb->get_results("SELECT `id`, `name` FROM `" . WPPA_ALBUMS . "` ORDER BY `timestamp` DESC", ARRAY_A); if ($albums) { if (wppa_switch('wppa_hier_albsel')) { $albums = wppa_add_paths($albums); } else { foreach (array_keys($albums) as $index) { $albums[$index]['name'] = __(stripslashes($albums[$index]['name']), 'wp-photo-album-plus'); } } // Sort $albums = wppa_array_sort($albums, 'name'); $result .= '<option value="0" disabled="disabled" selected="selected" >' . __('Please select an album', 'wp-photo-album-plus') . '</option>'; // All standard albums foreach ($albums as $album) { $value = $album['id']; $alb = $album['id']; $photos = $wpdb->get_results($wpdb->prepare("SELECT `id`, `name`, `album`, `ext` FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s " . wppa_get_photo_order($alb) . " LIMIT 100", $alb), ARRAY_A); if ($photos) { foreach ($photos as $photo) { $photo_id = wppa_opt('file_system') == 'tree' ? wppa_expand_id($photo['id']) : $photo['id']; $value .= '|' . $photo_id . '.' . $photo['ext']; } } else { $value .= '|'; } $note = ' (' . $album['id'] . ')'; if (count($photos) <= wppa_opt('min_thumbs')) { $note .= ' *'; } $result .= '<option value="' . $value . '" >' . stripslashes(__($album['name'], 'wp-photo-album-plus')) . $note . '</option>'; } // #last $value = '#last'; $alb = $albums[0]['id']; $photos = $wpdb->get_results($wpdb->prepare("SELECT `id`, `name`, `album`, `ext` FROM `" . WPPA_PHOTOS . "` WHERE `album` = %s " . wppa_get_photo_order($alb) . " LIMIT 100", $alb), ARRAY_A); if ($photos) { foreach ($photos as $photo) { $photo_id = wppa_opt('file_system') == 'tree' ? wppa_expand_id($photo['id']) : $photo['id']; $value .= '|' . $photo_id . '.' . $photo['ext']; } } else { $value .= '|'; } $result .= '<option value="' . $value . '" >' . __('- The latest created album -', 'wp-photo-album-plus') . '</option>'; // #topten $value = '#topten'; $photos = $wpdb->get_results("SELECT `id`, `name`, `album`, `ext` FROM `" . WPPA_PHOTOS . "` ORDER BY `mean_rating` DESC LIMIT " . wppa_opt('topten_count'), ARRAY_A); if ($photos) { foreach ($photos as $photo) { $photo_id = wppa_opt('file_system') == 'tree' ? wppa_expand_id($photo['id']) : $photo['id']; $value .= '|' . $photo_id . '.' . $photo['ext']; } } else { $value .= '|'; } $result .= '<option value = "' . $value . '" >' . __('--- The top rated photos ---', 'wp-photo-album-plus') . '</option>'; // #lasten $value = '#lasten'; $photos = $wpdb->get_results("SELECT `id`, `name`, `album`, `ext` FROM `" . WPPA_PHOTOS . "` ORDER BY `timestamp` DESC LIMIT " . wppa_opt('lasten_count'), ARRAY_A); if ($photos) { foreach ($photos as $photo) { $photo_id = wppa_opt('file_system') == 'tree' ? wppa_expand_id($photo['id']) : $photo['id']; $value .= '|' . $photo_id . '.' . $photo['ext']; } } else { $value .= '|'; } $result .= '<option value = "' . $value . '" >' . __('--- The most recently uploaded photos ---', 'wp-photo-album-plus') . '</option>'; // #featen $value = '#featen'; $photos = $wpdb->get_results("SELECT `id`, `name`, `album`, `ext` FROM `" . WPPA_PHOTOS . "` WHERE `status` = 'featured' ORDER BY RAND() DESC LIMIT " . wppa_opt('featen_count'), ARRAY_A); if ($photos) { foreach ($photos as $photo) { $photo_id = wppa_opt('file_system') == 'tree' ? wppa_expand_id($photo['id']) : $photo['id']; $value .= '|' . $photo_id . '.' . $photo['ext']; } } else { $value .= '|'; } $result .= '<option value = "' . $value . '" >' . __('--- A random selection of featured photos ---', 'wp-photo-album-plus') . '</option>'; // #comten $value = '#comten'; $comments = $wpdb->get_results("SELECT `id`, `photo` FROM `" . WPPA_COMMENTS . "` ORDER BY `timestamp` DESC", ARRAY_A); $photos = false; $done = array(); if ($comments) { foreach ($comments as $comment) { if (count($done) < wppa_opt('comten_count') && !in_array($comment['photo'], $done)) { $done[] = $comment['photo']; $photos[] = $wpdb->get_row("SELECT `id`, `name`, `album`, `ext` FROM `" . WPPA_PHOTOS . "` WHERE `id` = " . $comment['photo'], ARRAY_A); } } } if ($photos) { foreach ($photos as $photo) { $photo_id = wppa_opt('file_system') == 'tree' ? wppa_expand_id($photo['id']) : $photo['id']; $value .= '|' . $photo_id . '.' . $photo['ext']; } } else { $value .= '|'; } $result .= '<option value = "' . $value . '" >' . __('--- The most recently commented photos ---', 'wp-photo-album-plus') . '</option>'; // #tags $value = '#tags'; $result .= '<option value = "' . $value . '" >' . __('--- Photos that have certain tags ---', 'wp-photo-album-plus') . '</option>'; // #all $value = '#all'; $photos = $wpdb->get_results("SELECT `id`, `name`, `album`, `ext` FROM `" . WPPA_PHOTOS . "` " . wppa_get_photo_order('0') . " LIMIT 100", ARRAY_A); if ($photos) { foreach ($photos as $photo) { $photo_id = wppa_opt('file_system') == 'tree' ? wppa_expand_id($photo['id']) : $photo['id']; $value .= '|' . $photo_id . '.' . $photo['ext']; } } else { $value .= '|'; } $result .= '<option value = "' . $value . '" >' . __('--- All photos in the system ---', 'wp-photo-album-plus') . '</option>'; } else { $result .= '<option value="0" >' . __('There are no albums yet', 'wp-photo-album-plus') . '</option>'; } $result .= '</select>' . '<input type="text" id="wppagallery-alb" name="alb" value="" style="width:50px; display:none; background-color:#ddd;" class="wppagallery-extra" title="Enter albumnumber if not systemwide" />' . '<input type="text" id="wppagallery-cnt" name="cnt" value="" style="width:50px; display:none; background-color:#ddd;" class="wppagallery-extra" title="Enter count if not default" />' . '<br />' . '<small class="wppagallery-album" >' . __('Specify the album to be used or --- A special selection of photos ---', 'wp-photo-album-plus') . '<br />' . __('In an upload box, the album is optional. When no album is specified: a selection box will be displayed of the albums the user has the right to upload.', 'wp-photo-album-plus') . '<br />' . __('* Album contains less than the minimun number of photos', 'wp-photo-album-plus') . '</small>' . '</td>' . '</tr>' . '<tr class="wppagallery-photo" style="display:none;" >' . '<th><label for="wppagallery-photo" style="display:none;" class="wppagallery-photo" >' . __('The Photo to be used:', 'wp-photo-album-plus') . '</label></th>' . '<td>' . '<select id="wppagallery-photo" name="photo" style="display:none;" class="wppagallery-photo" onchange="wppaTinyMcePhotoPreview(this.value)" >'; $photos = $wpdb->get_results("SELECT `id`, `name`, `album`, `ext` FROM `" . WPPA_PHOTOS . "` ORDER BY `timestamp` DESC LIMIT 100", ARRAY_A); if ($photos) { $result .= '<option value="0" disabled="disabled" selected="selected" >' . __('Please select a photo', 'wp-photo-album-plus') . '</option>'; foreach ($photos as $photo) { $name = stripslashes(__($photo['name'], 'wp-photo-album-plus')); if (strlen($name) > '50') { $name = substr($name, '0', '50') . '...'; } if (get_option('wppa_file_system') == 'flat') { $result .= '<option value="' . $photo['id'] . '.' . $photo['ext'] . '" >' . $name . ' (' . wppa_get_album_name($photo['album']) . ')' . '</option>'; } else { $result .= '<option value="' . wppa_expand_id($photo['id']) . '.' . $photo['ext'] . '" >' . $name . ' (' . wppa_get_album_name($photo['album']) . ')' . '</option>'; } } $result .= '<option value="#last" >' . __('--- The most recently uploaded photo ---', 'wp-photo-album-plus') . '</option>' . '<option value="#potd" >' . __('--- The photo of the day ---', 'wp-photo-album-plus') . '</option>'; } else { $result .= '<option value="0" >' . __('There are no photos yet', 'wp-photo-album-plus') . '</option>'; } $result .= '</select>' . '<br />' . '<small style="display:none;" class="wppagallery-photo" >' . __('Specify the photo to be used', 'wp-photo-album-plus') . '<br />' . __('You can select from a maximum of 100 most recently added photos', 'wp-photo-album-plus') . '<br />' . '</small>' . '</td>' . '</tr>' . '<tr class="wppagallery-tags" style="display:none;" >' . '<th><label for="wppagallery-tags">' . __('The tags the photos should have:', 'wp-photo-album-plus') . '</label></th>' . '<td>' . '<select id="wppagallery-tags" multiple="multiple">' . '<option value="" >' . __('--- please select tag(s) ---', 'wp-photo-album-plus') . '</option>'; $tags = wppa_get_taglist(); if ($tags) { foreach (array_keys($tags) as $tag) { $result .= '<option value="' . $tag . '" >' . $tag . '</option>'; } } $result .= '</select>' . '<div><input type="checkbox" id="wppagallery-andor" /> <small>' . __('If you want that the photos have all the selected tags, check this box. Leave it unchecked if the photo must have atleast only one of the selected tags', 'wp-photo-album-plus') . '</small></div>' . '</td>' . '</tr>' . '<tr>' . '<th><label for="wppagallery-size">' . __('The size of the display:', 'wp-photo-album-plus') . '</label></th>' . '<td>' . '<input type="text" id="wppagallery-size" value="" />' . '<br />' . '<small>' . __('Specify the horizontal size in pixels or <span style="color:blue" >auto</span>.', 'wp-photo-album-plus') . ' ' . __('A value less than <span style="color:blue" >100</span> will automaticly be interpreted as a <span style="color:blue" >percentage</span> of the available space.', 'wp-photo-album-plus') . '<br />' . __('Leave this blank for default size', 'wp-photo-album-plus') . '</small>' . '</td>' . '</tr>' . '<tr>' . '<th><label for="wppagallery-align">' . __('Horizontal alignment:', 'wp-photo-album-plus') . '</label></th>' . '<td>' . '<select id="wppagallery-align" name="align" >' . '<option value="none" >' . __('--- none ---', 'wp-photo-album-plus') . '</option>' . '<option value="left" >' . __('left', 'wp-photo-album-plus') . '</option>' . '<option value="center" >' . __('center', 'wp-photo-album-plus') . '</option>' . '<option value="right" >' . __('right', 'wp-photo-album-plus') . '</option>' . '</select>' . '<br />' . '<small>' . __('Specify the alignment to be used or --- none ---', 'wp-photo-album-plus') . '</small>' . '</td>' . '</tr>' . '</table>' . '<p class="submit">' . '<input type="button" id="wppagallery-submit" class="button-primary" value="' . __('Insert Gallery', 'wp-photo-album-plus') . '" name="submit" /> ' . '</p>' . '</div>'; return $result; }
function wppa_check_memory_limit($verbose = true, $x = '0', $y = '0') { // ini_set( 'memory_limit', '18M' ); // testing if (!function_exists('memory_get_usage')) { return ''; } if (is_admin() && !wppa_switch('wppa_memcheck_admin')) { return ''; } if (!is_admin() && !wppa_switch('wppa_memcheck_frontend')) { return ''; } // get memory limit $memory_limit = 0; $memory_limini = wppa_convert_bytes(ini_get('memory_limit')); $memory_limcfg = wppa_convert_bytes(get_cfg_var('memory_limit')); // find the smallest not being zero if ($memory_limini && $memory_limcfg) { $memory_limit = min($memory_limini, $memory_limcfg); } elseif ($memory_limini) { $memory_limit = $memory_limini; } else { $memory_limit = $memory_limcfg; } // No data if (!$memory_limit) { return ''; } // Calculate the free memory $free_memory = $memory_limit - memory_get_usage(true); // Calculate number of pixels largest target resized image if (wppa_switch('wppa_resize_on_upload')) { $t = wppa_opt('wppa_resize_to'); if ($t == '0') { $to['0'] = wppa_opt('wppa_fullsize'); $to['1'] = wppa_opt('wppa_maxheight'); } else { $to = explode('x', $t); } $resizedpixels = $to['0'] * $to['1']; } else { $resizedpixels = wppa_get_minisize() * wppa_get_minisize() * 3 / 4; } // Number of bytes per pixel ( found by trial and error ) // $factor = '5.60'; // 5.60 for 17M: 386 x 289 ( 0.1 MP ) thumb only // $factor = '5.10'; // 5.10 for 104M: 4900 x 3675 ( 17.2 MP ) thumb only $memlimmb = $memory_limit / (1024 * 1024); $factor = '6.00' - '0.58' * ($memlimmb / 104); // 6.00 .. 0.58 // Calculate max size $maxpixels = $free_memory / $factor - $resizedpixels; // If obviously faulty: quit silently if ($maxpixels < 0) { return ''; } // What are we asked for? if ($x && $y) { // Request for check an image if ($x * $y <= $maxpixels) { $result = true; } else { $result = false; } } else { // Request for tel me what is the limit $maxx = sqrt($maxpixels / 12) * 4; $maxy = sqrt($maxpixels / 12) * 3; if ($verbose) { // Make it a string $result = '<br />' . sprintf(__('Based on your server memory limit you should not upload images larger then <strong>%d x %d (%2.1f MP)</strong>', 'wppa'), $maxx, $maxy, $maxpixels / (1024 * 1024)); } else { // Or an array $result['maxx'] = $maxx; $result['maxy'] = $maxy; $result['maxp'] = $maxpixels; } } return $result; }
function wppa_get_svghtml($name, $height = false, $lightbox = false, $border = false, $none = '0', $light = '10', $medium = '20', $heavy = '50') { // Find the colors if ($lightbox) { $fillcolor = wppa_opt('ovl_svg_color'); $bgcolor = wppa_opt('ovl_svg_bg_color'); } else { $fillcolor = wppa_opt('svg_color'); $bgcolor = wppa_opt('svg_bg_color'); } // Find the border radius switch (wppa_opt('icon_corner_style')) { case 'none': $bradius = $none; break; case 'light': $bradius = $light; break; case 'medium': $bradius = $medium; break; case 'heavy': $bradius = $heavy; break; } $is_ie = wppa_is_ie(); $src = $is_ie ? $name . '.png' : $name . '.svg'; // Compose the html $result = '<img' . ' src="' . wppa_get_imgdir($src) . '"' . ($is_ie ? '' : ' class="wppa-svg"') . ' style="' . ($height ? 'height:' . $height . ';' : '') . 'fill:' . $fillcolor . ';' . 'background-color:' . $bgcolor . ';' . ($is_ie ? '' : 'display:none;') . 'text-decoration:none !important;' . 'vertical-align:middle;' . ($bradius ? 'border-radius:' . $bradius . '%;' : '') . ($border ? 'border:2px solid ' . $bgcolor . ';box-sizing:border-box;' : '') . '"' . ' alt="' . $name . '"' . ' onload="wppaReplaceSvg()"' . ' />'; return $result; }
function wppa_import_dir_to_album($file, $parent) { global $photocount; global $wpdb; global $wppa_session; // Session should survive the default hour wppa_extend_session(); // see if album exists if (is_dir($file)) { // Check parent if (wppa_switch('import_parent_check')) { $alb = wppa_get_album_id(basename($file), $parent); // If parent = 0 ( top-level album ) and album not found, // try a 'separate' album ( i.e. parent = -1 ) with this name if (!$alb && $parent == '0') { $alb = wppa_get_album_id(basename($file), '-1'); } } else { $alb = wppa_get_album_id(basename($file), false); } if (!$alb) { // Album must be created $name = basename($file); $uplim = wppa_opt('upload_limit_count') . '/' . wppa_opt('upload_limit_time'); $alb = wppa_create_album_entry(array('name' => $name, 'a_parent' => $parent)); if ($alb === false) { wppa_error_message(__('Could not create album.', 'wp-photo-album-plus') . '<br/>Query = ' . $query); wp_die('Sorry, cannot continue'); } else { wppa_set_last_album($alb); wppa_flush_treecounts($alb); wppa_index_add('album', $alb); wppa_create_pl_htaccess(); wppa_ok_message(__('Album #', 'wp-photo-album-plus') . ' ' . $alb . ' ( ' . $name . ' ) ' . __('Added.', 'wp-photo-album-plus')); if (wppa_switch('newpag_create') && $parent <= '0') { // Create post object $my_post = array('post_title' => $name, 'post_content' => str_replace('w#album', $alb, wppa_opt('newpag_content')), 'post_status' => wppa_opt('newpag_status'), 'post_type' => wppa_opt('newpag_type')); // Insert the post into the database $pagid = wp_insert_post($my_post); if ($pagid) { wppa_ok_message(sprintf(__('Page <a href="%s" target="_blank" >%s</a> created.', 'wp-photo-album-plus'), home_url() . '?page_id=' . $pagid, $name)); $wpdb->query($wpdb->prepare("UPDATE `" . WPPA_ALBUMS . "` SET `cover_linkpage` = %s WHERE `id` = %s", $pagid, $alb)); } else { wppa_error_message(__('Could not create page.', 'wp-photo-album-plus')); } } } } // Now import the files $photofiles = glob($file . '/*'); if ($photofiles) { foreach ($photofiles as $photofile) { if (!is_dir($photofile)) { if (!isset($wppa_session[$photofile]) || !wppa_switch('keep_import_files')) { if (wppa_albumphoto_exists($alb, basename($photofile))) { if (!wppa_switch('keep_import_files')) { wppa_warning_message('Photo ' . basename($photofile) . ' already exists in album ' . $alb . '. Removed. (2)'); } } else { $bret = wppa_insert_photo($photofile, $alb, basename($photofile)); $photocount++; } if (!wppa_switch('keep_import_files')) { @unlink($photofile); } $wppa_session[$photofile] = true; } if (wppa_is_time_up($photocount)) { return false; } } } } // Now go deeper, process the subdirs $subdirs = glob($file . '/*'); if ($subdirs) { foreach ($subdirs as $subdir) { if (is_dir($subdir)) { if (basename($subdir) != '.' && basename($subdir) != '..') { $bret = wppa_import_dir_to_album($subdir, $alb); if (!$bret) { return false; } // Time out } } } } @rmdir($file); // Try to remove dir, ignore error } else { wppa_dbg_msg('Invalid file in wppa_import_dir_to_album(): ' . $file); return false; } return true; }
/** @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', 'topten'); wppa_bump_mocc(); extract($args); $instance = wp_parse_args((array) $instance, array('title' => '', 'sortby' => 'mean_rating', 'title' => '', 'album' => '', 'display' => 'thumbs', 'meanrat' => 'yes', 'ratcount' => 'yes', 'viewcount' => 'yes', 'includesubs' => 'yes', 'medalsonly' => 'no', 'showowner' => 'no', 'showalbum' => 'no')); $widget_title = apply_filters('widget_title', $instance['title']); $page = in_array(wppa_opt('topten_widget_linktype'), wppa('links_no_page')) ? '' : wppa_get_the_landing_page('topten_widget_linkpage', __('Top Ten Photos', 'wp-photo-album-plus')); $albumlinkpage = wppa_get_the_landing_page('topten_widget_album_linkpage', __('Top Ten Photo album', 'wp-photo-album-plus')); $max = wppa_opt('topten_count'); $album = $instance['album']; switch ($instance['sortby']) { case 'mean_rating': $sortby = '`mean_rating` DESC, `rating_count` DESC, `views` DESC'; break; case 'rating_count': $sortby = '`rating_count` DESC, `mean_rating` DESC, `views` DESC'; break; case 'views': $sortby = '`views` DESC, `mean_rating` DESC, `rating_count` DESC'; break; } $display = $instance['display']; $meanrat = $instance['meanrat'] == 'yes'; $ratcount = $instance['ratcount'] == 'yes'; $viewcount = $instance['viewcount'] == 'yes'; $includesubs = $instance['includesubs'] == 'yes'; $albenum = ''; $medalsonly = $instance['medalsonly'] == 'yes'; $showowner = $instance['showowner'] == 'yes'; $showalbum = $instance['showalbum'] == 'yes'; wppa('medals_only', $medalsonly); $likes = wppa_opt('rating_display_type') == 'likes'; // When likes only, mean rating has no meaning, chan to (rating)(like)count if ($likes && $instance['sortby'] == 'mean_rating') { $instance['sortby'] = 'rating_count'; } // Album specified? if ($album) { // All albums ? if ($album == '-2') { $album = '0'; } // Albums of owner is current logged in user or public? if ($album == '-3') { $temp = $wpdb->get_results("SELECT `id` FROM `" . WPPA_ALBUMS . "` WHERE `owner` = '--- public ---' OR `owner` = '" . wppa_get_user() . "' ORDER BY `id`", ARRAY_A); $album = ''; if ($temp) { foreach ($temp as $t) { $album .= '.' . $t['id']; } $album = ltrim($album, '.'); } } // Including subalbums? if ($includesubs) { $albenum = wppa_alb_to_enum_children($album); $albenum = wppa_expand_enum($albenum); $album = str_replace('.', ',', $albenum); } // Doit if ($medalsonly) { $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `album` IN (" . $album . ") " . "AND `status` IN ( 'gold', 'silver', 'bronze' ) " . "ORDER BY " . $sortby . " " . "LIMIT " . $max, ARRAY_A); } else { $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `album` IN (" . $album . ") " . "ORDER BY " . $sortby . " " . "LIMIT " . $max, ARRAY_A); } } else { if ($medalsonly) { $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` " . "WHERE `status` IN ( 'gold', 'silver', 'bronze' ) " . "ORDER BY " . $sortby . " " . "LIMIT " . $max, ARRAY_A); } else { $thumbs = $wpdb->get_results("SELECT * FROM `" . WPPA_PHOTOS . "` " . "ORDER BY " . $sortby . " " . "LIMIT " . $max, ARRAY_A); } } $widget_content = "\n" . '<!-- WPPA+ TopTen Widget start -->'; $maxw = wppa_opt('topten_size'); $maxh = $maxw; $lineheight = wppa_opt('fontsize_widget_thumb') * 1.5; $maxh += $lineheight; if ($meanrat) { $maxh += $lineheight; } if ($ratcount) { $maxh += $lineheight; } if ($viewcount) { $maxh += $lineheight; } if ($showowner) { $maxh += $lineheight; } if ($showalbum) { $maxh += $lineheight; } if ($thumbs) { foreach ($thumbs as $image) { $thumb = $image; // Make the HTML for current picture if ($display == 'thumbs') { $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">'; } else { $widget_content .= "\n" . '<div class="wppa-widget" >'; } if ($image) { $no_album = !$album; if ($no_album) { $tit = __('View the top rated photos', 'wp-photo-album-plus'); } else { $tit = esc_attr(__(stripslashes($image['description']))); } $compressed_albumenum = wppa_compress_enum($albenum); $link = wppa_get_imglnk_a('topten', $image['id'], '', $tit, '', $no_album, $compressed_albumenum); $file = wppa_get_thumb_path($image['id']); $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'ttthumb'); $imgurl = wppa_get_thumb_url($image['id'], '', $imgstyle_a['width'], $imgstyle_a['height']); $imgevents = wppa_get_imgevents('thumb', $image['id'], true); $title = $link ? esc_attr(stripslashes($link['title'])) : ''; $widget_content .= wppa_get_the_widget_thumb('topten', $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents); $widget_content .= "\n\t" . '<div style="font-size:' . wppa_opt('fontsize_widget_thumb') . 'px; line-height:' . $lineheight . 'px;">'; // Display (owner) ? if ($showowner) { $widget_content .= '<div>(' . $image['owner'] . ')</div>'; } // Display (album) ? if ($showalbum) { $href = wppa_convert_to_pretty(wppa_encrypt_url(wppa_get_album_url($image['album'], $albumlinkpage, 'content', '1'))); $widget_content .= '<div>(<a href="' . $href . '" >' . wppa_get_album_name($image['album']) . '</a>)</div>'; } // Display the rating if ($likes) { $lt = wppa_get_like_title_a($image['id']); } switch ($instance['sortby']) { case 'mean_rating': if ($meanrat == 'yes') { $widget_content .= '<div>' . wppa_get_rating_by_id($image['id']) . '</div>'; } if ($ratcount == 'yes') { $n = wppa_get_rating_count_by_id($image['id']); $widget_content .= '<div>' . sprintf(_n('%d vote', '%d votes', $n, 'wp-photo-album-plus'), $n) . '</div>'; } if ($viewcount == 'yes') { $n = $image['views']; $widget_content .= '<div>' . sprintf(_n('%d view', '%d views', $n, 'wp-photo-album-plus'), $n) . '</div>'; } break; case 'rating_count': if ($ratcount == 'yes') { $n = wppa_get_rating_count_by_id($image['id']); $widget_content .= '<div>' . ($likes ? $lt['display'] : sprintf(_n('%d vote', '%d votes', $n, 'wp-photo-album-plus'), $n)) . '</div>'; } if ($meanrat == 'yes') { $widget_content .= '<div>' . wppa_get_rating_by_id($image['id']) . '</div>'; } if ($viewcount == 'yes') { $n = $image['views']; $widget_content .= '<div>' . sprintf(_n('%d view', '%d views', $n, 'wp-photo-album-plus'), $n) . '</div>'; } break; case 'views': if ($viewcount == 'yes') { $n = $image['views']; $widget_content .= '<div>' . sprintf(_n('%d view', '%d views', $n, 'wp-photo-album-plus'), $n) . '</div>'; } if ($meanrat == 'yes') { $widget_content .= '<div>' . wppa_get_rating_by_id($image['id']) . '</div>'; } if ($ratcount == 'yes') { $n = wppa_get_rating_count_by_id($image['id']); $widget_content .= '<div>' . ($likes ? $lt['display'] : sprintf(_n('%d vote', '%d votes', $n, 'wp-photo-album-plus'), $n)) . '</div>'; } break; } $widget_content .= '</div>'; } else { // No image $widget_content .= __('Photo not found', 'wp-photo-album-plus'); } $widget_content .= "\n" . '</div>'; } } else { $widget_content .= __('There are no rated photos (yet)', 'wp-photo-album-plus'); } $widget_content .= '<div style="clear:both"></div>'; $widget_content .= "\n" . '<!-- WPPA+ TopTen 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 ); wppa_reset_occurrance(); }
function wppa_get_thumby($id, $force = false) { if (wppa_is_video($id)) { $x = wppa_get_videox($id); $y = wppa_get_videoy($id); if ($x > $y) { // Landscape $result = wppa_opt('thumbsize') * $y / $x; } else { $result = wppa_opt('thumbsize'); } } else { $result = wppa_get_thumbphotoxy($id, 'thumby', $force); } if (!$result && wppa_has_audio($id)) { $result = wppa_opt('thumbsize'); // * 1080 / 1920; $siz = getimagesize(WPPA_UPLOAD_PATH . '/' . wppa_opt('audiostub')); $result *= $siz['1'] / $siz['0']; } return $result; }
function wppa_theme() { global $wppa_version; $wppa_version = '6-1-15-000'; // The version number of this file global $wppa; global $wppa_show_statistics; // Can be set to true by a custom page template $curpage = wppa_get_curpage(); // Get the page # we are on when pagination is on, or 1 $didsome = false; // Required initializations for pagination $n_album_pages = '0'; // " $n_thumb_pages = '0'; // " // Open container wppa_container('open'); // Show statistics if set so by the page template if ($wppa_show_statistics) { wppa_statistics(); } // Display breadcrumb navigation only if it is set in the settings page wppa_breadcrumb('optional'); if (wppa_page('albums')) { // Page 'Albums' requested // Get the albums and the thumbs and the number of pages for each set $albums = wppa_get_albums(); // Get the albums $n_album_pages = wppa_get_npages('albums', $albums); // Get the number of album pages if (wppa_opt('thumbtype') != 'none') { $thumbs = wppa_get_thumbs(); // Get the Thumbs } else { $thumbs = false; } $wanted_empty = wppa_is_wanted_empty($thumbs); // See if we need to display an empty thumbnail area $n_thumb_pages = wppa_get_npages('thumbs', $thumbs); // Get the number of thumb pages if ($n_thumb_pages == '0' && !$wanted_empty) { $thumbs = false; } // No pages: no thumbs. Maybe want covers only if ($wanted_empty) { $n_thumb_pages = '1'; } // Get total number of pages if (!wppa_is_pagination()) { $totpag = '1'; } else { $totpag = $n_album_pages + $n_thumb_pages; } // Make pagelinkbar if requested on top if (wppa_opt('pagelink_pos') == 'top' || wppa_opt('pagelink_pos') == 'both') { wppa_page_links($totpag, $curpage); } // Process the albums if (!wppa_switch('wppa_thumbs_first')) { if ($albums) { $counter_albums = '0'; wppa_album_list('open'); // Open Albums sub-container foreach ($albums as $album) { // Loop the albums $counter_albums++; if (wppa_onpage('albums', $counter_albums, $curpage)) { wppa_album_cover($album['id']); // Show the cover $didsome = true; } // End if on page } wppa_album_list('close'); // Close Albums sub-container } // If albums } if ($didsome && wppa_is_pagination()) { $thumbs = false; } // Pag on and didsome: force a pagebreak by faking no thumbs if (count($thumbs) <= wppa_get_mincount() && !$wanted_empty) { $thumbs = false; } // Less than treshold value if (wppa_switch('wppa_thumbs_first') && $curpage > $n_thumb_pages) { $thumbs = false; } // If thumbs done, do not display an empty thumbarea // Process the thumbs if ($thumbs || $wanted_empty) { if (!$wanted_empty || !wppa_switch('thumbs_first') || wppa_get_curpage() == '1') { if (!$wanted_empty || wppa_switch('thumbs_first') || wppa_get_curpage() == $totpag) { // Init $counter_thumbs = '0'; // As covers if (wppa_opt('wppa_thumbtype') == 'ascovers' || wppa_opt('wppa_thumbtype') == 'ascovers-mcr') { // Do the thumbs As covers wppa_thumb_list('open'); // Open Thumblist sub-container $relpage = wppa_switch('wppa_thumbs_first') ? $curpage : $curpage - $n_album_pages; foreach ($thumbs as $tt) { global $thumb; $thumb = $tt; // Loop the Thumbs $counter_thumbs++; if (wppa_onpage('thumbs', $counter_thumbs, $relpage)) { $didsome = true; wppa_thumb_ascover($thumb['id']); // Show Thumb as cover } // End if on page } wppa_thumb_list('close'); // Close Thumblist sub-container } elseif (wppa_opt('wppa_thumbtype') == 'masonry-v') { // Masonry // The header wppa_thumb_area('open'); // Open Thumbarea sub-container wppa_popup(); // Prepare Popup box wppa_album_name('top'); // Optionally display album name wppa_album_desc('top'); // Optionally display album description // Init $relpage = wppa_switch('wppa_thumbs_first') ? $curpage : $curpage - $n_album_pages; $cont_width = wppa_get_container_width(); $count_cols = ceil($cont_width / (wppa_opt('wppa_thumbsize') + wppa_opt('wppa_tn_margin'))); $correction = wppa_opt('wppa_tn_margin') * ($cont_width / $count_cols) / 100; // Init the table wppa_out('<table class="wppa-masonry" style="margin-top:3px;" ><tbody class="wppa-masonry" ><tr class="wppa-masonry" >'); // Init the columns $col_headers = array(); $col_contents = array(); $col_heights = array(); $col_widths = array(); for ($col = 0; $col < $count_cols; $col++) { $col_headers[$col] = ''; $col_contents[$col] = ''; $col_heights[$col] = 0; $col_widths[$col] = 100; } // Process the thumbnails $col = '0'; if ($thumbs) { foreach ($thumbs as $tt) { $id = $tt['id']; $counter_thumbs++; if (wppa_onpage('thumbs', $counter_thumbs, $relpage)) { $col_contents[$col] .= wppa_get_thumb_masonry($id); $col_heights[$col] += ($correction + wppa_get_thumby($id)) / ($correction + wppa_get_thumbx($id)) * $col_widths[$col]; $col += '1'; if ($col == $count_cols) { $col = '0'; } $didsome = true; } } } // Find longest column $long = 0; for ($col = 0; $col < $count_cols; $col++) { if ($col_heights[$col] > $long) { $long = $col_heights[$col]; } } // Adjust column widths to resize lengths to equal lengths for ($col = 0; $col < $count_cols; $col++) { if ($col_heights[$col]) { $col_widths[$col] = $long / $col_heights[$col] * $col_widths[$col]; } } // Adjust column widths to total 100 $wide = 0; for ($col = 0; $col < $count_cols; $col++) { $wide += $col_widths[$col]; } for ($col = 0; $col < $count_cols; $col++) { $col_widths[$col] = $col_widths[$col] * 100 / $wide; } // Make column headers for ($col = 0; $col < $count_cols; $col++) { $col_headers[$col] = '<td style="width: ' . $col_widths[$col] . '%; vertical-align:top;" class="wppa-masonry" >'; } // Add the columns to the output stream for ($col = 0; $col < $count_cols; $col++) { wppa_out($col_headers[$col]); wppa_out($col_contents[$col]); wppa_out('</td>'); } // Close the table wppa_out('</tr></tbody></table>'); // The footer wppa_album_name('bottom'); // Optionally display album name wppa_album_desc('bottom'); // Optionally display album description wppa_thumb_area('close'); // Close Thumbarea sub-container } elseif (wppa_opt('wppa_thumbtype') == 'masonry-h') { // Masonry // The header wppa_thumb_area('open'); // Open Thumbarea sub-container wppa_popup(); // Prepare Popup box wppa_album_name('top'); // Optionally display album name wppa_album_desc('top'); // Optionally display album description // Init $relpage = wppa_switch('wppa_thumbs_first') ? $curpage : $curpage - $n_album_pages; $cont_width = wppa_get_container_width('netto'); $correction = wppa_opt('wppa_tn_margin'); // Init the table wppa_out('<table class="wppa-masonry" style="margin-top:3px;" ><tbody class="wppa-masonry" >'); // Process the thumbnails $row_content = ''; $row_width = 0; $target_row_height = wppa_opt('wppa_thumbsize') * 0.75 + $correction; $rw_count = 0; $tr_count = '1'; $done_count = 0; $last = false; $max_row_height = $target_row_height * 0.8; // Init keep track for last if ($thumbs) { foreach ($thumbs as $tt) { $id = $tt['id']; $counter_thumbs++; if (wppa_onpage('thumbs', $counter_thumbs, $relpage)) { $row_content .= wppa_get_thumb_masonry($tt['id']); $rw_count += 1; $row_width += wppa_get_thumbratioxy($id) * ($target_row_height - $correction); $didsome = true; } $done_count += 1; $last = $done_count == count($thumbs); if ($row_width > $cont_width || $last) { $tot_marg = $rw_count * $correction; $row_height = $row_width ? ($target_row_height - $correction) * ($cont_width - '3' - $tot_marg) / $row_width + $correction : '0'; if (!$last) { $max_row_height = max($max_row_height, $row_height); } if ($last && $row_height > wppa_get_thumby($id)) { $row_height = $max_row_height; } $row_height_p = $row_height / $cont_width * 100; wppa_out('<tr class="wppa-masonry" >' . '<td style="border:none;padding:0;margin:0" >' . '<div' . ' id="wppa-mas-h-' . $tr_count . '-' . wppa('mocc') . '"' . ' style="height:' . $row_height . 'px;"' . ' class="wppa-masonry"' . ' data-height-perc="' . $row_height_p . '"' . ' >'); wppa_out($row_content); wppa_out('</div></td></tr>'); $row_content = ''; $row_width = 0; $row_height = wppa_opt('wppa_thumbsize'); $rw_count = 0; $tr_count += '1'; } } } wppa_out('</tbody></table>'); // The footer wppa_album_name('bottom'); // Optionally display album name wppa_album_desc('bottom'); // Optionally display album description wppa_thumb_area('close'); // Close Thumbarea sub-container } elseif (wppa_opt('wppa_thumbtype') == 'default') { // Do the thumbs As default // The header wppa_thumb_area('open'); // Open Thumbarea sub-container wppa_popup(); // Prepare Popup box wppa_album_name('top'); // Optionally display album name wppa_album_desc('top'); // Optionally display album description // Init $relpage = wppa_switch('wppa_thumbs_first') ? $curpage : $curpage - $n_album_pages; // Process the thumbnails if ($thumbs) { foreach ($thumbs as $tt) { $counter_thumbs++; if (wppa_onpage('thumbs', $counter_thumbs, $relpage)) { $didsome = true; wppa_thumb_default($tt['id']); // Show Thumb as default } // End if on page } } // The footer wppa_album_name('bottom'); // Optionally display album name wppa_album_desc('bottom'); // Optionally display album description wppa_thumb_area('close'); // Close Thumbarea sub-container } else { wppa_out('Unimplemented thumbnail type'); } } } } // If thumbs if ($didsome && wppa_is_pagination()) { $albums = false; } // Pag on and didsome: force a pagebreak by faking no albums if (!wppa_is_pagination()) { $n_thumb_pages = '0'; } // Still on page one // Process the albums if (wppa_switch('wppa_thumbs_first')) { if ($albums) { $counter_albums = '0'; wppa_album_list('open'); // Open Albums sub-container foreach ($albums as $album) { // Loop the albums $counter_albums++; if (wppa_onpage('albums', $counter_albums, $curpage - $n_thumb_pages)) { wppa_album_cover($album['id']); // Show the cover $didsome = true; } // End if on page } wppa_album_list('close'); // Close Albums sub-container } // If albums } // Make pagelinkbar if requested on bottom if (wppa_opt('pagelink_pos') == 'bottom' || wppa_opt('pagelink_pos') == 'both') { wppa_page_links($totpag, $curpage); } // Empty results? if (!$didsome && !$wanted_empty) { if (wppa('photos_only')) { wppa_out(wppa_errorbox(__a('No photos found matching your search criteria.', 'wppa_theme'))); } elseif (wppa('albums_only')) { wppa_out(wppa_errorbox(__a('No albums found matching your search criteria.', 'wppa_theme'))); } else { wppa_out(wppa_errorbox(__a('No albums or photos found matching your search criteria.', 'wppa_theme'))); } } } elseif (wppa_page('slide') || wppa_page('single')) { // Page 'Slideshow' or 'Single' in browsemode requested $thumbs = wppa_get_thumbs(); wppa_dbg_msg('From theme: #thumbs=' . ($thumbs ? count($thumbs) : '0')); if ($thumbs) { wppa_the_slideshow(); // Producs all the html required for the slideshow wppa_run_slidecontainer('slideshow'); // Fill in the photo array and display it. } else { wppa_out(wppa_errorbox(__a('No photos found matching your search criteria.', 'wppa_theme'))); } } // wppa_page( 'slide' ) // Close container wppa_container('close'); }
function wppa_create_thumbnail($id, $use_source = true) { // Find file to make thumbnail from $source_path = wppa_fix_poster_ext(wppa_get_source_path($id), $id); // Use source if requested and available if ($use_source) { if (!wppa_switch('watermark_thumbs') && is_file($source_path)) { $file = $source_path; // Use sourcefile } else { $file = wppa_fix_poster_ext(wppa_get_photo_path($id), $id); // Use photofile } // Non standard orientation files: never use source $orient = wppa_get_exif_orientation($file); if ($orient > '1') { $file = wppa_fix_poster_ext(wppa_get_photo_path($id), $id); // Use photofile } } else { $file = wppa_fix_poster_ext(wppa_get_photo_path($id), $id); // Use photofile } // Max side $max_side = wppa_get_minisize(); // Check file if (!file_exists($file)) { return false; } // No file, fail $img_attr = getimagesize($file); if (!$img_attr) { return false; } // Not an image, fail // Retrieve aspect $asp_attr = explode(':', wppa_opt('thumb_aspect')); // Get output path $thumbpath = wppa_get_thumb_path($id); if (wppa_get_ext($thumbpath) == 'xxx') { // Video poster $thumbpath = wppa_strip_ext($thumbpath) . '.jpg'; } // Source size $src_size_w = $img_attr[0]; $src_size_h = $img_attr[1]; // Temp convert width if stereo if (wppa_get_photo_item($id, 'stereo')) { $src_size_w /= 2; } // Mime type and thumb type $mime = $img_attr[2]; $type = $asp_attr[2]; // Source native aspect $src_asp = $src_size_h / $src_size_w; // Required aspect if ($type == 'none') { $dst_asp = $src_asp; } else { $dst_asp = $asp_attr[0] / $asp_attr[1]; } // Convert back width if stereo if (wppa_get_photo_item($id, 'stereo')) { $src_size_w *= 2; } // Create the source image switch ($mime) { // mime type case 1: // gif $temp = @imagecreatefromgif($file); if ($temp) { $src = imagecreatetruecolor($src_size_w, $src_size_h); imagecopy($src, $temp, 0, 0, 0, 0, $src_size_w, $src_size_h); 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 creating thmbnail'); return true; } // Compute the destination image size if ($dst_asp < 1.0) { // Landscape $dst_size_w = $max_side; $dst_size_h = round($max_side * $dst_asp); } else { // Portrait $dst_size_w = round($max_side / $dst_asp); $dst_size_h = $max_side; } // Create the ( empty ) destination image $dst = imagecreatetruecolor($dst_size_w, $dst_size_h); if ($mime == 3) { // Png, save transparancy imagealphablending($dst, false); imagesavealpha($dst, true); } // Fill with the required color $c = trim(strtolower(wppa_opt('bgcolor_thumbnail'))); if ($c != '#000000') { $r = hexdec(substr($c, 1, 2)); $g = hexdec(substr($c, 3, 2)); $b = hexdec(substr($c, 5, 2)); $color = imagecolorallocate($dst, $r, $g, $b); if ($color === false) { wppa_log('Err', 'Unable to set background color to: ' . $r . ', ' . $g . ', ' . $b . ' in wppa_create_thumbnail'); } else { imagefilledrectangle($dst, 0, 0, $dst_size_w, $dst_size_h, $color); } } // Switch on what we have to do switch ($type) { case 'none': // Use aspect from fullsize image $src_x = 0; $src_y = 0; $src_w = $src_size_w; $src_h = $src_size_h; $dst_x = 0; $dst_y = 0; $dst_w = $dst_size_w; $dst_h = $dst_size_h; break; case 'clip': // Clip image to given aspect ratio if ($src_asp < $dst_asp) { // Source image more landscape than destination $dst_x = 0; $dst_y = 0; $dst_w = $dst_size_w; $dst_h = $dst_size_h; $src_x = round(($src_size_w - $src_size_h / $dst_asp) / 2); $src_y = 0; $src_w = round($src_size_h / $dst_asp); $src_h = $src_size_h; } else { $dst_x = 0; $dst_y = 0; $dst_w = $dst_size_w; $dst_h = $dst_size_h; $src_x = 0; $src_y = round(($src_size_h - $src_size_w * $dst_asp) / 2); $src_w = $src_size_w; $src_h = round($src_size_w * $dst_asp); } break; case 'padd': // Padd image to given aspect ratio if ($src_asp < $dst_asp) { // Source image more landscape than destination $dst_x = 0; $dst_y = round(($dst_size_h - $dst_size_w * $src_asp) / 2); $dst_w = $dst_size_w; $dst_h = round($dst_size_w * $src_asp); $src_x = 0; $src_y = 0; $src_w = $src_size_w; $src_h = $src_size_h; } else { $dst_x = round(($dst_size_w - $dst_size_h / $src_asp) / 2); $dst_y = 0; $dst_w = round($dst_size_h / $src_asp); $dst_h = $dst_size_h; $src_x = 0; $src_y = 0; $src_w = $src_size_w; $src_h = $src_size_h; } break; default: // Not implemented return false; } // Copy left half if stereo if (wppa_get_photo_item($id, 'stereo')) { $src_w /= 2; } // Do the copy imagecopyresampled($dst, $src, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h); // Save the thumb $thumbpath = wppa_strip_ext($thumbpath); switch ($mime) { // mime type case 1: $full_thumbpath = $thumbpath . '.gif'; imagegif($dst, $full_thumbpath); break; case 2: $full_thumbpath = $thumbpath . '.jpg'; imagejpeg($dst, $full_thumbpath, wppa_opt('jpeg_quality')); break; case 3: $full_thumbpath = $thumbpath . '.png'; imagepng($dst, $full_thumbpath, 6); break; } // Cleanup imagedestroy($src); imagedestroy($dst); // Make sure file is accessable wppa_chmod($full_thumbpath); // Optimize wppa_optimize_image_file($full_thumbpath); // Compute and save sizes wppa_get_thumbx($id, 'force'); // forces recalc x and y return true; }
function wppa_get_potd() { global $wpdb; global $thumb; $image = ''; switch (wppa_opt('wppa_widget_method')) { case '1': // Fixed photo $id = wppa_opt('wppa_widget_photo'); if ($id != '') { $image = $wpdb->get_row($wpdb->prepare("SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `id` = %s LIMIT 0,1", $id), ARRAY_A); wppa_dbg_q('Q-Potd'); wppa_cache_photo('add', $image); } break; case '2': // Random $album = wppa_opt('wppa_widget_album'); if ($album == 'topten') { $images = wppa_get_widgetphotos($album); if (count($images) > 1) { // Select a random first from the current selection $idx = rand(0, count($images) - 1); $image = $images[$idx]; } } elseif ($album != '') { $images = wppa_get_widgetphotos($album, "ORDER BY RAND() LIMIT 0,1"); $image = $images[0]; } break; case '3': // Last upload $album = wppa_opt('wppa_widget_album'); if ($album == 'topten') { $images = wppa_get_widgetphotos($album); if ($images) { // fid last uploaded image in the $images pool $temp = 0; foreach ($images as $img) { if ($img['timestamp'] > $temp) { $temp = $img['timestamp']; $image = $img; } } } } elseif ($album != '') { $images = wppa_get_widgetphotos($album, "ORDER BY timestamp DESC LIMIT 0,1"); $image = $images[0]; } break; case '4': // Change every $album = wppa_opt('wppa_widget_album'); if ($album != '') { $per = wppa_opt('wppa_widget_period'); $photos = wppa_get_widgetphotos($album); if ($per == '0') { if ($photos) { $image = $photos[rand(0, count($photos) - 1)]; } else { $image = ''; } } elseif ($per == 'day-of-week') { $image = ''; if ($photos) { $d = wppa_local_date('w'); if (!$d) { $d = '7'; } foreach ($photos as $img) { if ($img['p_order'] == $d) { $image = $img; } } } } elseif ($per == 'day-of-month') { $image = ''; if ($photos) { $d = wppa_local_date('d'); if (substr($d, '0', '1') == '0') { $d = substr($d, '1'); } foreach ($photos as $img) { if ($img['p_order'] == $d) { $image = $img; } } } } else { $u = date("U"); // Seconds since 1-1-1970 $u /= 3600; // hours since $u = floor($u); $u /= $per; $u = floor($u); if ($photos) { $p = count($photos); $idn = fmod($u, $p); $image = $photos[$idn]; } else { $image = ''; } } } else { $image = ''; } break; default: $image = ''; } $thumb = $image; return $image; }
/** @see WP_Widget::widget */ function widget($args, $instance) { global $wpdb; global $wppa_opt; 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', 'lasten'); wppa_bump_mocc(); extract($args); $instance = wp_parse_args((array) $instance, array('title' => '', 'album' => '', 'albumenum' => '', 'timesince' => 'yes', 'display' => 'thumbs', 'includesubs' => 'no')); $widget_title = apply_filters('widget_title', $instance['title']); $page = in_array(wppa_opt('lasten_widget_linktype'), wppa('links_no_page')) ? '' : wppa_get_the_landing_page('lasten_widget_linkpage', __('Last Ten Uploaded Photos', 'wp-photo-album-plus')); $max = wppa_opt('lasten_count'); $album = $instance['album']; $timesince = $instance['timesince']; $display = $instance['display']; $albumenum = $instance['albumenum']; $subs = $instance['includesubs'] == 'yes'; switch ($album) { case '-99': // 'Multiple see below' is a list of id, seperated by comma's $album = str_replace(',', '.', $albumenum); if ($subs) { $album = wppa_expand_enum(wppa_alb_to_enum_children($album)); } $album = str_replace('.', ',', $album); break; case '0': // ---all--- break; case '-2': // ---generic--- $albs = $wpdb->get_results("SELECT `id` FROM `" . WPPA_ALBUMS . "` WHERE `a_parent` = '0'", ARRAY_A); $album = ''; foreach ($albs as $alb) { $album .= '.' . $alb['id']; } $album = ltrim($album, '.'); if ($subs) { $album = wppa_expand_enum(wppa_alb_to_enum_children($album)); } $album = str_replace('.', ',', $album); break; default: if ($subs) { $album = wppa_expand_enum(wppa_alb_to_enum_children($album)); $album = str_replace('.', ',', $album); } break; } $album = trim($album, ','); // Eiter look at timestamp or at date/time modified $order_by = wppa_switch('lasten_use_modified') ? 'modified' : 'timestamp'; // If you want only 'New' photos in the selection, the period must be <> 0; if (wppa_switch('lasten_limit_new') && wppa_opt('max_photo_newtime')) { $newtime = " `" . $order_by . "` >= " . (time() - wppa_opt('max_photo_newtime')); if ($album) { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE (" . $newtime . ") AND `album` IN ( " . $album . " ) AND ( `status` <> 'pending' AND `status` <> 'scheduled' ) ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } else { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE (" . $newtime . ") AND `status` <> 'pending' AND `status` <> 'scheduled' ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } } else { if ($album) { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `album` IN ( " . $album . " ) AND ( `status` <> 'pending' AND `status` <> 'scheduled' ) ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } else { $q = "SELECT * FROM `" . WPPA_PHOTOS . "` WHERE `status` <> 'pending' AND `status` <> 'scheduled' ORDER BY `" . $order_by . "` DESC LIMIT " . $max; } } $thumbs = $wpdb->get_results($q, ARRAY_A); $widget_content = "\n" . '<!-- WPPA+ LasTen Widget start -->'; $maxw = wppa_opt('lasten_size'); $maxh = $maxw; $lineheight = wppa_opt('fontsize_widget_thumb') * 1.5; $maxh += $lineheight; if ($timesince == 'yes') { $maxh += $lineheight; } $count = '0'; if ($thumbs) { foreach ($thumbs as $image) { $thumb = $image; // Make the HTML for current picture if ($display == 'thumbs') { $widget_content .= "\n" . '<div class="wppa-widget" style="width:' . $maxw . 'px; height:' . $maxh . 'px; margin:4px; display:inline; text-align:center; float:left;">'; } else { $widget_content .= "\n" . '<div class="wppa-widget" >'; } if ($image) { $no_album = !$album; if ($no_album) { $tit = __('View the most recent uploaded photos', 'wp-photo-album-plus'); } else { $tit = esc_attr(__(stripslashes($image['description']))); } $link = wppa_get_imglnk_a('lasten', $image['id'], '', $tit, '', $no_album, str_replace(',', '.', $album)); $file = wppa_get_thumb_path($image['id']); $imgstyle_a = wppa_get_imgstyle_a($image['id'], $file, $maxw, 'center', 'ltthumb'); $imgurl = wppa_get_thumb_url($image['id'], '', $imgstyle_a['width'], $imgstyle_a['height']); $imgevents = wppa_get_imgevents('thumb', $image['id'], true); $title = $link ? esc_attr(stripslashes($link['title'])) : ''; $widget_content .= wppa_get_the_widget_thumb('lasten', $image, $album, $display, $link, $title, $imgurl, $imgstyle_a, $imgevents); $widget_content .= "\n\t" . '<div style="font-size:' . wppa_opt('fontsize_widget_thumb') . 'px; line-height:' . $lineheight . 'px;">'; if ($timesince == 'yes') { $widget_content .= "\n\t" . '<div>' . wppa_get_time_since($image[$order_by]) . '</div>'; } $widget_content .= '</div>'; } else { // No image $widget_content .= __('Photo not found', 'wp-photo-album-plus'); } $widget_content .= "\n" . '</div>'; $count++; if ($count == wppa_opt('lasten_count')) { break; } } } else { $widget_content .= __('There are no uploaded photos (yet)', 'wp-photo-album-plus'); } $widget_content .= '<div style="clear:both"></div>'; $widget_content .= "\n" . '<!-- WPPA+ LasTen 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); }
function wppa_get_ss_to_tn_link($page = '0', $id = '0') { global $thumbs; global $thumbs_ids; // Search ? if (wppa('src') && wppa('mocc') == '1' && !wppa('is_related')) { $thumbhref = wppa_get_permalink($page) . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-searchstring=' . stripslashes(wppa('searchstring')); } elseif (wppa('is_upldr')) { if (wppa('start_album')) { $thumbhref = wppa_get_permalink($page) . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-upldr=' . wppa('is_upldr') . '&wppa-album=' . wppa('start_album'); } else { $thumbhref = wppa_get_permalink($page) . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-upldr=' . wppa('is_upldr'); } } elseif (wppa('is_topten')) { $thumbhref = wppa_get_permalink($page) . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-topten=' . wppa('topten_count') . '&wppa-album=' . wppa('start_album'); } elseif (wppa('is_lasten')) { $thumbhref = wppa_get_permalink($page) . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-lasten=' . wppa('lasten_count') . '&wppa-album=' . wppa('start_album'); } elseif (wppa('is_comten')) { $thumbhref = wppa_get_permalink($page) . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-comten=' . wppa('comten_count') . '&wppa-album=' . wppa('start_album'); } elseif (wppa('is_featen')) { $thumbhref = wppa_get_permalink($page) . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-featen=' . wppa('featen_count') . '&wppa-album=' . wppa('start_album'); } elseif (wppa('is_tag')) { $thumbhref = wppa_get_permalink($page) . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-tag=' . wppa('is_tag') . '&wppa-album=' . wppa('start_album'); } elseif (wppa('is_cat')) { $thumbhref = wppa_get_permalink($page) . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-cat=' . wppa('is_cat') . '&wppa-album=' . wppa('start_album'); } else { $thumbhref = wppa_get_permalink($page) . 'wppa-cover=0&wppa-occur=' . wppa('occur') . '&wppa-album=' . wppa('start_album'); } // $id is the id. See to what page we have to go $page = '1'; $p = wppa_opt('thumb_page_size'); if ($p) { $i = '0'; foreach ($thumbs_ids as $ti) { // $thumbs_ids is setup in function wppa_prepare_slideshow_pagination() if ($id == $ti) { $page = floor($i / $p) + '1'; } $i++; } if ($page > '1') { $thumbhref .= '&wppa-page=' . $page; } } // Make sure the clicked photos thumb is highligted $thumbhref .= '&wppa-hilite=' . $id; $thumbhref = wppa_convert_to_pretty(wppa_trim_wppa_($thumbhref)); return $thumbhref; }
function wppa_set_shortcode_priority() { $newpri = wppa_opt('wppa_shortcode_priority'); if ($newpri == '11') { return; } // Default, do not change $oldpri = has_filter('the_content', 'do_shortcode'); if ($oldpri) { remove_filter('the_content', 'do_shortcode', $oldpri); add_filter('the_content', 'do_shortcode', $newpri); } }
/** @see WP_Widget::form */ function form($instance) { //Defaults $instance = wp_parse_args((array) $instance, array('title' => __('Sidebar Slideshow', 'wp-photo-album-plus'), 'album' => '', 'width' => wppa_opt('widget_width'), 'height' => round(wppa_opt('widget_width') * wppa_opt('maxheight') / wppa_opt('fullsize')), 'ponly' => 'no', 'linkurl' => '', 'linktitle' => '', 'subtext' => '', 'supertext' => '', 'valign' => 'center', 'timeout' => '4', 'film' => 'no', 'browse' => 'no', 'name' => 'no', 'numbar' => 'no', 'desc' => 'no')); $title = esc_attr($instance['title']); $album = $instance['album']; $width = $instance['width']; $height = $instance['height']; $ponly = $instance['ponly']; $linkurl = $instance['linkurl']; $linktitle = $instance['linktitle']; $supertext = $instance['supertext']; $subtext = $instance['subtext']; $valign = $instance['valign']; $timeout = $instance['timeout']; $film = $instance['film']; $browse = $instance['browse']; $name = $instance['name']; $numbar = $instance['numbar']; $desc = $instance['desc']; ?> <p><label for="<?php echo $this->get_field_id('title'); ?> "><?php _e('Title:', 'wp-photo-album-plus'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('title'); ?> " name="<?php echo $this->get_field_name('title'); ?> " type="text" value="<?php echo $title; ?> " /></p> <p><label for="<?php echo $this->get_field_id('album'); ?> "><?php _e('Album:', 'wp-photo-album-plus'); ?> </label> <select class="widefat" id="<?php echo $this->get_field_id('album'); ?> " name="<?php echo $this->get_field_name('album'); ?> "><?php echo '<option value="-2">' . __('--- all ---', 'wp-photo-album-plus') . '</option>' . wppa_album_select_a(array('selected' => $album, 'path' => wppa_switch('wppa_hier_albsel'))); ?> </select></p> <p><?php _e('Enter the width and optionally the height of the area wherein the slides will appear. If you specify a 0 for the height, it will be calculated. The value for the height will be ignored if you set the vertical alignment to \'fit\'.', 'wp-photo-album-plus'); ?> </p> <p><label for="<?php echo $this->get_field_id('width'); ?> "><?php _e('Width:', 'wp-photo-album-plus'); ?> </label> <input class="widefat" style="width:15%;" id="<?php echo $this->get_field_id('width'); ?> " name="<?php echo $this->get_field_name('width'); ?> " type="text" value="<?php echo $width; ?> " /> <?php _e('pixels.', 'wp-photo-album-plus'); ?> <label for="<?php echo $this->get_field_id('height'); ?> "><?php _e('Height:', 'wp-photo-album-plus'); ?> </label> <input class="widefat" style="width:15%;" id="<?php echo $this->get_field_id('height'); ?> " name="<?php echo $this->get_field_name('height'); ?> " type="text" value="<?php echo $height; ?> " /> <?php _e('pixels.', 'wp-photo-album-plus'); ?> </p> <p> <?php _e('Portrait only:', 'wp-photo-album-plus'); ?> <select id="<?php echo $this->get_field_id('ponly'); ?> " name="<?php echo $this->get_field_name('ponly'); ?> "> <option value="no" <?php if ($ponly == 'no') { echo 'selected="selected"'; } ?> ><?php _e('no.', 'wp-photo-album-plus'); ?> </option> <option value="yes" <?php if ($ponly == 'yes') { echo 'selected="selected"'; } ?> ><?php _e('yes.', 'wp-photo-album-plus'); ?> </option> </select> <?php _e('Set to \'yes\' if there are only portrait images in the album and you want the photos to fill the full width of the widget.<br/>Set to \'no\' otherwise.', 'wp-photo-album-plus'); ?> <?php _e('If set to \'yes\', Vertical alignment will be forced to \'fit\'.', 'wp-photo-album-plus'); ?> </p> <p> <?php _e('Vertical alignment:', 'wp-photo-album-plus'); ?> <select id="<?php echo $this->get_field_id('valign'); ?> " name="<?php echo $this->get_field_name('valign'); ?> "> <option value="top" <?php if ($valign == 'top') { echo ' selected '; } ?> ><?php _e('top', 'wp-photo-album-plus'); ?> </option> <option value="center" <?php if ($valign == 'center') { echo ' selected '; } ?> ><?php _e('center', 'wp-photo-album-plus'); ?> </option> <option value="bottom" <?php if ($valign == 'bottom') { echo ' selected '; } ?> ><?php _e('bottom', 'wp-photo-album-plus'); ?> </option> <option value="fit" <?php if ($valign == 'fit') { echo ' selected '; } ?> ><?php _e('fit', 'wp-photo-album-plus'); ?> </option> </select><br/><?php _e('Set the desired vertical alignment method.', 'wp-photo-album-plus'); ?> </p> <p><label for="<?php echo $this->get_field_id('timeout'); ?> "><?php _e('Slideshow timeout:', 'wp-photo-album-plus'); ?> </label> <input class="widefat" style="width:15%;" id="<?php echo $this->get_field_id('timeout'); ?> " name="<?php echo $this->get_field_name('timeout'); ?> " type="text" value="<?php echo $timeout; ?> " /> <?php _e('sec.', 'wp-photo-album-plus'); ?> </p> <p><label for="<?php echo $this->get_field_id('linkurl'); ?> "><?php _e('Link to:', 'wp-photo-album-plus'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('linkurl'); ?> " name="<?php echo $this->get_field_name('linkurl'); ?> " type="text" value="<?php echo $linkurl; ?> " /></p> <p> <?php _e('Show name:', 'wp-photo-album-plus'); ?> <select id="<?php echo $this->get_field_id('name'); ?> " name="<?php echo $this->get_field_name('name'); ?> "> <option value="no" <?php if ($name == 'no') { echo 'selected="selected"'; } ?> ><?php _e('no.', 'wp-photo-album-plus'); ?> </option> <option value="yes" <?php if ($name == 'yes') { echo 'selected="selected"'; } ?> ><?php _e('yes.', 'wp-photo-album-plus'); ?> </option> </select> </p> <p> <?php _e('Show description:', 'wp-photo-album-plus'); ?> <select id="<?php echo $this->get_field_id('desc'); ?> " name="<?php echo $this->get_field_name('desc'); ?> "> <option value="no" <?php if ($desc == 'no') { echo 'selected="selected"'; } ?> ><?php _e('no.', 'wp-photo-album-plus'); ?> </option> <option value="yes" <?php if ($desc == 'yes') { echo 'selected="selected"'; } ?> ><?php _e('yes.', 'wp-photo-album-plus'); ?> </option> </select> </p> <p> <?php _e('Show filmstrip:', 'wp-photo-album-plus'); ?> <select id="<?php echo $this->get_field_id('film'); ?> " name="<?php echo $this->get_field_name('film'); ?> "> <option value="no" <?php if ($film == 'no') { echo 'selected="selected"'; } ?> ><?php _e('no.', 'wp-photo-album-plus'); ?> </option> <option value="yes" <?php if ($film == 'yes') { echo 'selected="selected"'; } ?> ><?php _e('yes.', 'wp-photo-album-plus'); ?> </option> </select> </p> <p> <?php _e('Show browsebar:', 'wp-photo-album-plus'); ?> <select id="<?php echo $this->get_field_id('browse'); ?> " name="<?php echo $this->get_field_name('browse'); ?> "> <option value="no" <?php if ($browse == 'no') { echo 'selected="selected"'; } ?> ><?php _e('no.', 'wp-photo-album-plus'); ?> </option> <option value="yes" <?php if ($browse == 'yes') { echo 'selected="selected"'; } ?> ><?php _e('yes.', 'wp-photo-album-plus'); ?> </option> </select> </p> <p> <?php _e('Show numbar:', 'wp-photo-album-plus'); ?> <select id="<?php echo $this->get_field_id('numbar'); ?> " name="<?php echo $this->get_field_name('numbar'); ?> "> <option value="no" <?php if ($numbar == 'no') { echo 'selected="selected"'; } ?> ><?php _e('no.', 'wp-photo-album-plus'); ?> </option> <option value="yes" <?php if ($numbar == 'yes') { echo 'selected="selected"'; } ?> ><?php _e('yes.', 'wp-photo-album-plus'); ?> </option> </select> </p> <p><span style="color:blue"><small><?php _e('The following text fields support qTranslate', 'wp-photo-album-plus'); ?> </small></span></p> <p><label for="<?php echo $this->get_field_id('linktitle'); ?> "><?php _e('Tooltip text:', 'wp-photo-album-plus'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('linktitle'); ?> " name="<?php echo $this->get_field_name('linktitle'); ?> " type="text" value="<?php echo $linktitle; ?> " /></p> <p><label for="<?php echo $this->get_field_id('supertext'); ?> "><?php _e('Text above photos:', 'wp-photo-album-plus'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('supertext'); ?> " name="<?php echo $this->get_field_name('supertext'); ?> " type="text" value="<?php echo $supertext; ?> " /></p> <p><label for="<?php echo $this->get_field_id('subtext'); ?> "><?php _e('Text below photos:', 'wp-photo-album-plus'); ?> </label> <input class="widefat" id="<?php echo $this->get_field_id('subtext'); ?> " name="<?php echo $this->get_field_name('subtext'); ?> " type="text" value="<?php echo $subtext; ?> " /></p> <?php }