12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923 |
- <?php
- define('MENU_IS_ROOT', 0x0001);
- define('MENU_VISIBLE_IN_TREE', 0x0002);
- define('MENU_VISIBLE_IN_BREADCRUMB', 0x0004);
- define('MENU_LINKS_TO_PARENT', 0x0008);
- define('MENU_MODIFIED_BY_ADMIN', 0x0020);
- define('MENU_CREATED_BY_ADMIN', 0x0040);
- define('MENU_IS_LOCAL_TASK', 0x0080);
- define('MENU_IS_LOCAL_ACTION', 0x0100);
- define('MENU_NORMAL_ITEM', MENU_VISIBLE_IN_TREE | MENU_VISIBLE_IN_BREADCRUMB);
- define('MENU_CALLBACK', 0x0000);
- define('MENU_SUGGESTED_ITEM', MENU_VISIBLE_IN_BREADCRUMB | 0x0010);
- define('MENU_LOCAL_TASK', MENU_IS_LOCAL_TASK | MENU_VISIBLE_IN_BREADCRUMB);
- define('MENU_DEFAULT_LOCAL_TASK', MENU_IS_LOCAL_TASK | MENU_LINKS_TO_PARENT | MENU_VISIBLE_IN_BREADCRUMB);
- define('MENU_LOCAL_ACTION', MENU_IS_LOCAL_TASK | MENU_IS_LOCAL_ACTION | MENU_VISIBLE_IN_BREADCRUMB);
- define('MENU_CONTEXT_NONE', 0x0000);
- define('MENU_CONTEXT_PAGE', 0x0001);
- define('MENU_CONTEXT_INLINE', 0x0002);
- define('MENU_FOUND', 1);
- define('MENU_NOT_FOUND', 2);
- define('MENU_ACCESS_DENIED', 3);
- define('MENU_SITE_OFFLINE', 4);
- define('MENU_SITE_ONLINE', 5);
-
- define('MENU_MAX_PARTS', 9);
- define('MENU_MAX_DEPTH', 9);
- define('MENU_PREFERRED_LINK', '1cf698d64d1aa4b83907cf6ed55db3a7f8e92c91');
- function menu_get_ancestors($parts) {
- $number_parts = count($parts);
- $ancestors = array();
- $length = $number_parts - 1;
- $end = (1 << $number_parts) - 1;
- $masks = variable_get('menu_masks');
-
-
-
-
- if (!$masks) {
- $masks = range(511, 1);
- }
-
- foreach ($masks as $i) {
- if ($i > $end) {
-
- continue;
- }
- elseif ($i < (1 << $length)) {
-
- --$length;
- }
- $current = '';
- for ($j = $length; $j >= 0; $j--) {
-
- if ($i & (1 << $j)) {
-
- $current .= $parts[$length - $j];
- }
- else {
-
- $current .= '%';
- }
-
- if ($j) {
- $current .= '/';
- }
- }
- $ancestors[] = $current;
- }
- return $ancestors;
- }
- function menu_unserialize($data, $map) {
- if ($data = unserialize($data)) {
- foreach ($data as $k => $v) {
- if (is_int($v)) {
- $data[$k] = isset($map[$v]) ? $map[$v] : '';
- }
- }
- return $data;
- }
- else {
- return array();
- }
- }
- function menu_set_item($path, $router_item) {
- menu_get_item($path, $router_item);
- }
- function menu_get_item($path = NULL, $router_item = NULL) {
- $router_items = &drupal_static(__FUNCTION__);
- if (!isset($path)) {
- $path = $_GET['q'];
- }
- if (isset($router_item)) {
- $router_items[$path] = $router_item;
- }
- if (!isset($router_items[$path])) {
-
-
- if (variable_get('menu_rebuild_needed', FALSE) || !variable_get('menu_masks', array())) {
- if (_menu_check_rebuild()) {
- menu_rebuild();
- }
- }
- $original_map = arg(NULL, $path);
- $parts = array_slice($original_map, 0, MENU_MAX_PARTS);
- $ancestors = menu_get_ancestors($parts);
- $router_item = db_query_range('SELECT * FROM {menu_router} WHERE path IN (:ancestors) ORDER BY fit DESC', 0, 1, array(':ancestors' => $ancestors))->fetchAssoc();
- if ($router_item) {
-
-
- drupal_alter('menu_get_item', $router_item, $path, $original_map);
- $map = _menu_translate($router_item, $original_map);
- $router_item['original_map'] = $original_map;
- if ($map === FALSE) {
- $router_items[$path] = FALSE;
- return FALSE;
- }
- if ($router_item['access']) {
- $router_item['map'] = $map;
- $router_item['page_arguments'] = array_merge(menu_unserialize($router_item['page_arguments'], $map), array_slice($map, $router_item['number_parts']));
- $router_item['theme_arguments'] = array_merge(menu_unserialize($router_item['theme_arguments'], $map), array_slice($map, $router_item['number_parts']));
- }
- }
- $router_items[$path] = $router_item;
- }
- return $router_items[$path];
- }
- function menu_execute_active_handler($path = NULL, $deliver = TRUE) {
-
- $page_callback_result = _menu_site_is_offline() ? MENU_SITE_OFFLINE : MENU_SITE_ONLINE;
-
-
-
- $read_only_path = !empty($path) ? $path : $_GET['q'];
- drupal_alter('menu_site_status', $page_callback_result, $read_only_path);
-
- if ($page_callback_result == MENU_SITE_ONLINE) {
- if ($router_item = menu_get_item($path)) {
- if ($router_item['access']) {
- if ($router_item['include_file']) {
- require_once DRUPAL_ROOT . '/' . $router_item['include_file'];
- }
- $page_callback_result = call_user_func_array($router_item['page_callback'], $router_item['page_arguments']);
- }
- else {
- $page_callback_result = MENU_ACCESS_DENIED;
- }
- }
- else {
- $page_callback_result = MENU_NOT_FOUND;
- }
- }
-
-
- if ($deliver) {
- $default_delivery_callback = (isset($router_item) && $router_item) ? $router_item['delivery_callback'] : NULL;
- drupal_deliver_page($page_callback_result, $default_delivery_callback);
- }
- else {
- return $page_callback_result;
- }
- }
- function _menu_load_objects(&$item, &$map) {
- if ($load_functions = $item['load_functions']) {
-
- if (!is_array($load_functions)) {
- $load_functions = unserialize($load_functions);
- }
- $path_map = $map;
- foreach ($load_functions as $index => $function) {
- if ($function) {
- $value = isset($path_map[$index]) ? $path_map[$index] : '';
- if (is_array($function)) {
-
-
-
-
- list($function, $args) = each($function);
- $load_functions[$index] = $function;
-
- foreach ($args as $i => $arg) {
- if ($arg === '%index') {
-
-
- $args[$i] = $index;
- }
- if ($arg === '%map') {
-
-
-
- $args[$i] = &$map;
- }
- if (is_int($arg)) {
- $args[$i] = isset($path_map[$arg]) ? $path_map[$arg] : '';
- }
- }
- array_unshift($args, $value);
- $return = call_user_func_array($function, $args);
- }
- else {
- $return = $function($value);
- }
-
- if ($return === FALSE) {
- $item['access'] = FALSE;
- $map = FALSE;
- return FALSE;
- }
- $map[$index] = $return;
- }
- }
- $item['load_functions'] = $load_functions;
- }
- return TRUE;
- }
- function _menu_check_access(&$item, $map) {
- $item['access'] = FALSE;
-
-
- $callback = empty($item['access_callback']) ? 0 : trim($item['access_callback']);
-
- if (is_numeric($callback)) {
- $item['access'] = (bool) $callback;
- }
- else {
- $arguments = menu_unserialize($item['access_arguments'], $map);
-
-
- if ($callback == 'user_access') {
- $item['access'] = (count($arguments) == 1) ? user_access($arguments[0]) : user_access($arguments[0], $arguments[1]);
- }
- elseif (function_exists($callback)) {
- $item['access'] = call_user_func_array($callback, $arguments);
- }
- }
- }
- function _menu_item_localize(&$item, $map, $link_translate = FALSE) {
- $callback = $item['title_callback'];
- $item['localized_options'] = $item['options'];
-
-
-
-
-
- if (isset($item['options']['attributes']['class']) && is_string($item['options']['attributes']['class'])) {
- $item['localized_options']['attributes']['class'] = explode(' ', $item['options']['attributes']['class']);
- }
-
-
-
-
-
-
- if (!$link_translate || ($item['title'] == $item['link_title'])) {
-
-
- if ($callback == 't') {
- if (empty($item['title_arguments'])) {
- $item['title'] = t($item['title']);
- }
- else {
- $item['title'] = t($item['title'], menu_unserialize($item['title_arguments'], $map));
- }
- }
- elseif ($callback && function_exists($callback)) {
- if (empty($item['title_arguments'])) {
- $item['title'] = $callback($item['title']);
- }
- else {
- $item['title'] = call_user_func_array($callback, menu_unserialize($item['title_arguments'], $map));
- }
-
- if ($callback == 'check_plain') {
- $item['localized_options']['html'] = TRUE;
- }
- }
- }
- elseif ($link_translate) {
- $item['title'] = $item['link_title'];
- }
-
- if (!empty($item['description'])) {
- $original_description = $item['description'];
- $item['description'] = t($item['description']);
- if ($link_translate && isset($item['options']['attributes']['title']) && $item['options']['attributes']['title'] == $original_description) {
- $item['localized_options']['attributes']['title'] = $item['description'];
- }
- }
- }
- function _menu_translate(&$router_item, $map, $to_arg = FALSE) {
- if ($to_arg && !empty($router_item['to_arg_functions'])) {
-
- _menu_link_map_translate($map, $router_item['to_arg_functions']);
- }
-
-
- $path_map = $map;
- if (!empty($router_item['load_functions']) && !_menu_load_objects($router_item, $map)) {
-
- $router_item['access'] = FALSE;
- return FALSE;
- }
-
- $link_map = explode('/', $router_item['path']);
- if (isset($router_item['tab_root'])) {
- $tab_root_map = explode('/', $router_item['tab_root']);
- }
- if (isset($router_item['tab_parent'])) {
- $tab_parent_map = explode('/', $router_item['tab_parent']);
- }
- for ($i = 0; $i < $router_item['number_parts']; $i++) {
- if ($link_map[$i] == '%') {
- $link_map[$i] = $path_map[$i];
- }
- if (isset($tab_root_map[$i]) && $tab_root_map[$i] == '%') {
- $tab_root_map[$i] = $path_map[$i];
- }
- if (isset($tab_parent_map[$i]) && $tab_parent_map[$i] == '%') {
- $tab_parent_map[$i] = $path_map[$i];
- }
- }
- $router_item['href'] = implode('/', $link_map);
- $router_item['tab_root_href'] = implode('/', $tab_root_map);
- $router_item['tab_parent_href'] = implode('/', $tab_parent_map);
- $router_item['options'] = array();
- _menu_check_access($router_item, $map);
-
- if ($router_item['access']) {
- _menu_item_localize($router_item, $map);
- }
- return $map;
- }
- function _menu_link_map_translate(&$map, $to_arg_functions) {
- $to_arg_functions = unserialize($to_arg_functions);
- foreach ($to_arg_functions as $index => $function) {
-
- $arg = $function(!empty($map[$index]) ? $map[$index] : '', $map, $index);
- if (!empty($map[$index]) || isset($arg)) {
- $map[$index] = $arg;
- }
- else {
- unset($map[$index]);
- }
- }
- }
- function menu_tail_to_arg($arg, $map, $index) {
- return implode('/', array_slice($map, $index));
- }
- function menu_tail_load($arg, &$map, $index) {
- $arg = implode('/', array_slice($map, $index));
- $map = array_slice($map, 0, $index);
- return $arg;
- }
- function _menu_link_translate(&$item, $translate = FALSE) {
- if (!is_array($item['options'])) {
- $item['options'] = unserialize($item['options']);
- }
- if ($item['external']) {
- $item['access'] = 1;
- $map = array();
- $item['href'] = $item['link_path'];
- $item['title'] = $item['link_title'];
- $item['localized_options'] = $item['options'];
- }
- else {
-
-
- $map = explode('/', $item['link_path']);
- if (strpos($item['link_path'], '%') !== FALSE) {
-
- if (!empty($item['to_arg_functions'])) {
- _menu_link_map_translate($map, $item['to_arg_functions']);
- }
-
-
-
-
-
-
-
-
- elseif ($translate && ($current_router_item = menu_get_item())) {
-
-
- if (strpos($current_router_item['path'], $item['link_path']) === 0) {
- $count = count($map);
- $map = array_slice($current_router_item['original_map'], 0, $count);
- $item['original_map'] = $map;
- if (isset($current_router_item['map'])) {
- $item['map'] = array_slice($current_router_item['map'], 0, $count);
- }
-
- unset($item['access']);
- }
- }
- }
- $item['href'] = implode('/', $map);
-
- if (strpos($item['href'], '%') !== FALSE) {
- $item['access'] = FALSE;
- return FALSE;
- }
-
- if (!isset($item['access'])) {
- if (!empty($item['load_functions']) && !_menu_load_objects($item, $map)) {
-
- $item['access'] = FALSE;
- return FALSE;
- }
- _menu_check_access($item, $map);
- }
-
- if ($item['access']) {
- _menu_item_localize($item, $map, TRUE);
- }
- }
-
-
-
- if (!empty($item['options']['alter'])) {
- drupal_alter('translated_menu_link', $item, $map);
- }
- return $map;
- }
- function menu_get_object($type = 'node', $position = 1, $path = NULL) {
- $router_item = menu_get_item($path);
- if (isset($router_item['load_functions'][$position]) && !empty($router_item['map'][$position]) && $router_item['load_functions'][$position] == $type . '_load') {
- return $router_item['map'][$position];
- }
- }
- function menu_tree($menu_name) {
- $menu_output = &drupal_static(__FUNCTION__, array());
- if (!isset($menu_output[$menu_name])) {
- $tree = menu_tree_page_data($menu_name);
- $menu_output[$menu_name] = menu_tree_output($tree);
- }
- return $menu_output[$menu_name];
- }
- function menu_tree_output($tree) {
- $build = array();
- $items = array();
-
-
- foreach ($tree as $data) {
- if ($data['link']['access'] && !$data['link']['hidden']) {
- $items[] = $data;
- }
- }
- $router_item = menu_get_item();
- $num_items = count($items);
- foreach ($items as $i => $data) {
- $class = array();
- if ($i == 0) {
- $class[] = 'first';
- }
- if ($i == $num_items - 1) {
- $class[] = 'last';
- }
-
-
-
- if ($data['link']['has_children'] && $data['below']) {
- $class[] = 'expanded';
- }
- elseif ($data['link']['has_children']) {
- $class[] = 'collapsed';
- }
- else {
- $class[] = 'leaf';
- }
-
- if ($data['link']['in_active_trail']) {
- $class[] = 'active-trail';
- $data['link']['localized_options']['attributes']['class'][] = 'active-trail';
- }
-
-
-
-
- if ($data['link']['href'] == $router_item['tab_root_href'] && $data['link']['href'] != $_GET['q']) {
- $data['link']['localized_options']['attributes']['class'][] = 'active';
- }
-
- $element['#theme'] = 'menu_link__' . strtr($data['link']['menu_name'], '-', '_');
- $element['#attributes']['class'] = $class;
- $element['#title'] = $data['link']['title'];
- $element['#href'] = $data['link']['href'];
- $element['#localized_options'] = !empty($data['link']['localized_options']) ? $data['link']['localized_options'] : array();
- $element['#below'] = $data['below'] ? menu_tree_output($data['below']) : $data['below'];
- $element['#original_link'] = $data['link'];
-
- $build[$data['link']['mlid']] = $element;
- }
- if ($build) {
-
- $build['#sorted'] = TRUE;
-
-
- $build['#theme_wrappers'][] = 'menu_tree__' . strtr($data['link']['menu_name'], '-', '_');
- }
- return $build;
- }
- function menu_tree_all_data($menu_name, $link = NULL, $max_depth = NULL) {
- $tree = &drupal_static(__FUNCTION__, array());
-
- $mlid = isset($link['mlid']) ? $link['mlid'] : 0;
-
- $cid = 'links:' . $menu_name . ':all:' . $mlid . ':' . $GLOBALS['language']->language . ':' . (int) $max_depth;
- if (!isset($tree[$cid])) {
-
- $cache = cache_get($cid, 'cache_menu');
- if ($cache && isset($cache->data)) {
-
-
- $tree_parameters = $cache->data;
- }
-
- if (!isset($tree_parameters)) {
- $tree_parameters = array(
- 'min_depth' => 1,
- 'max_depth' => $max_depth,
- );
- if ($mlid) {
-
-
- $parents = array(0);
- for ($i = 1; $i < MENU_MAX_DEPTH; $i++) {
- if (!empty($link["p$i"])) {
- $parents[] = $link["p$i"];
- }
- }
- $tree_parameters['expanded'] = $parents;
- $tree_parameters['active_trail'] = $parents;
- $tree_parameters['active_trail'][] = $mlid;
- }
-
- cache_set($cid, $tree_parameters, 'cache_menu');
- }
-
-
- $tree[$cid] = menu_build_tree($menu_name, $tree_parameters);
- }
- return $tree[$cid];
- }
- function menu_tree_set_path($menu_name, $path = NULL) {
- $paths = &drupal_static(__FUNCTION__);
- if (isset($path)) {
- $paths[$menu_name] = $path;
- }
- return isset($paths[$menu_name]) ? $paths[$menu_name] : NULL;
- }
- function menu_tree_get_path($menu_name) {
- return menu_tree_set_path($menu_name);
- }
- function menu_tree_page_data($menu_name, $max_depth = NULL, $only_active_trail = FALSE) {
- $tree = &drupal_static(__FUNCTION__, array());
-
- $active_path = menu_tree_get_path($menu_name);
-
- if ($item = menu_get_item($active_path)) {
- if (isset($max_depth)) {
- $max_depth = min($max_depth, MENU_MAX_DEPTH);
- }
-
- $cid = 'links:' . $menu_name . ':page:' . $item['href'] . ':' . $GLOBALS['language']->language . ':' . (int) $item['access'] . ':' . (int) $max_depth;
-
-
-
-
-
-
-
-
- if (!isset($tree[$cid]) && $only_active_trail) {
- $cid .= ':trail';
- }
- if (!isset($tree[$cid])) {
-
- $cache = cache_get($cid, 'cache_menu');
- if ($cache && isset($cache->data)) {
-
-
- $tree_parameters = $cache->data;
- }
-
- if (!isset($tree_parameters)) {
- $tree_parameters = array(
- 'min_depth' => 1,
- 'max_depth' => $max_depth,
- );
-
-
- $active_trail = array(0 => 0);
-
-
- if ($item['access']) {
-
-
- if ($active_link = menu_link_get_preferred($active_path, $menu_name)) {
-
-
-
-
- if ($active_link['menu_name'] == $menu_name) {
-
-
- for ($i = 1; $i < MENU_MAX_DEPTH; $i++) {
- if ($active_link['p' . $i]) {
- $active_trail[$active_link['p' . $i]] = $active_link['p' . $i];
- }
- }
-
-
- if ($only_active_trail) {
- $tree_parameters['only_active_trail'] = TRUE;
- }
- }
- }
- $parents = $active_trail;
- $expanded = variable_get('menu_expanded', array());
-
- if (!$only_active_trail && in_array($menu_name, $expanded)) {
-
-
- do {
- $result = db_select('menu_links', NULL, array('fetch' => PDO::FETCH_ASSOC))
- ->fields('menu_links', array('mlid'))
- ->condition('menu_name', $menu_name)
- ->condition('expanded', 1)
- ->condition('has_children', 1)
- ->condition('plid', $parents, 'IN')
- ->condition('mlid', $parents, 'NOT IN')
- ->execute();
- $num_rows = FALSE;
- foreach ($result as $item) {
- $parents[$item['mlid']] = $item['mlid'];
- $num_rows = TRUE;
- }
- } while ($num_rows);
- }
- $tree_parameters['expanded'] = $parents;
- $tree_parameters['active_trail'] = $active_trail;
- }
-
- else {
- $tree_parameters['expanded'] = $active_trail;
- $tree_parameters['active_trail'] = $active_trail;
- }
-
- cache_set($cid, $tree_parameters, 'cache_menu');
- }
-
-
- $tree[$cid] = menu_build_tree($menu_name, $tree_parameters);
- }
- return $tree[$cid];
- }
- return array();
- }
- function menu_build_tree($menu_name, array $parameters = array()) {
-
- $data = _menu_build_tree($menu_name, $parameters);
-
- menu_tree_check_access($data['tree'], $data['node_links']);
- return $data['tree'];
- }
- function _menu_build_tree($menu_name, array $parameters = array()) {
-
- $trees = &drupal_static(__FUNCTION__, array());
-
-
- if (isset($parameters['expanded'])) {
- sort($parameters['expanded']);
- }
- $tree_cid = 'links:' . $menu_name . ':tree-data:' . $GLOBALS['language']->language . ':' . hash('sha256', serialize($parameters));
-
- if (!isset($trees[$tree_cid])) {
- $cache = cache_get($tree_cid, 'cache_menu');
- if ($cache && isset($cache->data)) {
- $trees[$tree_cid] = $cache->data;
- }
- }
- if (!isset($trees[$tree_cid])) {
-
-
-
- $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));
- $query->addTag('translatable');
- $query->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
- $query->fields('ml');
- $query->fields('m', array(
- 'load_functions',
- 'to_arg_functions',
- 'access_callback',
- 'access_arguments',
- 'page_callback',
- 'page_arguments',
- 'delivery_callback',
- 'tab_parent',
- 'tab_root',
- 'title',
- 'title_callback',
- 'title_arguments',
- 'theme_callback',
- 'theme_arguments',
- 'type',
- 'description',
- ));
- for ($i = 1; $i <= MENU_MAX_DEPTH; $i++) {
- $query->orderBy('p' . $i, 'ASC');
- }
- $query->condition('ml.menu_name', $menu_name);
- if (!empty($parameters['expanded'])) {
- $query->condition('ml.plid', $parameters['expanded'], 'IN');
- }
- elseif (!empty($parameters['only_active_trail'])) {
- $query->condition('ml.mlid', $parameters['active_trail'], 'IN');
- }
- $min_depth = (isset($parameters['min_depth']) ? $parameters['min_depth'] : 1);
- if ($min_depth != 1) {
- $query->condition('ml.depth', $min_depth, '>=');
- }
- if (isset($parameters['max_depth'])) {
- $query->condition('ml.depth', $parameters['max_depth'], '<=');
- }
-
- if (isset($parameters['conditions'])) {
- foreach ($parameters['conditions'] as $column => $value) {
- $query->condition($column, $value);
- }
- }
-
- $links = array();
- foreach ($query->execute() as $item) {
- $links[] = $item;
- }
- $active_trail = (isset($parameters['active_trail']) ? $parameters['active_trail'] : array());
- $data['tree'] = menu_tree_data($links, $active_trail, $min_depth);
- $data['node_links'] = array();
- menu_tree_collect_node_links($data['tree'], $data['node_links']);
-
- cache_set($tree_cid, $data, 'cache_menu');
- $trees[$tree_cid] = $data;
- }
- return $trees[$tree_cid];
- }
- function menu_tree_collect_node_links(&$tree, &$node_links) {
- foreach ($tree as $key => $v) {
- if ($tree[$key]['link']['router_path'] == 'node/%') {
- $nid = substr($tree[$key]['link']['link_path'], 5);
- if (is_numeric($nid)) {
- $node_links[$nid][$tree[$key]['link']['mlid']] = &$tree[$key]['link'];
- $tree[$key]['link']['access'] = FALSE;
- }
- }
- if ($tree[$key]['below']) {
- menu_tree_collect_node_links($tree[$key]['below'], $node_links);
- }
- }
- }
- function menu_tree_check_access(&$tree, $node_links = array()) {
- if ($node_links) {
- $nids = array_keys($node_links);
- $select = db_select('node', 'n');
- $select->addField('n', 'nid');
- $select->condition('n.status', 1);
- $select->condition('n.nid', $nids, 'IN');
- $select->addTag('node_access');
- $nids = $select->execute()->fetchCol();
- foreach ($nids as $nid) {
- foreach ($node_links[$nid] as $mlid => $link) {
- $node_links[$nid][$mlid]['access'] = TRUE;
- }
- }
- }
- _menu_tree_check_access($tree);
- }
- function _menu_tree_check_access(&$tree) {
- $new_tree = array();
- foreach ($tree as $key => $v) {
- $item = &$tree[$key]['link'];
- _menu_link_translate($item);
- if ($item['access'] || ($item['in_active_trail'] && strpos($item['href'], '%') !== FALSE)) {
- if ($tree[$key]['below']) {
- _menu_tree_check_access($tree[$key]['below']);
- }
-
-
-
- $new_tree[(50000 + $item['weight']) . ' ' . $item['title'] . ' ' . $item['mlid']] = $tree[$key];
- }
- }
-
- ksort($new_tree);
- $tree = $new_tree;
- }
- function menu_tree_data(array $links, array $parents = array(), $depth = 1) {
-
- $links = array_reverse($links);
- return _menu_tree_data($links, $parents, $depth);
- }
- function _menu_tree_data(&$links, $parents, $depth) {
- $tree = array();
- while ($item = array_pop($links)) {
-
-
- $item['in_active_trail'] = in_array($item['mlid'], $parents);
-
- $tree[$item['mlid']] = array(
- 'link' => $item,
- 'below' => array(),
- );
-
-
- $next = end($links);
-
- if ($next && $next['depth'] > $depth) {
-
- $tree[$item['mlid']]['below'] = _menu_tree_data($links, $parents, $next['depth']);
-
- $next = end($links);
- }
-
- if (!$next || $next['depth'] < $depth) {
- break;
- }
- }
- return $tree;
- }
- function template_preprocess_menu_tree(&$variables) {
- $variables['tree'] = $variables['tree']['#children'];
- }
- function theme_menu_tree($variables) {
- return '<ul class="menu">' . $variables['tree'] . '</ul>';
- }
- function theme_menu_link(array $variables) {
- $element = $variables['element'];
- $sub_menu = '';
- if ($element['#below']) {
- $sub_menu = drupal_render($element['#below']);
- }
- $output = l($element['#title'], $element['#href'], $element['#localized_options']);
- return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
- }
- function theme_menu_local_task($variables) {
- $link = $variables['element']['#link'];
- $link_text = $link['title'];
- if (!empty($variables['element']['#active'])) {
-
- $active = '<span class="element-invisible">' . t('(active tab)') . '</span>';
-
-
- if (empty($link['localized_options']['html'])) {
- $link['title'] = check_plain($link['title']);
- }
- $link['localized_options']['html'] = TRUE;
- $link_text = t('!local-task-title!active', array('!local-task-title' => $link['title'], '!active' => $active));
- }
- return '<li' . (!empty($variables['element']['#active']) ? ' class="active"' : '') . '>' . l($link_text, $link['href'], $link['localized_options']) . "</li>\n";
- }
- function theme_menu_local_action($variables) {
- $link = $variables['element']['#link'];
- $output = '<li>';
- if (isset($link['href'])) {
- $output .= l($link['title'], $link['href'], isset($link['localized_options']) ? $link['localized_options'] : array());
- }
- elseif (!empty($link['localized_options']['html'])) {
- $output .= $link['title'];
- }
- else {
- $output .= check_plain($link['title']);
- }
- $output .= "</li>\n";
- return $output;
- }
- function drupal_help_arg($arg = array()) {
-
- return $arg + array('', '', '', '', '', '', '', '', '', '', '', '');
- }
- function menu_get_active_help() {
- $output = '';
- $router_path = menu_tab_root_path();
-
- if (!$router_path) {
- return '';
- }
- $arg = drupal_help_arg(arg(NULL));
- foreach (module_implements('help') as $module) {
- $function = $module . '_help';
-
- if ($help = $function($router_path, $arg)) {
- $output .= $help . "\n";
- }
- }
- return $output;
- }
- function menu_get_custom_theme($initialize = FALSE) {
- $custom_theme = &drupal_static(__FUNCTION__);
-
-
- if ($initialize && !_menu_site_is_offline(TRUE) && (!defined('MAINTENANCE_MODE') || (MAINTENANCE_MODE != 'update' && MAINTENANCE_MODE != 'install'))) {
-
-
-
- $custom_themes = array_filter(module_invoke_all('custom_theme'), 'drupal_theme_access');
- if (!empty($custom_themes)) {
- $custom_theme = array_pop($custom_themes);
- }
-
-
-
- $router_item = menu_get_item();
- if (!empty($router_item['access']) && !empty($router_item['theme_callback']) && function_exists($router_item['theme_callback'])) {
- $theme_name = call_user_func_array($router_item['theme_callback'], $router_item['theme_arguments']);
- if (drupal_theme_access($theme_name)) {
- $custom_theme = $theme_name;
- }
- }
- }
- return $custom_theme;
- }
- function menu_set_custom_theme() {
- menu_get_custom_theme(TRUE);
- }
- function menu_get_names() {
- $names = &drupal_static(__FUNCTION__);
- if (empty($names)) {
- $names = db_select('menu_links')
- ->distinct()
- ->fields('menu_links', array('menu_name'))
- ->orderBy('menu_name')
- ->execute()->fetchCol();
- }
- return $names;
- }
- function menu_list_system_menus() {
- return array(
- 'navigation' => 'Navigation',
- 'management' => 'Management',
- 'user-menu' => 'User menu',
- 'main-menu' => 'Main menu',
- );
- }
- function menu_main_menu() {
- return menu_navigation_links(variable_get('menu_main_links_source', 'main-menu'));
- }
- function menu_secondary_menu() {
-
-
- if (variable_get('menu_secondary_links_source', 'user-menu') == variable_get('menu_main_links_source', 'main-menu')) {
- return menu_navigation_links(variable_get('menu_main_links_source', 'main-menu'), 1);
- }
- else {
- return menu_navigation_links(variable_get('menu_secondary_links_source', 'user-menu'), 0);
- }
- }
- function menu_navigation_links($menu_name, $level = 0) {
-
- if (empty($menu_name)) {
- return array();
- }
-
- $tree = menu_tree_page_data($menu_name, $level + 1);
-
- while ($level-- > 0 && $tree) {
-
- while ($item = array_shift($tree)) {
- if ($item['link']['in_active_trail']) {
-
- $tree = empty($item['below']) ? array() : $item['below'];
- break;
- }
- }
- }
-
- $router_item = menu_get_item();
- $links = array();
- foreach ($tree as $item) {
- if (!$item['link']['hidden']) {
- $class = '';
- $l = $item['link']['localized_options'];
- $l['href'] = $item['link']['href'];
- $l['title'] = $item['link']['title'];
- if ($item['link']['in_active_trail']) {
- $class = ' active-trail';
- $l['attributes']['class'][] = 'active-trail';
- }
-
-
-
-
- if ($item['link']['href'] == $router_item['tab_root_href'] && $item['link']['href'] != $_GET['q']) {
- $l['attributes']['class'][] = 'active';
- }
-
- $links['menu-' . $item['link']['mlid'] . $class] = $l;
- }
- }
- return $links;
- }
- function menu_local_tasks($level = 0) {
- $data = &drupal_static(__FUNCTION__);
- $root_path = &drupal_static(__FUNCTION__ . ':root_path', '');
- $empty = array(
- 'tabs' => array('count' => 0, 'output' => array()),
- 'actions' => array('count' => 0, 'output' => array()),
- 'root_path' => &$root_path,
- );
- if (!isset($data)) {
- $data = array();
-
- $actions = $empty['actions'];
- $tabs = array();
- $router_item = menu_get_item();
-
-
- if ($router_item && ($router_item['type'] & MENU_LINKS_TO_PARENT)) {
- $router_item = menu_get_item($router_item['tab_parent_href']);
- }
-
-
- if (!$router_item || !$router_item['access']) {
- return $empty;
- }
-
- $cid = 'local_tasks:' . $router_item['tab_root'];
- if ($cache = cache_get($cid, 'cache_menu')) {
- $result = $cache->data;
- }
- else {
- $result = db_select('menu_router', NULL, array('fetch' => PDO::FETCH_ASSOC))
- ->fields('menu_router')
- ->condition('tab_root', $router_item['tab_root'])
- ->condition('context', MENU_CONTEXT_INLINE, '<>')
- ->orderBy('weight')
- ->orderBy('title')
- ->execute()
- ->fetchAll();
- cache_set($cid, $result, 'cache_menu');
- }
- $map = $router_item['original_map'];
- $children = array();
- $tasks = array();
- $root_path = $router_item['path'];
- foreach ($result as $item) {
- _menu_translate($item, $map, TRUE);
- if ($item['tab_parent']) {
-
- $children[$item['tab_parent']][$item['path']] = $item;
- }
-
- $tasks[$item['path']] = $item;
- }
-
- $path = $router_item['path'];
-
-
- $depth = 1001;
- $actions['count'] = 0;
- $actions['output'] = array();
- while (isset($children[$path])) {
- $tabs_current = array();
- $actions_current = array();
- $next_path = '';
- $tab_count = 0;
- $action_count = 0;
- foreach ($children[$path] as $item) {
-
-
- if (!($item['type'] & MENU_IS_LOCAL_TASK)) {
-
- continue;
- }
- if ($item['access']) {
- $link = $item;
-
-
- if (($item['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT) {
-
- for ($p = $item['tab_parent']; ($tasks[$p]['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT; $p = $tasks[$p]['tab_parent']);
-
- $link['href'] = $tasks[$p]['href'];
-
-
-
-
-
-
-
- if ($link['href'] != $_GET['q']) {
- $link['localized_options']['attributes']['class'][] = 'active';
- }
- $tabs_current[] = array(
- '#theme' => 'menu_local_task',
- '#link' => $link,
- '#active' => TRUE,
- );
- $next_path = $item['path'];
- $tab_count++;
- }
- else {
-
-
- if (($item['type'] & MENU_IS_LOCAL_ACTION) == MENU_IS_LOCAL_ACTION) {
-
- $actions_current[] = array(
- '#theme' => 'menu_local_action',
- '#link' => $link,
- );
- $action_count++;
- }
- else {
-
- $tabs_current[] = array(
- '#theme' => 'menu_local_task',
- '#link' => $link,
- );
- $tab_count++;
- }
- }
- }
- }
- $path = $next_path;
- $tabs[$depth]['count'] = $tab_count;
- $tabs[$depth]['output'] = $tabs_current;
- $actions['count'] += $action_count;
- $actions['output'] = array_merge($actions['output'], $actions_current);
- $depth++;
- }
- $data['actions'] = $actions;
-
- $parent = $router_item['tab_parent'];
- $path = $router_item['path'];
- $current = $router_item;
- $depth = 1000;
- while (isset($children[$parent])) {
- $tabs_current = array();
- $next_path = '';
- $next_parent = '';
- $count = 0;
- foreach ($children[$parent] as $item) {
-
- if ($item['type'] & MENU_IS_LOCAL_ACTION) {
- continue;
- }
- if ($item['access']) {
- $count++;
- $link = $item;
-
-
- if (($item['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT) {
-
- for ($p = $item['tab_parent']; ($tasks[$p]['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT; $p = $tasks[$p]['tab_parent']);
-
- $link['href'] = $tasks[$p]['href'];
- if ($item['path'] == $router_item['path']) {
- $root_path = $tasks[$p]['path'];
- }
- }
-
- if ($item['path'] == $path) {
-
-
-
-
- if ($link['href'] != $_GET['q']) {
- $link['localized_options']['attributes']['class'][] = 'active';
- }
- $tabs_current[] = array(
- '#theme' => 'menu_local_task',
- '#link' => $link,
- '#active' => TRUE,
- );
- $next_path = $item['tab_parent'];
- if (isset($tasks[$next_path])) {
- $next_parent = $tasks[$next_path]['tab_parent'];
- }
- }
- else {
- $tabs_current[] = array(
- '#theme' => 'menu_local_task',
- '#link' => $link,
- );
- }
- }
- }
- $path = $next_path;
- $parent = $next_parent;
- $tabs[$depth]['count'] = $count;
- $tabs[$depth]['output'] = $tabs_current;
- $depth--;
- }
-
- ksort($tabs);
-
- $tabs = array_values($tabs);
- $data['tabs'] = $tabs;
-
- drupal_alter('menu_local_tasks', $data, $router_item, $root_path);
- }
- if (isset($data['tabs'][$level])) {
- return array(
- 'tabs' => $data['tabs'][$level],
- 'actions' => $data['actions'],
- 'root_path' => $root_path,
- );
- }
-
-
- elseif (!empty($data['actions']['output'])) {
- return array('actions' => $data['actions']) + $empty;
- }
- return $empty;
- }
- function menu_contextual_links($module, $parent_path, $args) {
- static $path_empty = array();
- $links = array();
-
-
- if (isset($path_empty[$parent_path]) && strpos($parent_path, '%') !== FALSE) {
- return $links;
- }
-
- $path = $parent_path . '/' . implode('/', $args);
-
- $router_item = menu_get_item($path);
- if (!$router_item || !$router_item['access']) {
- $path_empty[$parent_path] = TRUE;
- return $links;
- }
- $data = &drupal_static(__FUNCTION__, array());
- $root_path = $router_item['path'];
-
-
- if (!isset($data[$root_path])) {
-
-
- $data[$root_path] = db_select('menu_router', 'm')
- ->fields('m')
- ->condition('tab_parent', $router_item['tab_root'])
- ->condition('context', MENU_CONTEXT_NONE, '<>')
- ->condition('context', MENU_CONTEXT_PAGE, '<>')
- ->orderBy('weight')
- ->orderBy('title')
- ->execute()
- ->fetchAllAssoc('path', PDO::FETCH_ASSOC);
- }
- $parent_length = drupal_strlen($root_path) + 1;
- $map = $router_item['original_map'];
- foreach ($data[$root_path] as $item) {
-
- $key = drupal_substr($item['path'], $parent_length);
-
- _menu_translate($item, $map, TRUE);
- if (!$item['access']) {
- continue;
- }
-
-
- $links[$module . '-' . $key] = $item;
- }
-
- drupal_alter('menu_contextual_links', $links, $router_item, $root_path);
-
-
-
- if (empty($links)) {
- $path_empty[$parent_path] = TRUE;
- }
- return $links;
- }
- function menu_primary_local_tasks() {
- $links = menu_local_tasks(0);
-
- return ($links['tabs']['count'] > 1 ? $links['tabs']['output'] : '');
- }
- function menu_secondary_local_tasks() {
- $links = menu_local_tasks(1);
-
- return ($links['tabs']['count'] > 1 ? $links['tabs']['output'] : '');
- }
- function menu_local_actions() {
- $links = menu_local_tasks();
- return $links['actions']['output'];
- }
- function menu_tab_root_path() {
- $links = menu_local_tasks();
- return $links['root_path'];
- }
- function menu_local_tabs() {
- return array(
- '#theme' => 'menu_local_tasks',
- '#primary' => menu_primary_local_tasks(),
- '#secondary' => menu_secondary_local_tasks(),
- );
- }
- function theme_menu_local_tasks(&$variables) {
- $output = '';
- if (!empty($variables['primary'])) {
- $variables['primary']['#prefix'] = '<h2 class="element-invisible">' . t('Primary tabs') . '</h2>';
- $variables['primary']['#prefix'] .= '<ul class="tabs primary">';
- $variables['primary']['#suffix'] = '</ul>';
- $output .= drupal_render($variables['primary']);
- }
- if (!empty($variables['secondary'])) {
- $variables['secondary']['#prefix'] = '<h2 class="element-invisible">' . t('Secondary tabs') . '</h2>';
- $variables['secondary']['#prefix'] .= '<ul class="tabs secondary">';
- $variables['secondary']['#suffix'] = '</ul>';
- $output .= drupal_render($variables['secondary']);
- }
- return $output;
- }
- function menu_set_active_menu_names($menu_names = NULL) {
- $active = &drupal_static(__FUNCTION__);
- if (isset($menu_names) && is_array($menu_names)) {
- $active = $menu_names;
- }
- elseif (!isset($active)) {
- $active = variable_get('menu_default_active_menus', array_keys(menu_list_system_menus()));
- }
- return $active;
- }
- function menu_get_active_menu_names() {
- return menu_set_active_menu_names();
- }
- function menu_set_active_item($path) {
- $_GET['q'] = $path;
-
-
- drupal_static_reset('menu_set_active_trail');
- }
- function menu_set_active_trail($new_trail = NULL) {
- $trail = &drupal_static(__FUNCTION__);
- if (isset($new_trail)) {
- $trail = $new_trail;
- }
- elseif (!isset($trail)) {
- $trail = array();
- $trail[] = array(
- 'title' => t('Home'),
- 'href' => '<front>',
- 'link_path' => '',
- 'localized_options' => array(),
- 'type' => 0,
- );
-
-
- $preferred_link = menu_link_get_preferred();
- $current_item = menu_get_item();
-
- if ($preferred_link) {
-
-
-
- $tree = menu_tree_page_data($preferred_link['menu_name'], NULL, TRUE);
- list($key, $curr) = each($tree);
- }
-
- else {
- $preferred_link = $current_item;
- $curr = FALSE;
- }
- while ($curr) {
- $link = $curr['link'];
- if ($link['in_active_trail']) {
-
- if (!($link['type'] & MENU_LINKS_TO_PARENT)) {
-
-
-
-
-
-
-
-
- if (strpos($link['href'], '%') !== FALSE) {
- _menu_link_translate($link, TRUE);
- }
- if ($link['access']) {
- $trail[] = $link;
- }
- }
- $tree = $curr['below'] ? $curr['below'] : array();
- }
- list($key, $curr) = each($tree);
- }
-
-
-
- $last = end($trail);
- if ($preferred_link && $last['href'] != $preferred_link['href'] && !drupal_is_front_page()) {
- $trail[] = $preferred_link;
- }
- }
- return $trail;
- }
- function menu_link_get_preferred($path = NULL, $selected_menu = NULL) {
- $preferred_links = &drupal_static(__FUNCTION__);
- if (!isset($path)) {
- $path = $_GET['q'];
- }
- if (empty($selected_menu)) {
-
- $selected_menu = MENU_PREFERRED_LINK;
- }
- if (!isset($preferred_links[$path])) {
-
-
-
-
- $item = menu_get_item($path);
- $path_candidates = array();
-
- $path_candidates[$item['href']] = $item['href'];
-
- if ($item['tab_parent'] && ($tab_root = menu_get_item($item['tab_root_href']))) {
- $path_candidates[$tab_root['href']] = $tab_root['href'];
- }
-
- $path_candidates[$item['path']] = $item['path'];
-
- if (!empty($tab_root)) {
- $path_candidates[$tab_root['path']] = $tab_root['path'];
- }
-
- $menu_names = menu_get_active_menu_names();
-
- array_unshift($menu_names, $selected_menu);
- $query = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC));
- $query->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
- $query->fields('ml');
-
- $query->addField('ml', 'weight', 'link_weight');
- $query->fields('m');
- $query->condition('ml.link_path', $path_candidates, 'IN');
- $query->addTag('preferred_menu_links');
-
- $candidates = array();
- foreach ($query->execute() as $candidate) {
- $candidate['weight'] = $candidate['link_weight'];
- $candidates[$candidate['link_path']][$candidate['menu_name']] = $candidate;
-
- if (!in_array($candidate['menu_name'], $menu_names)) {
- $menu_names[] = $candidate['menu_name'];
- }
- }
-
-
- foreach ($path_candidates as $link_path) {
- if (isset($candidates[$link_path])) {
- foreach ($menu_names as $menu_name) {
- if (empty($preferred_links[$path][$menu_name]) && isset($candidates[$link_path][$menu_name])) {
- $candidate_item = $candidates[$link_path][$menu_name];
- $map = explode('/', $path);
- _menu_translate($candidate_item, $map);
- if ($candidate_item['access']) {
- $preferred_links[$path][$menu_name] = $candidate_item;
- if (empty($preferred_links[$path][MENU_PREFERRED_LINK])) {
-
- $preferred_links[$path][MENU_PREFERRED_LINK] = $candidate_item;
- }
- }
- }
- }
- }
- }
- }
- return isset($preferred_links[$path][$selected_menu]) ? $preferred_links[$path][$selected_menu] : FALSE;
- }
- function menu_get_active_trail() {
- return menu_set_active_trail();
- }
- function menu_get_active_breadcrumb() {
- $breadcrumb = array();
-
- if (drupal_is_front_page()) {
- return $breadcrumb;
- }
- $item = menu_get_item();
- if (!empty($item['access'])) {
- $active_trail = menu_get_active_trail();
-
-
- drupal_alter('menu_breadcrumb', $active_trail, $item);
-
- $end = end($active_trail);
- if ($item['href'] == $end['href']) {
- array_pop($active_trail);
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
- if (($item['type'] & MENU_LINKS_TO_PARENT) == MENU_LINKS_TO_PARENT) {
- array_pop($active_trail);
- }
- foreach ($active_trail as $parent) {
- $breadcrumb[] = l($parent['title'], $parent['href'], $parent['localized_options']);
- }
- }
- return $breadcrumb;
- }
- function menu_get_active_title() {
- $active_trail = menu_get_active_trail();
- foreach (array_reverse($active_trail) as $item) {
- if (!(bool) ($item['type'] & MENU_IS_LOCAL_TASK)) {
- return $item['title'];
- }
- }
- }
- function menu_link_load($mlid) {
- if (is_numeric($mlid)) {
- $query = db_select('menu_links', 'ml');
- $query->leftJoin('menu_router', 'm', 'm.path = ml.router_path');
- $query->fields('ml');
-
- $query->addField('ml', 'weight', 'link_weight');
- $query->fields('m');
- $query->condition('ml.mlid', $mlid);
- if ($item = $query->execute()->fetchAssoc()) {
- $item['weight'] = $item['link_weight'];
- _menu_link_translate($item);
- return $item;
- }
- }
- return FALSE;
- }
- function menu_cache_clear($menu_name = 'navigation') {
- $cache_cleared = &drupal_static(__FUNCTION__, array());
- if (empty($cache_cleared[$menu_name])) {
- cache_clear_all('links:' . $menu_name . ':', 'cache_menu', TRUE);
- $cache_cleared[$menu_name] = 1;
- }
- elseif ($cache_cleared[$menu_name] == 1) {
- drupal_register_shutdown_function('cache_clear_all', 'links:' . $menu_name . ':', 'cache_menu', TRUE);
- $cache_cleared[$menu_name] = 2;
- }
-
- menu_reset_static_cache();
- }
- function menu_cache_clear_all() {
- cache_clear_all('*', 'cache_menu', TRUE);
- menu_reset_static_cache();
- }
- function menu_reset_static_cache() {
- drupal_static_reset('_menu_build_tree');
- drupal_static_reset('menu_tree');
- drupal_static_reset('menu_tree_all_data');
- drupal_static_reset('menu_tree_page_data');
- drupal_static_reset('menu_load_all');
- drupal_static_reset('menu_link_get_preferred');
- }
- function _menu_check_rebuild() {
-
-
- $variables = variable_initialize();
- if (empty($variables['menu_rebuild_needed']) && !empty($variables['menu_masks'])) {
- unset($GLOBALS['conf']['menu_rebuild_needed']);
- $GLOBALS['conf']['menu_masks'] = $variables['menu_masks'];
- return FALSE;
- }
- return TRUE;
- }
- function menu_rebuild() {
- if (!lock_acquire('menu_rebuild')) {
-
-
-
- lock_wait('menu_rebuild');
- if (_menu_check_rebuild()) {
-
-
-
-
- return menu_rebuild();
- }
- return FALSE;
- }
- $transaction = db_transaction();
- try {
- list($menu, $masks) = menu_router_build();
- _menu_router_save($menu, $masks);
- _menu_navigation_links_rebuild($menu);
-
- menu_cache_clear_all();
- _menu_clear_page_cache();
- if (defined('MAINTENANCE_MODE')) {
- variable_set('menu_rebuild_needed', TRUE);
- }
- else {
- variable_del('menu_rebuild_needed');
- }
- }
- catch (Exception $e) {
- $transaction->rollback();
- watchdog_exception('menu', $e);
- }
-
-
-
-
-
- unset($transaction);
- lock_release('menu_rebuild');
- return TRUE;
- }
- function menu_router_build() {
-
-
- $callbacks = array();
- foreach (module_implements('menu') as $module) {
- $router_items = call_user_func($module . '_menu');
- if (isset($router_items) && is_array($router_items)) {
- foreach (array_keys($router_items) as $path) {
- $router_items[$path]['module'] = $module;
- }
- $callbacks = array_merge($callbacks, $router_items);
- }
- }
-
- drupal_alter('menu', $callbacks);
- list($menu, $masks) = _menu_router_build($callbacks);
- _menu_router_cache($menu);
- return array($menu, $masks);
- }
- function _menu_router_cache($new_menu = NULL) {
- $menu = &drupal_static(__FUNCTION__);
- if (isset($new_menu)) {
- $menu = $new_menu;
- }
- return $menu;
- }
- function menu_get_router() {
-
- $menu = _menu_router_cache();
- if (empty($menu)) {
- list($menu, $masks) = menu_router_build();
- }
- return $menu;
- }
- function _menu_link_build($item) {
-
- if ($item['type'] == MENU_SUGGESTED_ITEM) {
- $item['hidden'] = 1;
- }
-
- elseif (!($item['type'] & MENU_VISIBLE_IN_TREE)) {
- $item['hidden'] = -1;
- }
-
-
- $item['module'] = 'system';
- $item += array(
- 'menu_name' => 'navigation',
- 'link_title' => $item['title'],
- 'link_path' => $item['path'],
- 'hidden' => 0,
- 'options' => empty($item['description']) ? array() : array('attributes' => array('title' => $item['description'])),
- );
- return $item;
- }
- function _menu_navigation_links_rebuild($menu) {
-
- $menu_links = array();
- foreach ($menu as $path => $item) {
- if ($item['_visible']) {
- $menu_links[$path] = $item;
- $sort[$path] = $item['_number_parts'];
- }
- }
- if ($menu_links) {
-
-
- $parent_candidates = array();
-
- array_multisort($sort, SORT_NUMERIC, $menu_links);
- foreach ($menu_links as $key => $item) {
- $existing_item = db_select('menu_links')
- ->fields('menu_links')
- ->condition('link_path', $item['path'])
- ->condition('module', 'system')
- ->execute()->fetchAssoc();
- if ($existing_item) {
- $item['mlid'] = $existing_item['mlid'];
-
- if (empty($item['menu_name']) || ($item['menu_name'] == $existing_item['menu_name'])) {
- $item['menu_name'] = $existing_item['menu_name'];
- $item['plid'] = $existing_item['plid'];
- }
- else {
-
-
- unset($item['plid']);
- }
- $item['has_children'] = $existing_item['has_children'];
- $item['updated'] = $existing_item['updated'];
- }
- if ($existing_item && $existing_item['customized']) {
- $parent_candidates[$existing_item['mlid']] = $existing_item;
- }
- else {
- $item = _menu_link_build($item);
- menu_link_save($item, $existing_item, $parent_candidates);
- $parent_candidates[$item['mlid']] = $item;
- unset($menu_links[$key]);
- }
- }
- }
- $paths = array_keys($menu);
-
- $result = db_select('menu_links', NULL, array('fetch' => PDO::FETCH_ASSOC))
- ->fields('menu_links', array(
- 'link_path',
- 'mlid',
- 'router_path',
- 'updated',
- ))
- ->condition(db_or()
- ->condition('updated', 1)
- ->condition(db_and()
- ->condition('router_path', $paths, 'NOT IN')
- ->condition('external', 0)
- ->condition('customized', 1)
- )
- )
- ->execute();
- foreach ($result as $item) {
- $router_path = _menu_find_router_path($item['link_path']);
- if (!empty($router_path) && ($router_path != $item['router_path'] || $item['updated'])) {
-
-
- $updated = $item['updated'] && $router_path != $item['link_path'];
- db_update('menu_links')
- ->fields(array(
- 'router_path' => $router_path,
- 'updated' => (int) $updated,
- ))
- ->condition('mlid', $item['mlid'])
- ->execute();
- }
- }
-
- $result = db_select('menu_links')
- ->fields('menu_links')
- ->condition('router_path', $paths, 'NOT IN')
- ->condition('external', 0)
- ->condition('updated', 0)
- ->condition('customized', 0)
- ->orderBy('depth', 'DESC')
- ->execute();
-
-
- foreach ($result as $item) {
- _menu_delete_item($item, TRUE);
- }
- }
- function menu_links_clone($links, $menu_name = NULL) {
- foreach ($links as &$link) {
- unset($link['mlid']);
- unset($link['plid']);
- if (isset($menu_name)) {
- $link['menu_name'] = $menu_name;
- }
- }
- return $links;
- }
- function menu_load_links($menu_name) {
- $links = db_select('menu_links', 'ml', array('fetch' => PDO::FETCH_ASSOC))
- ->fields('ml')
- ->condition('ml.menu_name', $menu_name)
-
-
- ->orderBy('weight')
- ->execute()
- ->fetchAll();
- foreach ($links as &$link) {
- $link['options'] = unserialize($link['options']);
- }
- return $links;
- }
- function menu_delete_links($menu_name) {
- $links = menu_load_links($menu_name);
- foreach ($links as $link) {
-
-
-
- $link['has_children'] = FALSE;
- $link['plid'] = 0;
- _menu_delete_item($link);
- }
- }
- function menu_link_delete($mlid, $path = NULL) {
- if (isset($mlid)) {
- _menu_delete_item(db_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchAssoc());
- }
- else {
- $result = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path", array(':link_path' => $path));
- foreach ($result as $link) {
- _menu_delete_item($link);
- }
- }
- }
- function _menu_delete_item($item, $force = FALSE) {
- $item = is_object($item) ? get_object_vars($item) : $item;
- if ($item && ($item['module'] != 'system' || $item['updated'] || $force)) {
-
- if ($item['has_children']) {
- $result = db_query("SELECT mlid FROM {menu_links} WHERE plid = :plid", array(':plid' => $item['mlid']));
- foreach ($result as $m) {
- $child = menu_link_load($m->mlid);
- $child['plid'] = $item['plid'];
- menu_link_save($child);
- }
- }
-
- module_invoke_all('menu_link_delete', $item);
- db_delete('menu_links')->condition('mlid', $item['mlid'])->execute();
-
- _menu_update_parental_status($item);
- menu_cache_clear($item['menu_name']);
- _menu_clear_page_cache();
- }
- }
- function menu_link_save(&$item, $existing_item = array(), $parent_candidates = array()) {
- drupal_alter('menu_link', $item);
-
-
- $item['external'] = (url_is_external($item['link_path']) || $item['link_path'] == '<front>') ? 1 : 0;
-
- $item += array(
- 'menu_name' => 'navigation',
- 'weight' => 0,
- 'link_title' => '',
- 'hidden' => 0,
- 'has_children' => 0,
- 'expanded' => 0,
- 'options' => array(),
- 'module' => 'menu',
- 'customized' => 0,
- 'updated' => 0,
- );
- if (isset($item['mlid'])) {
- if (!$existing_item) {
- $existing_item = db_query('SELECT * FROM {menu_links} WHERE mlid = :mlid', array('mlid' => $item['mlid']))->fetchAssoc();
- }
- if ($existing_item) {
- $existing_item['options'] = unserialize($existing_item['options']);
- }
- }
- else {
- $existing_item = FALSE;
- }
-
- $parent = _menu_link_find_parent($item, $parent_candidates);
- if (!empty($parent['mlid'])) {
- $item['plid'] = $parent['mlid'];
- $item['menu_name'] = $parent['menu_name'];
- }
-
- else {
- $item['plid'] = 0;
- }
- $menu_name = $item['menu_name'];
- if (!$existing_item) {
- $item['mlid'] = db_insert('menu_links')
- ->fields(array(
- 'menu_name' => $item['menu_name'],
- 'plid' => $item['plid'],
- 'link_path' => $item['link_path'],
- 'hidden' => $item['hidden'],
- 'external' => $item['external'],
- 'has_children' => $item['has_children'],
- 'expanded' => $item['expanded'],
- 'weight' => $item['weight'],
- 'module' => $item['module'],
- 'link_title' => $item['link_title'],
- 'options' => serialize($item['options']),
- 'customized' => $item['customized'],
- 'updated' => $item['updated'],
- ))
- ->execute();
- }
-
- if ($item['plid'] == 0) {
- $item['p1'] = $item['mlid'];
- for ($i = 2; $i <= MENU_MAX_DEPTH; $i++) {
- $item["p$i"] = 0;
- }
- $item['depth'] = 1;
- }
-
-
- else {
- if ($item['has_children'] && $existing_item) {
- $limit = MENU_MAX_DEPTH - menu_link_children_relative_depth($existing_item) - 1;
- }
- else {
- $limit = MENU_MAX_DEPTH - 1;
- }
- if ($parent['depth'] > $limit) {
- return FALSE;
- }
- $item['depth'] = $parent['depth'] + 1;
- _menu_link_parents_set($item, $parent);
- }
-
- if ($existing_item && ($item['plid'] != $existing_item['plid'] || $menu_name != $existing_item['menu_name'])) {
- _menu_link_move_children($item, $existing_item);
- }
-
- if (empty($item['router_path']) || !$existing_item || ($existing_item['link_path'] != $item['link_path'])) {
- if ($item['external']) {
- $item['router_path'] = '';
- }
- else {
-
- $item['parts'] = explode('/', $item['link_path'], MENU_MAX_PARTS);
- $item['router_path'] = _menu_find_router_path($item['link_path']);
- }
- }
-
-
-
-
-
- if (!$existing_item || (array_intersect_key($item, $existing_item) != $existing_item)) {
- db_update('menu_links')
- ->fields(array(
- 'menu_name' => $item['menu_name'],
- 'plid' => $item['plid'],
- 'link_path' => $item['link_path'],
- 'router_path' => $item['router_path'],
- 'hidden' => $item['hidden'],
- 'external' => $item['external'],
- 'has_children' => $item['has_children'],
- 'expanded' => $item['expanded'],
- 'weight' => $item['weight'],
- 'depth' => $item['depth'],
- 'p1' => $item['p1'],
- 'p2' => $item['p2'],
- 'p3' => $item['p3'],
- 'p4' => $item['p4'],
- 'p5' => $item['p5'],
- 'p6' => $item['p6'],
- 'p7' => $item['p7'],
- 'p8' => $item['p8'],
- 'p9' => $item['p9'],
- 'module' => $item['module'],
- 'link_title' => $item['link_title'],
- 'options' => serialize($item['options']),
- 'customized' => $item['customized'],
- ))
- ->condition('mlid', $item['mlid'])
- ->execute();
-
- _menu_update_parental_status($item);
- menu_cache_clear($menu_name);
- if ($existing_item && $menu_name != $existing_item['menu_name']) {
- menu_cache_clear($existing_item['menu_name']);
- }
-
- $hook = 'menu_link_insert';
- if ($existing_item) {
- $hook = 'menu_link_update';
- }
- module_invoke_all($hook, $item);
-
- _menu_clear_page_cache();
- }
- return $item['mlid'];
- }
- function _menu_link_find_parent($menu_link, $parent_candidates = array()) {
- $parent = FALSE;
-
- if (isset($menu_link['plid']) && empty($menu_link['plid'])) {
- return $parent;
- }
-
- $candidates = array();
- if (isset($menu_link['plid'])) {
- $candidates[] = $menu_link['plid'];
- }
-
- if (!empty($menu_link['depth']) && $menu_link['depth'] > 1) {
- for ($depth = $menu_link['depth'] - 1; $depth >= 1; $depth--) {
- $candidates[] = $menu_link['p' . $depth];
- }
- }
- foreach ($candidates as $mlid) {
- if (isset($parent_candidates[$mlid])) {
- $parent = $parent_candidates[$mlid];
- }
- else {
- $parent = db_query("SELECT * FROM {menu_links} WHERE mlid = :mlid", array(':mlid' => $mlid))->fetchAssoc();
- }
- if ($parent) {
- return $parent;
- }
- }
-
-
-
- if ($menu_link['module'] == 'system') {
- $query = db_select('menu_links');
- $query->condition('module', 'system');
-
-
- $query->condition('menu_name', $menu_link['menu_name']);
-
- $parent_path = $menu_link['link_path'];
- do {
- $parent = FALSE;
- $parent_path = substr($parent_path, 0, strrpos($parent_path, '/'));
- $new_query = clone $query;
- $new_query->condition('link_path', $parent_path);
-
- if ($new_query->countQuery()->execute()->fetchField() == 1) {
- $parent = $new_query->fields('menu_links')->execute()->fetchAssoc();
- }
- } while ($parent === FALSE && $parent_path);
- }
- return $parent;
- }
- function _menu_clear_page_cache() {
- $cache_cleared = &drupal_static(__FUNCTION__, 0);
-
-
- if ($cache_cleared == 0) {
- cache_clear_all();
-
- _menu_set_expanded_menus();
- $cache_cleared = 1;
- }
- elseif ($cache_cleared == 1) {
- drupal_register_shutdown_function('cache_clear_all');
-
- drupal_register_shutdown_function('_menu_set_expanded_menus');
- $cache_cleared = 2;
- }
- }
- function _menu_set_expanded_menus() {
- $names = db_query("SELECT menu_name FROM {menu_links} WHERE expanded <> 0 GROUP BY menu_name")->fetchCol();
- variable_set('menu_expanded', $names);
- }
- function _menu_find_router_path($link_path) {
-
- $menu = _menu_router_cache();
- $router_path = $link_path;
- $parts = explode('/', $link_path, MENU_MAX_PARTS);
- $ancestors = menu_get_ancestors($parts);
- if (empty($menu)) {
-
- $router_path = (string) db_select('menu_router')
- ->fields('menu_router', array('path'))
- ->condition('path', $ancestors, 'IN')
- ->orderBy('fit', 'DESC')
- ->range(0, 1)
- ->execute()->fetchField();
- }
- elseif (!isset($menu[$router_path])) {
-
- $ancestors[] = '';
- foreach ($ancestors as $key => $router_path) {
- if (isset($menu[$router_path])) {
-
- break;
- }
- }
-
-
- }
- return $router_path;
- }
- function menu_link_maintain($module, $op, $link_path, $link_title) {
- switch ($op) {
- case 'insert':
- $menu_link = array(
- 'link_title' => $link_title,
- 'link_path' => $link_path,
- 'module' => $module,
- );
- return menu_link_save($menu_link);
- break;
- case 'update':
- $result = db_query("SELECT * FROM {menu_links} WHERE link_path = :link_path AND module = :module AND customized = 0", array(':link_path' => $link_path, ':module' => $module))->fetchAll(PDO::FETCH_ASSOC);
- foreach ($result as $link) {
- $link['link_title'] = $link_title;
- $link['options'] = unserialize($link['options']);
- menu_link_save($link);
- }
- break;
- case 'delete':
- menu_link_delete(NULL, $link_path);
- break;
- }
- }
- function menu_link_children_relative_depth($item) {
- $query = db_select('menu_links');
- $query->addField('menu_links', 'depth');
- $query->condition('menu_name', $item['menu_name']);
- $query->orderBy('depth', 'DESC');
- $query->range(0, 1);
- $i = 1;
- $p = 'p1';
- while ($i <= MENU_MAX_DEPTH && $item[$p]) {
- $query->condition($p, $item[$p]);
- $p = 'p' . ++$i;
- }
- $max_depth = $query->execute()->fetchField();
- return ($max_depth > $item['depth']) ? $max_depth - $item['depth'] : 0;
- }
- function _menu_link_move_children($item, $existing_item) {
- $query = db_update('menu_links');
- $query->fields(array('menu_name' => $item['menu_name']));
- $p = 'p1';
- $expressions = array();
- for ($i = 1; $i <= $item['depth']; $p = 'p' . ++$i) {
- $expressions[] = array($p, ":p_$i", array(":p_$i" => $item[$p]));
- }
- $j = $existing_item['depth'] + 1;
- while ($i <= MENU_MAX_DEPTH && $j <= MENU_MAX_DEPTH) {
- $expressions[] = array('p' . $i++, 'p' . $j++, array());
- }
- while ($i <= MENU_MAX_DEPTH) {
- $expressions[] = array('p' . $i++, 0, array());
- }
- $shift = $item['depth'] - $existing_item['depth'];
- if ($shift > 0) {
-
-
-
-
- $expressions = array_reverse($expressions);
- }
- foreach ($expressions as $expression) {
- $query->expression($expression[0], $expression[1], $expression[2]);
- }
- $query->expression('depth', 'depth + :depth', array(':depth' => $shift));
- $query->condition('menu_name', $existing_item['menu_name']);
- $p = 'p1';
- for ($i = 1; $i <= MENU_MAX_DEPTH && $existing_item[$p]; $p = 'p' . ++$i) {
- $query->condition($p, $existing_item[$p]);
- }
- $query->execute();
-
- _menu_update_parental_status($existing_item, TRUE);
- }
- function _menu_update_parental_status($item, $exclude = FALSE) {
-
- if ($item['plid']) {
-
- $query = db_select('menu_links');
- $query->addField('menu_links', 'mlid');
- $query->condition('menu_name', $item['menu_name']);
- $query->condition('hidden', 0);
- $query->condition('plid', $item['plid']);
- $query->range(0, 1);
- if ($exclude) {
- $query->condition('mlid', $item['mlid'], '<>');
- }
- $parent_has_children = ((bool) $query->execute()->fetchField()) ? 1 : 0;
- db_update('menu_links')
- ->fields(array('has_children' => $parent_has_children))
- ->condition('mlid', $item['plid'])
- ->execute();
- }
- }
- function _menu_link_parents_set(&$item, $parent) {
- $i = 1;
- while ($i < $item['depth']) {
- $p = 'p' . $i++;
- $item[$p] = $parent[$p];
- }
- $p = 'p' . $i++;
-
- $item[$p] = $item['mlid'];
- while ($i <= MENU_MAX_DEPTH) {
- $p = 'p' . $i++;
- $item[$p] = 0;
- }
- }
- function _menu_router_build($callbacks) {
-
-
- $menu = array();
- $masks = array();
- foreach ($callbacks as $path => $item) {
- $load_functions = array();
- $to_arg_functions = array();
- $fit = 0;
- $move = FALSE;
- $parts = explode('/', $path, MENU_MAX_PARTS);
- $number_parts = count($parts);
-
-
- $slashes = $number_parts - 1;
-
- foreach ($parts as $k => $part) {
- $match = FALSE;
-
-
- if (preg_match('/^%(|' . DRUPAL_PHP_FUNCTION_PATTERN . ')$/', $part, $matches)) {
- if (empty($matches[1])) {
- $match = TRUE;
- $load_functions[$k] = NULL;
- }
- else {
- if (function_exists($matches[1] . '_to_arg')) {
- $to_arg_functions[$k] = $matches[1] . '_to_arg';
- $load_functions[$k] = NULL;
- $match = TRUE;
- }
- if (function_exists($matches[1] . '_load')) {
- $function = $matches[1] . '_load';
-
-
-
- $load_functions[$k] = isset($item['load arguments']) ? array($function => $item['load arguments']) : $function;
- $match = TRUE;
- }
- }
- }
- if ($match) {
- $parts[$k] = '%';
- }
- else {
- $fit |= 1 << ($slashes - $k);
- }
- }
- if ($fit) {
- $move = TRUE;
- }
- else {
-
- $fit = (1 << $number_parts) - 1;
- }
- $masks[$fit] = 1;
- $item['_load_functions'] = $load_functions;
- $item['to_arg_functions'] = empty($to_arg_functions) ? '' : serialize($to_arg_functions);
- $item += array(
- 'title' => '',
- 'weight' => 0,
- 'type' => MENU_NORMAL_ITEM,
- 'module' => '',
- '_number_parts' => $number_parts,
- '_parts' => $parts,
- '_fit' => $fit,
- );
- $item += array(
- '_visible' => (bool) ($item['type'] & MENU_VISIBLE_IN_BREADCRUMB),
- '_tab' => (bool) ($item['type'] & MENU_IS_LOCAL_TASK),
- );
- if ($move) {
- $new_path = implode('/', $item['_parts']);
- $menu[$new_path] = $item;
- $sort[$new_path] = $number_parts;
- }
- else {
- $menu[$path] = $item;
- $sort[$path] = $number_parts;
- }
- }
- array_multisort($sort, SORT_NUMERIC, $menu);
-
- foreach ($menu as $path => $v) {
- $item = &$menu[$path];
- if (!$item['_tab']) {
-
- $item['tab_parent'] = '';
- $item['tab_root'] = $path;
- }
-
- elseif (!isset($item['context'])) {
- $item['context'] = MENU_CONTEXT_PAGE;
- }
- for ($i = $item['_number_parts'] - 1; $i; $i--) {
- $parent_path = implode('/', array_slice($item['_parts'], 0, $i));
- if (isset($menu[$parent_path])) {
- $parent = &$menu[$parent_path];
-
- if (!isset($item['menu_name'])) {
-
-
-
- if (!isset($parent['menu_name'])) {
- $menu_name = db_query("SELECT menu_name FROM {menu_links} WHERE router_path = :router_path AND module = 'system'", array(':router_path' => $parent_path))->fetchField();
- if ($menu_name) {
- $parent['menu_name'] = $menu_name;
- }
- }
-
- if (!empty($parent['menu_name'])) {
- $item['menu_name'] = $parent['menu_name'];
- }
- }
- if (!isset($item['tab_parent'])) {
-
- $item['tab_parent'] = $parent_path;
- }
- if (!isset($item['tab_root']) && !$parent['_tab']) {
- $item['tab_root'] = $parent_path;
- }
-
-
-
- if (($item['type'] == MENU_DEFAULT_LOCAL_TASK) && !isset($item['access callback']) && isset($parent['access callback'])) {
- $item['access callback'] = $parent['access callback'];
- if (!isset($item['access arguments']) && isset($parent['access arguments'])) {
- $item['access arguments'] = $parent['access arguments'];
- }
- }
-
- if (!isset($item['page callback']) && isset($parent['page callback'])) {
- $item['page callback'] = $parent['page callback'];
- if (!isset($item['page arguments']) && isset($parent['page arguments'])) {
- $item['page arguments'] = $parent['page arguments'];
- }
- if (!isset($item['file path']) && isset($parent['file path'])) {
- $item['file path'] = $parent['file path'];
- }
- if (!isset($item['file']) && isset($parent['file'])) {
- $item['file'] = $parent['file'];
- if (empty($item['file path']) && isset($item['module']) && isset($parent['module']) && $item['module'] != $parent['module']) {
- $item['file path'] = drupal_get_path('module', $parent['module']);
- }
- }
- }
-
- if (!isset($item['delivery callback']) && isset($parent['delivery callback'])) {
- $item['delivery callback'] = $parent['delivery callback'];
- }
-
- if (!isset($item['theme callback']) && isset($parent['theme callback'])) {
- $item['theme callback'] = $parent['theme callback'];
- if (!isset($item['theme arguments']) && isset($parent['theme arguments'])) {
- $item['theme arguments'] = $parent['theme arguments'];
- }
- }
-
-
- if (!isset($item['load arguments'])) {
- foreach ($item['_load_functions'] as $k => $function) {
-
- if (!is_array($function)) {
-
-
- if (isset($parent['_load_functions'][$k]) && is_array($parent['_load_functions'][$k]) && key($parent['_load_functions'][$k]) === $function) {
-
- $item['_load_functions'][$k] = $parent['_load_functions'][$k];
- }
- }
- }
- }
- }
- }
- if (!isset($item['access callback']) && isset($item['access arguments'])) {
-
- $item['access callback'] = 'user_access';
- }
- if (!isset($item['access callback']) || empty($item['page callback'])) {
- $item['access callback'] = 0;
- }
- if (is_bool($item['access callback'])) {
- $item['access callback'] = intval($item['access callback']);
- }
- $item['load_functions'] = empty($item['_load_functions']) ? '' : serialize($item['_load_functions']);
- $item += array(
- 'access arguments' => array(),
- 'access callback' => '',
- 'page arguments' => array(),
- 'page callback' => '',
- 'delivery callback' => '',
- 'title arguments' => array(),
- 'title callback' => 't',
- 'theme arguments' => array(),
- 'theme callback' => '',
- 'description' => '',
- 'position' => '',
- 'context' => 0,
- 'tab_parent' => '',
- 'tab_root' => $path,
- 'path' => $path,
- 'file' => '',
- 'file path' => '',
- 'include file' => '',
- );
-
- if ($item['file']) {
- $file_path = $item['file path'] ? $item['file path'] : drupal_get_path('module', $item['module']);
- $item['include file'] = $file_path . '/' . $item['file'];
- }
- }
-
- $masks = array_keys($masks);
- rsort($masks);
- return array($menu, $masks);
- }
- function _menu_router_save($menu, $masks) {
-
- db_truncate('menu_router')->execute();
-
- $insert = db_insert('menu_router')
- ->fields(array(
- 'path',
- 'load_functions',
- 'to_arg_functions',
- 'access_callback',
- 'access_arguments',
- 'page_callback',
- 'page_arguments',
- 'delivery_callback',
- 'fit',
- 'number_parts',
- 'context',
- 'tab_parent',
- 'tab_root',
- 'title',
- 'title_callback',
- 'title_arguments',
- 'theme_callback',
- 'theme_arguments',
- 'type',
- 'description',
- 'position',
- 'weight',
- 'include_file',
- ));
- $num_records = 0;
- foreach ($menu as $path => $item) {
-
- $insert->values(array(
- 'path' => $item['path'],
- 'load_functions' => $item['load_functions'],
- 'to_arg_functions' => $item['to_arg_functions'],
- 'access_callback' => $item['access callback'],
- 'access_arguments' => serialize($item['access arguments']),
- 'page_callback' => $item['page callback'],
- 'page_arguments' => serialize($item['page arguments']),
- 'delivery_callback' => $item['delivery callback'],
- 'fit' => $item['_fit'],
- 'number_parts' => $item['_number_parts'],
- 'context' => $item['context'],
- 'tab_parent' => $item['tab_parent'],
- 'tab_root' => $item['tab_root'],
- 'title' => $item['title'],
- 'title_callback' => $item['title callback'],
- 'title_arguments' => ($item['title arguments'] ? serialize($item['title arguments']) : ''),
- 'theme_callback' => $item['theme callback'],
- 'theme_arguments' => serialize($item['theme arguments']),
- 'type' => $item['type'],
- 'description' => $item['description'],
- 'position' => $item['position'],
- 'weight' => $item['weight'],
- 'include_file' => $item['include file'],
- ));
-
-
- if (++$num_records == 20) {
- $insert->execute();
- $num_records = 0;
- }
- }
-
- $insert->execute();
-
- variable_set('menu_masks', $masks);
- return $menu;
- }
- function _menu_site_is_offline($check_only = FALSE) {
-
- if (variable_get('maintenance_mode', 0)) {
- if (user_access('access site in maintenance mode')) {
-
-
-
- if (!$check_only && $_GET['q'] != 'admin/config/development/maintenance') {
- if (user_access('administer site configuration')) {
- drupal_set_message(t('Operating in maintenance mode. <a href="@url">Go online.</a>', array('@url' => url('admin/config/development/maintenance'))), 'status', FALSE);
- }
- else {
- drupal_set_message(t('Operating in maintenance mode.'), 'status', FALSE);
- }
- }
- }
- else {
- return TRUE;
- }
- }
- return FALSE;
- }
|