public function obfuscateAssetUrl($asset)
 {
     craft()->fixMeALink->cleanUpStaleLinks();
     $obfuscated_link_hash = craft()->fixMeALink->saveAssetLink($asset);
     $obfuscated_link = UrlHelper::getActionUrl('fixMeALink/link/followLink', array('hash' => $obfuscated_link_hash));
     return $obfuscated_link;
 }
 public function init()
 {
     Craft::log(__METHOD__, LogLevel::Info, true);
     // request params
     $providerHandle = craft()->request->getParam('provider');
     $namespace = craft()->request->getParam('namespace');
     $scope = unserialize(base64_decode(craft()->request->getParam('scope')));
     // userMode
     $userMode = false;
     if (!$namespace) {
         $userMode = true;
     }
     // clean session vars
     if (!craft()->httpSession->get('oauth.social')) {
         craft()->oauth->sessionClean();
     }
     // set session vars
     craft()->oauth->sessionAdd('oauth.providerClass', $providerHandle);
     craft()->oauth->sessionAdd('oauth.userMode', $userMode);
     craft()->oauth->sessionAdd('oauth.referer', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null);
     craft()->oauth->sessionAdd('oauth.scope', $scope);
     // redirect
     $url = UrlHelper::getActionUrl('oauth/public/connect/', array('provider' => $providerHandle, 'namespace' => $namespace));
     $this->redirect($url);
 }
 /**
  * Connect
  *
  * @return null
  */
 public function actionConnect()
 {
     $referer = craft()->request->getUrlReferrer();
     $providerHandle = craft()->request->getParam('provider');
     craft()->httpSession->add('oauth.console.referer', $referer);
     craft()->httpSession->add('oauth.console.providerHandle', $providerHandle);
     craft()->httpSession->remove('oauth.console.token.' . $providerHandle);
     $this->redirect(UrlHelper::getActionUrl('oauth/console/connectStep2'));
 }
 public function actionConnect()
 {
     $referer = craft()->httpSession->get('socialPoster.referer');
     if (!$referer) {
         $referer = craft()->request->getUrlReferrer();
         craft()->httpSession->add('socialPoster.referer', $referer);
     }
     $handle = craft()->request->getParam('handle');
     $redirectUrl = UrlHelper::getActionUrl('socialPoster/oauth/connect', array('handle' => $handle));
     $this->redirect($redirectUrl);
 }
Exemplo n.º 5
0
 public function downvoteAction($comment, $options = array())
 {
     $user = craft()->userSession->getUser();
     $params = array('id' => $comment->id, 'return' => craft()->request->getUrl());
     // Only logged in users can downvote a comment
     if ($user) {
         // Ensure the user hasn't voted yet
         $hasVoted = craft()->comments_vote->hasDownVoted($comment, $user);
         if (!$hasVoted) {
             return UrlHelper::getActionUrl('comments/downvoteComment', $params);
         }
     }
 }
Exemplo n.º 6
0
 public static function removeAction($itemId, $listId = null, $options = array())
 {
     $params = array();
     $params['itemId'] = $itemId;
     $params['return'] = craft()->request->getUrl();
     if ($listId !== null) {
         $params['listId'] = $listId;
     }
     if (isset($options['return'])) {
         $params['return'] = $options['return'];
     }
     return UrlHelper::getActionUrl('shortlist/item/remove', $params);
 }
 public function init()
 {
     Craft::log(__METHOD__, LogLevel::Info, true);
     // request params
     $params = array();
     $params['provider'] = craft()->request->getParam('provider');
     $params['namespace'] = craft()->request->getParam('namespace');
     // clean session vars
     craft()->oauth->sessionClean();
     craft()->oauth->sessionAdd('oauth.referer', $_SERVER['HTTP_REFERER']);
     // redirect
     $url = UrlHelper::getActionUrl('oauth/public/disconnect/', $params);
     $this->redirect($url);
 }
Exemplo n.º 8
0
 /**
  * Returns our dropzone form to the template
  * @param  array  $config An array of settings
  * @return String         The resulting HTML form
  */
 public function form($config = array())
 {
     $this->_includeDropzoneResources();
     $actionUrl = UrlHelper::getActionUrl('dropzone/upload');
     $form = "<form method=\"POST\" enctype=\"multipart/form-data\" class=\"dropzone\" action=\"{$actionUrl}\">";
     if (isset($config['sourceId'])) {
         $form .= "<input type=\"hidden\" name=\"sourceId\" value=\"{$config['sourceId']}\">";
     }
     if (isset($config['allowAnonymous'])) {
         $form .= "<input type=\"hidden\" name=\"allowAnonymous\" value=\"{$config['allowAnonymous']}\">";
     }
     $form .= "</form>";
     return $form;
 }
 /**
  * Download
  *
  * @return null
  */
 public function actionDownload()
 {
     Craft::log(__METHOD__, LogLevel::Info, true);
     $pluginHandle = craft()->request->getParam('plugin');
     // download plugin (includes download, unzip)
     $download = $this->pluginService->download($pluginHandle);
     if ($download['success'] == true) {
         $this->redirect(UrlHelper::getActionUrl($this->pluginHandle . '/plugin/install', array('plugin' => $pluginHandle, 'redirect' => craft()->request->getUrlReferrer())));
     } else {
         // download failure
         $msg = 'Couldn’t install plugin.';
         if (isset($download['msg'])) {
             $msg = $download['msg'];
         }
         Craft::log(__METHOD__ . ' : ' . $msg, LogLevel::Info, true);
         craft()->userSession->setError(Craft::t($msg));
     }
     // redirect
     $this->redirect(craft()->request->getUrlReferrer());
 }
