Changeset bb0e4c03b038dca05a1ebd482427351c958b733e
- Timestamp:
- 11/01/11 11:42:21 (7 months ago)
- Children:
- e7234c1259e67fbdaae43224343ef0f925519124
- Parents:
- f8d271c1ff0aebd1c0487928bf60ad46cd8d9aa6
- git-committer:
- Xemle <xemle@phtagr.org> / 2011-11-01T11:42:21Z+0100
- Files:
-
- 6 modified
-
controllers/components/file_cache.php (modified) (1 diff)
-
controllers/explorer_controller.php (modified) (7 diffs)
-
models/media.php (modified) (5 diffs)
-
views/elements/explorer/menu.ctp (modified) (3 diffs)
-
views/explorer/editmeta.ctp (modified) (1 diff)
-
views/explorer/index.ctp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
controllers/components/file_cache.php
re0ad18e rbb0e4c0 92 92 @param userId Id of the current user 93 93 @param mediaId Id of the current image/file */ 94 function delete( $userId, $mediaId) {95 $mediaId = intval($media Id);96 $cacheDir = $this->getPath( $userId, $mediaId, false);94 function delete(&$media) { 95 $mediaId = intval($media['Media']['id']); 96 $cacheDir = $this->getPath(&$media, false); 97 97 if (!$cacheDir) { 98 Logger::trace("No cache dir found for image$mediaId");98 Logger::trace("No cache dir found for media $mediaId"); 99 99 return true; 100 100 } -
controllers/explorer_controller.php
re4e22b0 rbb0e4c0 24 24 class ExplorerController extends AppController 25 25 { 26 var $components = array('RequestHandler', 'FilterManager', 'Search', 'QueryBuilder', 'FastFileResponder', 'Feed' );26 var $components = array('RequestHandler', 'FilterManager', 'Search', 'QueryBuilder', 'FastFileResponder', 'Feed', 'FileCache'); 27 27 var $uses = array('Media', 'MyFile', 'Group', 'Tag', 'Category', 'Location'); 28 28 var $helpers = array('Form', 'Html', 'Ajax', 'ImageData', 'Time', 'ExplorerMenu', 'Rss', 'Search', 'Navigator', 'Tab', 'Breadcrumb', 'Autocomplete'); … … 540 540 continue; 541 541 } 542 543 if ($media['Media']['canWriteMeta']) { 544 $tmp = $this->Media->editMetaMulti(&$media, $editData); 545 } else { 546 $tmp = $this->Media->editTagMulti(&$media, $editData); 547 } 542 $tmp = $this->Media->editMulti(&$media, $editData); 548 543 if ($tmp) { 549 544 $changedMedia[] = $tmp; … … 555 550 } else { 556 551 Logger::debug("Saved media: " . join(', ', Set::extract("/Media/id", $changedMedia))); 552 } 553 foreach ($changedMedia as $media) { 554 if ($media['Media']['orientation']) { 555 $this->FileCache->delete($media); 556 Logger::debug("Deleted previews of media {$media['Media']['id']}"); 557 } 557 558 } 558 559 } … … 599 600 $media = $this->Media->findById($id); 600 601 $this->Media->setAccessFlags(&$media, $user); 601 $this->set('data', $media); 602 if (!$media['Media']['canWriteTag']) { 603 Logger::warn("User is not allowed to edit media {$media['Media']['id']}"); 604 $this->redirect(null, '403'); 605 } 606 $this->data = $media; 602 607 $this->layout='bare'; 603 if (!$this->Media->checkAccess(&$media, &$user, ACL_WRITE_META, ACL_WRITE_MASK)) { 604 if ($this->Media->checkAccess(&$media, &$user, ACL_WRITE_TAG, ACL_WRITE_MASK)) { 605 $this->render('edittag'); 606 } else { 607 Logger::warn("User '{$user['User']['username']}' ({$user['User']['id']}) has no previleges to change ACL of image ".$id); 608 $this->render('updatemeta'); 609 } 610 } 608 $this->render('editmeta'); 611 609 //Configure::write('debug', 0); 612 610 } … … 616 614 */ 617 615 function savemeta($id) { 618 if (!$this->RequestHandler->isAjax() || !$this->RequestHandler->isPost()) {616 if (!$this->RequestHandler->isAjax()) { 619 617 Logger::warn("Decline wrong ajax request"); 620 618 $this->redirect(null, '404'); … … 626 624 if (isset($this->data)) { 627 625 $media = $this->Media->findById($id); 626 $this->Media->setAccessFlags(&$media, $user); 628 627 if (!$media) { 629 628 Logger::warn("Invalid media id: $id"); 630 629 $this->redirect(null, '404'); 631 } elseif (!$ this->Media->checkAccess(&$media, &$user, ACL_WRITE_TAG, ACL_WRITE_MASK)) {630 } elseif (!$media['Media']['canWriteTag']) { 632 631 Logger::warn("User '{$username}' ({$user['User']['id']}) has no previleges to change tags of image ".$id); 633 632 } else { 634 if ($this->Media->checkAccess(&$media, &$user, ACL_WRITE_META, ACL_WRITE_MASK)) { 635 Logger::debug("User {$username} updates metadata of media {$id}"); 636 $tmp = $this->Media->editMetaSingle(&$media, &$this->data); 637 } else { 638 Logger::debug("User {$username} updates tags of media {$id}"); 639 $tmp = $this->Media->editTagSingle(&$media, &$this->data); 640 } 633 $tmp = $this->Media->editSingle(&$media, &$this->data); 641 634 if (!$this->Media->save($tmp)) { 642 635 Logger::warn("Could not save media"); … … 644 637 } else { 645 638 Logger::info("Updated meta of media {$tmp['Media']['id']}"); 639 } 640 if ($tmp['Media']['orientation']) { 641 $this->FileCache->delete($tmp); 642 Logger::debug("Deleted previews of media {$tmp['Media']['id']}"); 646 643 } 647 644 } -
models/media.php
r249034c rbb0e4c0 707 707 } 708 708 709 function rotate(&$data, $orientation, $rotation) { 710 $rotateClockwise = array( 711 1 => 8, 8 => 3, 3 => 6, 6 => 1, 712 2 => 7, 7 => 4, 4 => 5, 5 => 2 713 ); 714 $rotated = $orientation; 715 switch ($rotation) { 716 case '270': $rotated = $rotateClockwise[$rotated]; 717 case '180': $rotated = $rotateClockwise[$rotated]; 718 case '90': $rotated = $rotateClockwise[$rotated]; 719 default: break; 720 } 721 if ($rotated != $orientation) { 722 $data['Media']['orientation'] = $rotated; 723 } 724 } 725 709 726 /** 710 727 * Prepare the input data for edit … … 718 735 $this->splitGeo(&$data, $data['Media']['geo']); 719 736 } 720 $fields = array('name', 'description', 'date', 'latitude', 'longitude' );737 $fields = array('name', 'description', 'date', 'latitude', 'longitude', 'rotation'); 721 738 foreach ($fields as $field) { 722 739 if (!empty($data['Media'][$field])) { … … 743 760 } 744 761 745 function editTagMulti(&$media, &$data) { 746 $tmp = array('Media' => array('id' => $media['Media']['id'])); 747 748 $tag = $this->Tag->editMetaMulti(&$media, &$data); 749 if ($tag) { 750 $tmp['Tag'] = $tag['Tag']; 751 } 752 if (count($tmp) == 1 && count($tmp['Media']) == 1) { 753 return false; 754 } 755 $tmp['Media']['flag'] = ($media['Media']['flag'] | MEDIA_FLAG_DIRTY); 756 return $tmp; 757 } 758 759 function editMetaMulti(&$media, &$data) { 760 $tmp = array('Media' => array('id' => $media['Media']['id'])); 761 762 $fields = array('name', 'description', 'date', 'latitude', 'longitude'); 763 foreach ($fields as $field) { 764 if (empty($data['Media'][$field])) { 765 continue; 766 } 767 $tmp['Media'][$field] = $data['Media'][$field]; 768 } 769 770 $tag = $this->Tag->editMetaMulti(&$media, &$data); 771 if ($tag) { 772 $tmp['Tag'] = $tag['Tag']; 773 } 774 $category = $this->Category->editMetaMulti(&$media, &$data); 775 if ($category) { 776 $tmp['Category'] = $category['Category']; 777 } 778 $location = $this->Location->editMetaMulti(&$media, &$data); 779 if ($location) { 780 $tmp['Location'] = $location['Location']; 781 } 782 if (count($tmp) == 1 && count($tmp['Media']) == 1) { 762 function editMulti(&$media, &$data) { 763 $tmp = array('Media' => array('id' => $media['Media']['id'], 'user_id' => $media['Media']['user_id'])); 764 765 if ($media['Media']['canWriteTag']) { 766 $tag = $this->Tag->editMetaMulti(&$media, &$data); 767 if ($tag) { 768 $tmp['Tag'] = $tag['Tag']; 769 } 770 } 771 if ($media['Media']['canWriteMeta']) { 772 $category = $this->Category->editMetaMulti(&$media, &$data); 773 if ($category) { 774 $tmp['Category'] = $category['Category']; 775 } 776 $location = $this->Location->editMetaMulti(&$media, &$data); 777 if ($location) { 778 $tmp['Location'] = $location['Location']; 779 } 780 $fields = array('latitude', 'longitude'); 781 foreach ($fields as $field) { 782 if (empty($data['Media'][$field])) { 783 continue; 784 } 785 $tmp['Media'][$field] = $data['Media'][$field]; 786 } 787 } 788 if ($media['Media']['canWriteCaption']) { 789 $fields = array('name', 'caption', 'date'); 790 foreach ($fields as $field) { 791 if (empty($data['Media'][$field])) { 792 continue; 793 } else { 794 $tmp['Media'][$field] = $data['Media'][$field]; 795 } 796 } 797 if (isset($data['Media']['rotation'])) { 798 $this->rotate(&$tmp, $media['Media']['orientation'], $data['Media']['rotation']); 799 } 800 } 801 if (count($tmp) == 1 && count($tmp['Media']) == 2) { 783 802 return false; 784 803 } … … 794 813 * @return type 795 814 */ 796 function editTagSingle(&$media, &$data) { 797 $tmp = array('Media' => array('id' => $media['Media']['id'])); 798 799 $tag = $this->Tag->editMetaSingle(&$media, &$data); 800 if (isset($tag['Tag'])) { 801 $tmp['Tag'] = $tag['Tag']; 802 } 803 if (count($tmp) == 1 && count($tmp['Media']) == 1) { 804 // Unchanged data 815 function editSingle(&$media, &$data) { 816 $tmp = array('Media' => array('id' => $media['Media']['id'], 'user_id' => $media['Media']['user_id'])); 817 if ($media['Media']['canWriteTag']) { 818 $tag = $this->Tag->editMetaSingle(&$media, &$data); 819 if (isset($tag['Tag'])) { 820 $tmp['Tag'] = $tag['Tag']; 821 } 822 } 823 if ($media['Media']['canWriteMeta']) { 824 $category = $this->Category->editMetaSingle(&$media, &$data); 825 if (isset($category['Category'])) { 826 $tmp['Category'] = $category['Category']; 827 } 828 $location = $this->Location->editMetaSingle(&$media, &$data); 829 if (isset($location['Location'])) { 830 $tmp['Location'] = $location['Location']; 831 } 832 if (!empty($data['Media']['geo'])) { 833 $this->splitGeo(&$data, $data['Media']['geo']); 834 } 835 $fields = array('latitude', 'longitude', 'altitude'); 836 foreach ($fields as $field) { 837 if (isset($data['Media'][$field]) && $media['Media'][$field] !== $data['Media'][$field]) { 838 $tmp['Media'][$field] = $data['Media'][$field]; 839 } 840 } 841 } 842 if ($media['Media']['canWriteCaption']) { 843 $fields = array('name', 'description', 'date', 'latitude', 'longitude'); 844 foreach ($fields as $field) { 845 if (isset($data['Media'][$field]) && $media['Media'][$field] !== $data['Media'][$field]) { 846 $tmp['Media'][$field] = $data['Media'][$field]; 847 } 848 } 849 if (isset($data['Media']['rotation'])) { 850 $this->rotate(&$tmp, $media['Media']['orientation'], $data['Media']['rotation']); 851 } 852 } 853 // Unchanged data 854 if (count($tmp) == 1 && count($tmp['Media']) == 2) { 805 855 return false; 806 856 } … … 808 858 return $tmp; 809 859 } 810 811 /**812 * Creates an new media data with updated values of given data813 *814 * @param type $media Media model data array815 * @param type $data Input data array816 * @return type817 */818 function editMetaSingle(&$media, &$data) {819 $tmp = array('Media' => array('id' => $media['Media']['id']));820 if (!empty($data['Media']['geo'])) {821 $this->splitGeo(&$data, $data['Media']['geo']);822 }823 $fields = array('name', 'description', 'date', 'latitude', 'longitude');824 foreach ($fields as $field) {825 if (isset($data['Media'][$field]) && $media['Media'][$field] !== $data['Media'][$field]) {826 $tmp['Media'][$field] = $data['Media'][$field];827 }828 }829 $tag = $this->Tag->editMetaSingle(&$media, &$data);830 if (isset($tag['Tag'])) {831 $tmp['Tag'] = $tag['Tag'];832 }833 $category = $this->Category->editMetaSingle(&$media, &$data);834 if (isset($category['Category'])) {835 $tmp['Category'] = $category['Category'];836 }837 $location = $this->Location->editMetaSingle(&$media, &$data);838 if (isset($location['Location'])) {839 $tmp['Location'] = $location['Location'];840 }841 // Unchanged data842 if (count($tmp) == 1 && count($tmp['Media']) == 1) {843 return false;844 }845 $tmp['Media']['flag'] = ($media['Media']['flag'] | MEDIA_FLAG_DIRTY);846 return $tmp;847 }848 860 } 849 861 ?> -
views/elements/explorer/menu.ctp
r3ee918f rbb0e4c0 1 1 <?php 2 $canWriteTag = $canWriteMeta = $canWrite Acl = 0;2 $canWriteTag = $canWriteMeta = $canWriteCaption = $canWriteAcl = 0; 3 3 if (count($this->data)) { 4 4 $canWriteTag = max(Set::extract('/Media/canWriteTag', $this->data)); 5 5 $canWriteMeta = max(Set::extract('/Media/canWriteMeta', $this->data)); 6 $canWriteCaption = max(Set::extract('/Media/canWriteCaption', $this->data)); 6 7 $canWriteAcl = max(Set::extract('/Media/canWriteAcl', $this->data)); 7 8 } … … 85 86 <?php 86 87 echo $form->hidden('Media.ids', array('id' => 'MediaIds')); 87 if ($canWriteMeta) { 88 echo $form->input('Media.date', array('type' => 'text', 'after' => $html->tag('div', __('E.g. 2008-08-07 15:30', true), array('class' => 'description')))); 88 if ($canWriteTag) { 89 echo $form->input('Tag.names', array('label' => __('Tags', true), 'after' => $html->tag('div', __('E.g. newtag, -oldtag', true), array('class' => 'description')))); 90 echo $autocomplete->autoComplete('Tag.names', 'autocomplete/tag', array('split' => true)); 89 91 } 90 echo $form->input('Tag.names', array('label' => __('Tags', true), 'after' => $html->tag('div', __('E.g. newtag, -oldtag', true), array('class' => 'description'))));91 echo $autocomplete->autoComplete('Tag.names', 'autocomplete/tag', array('split' => true));92 92 if ($canWriteMeta) { 93 93 echo $form->input('Category.names', array('label' => __('Categories', true))); … … 102 102 echo $autocomplete->autoComplete('Location.country', 'autocomplete/country'); 103 103 echo $form->input('Media.geo', array('label' => __('Geo data', true), 'maxlength' => 32, 'after' => $html->tag('div', __('latitude, longitude', true), array('class' => 'description')))); 104 } 105 if ($canWriteCaption) { 106 echo $form->input('Media.date', array('type' => 'text', 'after' => $html->tag('div', __('E.g. 2008-08-07 15:30', true), array('class' => 'description')))); 107 echo $form->input('Media.name', array('type' => 'text')); 108 echo $form->input('Media.caption', array('type' => 'textarea')); 109 $rotations = array( 110 '0' => __("Keep", true), 111 '90' => __("90 CW", true), 112 '180' => __("180 CW", true), 113 '270' => __("90 CCW", true) 114 ); 115 echo $html->tag('div', $html->tag('label', __("Rotate", true)) . 116 $html->tag('div', $form->radio('Media.rotation', $rotations, array('legend' => false, 'value' => '0')), array('escape' => false, 'class' => 'radioSet')), array('escape' => false, 'class' => 'input radio')); 104 117 } 105 118 ?> -
views/explorer/editmeta.ctp
r5511ea6 rbb0e4c0 1 1 <?php 2 $mediaId = $ data['Media']['id'];2 $mediaId = $this->data['Media']['id']; 3 3 echo $form->create(null, array('url' => 'savemeta/'.$mediaId, 'id' => 'form-meta-'.$mediaId)); 4 4 ?> 5 5 <fieldset> 6 6 <?php 7 echo $form->input('Media.date', array('type' => 'text', 'value' => $data['Media']['date'], 'label' => __("Date", true))); 8 echo $form->input('Media.name', array('type' => 'text', 'value' => $data['Media']['name'], 'label' => __("Name", true))); 9 echo $form->input('Tag.names', array('label' => __('Tags', true), 'value' => join(', ', Set::extract('/Tag/name', $data)))); 10 echo $autocomplete->autoComplete('Tags.text', 'autocomplete/tag', array('split' => true)); 11 echo $form->input('Category.names', array('label' => __('Categories', true), 'value' => join(', ', Set::extract('/Category/name', $data)))); 12 echo $autocomplete->autoComplete('Categories.text', 'autocomplete/category', array('split' => true)); 13 echo $form->input('Location.city', array('label' => __('City', true), 'value' => join('', Set::extract('/Location[type='.LOCATION_CITY.']/name', $data)))); 14 echo $autocomplete->autoComplete('Locations.city', 'autocomplete/city'); 15 echo $form->input('Location.sublocation', array('label' => __('Sublocation', true), 'value' => join('', Set::extract('/Location[type='.LOCATION_SUBLOCATION.']/name', $data)))); 16 echo $autocomplete->autoComplete('Locations.sublocation', 'autocomplete/sublocation'); 17 echo $form->input('Location.state', array('label' => __('State', true), 'value' => join('', Set::extract('/Location[type='.LOCATION_STATE.']/name', $data)))); 18 echo $autocomplete->autoComplete('Locations.state', 'autocomplete/state'); 19 echo $form->input('Location.country', array('label' => __('Country', true), 'value' => join('', Set::extract('/Location[type='.LOCATION_COUNTRY.']/name', $data)))); 20 echo $autocomplete->autoComplete('Locations.country', 'autocomplete/country'); 21 echo $form->input('Media.geo', array('label' => __('Geo data', true), 'maxlength' => 32)); 7 if ($this->data['Media']['canWriteTag']) { 8 echo $form->input('Tag.names', array('label' => __('Tags', true), 'value' => join(', ', Set::extract('/Tag/name', $this->data)))); 9 echo $autocomplete->autoComplete('Tags.text', 'autocomplete/tag', array('split' => true)); 10 } 11 if ($this->data['Media']['canWriteMeta']) { 12 echo $form->input('Category.names', array('label' => __('Categories', true), 'value' => join(', ', Set::extract('/Category/name', $this->data)))); 13 echo $autocomplete->autoComplete('Categories.text', 'autocomplete/category', array('split' => true)); 14 echo $form->input('Location.city', array('label' => __('City', true), 'value' => join('', Set::extract('/Location[type='.LOCATION_CITY.']/name', $this->data)))); 15 echo $autocomplete->autoComplete('Locations.city', 'autocomplete/city'); 16 echo $form->input('Location.sublocation', array('label' => __('Sublocation', true), 'value' => join('', Set::extract('/Location[type='.LOCATION_SUBLOCATION.']/name', $this->data)))); 17 echo $autocomplete->autoComplete('Locations.sublocation', 'autocomplete/sublocation'); 18 echo $form->input('Location.state', array('label' => __('State', true), 'value' => join('', Set::extract('/Location[type='.LOCATION_STATE.']/name', $this->data)))); 19 echo $autocomplete->autoComplete('Locations.state', 'autocomplete/state'); 20 echo $form->input('Location.country', array('label' => __('Country', true), 'value' => join('', Set::extract('/Location[type='.LOCATION_COUNTRY.']/name', $this->data)))); 21 echo $autocomplete->autoComplete('Locations.country', 'autocomplete/country'); 22 echo $form->input('Media.geo', array('label' => __('Geo data', true), 'maxlength' => 32)); 23 } 24 if ($this->data['Media']['canWriteCaption']) { 25 echo $form->input('Media.date', array('type' => 'text', 'after' => $html->tag('div', __('E.g. 2008-08-07 15:30', true), array('class' => 'description')))); 26 echo $form->input('Media.name', array('type' => 'text')); 27 echo $form->input('Media.caption', array('type' => 'text')); 28 $rotations = array( 29 '0' => __("Keep", true), 30 '90' => __("90 CW", true), 31 '180' => __("180 CW", true), 32 '270' => __("90 CCW", true) 33 ); 34 echo $html->tag('div', $html->tag('label', __("Rotate", true)) . 35 $html->tag('div', $form->radio('Media.rotation', $rotations, array('legend' => false, 'value' => '0')), array('escape' => false, 'class' => 'radioSet')), array('escape' => false, 'class' => 'input radio')); 36 } 22 37 ?> 23 38 </fieldset> -
views/explorer/index.ctp
r6962dbe rbb0e4c0 70 70 } 71 71 }); 72 $dialog.find('.radioSet').buttonset(); 72 73 } 73 74 });
