/** * Remove thumbnails and db entries for deleted files * @param array $params All parameters passed by hook */ public static function cleanupForDelete($params) { // Get full thumbnail path $path = $params['path']; \OCA\OCLife\utilities::deleteThumb($path); // Now remove all entry in DB for this file // -- Verificare che qui esista l'entry del file nel DB!!! :-/// $fileInfos = \OC\Files\Filesystem::getFileInfo($path); if ($fileInfos['fileid']) { $result = \OCA\OCLife\hTags::removeAllTagsForFile($fileInfos['fileid']); } return $result; }
if (array_search($tagOp, $validOps) === FALSE) { $result = array('result' => 'KO', 'title' => '', 'key' => ''); die(json_encode($result)); } // Check for valid input parameters $parentID = intval(filter_input(INPUT_POST, 'parentID', FILTER_SANITIZE_NUMBER_INT)); $tagID = filter_input(INPUT_POST, 'tagID', FILTER_SANITIZE_NUMBER_INT); $tagName = filter_input(INPUT_POST, 'tagName', FILTER_SANITIZE_STRING); $tagLang = filter_input(INPUT_POST, 'tagLang', FILTER_SANITIZE_STRING); if ($parentID === FALSE || $tagName === FALSE || strlen($tagLang) === 0 || strlen($tagLang) > 2) { $result = array('result' => 'KO', 'title' => '', 'key' => ''); die(json_encode($result)); } // For write operations check if tag can be written if ($tagOp == 'rename' || $tagOp == 'delete') { if (!\OCA\OCLife\hTags::writeAllowed($tagID)) { $result = array('result' => 'NOTALLOWED', 'title' => '', 'key' => $tagID); die(json_encode($result)); } } // Tag handler instance $ctags = new \OCA\OCLife\hTags(); // Switch between possible operations switch ($tagOp) { case 'new': $tagID = $ctags->newTag($tagLang, $tagName, $parentID); $permission = $ctags->getTagPermission($tagID); $result = TRUE; break; case 'rename': $tagData = array($tagLang => $tagName);
* oclife is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * oclife is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with oclife. If not, see <http://www.gnu.org/licenses/>. */ \OCP\JSON::callCheck(); \OCP\JSON::checkLoggedIn(); \OCP\JSON::checkAppEnabled('oclife'); $rawFilesData = filter_input(INPUT_POST, 'id', FILTER_SANITIZE_URL); $filesData = json_decode($rawFilesData); if (is_array($filesData)) { $tagCodes = \OCA\OCLife\hTags::getCommonTagsForFiles($filesData); } else { $tagCodes = \OCA\OCLife\hTags::getAllTagsForFile($filesData); } $tags = new \OCA\OCLife\hTags(); $result = array(); foreach ($tagCodes as $tagID) { $tagData = $tags->searchTagFromID($tagID); $result[] = new \OCA\OCLife\tag($tagID, $tagData['xx']); } $jsonTagData = json_encode((array) $result); echo $jsonTagData;
* oclife is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with oclife. If not, see <http://www.gnu.org/licenses/>. */ \OCP\JSON::callCheck(); \OCP\JSON::checkLoggedIn(); \OCP\JSON::checkAppEnabled('oclife'); $ctags = new \OCA\OCLife\hTags(); $JSONtags = filter_input(INPUT_POST, 'tags', FILTER_SANITIZE_URL); // Look for selected tag and child $tags = json_decode($JSONtags); $tagsToSearch = array(); foreach ($tags as $tag) { $tagID = intval($tag->key); $partTags = $ctags->getAllChildID($tagID); foreach ($partTags as $tag) { $tagsToSearch[] = intval($tag); } } // Look for files with that tag $filesIDs = \OCA\OCLife\hTags::getFileWithTagArray($tagsToSearch); $fileData = \OCA\OCLife\utilities::getFileInfoFromID(OCP\User::getUser(), $filesIDs); $result = ''; foreach ($fileData as $file) { $result .= \OCA\OCLife\utilities::prepareTile($file); } echo $result;
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with oclife. If not, see <http://www.gnu.org/licenses/>. */ \OCP\JSON::callCheck(); \OCP\JSON::checkLoggedIn(); \OCP\JSON::checkAppEnabled('oclife'); $op = filter_input(INPUT_POST, 'op', FILTER_SANITIZE_STRING); $rawFileID = filter_input(INPUT_POST, 'fileID', FILTER_SANITIZE_URL); $tagID = filter_input(INPUT_POST, 'tagID', FILTER_SANITIZE_NUMBER_INT); $fileIDs = json_decode($rawFileID); switch ($op) { case 'add': if (is_array($fileIDs)) { $result = \OCA\OCLife\hTags::addTagForFiles($fileIDs, $tagID); } else { $result = \OCA\OCLife\hTags::addTagForFile($fileIDs, $tagID); } break; case 'remove': if (is_array($fileIDs)) { $result = \OCA\OCLife\hTags::removeTagForFiles($fileIDs, $tagID); } else { $result = \OCA\OCLife\hTags::removeTagForFile($fileIDs, $tagID); } break; } die($result);
/** * Check if provided tag id can be read by the provided user * @param $tagid integer Tag id * @param $user string Actual user; NULL pickup actual logged in user * @return boolean TRUE if permission is valid, false otherwise */ public static function readAllowed($tagid, $user = NULL) { // If owner is not set, assign the actual username if ($user === NULL) { $user = \OCP\User::getUser(); } // If user is an administrator, read is allowed if (\OC_User::isAdminUser(\OCP\User::getUser())) { return TRUE; } // Query for actual tag's owner and permission $sql = "SELECT `owner`, `permission` FROM `*PREFIX*oclife_tags` WHERE `id`=?"; $args = array($tagid); $query = \OCP\DB::prepare($sql); $resRsrc = $query->execute($args); $owner = NULL; $permission = NULL; while ($row = $resRsrc->fetchRow()) { // Legacy check on user and permission $permission = \OCA\OCLife\hTags::getPermission($row['permission']); $owner = isset($row['owner']) ? $row['owner'] : $user; } // Check if worldwide readable if (substr($permission, 4, 1) === 'r') { return TRUE; } // Check for operating on owner's tag if ($user === $owner) { return substr($permission, 0, 1) === 'r' ? TRUE : FALSE; } // Check for tags owned by group's companion where $user belongs to if (substr($permission, 2, 1) === 'r') { $userCompanion = \OCA\OCLife\utilities::getUsers($user); $groupPos = in_array($owner, $userCompanion); return $groupPos === FALSE ? FALSE : TRUE; } else { return FALSE; } }