Beispiel #1
0
 /**
  * Run the job
  *
  */
 protected function __construct()
 {
     JLoader::register('PostHelper', JPATH_AUTOTWEET_HELPERS . '/post.php');
     // Cronjob params
     $this->cron_enabled = EParameter::getComponentParam(CAUTOTWEETNG, 'cron_enabled', false);
     $this->max_posts = EParameter::getComponentParam(CAUTOTWEETNG, 'max_posts', 1);
     // Wrapper for mbstrings
     // include_once dirname(__FILE__) . '/mbstringwrapper/mbstringwrapper.php';
 }
Beispiel #2
0
 /**
  * getInstance
  *
  * @return	object
  */
 public static function &getInstance()
 {
     if (!self::$_instance) {
         $log_level = EParameter::getComponentParam(CAUTOTWEETNG, 'log_level', JLog::ERROR);
         $log_mode = EParameter::getComponentParam(CAUTOTWEETNG, 'log_mode', ELog::LOG_MODE_SCREEN);
         self::$_instance = new ELog($log_level, $log_mode);
     }
     return self::$_instance;
 }
 /**
  * FeedHelper
  *
  */
 public function __construct()
 {
     include_once 'feedcontent.php';
     include_once 'feeddupchecker.php';
     include_once 'feedimage.php';
     include_once 'feedtext.php';
     self::$_params = null;
     $this->_shorturl_always = EParameter::getComponentParam(CAUTOTWEETNG, 'shorturl_always', 1);
     $this->_logger = AutotweetLogger::getInstance();
 }
Beispiel #4
0
 /**
  * Runs before rendering the view template, echoing HTML to put before the
  * view template's generated HTML
  *
  * @return void
  */
 protected function preRender()
 {
     parent::preRender();
     if (!AUTOTWEETNG_FREE) {
         $cron_enabled = EParameter::getComponentParam(CAUTOTWEETNG, 'cron_enabled');
         if (!$cron_enabled && F0FModel::getTmpInstance('Channels', 'AutoTweetModel')->getTotal() > self::CHANNELS_PAGE_LOAD_LIMIT) {
             echo JText::_('COM_AUTOTWEET_LBL_CHANNELS_TOOMANY_NOTCRON');
         }
     }
 }
Beispiel #5
0
 /**
  * Checks the record for validity
  *
  * @return  int  True if the record is valid
  */
 public function check()
 {
     if (empty($this->image_url)) {
         // Default image: used in media mode when no image is available
         $this->image_url = EParameter::getComponentParam(CAUTOTWEETNG, 'default_image', '');
     }
     if (!empty($this->image_url)) {
         $routeHelp = RouteHelp::getInstance();
         $this->image_url = $routeHelp->getAbsoluteUrl($this->image_url, true);
     }
     return true;
 }
 /**
  * sendMessage.
  *
  * @param   string  $message  Params
  * @param   object  $data     Params
  *
  * @return	boolean
  */
 public function sendMessage($message, $data)
 {
     $title = $data->title;
     $text = $data->fulltext;
     $url = $data->url;
     $org_url = $data->org_url;
     $image_url = $data->image_url;
     $media_mode = $this->getMediaMode();
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, 'sendFacebookMessage', $message);
     if (empty($image_url)) {
         return array(true, 'No photo.');
     }
     $fb_id = $this->getFbChannelId();
     $fbalbum_id = $this->get('fbalbum_id');
     $fb_token = $this->get('fbchannel_access_token');
     $result = null;
     $status_type = array('value' => 'added_photos');
     // Photo object: /user/photos
     $arguments = array('message' => $message, 'url' => $image_url, 'access_token' => $fb_token, 'type' => 'photo', 'created_time' => JFactory::getDate()->toISO8601(), 'status_type' => json_encode($status_type));
     $isUserProfile = $this->isUserProfile();
     if ($isUserProfile) {
         $privacy = $this->get('sharedwith', 'EVERYONE');
         $privacy = array('value' => $privacy);
         $arguments['privacy'] = json_encode($privacy);
     }
     $target_id = $data->xtform->get('target_id');
     if (EParameter::getComponentParam(CAUTOTWEETNG, 'targeting', false) && $target_id) {
         $this->addTargetArguments($arguments, $target_id);
     }
     try {
         $api = $this->getApiInstance();
         $api->setFileUploadSupport(true);
         // Simulated
         if ($this->channel->params->get('use_own_api') == 0) {
             $this->getApiInstance()->api("/me/permissions");
             $result = array(true, JText::_('COM_AUTOTWEET_VIEW_SIMULATED_OK'));
         } else {
             if ($fbalbum_id) {
                 $result = $this->getApiInstance()->api("/{$fbalbum_id}/photos", 'post', $arguments);
             } else {
                 $result = $this->getApiInstance()->api("/{$fb_id}/photos", 'post', $arguments);
             }
             $msg = 'Facebook id: ' . $result['id'];
             $result = array(true, $msg);
         }
     } catch (Exception $e) {
         $result = array(false, $e->getCode() . ' - ' . $e->getMessage());
     }
     return $result;
 }
Beispiel #7
0
 /**
  * ShorturlHelper. No public access (singleton pattern).
  *
  */
 protected function __construct()
 {
     JLoader::register('AutotweetShortservice', dirname(__FILE__) . '/urlshortservices/autotweetshortservice.php');
     JLoader::register('AutotweetURLShortserviceFactory', dirname(__FILE__) . '/urlshortservices/autotweeturlshortservicefactory.php');
     // General params for message and posting
     $this->resend_attempts = EParameter::getComponentParam(CAUTOTWEETNG, 'resend_attempts', 2);
     $this->shorturl_service = EParameter::getComponentParam(CAUTOTWEETNG, 'shorturl_service', 'Tinyurlcom');
     // Bit.ly, Goog.gl and yourls account data
     $this->bit_username = EParameter::getComponentParam(CAUTOTWEETNG, 'bit_username', null);
     $this->bit_key = EParameter::getComponentParam(CAUTOTWEETNG, 'bit_key', null);
     $this->google_api_key = EParameter::getComponentParam(CAUTOTWEETNG, 'google_api_key', null);
     $this->yourls_host = EParameter::getComponentParam(CAUTOTWEETNG, 'yourls_host', null);
     $this->yourls_token = EParameter::getComponentParam(CAUTOTWEETNG, 'yourls_token', null);
     // Init AutoTweet logging
     $this->logger = AutotweetLogger::getInstance();
 }
Beispiel #8
0
 /**
  * onAdd.
  *
  * @param   string  $tpl  Param
  *
  * @return	void
  */
 public function onAdd($tpl = null)
 {
     $jlang = JFactory::getLanguage();
     $jlang->load('com_content');
     Extly::loadAwesome();
     $file = EHtml::getRelativeFile('js', 'com_autotweet/feed.min.js');
     if ($file) {
         $dependencies = array();
         $paths = array();
         $ajax_import = EParameter::getComponentParam(CAUTOTWEETNG, 'ajax_import', true);
         $this->assignRef('ajax_import', $ajax_import);
         if ($ajax_import) {
             $paths['import'] = 'media/com_autotweet/js/import.min';
         }
         Extly::initApp(CAUTOTWEETNG_VERSION, $file, $dependencies, $paths);
     }
     return parent::onAdd($tpl);
 }
Beispiel #9
0
 /**
  * isValidImageFile
  *
  * @param   string  $imagefile  Param
  *
  * @return	bool
  */
 public function isValidImageFile($imagefile)
 {
     list($width, $height, $type, $attr) = getimagesize($imagefile);
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, "isValidImage ({$width}, {$height}, {$type}, {$attr})");
     if (!in_array($type, array(IMAGETYPE_GIF, IMAGETYPE_JPEG, IMAGETYPE_PNG))) {
         return false;
     }
     $image_minx = EParameter::getComponentParam(CAUTOTWEETNG, 'image_minx', 100);
     if ($width < $image_minx) {
         return false;
     }
     $image_miny = EParameter::getComponentParam(CAUTOTWEETNG, 'image_miny', 0);
     if ($height < $image_miny) {
         return false;
     }
     return true;
 }
