コード例 #1
0
ファイル: item.php プロジェクト: beingsane/facebook-importer
 /**
  * saveAsCombined
  *
  * @param array $items
  * @param array $cids
  *
  * @throws  RuntimeException
  * @return  boolean
  */
 public function saveAsCombined($items, $cids)
 {
     $params = JComponentHelper::getParams('com_fbimporter');
     $format = $this->getTable('Format');
     $table = JTable::getInstance('Content');
     $sample = $this->state->get('combined.sample', $params->get('combined_sample', 2));
     $params = JComponentHelper::getParams('com_fbimporter');
     if (!$format->load($sample)) {
         throw new \RuntimeException(JText::_('COM_FBIMPORTER_CANNOT_GET_IMPORT_FORMAT'));
     }
     $catid = $this->state->get('combined.catid', $params->get('combined_catid', $format->catid));
     $sample_intro = $format->introtext;
     $sample_full = $format->fulltext;
     $temp = TempHelper::getPath();
     $r = '';
     if (is_file($temp)) {
         $r = file_get_contents($temp);
     }
     $r = json_decode($r);
     if (isset($r->data)) {
         foreach ($r->data as $key => &$item) {
             $item = new JObject($item);
             $item->id = explode('_', $item->id);
             $item->id = $item->id[1];
             if (isset($items[$item->id])) {
                 $items[$item->id]['type'] = $item->type;
                 $items[$item->id]['name'] = isset($item->name) ? $item->name : '';
                 $items[$item->id]['picture'] = base64_encode(isset($item->picture) ? $item->picture : '');
                 $items[$item->id]['link'] = base64_encode(isset($item->link) ? $item->link : '');
                 $items[$item->id]['source'] = base64_encode(isset($item->source) ? $item->source : '');
                 $items[$item->id]['likes'] = isset($item->likes->summary->total_count) ? $item->likes->summary->total_count : 0;
                 $items[$item->id]['created'] = $item->created_time;
             }
         }
     } else {
         throw new \RuntimeException(JText::_('COM_FBIMPORTER_CANNOT_GET_DATA'));
     }
     // Sort
     // ========================================================================
     $ids = array();
     $key = $this->state->get('combined.sort', $params->get('combined_sort', 'likes'));
     foreach ($cids as $cid) {
         $ids[$cid] = $items[$cid][$key];
     }
     if ($this->state->get('combined.dir', $params->get('combined_dir', 'desc')) == 'desc') {
         asort($ids);
     } else {
         arsort($ids);
     }
     $posts = array();
     foreach ($ids as $cid => $id) {
         // Get item
         $item = $items[$cid];
         $posts[] = $this->replaceText($item, $sample_full, $cid);
     }
     // reset article
     $table->id = null;
     $table->created = null;
     $table->published_up = null;
     $table->published_down = null;
     $table->title = $params->get('combined_article_title', 'A Combined Article');
     $table->alias = JFilterOutput::stringURLSafe('content-from-facebook-' . uniqid());
     $table->introtext = $sample_intro;
     $table->fulltext = implode("\n", $posts);
     $table->state = 0;
     $table->hits = 0;
     $table->catid = $catid;
     $table->created_by = JFactory::getUser()->get('id');
     $table->store();
     $this->state->set('content.id', $table->id);
     return true;
 }
コード例 #2
0
ファイル: items.php プロジェクト: beingsane/facebook-importer
 /**
  * Constructor
  *
  * @param   array                 $config    An array of configuration options (name, state, dbo, table_path, ignore_request).
  * @param   \Joomla\DI\Container  $container Service container.
  * @param   \JRegistry            $state     The model state.
  * @param   \JDatabaseDriver      $db        The database adapter.
  */
 public function __construct($config = array(), \Joomla\DI\Container $container = null, \JRegistry $state = null, \JDatabaseDriver $db = null)
 {
     parent::__construct($config, $container, $state, $db);
     $this->temp = \Fbimporter\Helper\TempHelper::getPath();
     $this->params = JComponentHelper::getParams('com_fbimporter');
 }