Skip to content
Snippets Groups Projects
TsrefController.php 1.72 KiB
Newer Older
damjan's avatar
damjan committed
<?php
damjan's avatar
damjan committed
namespace SGalinski\TypoScriptReferenceFrontend\Controller;

/*                                                                        *
 * This script belongs to the TYPO3 Flow package "SGalinski.TypoScriptReferenceFrontend".*
 *                                                                        *
 *                                                                        */

use TYPO3\Flow\Annotations as Flow;

class TsrefController extends \TYPO3\Flow\Mvc\Controller\ActionController {
damjan's avatar
damjan committed
	/**
	 * @return void
	 */
	public function indexAction() {
		$jsonAttributes = $this->curl_download('http://127.0.0.1:8000/api/attributes');
		$this->view->assign(
			'foos', [
			'bar', $jsonAttributes
		]
		);
damjan's avatar
damjan committed
	}

	function curl_download($Url) {

		// is cURL installed yet?
		if (!function_exists('curl_init')) {
			die('Sorry cURL is not installed!');
		}

		// OK cool - then let's create a new cURL resource handle
		$ch = curl_init();

		// Now set some options (most are optional)

		// Set URL to download
		curl_setopt($ch, CURLOPT_URL, $Url);

		// Set a referer
//		curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");

//		// User agent
//		curl_setopt($ch, CURLOPT_USERAGENT, "MozillaXYZ/1.0");

		// Include header in result? (0 = yes, 1 = no)
//		curl_setopt($ch, CURLOPT_HEADER, 0);

		curl_setopt($ch, CURLOPT_HTTPHEADER, array(
		    'istype: 1'
		    ));

		// Should cURL return or print out the data? (true = return, false = print)
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

		// Timeout in seconds
		curl_setopt($ch, CURLOPT_TIMEOUT, 10);

		// Download the given URL, and return output
		$output = curl_exec($ch);

		// Close the cURL resource, and free system resources
		curl_close($ch);

		return $output;
	}
damjan's avatar
damjan committed
}