private function getAuthorizationUserForm()
 {
     $urlHelper = new UrlHelper();
     $this->form = '';
     $this->form .= '<form class="AuthorizationForm" name="AuthorizationForm" action="' . $urlHelper->getThisPage() . '" 
         method="post" accept-charset="UTF-8" autocomplete="on">';
     $this->form .= '<center>';
     $this->form .= "<div class='AuthorizationFormBlock'>";
     $this->form .= '<table class="AuthorizationFormTable" >';
     $this->form .= '<tr>';
     $this->form .= '<td>';
     $this->form .= "<div class='AuthorizationFormLogin'></div>";
     $this->form .= '</td>';
     $this->form .= '<td>';
     $this->form .= $this->inputHelper->paternTextBox("login", "login", "login", 25, true, $this->localization->getText("login"), "[A-Za-z0-9]{3,20}", null);
     $this->form .= '</td>';
     //$this->form .= '<td rowspan="2">';
     //$this->form .= '</td>';
     $this->form .= '</tr>';
     $this->form .= '<tr>';
     $this->form .= '<td>';
     $this->form .= "<div class='AuthorizationFormPassword'></div>";
     $this->form .= '</td>';
     $this->form .= '<td>';
     $this->form .= $this->inputHelper->paternPasswordBox("password", "password", "password", 25, true, $this->localization->getText("password"), "[A-Za-z0-9]{3,20}", null);
     $this->form .= '</td>';
     $this->form .= '</tr>';
     $this->form .= '</tr>';
     $this->form .= '</table>';
     $this->form .= '<input class="AuthorizationFormButton" type="submit" name="AuthorizationFormSubmit" value="in" title="' . $this->localization->getText("authorizationFormText") . '">';
     $this->form .= "</div>";
     $this->form .= '</center>';
     $this->form .= '</form>';
 }
Esempio n. 2
0
 public function testAbsoluteLinkShouldCreateRequestFormGlobalsWhenNoRequestIsGiven()
 {
     $helper = new UrlHelper();
     $_SERVER['HTTPS'] = 'on';
     $_SERVER['HTTP_HOST'] = 'localhost';
     $_SERVER['REQUEST_URI'] = '/webroot/test';
     $_SERVER['REQUEST_METHOD'] = 'GET';
     $_SERVER['SCRIPT_NAME'] = '/webroot';
     $this->assertEquals('https://localhost/webroot/page', $helper->absoluteLink('/page'));
 }
Esempio n. 3
0
 private function generateHTML()
 {
     $this->getSliderData();
     $out = '<div class="border_box">';
     $out .= '<div class="box_skitter box_skitter_large ' . $this->name . '">';
     $out .= '<ul>';
     foreach ($this->data['slides'] as $slide) {
         $html = "<li>";
         //            echo $this->sliderDir.$this->name.'/'.strtolower($this->thisLang).'/'.$slide['fileName']."<br>";
         $img = '<img src="' . $this->sliderDir . $this->name . '/' . strtolower($this->thisLang) . '/' . $slide['fileName'] . '" class="' . $slide['animation'] . '" />';
         $imgFile = $this->sliderDir . $this->name . '/' . strtolower($this->thisLang) . '/' . $slide['fileName'];
         if (!file_exists($imgFile)) {
             $imgFile = $this->sliderDir . $this->name . '/' . strtolower($this->defaultLang) . '/' . $slide['fileName'];
         }
         $img = '<img src="' . $imgFile . '" class="' . $slide['animation'] . '" />';
         if (isset($slide['url']) && $slide['url'] != null && $slide['url'] != "") {
             $urlHelper = new UrlHelper();
             $target = "";
             if (substr($slide['url'], 0, 1) == "#") {
                 $url = $urlHelper->getThisPage() . $slide['url'];
             } else {
                 if (substr($slide['url'], 0, 1) == "\$") {
                     $url = $urlHelper->pageUrl(substr($slide['url'], 1), null);
                 } else {
                     if (substr($slide['url'], 0, 7) == "http://") {
                         $target = 'target="_blank"';
                     }
                     $url = $slide['url'];
                 }
             }
             $html .= '<a href="' . $url . ' ' . $target . '">';
             $html .= $img;
             $html .= '</a>';
         } else {
             $html .= $img;
         }
         if (isset($slide['text']) && $slide['text'] != null && $slide['text'] != "") {
             $html .= '<div class="label_text">';
             $html .= $slide['text'];
             $html .= '</div>';
         }
         $html .= "</li>";
         $out .= $html;
     }
     $out .= '</ul>';
     $out .= '</div>';
     $out .= '</div>';
     $out .= $this->generateParams();
     $this->html = $out;
 }
