Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
AddThisStatisticsGridHandler.inc.php
1 <?php
2 
16 // import grid base classes
17 import('lib.pkp.classes.controllers.grid.GridHandler');
18 
21  var $_plugin;
22 
26  function AddThisStatisticsGridHandler($plugin) {
27  parent::GridHandler();
28  $this->addRoleAssignment(
29  array(ROLE_ID_MANAGER),
30  array('fetchGrid', 'fetchRow'));
31 
32  $this->setPlugin($plugin);
33  }
34 
35 
36  //
37  // Getters/Setters
38  //
43  function getPlugin() {
44  return $this->_plugin;
45  }
46 
51  function setPlugin($plugin) {
52  $this->_plugin = $plugin;
53  }
54 
55  //
56  // Overridden methods from PKPHandler
57  //
64  function authorize($request, &$args, $roleAssignments) {
65  import('lib.pkp.classes.security.authorization.PkpContextAccessPolicy');
66  $this->addPolicy(new PkpContextAccessPolicy($request, $roleAssignments));
67  return parent::authorize($request, $args, $roleAssignments);
68  }
69 
74  function initialize($request) {
75  parent::initialize($request);
76 
77  // Load submission-specific translations
79  LOCALE_COMPONENT_PKP_SUBMISSION,
80  LOCALE_COMPONENT_PKP_USER,
81  LOCALE_COMPONENT_APP_DEFAULT,
82  LOCALE_COMPONENT_PKP_DEFAULT
83  );
84 
85  $plugin = $this->getPlugin();
86  $plugin->addLocaleData();
87 
88  // Basic grid configuration
89 
90  $this->setTitle('plugins.generic.addThis.grid.title');
91 
92  // Columns
93  $plugin->import('AddThisStatisticsGridCellProvider');
94  $cellProvider = new AddThisStatisticsGridCellProvider();
95  $gridColumn = new GridColumn(
96  'url',
97  'common.url',
98  null,
99  'controllers/grid/gridCell.tpl',
100  $cellProvider,
101  array('width' => 50, 'alignment' => COLUMN_ALIGNMENT_LEFT)
102  );
103 
104  $gridColumn->addFlag('html', true);
105 
106  $this->addColumn($gridColumn);
107 
108  $this->addColumn(
109  new GridColumn(
110  'shares',
111  'plugins.generic.addThis.grid.shares',
112  null,
113  'controllers/grid/gridCell.tpl',
114  $cellProvider
115  )
116  );
117  }
118 
119 
120  //
121  // Overridden methods from GridHandler
122  //
127  function getRowInstance() {
128  $plugin = $this->getPlugin();
129  $plugin->import('AddThisStatisticsGridRow');
131  }
132 
136  function loadData($request, $filter = null) {
137  $plugin = $this->getPlugin();
138  $press = $request->getPress();
140  $addThisProfileId = $press->getSetting('addThisProfileId');
141  $addThisUsername = $press->getSetting('addThisUsername');
142  $addThisPassword = $press->getSetting('addThisPassword');
143 
144  $data = array();
145 
146  if (isset($addThisProfileId) && isset($addThisUsername) && isset($addThisPassword)) {
147  $topSharedUrls = 'https://api.addthis.com/analytics/1.0/pub/shares/url.json?period=week&pubid='.urlencode($addThisProfileId).
148  '&username='.urlencode($addThisUsername).
149  '&password='.urlencode($addThisPassword);
150 
151  import('lib.pkp.classes.file.FileWrapper');
152  $wrapper = FileWrapper::wrapper($topSharedUrls);
153  $jsonData = $wrapper->contents();
154 
155  if ($jsonData != '') {
156  $jsonMessage = json_decode($jsonData);
157  foreach ($jsonMessage as $statElement) {
158  $data[] = array('url' => $statElement->url, 'shares' => $statElement->shares);
159  }
160  }
161  }
162  return $data;
163  }
164 }
165 
166 ?>
addPolicy($authorizationPolicy, $addToTop=false)
static requireComponents()
addColumn($column)
Class defining basic operations for handling HTML grids.
Base class for a cell provider that can retrieve labels for AddThis stats.
AddThis statistics grid row definition.
Class to control access to PKP applications&#39; setup components.
addRoleAssignment($roleIds, $operations)
authorize($request, &$args, $roleAssignments)
Handle addThis plugin requests for statistics.
Represents a column within a grid. It is used to configure the way cells within a column are displaye...
static & wrapper($source)