Browse Source

Remove deprecated classes that are now standalone.

euromark 10 years ago
parent
commit
fb1c8a6a5e
4 changed files with 4 additions and 635 deletions
  1. 0 129
      Controller/Component/AjaxComponent.php
  2. 0 117
      View/AjaxView.php
  3. 4 4
      View/Helper/CommonHelper.php
  4. 0 385
      View/RssView.php

+ 0 - 129
Controller/Component/AjaxComponent.php

@@ -1,129 +0,0 @@
-<?php
-
-App::uses('Component', 'Controller');
-
-/**
- * Ajax Component to respond to AJAX requests.
- *
- * Works together with the AjaxView to easily switch
- * output type from HTML to JSON format.
- *
- * It will also avoid redirects and pass those down as content
- * of the JSON response object.
- *
- * Don't forget Configure::write('Ajax.flashKey', 'messages');
- * if you want to use it with Tools.Flash component.
- *
- * @author Mark Scherer
- * @license http://opensource.org/licenses/mit-license.php MIT
- * @deprecated Use https://github.com/dereuromark/cakephp-ajax/tree/2.x
- */
-class AjaxComponent extends Component {
-
-	public $Controller;
-
-	public $components = ['Session'];
-
-	public $respondAsAjax = false;
-
-	protected $_defaultConfig = [
-		'autoDetect' => true,
-		'resolveRedirect' => true,
-		'flashKey' => 'Message.flash' // Use "messages" for Tools plugin Flash component, set to false to disable
-	];
-
-	/**
-	 * Constructor.
-	 *
-	 * @param ComponentCollection $collection
-	 * @param array $config
-	 */
-	public function __construct(ComponentCollection $collection, $config = []) {
-		$defaults = (array)Configure::read('Ajax') + $this->_defaultConfig;
-		$config += $defaults;
-		parent::__construct($collection, $config);
-	}
-
-	public function initialize(Controller $Controller) {
-		$this->Controller = $Controller;
-
-		if (!$this->settings['autoDetect']) {
-			return;
-		}
-		$this->respondAsAjax = $this->Controller->request->is('ajax');
-	}
-
-	/**
-	 * Called before the Controller::beforeRender(), and before
-	 * the view class is loaded, and before Controller::render()
-	 *
-	 * @param Controller $controller Controller with components to beforeRender
-	 * @return void
-	 */
-	public function beforeRender(Controller $controller) {
-		if (!$this->respondAsAjax) {
-			return;
-		}
-		$this->_respondAsAjax();
-	}
-
-	/**
-	 * AjaxComponent::respondAsAjax()
-	 *
-	 * @return void
-	 */
-	protected function _respondAsAjax() {
-		$this->Controller->viewClass = 'Tools.Ajax';
-
-		// Set flash messages to the view
-		if ($this->settings['flashKey']) {
-			$_message = $this->Session->read($this->settings['flashKey']);
-			$this->Session->delete($this->settings['flashKey']);
-			$this->Controller->set(compact('_message'));
-		}
-	}
-
-	/**
-	 * Called before Controller::redirect(). Allows you to replace the URL that will
-	 * be redirected to with a new URL. The return of this method can either be an array or a string.
-	 *
-	 * If the return is an array and contains a 'url' key. You may also supply the following:
-	 *
-	 * - `status` The status code for the redirect
-	 * - `exit` Whether or not the redirect should exit.
-	 *
-	 * If your response is a string or an array that does not contain a 'url' key it will
-	 * be used as the new URL to redirect to.
-	 *
-	 * @param Controller $controller Controller with components to beforeRedirect
-	 * @param string|array $url Either the string or URL array that is being redirected to.
-	 * @param int $status The status code of the redirect
-	 * @param bool $exit Will the script exit.
-	 * @return array|void Either an array or null.
-	 */
-	public function beforeRedirect(Controller $controller, $url, $status = null, $exit = true) {
-		if (!$this->respondAsAjax || !$this->settings['resolveRedirect']) {
-			return parent::beforeRedirect($controller, $url, $status, $exit);
-		}
-
-		$url = Router::url($url, true);
-
-		if (is_string($status)) {
-			$codes = array_flip($this->response->httpCodes());
-			if (isset($codes[$status])) {
-				$status = $codes[$status];
-			}
-		}
-
-		$this->Controller->autoRender = true;
-		$this->Controller->set('_redirect', compact('url', 'status', 'exit'));
-		$serializeKeys = ['_redirect', '_message'];
-		if (!empty($this->Controller->viewVars['_serialize'])) {
-			$serializeKeys = array_merge($serializeKeys, $this->Controller->viewVars['_serialize']);
-		}
-		$this->Controller->set('_serialize', $serializeKeys);
-
-		return false;
-	}
-
-}