Exemplo n.º 10
0
 /**
  * Displays the category edit page.
  *
  * @param array $variables The route variables.
  *
  * @throws HttpException
  * @return null
  */
 public function actionEditCategory(array $variables = array())
 {
     $this->_prepEditCategoryVariables($variables);
     $this->_enforceEditCategoryPermissions($variables['category']);
     // Parent Category selector variables
     // ---------------------------------------------------------------------
     if ($variables['group']->maxLevels != 1) {
         $variables['elementType'] = new ElementTypeVariable(craft()->elements->getElementType(ElementType::Category));
         // Define the parent options criteria
         $variables['parentOptionCriteria'] = array('locale' => $variables['localeId'], 'groupId' => $variables['group']->id, 'status' => null, 'localeEnabled' => null);
         if ($variables['group']->maxLevels) {
             $variables['parentOptionCriteria']['level'] = '< ' . $variables['group']->maxLevels;
         }
         if ($variables['category']->id) {
             // Prevent the current category, or any of its descendants, from being options
             $idParam = array('and', 'not ' . $variables['category']->id);
             $descendantCriteria = craft()->elements->getCriteria(ElementType::Category);
             $descendantCriteria->descendantOf = $variables['category'];
             $descendantCriteria->status = null;
             $descendantCriteria->localeEnabled = null;
             $descendantIds = $descendantCriteria->ids();
             foreach ($descendantIds as $id) {
                 $idParam[] = 'not ' . $id;
             }
             $variables['parentOptionCriteria']['id'] = $idParam;
         }
         // Get the initially selected parent
         $parentId = craft()->request->getParam('parentId');
         if ($parentId === null && $variables['category']->id) {
             $parentIds = $variables['category']->getAncestors(1)->status(null)->localeEnabled(null)->ids();
             if ($parentIds) {
                 $parentId = $parentIds[0];
             }
         }
         if ($parentId) {
             $variables['parent'] = craft()->categories->getCategoryById($parentId, $variables['localeId']);
         }
     }
     // Other variables
     // ---------------------------------------------------------------------
     // Page title
     if (!$variables['category']->id) {
         $variables['title'] = Craft::t('Create a new category');
     } else {
         $variables['docTitle'] = $variables['title'] = $variables['category']->title;
     }
     // Breadcrumbs
     $variables['crumbs'] = array(array('label' => Craft::t('Categories'), 'url' => UrlHelper::getUrl('categories')), array('label' => Craft::t($variables['group']->name), 'url' => UrlHelper::getUrl('categories/' . $variables['group']->handle)));
     foreach ($variables['category']->getAncestors() as $ancestor) {
         $variables['crumbs'][] = array('label' => $ancestor->title, 'url' => $ancestor->getCpEditUrl());
     }
     // Enable Live Preview?
     if (!craft()->request->isMobileBrowser(true) && craft()->categories->isGroupTemplateValid($variables['group'])) {
         craft()->templates->includeJs('Craft.LivePreview.init(' . JsonHelper::encode(array('fields' => '#title-field, #fields > div > div > .field', 'extraFields' => '#settings', 'previewUrl' => $variables['category']->getUrl(), 'previewAction' => 'categories/previewCategory', 'previewParams' => array('groupId' => $variables['group']->id, 'categoryId' => $variables['category']->id, 'locale' => $variables['category']->locale))) . ');');
         $variables['showPreviewBtn'] = true;
         // Should we show the Share button too?
         if ($variables['category']->id) {
             // If the category is enabled, use its main URL as its share URL.
             if ($variables['category']->getStatus() == BaseElementModel::ENABLED) {
                 $variables['shareUrl'] = $variables['category']->getUrl();
             } else {
                 $variables['shareUrl'] = UrlHelper::getActionUrl('categories/shareCategory', array('categoryId' => $variables['category']->id, 'locale' => $variables['category']->locale));
             }
         }
     } else {
         $variables['showPreviewBtn'] = false;
     }
     // Set the base CP edit URL
     $variables['baseCpEditUrl'] = 'categories/' . $variables['group']->handle . '/{id}-{slug}';
     // Set the "Continue Editing" URL
     $variables['continueEditingUrl'] = $variables['baseCpEditUrl'] . (craft()->isLocalized() && craft()->getLanguage() != $variables['localeId'] ? '/' . $variables['localeId'] : '');
     // Render the template!
     craft()->templates->includeCssResource('css/category.css');
     $this->renderTemplate('categories/_edit', $variables);
 }
