function templates_variables_substitute($param) { global $CFG; $variables = $param[0]; $template_variable = $param[1]; $run_result = ''; // Substitute variables in templates: // where {{variablename}} is found in the template, this function is passed // "variablename" and returns the proper variable global $menubar; global $submenubar; global $metatags; global $PAGE; global $template_id; global $template_name; global $db; //error_log("tvs " . print_r($template_variable,1)); $result = ""; if (isset($variables[$template_variable])) { $result .= $variables[$template_variable]; } else { $vars = array(); if (substr_count($template_variable, ":") > 0) { $vars = explode(":", $template_variable); $template_variable = $vars[0]; } switch ($template_variable) { case "username": if (logged_on) { $result = $_SESSION['username']; } else { $result = __gettext("Guest"); } break; case "usericonid": if (logged_on) { $result = user_info("icon", $_SESSION['userid']); } else { $result = 0; } break; case "name": if (logged_on) { $result = htmlspecialchars($_SESSION['name'], ENT_COMPAT, 'utf-8'); } else { $result = __gettext("Guest"); } break; case "userfullname": if (logged_on) { $result = __gettext("Welcome") . " " . htmlspecialchars($_SESSION['name'], ENT_COMPAT, 'utf-8'); } else { $result = __gettext("Welcome") . " " . __gettext("Guest") . " [<a href=\"" . url . "login/index.php\">" . __gettext("Log in") . "</a>]"; } break; case "menu": if (logged_on) { $result = templates_draw(array('menuitems' => menu_join('', $PAGE->menu), 'context' => 'menu')); } break; case "submenu": $result = templates_draw(array('submenuitems' => menu_join(' | ', $PAGE->menu_sub), 'context' => 'submenu')); break; case "topmenu": $result = templates_draw(array('topmenuitems' => menu_join('', $PAGE->menu_top), 'context' => 'topmenu')); break; case "url": $result = url; break; case "sitename": $result = $CFG->sitename; break; case "tagline": $result = $CFG->tagline; break; case "metatags": if (!empty($template_name)) { // use a defined style $result = '<link href="' . $CFG->wwwroot . '_templates/css/' . $template_name . '" rel="stylesheet" type="text/css" />' . "\n"; } else { // use whatever's in $template['css'] $result = "<style type=\"text/css\">\n" . templates_draw(array('template' => $template_name, 'context' => 'css')) . "\n</style>\n"; } // locate css at end $result = $metatags . "\n" . $result; break; case 'perf': $perf = get_performance_info(); if (defined('ELGG_PERFTOLOG')) { error_log("PERF: " . $perf['txt']); } if (defined('ELGG_PERFTOFOOT') || $CFG->debug > 7 || $CFG->perfdebug > 7) { $result = $perf['html']; } break; case 'randomusers': $result = ""; if (isset($vars[1])) { $vars[1] = (int) $vars[1]; } else { $vars[1] = 3; } if ($users = get_records_sql("SELECT DISTINCT u.*,i.filename AS iconfile, " . $db->random . " as rand \n FROM " . $CFG->prefix . "profile_data t JOIN " . $CFG->prefix . "users u ON u.ident = t.owner\n LEFT JOIN " . $CFG->prefix . "icons i ON i.ident = u.icon \n WHERE t.name IN (?,?,?) AND u.icon != ? AND t.access = ? AND u.user_type = ? \n ORDER BY rand LIMIT " . $vars[1], array('biography', 'minibio', 'interests', -1, 'PUBLIC', 'person'))) { $usercount = 0; foreach ($users as $user) { if ($usercount > 0) { $result .= ", "; } else { $result .= " "; } $result .= "<a href=\"" . $CFG->wwwroot . $user->username . "/\">" . $user->name . "</a>"; $usercount++; } } else { $result .= __gettext("Sorry, no users have filled in their profiles yet."); } break; case 'people': $result = ""; if (isset($vars[1])) { $vars[1] = $db->qstr($vars[1]); } else { $vars[1] = "'interests'"; } if (isset($vars[2])) { $vars[2] = $db->qstr($vars[2]); } else { $vars[2] = "'foo'"; } if (isset($vars[3])) { $vars[3] = (int) $vars[3]; } else { $vars[3] = 5; } $users = get_records_sql("SELECT users.*, icons.filename as iconfile, icons.ident as iconid FROM " . $CFG->prefix . "tags LEFT JOIN " . $CFG->prefix . "users ON users.ident = tags.owner left join " . $CFG->prefix . "icons on icons.ident = users.icon WHERE tags.tag = " . $vars[2] . " AND tags.tagtype = " . $vars[1] . " AND users.icon != -1 AND tags.access = 'PUBLIC' and users.user_type = 'person' ORDER BY rand( ) LIMIT " . $vars[3]); if (sizeof($users) > 0 && is_array($users)) { $result .= <<<END <table width="550px" border="0" cellpadding="0" cellspacing="0"> <tr> END; foreach ($users as $user) { $icon_html = user_icon_html($user->ident, 67); $result .= <<<END <td align="center"> <div class="image_holder"> <a href="{$CFG->wwwroot}{$user->username}/">{$icon_html}</a> </div> <div class="userdetails"> <p><a href="{$CFG->wwwroot}{$user->username}/">{$user->name}</a></p> </div> END; } $result .= <<<END <tr> </table> END; } break; case "toptags": if (isset($vars[1])) { $vars[1] = $db->qstr($vars[1]); } else { $vars[1] = "'town'"; } if ($tags = get_records_sql("SELECT tag, count(ident) as numtags FROM `" . $CFG->prefix . "tags` WHERE access = 'public' and tagtype=" . $vars[1] . " group by tag order by numtags desc limit 20")) { $tag_count = 0; foreach ($tags as $tag) { $result .= "<a href=\"" . url . "tag/" . urlencode(htmlspecialchars(strtolower($tag->tag), ENT_COMPAT, 'utf-8')) . "\" title=\"" . htmlspecialchars($tag->tag, ENT_COMPAT, 'utf-8') . " (" . $tag->numtags . ")\">"; $result .= $tag->tag . "</a>"; if ($tag_count < sizeof($tags) - 1) { $result .= ", "; } $tag_count++; } } break; case "populartags": $result = ""; if ($tags = get_records_sql("SELECT tag, count(ident) as numtags FROM `" . $CFG->prefix . "tags` WHERE access = 'public' and tag!='' group by tag having numtags > 1 order by ident desc limit 20")) { $max = 0; foreach ($tags as $tag) { if ($tag->numtags > $max) { $max = $tag->numtags; } } $tag_count = 0; foreach ($tags as $tag) { if ($max > 1) { $size = round(log($tag->numtags) / log($max) * 300); } else { $size = 100; } $result .= "<a href=\"" . url . "tag/" . urlencode(htmlspecialchars(strtolower($tag->tag), ENT_COMPAT, 'utf-8')) . "\" style=\"font-size: {$size}%\" title=\"" . htmlspecialchars($tag->tag, ENT_COMPAT, 'utf-8') . " (" . $tag->numtags . ")\">"; $result .= $tag->tag . "</a>"; if ($tag_count < sizeof($tags) - 1) { $result .= ", "; } $tag_count++; } } break; default: break; } } if (!empty($CFG->templates->variables_substitute) && !empty($CFG->templates->variables_substitute[$template_variable])) { if (is_array($CFG->templates->variables_substitute[$template_variable])) { foreach ($CFG->templates->variables_substitute[$template_variable] as $sub_function) { $result .= $sub_function($vars); } } elseif (is_callable($CFG->templates->variables_substitute[$template_variable])) { $result .= $CFG->templates->variables_substitute[$template_variable]($vars); } } $run_result .= $result; return $run_result; }
function displaymenu_user() { if (logged_on == 1) { return templates_draw(array('context' => 'menu', 'menuitems' => menu_join('', $PAGE->menu_user))); } return ''; }
function templates_variables_substitute($param) { global $CFG; $variables = $param[0]; $template_variable = $param[1]; $run_result = ''; // Substitute variables in templates: // where {{variablename}} is found in the template, this function is passed // "variablename" and returns the proper variable global $menubar; global $submenubar; global $metatags; global $PAGE; global $template_id; //error_log("tvs " . print_r($template_variable,1)); if (isset($variables[$template_variable])) { return $variables[$template_variable]; } else { switch ($template_variable) { case "username": if (logged_on) { return $_SESSION['username']; } else { return gettext("Guest"); } break; case "userfullname": if (logged_on) { return htmlspecialchars($_SESSION['name'], ENT_COMPAT, 'utf-8'); } else { return gettext("Guest") . " [<a href=\"" . url . "login/index.php\">" . gettext("Log in") . "</a>]"; } break; // case "userfullname": // global $page_owner; // if (!isset($page_owner) || $page_owner == -1) { // return ""; // } else { // return run("users:id_to_name", $page_owner); // } // break; // case "userfullname": // global $page_owner; // if (!isset($page_owner) || $page_owner == -1) { // return ""; // } else { // return run("users:id_to_name", $page_owner); // } // break; case "menu": if (logged_on) { return templates_draw(array('menuitems' => menu_join('', $PAGE->menu), 'context' => 'menu')); } break; case "submenu": return templates_draw(array('submenuitems' => menu_join(' | ', $PAGE->menu_sub), 'context' => 'submenu')); break; case "topmenu": if (logged_on) { return templates_draw(array('topmenuitems' => menu_join('', $PAGE->menu_top), 'context' => 'topmenu')); } break; case "url": return url; break; case "metatags": // $run_result = "<link href=\"/".$template_variable.".css\" rel=\"stylesheet\" type=\"text/css\" />"; return "<style type=\"text/css\"><!--\n" . templates_draw(array('template' => $template_id, 'context' => 'css')) . "// -->\n</style>\n" . $metatags; break; case 'perf': $perf = get_performance_info(); if (defined('ELGG_PERFTOLOG')) { error_log("PERF: " . $perf['txt']); } if (defined('ELGG_PERFTOFOOT') || $CFG->debug > 7 || $CFG->perfdebug > 7) { return $perf['html']; } break; } } return $run_result; }