Esempio n. 4
0
 private function generateMenuLevelHtml($parent)
 {
     $out = "";
     if (isset($this->menuItems[$parent]) && count($this->menuItems[$parent]) > 0) {
         if ($parent != 0) {
             $javaID = $this->menuName . "_child_" . $parent;
             $out .= "<ul id='" . $javaID . "' style='display: none;' ";
             $out .= "class='menu child_menu " . $this->menuType . " ";
             $out .= $this->menuCssClass . " " . $this->menuName . "' ";
             $out .= "onmouseover=\"showChildMenu('{$javaID}');\" ";
             $out .= "onmouseout=\"hideChildMenu('{$javaID}');\">";
         } else {
             $out .= "<ul id='" . $this->menuName . "' class='menu ";
             $out .= $this->menuType . " " . $this->menuCssClass . " ";
             $out .= $this->menuName . "'>";
         }
         foreach ($this->menuItems[$parent] as $menuItem) {
             if ($this->checkValue($menuItem['url'])) {
                 $url = $menuItem['url'];
             } else {
                 $urlHelper = new UrlHelper();
                 if ($menuItem['postfix'][0] == "/") {
                     $menuItem['postfix'] = substr($menuItem['postfix'], 1);
                 }
                 $url = $urlHelper->pageUrl($menuItem['page'], null) . $menuItem['postfix'];
             }
             global $_URL_PARAMS;
             $thisPageClass = "";
             if ($menuItem['page'] == $_URL_PARAMS['page']) {
                 $thisPageClass = "thisPage";
             }
             $javaChildID = $this->menuName . "_child_" . $menuItem['menuItem'];
             //                $out .= "<a href='$url' target='".$menuItem['target']."'>";
             $out .= "<li onmouseover=\"showChildMenu('{$javaChildID}');\" onmouseout=\"hideChildMenu('{$javaChildID}');\" ";
             $out .= "class='{$thisPageClass}'>";
             $out .= "<a href='{$url}' target='" . $menuItem['target'] . "'>";
             $out .= "<span text='text'>";
             $out .= $menuItem['title'];
             $out .= "</span>";
             $out .= "</a>";
             $out .= "</li>";
             //                $out .= "</a>";
             $out .= $this->generateMenuLevelHtml($menuItem['menuItem']);
         }
         $out .= "</ul>";
     }
     return $out;
 }
Esempio n. 5
0
 /**
  * Returns the field's input HTML.
  *
  * @param string $name
  * @param mixed  $value
  * @return string
  */
 public function getInputHtml($name, $value)
 {
     $id = craft()->templates->formatInputId($name);
     craft()->templates->includeCssResource('twitter/css/tweet.css');
     craft()->templates->includeJsResource('twitter/js/TweetInput.js');
     craft()->templates->includeJs('new TweetInput("' . craft()->templates->namespaceInputId($id) . '");');
     $tweet = $value;
     $html = "";
     if ($tweet && isset($tweet['id_str'])) {
         $url = 'https://twitter.com/' . $tweet['user']['screen_name'] . '/status/' . $tweet['id_str'];
         if (craft()->request->isSecureConnection()) {
             $profileImageUrl = $tweet['user']['profile_image_url_https'];
         } else {
             $profileImageUrl = $tweet['user']['profile_image_url'];
         }
         if (craft()->twitter_plugin->checkDependencies()) {
             $html .= '<div class="tweet-preview">' . '<div class="tweet-image" style="background-image: url(' . $profileImageUrl . ');"></div> ' . '<div class="tweet-user">' . '<span class="tweet-user-name">' . $tweet['user']['name'] . '</span> ' . '<a class="tweet-user-screenname light" href="http://twitter.com/' . $tweet['user']['screen_name'] . '" target="_blank">@' . $tweet['user']['screen_name'] . '</a>' . '</div>' . '<div class="tweet-text">' . $tweet['text'] . '</div>' . '</div>';
         }
     } else {
         $url = $value;
         $preview = '';
     }
     if (!craft()->twitter_plugin->checkDependencies()) {
         $html .= '<p class="light">' . Craft::t("Twitter plugin is not configured properly. Please check {url} for more informations.", array('url' => Craft::t('<a href="' . UrlHelper::getUrl('twitter/settings') . '">{title}</a>', array('title' => 'Twitter plugin settings')))) . '</p>';
     }
     return '<div class="tweet">' . craft()->templates->render('_includes/forms/text', array('id' => $id, 'name' => $name, 'value' => $url, 'placeholder' => Craft::t('Enter a tweet URL or ID'))) . '<div class="spinner hidden"></div>' . $html . '</div>';
 }
 public function getCpEditUrl()
 {
     $form = $this->getForm();
     if ($form) {
         return UrlHelper::getCpUrl('formerly/' . $form->handle . '/' . $this->id);
     }
 }
