Skip to content

Commit 263817f

Browse files
authored
Start webservices integration
1 parent ef1d550 commit 263817f

File tree

9 files changed

+452
-70
lines changed

9 files changed

+452
-70
lines changed
Lines changed: 73 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,73 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<extension type="component" version="3.5" method="upgrade">
3-
<name>com_weblinks</name>
4-
<element>com_weblinks</element>
5-
<author>Joomla! Project</author>
6-
<creationDate>##DATE##</creationDate>
7-
<copyright>(C) 2005 - ##YEAR## Open Source Matters. All rights reserved.</copyright>
8-
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
9-
<authorEmail>[email protected]</authorEmail>
10-
<authorUrl>www.joomla.org</authorUrl>
11-
<version>##VERSION##</version>
12-
<description>COM_WEBLINKS_XML_DESCRIPTION</description>
13-
<scriptfile>script.php</scriptfile>
14-
<namespace path="src">Joomla\Component\Weblinks</namespace>
15-
16-
<install>
17-
<sql>
18-
<file charset="utf8" driver="mysql">sql/install.mysql.sql</file>
19-
<file charset="utf8" driver="postgresql">sql/install.postgresql.sql</file>
20-
</sql>
21-
</install>
22-
<uninstall>
23-
<sql>
24-
<file charset="utf8" driver="mysql">sql/uninstall.mysql.sql</file>
25-
<file charset="utf8" driver="postgresql">sql/uninstall.postgresql.sql</file>
26-
</sql>
27-
</uninstall>
28-
<update>
29-
<schemas>
30-
<schemapath type="mysql">sql/updates/mysql</schemapath>
31-
<schemapath type="postgresql">sql/updates/postgresql</schemapath>
32-
</schemas>
33-
</update>
34-
35-
<media folder="media/com_weblinks" destination="com_weblinks">
36-
##MEDIA_FILES##
37-
</media>
38-
39-
<files folder="components/com_weblinks">
40-
##FRONTEND_COMPONENT_FILES##
41-
</files>
42-
<languages folder="language">
43-
##FRONTEND_LANGUAGE_FILES##
44-
</languages>
45-
<administration>
46-
<menu img="class:weblinks">com_weblinks</menu>
47-
<submenu>
48-
<!--
49-
Note that all & must be escaped to &amp; for the file to be valid
50-
XML and be parsed by the installer
51-
-->
52-
<menu link="option=com_weblinks" view="links" img="class:weblinks"
53-
alt="Weblinks/Links">com_weblinks_links</menu>
54-
<menu link="option=com_categories&amp;extension=com_weblinks"
55-
view="categories" img="class:weblinks-cat" alt="Weblinks/Categories">com_weblinks_categories</menu>
56-
<menu link="option=com_fields&amp;view=fields&amp;context=com_weblinks.weblink"
57-
alt="Weblinks/Fields">com_weblinks_fields</menu>
58-
<menu link="option=com_fields&amp;view=groups&amp;context=com_weblinks.weblink"
59-
alt="Weblinks/Field Groups">com_weblinks_field_groups</menu>
60-
</submenu>
61-
<files folder="administrator/components/com_weblinks">
62-
##BACKEND_COMPONENT_FILES##
63-
</files>
64-
<languages folder="administrator/language">
65-
##BACKEND_LANGUAGE_FILES##
66-
</languages>
67-
</administration>
68-
</extension>
69-
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<extension type="component" version="3.5" method="upgrade">
3+
<name>com_weblinks</name>
4+
<element>com_weblinks</element>
5+
<author>Joomla! Project</author>
6+
<creationDate>##DATE##</creationDate>
7+
<copyright>(C) 2005 - ##YEAR## Open Source Matters. All rights reserved.</copyright>
8+
<license>GNU General Public License version 2 or later; see LICENSE.txt</license>
9+
<authorEmail>[email protected]</authorEmail>
10+
<authorUrl>www.joomla.org</authorUrl>
11+
<version>##VERSION##</version>
12+
<description>COM_WEBLINKS_XML_DESCRIPTION</description>
13+
<scriptfile>script.php</scriptfile>
14+
<namespace path="src">Joomla\Component\Weblinks</namespace>
15+
16+
<install>
17+
<sql>
18+
<file charset="utf8" driver="mysql">sql/install.mysql.sql</file>
19+
<file charset="utf8" driver="postgresql">sql/install.postgresql.sql</file>
20+
</sql>
21+
</install>
22+
<uninstall>
23+
<sql>
24+
<file charset="utf8" driver="mysql">sql/uninstall.mysql.sql</file>
25+
<file charset="utf8" driver="postgresql">sql/uninstall.postgresql.sql</file>
26+
</sql>
27+
</uninstall>
28+
<update>
29+
<schemas>
30+
<schemapath type="mysql">sql/updates/mysql</schemapath>
31+
<schemapath type="postgresql">sql/updates/postgresql</schemapath>
32+
</schemas>
33+
</update>
34+
35+
<media folder="media/com_weblinks" destination="com_weblinks">
36+
##MEDIA_FILES##
37+
</media>
38+
39+
<files folder="components/com_weblinks">
40+
##FRONTEND_COMPONENT_FILES##
41+
</files>
42+
<languages folder="language">
43+
##FRONTEND_LANGUAGE_FILES##
44+
</languages>
45+
<administration>
46+
<menu img="class:weblinks">com_weblinks</menu>
47+
<submenu>
48+
<!--
49+
Note that all & must be escaped to &amp; for the file to be valid
50+
XML and be parsed by the installer
51+
-->
52+
<menu link="option=com_weblinks" view="links" img="class:weblinks"
53+
alt="Weblinks/Links">com_weblinks_links</menu>
54+
<menu link="option=com_categories&amp;extension=com_weblinks"
55+
view="categories" img="class:weblinks-cat" alt="Weblinks/Categories">com_weblinks_categories</menu>
56+
<menu link="option=com_fields&amp;view=fields&amp;context=com_weblinks.weblink"
57+
alt="Weblinks/Fields">com_weblinks_fields</menu>
58+
<menu link="option=com_fields&amp;view=groups&amp;context=com_weblinks.weblink"
59+
alt="Weblinks/Field Groups">com_weblinks_field_groups</menu>
60+
</submenu>
61+
<files folder="administrator/components/com_weblinks">
62+
##BACKEND_COMPONENT_FILES##
63+
</files>
64+
<languages folder="administrator/language">
65+
##BACKEND_LANGUAGE_FILES##
66+
</languages>
67+
</administration>
68+
<api>
69+
<files folder="api/components/com_weblinks">
70+
##API_COMPONENT_FILES##
71+
</files>
72+
</api>
73+
</extension>

