Skip to content

Commit

Permalink
Rename get_wiki_data() to getWikiDataFromDb()
Browse files Browse the repository at this point in the history
Improve validations on use of $userinfo
  • Loading branch information
ywarnier committed Jun 16, 2016
1 parent abebfc8 commit a6f5875
Showing 1 changed file with 49 additions and 33 deletions.
82 changes: 49 additions & 33 deletions main/wiki/wiki.inc.php
Expand Up @@ -1909,7 +1909,7 @@ public function export2doc($doc_id)
{
$_course = $this->courseInfo;
$groupId = api_get_group_id();
$data = self::get_wiki_data($doc_id);
$data = self::getWikiDataFromDb($doc_id);

if (empty($data)) {
return false;
Expand Down Expand Up @@ -2027,7 +2027,7 @@ public function export_to_pdf($id, $course_code)
}
}

$data = self::get_wiki_data($id);
$data = self::getWikiDataFromDb($id);
$content_pdf = api_html_entity_decode($data['content'], ENT_QUOTES, api_get_system_encoding());

//clean wiki links
Expand Down Expand Up @@ -2366,7 +2366,7 @@ public function display_wiki_search_results($search_term, $search_content=0, $al
$obj->title.'</a>';
}

$row[] = $obj->user_id != 0 ? UserManager::getUserProfileLink($userinfo) : get_lang('Anonymous').' ('.$obj->user_ip.')';
$row[] = ($obj->user_id != 0 && $userinfo !== false) ? UserManager::getUserProfileLink($userinfo) : get_lang('Anonymous').' ('.$obj->user_ip.')';
$row[] = $year.'-'.$month.'-'.$day.' '.$hours.":".$minutes.":".$seconds;