Esempio n. 7
0
 protected function addResources()
 {
     // Get revision manifest
     $manifestPath = dirname(__FILE__) . '/resources/rev-manifest.json';
     $manifest = file_exists($manifestPath) && ($manifest = file_get_contents($manifestPath)) ? json_decode($manifest) : false;
     // Get data
     $data = ['fields' => [], 'entryTypeIds' => [], 'baseEditFieldUrl' => rtrim(UrlHelper::getCpUrl('settings/fields/edit'), '/'), 'baseEditEntryTypeUrl' => rtrim(UrlHelper::getCpUrl('settings/sections/sectionId/entrytypes'), '/'), 'baseEditGlobalSetUrl' => rtrim(UrlHelper::getCpUrl('settings/globals'), '/'), 'baseEditCategoryGroupUrl' => rtrim(UrlHelper::getCpUrl('settings/categories'), '/')];
     $sectionIds = craft()->sections->allSectionIds;
     foreach ($sectionIds as $sectionId) {
         $entryTypes = craft()->sections->getEntryTypesBySectionId($sectionId);
         $data['entryTypeIds']['' . $sectionId] = [];
         foreach ($entryTypes as $entryType) {
             $data['entryTypeIds']['' . $sectionId][] = $entryType->id;
         }
     }
     $fields = craft()->fields->allFields;
     foreach ($fields as $field) {
         $data['fields'][$field->handle] = ['id' => $field->id, 'handle' => $field->handle, 'type' => $field->type];
     }
     $data = json_encode($data);
     craft()->templates->includeJs('window._CpFieldLinksData=' . $data . ';');
     // Include resources
     $cssFile = 'stylesheets/CpFieldLinks.css';
     $jsFile = 'javascripts/CpFieldLinks.js';
     craft()->templates->includeCssResource('cpfieldlinks/' . ($manifest ? $manifest->{$cssFile} : $cssFile));
     craft()->templates->includeJsResource('cpfieldlinks/' . ($manifest ? $manifest->{$jsFile} : $jsFile));
 }
 function post()
 {
     $blog_post_id = $this->node->arg('blog_post_id');
     $values = array();
     $form = $this->components->add('form', array('back' => $this->db->from('blog_post')->select('title')));
     $author_id = $this->db->from('blog_author')->select('blog_author_id')->where('user_id', $this->plugin->Auth->get('user_id'))->fetchScalar();
     $blog_post = $form->addTable('blog_post', array('title' => array('validator' => $this->valid->get('required', 'no_html')), 'content' => array('validator' => $this->valid->required), 'blog_author_id' => array('value' => $author_id), 'blog_id' => array('value' => $this->node->arg('blog_id')), 'pub_date' => array('value' => date('Y-m-d H:i:s')), 'summary' => array('validator' => $this->valid->required), 'status' => array('validator' => $this->valid->required), 'blog_category_id' => array('type' => 'dropdown', 'validator' => $this->valid->required)));
     $plugins = $blog_post->content->getConfigOption('plugins');
     $blog_post->content->setConfigOption('plugins', $plugins . ',table,pagebreak,markettoimages');
     $blog_post->content->setConfigOption('pagebreak_separator', '<!-- Break -->');
     $blog_post->content->setConfigOption('height', 600);
     $blog_post->content->setConfigOption('theme_advanced_blockformats', "p,pre,h1,h2,h3,h4,blockquote,code");
     $blog_post->content->setConfigOption('content_css', UrlHelper::resource('/blog/tinymce.css'));
     $blog_post->content->setConfigOption('theme_advanced_buttons1_add', 'pagebreak,markettoimages');
     $blog_post->content->setConfigOption('theme_advanced_buttons2', 'tablecontrols');
     $blog_post->content->setConfigOption('valid_elements', '*[*]');
     $blog_post->content->filter_html = false;
     $blog_post->blog_category_id->setDataSource($this->db->from('blog_category')->select('blog_category_id', 'name')->where('blog_id', $this->node->arg('blog_id'))->orderby('name', 'asc'));
     $blog_post->blog_category_id->add('', $this->lang->categories['select']);
     $blog_post->status->setDataSource($this->lang->status);
     $blog_post_tag = $form->addTable('blog_post_tag', array('blog_tag_id' => array('type' => '/blog/taglist')), array('keys' => array('blog_post_id' => $blog_post), 'delete' => array('blog_post_id' => $blog_post), 'multirow' => true, 'multicolumn' => true));
     $blog_post_tag->blog_post_id->setReference($blog_post->blog_post_id, true);
     $blog_post_tag->blog_tag_id->setNote($this->lang->fields['separated']);
     if ($blog_post_id) {
         $values = $this->db->from('blog_post')->where('blog_post_id', $blog_post_id)->fetchRow();
         $form->setValues($blog_post, $values);
         $values = $this->db->from('blog_post_tag')->select('blog_tag_id')->where('blog_post_id', $blog_post_id)->fetchArray();
         $form->setValues($blog_post_tag, array('blog_tag_id' => $values));
     }
 }
 /**
  * Edit an asset source.
  *
  * @param array $variables
  *
  * @throws HttpException
  * @return null
  */
 public function actionEditSource(array $variables = array())
 {
     if (empty($variables['source'])) {
         if (!empty($variables['sourceId'])) {
             $variables['source'] = craft()->assetSources->getSourceById($variables['sourceId']);
             if (!$variables['source']) {
                 throw new HttpException(404);
             }
             $variables['sourceType'] = craft()->assetSources->populateSourceType($variables['source']);
         } else {
             $variables['source'] = new AssetSourceModel();
             $variables['sourceType'] = craft()->assetSources->getSourceType('Local');
         }
     }
     if (empty($variables['sourceType'])) {
         $variables['sourceType'] = craft()->assetSources->populateSourceType($variables['source']);
     }
     if (craft()->getEdition() == Craft::Pro) {
         $sourceTypes = craft()->assetSources->getAllSourceTypes();
         $variables['sourceTypes'] = AssetSourceTypeVariable::populateVariables($sourceTypes);
     }
     $variables['isNewSource'] = !$variables['source']->id;
     if ($variables['isNewSource']) {
         $variables['title'] = Craft::t('Create a new asset source');
     } else {
         $variables['title'] = $variables['source']->name;
     }
     $variables['crumbs'] = array(array('label' => Craft::t('Settings'), 'url' => UrlHelper::getUrl('settings')), array('label' => Craft::t('Assets'), 'url' => UrlHelper::getUrl('settings/assets')), array('label' => Craft::t('Asset Sources'), 'url' => UrlHelper::getUrl('settings/assets')));
     $variables['tabs'] = array('settings' => array('label' => Craft::t('Settings'), 'url' => '#assetsource-settings'), 'fieldlayout' => array('label' => Craft::t('Field Layout'), 'url' => '#assetsource-fieldlayout'));
     $this->renderTemplate('settings/assets/sources/_edit', $variables);
 }
 /**
  * Includes the plugin's resources for the Control Panel.
  */
 protected function includeCpResources()
 {
     // Prepare config
     $config = [];
     $config['iconMapping'] = craft()->config->get('iconMapping', 'redactoriconbuttons');
     $iconAdminPath = craft()->path->getConfigPath() . 'redactoriconbuttons/icons.svg';
     $iconPublicPath = craft()->config->get('iconFile', 'redactoriconbuttons');
     if (IOHelper::fileExists($iconAdminPath)) {
         $config['iconFile'] = UrlHelper::getResourceUrl('config/redactoriconbuttons/icons.svg');
     } elseif ($iconPublicPath) {
         $config['iconFile'] = craft()->config->parseEnvironmentString($iconPublicPath);
     } else {
         $config['iconFile'] = UrlHelper::getResourceUrl('redactoriconbuttons/icons/redactor-i.svg');
     }
     // Include JS
     $config = JsonHelper::encode($config);
     $js = "var RedactorIconButtons = {}; RedactorIconButtons.config = {$config};";
     craft()->templates->includeJs($js);
     craft()->templates->includeJsResource('redactoriconbuttons/redactoriconbuttons.js');
     // Include CSS
     craft()->templates->includeCssResource('redactoriconbuttons/redactoriconbuttons.css');
     // Add external spritemap support for IE9+ and Edge 12
     $ieShim = craft()->config->get('ieShim', 'redactoriconbuttons');
     if (filter_var($ieShim, FILTER_VALIDATE_BOOLEAN)) {
         craft()->templates->includeJsResource('redactoriconbuttons/lib/svg4everybody.min.js');
         craft()->templates->includeJs('svg4everybody();');
     }
 }
 /**
  * Returns the URL to a specific page
  *
  * @param int $page
  *
  * @return string|null
  */
 public function getPageUrl($page)
 {
     if ($page >= 1 && $page <= $this->totalPages) {
         $path = craft()->request->getPath();
         $params = array();
         if ($page != 1) {
             $pageTrigger = craft()->config->get('pageTrigger');
             if (!is_string($pageTrigger) || !strlen($pageTrigger)) {
                 $pageTrigger = 'p';
             }
             // Is this query string-based pagination?
             if ($pageTrigger[0] === '?') {
                 $pageTrigger = trim($pageTrigger, '?=');
                 if ($pageTrigger === 'p') {
                     // Avoid conflict with the main 'p' param
                     $pageTrigger = 'pg';
                 }
                 $params = array($pageTrigger => $page);
             } else {
                 if ($path) {
                     $path .= '/';
                 }
                 $path .= $pageTrigger . $page;
             }
         }
         return UrlHelper::getUrl($path, $params);
     }
 }
 public function getInputHtml($name, $value)
 {
     // Include JavaScript & CSS
     craft()->templates->includeJsResource('simplemeta/simple.meta.js');
     craft()->templates->includeCssResource('simplemeta/simple.meta.css');
     // Whether any assets sources exist
     $sources = craft()->assets->findFolders();
     $variables['assetsSourceExists'] = count($sources);
     // URL to create a new assets source
     $variables['newAssetsSourceUrl'] = UrlHelper::getUrl('settings/assets/sources/new');
     if (!empty($value)) {
         $simpleMetaModel = SimpleMeta_SimpleMetaModel::populateModel($value);
     } else {
         $simpleMetaModel = new SimpleMeta_SimpleMetaModel();
         $simpleMetaModel->handle = $name;
     }
     // Set assets
     $simplemetaAssets = array('socialOGImage' => $simpleMetaModel->socialOGImageId, 'socialTwitterGalleryImages' => $simpleMetaModel->socialTwitterGalleryImagesId, 'socialTwitterPhoto' => $simpleMetaModel->socialTwitterPhotoId, 'socialTwitterProductImage' => $simpleMetaModel->socialTwitterProductImageId, 'socialTwitterSummaryImage' => $simpleMetaModel->socialTwitterSummaryImageId, 'socialTwitterSummaryLargeImage' => $simpleMetaModel->socialTwitterSummaryLargeImageId);
     foreach ($simplemetaAssets as $key => $value) {
         if ($value) {
             $asset = craft()->elements->getElementById($value);
             $variables[$key . 'Elements'] = array($asset);
             $variables[$key . 'Id'] = $asset->id;
         } else {
             $variables[$key . 'Elements'] = array();
             $variables[$key . 'Id'] = "";
         }
     }
     // Set element type
     $variables['elementType'] = craft()->elements->getElementType(ElementType::Asset);
     $data = array_merge($simpleMetaModel->getAttributes(), $variables);
     return craft()->templates->render('simplemeta/input', $data);
 }
 /**
  * @inheritDoc ITask::runStep()
  *
  * @param int $step
  *
  * @return bool
  */
 public function runStep($step)
 {
     // NOTE: Perhaps much of this should be moved into a service
     $batch = \Guzzle\Batch\BatchBuilder::factory()->transferRequests(20)->bufferExceptions()->build();
     // Make the client
     $client = new \Guzzle\Http\Client();
     // Set the Accept header
     $client->setDefaultOption('headers/Accept', '*/*');
     // Loop the paths in this step
     foreach ($this->_paths[$step] as $path) {
         // Make the url, stripping 'site:' from the path if it exists
         $newPath = preg_replace('/site:/', '', $path, 1);
         $url = UrlHelper::getSiteUrl($newPath);
         // Create the GET request
         $request = $client->get($url);
         // Add it to the batch
         $batch->add($request);
     }
     // Flush the queue and retrieve the flushed items
     $requests = $batch->flush();
     // Log any exceptions
     foreach ($batch->getExceptions() as $e) {
         Craft::log('CacheMonster: an exception occurred: ' . $e->getMessage(), LogLevel::Error);
     }
     // Clear any exceptions
     $batch->clearExceptions();
     return true;
 }
 function admin_setup()
 {
     if ($this->layout) {
         $this->layout = $this->load->layout('admin');
     }
     $default_utility = '/' . DEFAULT_MODULE . '/admin/' . DEFAULT_MODULE . 'admin';
     if (!file_exists(APPD_APPLICATION . '/' . DEFAULT_MODULE . '/admin/' . DEFAULT_MODULE . 'admin.utility.php')) {
         $default_utility = '/admin/admin/adminadmin';
     }
     $util = $this->load->utility($default_utility);
     $path = $util ? DEFAULT_MODULE . '/' . DEFAULT_MODULE : 'admin/index';
     $default_config = array('roles' => array('admin' => array('home' => $path, 'modules' => '*')), 'time_limit' => 500, 'memory_limit' => '128M');
     $this->config = array_merge($default_config, $this->config);
     $roles = array_keys($this->config['roles']);
     $this->plugin->Auth->addArea('admin-area', $roles);
     foreach ($roles as $role) {
         $this->plugin->Auth->addRole($role, array('member-area', 'admin-area', 'open-area'));
     }
     $this->plugin->Auth->authorize('admin-area', array('admin', 'node', 'node_process', 'error'), array(&$this, '_goLogin'));
     if (isset($this->config['language']) && $this->config['language'] != Lang::getCurrent()) {
         $this->helper->redirect->to(UrlHelper::current($this->config['language']));
     }
     if (!ini_get('safe_mode') && is_callable('set_time_limit') && is_callable('ini_set')) {
         @set_time_limit($this->config['time_limit']);
         @ini_set("memory_limit", $this->config['memory_limit']);
     }
 }
