function macro_TitleIndex($formatter, $value, $options = array()) { global $DBInfo; $pc = !empty($DBInfo->titleindex_pagecount) ? intval($DBInfo->titleindex_pagecount) : 100; if ($pc < 1) { $pc = 100; } $pg = empty($options['p']) ? 1 : intval($options['p']); if ($pg < 1) { $pg = 1; } $group = $formatter->group; $key = -1; $keys = array(); if ($value == '' or $value == 'all') { $sel = ''; } else { $sel = ucfirst($value); } // get all keys $all_keys = get_keys(); if (isset($sel[0])) { if (!isset($all_keys[$sel])) { $sel = key($all_keys); } // default } if (@preg_match('/' . $sel . '/i', '') === false) { $sel = ''; } $titleindex = array(); // cache titleindex $kc = new Cache_text('titleindex'); $delay = !empty($DBInfo->default_delaytime) ? $DBInfo->default_delaytime : 0; $uid = ''; if (function_exists('posix_getuid')) { $uid = '.' . posix_getuid(); } $lock_file = _fake_lock_file($DBInfo->vartmp_dir, 'titleindex' . $uid); $locked = _fake_locked($lock_file, $DBInfo->mtime()); if ($locked or $kc->exists('key') and $DBInfo->checkUpdated($kc->mtime('key'), $delay)) { if (!empty($formatter->use_group) and $formatter->group) { $keys = $kc->fetch('key.' . $formatter->group); $titleindex = $kc->fetch('titleindex.' . $formatter->group); } else { $keys = $kc->fetch('key'); $titleindex = $kc->fetch('titleindex' . $sel); } if (isset($sel[0]) and isset($titleindex[$sel])) { $all_pages = $titleindex[$sel]; } if (empty($titleindex) and $locked) { // no cache found return _("Please wait..."); } } if (empty($all_pages)) { $all_pages = array(); $indexer = $DBInfo->lazyLoad('titleindexer'); if (!empty($formatter->use_group) and $formatter->group) { $group_pages = $indexer->getLikePages('^' . $formatter->group); foreach ($group_pages as $page) { $all_pages[] = str_replace($formatter->group, '', $page); } } else { $all_pages = $indexer->getLikePages('^' . $all_keys[$sel], 0); } #natcasesort($all_pages); #sort($all_pages,SORT_STRING); //usort($all_pages, 'strcasecmp'); $pages = array_flip($all_pages); if (!empty($formatter->use_group)) { array_walk($pages, '_setpagekey'); } else { array_walk($pages, create_function('&$p, $k', '$p = $k;')); } $all_pages = array_flip($pages); uksort($all_pages, 'strcasecmp'); } if (empty($keys) or empty($titleindex)) { _fake_lock($lock_file); foreach ($all_pages as $page => $rpage) { $p = ltrim($page); $pkey = get_key("{$p}"); if ($key != $pkey) { $key = $pkey; //$keys[] = $pkey; if (!isset($titleindex[$pkey])) { $titleindex[$pkey] = array(); } } $titleindex[$pkey][$page] = $rpage; } $keys = array_keys($all_keys); if (!empty($tlink)) { $keys[] = 'all'; } if (!empty($formatter->use_group) and $formatter->group) { $kc->update('key.' . $formatter->group, $keys); $kc->update('titleindex.' . $formatter->group, $titleindex); } else { $kc->update('key', $keys); $kc->update('titleindex' . $sel, $titleindex); } if (isset($sel[0]) and isset($titleindex[$sel])) { $all_pages = $titleindex[$sel]; } _fake_lock($lock_file, LOCK_UN); } $pnut = null; if (isset($sel[0]) and count($all_pages) > $pc) { $pages_number = intval(count($all_pages) / $pc); if (count($all_pages) % $pc) { $pages_number++; } $pages = array_keys($all_pages); $pages = array_splice($pages, ($pg - 1) * $pc, $pc); $selected = array(); foreach ($pages as $p) { $selected[$p] = $all_pages[$p]; } $pages = $selected; $pnut = get_pagelist($formatter, $pages_number, '?action=titleindex&sec=' . $sel . '&p=', !empty($pg) ? $pg : 1); } else { $pages =& $all_pages; } //print count($all_pages); //exit; $out = ''; # if ($DBInfo->use_titlecache) # $cache=new Cache_text('title'); $key = ''; foreach ($pages as $page => $rpage) { $p = ltrim($page); $pkey = get_key("{$p}"); if ($key != $pkey) { $key = $pkey; if (isset($sel[0]) and !preg_match('/^' . $sel . '/i', $pkey)) { continue; } if (!empty($out)) { $out .= "</ul>"; } $out .= "<a name='{$key}'></a><h3><a href='#top'>{$key}</a></h3>\n"; $out .= "<ul>"; } if (isset($sel[0]) and !preg_match('/^' . $sel . '/i', $pkey)) { continue; } # # if ($DBInfo->use_titlecache and $cache->exists($page)) # $title=$cache->fetch($page); # else $title = get_title($rpage, $page); #$out.= '<li>' . $formatter->word_repl('"'.$page.'"',$title,'',0,0); $urlname = _urlencode($group . $rpage); $out .= '<li>' . $formatter->link_tag($urlname, '', _html_escape($title)); $keyname = $DBInfo->pageToKeyname(urldecode($rpage)); if (is_dir($DBInfo->upload_dir . "/{$keyname}") or !empty($DBInfo->use_hashed_upload_dir) and is_dir($DBInfo->upload_dir . '/' . get_hashed_prefix($keyname) . $keyname)) { $out .= ' ' . $formatter->link_tag($urlname, "?action=uploadedfiles", $formatter->icon['attach']); } $out .= "</li>\n"; } if (!empty($pnut)) { $out .= '<li style="list-style:none">' . $pnut . '</li>' . "\n"; } $out .= "</ul>\n"; $index = ''; $tlink = ''; if (isset($sel[0])) { $tlink = $formatter->link_url($formatter->page->urlname, '?action=titleindex&sec='); } $index = array(); foreach ($keys as $key) { $name = strval($key); $tag = '#' . $key; $link = !empty($tlink) ? preg_replace('/sec=/', 'sec=' . _urlencode($key), $tlink) : ''; if ($name == 'Others') { $name = _("Others"); } else { if ($name == 'all') { $name = _("Show all"); } } $index[] = "<a href='{$link}{$tag}'>{$name}</a>"; } $str = implode(' | ', $index); return "<center><a name='top'></a>{$str}</center>\n{$out}"; }
#!/usr/bin/php <?php function get_keys($argv) { if (isset($argv)) { $dict = array(); foreach ($argv as $elem) { $tmp = explode(":", $elem); $dict = array_merge($dict, array($tmp[0] => $tmp[1])); } } return $dict; } if ($argv > 1) { unset($argv[0]); $search = $argv[1]; unset($argv[1]); $dict = get_keys($argv); if (array_key_exists($search, $dict)) { foreach ($dict as $key => $value) { if ($key == $search) { echo $value . "\n"; } } } }
function amazon_getkey($id, $key, $media) { global $vars, $array, $genre; global $_amazon_msg; $filename = CACHE_DIR . "AZ" . $id . ".link"; $body = amazon_getfile($filename); $key = htmlspecialchars($key); //ページタイトル、空白で区切り数個並べる、単独使用 $keys = $key == '' ? get_keys($vars['page']) : split(' ', $key); srand(); $key = $key0 = $keys[rand(0, count($keys) - 1)]; $search = "search=" . rawurlencode(mb_convert_encoding($key, 'UTF-8', SOURCE_ENCODING)); $media = trim(htmlspecialchars($media)); $medias = preg_split('/ +/', $media); $media = $media == '' ? $genre[rand(0, count($genre) - 1)] : $medias[rand(0, count($medias) - 1)]; $mode = "mode={$media}-jp"; $body = preg_replace("'mode=[^&]+'", $mode, $body); $body = preg_replace("'search=[^&]+'", $search, $body); $footer = "</iframe><div style='text-align:center'><span style='color:red'>{$key0}" . "{$_amazon_msg['msg_Relation']}<br />({$media})</span></div>"; $body = preg_replace("'</iframe>'", $footer, $body); return $body; }
######## Get posted values ######## if ($_POST['action'] == "get_keys") { // get posted values: $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); $auth_url = mysql_real_escape_string($_POST['auth_url']); $version = mysql_real_escape_string($_POST['api_version']); $redirect = mysql_real_escape_string($_POST['redirect']); //point script back to the page it came from ## Test values: #$name="xGDBvm"; $description = "This app is a virtual server for genome annotation, registered on {$today}"; $callback_url = ""; #$version="v2"; // run 'get_keys' function (login_functions_inc.php) using posted credentials and auth_url: $keys = get_keys($username, $password, $auth_url, $name, $description, $callback_url, $version); // sends user/pass (via curl) to auth_url to obtain a consumer_key and consumer_secret, http_code indicates success or not // return array($status, $message, $http_code, $consumer_key, $consumer_secret, $name, $version_details, $url, $header_sent, $response); $status = $keys[0]; $message = $keys[1]; $http_code = $keys[2]; //200 = success; 401 = bad username/password; 400 Bad Request The request could not be understood by the server due to malformed syntax. 0 = no repsonse (bad URL) $consumer_key = $keys[3]; //hash string $consumer_secret = $keys[4]; //hash string $stored_name = $keys[5]; //name spit back by the server, should be same as sent $version_details = $keys[6]; // detailed version $url = $keys[7];