public function testConcat() { $xs = new MyArray(array(1, 2)); $result = $xs->concat(array(3))->toList(); $this->assertEquals(array(1, 2, 3), $result); $result = $xs->concat(array(3, 4))->toList(); $this->assertEquals(array(1, 2, 3, 4), $result); }
function testIt() { $arr = new MyArray(); for ($i = 0; $i < 20; $i++) { $val = new stdClass(); $val->foo = "foo value {$i}"; $arr->push($val); } $tpl = $this->newPHPTAL('input/array-overload.01.html'); $tpl->myobject = $arr; $res = $tpl->execute(); $exp = normalize_html_file('output/array-overload.01.html'); $res = normalize_html($res); $this->assertEquals($exp, $res); }
function get_page($url) { $_SESSION['fw_search_count']++; global $links_list; global $index_list; global $local_check; global $db; global $error404; global $noindex; global $start_time; $link_matches = array(); $page = ''; $can_process = true; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); $page = curl_exec($curl); $result = curl_getinfo($curl); curl_close($curl); if ($page != '' && in_array($result['http_code'], array('200', '302', '301'))) { preg_match_all("/<a[^>]*?href\\s*=\\s*[\"\\'\\s]*([^\\s\"\\'>]+)/i", $page, $link_matches); preg_match("/<title>([^<]*)<\\/title>/i", $page, $title); preg_replace("/<title>[^<]*<\\/title>/i", "", $page); if (isset($title[1])) { $title = $title[1]; } else { $title = ''; } //----------------------------ИНДЕКСАЦИЯ----------------------------------- $page = str_replace("\r", " ", $page); $page = str_replace("\n", " ", $page); $page = preg_replace("/<!--[^>]+?-->/i", " ", $page); $page = preg_replace("/<script[^>]*>[^>]+?<\\/script>/im", " ", $page); $page = preg_replace("/<skip>[^\$]+?<\\/skip>/im", " ", $page); $page = preg_replace("/<[^>]*>/i", " ", $page); $page = preg_replace("/<\\/[^>]*>/i", " ", $page); $page = preg_replace("/\\s+/", " ", $page); $page = str_replace(' ', "", $page); $page = mysql_real_escape_string($page); $title = mysql_real_escape_string($title); $sqlurl = $result['url']; $index_list[] = $url; $db->query("REPLACE INTO fw_search(url,title,content) VALUES('{$sqlurl}','{$title}','{$page}')"); //------------------------------------------------------------------------- $tmp_list = $link_matches[1]; for ($i = 0; $i < sizeof($tmp_list); $i++) { $check = true; if (substr($tmp_list[$i], -1) == '/') { $tmp_list[$i] = substr($tmp_list[$i], 0, -1); } if (substr($tmp_list[$i], 0, 1) == '/') { $tmp_list[$i] = substr($tmp_list[$i], 1); } if (!stristr($tmp_list[$i], 'http://')) { $tmp_list[$i] = BASE_URL . '/' . $tmp_list[$i]; } $ext = substr($tmp_list[$i], -4); if (in_array($tmp_list[$i], $links_list) || in_array($tmp_list[$i], $index_list) || $tmp_list[$i] == BASE_URL || $tmp_list[$i] == BASE_URL . '/#' || !stristr($tmp_list[$i], $local_check) || preg_match("/^\\.[a-z]{3}\$/", $ext)) { $check = false; } foreach ($noindex as $k => $v) { if (stristr($tmp_list[$i], $v)) { $check = false; } } if ($check) { $links_list[] = $tmp_list[$i]; } } } if ($_SESSION['fw_search_count'] >= 50 && isset($links_list[0]) && strlen($links_list[0]) >= strlen(BASE_URL)) { $_SESSION['fw_links_list'] = serialize($links_list); $_SESSION['fw_index_list'] = serialize($index_list); $end_time = time(); $result_time = $end_time - $start_time; $_SESSION['fw_search_time'] += $result_time; $location = BASE_URL . '/admin/index.php?mod=search&action=index&do=update_search_index&next=true'; header("Location: {$location}"); die; } if (isset($links_list[0]) && strlen($links_list[0]) >= strlen(BASE_URL)) { $goto = $links_list[0]; $links_list = MyArray::unset_element($links_list, 0); get_page($goto); } return $index_list; }
<?php require_once getenv("DOCUMENT_ROOT") . "/lib/config.php"; require_once "ArrayString.php"; $arr = array(3, 5, 8, 7, -5, 9); $string = "Hello man"; MyArray::length($arr); MyString::length($string);
$current_poll_found = false; $active_polls = array(); $finished_polls = array(); $polls_list = $db->get_all("SELECT * FROM fw_polls WHERE status>'0' ORDER BY publish_date DESC"); for ($i = 0; $i < count($polls_list); $i++) { if ($polls_list[$i]['status'] == '1') { $current_poll = $polls_list[$i]; $answers_list = $db->get_all("SELECT *,(SELECT SUM(answers) FROM fw_polls_answers WHERE parent='" . $current_poll['id'] . "') AS total_answers FROM fw_polls_answers WHERE parent='" . $current_poll['id'] . "' ORDER BY sort_order"); $total_answers = $answers_list[0]['total_answers']; for ($a = 0; $a < count($answers_list); $a++) { if ($answers_list[$a]['answers'] > 0) { $answers_list[$a]['percent'] = round($answers_list[$a]['answers'] / $total_answers * 100, 1); } } $current_poll['answers'] = $answers_list; $polls_list = MyArray::unset_element($polls_list, $i); $current_poll_found = true; $check_poll = explode(",", @$_COOKIE['fw_polls']); if (in_array($current_poll['id'], $check_poll)) { $smarty->assign("poll_done", "true"); } break; } } for ($i = 0; $i < count($polls_list); $i++) { if ($polls_list[$i]['status'] == '1') { $active_polls[] = $polls_list[$i]; } else { $finished_polls[] = $polls_list[$i]; } }
static function generate_main_menu($level = 0) { global $db; $content = array(); $level_str = ""; if ($level > 0) { $level_str = "param_level BETWEEN 0 AND {$level} AND"; } $res = $db->get_all("SELECT * FROM fw_tree WHERE {$level_str} status='1' ORDER BY param_left"); $content = Common::generate_menu($res, $res[0]['param_left'], $res[0]['param_right']); $modules = array('shop', 'cabinet', 'site_map'); foreach ($content as $value) { if ($value['param_level'] == 1) { if (!in_array($value['module'], $modules)) { $modules[$value['url']] = $value['module']; } } } if (in_array("shop", $modules)) { $shop_menu = $db->get_all("SELECT id,name,url,param_left,param_right,(param_level+1) as param_level,'shop' as module,'1' as status FROM fw_catalogue WHERE status='1' ORDER BY param_left"); $shop_menu = Common::generate_menu($shop_menu, $shop_menu[0]['param_left'], $shop_menu[0]['param_right']); //print_r($shop_menu); $content = MyArray::insert_array_into_array($content, $shop_menu, "shop"); } if (in_array("forum", $modules)) { $forum_menu = $db->get_all("SELECT id,name,url,param_left,param_right,(param_level+1) as param_level,'forum' as module,status FROM fw_forums WHERE status='1' ORDER BY param_left"); $forum_menu = Common::generate_menu($forum_menu, $forum_menu[0]['param_left'], $forum_menu[0]['param_right']); $content = MyArray::insert_array_into_array($content, $forum_menu, "forum"); } if (in_array("news", $modules)) { $news_menu = $db->get_all("SELECT id,title as name,CONCAT('archive','/',id) as url,'1' as param_left,'2' as param_right,'2' as param_level,'news' as module,'1' as status FROM fw_news ORDER BY publish_date DESC"); $content = MyArray::insert_array_into_array($content, $news_menu, "news"); } /*if (in_array("cabinet", $modules)) { $cabinet_menu=array( array( "id" => "1", "name" => "Вход в систему", "url" => "login", "param_left" => "1", "param_right" => "2", "param_level" => "2", "module" => "cabinet", "status" => "1" ), array( "id" => "3", "name" => "Выполненные заказы", "url" => "orders", "param_left" => "5", "param_right" => "6", "param_level" => "2", "module" => "cabinet", "status" => "1" ), array( "id" => "4", "name" => "Регистрация", "url" => "register", "param_left" => "7", "param_right" => "8", "param_level" => "2", "module" => "cabinet", "status" => "1" ), array( "id" => "5", "name" => "Выйти из системы", "url" => "logout", "param_left" => "9", "param_right" => "10", "param_level" => "2", "module" => "cabinet", "status" => "1" ) ); $content=MyArray::insert_array_into_array($content, $cabinet_menu, "cabinet"); }*/ $full_url = "/"; $_tmp_full_url = $full_url; $content = Common::generate_main_menu_full_url($content, $full_url); return $content; }