Exemplo n.º 11
0
 /**
  * Sets a new verification code on a user, and returns their new Password Reset URL.
  *
  * @param UserModel $user The user that should get the new Password Reset URL
  *
  * @return string The new Password Reset URL.
  */
 public function getPasswordResetUrl(UserModel $user)
 {
     $userRecord = $this->_getUserRecordById($user->id);
     $unhashedVerificationCode = $this->_setVerificationCodeOnUserRecord($userRecord);
     $userRecord->save();
     if ($user->can('accessCp')) {
         $url = UrlHelper::getActionUrl('users/setpassword', array('code' => $unhashedVerificationCode, 'id' => $userRecord->uid), craft()->request->isSecureConnection() ? 'https' : 'http');
     } else {
         // We want to hide the CP trigger if they don't have access to the CP.
         $path = craft()->config->get('actionTrigger') . '/users/setpassword';
         $url = UrlHelper::getSiteUrl($path, array('code' => $unhashedVerificationCode, 'id' => $userRecord->uid), craft()->request->isSecureConnection() ? 'https' : 'http');
     }
     return $url;
 }
Exemplo n.º 12
0
    /**
     * Figure out how to initiate a new task runner.
     */
    public function handleRequestEnd()
    {
        // Make sure a future call to craft()->end() dosen't trigger this a second time
        craft()->detachEventHandler('onEndRequest', array($this, '_onEndRequest'));
        // Make sure nothing has been output to the browser yet, and there's no pending response body
        if (!headers_sent() && !ob_get_length()) {
            $this->closeAndRun();
        } else {
            if (craft()->request->isSiteRequest() && in_array(HeaderHelper::getMimeType(), array('text/html', 'application/xhtml+xml')) && !craft()->request->isAjaxRequest()) {
                // Just output JS that tells the browser to fire an Ajax request to kick off task running
                $url = JsonHelper::encode(UrlHelper::getActionUrl('tasks/runPendingTasks'));
                // Ajax request code adapted from http://www.quirksmode.org/js/xmlhttp.html - thanks ppk!
                echo <<<EOT
<script type="text/javascript">
/*<![CDATA[*/
(function(){
\tvar XMLHttpFactories = [
\t\tfunction () {return new XMLHttpRequest()},
\t\tfunction () {return new ActiveXObject("Msxml2.XMLHTTP")},
\t\tfunction () {return new ActiveXObject("Msxml3.XMLHTTP")},
\t\tfunction () {return new ActiveXObject("Microsoft.XMLHTTP")}
\t];
\tvar req = false;
\tfor (var i = 0; i < XMLHttpFactories.length; i++) {
\t\ttry {
\t\t\treq = XMLHttpFactories[i]();
\t\t}
\t\tcatch (e) {
\t\t\tcontinue;
\t\t}
\t\tbreak;
\t}
\tif (!req) return;
\treq.open('GET', {$url}, true);
\tif (req.readyState == 4) return;
\treq.send();
})();
/*]]>*/
</script>
EOT;
            }
        }
    }
 /**
  * Route Controller for Edit Entry Template
  *
  * @param array $variables
  *
  * @throws HttpException
  * @throws Exception
  */
 public function actionEditEntryTemplate(array $variables = array())
 {
     $entryId = craft()->request->getSegment(4);
     $campaignId = craft()->request->getSegment(3);
     // Check if we already have an entry route variable
     // If so it's probably due to a bad form submission and has an error object
     // that we don't want to overwrite.
     if (!isset($variables['entry'])) {
         if (is_numeric($entryId)) {
             $variables['entry'] = craft()->elements->getElementById($entryId);
             $variables['entryId'] = $entryId;
         } else {
             $variables['entry'] = new SproutEmail_EntryModel();
         }
     }
     if (!is_numeric($campaignId)) {
         $campaignId = $variables['entry']->campaignId;
     }
     $variables['campaign'] = sproutEmail()->campaigns->getCampaignById($campaignId);
     $variables['campaignId'] = $campaignId;
     // Tabs
     $variables['tabs'] = array();
     foreach ($variables['campaign']->getFieldLayout()->getTabs() as $index => $tab) {
         // Do any of the fields on this tab have errors?
         $hasErrors = false;
         if ($variables['entry']->hasErrors()) {
             foreach ($tab->getFields() as $field) {
                 if ($variables['entry']->getErrors($field->getField()->handle)) {
                     $hasErrors = true;
                     break;
                 }
             }
         }
         $variables['tabs'][] = array('url' => '#tab' . ($index + 1), 'label' => Craft::t($tab->name), 'class' => $hasErrors ? 'error' : null);
     }
     $shareParamsHtml = array('entryId' => $variables['entry']->id, 'template' => 'html');
     $shareParamsText = array('entryId' => $variables['entry']->id, 'template' => 'txt');
     // Enable Live Preview?
     if (!craft()->request->isMobileBrowser(true) && sproutEmail()->doesSiteTemplateExist($variables['campaign']->template)) {
         craft()->templates->includeJs('Craft.LivePreview.init(' . JsonHelper::encode(array('fields' => '#subjectLine-field, #title-field, #fields > div > div > .field', 'extraFields' => '#settings', 'previewUrl' => $variables['entry']->getUrl(), 'previewAction' => 'sproutEmail/entry/livePreviewEntry', 'previewParams' => array('entryId' => $variables['entry']->id, 'campaignId' => $variables['campaign']->id))) . ');');
         $variables['showPreviewBtn'] = true;
         // Should we show the Share button too?
         if ($variables['entry']->id) {
             if ($variables['entry']->enabled) {
                 $variables['shareUrl'] = $variables['entry']->getUrl();
             } else {
                 $shareParams = array('entryId' => $variables['entry']->id, 'campaignId' => $variables['campaign']->id);
                 $variables['shareUrl'] = UrlHelper::getActionUrl('sproutEmail/entry/shareEntry', $shareParams);
             }
         }
     } else {
         $variables['showPreviewBtn'] = false;
     }
     if ($variables['campaign']->type == 'notification') {
         $notificationId = null;
         $notification = sproutEmail()->notifications->getNotification(array('campaignId' => $campaignId));
         if ($notification) {
             $notificationId = $notification->eventId;
         }
         $variables['notificationEvent'] = $notificationId;
     }
     $variables['shareUrlHtml'] = UrlHelper::getActionUrl('sproutEmail/entry/shareEntry', $shareParamsHtml);
     $variables['shareUrlText'] = UrlHelper::getActionUrl('sproutEmail/entry/shareEntry', $shareParamsText);
     // end <
     $variables['recipientLists'] = sproutEmail()->entries->getRecipientListsByEntryId($entryId);
     $this->renderTemplate('sproutemail/entries/_edit', $variables);
 }
