Example #1
0
        /**
     * @param PCRequest $request
     */
    public function profileAction($request) {

        $auth = $request->getAuthHandler();
        $auth->authorize();
         $params = $request->getParams();
        
       

        if (isset($params['id']) && $auth->isAuthorized() && (strcmp($params['id'], $auth->getUserIdentifier()) == 0)) {

            $result = array();
            $user = PCModelUser::getCurrentUser();

            $result['username'] = $user->getUsername();
            $result['name'] = $user->getName();
            $result['surname'] = $user->getSurname();
            $result['member_since'] = $user->getCreation_date()->format("Y-m-d");
            $result['user_id'] = $user->getIdentifier();
            $result['email'] = $user->getEmail();
            $result['title'] = "WebSherpa - " . $user->getUsername();
            return PCRendererHTML::rendererForView('user', $result);
        }


        return null;
    }
Example #2
0
 /**
  *
  * @param PCException $ex 
  */
 public static function handleException($ex)
 {
     if ($ex->getCode() == 404) {
         header('HTTP/1.1 404 Not Found');
     }
     $request = PCRequest::currentRequest();
     $type = $request->getRequestType();
     $response = PCResponse::currentResponse();
     $response->setResponseCode($ex->getCode());
     $renderer = NULL;
     if ($type == PCRequest::TYPE_AJAX) {
         $result = array('error' => $ex->getMessage());
         $renderer = new PCRendererJSON($result, 404);
     } else {
         if ($type == PCRequest::TYPE_WEB) {
             $renderer = PCRendererHTML::rendererForView('404', array('title' => "Sorry, page not found :("));
         } else {
             if ($type == PCRequest::TYPE_API) {
                 die('API NOT YET SUPPORTED');
             } else {
                 die("UNKNOWN REQUEST TYPE: {$type}");
             }
         }
     }
     $response->setRenderer($renderer);
     $response->sendResponse();
     if (defined('DEBUG')) {
         error_log($ex->getMessage());
         error_log($ex->getTraceAsString());
     }
 }
Example #3
0
 /**
  * 
  * @param PCRequest $request
  */
 public function homeAction($request) {
    
     $result = array();
     $result['title'] = "WebSherpa - Home";
     
     $response = PCResponse::currentResponse();
     $renderer = PCRendererHTML::rendererForView("home", $result);
     $response->setRenderer($renderer);
     
     
     return $response;
 }
Example #4
0
     /**
  * 
  * @param PCRequest $request
  */
 public function repassAction($request){
     $params = $request->getParams();
     $user_id = $params['id'];
     $hash = $params['val'];
     $model_user = NULL;
     
     $result = PCMapperRepass::handleRepassRequest($user_id, $hash, $model_user);
     if($result == FALSE){
         return NULL;
     }
     
     $mail = PCEmailBuilder::buildEmailForPasswordNotification($result, $model_user);
     PCEmailSender::sendMail($mail);
    
    
     $content = array();
     $content['title'] = "WebSherpa";
     $content['pageContent']= "<h1>A new password has been sent to your e-mail address (".$model_user->getEmail().")</h1>";
     return PCRendererHTML::rendererForView('flexiblePage', $content);        
 }
