This repository has been archived by the owner on Mar 1, 2024. It is now read-only.
/
wppa-album-navigator-widget.php
187 lines (160 loc) · 8.21 KB
/
wppa-album-navigator-widget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<?php
/* wppa-album-navigator-widget.php
* Package: wp-photo-album-plus
*
* display album names linking to content
* Version 6.3.0
*/
class AlbumNavigatorWidget extends WP_Widget {
/** constructor */
function __construct() {
$widget_ops = array('classname' => 'wppa_album_navigator_widget', 'description' => __( 'WPPA+ Album navigator', 'wp-photo-album-plus') );
parent::__construct('wppa_album_navigator_widget', __('Album navigator', 'wp-photo-album-plus'), $widget_ops);
}
/** @see WP_Widget::widget */
function widget($args, $instance) {
global $wpdb;
global $wppa;
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'] = 'albnav';
$wppa['mocc'] ++;
extract( $args );
$instance = wp_parse_args( (array) $instance, array(
'title' => '', // Widget title
'parent' => '0', // Parent album
'skip' => 'yes' // Skip empty albums
) );
$widget_title = apply_filters('widget_title', $instance['title']);
$page = wppa_get_the_landing_page('wppa_album_navigator_widget_linkpage', __('Photo Albums', 'wp-photo-album-plus'));
$parent = $instance['parent'];
$skip = $instance['skip'];
$widget_content = "\n".'<!-- WPPA+ Album Navigator Widget start -->';
$widget_content .= '<div style="width:100%; overflow:hidden; position:relative; left: -12px;" >';
if ( $parent == 'all' ) {
$widget_content .= $this->do_album_navigator( '0', $page, $skip, '' );
$widget_content .= $this->do_album_navigator( '-1', $page, $skip, '' );
}
else {
$widget_content .= $this->do_album_navigator( $parent, $page, $skip, '' );
}
$widget_content .= '</div>';
$widget_content .= '<div style="clear:both"></div>';
$widget_content .= "\n".'<!-- WPPA+ Album Navigator 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;
}
/** @see WP_Widget::update */
function update($new_instance, $old_instance) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
$instance['parent'] = $new_instance['parent'];
$instance['skip'] = $new_instance['skip'];
return $instance;
}
/** @see WP_Widget::form */
function form($instance) {
global $wpdb;
//Defaults
$instance = wp_parse_args( (array) $instance, array(
'title' => __('Photo Albums', 'wp-photo-album-plus'),
'parent' => '0',
'skip' => 'yes' ) );
$parent = $instance['parent'];
$skip = $instance['skip'];
$widget_title = $instance['title'];
?>
<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 $widget_title; ?>" /></p>
<p><label for="<?php echo $this->get_field_id('parent'); ?>"><?php _e('Album selection or Parent album:', 'wp-photo-album-plus'); ?></label>
<select class="widefat" id="<?php echo $this->get_field_id('parent'); ?>" name="<?php echo $this->get_field_name('parent'); ?>" >
<option value="all" <?php if ($parent == 'all') echo 'selected="selected"' ?>><?php _e('--- all albums ---', 'wp-photo-album-plus') ?></option>
<option value="0" <?php if ($parent == '0') echo 'selected="selected"' ?>><?php _e('--- all generic albums ---', 'wp-photo-album-plus') ?></option>
<option value="-1" <?php if ($parent == '-1') echo 'selected="selected"' ?>><?php _e('--- all separate albums ---', 'wp-photo-album-plus') ?></option>
<?php $albs = $wpdb->get_results( "SELECT * FROM `".WPPA_ALBUMS."` ORDER BY `name`", ARRAY_A);
if ( $albs ) foreach( $albs as $alb ) {
echo '<option value="'.$alb['id'].'" ';
if ( $parent == $alb['id'] ) echo 'selected="selected" ';
if ( !wppa_has_children($alb['id']) ) echo 'disabled="disabled" ';
echo '>'.__(stripslashes($alb['name']), 'wp-photo-album-plus').'</option>';
} ?>
</select>
</p>
<p>
<?php _e('Skip "empty" albums:', 'wp-photo-album-plus'); ?>
<select id="<?php echo $this->get_field_id('skip'); ?>" name="<?php echo $this->get_field_name('skip'); ?>">
<option value="no" <?php if ($skip == 'no') echo 'selected="selected"' ?>><?php _e('no.', 'wp-photo-album-plus'); ?></option>
<option value="yes" <?php if ($skip == 'yes') echo 'selected="selected"' ?>><?php _e('yes.', 'wp-photo-album-plus'); ?></option>
</select>
</p>
<?php
}
function get_widget_id() {
$widgetid = substr( $this->get_field_name( 'txt' ), strpos( $this->get_field_name( 'txt' ), '[' ) + 1 );
$widgetid = substr( $widgetid, 0, strpos( $widgetid, ']' ) );
return $widgetid;
}
function do_album_navigator( $parent, $page, $skip, $propclass ) {
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' );
}
else {
$level++;
}
$slide = wppa_opt( 'wppa_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 ".wppa_get_album_order( max( '0', $parent ) ), $parent ), ARRAY_A );
wppa_dbg_q( 'Q-WidANav' );
wppa_cache_album( 'add', $albums );
if ( $albums ) {
$result .= '<ul>';
foreach ( $albums as $album ) {
$a = $album['id'];
$treecount = wppa_treecount_a( $a );
if ( $treecount['albums'] || $treecount['photos'] > wppa_opt( 'wppa_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_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 ) . '</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 );
}
} // class AlbumNavigatorWidget
// register AlbumNavigatorWidget widget
add_action('widgets_init', create_function('', 'return register_widget("AlbumNavigatorWidget");'));