Exemplo n.º 14
0
 /**
  * craft.sass.link() returns a URL that will return the compiled, CSS
  * version of a specified Sass file. The path should be relative to the
  * document root.
  *
  * @param string $filename  File to compile.
  * @return string           Relative URL to the compiled CSS version.
  */
 public function link($filename)
 {
     return UrlHelper::getActionUrl('sass/compiler/sass', array('filename' => $filename));
 }
Exemplo n.º 15
0
 /**
  * Called when a user beings up an entry for editing before being displayed.
  *
  * @param array $variables
  *
  * @throws HttpException
  * @return null
  */
 public function actionEditEntry(array $variables = array())
 {
     $this->_prepEditEntryVariables($variables);
     // Make sure they have permission to edit this entry
     $this->enforceEditEntryPermissions($variables['entry']);
     $currentUser = craft()->userSession->getUser();
     $variables['permissionSuffix'] = ':' . $variables['entry']->sectionId;
     if (craft()->getEdition() >= Craft::Client && $variables['section']->type != SectionType::Single) {
         // Get all the possible authors
         if ($variables['entry']->authorId) {
             if ($variables['entry']->authorId == $currentUser->id) {
                 $excludeAuthorIds = 'not ' . $currentUser->id;
                 $excludeAuthorIds = array('and', $excludeAuthorIds, 'not ' . $variables['entry']->authorId);
             } else {
                 $excludeAuthorIds = array('not ' . $variables['entry']->authorId);
             }
         }
         $authorOptionCriteria = craft()->elements->getCriteria(ElementType::User);
         $authorOptionCriteria->can = 'editEntries' . $variables['permissionSuffix'];
         $authorOptionCriteria->limit = null;
         if ($variables['entry']->authorId) {
             $authorOptionCriteria->id = $excludeAuthorIds;
         }
         $authorOptions = $authorOptionCriteria->find();
         // List the current author first
         if ($variables['entry']->authorId && $variables['entry']->authorId != $currentUser->id) {
             $currentAuthor = craft()->users->getUserById($variables['entry']->authorId);
             if ($currentAuthor) {
                 array_unshift($authorOptions, $currentAuthor);
             }
         }
         // Then the current user
         if (!$variables['entry']->authorId || $variables['entry']->authorId == $currentUser->id) {
             array_unshift($authorOptions, $currentUser);
         }
         $variables['authorOptions'] = array();
         foreach ($authorOptions as $authorOption) {
             $authorLabel = $authorOption->username;
             $authorFullName = $authorOption->getFullName();
             if ($authorFullName) {
                 $authorLabel .= ' - ' . $authorFullName;
             }
             $variables['authorOptions'][] = array('label' => $authorLabel, 'value' => $authorOption->id);
         }
     }
     if (craft()->getEdition() >= Craft::Client && $variables['section']->type == SectionType::Structure) {
         // Get all the possible parent options
         $parentOptionCriteria = craft()->elements->getCriteria(ElementType::Entry);
         $parentOptionCriteria->sectionId = $variables['section']->id;
         $parentOptionCriteria->status = null;
         $parentOptionCriteria->localeEnabled = null;
         $parentOptionCriteria->limit = null;
         if ($variables['section']->maxLevels) {
             $parentOptionCriteria->level = '< ' . $variables['section']->maxLevels;
         }
         if ($variables['entry']->id) {
             $idParam = array('and', 'not ' . $variables['entry']->id);
             $descendantCriteria = craft()->elements->getCriteria(ElementType::Entry);
             $descendantCriteria->descendantOf = $variables['entry'];
             $descendantCriteria->status = null;
             $descendantCriteria->localeEnabled = null;
             $descendantIds = $descendantCriteria->ids();
             foreach ($descendantIds as $id) {
                 $idParam[] = 'not ' . $id;
             }
             $parentOptionCriteria->id = $idParam;
         }
         $parentOptions = $parentOptionCriteria->find();
         $variables['parentOptions'] = array(array('label' => '', 'value' => '0'));
         foreach ($parentOptions as $parentOption) {
             $label = '';
             for ($i = 1; $i < $parentOption->level; $i++) {
                 $label .= '    ';
             }
             $label .= $parentOption->title;
             $variables['parentOptions'][] = array('label' => $label, 'value' => $parentOption->id);
         }
         // Get the initially selected parent
         $variables['parentId'] = craft()->request->getParam('parentId');
         if ($variables['parentId'] === null && $variables['entry']->id) {
             $parentIdCriteria = craft()->elements->getCriteria(ElementType::Entry);
             $parentIdCriteria->ancestorOf = $variables['entry'];
             $parentIdCriteria->ancestorDist = 1;
             $parentIdCriteria->status = null;
             $parentIdCriteria->localeEnabled = null;
             $parentIds = $parentIdCriteria->ids();
             if ($parentIds) {
                 $variables['parentId'] = $parentIds[0];
             }
         }
     }
     // Get the enabled locales
     if (craft()->isLocalized()) {
         if ($variables['entry']->id) {
             $variables['enabledLocales'] = craft()->elements->getEnabledLocalesForElement($variables['entry']->id);
         } else {
             $variables['enabledLocales'] = array();
             foreach ($variables['section']->getLocales() as $locale) {
                 if ($locale->enabledByDefault) {
                     $variables['enabledLocales'][] = $locale->locale;
                 }
             }
         }
     }
     // Page title w/ revision label
     if (craft()->getEdition() >= Craft::Client) {
         switch ($variables['entry']->getClassHandle()) {
             case 'EntryDraft':
                 $variables['revisionLabel'] = $variables['entry']->name;
                 break;
             case 'EntryVersion':
                 $variables['revisionLabel'] = Craft::t('Version {num}', array('num' => $variables['entry']->num));
                 break;
             default:
                 $variables['revisionLabel'] = Craft::t('Current');
         }
     }
     if (!$variables['entry']->id) {
         $variables['title'] = Craft::t('Create a new entry');
     } else {
         $variables['docTitle'] = Craft::t($variables['entry']->title);
         $variables['title'] = HtmlHelper::encode(Craft::t($variables['entry']->title));
         if (craft()->getEdition() >= Craft::Client && $variables['entry']->getClassHandle() != 'Entry') {
             $variables['title'] .= ' <span class="hidden">(' . $variables['revisionLabel'] . ')</span>';
         }
     }
     // Breadcrumbs
     $variables['crumbs'] = array(array('label' => Craft::t('Entries'), 'url' => UrlHelper::getUrl('entries')));
     if ($variables['section']->type == SectionType::Single) {
         $variables['crumbs'][] = array('label' => Craft::t('Singles'), 'url' => UrlHelper::getUrl('entries/singles'));
     } else {
         $variables['crumbs'][] = array('label' => Craft::t($variables['section']->name), 'url' => UrlHelper::getUrl('entries/' . $variables['section']->handle));
         if ($variables['section']->type == SectionType::Structure) {
             foreach ($variables['entry']->getAncestors() as $ancestor) {
                 $variables['crumbs'][] = array('label' => $ancestor->title, 'url' => $ancestor->getCpEditUrl());
             }
         }
     }
     // Multiple entry types?
     $entryTypes = $variables['section']->getEntryTypes();
     if (count($entryTypes) > 1) {
         $variables['showEntryTypes'] = true;
         foreach ($entryTypes as $entryType) {
             $variables['entryTypeOptions'][] = array('label' => Craft::t($entryType->name), 'value' => $entryType->id);
         }
         craft()->templates->includeJsResource('js/EntryTypeSwitcher.js');
         craft()->templates->includeJs('new Craft.EntryTypeSwitcher();');
     } else {
         $variables['showEntryTypes'] = false;
     }
     // Enable preview mode?
     if (!craft()->request->isMobileBrowser(true) && craft()->sections->isSectionTemplateValid($variables['section'])) {
         craft()->templates->includeJsResource('js/LivePreview.js');
         craft()->templates->includeJs('Craft.livePreview = new Craft.LivePreview(' . JsonHelper::encode($variables['entry']->getUrl()) . ', "' . $variables['entry']->locale . '");');
         $variables['showPreviewBtn'] = true;
         // Should we show the Share button too?
         if ($variables['entry']->id) {
             $classHandle = $variables['entry']->getClassHandle();
             // If we're looking at the live version of an entry, just use
             // the entry's main URL as its share URL
             if ($classHandle == 'Entry' && $variables['entry']->getStatus() == EntryModel::LIVE) {
                 $variables['shareUrl'] = $variables['entry']->getUrl();
             } else {
                 switch ($classHandle) {
                     case 'EntryDraft':
                         $shareParams = array('draftId' => $variables['entry']->draftId);
                         break;
                     case 'EntryVersion':
                         $shareParams = array('versionId' => $variables['entry']->versionId);
                         break;
                     default:
                         $shareParams = array('entryId' => $variables['entry']->id, 'locale' => $variables['entry']->locale);
                         break;
                 }
                 $variables['shareUrl'] = UrlHelper::getActionUrl('entries/shareEntry', $shareParams);
             }
         }
     } else {
         $variables['showPreviewBtn'] = false;
     }
     // Set the base CP edit URL
     // Can't just use the entry's getCpEditUrl() because that might include the locale ID when we don't want it
     $variables['baseCpEditUrl'] = 'entries/' . $variables['section']->handle . '/{id}-{slug}';
     // Set the "Continue Editing" URL
     $variables['continueEditingUrl'] = $variables['baseCpEditUrl'] . (isset($variables['draftId']) ? '/drafts/' . $variables['draftId'] : '') . (craft()->isLocalized() && craft()->getLanguage() != $variables['localeId'] ? '/' . $variables['localeId'] : '');
     // Can the user delete the entry?
     $variables['canDeleteEntry'] = $variables['entry']->id && ($variables['entry']->authorId == $currentUser->id && $currentUser->can('deleteEntries' . $variables['permissionSuffix']) || $variables['entry']->authorId != $currentUser->id && $currentUser->can('deletePeerEntries' . $variables['permissionSuffix']));
     // Include translations
     craft()->templates->includeTranslations('Live Preview');
     // Render the template!
     craft()->templates->includeCssResource('css/entry.css');
     $this->renderTemplate('entries/_edit', $variables);
 }
