예제 #1
0
 function onAfterInitialise()
 {
     $mainframe = JFactory::getApplication();
     if ($mainframe->isAdmin()) {
         return;
     }
     $cron = JRequest::getInt('jasocial_feed_cron', 0);
     $next_run = $this->getNextRun();
     $jatoken = JRequest::getInt('jatoken', 0);
     $last_run = isset($this->aInfo['last_run']) ? $this->aInfo['last_run'] : 0;
     $cron_interval = $this->plgParams->get('cache_time', 3600);
     $diff = $last_run - $jatoken;
     $isRunbyadmin = $diff >= 0 && $diff <= $cron_interval ? 1 : 0;
     if ($next_run > time() && !$isRunbyadmin) {
         return;
     }
     if (!$cron) {
         $document = JFactory::getDocument();
         $script = "\r\n\t\t\tfunction jaGetSocialFeed() {\r\n\t\t\t\tvar jaSocialFeedReq = new Request({method: 'get', url: '" . JURI::root() . "/?jasocial_feed_cron=1'}).send();\r\n\t\t\t}\r\n\t\t\twindow.addEvent('load', function() {\r\n\t\t\t\tsetTimeout('jaGetSocialFeed()', 1000);\r\n\t\t\t});\r\n\t\t\t";
         $document->addScriptDeclaration($script);
     } else {
         ignore_user_abort(true);
         require_once dirname(__FILE__) . '/helpers.php';
         //update last run info to limit other people call request to get feed
         $this->updateCacheInfo(1);
         //order descreasing by processing speed
         $sources = array('vimeo', 'youtube', 'flickr', 'instagram', 'facebook', 'twitter');
         foreach ($sources as $source) {
             $method = 'fetch' . ucfirst($source) . 'Post';
             $profiles = jaSocialFeedGetProfiles($source);
             if (count($profiles)) {
                 foreach ($profiles as $profile => $pName) {
                     $data = jaSocialFeedGetProfile($source, $profile);
                     if (is_object($data)) {
                         $status = $this->getProperty($data, $source . '_status', 1);
                         if ($status) {
                             call_user_func_array(array($this, $method), array($data));
                         }
                     }
                 }
             }
         }
         jexit('done');
     }
     return;
 }
예제 #2
0
 public function save_profile()
 {
     $source = JRequest::getVar('profile_source');
     $profile = JRequest::getString('profile_' . $source);
     $this->check_profile($source, $profile);
     $path = PLG_JASOCIALFEED_PATH . 'profiles/' . $source . '/';
     if (!JFolder::exists($path)) {
         JFolder::create($path);
     }
     //filter data
     $prefix = $source . '_';
     $data = array();
     $post = JRequest::getVar('jform');
     $socialId = '';
     $fieldSocialId = $prefix . 'account';
     if (isset($post['params'])) {
         foreach ($post['params'] as $key => $val) {
             if (strpos($key, $prefix) === 0) {
                 if ($key == $fieldSocialId) {
                     $socialId = $val;
                 }
                 $data[$key] = $val;
             }
         }
     }
     if (!count($data)) {
         $this->doResponse(null, 0, JText::_('Invalid Request!'));
     }
     //check for duplicated social account
     if (!empty($socialId)) {
         $listProfiles = jaSocialFeedGetProfiles($source);
         if (count($listProfiles)) {
             foreach ($listProfiles as $cP => $cPN) {
                 $pData = jaSocialFeedGetProfile($source, $cP);
                 if ($cP != $profile && isset($pData->{$fieldSocialId}) && $pData->{$fieldSocialId} == $socialId) {
                     $this->doResponse(null, 0, JText::sprintf('ALERT_SOCIAL_ACCOUNT_IS_EXISTED', $source, $socialId, $cPN));
                 }
             }
         }
     }
     //
     $data = json_encode($data);
     $result = JFile::write($path . $profile . '.json', $data);
     if ($result) {
         $this->doResponse(null, 1, JText::sprintf('Successfully saved profile: %s!', $profile));
     } else {
         $this->doResponse(null, 0, JText::sprintf('Failed saved profile: %s!', $profile));
     }
 }