Beispiel #10
0
 /**
  * publishPosts - This static function should used from backend only for manual (re)posting attempts
  *
  * @param   array  $posts   Param
  * @param   int    $userid  Param
  *
  * @return	boolean
  */
 public static function publishPosts($posts, $userid = null)
 {
     JLoader::register('SharingHelper', JPATH_AUTOTWEET_HELPERS . '/sharing.php');
     $cron_enabled = EParameter::getComponentParam(CAUTOTWEETNG, 'cron_enabled', 0);
     $success = false;
     $sharinghelper = SharingHelper::getInstance();
     $post = F0FModel::getTmpInstance('Posts', 'AutoTweetModel')->getTable();
     foreach ($posts as $pid) {
         $post->reset();
         $post->load($pid);
         $post->xtform = EForm::paramsToRegistry($post);
         if ($post->pubstate == AutotweetPostHelper::POST_APPROVE && $cron_enabled) {
             $success = self::savePost(AutotweetPostHelper::POST_CRONJOB, 'COM_AUTOTWEET_MSG_POSTRESULT_CRONJOB', $post, $userid);
         } else {
             $success = $sharinghelper->publishPost($post, $userid);
         }
     }
     return $success;
 }
 /**
  * Public constructor. Initialises the protected members as well.
  *
  * @param   array  $config  Param
  */
 public function __construct($config = array())
 {
     parent::__construct($config);
     $dlid = EParameter::getComponentParam(CAUTOTWEETNG, 'update_dlid', '');
     $this->extraQuery = '';
     // If I have a valid Download ID I will need to use a non-blank extra_query in Joomla! 3.2+
     if (preg_match('/^([0-9]{1,}:)?[0-9a-f]{32}$/i', $dlid)) {
         $this->extraQuery = 'dlid=' . $dlid;
     }
     $this->updateSiteName = VersionHelper::getFlavourName();
     $this->updateSite = VersionHelper::getUpdatesSite();
     $minstability = EParameter::getComponentParam(CAUTOTWEETNG, 'minstability');
     if ($minstability == self::CONFIG_AUTOUPDATE_BETA) {
         // Live site
         $this->updateSite .= '-beta';
     }
     // $this->updateSite = 'http://www.extly.com/update-autotweetng-free-test.xml';
     // $this->updateSite = 'http://www.extly.com/update-autotweetng-joocial-test.xml';
 }
 /**
  * postQueuedMessages
  *
  * @param   integer  $max  Param
  *
  * @return	boolean
  */
 public function postQueuedMessages($max)
 {
     $now = JFactory::getDate();
     $logger = AutotweetLogger::getInstance();
     if (AUTOTWEETNG_JOOCIAL && !VirtualManager::getInstance()->isWorking($now)) {
         $logger->log(JLog::INFO, 'AutotweetPostHelper - VM not working now ' . $now->toISO8601(true));
         return false;
     }
     // Get msgs from queue (sending is allowed only, when publish date is not in the future)
     // Sub 1 minute to avoid problems when automator plugin and extension plugin are executed at the same time...
     $check_date = $now->toUnix();
     // Sub 1 minute check
     $mincheck_time_intval = EParameter::getComponentParam(CAUTOTWEETNG, 'mincheck_time_intval', 60);
     $check_date = $check_date - $mincheck_time_intval;
     $check_date = JFactory::getDate($check_date);
     $requests = RequestHelp::getRequestList($check_date, $max);
     $sharingHelper = SharingHelper::getInstance();
     $logger->log(JLog::INFO, 'postQueuedMessages Requests: ' . count($requests));
     foreach ($requests as $request) {
         $result = false;
         $message = null;
         try {
             $result = $sharingHelper->publishRequest($request);
         } catch (Exception $e) {
             $message = $e->getMessage();
             $logger->log(JLog::ERROR, 'postQueuedMessages: Exception! ' . $message);
         }
         if ($result) {
             RequestHelp::processed($request->id);
         } else {
             RequestHelp::saveError($request->id, $message);
         }
     }
     if (AUTOTWEETNG_JOOCIAL && empty($requests)) {
         $logger->log(JLog::INFO, 'VirtualManager: anything else to publish?');
         VirtualManager::getInstance()->enqueueEvergreenMessage($check_date, $max);
     }
 }
Beispiel #13
0
 /**
  * onBrowse
  *
  * @param   string  $tpl  Param
  *
  * @return	bool
  */
 protected function onBrowse($tpl = null)
 {
     Extly::loadAwesome();
     GridHelper::loadComponentInfo($this);
     GridHelper::loadStats($this);
     GridHelper::loadStatsTimeline($this);
     $document = JFactory::getDocument();
     $document->addScript('//cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.min.js');
     $document->addScript('//cdnjs.cloudflare.com/ajax/libs/nvd3/1.7.0/nv.d3.min.js');
     $document->addStyleSheet('//cdnjs.cloudflare.com/ajax/libs/nvd3/1.7.0/nv.d3.min.css');
     // Get component parameter - Offline mode
     $version_check = EParameter::getComponentParam(CAUTOTWEETNG, 'version_check', 1);
     $this->assign('version_check', $version_check);
     $platform = F0FPlatform::getInstance();
     if ($version_check && $platform->isBackend()) {
         $file = EHtml::getRelativeFile('js', 'com_autotweet/liveupdate.min.js');
         if ($file) {
             $dependencies = array();
             $dependencies['liveupdate'] = array('extlycore');
             Extly::initApp(CAUTOTWEETNG_VERSION, $file, $dependencies);
         }
     }
     parent::onBrowse($tpl);
 }
Beispiel #14
0
 /**
  * _getInternalViews
  *
  * @return  array
  */
 private function _getInternalViews()
 {
     $views = array('cpanels', 'composer');
     if (EXTLY_J3) {
         // Activities menu definition
         $activities = array('requests');
         // Rules and evergreens - Only in the backend
         if ($this->isBackend) {
             if (AUTOTWEETNG_JOOCIAL) {
                 $activities[] = 'evergreens';
             }
             $activities[] = 'rules';
         }
         $activities[] = 'posts';
         $views['COM_AUTOTWEET_TITLE_ACTIVITIES'] = $activities;
     } else {
         $views[] = 'requests';
         // Rules and evergreens - Only in the backend
         if ($this->isBackend) {
             if (AUTOTWEETNG_JOOCIAL) {
                 $views[] = 'evergreens';
             }
             $views[] = 'rules';
         }
         $views[] = 'posts';
     }
     $views[] = 'channels';
     // Feeds and System Check - Only in the backend
     if ($this->isBackend) {
         // Targeting - Only in Joocial
         if (AUTOTWEETNG_JOOCIAL && EParameter::getComponentParam(CAUTOTWEETNG, 'targeting', false)) {
             array_push($views, 'targets');
         }
         $views[] = 'feeds';
         $views[] = 'infos';
         $views[] = 'usermanual';
         if (EXTLY_J3) {
             $views[] = 'options';
         }
     }
     return $views;
 }
