예제 #1
0
/**
 * used by user/myfriends.php and user/find.php to get the data (including pieforms etc) for display
 * @param $userlist the ids separated by commas
 * @return array containing the users in the order from $userlist
 */
function get_users_data($userlist, $getviews = true)
{
    global $USER;
    // $userlist is only used by build_userlist_html() in this file and is sanitised there
    $sql = 'SELECT u.id, u.username, u.preferredname, u.firstname, u.lastname, u.admin, u.staff, u.deleted,
                u.profileicon, u.email,
                0 AS pending, ap.value AS hidenamepref,
                COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages,
                COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'friendscontrol\'), \'auth\') AS friendscontrol,
                (SELECT 1 FROM {usr_friend} WHERE ((usr1 = ? AND usr2 = u.id) OR (usr2 = ? AND usr1 = u.id))) AS friend,
                (SELECT 1 FROM {usr_friend_request} fr WHERE fr.requester = ? AND fr.owner = u.id) AS requestedfriendship,
                (SELECT title FROM {artefact} WHERE artefacttype = \'introduction\' AND owner = u.id) AS introduction,
                NULL AS message
                FROM {usr} u
                LEFT JOIN {usr_account_preference} ap ON (u.id = ap.usr AND ap.field = \'hiderealname\')
                WHERE u.id IN (' . $userlist . ')
            UNION
            SELECT u.id, u.username, u.preferredname, u.firstname, u.lastname, u.admin, u.staff, u.deleted,
                u.profileicon, u.email,
                1 AS pending, ap.value AS hidenamepref,
                COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages,
                NULL AS friendscontrol,
                NULL AS friend,
                NULL AS requestedfriendship,
                (SELECT title FROM {artefact} WHERE artefacttype = \'introduction\' AND owner = u.id) AS introduction,
                message
                FROM {usr} u
                LEFT JOIN {usr_account_preference} ap ON (u.id = ap.usr AND ap.field = \'hiderealname\')
                JOIN {usr_friend_request} fr ON fr.requester = u.id
                WHERE fr.owner = ?
                AND u.id IN (' . $userlist . ')';
    $userid = $USER->get('id');
    $data = get_records_sql_assoc($sql, array($userid, $userid, $userid, $userid));
    $allowhidename = get_config('userscanhiderealnames');
    $showusername = get_config('searchusernames');
    foreach ($data as &$record) {
        $record->messages = $record->messages == 'allow' || $record->friend && $record->messages == 'friends' || $USER->get('admin') ? 1 : 0;
        $record->institutions = get_institution_string_for_user($record->id);
        $record->display_name = display_name($record, null, false, !$allowhidename || !$record->hidenamepref, $showusername);
    }
    if (!$data || !$getviews || !($views = get_views(array_keys($data), null, null))) {
        $views = array();
    }
    if ($getviews) {
        $viewcount = array_map('count', $views);
        // since php is so special and inconsistent, we can't use array_map for this because it breaks the top level indexes.
        $cleanviews = array();
        foreach ($views as $userindex => $viewarray) {
            $cleanviews[$userindex] = array_slice($viewarray, 0, 5);
            // Don't reveal any more about the view than necessary
            foreach ($cleanviews as $userviews) {
                foreach ($userviews as &$view) {
                    foreach (array_keys(get_object_vars($view)) as $key) {
                        if ($key != 'id' && $key != 'title') {
                            unset($view->{$key});
                        }
                    }
                }
            }
        }
    }
    foreach ($data as $friend) {
        if ($getviews && isset($cleanviews[$friend->id])) {
            $friend->views = $cleanviews[$friend->id];
        }
        if ($friend->pending) {
            $friend->accept = pieform(array('name' => 'acceptfriend' . $friend->id, 'successcallback' => 'acceptfriend_submit', 'renderer' => 'div', 'autofocus' => 'false', 'elements' => array('submit' => array('type' => 'submit', 'value' => get_string('approverequest', 'group')), 'id' => array('type' => 'hidden', 'value' => $friend->id))));
        }
        if (!$friend->friend && !$friend->pending && !$friend->requestedfriendship && $friend->friendscontrol == 'auto') {
            $friend->makefriend = pieform(array('name' => 'addfriend' . $friend->id, 'successcallback' => 'addfriend_submit', 'renderer' => 'div', 'autofocus' => 'false', 'elements' => array('submit' => array('type' => 'submit', 'value' => get_string('addtofriendslist', 'group')), 'id' => array('type' => 'hidden', 'value' => $friend->id), 'query' => array('type' => 'hidden', 'value' => param_variable('query', '')), 'offset' => array('type' => 'hidden', 'value' => param_integer('offset', 0)))));
        }
    }
    $order = explode(',', $userlist);
    $ordereddata = array();
    foreach ($order as $id) {
        if (isset($data[$id])) {
            $ordereddata[] = $data[$id];
        }
    }
    return $ordereddata;
}
예제 #2
0
function get_static_sub_post($static, $sub_static)
{
    $posts = get_static_sub_pages($static);
    $tmp = array();
    if (!empty($posts)) {
        foreach ($posts as $index => $v) {
            if (stripos($v, $sub_static . '.md') !== false) {
                $post = new stdClass();
                // Replaced string
                $replaced = substr($v, 0, strrpos($v, '/')) . '/';
                // The static page URL
                $url = str_replace($replaced, '', $v);
                $post->url = site_url() . $static . "/" . str_replace('.md', '', $url);
                $post->file = $v;
                // Get the contents and convert it to HTML
                $content = file_get_contents($v);
                // Extract the title and body
                $post->title = get_content_tag('t', $content, $sub_static);
                $post->body = MarkdownExtra::defaultTransform(remove_html_comments($content));
                $post->views = get_views($post->file);
                $post->description = get_content_tag("d", $content, get_description($post->body));
                $tmp[] = $post;
            }
        }
    }
    return $tmp;
}
예제 #3
0
function post_show($id, $preview = TRUE, $db, $adm_log = 0)
{
    if (!ctype_digit($id)) {
        alert_try_sqlinj();
        header('Location:index.php?error=error');
        die;
    }
    $id = validate($id, $db);
    $query = 'SELECT post_title,post_logo,p.categ_id,categ_name,post_text,UNIX_TIMESTAMP(post_edit_date) AS post_edit_date,UNIX_TIMESTAMP(post_date) AS post_date FROM posts p JOIN categories c ON p.categ_id=c.categ_id  WHERE  post_id=' . mysql_real_escape_string($id, $db);
    $result = sql_query($query, $db);
    if (mysql_num_rows($result) > 0) {
        while ($row = mysql_fetch_assoc($result)) {
            extract($row);
            echo '<table class=post-tablef>
<tr><td>';
            echo $adm_log == 1 ? '<div>
<span class="span-edit">
<a href="admin_main.php?mode=confirm&submit=post_delete&post_id=' . $id . '">
Delete this post
</a>
||
<a href="admin_main.php?mode=edit_post&post_id=' . $id . '">
Edit this post
</a>
</span>
</div>' : '';
            echo '<div>
<div><span class="span-posttitle">
<a href="view_post.php?id=' . mysql_real_escape_string($id, $db) . '">
' . nl2br(deletenbsp($post_title)) . '
</a>
</span>
</div>
</br>';
            echo '<span class="span-submitted"><strong>
Submitted:</strong>' . htmlspecialchars(date('l F j, Y H:i', $post_date)) . '
</span>
</br>';
            if ($post_edit_date != "") {
                echo '<span class="span-submitted">
<strong>Edit Date:</strong>
' . htmlspecialchars(date('l F j, Y H:i', $post_edit_date)) . '
</span>
</br>';
            }
            echo '
<span class="span-category">
<strong>Category:</strong>
<a href="index.php?categ=' . $categ_id . '">
' . deletenbsp($categ_name) . '
</a>
</span>
</br></br>';
            if ($post_logo != "") {
                echo '<img class="logo_link" src="' . stripslashes(deletescript(html_entity_decode(deletenbsp($post_logo), ENT_QUOTES))) . '"/></br></br>';
            }
            if ($preview) {
                $text = nl2br(stripslashes(preview(htmlsostitution(deletenbsp($post_text)))));
                echo '<table class="post-textf">
<tr>
<td>' . $text;
                if (strlen(nl2br(stripslashes(htmlsostitution(deletenbsp($post_text))))) > MAX_LENGTH_PREVIEW) {
                    echo '</br>
<a href="view_post.php?id=' . $id . '">
More
</a>';
                }
                echo '</td>
</tr>
</table>';
            } else {
                echo '<table class="post-textf">
<tr>
<td>
' . nl2br(stripslashes(htmlsostitution(deletenbsp($post_text)))) . '
</td>
</tr>
</table>';
            }
            echo '</br>
<div>
<strong>
Tags:
</strong></br>
<span class="span-tags">';
            $query = 'SELECT * FROM
tags t JOIN posttags pt ON t.tag_id=pt.tag_id
WHERE
pt.post_id= ' . mysql_real_escape_string($id, $db) . ' ORDER BY t.tag_name ASC ';
            $result = sql_query($query, $db);
            if (mysql_num_rows($result) > 0) {
                while ($row = mysql_fetch_array($result)) {
                    extract($row);
                    echo $tag_name . '; ';
                }
            } else {
                echo 'No tags for this post';
            }
            echo '</span>
</div></br>';
            if (!$preview) {
                add_view($id, $db);
                echo '<span style="font-size:15px;">' . get_views($id, $db) . '</span></br>';
                show_tag_posts($id, $db);
                show_comments($id, $db);
            }
            if ($preview) {
                $query = 'SELECT * FROM comments 
WHERE 
post_id=' . mysql_real_escape_string($id, $db);
                $result2 = sql_query($query, $db);
                echo '<span style="font-size:15px;">' . get_views($id, $db) . ',<a href="view_post.php?id=' . $id . '">
Comments:' . mysql_num_rows($result2) . '
</a>
</span>
</div>';
            }
        }
        mysql_free_result($result);
    } else {
        echo 'Article Not found';
    }
    echo '</td>
</tr>';
    echo '</table>
</br>';
}
예제 #4
0
파일: Main.php 프로젝트: elbarzata/mulder
 public function get_xml_views()
 {
     $workbook_id = $this->input->post('workbook_id');
     $server_url = $this->config->item('tableau_server_url');
     $token = $this->input->cookie('token', TRUE);
     $site_id = $this->input->cookie('site_id', TRUE);
     $response = get_views($server_url, $site_id, $token, $workbook_id);
     $xml = simplexml_load_string($response) or die("Error: Se perdió conectividad con el servidor");
     $array_views = $xml->views;
     if (is_iterable($array_views->view)) {
         foreach ($array_views->view as $view) {
             //despues descomentar se usa una img local
             $view->img = base64_encode(get_view_img($server_url, $workbook_id, $site_id, $token, $view['id']));
         }
         echo $array_views->asXML();
     } else {
         echo '<error> bad response </error>';
     }
 }
예제 #5
0
파일: user.php 프로젝트: patkira/mahara
/**
 * used by user/myfriends.php and user/find.php to get the data (including pieforms etc) for display
 * @param array $userids
 * @return array containing the users in the order from $userids
 */
function get_users_data($userids, $getviews = true)
{
    global $USER;
    $userids = array_map('intval', $userids);
    $sql = 'SELECT u.id, u.username, u.preferredname, u.firstname, u.lastname, u.admin, u.staff, u.deleted,
                u.profileicon, u.email, u.urlid,
                fp.requester AS pending,
                fp.ctime AS pending_time,
                ap.value AS hidenamepref,
                COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'messages\'), \'allow\') AS messages,
                COALESCE((SELECT ap.value FROM {usr_account_preference} ap WHERE ap.usr = u.id AND ap.field = \'friendscontrol\'), \'auth\') AS friendscontrol,
                (SELECT 1 FROM {usr_friend} WHERE ((usr1 = ? AND usr2 = u.id) OR (usr2 = ? AND usr1 = u.id))) AS friend,
                (SELECT 1 FROM {usr_friend_request} fr WHERE fr.requester = ? AND fr.owner = u.id) AS requestedfriendship,
                (SELECT title FROM {artefact} WHERE artefacttype = \'introduction\' AND owner = u.id) AS introduction,
                fp.message
                FROM {usr} u
                LEFT JOIN {usr_account_preference} ap ON (u.id = ap.usr AND ap.field = \'hiderealname\')
                LEFT JOIN {usr_friend_request} fp ON fp.owner = ? AND fp.requester = u.id
                WHERE u.id IN (' . join(',', array_fill(0, count($userids), '?')) . ')';
    $userid = $USER->get('id');
    $data = get_records_sql_assoc($sql, array_merge(array($userid, $userid, $userid, $userid), $userids));
    $allowhidename = get_config('userscanhiderealnames');
    $showusername = !get_config('nousernames');
    $institutionstrings = get_institution_strings_for_users($userids);
    foreach ($data as &$record) {
        $record->pending_time = format_date(strtotime($record->pending_time), 'strftimedaydate');
        $record->messages = $record->messages == 'allow' || $record->friend && $record->messages == 'friends' || $USER->get('admin') ? 1 : 0;
        if (isset($institutionstrings[$record->id])) {
            $record->institutions = $institutionstrings[$record->id];
        }
        $record->display_name = display_name($record, null, false, !$allowhidename || !$record->hidenamepref, $showusername);
    }
    if (!$data || !$getviews || !($views = get_views(array_keys($data), null, null))) {
        $views = array();
    }
    if ($getviews) {
        $viewcount = array_map('count', $views);
        // since php is so special and inconsistent, we can't use array_map for this because it breaks the top level indexes.
        $cleanviews = array();
        foreach ($views as $userindex => $viewarray) {
            $cleanviews[$userindex] = array_slice($viewarray, 0, 5);
            // Don't reveal any more about the view than necessary
            foreach ($cleanviews as $userviews) {
                foreach ($userviews as &$view) {
                    foreach (array_keys(get_object_vars($view)) as $key) {
                        if ($key != 'id' && $key != 'title' && $key != 'url' && $key != 'fullurl') {
                            unset($view->{$key});
                        }
                    }
                }
            }
        }
    }
    foreach ($data as $friend) {
        if ($getviews && isset($cleanviews[$friend->id])) {
            $friend->views = $cleanviews[$friend->id];
        }
        if ($friend->pending) {
            $friend->accept = acceptfriend_form($friend->id);
        }
        if (!$friend->friend && !$friend->pending && !$friend->requestedfriendship && $friend->friendscontrol == 'auto') {
            $friend->makefriend = addfriend_form($friend->id);
        }
    }
    $ordereddata = array();
    foreach ($userids as $id) {
        if (isset($data[$id])) {
            $ordereddata[] = $data[$id];
        }
    }
    return $ordereddata;
}
예제 #6
0
파일: elgglib.php 프로젝트: eokyere/elgg
/**
 * When given a partial view root (eg 'js' or 'page_elements'), returns an array of views underneath it
 *
 * @param string $view_root The root view
 * @param string $viewtype Optionally specify a view type other than the current one.
 * @return array A list of view names underneath that root view
 */
function elgg_view_tree($view_root, $viewtype = "")
{
    global $CONFIG;
    static $treecache;
    // Get viewtype
    if (!$viewtype) {
        $viewtype = elgg_get_viewtype();
    }
    // Has the treecache been initialised?
    if (!isset($treecache)) {
        $treecache = array();
    }
    // A little light internal caching
    if (!empty($treecache[$view_root])) {
        return $treecache[$view_root];
    }
    // Examine $CONFIG->views->locations
    if (isset($CONFIG->views->locations[$viewtype])) {
        foreach ($CONFIG->views->locations[$viewtype] as $view => $path) {
            $pos = strpos($view, $view_root);
            if ($pos === 0) {
                $treecache[$view_root][] = $view;
            }
        }
    }
    // Now examine core
    $location = $CONFIG->viewpath;
    $viewtype = elgg_get_viewtype();
    $root = $location . $viewtype . '/' . $view_root;
    if (file_exists($root) && is_dir($root)) {
        $val = get_views($root, $view_root);
        if (!is_array($treecache[$view_root])) {
            $treecache[$view_root] = array();
        }
        $treecache[$view_root] = array_merge($treecache[$view_root], $val);
    }
    return $treecache[$view_root];
}
예제 #7
0
파일: myfriends.php 프로젝트: Br3nda/mahara
        $count = count_records_sql('SELECT COUNT(usr1) FROM {usr_friend}
            JOIN {usr} u1 ON (u1.id = usr1 AND u1.deleted = 0)
            JOIN {usr} u2 ON (u2.id = usr2 AND u2.deleted = 0)
            WHERE usr1 = ? OR usr2 = ?', array($userid, $userid)) + count_records_sql('SELECT COUNT(owner) FROM {usr_friend_request}
	        JOIN {usr} u ON (u.id = requester AND u.deleted = 0)
	        WHERE owner = ?', array($userid));
        $data = get_column_sql('SELECT f.id FROM (
            SELECT requester AS id, \'1\' AS status FROM {usr_friend_request} WHERE owner = ?
            UNION SELECT usr2 AS id, \'2\' AS status FROM {usr_friend} WHERE usr1 = ?
            UNION SELECT usr1 AS id, \'2\' AS status FROM {usr_friend} WHERE usr2 = ?
        ) f
        JOIN {usr} u ON (f.id = u.id AND u.deleted = 0)
        ORDER BY status, firstname, lastname, u.id
        LIMIT ?
        OFFSET ?', array($userid, $userid, $userid, $limit, $offset));
        if (!$data || !($views = get_views(array_keys($data), null, null))) {
            $views = array();
        }
    }
}
if ($data) {
    $userlist = join(',', $data);
    $data = get_users_data($userlist);
}
$filterform = pieform(array('name' => 'filter', 'renderer' => 'oneline', 'elements' => array('filter' => array('type' => 'select', 'options' => array('all' => get_string('allfriends', 'group'), 'current' => get_string('currentfriends', 'group'), 'pending' => get_string('pendingfriends', 'group')), 'defaultvalue' => $filter), 'submit' => array('type' => 'submit', 'value' => get_string('filter')))));
$pagination = build_pagination(array('url' => get_config('wwwroot') . 'user/myfriends.php?filter=' . $filter, 'count' => $count, 'limit' => $limit, 'offset' => $offset, 'resultcounttextsingular' => get_string('friend', 'group'), 'resultcounttextplural' => get_string('friends', 'group')));
if (!$data) {
    if ($filter == 'pending') {
        $message = get_string('nobodyawaitsfriendapproval', 'group');
    } else {
        $message = get_string('trysearchingforfriends', 'group', '<a href="' . get_config('wwwroot') . 'user/find.php">', '</a>');
예제 #8
0
function show_unit_row($unit, $class, $level, $is_answer)
{
    global $breakdown, $breakdown_cat;
    global $rownum, $course_id;
    $a = $is_answer ? " (answer)" : "";
    $j = $rownum++ % 2;
    echo "<tr class=row{$j}>";
    if ($breakdown && $breakdown_cat) {
        echo "\n\t\t\t<td><br></td>\n\t\t\t<td><br></td>\n\t\t";
    } else {
        $c = class_name($class);
        echo "\n\t\t\t<td><b>" . spaces($level) . "{$unit->name}</b></td>\n\t\t\t<td>{$c} {$a}</td>\n\t\t";
    }
    if ($breakdown) {
        if ($breakdown_cat) {
            echo "<td>{$breakdown_cat}</td>\n";
        } else {
            echo "<td>Total</td>\n";
        }
    }
    switch ($class) {
        case "BoltLesson":
            $mode = BOLT_MODE_LESSON;
            $views = get_views($unit, $mode);
            $n = count($views);
            $out = outcomes($views);
            $t = avg_time($views);
            echo "<td>{$n}</td>";
            $n = get_nquestions($unit, $mode);
            if ($n) {
                echo "<td><a href=bolt_map.php?action=questions&course_id={$course_id}&name={$unit->name}&mode={$mode}" . filter_url() . ">{$n}</a></td>\n";
            } else {
                echo "<td>0</td>\n";
            }
            echo outcome_graph($out, 200);
            echo empty_cell();
            echo time_graph($t, 200);
            break;
        case "BoltExercise":
            $mode = $is_answer ? BOLT_MODE_ANSWER : BOLT_MODE_SHOW;
            $views = get_views($unit, $mode);
            $n = count($views);
            $out = outcomes($views);
            $t = avg_time($views);
            echo "<td>{$n}</td>";
            $n = get_nquestions($unit, $mode);
            if ($n) {
                echo "<td><a href=bolt_map.php?action=questions&course_id={$course_id}&name={$unit->name}&mode={$mode}>{$n}</a></td>\n";
            } else {
                echo "<td>0</td>\n";
            }
            echo outcome_graph($out, 200);
            if ($is_answer) {
                echo empty_cell();
            } else {
                $results = get_results($unit);
                $score = avg_score($results);
                echo score_graph($score, 200);
            }
            echo time_graph($t, 200);
            break;
        case "BoltExerciseSet":
            $xr = get_xset_results($unit);
            $n = count($xr);
            echo "<td>{$n}</td>";
            echo empty_cell();
            echo empty_cell();
            $score = avg_score($xr);
            echo score_graph($score, 200);
            echo empty_cell();
            break;
        default:
            echo empty_cell();
            echo empty_cell();
            echo empty_cell();
            echo empty_cell();
            echo empty_cell();
    }
    echo "</tr>\n";
}
예제 #9
0
파일: simpviews.php 프로젝트: Omuze/barakat
function update_views($post_id)
{
    global $wpdb;
    $table = $wpdb->prefix . "simpleviews";
    $views = get_views($post_id) + 1;
    if ($wpdb->query("SELECT view FROM {$table} WHERE post_id = '{$post_id}'") != 1) {
        insert_views($views, $post_id);
    }
    $result = $wpdb->query("UPDATE {$table} SET view = {$views} WHERE post_id = '{$post_id}'");
    return $result;
}