/**
  * Redirects the client to a URL for viewing an entry/draft/version on the front end.
  *
  * @param mixed $entryId
  * @param mixed $locale
  * @param mixed $draftId
  * @param mixed $versionId
  *
  * @throws HttpException
  * @return null
  */
 public function actionShareEntry($entryId = null, $locale = null, $draftId = null, $versionId = null)
 {
     if ($entryId) {
         $entry = craft()->entries->getEntryById($entryId, $locale);
         if (!$entry) {
             throw new HttpException(404);
         }
         $params = array('entryId' => $entryId, 'locale' => $entry->locale);
     } else {
         if ($draftId) {
             $entry = craft()->entryRevisions->getDraftById($draftId);
             if (!$entry) {
                 throw new HttpException(404);
             }
             $params = array('draftId' => $draftId);
         } else {
             if ($versionId) {
                 $entry = craft()->entryRevisions->getVersionById($versionId);
                 if (!$entry) {
                     throw new HttpException(404);
                 }
                 $params = array('versionId' => $versionId);
             } else {
                 throw new HttpException(404);
             }
         }
     }
     // Make sure they have permission to be viewing this entry
     $this->enforceEditEntryPermissions($entry);
     // Make sure the entry actually can be viewed
     if (!craft()->sections->isSectionTemplateValid($entry->getSection())) {
         throw new HttpException(404);
     }
     // Create the token and redirect to the entry URL with the token in place
     $token = craft()->tokens->createToken(array('action' => 'entries/viewSharedEntry', 'params' => $params));
     $url = UrlHelper::getUrlWithToken($entry->getUrl(), $token);
     craft()->request->redirect($url);
 }
 /**
  * Redirects the client to a URL for viewing a disabled category on the front end.
  *
  * @param mixed $categoryId
  * @param mixed $locale
  *
  * @throws HttpException
  * @return null
  */
 public function actionShareCategory($categoryId, $locale = null)
 {
     $category = craft()->categories->getCategoryById($categoryId, $locale);
     if (!$category) {
         throw new HttpException(404);
     }
     // Make sure they have permission to be viewing this category
     $this->_enforceEditCategoryPermissions($category);
     // Make sure the category actually can be viewed
     if (!craft()->categories->isGroupTemplateValid($category->getGroup())) {
         throw new HttpException(404);
     }
     // Create the token and redirect to the category URL with the token in place
     $token = craft()->tokens->createToken(array('action' => 'categories/viewSharedCategory', 'params' => array('categoryId' => $categoryId, 'locale' => $category->locale)));
     $url = UrlHelper::getUrlWithToken($category->getUrl(), $token);
     craft()->request->redirect($url);
 }
 /**
  * Redirects the client to a URL for viewing an entry/draft on the front end.
  *
  * @param mixed $entryId
  *
  * @throws HttpException
  * @return null
  */
 public function actionShareEntry($entryId = null)
 {
     if ($entryId) {
         $entry = sproutEmail()->entries->getEntryById($entryId);
         if (!$entry) {
             throw new HttpException(404);
         }
         $params = array('entryId' => $entryId);
     } else {
         throw new HttpException(404);
     }
     // Create the token and redirect to the entry URL with the token in place
     $token = craft()->tokens->createToken(array('action' => 'sproutEmail/entry/viewSharedEntry', 'params' => $params));
     $url = UrlHelper::getUrlWithToken($entry->getUrl(), $token);
     craft()->request->redirect($url);
 }