@@ -31,6 +31,54 @@ function register($category, $path, $mainContextId = null) {
3131 new InlineHtmlGalleyBlockPlugin ($ this ->getName (), $ this ->getPluginPath ()),
3232 $ this ->getPluginPath ()
3333 );
34+ $ this ->import ('InlineHtmlGalleySidebarBlockPlugin ' );
35+ PluginRegistry::register (
36+ 'blocks ' ,
37+ new InlineHtmlGalleyAuthorsSidebarBlockPlugin ($ this ->getName (), $ this ->getPluginPath ()),
38+ $ this ->getPluginPath ()
39+ );
40+ PluginRegistry::register (
41+ 'blocks ' ,
42+ new InlineHtmlGalleyKeywordsSidebarBlockPlugin ($ this ->getName (), $ this ->getPluginPath ()),
43+ $ this ->getPluginPath ()
44+ );
45+ PluginRegistry::register (
46+ 'blocks ' ,
47+ new InlineHtmlGalleyDoiSidebarBlockPlugin ($ this ->getName (), $ this ->getPluginPath ()),
48+ $ this ->getPluginPath ()
49+ );
50+ PluginRegistry::register (
51+ 'blocks ' ,
52+ new InlineHtmlGalleyCoverImageSidebarBlockPlugin ($ this ->getName (), $ this ->getPluginPath ()),
53+ $ this ->getPluginPath ()
54+ );
55+ PluginRegistry::register (
56+ 'blocks ' ,
57+ new InlineHtmlGalleyPublishedDateSidebarBlockPlugin ($ this ->getName (), $ this ->getPluginPath ()),
58+ $ this ->getPluginPath ()
59+ );
60+ PluginRegistry::register (
61+ 'blocks ' ,
62+ new InlineHtmlGalleyHowToCiteSidebarBlockPlugin ($ this ->getName (), $ this ->getPluginPath ()),
63+ $ this ->getPluginPath ()
64+ );
65+ PluginRegistry::register (
66+ 'blocks ' ,
67+ new InlineHtmlGalleyLicenseSidebarBlockPlugin ($ this ->getName (), $ this ->getPluginPath ()),
68+ $ this ->getPluginPath ()
69+ );
70+ PluginRegistry::register (
71+ 'blocks ' ,
72+ new InlineHtmlGalleyReferencesSidebarBlockPlugin ($ this ->getName (), $ this ->getPluginPath ()),
73+ $ this ->getPluginPath ()
74+ );
75+ PluginRegistry::register (
76+ 'blocks ' ,
77+ new InlineHtmlGalleyGalleysSidebarBlockPlugin ($ this ->getName (), $ this ->getPluginPath ()),
78+ $ this ->getPluginPath ()
79+ );
80+ HookRegistry::register ('ArticleHandler::view ' , array ($ this , 'articleViewCallback ' ), HOOK_SEQUENCE_LATE );
81+ HookRegistry::register ('TemplateResource::getFilename ' , array ($ this , '_overridePluginTemplates ' ), HOOK_SEQUENCE_CORE );
3482 }
3583
3684 return true ;
@@ -57,24 +105,30 @@ function getDescription() {
57105 * @param array $args
58106 */
59107 function articleViewCallback ($ hookName , $ args ) {
60- $ request =& $ args [0 ];
61- $ issue =& $ args [1 ];
62- $ galley =& $ args [2 ];
63- $ article =& $ args [3 ];
108+ if ($ hookName == "ArticleHandler::view " ) {
109+ $ request =& $ args [0 ];
110+ $ issue =& $ args [1 ];
111+ $ article =& $ args [2 ];
112+ $ galleys = $ article ->getGalleys ();
113+ if (!$ galleys ) return false ;
64114
65- if ($ galley && $ galley ->getFileType () == 'text/html ' ) {
66- $ templateMgr = TemplateManager::getManager ($ request );
67- $ templateMgr ->assign (array (
68- 'issue ' => $ issue ,
69- 'article ' => $ article ,
70- 'galley ' => $ galley ,
71- ));
72- $ inlineHtmlGalley = $ this ->_getHTMLContents ($ request , $ galley );
73- $ inlineHtmlGalleyBody = $ this ->_extractBodyContents ($ inlineHtmlGalley );
74- $ templateMgr ->assign ('inlineHtmlGalley ' , $ inlineHtmlGalleyBody );
75- $ templateMgr ->display ($ this ->getTemplateResource ('displayInline.tpl ' ));
115+ foreach ($ galleys as $ galley ) {
116+ if ($ galley ->getFileType () == 'text/html ' ) {
117+ $ templateMgr = TemplateManager::getManager ($ request );
118+ $ templateMgr ->assign (array (
119+ 'issue ' => $ issue ,
120+ 'article ' => $ article ,
121+ 'galley ' => $ galley ,
122+ 'orcidIcon ' => $ this ->getOrcidIcon ()
123+ ));
124+ $ inlineHtmlGalley = $ this ->_getHTMLContents ($ request , $ galley );
125+ $ inlineHtmlGalleyBody = $ this ->_extractBodyContents ($ inlineHtmlGalley , $ request ->getContext ()->getId ());
126+ $ templateMgr ->assign ('inlineHtmlGalley ' , $ inlineHtmlGalleyBody );
127+ $ templateMgr ->display ($ this ->getTemplateResource ('displayInline.tpl ' ));
76128
77- return true ;
129+ return true ;
130+ }
131+ }
78132 }
79133
80134 return false ;
@@ -83,23 +137,33 @@ function articleViewCallback($hookName, $args) {
83137 /**
84138 * Return string containing the contents of the HTML body
85139 * @param $html string
140+ * @param $contextId int
86141 * @return string
87142 */
88- function _extractBodyContents ($ html ) {
143+ function _extractBodyContents ($ html, $ contextId ) {
89144 $ bodyContent = '' ;
90145 try {
91- if (!function_exists ('libxml_use_internal_errors ' ) || !class_exists ('DOMDocument ' )) {
146+ if (!function_exists ('libxml_use_internal_errors ' ) || !class_exists ('DOMDocument ' ) || ! class_exists ( ' DOMXPath ' ) ) {
92147 throw new Exception ('Missing libxml/dom requirements ' );
93148 }
94149 $ errorsEnabled = libxml_use_internal_errors ();
95150 libxml_use_internal_errors (true );
96151 $ dom = DOMDocument::loadHTML ($ html );
97- $ tags = $ dom ->getElementsByTagName ('body ' );
98- foreach ($ tags as $ body ) {
99- foreach ($ body ->childNodes as $ child ) {
100- $ bodyContent .= $ dom ->saveHTML ($ child );
152+ $ xpath = $ this ->getSetting ($ contextId , 'xpath ' );
153+ if (empty ($ xpath )) {
154+ $ tags = $ dom ->getElementsByTagName ('body ' );
155+ foreach ($ tags as $ body ) {
156+ foreach ($ body ->childNodes as $ child ) {
157+ $ bodyContent .= $ dom ->saveHTML ($ child );
158+ }
159+ last;
160+ }
161+ } else {
162+ $ domXpath = new DOMXPath ($ dom );
163+ $ tags = $ domXpath ->query ($ xpath );
164+ foreach ($ tags as $ tag ) {
165+ $ bodyContent .= $ dom ->saveHTML ($ tag );
101166 }
102- last;
103167 }
104168 libxml_use_internal_errors ($ errorsEnabled );
105169 } catch (Exception $ e ) {
@@ -109,4 +173,57 @@ function _extractBodyContents($html) {
109173 }
110174 return $ bodyContent ;
111175 }
176+
177+ /**
178+ * Return a string of the ORCiD SVG icon
179+ *
180+ * @return string
181+ */
182+ function getOrcidIcon () {
183+ $ path = Core::getBaseDir () . '/ ' . $ this ->getPluginPath () . '/templates/images/orcid.svg ' ;
184+ return file_exists ($ path ) ? file_get_contents ($ path ) : '' ;
185+ }
186+
187+ /**
188+ * @copydoc Plugin::manage()
189+ */
190+ function manage ($ args , $ request ) {
191+ $ this ->import ('InlineHtmlGalleySettingsForm ' );
192+ if ($ request ->getUserVar ('verb ' ) == 'settings ' ) {
193+ $ settingsForm = new InlineHtmlGalleySettingsForm ($ this , $ request ->getContext ()->getId ());
194+ if ($ request ->getUserVar ('save ' )) {
195+ $ settingsForm ->readInputData ();
196+ if ($ settingsForm ->validate ()) {
197+ $ settingsForm ->execute ();
198+ return new JSONMessage (true );
199+ }
200+ } else {
201+ $ settingsForm ->initData ();
202+ }
203+ return new JSONMessage (true , $ settingsForm ->fetch ($ request ));
204+ }
205+ return parent ::manage ($ args , $ request );
206+ }
207+
208+ /**
209+ * @copydoc Plugin::getActions()
210+ */
211+ function getActions ($ request , $ verb ) {
212+ $ router = $ request ->getRouter ();
213+ import ('lib.pkp.classes.linkAction.request.AjaxModal ' );
214+ return array_merge (
215+ $ this ->getEnabled ()?array (
216+ new LinkAction (
217+ 'settings ' ,
218+ new AjaxModal (
219+ $ router ->url ($ request , null , null , 'manage ' , null , array ('verb ' => 'settings ' , 'plugin ' => $ this ->getName (), 'category ' => 'generic ' )),
220+ $ this ->getDisplayName ()
221+ ),
222+ __ ('manager.plugins.settings ' ),
223+ null
224+ ),
225+ ):array (),
226+ parent ::getActions ($ request , $ verb )
227+ );
228+ }
112229}
0 commit comments