Esempio n. 15
0
 public function __callStatic($funName, $argu)
 {
     if (($index = strpos($funName, "Url")) && !method_exists(UrlHelper, $funName)) {
         $type = strtolower(substr($funName, 0, $index));
         return UrlHelper::CommonUrlHelper($type, $argu[0], $argu[1], $argu[2]);
     }
 }
Esempio n. 16
0
 /**
  * Crop user photo.
  *
  * @return null
  */
 public function actionCropLogo()
 {
     $this->requireAjaxRequest();
     $this->requireAdmin();
     try {
         $x1 = craft()->request->getRequiredPost('x1');
         $x2 = craft()->request->getRequiredPost('x2');
         $y1 = craft()->request->getRequiredPost('y1');
         $y2 = craft()->request->getRequiredPost('y2');
         $source = craft()->request->getRequiredPost('source');
         // Strip off any querystring info, if any.
         $source = UrlHelper::stripQueryString($source);
         $imagePath = craft()->path->getTempUploadsPath() . $source;
         if (IOHelper::fileExists($imagePath) && craft()->images->checkMemoryForImage($imagePath)) {
             $targetPath = craft()->path->getStoragePath() . 'logo/';
             IOHelper::ensureFolderExists($targetPath);
             IOHelper::clearFolder($targetPath);
             craft()->images->loadImage($imagePath, 300, 300)->crop($x1, $x2, $y1, $y2)->scaleToFit(300, 300, false)->saveAs($targetPath . $source);
             IOHelper::deleteFile($imagePath);
             $html = craft()->templates->render('settings/general/_logo');
             $this->returnJson(array('html' => $html));
         }
         IOHelper::deleteFile($imagePath);
     } catch (Exception $exception) {
         $this->returnErrorJson($exception->getMessage());
     }
     $this->returnErrorJson(Craft::t('Something went wrong when processing the logo.'));
 }
 /**
  * Process Successful Login
  */
 private function _handleSuccessfulLogin($setNotice)
 {
     // Get the current user
     $currentUser = craft()->userSession->getUser();
     // Were they trying to access a URL beforehand?
     $returnUrl = craft()->userSession->getReturnUrl(null, true);
     if ($returnUrl === null || $returnUrl == craft()->request->getPath()) {
         // If this is a CP request and they can access the control panel, send them wherever
         // postCpLoginRedirect tells us
         if (craft()->request->isCpRequest() && $currentUser->can('accessCp')) {
             $postCpLoginRedirect = craft()->config->get('postCpLoginRedirect');
             $returnUrl = UrlHelper::getCpUrl($postCpLoginRedirect);
         } else {
             // Otherwise send them wherever postLoginRedirect tells us
             $postLoginRedirect = craft()->config->get('postLoginRedirect');
             $returnUrl = UrlHelper::getSiteUrl($postLoginRedirect);
         }
     }
     // If this was an Ajax request, just return success:true
     if (craft()->request->isAjaxRequest()) {
         $this->returnJson(array('success' => true, 'returnUrl' => $returnUrl));
     } else {
         if ($setNotice) {
             craft()->userSession->setNotice(Craft::t('Logged in.'));
         }
         $this->redirectToPostedUrl($currentUser, $returnUrl);
     }
 }