Beispiel #15
0
} elseif (function_exists('phpversion')) {
    $version = phpversion();
} else {
    // No version info. I'll lie and hope for the best.
    $version = '5.0.0';
}
// Old PHP version detected. EJECT! EJECT! EJECT!
if (!version_compare($version, '5.3.0', '>=')) {
    return JError::raise(E_ERROR, 500, 'PHP versions 4.x, 5.0, 5.1 and 5.2 are no longer supported by AutoTweetNG.', 'The version of PHP used on your site is obsolete and contains known security vulenrabilities.
			Moreover, it is missing features required by AutoTweetNG to work properly or at all.
			Please ask your host to upgrade your server to the latest PHP 5.3/5.4 stable release. Thank you!');
}
if (!defined('AUTOTWEET_API')) {
    include_once JPATH_ADMINISTRATOR . '/components/com_autotweet/api/autotweetapi.php';
}
$base_url = EParameter::getComponentParam(CAUTOTWEETNG, 'base_url');
if (defined('AUTOTWEET_CRONJOB_RUNNING') && AUTOTWEET_CRONJOB_RUNNING && !filter_var($base_url, FILTER_VALIDATE_URL)) {
    throw new Exception('AUTOTWEET_CRONJOB: Url base not set.');
}
$config = array();
$controller = null;
// If we are processing Gplus, redirect to controller
$session = JFactory::getSession();
$channelId = $session->get('channelId');
if (!empty($channelId)) {
    $input = new F0FInput();
    // Google+ and Blogger
    $code = $input->getString('code');
    // ScoopIt
    $oauth_token = $input->getString('oauth_token');
    $oauth_verifier = $input->getString('oauth_verifier');
 /**
  * Checks for new events in the database (no triggers).
  *
  * @return	void
  */
 private function _onAfterRender()
 {
     $app = JFactory::getApplication();
     if ($app->isAdmin()) {
         return;
     }
     $option = $app->input->get('option');
     $task = $app->input->get('task');
     if ($option == 'com_autotweet' && $task == 'route') {
         return;
     }
     $this->cron_enabled = EParameter::getComponentParam(CAUTOTWEETNG, 'cron_enabled', false);
     if ($this->cron_enabled) {
         return;
     }
     $automators = F0FModel::getTmpInstance('Automators', 'AutoTweetModel');
     if (!$automators->lastRunCheck('automator', $this->interval)) {
         return;
     }
     $logger = AutotweetLogger::getInstance();
     // Bot/crawler detection
     $http_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : null;
     $remote_addr = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null;
     if (0 < $this->detect_bots && ($this->detectCrawlerByAgent($http_user_agent) || $this->detectCrawlerByIP($remote_addr))) {
         $logger->log(JLog::WARNING, 'AutoTweet NG Automator-Plugin - crawler detected. IP: ' . $remote_addr . ', Agent: ' . $http_user_agent);
         return;
     }
     $logger->log(JLog::INFO, 'AutoTweet NG Automator-Plugin - executed - IP: ' . $remote_addr . ', Agent: ' . $http_user_agent);
     define('AUTOTWEET_AUTOMATOR_RUNNING', true);
     $helper = AutotweetPostHelper::getInstance();
     $helper->postQueuedMessages($this->max_posts);
     $feeds_enabled = EParameter::getComponentParam(CAUTOTWEETNG, 'feeds_enabled', false);
     if ($feeds_enabled) {
         $helper = FeedLoaderHelper::getInstance();
         $helper->importFeeds();
     }
 }
 /**
  * loadAjaxImporter
  *
  * @param   object  $view  Param
  *
  * @return	void
  */
 public static function loadAjaxImporter($view)
 {
     $ajax_import = EParameter::getComponentParam(CAUTOTWEETNG, 'ajax_import', true);
     $view->assignRef('ajax_import', $ajax_import);
     if ($ajax_import) {
         $file = EHtml::getRelativeFile('js', 'com_autotweet/import.min.js');
         if ($file) {
             $dependencies = array();
             $dependencies['import'] = array('extlycore');
             Extly::initApp(CAUTOTWEETNG_VERSION, $file, $dependencies);
         }
     } else {
         Extly::initApp(CAUTOTWEETNG_VERSION);
     }
 }
Beispiel #18
0
 /**
  * queueMessage
  *
  * @param   string  $articleid         Param
  * @param   string  $source_plugin     Param
  * @param   string  $publish_up        Param
  * @param   string  $description       Param
  * @param   string  $typeinfo          Param
  * @param   string  $url               Param
  * @param   string  $image_url         Param
  * @param   object  &$native_object    Param
  * @param   string  &$advanced_attrs   Param
  * @param   string  &$params           Param
  * @param   string  $content_language  Param
  *
  * @return	mixed - false, or id of request
  */
 public static function insertRequest($articleid, $source_plugin, $publish_up, $description, $typeinfo = 0, $url = '', $image_url = '', &$native_object = null, &$advanced_attrs = null, &$params = null, $content_language = null)
 {
     $logger = AutotweetLogger::getInstance();
     // Check if message is already queued (it makes no sense to queue message more than once when modfied)
     // if message is already queued, correct the publish date
     $requestsModel = F0FModel::getTmpInstance('Requests', 'AutoTweetModel');
     $requestsModel->set('ref_id', $articleid);
     $requestsModel->set('plugin', $source_plugin);
     $requestsModel->set('typeinfo', $typeinfo);
     $row = $requestsModel->getFirstItem();
     $id = $row->id;
     // Avoid databse warnings when desc is longer then expected
     if (!empty($description)) {
         $description = TextUtil::cleanText($description);
         $description = JString::substr($description, 0, SharingHelper::MAX_CHARS_TITLE);
     }
     $routeHelp = RouteHelp::getInstance();
     if ($content_language) {
         $routeHelp->setContentLanguage($content_language);
     }
     if (AUTOTWEETNG_JOOCIAL && EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_mode') && EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_donot_post_url')) {
         $url = 'index.php';
     }
     $url = $routeHelp->getAbsoluteUrl($url);
     if (AUTOTWEETNG_JOOCIAL && EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_mode') && EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_donot_image_url')) {
         $image_url = null;
     }
     if (empty($image_url)) {
         // Default image: used in media mode when no image is available
         $image_url = EParameter::getComponentParam(CAUTOTWEETNG, 'default_image', '');
     }
     if (!empty($image_url)) {
         $image_url = $routeHelp->getAbsoluteUrl($image_url, true);
     }
     $row->reset();
     if ($id) {
         $row->load($id);
     }
     // If there's no date, it means now
     if (empty($publish_up)) {
         $publish_up = JFactory::getDate()->toSql();
     }
     $request = array('id' => $id, 'ref_id' => $articleid, 'plugin' => $source_plugin, 'publish_up' => $publish_up, 'description' => $description, 'typeinfo' => $typeinfo, 'url' => $url, 'image_url' => $image_url, 'native_object' => $native_object, 'params' => $params, 'published' => 0);
     $logger->log(JLog::INFO, 'Enqueued request', $request);
     // Saving the request
     $queued = $row->save($request);
     if (!$queued) {
         $logger->log(JLog::ERROR, 'queueMessage: error storing message to database message queue, article id = ' . $articleid . ', error message = ' . $row->getError());
     } else {
         $logger->log(JLog::INFO, 'queueMessage: message stored/updated to database message queue, article id = ' . $articleid);
     }
     if (!$id) {
         $id = $row->id;
     }
     if ($advanced_attrs && isset($advanced_attrs->attr_id)) {
         $row = F0FModel::getTmpInstance('Advancedattrs', 'AutoTweetModel')->getTable();
         $row->reset();
         $row->load($advanced_attrs->attr_id);
         $attr = array('id' => $advanced_attrs->attr_id, 'request_id' => $id);
         // Updating attr
         $result = $row->save($attr);
         if (!$result) {
             $logger->log(JLog::ERROR, 'Updating attr, attr_id = ' . $advanced_attrs->attr_id . ', error message = ' . $row->getError());
         } else {
             $logger->log(JLog::INFO, 'Updating attr, attr_id = ' . $advanced_attrs->attr_id);
         }
     }
     $app = JFactory::getApplication();
     if ($app->isAdmin() && JFactory::getConfig()->get('show_req_notification', true)) {
         $msg = VersionHelper::getFlavourName() . ': ' . JText::sprintf('COM_AUTOTWEET_REQUEST_ENQUEUED_MSG', $id);
         $app->enqueueMessage($msg);
     }
     return $queued ? $id : false;
 }
 /**
  * sampleAutoTweetNGIntegration
  *
  * @param   int    $productId  Param
  * @param   array  &$data      Param
  *
  * Example of how to save AutoTweetNG Request
  * Copy-paste into your extension, and customize freely
  *
  * @return	void
  */
 private static function sampleAutoTweetNGIntegration($productId, &$data)
 {
     // If product is not published, nothing else to do
     if (!$data['published']) {
         return;
     }
     $typeinfo = 99;
     $native_object = json_encode($data);
     // Product Url
     $viewProductUrl = EshopRoute::getProductRoute($productId, EshopHelper::getProductCategory($productId));
     // Image Url
     $db = JFactory::getDbo();
     $query = $db->getQuery(true);
     $query->clear();
     $query->select('image')->from('#__eshop_productimages')->where('product_id = ' . intval($productId))->order('ordering');
     $db->setQuery($query);
     $product_image = $db->loadResult();
     $image_url = null;
     if ($product_image && JFile::exists(JPATH_ROOT . '/media/com_eshop/products/' . $product_image)) {
         $image_url = 'media/com_eshop/products/' . $product_image;
     }
     $langmgmt_default_language = EParameter::getComponentParam(CAUTOTWEETNG, 'langmgmt_default_language');
     if ($langmgmt_default_language) {
         $key = 'product_name_' . $langmgmt_default_language;
         if (array_key_exists($key, $data)) {
             $title = $data[$key];
         }
         $key = 'product_desc_' . $langmgmt_default_language;
         if (array_key_exists($key, $data)) {
             $description = TextUtil::cleanText($data[$key]);
         }
     }
     if (empty($title)) {
         $title = $data['product_name'];
     }
     if (empty($description)) {
         $description = TextUtil::cleanText($data['product_desc']);
     }
     if (empty($title)) {
         return;
     }
     // Saving Advanced Attributes
     $autotweet_advanced = $data['autotweet_advanced_attrs'];
     $advanced_attrs = AdvancedattrsHelper::retrieveAdvancedAttrs($autotweet_advanced);
     AdvancedattrsHelper::saveAdvancedAttrs($advanced_attrs, $productId);
     // AutotweetAPI
     $id = self::insertRequest($productId, 'autotweetpost', JFactory::getDate()->toSql(), $title, $typeinfo, $viewProductUrl, $image_url, $native_object, $advanced_attrs);
     // Adding more information to the request
     $requestsModel = F0FModel::getTmpInstance('Requests', 'AutoTweetModel');
     $request = $requestsModel->getItem($id);
     $request = (array) $request;
     $request['xtform']->set('title', $title);
     $request['xtform']->set('fulltext', $description);
     $request['xtform']->set('author', JFactory::getUser()->username);
     $requestsModel->save($request);
 }
