1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Ansel_Ajax_Imple_EditGalleryFaces extends Horde_Ajax_Imple_Base
14: {
15: 16: 17: 18:
19: public function attach()
20: {
21: Horde::addScriptFile('editfaces.js');
22: $url = $this->_getUrl('EditFaces', 'ansel');
23: $js = array();
24: $js[] = "Ansel.ajax['editFaces'] = {'url':'" . $url . "', text: {loading:'" . _("Loading...") . "'}};";
25: $image_id = $this->_params['image_id'];
26:
27: $faces = $GLOBALS['injector']->getInstance('Ansel_Faces');
28: $name = '';
29: $autocreate = true;
30: $results = $faces->getImageFacesData($image_id);
31: if (empty($results)) {
32: $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($this->_params['image_id']);
33: $image->createView('screen');
34: $results = $faces->getFromPicture($this->_params['image_id'], $autocreate);
35: }
36: if (!empty($results)) {
37: $customurl = Horde::url('faces/custom.php');
38: $url = (!empty($args['url']) ? urldecode($args['url']) : '');
39: Horde::startBuffer();
40: require_once ANSEL_TEMPLATES . '/faces/image.inc';
41: return Horde::endBuffer();
42: } else {
43: return _("No faces found");
44: }
45:
46: Horde::addInlineScript($js, 'dom');
47: }
48:
49: function handle($args, $post)
50: {
51: if (Horde_Auth::getAuth()) {
52: $action = $args['action'];
53: $image_id = (int)$post['image'];
54: $reload = empty($post['reload']) ? 0 : $post['reload'];
55:
56: if (empty($action)) {
57: return array('response' => 0);
58: }
59:
60: $faces = $GLOBALS['injector']->getInstance('Ansel_Faces');
61: switch($action) {
62: case 'process':
63:
64: $name = '';
65: $autocreate = true;
66: $result = $faces->getImageFacesData($image_id);
67:
68:
69: if (($reload || empty($result))) {
70: $image = $GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image_id);
71: $image->createView('screen');
72: $result = $faces->getFromPicture($image_id, $autocreate);
73: }
74: if (!empty($result)) {
75: $customurl = Horde::url('faces/custom.php');
76: $url = (!empty($args['url']) ? urldecode($args['url']) : '');
77: Horde::startBuffer();
78: require_once ANSEL_TEMPLATES . '/faces/image.inc';
79: $html = Horde::endBuffer();
80: return array('response' => 1,
81: 'message' => $html);
82: } else {
83: return array('response' => 1,
84: 'message' => _("No faces found"));
85: }
86: break;
87:
88: case 'delete':
89:
90: $face_id = (int)$post['face'];
91: $image = &$GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image_id);
92: $gallery = &$GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
93: if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
94: throw new Horde_Exception('Access denied editing the photo.');
95: }
96:
97: $faces = $GLOBALS['injector']->getInstance('Ansel_Faces');
98: $faces->delete($image, $face_id);
99: break;
100:
101: case 'setname':
102:
103: $face_id = (int)$post['face'];
104: if (!$face_id) {
105: return array('response' => 0);
106: }
107:
108: $name = $post['facename'];
109: $image = &$GLOBALS['injector']->getInstance('Ansel_Storage')->getImage($image_id);
110: $gallery = &$GLOBALS['injector']->getInstance('Ansel_Storage')->getGallery($image->gallery);
111: if (!$gallery->hasPermission(Horde_Auth::getAuth(), Horde_Perms::EDIT)) {
112: throw new Horde_Exception('You are not allowed to edit this photo');
113: }
114:
115: $faces = $GLOBALS['injector']->getInstance('Ansel_Faces');
116: $result = $faces->setName($face_id, $name);
117: return array('response' => 1,
118: 'message' => Ansel_Faces::getFaceTile($face_id));
119: break;
120: }
121: }
122: }
123:
124: }
125: