Beispiel #1
0
 public static function url($id, $options = array())
 {
     $options += array('full' => false, 'route' => true, 'slug' => true);
     $full = $options['full'];
     unset($options['full']);
     $slug = $options['slug'];
     unset($options['slug']);
     $route = $options['route'];
     unset($options['route']);
     if (!is_array($id)) {
         $node = self::read($id);
     } else {
         $node = isset($id['CmsNode']) ? $id : array('CmsNode' => $id);
         $id = $node['CmsNode']['id'];
     }
     if ($node['CmsNode']['model']) {
         $options += array('plugin' => $node['CmsNode']['plugin'], 'controller' => Inflector::tableize($node['CmsNode']['model']));
     } else {
         $options += array('plugin' => 'cms', 'controller' => 'cms_nodes');
     }
     $options += array('admin' => false, 'action' => 'view', $id);
     if ($slug && $node['CmsNode']['slug']) {
         $options[] = $node['CmsNode']['slug'];
     }
     return $route ? Sl::url($options, $full) : $options;
 }
Beispiel #2
0
 /**
  * Get or set version info (DB)
  *
  * @param string $extension
  * @param string $newVersion
  */
 public static function version($extension = 'core', $newVersion = null)
 {
     if (SlConfigure::read('Sl.installPending')) {
         return SlConfigure::read('Sl.version');
     }
     if (!SlConfigure::read('Mirror.version')) {
         App::import('Core', 'ConnectionManager');
         $db = @ConnectionManager::getDataSource('default');
         if (!$db->isConnected() || !in_array("{$db->config['prefix']}core_versions", $db->listSources())) {
             if (strpos(Sl::url(false), '/install') === false) {
                 Router::connect(Sl::url(false), array('controller' => 'install'));
             }
             return;
         }
         App::import('Core', 'ClassRegistry');
         ClassRegistry::init('Version')->refreshMirror();
     }
     if ($newVersion) {
         $versionModel = ClassRegistry::init('Version');
         $id = $versionModel->field('Version.id', array('Version.name' => $extension));
         $versionModel->create();
         return $versionModel->save(array('id' => $id, 'name' => $extension, 'version' => $newVersion));
     }
     return SlConfigure::read("Mirror.version.{$extension}");
 }
 public function oauth()
 {
     if (isset($this->params['url']['code'])) {
         $code = $this->params['url']['code'];
     }
     SlSession::write('Api.facebook.accessToken', r('access_token=', '', $this->Facebook->graph("oauth/access_token", array('client_id' => SlConfigure::read('Api.facebook.appId'), 'redirect_uri' => Sl::url(true), 'client_secret' => SlConfigure::read('Api.facebook.secret'), 'code' => $code, 'decode' => false))));
     $this->redirect(SlConfigure::read('Api.facebook.oauthSuccess'));
 }
Beispiel #4
0
 public function getSession($scope = null)
 {
     $this->accessToken = SlSession::read('Api.facebook.accessToken');
     if ($this->accessToken) {
         return;
     }
     if (is_array($scope)) {
         $scope = implode(',', $scope);
     }
     $appId = SlConfigure::read('Api.facebook.appId');
     $redirectUrl = array('plugin' => 'api', 'controller' => 'facebook', 'action' => 'oauth');
     if (!empty($this->params['prefix'])) {
         $redirectUrl += array($this->params['prefix'] => false);
     }
     $redirectUrl = urlencode(Sl::url($redirectUrl, true));
     $this->controller->redirect("https://graph.facebook.com/oauth/authorize?client_id={$appId}&redirect_uri={$redirectUrl}&scope={$scope}");
 }
 function parse($html = null, $blockName = 'document', $blockParams = null)
 {
     $blockParams = (array) $blockParams;
     $blockParams += array('fields' => $this->_getVar('fields'), 'domId' => Sl::uniqid());
     if (!is_array($blockParams['fields'])) {
         return;
     }
     $form = $this->_getHelper('SlForm');
     $fields = array();
     $form->create('CmsContactForm');
     foreach ($blockParams['fields'] as $f => $o) {
         $fields[] = array('inputName' => $f, 'inputOptions' => $o, 'inputHtml' => $form->input($f, $o));
     }
     if ($fields) {
         $this->blocks['loop']->params[0] = $fields;
         $this->vars['domId'] = $blockParams['domId'];
         $this->vars['actionUrl'] = Sl::url();
         return parent::parse($html, $blockName);
     }
 }
