Exemple #1
0
function array_replace_keys(&$array, $callback)
{
    $copy = $array;
    array_clear($array);
    foreach ($copy as $value) {
        $array[$callback($value)] = $value;
    }
    ksort($array);
    return $array;
}
Exemple #2
0
 /**
  * 读取日志内的接口调用记录
  *
  * @param unknown $fileRealPath
  * @param string $url
  * @return multitype:Ambigous <> |boolean|multitype:|multitype:Ambigous <Ambigous> |Ambigous <number, multitype:, multitype:Ambigous , multitype:multitype:unknown string >
  */
 function readMonoLogFile($fileRealPath, $url = '')
 {
     static $returns = [];
     static $loaded = [];
     if ($url) {
         if (isset($returns[$url])) {
             return [$url => $returns[$url]];
         }
         if (isset($loaded[$fileRealPath])) {
             return false;
         }
     } else {
         if (isset($loaded[$fileRealPath])) {
             return $returns;
         } else {
             $loaded[$fileRealPath] = true;
         }
     }
     $filelines = [];
     file_exists($fileRealPath) && ($filelines = file($fileRealPath, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES));
     $HTTP_HOST = '';
     $keys = ['status', 'message', 'data'];
     foreach ($filelines as $key => $line) {
         preg_match('/\\{.*\\}/', $line, $matchs);
         if ($matchs) {
             $matchs = json_decode($matchs[0], true);
             if (json_last_error() == JSON_ERROR_NONE && isset($matchs['Url']) && isset($matchs['func_num_args']) && (!$url || endsWith($matchs['Url'], $url))) {
                 if (!$HTTP_HOST) {
                     // Get Host Name
                     preg_match('/^http(:?s)?:\\/\\/[^\\/]*/', $matchs['Url'], $mh);
                     if ($mh) {
                         $HTTP_HOST = $mh[0];
                     }
                 }
                 $matchs['Url'] = substr($matchs['Url'], stripos($matchs['Url'], $HTTP_HOST) + strlen($HTTP_HOST));
                 $matchs['Url'] = '/' . ltrim($matchs['Url'], '/');
                 $ret = $matchs['func_num_args'];
                 count($ret) == 2 && ($ret[] = []);
                 $ret = array_combine($keys, $ret);
                 // /Filter When Return Data Contains [object]
                 // [object] (User\Account: {"uid":159007,"password":"","salt":"","account_status":0,"my_code":"031077"})
                 // array_map_recursive
                 $ret = json_decode_recursive($ret);
                 $ret = array_clear($ret);
                 // TODO :Remove Large Return
                 if (isset($returns[$matchs['Url']])) {
                     $returns[$matchs['Url']]['Times']++;
                     /**
                      * 补全返回信息
                      */
                     if (isset($ret['status']) && !isset($returns[$matchs['Url']]['Return'][$ret['status']])) {
                         $returns[$matchs['Url']]['Return'][$ret['status']] = $ret;
                     } else {
                         if (isset($returns[$matchs['Url']]['Return'][$ret['status']])) {
                             // TODO :Complete Return Info
                             // Complete Input Data
                             if (!isset($returns[$matchs['Url']]['Return'][$ret['status']]['data'])) {
                                 // 								edump ( $returns [$matchs ['Url']] ['Return'] [$ret ['status']] );
                                 continue;
                             }
                             if (is_array($ret['data'])) {
                                 $returns[$matchs['Url']]['Return'][$ret['status']]['data'] = array_filter($returns[$matchs['Url']]['Return'][$ret['status']]['data'], function ($v) {
                                 }) + $ret['data'];
                                 ksort($returns[$matchs['Url']]['Return'][$ret['status']]['data']);
                             }
                             // isset($returns[$matchs['Url']]['Return'][$ret['status']]['data'] ) &&
                         }
                     }
                     $returns[$matchs['Url']]['Params'] = array_filter($returns[$matchs['Url']]['Params']) + $matchs['Input'];
                 } else {
                     if (isset($matchs['Input'])) {
                         // Add Input And Return
                         $returns[$matchs['Url']] = ['Times' => 1, 'Url' => $matchs['Url'], 'Params' => $matchs['Input'], 'Method' => $matchs['Method']];
                         if (isset($ret['status'])) {
                             $returns[$matchs['Url']]['Return'][$ret['status']] = $ret;
                         }
                     } else {
                         // TODO :Error Handler
                         // echo 'Input Field Not Found<br/>';
                         // return false;
                     }
                 }
             } else {
                 // echo 'Line '.$key.' Can\'t Be Json Or Can\'t Find Url<br/>';
                 // return false;
             }
         }
     }
     if ($url) {
         if (isset($returns[$url])) {
             return [$url => $returns[$url]];
         } else {
             return false;
         }
     }
     return $returns;
 }