Esempio n. 18
0
 function login_process()
 {
     $form = $this->load->form('login', $_POST);
     if (!$form->validate()) {
         Session::setFlash('next', $form->next->getValue());
         $this->helper->redirect->flash(UrlHelper::referer(), $form->getId(), $form->getFlashParams());
     }
     $values = $form->getValue();
     if ($form->next->getValue()) {
         #Parameters 'auth' => 'login' are passed as a flash to the next page
         $this->view->setRedirect($form->next->getValue(), 'auth', 'login');
     } else {
         $this->view->setRedirect('/');
     }
     $user_id = $this->db->Auth->getUserId($values['username'], $values['password']);
     if (!$user_id && $this->config['old_password']) {
         $user_id = $this->db->Auth->getUserIdFromOldPassword($values['username'], $form->password->getRawValue());
     }
     if (!$user_id) {
         $form->username->setErrorCode('invalid');
         $this->helper->redirect->flash(UrlHelper::referer(), $form->getId(), $form->getFlashParams());
     }
     if (!$this->db->Auth->isEnabled($user_id)) {
         $this->helper->redirect->flash(UrlHelper::referer(), $form->getId(), $form->getFlashParams());
     }
     if (!$this->db->Auth->isActivated($user_id)) {
         $this->helper->redirect->to('/auth/unconfirmed');
     }
     $this->plugin->Auth->login($user_id, $form->remember->isChecked(), $values['module']);
 }
 /**
  * Edit an device.
  *
  * @param array $variables
  *
  * @throws HttpException
  */
 public function actionEditDevice(array $variables = array())
 {
     if (!empty($variables['appHandle'])) {
         $variables['app'] = craft()->pushNotifications_apps->getAppByHandle($variables['appHandle']);
     } elseif (!empty($variables['appId'])) {
         $variables['app'] = craft()->pushNotifications_apps->getAppById($variables['appId']);
     }
     if (empty($variables['app'])) {
         throw new HttpException(404);
     }
     // Now let's set up the actual device
     if (empty($variables['device'])) {
         if (!empty($variables['deviceId'])) {
             $variables['device'] = craft()->pushNotifications_devices->getDeviceById($variables['deviceId']);
             if (!$variables['device']) {
                 throw new HttpException(404);
             }
         } else {
             $variables['device'] = new PushNotifications_DeviceModel();
             $variables['device']->appId = $variables['app']->id;
         }
     }
     if (!$variables['device']->id) {
         $variables['title'] = Craft::t('Create a new device');
     } else {
         $variables['title'] = $variables['device']->title;
     }
     // Breadcrumbs
     $variables['crumbs'] = array(array('label' => Craft::t('Push Notifications'), 'url' => UrlHelper::getUrl('pushnotifications')), array('label' => $variables['app']->name, 'url' => UrlHelper::getUrl('pushnotifications')));
     // Set the "Continue Editing" URL
     $variables['continueEditingUrl'] = 'pushnotifications/devices/' . $variables['app']->handle . '/{id}';
     // Render the template!
     $this->renderTemplate('pushnotifications/devices/_edit', $variables);
 }
 /**
  * Install examples
  *
  * @return void
  */
 public function actionInstall()
 {
     $this->_installExampleTemplates();
     $this->_installExampleData();
     craft()->userSession->setNotice(Craft::t('Examples successfully installed.'));
     $this->redirect(UrlHelper::getCpUrl() . '/sproutemail');
 }
 public function processRedirect($uri)
 {
     $records = $this->getAllRedirects();
     $doRedirect = false;
     foreach ($records as $record) {
         $record = $record->attributes;
         // trim to tolerate whitespace in user entry
         $record['uri'] = trim($record['uri']);
         // type of match. 3 possibilities:
         // standard match (no *, no initial and final #) - regex_match = false
         // regex match (initial and final # (may also contain *)) - regex_match = true
         // wildcard match (no initial and final #, but does have *) - regex_match = true
         $regex_match = false;
         if (preg_match("/^#(.+)#\$/", $record['uri'], $matches)) {
             // all set to use the regex
             $regex_match = true;
         } elseif (strpos($record['uri'], "*")) {
             // not necessary to replace / with \/ here, but no harm to it either
             $record['uri'] = "#^" . str_replace(array("*", "/"), array("(.*)", "\\/"), $record['uri']) . '#';
             $regex_match = true;
         }
         if ($regex_match) {
             if (preg_match($record['uri'], $uri)) {
                 $redirectLocation = preg_replace($record['uri'], $record['location'], $uri);
             }
         } else {
             // Standard match
             if ($record['uri'] == $uri) {
                 $redirectLocation = $record['location'];
             }
         }
     }
     return isset($redirectLocation) ? array("url" => strpos($record['location'], "http") === 0 ? $redirectLocation : UrlHelper::getSiteUrl($redirectLocation), "type" => $record['type']) : false;
 }
 /**
  * Load Required Scripts
  * 
  */
 public function includeScripts($form)
 {
     // Ajax Submit Script
     if ($form->formSettings["ajaxSubmit"] == "1") {
         craft()->templates->includeJsFile(UrlHelper::getResourceUrl('formbuilder2/js/ajaxsubmit.js'));
     }
     $fieldLayout = $form->fieldLayout->getFieldLayout();
     $fields = $fieldLayout->getFields();
     foreach ($fields as $key => $value) {
         $field = $value->getField();
         if ($field->type == 'Color') {
             // Colorpicker
             craft()->templates->includeCssFile(UrlHelper::getResourceUrl('formbuilder2/css/libs/colorpicker.css'));
             craft()->templates->includeJsFile(UrlHelper::getResourceUrl('formbuilder2/js/libs/colorpicker.js'));
         } elseif ($field->type == 'Date') {
             // Date & Time Picker
             craft()->templates->includeJsFile(UrlHelper::getResourceUrl('/lib/jquery-ui.min.js'));
             craft()->templates->includeJsFile(UrlHelper::getResourceUrl('lib/jquery.timepicker/jquery.timepicker.min.js'));
             craft()->templates->includeCssFile(UrlHelper::getResourceUrl('formbuilder2/css/libs/datetimepicker.css'));
         } elseif ($field->type == 'RichText') {
             // WYSIWYG Editor
             craft()->templates->includeCssResource('/lib/redactor/redactor.css');
             craft()->templates->includeJsResource('/lib/redactor/redactor.min.js');
         } elseif ($field->type == 'Lightswitch') {
             // Lightswitch
             craft()->templates->includeCssFile(UrlHelper::getResourceUrl('formbuilder2/css/libs/lightswitch.css'));
         }
     }
     return;
 }
 public function init()
 {
     parent::init();
     $user = craft()->userSession->getUser();
     if (craft()->request->isCpRequest()) {
         $allNavs = craft()->cpNav_nav->getDefaultOrUserNavs();
         if ($user) {
             if ($this->getSettings()->showQuickAddMenu && $user->can('quickAddMenu')) {
                 $this->insertJsForQuickMenuAdd($allNavs);
             }
         }
         if ($allNavs) {
             foreach ($allNavs as $nav) {
                 // Allow links to be opened in new window - insert some small JS
                 if ($nav->newWindow) {
                     $this->insertJsForNewWindow($nav);
                 }
                 // Check to ensure this page is enabled - otherwise simply redirect to first available menu item
                 if (craft()->request->path == $nav->url) {
                     if (!$nav->enabled) {
                         $enabledNavs = craft()->cpNav_nav->getAllNavsByAttributes(array('enabled' => true));
                         // We're on a page that's disabled - redirect to the first enabled one!
                         craft()->request->redirect(UrlHelper::getUrl($enabledNavs[0]->url));
                     }
                 } else {
                     if (craft()->request->path == preg_replace(sprintf('/^(https?:\\/\\/)?(%s)?\\/?%s\\//', preg_quote(craft()->getSiteUrl(''), '/'), preg_quote(craft()->config->get('cpTrigger')), '/'), '', $nav->url) && $nav->enabled && $nav->manualNav) {
                         // Add some JavaScript to correct the selected nav item for manually added navigation items.
                         // Have to do this with JavaScript for now as the nav item selection is made after the modifyCpNav hook.
                         $this->insertJsForManualNavSelection($nav);
                     }
                 }
             }
         }
     }
 }
 /**
  * Edit a Redirect.
  *
  * @param array $variables
  * @throws HttpException
  */
 public function actionEditRedirect(array $variables = array())
 {
     //Get method options
     $variables['methodOptions'] = sproutSeo()->redirects->getMethods();
     //Set title
     $variables['subTitle'] = Craft::t('Create a new redirect');
     // Now let's set up the actual redirect
     if (empty($variables['redirect'])) {
         if (!empty($variables['redirectId'])) {
             //Set title
             $variables['subTitle'] = Craft::t('Edit redirect');
             $variables['redirect'] = sproutSeo()->redirects->getRedirectById($variables['redirectId']);
             if (!$variables['redirect']) {
                 throw new HttpException(404);
             }
         } else {
             $variables['redirect'] = new SproutSeo_RedirectModel();
         }
     }
     // Set the "Continue Editing" URL
     $variables['continueEditingUrl'] = 'sproutseo/redirects/{id}';
     // Breadcrumbs
     $variables['crumbs'] = array(array('label' => Craft::t('Redirects'), 'url' => UrlHelper::getUrl('redirects')));
     $this->renderTemplate('sproutseo/redirects/_edit', $variables);
 }
 /**
  * Returns the element's CP edit URL.
  *
  * @return string|false
  */
 public function getCpEditUrl()
 {
     $app = $this->getApp();
     if ($app) {
         return UrlHelper::getCpUrl('pushnotifications/devices/' . $app->handle . '/' . $this->id);
     }
 }
 /**
  * Upload a logo for the admin panel.
  */
 public function actionUploadLogo()
 {
     $this->requireAjaxRequest();
     $this->requireAdmin();
     // Upload the file and drop it in the temporary folder
     $uploader = new \qqFileUploader();
     try {
         // Make sure a file was uploaded
         if ($uploader->file && $uploader->file->getSize()) {
             $folderPath = craft()->path->getTempUploadsPath();
             IOHelper::ensureFolderExists($folderPath);
             IOHelper::clearFolder($folderPath, true);
             $fileName = IOHelper::cleanFilename($uploader->file->getName());
             $uploader->file->save($folderPath . $fileName);
             // Test if we will be able to perform image actions on this image
             if (!craft()->images->setMemoryForImage($folderPath . $fileName)) {
                 IOHelper::deleteFile($folderPath . $fileName);
                 $this->returnErrorJson(Craft::t('The uploaded image is too large'));
             }
             craft()->images->cleanImage($folderPath . $fileName);
             $constraint = 500;
             list($width, $height) = getimagesize($folderPath . $fileName);
             // If the file is in the format badscript.php.gif perhaps.
             if ($width && $height) {
                 // Never scale up the images, so make the scaling factor always <= 1
                 $factor = min($constraint / $width, $constraint / $height, 1);
                 $html = craft()->templates->render('_components/tools/cropper_modal', array('imageUrl' => UrlHelper::getResourceUrl('tempuploads/' . $fileName), 'width' => round($width * $factor), 'height' => round($height * $factor), 'factor' => $factor));
                 $this->returnJson(array('html' => $html));
             }
         }
     } catch (Exception $exception) {
         $this->returnErrorJson($exception->getMessage());
     }
     $this->returnErrorJson(Craft::t('There was an error uploading your photo'));
 }