Beispiel #6
0
 /**
  * Extended Router::url() with proper html entities and spaces replaced by '+'
  *
  * @param mixed $url Set to bool (true = 'with base' or false) to get current requestUri
  * @param bool $full
  * @return string
  * @static
  */
 function url($url = null, $full = false)
 {
     return h(r(' ', '+', Sl::url($url, $full)));
 }
Beispiel #7
0
 * @link          http://cakephp.org CakePHP(tm) Project
 * @package       cake
 * @subpackage    cake.app.config
 * @since         CakePHP(tm) v 0.2.9
 * @license       MIT License (http://www.opensource.org/licenses/mit-license.php)
 */
/**
 * Here, we are connecting '/' (base path) to controller called 'Pages',
 * its action called 'display', and we pass a param to select the view file
 * to use (in this case, /app/views/pages/home.ctp)...
 */
// check installation
if (Sl::version() != SlConfigure::read('Sl.version')) {
    if (!preg_match('!/install|/users/login!', Sl::url(false))) {
        SlConfigure::write('Message.migrate', array('message' => __t('System files have been recently updated. Proceeding to database migration...'), 'params' => array('class' => 'message')));
        Router::connect(Sl::url(false), array('controller' => 'install', 'action' => 'migrate'));
    }
}
// localized routes
$langRules = array('lang' => implode('|', SlConfigure::read('I18n.langs')));
// home
$home = SlConfigure::read1('Routing.home');
Router::connect('/', $home);
Router::connect('/:lang', $home, $langRules);
// prefixed homes
$prefixedRoutes = SlConfigure::read('Routing.prefixes');
foreach ($prefixedRoutes as $prefix => $route) {
    Router::connect("/{$prefix}", $route);
}
// custom routes
$routes = SlConfigure::read('Routing.routes');
 /**
  * Redirects to given $url, after turning off $this->autoRender.
  * Script execution is halted after the redirect.
  *
  * @param mixed $url A string or array-based URL pointing to another location within the app, or an absolute URL
  * @param integer $status Optional HTTP status code (eg: 404)
  * @access public
  * @link http://book.cakephp.org/view/425/redirect
  */
 public function redirect($url, $status = null, $useReferer = true)
 {
     if ($useReferer) {
         $ref = SlSession::read('Routing.ref');
         if ($ref) {
             SlSession::delete('Routing.ref');
             if (Sl::url($ref) !== Sl::url()) {
                 $url = $ref;
             }
         }
     }
     // cyclic check
     if (Sl::url($url) === Sl::url()) {
         die('Infinite redirection loop detected.');
     }
     // code inspired from RequestHandlerComponent
     if ($this->RequestHandler->isAjax()) {
         foreach ($_POST as $key => $val) {
             unset($_POST[$key]);
         }
         echo Sl::requestAction($url, array('requested' => false));
         $this->_stop();
     }
     // show a human readable redirect message allowing debug output to be read
     if (headers_sent() || $this->output && Configure::read()) {
         $url = h(SL::url($url));
         if (empty($status)) {
             $status = 'null';
         }
         echo "<p style='background: #ff7; color: #000; padding: 1em;'>Redirect to <a href='{$url}'>{$url}</a> (code: {$status}) cancelled.</p>";
         while (ob_get_level()) {
             ob_end_flush();
         }
         $this->_stop();
     }
     parent::redirect(Sl::url($url, true), $status);
 }
Beispiel #9
0
 function parse($html, $blockName = 'document', $blockParams = null)
 {
     $full = !empty($blockParams['full']);
     unset($blockParams['full']);
     return h(r(' ', '+', Sl::url($html ? trim(parent::parse($html)) : $blockParams, $full)));
 }
Beispiel #10
0
 function parse($html = null, $blockName = 'document', $blockParams = null, $noCycle = false)
 {
     $this->vars['href'] = null;
     $blockParams = (array) $blockParams;
     $blockParams += array('align' => false, 'var' => 'CmsImage', 'thumb' => 'icon', 'zoomCrop' => false, 'quality' => 75, 'link' => empty($blockParams['filter']) || $blockParams['filter'] !== 'full' ? 'auto' : false, 'rel' => empty($blockParams['href']) ? 'colorbox' : null, 'href' => null);
     $autoLink = $blockParams['link'] == 'auto';
     if (!empty($blockParams['id'])) {
         $image = ClassRegistry::init('Image');
         list($data) = $image->find('first', array('conditions' => array('id' => $blockParams['id']), 'recursive' => -1));
     } elseif (isset($blockParams['index'])) {
         $data = $this->_getVar("ImageGallery.{$blockParams['index']}");
     } else {
         $data = $this->_getVar($blockParams["var"]);
     }
     if (!empty($data['filename'])) {
         // support for skin-specific filter versions
         if (!empty($blockParams['width']) && !empty($blockParams['height'])) {
             $blockParams['thumb'] = $filter = "{$blockParams['width']}x{$blockParams['height']}{$blockParams['crop']}";
             $targetFilename = r('/', DS, WWW_ROOT . "files/cms_images/thumb/{$blockParams['thumb']}/{$data['filename']}");
             // check for file
             if (!file_exists($targetFilename)) {
                 $sourceFilename = WWW_ROOT . "files/cms_images/{$data['filename']}";
                 $this->_thumb($sourceFilename, $targetFilename, $blockParams);
             }
         }
         $src = "files/cms_images/thumb/{$blockParams['thumb']}/{$data['filename']}";
         if ($blockParams['href']) {
             $href = h(r(' ', '+', Sl::url($blockParams['href'])));
         } elseif ($blockParams['link']) {
             if (!$autoLink || !$this->_getVar('href')) {
                 $href = $this->_getHelper('SlHtml')->webroot("files/cms_images/{$data['filename']}");
             }
         }
     }
     if (!empty($src)) {
         $this->vars['align'] = $blockParams['align'];
         $this->vars['rel'] = empty($href) ? $autoLink ? null : false : $blockParams['rel'];
         $this->vars['title'] = empty($data['title']) ? false : $data['title'];
         $this->vars['src'] = $src;
         $this->vars['href'] = empty($href) ? $autoLink ? null : false : $href;
         return parent::parse($html, $blockName);
     }
 }
Beispiel #11
0
 public function actionLink($action, $url = null, $options = array())
 {
     $options += array('title' => __t(Inflector::humanize($action)), 'url' => array());
     switch ($action) {
         case 'back':
             $ref = SlSession::read('Routing.ref');
             if (empty($ref)) {
                 $ref = env('HTTP_REFERER');
             }
             if (Sl::url($ref, true) == Sl::url(true)) {
                 $ref = null;
             }
             if ($ref) {
                 $options['url'] = $ref;
             } else {
                 $url2 = array('action' => 'index');
             }
             break;
         case 'clone':
             $url2 = array('action' => 'add');
             break;
         case 'preview':
             $url2 = array('admin' => false, 'action' => 'view');
             break;
         default:
             $url2 = array('action' => $action);
     }
     $url2['ref'] = isset($this->params['named']['ref_override']) ? $this->params['named']['ref_override'] : base64_encode(Sl::getInstance(true)->url(false));
     if ($url !== null) {
         if (is_array($url)) {
             $url2 = $url + $url2;
         } else {
             $url2[] = $url;
         }
     } else {
         // automagically pass filtering params
         foreach ($this->params['named'] as $param => $value) {
             if (preg_match('/_id$/', $param) || $param == 'skin') {
                 $url2[$param] = $value;
             }
         }
     }
     if (is_array($options['url'])) {
         $options['url'] += $url2;
     }
     switch ($action) {
         case 'add':
         case 'clone':
             $options += array('class' => 'add');
             break;
         case 'edit':
             $options += array('class' => 'edit');
             break;
         case 'preview':
             $options += array('target' => '_blank');
             break;
         case 'delete':
             $options += array('confirm' => __t('Delete?'), 'class' => 'remove');
             break;
     }
     $title = $options['title'];
     $url = $options['url'];
     unset($options['title']);
     unset($options['url']);
     return $this->link($title, $url, $options);
 }