method, "list")) { session_write_close(); $this->SmartAlbumList(); } elseif (!strcasecmp($this->method, "getinfo")) { session_write_close(); $this->GetInfo(); } else { csSYNOPhotoMisc::CheckSessionTimeOut(); if (!strcasecmp($this->method, "create")) { $this->Create(); } elseif (!strcasecmp($this->method, "edit")) { $this->Edit(); } elseif (!strcasecmp($this->method, "delete")) { $this->Delete(); } } } private function ExtractAlbumToArray($data) { $params = array(); $idArr = array(); $items = explode(',', $data); foreach ($items as $item) { $arr = explode('_', $item); if (2 !== count($arr)) { return $idArr; } if ('album' !== $arr[0]) { return $idArr; } $sharename = trim($arr[1]); if ('' != $sharename) { $sharename = @pack('H*', $arr[1]); array_push($params, $sharename); } } $albums = Album::GetBySharename($params); foreach ($albums as $album) { $id = $album['shareid']; array_push($idArr, $id); } return $idArr; } private function ExtractTagStringToArray($tagString) { $tagArr = array(); $arr = explode(',', $tagString); foreach ($arr as $tag) { $split = explode('tag_', $tag); if (2 !== count($split)) { return $tagArr; } array_push($tagArr, $split[1]); } return $tagArr; } private function ExtractExifStringToArray($exifString, $prefix = 'tag_') { $exifArr = array(); $arr = explode(',', $exifString); foreach ($arr as $exif) { $split = explode($prefix, $exif); if (2 !== count($split)) { return false; } array_push($exifArr, $split[1]); } return $exifArr; } private function GetParams_List() { $params = array(); if (!isset($_REQUEST['offset']) || !isset($_REQUEST['limit'])) { return false; } $params['offset'] = $_REQUEST['offset']; $params['limit'] = $_REQUEST['limit']; $params['sort_by'] = (isset($_REQUEST['sort_by'])) ? $_REQUEST['sort_by'] : 'title'; if (!in_array($params['sort_by'], array('title'))) { return false; } $params['sort_direction'] = (isset($_REQUEST['sort_direction'])) ? $_REQUEST['sort_direction'] : 'asc'; if (!in_array($params['sort_direction'], array('asc', 'desc'))) { return false; } // additional operator $params['additional'] = array(); $params['additional'] = explode(',', $_REQUEST['additional']); return $params; } /** * * @return * params object - success * -1 - bad parameter * -2 - smart album not exist */ private function GetParams_Info() { $params = array(); if (!isset($_REQUEST['id'])) { return -1; } $arr = explode(',', $_REQUEST['id']); $params['id'] = array(); foreach ($arr as $smartID) { if (!$this->CheckSmartAlbumExist($smartID)) { return -2; } $split = explode('smart_', $smartID); array_push($params['id'], $split[1]); } // additional operator $params['additional'] = array(); $params['additional'] = explode(',', $_REQUEST['additional']); return $params; } /** * * @return * -1 - bad parameter * -2 - smart album not exist */ private function GetPrams_Edit() { $params = array(); if (!isset($_REQUEST['id'])) { return -1; } // check smart album exist if (!$this->CheckSmartAlbumExist($_REQUEST['id'])) { return -2; } $arr = explode('smart_', $_REQUEST['id']); if (2 !== count($arr)) { return -1; } $params['id'] = $arr[1]; $smartName = @pack('H*', $arr[1]); $params['name'] = (isset($_REQUEST['name']) && '' !== $_REQUEST['name']) ? $_REQUEST['name'] : $smartName; $params['orig_name'] = $smartName; // get original smart album setting $smartAlbumCond = SmartAlbum::GetSmartAlbumInstance()->GetSmartCondition($smartName); // type if (isset($_REQUEST['type'])) { $params['type'] = $_REQUEST['type']; $arr = explode(',', $params['type']); $count = 0; foreach ($arr as $type) { if (!in_array($type, array('photo', 'video'))) { return -1; } $count++; } if (1 > $count) { return -1; } } else { $params['type'] = $smartAlbumCond['type']; } // albums if (isset($_REQUEST['albums'])) { if (empty($_REQUEST['albums'])) { $params['albums'] = null; } else { $params['albums'] = $this->ExtractAlbumToArray($_REQUEST['albums']); } } else { $arr = $this->ExtractAlbumToArray($smartAlbumCond['albums']); $params['albums'] = empty($arr) ? null : $arr; } // keyword if (isset($_REQUEST['keyword'])) { if ('' === $_REQUEST['keyword']) { $params['keyword'] = null; $params['keyword_op'] = null; } else { $params['keyword'] = $_REQUEST['keyword']; $default = isset($smartAlbumCond['keyword_op']) ? $smartAlbumCond['keyword_op'] : 'any'; $params['keyword_op'] = (isset($_REQUEST['keyword_op'])) ? $_REQUEST['keyword_op'] : $default; if (isset($params['keyword_op']) && !in_array($params['keyword_op'], array('any', 'all', 'exact'))) { return -1; } } } else { $params['keyword'] = $smartAlbumCond['keyword']; $params['keyword_op'] = $smartAlbumCond['keyword_op']; } // date if (isset($_REQUEST['date'])) { if (empty($_REQUEST['date'])) { $params['date'] = null; $params['date_op'] = null; } else { $default = isset($smartAlbumCond['date_op']) ? $smartAlbumCond['date_op'] : 'taken'; $params['date_op'] = (isset($_REQUEST['date_op'])) ? $_REQUEST['date_op'] : $default; if (in_array($params['date_op'], array('recently_add', 'recently_comment'))) { $params['date'] = $_REQUEST['date']; } else if (in_array($params['date_op'], array('taken', 'upload'))) { $dates = explode(',', $_REQUEST['date']); try { if ($dates[0]) { $date1 = new DateTime($dates[0]); } if ($dates[1]) { $date2 = new DateTime($dates[1]); } } catch (Exception $e) { return -1; } if (($date1 && $date2 && $date2 < $date1) || (!$date1 && !$date2)) { return -1; } $params['date'] = ($date1 ? $date1->format('Y-m-d') : "").",".($date2 ? $date2->format("Y-m-d") : ""); } else { return -1; } } } else { $params['date'] = $smartAlbumCond['date']; $params['date_op'] = $smartAlbumCond['date_op']; } // peopel_tag if (isset($_REQUEST['people_tag'])) { if (empty($_REQUEST['people_tag'])) { $params['people_tag'] = null; $params['people_tag_op'] = null; } else { // get people_tag $params['people_tag'] = $this->ExtractTagStringToArray($_REQUEST['people_tag']); // get people_tag_op $default = isset($smartAlbumCond['people_tag_op']) ? $smartAlbumCond['people_tag_op'] : 'all'; $params['people_tag_op'] = (isset($_REQUEST['people_tag_op'])) ? $_REQUEST['people_tag_op'] : $default; if (isset($params['people_tag_op']) && !in_array($params['people_tag_op'], array('all', 'any'))) { return -1; } } } else { $arr = $this->ExtractTagStringToArray($smartAlbumCond['people_tag']); $params['people_tag'] = empty($arr) ? null : $arr; $params['people_tag_op'] = $smartAlbumCond['people_tag_op']; } // geo_tag if (isset($_REQUEST['geo_tag'])) { if (empty($_REQUEST['geo_tag'])) { $params['geo_tag'] = null; $params['geo_tag_op'] = null; } else { // get geo_tag $params['geo_tag'] = $this->ExtractTagStringToArray($_REQUEST['geo_tag']); // get geo_tag_op $default = isset($smartAlbumCond['geo_tag_op']) ? $smartAlbumCond['geo_tag_op'] : 'all'; $params['geo_tag_op'] = (isset($_REQUEST['geo_tag_op'])) ? $_REQUEST['geo_tag_op'] : $default; if (isset($params['geo_tag_op']) && !in_array($params['geo_tag_op'], array('all', 'any'))) { return -1; } } } else { $arr = $this->ExtractTagStringToArray($smartAlbumCond['geo_tag']); $params['geo_tag'] = empty($arr) ? null : $arr; $params['geo_tag_op'] = $smartAlbumCond['geo_tag_op']; } // desc_tag if (isset($_REQUEST['desc_tag'])) { if (empty($_REQUEST['desc_tag'])) { $params['desc_tag'] = null; $params['desc_tag_op'] = null; } else { // get desc_tag $params['desc_tag'] = $this->ExtractTagStringToArray($_REQUEST['desc_tag']); // get desc_tag_op $default = isset($smartAlbumCond['desc_tag_op']) ? $smartAlbumCond['desc_tag_op'] : 'all'; $params['desc_tag_op'] = (isset($_REQUEST['desc_tag_op'])) ? $_REQUEST['desc_tag_op'] : $default; if (isset($params['desc_tag_op']) && !in_array($params['desc_tag_op'], array('all', 'any'))) { return -1; } } } else { $arr = $this->ExtractTagStringToArray($smartAlbumCond['desc_tag']); $params['desc_tag'] = empty($arr) ? null : $arr; $params['desc_tag_op'] = $smartAlbumCond['desc_tag_op']; } foreach(SmartAlbum::$exif2IdPrefix as $label => $prefix) { $exifParam = $this->GetExifParams_Edit($label, $prefix.'_'); if (-1 === $exifParam['success']) { return -1; } else { $params[$label] = $exifParam['label']; $params[$label.'_op'] = $exifParam['op']; } } if ((null === $params['keyword'] || '' === $params['keyword']) && empty($params['date']) && empty($params['people_tag']) && empty($params['geo_tag']) && empty($params['desc_tag']) && empty($params['albums']) && empty($params['camera']) && empty($params['model']) && empty($params['exposure']) && empty($params['aperture']) && empty($params['iso']) && empty($params['focal']) && empty($params['lens']) && empty($params['flash'])) { return -1; } return $params; } private function GetExifParams_Edit($label, $prefix) { $ret['success'] = true; $op = $label."_op"; if (isset($_REQUEST[$label])) { if (empty($_REQUEST[$label])) { $ret['label'] = null; $ret['op'] = null; } else { $ret['label'] = array(); $ret['label'] = $this->ExtractExifStringToArray($_REQUEST[$label], $prefix); $defalt = isset($smartAlbumCond[$op]) ? $smartAlbumCond[$op] : 'any'; $ret['op'] = (isset($_REQUEST[$op])) ? $_REQUEST[$op] : $default; if (isset($ret['op']) && 'any' !== $ret['op']) { $ret['success'] = false; } } } else { $arr = $this->ExtractExifStringToArray($smartAlbumCond[$lable]); $ret['label'] = empty($arr) ? null : $arr; $ret['op'] = $smartAlbumCond[$op]; } return $ret; } private function GetParams_Create() { $params = array(); if (!isset($_REQUEST['name']) || !isset($_REQUEST['type'])) { return false; } $params['name'] = $_REQUEST['name']; // type $params['type'] = $_REQUEST['type']; $arr = explode(',', $params['type']); $count = 0; foreach ($arr as $type) { if (!in_array($type, array('photo', 'video'))) { return false; } $count++; } if (1 > $count) { return false; } $albums = (isset($_REQUEST['albums'])) ? $_REQUEST['albums'] : null; if (!empty($_REQUEST['albums'])) { $params['albums'] = $this->ExtractAlbumToArray($albums); } $params['keyword'] = (isset($_REQUEST['keyword'])) ? $_REQUEST['keyword'] : null; if (!empty($_REQUEST['keyword']) || '0' === $_REQUEST['keyword']) { $default = 'all'; $params['keyword_op'] = (isset($_REQUEST['keyword_op'])) ? $_REQUEST['keyword_op'] : $default; if (isset($params['keyword_op']) && !in_array($params['keyword_op'], array('any', 'all', 'exact'))) { return false; } } $params['date'] = (isset($_REQUEST['date'])) ? $_REQUEST['date'] : null; if (!empty($_REQUEST['date'])) { $default = 'taken'; $params['date_op'] = (isset($_REQUEST['date_op'])) ? $_REQUEST['date_op'] : $default; if (isset($params['date_op']) && !in_array($params['date_op'], array('taken', 'upload', 'recently_add', 'recently_comment'))) { return false; } } $people_tags = (isset($_REQUEST['people_tag'])) ? $_REQUEST['people_tag'] : null; if (!empty($_REQUEST['people_tag'])) { // get people_tag $params['people_tag'] = array(); $params['people_tag'] = $this->ExtractTagStringToArray($people_tags); // get people_tag_op $default = 'all'; $params['people_tag_op'] = (isset($_REQUEST['people_tag_op'])) ? $_REQUEST['people_tag_op'] : $default; if (isset($params['people_tag_op']) && !in_array($params['people_tag_op'], array('all', 'any'))) { return false; } } $geo_tags = (isset($_REQUEST['geo_tag'])) ? $_REQUEST['geo_tag'] : null; if (!empty($_REQUEST['geo_tag'])) { // get geo_tag $params['geo_tag'] = array(); $params['geo_tag'] = $this->ExtractTagStringToArray($geo_tags); // get geo_tag_op $default = 'all'; $params['geo_tag_op'] = (isset($_REQUEST['geo_tag_op'])) ? $_REQUEST['geo_tag_op'] : $default; if (isset($params['geo_tag_op']) && !in_array($params['geo_tag_op'], array('all', 'any'))) { return false; } } $desc_tags = (isset($_REQUEST['desc_tag'])) ? $_REQUEST['desc_tag'] : null; if (!empty($_REQUEST['desc_tag'])) { // get desc_tag $params['desc_tag'] = array(); $params['desc_tag'] = $this->ExtractTagStringToArray($desc_tags); // get desc_tag_op $default = 'all'; $params['desc_tag_op'] = (isset($_REQUEST['desc_tag_op'])) ? $_REQUEST['desc_tag_op'] : $default; if (isset($params['desc_tag_op']) && !in_array($params['desc_tag_op'], array('all', 'any'))) { return false; } } foreach(SmartAlbum::$exif2IdPrefix as $label => $prefix) { $value = (isset($_REQUEST[$label])) ? $_REQUEST[$label] : null; $op = $label.'_op'; if (!empty($_REQUEST[$label])) { $params[$label] = $this->ExtractExifStringToArray($value, $prefix.'_'); $default = 'any'; $params[$op] = (isset($_REQUEST[$op])) ? $_REQUEST[$op] : $default; if (isset($params[$op]) && 'any' !== $params[$op]) { return false; } } } if ((null === $params['keyword'] || '' === $params['keyword']) && empty($params['albums']) && empty($params['date']) && empty($params['people_tag']) && empty($params['geo_tag']) && empty($params['desc_tag']) && empty($params['camera']) && empty($params['model']) && empty($params['exposure']) && empty($params['aperture']) && empty($params['iso']) && empty($params['focal']) && empty($params['lens']) && empty($params['flash'])) { return false; } return $params; } /** * * @param * $tagIDs - array * $type - 0 means people tag * 1 means geo tag * 2 means desc tag */ private function CheckTagExist($tagIDs, $type) { if (!is_array($tagIDs)) { return false; } foreach ($tagIDs as $id) { $query = "SELECT count(id) FROM photo_label WHERE id={$id} AND category={$type}"; $db_result = PHOTO_DB_Query($query); $row = PHOTO_DB_FetchRow($db_result); if (1 !== (int)$row[0]) { return false; } } return true; } private function CheckExifExist($exifNames, $columnName) { if (!is_array($exifNames)) { return false; } foreach($exifNames as $exifName) { if ('flash_v2' == $columnName) { $exifName = str_replace('#', ',', $exifName); } $query = "SELECT count(". $columnName .") FROM photo_image WHERE ". $columnName ."=?"; $db_result = PHOTO_DB_Query($query, array($exifName)); $row = PHOTO_DB_FetchRow($db_result); if (1 > (int)$row[0]) { return false; } } return true; } /** * * @param * $smartID - ex: smart_id */ private function CheckSmartAlbumExist($smartID) { $arr = explode('smart_', $smartID); if (2 !== count($arr)) { return false; } $smartName = @pack('H*', $arr[1]); $result = SmartAlbum::GetSmartAlbumInstance()->ReadSmartAlbumFile(); if (!isset($result['smart_albums'][$smartName])) { return false; } return true; } private function ConvertToSmartExifCondition($data, $label, $op){ $rule_set['field'] = $label; $rule_set['operator'] = $data[$op]; $strings = implode(',', $data[$label]); $rule_set['value'] = $strings; return $rule_set; } private function ConvertToSmartCondition($data) { $rule_sets = array(); $rule_sets[0] = array(); $ret['orig_name'] = $data['orig_name']; $ret['name'] = $data['name']; $ret['desc'] = ''; $ret['show_photo'] = strstr($data['type'], 'photo') ? true : false; $ret['show_video'] = strstr($data['type'], 'video') ? true : false; if (isset($data['albums'])) { $rule_set['field'] = 'albums'; $rule_set['operator'] = 'any'; $albumString = implode(',', $data['albums']); $rule_set['value'] = $albumString; array_push($rule_sets[0], $rule_set); } if (isset($data['keyword']) && isset($data['keyword_op'])) { $rule_set['field'] = 'keyword'; $rule_set['operator'] = $data['keyword_op']; $rule_set['value'] = $data['keyword']; array_push($rule_sets[0], $rule_set); } if (isset($data['date']) && isset($data['date_op'])) { $rule_set['field'] = 'date'; $rule_set['operator'] = $data['date_op']; $rule_set['value'] = $data['date']; array_push($rule_sets[0], $rule_set); } if (isset($data['people_tag']) && isset($data['people_tag_op'])) { $rule_set['field'] = 'people'; $rule_set['operator'] = $data['people_tag_op']; $peopleString = implode(',', $data['people_tag']); $rule_set['value'] = $peopleString; array_push($rule_sets[0], $rule_set); } if (isset($data['geo_tag']) && isset($data['geo_tag_op'])) { $rule_set['field'] = 'geo'; $rule_set['operator'] = $data['geo_tag_op']; $geoString = implode(',', $data['geo_tag']); $rule_set['value'] = $geoString; array_push($rule_sets[0], $rule_set); } if (isset($data['desc_tag']) && isset($data['desc_tag_op'])) { $rule_set['field'] = 'desc'; $rule_set['operator'] = $data['desc_tag_op']; $descString = implode(',', $data['desc_tag']); $rule_set['value'] = $descString; array_push($rule_sets[0], $rule_set); } foreach(SmartAlbum::$exif2IdPrefix as $label => $prefix) { $op = $label.'_op'; if (isset($data[$label]) && isset($data[$op])) { $rule_set = $this->ConvertToSmartExifCondition($data, $label, $op); array_push($rule_sets[0], $rule_set); } } $ret['rule_sets'] = $rule_sets; return json_encode($ret); } private function FormSmartAlbums($smartNames = false, $params = array()) { $smartAlbumList = SmartAlbum::GetSmartAlbumInstance()->ReadSmartAlbumFile(); $smartAlbumArr = array(); if (empty($smartAlbumList) || !is_array($smartAlbumList['smart_albums'])) { return $smartAlbumArr; } $smartAlbums = $smartAlbumList['smart_albums']; if (false != $smartNames) { foreach($smartNames as $name) { if ($smartAlbums[$name]) { $list[$name] = $smartAlbums[$name]; } } } else { $list = $smartAlbums; } $needThumbSize = in_array('thumb_size', $params['additional']); foreach ($list as $key => $item) { $item['name'] = (string)$key; $smartAlbum = Decorator::SmartFormula($item, array( 'param'=> $params, 'needThumbSize' => $needThumbSize )); if (-1 === $smartAlbum) { continue; } $smartAlbumArr[] = $smartAlbum; } return $smartAlbumArr; } private function SortTitle_ASC($a, $b) { if (strtoupper($a['name']) == strtoupper($b['name'])) { return 0; } return (strtoupper($a['name']) < strtoupper($b['name'])) ? -1 : 1; } private function SortTitle_DESC($a, $b) { if (strtoupper($a['name']) == strtoupper($b['name'])) { return 0; } return (strtoupper($a['name']) > strtoupper($b['name'])) ? -1 : 1; } private function SortItem($smartAlbums, $sortBy, $sortDirection, $offset, $limit) { if ('title' ===$sortBy) { if ('asc' === $sortDirection) { usort($smartAlbums, 'self::SortTitle_ASC'); } else { usort($smartAlbums, 'self::SortTitle_DESC'); } } $cutItemSort = array(); if (0 > (int)$limit) { // array_slice() will reorder and reset the numeric array indices by default. // Preserve_keys are set to TRUE to solve bug#2195. $cutItemsSort = array_slice($smartAlbums, $offset, NULL, true); } else { $cutItemsSort = array_slice($smartAlbums, $offset, $limit, true); } return $cutItemsSort; } private function SmartAlbumList() { // Get and check params $params = array(); $params = $this->GetParams_List(); if (!$params) { $this->SetError(WEBAPI_ERR_BAD_REQUEST); goto End; } $resp = array( 'total' => 0, 'offset' => 0, 'smart_albums'=> array() ); $smartAlbumList = SmartAlbum::GetSmartAlbumInstance()->ReadSmartAlbumFile(); if (empty($smartAlbumList) || !is_array($smartAlbumList['smart_albums'])) { goto End; } $smartAlbums = $smartAlbumList['smart_albums']; $selectedAlbums = array(); if ('title' == $params['sort_by']) { if ('asc' === $params['sort_direction']) { ksort($smartAlbums); } else { krsort($smartAlbums); } if (0 > (int)$limit) { // array_slice() will reorder and reset the numeric array indices by default. // Preserve_keys are set to TRUE to solve bug#2195. $selectedAlbums = array_slice($smartAlbums, $params['offset'], NULL, true); } else { $selectedAlbums = array_slice($smartAlbums, $params['offset'], $params['limit'], true); } } if (count($selectedAlbums)) { $albumNames = array_keys($selectedAlbums); } else { $albumNames = false; } // Get and form to webapi format $smart_albums = array(); $smart_albums = $this->FormSmartAlbums($albumNames, $params); $total = count($smart_albums); // sort and set offset, limit $smartSort = $smart_albums; $smartSort = $this->SortItem($smart_albums, $params['sort_by'], $params['sort_direction'], $params['offset'], $params['limit']); $resp['total'] = $total; $offset = (0 > $params['limit']) ? $resp['total'] : $params['offset'] + $params['limit']; $resp['offset'] = ($offset > $total) ? $total : $offset; $resp['smart_albums'] = $smartSort; End: $this->SetResponse($resp); return; } private function GetInfo() { // Get and check params $params = array(); $params = $this->GetParams_Info(); if (-1 === $params) { $this->SetError(WEBAPI_ERR_BAD_REQUEST); goto End; } elseif (-2 === $params) { $this->SetError(PHOTOSTATION_SMARTALBUM_NOT_EXIST); goto End; } // Get and form to webapi format $smartNames = array(); foreach ($params['id'] as $id) { $smartName = @pack('H*', $id); array_push($smartNames, $smartName); } $smart_albums = $this->FormSmartAlbums($smartNames, $params); $resp['smart_albums'] = $smart_albums; $this->SetResponse($resp); End: return; } private function Create() { $isAdmin = isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']); if (false === $isAdmin) { $this->SetError(PHOTOSTATION_SMARTALBUM_ACCESS_DENY); goto End; } // check parameter if (false === ($params = $this->GetParams_Create())) { $this->SetError(WEBAPI_ERR_BAD_REQUEST); goto End; } // check tag_id exist if (is_array($params['people_tag']) && !$this->CheckTagExist($params['people_tag'], 0)) { $this->SetError(PHOTOSTATION_SMARTALBUM_TAG_NOT_EXIST); goto End; } if (is_array($params['geo_tag']) && !$this->CheckTagExist($params['geo_tag'], 1)) { $this->SetError(PHOTOSTATION_SMARTALBUM_TAG_NOT_EXIST); goto End; } if (is_array($params['desc_tag']) && !$this->CheckTagExist($params['desc_tag'], 2)) { $this->SetError(PHOTOSTATION_SMARTALBUM_TAG_NOT_EXIST); goto End; } foreach(SmartAlbum::$exif2Column as $label => $column) { if (is_array($params[$label]) && !$this->CheckExifExist($params[$label], $column)) { $this->SetError(PHOTOSTATION_SMARTALBUM_TAG_NOT_EXIST); goto End; } } // add smart album $jsonRuleData = $this->ConvertToSmartCondition($params); $jsonRet = SmartAlbum::GetSmartAlbumInstance()->AddSmartAlbum($jsonRuleData); $ret = json_decode($jsonRet, true); if (false === $ret['success']) { if ($ret["error"]["code"] == 103) { $this->SetError(PHOTOSTATION_SMARTALBUM_CREATE_FAIL_EXIST); } else { $this->SetError(PHOTOSTATION_SMARTALBUM_CREATE_FAIL); } goto End; } $resp['id'] = 'smart_'.bin2hex($params['name']); $this->SetResponse($resp); End: return; } private function Edit() { $isAdmin = isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']); if (false === $isAdmin) { $this->SetError(PHOTOSTATION_SMARTALBUM_ACCESS_DENY); goto End; } // get parameter $params = $this->GetPrams_Edit(); if (-1 === $params) { $this->SetError(WEBAPI_ERR_BAD_REQUEST); goto End; } elseif (-2 === $params) { $this->SetError(PHOTOSTATION_SMARTALBUM_NOT_EXIST); goto End; } // check tag_id exist if (is_array($params['people_tag']) && !$this->CheckTagExist($params['people_tag'], 0)) { $this->SetError(PHOTOSTATION_SMARTALBUM_TAG_NOT_EXIST); goto End; } if (is_array($params['geo_tag']) && !$this->CheckTagExist($params['geo_tag'], 1)) { $this->SetError(PHOTOSTATION_SMARTALBUM_TAG_NOT_EXIST); goto End; } if (is_array($params['desc_tag']) && !$this->CheckTagExist($params['desc_tag'], 2)) { $this->SetError(PHOTOSTATION_SMARTALBUM_TAG_NOT_EXIST); goto End; } foreach(SmartAlbum::$exif2Column as $label => $column) { if (is_array($params[$label]) && !$this->CheckExifExist($params[$label], $column)) { $this->SetError(PHOTOSTATION_SMARTALBUM_TAG_NOT_EXIST); goto End; } } // edit smart album $jsonRuleData = $this->ConvertToSmartCondition($params); $jsonRet = SmartAlbum::GetSmartAlbumInstance()->EditSmartAlbum($jsonRuleData); $ret = json_decode($jsonRet, true); if (empty($ret) || false === $ret['success']) { $this->SetError(PHOTOSTATION_SMARTALBUM_EDIT_FAIL); goto End; } // category hook if ($params['name'] !== $params['orig_name']) { $newID = bin2hex($params['name']); $query = "UPDATE category_items SET smart_id='{$newID}' WHERE smart_id='{$params['id']}'"; if (false === PHOTO_DB_Query($query)) { $this->SetError(PHOTOSTATION_SMARTALBUM_EDIT_FAIL); goto End; } } $resp['id'] = 'smart_'.bin2hex($params['name']); $this->SetResponse($resp); End: return; } private function Delete() { $isAdmin = isset($_SESSION[SYNOPHOTO_ADMIN_USER]['admin_syno_user']); if (false === $isAdmin) { $this->SetError(PHOTOSTATION_SMARTALBUM_ACCESS_DENY); goto End; } // Get and check params $params = $this->GetParams_Info(); if (-1 === $params) { $this->SetError(WEBAPI_ERR_BAD_REQUEST); goto End; } elseif (-2 === $params) { $this->SetError(PHOTOSTATION_SMARTALBUM_NOT_EXIST); goto End; } // get smart album names $smartNames = array(); foreach ($params['id'] as $id) { $smartName = @pack('H*', $id); array_push($smartNames, $smartName); } // delete foreach ($smartNames as $smartName) { $data['name'] = $smartName; $jsonData = json_encode($data); SmartAlbum::GetSmartAlbumInstance()->DeleteSmartAlbum($jsonData); // category hook $id = bin2hex($smartName); $query = "DELETE FROM category_items WHERE smart_id='{$id}'"; PHOTO_DB_Query($query); } End: return; } } $api = new SmartAlbumAPI(); $api->Run(); ?>