Open Monograph Press  3.3.0
Ithenticate.php
1 <?php
2 
4 
5 /*
6  * Using needed classes from PhpXmlRpc library.
7  */
11 
13 {
14  /*
15  * This property is for ithenticate API Url.
16  */
17  private $url;
18  /*
19  * These properties are for storing Ithenticate's API Username and Password.
20  */
21  private $username;
22  private $password;
23  //This property will be filled with the login session hash value returned by Ithenticate's API after logging in.
24  private $sid;
25 
26  /*
27  * Construct method initializes Url, Username, and Password in properties.
28  * It also logs in using login method and puts the login hash session into
29  * the defined property.
30  */
31  public function __construct($username, $password)
32  {
33  $this->setUrl("https://api.ithenticate.com/rpc");
34  $this->setUsername($username);
35  $this->setPassword($password);
36  $this->setSid($this->login());
37  }
38 
39  /*
40  * This is setter method for Ithenticate's API Url.
41  */
42  public function setUrl($url)
43  {
44  if (property_exists($this, 'url')) {
45  $this->url = $url;
46  }
47  }
48 
49  /*
50  * This is setter method for Ithenticate's API Username.
51  */
52  public function setUsername($username)
53  {
54  if (property_exists($this, 'username')) {
55  $this->username = $username;
56  }
57  }
58 
59  /*
60  * This is setter method for Ithenticate's API Password.
61  */
62  public function setPassword($password)
63  {
64  if (property_exists($this, 'password')) {
65  $this->password = $password;
66  }
67  }
68 
69  /*
70  * This is setter method for Ithenticate's responded hash login session.
71  */
72  public function setSid($sid)
73  {
74  if (property_exists($this, "sid")) {
75  $this->sid = $sid;
76  }
77  }
78 
79  /*
80  * This is getter method for Ithenticate's API Url.
81  */
82  public function getUrl()
83  {
84  if (property_exists($this, 'url')) {
85  return $this->url;
86  }
87  }
88 
89  /*
90  * This is getter method for Ithenticate's API Username.
91  */
92  public function getUsername()
93  {
94  if (property_exists($this, 'username')) {
95  return $this->username;
96  }
97  }
98 
99  /*
100  * This is getter method for Ithenticate's API Password.
101  */
102  public function getPassword()
103  {
104  if (property_exists($this, 'password')) {
105  return $this->password;
106  }
107  }
108 
109  /*
110  * This is getter method for Ithenticate's responded hash login session.
111  */
112  public function getSid()
113  {
114  if (property_exists($this, 'sid')) {
115  return $this->sid;
116  }
117  }
118 
119  /*
120  * This method logs into Ithenticate using Username and Password
121  * The return value is Ithenticate's login hash session which will
122  * be used in other methods as the authentication.
123  */
124  private function login()
125  {
126  $client = new Client($this->getUrl());
127  $args = array(
128  'username' => new Value($this->getUsername()),
129  'password' => new Value($this->getPassword())
130  );
131 
132  $response = $client->send(new Request('login', array(new Value($args, "struct"))));
133  $response = json_decode(json_encode($response), true);
134  if (isset($response['val']['me']['struct']['sid']['me']['string'])) {
135  $sid = $response['val']['me']['struct']['sid']['me']['string'];
136  if ($sid != null) {
137  return $sid;
138  } else {
139  return false;
140  }
141  } else {
142  return false;
143  }
144  }
145 
146  /*
147  * This method submits new documents into Ithenticate into your prefered folder.
148  * The return value is the unique number of the submitted document which will be
149  * used for getting result and other actions which will be performed on document.
150  * The last parameter in the method is the number of the folder which you want to
151  * save the document in it.
152  */
153  public function submitDocument($essay_title, $author_firstname, $author_lastname, $filename, $document_content, $folder_number)
154  {
155  $client = new Client($this->getUrl());
156  $uploads_array = array(
157  new Value(
158  array(
159  'title' => new Value($essay_title),
160  'author_first' => new Value($author_firstname),
161  'author_last' => new Value($author_lastname),
162  'filename' => new Value($filename),
163  'upload' => new Value($document_content, 'base64'),
164  ),
165  'struct'
166  ),
167  );
168  $args = array(
169  'sid' => new Value($this->getSid()),
170  'folder' => new Value($folder_number),
171  'submit_to' => new Value(1),
172  'uploads' => new Value($uploads_array, 'array'),
173  );
174 
175  $response = $client->send(new Request('document.add', array(new Value($args, "struct"))));
176  $response = json_decode(json_encode($response), true);
177  if (isset($response['val']['me']['struct']['uploaded']['me']['array'][0]['me']['struct']['id']['me']['int'])) {
178  $document_id = $response['val']['me']['struct']['uploaded']['me']['array'][0]['me']['struct']['id']['me']['int'];
179  if ($document_id != null) {
180  return $document_id;
181  } else {
182  return false;
183  }
184  } else {
185  return false;
186  }
187  }
188 
189  public function createGroup($group_name)
190  {
191  $client = new Client($this->getUrl());
192  $args = array(
193  'sid' => new Value($this->getSid()),
194  'name' => new Value($group_name),
195  );
196 
197  $response = $client->send(new Request('group.add', array(new Value($args, "struct"))));
198  $response = json_decode(json_encode($response), true);
199  if (isset($response['val']['me']['struct']['id']['me']['int'])) {
200  return $response['val']['me']['struct']['id']['me']['int'];
201  }
202  return false;
203  }
204 
205  public function createFolder($folder_name, $folder_description, $group_id, $exclude_quotes)
206  {
207  $client = new Client($this->getUrl());
208  $args = array(
209  'sid' => new Value($this->getSid()),
210  'folder_group' => new Value($group_id),
211  'name' => new Value($folder_name),
212  'description' => new Value($folder_description),
213  'exclude_quotes' => new Value($exclude_quotes),
214  );
215 
216  $response = $client->send(new Request('folder.add', array(new Value($args, "struct"))));
217  $response = json_decode(json_encode($response), true);
218  if (isset($response['val']['me']['struct']['id']['me']['int'])) {
219  return $response['val']['me']['struct']['id']['me']['int'];
220  }
221  return false;
222  }
223 
224  public function fetchGroupList()
225  {
226  $client = new Client($this->getUrl());
227  $args = array(
228  'sid' => new Value($this->getSid()),
229  );
230 
231  $response = $client->send(new Request('group.list', array(new Value($args, "struct"))));
232  $response = json_decode(json_encode($response), true);
233  if (isset($response['val']['me']['struct']['groups']['me']['array'])) {
234  return array_combine(
235  array_map(function($o) {
236  return $o['me']['struct']['id']['me']['int'];
237  }, $response['val']['me']['struct']['groups']['me']['array']),
238  array_map(function($o) {
239  return $o['me']['struct']['name']['me']['string'];
240  }, $response['val']['me']['struct']['groups']['me']['array'])
241  );
242  } else {
243  return false;
244  }
245  }
246 
247  public function fetchDocumentReportState($document_id)
248  {
249  $client = new Client($this->getUrl());
250  $args = array(
251  'sid' => new Value($this->getSid()),
252  'id' => new Value($document_id),
253  );
254 
255  $response = $client->send(new Request('document.get', array(new Value($args, "struct"))));
256  $response = json_decode(json_encode($response), true);
257  if (isset($response['val']['me']['struct']['documents']['me']['array'][0]['me']['struct']['is_pending']['me']['int'])) {
258  $state = $response['val']['me']['struct']['documents']['me']['array'][0]['me']['struct']['is_pending']['me']['int'];
259  if ($state !== null) {
260  $is_pending['is_pending'] = $state;
261  return $is_pending;
262  } else {
263  return false;
264  }
265  } else {
266  return false;
267  }
268 
269  }
270 
271  public function fetchDocumentReportId($document_id)
272  {
273  $client = new Client($this->getUrl());
274  $args = array(
275  'sid' => new Value($this->getSid()),
276  'id' => new Value($document_id),
277  );
278 
279  $response = $client->send(new Request('document.get', array(new Value($args, "struct"))));
280  $response = json_decode(json_encode($response), true);
281  if (isset($response['val']['me']['struct']['documents']['me']['array'][0]['me']['struct']['parts']['me']['array'][0]['me']['struct']['id']['me']['int'])) {
282  $report_id = $response['val']['me']['struct']['documents']['me']['array'][0]['me']['struct']['parts']['me']['array'][0]['me']['struct']['id']['me']['int'];
283  if ($report_id != null) {
284  return $report_id;
285  } else {
286  return false;
287  }
288  } else {
289  return false;
290  }
291  }
292 
293  public function fetchDocumentReportUrl($report_id, $exclude_biblio = 1, $exclude_quotes = 1, $exclude_small_matches = 1)
294  {
295  $client = new Client($this->getUrl());
296  $args = array(
297  'sid' => new Value($this->getSid()),
298  'id' => new Value($report_id),
299  'exclude_biblio' => new Value($exclude_biblio),
300  'exclude_quotes' => new Value($exclude_quotes),
301  'exclude_small_matches' => new Value($exclude_small_matches),
302  );
303 
304  $response = $client->send(new Request('report.get', array(new Value($args, "struct"))));
305  $response = json_decode(json_encode($response), true);
306  if (isset($response['val']['me']['struct']['view_only_url']['me']['string'])) {
307  $report_url = $response['val']['me']['struct']['view_only_url']['me']['string'];
308  if ($report_url != null) {
309  return $report_url;
310  } else {
311  return false;
312  }
313  } else {
314  return false;
315  }
316  }
317 }
bsobbe\ithenticate\Ithenticate\fetchDocumentReportId
fetchDocumentReportId($document_id)
Definition: Ithenticate.php:271
bsobbe\ithenticate\Ithenticate\setUsername
setUsername($username)
Definition: Ithenticate.php:52
bsobbe\ithenticate
Definition: Ithenticate.php:3
bsobbe\ithenticate\Ithenticate\createFolder
createFolder($folder_name, $folder_description, $group_id, $exclude_quotes)
Definition: Ithenticate.php:205
bsobbe\ithenticate\Ithenticate\setSid
setSid($sid)
Definition: Ithenticate.php:72
bsobbe\ithenticate\Ithenticate\getUrl
getUrl()
Definition: Ithenticate.php:82
bsobbe\ithenticate\Ithenticate\__construct
__construct($username, $password)
Definition: Ithenticate.php:31
bsobbe\ithenticate\Ithenticate\setUrl
setUrl($url)
Definition: Ithenticate.php:42
bsobbe\ithenticate\Ithenticate\fetchGroupList
fetchGroupList()
Definition: Ithenticate.php:224
bsobbe\ithenticate\Ithenticate\getPassword
getPassword()
Definition: Ithenticate.php:102
PhpXmlRpc\Value
Definition: Value.php:7
PhpXmlRpc\Client
Definition: generic/plagiarism/vendor/phpxmlrpc/phpxmlrpc/src/Client.php:7
bsobbe\ithenticate\Ithenticate\setPassword
setPassword($password)
Definition: Ithenticate.php:62
bsobbe\ithenticate\Ithenticate\submitDocument
submitDocument($essay_title, $author_firstname, $author_lastname, $filename, $document_content, $folder_number)
Definition: Ithenticate.php:153
bsobbe\ithenticate\Ithenticate\getSid
getSid()
Definition: Ithenticate.php:112
bsobbe\ithenticate\Ithenticate\createGroup
createGroup($group_name)
Definition: Ithenticate.php:189
bsobbe\ithenticate\Ithenticate\fetchDocumentReportState
fetchDocumentReportState($document_id)
Definition: Ithenticate.php:247
bsobbe\ithenticate\Ithenticate\getUsername
getUsername()
Definition: Ithenticate.php:92
bsobbe\ithenticate\Ithenticate
Definition: Ithenticate.php:12
bsobbe\ithenticate\Ithenticate\fetchDocumentReportUrl
fetchDocumentReportUrl($report_id, $exclude_biblio=1, $exclude_quotes=1, $exclude_small_matches=1)
Definition: Ithenticate.php:293
PhpXmlRpc\Request
Definition: generic/plagiarism/vendor/phpxmlrpc/phpxmlrpc/src/Request.php:10