/**
  * Saves a Redirect.
  */
 public function actionSaveRedirect()
 {
     $this->requirePostRequest();
     $redirectId = craft()->request->getPost('redirectId');
     if ($redirectId) {
         $redirect = sproutSeo()->redirects->getRedirectById($redirectId);
         if (!$redirect) {
             throw new Exception(Craft::t('No redirect exists with the ID “{id}”', array('id' => $redirectId)));
         }
     } else {
         $redirect = new SproutSeo_RedirectModel();
     }
     // Set the event attributes, defaulting to the existing values for whatever is missing from the post data
     $redirect->oldUrl = craft()->request->getPost('oldUrl', $redirect->oldUrl);
     $redirect->newUrl = craft()->request->getPost('newUrl');
     $redirect->method = craft()->request->getPost('method');
     $redirect->regex = craft()->request->getPost('regex');
     if (sproutSeo()->redirects->saveRedirect($redirect)) {
         craft()->userSession->setNotice(Craft::t('Redirect saved.'));
         $this->redirectToPostedUrl($redirect);
     } else {
         craft()->userSession->setError(Craft::t('Couldn’t save redirect.'));
         // Send the event back to the template
         craft()->urlManager->setRouteVariables(array('redirect' => $redirect));
     }
 }
 /**
  * Deletes a Custom Page Record
  *
  * @return json success object
  */
 public function actionDeleteCustomPage()
 {
     $this->requirePostRequest();
     $this->requireAjaxRequest();
     $id = craft()->request->getRequiredPost('id');
     $result = sproutSeo()->sitemap->deleteCustomPageById($id);
     $this->returnJson(array('success' => $result));
 }
 /**
  * Update "oldUrl" and "newUrl" to starts with a "/"
  *
  */
 protected function beforeValidate()
 {
     if (!$this->regex) {
         $this->oldUrl = sproutSeo()->redirects->addSlash($this->oldUrl);
     }
     $this->newUrl = sproutSeo()->redirects->addSlash($this->newUrl);
     return true;
 }
 /**
  * @inheritDoc IElementAction::performAction()
  *
  * @param ElementCriteriaModel $criteria
  *
  * @return bool
  */
 public function performAction(ElementCriteriaModel $criteria)
 {
     $elementIds = $criteria->ids();
     $response = false;
     // Call updateMethods service
     $response = sproutSeo()->redirects->updateMethods($elementIds, SproutSeo_RedirectMethods::Temporary);
     $message = sproutSeo()->redirects->getMethodUpdateResponse($response);
     $this->setMessage($message);
     return $response;
 }
 public function init()
 {
     Craft::import('plugins.sproutseo.helpers.SproutSeoMetaHelper');
     if (craft()->request->isSiteRequest() && !craft()->request->isLivePreview()) {
         $url = craft()->request->getUrl();
         // check if the request url needs redirect
         $redirect = sproutSeo()->redirects->getRedirect($url);
         if ($redirect) {
             craft()->request->redirect($redirect->newUrl, true, $redirect->method);
         }
     }
 }
 public function actionSaveSettings()
 {
     $this->requirePostRequest();
     $settings = craft()->request->getPost('settings');
     if (sproutSeo()->settings->saveSettings($settings)) {
         craft()->userSession->setNotice(Craft::t('Settings saved.'));
         $this->redirectToPostedUrl();
     } else {
         craft()->userSession->setError(Craft::t('Couldn’t save settings.'));
         // Send the settings back to the template
         craft()->urlManager->setRouteVariables(array('settings' => $settings));
     }
 }
 public function actionDeleteDefaults()
 {
     $this->requirePostRequest();
     $this->requireAjaxRequest();
     $this->returnJson(array('success' => sproutSeo()->defaults->deleteDefault(craft()->request->getRequiredPost('id')) >= 0 ? true : false));
 }
 /**
  * Display our FieldType
  *
  * @param string $name  Our FieldType handle
  * @param string $value Always returns blank, our block
  *                       only styles the Instructions field
  * @return string Return our blocks input template
  */
 public function getInputHtml($name, $value)
 {
     $entryId = craft()->request->getSegment(3);
     $locale = $this->element->locale;
     $values = sproutSeo()->overrides->getGeographicMetaFieldByEntryId($entryId, $locale);
     // Cleanup the namespace around the $name handle
     $name = str_replace("fields[", "", $name);
     $name = rtrim($name, "]");
     $name = "sproutseo_fields[{$name}]";
     // $value = $values['title'];
     return craft()->templates->render('sproutseo/_partials/fields/geo', array('name' => $name, 'values' => $values));
 }
 /**
  * This service allows find a url that needs redirect
  *
  * @param string current request url
  * @return SproutSeo_RedirectRecord
  */
 public function getRedirect($url)
 {
     // check first on normal urls
     $redirect = sproutSeo()->redirects->findUrl($url);
     if (!$redirect) {
         // check on regex urls
         $redirect = sproutSeo()->redirects->findRegexUrl($url);
     }
     return $redirect;
 }
 /**
  * Create our default SproutSeo_MetaModel
  *
  * @param $overrideInfo
  * @return SproutSeo_MetaModel
  */
 protected function getDefault($overrideInfo)
 {
     if (isset($overrideInfo['default'])) {
         $defaultMetaModel = sproutSeo()->defaults->getDefaultByHandle($overrideInfo['default']);
         return $defaultMetaModel->getAttributes();
     }
     return array();
 }
 /**
  * Display our FieldType
  *
  * @param string $name  Our FieldType handle
  * @param string $value Always returns blank, our block
  *                       only styles the Instructions field
  * @return string Return our blocks input template
  */
 public function getInputHtml($name, $value)
 {
     $entryId = craft()->request->getSegment(3);
     $locale = $this->element->locale;
     $variables['values'] = sproutSeo()->overrides->getOpenGraphFieldByEntryId($entryId, $locale);
     // Set up our asset fields
     if (isset($variables['values']->ogImage)) {
         $asset = craft()->elements->getElementById($variables['values']->ogImage);
         $variables['ogImageElements'] = array($asset);
     } else {
         $variables['ogImageElements'] = array();
     }
     // Set assetsSourceExists
     $sources = craft()->assets->findFolders();
     $variables['assetsSourceExists'] = count($sources);
     // Set elementType
     $variables['elementType'] = craft()->elements->getElementType(ElementType::Asset);
     // include css resource
     craft()->templates->includeCssResource('sproutseo/css/fields.css');
     // Cleanup the namespace around the $name handle
     $name = str_replace("fields[", "", $name);
     $name = rtrim($name, "]");
     $name = "sproutseo_fields[{$name}]";
     return craft()->templates->render('sproutseo/_partials/fields/open-graph', $variables);
 }
 /**
  * @inheritdoc BaseElementType::saveElement()
  *
  * @return bool
  */
 public function saveElement(BaseElementModel $element, $params)
 {
     // Route this through RedirectsService::saveRedirect() so the proper redirect events get fired.
     $redirect = new SproutSeo_RedirectModel();
     $redirect->id = $element->id;
     $redirect->oldUrl = $params['oldUrl'];
     $redirect->newUrl = $params['newUrl'];
     $redirect->method = $params['method'];
     $redirect->regex = $params['regex'];
     // send response
     return sproutSeo()->redirects->saveRedirect($redirect);
 }
 /**
  * Returns all custom pages for sitemap settings
  *
  * @return array of Sections
  */
 public function getAllCustomPages()
 {
     return sproutSeo()->sitemap->getAllCustomPages();
 }
 /**
  * Display our FieldType
  *
  * @param string $name Our FieldType handle
  * @param string $value Always returns blank, our block
  *                       only styles the Instructions field
  * @return string Return our blocks input template
  */
 public function getInputHtml($name, $value)
 {
     $entryId = craft()->request->getSegment(3);
     $locale = $this->element->locale;
     $values = sproutSeo()->overrides->getRobotsMetaFieldByEntryId($entryId, $locale);
     $values->robots = explode(',', $values->robots);
     // Cleanup the namespace around the $name handle
     $name = str_replace("fields[", "", $name);
     $name = rtrim($name, "]");
     $name = "sproutseo_fields[{$name}]";
     return craft()->templates->render('sproutseo/_partials/fields/robots', array('name' => $name, 'values' => $values, 'fieldContext' => 'robots'));
 }