+ 0 - 117
View/AjaxView.php

@@ -1,117 +0,0 @@
-<?php
-App::uses('View', 'View');
-
-/**
- * A view to handle AJAX requests.
- *
- * Expects all incoming requests to be of extension "json" and that the expected result
- * will also be in JSON format.
- * A response to an invalid request may be just HTTP status "code" and error "message"
- * (e.g, on 4xx or 5xx).
- * A response to a valid request will always contain at least "content" and "error" keys.
- * You can add more data using _serialize.
- *
- * @author Mark Scherer
- * @license http://opensource.org/licenses/mit-license.php MIT
- * @deprecated Use https://github.com/dereuromark/cakephp-ajax/tree/2.x
- */
-class AjaxView extends View {
-
-	/**
-	 * List of variables to collect from the associated controller.
-	 *
-	 * @var array
-	 */
-	protected $_passedVars = [
-			'viewVars', 'autoLayout', 'ext', 'helpers', 'view', 'layout', 'name', 'theme',
-			'layoutPath', 'viewPath', 'request', 'plugin', 'passedArgs', 'cacheAction', 'subDir'
-	];
-
-	/**
-	 * The subdirectory. AJAX views are always in ajax.
-	 *
-	 * @var string
-	 */
-	public $subDir = 'ajax';
-
-	/**
-	 * Name of layout to use with this View.
-	 *
-	 * @var string
-	 */
-	public $layout = false;
-
-	/**
-	 * Constructor
-	 *
-	 * @param Controller $controller
-	 */
-	public function __construct(Controller $controller = null) {
-		parent::__construct($controller);
-		// Unfortunately, layout gets overwritten via passed Controller attribute
-		if ($this->layout === 'default' || $this->layout === 'ajax') {
-			$this->layout = false;
-		}
-		if ($this->subDir === null) {
-			$this->subDir = 'ajax';
-		}
-
-		if (isset($controller->response) && $controller->response instanceof CakeResponse) {
-			$controller->response->type('json');
-		}
-	}
-
-	/**
-	 * Renders an AJAX view.
-	 * The rendered content will be part of the JSON response object and
-	 * can be accessed via response.content in JavaScript.
-	 *
-	 * If an error has been set, the rendering will be skipped.
-	 *
-	 * @param string $view The view being rendered.
-	 * @param string $layout The layout being rendered.
-	 * @return string The rendered view.
-	 */
-	public function render($view = null, $layout = null) {
-		$response = [
-			'error' => null,
-			'content' => null,
-		];
-
-		if (!empty($this->viewVars['error'])) {
-			$view = false;
-		}
-
-		if ($view !== false && !isset($this->viewVars['_redirect']) && $this->_getViewFileName($view)) {
-			$response['content'] = parent::render($view, $layout);
-		}
-		if (isset($this->viewVars['_serialize'])) {
-			$response = $this->_serialize($response, $this->viewVars['_serialize']);
-		}
-		return json_encode($response);
-	}
-
-	/**
-	 * Serializes view vars.
-	 *
-	 * @param array $response Response data array.
-	 * @param array $serialize The viewVars that need to be serialized.
-	 * @return array The serialized data.
-	 */
-	protected function _serialize($response, $serialize) {
-		if (is_array($serialize)) {
-			foreach ($serialize as $alias => $key) {
-				if (is_numeric($alias)) {
-					$alias = $key;
-				}
-				if (array_key_exists($key, $this->viewVars)) {
-					$response[$alias] = $this->viewVars[$key];
-				}
-			}
-		} else {
-			$response[$serialize] = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
-		}
-		return $response;
-	}
-
-}

+ 4 - 4
View/Helper/CommonHelper.php

