Beispiel #1
0
        function printAddToFavorites($obj, $add = NULL, $remove = NULL)
        {
            global $_myFavorites, $_zp_current_admin_obj, $_zp_gallery_page, $_myFavorites_button_count;
            if (!zp_loggedin() || $_myFavorites->getOwner() != $_zp_current_admin_obj->getUser() || !is_object($obj) || !$obj->exists) {
                return;
            }
            $v = 1;
            if (is_null($add)) {
                $add = get_language_string(getOption('favorites_add_button'));
            }
            if (is_null($remove)) {
                $remove = get_language_string(getOption('favorites_remove_button'));
            } else {
                $add = $remove;
            }
            $table = $obj->table;
            $target = array('type' => $table);
            if ($_zp_gallery_page == 'favorites.php') {
                //	 only need one remove button since we know the instance
                $multi = false;
                $list = array($_myFavorites->instance);
            } else {
                if ($multi = getOption('favorites_multi')) {
                    $list = $_myFavorites->list;
                } else {
                    $list = array('');
                }
                if (extensionEnabled('tag_suggest') && !$_myFavorites_button_count) {
                    $_myFavorites_button_count++;
                    $favList = array_slice($list, 1);
                    ?>
					<script type="text/javascript">
						// <!-- <![CDATA[
						var _favList = ['<?php 
                    echo implode("','", $favList);
                    ?>
'];
						$(function() {
							$('.favorite_instance').tagSuggest({tags: _favList})
						});
						// ]]> -->
					</script>
					<?php 
                }
            }
            $seen = array_flip($list);
            switch ($table) {
                case 'images':
                    $id = $obj->imagefolder . '/' . $obj->filename;
                    foreach ($list as $instance) {
                        $_myFavorites->instance = $instance;
                        $images = $_myFavorites->getImages(0);
                        $seen[$instance] = false;
                        foreach ($images as $image) {
                            if ($image['folder'] == $obj->imagefolder && $image['filename'] == $obj->filename) {
                                $seen[$instance] = true;
                                favorites::ad_removeButton($obj, $id, 0, $remove, $instance, $multi);
                                break;
                            }
                        }
                    }
                    if ($multi || in_array(false, $seen)) {
                        favorites::ad_removeButton($obj, $id, 1, $add, NULL, $multi);
                    }
                    break;
                case 'albums':
                    $id = $obj->name;
                    foreach ($list as $instance) {
                        $_myFavorites->instance = $instance;
                        $albums = $_myFavorites->getAlbums(0);
                        $seen[$instance] = false;
                        foreach ($albums as $album) {
                            if ($album == $id) {
                                $seen[$instance] = true;
                                favorites::ad_removeButton($obj, $id, 0, $remove, $instance, $multi);
                                break;
                            }
                        }
                    }
                    if ($multi || in_array(false, $seen)) {
                        favorites::ad_removeButton($obj, $id, 1, $add, NULL, $multi);
                    }
                    break;
                default:
                    //We do not handle these.
                    return;
            }
        }