diff --git a/extensions/webservices/joomla/site.content.1.0.0.php b/extensions/webservices/joomla/site.content.1.0.0.php new file mode 100644 index 00000000..caeb8b4b --- /dev/null +++ b/extensions/webservices/joomla/site.content.1.0.0.php @@ -0,0 +1,154 @@ +createContent($data); + } + + if (isset($data['job_type']) && $data['job_type'] == 'edit') + { + return $this->editContent($data); + } + } + + /** + * @throws Exception + */ + private function createContent($data): string + { + $article = JTable::getInstance('content'); + $article->title = $data['title']; + $article->alias = JFilterOutput::stringURLSafe($data['title']); + $article->introtext = '
'.$data['description'].'
'; + $article->created = JFactory::getDate()->toSQL();; + $article->created_by_alias = $data['user']; + $article->state = 1; + $article->access = 1; + $article->metadata = '{"page_title":"'.$data['title'].'","author":"'.$data['user'].'","robots":""}'; + $article->language = '*'; + + if (!$article->check()) { + throw new Exception($article->getError()); + return false; + } + + if ($article->store(TRUE)) { + + if (isset($data['image']) && $data['image']) + { + $articleId = $article->get('id'); + $imgSrc = $this->checkImages($data['image'], $articleId); + $article->set('introtext', ''.$data['description'].'
' . $imgSrc); + $article->store(); + } + + return json_encode($article->getProperties()); + + }else { + throw new Exception($article->getError()); + return false; + } + } + + /** + * @throws Exception + */ + private function editContent($data): string + { + if (empty($data['article_id'])) + { + return false; + } + + $article = JTable::getInstance('content'); + $id = $data['article_id']; + $imgSrc = ''; + $article->load($id); + $article->set('title', $data['title']); + + if (isset($data['image']) && $data['image']) + { + $imgSrc = $this->checkImages($data['image'], $id); + } + + $article->set('introtext', ''.$data['description'].'
' . $imgSrc); + + if (!$article->store()) { + throw new Exception($article->getError()); + return false; + } + + return json_encode($article->getProperties()); + } + + + private function checkImages($images, $articleId) + { + $imgSrc = ''; + $extTypes = ['gif','jpg','jpe','jpeg','png']; + + foreach ($images as $image) + { + $typeImg = strtolower(explode('/', $image['type'])[1]); + + if (!in_array($typeImg, $extTypes) || $image['error'] != 0) + { + continue; + } + + $imgSrc .= $this->processImages($image, $articleId); + } + + return $imgSrc; + } + + private function processImages($image, $articleId) + { + $path = JPATH_BASE.'/images/aesir/'.$articleId.'/'; + $pathFile = '/images/aesir/'.$articleId.'/'.$image['name']; + + if (!is_dir($path)) { + mkdir($path,0777,true); + } + + if (move_uploaded_file($image['tmp_name'], $path.$image['name'])) + { + return '