src/administrator/manifests/packages/pkg_weblinks.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
<file type="plugin" id="weblinks" group="finder">plg_finder_weblinks.zip</file>
2222
<file type="plugin" id="weblinks" group="search">plg_search_weblinks.zip</file>
2323
<file type="plugin" id="weblinks" group="system">plg_system_weblinks.zip</file>
24-
<file type="plugin" id="weblink" group="editors-xtd">plg_editors-xtd_weblink.zip</file>
24+
<file type="plugin" id="weblinks" group="editors-xtd">plg_editors-xtd_weblink.zip</file>
25+
<file type="plugin" id="weblinks" group="webservices">plg_webservices_weblinks.zip</file>
2526
</files>
2627
<languages folder="language">
2728
<language tag="en-GB">en-GB/pkg_weblinks.sys.ini</language>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.API
5+
* @subpackage com_weblinks
6+
*
7+
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
namespace Joomla\Component\Weblinks\Api\Controller;
12+
13+
use Joomla\CMS\MVC\Controller\ApiController;
14+
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
15+
16+
// phpcs:disable PSR1.Files.SideEffects
17+
\defined('_JEXEC') or die;
18+
// phpcs:enable PSR1.Files.SideEffects
19+
20+
/**
21+
* The weblinks controller
22+
*
23+
* @since 4.0.0
24+
*/
25+
class WeblinksController extends ApiController
26+
{
27+
/**
28+
* The content type of the item.
29+
*
30+
* @var string
31+
* @since 4.0.0
32+
*/
33+
protected $contentType = 'weblinks';
34+
35+
/**
36+
* The default view for the display method.
37+
*
38+
* @var string
39+
* @since 3.0
40+
*/
41+
protected $default_view = 'weblinks';
42+
43+
/**
44+
* Method to save a record.
45+
*
46+
* @param integer $recordKey The primary key of the item (if exists)
47+
*
48+
* @return integer The record ID on success, false on failure
49+
*
50+
* @since 4.0.0
51+
*/
52+
protected function save($recordKey = null)
53+
{
54+
$data = (array) json_decode($this->input->json->getRaw(), true);
55+
56+
foreach (FieldsHelper::getFields('com_weblinks.weblink') as $field) {
57+
if (isset($data[$field->name])) {
58+
!isset($data['com_fields']) && $data['com_fields'] = [];
59+
60+
$data['com_fields'][$field->name] = $data[$field->name];
61+
unset($data[$field->name]);
62+
}
63+
}
64+
65+
$this->input->set('data', $data);
66+
67+
return parent::save($recordKey);
68+
}
69+
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
<?php
2+
3+
/**
4+
* @package Joomla.API
5+
* @subpackage com_weblinks
6+
*
7+
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
8+
* @license GNU General Public License version 2 or later; see LICENSE.txt
9+
*/
10+
11+
namespace Joomla\Component\Weblinks\Api\View\Weblinks;
12+
13+
use Joomla\CMS\MVC\View\JsonApiView as BaseApiView;
14+
use Joomla\Component\Fields\Administrator\Helper\FieldsHelper;
15+
16+
// phpcs:disable PSR1.Files.SideEffects
17+
\defined('_JEXEC') or die;
18+
// phpcs:enable PSR1.Files.SideEffects
19+
20+
/**
21+
* The weblinks view
22+
*
23+
* @since 4.0.0
24+
*/
25+
class JsonApiView extends BaseApiView
26+
{
27+
/**
28+
* The fields to render item in the documents
29+
*
30+
* @var array
31+
* @since 4.0.0
32+
*/
33+
protected $fieldsToRenderItem = [
34+
'id',
35+
'catid',
36+
'title',
37+
'alias',
38+
'url',
39+
'description',
40+
'hits',
41+
'state',
42+
'checked_out',
43+
'checked_out_time',
44+
'ordering',
45+
'access',
46+
'params',
47+
'language',
48+
'created',
49+
'created_by',
50+
'created_by_alias',
51+
'modified',
52+
'modified_by',
53+
'metakey',
54+
'metadesc',
55+
'metadata',
56+
'featured',
57+
'xreference',
58+
'publish_up',
59+
'publish_down',
60+
'version',
61+
'images',
62+
'tags',
63+
];
64+
65+
/**
66+
* The fields to render items in the documents
67+
*
68+
* @var array
69+
* @since 4.0.0
70+
*/
71+
protected $fieldsToRenderList = [
72+
'id',
73+
'title',
74+
'alias',
75+
'checked_out',
76+
'checked_out_time',
77+
'catid',
78+
'created',
79+
'created_by',
80+
'hits',
81+
'state',
82+
'access',
83+
'ordering',
84+
'language',
85+
'publish_up',
86+
'publish_down',
87+
'language_title',
88+
'language_image',
89+
'editor',
90+
'access_level',
91+
'category_title',
92+
];
93+
94+
/**
95+
* Execute and display a template script.
96+
*
97+
* @param array|null $items Array of items
98+
*
99+
* @return string
100+
*
101+
* @since 4.0.0
102+
*/
103+
public function displayList(?array $items = null)
104+
{
105+
foreach (FieldsHelper::getFields('com_weblinks.weblink') as $field) {
106+
$this->fieldsToRenderList[] = $field->name;
107+
}
108+
109+
return parent::displayList();
110+
}
111+
112+
/**
113+
* Execute and display a template script.
114+
*
115+
* @param object $item Item
116+
*
117+
* @return string
118+
*
119+
* @since 4.0.0
120+
*/
121+
public function displayItem($item = null)
122+
{
123+
foreach (FieldsHelper::getFields('com_weblinks.weblink') as $field) {
124+
$this->fieldsToRenderItem[] = $field->name;
125+
}
126+
127+
return parent::displayItem();
128+
}
129+
130+
/**
131+
* Prepare item before render.
132+
*
133+
* @param object $item The model item
134+
*
135+
* @return object
136+
*
137+
* @since 4.0.0
138+
*/
139+
protected function prepareItem($item)
140+
{
141+
foreach (FieldsHelper::getFields('com_weblinks.weblink', $item, true) as $field) {
142+
$item->{$field->name} = isset($field->apivalue) ? $field->apivalue : $field->rawvalue;
143+
}
144+
145+
return parent::prepareItem($item);
146+
}
147+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
; Joomla! Project
2+
; Copyright (C) 2005 - 2019 Open Source Matters. All rights reserved.
3+
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
4+
; Note : All ini files need to be saved as UTF-8
5+
6+
PLG_WEBSERVICES_WEBLINKS="Web Services - Weblinks"
7+
PLG_WEBSERVICES_WEBLINKS_XML_DESCRIPTION="Used to add weblinks routes to the API for your website."
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
; Joomla! Project
2+
; Copyright (C) 2005 - 2019 Open Source Matters. All rights reserved.
3+
; License GNU General Public License version 2 or later; see LICENSE.txt, see LICENSE.php
4+
; Note : All ini files need to be saved as UTF-8
5+
6+
PLG_WEBSERVICES_WEBLINKS="Web Services - Weblinks"
7+
PLG_WEBSERVICES_WEBLINKS_XML_DESCRIPTION="Used to add weblinks routes to the API for your website."

0 commit comments

Comments
 (0)