Beispiel #20
0
 /**
  * loadINI
  *
  * @return	bool
  */
 protected static function loadINI()
 {
     if (self::$_compinfo && self::$_pluginfo) {
         return true;
     }
     self::$_compinfo = array();
     self::$_pluginfo = array();
     self::$_thirdparty = array();
     // Get component parameter
     $version_check = EParameter::getComponentParam(CAUTOTWEETNG, 'version_check', 1);
     $remoteFile = self::SERVER_INI_PATH . self::SERVER_INI_FILE;
     $localFile = JPATH_AUTOTWEET_HELPERS . '/' . self::SERVER_INI_FILE;
     $file = $localFile;
     if ($version_check) {
         try {
             $ch = curl_init($remoteFile);
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
             curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::CXN_TIMEOUT);
             curl_setopt($ch, CURLOPT_TIMEOUT, self::EXEC_TIMEOUT);
             $data = curl_exec($ch);
             curl_close($ch);
             file_put_contents($localFile, $data);
         } catch (Exception $e) {
             $msg = $e->getMessage();
             $logger->log(JLog::ERROR, 'AutoTweetNG - ' . $msg);
         }
     }
     jimport('joomla.error.error');
     jimport('joomla.registry.registry');
     $registry = new JRegistry();
     if (!$registry->loadFile($file, 'INI', array('processSections' => 'true'))) {
         $logger->log(JLog::ERROR, 'AutoTweetNG - error reading INI file ' . $file);
         return false;
     }
     // Init logging
     $logger = AutotweetLogger::getInstance();
     $db = JFactory::getDBO();
     // Get component info and remove from array
     $data = JApplicationHelper::parseXMLInstallFile(JPATH_COMPONENT_ADMINISTRATOR . DIRECTORY_SEPARATOR . self::COMP_INSTALL_FILE);
     self::$_compinfo = array('id' => $registry->get('component.id'), 'name' => $registry->get('component.name'), 'server_version' => $registry->get('component.version'), 'client_version' => $data['version'], 'home' => $registry->get('component.home'), 'faq' => $registry->get('component.faq'), 'download' => $registry->get('component.download'), 'support' => $registry->get('component.support'), 'products' => $registry->get('component.products'), 'twitter' => $registry->get('component.twitter'), 'jed' => $registry->get('component.jed'), 'message' => $registry->get('component.message'), 'news' => $registry->get('component.news'));
     $extensions = TextUtil::listToArray($registry->get('component.extensions'));
     foreach ($extensions as $extension) {
         $state = self::EXT_NOTINSTALLED;
         $config = '';
         $client_version = '';
         $type = $registry->get($extension . '.type');
         $id = $registry->get($extension . '.id');
         $source = $registry->get($extension . '.source');
         if ('module' == $type) {
             $mod_filename = 'mod_' . $id;
             // Get the module id and set url for config
             $pluginsModel = F0FModel::getTmpInstance('Extensions', 'ExtlyModel');
             $pluginsModel->savestate(false)->setState('element', $mod_filename);
             $rows = $pluginsModel->getItemList();
             if (!empty($rows)) {
                 $row = $rows[0];
                 if ($row->client_id) {
                     $path = JPATH_ADMINISTRATOR . '/modules/' . $mod_filename . DIRECTORY_SEPARATOR . $mod_filename . '.xml';
                 } else {
                     $path = JPATH_ROOT . '/modules/' . $mod_filename . DIRECTORY_SEPARATOR . $mod_filename . '.xml';
                 }
                 $data = JApplicationHelper::parseXMLInstallFile($path);
                 $client_version = $data['version'];
                 if (self::_isEnabled($mod_filename)) {
                     $state = self::EXT_ENABLED;
                 } else {
                     $state = self::EXT_DISABLED;
                 }
                 // $config = 'index.php?option=com_modules&task=module.edit&id=' . $row->extension_id;
             }
         } else {
             // Get the plugin id and set url for config
             $pluginsModel = F0FModel::getTmpInstance('Plugins', 'AutoTweetModel');
             $pluginsModel->savestate(false)->set('element_id', $id);
             $rows = $pluginsModel->getItemList();
             if (!empty($rows)) {
                 $row = $rows[0];
                 $path = JPATH_PLUGINS . DIRECTORY_SEPARATOR . $row->folder . DIRECTORY_SEPARATOR . $row->element . DIRECTORY_SEPARATOR . $row->element . '.xml';
                 $data = JApplicationHelper::parseXMLInstallFile($path);
                 $client_version = $data['version'];
                 if (JPluginHelper::isEnabled($row->folder, $row->element)) {
                     $state = self::EXT_ENABLED;
                 } else {
                     $state = self::EXT_DISABLED;
                 }
                 $config = 'index.php?option=com_plugins&task=plugin.edit&extension_id=' . $row->id;
             }
         }
         // Append plugin state to result arrays
         if (self::FM_EXT_SOURCE == $source) {
             self::$_pluginfo[] = array('id' => $id, 'name' => $registry->get($extension . '.name'), 'state' => $state, 'client_version' => $client_version, 'server_version' => $registry->get($extension . '.version'), 'message' => $registry->get($extension . '.message'), 'config' => $config);
         } else {
             self::$_thirdparty[] = array('id' => $id, 'name' => $registry->get($extension . '.name'), 'state' => $state, 'client_version' => $client_version, 'message' => $registry->get($extension . '.message'), 'config' => $config, 'source' => $source, 'download' => $registry->get($extension . '.download'));
         }
     }
     // Add installed plugins without entry in ini file to 3rd party list
     $pluginsModel = F0FModel::getTmpInstance('Plugins', 'AutoTweetModel');
     $pluginsModel->savestate(false);
     $plugins = $pluginsModel->getItemList();
     foreach ($plugins as $plugin) {
         $id = $plugin->element;
         $type = $plugin->folder;
         if (!self::in_array_recursive($id, self::$_pluginfo) && !self::in_array_recursive($id, self::$_thirdparty)) {
             $path = JPATH_PLUGINS . DIRECTORY_SEPARATOR . $type . DIRECTORY_SEPARATOR . $id . DIRECTORY_SEPARATOR . $id . '.xml';
             $data = JApplicationHelper::parseXMLInstallFile($path);
             $client_version = $data['version'];
             if (JPluginHelper::isEnabled($type, $id)) {
                 $state = self::EXT_ENABLED;
             } else {
                 $state = self::EXT_DISABLED;
             }
             $config = 'index.php?option=com_plugins&task=plugin.edit&extension_id=' . $plugin->id;
             if (!empty($data['authorUrl'])) {
                 $source = $data['authorUrl'];
                 $download = $data['authorUrl'];
             } else {
                 $source = self::EXT_UNKNOWN;
                 $download = '';
             }
             self::$_thirdparty[] = array('id' => $id, 'name' => $plugin->name, 'state' => $state, 'client_version' => $client_version, 'message' => 'unknown extension plugin', 'config' => $config, 'source' => $source, 'download' => $download);
         }
     }
     return true;
 }
