public static function Option($a = array(), $v = null, $all = null) { $option = null; if ($all) { $selected = $v ? null : 'selected'; $option .= "<option value='' {$selected}>" . strip_tags($all) . "</option>"; } $v = explode(',', $v); settype($v, 'array'); if (is_list($a)) { $a = array_to_map($a); } foreach ($a as $key => $value) { if (is_array($value)) { $key = strval($value['id']); $value = strval($value['name']); } $selected = in_array($key, $v) ? 'selected' : null; $option .= "<option value='{$key}' {$selected}>" . strip_tags($value) . "</option>"; } return $option; }
function user_map() { global $output_paths; $users = DB_DataObject::factory('user'); $users->query('SELECT id, nickname FROM user'); $user_count = 0; $map_count = 1; while ($users->fetch()) { // Maximum 50,000 URLs per sitemap file. if ($user_count == 50000) { $user_count = 0; $map_count++; } $user_args = array('nickname' => $users->nickname); // Define parameters for generating <url></url> elements. $user = array('url' => common_local_url('showstream', $user_args), 'changefreq' => 'daily', 'priority' => '1'); $user_rss = array('url' => common_local_url('userrss', $user_args), 'changefreq' => 'daily', 'priority' => '0.3'); $all = array('url' => common_local_url('all', $user_args), 'changefreq' => 'daily', 'priority' => '1'); $all_rss = array('url' => common_local_url('allrss', $user_args), 'changefreq' => 'daily', 'priority' => '0.3'); $replies = array('url' => common_local_url('replies', $user_args), 'changefreq' => 'daily', 'priority' => '1'); $replies_rss = array('url' => common_local_url('repliesrss', $user_args), 'changefreq' => 'daily', 'priority' => '0.3'); $foaf = array('url' => common_local_url('foaf', $user_args), 'changefreq' => 'weekly', 'priority' => '0.5'); // Construct a <url></url> element for each user facet and add it // to our existing list of those. $user_list[$map_count] .= url($user); $user_rss_list[$map_count] .= url($user_rss); $all_list[$map_count] .= url($all); $all_rss_list[$map_count] .= url($all_rss); $replies_list[$map_count] .= url($replies); $replies_rss_list[$map_count] .= url($replies_rss); $foaf_list[$map_count] .= url($foaf); $user_count++; } // Make full sitemaps from the lists and save them. // Possible factoring: put all the lists into a master array, thus allowing // calling with single argument (i.e., array_to_map('user')). array_to_map($user_list, 'user'); array_to_map($user_rss_list, 'user_rss'); array_to_map($all_list, 'all'); array_to_map($all_rss_list, 'all_rss'); array_to_map($replies_list, 'replies'); array_to_map($replies_rss_list, 'replies_rss'); array_to_map($foaf_list, 'foaf'); }
function column_item_value($key, &$data, $column_info, $length) { $display_value = $data[$key]; if ($length != 0) { $display_value = substr($display_value, 0, $length); } if ($column_info[$key]['type'] == 'select') { $options = $column_info[$key]['options']; if (is_list($options)) { $options = array_to_map($options); } if ($options[$display_value]) { $display_value = $options[$display_value]; } } if ($column_info[$key]['link']) { $link = $column_info[$key]['link']; $link_type = $link['link_type']; $column = $link['column']; if (empty($column)) { $column = $key; } if ($link_type == 'school' || $link_type == 'project' || $link_type == 'user') { $html = "<a target='_blank' href='/{$link_type}/detail/" . $data[$column] . "'>" . $display_value . "</a>"; } if ($link_type == 'mail') { $html = "<a target='_blank' href='mailto:" . $display_value . "'>" . $display_value . "</a>"; } if ($link_type == 'website') { $html = "<a target='_blank' href='" . $data[$column] . "'>" . $display_value . "</a>"; } if ($link_type == 'weibo') { $weibo_link = $data['weibo_link']; $weibo_name = $data['weibo_name']; if ($weibo_link && $weibo_name) { $html = "<a target='_blank' href='" . $weibo_link . "'>" . $weibo_name . "</a>"; } } if ($link_type == 'tag') { $html = display_tag_string($data['id'], $data['tags']); } return $html; } else { if ($column_info[$key]['extra_type'] == 'money') { return moneyit($display_value); } return $display_value; } }
function json_encode_for_xedit($array) { if (!$array) { return false; } if (is_list($array)) { $array = array_to_map($array); } foreach ($array as $k => $v) { $temp_array[] = array('value' => $k, 'text' => $v); } return json_encode($temp_array); }