function wppa_flush_upldr_cache($key = '', $id = '') { $upldrcache = wppa_get_upldr_cache(); foreach (array_keys($upldrcache) as $widget_id) { switch ($key) { case 'widgetid': if ($id == $widget_id) { unset($upldrcache[$widget_id]); } case 'photoid': $usr = wppa_get_photo_item($id, 'owner'); if (isset($upldrcache[$widget_id][$usr])) { unset($upldrcache[$widget_id][$usr]); } break; case 'username': $usr = $id; if (isset($upldrcache[$widget_id][$usr])) { unset($upldrcache[$widget_id][$usr]); } break; case 'all': $upldrcache = array(); break; default: wppa_dbg_msg('Missing key in wppa_flush_upldr_cache()', 'red'); break; } } update_option('wppa_upldr_cache', $upldrcache); }
/** @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', 'upldr'); wppa_bump_mocc(); extract($args); $instance = wp_parse_args((array) $instance, array('title' => '', 'sortby' => 'name', 'ignore' => 'admin', 'parent' => '')); $widget_title = apply_filters('widget_title', $instance['title']); $page = in_array('album', wppa('links_no_page')) ? '' : wppa_get_the_landing_page('wppa_upldr_widget_linkpage', __('User uploaded photos', 'wp-photo-album-plus')); $ignorelist = explode(',', $instance['ignore']); $upldrcache = wppa_get_upldr_cache(); $needupdate = false; $users = wppa_get_users(); $workarr = array(); $selalbs = str_replace('.', ',', wppa_expand_enum(wppa_alb_to_enum_children(wppa_expand_enum($instance['parent'])))); // Make the data we need if ($users) { foreach ($users as $user) { if (!in_array($user['user_login'], $ignorelist)) { $me = wppa_get_user(); if ($user['user_login'] != $me && isset($upldrcache[$this->get_widget_id()][$user['user_login']]['c'])) { $photo_count = $upldrcache[$this->get_widget_id()][$user['user_login']]['c']; } else { if ($instance['parent']) { $query = $wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `owner` = %s AND `album` IN (" . $selalbs . ") AND ( ( `status` <> 'pending' AND `status` <> 'scheduled' ) OR `owner` = %s )", $user['user_login'], $me); //); } else { $query = $wpdb->prepare("SELECT COUNT(*) FROM `" . WPPA_PHOTOS . "` WHERE `owner` = %s AND ( ( `status` <> 'pending' AND `status` <> 'scheduled' ) OR `owner` = %s )", $user['user_login'], $me); //); } $photo_count = $wpdb->get_var($query); if ($user['user_login'] != $me) { $upldrcache[$this->get_widget_id()][$user['user_login']]['c'] = $photo_count; $needupdate = true; } } if ($photo_count) { if ($user['user_login'] != $me && isset($upldrcache[$this->get_widget_id()][$user['user_login']]['d'])) { $last_dtm = $upldrcache[$this->get_widget_id()][$user['user_login']]['d']; } else { if ($instance['parent']) { $last_dtm = $wpdb->get_var($wpdb->prepare("SELECT `timestamp` FROM `" . WPPA_PHOTOS . "` WHERE `owner` = %s AND `album` IN (" . $selalbs . ") AND ( ( `status` <> 'pending' AND `status` <> 'scheduled' ) OR `owner` = %s ) ORDER BY `timestamp` DESC LIMIT 1", $user['user_login'], $me)); } else { $last_dtm = $wpdb->get_var($wpdb->prepare("SELECT `timestamp` FROM `" . WPPA_PHOTOS . "` WHERE `owner` = %s AND ( ( `status` <> 'pending' AND `status` <> 'scheduled' ) OR `owner` = %s ) ORDER BY `timestamp` DESC LIMIT 1", $user['user_login'], $me)); } } if ($user['user_login'] != $me) { $upldrcache[$this->get_widget_id()][$user['user_login']]['d'] = $last_dtm; $needupdate = true; } $workarr[] = array('login' => $user['user_login'], 'name' => $user['display_name'], 'count' => $photo_count, 'date' => $last_dtm); } } } } else { $widget_content = __('There are too many registered users in the system for this widget', 'wp-photo-album-plus'); echo "\n" . $before_widget; if (!empty($widget_title)) { echo $before_title . $widget_title . $after_title; } echo $widget_content . $after_widget; return; } if ($needupdate) { update_option('wppa_upldr_cache', $upldrcache); } // Bring me to top $myline = false; if (is_user_logged_in()) { $me = wppa_get_user(); foreach (array_keys($workarr) as $key) { $user = $workarr[$key]; if ($user['login'] == $me) { $myline = $workarr[$key]; unset($workarr[$key]); } } } // Sort workarray $ord = $instance['sortby'] == 'name' ? SORT_ASC : SORT_DESC; $workarr = wppa_array_sort($workarr, $instance['sortby'], $ord); // Create widget content $widget_content = "\n" . '<!-- WPPA+ Upldr Widget start -->'; $widget_content .= '<div class="wppa-upldr" style="max-height:180px; overflow:auto"><table><tbody>'; $albs = $instance['parent'] ? wppa_alb_to_enum_children(wppa_expand_enum($instance['parent'])) : ''; $a = $albs ? wppa_trim_wppa_('&wppa-album=' . $albs) : ''; if ($myline) { $user = $myline; $widget_content .= '<tr class="wppa-user" > <td style="padding: 0 3px;" ><a href="' . wppa_get_upldr_link($user['login']) . $a . '" title="' . __('Photos uploaded by', 'wp-photo-album-plus') . ' ' . $user['name'] . '" ><b>' . $user['name'] . '</b></a></td> <td style="padding: 0 3px;" ><b>' . $user['count'] . '</b></td> <td style="padding: 0 3px;" ><b>' . wppa_get_time_since($user['date']) . '</b></td> </tr>'; } foreach ($workarr as $user) { $widget_content .= '<tr class="wppa-user" > <td style="padding: 0 3px;" ><a href="' . wppa_get_upldr_link($user['login']) . $a . '" title="' . __('Photos uploaded by', 'wp-photo-album-plus') . ' ' . $user['name'] . '" >' . $user['name'] . '</a></td> <td style="padding: 0 3px;" >' . $user['count'] . '</td> <td style="padding: 0 3px;" >' . wppa_get_time_since($user['date']) . '</td> </tr>'; } $widget_content .= '</tbody></table></div>'; $widget_content .= '<div style="clear:both"></div>'; $widget_content .= "\n" . '<!-- WPPA+ Upldr Widget end -->'; // Output echo "\n" . $before_widget; if (!empty($widget_title)) { echo $before_title . $widget_title . $after_title; } echo $widget_content . $after_widget; wppa('in_widget', false); }