Exemplo n.º 16
0
 public function getLogoutUrl($redirect = null)
 {
     $params = array('redirect' => $redirect);
     return UrlHelper::getActionUrl('social/logout', $params);
 }
Exemplo n.º 17
0
 /**
  * Get unlink account URL
  *
  * @param $handle
  *
  * @return string
  */
 public function getLoginAccountDisconnectUrl($handle)
 {
     return UrlHelper::getActionUrl('social/disconnectLoginAccount', ['provider' => $handle]);
 }
Exemplo n.º 18
0
 /**
  * Sets a new verification code on a user, and returns their new Email Verification URL.
  *
  * @param UserModel $user The user that should get the new Email Verification URL.
  *
  * @return string The new Email Verification URL.
  */
 public function getEmailVerifyUrl(UserModel $user)
 {
     $userRecord = $this->_getUserRecordById($user->id);
     $unhashedVerificationCode = $this->_setVerificationCodeOnUserRecord($userRecord);
     $userRecord->save();
     if ($user->can('accessCp')) {
         $url = UrlHelper::getActionUrl('users/verifyemail', array('code' => $unhashedVerificationCode, 'id' => $userRecord->uid), craft()->request->isSecureConnection() ? 'https' : 'http');
     } else {
         // We want to hide the CP trigger if they don't have access to the CP.
         $path = craft()->config->get('actionTrigger') . '/users/verifyemail';
         $params = array('code' => $unhashedVerificationCode, 'id' => $userRecord->uid);
         $locale = $user->preferredLocale ?: craft()->i18n->getPrimarySiteLocaleId();
         $url = UrlHelper::getSiteUrl($path, $params, UrlHelper::getProtocolForTokenizedUrl(), $locale);
     }
     return $url;
 }
