به روز کردن اطلاعات یک مکان

با استفاده از این فراخوانی اطلاعات یک مکان را به روز می‌کند. کابر باید
دسترسی‌های مجاز را داشته باشد.

@param unknown $request
@param unknown $match
@throws Pluf_Exception_NotImplemented
350032
function update ($request, $match)
    {
        // Get data
        $location = Geo_Shortcuts_GetLocationOr404($match[1]);
        // Check access
//         Geo_Precondition::canEditLocation($request, $location);
        // Do
        $extra = array(
                'user' => $request->user,
                'location' => $location
        );
        $form = new Geo_Form_LocationUpdate(
                array_merge($request->REQUEST, $request->FILES), $extra);
        $new_location = $form->update();
        $request->user->setMessage(
                sprintf(__('the location %s has been updated.'), 
                        (string) $new_location->name));
        return new Pluf_HTTP_Response_Json($new_location);
    }
578549
public static function update($request, $match)
    {
        if (array_key_exists('userId', $match)) {
            // Check user is owner 
            if ($request->user->id != $match['userId'] && !User_Precondition::isOwner($request)) {
                throw new Pluf_Exception_Forbidden('Not allowed to change others avatar');
            }
            $user = Pluf_Shortcuts_GetObjectOr404('User_Account', $match['userId']);
        } else {
            $user = $request->user;
        }
        if($user->isAnonymous()){
            throw new Pluf_Exception_BadRequest('User is not defined');
        }
        return User_Shortcuts_UpdateAvatar($user, array_merge($request->REQUEST, $request->FILES));
    }
942369
public function find($request, $match)
    {
        $builder = new Pluf_Paginator_Builder(new CMS_Content());
        return $builder->setRequest($request)->build();
    }
1003644
public function changeEmail ($request, $match)
    {
        $key = $match[1];
        list ($email, $id, $time) = User_Form_UserChangeEmail::validateKey($key);
        if ($id != $request->user->id) {
            throw new Pluf_Exception('user not match');
        }
        // Now we have a change link coming from the right user.
        if ($request->user->email == $email) {
            return new Pluf_HTTP_Response_Json($request->user);
        }
        
        $request->user->email = $email;
        $request->user->update();
        $request->user->setMessage(
                sprintf(
                        __(
                                'Your new email address "%s" has been validated. Thank you!'), 
                        Pluf_esc($email)));
        User_Shortcuts_UpdateLeveFor($request->user, 'user_email_registerd');
        // Return response
        return new Pluf_HTTP_Response_Json($request->user);
    }
88783
public function addTagBykeyvalue ($request, $match)
    {
        $location = Geo_Shortcuts_GetLocationOr404($match[1]);
        Geo_Precondition::canEditLocation($request, $location);
        $tag = SaaSKM_Tag::getFromString($request->tenant, $request->REQUEST['tag']);
        if(! $tag){
            throw new Pluf_Exception("Tag not found");
        }
        SaaSKM_Precondition::userCanAccessTag($request, $tag);
        SaaSKM_TagRow::add($request->tenant, $location, $tag);
        return new Pluf_HTTP_Response_Json($location);
    }
832207
public function putMap ($request, $match)
    {
        if (isset($match['collectionId'])) {
            $collectionId = $match['collectionId'];
        } else {
            $collectionId = $request->REQUEST['collectionId'];
        }
        // $collection = Pluf_Shortcuts_GetObjectOr404('Collection_Collection',
        // $collectionId);
        if (isset($match['documentId'])) {
            $documentId = $match['documentId'];
        } else {
            $documentId = $request->REQUEST['documentId'];
        }
        $document = Pluf_Shortcuts_GetObjectOr404('Collection_Document', 
                $documentId);
        
        if ($document->collection != $collectionId) {
            throw new Pluf_Exception_DoesNotExist(
                    'Document with id (' . $documentId .
                             ') does not exist in collection with id (' .
                             $collectionId . ')');
        }
        
        $this->putDocumentMap($document, $request->REQUEST);
        return new Pluf_HTTP_Response_Json($this->getDocumentMap($document));
    }
604814
public function match(Request $request)
    {
        foreach ($this->matchers as $matcher) {
            $matcherInstance = app($matcher);
            if ($matcherInstance->matches($request->getPathInfo())) {
                return $matcherInstance->render($request);
            }
        }

        return $this->handlePageNotFound();
    }
