11<?php
22
33class photosPublicgalleryPlugin extends photosPlugin
4- {
4+ {
55 public function saveSettings ($ settings = array ())
66 {
77 if (empty ($ settings ['min_size ' ]) || !is_numeric ($ settings ['min_size ' ])) {
@@ -10,44 +10,44 @@ public function saveSettings($settings = array())
1010 if (empty ($ settings ['max_size ' ]) || !is_numeric ($ settings ['max_size ' ])) {
1111 $ settings ['max_size ' ] = '' ;
1212 }
13- if (is_numeric ($ settings ['min_size ' ]) && is_numeric ($ settings ['max_size ' ]) &&
14- $ settings ['min_size ' ] > $ settings ['max_size ' ])
13+ if (is_numeric ($ settings ['min_size ' ]) && is_numeric ($ settings ['max_size ' ]) &&
14+ $ settings ['min_size ' ] > $ settings ['max_size ' ])
1515 {
1616 list ($ settings ['max_size ' ], $ settings ['min_size ' ]) = array ($ settings ['min_size ' ], $ settings ['max_size ' ]);
1717 }
1818 parent ::saveSettings ($ settings );
1919 }
20-
20+
2121 public function frontendSidebar ()
2222 {
2323 return array ('menu ' => '<a href=" ' .wa ()->getRouteUrl ('photos/frontend/myphotos ' ).'" id="photos-my-photos"> ' ._wp ('My uploads ' ).'</a> ' );
2424 }
25-
25+
2626 public function frontendPhoto ($ photo )
2727 {
2828 if (!isset ($ photo ['id ' ])) {
2929 return ;
3030 }
31-
31+
3232 $ photo_model = new photosPhotoModel ();
3333 $ photo = $ photo_model ->getById ($ photo ['id ' ]);
3434 if (!$ photo ) {
3535 return ;
3636 }
37-
37+
3838 $ votes_count_text = '' ;
3939 if ($ photo ['votes_count ' ] > 0 ) {
4040 $ votes_count_text = _wp ('%d vote ' , '%d votes ' , $ photo ['votes_count ' ]);
4141 }
4242 $ frontend_vote_url = wa ()->getRouteUrl ('photos/frontend/vote ' );
43-
43+
4444 $ vote_model = new photosPublicgalleryVoteModel ();
4545 $ vote_item = $ vote_model ->getByField (array ('photo_id ' => $ photo ['id ' ], 'contact_id ' => wa ()->getUser ()->getId ()));
4646 $ your_rate = 0 ;
4747 if ($ vote_item ) {
4848 $ your_rate = $ vote_item ['rate ' ];
4949 }
50-
50+
5151 $ sidebar = '<p><span href="javascript:void(0);" id="photo-rate" class="p-rate-photo" title=" ' ._wp ('Rate ' ).'" data-rate=" ' .$ photo ['rate ' ].'"> ' .
5252 photosPhoto::getRatingHtml ($ photo ['rate ' ], 16 , true )
5353 .'</span> ' .
@@ -60,25 +60,25 @@ public function frontendPhoto($photo)
6060 photosPhoto::getRatingHtml ($ your_rate , 16 , true )
6161 .'</a> ' .
6262 '<em class="error" id="photo-rate-error" style="display:none;"></em> ' .
63- '<a class="inline-link p-rate-clear small" href="javascript:void(0);" style="display:none;" id="clear-photo-rate"><b><i> ' ._wp ('cancel my vote ' ).'</b></i> </a> ' .
63+ '<a class="p-rate-clear small" href="javascript:void(0);" style="display:none;" id="clear-photo-rate"> ' ._wp ('cancel my vote ' ).'</a> ' .
6464 '</span></p> ' ;
6565 $ sidebar .= '<script>$(function() { $.photos.publicgalleryInitRateWidget(); });</script> ' ;
66-
66+
6767 $ left = '' ;
6868 if ($ photo ['moderation ' ] == 0 ) {
6969 $ left .= "<p class='p-awaiting-moderation'> " ._wp ("Pending moderation " )."</p> " ;
7070 } else if ($ photo ['moderation ' ] == -1 ) {
7171 $ left .= "<p class='p-declined'> " ._wp ("Photo has been declined by the administrator " )."</p> " ;
7272 }
73-
73+
7474 return array ('sidebar ' => $ sidebar , 'top_left ' => $ left );
7575 }
76-
76+
7777 public function backendAssets () {
7878 $ this ->addJs ('js/backend.js? ' .wa ()->getVersion ());
7979 return "<style>#sidebar-publicgallery-plugin-awaiting { margin-top: 15px; } </style> " ;
8080 }
81-
81+
8282 public function frontendAssets () {
8383 $ v = wa ()->getVersion ();
8484 $ this ->addJs ('js/frontend.js? ' .$ v );
@@ -96,7 +96,7 @@ public function frontendAssets() {
9696 $ view ->assign ('strings ' , $ strings ? $ strings : new stdClass ()); // stdClass is used to show {} instead of [] when there's no strings
9797 return $ view ->fetch ($ this ->path .'/templates/actions/frontend/FrontendLoc.html ' );
9898 }
99-
99+
100100 public function backendSidebar ()
101101 {
102102 $ photo_model = new photosPhotoModel ();
@@ -114,21 +114,25 @@ public function backendSidebar()
114114 'declined ' => '<span class="count"> ' .$ declined_count .'</span><a href="#/search/moderation=-1/"><i class="icon10 no"></i> ' ._wp ('Declined ' ).'</a> '
115115
116116 );
117+ if (wa ()->whichUI () === '2.0 ' ){
118+ $ items ['awaiting ' ] = '<a href="#/search/moderation=0/"><i class="fas fa-exclamation-triangle"></i><span> ' ._wp ('Pending moderation ' ).'</span><span class="count ' .($ awaiting_count ? 'badge text-white ' : '' ).'"> ' .$ awaiting_count .'</span></a> ' ;
119+ $ items ['declined ' ] = '<a href="#/search/moderation=-1/"><i class="fas fa-times-circle"></i><span> ' ._wp ('Declined ' ).'</span><span class="count"> ' .$ declined_count .'</span></a> ' ;
120+ }
117121 return array (
118122 'menu ' => $ items
119123 );
120124 }
121-
125+
122126 public function preparePhotosBackend (&$ photos )
123127 {
124128 if (wa ()->getUser ()->getRights ('photos ' , 'edit ' )) {
125129 foreach ($ photos as &$ p ) {
126130 if ($ p ['source ' ] == 'publicgallery ' ) {
127131 $ links = array (
128- '<a href="javascript:void(0);" class="moderation approve small nowrap"
132+ '<a href="javascript:void(0);" class="moderation approve small nowrap"
129133 style="margin-right: 10px; ' .($ p ['moderation ' ] == 1 ? 'display:none ' : '' ).'" ' .
130134 'data-action="approve"><i class="icon10 yes"></i> ' ._wp ('Approve photo ' ).'</a> ' ,
131- '<a href="javascript:void(0);" class="moderation decline small nowrap"
135+ '<a href="javascript:void(0);" class="moderation decline small nowrap"
132136 style=" ' .($ p ['moderation ' ] == -1 ? 'display:none ' : '' ).'" ' .
133137 'data-action="decline"><i class="icon10 no"></i> ' ._wp ('Decline ' ).'</a> '
134138 );
@@ -138,7 +142,7 @@ public function preparePhotosBackend(&$photos)
138142 unset($ p );
139143 }
140144 }
141-
145+
142146 public function beforeSaveField (&$ params )
143147 {
144148 if (empty ($ params ['photo_id ' ])) {
@@ -149,25 +153,25 @@ public function beforeSaveField(&$params)
149153 } else {
150154 $ photo_id = (int ) $ params ['photo_id ' ];
151155 }
152-
156+
153157 $ photo_model = new photosPhotoModel ();
154158 $ photo = $ photo_model ->getById ($ photo_id );
155159 if (!$ photo ) {
156160 return ;
157161 }
158-
162+
159163 if (empty ($ params ['data ' ])) {
160164 return ;
161165 }
162166 $ data = $ params ['data ' ];
163167 if (!isset ($ data ['rate ' ])) {
164168 return ;
165169 }
166-
170+
167171 $ contact_id = wa ()->getUser ()->getId ();
168-
172+
169173 $ vote_model = new photosPublicgalleryVoteModel ();
170-
174+
171175 if ($ vote_model ->getByField (array (
172176 'photo_id ' => $ photo_id ,
173177 'contact_id ' => $ contact_id
@@ -185,7 +189,7 @@ public function beforeSaveField(&$params)
185189 $ params ['data ' ]['votes_count ' ] = $ vote_model ->getVotesCount ($ photo_id );
186190 }
187191 }
188-
192+
189193 public function preparePhotosFrontend (&$ photos )
190194 {
191195 foreach ($ photos as &$ p ) {
@@ -197,7 +201,7 @@ public function preparePhotosFrontend(&$photos)
197201 }
198202 unset($ p );
199203 }
200-
204+
201205 public function backendPhotoToolbar ()
202206 {
203207 if (wa ()->getUser ()->getRights ('photos ' , 'edit ' )) {
@@ -208,7 +212,7 @@ public function backendPhotoToolbar()
208212 return array ('share_menu ' => $ items );
209213 }
210214 }
211-
215+
212216 public function backendPhoto ($ photo_id )
213217 {
214218 $ photo_model = new photosPhotoModel ();
@@ -218,34 +222,34 @@ public function backendPhoto($photo_id)
218222 if ($ photo ['votes_count ' ] > 0 ) {
219223 $ votes_count_text = _wp ('%d vote ' , '%d votes ' , $ photo ['votes_count ' ]);
220224 }
221-
225+
222226 $ vote_model = new photosPublicgalleryVoteModel ();
223227 $ vote_item = $ vote_model ->getByField (array ('photo_id ' => $ photo ['id ' ], 'contact_id ' => wa ()->getUser ()->getId ()));
224228 $ your_rate = 0 ;
225229 if ($ vote_item ) {
226230 $ your_rate = $ vote_item ['rate ' ];
227231 }
228-
232+
229233 $ html = '<a class="hint" href="javascript:void(0);" id="photo-rate-votes-count" data-you-voted=" ' .(int )($ your_rate > 0 ).'"><u> ' .$ votes_count_text .'</u></a> ' .
230234 '<span id="p-your-rate-wrapper"> ' ._wp ('My vote: ' ).
231235 '<a href="javascript:void(0);" id="your-rate" class="p-rate-photo" data-rate=" ' .$ your_rate .'"> ' .
232236 photosPhoto::getRatingHtml ($ your_rate , 10 , true ).
233237 '</a></span> ' .
234- '<a class="inline-link p-rate-clear small" href="javascript:void(0);" style="display:none;" id="clear-photo-rate"><b><i> ' ._wp ('cancel my vote ' ).'</b></i> </a> ' ;
238+ '<a class="p-rate-clear small" href="javascript:void(0);" style="display:none;" id="clear-photo-rate"> ' ._wp ('cancel my vote ' ).'</a> ' ;
235239 $ html .= '<script>$.photos.publicgalleryInitYourRate();</script> ' ;
236240 return array (
237241 'after_rate ' => $ html
238242 );
239243 }
240244 }
241-
245+
242246 public function searchFrontendLink ($ query )
243247 {
244248 if ($ query == 'votes_count>0 ' || $ query == 'moderation=0 ' || $ query == 'moderation=-1 ' ) {
245249 return '' ;
246250 }
247251 }
248-
252+
249253 public function prepareCollection ($ params )
250254 {
251255 if (isset ($ params ['hash ' ]) && $ params ['hash ' ][0 ] == 'publicgallery ' && $ params ['hash ' ][1 ] == 'myphotos ' ) {
@@ -264,8 +268,8 @@ public function prepareCollection($params)
264268 return true ;
265269 }
266270 }
267-
268- public function extraPrepareCollection ($ params )
271+
272+ public function extraPrepareCollection ($ params )
269273 {
270274 if (isset ($ params ['hash ' ][1 ]) && strstr ($ params ['hash ' ][1 ], 'moderation= ' ) !== false ) {
271275 if (wa ()->getEnv () == 'frontend ' ) {
@@ -283,9 +287,9 @@ public function extraPrepareCollection($params)
283287 return ;
284288 }
285289 }
286-
290+
287291 // hash = id/photo_id:private_hash
288- if (isset ($ params ['hash ' ][0 ]) && $ params ['hash ' ][0 ] == 'id ' &&
292+ if (isset ($ params ['hash ' ][0 ]) && $ params ['hash ' ][0 ] == 'id ' &&
289293 isset ($ params ['hash ' ][1 ]) && preg_match ("!^[\d]+:[\da-fA-F]{32}$! " , $ params ['hash ' ][1 ]))
290294 {
291295 return ;
@@ -294,7 +298,7 @@ public function extraPrepareCollection($params)
294298 if (isset ($ params ['hash ' ]) && $ params ['hash ' ][0 ] == 'publicgallery ' && $ params ['hash ' ][1 ] == 'myphotos ' ) {
295299 return ;
296300 }
297-
301+
298302 $ params ['collection ' ]->addWhere ('moderation=1 ' );
299303 }
300- }
304+ }
0 commit comments