login(); sleep(2); /** * Get all xpath of main menu. * * @param int $count * @access public * @return mixed */ function getAppMenu($mainCount = 15) { $xpath = '//*[@id="menuMainNav"]/li[%s]'; $mainMenu = array(); for($i = 1; $i <= $mainCount; $i ++) { $mainMenu[] = sprintf($xpath, $i); } return $mainMenu; } /** * Get all xpath of secondary menu. * * @param int $count * @access public * @return mixed */ function getMainNav($count = 20) { $xpath = '//*[@id="navbar"]//li[%s]'; $menus = array(); for($i = 1; $i <= $count; $i ++) { $menus[] = sprintf($xpath, $i); } return $menus; } /** * Get all xpath of level3 menu. * * @param int $count * @access public * @return mixed */ function getSubNav($count = 10) { $xpath = '//*[@id="subNavbar"]/ul/li[%s]'; $menus = array(); for($i = 1; $i <= $count; $i ++) { $menus[] = sprintf($xpath, $i); } return $menus; } /** * Get all xpath of more menu. * * @param int $count * @access public * @return void */ function getMoreMenu($count = 5) { $xpath = '//*[@id="menuMoreList"]/li[%s]/a'; $menus = array(); for($i = 1; $i <= $count; $i ++) { $menus[] = sprintf($xpath, $i); } return $menus; } /** * Get all xpath of set menu. * * @param int $count * @access public * @return void */ function getSetMenu($count = 10) { $xpath = '//*[@id="mainContent"]/div[1]/div[1]/div[2]/div[%s]'; $menus = array(); for($i = 1; $i <= $count; $i ++) { $menus[] = sprintf($xpath, $i); } return $menus; } /** * Filter link list. * * @param array $linkList * @param string $type get|pathinfo|'' * @access public * @return object */ function filter($linkList, $type = '') { $links = new stdclass; foreach($linkList as $link) { if(preg_match('/^$/', $link) !== 0) continue; if(strpos($link, 'javascript:') !== false) continue; if(strpos($link, 'index.php') === false) continue; if(strpos($link, '%') !== false) continue; if($type == 'get') { $queryString = str_replace('index.php?', '', $link); parse_str($queryString, $queryArray); if(!isset($queryArray['m'])) continue; $moduleName = $queryArray['m']; $methodName = strpos($queryArray['f'], '#') ? substr($queryArray['f'], 0, strpos($queryArray['f'], '#')) : $queryArray['f']; } if($type == 'pathinfo') { $urlParts = explode('-', $link); $moduleName = $urlParts[0]; $methodName = strpos($urlParts[1], '#') ? substr($urlParts[1], 0, strpos($urlParts[1], '#')) : $urlParts[1]; } if(!isset($links->$moduleName)) $links->$moduleName = new stdclass; if(!isset($links->$moduleName->$methodName)) $links->$moduleName->$methodName = array(); if(in_array($link, $links->$moduleName->$methodName)) continue; $links->$moduleName->$methodName[] = $link; } return $links; } /** * Save links to config file. * * @param object $object * @param string $name * @param string $fileName * @access public * @return mixed */ function saveToConfig($object, $name = 'config', $fileName = 'result.php') { $config = ''; $config .= " $moduleObject) { $config .= "\${$name}->{$module} = new stdclass;\n"; foreach($moduleObject as $method => $link) { foreach($link as $key => $value) { $methodName = $key == 0 ? $method : "{$method}_{$key}"; $config .= "\${$name}->{$module}->{$methodName} = '{$value}';\n"; } } } file_put_contents($fileName, $config); } /** * 点击第一级导航。 * Click first nav. * * @param string $menu * @param object $page * @param int $waitTime * @access public * @return void */ function clickFirstNAV($menu, $page, $waitTime = 2) { if(strpos($menu, 'menuMainNav') == false) $page->dom->btn('更多')->click(); $setMenu = ''; if(strpos($menu, 'mainContent') !== false) { $setMenu = $menu; $menu = '//*[@id="menuMoreList"]/li[@data-app="admin"]'; } $menuElement = $page->dom->getElement($menu); $appName = $menuElement->getText(); if(!$appName) $appName = $menuElement->attr('class'); if($appName == 'hidden') return false; $dataApp = $menuElement->attr('data-app'); $iframeID = 'appIframe-' . $dataApp; if($iframeID == 'admin' && (strpos($menu, 'mainContent') == false)) return false; if($iframeID == 'appIframe-') $iframeID = 'appIframe-admin'; $menuElement->click(); }