Project

General

Profile

1
<?php
2

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

    
5
jimport('joomla.application.component.view');
6
jimport('joomla.environment.request');
7
jimport('joomla.log.log');
8

    
9
class OpenAireViewClaim4 extends JView {
10
	const CLAIM = 'claim';
11
	const SEARCH = 'search';
12
	const PIWIK = 'piwik';
13
	const SUBMIT = 'submit';
14
	const LOG = 'openaire';
15
	
16
	function display($template = NULL) {
17
		$this -> itemId = JRequest :: getUInt('Itemid', 0);
18
		$application = JFactory :: getApplication();
19
		$user = JFactory :: getUser();
20
 		$claim = $this -> getModel(self :: CLAIM);
21
		$search = $this -> getModel(self :: SEARCH);
22
		$piwik = $this -> getModel(self :: PIWIK);
23
		$locale = JFactory :: getLanguage() -> getTag();
24
		if ($user-> guest) {
25
			$application -> redirect(JRoute :: _('index.php?option=com_users&view=login&return=' . base64_encode(JRoute :: _('index.php?option=com_openaire&view=claim4&Itemid=' . $this -> itemId, FALSE)), FALSE));
26
			return TRUE;
27
		}
28
		if (JRequest :: getString('action') == self :: SUBMIT) {
29
			$data = '';
30
			foreach ($claim -> getSelectedPublications() as $publication) {
31
				if(JRequest :: getString($this -> escapeHttpParameter($publication -> source . '-' . $publication -> id . '-license'))!=null){
32
					$publication -> license = JRequest :: getString($this -> escapeHttpParameter($publication -> source . '-' . $publication -> id . '-license'));				
33
					$publication -> embargoEndDate = JRequest :: getString($this -> escapeHttpParameter( 'embargoEndDate-' . $publication -> id ));
34
					$claim -> removeSelectedPublication($publication -> source, $publication -> id);
35
					$claim -> addSelectedPublication($publication);
36
				}
37
				
38
				$data .= '&source=' . urlencode($publication -> source) . '&id=' . urlencode($publication -> id) . '&license=' . urlencode($publication -> license) . '&embargo=' . urlencode($publication -> embargoEndDate);
39
			}
40
			foreach ($claim -> getSelectedProjects() as $project)
41
			$data .= '&project=' . $project -> id;
42
			$data = substr($data, 1); // get rid of the firs ampersand
43
			$piwik -> track('claimPublications', $data);
44
			$claim -> claimSelectedPublications($user);
45
			$application -> redirect(JRoute :: _('index.php?option=com_openaire&view=claim4&Itemid=' . $this -> itemId, FALSE));
46
			return TRUE;
47
		}
48
		JView :: loadHelper('PiwikHelper');
49
		PiwikHelper :: logPageView('viewClaims', '');
50
		$claimedPublications = $claim -> getClaimedPublications($user);
51
		if ($claimedPublications === NULL)
52
			$this -> claimedPublications = NULL;
53
		else {
54
			$this -> claimedPublications = array();
55
			foreach ($claimedPublications as $claimedPublication) {
56
				$claimed = $claimedPublication;
57
				$claimed -> publication = ($claimedPublication -> publication === NULL) ? $search -> getPublication($claimedPublication -> publicationId, $locale) : $claimedPublication -> publication;
58
				$this -> claimedPublications[] = $claimed;
59
			}
60
			usort($this -> claimedPublications, function ($claim1, $claim2) {return $claim1 -> date - $claim2 -> date;});
61
		}
62
		if (count($errors = $this -> get('Errors')) > 0) {
63
			JLog :: add('Error viewing claim4: ' . implode("\n", $errors), JLog :: ERROR, self :: LOG);
64
			return FALSE;
65
		}
66
		parent :: display($template);
67
	}
68
	
69
	private function escapeHttpParameter($name) {
70
		$illegalChars = array(chr(32), chr(46), chr(91), chr(128), chr(129), chr(130), chr(131), chr(132), chr(133), chr(134), chr(135), chr(136), chr(137), chr(138), chr(139),
71
				chr(140), chr(141), chr(142), chr(143), chr(144), chr(145), chr(146), chr(147), chr(148), chr(149), chr(150), chr(151), chr(152), chr(153), chr(154),
72
				chr(155), chr(156), chr(157), chr(158), chr(159));
73
		return str_replace($illegalChars, array_fill(0, count($illegalChars), '_'), $name);
74
	}
75
}
76

    
(2-2/2)