Esempio n. 27
0
    private function _loadCodeMirror()
    {
        if ($this->_actualSettingsPage()) {
            craft()->templates->includeCssResource('cpcss/css/codemirror.css');
            craft()->templates->includeCssResource('cpcss/css/blackboard.css');
            craft()->templates->includeJsResource('cpcss/js/codemirror-css.js');
            craft()->templates->includeJs('
$(function () {
    var $redirect = $("' . addslashes('input[type="hidden"][name="redirect"][value$="settings/plugins"]') . '"),
        $saveBtn = $("' . addslashes('input[type="submit"') . '").wrap("' . addslashes('<div class="btngroup" />') . '"),
        $menuBtn = $("' . addslashes('<div class="btn submit menubtn" />') . '").appendTo($saveBtn.parent()),
        $menu = $("' . addslashes('<div class="menu" />') . '").appendTo($saveBtn.parent()),
        $items = $("<ul />").appendTo($menu),
        $continueOpt = $("' . addslashes('<li><a class="formsubmit" data-redirect="' . UrlHelper::getCpUrl('settings/plugins/cpcss') . '">' . Craft::t('Save and continue editing') . '<span class="shortcut">' . (craft()->request->getClientOs() === 'Mac' ? '⌘' : 'Ctrl+') . 'S</span></a></li>') . '").appendTo($items);
    new Garnish.MenuBtn($menuBtn, {
        onOptionSelect : function (option) {
            Craft.cp.submitPrimaryForm();
        }
    });
    $saveBtn.on("click", function (e) { $redirect.attr("value", "' . UrlHelper::getCpUrl('settings/plugins') . '"); });
    $redirect.attr("value", "' . UrlHelper::getCpUrl('settings/plugins/cpcss') . '");
    CodeMirror.fromTextArea(document.getElementById("settings-additionalCss"), {
        indentUnit: 4,
        styleActiveLine: true,
        lineNumbers: true,
        lineWrapping: true,
        theme: "blackboard"
    });
});', true);
        }
    }
 function setupThumbs($filedef, $imagedef)
 {
     $path_helper = new PathHelper();
     foreach ($imagedef['thumbs'] as &$thumb) {
         $thumb[1] = $path_helper->join(array($imagedef['base_dir'], $thumb[1], $filedef['filename']), '/');
     }
     if ($imagedef['admin_dir'] !== false) {
         #For the list
         $path_1 = $path_helper->join(array('{public}/' . DEFAULT_MODULE . '/admin', $imagedef['admin_dir'], 'small', $filedef['value']), '/');
         $admin_thumb_1 = array('crop', $path_1, 30, 30);
         $imagedef['thumbs'][] = $admin_thumb_1;
         #For the gallery
         $path_2 = $path_helper->join(array('{public}/' . DEFAULT_MODULE . '/admin', $imagedef['admin_dir'], $filedef['value']), '/');
         $admin_thumb_2 = array('filled', $path_2, 160);
         $imagedef['thumbs'][] = $admin_thumb_2;
     }
     $thumbs = $imagedef['thumbs'];
     if ($thumbs) {
         $last = $thumbs[count($thumbs) - 1];
         $parts = explode('/', $last[1]);
         $dir = implode('/', array_slice($parts, 3, count($parts) - 4));
         $this->setBasePath(UrlHelper::resource('/' . DEFAULT_MODULE . '/admin/' . $dir));
     }
     $this->setThumbsTarget($thumbs);
 }
 /**
  * Get all available entries to edit from a section.
  *
  * @param array $variables
  *
  * @return array
  */
 public function editEntry($variables)
 {
     if (!isset($variables['sectionHandle'])) {
         return false;
     }
     // Gather commands
     $commands = array();
     // Find entries
     $criteria = array('section' => $variables['sectionHandle'], 'locale' => craft()->language);
     $entries = craft()->amCommand_elements->getElements(ElementType::Entry, $criteria);
     if (!$entries) {
         craft()->amCommand->setReturnMessage(Craft::t('No entries in this section exist yet.'));
     } else {
         foreach ($entries as $entry) {
             // Get CP edit URL
             $url = UrlHelper::getCpUrl('entries/' . $variables['sectionHandle'] . '/' . $entry['id'] . ($entry['slug'] ? '-' . $entry['slug'] : ''));
             if (craft()->isLocalized()) {
                 $url .= '/' . craft()->language;
             }
             // Add command
             $commands[] = array('name' => $entry['title'], 'info' => Craft::t('URI') . ': ' . $entry['uri'], 'url' => $url);
         }
     }
     return $commands;
 }
Esempio n. 30
0
 /**
  * @inheritDoc BaseElementModel::getCpEditUrl()
  *
  * @return string|false
  */
 public function getCpEditUrl()
 {
     $group = $this->getGroup();
     if ($group) {
         return UrlHelper::getCpUrl('tagmanager/' . $group->handle . '/' . $this->id);
     }
 }