Beispiel #21
0
 /**
  * checkTimestamp.
  *
  * @return	boolean
  */
 public static function checkTimestamp()
 {
     // Get component parameter - Offline mode
     $version_check = EParameter::getComponentParam(CAUTOTWEETNG, 'version_check', 1);
     if (!$version_check) {
         return '998 Offline';
     }
     $appHelper = new TwAppHelper('TOCHECK', 'TOCHECK', 'TOCHECK', 'TOCHECK');
     $result = $appHelper->verify();
     $api = $appHelper->getApi();
     $dateCompare = '999 Unable to check';
     if (array_key_exists('headers', $api->response)) {
         $headers = $api->response['headers'];
         $twitterDate = $headers['date'];
         $twistamp = strtotime($twitterDate);
         $srvstamp = time();
         $dateCompare = abs($srvstamp - $twistamp);
     }
     return $dateCompare;
 }
Beispiel #22
0
 /**
  * _sendTwitterMessageWithImage
  *
  * @param   string  $status_msg  Param
  * @param   string  $imagefile   Param
  *
  * @return	array
  */
 private function _sendTwitterMessageWithImage($status_msg, $imagefile)
 {
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, '_sendTwitterMessageWithImage: ' . $status_msg . ' - ' . $imagefile);
     $api = $this->getApiInstance();
     if ($imagefile) {
         $basename = basename($imagefile);
         list($width, $height, $type, $attr) = getimagesize($imagefile);
         $mimetype = image_type_to_mime_type($type);
         $binaryimage_load = EParameter::getComponentParam(CAUTOTWEETNG, 'binaryimage_load');
         if ($binaryimage_load) {
             $handle = fopen($imagefile, "rb");
             $postimage = fread($handle, filesize($imagefile));
             fclose($handle);
         } else {
             $postimage = '@' . $imagefile;
         }
         $code = $api->request('POST', $api->url('1.1/statuses/update_with_media'), array('media[]' => "{$postimage};type={$mimetype};filename={$basename}", 'status' => $status_msg), true, true);
     } else {
         $code = $api->request('POST', $api->url('1.1/statuses/update'), array('status' => $status_msg));
     }
     return $this->_processResponse($code, $api);
 }
 /**
  * addItemeditorHelperApp
  *
  * @return string
  */
 public static function addItemeditorHelperApp()
 {
     static $link = false;
     if ($link) {
         return $link;
     }
     $doc = JFactory::getDocument();
     $app = JFactory::getApplication();
     list($isAdmin, $option, $controller, $task, $view, $layout, $id) = AutotweetBaseHelper::getControllerParams();
     $js = "var autotweetUrlRoot = '" . JUri::root() . "';\n";
     $js .= "var autotweetUrlBase = '" . JUri::base() . "';\n";
     $mediaPath = 'media/com_autotweet/js/itemeditor/templates/';
     $ext = '.txt';
     $joomlaPart = '.j' . (EXTLY_J3 ? '3' : '25');
     $sitePart = $isAdmin ? '.admin' : '.site';
     $tpl0 = $mediaPath . $option . $ext;
     $tpl1 = $mediaPath . $option . $joomlaPart . $ext;
     $tpl2 = $mediaPath . $option . $sitePart . $joomlaPart . $ext;
     $tpl3 = $mediaPath . $option . $sitePart . $ext;
     if (file_exists(JPATH_ROOT . '/' . $tpl2)) {
         $tpl = $tpl2;
     } elseif (file_exists(JPATH_ROOT . '/' . $tpl1)) {
         $tpl = $tpl1;
     } elseif (file_exists(JPATH_ROOT . '/' . $tpl3)) {
         $tpl = $tpl3;
     } elseif (file_exists(JPATH_ROOT . '/' . $tpl0)) {
         $tpl = $tpl0;
     } else {
         $tpl = $mediaPath . 'com_joocial-default' . $joomlaPart . $ext;
     }
     $tpl = JUri::root() . $tpl . '?version=' . CAUTOTWEETNG_VERSION;
     $js .= "var autotweetPanelTemplate = 'text!" . $tpl . "';\n";
     $doc->addScriptDeclaration($js);
     $link = 'index.php?option=com_autotweet&amp;view=itemeditor&amp;layout=modal&amp;tmpl=component&amp;' . JSession::getFormToken() . '=1';
     // Add Advanced Attributes
     $params = null;
     // Case Request edit page
     if ($option == CAUTOTWEETNG && $view == 'request' && $task == 'edit') {
         $params = AdvancedattrsHelper::getAdvancedAttrByReq($id);
     } elseif ($id > 0) {
         $params = AdvancedattrsHelper::getAdvancedAttrs($option, $id);
     }
     if (!$params) {
         $params = new StdClass();
         $params->description = '';
         $params->hashtags = '';
         $params->fulltext = '';
         $params->postthis = EParameter::getComponentParam(CAUTOTWEETNG, 'joocial_postthis', PlgAutotweetBase::POSTTHIS_DEFAULT);
         $params->evergreen = PlgAutotweetBase::POSTTHIS_NO;
         $params->agenda = array();
         $params->unix_mhdmd = '';
         $params->repeat_until = '';
         $params->image = '';
         $params->image_url = '';
         $params->channels = '';
         $params->channels_text = '';
     }
     // Migrating old objects
     if (!isset($params->description)) {
         $params->description = '';
     }
     // Migrating old objects
     if (!isset($params->hashtags)) {
         $params->hashtags = '';
     }
     // Migrating old objects
     if (!isset($params->fulltext)) {
         $params->fulltext = '';
     }
     // Migrating old objects
     if (!isset($params->image_url)) {
         $params->image_url = '';
     }
     $params->editorTitle = VersionHelper::getFlavourName() . ' ' . JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_TITLE');
     $params->postthisLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_POSTTHIS');
     $params->evergreenLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_EVERGREEN');
     $params->agendaLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_SCHEDULER');
     $params->unix_mhdmdLabel = JText::_('COM_XTCRONJOB_TASKS_FIELD_UNIX_MHDMD');
     $params->repeat_untilLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_REPEAT_UNTIL');
     $params->imageLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_IMAGES');
     $params->channelLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_CHANNELS');
     $params->postthisDefaultLabel = '<i class="xticon xticon-circle-o"></i> ' . JText::_('COM_AUTOTWEET_DEFAULT_LABEL');
     $params->postthisYesLabel = '<i class="xticon xticon-check"></i> ' . JText::_('JYES');
     $params->postthisNoLabel = '<i class="xticon xticon-times"></i> ' . JText::_('JNO');
     $params->descriptionLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_MSG');
     $params->hashtagsLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_HASHTAGS');
     $params->fulltextLabel = JText::_('COM_AUTOTWEET_VIEW_ITEMEDITOR_FULLTEXT_DESC');
     if (!isset($params->channels_text)) {
         $params->channels_text = '';
     }
     AutotweetBaseHelper::convertUTCLocalAgenda($params->agenda);
     $js = 'var autotweetAdvancedAttrs = ' . json_encode($params) . ";\n";
     $doc->addScriptDeclaration($js);
     $file = EHtml::getRelativeFile('js', 'com_autotweet/itemeditor.helper.min.js');
     if ($file) {
         $paths = array();
         $paths = array('text' => Extly::JS_LIB . 'require/text.min');
         $deps = array('itemeditor.helper' => array('text', 'underscore'));
         Extly::getScriptManager(false);
         Extly::initApp(CAUTOTWEETNG_VERSION, $file, $deps, $paths);
     }
     return $link;
 }
