1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892 |
- <?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())) {
- 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_rebuild() {
- if (!lock_acquire('menu_rebuild')) {
-
-
-
- lock_wait('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);
- }
- 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;
- }
|