Exemplo n.º 19
0
 /**
  * Sends a “Forgot Password” email to a given user.
  *
  * @param UserModel $user The user.
  *
  * @return bool Whether the email was sent successfully.
  */
 public function sendForgotPasswordEmail(UserModel $user)
 {
     $userRecord = $this->_getUserRecordById($user->id);
     $unhashedVerificationCode = $this->_setVerificationCodeOnUserRecord($userRecord);
     $userRecord->save();
     $url = UrlHelper::getActionUrl('users/setpassword', array('code' => $unhashedVerificationCode, 'id' => $userRecord->uid), craft()->request->isSecureConnection() ? 'https' : 'http');
     return craft()->email->sendEmailByKey($user, 'forgot_password', array('link' => TemplateHelper::getRaw($url)));
 }
Exemplo n.º 20
0
 /**
  * Get URL for a file.
  *
  * @param AssetFileModel $file
  * @param $transform
  * @return string
  */
 public function getUrlForFile(AssetFileModel $file, $transform = null)
 {
     $returnPlaceholder = false;
     if (!$transform || !in_array(IOHelper::getExtension($file->filename), ImageHelper::getAcceptedExtensions())) {
         $sourceType = craft()->assetSources->getSourceTypeById($file->sourceId);
         $base = $sourceType->getBaseUrl();
         return $base . $file->getFolder()->fullPath . $file->filename;
     }
     // Get the transform index model
     $existingTransformData = craft()->assetTransforms->getTransformIndex($file, $transform);
     // Does the file actually exist?
     if ($existingTransformData->fileExists) {
         return craft()->assetTransforms->getUrlforTransformByFile($file, $transform);
     } else {
         // File doesn't exist yet - load the TransformLoader and set the placeholder URL flag
         $placeholderUrl = UrlHelper::getResourceUrl('images/blank.gif');
         if (!$this->_includedTransformLoader) {
             $entityPlaceholderUrl = htmlspecialchars($placeholderUrl, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
             $spinnerUrl = UrlHelper::getResourceurl('images/spinner_transform.gif');
             $actionUrl = UrlHelper::getActionUrl('assets/generateTransform');
             craft()->templates->includeJsResource('js/TransformLoader.js');
             craft()->templates->includeJs('new TransformLoader(' . JsonHelper::encode($placeholderUrl) . ', ' . JsonHelper::encode($entityPlaceholderUrl) . ', ' . JsonHelper::encode($spinnerUrl) . ', ' . JsonHelper::encode($actionUrl) . ');');
             $this->_includedTransformLoader = true;
         }
         return $placeholderUrl . '#' . $existingTransformData->id;
     }
 }
Exemplo n.º 21
0
 /**
  * Called when a user beings up an entry for editing before being displayed.
  *
  * @param array $variables
  *
  * @throws HttpException
  * @return null
  */
 public function actionEditEntry(array $variables = array())
 {
     $this->_prepEditEntryVariables($variables);
     // Make sure they have permission to edit this entry
     $this->enforceEditEntryPermissions($variables['entry']);
     $currentUser = craft()->userSession->getUser();
     $variables['permissionSuffix'] = ':' . $variables['entry']->sectionId;
     if (craft()->getEdition() == Craft::Pro && $variables['section']->type != SectionType::Single) {
         // Author selector variables
         // ---------------------------------------------------------------------
         $variables['userElementType'] = new ElementTypeVariable(craft()->elements->getElementType(ElementType::User));
         $authorPermission = 'editEntries' . $variables['permissionSuffix'];
         $variables['authorOptionCriteria'] = array('can' => $authorPermission);
         $variables['author'] = $variables['entry']->getAuthor();
         if (!$variables['author']) {
             // Default to the current user
             $variables['author'] = $currentUser;
         }
     }
     // Parent Entry selector variables
     // ---------------------------------------------------------------------
     if (craft()->getEdition() >= Craft::Client && $variables['section']->type == SectionType::Structure && $variables['section']->maxLevels != 1) {
         $variables['elementType'] = new ElementTypeVariable(craft()->elements->getElementType(ElementType::Entry));
         $variables['parentOptionCriteria'] = array('locale' => $variables['localeId'], 'sectionId' => $variables['section']->id, 'status' => null, 'localeEnabled' => null);
         if ($variables['section']->maxLevels) {
             $variables['parentOptionCriteria']['level'] = '< ' . $variables['section']->maxLevels;
         }
         if ($variables['entry']->id) {
             // Prevent the current entry, or any of its descendants, from being options
             $idParam = array('and', 'not ' . $variables['entry']->id);
             $descendantCriteria = craft()->elements->getCriteria(ElementType::Entry);
             $descendantCriteria->descendantOf = $variables['entry'];
             $descendantCriteria->status = null;
             $descendantCriteria->localeEnabled = null;
             $descendantIds = $descendantCriteria->ids();
             foreach ($descendantIds as $id) {
                 $idParam[] = 'not ' . $id;
             }
             $variables['parentOptionCriteria']['id'] = $idParam;
         }
         // Get the initially selected parent
         $parentId = craft()->request->getParam('parentId');
         if ($parentId === null && $variables['entry']->id) {
             $parentIds = $variables['entry']->getAncestors(1)->status(null)->localeEnabled(null)->ids();
             if ($parentIds) {
                 $parentId = $parentIds[0];
             }
         }
         if ($parentId) {
             $variables['parent'] = craft()->entries->getEntryById($parentId, $variables['localeId']);
         }
     }
     // Enabled locales
     // ---------------------------------------------------------------------
     if (craft()->isLocalized()) {
         if ($variables['entry']->id) {
             $variables['enabledLocales'] = craft()->elements->getEnabledLocalesForElement($variables['entry']->id);
         } else {
             $variables['enabledLocales'] = array();
             foreach ($variables['section']->getLocales() as $locale) {
                 if ($locale->enabledByDefault) {
                     $variables['enabledLocales'][] = $locale->locale;
                 }
             }
         }
     }
     // Other variables
     // ---------------------------------------------------------------------
     // Page title w/ revision label
     if (craft()->getEdition() >= Craft::Client) {
         switch ($variables['entry']->getClassHandle()) {
             case 'EntryDraft':
                 $variables['revisionLabel'] = $variables['entry']->name;
                 break;
             case 'EntryVersion':
                 $variables['revisionLabel'] = Craft::t('Version {num}', array('num' => $variables['entry']->num));
                 break;
             default:
                 $variables['revisionLabel'] = Craft::t('Current');
         }
     }
     if (!$variables['entry']->id) {
         $variables['title'] = Craft::t('Create a new entry');
     } else {
         $variables['docTitle'] = Craft::t($variables['entry']->title);
         $variables['title'] = Craft::t($variables['entry']->title);
         if (craft()->getEdition() >= Craft::Client && $variables['entry']->getClassHandle() != 'Entry') {
             $variables['docTitle'] .= ' (' . $variables['revisionLabel'] . ')';
         }
     }
     // Breadcrumbs
     $variables['crumbs'] = array(array('label' => Craft::t('Entries'), 'url' => UrlHelper::getUrl('entries')));
     if ($variables['section']->type == SectionType::Single) {
         $variables['crumbs'][] = array('label' => Craft::t('Singles'), 'url' => UrlHelper::getUrl('entries/singles'));
     } else {
         $variables['crumbs'][] = array('label' => Craft::t($variables['section']->name), 'url' => UrlHelper::getUrl('entries/' . $variables['section']->handle));
         if ($variables['section']->type == SectionType::Structure) {
             foreach ($variables['entry']->getAncestors() as $ancestor) {
                 $variables['crumbs'][] = array('label' => $ancestor->title, 'url' => $ancestor->getCpEditUrl());
             }
         }
     }
     // Multiple entry types?
     $entryTypes = $variables['section']->getEntryTypes();
     if (count($entryTypes) > 1) {
         $variables['showEntryTypes'] = true;
         foreach ($entryTypes as $entryType) {
             $variables['entryTypeOptions'][] = array('label' => Craft::t($entryType->name), 'value' => $entryType->id);
         }
         craft()->templates->includeJsResource('js/EntryTypeSwitcher.js');
         craft()->templates->includeJs('new Craft.EntryTypeSwitcher();');
     } else {
         $variables['showEntryTypes'] = false;
     }
     // Enable Live Preview?
     if (!craft()->request->isMobileBrowser(true) && craft()->sections->isSectionTemplateValid($variables['section'])) {
         craft()->templates->includeJs('Craft.LivePreview.init(' . JsonHelper::encode(array('fields' => '#title-field, #fields > div > div > .field', 'extraFields' => '#settings', 'previewUrl' => $variables['entry']->getUrl(), 'previewAction' => 'entries/previewEntry', 'previewParams' => array('sectionId' => $variables['section']->id, 'entryId' => $variables['entry']->id, 'locale' => $variables['entry']->locale, 'versionId' => $variables['entry']->getClassHandle() == 'EntryVersion' ? $variables['entry']->versionId : null))) . ');');
         $variables['showPreviewBtn'] = true;
         // Should we show the Share button too?
         if ($variables['entry']->id) {
             $classHandle = $variables['entry']->getClassHandle();
             // If we're looking at the live version of an entry, just use
             // the entry's main URL as its share URL
             if ($classHandle == 'Entry' && $variables['entry']->getStatus() == EntryModel::LIVE) {
                 $variables['shareUrl'] = $variables['entry']->getUrl();
             } else {
                 switch ($classHandle) {
                     case 'EntryDraft':
                         $shareParams = array('draftId' => $variables['entry']->draftId);
                         break;
                     case 'EntryVersion':
                         $shareParams = array('versionId' => $variables['entry']->versionId);
                         break;
                     default:
                         $shareParams = array('entryId' => $variables['entry']->id, 'locale' => $variables['entry']->locale);
                         break;
                 }
                 $variables['shareUrl'] = UrlHelper::getActionUrl('entries/shareEntry', $shareParams);
             }
         }
     } else {
         $variables['showPreviewBtn'] = false;
     }
     // Set the base CP edit URL
     // Can't just use the entry's getCpEditUrl() because that might include the locale ID when we don't want it
     $variables['baseCpEditUrl'] = 'entries/' . $variables['section']->handle . '/{id}-{slug}';
     // Set the "Continue Editing" URL
     $variables['continueEditingUrl'] = $variables['baseCpEditUrl'] . (isset($variables['draftId']) ? '/drafts/' . $variables['draftId'] : '') . (craft()->isLocalized() && craft()->getLanguage() != $variables['localeId'] ? '/' . $variables['localeId'] : '');
     // Can the user delete the entry?
     $variables['canDeleteEntry'] = $variables['entry']->id && ($variables['entry']->authorId == $currentUser->id && $currentUser->can('deleteEntries' . $variables['permissionSuffix']) || $variables['entry']->authorId != $currentUser->id && $currentUser->can('deletePeerEntries' . $variables['permissionSuffix']));
     // Include translations
     craft()->templates->includeTranslations('Live Preview');
     // Render the template!
     craft()->templates->includeCssResource('css/entry.css');
     $this->renderTemplate('entries/_edit', $variables);
 }