Beispiel #24
0
 /**
  * _addUtm
  *
  * @param   string  $url  Param
  *
  * @return	string
  */
 private function _addUtm($url)
 {
     if (empty($url)) {
         return $url;
     }
     $utm_source = EParameter::getComponentParam(CAUTOTWEETNG, 'utm_source');
     $utm_medium = EParameter::getComponentParam(CAUTOTWEETNG, 'utm_medium');
     $utm_term = EParameter::getComponentParam(CAUTOTWEETNG, 'utm_term');
     $utm_content = EParameter::getComponentParam(CAUTOTWEETNG, 'utm_content');
     $utm_campaign = EParameter::getComponentParam(CAUTOTWEETNG, 'utm_campaign');
     if ($utm_source || $utm_medium || $utm_term || $utm_content || $utm_campaign) {
         $uri = JUri::getInstance($url);
         if ($utm_source) {
             $uri->setVar('utm_source', $utm_source);
         }
         if ($utm_medium) {
             $uri->setVar('utm_medium', $utm_medium);
         }
         if ($utm_term) {
             $uri->setVar('utm_term', $utm_term);
         }
         if ($utm_content) {
             $uri->setVar('utm_content', $utm_content);
         }
         if ($utm_campaign) {
             $uri->setVar('utm_campaign', $utm_campaign);
         }
         $url = $uri->toString();
     }
     return $url;
 }
Beispiel #25
0
 /**
  * adminNotification
  *
  * @param   string  $channel  Param
  * @param   string  $msg      Param
  * @param   object  &$post    Param
  *
  * @return	boolean
  */
 public static function adminNotification($channel, $msg, &$post)
 {
     if (!EParameter::getComponentParam(CAUTOTWEETNG, 'admin_notification', 0)) {
         return;
     }
     JLoader::import('extly.mail.notification');
     $postmsg = print_r($post, true);
     $emailSubject = 'AutoTweetNG Notification - Error on Channel "' . $channel . '"';
     $emailBody = "<h2>Hi,</h2>\n\t\t<p>This is an <b>AutoTweetNG</b> Notification, about an error on channel \"{$channel}\".</p>\n\t\t<h3>Error Message</h3>\n\t\t<p>{$msg}</p>\n\t\t<h3>Post details</h3>\n\t\t<p>{$postmsg}</p>\n\t\t<p>If you are working in the configuration, it must be related with your work. However, if the site is stable, you should check if there's any problem (E.g. an expired token).</p>\n\t\t<p><br></p>\n\t\t<p>If you have any question, the support team is ready to answer!</p>\n\t\t<p>Best regards,</p>\n\t\t<p>Support Team<br> <b>Extly.com</b> - Extensions<br> Support: <a target=\"_blank\" href=\"http://support.extly.com\">http://support.extly.com</a><br> Twitter @extly | Facebook <a target=\"_blank\" href=\"http://www.facebook.com/extly\">www.facebook.com/extly</a></p>";
     Notification::mailToAdmin($emailSubject, $emailBody);
 }
Beispiel #26
0
 /**
  * publishRequest
  *
  * @param   array   $request  Param
  * @param   object  $userid   Param
  *
  * @return	boolean
  */
 public function publishRequest($request, $userid = null)
 {
     $this->logger->log(JLog::INFO, 'publishRequest request', $request);
     // Default: generate new entry for repost of entry with state success
     $postid = 0;
     $data = $this->_getContentData($request);
     if (!$data) {
         return false;
     }
     // Convert array to object
     $json = json_encode($data);
     $post = json_decode($json);
     if (AUTOTWEETNG_JOOCIAL) {
         $params = AdvancedattrsHelper::getAdvancedAttrByReq($request->id);
     }
     $post->ref_id = $request->ref_id;
     $post->plugin = $request->plugin;
     $post->postdate = $request->publish_up;
     $post->message = $post->text;
     unset($post->text);
     // Url
     if (isset($post->url) && !empty($post->url)) {
         $routeHelp = RouteHelp::getInstance();
         $url = $routeHelp->getAbsoluteUrl($post->url);
         $post->url = $url;
     } elseif (isset($request->url) && !empty($request->url)) {
         $post->url = $request->url;
     } else {
         $this->logger->log(JLog::INFO, 'publishRequest: No url');
         $post->url = '';
     }
     $this->logger->log(JLog::INFO, 'publishRequest: url = ' . $post->url);
     // Image url
     if (isset($post->image_url) && !empty($post->image_url)) {
         // If defined in getExtendedData, use this image_url
         $routeHelp = RouteHelp::getInstance();
         $url = $routeHelp->getAbsoluteUrl($post->image_url);
         // Only if it's a valid Url
         if (!ImageUtil::getInstance()->isValidImageUrl($url)) {
             $url = null;
         }
         $post->image_url = $url;
     } elseif (isset($request->image_url) && !empty($request->image_url)) {
         $url = $request->image_url;
         // Only if it's a valid Url
         if (!ImageUtil::getInstance()->isValidImageUrl($url)) {
             $url = null;
         }
         // Use this image_url (it's already routed)
         $post->image_url = $url;
     } else {
         $this->logger->log(JLog::INFO, 'publishRequest: No image url');
         $post->image_url = null;
     }
     $this->logger->log(JLog::INFO, 'publishRequest: image url = ' . $post->image_url);
     // Title
     // Truncate title and fulltext for new messages ('if' is for backward compatibillity)
     if (isset($post->title)) {
         $title = TextUtil::cleanText($post->title);
         $post->title = TextUtil::truncString($title, self::MAX_CHARS_TITLE);
     } else {
         $post->title = '';
     }
     // Fulltext
     if (!isset($post->fulltext)) {
         $post->fulltext = '';
     }
     if (AUTOTWEETNG_JOOCIAL) {
         if (isset($params->fulltext) && !empty($params->fulltext)) {
             $post->fulltext = $params->fulltext;
         }
     }
     if (AUTOTWEETNG_JOOCIAL && EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_mode') && ($fulltext = EParameter::getComponentParam(CAUTOTWEETNG, 'paywall_titleonly'))) {
         $post->fulltext = $fulltext;
     }
     $fulltext = TextUtil::cleanText($post->fulltext);
     $post->fulltext = TextUtil::truncString($fulltext, self::MAX_CHARS_FULLTEXT);
     $post->xtform = new JRegistry();
     // Catids
     if (isset($post->catids)) {
         $catids = $post->catids;
         unset($post->catids);
         $post->xtform->set('catids', $catids);
     } else {
         $post->xtform->set('catids', array());
     }
     // Author
     if (isset($post->author)) {
         $author = $post->author;
         unset($post->author);
         $post->xtform->set('author', $author);
     }
     // Language
     if (isset($post->language)) {
         $language = $post->language;
         unset($post->language);
         $post->xtform->set('language', $language);
     }
     // Access
     if (isset($post->access)) {
         $access = $post->access;
         unset($post->access);
         $post->xtform->set('access', $access);
     }
     // Target_id
     if (isset($post->target_id)) {
         $target_id = $post->target_id;
         unset($post->target_id);
         $post->xtform->set('target_id', $target_id);
     }
     // Hashtags
     if (isset($post->hashtags)) {
         $hashtags = $post->hashtags;
         unset($post->hashtags);
         $post->xtform->set('hashtags', $hashtags);
     }
     // Native object
     if (isset($request->native_object)) {
         $native_object = $request->native_object;
         $native_object = json_decode($native_object);
         if ($native_object) {
             $post->xtform->set('native_object', $native_object);
         } else {
             $this->logger->log(JLog::INFO, 'publishRequest: Inavlid JSON native_object');
         }
     }
     // Featured
     if (isset($post->featured)) {
         $post->xtform->set('featured', $post->featured);
         unset($post->featured);
     }
     return $this->sendRequest($request, $post, $userid);
 }
