Exemplo n.º 1
0
 public function checkPosts()
 {
     global $current_user, $wp_query;
     $userId = 0;
     if (isset($current_user->ID)) {
         $userId = $current_user->ID;
     }
     if (is_home()) {
         $protectedContent = new MM_ProtectedContentEngine();
         $posts = array();
         for ($i = 0; $i < count($wp_query->posts); $i++) {
             $post = $wp_query->posts[$i];
             if (!$protectedContent->canAccessPost($post->ID, $userId)) {
                 $post->post_content = "You don't have access to view this content";
             }
             $posts[] = $post;
         }
         $wp_query->posts = $posts;
     }
 }
Exemplo n.º 2
0
 function loginRedirect($redirectTo, $request, $user)
 {
     // clear login form session parameters
     MM_Session::clear(MM_Session::$KEY_LOGIN_FORM_USER_ID);
     MM_Session::clear(MM_Session::$KEY_LOGIN_FORM_USERNAME);
     $newRedirectTo = "";
     $allowUserOverride = true;
     if (class_exists("MM_CorePageEngine")) {
         if ($user instanceof WP_User && isset($user->data->ID) && intval($user->data->ID) > 0) {
             // check if this is an employee
             $employee = MM_Employee::findByUserId($user->data->ID);
             if ($employee->isValid()) {
                 MM_Preview::clearPreviewMode();
                 MM_Preview::getData();
                 $newRedirectTo = $employee->getHomepage();
             }
             if (empty($newRedirectTo)) {
                 $mmUser = new MM_User($user->data->ID);
                 if ($mmUser->getStatus() == MM_Status::$EXPIRED) {
                     $allowUserOverride = false;
                     $newRedirectTo = MM_CorePageEngine::getUrl(MM_CorePageType::$ERROR, MM_Error::$ACCOUNT_EXPIRED, $mmUser);
                     wp_logout();
                 } else {
                     if ($mmUser->getStatus() == MM_Status::$CANCELED) {
                         $allowUserOverride = false;
                         $newRedirectTo = MM_CorePageEngine::getUrl(MM_CorePageType::$ERROR, MM_Error::$ACCOUNT_CANCELED, $mmUser);
                         wp_logout();
                     } else {
                         if ($mmUser->getStatus() == MM_Status::$LOCKED) {
                             $allowUserOverride = false;
                             $newRedirectTo = MM_CorePageEngine::getUrl(MM_CorePageType::$ERROR, MM_Error::$ACCOUNT_LOCKED, $mmUser);
                             wp_logout();
                         } else {
                             if ($mmUser->getStatus() == MM_Status::$OVERDUE) {
                                 $newRedirectTo = MM_CorePageEngine::getUrl(MM_CorePageType::$MY_ACCOUNT, "", $mmUser);
                             } else {
                                 MM_Preview::clearPreviewMode();
                                 $setting = MM_OptionUtils::getOption(MM_OptionUtils::$OPTION_KEY_ON_LOGIN_USE_WP_FRONTPAGE);
                                 if ($setting == "1") {
                                     $newRedirectTo = MM_OptionUtils::getOption("siteurl");
                                 } else {
                                     $newRedirectTo = MM_CorePageEngine::getUrl(MM_CorePageType::$MEMBER_HOME_PAGE, "", $mmUser);
                                 }
                                 $lastAccessDeniedPageID = MM_Session::value(MM_OptionUtils::$OPTION_KEY_LAST_PAGE_DENIED);
                                 // check if current member has access to the last access denied page
                                 $pce = new MM_ProtectedContentEngine();
                                 if (intval($lastAccessDeniedPageID) > 0 && $pce->canAccessPost($lastAccessDeniedPageID, $mmUser->getId())) {
                                     $corePageEngine = new MM_CorePageEngine();
                                     if (!$corePageEngine->arePermalinksUsed()) {
                                         $newRedirectTo = get_page_link($lastAccessDeniedPageID);
                                     } else {
                                         $newRedirectTo = get_permalink($lastAccessDeniedPageID);
                                     }
                                 }
                                 MM_Session::clear(MM_OptionUtils::$OPTION_KEY_LAST_PAGE_DENIED);
                                 MM_ActivityLog::log($mmUser, MM_ActivityLog::$EVENT_TYPE_LOGIN);
                                 if ($mmUser->hasReachedMaxIPCount()) {
                                     global $current_user, $user;
                                     $mmUser->setStatus(MM_Status::$LOCKED);
                                     $mmUser->commitData();
                                     $newRedirectTo = MM_CorePageEngine::getUrl(MM_CorePageType::$ERROR, MM_Error::$ACCOUNT_LOCKED, $mmUser);
                                     wp_logout();
                                 }
                             }
                         }
                     }
                 }
                 if (empty($newRedirectTo)) {
                     $newRedirectTo = MM_OptionUtils::getOption("siteurl");
                 }
             }
         }
         // give customer an opportunity to redirect the user
         if ($allowUserOverride) {
             $currentUrl = !empty($newRedirectTo) ? $newRedirectTo : $redirectTo;
             $infoObj = new stdClass();
             $infoObj->currentUrl = $currentUrl;
             $infoObj->user = $user;
             $redirectOverride = apply_filters(MM_Filters::$LOGIN_REDIRECT, $infoObj);
             if (is_string($redirectOverride) && !empty($redirectOverride) && $redirectOverride != $currentUrl) {
                 if (!defined("DOING_AJAX") || !DOING_AJAX) {
                     wp_redirect($redirectOverride);
                     exit;
                 } else {
                     return $redirectOverride;
                 }
             }
         }
         if (!empty($newRedirectTo)) {
             return $newRedirectTo;
         }
         return $redirectTo;
     }
 }