Example #1
0
File: views.php Project: rasul/Elgg
/**
 * Returns a string of a rendered annotation.
 *
 * Annotation views are expected to be in annotation/$annotation_name.
 * If a view is not found for $annotation_name, the default annotation/default
 * will be used.
 *
 * @warning annotation/default is not currently defined in core.
 *
 * The annotation view is called with the following in $vars:
 *  - ElggEntity 'annotation' The annotation being viewed.
 *
 * @param ElggAnnotation $annotation The annotation to display
 * @param array          $vars       Variable array for view.
 * @param bool           $bypass     If false, will not pass to a custom
 *                                   template handler. {@see set_template_handler()}
 * @param bool           $debug      Complain if views are missing
 *
 * @return string/false Rendered annotation
 */
function elgg_view_annotation(ElggAnnotation $annotation, array $vars = array(), $bypass = true, $debug = false)
{
    global $autofeed;
    $autofeed = true;
    $defaults = array('full_view' => true);
    $vars = array_merge($defaults, $vars);
    $vars['annotation'] = $annotation;
    // @todo setting the view on an annotation is not advertised anywhere
    // do we want to keep this?
    $view = $annotation->view;
    if (is_string($view)) {
        return elgg_view($view, $vars, $bypass, $debug);
    }
    // @todo would be better to always make sure name is initialized properly
    $name = $annotation->name;
    $intname = (int) $name;
    if ("{$intname}" == "{$name}") {
        $name = get_metastring($intname);
    }
    if (empty($name)) {
        return false;
    }
    if (elgg_view_exists("annotation/{$name}")) {
        return elgg_view("annotation/{$name}", $vars, $bypass, $debug);
    } else {
        return elgg_view("annotation/default", $vars, $bypass, $debug);
    }
}
<?php

$catId = (int) get_input("categoryId");
if (!empty($catId)) {
    $cats = getCategories();
    $cat = get_metastring($catId);
    if (in_array($cat, $cats)) {
        $faqs = getFaqs($cat);
        if (!empty($faqs)) {
            $display = "<h3>" . elgg_echo("faq:list:category_title") . $cat . "</h3><br>";
            foreach ($faqs as $faq) {
                $display .= elgg_view("object/faq", array("entity" => $faq));
            }
        } else {
            forward(elgg_get_site_url() . "faq/");
        }
    } else {
        register_error(elgg_echo("faq:list:no_category"));
        forward(elgg_get_site_url() . "faq/");
    }
} else {
    register_error(elgg_echo("faq:list:no_category"));
    forward(elgg_get_site_url() . "faq/");
}
?>

<div>
	<div id="result">
		<?php 
echo $display;
?>
Example #3
0
/**
 * When given an annotation, views it intelligently.
 * 
 * This function expects annotation views to be of the form annotation/name, where name
 * is the type of annotation. 
 *
 * @param ElggAnnotation $annotation The annotation to display
 * @param boolean $full Determines whether or not to display the full version of an object, or a smaller version for use in aggregators etc
 * @param boolean $bypass If set to true, elgg_view will bypass any specified alternative template handler; by default, it will hand off to this if requested (see set_template_handler)
 * @param boolean $debug If set to true, the viewer will complain if it can't find a view
 * @return string HTML (etc) to display
 */
function elgg_view_annotation(ElggAnnotation $annotation, $bypass = true, $debug = false)
{
    global $autofeed;
    $autofeed = true;
    $view = $annotation->view;
    if (is_string($view)) {
        return elgg_view($view, array('annotation' => $annotation), $bypass, $debug);
    }
    $name = $annotation->name;
    $intname = (int) $name;
    if ("{$intname}" == "{$name}") {
        $name = get_metastring($intname);
    }
    if (empty($name)) {
        return "";
    }
    if (elgg_view_exists("annotation/{$name}")) {
        return elgg_view("annotation/{$name}", array('annotation' => $annotation), $bypass, $debug);
    } else {
        return elgg_view("annotation/default", array('annotation' => $annotation), $bypass, $debug);
    }
}
function faq_page_handler($page)
{
    if (!isset($page[0])) {
        $page[0] = 'index';
    }
    elgg_push_breadcrumb(elgg_echo('faq:shorttitle'), 'faq/');
    $title = elgg_echo('faq:title');
    $page_type = $page[0];
    switch ($page_type) {
        case 'index':
            $area = elgg_view('faq/search');
            $area .= elgg_view('faq/stats');
            break;
        case 'list':
            $catId = (int) get_input("categoryId");
            if (!empty($catId)) {
                $cats = getCategories();
                $cat = get_metastring($catId);
                if (in_array($cat, $cats)) {
                    elgg_push_breadcrumb(elgg_echo("faq:list:category_title") . $cat);
                }
            }
            $area = elgg_view('faq/list');
            break;
        case 'ask':
            gatekeeper();
            elgg_push_breadcrumb(elgg_echo('faq:ask:title'));
            $area = elgg_view('faq/forms/ask');
            break;
        case 'asked':
            admin_gatekeeper();
            elgg_push_breadcrumb(elgg_echo('faq:asked:title'));
            $area = elgg_view('faq/asked');
            break;
        case 'add':
            admin_gatekeeper();
            elgg_push_breadcrumb(elgg_echo('faq:add:title'));
            $area = elgg_view('faq/forms/add');
            break;
        case 'edit':
            admin_gatekeeper();
            elgg_push_breadcrumb(elgg_echo('faq:edit:title'));
            $area = elgg_view('faq/forms/add');
            break;
        default:
            return false;
    }
    $sidebar = elgg_view('faq/sidebar');
    // Format page
    $body = elgg_view_layout('content', array('content' => $area, 'filter' => '', 'title' => $title, 'sidebar' => $sidebar));
    // Draw it
    echo elgg_view_page(elgg_echo('faq:title'), $body);
    return true;
}
Example #5
0
/**
 * Page handler for CSV download
 *
 * @param array $page
 */