@@ -176,7 +176,7 @@ class CommonHelper extends AppHelper {
 	 * unexpected results.
 	 * TODO: move to booststrap/lib!!!
 	 *
-	 * @param string strings to alternate between
+	 * @param string $string Strings to alternate between
 	 * @return string
 	 */
 	public static function alternate() {
@@ -580,6 +580,7 @@ jQuery(document).ready(function() {
 	 * uses Piwik open source statistics framework
 	 *
 	 * @return string
+	 * @deprecated Use element instead
 	 */
 
 	public function visitStats($viewPath = null) {
@@ -619,6 +620,7 @@ piwikTracker.enableLinkTracking();
 	 * Non js browsers
 	 *
 	 * @return string
+	 * @deprecated Use element instead
 	 */
 	public function visitStatsImg($trackingUrl = null) {
 		if (empty($trackingUrl)) {
@@ -630,12 +632,10 @@ piwikTracker.enableLinkTracking();
 		return '<img src="' . Router::url('/', true) . $trackingUrl . '/piwik.php?idsite=1" style="border:0" alt=""/>';
 	}
 
-/*** deprecated ***/
-
 	/**
 	 * Checks if a role is in the current users session
 	 *
-	 * @param necessary right(s) as array - or a single one as string possible
+	 * @param array|null $roles Necessary right(s) as array - or a single one as string possible
 	 * @return array
 	 * @deprecated - use Auth class instead
 	 */

+ 0 - 385
View/RssView.php

@@ -1,385 +0,0 @@
-<?php
-/**
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice.
- *
- * @author Mark Scherer
- * @license http://opensource.org/licenses/mit-license.php MIT
- * @link http://www.dereuromark.de/2013/10/03/rss-feeds-in-cakephp
- */
-
-App::uses('View', 'View');
-App::uses('Xml', 'Utility');
-App::uses('CakeTime', 'Utility');
-App::uses('Routing', 'Router');
-App::uses('Hash', 'Utility');
-
-/**
- * A view class that is used for creating RSS feeds.
- *
- * By setting the '_serialize' key in your controller, you can specify a view variable
- * that should be serialized to XML and used as the response for the request.
- * This allows you to omit views + layouts, if your just need to emit a single view
- * variable as the XML response.
- *
- * In your controller, you could do the following:
- *
- * `$this->set(array('posts' => $posts, '_serialize' => 'posts'));`
- *
- * When the view is rendered, the `$posts` view variable will be serialized
- * into the RSS XML.
- *
- * **Note** The view variable you specify must be compatible with Xml::fromArray().
- *
- * If you don't use the `_serialize` key, you will need a view. You can use extended
- * views to provide layout like functionality. This is currently not yet tested/supported.
- *
- * @license MIT
- * @author Mark Scherer
- * @deprecated Use https://github.com/dereuromark/cakephp-feed/tree/2.x
- */
-class RssView extends View {
-
-	/**
-	 * Default spec version of generated RSS.
-	 *
-	 * @var string
-	 */
-	public $version = '2.0';
-
-	/**
-	 * The subdirectory. RSS views are always in rss. Currently not in use.
-	 *
-	 * @var string
-	 */
-	public $subDir = 'rss';
-
-	/**
-	 * Holds usable namespaces.
-	 *
-	 * @var array
-	 * @link http://validator.w3.org/feed/docs/howto/declare_namespaces.html
-	 */
-	protected $_namespaces = [
-		'atom' => 'http://www.w3.org/2005/Atom',
-		'content' => 'http://purl.org/rss/1.0/modules/content/',
-		'dc' => 'http://purl.org/dc/elements/1.1/',
-		'sy' => 'http://purl.org/rss/1.0/modules/syndication/'
-	];
-
-	/**
-	 * Holds the namespace keys in use.
-	 *
-	 * @var array
-	 */
-	protected $_usedNamespaces = [];
-
-	/**
-	 * Holds CDATA placeholders.
-	 *
-	 * @var array
-	 */
-	protected $_cdata = [];
-
-	/**
-	 * Constructor
-	 *
-	 * @param Controller $controller
-	 */
-	public function __construct(Controller $controller = null) {
-		parent::__construct($controller);
-
-		if (isset($controller->response) && $controller->response instanceof CakeResponse) {
-			$controller->response->type('rss');
-		}
-	}
-
-	/**
-	 * If you are using namespaces that are not yet known to the class, you need to globablly
-	 * add them with this method. Namespaces will only be added for actually used prefixes.
-	 *
-	 * @param string $prefix
-	 * @param string $url
-	 * @return void
-	 */
-	public function setNamespace($prefix, $url) {
-		$this->_namespaces[$prefix] = $url;
-	}
-
-	/**
-	 * Prepares the channel and sets default values.
-	 *
-	 * @param array $channel
-	 * @return array Channel
-	 */
-	public function channel($channel) {
-		if (!isset($channel['link'])) {
-			$channel['link'] = '/';
-		}
-		if (!isset($channel['title'])) {
-			$channel['title'] = '';
-		}
-		if (!isset($channel['description'])) {
-			$channel['description'] = '';
-		}
-
-		$channel = $this->_prepareOutput($channel);
-		return $channel;
-	}
-
-	/**
-	 * Converts a time in any format to an RSS time
-	 *
-	 * @param int|string|DateTime $time
-	 * @return string An RSS-formatted timestamp
-	 * @see CakeTime::toRSS
-	 */
-	public function time($time) {
-		return CakeTime::toRSS($time);
-	}
-
-	/**
-	 * Skip loading helpers if this is a _serialize based view.
-	 *
-	 * @return void
-	 */
-	public function loadHelpers() {
-		if (isset($this->viewVars['_serialize'])) {
-			return;
-		}
-		parent::loadHelpers();
-	}
-
-	/**
-	 * Render a RSS view.
-	 *
-	 * Uses the special '_serialize' parameter to convert a set of
-	 * view variables into a XML response. Makes generating simple
-	 * XML responses very easy. You can omit the '_serialize' parameter,
-	 * and use a normal view + layout as well.
-	 *
-	 * @param string $view The view being rendered.
-	 * @param string $layout The layout being rendered.
-	 * @return string The rendered view.
-	 */
-	public function render($view = null, $layout = null) {
-		if (isset($this->viewVars['_serialize'])) {
-			return $this->_serialize($this->viewVars['_serialize']);
-		}
-		if ($view !== false && $this->_getViewFileName($view)) {
-			return parent::render($view, false);
-		}
-	}
-
-	/**
-	 * Serialize view vars.
-	 *
-	 * @param string|array $serialize The viewVars that need to be serialized.
-	 * @return string The serialized data
-	 * @throws RuntimeException When the prefix is not specified
-	 */
-	protected function _serialize($serialize) {
-		$rootNode = isset($this->viewVars['_rootNode']) ? $this->viewVars['_rootNode'] : 'channel';
-
-		if (is_array($serialize)) {
-			$data = [$rootNode => []];
-			foreach ($serialize as $alias => $key) {
-				if (is_numeric($alias)) {
-					$alias = $key;
-				}
-				$data[$rootNode][$alias] = $this->viewVars[$key];
-			}
-		} else {
-			$data = isset($this->viewVars[$serialize]) ? $this->viewVars[$serialize] : null;
-			if (is_array($data) && Hash::numeric(array_keys($data))) {
-				$data = [$rootNode => [$serialize => $data]];
-			}
-		}
-
-		$defaults = ['document' => [], 'channel' => [], 'items' => []];
-		$data += $defaults;
-		if (!empty($data['document']['namespace'])) {
-			foreach ($data['document']['namespace'] as $prefix => $url) {
-				$this->setNamespace($prefix, $url);
-			}
-		}
-
-		$channel = $this->channel($data['channel']);
-		if (!empty($channel['image']) && empty($channel['image']['title'])) {
-			$channel['image']['title'] = $channel['title'];
-		}
-
-		foreach ($data['items'] as $item) {
-			$channel['item'][] = $this->_prepareOutput($item);
-		}
-
-		$array = [
-			'rss' => [
-				'@version' => $this->version,
-				'channel' => $channel,
-			]
-		];
-		$namespaces = [];
-		foreach ($this->_usedNamespaces as $usedNamespacePrefix) {
-			if (!isset($this->_namespaces[$usedNamespacePrefix])) {
-				throw new RuntimeException(sprintf('The prefix %s is not specified.', $usedNamespacePrefix));
-			}
-			$namespaces['xmlns:' . $usedNamespacePrefix] = $this->_namespaces[$usedNamespacePrefix];
-		}
-		$array['rss'] += $namespaces;
-
-		$options = [];
-		if (Configure::read('debug')) {
-			$options['pretty'] = true;
-		}
-
-		$output = Xml::fromArray($array, $options)->asXML();
-		$output = $this->_replaceCdata($output);
-
-		return $output;
-	}
-
-	/**
-	 * RssView::_prepareOutput()
-	 *
-	 * @param array $item
-	 * @return array
-	 */
-	protected function _prepareOutput($item) {
-		foreach ($item as $key => $val) {
-			$prefix = null;
-			// The cast prevents a PHP bug for switch case and false positives with integers
-			$bareKey = (string)$key;
-
-			// Detect namespaces
-			if (strpos($key, ':') !== false) {
-				list($prefix, $bareKey) = explode(':', $key, 2);
-				if (strpos($prefix, '@') !== false) {
-					$prefix = substr($prefix, 1);
-				}
-				if (!in_array($prefix, $this->_usedNamespaces)) {
-					$this->_usedNamespaces[] = $prefix;
-				}
-			}
-
-			$attrib = null;
-			switch ($bareKey) {
-				case 'encoded':
-					$val = $this->_newCdata($val);
-					break;
-
-				case 'pubDate':
-					$val = $this->time($val);
-					break;
-
-				case 'category':
-					if (is_array($val) && isset($val['domain'])) {
-						$attrib['@domain'] = $val['domain'];
-						$attrib['@'] = isset($val['content']) ? $val['content'] : $attrib['@domain'];
-						$val = $attrib;
-					} elseif (is_array($val) && !empty($val[0])) {
-						$categories = [];
-						foreach ($val as $category) {
-							$attrib = [];
-							if (is_array($category) && isset($category['domain'])) {
-								$attrib['@domain'] = $category['domain'];
-								$attrib['@'] = isset($val['content']) ? $val['content'] : $attrib['@domain'];
-								$category = $attrib;
-							}
-							$categories[] = $category;
-						}
-						$val = $categories;
-					}
-					break;
-
-				case 'link':
-				case 'url':
-				case 'guid':
-				case 'comments':
-					if (is_array($val) && isset($val['@href'])) {
-						$attrib = $val;
-						$attrib['@href'] = Router::url($val['@href'], true);
-						if ($prefix === 'atom') {
-							$attrib['@rel'] = 'self';
-							$attrib['@type'] = 'application/rss+xml';
-						}
-						$val = $attrib;
-					} elseif (is_array($val) && isset($val['url'])) {
-						$val['url'] = Router::url($val['url'], true);
-						if ($bareKey === 'guid') {
-							$val['@'] = $val['url'];
-							unset($val['url']);
-						}
-					} else {
-						$val = Router::url($val, true);
-					}
-					break;
-
-				case 'source':
-					if (is_array($val) && isset($val['url'])) {
-						$attrib['@url'] = Router::url($val['url'], true);
-						$attrib['@'] = isset($val['content']) ? $val['content'] : $attrib['@url'];
-					} elseif (!is_array($val)) {
-						$attrib['@url'] = Router::url($val, true);
-						$attrib['@'] = $attrib['@url'];
-					}
-					$val = $attrib;
-					break;
-
-				case 'enclosure':
-					if (isset($val['url']) && is_string($val['url']) && is_file(WWW_ROOT . $val['url']) && file_exists(WWW_ROOT . $val['url'])) {
-						if (!isset($val['length']) && strpos($val['url'], '://') === false) {
-							$val['length'] = sprintf("%u", filesize(WWW_ROOT . $val['url']));
-						}
-						if (!isset($val['type']) && function_exists('mime_content_type')) {
-							$val['type'] = mime_content_type(WWW_ROOT . $val['url']);
-						}
-					}
-					$attrib['@url'] = Router::url($val['url'], true);
-					$attrib['@length'] = $val['length'];
-					$attrib['@type'] = $val['type'];
-					$val = $attrib;
-					break;
-
-				default:
-					//nothing
-			}
-
-			if (is_array($val)) {
-				$val = $this->_prepareOutput($val);
-			}
-
-			$item[$key] = $val;
-		}
-
-		return $item;
-	}
-
-	/**
-	 * RssView::_newCdata()
-	 *
-	 * @param string $content
-	 * @return string
-	 */
-	protected function _newCdata($content) {
-		$i = count($this->_cdata);
-		$this->_cdata[$i] = $content;
-		return '###CDATA-' . $i . '###';
-	}
-
-	/**
-	 * RssView::_replaceCdata()
-	 *
-	 * @param string $content
-	 * @return string
-	 */
-	protected function _replaceCdata($content) {
-		foreach ($this->_cdata as $n => $data) {
-			$data = '<![CDATA[' . $data . ']]>';
-			$content = str_replace('###CDATA-' . $n . '###', $data, $content);
-		}
-		return $content;
-	}
-
-}