@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | /** |
127 | 127 | * This method returns an error message set by PGTStorage::setErrorMessage(). |
128 | 128 | * |
129 | - * @return an error message when set by PGTStorage::setErrorMessage(), FALSE |
|
129 | + * @return boolean error message when set by PGTStorage::setErrorMessage(), FALSE |
|
130 | 130 | * otherwise. |
131 | 131 | * |
132 | 132 | * @public |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | /** |
154 | 154 | * This method tells if the storage has already been intialized. |
155 | 155 | * |
156 | - * @return a boolean |
|
156 | + * @return boolean boolean |
|
157 | 157 | * |
158 | 158 | * @protected |
159 | 159 | */ |
@@ -44,167 +44,167 @@ |
||
44 | 44 | |
45 | 45 | class PGTStorage |
46 | 46 | { |
47 | - /** |
|
48 | - * @addtogroup internalPGTStorage |
|
49 | - * @{ |
|
50 | - */ |
|
51 | - |
|
52 | - // ######################################################################## |
|
53 | - // CONSTRUCTOR |
|
54 | - // ######################################################################## |
|
47 | + /** |
|
48 | + * @addtogroup internalPGTStorage |
|
49 | + * @{ |
|
50 | + */ |
|
51 | + |
|
52 | + // ######################################################################## |
|
53 | + // CONSTRUCTOR |
|
54 | + // ######################################################################## |
|
55 | 55 | |
56 | - /** |
|
57 | - * The constructor of the class, should be called only by inherited classes. |
|
58 | - * |
|
59 | - * @param $cas_parent the CASclient instance that creates the current object. |
|
60 | - * |
|
61 | - * @protected |
|
62 | - */ |
|
63 | - function PGTStorage($cas_parent) |
|
56 | + /** |
|
57 | + * The constructor of the class, should be called only by inherited classes. |
|
58 | + * |
|
59 | + * @param $cas_parent the CASclient instance that creates the current object. |
|
60 | + * |
|
61 | + * @protected |
|
62 | + */ |
|
63 | + function PGTStorage($cas_parent) |
|
64 | 64 | { |
65 | - phpCAS::traceBegin(); |
|
66 | - if ( !$cas_parent->isProxy() ) { |
|
67 | - phpCAS::error('defining PGT storage makes no sense when not using a CAS proxy'); |
|
68 | - } |
|
69 | - phpCAS::traceEnd(); |
|
65 | + phpCAS::traceBegin(); |
|
66 | + if ( !$cas_parent->isProxy() ) { |
|
67 | + phpCAS::error('defining PGT storage makes no sense when not using a CAS proxy'); |
|
68 | + } |
|
69 | + phpCAS::traceEnd(); |
|
70 | 70 | } |
71 | 71 | |
72 | - // ######################################################################## |
|
73 | - // DEBUGGING |
|
74 | - // ######################################################################## |
|
72 | + // ######################################################################## |
|
73 | + // DEBUGGING |
|
74 | + // ######################################################################## |
|
75 | 75 | |
76 | - /** |
|
77 | - * This virtual method returns an informational string giving the type of storage |
|
78 | - * used by the object (used for debugging purposes). |
|
79 | - * |
|
80 | - * @public |
|
81 | - */ |
|
82 | - function getStorageType() |
|
76 | + /** |
|
77 | + * This virtual method returns an informational string giving the type of storage |
|
78 | + * used by the object (used for debugging purposes). |
|
79 | + * |
|
80 | + * @public |
|
81 | + */ |
|
82 | + function getStorageType() |
|
83 | 83 | { |
84 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
84 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
85 | 85 | } |
86 | 86 | |
87 | - /** |
|
88 | - * This virtual method returns an informational string giving informations on the |
|
89 | - * parameters of the storage.(used for debugging purposes). |
|
90 | - * |
|
91 | - * @public |
|
92 | - */ |
|
93 | - function getStorageInfo() |
|
87 | + /** |
|
88 | + * This virtual method returns an informational string giving informations on the |
|
89 | + * parameters of the storage.(used for debugging purposes). |
|
90 | + * |
|
91 | + * @public |
|
92 | + */ |
|
93 | + function getStorageInfo() |
|
94 | 94 | { |
95 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
95 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
96 | 96 | } |
97 | 97 | |
98 | - // ######################################################################## |
|
99 | - // ERROR HANDLING |
|
100 | - // ######################################################################## |
|
98 | + // ######################################################################## |
|
99 | + // ERROR HANDLING |
|
100 | + // ######################################################################## |
|
101 | 101 | |
102 | - /** |
|
103 | - * string used to store an error message. Written by PGTStorage::setErrorMessage(), |
|
104 | - * read by PGTStorage::getErrorMessage(). |
|
105 | - * |
|
106 | - * @hideinitializer |
|
107 | - * @private |
|
108 | - * @deprecated not used. |
|
109 | - */ |
|
110 | - var $_error_message=FALSE; |
|
111 | - |
|
112 | - /** |
|
113 | - * This method sets en error message, which can be read later by |
|
114 | - * PGTStorage::getErrorMessage(). |
|
115 | - * |
|
116 | - * @param $error_message an error message |
|
117 | - * |
|
118 | - * @protected |
|
119 | - * @deprecated not used. |
|
120 | - */ |
|
121 | - function setErrorMessage($error_message) |
|
102 | + /** |
|
103 | + * string used to store an error message. Written by PGTStorage::setErrorMessage(), |
|
104 | + * read by PGTStorage::getErrorMessage(). |
|
105 | + * |
|
106 | + * @hideinitializer |
|
107 | + * @private |
|
108 | + * @deprecated not used. |
|
109 | + */ |
|
110 | + var $_error_message=FALSE; |
|
111 | + |
|
112 | + /** |
|
113 | + * This method sets en error message, which can be read later by |
|
114 | + * PGTStorage::getErrorMessage(). |
|
115 | + * |
|
116 | + * @param $error_message an error message |
|
117 | + * |
|
118 | + * @protected |
|
119 | + * @deprecated not used. |
|
120 | + */ |
|
121 | + function setErrorMessage($error_message) |
|
122 | 122 | { |
123 | - $this->_error_message = $error_message; |
|
123 | + $this->_error_message = $error_message; |
|
124 | 124 | } |
125 | 125 | |
126 | - /** |
|
127 | - * This method returns an error message set by PGTStorage::setErrorMessage(). |
|
128 | - * |
|
129 | - * @return an error message when set by PGTStorage::setErrorMessage(), FALSE |
|
130 | - * otherwise. |
|
131 | - * |
|
132 | - * @public |
|
133 | - * @deprecated not used. |
|
134 | - */ |
|
135 | - function getErrorMessage() |
|
126 | + /** |
|
127 | + * This method returns an error message set by PGTStorage::setErrorMessage(). |
|
128 | + * |
|
129 | + * @return an error message when set by PGTStorage::setErrorMessage(), FALSE |
|
130 | + * otherwise. |
|
131 | + * |
|
132 | + * @public |
|
133 | + * @deprecated not used. |
|
134 | + */ |
|
135 | + function getErrorMessage() |
|
136 | 136 | { |
137 | - return $this->_error_message; |
|
137 | + return $this->_error_message; |
|
138 | 138 | } |
139 | 139 | |
140 | - // ######################################################################## |
|
141 | - // INITIALIZATION |
|
142 | - // ######################################################################## |
|
143 | - |
|
144 | - /** |
|
145 | - * a boolean telling if the storage has already been initialized. Written by |
|
146 | - * PGTStorage::init(), read by PGTStorage::isInitialized(). |
|
147 | - * |
|
148 | - * @hideinitializer |
|
149 | - * @private |
|
150 | - */ |
|
151 | - var $_initialized = FALSE; |
|
152 | - |
|
153 | - /** |
|
154 | - * This method tells if the storage has already been intialized. |
|
155 | - * |
|
156 | - * @return a boolean |
|
157 | - * |
|
158 | - * @protected |
|
159 | - */ |
|
160 | - function isInitialized() |
|
140 | + // ######################################################################## |
|
141 | + // INITIALIZATION |
|
142 | + // ######################################################################## |
|
143 | + |
|
144 | + /** |
|
145 | + * a boolean telling if the storage has already been initialized. Written by |
|
146 | + * PGTStorage::init(), read by PGTStorage::isInitialized(). |
|
147 | + * |
|
148 | + * @hideinitializer |
|
149 | + * @private |
|
150 | + */ |
|
151 | + var $_initialized = FALSE; |
|
152 | + |
|
153 | + /** |
|
154 | + * This method tells if the storage has already been intialized. |
|
155 | + * |
|
156 | + * @return a boolean |
|
157 | + * |
|
158 | + * @protected |
|
159 | + */ |
|
160 | + function isInitialized() |
|
161 | 161 | { |
162 | - return $this->_initialized; |
|
162 | + return $this->_initialized; |
|
163 | 163 | } |
164 | 164 | |
165 | - /** |
|
166 | - * This virtual method initializes the object. |
|
167 | - * |
|
168 | - * @protected |
|
169 | - */ |
|
170 | - function init() |
|
165 | + /** |
|
166 | + * This virtual method initializes the object. |
|
167 | + * |
|
168 | + * @protected |
|
169 | + */ |
|
170 | + function init() |
|
171 | 171 | { |
172 | - $this->_initialized = TRUE; |
|
172 | + $this->_initialized = TRUE; |
|
173 | 173 | } |
174 | 174 | |
175 | - // ######################################################################## |
|
176 | - // PGT I/O |
|
177 | - // ######################################################################## |
|
178 | - |
|
179 | - /** |
|
180 | - * This virtual method stores a PGT and its corresponding PGT Iuo. |
|
181 | - * @note Should never be called. |
|
182 | - * |
|
183 | - * @param $pgt the PGT |
|
184 | - * @param $pgt_iou the PGT iou |
|
185 | - * |
|
186 | - * @protected |
|
187 | - */ |
|
188 | - function write($pgt,$pgt_iou) |
|
175 | + // ######################################################################## |
|
176 | + // PGT I/O |
|
177 | + // ######################################################################## |
|
178 | + |
|
179 | + /** |
|
180 | + * This virtual method stores a PGT and its corresponding PGT Iuo. |
|
181 | + * @note Should never be called. |
|
182 | + * |
|
183 | + * @param $pgt the PGT |
|
184 | + * @param $pgt_iou the PGT iou |
|
185 | + * |
|
186 | + * @protected |
|
187 | + */ |
|
188 | + function write($pgt,$pgt_iou) |
|
189 | 189 | { |
190 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
190 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
191 | 191 | } |
192 | 192 | |
193 | - /** |
|
194 | - * This virtual method reads a PGT corresponding to a PGT Iou and deletes |
|
195 | - * the corresponding storage entry. |
|
196 | - * @note Should never be called. |
|
197 | - * |
|
198 | - * @param $pgt_iou the PGT iou |
|
199 | - * |
|
200 | - * @protected |
|
201 | - */ |
|
202 | - function read($pgt_iou) |
|
193 | + /** |
|
194 | + * This virtual method reads a PGT corresponding to a PGT Iou and deletes |
|
195 | + * the corresponding storage entry. |
|
196 | + * @note Should never be called. |
|
197 | + * |
|
198 | + * @param $pgt_iou the PGT iou |
|
199 | + * |
|
200 | + * @protected |
|
201 | + */ |
|
202 | + function read($pgt_iou) |
|
203 | 203 | { |
204 | - phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
204 | + phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
|
205 | 205 | } |
206 | 206 | |
207 | - /** @} */ |
|
207 | + /** @} */ |
|
208 | 208 | |
209 | 209 | } |
210 | 210 |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | function PGTStorage($cas_parent) |
64 | 64 | { |
65 | 65 | phpCAS::traceBegin(); |
66 | - if ( !$cas_parent->isProxy() ) { |
|
66 | + if (!$cas_parent->isProxy()) { |
|
67 | 67 | phpCAS::error('defining PGT storage makes no sense when not using a CAS proxy'); |
68 | 68 | } |
69 | 69 | phpCAS::traceEnd(); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @private |
108 | 108 | * @deprecated not used. |
109 | 109 | */ |
110 | - var $_error_message=FALSE; |
|
110 | + var $_error_message = FALSE; |
|
111 | 111 | |
112 | 112 | /** |
113 | 113 | * This method sets en error message, which can be read later by |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * |
186 | 186 | * @protected |
187 | 187 | */ |
188 | - function write($pgt,$pgt_iou) |
|
188 | + function write($pgt, $pgt_iou) |
|
189 | 189 | { |
190 | 190 | phpCAS::error(__CLASS__.'::'.__FUNCTION__.'() should never be called'); |
191 | 191 | } |
@@ -33,6 +33,7 @@ discard block |
||
33 | 33 | * render to courses_list view |
34 | 34 | * @param string action |
35 | 35 | * @param string confirmation message(optional) |
36 | + * @param string $action |
|
36 | 37 | */ |
37 | 38 | public function courses_list($action, $message = '') |
38 | 39 | { |
@@ -79,7 +80,7 @@ discard block |
||
79 | 80 | /** |
80 | 81 | * It's used for listing courses with categories, |
81 | 82 | * render to courses_categories view |
82 | - * @param $action |
|
83 | + * @param string $action |
|
83 | 84 | * @param string $category_code |
84 | 85 | * @param string $message |
85 | 86 | * @param string $error |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @param string $message confirmation message(optional) |
63 | 63 | * @param string $error error message(optional) |
64 | 64 | */ |
65 | - public function categories_list($action, $message='', $error='') |
|
65 | + public function categories_list($action, $message = '', $error = '') |
|
66 | 66 | { |
67 | 67 | $data = array(); |
68 | 68 | $data['user_course_categories'] = $this->model->get_user_course_categories(); |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | |
118 | 118 | // we need only the course codes as these will be used to match against the courses of the category |
119 | 119 | if ($user_courses != '') { |
120 | - foreach($user_courses as $key => $value) { |
|
120 | + foreach ($user_courses as $key => $value) { |
|
121 | 121 | $user_coursecodes[] = $value['code']; |
122 | 122 | } |
123 | 123 | } |
@@ -386,13 +386,13 @@ discard block |
||
386 | 386 | $html .= '</strong>'; |
387 | 387 | } else { |
388 | 388 | if (!empty($categoryCourses)) { |
389 | - $html .= '<a href="' . CourseCategory::getCourseCategoryUrl( |
|
389 | + $html .= '<a href="'.CourseCategory::getCourseCategoryUrl( |
|
390 | 390 | 1, |
391 | 391 | $limit['length'], |
392 | 392 | $categoryCode, |
393 | 393 | $hiddenLinks, |
394 | 394 | $action |
395 | - ) . '">'; |
|
395 | + ).'">'; |
|
396 | 396 | $html .= "$categoryName ($categoryCourses)"; |
397 | 397 | $html .= '</a>'; |
398 | 398 | } else { |
@@ -413,13 +413,13 @@ discard block |
||
413 | 413 | if ($code == $subCategory1Code) { |
414 | 414 | $html .= "<strong>$subCategory1Name ($subCategory1Courses)</strong>"; |
415 | 415 | } else { |
416 | - $html .= '<a href="' . CourseCategory::getCourseCategoryUrl( |
|
416 | + $html .= '<a href="'.CourseCategory::getCourseCategoryUrl( |
|
417 | 417 | 1, |
418 | 418 | $limit['length'], |
419 | 419 | $categoryCode, |
420 | 420 | $hiddenLinks, |
421 | 421 | $action |
422 | - ) . '">'; |
|
422 | + ).'">'; |
|
423 | 423 | $html .= "$subCategory1Name ($subCategory1Courses)"; |
424 | 424 | $html .= '</a>'; |
425 | 425 | } |
@@ -437,13 +437,13 @@ discard block |
||
437 | 437 | if ($code == $subCategory2Code) { |
438 | 438 | $html .= "<strong>$subCategory2Name ($subCategory2Courses)</strong>"; |
439 | 439 | } else { |
440 | - $html .= '<a href="' . CourseCategory::getCourseCategoryUrl( |
|
440 | + $html .= '<a href="'.CourseCategory::getCourseCategoryUrl( |
|
441 | 441 | 1, |
442 | 442 | $limit['length'], |
443 | 443 | $categoryCode, |
444 | 444 | $hiddenLinks, |
445 | 445 | $action |
446 | - ) . '">'; |
|
446 | + ).'">'; |
|
447 | 447 | $html .= "$subCategory2Name ($subCategory2Courses)"; |
448 | 448 | $html .= '</a>'; |
449 | 449 | } |
@@ -461,13 +461,13 @@ discard block |
||
461 | 461 | if ($code == $subCategory3Code) { |
462 | 462 | $html .= "<strong>$subCategory3Name ($subCategory3Courses)</strong>"; |
463 | 463 | } else { |
464 | - $html .= '<a href="' . CourseCategory::getCourseCategoryUrl( |
|
464 | + $html .= '<a href="'.CourseCategory::getCourseCategoryUrl( |
|
465 | 465 | 1, |
466 | 466 | $limit['length'], |
467 | 467 | $categoryCode, |
468 | 468 | $hiddenLinks, |
469 | 469 | $action |
470 | - ) . '">'; |
|
470 | + ).'">'; |
|
471 | 471 | $html .= "$subCategory3Name ($subCategory3Courses)"; |
472 | 472 | $html .= '</a>'; |
473 | 473 | } |
@@ -594,7 +594,7 @@ discard block |
||
594 | 594 | $icon = '<em class="fa fa-smile-o"></em>'; |
595 | 595 | |
596 | 596 | return Display::div( |
597 | - $icon . ' ' . get_lang("AlreadyRegisteredToSession"), |
|
597 | + $icon.' '.get_lang("AlreadyRegisteredToSession"), |
|
598 | 598 | array('class' => 'info-catalog') |
599 | 599 | ); |
600 | 600 | } |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | */ |
607 | 607 | public function getSessionIcon($sessionName) |
608 | 608 | { |
609 | - return Display::return_icon('window_list.png', $sessionName, null,ICON_SIZE_MEDIUM); |
|
609 | + return Display::return_icon('window_list.png', $sessionName, null, ICON_SIZE_MEDIUM); |
|
610 | 610 | } |
611 | 611 | |
612 | 612 | /** |
@@ -627,8 +627,7 @@ discard block |
||
627 | 627 | $pageTotal = intval(ceil(intval($countSessions) / $limit['length'])); |
628 | 628 | // Do NOT show pagination if only one page or less |
629 | 629 | $cataloguePagination = $pageTotal > 1 ? |
630 | - CourseCategory::getCatalogPagination($limit['current'], $limit['length'], $pageTotal) : |
|
631 | - ''; |
|
630 | + CourseCategory::getCatalogPagination($limit['current'], $limit['length'], $pageTotal) : ''; |
|
632 | 631 | $sessionsBlocks = $this->getFormatedSessionsBlock($sessions); |
633 | 632 | |
634 | 633 | // Get session list catalogue URL |
@@ -62,6 +62,7 @@ discard block |
||
62 | 62 | * @param string $accessToken |
63 | 63 | * @param int $expiresAt |
64 | 64 | * @param string|null machineId |
65 | + * @param string $machineId |
|
65 | 66 | */ |
66 | 67 | public function __construct($accessToken, $expiresAt = 0, $machineId = null) |
67 | 68 | { |
@@ -97,7 +98,7 @@ discard block |
||
97 | 98 | /** |
98 | 99 | * Getter for machineId. |
99 | 100 | * |
100 | - * @return string|null |
|
101 | + * @return string |
|
101 | 102 | */ |
102 | 103 | public function getMachineId() |
103 | 104 | { |
@@ -191,11 +192,11 @@ discard block |
||
191 | 192 | /** |
192 | 193 | * Get a valid code from an access token. |
193 | 194 | * |
194 | - * @param AccessToken|string $accessToken |
|
195 | + * @param AccessToken $accessToken |
|
195 | 196 | * @param string|null $appId |
196 | 197 | * @param string|null $appSecret |
197 | 198 | * |
198 | - * @return AccessToken |
|
199 | + * @return string |
|
199 | 200 | */ |
200 | 201 | public static function getCodeFromAccessToken($accessToken, $appId = null, $appSecret = null) |
201 | 202 | { |
@@ -35,119 +35,119 @@ discard block |
||
35 | 35 | class AccessToken |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * The access token. |
|
40 | - * |
|
41 | - * @var string |
|
42 | - */ |
|
43 | - protected $accessToken; |
|
44 | - |
|
45 | - /** |
|
46 | - * A unique ID to identify a client. |
|
47 | - * |
|
48 | - * @var string |
|
49 | - */ |
|
50 | - protected $machineId; |
|
51 | - |
|
52 | - /** |
|
53 | - * Date when token expires. |
|
54 | - * |
|
55 | - * @var \DateTime|null |
|
56 | - */ |
|
57 | - protected $expiresAt; |
|
58 | - |
|
59 | - /** |
|
60 | - * Create a new access token entity. |
|
61 | - * |
|
62 | - * @param string $accessToken |
|
63 | - * @param int $expiresAt |
|
64 | - * @param string|null machineId |
|
65 | - */ |
|
66 | - public function __construct($accessToken, $expiresAt = 0, $machineId = null) |
|
67 | - { |
|
38 | + /** |
|
39 | + * The access token. |
|
40 | + * |
|
41 | + * @var string |
|
42 | + */ |
|
43 | + protected $accessToken; |
|
44 | + |
|
45 | + /** |
|
46 | + * A unique ID to identify a client. |
|
47 | + * |
|
48 | + * @var string |
|
49 | + */ |
|
50 | + protected $machineId; |
|
51 | + |
|
52 | + /** |
|
53 | + * Date when token expires. |
|
54 | + * |
|
55 | + * @var \DateTime|null |
|
56 | + */ |
|
57 | + protected $expiresAt; |
|
58 | + |
|
59 | + /** |
|
60 | + * Create a new access token entity. |
|
61 | + * |
|
62 | + * @param string $accessToken |
|
63 | + * @param int $expiresAt |
|
64 | + * @param string|null machineId |
|
65 | + */ |
|
66 | + public function __construct($accessToken, $expiresAt = 0, $machineId = null) |
|
67 | + { |
|
68 | 68 | $this->accessToken = $accessToken; |
69 | 69 | if ($expiresAt) { |
70 | - $this->setExpiresAtFromTimeStamp($expiresAt); |
|
70 | + $this->setExpiresAtFromTimeStamp($expiresAt); |
|
71 | 71 | } |
72 | 72 | $this->machineId = $machineId; |
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * Setter for expires_at. |
|
77 | - * |
|
78 | - * @param int $timeStamp |
|
79 | - */ |
|
80 | - protected function setExpiresAtFromTimeStamp($timeStamp) |
|
81 | - { |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * Setter for expires_at. |
|
77 | + * |
|
78 | + * @param int $timeStamp |
|
79 | + */ |
|
80 | + protected function setExpiresAtFromTimeStamp($timeStamp) |
|
81 | + { |
|
82 | 82 | $dt = new \DateTime(); |
83 | 83 | $dt->setTimestamp($timeStamp); |
84 | 84 | $this->expiresAt = $dt; |
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * Getter for expiresAt. |
|
89 | - * |
|
90 | - * @return \DateTime|null |
|
91 | - */ |
|
92 | - public function getExpiresAt() |
|
93 | - { |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * Getter for expiresAt. |
|
89 | + * |
|
90 | + * @return \DateTime|null |
|
91 | + */ |
|
92 | + public function getExpiresAt() |
|
93 | + { |
|
94 | 94 | return $this->expiresAt; |
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * Getter for machineId. |
|
99 | - * |
|
100 | - * @return string|null |
|
101 | - */ |
|
102 | - public function getMachineId() |
|
103 | - { |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * Getter for machineId. |
|
99 | + * |
|
100 | + * @return string|null |
|
101 | + */ |
|
102 | + public function getMachineId() |
|
103 | + { |
|
104 | 104 | return $this->machineId; |
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * Determines whether or not this is a long-lived token. |
|
109 | - * |
|
110 | - * @return bool |
|
111 | - */ |
|
112 | - public function isLongLived() |
|
113 | - { |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * Determines whether or not this is a long-lived token. |
|
109 | + * |
|
110 | + * @return bool |
|
111 | + */ |
|
112 | + public function isLongLived() |
|
113 | + { |
|
114 | 114 | if ($this->expiresAt) { |
115 | - return $this->expiresAt->getTimestamp() > time() + (60 * 60 * 2); |
|
115 | + return $this->expiresAt->getTimestamp() > time() + (60 * 60 * 2); |
|
116 | 116 | } |
117 | 117 | return false; |
118 | - } |
|
119 | - |
|
120 | - /** |
|
121 | - * Checks the validity of the access token. |
|
122 | - * |
|
123 | - * @param string|null $appId Application ID to use |
|
124 | - * @param string|null $appSecret App secret value to use |
|
125 | - * @param string|null $machineId |
|
126 | - * |
|
127 | - * @return boolean |
|
128 | - */ |
|
129 | - public function isValid($appId = null, $appSecret = null, $machineId = null) |
|
130 | - { |
|
118 | + } |
|
119 | + |
|
120 | + /** |
|
121 | + * Checks the validity of the access token. |
|
122 | + * |
|
123 | + * @param string|null $appId Application ID to use |
|
124 | + * @param string|null $appSecret App secret value to use |
|
125 | + * @param string|null $machineId |
|
126 | + * |
|
127 | + * @return boolean |
|
128 | + */ |
|
129 | + public function isValid($appId = null, $appSecret = null, $machineId = null) |
|
130 | + { |
|
131 | 131 | $accessTokenInfo = $this->getInfo($appId, $appSecret); |
132 | 132 | $machineId = $machineId ?: $this->machineId; |
133 | 133 | return static::validateAccessToken($accessTokenInfo, $appId, $machineId); |
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Ensures the provided GraphSessionInfo object is valid, |
|
138 | - * throwing an exception if not. Ensures the appId matches, |
|
139 | - * that the machineId matches if it's being used, |
|
140 | - * that the token is valid and has not expired. |
|
141 | - * |
|
142 | - * @param GraphSessionInfo $tokenInfo |
|
143 | - * @param string|null $appId Application ID to use |
|
144 | - * @param string|null $machineId |
|
145 | - * |
|
146 | - * @return boolean |
|
147 | - */ |
|
148 | - public static function validateAccessToken(GraphSessionInfo $tokenInfo, |
|
149 | - $appId = null, $machineId = null) |
|
150 | - { |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Ensures the provided GraphSessionInfo object is valid, |
|
138 | + * throwing an exception if not. Ensures the appId matches, |
|
139 | + * that the machineId matches if it's being used, |
|
140 | + * that the token is valid and has not expired. |
|
141 | + * |
|
142 | + * @param GraphSessionInfo $tokenInfo |
|
143 | + * @param string|null $appId Application ID to use |
|
144 | + * @param string|null $machineId |
|
145 | + * |
|
146 | + * @return boolean |
|
147 | + */ |
|
148 | + public static function validateAccessToken(GraphSessionInfo $tokenInfo, |
|
149 | + $appId = null, $machineId = null) |
|
150 | + { |
|
151 | 151 | $targetAppId = FacebookSession::_getTargetAppId($appId); |
152 | 152 | |
153 | 153 | $appIdIsValid = $tokenInfo->getAppId() == $targetAppId; |
@@ -156,90 +156,90 @@ discard block |
||
156 | 156 | |
157 | 157 | // Not all access tokens return an expiration. E.g. an app access token. |
158 | 158 | if ($tokenInfo->getExpiresAt() instanceof \DateTime) { |
159 | - $accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time(); |
|
159 | + $accessTokenIsStillAlive = $tokenInfo->getExpiresAt()->getTimestamp() >= time(); |
|
160 | 160 | } else { |
161 | - $accessTokenIsStillAlive = true; |
|
161 | + $accessTokenIsStillAlive = true; |
|
162 | 162 | } |
163 | 163 | |
164 | 164 | return $appIdIsValid && $machineIdIsValid && $accessTokenIsValid && $accessTokenIsStillAlive; |
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * Get a valid access token from a code. |
|
169 | - * |
|
170 | - * @param string $code |
|
171 | - * @param string|null $appId |
|
172 | - * @param string|null $appSecret |
|
173 | - * @param string|null $machineId |
|
174 | - * |
|
175 | - * @return AccessToken |
|
176 | - */ |
|
177 | - public static function getAccessTokenFromCode($code, $appId = null, $appSecret = null, $machineId = null) |
|
178 | - { |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * Get a valid access token from a code. |
|
169 | + * |
|
170 | + * @param string $code |
|
171 | + * @param string|null $appId |
|
172 | + * @param string|null $appSecret |
|
173 | + * @param string|null $machineId |
|
174 | + * |
|
175 | + * @return AccessToken |
|
176 | + */ |
|
177 | + public static function getAccessTokenFromCode($code, $appId = null, $appSecret = null, $machineId = null) |
|
178 | + { |
|
179 | 179 | $params = array( |
180 | - 'code' => $code, |
|
181 | - 'redirect_uri' => '', |
|
180 | + 'code' => $code, |
|
181 | + 'redirect_uri' => '', |
|
182 | 182 | ); |
183 | 183 | |
184 | 184 | if ($machineId) { |
185 | - $params['machine_id'] = $machineId; |
|
185 | + $params['machine_id'] = $machineId; |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | return static::requestAccessToken($params, $appId, $appSecret); |
189 | - } |
|
190 | - |
|
191 | - /** |
|
192 | - * Get a valid code from an access token. |
|
193 | - * |
|
194 | - * @param AccessToken|string $accessToken |
|
195 | - * @param string|null $appId |
|
196 | - * @param string|null $appSecret |
|
197 | - * |
|
198 | - * @return AccessToken |
|
199 | - */ |
|
200 | - public static function getCodeFromAccessToken($accessToken, $appId = null, $appSecret = null) |
|
201 | - { |
|
189 | + } |
|
190 | + |
|
191 | + /** |
|
192 | + * Get a valid code from an access token. |
|
193 | + * |
|
194 | + * @param AccessToken|string $accessToken |
|
195 | + * @param string|null $appId |
|
196 | + * @param string|null $appSecret |
|
197 | + * |
|
198 | + * @return AccessToken |
|
199 | + */ |
|
200 | + public static function getCodeFromAccessToken($accessToken, $appId = null, $appSecret = null) |
|
201 | + { |
|
202 | 202 | $accessToken = (string) $accessToken; |
203 | 203 | |
204 | 204 | $params = array( |
205 | - 'access_token' => $accessToken, |
|
206 | - 'redirect_uri' => '', |
|
205 | + 'access_token' => $accessToken, |
|
206 | + 'redirect_uri' => '', |
|
207 | 207 | ); |
208 | 208 | |
209 | 209 | return static::requestCode($params, $appId, $appSecret); |
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Exchanges a short lived access token with a long lived access token. |
|
214 | - * |
|
215 | - * @param string|null $appId |
|
216 | - * @param string|null $appSecret |
|
217 | - * |
|
218 | - * @return AccessToken |
|
219 | - */ |
|
220 | - public function extend($appId = null, $appSecret = null) |
|
221 | - { |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Exchanges a short lived access token with a long lived access token. |
|
214 | + * |
|
215 | + * @param string|null $appId |
|
216 | + * @param string|null $appSecret |
|
217 | + * |
|
218 | + * @return AccessToken |
|
219 | + */ |
|
220 | + public function extend($appId = null, $appSecret = null) |
|
221 | + { |
|
222 | 222 | $params = array( |
223 | - 'grant_type' => 'fb_exchange_token', |
|
224 | - 'fb_exchange_token' => $this->accessToken, |
|
223 | + 'grant_type' => 'fb_exchange_token', |
|
224 | + 'fb_exchange_token' => $this->accessToken, |
|
225 | 225 | ); |
226 | 226 | |
227 | 227 | return static::requestAccessToken($params, $appId, $appSecret); |
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * Request an access token based on a set of params. |
|
232 | - * |
|
233 | - * @param array $params |
|
234 | - * @param string|null $appId |
|
235 | - * @param string|null $appSecret |
|
236 | - * |
|
237 | - * @return AccessToken |
|
238 | - * |
|
239 | - * @throws FacebookRequestException |
|
240 | - */ |
|
241 | - public static function requestAccessToken(array $params, $appId = null, $appSecret = null) |
|
242 | - { |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * Request an access token based on a set of params. |
|
232 | + * |
|
233 | + * @param array $params |
|
234 | + * @param string|null $appId |
|
235 | + * @param string|null $appSecret |
|
236 | + * |
|
237 | + * @return AccessToken |
|
238 | + * |
|
239 | + * @throws FacebookRequestException |
|
240 | + */ |
|
241 | + public static function requestAccessToken(array $params, $appId = null, $appSecret = null) |
|
242 | + { |
|
243 | 243 | $response = static::request('/oauth/access_token', $params, $appId, $appSecret); |
244 | 244 | $data = $response->getResponse(); |
245 | 245 | |
@@ -248,133 +248,133 @@ discard block |
||
248 | 248 | * @see https://github.com/facebook/facebook-php-sdk-v4/issues/36 |
249 | 249 | */ |
250 | 250 | if (is_array($data)) { |
251 | - if (isset($data['access_token'])) { |
|
251 | + if (isset($data['access_token'])) { |
|
252 | 252 | $expiresAt = isset($data['expires']) ? time() + $data['expires'] : 0; |
253 | 253 | return new static($data['access_token'], $expiresAt); |
254 | - } |
|
254 | + } |
|
255 | 255 | } elseif($data instanceof \stdClass) { |
256 | - if (isset($data->access_token)) { |
|
256 | + if (isset($data->access_token)) { |
|
257 | 257 | $expiresAt = isset($data->expires_in) ? time() + $data->expires_in : 0; |
258 | 258 | $machineId = isset($data->machine_id) ? (string) $data->machine_id : null; |
259 | 259 | return new static((string) $data->access_token, $expiresAt, $machineId); |
260 | - } |
|
260 | + } |
|
261 | 261 | } |
262 | 262 | |
263 | 263 | throw FacebookRequestException::create( |
264 | - $response->getRawResponse(), |
|
265 | - $data, |
|
266 | - 401 |
|
264 | + $response->getRawResponse(), |
|
265 | + $data, |
|
266 | + 401 |
|
267 | 267 | ); |
268 | - } |
|
269 | - |
|
270 | - /** |
|
271 | - * Request a code from a long lived access token. |
|
272 | - * |
|
273 | - * @param array $params |
|
274 | - * @param string|null $appId |
|
275 | - * @param string|null $appSecret |
|
276 | - * |
|
277 | - * @return string |
|
278 | - * |
|
279 | - * @throws FacebookRequestException |
|
280 | - */ |
|
281 | - public static function requestCode(array $params, $appId = null, $appSecret = null) |
|
282 | - { |
|
268 | + } |
|
269 | + |
|
270 | + /** |
|
271 | + * Request a code from a long lived access token. |
|
272 | + * |
|
273 | + * @param array $params |
|
274 | + * @param string|null $appId |
|
275 | + * @param string|null $appSecret |
|
276 | + * |
|
277 | + * @return string |
|
278 | + * |
|
279 | + * @throws FacebookRequestException |
|
280 | + */ |
|
281 | + public static function requestCode(array $params, $appId = null, $appSecret = null) |
|
282 | + { |
|
283 | 283 | $response = static::request('/oauth/client_code', $params, $appId, $appSecret); |
284 | 284 | $data = $response->getResponse(); |
285 | 285 | |
286 | 286 | if (isset($data->code)) { |
287 | - return (string) $data->code; |
|
287 | + return (string) $data->code; |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | throw FacebookRequestException::create( |
291 | - $response->getRawResponse(), |
|
292 | - $data, |
|
293 | - 401 |
|
291 | + $response->getRawResponse(), |
|
292 | + $data, |
|
293 | + 401 |
|
294 | 294 | ); |
295 | - } |
|
296 | - |
|
297 | - /** |
|
298 | - * Send a request to Graph with an app access token. |
|
299 | - * |
|
300 | - * @param string $endpoint |
|
301 | - * @param array $params |
|
302 | - * @param string|null $appId |
|
303 | - * @param string|null $appSecret |
|
304 | - * |
|
305 | - * @return \Facebook\FacebookResponse |
|
306 | - * |
|
307 | - * @throws FacebookRequestException |
|
308 | - */ |
|
309 | - protected static function request($endpoint, array $params, $appId = null, $appSecret = null) |
|
310 | - { |
|
295 | + } |
|
296 | + |
|
297 | + /** |
|
298 | + * Send a request to Graph with an app access token. |
|
299 | + * |
|
300 | + * @param string $endpoint |
|
301 | + * @param array $params |
|
302 | + * @param string|null $appId |
|
303 | + * @param string|null $appSecret |
|
304 | + * |
|
305 | + * @return \Facebook\FacebookResponse |
|
306 | + * |
|
307 | + * @throws FacebookRequestException |
|
308 | + */ |
|
309 | + protected static function request($endpoint, array $params, $appId = null, $appSecret = null) |
|
310 | + { |
|
311 | 311 | $targetAppId = FacebookSession::_getTargetAppId($appId); |
312 | 312 | $targetAppSecret = FacebookSession::_getTargetAppSecret($appSecret); |
313 | 313 | |
314 | 314 | if (!isset($params['client_id'])) { |
315 | - $params['client_id'] = $targetAppId; |
|
315 | + $params['client_id'] = $targetAppId; |
|
316 | 316 | } |
317 | 317 | if (!isset($params['client_secret'])) { |
318 | - $params['client_secret'] = $targetAppSecret; |
|
318 | + $params['client_secret'] = $targetAppSecret; |
|
319 | 319 | } |
320 | 320 | |
321 | 321 | // The response for this endpoint is not JSON, so it must be handled |
322 | 322 | // differently, not as a GraphObject. |
323 | 323 | $request = new FacebookRequest( |
324 | - FacebookSession::newAppSession($targetAppId, $targetAppSecret), |
|
325 | - 'GET', |
|
326 | - $endpoint, |
|
327 | - $params |
|
324 | + FacebookSession::newAppSession($targetAppId, $targetAppSecret), |
|
325 | + 'GET', |
|
326 | + $endpoint, |
|
327 | + $params |
|
328 | 328 | ); |
329 | 329 | return $request->execute(); |
330 | - } |
|
331 | - |
|
332 | - /** |
|
333 | - * Get more info about an access token. |
|
334 | - * |
|
335 | - * @param string|null $appId |
|
336 | - * @param string|null $appSecret |
|
337 | - * |
|
338 | - * @return GraphSessionInfo |
|
339 | - */ |
|
340 | - public function getInfo($appId = null, $appSecret = null) |
|
341 | - { |
|
330 | + } |
|
331 | + |
|
332 | + /** |
|
333 | + * Get more info about an access token. |
|
334 | + * |
|
335 | + * @param string|null $appId |
|
336 | + * @param string|null $appSecret |
|
337 | + * |
|
338 | + * @return GraphSessionInfo |
|
339 | + */ |
|
340 | + public function getInfo($appId = null, $appSecret = null) |
|
341 | + { |
|
342 | 342 | $params = array('input_token' => $this->accessToken); |
343 | 343 | |
344 | 344 | $request = new FacebookRequest( |
345 | - FacebookSession::newAppSession($appId, $appSecret), |
|
346 | - 'GET', |
|
347 | - '/debug_token', |
|
348 | - $params |
|
345 | + FacebookSession::newAppSession($appId, $appSecret), |
|
346 | + 'GET', |
|
347 | + '/debug_token', |
|
348 | + $params |
|
349 | 349 | ); |
350 | 350 | $response = $request->execute()->getGraphObject(GraphSessionInfo::className()); |
351 | 351 | |
352 | 352 | // Update the data on this token |
353 | 353 | if ($response->getExpiresAt()) { |
354 | - $this->expiresAt = $response->getExpiresAt(); |
|
354 | + $this->expiresAt = $response->getExpiresAt(); |
|
355 | 355 | } |
356 | 356 | |
357 | 357 | return $response; |
358 | - } |
|
359 | - |
|
360 | - /** |
|
361 | - * Returns the access token as a string. |
|
362 | - * |
|
363 | - * @return string |
|
364 | - */ |
|
365 | - public function __toString() |
|
366 | - { |
|
358 | + } |
|
359 | + |
|
360 | + /** |
|
361 | + * Returns the access token as a string. |
|
362 | + * |
|
363 | + * @return string |
|
364 | + */ |
|
365 | + public function __toString() |
|
366 | + { |
|
367 | 367 | return $this->accessToken; |
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * Returns true if the access token is an app session token. |
|
372 | - * |
|
373 | - * @return bool |
|
374 | - */ |
|
375 | - public function isAppSession() |
|
376 | - { |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * Returns true if the access token is an app session token. |
|
372 | + * |
|
373 | + * @return bool |
|
374 | + */ |
|
375 | + public function isAppSession() |
|
376 | + { |
|
377 | 377 | return strpos($this->accessToken, "|") !== false; |
378 | - } |
|
378 | + } |
|
379 | 379 | |
380 | 380 | } |
@@ -252,7 +252,7 @@ |
||
252 | 252 | $expiresAt = isset($data['expires']) ? time() + $data['expires'] : 0; |
253 | 253 | return new static($data['access_token'], $expiresAt); |
254 | 254 | } |
255 | - } elseif($data instanceof \stdClass) { |
|
255 | + } elseif ($data instanceof \stdClass) { |
|
256 | 256 | if (isset($data->access_token)) { |
257 | 257 | $expiresAt = isset($data->expires_in) ? time() + $data->expires_in : 0; |
258 | 258 | $machineId = isset($data->machine_id) ? (string) $data->machine_id : null; |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | /** |
64 | 64 | * Returns the raw signed request data. |
65 | 65 | * |
66 | - * @return string|null |
|
66 | + * @return string |
|
67 | 67 | */ |
68 | 68 | public function getRawSignedRequest() |
69 | 69 | { |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * Returns a property from the signed request data if available. |
85 | 85 | * |
86 | 86 | * @param string $key |
87 | - * @param mixed|null $default |
|
87 | + * @param integer $default |
|
88 | 88 | * |
89 | 89 | * @return mixed|null |
90 | 90 | */ |
@@ -33,99 +33,99 @@ discard block |
||
33 | 33 | class SignedRequest |
34 | 34 | { |
35 | 35 | |
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - public $rawSignedRequest; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - public $payload; |
|
45 | - |
|
46 | - /** |
|
47 | - * Instantiate a new SignedRequest entity. |
|
48 | - * |
|
49 | - * @param string|null $rawSignedRequest The raw signed request. |
|
50 | - * @param string|null $state random string to prevent CSRF. |
|
51 | - * @param string|null $appSecret |
|
52 | - */ |
|
53 | - public function __construct($rawSignedRequest = null, $state = null, $appSecret = null) |
|
54 | - { |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + public $rawSignedRequest; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + public $payload; |
|
45 | + |
|
46 | + /** |
|
47 | + * Instantiate a new SignedRequest entity. |
|
48 | + * |
|
49 | + * @param string|null $rawSignedRequest The raw signed request. |
|
50 | + * @param string|null $state random string to prevent CSRF. |
|
51 | + * @param string|null $appSecret |
|
52 | + */ |
|
53 | + public function __construct($rawSignedRequest = null, $state = null, $appSecret = null) |
|
54 | + { |
|
55 | 55 | if (!$rawSignedRequest) { |
56 | - return; |
|
56 | + return; |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | $this->rawSignedRequest = $rawSignedRequest; |
60 | 60 | $this->payload = static::parse($rawSignedRequest, $state, $appSecret); |
61 | - } |
|
62 | - |
|
63 | - /** |
|
64 | - * Returns the raw signed request data. |
|
65 | - * |
|
66 | - * @return string|null |
|
67 | - */ |
|
68 | - public function getRawSignedRequest() |
|
69 | - { |
|
61 | + } |
|
62 | + |
|
63 | + /** |
|
64 | + * Returns the raw signed request data. |
|
65 | + * |
|
66 | + * @return string|null |
|
67 | + */ |
|
68 | + public function getRawSignedRequest() |
|
69 | + { |
|
70 | 70 | return $this->rawSignedRequest; |
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Returns the parsed signed request data. |
|
75 | - * |
|
76 | - * @return array|null |
|
77 | - */ |
|
78 | - public function getPayload() |
|
79 | - { |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Returns the parsed signed request data. |
|
75 | + * |
|
76 | + * @return array|null |
|
77 | + */ |
|
78 | + public function getPayload() |
|
79 | + { |
|
80 | 80 | return $this->payload; |
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Returns a property from the signed request data if available. |
|
85 | - * |
|
86 | - * @param string $key |
|
87 | - * @param mixed|null $default |
|
88 | - * |
|
89 | - * @return mixed|null |
|
90 | - */ |
|
91 | - public function get($key, $default = null) |
|
92 | - { |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Returns a property from the signed request data if available. |
|
85 | + * |
|
86 | + * @param string $key |
|
87 | + * @param mixed|null $default |
|
88 | + * |
|
89 | + * @return mixed|null |
|
90 | + */ |
|
91 | + public function get($key, $default = null) |
|
92 | + { |
|
93 | 93 | if (isset($this->payload[$key])) { |
94 | - return $this->payload[$key]; |
|
94 | + return $this->payload[$key]; |
|
95 | 95 | } |
96 | 96 | return $default; |
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Returns user_id from signed request data if available. |
|
101 | - * |
|
102 | - * @return string|null |
|
103 | - */ |
|
104 | - public function getUserId() |
|
105 | - { |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Returns user_id from signed request data if available. |
|
101 | + * |
|
102 | + * @return string|null |
|
103 | + */ |
|
104 | + public function getUserId() |
|
105 | + { |
|
106 | 106 | return $this->get('user_id'); |
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Checks for OAuth data in the payload. |
|
111 | - * |
|
112 | - * @return boolean |
|
113 | - */ |
|
114 | - public function hasOAuthData() |
|
115 | - { |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Checks for OAuth data in the payload. |
|
111 | + * |
|
112 | + * @return boolean |
|
113 | + */ |
|
114 | + public function hasOAuthData() |
|
115 | + { |
|
116 | 116 | return isset($this->payload['oauth_token']) || isset($this->payload['code']); |
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * Creates a signed request from an array of data. |
|
121 | - * |
|
122 | - * @param array $payload |
|
123 | - * @param string|null $appSecret |
|
124 | - * |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - public static function make(array $payload, $appSecret = null) |
|
128 | - { |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * Creates a signed request from an array of data. |
|
121 | + * |
|
122 | + * @param array $payload |
|
123 | + * @param string|null $appSecret |
|
124 | + * |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + public static function make(array $payload, $appSecret = null) |
|
128 | + { |
|
129 | 129 | $payload['algorithm'] = 'HMAC-SHA256'; |
130 | 130 | $payload['issued_at'] = time(); |
131 | 131 | $encodedPayload = static::base64UrlEncode(json_encode($payload)); |
@@ -134,20 +134,20 @@ discard block |
||
134 | 134 | $encodedSig = static::base64UrlEncode($hashedSig); |
135 | 135 | |
136 | 136 | return $encodedSig.'.'.$encodedPayload; |
137 | - } |
|
138 | - |
|
139 | - /** |
|
140 | - * Validates and decodes a signed request and returns |
|
141 | - * the payload as an array. |
|
142 | - * |
|
143 | - * @param string $signedRequest |
|
144 | - * @param string|null $state |
|
145 | - * @param string|null $appSecret |
|
146 | - * |
|
147 | - * @return array |
|
148 | - */ |
|
149 | - public static function parse($signedRequest, $state = null, $appSecret = null) |
|
150 | - { |
|
137 | + } |
|
138 | + |
|
139 | + /** |
|
140 | + * Validates and decodes a signed request and returns |
|
141 | + * the payload as an array. |
|
142 | + * |
|
143 | + * @param string $signedRequest |
|
144 | + * @param string|null $state |
|
145 | + * @param string|null $appSecret |
|
146 | + * |
|
147 | + * @return array |
|
148 | + */ |
|
149 | + public static function parse($signedRequest, $state = null, $appSecret = null) |
|
150 | + { |
|
151 | 151 | list($encodedSig, $encodedPayload) = static::split($signedRequest); |
152 | 152 | |
153 | 153 | // Signature validation |
@@ -159,228 +159,228 @@ discard block |
||
159 | 159 | $data = static::decodePayload($encodedPayload); |
160 | 160 | static::validateAlgorithm($data); |
161 | 161 | if ($state) { |
162 | - static::validateCsrf($data, $state); |
|
162 | + static::validateCsrf($data, $state); |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | return $data; |
166 | - } |
|
167 | - |
|
168 | - /** |
|
169 | - * Validates the format of a signed request. |
|
170 | - * |
|
171 | - * @param string $signedRequest |
|
172 | - * |
|
173 | - * @throws FacebookSDKException |
|
174 | - */ |
|
175 | - public static function validateFormat($signedRequest) |
|
176 | - { |
|
166 | + } |
|
167 | + |
|
168 | + /** |
|
169 | + * Validates the format of a signed request. |
|
170 | + * |
|
171 | + * @param string $signedRequest |
|
172 | + * |
|
173 | + * @throws FacebookSDKException |
|
174 | + */ |
|
175 | + public static function validateFormat($signedRequest) |
|
176 | + { |
|
177 | 177 | if (strpos($signedRequest, '.') !== false) { |
178 | - return; |
|
178 | + return; |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | throw new FacebookSDKException( |
182 | - 'Malformed signed request.', 606 |
|
182 | + 'Malformed signed request.', 606 |
|
183 | 183 | ); |
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * Decodes a raw valid signed request. |
|
188 | - * |
|
189 | - * @param string $signedRequest |
|
190 | - * |
|
191 | - * @returns array |
|
192 | - */ |
|
193 | - public static function split($signedRequest) |
|
194 | - { |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * Decodes a raw valid signed request. |
|
188 | + * |
|
189 | + * @param string $signedRequest |
|
190 | + * |
|
191 | + * @returns array |
|
192 | + */ |
|
193 | + public static function split($signedRequest) |
|
194 | + { |
|
195 | 195 | static::validateFormat($signedRequest); |
196 | 196 | |
197 | 197 | return explode('.', $signedRequest, 2); |
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Decodes the raw signature from a signed request. |
|
202 | - * |
|
203 | - * @param string $encodedSig |
|
204 | - * |
|
205 | - * @returns string |
|
206 | - * |
|
207 | - * @throws FacebookSDKException |
|
208 | - */ |
|
209 | - public static function decodeSignature($encodedSig) |
|
210 | - { |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Decodes the raw signature from a signed request. |
|
202 | + * |
|
203 | + * @param string $encodedSig |
|
204 | + * |
|
205 | + * @returns string |
|
206 | + * |
|
207 | + * @throws FacebookSDKException |
|
208 | + */ |
|
209 | + public static function decodeSignature($encodedSig) |
|
210 | + { |
|
211 | 211 | $sig = static::base64UrlDecode($encodedSig); |
212 | 212 | |
213 | 213 | if ($sig) { |
214 | - return $sig; |
|
214 | + return $sig; |
|
215 | 215 | } |
216 | 216 | |
217 | 217 | throw new FacebookSDKException( |
218 | - 'Signed request has malformed encoded signature data.', 607 |
|
218 | + 'Signed request has malformed encoded signature data.', 607 |
|
219 | 219 | ); |
220 | - } |
|
221 | - |
|
222 | - /** |
|
223 | - * Decodes the raw payload from a signed request. |
|
224 | - * |
|
225 | - * @param string $encodedPayload |
|
226 | - * |
|
227 | - * @returns array |
|
228 | - * |
|
229 | - * @throws FacebookSDKException |
|
230 | - */ |
|
231 | - public static function decodePayload($encodedPayload) |
|
232 | - { |
|
220 | + } |
|
221 | + |
|
222 | + /** |
|
223 | + * Decodes the raw payload from a signed request. |
|
224 | + * |
|
225 | + * @param string $encodedPayload |
|
226 | + * |
|
227 | + * @returns array |
|
228 | + * |
|
229 | + * @throws FacebookSDKException |
|
230 | + */ |
|
231 | + public static function decodePayload($encodedPayload) |
|
232 | + { |
|
233 | 233 | $payload = static::base64UrlDecode($encodedPayload); |
234 | 234 | |
235 | 235 | if ($payload) { |
236 | - $payload = json_decode($payload, true); |
|
236 | + $payload = json_decode($payload, true); |
|
237 | 237 | } |
238 | 238 | |
239 | 239 | if (is_array($payload)) { |
240 | - return $payload; |
|
240 | + return $payload; |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | throw new FacebookSDKException( |
244 | - 'Signed request has malformed encoded payload data.', 607 |
|
244 | + 'Signed request has malformed encoded payload data.', 607 |
|
245 | 245 | ); |
246 | - } |
|
247 | - |
|
248 | - /** |
|
249 | - * Validates the algorithm used in a signed request. |
|
250 | - * |
|
251 | - * @param array $data |
|
252 | - * |
|
253 | - * @throws FacebookSDKException |
|
254 | - */ |
|
255 | - public static function validateAlgorithm(array $data) |
|
256 | - { |
|
246 | + } |
|
247 | + |
|
248 | + /** |
|
249 | + * Validates the algorithm used in a signed request. |
|
250 | + * |
|
251 | + * @param array $data |
|
252 | + * |
|
253 | + * @throws FacebookSDKException |
|
254 | + */ |
|
255 | + public static function validateAlgorithm(array $data) |
|
256 | + { |
|
257 | 257 | if (isset($data['algorithm']) && $data['algorithm'] === 'HMAC-SHA256') { |
258 | - return; |
|
258 | + return; |
|
259 | 259 | } |
260 | 260 | |
261 | 261 | throw new FacebookSDKException( |
262 | - 'Signed request is using the wrong algorithm.', 605 |
|
262 | + 'Signed request is using the wrong algorithm.', 605 |
|
263 | 263 | ); |
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Hashes the signature used in a signed request. |
|
268 | - * |
|
269 | - * @param string $encodedData |
|
270 | - * @param string|null $appSecret |
|
271 | - * |
|
272 | - * @return string |
|
273 | - * |
|
274 | - * @throws FacebookSDKException |
|
275 | - */ |
|
276 | - public static function hashSignature($encodedData, $appSecret = null) |
|
277 | - { |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Hashes the signature used in a signed request. |
|
268 | + * |
|
269 | + * @param string $encodedData |
|
270 | + * @param string|null $appSecret |
|
271 | + * |
|
272 | + * @return string |
|
273 | + * |
|
274 | + * @throws FacebookSDKException |
|
275 | + */ |
|
276 | + public static function hashSignature($encodedData, $appSecret = null) |
|
277 | + { |
|
278 | 278 | $hashedSig = hash_hmac( |
279 | - 'sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true |
|
279 | + 'sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true |
|
280 | 280 | ); |
281 | 281 | |
282 | 282 | if ($hashedSig) { |
283 | - return $hashedSig; |
|
283 | + return $hashedSig; |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | throw new FacebookSDKException( |
287 | - 'Unable to hash signature from encoded payload data.', 602 |
|
287 | + 'Unable to hash signature from encoded payload data.', 602 |
|
288 | 288 | ); |
289 | - } |
|
290 | - |
|
291 | - /** |
|
292 | - * Validates the signature used in a signed request. |
|
293 | - * |
|
294 | - * @param string $hashedSig |
|
295 | - * @param string $sig |
|
296 | - * |
|
297 | - * @throws FacebookSDKException |
|
298 | - */ |
|
299 | - public static function validateSignature($hashedSig, $sig) |
|
300 | - { |
|
289 | + } |
|
290 | + |
|
291 | + /** |
|
292 | + * Validates the signature used in a signed request. |
|
293 | + * |
|
294 | + * @param string $hashedSig |
|
295 | + * @param string $sig |
|
296 | + * |
|
297 | + * @throws FacebookSDKException |
|
298 | + */ |
|
299 | + public static function validateSignature($hashedSig, $sig) |
|
300 | + { |
|
301 | 301 | if (mb_strlen($hashedSig) === mb_strlen($sig)) { |
302 | - $validate = 0; |
|
303 | - for ($i = 0; $i < mb_strlen($sig); $i++) { |
|
302 | + $validate = 0; |
|
303 | + for ($i = 0; $i < mb_strlen($sig); $i++) { |
|
304 | 304 | $validate |= ord($hashedSig[$i]) ^ ord($sig[$i]); |
305 | - } |
|
306 | - if ($validate === 0) { |
|
305 | + } |
|
306 | + if ($validate === 0) { |
|
307 | 307 | return; |
308 | - } |
|
308 | + } |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | throw new FacebookSDKException( |
312 | - 'Signed request has an invalid signature.', 602 |
|
312 | + 'Signed request has an invalid signature.', 602 |
|
313 | 313 | ); |
314 | - } |
|
315 | - |
|
316 | - /** |
|
317 | - * Validates a signed request against CSRF. |
|
318 | - * |
|
319 | - * @param array $data |
|
320 | - * @param string $state |
|
321 | - * |
|
322 | - * @throws FacebookSDKException |
|
323 | - */ |
|
324 | - public static function validateCsrf(array $data, $state) |
|
325 | - { |
|
314 | + } |
|
315 | + |
|
316 | + /** |
|
317 | + * Validates a signed request against CSRF. |
|
318 | + * |
|
319 | + * @param array $data |
|
320 | + * @param string $state |
|
321 | + * |
|
322 | + * @throws FacebookSDKException |
|
323 | + */ |
|
324 | + public static function validateCsrf(array $data, $state) |
|
325 | + { |
|
326 | 326 | if (isset($data['state']) && $data['state'] === $state) { |
327 | - return; |
|
327 | + return; |
|
328 | 328 | } |
329 | 329 | |
330 | 330 | throw new FacebookSDKException( |
331 | - 'Signed request did not pass CSRF validation.', 604 |
|
331 | + 'Signed request did not pass CSRF validation.', 604 |
|
332 | 332 | ); |
333 | - } |
|
334 | - |
|
335 | - /** |
|
336 | - * Base64 decoding which replaces characters: |
|
337 | - * + instead of - |
|
338 | - * / instead of _ |
|
339 | - * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
340 | - * |
|
341 | - * @param string $input base64 url encoded input |
|
342 | - * |
|
343 | - * @return string decoded string |
|
344 | - */ |
|
345 | - public static function base64UrlDecode($input) |
|
346 | - { |
|
333 | + } |
|
334 | + |
|
335 | + /** |
|
336 | + * Base64 decoding which replaces characters: |
|
337 | + * + instead of - |
|
338 | + * / instead of _ |
|
339 | + * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
340 | + * |
|
341 | + * @param string $input base64 url encoded input |
|
342 | + * |
|
343 | + * @return string decoded string |
|
344 | + */ |
|
345 | + public static function base64UrlDecode($input) |
|
346 | + { |
|
347 | 347 | $urlDecodedBase64 = strtr($input, '-_', '+/'); |
348 | 348 | static::validateBase64($urlDecodedBase64); |
349 | 349 | return base64_decode($urlDecodedBase64); |
350 | - } |
|
351 | - |
|
352 | - /** |
|
353 | - * Base64 encoding which replaces characters: |
|
354 | - * + instead of - |
|
355 | - * / instead of _ |
|
356 | - * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
357 | - * |
|
358 | - * @param string $input string to encode |
|
359 | - * |
|
360 | - * @return string base64 url encoded input |
|
361 | - */ |
|
362 | - public static function base64UrlEncode($input) |
|
363 | - { |
|
350 | + } |
|
351 | + |
|
352 | + /** |
|
353 | + * Base64 encoding which replaces characters: |
|
354 | + * + instead of - |
|
355 | + * / instead of _ |
|
356 | + * @link http://en.wikipedia.org/wiki/Base64#URL_applications |
|
357 | + * |
|
358 | + * @param string $input string to encode |
|
359 | + * |
|
360 | + * @return string base64 url encoded input |
|
361 | + */ |
|
362 | + public static function base64UrlEncode($input) |
|
363 | + { |
|
364 | 364 | return strtr(base64_encode($input), '+/', '-_'); |
365 | - } |
|
366 | - |
|
367 | - /** |
|
368 | - * Validates a base64 string. |
|
369 | - * |
|
370 | - * @param string $input base64 value to validate |
|
371 | - * |
|
372 | - * @throws FacebookSDKException |
|
373 | - */ |
|
374 | - public static function validateBase64($input) |
|
375 | - { |
|
365 | + } |
|
366 | + |
|
367 | + /** |
|
368 | + * Validates a base64 string. |
|
369 | + * |
|
370 | + * @param string $input base64 value to validate |
|
371 | + * |
|
372 | + * @throws FacebookSDKException |
|
373 | + */ |
|
374 | + public static function validateBase64($input) |
|
375 | + { |
|
376 | 376 | $pattern = '/^[a-zA-Z0-9\/\r\n+]*={0,2}$/'; |
377 | 377 | if (preg_match($pattern, $input)) { |
378 | - return; |
|
378 | + return; |
|
379 | 379 | } |
380 | 380 | |
381 | 381 | throw new FacebookSDKException( |
382 | - 'Signed request contains malformed base64 encoding.', 608 |
|
382 | + 'Signed request contains malformed base64 encoding.', 608 |
|
383 | 383 | ); |
384 | - } |
|
384 | + } |
|
385 | 385 | |
386 | 386 | } |
@@ -18,14 +18,8 @@ |
||
18 | 18 | use Facebook\FacebookSession; |
19 | 19 | use Facebook\FacebookRedirectLoginHelper; |
20 | 20 | use Facebook\FacebookRequest; |
21 | -use Facebook\FacebookResponse; |
|
22 | 21 | use Facebook\FacebookSDKException; |
23 | 22 | use Facebook\FacebookRequestException; |
24 | -use Facebook\FacebookAuthorizationException; |
|
25 | -use Facebook\GraphObject; |
|
26 | -use Facebook\Entities\AccessToken; |
|
27 | -use Facebook\HttpClients\FacebookCurlHttpClient; |
|
28 | -use Facebook\HttpClients\FacebookHttpable; |
|
29 | 23 | |
30 | 24 | require_once dirname(__FILE__) . '/functions.inc.php'; |
31 | 25 |
@@ -11,9 +11,9 @@ discard block |
||
11 | 11 | * Please edit the facebook.conf.php file to adapt it to your fb application parameter |
12 | 12 | */ |
13 | 13 | |
14 | -require_once dirname(__FILE__) . '/../../inc/global.inc.php'; |
|
15 | -require_once dirname(__FILE__) . '/facebook.init.php'; |
|
16 | -require_once dirname(__FILE__) . '/facebook-php-sdk/autoload.php'; |
|
14 | +require_once dirname(__FILE__).'/../../inc/global.inc.php'; |
|
15 | +require_once dirname(__FILE__).'/facebook.init.php'; |
|
16 | +require_once dirname(__FILE__).'/facebook-php-sdk/autoload.php'; |
|
17 | 17 | |
18 | 18 | use Facebook\FacebookSession; |
19 | 19 | use Facebook\FacebookRedirectLoginHelper; |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | use Facebook\HttpClients\FacebookCurlHttpClient; |
28 | 28 | use Facebook\HttpClients\FacebookHttpable; |
29 | 29 | |
30 | -require_once dirname(__FILE__) . '/functions.inc.php'; |
|
30 | +require_once dirname(__FILE__).'/functions.inc.php'; |
|
31 | 31 | |
32 | 32 | // dont rename $facebook_config to $facebookConfig otherwise get a "Facebook\\FacebookSDKException" |
33 | 33 | FacebookSession::setDefaultApplication($facebook_config['appId'], $facebook_config['secret']); |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | $locale = $graphObject->getProperty('locale'); |
58 | 58 | $language = facebookPluginGetLanguage($locale); |
59 | 59 | if (!$language) { |
60 | - $language='en_US'; |
|
60 | + $language = 'en_US'; |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | //Checks if user already exists in chamilo |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $_user['user_id'] = $chamilo_uid; |
86 | 86 | $_user['uidReset'] = true; |
87 | 87 | $_SESSION['_user'] = $_user; |
88 | - header('Location:' . api_get_path(WEB_PATH)); |
|
88 | + header('Location:'.api_get_path(WEB_PATH)); |
|
89 | 89 | exit(); |
90 | 90 | } else { |
91 | 91 | return false; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | $_user['user_id'] = $chamilo_uid; |
99 | 99 | $_user['uidReset'] = true; |
100 | 100 | $_SESSION['_user'] = $_user; |
101 | - header('Location:' . api_get_path(WEB_PATH)); |
|
101 | + header('Location:'.api_get_path(WEB_PATH)); |
|
102 | 102 | exit(); |
103 | 103 | } |
104 | 104 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | { |
118 | 118 | global $facebook_config; |
119 | 119 | $helper = new FacebookRedirectLoginHelper($facebook_config['return_url']); |
120 | - $loginUrl = $helper->getLoginUrl( |
|
120 | + $loginUrl = $helper->getLoginUrl( |
|
121 | 121 | array('scope' => 'email') |
122 | 122 | ); |
123 | 123 |
@@ -148,7 +148,7 @@ |
||
148 | 148 | * - language |
149 | 149 | * - courses : string of all courses code separated by '|' |
150 | 150 | * - admin : boolean |
151 | - * @return boolean |
|
151 | + * @return boolean|null |
|
152 | 152 | * @author ndiechburg <[email protected]> |
153 | 153 | * */ |
154 | 154 | function external_update_user($new_user) { |
@@ -20,7 +20,7 @@ |
||
20 | 20 | //Those are the mandatory fields for user creation. |
21 | 21 | //See external_add_user function for all the fields you can have. |
22 | 22 | $table = USERINFO_TABLE; |
23 | - $sql = "SELECT * from $table where username='" . Database::escape_string($login) . "'"; |
|
23 | + $sql = "SELECT * from $table where username='".Database::escape_string($login)."'"; |
|
24 | 24 | $result = Database::query($sql); |
25 | 25 | |
26 | 26 | if (Database::num_rows($result) == 0) { //false password |
@@ -95,30 +95,43 @@ |
||
95 | 95 | * */ |
96 | 96 | function external_add_user($u) { |
97 | 97 | //Setting default |
98 | - if (empty($u['password'])) |
|
99 | - $u['password'] = null; |
|
100 | - if (empty($u['status'])) |
|
101 | - $u['status'] = 5; |
|
102 | - if (!isset($u['official_code'])) |
|
103 | - $u['official_code'] = ''; |
|
104 | - if (!isset($u['language'])) |
|
105 | - $u['language'] = ''; |
|
106 | - if (!isset($u['phone'])) |
|
107 | - $u['phone'] = ''; |
|
108 | - if (!isset($u['picture_uri'])) |
|
109 | - $u['picture_uri'] = ''; |
|
110 | - if (!isset($u['auth_source'])) |
|
111 | - $u['auth_source'] = PLATFORM_AUTH_SOURCE; |
|
112 | - if (!isset($u['expiration_date'])) |
|
113 | - $u['expiration_date'] = '0000-00-00 00:00:00'; |
|
114 | - if (!isset($u['active'])) |
|
115 | - $u['active'] = 1; |
|
116 | - if (!isset($u['hr_dept_id'])) |
|
117 | - $u['hr_dept_id'] = 0; //id of responsible HR |
|
118 | - if (!isset($u['extra'])) |
|
119 | - $u['extra'] = null; |
|
120 | - if (!isset($u['encrypt_method'])) |
|
121 | - $u['encrypt_method'] = ''; |
|
98 | + if (empty($u['password'])) { |
|
99 | + $u['password'] = null; |
|
100 | + } |
|
101 | + if (empty($u['status'])) { |
|
102 | + $u['status'] = 5; |
|
103 | + } |
|
104 | + if (!isset($u['official_code'])) { |
|
105 | + $u['official_code'] = ''; |
|
106 | + } |
|
107 | + if (!isset($u['language'])) { |
|
108 | + $u['language'] = ''; |
|
109 | + } |
|
110 | + if (!isset($u['phone'])) { |
|
111 | + $u['phone'] = ''; |
|
112 | + } |
|
113 | + if (!isset($u['picture_uri'])) { |
|
114 | + $u['picture_uri'] = ''; |
|
115 | + } |
|
116 | + if (!isset($u['auth_source'])) { |
|
117 | + $u['auth_source'] = PLATFORM_AUTH_SOURCE; |
|
118 | + } |
|
119 | + if (!isset($u['expiration_date'])) { |
|
120 | + $u['expiration_date'] = '0000-00-00 00:00:00'; |
|
121 | + } |
|
122 | + if (!isset($u['active'])) { |
|
123 | + $u['active'] = 1; |
|
124 | + } |
|
125 | + if (!isset($u['hr_dept_id'])) { |
|
126 | + $u['hr_dept_id'] = 0; |
|
127 | + } |
|
128 | + //id of responsible HR |
|
129 | + if (!isset($u['extra'])) { |
|
130 | + $u['extra'] = null; |
|
131 | + } |
|
132 | + if (!isset($u['encrypt_method'])) { |
|
133 | + $u['encrypt_method'] = ''; |
|
134 | + } |
|
122 | 135 | |
123 | 136 | $chamilo_uid = UserManager::create_user($u['firstname'], $u['lastname'], $u['status'], $u['email'], $u['username'], $u['password'], $u['official_code'], $u['language'], $u['phone'], $u['picture_uri'], $u['auth_source'], $u['expiration_date'], $u['active'], $u['hr_dept_id'], $u['extra'], $u['encrypt_method']); |
124 | 137 | return $chamilo_uid; |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | /** |
29 | 29 | * Establishes a connection to the LDAP server and sets the protocol version |
30 | 30 | * |
31 | - * @return resource ldap link identifier or false |
|
31 | + * @return boolean ldap link identifier or false |
|
32 | 32 | * @author ndiechburg <[email protected]> |
33 | 33 | * */ |
34 | 34 | function extldap_connect() |
@@ -77,6 +77,7 @@ discard block |
||
77 | 77 | /** |
78 | 78 | * Authenticate user on external ldap server and return user ldap entry if that succeeds |
79 | 79 | * |
80 | + * @param string $password |
|
80 | 81 | * @return mixed false if user cannot authenticate on ldap, user ldap entry if tha succeeds |
81 | 82 | * @author ndiechburg <[email protected]> |
82 | 83 | * Modified by [email protected] |
@@ -237,7 +238,7 @@ discard block |
||
237 | 238 | |
238 | 239 | /** |
239 | 240 | * Imports all LDAP users into Chamilo |
240 | - * @return bool false on error, true otherwise |
|
241 | + * @return false|null false on error, true otherwise |
|
241 | 242 | */ |
242 | 243 | function extldap_import_all_users() |
243 | 244 | { |
@@ -303,7 +303,7 @@ |
||
303 | 303 | |
304 | 304 | // TODO the password, if encrypted at the source, will be encrypted twice, which makes it useless. Try to fix that. |
305 | 305 | $passwordKey = isset($extldap_user_correspondance['password']) ? $extldap_user_correspondance['password'] : 'userPassword'; |
306 | - $password = $data[$passwordKey][0]; |
|
306 | + $password = $data[$passwordKey][0]; |
|
307 | 307 | |
308 | 308 | // To ease management, we add the step-year (etape-annee) code |
309 | 309 | //$official_code = $etape."-".$annee; |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | require 'ldap_var.inc.php'; |
68 | 68 | /** |
69 | 69 | * Check login and password with LDAP |
70 | - * @return true when login & password both OK, false otherwise |
|
70 | + * @return boolean when login & password both OK, false otherwise |
|
71 | 71 | * @author Roan Embrechts (based on code from Universit� Jean Monet) |
72 | 72 | */ |
73 | 73 | |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | } // end of check |
306 | 306 | /** |
307 | 307 | * Set the protocol version with version from config file (enables LDAP version 3) |
308 | - * @param resource The LDAP connexion resource, passed by reference. |
|
308 | + * @param resource resource LDAP connexion resource, passed by reference. |
|
309 | 309 | * @return void |
310 | 310 | */ |
311 | 311 | function ldap_set_version(&$resource) { |
@@ -323,6 +323,7 @@ discard block |
||
323 | 323 | * Handle bind (whether authenticated or not) |
324 | 324 | * @param resource The LDAP handler to which we are connecting (by reference) |
325 | 325 | * @param resource The LDAP bind handler we will be modifying |
326 | + * @param boolean $ldap_bind |
|
326 | 327 | * @return boolean Status of the bind assignment. True for success, false for failure. |
327 | 328 | */ |
328 | 329 | function ldap_handle_bind(&$ldap_handler,&$ldap_bind) { |
@@ -80,7 +80,12 @@ discard block |
||
80 | 80 | |
81 | 81 | if ($res==1) { //WRONG PASSWORD |
82 | 82 | //$errorMessage = "LDAP User or password incorrect, try again.<br />"; |
83 | - if (isset($log)) unset($log); if (isset($uid)) unset($uid); |
|
83 | + if (isset($log)) { |
|
84 | + unset($log); |
|
85 | + } |
|
86 | + if (isset($uid)) { |
|
87 | + unset($uid); |
|
88 | + } |
|
84 | 89 | $loginLdapSucces = false; |
85 | 90 | } |
86 | 91 | if ($res==-1) { //WRONG USERNAME |
@@ -401,8 +406,9 @@ discard block |
||
401 | 406 | return $info; |
402 | 407 | |
403 | 408 | } else { |
404 | - if (count($ldap_query)!=0) |
|
405 | - Display :: display_error_message(get_lang('LDAPConnectionError')); |
|
409 | + if (count($ldap_query)!=0) { |
|
410 | + Display :: display_error_message(get_lang('LDAPConnectionError')); |
|
411 | + } |
|
406 | 412 | return array(); |
407 | 413 | } |
408 | 414 | } |
@@ -78,16 +78,16 @@ discard block |
||
78 | 78 | // res=-1 -> the user does not exist in the ldap database |
79 | 79 | // res=1 -> invalid password (user does exist) |
80 | 80 | |
81 | - if ($res==1) { //WRONG PASSWORD |
|
81 | + if ($res == 1) { //WRONG PASSWORD |
|
82 | 82 | //$errorMessage = "LDAP User or password incorrect, try again.<br />"; |
83 | 83 | if (isset($log)) unset($log); if (isset($uid)) unset($uid); |
84 | 84 | $loginLdapSucces = false; |
85 | 85 | } |
86 | - if ($res==-1) { //WRONG USERNAME |
|
86 | + if ($res == -1) { //WRONG USERNAME |
|
87 | 87 | //$errorMessage = "LDAP User or password incorrect, try again.<br />"; |
88 | 88 | $login_ldap_success = false; |
89 | 89 | } |
90 | - if ($res==0) { //LOGIN & PASSWORD OK - SUCCES |
|
90 | + if ($res == 0) { //LOGIN & PASSWORD OK - SUCCES |
|
91 | 91 | //$errorMessage = "Successful login w/ LDAP.<br>"; |
92 | 92 | $login_ldap_success = true; |
93 | 93 | } |
@@ -103,30 +103,30 @@ discard block |
||
103 | 103 | * @author Stefan De Wannemacker |
104 | 104 | * @author Roan Embrechts |
105 | 105 | */ |
106 | -function ldap_find_user_info ($login) { |
|
106 | +function ldap_find_user_info($login) { |
|
107 | 107 | //error_log('Entering ldap_find_user_info('.$login.')',0); |
108 | 108 | global $ldap_host, $ldap_port, $ldap_basedn, $ldap_rdn, $ldap_pass, $ldap_search_dn; |
109 | 109 | // basic sequence with LDAP is connect, bind, search, |
110 | 110 | // interpret search result, close connection |
111 | 111 | |
112 | 112 | //echo "Connecting ..."; |
113 | - $ldap_connect = ldap_connect( $ldap_host, $ldap_port); |
|
113 | + $ldap_connect = ldap_connect($ldap_host, $ldap_port); |
|
114 | 114 | ldap_set_version($ldap_connect); |
115 | 115 | if ($ldap_connect) { |
116 | 116 | //echo " Connect to LDAP server successful "; |
117 | 117 | //echo "Binding ..."; |
118 | 118 | $ldap_bind = false; |
119 | - $ldap_bind_res = ldap_handle_bind($ldap_connect,$ldap_bind); |
|
119 | + $ldap_bind_res = ldap_handle_bind($ldap_connect, $ldap_bind); |
|
120 | 120 | if ($ldap_bind_res) { |
121 | 121 | //echo " LDAP bind successful... "; |
122 | 122 | //echo " Searching for uid... "; |
123 | 123 | // Search surname entry |
124 | 124 | //OLD: $sr=ldap_search($ldapconnect,"dc=rug, dc=ac, dc=be", "uid=$login"); |
125 | 125 | //echo "<p> ldapDc = '$LDAPbasedn' </p>"; |
126 | - if(!empty($ldap_search_dn)) { |
|
127 | - $sr=ldap_search($ldap_connect, $ldap_search_dn, "uid=$login"); |
|
126 | + if (!empty($ldap_search_dn)) { |
|
127 | + $sr = ldap_search($ldap_connect, $ldap_search_dn, "uid=$login"); |
|
128 | 128 | } else { |
129 | - $sr=ldap_search($ldap_connect, $ldap_basedn, "uid=$login"); |
|
129 | + $sr = ldap_search($ldap_connect, $ldap_basedn, "uid=$login"); |
|
130 | 130 | } |
131 | 131 | //echo " Search result is ".$sr; |
132 | 132 | //echo " Number of entries returned is ".ldap_count_entries($ldapconnect,$sr); |
@@ -177,25 +177,25 @@ discard block |
||
177 | 177 | $password1 = $ldap_pass_placeholder; |
178 | 178 | $official_code = ''; |
179 | 179 | |
180 | - define ("STUDENT",5); |
|
181 | - define ("COURSEMANAGER",1); |
|
180 | + define("STUDENT", 5); |
|
181 | + define("COURSEMANAGER", 1); |
|
182 | 182 | |
183 | 183 | $tutor_field = api_get_setting('ldap_filled_tutor_field'); |
184 | 184 | $tutor_value = api_get_setting('ldap_filled_tutor_field_value'); |
185 | - if(empty($tutor_field)) { |
|
185 | + if (empty($tutor_field)) { |
|
186 | 186 | $status = STUDENT; |
187 | 187 | } else { |
188 | - if(empty($tutor_value)) { |
|
188 | + if (empty($tutor_value)) { |
|
189 | 189 | //in this case, we are assuming that the admin didn't give a criteria |
190 | 190 | // so that if the field is not empty, it is a tutor |
191 | - if(!empty($info_array[$tutor_field])) { |
|
191 | + if (!empty($info_array[$tutor_field])) { |
|
192 | 192 | $status = COURSEMANAGER; |
193 | 193 | } else { |
194 | 194 | $status = STUDENT; |
195 | 195 | } |
196 | 196 | } else { |
197 | 197 | //the tutor_value is filled, so we need to check the contents of the LDAP field |
198 | - if (is_array($info_array[$tutor_field]) && in_array($tutor_value,$info_array[$tutor_field])) { |
|
198 | + if (is_array($info_array[$tutor_field]) && in_array($tutor_value, $info_array[$tutor_field])) { |
|
199 | 199 | $status = COURSEMANAGER; |
200 | 200 | } else { |
201 | 201 | $status = STUDENT; |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | if (empty($language)) { $language = 'english'; } |
213 | 213 | $_userId = UserManager::create_user($prenom, $nom, $status, |
214 | 214 | $email, $uname, $password, $official_code, |
215 | - $language,'', '', 'ldap'); |
|
215 | + $language, '', '', 'ldap'); |
|
216 | 216 | |
217 | 217 | //echo "new user added to Chamilo, id = $_userId"; |
218 | 218 | |
@@ -246,58 +246,58 @@ discard block |
||
246 | 246 | * @param string password given by user |
247 | 247 | * @return int 0 if authentication succeeded, 1 if password was incorrect, -1 if it didn't belong to LDAP |
248 | 248 | */ |
249 | -function ldap_authentication_check ($uname, $passwd) { |
|
249 | +function ldap_authentication_check($uname, $passwd) { |
|
250 | 250 | //error_log('Entering ldap_authentication_check('.$uname.','.$passwd.')',0); |
251 | - global $ldap_host, $ldap_port, $ldap_basedn, $ldap_host2, $ldap_port2,$ldap_rdn,$ldap_pass; |
|
251 | + global $ldap_host, $ldap_port, $ldap_basedn, $ldap_host2, $ldap_port2, $ldap_rdn, $ldap_pass; |
|
252 | 252 | //error_log('Entering ldap_authentication_check('.$uname.','.$passwd.')',0); |
253 | 253 | // Establish anonymous connection with LDAP server |
254 | 254 | // Etablissement de la connexion anonyme avec le serveur LDAP |
255 | - $ds=ldap_connect($ldap_host,$ldap_port); |
|
255 | + $ds = ldap_connect($ldap_host, $ldap_port); |
|
256 | 256 | ldap_set_version($ds); |
257 | 257 | |
258 | 258 | $test_bind = false; |
259 | - $test_bind_res = ldap_handle_bind($ds,$test_bind); |
|
259 | + $test_bind_res = ldap_handle_bind($ds, $test_bind); |
|
260 | 260 | //if problem, use the replica |
261 | - if ($test_bind_res===false) { |
|
262 | - $ds=ldap_connect($ldap_host2,$ldap_port2); |
|
261 | + if ($test_bind_res === false) { |
|
262 | + $ds = ldap_connect($ldap_host2, $ldap_port2); |
|
263 | 263 | ldap_set_version($ds); |
264 | 264 | } else { |
265 | 265 | //error_log('Connected to server '.$ldap_host); |
266 | 266 | } |
267 | - if ($ds!==false) { |
|
267 | + if ($ds !== false) { |
|
268 | 268 | //Creation of filter containing values input by the user |
269 | 269 | // Here it might be necessary to use $filter="(samaccountName=$uname)"; - see http://support.chamilo.org/issues/4675 |
270 | - $filter="(uid=$uname)"; |
|
270 | + $filter = "(uid=$uname)"; |
|
271 | 271 | // Open anonymous LDAP connection |
272 | - $result=false; |
|
273 | - $ldap_bind_res = ldap_handle_bind($ds,$result); |
|
272 | + $result = false; |
|
273 | + $ldap_bind_res = ldap_handle_bind($ds, $result); |
|
274 | 274 | // Executing the search with the $filter parametr |
275 | 275 | //error_log('Searching for '.$filter.' on LDAP server',0); |
276 | - $sr=ldap_search($ds,$ldap_basedn,$filter); |
|
276 | + $sr = ldap_search($ds, $ldap_basedn, $filter); |
|
277 | 277 | $info = ldap_get_entries($ds, $sr); |
278 | - $dn=($info[0]["dn"]); |
|
278 | + $dn = ($info[0]["dn"]); |
|
279 | 279 | // debug !! echo"<br> dn = $dn<br> pass = $passwd<br>"; |
280 | 280 | // closing 1st connection |
281 | 281 | ldap_close($ds); |
282 | 282 | } |
283 | 283 | |
284 | 284 | // test the Distinguish Name from the 1st connection |
285 | - if ($dn=="") { |
|
286 | - return (-1); // doesn't belong to the addressbook |
|
285 | + if ($dn == "") { |
|
286 | + return (-1); // doesn't belong to the addressbook |
|
287 | 287 | } |
288 | 288 | //bug ldap.. if password empty, return 1! |
289 | - if ($passwd=="") { |
|
289 | + if ($passwd == "") { |
|
290 | 290 | return(1); |
291 | 291 | } |
292 | 292 | // Opening 2nd LDAP connection : Connection user for password check |
293 | - $ds=ldap_connect($ldap_host,$ldap_port); |
|
293 | + $ds = ldap_connect($ldap_host, $ldap_port); |
|
294 | 294 | ldap_set_version($ds); |
295 | 295 | if (!$test_bind) { |
296 | - $ds=ldap_connect($ldap_host2,$ldap_port2); |
|
296 | + $ds = ldap_connect($ldap_host2, $ldap_port2); |
|
297 | 297 | ldap_set_version($ds); |
298 | 298 | } |
299 | 299 | // return in case of wrong password connection error |
300 | - if (@ldap_bind( $ds, $dn , $passwd) === false) { |
|
300 | + if (@ldap_bind($ds, $dn, $passwd) === false) { |
|
301 | 301 | return (1); // invalid password |
302 | 302 | } else {// connection successfull |
303 | 303 | return (0); |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | function ldap_set_version(&$resource) { |
312 | 312 | //error_log('Entering ldap_set_version(&$resource)',0); |
313 | 313 | global $ldap_version; |
314 | - if ($ldap_version>2) { |
|
314 | + if ($ldap_version > 2) { |
|
315 | 315 | if (ldap_set_option($resource, LDAP_OPT_PROTOCOL_VERSION, 3)) { |
316 | 316 | //ok - don't do anything |
317 | 317 | } else { |
@@ -325,14 +325,14 @@ discard block |
||
325 | 325 | * @param resource The LDAP bind handler we will be modifying |
326 | 326 | * @return boolean Status of the bind assignment. True for success, false for failure. |
327 | 327 | */ |
328 | -function ldap_handle_bind(&$ldap_handler,&$ldap_bind) { |
|
328 | +function ldap_handle_bind(&$ldap_handler, &$ldap_bind) { |
|
329 | 329 | //error_log('Entering ldap_handle_bind(&$ldap_handler,&$ldap_bind)',0); |
330 | - global $ldap_rdn,$ldap_pass, $extldap_config; |
|
330 | + global $ldap_rdn, $ldap_pass, $extldap_config; |
|
331 | 331 | $ldap_rdn = $extldap_config['admin_dn']; |
332 | 332 | $ldap_pass = $extldap_config['admin_password']; |
333 | 333 | if (!empty($ldap_rdn) and !empty($ldap_pass)) { |
334 | 334 | //error_log('Trying authenticated login :'.$ldap_rdn.'/'.$ldap_pass,0); |
335 | - $ldap_bind = ldap_bind($ldap_handler,$ldap_rdn,$ldap_pass); |
|
335 | + $ldap_bind = ldap_bind($ldap_handler, $ldap_rdn, $ldap_pass); |
|
336 | 336 | if (!$ldap_bind) { |
337 | 337 | //error_log('Authenticated login failed',0); |
338 | 338 | //try in anonymous mode, you never know... |
@@ -358,40 +358,40 @@ discard block |
||
358 | 358 | |
359 | 359 | global $ldap_basedn, $ldap_host, $ldap_port, $ldap_rdn, $ldap_pass, $ldap_search_dn, $extldap_user_correspondance; |
360 | 360 | |
361 | - $keyword_firstname = isset($_GET['keyword_firstname']) ? trim(Database::escape_string($_GET['keyword_firstname'])): ''; |
|
361 | + $keyword_firstname = isset($_GET['keyword_firstname']) ? trim(Database::escape_string($_GET['keyword_firstname'])) : ''; |
|
362 | 362 | $keyword_lastname = isset($_GET['keyword_lastname']) ? trim(Database::escape_string($_GET['keyword_lastname'])) : ''; |
363 | 363 | $keyword_username = isset($_GET['keyword_username']) ? trim(Database::escape_string($_GET['keyword_username'])) : ''; |
364 | 364 | $keyword_type = isset($_GET['keyword_type']) ? Database::escape_string($_GET['keyword_type']) : ''; |
365 | 365 | |
366 | - $ldap_query=array(); |
|
366 | + $ldap_query = array(); |
|
367 | 367 | |
368 | 368 | if ($keyword_username != "") { |
369 | 369 | $ldap_query[] = str_replace('%username%', $keyword_username, $ldap_search_dn); |
370 | 370 | } else { |
371 | - if ($keyword_lastname!=""){ |
|
372 | - $ldap_query[]="(".$extldap_user_correspondance['lastname']."=".$keyword_lastname."*)"; |
|
371 | + if ($keyword_lastname != "") { |
|
372 | + $ldap_query[] = "(".$extldap_user_correspondance['lastname']."=".$keyword_lastname."*)"; |
|
373 | 373 | } |
374 | - if ($keyword_firstname!="") { |
|
375 | - $ldap_query[]="(".$extldap_user_correspondance['firstname']."=".$keyword_firstname."*)"; |
|
374 | + if ($keyword_firstname != "") { |
|
375 | + $ldap_query[] = "(".$extldap_user_correspondance['firstname']."=".$keyword_firstname."*)"; |
|
376 | 376 | } |
377 | 377 | } |
378 | - if ($keyword_type !="" && $keyword_type !="all") { |
|
379 | - $ldap_query[]="(employeeType=".$keyword_type.")"; |
|
378 | + if ($keyword_type != "" && $keyword_type != "all") { |
|
379 | + $ldap_query[] = "(employeeType=".$keyword_type.")"; |
|
380 | 380 | } |
381 | 381 | |
382 | - if (count($ldap_query)>1){ |
|
383 | - $str_query.="(& "; |
|
384 | - foreach ($ldap_query as $query){ |
|
385 | - $str_query.=" $query"; |
|
382 | + if (count($ldap_query) > 1) { |
|
383 | + $str_query .= "(& "; |
|
384 | + foreach ($ldap_query as $query) { |
|
385 | + $str_query .= " $query"; |
|
386 | 386 | } |
387 | - $str_query.=" )"; |
|
387 | + $str_query .= " )"; |
|
388 | 388 | } else { |
389 | - $str_query= count($ldap_query) > 0 ? $ldap_query[0] : null; |
|
389 | + $str_query = count($ldap_query) > 0 ? $ldap_query[0] : null; |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | $ds = ldap_connect($ldap_host, $ldap_port); |
393 | 393 | ldap_set_version($ds); |
394 | - if ($ds && count($ldap_query)>0) { |
|
394 | + if ($ds && count($ldap_query) > 0) { |
|
395 | 395 | $r = false; |
396 | 396 | $res = ldap_handle_bind($ds, $r); |
397 | 397 | //$sr = ldap_search($ds, "ou=test-ou,$ldap_basedn", $str_query); |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | return $info; |
402 | 402 | |
403 | 403 | } else { |
404 | - if (count($ldap_query)!=0) |
|
404 | + if (count($ldap_query) != 0) |
|
405 | 405 | Display :: display_error_message(get_lang('LDAPConnectionError')); |
406 | 406 | return array(); |
407 | 407 | } |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | */ |
415 | 415 | function ldap_get_number_of_users() { |
416 | 416 | $info = ldap_get_users(); |
417 | - if (count($info)>0) { |
|
417 | + if (count($info) > 0) { |
|
418 | 418 | return $info['count']; |
419 | 419 | } else { |
420 | 420 | return 0; |
@@ -434,9 +434,9 @@ discard block |
||
434 | 434 | $is_western_name_order = api_is_western_name_order(); |
435 | 435 | if (isset($_GET['submit'])) { |
436 | 436 | $info = ldap_get_users(); |
437 | - if ($info['count']>0) { |
|
438 | - for ($key = 0; $key < $info["count"]; $key ++) { |
|
439 | - $user=array(); |
|
437 | + if ($info['count'] > 0) { |
|
438 | + for ($key = 0; $key < $info["count"]; $key++) { |
|
439 | + $user = array(); |
|
440 | 440 | // Get uid from dn |
441 | 441 | //YW: this might be a variation between LDAP 2 and LDAP 3, but in LDAP 3, the uid is in |
442 | 442 | //the corresponding index of the array |
@@ -470,9 +470,9 @@ discard block |
||
470 | 470 | * @return string Some HTML-code with modify-buttons |
471 | 471 | * @author Mustapha Alouani |
472 | 472 | */ |
473 | -function modify_filter($user_id,$url_params, $row) { |
|
474 | - $query_string="id[]=".$row[0]; |
|
475 | - if (!empty($_GET['id_session'])){ |
|
473 | +function modify_filter($user_id, $url_params, $row) { |
|
474 | + $query_string = "id[]=".$row[0]; |
|
475 | + if (!empty($_GET['id_session'])) { |
|
476 | 476 | $query_string .= '&id_session='.Security::remove_XSS($_GET['id_session']); |
477 | 477 | } |
478 | 478 | //$url_params_id="id=".$row[0]; |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | $firstname = api_convert_encoding($data['cn'][0], api_get_system_encoding(), 'UTF-8'); |
498 | 498 | $email = $data['mail'][0]; |
499 | 499 | // Get uid from dn |
500 | - $dn_array=ldap_explode_dn($data['dn'],1); |
|
500 | + $dn_array = ldap_explode_dn($data['dn'], 1); |
|
501 | 501 | $username = $dn_array[0]; // uid is first key |
502 | 502 | $outab[] = $data['edupersonprimaryaffiliation'][0]; // Here, "student" |
503 | 503 | //$val = ldap_get_values_len($ds, $entry, "userPassword"); |
@@ -505,21 +505,21 @@ discard block |
||
505 | 505 | //$password = $val[0]; |
506 | 506 | // TODO the password, if encrypted at the source, will be encrypted twice, which makes it useless. Try to fix that. |
507 | 507 | $password = $data['userPassword'][0]; |
508 | - $structure=$data['edupersonprimaryorgunitdn'][0]; |
|
509 | - $array_structure=explode(",", $structure); |
|
510 | - $array_val=explode("=", $array_structure[0]); |
|
511 | - $etape=$array_val[1]; |
|
512 | - $array_val=explode("=", $array_structure[1]); |
|
513 | - $annee=$array_val[1]; |
|
508 | + $structure = $data['edupersonprimaryorgunitdn'][0]; |
|
509 | + $array_structure = explode(",", $structure); |
|
510 | + $array_val = explode("=", $array_structure[0]); |
|
511 | + $etape = $array_val[1]; |
|
512 | + $array_val = explode("=", $array_structure[1]); |
|
513 | + $annee = $array_val[1]; |
|
514 | 514 | // To ease management, we add the step-year (etape-annee) code |
515 | - $official_code=$etape."-".$annee; |
|
516 | - $auth_source='ldap'; |
|
515 | + $official_code = $etape."-".$annee; |
|
516 | + $auth_source = 'ldap'; |
|
517 | 517 | // No expiration date for students (recover from LDAP's shadow expiry) |
518 | - $expiration_date='0000-00-00 00:00:00'; |
|
519 | - $active=1; |
|
520 | - if(empty($status)){$status = 5;} |
|
521 | - if(empty($phone)){$phone = '';} |
|
522 | - if(empty($picture_uri)){$picture_uri = '';} |
|
518 | + $expiration_date = '0000-00-00 00:00:00'; |
|
519 | + $active = 1; |
|
520 | + if (empty($status)) {$status = 5; } |
|
521 | + if (empty($phone)) {$phone = ''; } |
|
522 | + if (empty($picture_uri)) {$picture_uri = ''; } |
|
523 | 523 | // Adding user |
524 | 524 | $user_id = 0; |
525 | 525 | if (UserManager::is_username_available($username)) { |
@@ -541,7 +541,7 @@ discard block |
||
541 | 541 | } else { |
542 | 542 | if ($update_if_exists) { |
543 | 543 | $user = api_get_user_info($username); |
544 | - $user_id=$user['user_id']; |
|
544 | + $user_id = $user['user_id']; |
|
545 | 545 | UserManager::update_user($user_id, $firstname, $lastname, $username, null, null, $email, $status, $official_code, $phone, $picture_uri, $expiration_date, $active); |
546 | 546 | } |
547 | 547 | } |
@@ -558,21 +558,21 @@ discard block |
||
558 | 558 | |
559 | 559 | // Database Table Definitions |
560 | 560 | $tbl_session = Database::get_main_table(TABLE_MAIN_SESSION); |
561 | - $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS); |
|
561 | + $tbl_session_rel_class = Database::get_main_table(TABLE_MAIN_SESSION_CLASS); |
|
562 | 562 | $tbl_session_rel_course = Database::get_main_table(TABLE_MAIN_SESSION_COURSE); |
563 | 563 | $tbl_session_rel_course_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER); |
564 | 564 | $tbl_course = Database::get_main_table(TABLE_MAIN_COURSE); |
565 | 565 | $tbl_user = Database::get_main_table(TABLE_MAIN_USER); |
566 | 566 | $tbl_session_rel_user = Database::get_main_table(TABLE_MAIN_SESSION_USER); |
567 | - $tbl_class = Database::get_main_table(TABLE_MAIN_CLASS); |
|
568 | - $tbl_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER); |
|
567 | + $tbl_class = Database::get_main_table(TABLE_MAIN_CLASS); |
|
568 | + $tbl_class_user = Database::get_main_table(TABLE_MAIN_CLASS_USER); |
|
569 | 569 | |
570 | 570 | $id_session = (int) $id_session; |
571 | 571 | // Once users are imported in the users base, we can assign them to the session |
572 | - $result=Database::query("SELECT c_id FROM $tbl_session_rel_course WHERE session_id ='$id_session'"); |
|
573 | - $CourseList=array(); |
|
574 | - while ($row=Database::fetch_array($result)) { |
|
575 | - $CourseList[]=$row['c_id']; |
|
572 | + $result = Database::query("SELECT c_id FROM $tbl_session_rel_course WHERE session_id ='$id_session'"); |
|
573 | + $CourseList = array(); |
|
574 | + while ($row = Database::fetch_array($result)) { |
|
575 | + $CourseList[] = $row['c_id']; |
|
576 | 576 | } |
577 | 577 | foreach ($CourseList as $enreg_course) { |
578 | 578 | foreach ($UserList as $enreg_user) { |
@@ -583,21 +583,21 @@ discard block |
||
583 | 583 | "('$id_session','$enreg_course','$enreg_user')"); |
584 | 584 | } |
585 | 585 | $sql = "SELECT COUNT(user_id) as nbUsers ". |
586 | - " FROM $tbl_session_rel_course_rel_user " . |
|
586 | + " FROM $tbl_session_rel_course_rel_user ". |
|
587 | 587 | " WHERE session_id='$id_session' ". |
588 | 588 | " AND c_id='$enreg_course'"; |
589 | 589 | $rs = Database::query($sql); |
590 | 590 | list($nbr_users) = Database::fetch_array($rs); |
591 | 591 | Database::query("UPDATE $tbl_session_rel_course ". |
592 | - " SET nbr_users=$nbr_users " . |
|
592 | + " SET nbr_users=$nbr_users ". |
|
593 | 593 | " WHERE session_id='$id_session' ". |
594 | 594 | " AND c_id='$enreg_course'"); |
595 | 595 | } |
596 | 596 | foreach ($UserList as $enreg_user) { |
597 | 597 | $enreg_user = (int) $enreg_user; |
598 | 598 | Database::query("INSERT IGNORE INTO $tbl_session_rel_user ". |
599 | - " (session_id, user_id, registered_at) " . |
|
600 | - " VALUES('$id_session','$enreg_user', '" . api_get_utc_datetime() . "')"); |
|
599 | + " (session_id, user_id, registered_at) ". |
|
600 | + " VALUES('$id_session','$enreg_user', '".api_get_utc_datetime()."')"); |
|
601 | 601 | } |
602 | 602 | // We update the number of users in the session |
603 | 603 | $sql = "SELECT COUNT(user_id) as nbUsers FROM $tbl_session_rel_user ". |
@@ -612,13 +612,13 @@ discard block |
||
612 | 612 | function syncro_users() { |
613 | 613 | global $ldap_basedn, $ldap_host, $ldap_port, $ldap_rdn, $ldap_pass, $ldap_search_dn; |
614 | 614 | echo "Connecting ..."; |
615 | - $ldap_connect = ldap_connect( $ldap_host, $ldap_port); |
|
615 | + $ldap_connect = ldap_connect($ldap_host, $ldap_port); |
|
616 | 616 | ldap_set_version($ldap_connect); |
617 | 617 | if ($ldap_connect) { |
618 | 618 | //echo " Connect to LDAP server successful "; |
619 | 619 | //echo "Binding ..."; |
620 | 620 | $ldap_bind = false; |
621 | - $ldap_bind_res = ldap_handle_bind($ldap_connect,$ldap_bind); |
|
621 | + $ldap_bind_res = ldap_handle_bind($ldap_connect, $ldap_bind); |
|
622 | 622 | if ($ldap_bind_res) { |
623 | 623 | //echo " LDAP bind successful... "; |
624 | 624 | //echo " Searching for uid... "; |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | //OLD: $sr=ldap_search($ldapconnect,"dc=rug, dc=ac, dc=be", "uid=$login"); |
627 | 627 | //echo "<p> ldapDc = '$LDAPbasedn' </p>"; |
628 | 628 | $all_user_query = "uid=*"; |
629 | - if(!empty($ldap_search_dn)) { |
|
629 | + if (!empty($ldap_search_dn)) { |
|
630 | 630 | $sr = ldap_search($ldap_connect, $ldap_search_dn, $all_user_query); |
631 | 631 | } else { |
632 | 632 | $sr = ldap_search($ldap_connect, $ldap_basedn, $all_user_query); |
@@ -634,7 +634,7 @@ discard block |
||
634 | 634 | //echo " Number of entries returned is ".ldap_count_entries($ldapconnect,$sr); |
635 | 635 | //echo " Getting entries ..."; |
636 | 636 | $info = ldap_get_entries($ldap_connect, $sr); |
637 | - for ($key = 0; $key < $info['count']; $key ++) { |
|
637 | + for ($key = 0; $key < $info['count']; $key++) { |
|
638 | 638 | $user_id = ldap_add_user_by_array($info[$key], false); |
639 | 639 | if ($user_id) { |
640 | 640 | echo "User #$user_id created "; |
@@ -46,10 +46,9 @@ discard block |
||
46 | 46 | - Universite Jean Monet (J Dubois / Michel Courbon) |
47 | 47 | - Michel Panckoucke for reporting and fixing a bug |
48 | 48 | - Patrick Cool: fixing security hole |
49 | - |
|
50 | - * @author Roan Embrechts |
|
51 | - * @version 3.0 |
|
52 | - * @package chamilo.auth.ldap |
|
49 | + * @author Roan Embrechts |
|
50 | + * @version 3.0 |
|
51 | + * @package chamilo.auth.ldap |
|
53 | 52 | * Note: |
54 | 53 | * If you are using a firewall, you might need to check port 389 is open in |
55 | 54 | * order for Chamilo to communicate with the LDAP server. |
@@ -211,8 +210,8 @@ discard block |
||
211 | 210 | $language = api_get_setting('platformLanguage'); |
212 | 211 | if (empty($language)) { $language = 'english'; } |
213 | 212 | $_userId = UserManager::create_user($prenom, $nom, $status, |
214 | - $email, $uname, $password, $official_code, |
|
215 | - $language,'', '', 'ldap'); |
|
213 | + $email, $uname, $password, $official_code, |
|
214 | + $language,'', '', 'ldap'); |
|
216 | 215 | |
217 | 216 | //echo "new user added to Chamilo, id = $_userId"; |
218 | 217 | |
@@ -271,7 +270,7 @@ discard block |
||
271 | 270 | // Open anonymous LDAP connection |
272 | 271 | $result=false; |
273 | 272 | $ldap_bind_res = ldap_handle_bind($ds,$result); |
274 | - // Executing the search with the $filter parametr |
|
273 | + // Executing the search with the $filter parametr |
|
275 | 274 | //error_log('Searching for '.$filter.' on LDAP server',0); |
276 | 275 | $sr=ldap_search($ds,$ldap_basedn,$filter); |
277 | 276 | $info = ldap_get_entries($ds, $sr); |
@@ -564,35 +563,35 @@ discard block |
||
564 | 563 | foreach ($UserList as $enreg_user) { |
565 | 564 | $enreg_user = (int) $enreg_user; |
566 | 565 | Database::query("INSERT IGNORE ". |
567 | - " INTO $tbl_session_rel_course_rel_user ". |
|
568 | - "(session_id,c_id,user_id) VALUES ". |
|
569 | - "('$id_session','$enreg_course','$enreg_user')"); |
|
566 | + " INTO $tbl_session_rel_course_rel_user ". |
|
567 | + "(session_id,c_id,user_id) VALUES ". |
|
568 | + "('$id_session','$enreg_course','$enreg_user')"); |
|
570 | 569 | } |
571 | 570 | $sql = "SELECT COUNT(user_id) as nbUsers ". |
572 | - " FROM $tbl_session_rel_course_rel_user " . |
|
573 | - " WHERE session_id='$id_session' ". |
|
574 | - " AND c_id='$enreg_course'"; |
|
571 | + " FROM $tbl_session_rel_course_rel_user " . |
|
572 | + " WHERE session_id='$id_session' ". |
|
573 | + " AND c_id='$enreg_course'"; |
|
575 | 574 | $rs = Database::query($sql); |
576 | 575 | list($nbr_users) = Database::fetch_array($rs); |
577 | 576 | Database::query("UPDATE $tbl_session_rel_course ". |
578 | - " SET nbr_users=$nbr_users " . |
|
579 | - " WHERE session_id='$id_session' ". |
|
580 | - " AND c_id='$enreg_course'"); |
|
577 | + " SET nbr_users=$nbr_users " . |
|
578 | + " WHERE session_id='$id_session' ". |
|
579 | + " AND c_id='$enreg_course'"); |
|
581 | 580 | } |
582 | 581 | foreach ($UserList as $enreg_user) { |
583 | 582 | $enreg_user = (int) $enreg_user; |
584 | 583 | Database::query("INSERT IGNORE INTO $tbl_session_rel_user ". |
585 | - " (session_id, user_id, registered_at) " . |
|
586 | - " VALUES('$id_session','$enreg_user', '" . api_get_utc_datetime() . "')"); |
|
584 | + " (session_id, user_id, registered_at) " . |
|
585 | + " VALUES('$id_session','$enreg_user', '" . api_get_utc_datetime() . "')"); |
|
587 | 586 | } |
588 | 587 | // We update the number of users in the session |
589 | 588 | $sql = "SELECT COUNT(user_id) as nbUsers FROM $tbl_session_rel_user ". |
590 | - " WHERE session_id='$id_session' ". |
|
591 | - " AND relation_type<>".SESSION_RELATION_TYPE_RRHH." "; |
|
589 | + " WHERE session_id='$id_session' ". |
|
590 | + " AND relation_type<>".SESSION_RELATION_TYPE_RRHH." "; |
|
592 | 591 | $rs = Database::query($sql); |
593 | 592 | list($nbr_users) = Database::fetch_array($rs); |
594 | 593 | Database::query("UPDATE $tbl_session SET nbr_users=$nbr_users ". |
595 | - " WHERE id='$id_session'"); |
|
594 | + " WHERE id='$id_session'"); |
|
596 | 595 | } |
597 | 596 | |
598 | 597 | function syncro_users() { |
@@ -337,6 +337,7 @@ |
||
337 | 337 | |
338 | 338 | /** |
339 | 339 | * Make a HTTP request - This function has been copied straight over from Drupal 6 code (drupal_http_request) |
340 | + * @param string $data |
|
340 | 341 | */ |
341 | 342 | function openid_http_request($url, $headers = array(), $method = 'GET', $data = NULL, $retry = 3) { |
342 | 343 | $result = new stdClass(); |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | /** |
14 | 14 | * Initialisation |
15 | 15 | */ |
16 | -require_once api_get_path(CONFIGURATION_PATH) . 'auth.conf.php'; |
|
16 | +require_once api_get_path(CONFIGURATION_PATH).'auth.conf.php'; |
|
17 | 17 | |
18 | 18 | require_once 'openid.lib.php'; |
19 | 19 | require_once 'xrds.lib.php'; |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | // Now that there is an association created, move on |
69 | 69 | // to request authentication from the IdP |
70 | 70 | $identity = (!empty($services[0]['delegate'])) ? $services[0]['delegate'] : $claimed_id; |
71 | - if (isset($services[0]['types']) && is_array($services[0]['types']) && in_array(OPENID_NS_2_0 . '/server', $services[0]['types'])) { |
|
71 | + if (isset($services[0]['types']) && is_array($services[0]['types']) && in_array(OPENID_NS_2_0.'/server', $services[0]['types'])) { |
|
72 | 72 | $identity = 'http://openid.net/identifier_select/2.0'; |
73 | 73 | } |
74 | 74 | $authn_request = openid_authentication_request($claimed_id, $identity, $return_to, $assoc_handle, $services[0]['version']); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | |
127 | 127 | $xrds_url = $claimed_id; |
128 | 128 | if (_openid_is_xri($claimed_id)) { |
129 | - $xrds_url = 'http://xri.net/' . $claimed_id; |
|
129 | + $xrds_url = 'http://xri.net/'.$claimed_id; |
|
130 | 130 | } |
131 | 131 | $url = @parse_url($xrds_url); |
132 | 132 | if ($url['scheme'] == 'http' || $url['scheme'] == 'https') { |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | //@todo Remove Old Associations: |
192 | 192 | $openid_association = Database::get_main_table(TABLE_MAIN_OPENID_ASSOCIATION); |
193 | 193 | $sql = "DELETE FROM $openid_association |
194 | - WHERE created + expires_in < '" . api_get_utc_datetime() . "'"; |
|
194 | + WHERE created + expires_in < '".api_get_utc_datetime()."'"; |
|
195 | 195 | Database::query($sql); |
196 | 196 | |
197 | 197 | // Check to see if we have an association for this IdP already |
@@ -347,17 +347,17 @@ discard block |
||
347 | 347 | switch ($uri['scheme']) { |
348 | 348 | case 'http': |
349 | 349 | $port = isset($uri['port']) ? $uri['port'] : 80; |
350 | - $host = $uri['host'] . ($port != 80 ? ':' . $port : ''); |
|
350 | + $host = $uri['host'].($port != 80 ? ':'.$port : ''); |
|
351 | 351 | $fp = @fsockopen($uri['host'], $port, $errno, $errstr, 15); |
352 | 352 | break; |
353 | 353 | case 'https': |
354 | 354 | // Note: Only works for PHP 4.3 compiled with OpenSSL. |
355 | 355 | $port = isset($uri['port']) ? $uri['port'] : 443; |
356 | - $host = $uri['host'] . ($port != 443 ? ':' . $port : ''); |
|
357 | - $fp = @fsockopen('ssl://' . $uri['host'], $port, $errno, $errstr, 20); |
|
356 | + $host = $uri['host'].($port != 443 ? ':'.$port : ''); |
|
357 | + $fp = @fsockopen('ssl://'.$uri['host'], $port, $errno, $errstr, 20); |
|
358 | 358 | break; |
359 | 359 | default: |
360 | - $result->error = 'invalid schema ' . $uri['scheme']; |
|
360 | + $result->error = 'invalid schema '.$uri['scheme']; |
|
361 | 361 | return $result; |
362 | 362 | } |
363 | 363 | |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | // Construct the path to act on. |
374 | 374 | $path = isset($uri['path']) ? $uri['path'] : '/'; |
375 | 375 | if (isset($uri['query'])) { |
376 | - $path .= '?' . $uri['query']; |
|
376 | + $path .= '?'.$uri['query']; |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | // Create HTTP request. |
@@ -383,23 +383,23 @@ discard block |
||
383 | 383 | // host that do not take into account the port number. |
384 | 384 | 'Host' => "Host: $host", |
385 | 385 | 'User-Agent' => 'User-Agent: Chamilo (+http://www.chamilo.org/)', |
386 | - 'Content-Length' => 'Content-Length: ' . strlen($data) |
|
386 | + 'Content-Length' => 'Content-Length: '.strlen($data) |
|
387 | 387 | ); |
388 | 388 | |
389 | 389 | // If the server url has a user then attempt to use basic authentication |
390 | 390 | if (isset($uri['user'])) { |
391 | - $defaults['Authorization'] = 'Authorization: Basic ' . base64_encode($uri['user'] . (!empty($uri['pass']) ? ":" . $uri['pass'] : '')); |
|
391 | + $defaults['Authorization'] = 'Authorization: Basic '.base64_encode($uri['user'].(!empty($uri['pass']) ? ":".$uri['pass'] : '')); |
|
392 | 392 | } |
393 | 393 | |
394 | 394 | foreach ($headers as $header => $value) { |
395 | - $defaults[$header] = $header . ': ' . $value; |
|
395 | + $defaults[$header] = $header.': '.$value; |
|
396 | 396 | } |
397 | 397 | |
398 | - $request = $method . ' ' . $path . " HTTP/1.0\r\n"; |
|
398 | + $request = $method.' '.$path." HTTP/1.0\r\n"; |
|
399 | 399 | $request .= implode("\r\n", $defaults); |
400 | 400 | $request .= "\r\n\r\n"; |
401 | 401 | if ($data) { |
402 | - $request .= $data . "\r\n"; |
|
402 | + $request .= $data."\r\n"; |
|
403 | 403 | } |
404 | 404 | $result->request = $request; |
405 | 405 | |
@@ -425,7 +425,7 @@ discard block |
||
425 | 425 | if (isset($result->headers[$header]) && $header == 'Set-Cookie') { |
426 | 426 | // RFC 2109: the Set-Cookie response header comprises the token Set- |
427 | 427 | // Cookie:, followed by a comma-separated list of one or more cookies. |
428 | - $result->headers[$header] .= ',' . trim($value); |
|
428 | + $result->headers[$header] .= ','.trim($value); |
|
429 | 429 | } else { |
430 | 430 | $result->headers[$header] = trim($value); |
431 | 431 | } |