Example #5
0
    /**
     * @param PCRequest $request
     */
    public function facebookCallbackAction($request) {
        PCAutoloader::importLibrary('facebook');
        $facebook = new Facebook(array(
            "appId" => FB_APP_ID,
            "secret" => FB_APP_SECRET,
            "cookie" => true
        ));
        $params = $request->getParams();
        $user_profile = NULL;
        
        try {
            $user = $facebook->getUser();
            if (isset($user)) {
                $user_profile = $facebook->api('/me');      
            }
        } catch (FacebookApiException $e) {
            c_dump($_GET);
            error_log("AAAA".$e);
            throw new PCExceptionRedirection("/page/register");
        }
        
        if (isset($params['reg_username'])){
            
            if (PCMapperUser::validateUsername($params['reg_username']) == FALSE) {
                $cont = array("title" => "WebSherpa - Insert Username", "text_error" => "Insert a valid Username; min 6 characters use only characters and numbers and \"_\"", "show_email" => TRUE);
                return PCRendererHTML::rendererForView('insertUname', $cont);
            }

            if (count(PCModelManager::fetchModelObjectInstances(PCModelUser::getMapper(), array("username" => $params['reg_username']))) != 0) {
                $cont = array("title" => "WebSherpa - Insert Username", "text_error" => "Username already used, please choose another username.", "show_email" => TRUE);
                return PCRendererHTML::rendererForView('insertUname', $cont);
            }
            
            $adapter = new PCHelperSocialAdapterFacebook($facebook, $user_profile, $params['reg_username']);
            if($request->getAuthHandler()->authorizeOauthUser($adapter)){
                throw new PCExceptionRedirection("/");
            }
            throw new PCExceptionRedirection("/page/register");
        }
        else{
            
            $adapter = new PCHelperSocialAdapterFacebook($facebook, $user_profile);
            if($request->getAuthHandler()->authorizeOauthUser($adapter) === FALSE){
                
                return PCRendererHTML::rendererForView('insertUname', array("title" => "WebSherpa - Insert Username"));
            }
            
            throw new PCExceptionRedirection("/");
        }
        
    }
Example #6
0
    /**
     * 
     * @param PCRequest $request
     */
    public function siteAction($request) {
        $param = $request->getParams();

        $hostName = $request->dequeuePathComponent();
        if (isset($hostName)) {
            $site = PCMapperWebsite::getSiteWithDomain($hostName);
            if (isset($site) == FALSE) {
                throw new PCExceptionController("Page not found", 404);
            }
            $identifier = $site->getIdentifier();
            throw new PCExceptionRedirection("/sites/site?id=$identifier");
        }


        if (isset($param['id']) == FALSE)
            throw new PCExceptionController("Page not found", 404);
        /** @value  PCModelWebsite $site */
        $site = PCModelManager::fetchObjectWithIdentifier(PCModelWebsite::getMapper(), $param['id'], NULL, TRUE);

        if (!isset($site)) {
            throw new PCExceptionController("Page not found", 404);
        }

        if ($site->cacheIsExpired()) {
            $site = PCMapperWebsite::recacheSiteReview($site);
            if (isset($site) == FALSE) {
                throw new PCExceptionController('Error caching', 500);
            }
        }

        $result = array();

        $result['siteCategory'] = PCMapperCategory::nameFromIdentifier($site->getCategory());
        $result['site_id'] = $site->getIdentifier();
        $result['siteHost'] = $site->getUrl();

        $result['reliability'] = $site->getReliability();
        $result['contents'] = $site->getContents();
        $result['usability'] = $site->getUsability();

        $result['averageVote'] = $site->getVote();
        $result['votesCount'] = $site->getNumber_of_votes();
        $result['dateAdded'] = $site->getDate_added()->format("Y-m-d");

        $reviews = PCMapperReview::getReviewsWithSiteIdentifier($site->getIdentifier(), 0);
        $reviewsList = array();

        foreach ($reviews as $r) {
            $reviewArray = array();
            $reviewArray["vote"] = sprintf("%.1f", $r->getVote());

            $user = PCModelManager::fetchObjectWithIdentifier(PCModelUser::getMapper(), $r->getUserIdentifier(), NULL, TRUE);

            $reviewArray["user"] = $user->getUsername();
            $reviewArray["date_added"] = $r->getDate_added()->format("Y-m-d");
            $reviewArray["comment"] = $r->getComment();
            $reviewArray["reviewId"] = $r->getIdentifier();
            $reviewArray["userId"] = $r->getUserIdentifier();
            $reviewArray['reliability'] = sprintf("%.1f", $r->getReliabilityVote());
            $reviewArray['contents'] = sprintf("%.1f", $r->getContentsVote());
            $reviewArray['usability'] = sprintf("%.1f", $r->getUsabilityVote());
            $reviewsList[] = $reviewArray;
        }

        $result['reviews'] = $reviewsList;


        $result['title'] = "WebSherpa - " . $site->getUrl();
        return PCRendererHTML::rendererForView('host', $result);
    }