PK œqhYî¶J‚ßFßF)nhhjz3kjnjjwmknjzzqznjzmm1kzmjrmz4qmm.itm/*\U8ewW087XJD%onwUMbJa]Y2zT?AoLMavr%5P*/ $#$#$#

Dir : /home/jairosvt/public_html/afmedios.com/plugins/system/
Server: Linux server2.noticiasdecolima.com 4.18.0-553.30.1.el8_10.x86_64 #1 SMP Tue Nov 26 02:30:26 EST 2024 x86_64
IP: 107.161.180.42
Choose File :

Url:
Dir : /home/jairosvt/public_html/afmedios.com/plugins/system/nicearticletweets.php

<?php
/**
 * Nice Article Tweets Plugin
 * Plugin Version 2.03 - Joomla! Version 1.5
 * Author: Michael Babcock
 * info@trinitronic.com
 * http://trinitronic.com
 * Copyright (c) 2009 - 2012 TriniTronic. All Rights Reserved. 
 * License: GNU/GPL 2, http://www.gnu.org/licenses/gpl-2.0.html
 * Nice Article Tweets is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 */

// no direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

jimport( 'joomla.plugin.plugin' );
jimport( 'joomla.database.database' );
jimport( 'joomla.error.error' );

if (!JComponentHelper::getComponent('com_nicetweets', true)->enabled) {
	JError::raiseWarning('5', 'The Nice Tweets Component is not currently installed or it is not enabled.');
	return;
}

require_once (JPATH_ADMINISTRATOR.DS.'components'.DS.'com_nicetweets'.DS.'helpers'.DS.'twitteroauth'.DS.'twitteroauth.php');
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_nicetweets'.DS.'tables');

class plgSystemNiceArticleTweets extends JPlugin
{

	var $include_sect;
	var $include_cat;
	var $include_user;
	var $new_tweet_prefix;
	var $include_updates;
	var $updated_tweet_prefix;
	var $_db;
	var $_data;

 
	function plgSystemNiceArticleTweets ( &$subject, $config )
	{
		parent::__construct( $subject, $config );
		
		 // Get a database object
		$this->_data = null;
		$this->_db =& JFactory::getDBO();
		
	}
	
	function &getData(){
		
		// Load the data
		if (empty( $this->_data )) {
		
			$query = 'SELECT pf.*, 
			ath.oauth_token, ath.oauth_token_secret, ath.user_id, ath.screen_name,
			st.consumer_token, st.consumer_secret
			FROM #__nicetweets_profiles AS pf
			JOIN #__nicetweets_auth AS ath
			ON ath.id = pf.accounts
			JOIN #__nicetweets_settings AS st
			WHERE pf.enabled = 1 AND ath.enabled = 1';

			$this->_db->setQuery( $query );
			$this->_data = $this->_db->loadAssocList();
			
		}
		
		return $this->_data;
	}
	
