<commit_before><?php
// vim: set ts=4 sw=4 sts=4 si noet:

// A widget helper that retrieves data and renders the element.
// Ideas taken from:
//   http://jamienay.com/2009/11/an-easy-plugin-callback-component-for-cakephp-1-2/
//   http://debuggable.com/posts/requestaction-considered-harmful:48abb514-1f9c-4443-b91c-6d0f4834cda3
class WidgetHelper extends AppHelper {

	/** Similar to View::element with extra component name to load */
	function element($componentName, $elementName, $params = array(), $loadHelpers = false) {

		$componentName = Inflector::classify($componentName . '_widget');
		$componentClassName = $componentName . 'Component';

		// import the component, and call component's method
		if (App::import('Component', $componentName)) {
			$component = ClassRegistry::init($componentClassName, 'component');
			$url = Router::parse($elementName);
			$methodName = $url['action'];
			if (method_exists($component, $methodName)) {
				$data = $component->{$methodName}();
				$params += array('widget_data' => $data);
			}
		}

		$view = ClassRegistry::getObject('view');
		return $view->element($elementName, $params, $loadHelpers);
	}
}

?>
<commit_msg>use split() instead of Router::parse()<commit_after><?php
// vim: set ts=4 sw=4 sts=4 si noet:

// A widget helper that retrieves data and renders the element.
// Ideas taken from:
//   http://jamienay.com/2009/11/an-easy-plugin-callback-component-for-cakephp-1-2/
//   http://debuggable.com/posts/requestaction-considered-harmful:48abb514-1f9c-4443-b91c-6d0f4834cda3
class WidgetHelper extends AppHelper {

	/** Similar to View::element with extra component name to load */
	function element($componentName, $elementName, $params = array(), $loadHelpers = false) {

		$componentName = Inflector::classify($componentName . '_widget');
		$componentClassName = $componentName . 'Component';

		// import the component, and call component's method
		if (App::import('Component', $componentName)) {
			$component = ClassRegistry::init($componentClassName, 'component');
			$splitElementName = split('/', $elementName);
			$methodName = $splitElementName[1];
			if (method_exists($component, $methodName)) {
				$data = $component->{$methodName}();
				$params += array('widget_data' => $data);
			}
		}

		$view = ClassRegistry::getObject('view');
		return $view->element($elementName, $params, $loadHelpers);
	}
}

?>

{'fraction_non_alphanumeric': 0.16073670992046882, 'fraction_numerical': 0.026370866471326915, 'mean_word_length': 4.7314148681055155, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1041422', 'n_tokens_mistral': 835, 'n_tokens_neox': 750, 'n_words': 165}