1003623
function create ($request, $match)
    {
        $location = Geo_Shortcuts_GetLocationOr404($match[1]);
        $vote = $location->getUserVote($request->tenant, $request->user);
        $extra = array(
                'user' => $request->user,
                'tenant' => $request->tenant,
                'location' => $location,
                'vote' => $vote
        );
        $form = new Geo_Form_Vote(
                array_merge($request->REQUEST, $request->FILES), $extra);
        $old = $vote;
        if ($vote === null) {
            $vote = $form->save();
//             $old = new SaaSKM_Vote();
//             $old->vote_value = ! $vote->vote_value;
//             User_Shortcuts_UpdateLeveFor($request, "jahanjoo_location_like");
        } else {
            $vote = $form->update();
        }
        
        if ($old->vote_value != $vote->vote_value) {
//             User_Shortcuts_UpdateLeveFor($location->get_reporter(), 
//                     "jahanjoo_location_like", $vote->like);
        }
        return new Pluf_HTTP_Response_Json($vote);
    }
997491
public function deleteAccount($request, $match)
    {
        $user = Pluf_Shortcuts_GetObjectOr404('User', $request->user->id);
        $request->user->delete();
        return $user;
    }
1079529
private function parseRewriteRule( $match, $query ) {
        $matches = [ ];
        $request_match = $this->request;
        if ( ! empty( $this->request ) && strpos( $match, $this->request ) === 0 ) {
            $request_match = $this->request . '/' . $this->request;
        }
        if (
            preg_match( "#^{$match}#", $request_match, $matches )
            || preg_match( "#^{$match}#", urldecode( $request_match ), $matches )
        ) {
            $varmatch = NULL;
            if ( $this->resolver->isVerbose() && preg_match( '/pagename=\$matches\[([0-9]+)\]/', $query, $varmatch ) ) {
                $page = get_page_by_path( $matches[ $varmatch[1] ] );
                if ( ! $page ) {
                    return;
                }
            }
            $this->matched_rule = $match;
        }
        return $matches;
    }
67992
public static function count ($request, $match)
    {
        $userId = $request->user ? $request->user->id : 0;
        $sql = new Pluf_SQL('account_id=%s', array($userId));
        
        $message = new User_Message();
        $res = $message->getList(
                array(
                        'count' => true,
                        'filter' => $sql->gen()
                ));
        // Check permission
        return $res[0]['nb_items'];
    }
1093081
public function find ($request, $match)
    {
        // check for collection
        if (isset($match['collectionId'])) {
            $collectionId = $match['collectionId'];
        } elseif (isset($request->REQUEST['collectionId'])) {
            $collectionId = $request->REQUEST['collectionId'];
        }
        
        $document = new Collection_Document();
        $paginator = new Pluf_Paginator($document);
        if (isset($collectionId)) {
            $sql = new Pluf_SQL('collection=%s', 
                    array(
                            $collectionId
                    ));
            $paginator->forced_where = $sql;
        }
        $paginator->list_filters = array(
                'id'
        );
        $search_fields = array(
                'id'
        );
        $sort_fields = array(
                'id',
                'collection'
        );
        $paginator->configure(array(), $search_fields, $sort_fields);
        $paginator->items_per_page = Collection_Shortcuts_NormalizeItemPerPage(
                $request);
        $paginator->setFromRequest($request);
        $docs = $paginator->render_object();
        // TODO: maso, 2017: pass list of attributes
        foreach ($docs['items'] as $key => $value) {
            $docs['items'][$key] = $this->getDocumentMap($value);
        }
        return new Pluf_HTTP_Response_Json($docs);
    }
564764
public static function update($request, $match)
    {
        $model = Pluf_Shortcuts_GetObjectOr404('User_Role', $match['id']);
        $form = Pluf_Shortcuts_GetFormForUpdateModel($model, $request->REQUEST, array());
        $model = $form->save();
        $request->user->setMessage(sprintf(__('Role data has been updated.'), (string) $model));
        return new Pluf_HTTP_Response_Json($model);
    }
