<commit_before><?php namespace Thujohn\Twitter;

use Config;

class Twitter extends tmhOAuth {
	public function __construct($config = array()){
		$default = array();

		$default['consumer_key'] = Config::get('twitter::CONSUMER_KEY');
		$default['consumer_secret'] = Config::get('twitter::CONSUMER_SECRET');
		$default['token'] = Config::get('twitter::ACCESS_TOKEN');
		$default['secret'] = Config::get('twitter::ACCESS_TOKEN_SECRET');

		$default['use_ssl'] = Config::get('twitter::USE_SSL');
		$default['user_agent'] = 'TW-L4 '.parent::VERSION;
		
		$config = array_merge($default, $config);

		parent::__construct($config);
	}

	public function query($name, $requestMethod = 'GET', $parameters = array(), $multipart = false){
		parent::user_request(array(
			'method' => $requestMethod,
			'url' => parent::url(Config::get('twitter::API_VERSION').'/'.$name),
			'params' => $parameters,
			'multipart' => $multipart
		));

		$response = $this->response;

		$format = 'object';
		if (isset($parameters['format'])){
			$format = $parameters['format'];
		}

		switch ($format){
			default :
			case 'object' : $response = json_decode($response['response']);
			break;
			case 'json' : $response = $response['response'];
			break;
			case 'array' : $response = json_decode($response['response'], true);
			break;
		}

		return $response;
	}

	public function linkify($tweet) {
		// URL
		$tweet = " ".preg_replace("/(([[:alnum:]]+:\/\/)|www\.)([^[:space:]]*)([[:alnum:]#?\/&=])/i", "<a href=\"\\1\\3\\4\" target=\"_blank\">\\1\\3\\4</a>", $tweet);

		// Mailto
		$tweet = preg_replace("/(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))/i", "<a href=\"mailto:\\1\">\\1</a>", $tweet);

		// User
		$tweet = preg_replace("/ +@([a-z0-9_]*)?/i", " <a href=\"https://twitter.com/\\1\" target=\"_blank\">@\\1</a>", $tweet);

		// Hashtag
		$tweet = preg_replace("/ +#([a-z0-9_]*)?/i", " <a href=\"https://twitter.com/search?q=%23\\1\" target=\"_blank\">#\\1</a>", $tweet);

		// Long URL
		$tweet = preg_replace("/>(([[:alnum:]]+:\/\/)|www\.)([^[:space:]]{10,20})([^[:space:]]*)([^[:space:]]{10,20})([[:alnum:]#?\/&=])</", ">\\3...\\5\\6<", $tweet);

		return trim($tweet);
	}

	/**
	 * Parameters :
	 * - count (1-200)
	 * - include_rts (0|1)
	 * - since_id
	 * - max_id
	 * - trim_user (0|1)
	 * - contributor_details (0|1)
	 * - include_entities (0|1)
	 */
	public function getMentionsTimeline($parameters = array()){
		$response = $this->query('statuses/mentions_timeline', 'GET', $parameters);
<commit_msg>Add time ago function : ago($timestamp)<commit_after><?php namespace Thujohn\Twitter;

use Config;
use Carbon\Carbon as Carbon;

class Twitter extends tmhOAuth {
	public function __construct($config = array()){
		$default = array();

		$default['consumer_key'] = Config::get('twitter::CONSUMER_KEY');
		$default['consumer_secret'] = Config::get('twitter::CONSUMER_SECRET');
		$default['token'] = Config::get('twitter::ACCESS_TOKEN');
		$default['secret'] = Config::get('twitter::ACCESS_TOKEN_SECRET');

		$default['use_ssl'] = Config::get('twitter::USE_SSL');
		$default['user_agent'] = 'TW-L4 '.parent::VERSION;
		
		$config = array_merge($default, $config);

		parent::__construct($config);
	}

	public function query($name, $requestMethod = 'GET', $parameters = array(), $multipart = false){
		parent::user_request(array(
			'method' => $requestMethod,
			'url' => parent::url(Config::get('twitter::API_VERSION').'/'.$name),
			'params' => $parameters,
			'multipart' => $multipart
		));

		$response = $this->response;

		$format = 'object';
		if (isset($parameters['format'])){
			$format = $parameters['format'];
		}

		switch ($format){
			default :
			case 'object' : $response = json_decode($response['response']);
			break;
			case 'json' : $response = $response['response'];
			break;
			case 'array' : $response = json_decode($response['response'], true);
			break;
		}

		return $response;
	}

	public function linkify($tweet) {
		// URL
		$tweet = " ".preg_replace("/(([[:alnum:]]+:\/\/)|www\.)([^[:space:]]*)([[:alnum:]#?\/&=])/i", "<a href=\"\\1\\3\\4\" target=\"_blank\">\\1\\3\\4</a>", $tweet);

		// Mailto
		$tweet = preg_replace("/(([a-z0-9_]|\\-|\\.)+@([^[:space:]]*)([[:alnum:]-]))/i", "<a href=\"mailto:\\1\">\\1</a>", $tweet);

		// User
		$tweet = preg_replace("/ +@([a-z0-9_]*)?/i", " <a href=\"https://twitter.com/\\1\" target=\"_blank\">@\\1</a>", $tweet);

		// Hashtag
		$tweet = preg_replace("/ +#([a-z0-9_]*)?/i", " <a href=\"https://twitter.com/search?q=%23\\1\" target=\"_blank\">#\\1</a>", $tweet);

		// Long URL
		$tweet = preg_replace("/>(([[:alnum:]]+:\/\/)|www\.)([^[:space:]]{10,20})([^[:space:]]*)([^[:space:]]{10,20})([[:alnum:]#?\/&=])</", ">\\3...\\5\\6<", $tweet);

		return trim($tweet);
	}

	public function ago($timestamp){
		if (is_numeric($timestamp) && (int)$timestamp == $timestamp){
			$carbon = Carbon::createFromTimeStamp($timestamp);
		}else{
			$dt = new \DateTime($timestamp);
			$carbon = Carbon::instance($dt);
		}

		return $carbon->diffForHumans();
	}

	/**
	 * Parameters :
	 * - count (1-200)
	 * - include_rts (0|1)
	 * - since_id
	 * - max_id
	 * - trim_user (0|1)
	 * - contributor_details (0|1)
	 * - include_entities (0|1)
	 */
	public function getMentionsTimeline($parameters = array()){
		$response = $this->query('statuses/mentions_timeline', 'GET', $parameters);

{'fraction_non_alphanumeric': 0.27039670658682635, 'fraction_numerical': 0.016467065868263474, 'mean_word_length': 4.281620553359684, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 36, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, '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': '4489286', 'n_tokens_mistral': 2168, 'n_tokens_neox': 1964, 'n_words': 305}