OPiQuotations  v.02.00.00 — October 26, 2015
 All Classes Namespaces Files Functions Variables Pages
OPiQuotations_list.php
Go to the documentation of this file.
1 <?php /* -*- coding: utf-8 -*- */
2 
3 /** \file OPiQuotations_list.php
4  * (October 11, 2015)
5  *
6  * \brief
7  * Return list of authors, nations, subjects or works
8  * with their number of occurrences,
9  * in a JSON format.
10  *
11  * Piece of OPiQuotations.
12  * https://bitbucket.org/OPiMedia/opiquotations
13  *
14  * GPLv3 --- Copyright (C) 2015 Olivier Pirson
15  * http://www.opimedia.be/
16  *
17  * @package OPiCitations
18  */
19 
20 if (!isset($_GET['list'])) {
21  return;
22 }
23 
24 
25 require_once 'OPiQuotations/log.inc';
26 
27 #DEBUG
28 if (true) {
29  // Development configuration
30  ini_set('display_errors', 'stdout');
31  ini_set('display_startup_errors', 1);
32  ini_set('html_errors', 1);
33 
34  error_reporting(-1);
35 
36  assert_options(ASSERT_ACTIVE, true);
37  assert_options(ASSERT_WARNING, true);
38  assert_options(ASSERT_BAIL, true);
39 }
40 else {
41 #DEBUG_END
42  // Production configuration
43  ini_set('display_errors', 'stderr');
44  ini_set('display_startup_errors', 0);
45  ini_set('html_errors', 0);
46 
47  error_reporting(-1);
48 
49  assert_options(ASSERT_ACTIVE, false);
50  assert_options(ASSERT_WARNING, false);
51  assert_options(ASSERT_BAIL, false);
52 
53  set_error_handler('\OPiQuotations\error_handler');
54 #DEBUG
55 }
56 #DEBUG_END
57 
58 mb_internal_encoding('UTF-8');
59 mb_regex_encoding('UTF-8');
60 mb_http_output('UTF-8');
61 mb_detect_order('UTF-8');
62 
63 
64 require_once 'OPiQuotations/OPiQuotations.inc';
65 
67 
68 
69 if ($_GET['list'] === 'authors') {
70  $list = $opiquotations->list_authors();
71 }
72 else if ($_GET['list'] === 'nations') {
73  $list = $opiquotations->list_nations();
74 }
75 else if ($_GET['list'] === 'subjects') {
76  $list = $opiquotations->list_subjects();
77 }
78 else if ($_GET['list'] === 'works') {
79  $list = $opiquotations->list_works();
80 }
81 else {
82  return;
83 }
84 
85 
86 $count_list = count($list);
87 
88 #DEBUG
89 assert('$count_list > 0');
90 #DEBUG_END
91 
92 if ($count_list > 0) {
93  // Construct a PHP array in the correct order
94  $array = [];
95  foreach($list as $row) {
96  $array[] = $row;
97  }
98 
99  // Write JSON representation
100  $json = json_encode($array);
101  if ($json !== false) {
102  echo $json;
103  }
104 }
105 
106 ?>