1352426
public function loadResource($request, $match)
    {
        // First part of path
        $firstPart = $match['firstPart'];
        // Remain part of path
        $remainPart = '';
        if (array_key_exists('remainPart', $match)) {
            $remainPart = $match['remainPart'];
        }

        $spa = Tenant_SPA::getSpaByName($firstPart);
        if (isset($spa)) { // SPA is valid
            $path = $remainPart;
            $spaName = $firstPart;
        } else {
            // first part is not an SPA so use default SPA
            $path = isset($remainPart) && ! empty($remainPart) ? $firstPart . '/' . $remainPart : $firstPart;

            // find a resource
            $tenantResource = $this->findTenantResource('/' . $path);
            if ($tenantResource) {
                return new Pluf_HTTP_Response_File($tenantResource->getAbsloutPath(), $tenantResource->mime_type);
            }

            // [OR] check for default spa
            $name = Tenant_Service::setting('spa.default', 'not-found');
            $spa = Tenant_SPA::getSpaByName($name);
            if ($spa === null) {
                $spa = Tenant_SpaService::getNotfoundSpa();
                $spaName = 'not-found';
            } else {
                $spaName = null;
            }
        }

        if (preg_match('/.+\.[a-zA-Z0-9]+$/', $path)) {
            // Looking for file in SPA
            $resPath = $spa->getResourcePath($path);
            $isMain = false;
        } else {
            // [OR]Request is for main file (path is an internal state)
            $resPath = $spa->getMainPagePath();
            $isMain = true;
        }
        if ($isMain) {
            return new Tenant_HTTP_Response_SpaMain($resPath, Pluf_FileUtil::getMimeType($resPath), $spaName);
        } else {
            return new Pluf_HTTP_Response_File($resPath, Pluf_FileUtil::getMimeType($resPath));
        }
    }
1106462
private function handleRouterAnswer($match)
    {
        if ($match["target"] === self::DYNAMIC_PARSE) {
            $this->handleDynamicRouterAnswer($match);
        } else {
            $this->handleMatchedRouterAnswer($match);
        }

        if (!method_exists($this->controller, $this->action)) {
            $this->action = "noActionMatch";
        }
    }
1361232
public function password($request, $match)
    {
        $msg = array(
            'message' => 'succcess'
        );
        // TODO: maso, 2017: recover by mail
        if (array_key_exists('email', $request->REQUEST)) {
            $sql = new Pluf_SQL('email=%s', array(
                $request->REQUEST['email']
            ));
            $user = $request->user->getOne($sql->gen());
            if ($user) {
                $this->sendPasswordToken($request, $user);
            }
            return $msg;
        }
        // TODO: maso, 2017: recover by login
        if (array_key_exists('login', $request->REQUEST)) {
            $sql = new Pluf_SQL('login=%s', array(
                $request->REQUEST['login']
            ));
            $user = $request->user->getOne($sql->gen());
            if ($user) {
                $this->sendPasswordToken($request, $user);
            }
            return $msg;
        }
        // Reset password by token
        if (array_key_exists('token', $request->REQUEST)) {
            $token = new User_PasswordToken();
            $sql = new Pluf_SQL('token=%s', array(
                $request->REQUEST['token']
            ));
            $token = $token->getOne($sql->gen());
            if (! $token || $token->isExpired()) {
                throw new Pluf_Exception_DoesNotExist('Token not exist');
            }
            $user = $token->get_user();
            $user->setPassword($request->REQUEST['new']);
            $user->update();
            $token->delete();
            return $msg;
        }
        // Reset password by old password
        if (array_key_exists('old', $request->REQUEST) || array_key_exists('old_password', $request->REQUEST)) {
            $oldPass = array_key_exists('old', $request->REQUEST) ? 
            $request->REQUEST['old'] : $request->REQUEST['old_password'];
            if ($request->user->isAnonymous()) {
                throw new Pluf_Exception_Unauthorized();
            }
            // Retreive credential
            $cred = User_Credential::getCredential($request->user->id);
            if (! $cred->checkPassword($oldPass)) {
                throw new Pluf_Exception_MismatchParameter('Old pass is not currect');
            }
            $newPass = array_key_exists('new', $request->REQUEST) ? 
                $request->REQUEST['new'] : $request->REQUEST['password'];
            $cred->setPassword($newPass);
            $cred->update();
            return $msg;
        }

        throw new Pluf_Exception_MismatchParameter('Invalid request params');
    }
844011
public static function add($request, $match)
    {
        $perm = Pluf_Shortcuts_GetObjectOr404('User_Role', $match['role_id']);
        if (array_key_exists('user_id', $match)) {
            $user = Pluf_Shortcuts_GetObjectOr404('User_Account', $match['user_id']);
        } elseif (array_key_exists('user_id', $request->REQUEST)) {
            $user = Pluf_Shortcuts_GetObjectOr404('User_Account', $request->REQUEST['user_id']);
        } elseif (array_key_exists('login', $request->REQUEST)) {
            $user = new User_Account();
            $user = $user->getUser($request->REQUEST['login']);
        }
        if (! isset($user) || $user->isAnonymous()) {
            throw new Pluf_HTTP_Error404(__('User not found'));
        }
        $perm->setAssoc($user);
        return $user;
    }