/** * Add an item to the exporting list * * @param Item $item The item to export * @param Type $type The type of the item * * @return AppExporterZoo2 $this for chaining support * * @since 2.0 */ protected function _addZooItem(Item $item, Type $type) { $data = array(); foreach ($this->item_attributes as $attribute) { if (isset($item->{$attribute})) { $data[$attribute] = $item->{$attribute}; } } if ($user = $this->app->user->get($item->created_by)) { $data['author'] = $user->username; } $data['tags'] = $item->getTags(); // store item content, metadata, config params $data['content'] = $item->getParams()->get('content.'); $data['metadata'] = $item->getParams()->get('metadata.'); $data['config'] = $item->getParams()->get('config.'); // add categories foreach ($item->getRelatedCategoryIds() as $category_id) { $alias = ''; if (empty($category_id)) { $alias = '_root'; } else { if (isset($this->_categories[$category_id])) { $alias = $this->_categories[$category_id]->alias; } } if (!empty($alias)) { $data['categories'][] = $alias; } if ($item->getPrimaryCategoryId() == $category_id) { $data['config']['primary_category'] = $alias; } } foreach ($item->elements as $identifier => $element_data) { if (!($element = $type->getElement($identifier))) { continue; } $element_type = $element->getElementType(); switch ($element_type) { case 'relateditems': $items = array(); if (isset($element_data['item'])) { foreach ($element_data['item'] as $item_id) { $items[] = $this->app->alias->item->translateIDToAlias($item_id); } } $element_data['item'] = $items; break; case 'relatedcategories': $categories = array(); if (isset($element_data['category'])) { foreach ($element_data['category'] as $category_id) { $categories[] = isset($this->_categories[$category_id]) ? $this->_categories[$category_id]->alias : $this->app->alias->category->translateIDToAlias($category_id); } } $element_data['category'] = $categories; break; } $data['elements'][$identifier]['type'] = $element_type; $data['elements'][$identifier]['name'] = $element->config->get('name'); $data['elements'][$identifier]['data'] = $element_data; foreach ($this->_comment_table->getCommentsForItem($item->id) as $comment) { foreach ($this->comment_attributes as $attribute) { if (isset($comment->{$attribute})) { $data['comments'][$comment->id][$attribute] = $comment->{$attribute}; } } if ($comment->user_type == 'joomla' && ($user = $this->app->user->get($comment->user_id))) { $data['comments'][$comment->id]['username'] = $user->username; } } } parent::_addItem($item->name, $item->alias, $type->name, $data); }
/** * Add an item to the export list * * @param object $article The article to export * @param string $parent Where the article should be inserted into * @param string $group The group in which it should be put into * * @return AppExporterJoomla $this For chaining support * * @since 2.0 */ protected function _addJoomlaItem($article, $parent, $group = 'default') { if ($article->state > 1) { $article->state = 0; } $data = array(); foreach ($this->item_attributes as $attribute) { if (isset($article->{$attribute})) { $data[$attribute] = $article->{$attribute}; } } $metadata = $this->app->parameter->create($article->metadata); $data['metadata'] = array('description' => $article->metadesc, 'keywords' => $article->metakey, 'robots' => $metadata->get('robots'), 'author' => $metadata->get('author')); $data['author'] = ($user = $this->app->user->get($article->created_by)) ? $user->username : $this->app->user->get()->username; if ($article->featured) { $data['categories'][] = '_root'; } $data['categories'][] = $parent; $data['elements'][0]['type'] = 'textarea'; $data['elements'][0]['name'] = 'Article'; $data['elements'][0]['data'] = array(array('value' => $article->introtext), array('value' => $article->fulltext)); $images = @json_decode($article->images, true) ?: array(); $data['elements'][1]['type'] = 'image'; $data['elements'][1]['name'] = 'Intro Image'; $data['elements'][1]['data'] = array('file' => @$images['image_intro'], 'title' => @$images['image_intro_caption']); $data['elements'][2]['type'] = 'image'; $data['elements'][2]['name'] = 'Fulltext Image'; $data['elements'][2]['data'] = array('file' => @$images['image_fulltext'], 'title' => @$images['image_fulltext_caption']); $urls = @json_decode($article->urls, true) ?: array(); $data['elements'][3]['type'] = 'link'; $data['elements'][3]['name'] = 'Link A'; $data['elements'][3]['data'] = array(array('value' => @$urls['urla'] ?: '', 'text' => @$urls['urlatext'])); $data['elements'][4]['type'] = 'link'; $data['elements'][4]['name'] = 'Link B'; $data['elements'][4]['data'] = array(array('value' => @$urls['urlb'] ?: '', 'text' => @$urls['urlbtext'])); $data['elements'][5]['type'] = 'link'; $data['elements'][5]['name'] = 'Link C'; $data['elements'][5]['data'] = array(array('value' => @$urls['urlc'] ?: '', 'text' => @$urls['urlctext'])); parent::_addItem($article->title, $article->alias, $group, $data); }
/** * Add an item to the list of items to export * * @param object $item The item to export * @param array $extra_fields The extra fields for this item * @param array $categories The categories for this item * @param array $tags The item tags * @param string $group The item group * * @return AppExporterK2 $this for chaining support */ protected function _addK2Item($item, $extra_fields, $categories = array(), $tags = array(), $group = 'default') { $data = array(); foreach ($this->item_attributes as $attribute) { if (isset($item->{$attribute})) { $data[$attribute] = $item->{$attribute}; } } // add author $data['author'] = $this->app->user->get($item->created_by)->username; // add state $data['state'] = $item->published; // add category $data['categories'][] = $categories[$item->catid]->alias; // add tags $data['tags'] = isset($tags[$item->id]) ? $tags[$item->id] : array(); // add item content $i = 0; $data['elements'][$i]['type'] = 'textarea'; $data['elements'][$i]['name'] = 'content'; $data['elements'][$i++]['data'] = array(array('value' => $item->introtext), array('value' => $item->fulltext)); $data['elements'][$i]['type'] = 'image'; $data['elements'][$i]['name'] = 'image'; $data['elements'][$i++]['data'] = array('file' => 'media/k2/items/src/' . md5("Image" . $item->id) . '.jpg'); // add extra fields if (isset($item->extra_fields)) { foreach (json_decode($item->extra_fields) as $element) { $extrafield = $extra_fields[$element->id]; switch ($extrafield->type) { case 'textfield': $data['elements'][$i]['type'] = 'text'; $data['elements'][$i]['name'] = $extrafield->name; $data['elements'][$i++]['data'] = array(array('value' => $element->value)); break; case 'textarea': $data['elements'][$i]['type'] = 'textarea'; $data['elements'][$i]['name'] = $extrafield->name; $data['elements'][$i++]['data'] = array(array('value' => $element->value)); break; case 'select': case 'multipleSelect': $data['elements'][$i]['type'] = 'select'; $data['elements'][$i]['name'] = $extrafield->name; $data['elements'][$i++]['data'] = array('option' => $element->value); break; case 'radio': $data['elements'][$i]['type'] = 'radio'; $data['elements'][$i]['name'] = $extrafield->name; $data['elements'][$i++]['data'] = array('option' => $element->value); break; case 'link': $data['elements'][$i]['type'] = 'link'; $data['elements'][$i]['name'] = $extrafield->name; $data['elements'][$i++]['data'] = array(array('text' => $element->value[0], 'value' => $element->value[1])); break; } } } parent::_addItem($item->title, $item->alias, $group, $data); }
/** * Add an item to the export list * * @param object $article The article to export * @param string $parent Where the article should be inserted into * @param string $group The group in which it should be put into * * @return AppExporterJoomla $this For chaining support * * @since 2.0 */ protected function _addJoomlaItem($article, $parent, $group = 'default') { if ($article->state > 1) { $article->state = 0; } $data = array(); foreach ($this->item_attributes as $attribute) { if (isset($article->{$attribute})) { $data[$attribute] = $article->{$attribute}; } } $metadata = $this->app->parameter->create($article->metadata); $data['metadata'] = array('description' => $article->metadesc, 'keywords' => $article->metakey, 'robots' => $metadata->get('robots'), 'author' => $metadata->get('author')); $data['author'] = ($user = $this->app->user->get($article->created_by)) ? $user->username : $this->app->user->get()->username; if ($article->featured) { $data['categories'][] = '_root'; } $data['categories'][] = $parent; $data['elements'][0]['type'] = 'textarea'; $data['elements'][0]['name'] = 'Article'; $data['elements'][0]['data'] = array(array('value' => $article->introtext), array('value' => $article->fulltext)); parent::_addItem($article->title, $article->alias, $group, $data); }