if ($all_vers=='1') {
Expand Down Expand Up @@ -2513,13 +2513,16 @@ public function two_digits($number)

/**
* Get wiki information
* @param int wiki id
* @param int|bool wiki id
* @return array wiki data
*/
public function get_wiki_data($id)
public function getWikiDataFromDb($id)
{
$tbl_wiki = $this->tbl_wiki;
$course_id = api_get_course_int_id();
if ($id === false) {
return array();
}
$id = intval($id);
$sql = 'SELECT * FROM '.$tbl_wiki.'
WHERE c_id = '.$course_id.' AND id = '.$id.' ';
Expand Down Expand Up @@ -3281,7 +3284,7 @@ public function getActiveUsers($action)
$userinfo = api_get_user_info($obj->user_id);
$username = api_htmlentities(sprintf(get_lang('LoginX'), $userinfo['username']), ENT_QUOTES);
$row = array();
if ($obj->user_id <> 0) {
if ($obj->user_id != 0 && $userinfo !== false) {
$row[] = UserManager::getUserProfileLink($userinfo).'
<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=usercontrib&user_id='.urlencode($obj->user_id).
'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'"></a>';
Expand Down Expand Up @@ -3466,7 +3469,9 @@ public function getDiscuss($page)

echo $icon_assignment.'&nbsp;&nbsp;&nbsp;'.api_htmlentities($row['title']);

echo ' ('.get_lang('MostRecentVersionBy').' '.UserManager::getUserProfileLink($lastuserinfo).' '.$lastversiondate.$countWPost.')'.$avg_WPost_score.' '; //TODO: read average score
if ($lastuserinfo !== false) {
echo ' (' . get_lang('MostRecentVersionBy') . ' ' . UserManager::getUserProfileLink($lastuserinfo) . ' ' . $lastversiondate . $countWPost . ')' . $avg_WPost_score . ' '; //TODO: read average score
}

echo '</div>';

Expand Down Expand Up @@ -3616,7 +3621,11 @@ public function getDiscuss($page)
echo '<p><table>';
echo '<tr>';
echo '<td rowspan="2">'.$author_photo.'</td>';
echo '<td style=" color:#999999">'.UserManager::getUserProfileLink($userinfo).' ('.$author_status.') '.
$userProfile = '';
if ($userinfo !== false) {
$userProfile = UserManager::getUserProfileLink($userinfo);
}
echo '<td style=" color:#999999">' . $userProfile . ' (' . $author_status . ') '.
api_get_local_time($row['dtime'], null, date_default_timezone_get()).
' - '.get_lang('Rating').': '.$row['p_score'].' '.$imagerating.' </td>';
echo '</tr>';
Expand Down Expand Up @@ -3689,16 +3698,16 @@ public function allPages($action)

//get icon task
if (!empty($obj->task)) {
$icon_task=Display::return_icon('wiki_task.png', get_lang('StandardTask'),'',ICON_SIZE_SMALL);
$icon_task = Display::return_icon('wiki_task.png', get_lang('StandardTask'), '', ICON_SIZE_SMALL);
} else {
$icon_task= Display::return_icon('px_transparent.gif');
$icon_task = Display::return_icon('px_transparent.gif');
}

$row = array();
$row[] = $ShowAssignment.$icon_task;
$row[] = '<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">
'.api_htmlentities($obj->title).'</a>';
if ($obj->user_id <>0) {
if ($userinfo !== false) {
$row[] = UserManager::getUserProfileLink($userinfo);
}
else {
Expand Down Expand Up @@ -3811,7 +3820,7 @@ public function recentChanges($page, $action)
$row[] = '<a href="'.api_get_self().'?'.api_get_cidreq().'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&amp;view='.$obj->id.'&session_id='.api_get_session_id().'&group_id='.api_get_group_id().'">'.
api_htmlentities($obj->title).'</a>';
$row[] = $obj->version>1 ? get_lang('EditedBy') : get_lang('AddedBy');
if ($obj->user_id <> 0 ) {
if ($userinfo !== false) {
$row[] = UserManager::getUserProfileLink($userinfo);
} else {
$row[] = get_lang('Anonymous').' ('.api_htmlentities($obj->user_ip).')';
Expand Down Expand Up @@ -3922,19 +3931,19 @@ public function getLinks($page)
$seconds = substr($obj->dtime, 17,2);

//get type assignment icon
if ($obj->assignment==1) {
$ShowAssignment=Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'),'',ICON_SIZE_SMALL);
} elseif ($obj->assignment==2) {
$ShowAssignment=Display::return_icon('wiki_work.png', get_lang('AssignmentWork'),'',ICON_SIZE_SMALL);
} elseif ($obj->assignment==0) {
$ShowAssignment=Display::return_icon('px_transparent.gif');
if ($obj->assignment == 1) {
$ShowAssignment = Display::return_icon('wiki_assignment.png', get_lang('AssignmentDesc'), '', ICON_SIZE_SMALL);
} elseif ($obj->assignment == 2) {
$ShowAssignment = Display::return_icon('wiki_work.png', get_lang('AssignmentWork'), '', ICON_SIZE_SMALL);
} elseif ($obj->assignment == 0) {
$ShowAssignment = Display::return_icon('px_transparent.gif');
}

$row = array();
$row[] =$ShowAssignment;
$row[] = '<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=showpage&title='.api_htmlentities(urlencode($obj->reflink)).'&session_id='.api_htmlentities($_GET['session_id']).'&group_id='.api_htmlentities($_GET['group_id']).'">'.
api_htmlentities($obj->title).'</a>';
if ($obj->user_id <>0) {
if ($userinfo !== false) {
$row[] = UserManager::getUserProfileLink($userinfo);
}
else {
Expand Down Expand Up @@ -4037,11 +4046,12 @@ public function getUserContributions($userId, $action)

$userId = intval($userId);
$userinfo = api_get_user_info($userId);

echo '<div class="actions">'.get_lang('UserContributions').': '.UserManager::getUserProfileLink($userinfo).
'<a href="'.api_get_self().'?cidReq='.$_course['code'].'&action=usercontrib&user_id='.$userId.
'&session_id='.$this->session_id.'&group_id='.$this->group_id.'">
</a></div>';
if ($userinfo !== false) {
echo '<div class="actions">' . get_lang('UserContributions') . ': ' . UserManager::getUserProfileLink($userinfo) .
'<a href="' . api_get_self() . '?cidReq=' . $_course['code'] . '&action=usercontrib&user_id=' . $userId .
'&session_id=' . $this->session_id . '&group_id=' . $this->group_id . '">' .
'</a></div>';
}

if (api_is_allowed_to_edit(false,true) || api_is_platform_admin()) {
//only by professors if page is hidden
Expand Down Expand Up @@ -4292,11 +4302,11 @@ public function restorePage()
}

/**
* @param string $wikiId
* @param int|bool $wikiId
*/
public function setWikiData($wikiId)
{
$this->wikiData = self::get_wiki_data($wikiId);
$this->wikiData = self::getWikiDataFromDb($wikiId);
}

/**
Expand Down Expand Up @@ -5047,8 +5057,10 @@ public function editPage()
$rest_time = $max_edit_time - $time_editing;

$userinfo = api_get_user_info($row['is_editing']);
$is_being_edited = get_lang('ThisPageisBeginEditedBy').' '.UserManager::getUserProfileLink($userinfo).'
'.get_lang('ThisPageisBeginEditedTryLater').' '.date( "i",$rest_time).' '.get_lang('MinMinutes').'';
if ($userinfo !== false) {
$is_being_edited = get_lang('ThisPageisBeginEditedBy') . ' ' . UserManager::getUserProfileLink($userinfo) . '
' . get_lang('ThisPageisBeginEditedTryLater') . ' ' . date("i", $rest_time) . ' ' . get_lang('MinMinutes') . '';
}

Display::addFlash(
Display::return_message(
Expand Down Expand Up @@ -5217,17 +5229,21 @@ public function getHistory()
echo '</a>';
echo ' ('.get_lang('Version').' '.$row['version'].')';
echo ' '.get_lang('By').' ';
if ($row['user_id'] <> 0) {
if ($userinfo !== false) {
echo UserManager::getUserProfileLink($userinfo);
} else {
echo get_lang('Anonymous').' ('.api_htmlentities($row['user_ip']).')';
}
echo ' ( '.get_lang('Progress').': '.api_htmlentities($row['progress']).'%, ';
$comment = $row['comment'];
if (!empty($comment)) {
echo get_lang('Comments').': '.api_htmlentities(api_substr($row['comment'], 0, 100));
if (api_strlen($row['comment'])>100) {
echo '... ';
$comment = api_substr($comment, 0, 100);
if ($comment !== false) {
$comment = api_htmlentities($comment);
echo get_lang('Comments').': ' . $comment;
if (api_strlen($row['comment'])>100) {
echo '... ';
}
}
} else {
echo get_lang('Comments').': ---';
Expand Down Expand Up @@ -5560,7 +5576,7 @@ public function redirectHome()
*/
public function exportTo($id, $format = 'doc')
{
$data = self::get_wiki_data($id);
$data = self::getWikiDataFromDb($id);

if (isset($data['content']) && !empty($data['content'])) {
Export::htmlToOdt($data['content'], $data['reflink'], $format);
Expand Down

0 comments on commit a6f5875

Please sign in to comment.