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