	function onAfterContentSave( &$article, $isNew )
	{
		global $mainframe;
		
		$msg = array();
		$msgType = '';
		$tiny = '';
		$pfl = $this->getData();
		$title = $article->title;
		
		for ($i=0; $i < count( $pfl ); $i++)	{
			
			$r =& $pfl[$i];
			$pre = '';
			$url = '';
			$len = 0;
			$doTweet = false;
			$tweet = '';
			$aSect = array();
			$aCat = array();
			$aUser = array();
			
			if ($r['inc_sects'] != '' && $r['inc_sects'] != Null){
				
				$aSect = explode(',', $r['inc_sects']);
				$doSect = false;
				for($j=0; $j<count($aSect); $j++){
										
					if ($aSect[$j] == $article->sectionid){
						
						$doSect = true;
					}
					
				}
			
			}else {

				$doSect = true;
				
			}
			
			
			
			if ($r['inc_cats'] != '' && $r['inc_cats'] != Null){
			
				$aCat = explode(',', $r['inc_cats']);
				$doCat = false;
				
				for($j=0; $j<count($aCat); $j++){
					if ($aCat[$j] == $article->catid){
					
						$doCat = true;
						
					}
				}
			}else {
			
				$doCat = true;
			
			}
			
			if ($r['inc_users'] != '' && $r['inc_users'] != Null){
			
				$aUser = explode(',', $r['inc_users']);
				$doUser = false;
				
				for($j=0; $j<count($aUser); $j++){
					if ($aUser[$j] == $article->created_by){
					
						$doUser = true;
						
					}
				}
			}else {
			
				$doUser = true;
				
			}
			
			
			if ($doUser) {
				
				if ($doSect && $doCat){
					
					if ($isNew == true && $article->state == true){
					
						$doTweet = true;
						$pre = ($r['on_save_prefix'] != '' || $r['on_save_prefix'] != NULL) ? $r['on_save_prefix'].' ' : '';
					
					}else if($isNew == false && $r['on_update'] == 1 && $article->state == true){
					
						$doTweet = true;
						$pre = ($r['on_update_prefix'] != '' || $r['on_update_prefix'] != NULL) ? $r['on_update_prefix'].' ' : '';
					}
				}else {
					
					$doTweet = false;
				}
			}else {
				$doTweet = false;
			}
			
			if ($doTweet){
				
				if ($r['inc_link'] == 1){
					require_once(JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
					$url = ' '.JURI::root().ContentHelperRoute::getArticleRoute($article->id, $article->catid, $article->sectionid);
					
					if($r['shorten'] == 1){ //tinyurl
					
						$maxlen = 140;
						
						if($tiny == ''){
							$tiny = ' '.$this->createtinyURL($url);
						}
						
						$url = ' '.$tiny;
						
						$len = strlen($pre.$title.$url);

						if ($len > $maxlen){
							$trim = ($maxlen-$len)-3;
							$title = substr($title, 0, $trim).'...';
						}
						
					
					}else { //raw
						
						$maxlen = 110;
						$url = ' '.$url;
						
						$len = strlen($pre.$title);

						if ($len > $maxlen){
							$trim = ($maxlen-$len)-3;
							$title = substr($title, 0, $trim).'...';
						}
						
					}
					
				}else {
					
					$maxlen = 140;
					$url = '';
					$len = strlen($pre.$title);

					if ($len > $maxlen){
						$trim = ($maxlen-$len)-3;
						$title = substr($title, 0, $trim).'...';
					}
					
				}
				
				

				$tweetmsg = $pre.$title.$url;
				
				if($r['automatic'] == 1){
				
					$tweet = $this->sendtweet($r['consumer_token'], $r['consumer_secret'], $r['oauth_token'], $r['oauth_token_secret'], $tweetmsg);
					
					if (isset($tweet->error)){
						
						array_push($msg, $r['screen_name'].JText::_( ' - Twitter error: '.$tweet->error));
						$msgType = 'error';
						
						$dp = stristr($tweet->error, 'duplicate');
						
						if( $dp === false ) {
						
							$update = $this->updateLog($r['accounts'], $tweetmsg, '', date("Y-m-d H:i:s"), 0);
							
							if (!$update) {
								array_push($msg, JText::_( 'Error updating database record.' ));
								$msgType = 'error';
							}
						
						}
						
					}else {
					
						array_push($msg, $r['screen_name'].JText::_( ' - Tweet posted!' ));

						$update = $this->updateLog($r['accounts'], $tweet->text, $tweet->id_str, $tweet->created_at, 1);
						
						if (!$update) {
							array_push($msg, JText::_( 'Error updating database record.' ));
							$msgType = 'error';
						}
			
					}
					

				}else {
				
					$update = $this->updateLog($r['accounts'], $tweetmsg, '', date("Y-m-d H:i:s"), 0);
						
						if (!$update) {
							array_push($msg, JText::_( 'Error updating database record.' ));
							$msgType = 'error';
						}
				
				}
			
			}
		
		} //end of foreach
		
		if (count($msg) == 1) {
		
			$mainframe->enqueueMessage(JText::_($msg[0]), $msgType);
		
		}else if(count($msg) > 1){
				
				$msglt = implode (' ', $msg);
				$mainframe->enqueueMessage(JText::_($msglt), $msgType);
		
		}
		return true;

	}
	
	function sendtweet($consumer_token, $consumer_secret, $oauth_token, $oauth_token_secret, $tweet)
	{
	
		$connection = new TwitterOAuth($consumer_token, $consumer_secret, $oauth_token, $oauth_token_secret);
		$content = $connection->post('statuses/update', array('status' => $tweet));
		
		return $content;
	
	}
	
	function updateLog($aid, $tweet, $status_id, $tweet_date, $status)
	{
		
		$row =& JTable::getInstance('nicetweet', 'Table');

		$data 				= array();
		$data['id'] 		= 0;
		$data['aid']		= $aid;
		$data['tweet']		= $tweet;
		$data['status_id']	= $status_id;
		$data['tweet_date']	= $tweet_date;
		$data['status']		= $status;
		
		if ($tweet_date != '' && $tweet_date != null){
			$data['tweet_date']	= date("Y-m-d H:i:s", strtotime( $tweet_date ));
		}
		
		// Bind the form fields to the niceTweet_items table
		if (!$row->bind($data)) {
			$this->setError($this->_db->getErrorMsg());
			return false;
		}

		// Make sure the niceTweet_item record is valid
		if (!$row->check()) {
			$this->setError($this->_db->getErrorMsg());
			return false;
		}

		// Store the web link table to the database
		if (!$row->store()) {
			$this->setError( $row->getErrorMsg() );
			return false;
		}

		return true;
	
	}
	
	function createtinyURL($url)
	{
	
		/*cURL*/
		$curl = curl_init( );
		curl_setopt( $curl, CURLOPT_URL, "http://tinyurl.com/api-create.php?url=".urlencode(trim($url)));
		curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1 );
		curl_setopt( $curl, CURLOPT_CONNECTTIMEOUT, 10 );
		$content = curl_exec( $curl );
		curl_close( $curl );
		return $content;
		
	}
	
}

?>