Beispiel #27
0
							<label class="control-label" for="show_url" id="show_url-lbl" rel="tooltip" data-original-title="<?php 
echo JText::_('COM_AUTOTWEET_VIEW_CHANNEL_SHOWURL_DESC');
?>
"><?php 
echo JText::_('COM_AUTOTWEET_VIEW_SHOWURL_TITLE');
?>
</label>
							<div class="controls inline">
								<?php 
echo SelectControlHelper::showurl($this->item->xtform->get('show_url'), 'xtform[show_url]');
?>
							</div>
						</div>

						<?php 
if (AUTOTWEETNG_JOOCIAL && EParameter::getComponentParam(CAUTOTWEETNG, 'targeting', false)) {
    ?>
			            <hr/>

			            <div class="control-group">
			              <label class="control-label" for="xtformtarget_id" id="target_id-lbl"><?php 
    echo JText::_('COM_AUTOTWEET_VIEW_FBWACCOUNT_TARGETING_TITLE');
    ?>
</label>
			              <div class="controls">
			                <?php 
    echo SelectControlHelper::targets($this->item->xtform->get('target_id'), 'xtform[target_id]', null);
    ?>
			              </div>
			            </div>
 /**
  * getContentPollingFrom
  *
  * @return	JDate
  */
 protected function getContentPollingFrom()
 {
     $polling_window = EParameter::getComponentParam(CAUTOTWEETNG, 'polling_window_intval', 24);
     $check_from = JFactory::getDate()->toUnix() - $polling_window * 3600;
     $check_from = JFactory::getDate($check_from);
     return $check_from;
 }
Beispiel #29
0
 /**
  * sendMessage.
  *
  * @param   string  $message  Params
  * @param   object  $data     Params
  *
  * @return	booleans
  */
 public function sendMessage($message, $data)
 {
     $isUserProfile = $this->isUserProfile();
     if ($this->channel->params->get('open_graph_features') && $isUserProfile) {
         return $this->sendFacebookOG($message, $data->title, $data->fulltext, $data->url, $data->org_url, $data->image_url, $this->getMediaMode(), $data);
     }
     $title = $data->title;
     $text = $data->fulltext;
     $url = $data->url;
     $org_url = $data->org_url;
     $image_url = $data->image_url;
     $media_mode = $this->getMediaMode();
     $logger = AutotweetLogger::getInstance();
     $logger->log(JLog::INFO, 'sendFacebookMessage', $message);
     $fb_id = $this->getFbChannelId();
     $fb_token = $this->get('fbchannel_access_token');
     // Includes a workaround for Facebook ?ref=nf url extension problem and short urls
     // if API bug is fixed, replace all org_url variables by url
     $result = null;
     // Post message and/or attachment
     switch ($media_mode) {
         case 'attachment':
             $post_attach = true;
             $post_msg = false;
             break;
         case 'both':
             $post_msg = true;
             $post_attach = true;
             break;
         case 'message':
         default:
             $post_msg = true;
             $post_attach = false;
     }
     if (empty($org_url)) {
         $post_attach = false;
     }
     if (empty($text) && empty($image_url)) {
         $post_attach = false;
     }
     // Attachment: do also not post when text and image are empty
     if ($post_attach) {
         // Extract data for action link
         $url_comps = parse_url($org_url);
         $actionlink_text = $url_comps['host'];
         $actions = array();
         $actions['name'] = $actionlink_text;
         $actions['link'] = $org_url;
         $status_type = array('value' => 'wall_post');
         $title = TextUtil::truncString($title, self::MAX_CHARS_NAME);
         $arguments = array('link' => $org_url, 'name' => $title, 'caption' => $actionlink_text, 'description' => $text, 'actions' => json_encode($actions), 'access_token' => $fb_token, 'status_type' => json_encode($status_type));
         if ($isUserProfile) {
             $privacy = $this->get('sharedwith', 'EVERYONE');
             $privacy = array('value' => $privacy);
             $arguments['privacy'] = json_encode($privacy);
         }
         // Include image tag only, when image url is not empty to avoid error "... must have a valid src..."
         if (!empty($image_url)) {
             $arguments['picture'] = $image_url;
         }
         // Message
         if ($post_msg) {
             $arguments['message'] = $message;
         }
     } else {
         $arguments = array('message' => $message, 'access_token' => $fb_token);
     }
     $target_id = $data->xtform->get('target_id');
     if (EParameter::getComponentParam(CAUTOTWEETNG, 'targeting', false) && $target_id) {
         $this->addTargetArguments($arguments, $target_id);
     }
     try {
         $fbapi = $this->getApiInstance();
         // Simulated
         if ($this->channel->params->get('use_own_api') == 0) {
             $fbapi->api("/me/permissions");
             $result = array(true, JText::_('COM_AUTOTWEET_VIEW_SIMULATED_OK'));
         } else {
             $result = $fbapi->api("/{$fb_id}/feed", 'post', $arguments);
             $msg = 'Facebook id: ' . $result['id'];
             $result = array(true, $msg);
         }
     } catch (Exception $e) {
         $code = $e->getCode();
         $msg = $code . ' - ' . $e->getMessage();
         $donot_fberror02 = EParameter::getComponentParam(CAUTOTWEETNG, 'donot_fberror02', 0);
         $donottrack_error = $donot_fberror02 && ($code == 0 || $code == 2);
         if ($donottrack_error) {
             $logger = AutotweetLogger::getInstance();
             $logger->log(JLog::ERROR, 'DONOT_FBERROR02: ' . $msg);
             $result = array(true, $msg);
         } else {
             $result = array(false, $msg);
         }
     }
     return $result;
 }
Beispiel #30
0
 /**
  * getFeed
  *
  * @param   array  &$params  The module options.
  *
  * @return	void
  */
 public static function getFeed(&$params)
 {
     // Global $mainframe;
     // Init feed array
     $light_rss = array();
     // Get local module parameters from xml file module config settings
     $rssurl = $params->get('rssurl', null);
     $rssitems = $params->get('rssitems', 5);
     $rssdesc = $params->get('rssdesc', 1);
     $rssimage = $params->get('rssimage', 1);
     $rssitemtitle_words = $params->get('rssitemtitle_words', 0);
     $rssitemdesc = $params->get('rssitemdesc', 0);
     $rssitemdesc_images = $params->get('rssitemdesc_images', 1);
     $rssitemdesc_words = $params->get('rssitemdesc_words', 0);
     $rsstitle = $params->get('rsstitle', 1);
     $rsscache = $params->get('rsscache', 3600);
     $link_target = $params->get('link_target', 1);
     $no_follow = $params->get('no_follow', 0);
     $enable_tooltip = $params->get('enable_tooltip', 'yes');
     $tooltip_desc_words = $params->get('t_word_count_desc', 25);
     $tooltip_desc_images = $params->get('tooltip_desc_images', 1);
     $tooltip_title_words = $params->get('t_word_count_title', 25);
     $add_dots = !EParameter::getComponentParam(CAUTOTWEETNG, 'donot_add_dots');
     if (!$rssurl) {
         $light_rss['error'][] = 'Invalid feed url. Please enter a valid url in the module settings.';
         // Halt if no valid feed url supplied
         return $light_rss;
     }
     switch ($link_target) {
         // Open links in current or new window
         case 1:
             $link_target = '_blank';
             break;
         case 0:
             $link_target = '_self';
             break;
         default:
             $link_target = '_blank';
             break;
     }
     $light_rss['target'] = $link_target;
     if ($no_follow) {
         $light_rss['nofollow'] = 'rel="nofollow"';
     }
     if (!class_exists('SimplePie')) {
         // Include Simple Pie processor class
         include_once JPATH_AUTOTWEET . '/libs/SimplePie_autoloader.php';
     }
     // Load and build the feed array
     $feed = new SimplePie();
     $use_sp_cache = EParameter::getComponentParam(CAUTOTWEETNG, 'use_sp_cache', true);
     if ($use_sp_cache && is_writable(JPATH_CACHE)) {
         $feed->set_cache_location(JPATH_CACHE);
         $feed->enable_cache(true);
         $cache_time = intval($rsscache);
         $feed->set_cache_duration($cache_time);
     } else {
         $feed->enable_cache(false);
     }
     $feed->set_feed_url($rssurl);
     // Process the loaded feed
     $feed->init();
     $feed->handle_content_type();
     // Store any error message
     if (isset($feed->error)) {
         $light_rss['error'][] = $feed->error;
     }
     // Start building the feed meta-info (title, desc and image)
     // Feed title
     if ($feed->get_title() && $rsstitle) {
         $light_rss['title']['link'] = $feed->get_link();
         $light_rss['title']['title'] = $feed->get_title();
     }
     // Feed description
     if ($rssdesc) {
         $light_rss['description'] = $feed->get_description();
     }
     // Feed image
     if ($rssimage && $feed->get_image_url()) {
         $light_rss['image']['url'] = $feed->get_image_url();
         $light_rss['image']['title'] = $feed->get_image_title();
     }
     // End feed meta-info
     // Start processing feed items
     // If there are items in the feed
     if ($feed->get_item_quantity()) {
         // Start looping through the feed items
         $light_rss_item = 0;
         // Item counter for array indexing in the loop
         foreach ($feed->get_items(0, $rssitems) as $currItem) {
             // Item title
             $item_title = trim($currItem->get_title());
             // Item title word limit check
             if ($rssitemtitle_words) {
                 $item_titles = explode(' ', $item_title);
                 $count = count($item_titles);
                 if ($count > $rssitemtitle_words) {
                     $item_title = '';
                     for ($i = 0; $i < $rssitemtitle_words; $i++) {
                         $item_title .= ' ' . $item_titles[$i];
                     }
                     if ($add_dots) {
                         $item_title .= '...';
                     }
                 }
             }
             // Item Title
             $light_rss['items'][$light_rss_item]['title'] = $item_title;
             $light_rss['items'][$light_rss_item]['link'] = $currItem->get_permalink();
             // Item description
             if ($rssitemdesc) {
                 $desc = trim($currItem->get_description());
                 if (!$rssitemdesc_images) {
                     // Strip image tags
                     $desc = preg_replace("/<img[^>]+\\>/i", "", $desc);
                 }
                 // Item description word limit check
                 if ($rssitemdesc_words) {
                     $texts = explode(' ', $desc);
                     $count = count($texts);
                     if ($count > $rssitemdesc_words) {
                         $desc = '';
                         for ($i = 0; $i < $rssitemdesc_words; $i++) {
                             // Build words
                             $desc .= ' ' . $texts[$i];
                         }
                         if ($add_dots) {
                             $desc .= '...';
                         }
                     }
                 }
                 // Item Description
                 $light_rss['items'][$light_rss_item]['description'] = $desc;
             }
             // Tooltip text
             if ($enable_tooltip == 'yes') {
                 // Tooltip item title
                 $t_item_title = trim($currItem->get_title());
                 // Tooltip title word limit check
                 if ($tooltip_title_words) {
                     $t_item_titles = explode(' ', $t_item_title);
                     $count = count($t_item_titles);
                     if ($count > $tooltip_title_words) {
                         $tooltip_title = '';
                         for ($i = 0; $i < $tooltip_title_words; $i++) {
                             $tooltip_title .= ' ' . $t_item_titles[$i];
                         }
                         if ($add_dots) {
                             $tooltip_title .= '...';
                         }
                     } else {
                         $tooltip_title = $t_item_title;
                     }
                 } else {
                     $tooltip_title = $t_item_title;
                 }
                 // Replace new line characters in tooltip title, important!
                 $tooltip_title = preg_replace("/(\r\n|\n|\r)/", " ", $tooltip_title);
                 // Format text for tooltip
                 $tooltip_title = htmlspecialchars(html_entity_decode($tooltip_title), ENT_QUOTES);
                 // Tooltip Title
                 $light_rss['items'][$light_rss_item]['tooltip']['title'] = $tooltip_title;
                 // Tooltip item description
                 $text = trim($currItem->get_description());
                 if (!$tooltip_desc_images) {
                     $text = preg_replace("/<img[^>]+\\>/i", "", $text);
                 }
                 // Tooltip desc word limit check
                 if ($tooltip_desc_words) {
                     $texts = explode(' ', $text);
                     $count = count($texts);
                     if ($count > $tooltip_desc_words) {
                         $text = '';
                         for ($i = 0; $i < $tooltip_desc_words; $i++) {
                             $text .= ' ' . $texts[$i];
                         }
                         if ($add_dots) {
                             $text .= '...';
                         }
                     }
                 }
                 // Replace new line characters in tooltip, important!
                 $text = preg_replace("/(\r\n|\n|\r)/", " ", $text);
                 // Format text for tooltip
                 $text = htmlspecialchars(html_entity_decode($text), ENT_QUOTES);
                 // Tooltip Body
                 $light_rss['items'][$light_rss_item]['tooltip']['description'] = $text;
             } else {
                 // Blank
                 $light_rss['items'][$light_rss_item]['tooltip'] = array();
             }
             // Increment item counter
             $light_rss_item++;
         }
     }
     // End item quantity check if statement
     // Return the feed data structure for the template
     return $light_rss;
 }