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: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207: 208: 209: 210: 211: 212: 213: 214: 215: 216: 217: 218: 219: 220: 221: 222: 223: 224: 225: 226: 227: 228: 229: 230: 231: 232: 233: 234: 235: 236: 237: 238: 239: 240: 241: 242: 243: 244: 245: 246: 247: 248: 249: 250: 251: 252: 253: 254: 255: 256: 257: 258: 259: 260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270: 271: 272: 273: 274: 275: 276: 277: 278: 279: 280: 281: 282: 283: 284: 285: 286: 287: 288: 289: 290: 291: 292: 293: 294: 295: 296: 297: 298: 299: 300: 301: 302: 303: 304: 305: 306: 307: 308: 309: 310: 311: 312: 313: 314: 315: 316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326: 327: 328: 329: 330: 331: 332: 333: 334: 335: 336: 337: 338: 339: 340: 341: 342: 343: 344: 345: 346: 347: 348: 349: 350:
<?php
class favorites extends AlbumBase {
var $imageSortDirection;
var $albumSortDirection;
var $imageSortType;
var $albumSortType;
var $list = array('');
var $owner;
var $instance = '';
function __construct($user) {
$this->table = 'albums';
$this->name = $user;
$this->owner = $user;
$this->setTitle(get_language_string(getOption('favorites_title')));
$this->setDesc(get_language_string(getOption('favorites_desc')));
$this->imageSortDirection = getOption('favorites_image_sort_direction');
$this->albumSortDirection = getOption('favorites_album_sort_direction');
$this->imageSortType = getOption('favorites_image_sort_type');
$this->albumSortType = getOption('favorites_album_sort_type');
$list = query_full_array('SELECT `aux` FROM ' . prefix('plugin_storage') . ' WHERE `type`="favorites" AND `aux` REGEXP ' . db_quote('[[:<:]]' . $user . '[[:>:]]'));
foreach ($list as $aux) {
$instance = getSerializedArray($aux['aux']);
if (isset($instance[1])) {
$this->list[$instance[1]] = $instance[1];
}
}
}
protected function getInstance() {
if ($this->instance) {
return serialize(array($this->owner, $this->instance));
} else {
return $this->owner;
}
}
function getList() {
return $this->list;
}
function getOwner($fullname = false) {
$owner = $this->owner;
if ($fullname) {
return Zenphoto_Administrator::getNameByUser($owner);
}
return $owner;
}
function addImage($img) {
$folder = $img->imagefolder;
$filename = $img->filename;
$sql = 'INSERT INTO ' . prefix('plugin_storage') . ' (`type`, `aux`,`data`) VALUES ("favorites",' . db_quote($this->getInstance()) . ',' . db_quote(serialize(array('type' => 'images', 'id' => $folder . '/' . $filename))) . ')';
query($sql);
zp_apply_filter('favoritesHandler_action', 'add', $img, $this->name);
}
function removeImage($img) {
$folder = $img->imagefolder;
$filename = $img->filename;
$sql = 'DELETE FROM ' . prefix('plugin_storage') . ' WHERE `type`="favorites" AND `aux`=' . db_quote($this->getInstance()) . ' AND `data`=' . db_quote(serialize(array('type' => 'images', 'id' => $folder . '/' . $filename)));
query($sql);
zp_apply_filter('favoritesHandler_action', 'remove', $img, $this->name);
}
function addAlbum($alb) {
$folder = $alb->name;
$sql = 'INSERT INTO ' . prefix('plugin_storage') . ' (`type`, `aux`,`data`) VALUES ("favorites",' . db_quote($this->getInstance()) . ',' . db_quote(serialize(array('type' => 'albums', 'id' => $folder))) . ')';
query($sql);
zp_apply_filter('favoritesHandler_action', 'add', $alb, $this->name);
}
function removeAlbum($alb) {
$folder = $alb->name;
$sql = 'DELETE FROM ' . prefix('plugin_storage') . ' WHERE `type`="favorites" AND `aux`=' . db_quote($this->getInstance()) . ' AND `data`=' . db_quote(serialize(array('type' => 'albums', 'id' => $folder)));
query($sql);
zp_apply_filter('favoritesHandler_action', 'remove', $alb, $this->name);
}
static function getWatchers($obj) {
switch ($obj->table) {
case 'images':
$folder = $obj->imagefolder;
$filename = $obj->filename;
$sql = 'SELECT DISTINCT `aux` FROM ' . prefix('plugin_storage') . ' WHERE `data`=' . db_quote(serialize(array('type' => 'images', 'id' => $folder . '/' . $filename)));
break;
case 'albums':
$folder = $obj->name;
$sql = 'SELECT DISTINCT `aux` FROM ' . prefix('plugin_storage') . ' WHERE `data`=' . db_quote(serialize(array('type' => 'albums', 'id' => $folder)));
break;
}
$watchers = array();
$result = query_full_array($sql);
if ($result) {
foreach ($result as $watch) {
$watchers[] = $watch['aux'];
}
}
return $watchers;
}
static function showWatchers($html, $obj, $prefix) {
$watchers = self::getWatchers($obj);
if (!empty($watchers)) {
sortArray($watchers);
?>
<tr>
<td>
<?php echo gettext('Users watching:'); ?>
</td>
<td>
<ul class="userlist">
<?php
foreach ($watchers as $watchee) {
?>
<li>
<?php echo html_encode($watchee); ?>
</li>
<?php
}
?>
</ul>
</td>
</tr>
<?php
}
return $html;
}
function getAlbums($page = 0, $sorttype = null, $sortdirection = null, $care = true, $mine = NULL) {
global $_zp_gallery;
if ($mine || is_null($this->subalbums) || $care && $sorttype . $sortdirection !== $this->lastsubalbumsort) {
$results = array();
$result = query('SELECT * FROM ' . prefix('plugin_storage') . ' WHERE `type`="favorites" AND `aux`=' . db_quote($this->getInstance()) . ' AND `data` LIKE "%s:4:\"type\";s:6:\"albums\";%"');
if ($result) {
while ($row = db_fetch_assoc($result)) {
$data = getSerializedArray($row['data']);
$albumobj = newAlbum($data['id'], true, true);
if ($albumobj->exists) {
$results[$data['id']] = $albumobj->getData();
} else {
query("DELETE FROM " . prefix('plugin_storage') . ' WHERE `id`=' . $row['id']);
}
}
db_free_result($result);
if (is_null($sorttype)) {
$sorttype = $this->getSortType('album');
}
if (is_null($sortdirection)) {
if ($this->getSortDirection('album')) {
$sortdirection = 'DESC';
}
}
$sortkey = $this->getAlbumSortKey($sorttype);
if (($sortkey == '`sort_order`') || ($sortkey == 'RAND()')) {
$order = false;
} else {
if (!is_null($sortdirection)) {
$order = strtoupper($sortdirection) == 'DESC';
} else {
$order = $this->getSortDirection('album');
}
}
$results = sortByKey($results, $sortkey, $order);
$this->subalbums = array_keys($results);
$this->lastsubalbumsort = $sorttype . $sortdirection;
}
}
return parent::getAlbums($page);
}
function getImages($page = 0, $firstPageCount = 0, $sorttype = null, $sortdirection = null, $care = true, $mine = NULL) {
if ($mine || is_null($this->images) || $care && $sorttype . $sortdirection !== $this->lastimagesort) {
$this->images = NULL;
$images = array();
$result = query('SELECT * FROM ' . prefix('plugin_storage') . ' WHERE `type`="favorites" AND `aux`=' . db_quote($this->getInstance()) . ' AND `data` LIKE "%s:4:\"type\";s:6:\"images\";%"');
if ($result) {
while ($row = db_fetch_assoc($result)) {
$id = $row['id'];
$data = getSerializedArray($row['data']);
$imageObj = newImage(NULL, array('folder' => dirname($data['id']), 'filename' => basename($data['id'])), true);
if ($imageObj->exists) {
$images[] = array_merge(array('folder' => dirname($data['id']), 'filename' => basename($data['id'])), $imageObj->getData());
} else {
query("DELETE FROM " . prefix('plugin_storage') . ' WHERE `id`=' . $row['id']);
}
}
db_free_result($result);
if (is_null($sorttype)) {
$sorttype = $this->getSortType();
}
$sortkey = str_replace('` ', ' ', $this->getImageSortKey($sorttype));
if (($sortkey == 'sort_order') || ($sortkey == 'RAND()')) {
$order = false;
} else {
if (!is_null($sortdirection)) {
$order = strtoupper($sortdirection) == 'DESC';
} else {
$order = $this->getSortDirection('image');
}
}
$images = sortByKey($images, $sortkey, $order);
$this->images = array();
foreach ($images as $data) {
$this->images[] = array('folder' => $data['folder'], 'filename' => $data['filename']);
}
$this->lastimagesort = $sorttype . $sortdirection;
}
}
return parent::getImages($page, $firstPageCount);
}
static function loadScript($script, $request) {
global $_zp_current_admin_obj, $_zp_gallery_page, $_myFavorites, $_zp_current_album, $_zp_conf_vars;
if ($_myFavorites && isset($_REQUEST['instance'])) {
$_myFavorites->instance = sanitize(rtrim($_REQUEST['instance'], '/'));
if ($_myFavorites->instance)
$_myFavorites->setTitle($_myFavorites->getTitle() . '[' . $_myFavorites->instance . ']');
}
if ($_zp_gallery_page == "favorites.php") {
if (zp_loggedin()) {
$_zp_current_album = $_myFavorites;
add_context(ZP_ALBUM);
prepareAlbumPage();
$_zp_gallery_page = 'favorites.php';
} else {
$script = false;
}
}
return $script;
}
static function pageCount($count, $gallery_page, $page) {
global $_firstPageImages, $_oneImagePage;
if (stripSuffix($gallery_page) == 'favorites') {
$albums_per_page = max(1, getOption('albums_per_page'));
$pageCount = (int) ceil(getNumAlbums() / $albums_per_page);
$imageCount = getNumImages();
if ($_oneImagePage) {
if ($_oneImagePage === true) {
$imageCount = min(1, $imageCount);
} else {
$imageCount = 0;
}
}
$images_per_page = max(1, getOption('images_per_page'));
$count = ($pageCount + (int) ceil(($imageCount - $_firstPageImages) / $images_per_page));
if ($count < $page && isset($_POST['addToFavorites']) && !$_POST['addToFavorites']) {
global $_zp_page;
redirectURL(FULLWEBPATH . '/' . $this->getLink($_zp_page - 1));
}
}
return $count;
}
static function toolbox($zf) {
printFavoritesURL(gettext('Favorites'), '<li>', '</li><li>', '</li>');
return $zf;
}
function getLink($page = NULL, $instance = NULL) {
$link = _FAVORITES_ . '/';
$link_no = 'index.php?p=favorites';
if (is_null($instance))
$instance = $this->instance;
if ($instance) {
$instance = rtrim($instance, '/');
$link .= $instance . '/';
$link_no .= '&instance=' . $instance;
}
if ($page > 1) {
$link .= $page . '/';
$link_no .= '&page=' . $page;
}
return zp_apply_filter('getLink', rewrite_path($link, $link_no), 'favorites.php', $page);
}
static function ad_removeButton($obj, $id, $v, $add, $instance, $multi) {
global $_myFavorites;
$table = $obj->table;
if ($v) {
$tag = '_add';
} else {
$tag = '_remove';
}
if ($instance && $multi) {
$add .= '[' . $instance . ']';
}
?>
<form name="<?php echo $table . $obj->getID(); ?>Favorites_<?php echo $instance . $tag; ?>" class = "<?php echo $table; ?>Favorites<?php echo $tag; ?>" action = "<?php echo html_encode(getRequestURI()); ?>" method = "post" accept-charset = "UTF-8">
<input type = "hidden" name = "addToFavorites" value = "<?php echo $v; ?>" />
<input type = "hidden" name = "type" value = "<?php echo html_encode($table); ?>" />
<input type = "hidden" name = "id" value = "<?php echo html_encode($id); ?>" />
<input type = "submit" class = "button buttons" value = "<?php echo $add; ?>" title = "<?php echo $add; ?>"/>
<?php
if ($v) {
if ($multi) {
?>
<span class="tagSuggestContainer">
<input type="text" name="instance" class="favorite_instance" value="" />
</span>
<?php
}
} else {
?>
<input type="hidden" name="instance" value="<?php echo $_myFavorites->instance; ?>" />
<?php
}
?>
</form>
<?php
}
}