function upload_users_page_handler($page)
{
    admin_gatekeeper();
    switch ($page[0]) {
        default:
            return false;
        case 'report':
            $file_guid = get_input("guid");
            $file = get_entity($file_guid);
            if (!$file) {
                register_error(elgg_echo('upload_users:error:file_open_error'));
                forward("admin/users/upload");
            }
            header("Pragma: public");
            header("Content-type: text/csv");
            header("Content-Disposition: attachment; filename=\"{$file->originalfilename}\"");
            ob_clean();
            flush();
            readfile($file->getFilenameOnFilestore());
            exit;
            break;
        case 'sample':
            set_time_limit(0);
            $limit = get_input('limit', 20);
            $offset = get_input('offset', 0);
            $fileName = 'upload_users_sample.csv';
            header('Content-Description: File Transfer');
            header("Content-type: text/csv");
            header("Content-Disposition: attachment; filename={$fileName}");
            header('Expires: ' . gmdate('D, d M Y H:i:s \\G\\M\\T', strtotime("+1 day")), true);
            header("Pragma: public");
            $dbprefix = elgg_get_config('dbprefix');
            $query = "SELECT DISTINCT(md.name_id) FROM {$dbprefix}metadata md\n\t\t\t\t\tJOIN {$dbprefix}entities e ON md.entity_guid = e.guid\n\t\t\t\t\tWHERE e.type = 'user'";
            $md_names = get_data($query);
            foreach ($md_names as $md_name) {
                $string = get_metastring($md_name->name_id);
                if ($string && !is_int($string) && !in_array($string, array('name', 'username', 'password', 'email', 'user_upload_role'))) {
                    $md[] = $string;
                }
            }
            $results = array();
            $options = array('types' => 'user', 'limit' => $limit, 'offset' => $offset, 'order_by' => 'e.time_created ASC');
            $batch = new ElggBatch('elgg_get_entities', $options);
            foreach ($batch as $user) {
                $results[$user->guid] = array('name' => $user->name, 'username' => $user->username, 'password' => '', 'email' => $user->email, 'user_upload_role' => elgg_is_active_plugin('roles') ? roles_get_role()->name : null);
                foreach ($md as $string) {
                    $value = $user->{$string};
                    if (is_array($value)) {
                        $value = implode(', ', $value);
                    }
                    $results[$user->guid][$string] = $value;
                }
            }
            $fh = @fopen('php://output', 'w');
            $headerDisplayed = false;
            foreach ($results as $data) {
                // Add a header row if it hasn't been added yet
                if (!$headerDisplayed) {
                    // Use the keys from $data as the titles
                    fputcsv($fh, array_keys($data));
                    $headerDisplayed = true;
                }
                // Put the data into the stream
                fputcsv($fh, $data);
            }
            fclose($fh);
            exit;
            break;
    }
}
$extra_mapping_options = array();
foreach ($mapping_options as $md_name => $readable) {
    $id = get_metastring_id($md_name);
    if ($id) {
        $not_in[] = $id;
    }
}
$dbprefix = elgg_get_config('dbprefix');
$query = "SELECT DISTINCT(md.name_id) FROM {$dbprefix}metadata md\n\t\t\t\t\tJOIN {$dbprefix}entities e ON md.entity_guid = e.guid\n\t\t\t\t\tWHERE e.type = 'user'";
if (count($not_in)) {
    $not_in_str = implode(',', $not_in);
    $query .= " AND md.name_id NOT IN ({$not_in_str})";
}
$md_names = get_data($query);
foreach ($md_names as $md_name) {
    $string = get_metastring($md_name->name_id);
    if ($string && !is_int($string)) {
        $extra_mapping_options[$string] = $string;
    }
}
if ($extra_mapping_options) {
    ksort($extra_mapping_options);
    $mapping_options = array_merge($mapping_options, $extra_mapping_options);
}
echo '<div class="elgg-loud"><strong>' . elgg_echo('upload_users:mapping:instructions') . '</strong></div>';
echo '<table class="elgg-table-alt upload-users-mapping mam">';
echo '<thead>';
echo '<tr>';
echo '<th>' . elgg_echo('upload_users:mapping:csv_header') . '</th>';
echo '<th>' . elgg_echo('upload_users:mapping:elgg_header') . '</th>';
echo '<th>' . elgg_echo('upload_users:mapping:access_id') . '</th>';