Exemple #3
0
 /**
  * Test array_clear
  */
 function test_array_clear()
 {
     $data = array('first' => 'one', 'second' => 'two', 'third' => 'three');
     array_clear($data);
     $this->assertEquals(0, count($data));
 }
Exemple #4
0
assert('true === array_has_key($data, "third")');
array_unset_key($data, 'third');
assert('false === array_has_key($data, "third")');
array_unset_key($data, 'notpresent');
assert('false === array_has_key($data, "notpresent")');
/* test array_unset_keys */
$data = array('first' => 'one', 'second' => 'two', 'third' => 'three');
$keys_to_remove = array('first', 'second', 'notpresent');
array_unset_keys($data, $keys_to_remove);
assert('false === array_has_key($data, "first")');
assert('false === array_has_key($data, "second")');
assert('true === array_has_key($data, "third")');
assert('false === array_has_key($data, "notpresent")');
/* test array_clear */
$data = array('first' => 'one', 'second' => 'two', 'third' => 'three');
array_clear($data);
assert('count($data) == 0');
/* test array_flip_string_keys */
$data = array('first' => 'one', 'second' => 'two', 'third' => 'three', 4 => 'four', 5 => 'five', 'six' => 6);
$data = array_flip_string_keys($data);
assert('true === array_has_key($data, "one")');
assert('true === array_has_key($data, "two")');
assert('false === array_has_key($data, "first")');
assert('true === array_has_key($data, 4)');
assert('true === array_has_key($data, 6)');
assert('false === array_has_key($data, "six")');
$data = array_flip_string_keys($data);
assert('true === array_has_key($data, 6)');
assert('true === array_has_key($data, "first")');
/* test array_check_types */
$data = array('foo', 1, '2', true, 'bar', array());
Exemple #5
0
function xrumer_task($maps, $indexs, $post_links, $project_name, $multi = 1, $limit = 0)
{
    //Генерация проекта для хрумера
    //$multi - параметр, определяющий способ генерации. 0- для одиночного дора, 1- для нескольких доров
    //$maps - массив ссылок с анкорами на карты доров в виде url||key
    //$indexs - массив ссылок с анкорами на индексы доров виде url||key
    //$post_links - массив ссылок, учавствующих в формировании текста поста виде url||key
    $maps = array_clear($maps);
    $indexs = array_clear($indexs);
    $post_links = array_clear($post_links);
    //Домашняя страница
    if ($multi) {
        //В проекте учавствуют несколько доров, поэтому в домашнюю страницу подставляются
        //только индексы этих доров
        $home_page = get_url_var_str($indexs);
    } else {
        //Проект создается для одного дора, поэтому в домашнюю страницу подставляются
        //как индексы так и линки на карты
        $home_page = get_url_var_str(array_merge($indexs, $maps));
    }
    //Подпись
    $signature = get_url_ankor_vars(array_merge($indexs, $maps));
    //Тема
    $subject = get_ankor_var_str($indexs, $limit);
    //Текст объявления
    $post_text = get_xrumer_text($post_links, $limit);
    //считываем шаблон проекта
    $tpl = file_get_contents('xrumer.tpl');
    //Массив макросов
    $search_arr = array('[project_name]', '[home_page]', '[signature]', '[subject]', '[post_text]');
    //Массив замен макросов
    $replace_arr = array($project_name, $home_page, $signature, $subject, $post_text);
    //Готовый проект
    $project = str_replace($search_arr, $replace_arr, $tpl);
    return $project;
}
Exemple #6
0
function checkstep2()
{
    global $conf, $app_default;
    if (count($app_default) != 0) {
        //之后会支持多数据库
        $_SESSION['app_conf'][0]['mysql_host'] = $_GET['mysql_host'];
        $_SESSION['app_conf'][0]['mysql_port'] = $_GET['mysql_port'];
        $_SESSION['app_conf'][0]['mysql_user'] = $_GET['mysql_user'];
        $_SESSION['app_conf'][0]['mysql_pwd'] = $_GET['mysql_pwd'];
        $_SESSION['app_conf'][0]['db_name'] = $_GET['db_name'];
        $_SESSION['app_conf'][0]['db_pre'] = $_GET['db_pre'];
        $_SESSION['app_conf'][0]['app_root'] = $_GET['app_root'];
        $_SESSION['app_conf'][0]['db_isdrop'] = $_GET['db_isdrop'];
        $dbserver = $_GET['mysql_host'] . (isset($_GET['mysql_port']) ? ":" . $_GET['mysql_port'] : '');
        $conn = @mysql_connect($dbserver, $_GET['mysql_user'], $_GET['mysql_pwd']);
        //连接到MySQL Server
        if (!$conn) {
            $notes = array('notes' => "数据库设置不正确!");
            remark_setup(0, $notes);
            return false;
        } else {
            $_SESSION['setup_conf']['conf'] = $_SESSION['app_conf'][0];
        }
    }
    if (count($conf['APP_SVN']) > 0) {
        foreach ($conf['APP_SVN'] as $s) {
            $svn = new phpsvnclient($s['SVN_URL'], $s['SVN_USER'], $s['SVN_PWD']);
            $files = $svn->getDirectoryFiles($s['SVN_DIR']);
            if (count($files) == 0) {
                $notes = array('notes' => $s['SVN_TITLE'] . "-SVN设置不正确!");
                remark_setup(0, $notes);
                return false;
            } else {
                $setup_conf_svn[] = $s;
            }
        }
        $_SESSION['setup_conf']['svn'] = array_clear($setup_conf_svn);
        //过滤重复的数组
    }
    if (count($conf['APP_SQL']) > 0) {
        foreach ($conf['APP_SQL'] as $s) {
            $files = $s['SQL_FILE'];
            if (!file_exists($files)) {
                $notes = array('notes' => $s['SQL_INFO'] . '-' . $s['SQL_FILE'] . '-' . "-SQL文件不存在!");
                remark_setup(0, $notes);
                return false;
            } else {
                $setup_conf_sql[] = $s;
            }
        }
        $_SESSION['setup_conf']['sql'] = array_clear($setup_conf_sql);
        //过滤重复的数组
    }
    remark_setup(1);
    return true;
}
Exemple #7
0
 $index_urls = array();
 $map_urls = array();
 $page_urls = array();
 while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
     $id = $row["id"];
     $index_st = explode('&', $row["index_urls"]);
     $map_st = explode('&', $row["map_urls"]);
     $page_st = explode('&', $row["page_urls"]);
     $index_urls = array_merge($index_urls, $index_st);
     $map_urls = array_merge($map_urls, $map_st);
     $page_urls = array_merge($page_urls, $page_st);
 }
 mysql_free_result($result);
 $index_urls = array_clear(array_values(array_unique($index_urls)));
 $map_urls = array_clear(array_values(array_unique($map_urls)));
 $page_urls = array_clear(array_values(array_unique($page_urls)));
 $project_name = str_replace('.', '', $domen);
 $aposter_links = implode("\n", $page_urls);
 //$urls_arr = get_urls($links_arr);
 $urls_arr = get_urls($page_urls);
 $urls = implode("\n", $urls_arr[0]);
 $ankors = implode("\n", $urls_arr[1]);
 $bbcodes = implode("\n", $urls_arr[2]);
 $hrefs = implode("\n", $urls_arr[3]);
 $name = '{';
 $name .= implode("|", $urls_arr[1]);
 $name .= '}#gennick[' . md5($domen) . ', 5, 8]';
 $nick_name = str_replace(' ', '', $name);
 include 'data/d/header.php';
 //Выводим форму
 $form = '<form action=' . $_SERVER['PHP_SELF'] . ' method="post">