Project

General

Profile

1
<?php
2

    
3
defined('_JEXEC') or die('Access denied');
4

    
5
jimport('joomla.methods');
6

    
7
// This helper _formats publications.
8
abstract class PublicationHelper {
9
	const OPENAIRE = 'openaire';
10
	const MAX_AUTHORS = 15;
11
	const MAX_PROJECTS = 15;
12
	const MAX_DESCRIPTION = 500;
13
	const SUFFIX = '...';
14
	const OPEN_ACCESS = 'OPEN';
15
	const CLOSED_ACCESS = 'CLOSED';
16
	const RESTRICTED_ACCESS = 'RESTRICTED';
17
	const EMBARGO_ACCESS = 'EMBARGO';
18
	
19
	// Format a publication.
20
	// $publication the publication to format
21
	// $itemId the item ID to use for internal links
22
	// return a string containing the full HTML for the publication or an empty string if any errors occur
23
	public static function formatPublication($publication, $itemId) {
24
		if ($publication == NULL)
25
			return '';
26
                //:: _formatTrustMeter($publication).PublicationHelper 
27
		$publication = PublicationHelper :: _formatTitle(htmlspecialchars($publication -> title), $publication -> accessMode, $publication -> id, $publication -> source, $publication -> url, $itemId, 
28
                        isset($publication -> inferred)?$publication -> inferred:false, 
29
                        isset($publication -> trust)?$publication -> trust:"", 
30
                        isset($publication -> provenance)?$publication -> provenance:"") . PublicationHelper :: _formatData($publication, $itemId).  PublicationHelper :: _formatDescription($publication -> description);
31
		return ($publication == NULL) ? '' : ('<div class="srchRow">' . $publication . '</div>');
32
	}
33
	
34
	public static function _formatTitle($title, $accessMode, $id, $source, $url, $itemId, $inferred = false, $trust = "", $provenance = "") {
35
		switch ($accessMode) {
36
		case PublicationHelper :: OPEN_ACCESS:
37
			$accessModeClass = 'openAccess';
38
			$accessModeTitle = JText :: _('OPEN_ACCESS');
39
			break;
40
		case PublicationHelper :: EMBARGO_ACCESS:
41
			$accessModeClass = 'embargoAccess';
42
			$accessModeTitle = JText :: _('EMBARGO_ACCESS');
43
			break;
44
		case PublicationHelper :: RESTRICTED_ACCESS:
45
			$accessModeClass = 'restrictedAccess';
46
			$accessModeTitle = JText :: _('RESTRICTED_ACCESS');
47
			break;
48
		case PublicationHelper :: CLOSED_ACCESS:
49
			$accessModeClass = 'closedAccess';
50
			$accessModeTitle = JText :: _('CLOSED_ACCESS');
51
			break;
52
		default:
53
			$accessModeClass = NULL;
54
			$accessModeTitle = NULL;
55
		}
56
		//return ($title == NULL) ? '' : ('<h4' . (($accessModeClass == NULL) ? '' : (' class="' . $accessModeClass . '" title="' . $accessModeTitle . '"')) . '>' . (($source == self :: OPENAIRE) ? (($id == NULL) ? '' : ('<a href="' . JRoute :: _(JUri :: base() . 'index.php?option=com_openaire&view=article&Itemid=' . $itemId . '&articleId=' . $id) . '">')) : (($url == NULL) ? '' : ('<a target="_blank" class="icon-external" href="' . $url . '">'))) . $title . (($source == self :: OPENAIRE) ? (($id == NULL) ? '' : ('</a>')) : (($url == NULL) ? '' : ('</a>'))) . ($inferred == true?" <span class='inferred'><img src='templates/yoo_solar/styles/openaire/images/box_info_ok.png' /></span><div style='display: none'><div class='inferred-popup' id='popup-". $id. "'>trust: $trust, provenance: $provenance </div></div>" :"") . '</h4>');
57
		return ($title == NULL) ? '' : ('<h4' . (($accessModeClass == NULL) ? '' : (' class="' . $accessModeClass . '" title="' . $accessModeTitle . '"')) . '>' . (($source == self :: OPENAIRE) ? (($id == NULL) ? '' : ('<a href="' . JRoute :: _('index.php?option=com_openaire&view=article&Itemid=' . $itemId . '&articleId=' . $id) . '">')) : (($url == NULL) ? '' : ('<a target="_blank" class="icon-external" href="' . $url . '">'))) . $title . (($source == self :: OPENAIRE) ? (($id == NULL) ? '' : ('</a>')) : (($url == NULL) ? '' : ('</a>')))  . '</h4>');
58
	}
59
	
60
	public static function formatTrustMeter($publication) {
61
		if ($publication == NULL)
62
			return '';
63
		if ( property_exists($publication,'similarity')){
64
			if ( $publication->similarity!=null){
65
				$similarity=$publication -> similarity*100;
66
				return '<span  style=" display: none; ">'  .($similarity<10?'0':'').$similarity.'</span> 	<div title="'.($publication -> similarity*100).'%" style="width:80%;" class="uk-progress"><div class="uk-progress-bar" style="width: '.($publication -> similarity*100).'%;">&nbsp;</div></div>';
67
			}
68
		}
69
		return '';
70
	}
71
	public static function _formatData($publication, $itemId) {
72
		if ($publication == NULL)
73
			return '';
74
		$authors = PublicationHelper :: _formatAuthors($publication -> authors, $itemId);
75
		$year = PublicationHelper :: _formatYear($publication -> year);
76
		$data = array();
77
		$data[] = $authors . ((($authors == NULL) || ($year == NULL)) ? '' : ' ') . $year;
78
		$data[] = PublicationHelper :: _formatProjects($publication -> projects, $itemId);
79
		$data[] = PublicationHelper :: _formatEmbargoEndDate($publication -> embargoEndDate);
80
		$data = array_filter($data);
81
		return ($data == NULL) ? '' : ('<div class="biblio">' . implode('<br />', $data) . '</div>');
82
	}
83
	public static function _formatAuthors($authors, $itemId) {
84
		$authors = ($authors == NULL) ? NULL : array_filter(array_map(function ($author) use ($itemId) {return PublicationHelper :: _formatAuthor($author, $itemId);}, $authors));
85
		return ($authors == NULL) ? '' : (implode('; ',  array_slice($authors, 0, PublicationHelper :: MAX_AUTHORS)) . ((count($authors) > PublicationHelper :: MAX_AUTHORS) ? ';...' : ''));
86
	}
87
	
88
	public static function _formatAuthor($author, $itemId) {
89
		return (($author == NULL) || ((($author -> lastName == NULL) || ($author -> firstName == NULL)) && ($author -> fullName == NULL))) ? '' : ('<span class="auth">' . (($author -> id == NULL) ? '' : ('<a href="' . JRoute :: _('index.php?option=com_openaire&view=person&Itemid=' . $itemId . '&personId=' . $author -> id) . '">')) . ((($author -> lastName == NULL) || ($author -> firstName == NULL)) ? $author -> fullName : ($author -> lastName . ', ' . $author -> firstName)) . (($author -> id == NULL) ? '' : '</a>') . '</span>');
90
	}
91
	
92
	public static function _formatYear($year) {
93
		return ($year == NULL) ? '' : ('<span class="year">(' . $year . ')</span>');
94
	}
95
	
96
	public static function _formatProjects($projects, $itemId) {
97
		$projects = ($projects == NULL) ? NULL : array_filter(array_map(function ($project) use ($itemId) {return PublicationHelper :: _formatProject($project, $itemId);}, $projects));
98
		return ($projects == NULL) ? '' : (JText :: _('PROJECTS_') . '&nbsp;' . implode(', ', array_slice($projects, 0, PublicationHelper :: MAX_PROJECTS)) . ((count($projects) > PublicationHelper :: MAX_PROJECTS) ? ',...' : ''));
99
	}
100
	
101
	public static function _formatProject($project, $itemId) {
102
		return (($project -> acronym == NULL) && ($project -> title == NULL)) ? '' : ('<span class="proj">' . (($project -> id  == NULL) ? '' : ('<a href="' . JRoute :: _(JUri :: base() . 'index.php?option=com_openaire&view=project&Itemid=' . $itemId . '&projectId=' . $project -> id) . '">')) . (($project -> acronym == NULL) ? $project -> title : $project -> acronym) . (($project -> code == NULL) ? '' : (' (' . $project -> code . ')')) . (($project -> id == NULL) ? '' : '</a>') . '</span>');
103
	}
104
	
105
	public static function _formatEmbargoEndDate($embargoEndDate) {
106
		return ($embargoEndDate == NULL) ? '' : ('<span class="dchdr">'.JText :: _('EMBARGO_END_DATE_') . '&nbsp;</span><span class="embargoDate">' . date(JText :: _('DATE_FORMAT'), $embargoEndDate) . '</span>');
107
	}
108
	
109
	public static function _formatDescription($description) {
110
                $description= ($description == NULL) ? '' : strip_tags($description);
111
        return ($description == NULL) ? '' : ('<div class="description">' . ((strlen($description) > PublicationHelper :: MAX_DESCRIPTION) ? (substr($description, 0, PublicationHelper :: MAX_DESCRIPTION - strlen(PublicationHelper :: SUFFIX)) . PublicationHelper :: SUFFIX) : $description) . '</div>');	
112
	}
113
	
114
	public static function formatCitationLinks($citation) {
115
		if(sizeof($citation -> ids)==0){
116
			return '<h5>'.$citation -> title.'</h5>';													
117
		}else{			
118
			$citationId=$citation -> ids[0];
119
			 if (sizeof($citation -> ids)>1){
120
				usort($citation -> ids, function ($a, $b) {if ($a->confidenceLevel == $b->confidenceLevel) {return 0;}return ($a->confidenceLevel > $b->confidenceLevel) ? -1 : 1;});
121
				$citationId=$citation -> ids[0];
122
			}  														 
123
			$link = '<h5>'.$citation -> title.'</h5>';														 
124
			if(strcmp($citationId -> type,'openaire')==0){
125
				$link ='<h5><a href="'. JUri :: base() . 'index.php?option=com_openaire&view=article&articleId='.$citationId->id.'">'.$citation -> title.'</a></h5>';
126
			}else if(strcmp($citationId -> type,"pmid")==0){
127
				$link ='<h5><a target="_blank" class="icon-external" href="http://www.ncbi.nlm.nih.gov/pubmed/'.$citationId->id.'">'.$citation -> title.'</a></h5>';															 
128
			}else if(strcmp($citationId -> type,"pmcid")==0){
129
				$link ='<h5><a target="_blank" class="icon-external" href="http://europepmc.org/articles/'.$citationId->id.'">'.$citation -> title.'</a></h5>';															 
130
			}else if(strcmp($citationId -> type,"arxiv")==0){
131
				$link ='<h5><a target="_blank" class="icon-external" href="http://arxiv.org/abs/'.$citationId->id.'">'.$citation -> title.'</a></h5>';															 
132
			}else if(strcmp($citationId -> type,"doi")==0){
133
				$link ='<h5><a target="_blank" class="icon-external" href="http://dx.doi.org/'.$citationId->id.'">'.$citation -> title.'</a></h5>';															 
134
			}
135
/*pmid	15558770
136
doi	4821630
137
other	380750
138
medline	22244
139
pii	8982
140
publisher-id	8382
141
pmcid	5107
142
coden	335
143
rrn	19
144
art-access-id	2
145
doaj	1
146
arxiv*/
147
			
148
			//TODO add the rest id types
149
			return $link; 														 	
150
		}				
151
	}
152
	
153
}
154

    
(14-14/15)