views.module 84 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606
  1. <?php
  2. /**
  3. * @file
  4. * Primarily Drupal hooks and global API functions to manipulate views.
  5. *
  6. * This is the main module file for Views. The main entry points into
  7. * this module are views_page() and views_block(), where it handles
  8. * incoming page and block requests.
  9. */
  10. /**
  11. * Implements hook_help().
  12. */
  13. function views_help($path, $arg) {
  14. switch ($path) {
  15. case 'admin/help#views':
  16. $output = '';
  17. $output .= '<h3>' . t('About') . '</h3>';
  18. $output .= '<p>' . t('The Views module provides a back end to fetch information from content, user accounts, taxonomy terms, and other entities from the database and present it to the user as a grid, HTML list, table, unformatted list, etc. The resulting displays are known generally as views.') . '</p>';
  19. $output .= '<p>' . t('For more information, see the <a href="@views" target="blank">online documentation for the Views</a>.', array('@views' => 'https://www.drupal.org/documentation/modules/views')) . '</p>';
  20. $output .= '<p>' . t('In order to create and modify your own views using the administration and configuration user interface, you will need to enable either the Views UI module in core or a contributed module that provides a user interface for Views. See the <a href="/admin/structure/views">Views UI module help page</a> for more information.') . '</p>';
  21. $output .= '<h3>' . t('Uses') . '</h3>';
  22. $output .= '<dl>';
  23. $output .= '<dt>' . t('Adding functionality to administrative pages') . '</dt>';
  24. $output .= '<dd>' . t('The Views module adds functionality to some core administration pages. For example, <em>admin/content</em> uses Views to filter and sort content. With Views uninstalled, <em>admin/content</em> is more limited.') . '</dd>';
  25. $output .= '<dt>' . t('Expanding Views functionality') . '</dt>';
  26. $output .= '<dd>' . t('Contributed projects that support the Views module can be found in the <a href="@views-related" target="blank">online documentation for Views-related contributed modules.</a>.', array('@views-related' => 'https://www.drupal.org/documentation/modules/views/add-ons')) . '</dd>';
  27. $output .= '<dt>' . t('Improving table accessibility') . '</dt>';
  28. $output .= '<dd>' . t('Views tables include semantic markup to improve accessibility. Data cells are automatically associated with header cells through id and header attributes. To improve the accessibility of your tables you can add descriptive elements within the Views table settings. The caption element can introduce context for a table, making it easier to understand. The summary element can provide an overview of how the data has been organized and how to navigate the table. Both the caption and summary are visible by default and also implemented according to HTML5 guidelines.') . '</dd>';
  29. return $output;
  30. }
  31. }
  32. /**
  33. * Advertise the current views api version
  34. */
  35. function views_api_version() {
  36. return '3.0';
  37. }
  38. /**
  39. * Implements hook_forms().
  40. *
  41. * To provide distinct form IDs for Views forms, the View name and
  42. * specific display name are appended to the base ID,
  43. * views_form_views_form. When such a form is built or submitted, this
  44. * function will return the proper callback function to use for the given form.
  45. */
  46. function views_forms($form_id, $args) {
  47. if (strpos($form_id, 'views_form_') === 0) {
  48. return array(
  49. $form_id => array(
  50. 'callback' => 'views_form',
  51. ),
  52. );
  53. }
  54. }
  55. /**
  56. * Returns a form ID for a Views form using the name and display of the View.
  57. */
  58. function views_form_id($view) {
  59. $parts = array(
  60. 'views_form',
  61. $view->name,
  62. $view->current_display,
  63. );
  64. return implode('_', $parts);
  65. }
  66. /**
  67. * Views will not load plugins advertising a version older than this.
  68. */
  69. function views_api_minimum_version() {
  70. return '2';
  71. }
  72. /**
  73. * Implement hook_theme(). Register views theming functions.
  74. */
  75. function views_theme($existing, $type, $theme, $path) {
  76. $path = drupal_get_path('module', 'views');
  77. ctools_include('theme', 'views', 'theme');
  78. // Some quasi clever array merging here.
  79. $base = array(
  80. 'file' => 'theme.inc',
  81. 'path' => $path . '/theme',
  82. );
  83. // Our extra version of pager from pager.inc
  84. $hooks['views_mini_pager'] = $base + array(
  85. 'variables' => array('tags' => array(), 'element' => 0, 'parameters' => array()),
  86. 'pattern' => 'views_mini_pager__',
  87. );
  88. $variables = array(
  89. // For displays, we pass in a dummy array as the first parameter, since
  90. // $view is an object but the core contextual_preprocess() function only
  91. // attaches contextual links when the primary theme argument is an array.
  92. 'display' => array('view_array' => array(), 'view' => NULL),
  93. 'style' => array('view' => NULL, 'options' => NULL, 'rows' => NULL, 'title' => NULL),
  94. 'row' => array('view' => NULL, 'options' => NULL, 'row' => NULL, 'field_alias' => NULL),
  95. 'exposed_form' => array('view' => NULL, 'options' => NULL),
  96. 'pager' => array(
  97. 'view' => NULL, 'options' => NULL,
  98. 'tags' => array(), 'quantity' => 10, 'element' => 0, 'parameters' => array()
  99. ),
  100. );
  101. // Default view themes
  102. $hooks['views_view_field'] = $base + array(
  103. 'pattern' => 'views_view_field__',
  104. 'variables' => array('view' => NULL, 'field' => NULL, 'row' => NULL),
  105. );
  106. $hooks['views_view_grouping'] = $base + array(
  107. 'pattern' => 'views_view_grouping__',
  108. 'variables' => array('view' => NULL, 'grouping' => NULL, 'grouping_level' => NULL, 'rows' => NULL, 'title' => NULL),
  109. );
  110. $plugins = views_fetch_plugin_data();
  111. // Register theme functions for all style plugins
  112. foreach ($plugins as $type => $info) {
  113. foreach ($info as $plugin => $def) {
  114. if (isset($def['theme']) && (!isset($def['register theme']) || !empty($def['register theme']))) {
  115. $hooks[$def['theme']] = array(
  116. 'pattern' => $def['theme'] . '__',
  117. 'file' => $def['theme file'],
  118. 'path' => $def['theme path'],
  119. 'variables' => $variables[$type],
  120. );
  121. $include = DRUPAL_ROOT . '/' . $def['theme path'] . '/' . $def['theme file'];
  122. if (file_exists($include)) {
  123. require_once $include;
  124. }
  125. if (!function_exists('theme_' . $def['theme'])) {
  126. $hooks[$def['theme']]['template'] = drupal_clean_css_identifier($def['theme']);
  127. }
  128. }
  129. if (isset($def['additional themes'])) {
  130. foreach ($def['additional themes'] as $theme => $theme_type) {
  131. if (empty($theme_type)) {
  132. $theme = $theme_type;
  133. $theme_type = $type;
  134. }
  135. $hooks[$theme] = array(
  136. 'pattern' => $theme . '__',
  137. 'file' => $def['theme file'],
  138. 'path' => $def['theme path'],
  139. 'variables' => $variables[$theme_type],
  140. );
  141. if (!function_exists('theme_' . $theme)) {
  142. $hooks[$theme]['template'] = drupal_clean_css_identifier($theme);
  143. }
  144. }
  145. }
  146. }
  147. }
  148. $hooks['views_form_views_form'] = $base + array(
  149. 'render element' => 'form',
  150. );
  151. $hooks['views_exposed_form'] = $base + array(
  152. 'template' => 'views-exposed-form',
  153. 'pattern' => 'views_exposed_form__',
  154. 'render element' => 'form',
  155. );
  156. $hooks['views_more'] = $base + array(
  157. 'template' => 'views-more',
  158. 'pattern' => 'views_more__',
  159. 'variables' => array('more_url' => NULL, 'link_text' => 'more', 'view' => NULL),
  160. );
  161. // Add theme suggestions which are part of modules.
  162. foreach (views_get_module_apis() as $info) {
  163. if (isset($info['template path'])) {
  164. $hooks += _views_find_module_templates($hooks, $info['template path']);
  165. }
  166. }
  167. return $hooks;
  168. }
  169. /**
  170. * Scans a directory of a module for template files.
  171. *
  172. * @param $cache
  173. * The existing cache of theme hooks to test against.
  174. * @param $path
  175. * The path to search.
  176. *
  177. * @see drupal_find_theme_templates()
  178. */
  179. function _views_find_module_templates($cache, $path) {
  180. $templates = array();
  181. $regex = '/' . '\.tpl\.php' . '$' . '/';
  182. // Because drupal_system_listing works the way it does, we check for real
  183. // templates separately from checking for patterns.
  184. $files = drupal_system_listing($regex, $path, 'name', 0);
  185. foreach ($files as $template => $file) {
  186. // Chop off the remaining extensions if there are any. $template already
  187. // has the rightmost extension removed, but there might still be more,
  188. // such as with .tpl.php, which still has .tpl in $template at this point.
  189. if (($pos = strpos($template, '.')) !== FALSE) {
  190. $template = substr($template, 0, $pos);
  191. }
  192. // Transform - in filenames to _ to match function naming scheme
  193. // for the purposes of searching.
  194. $hook = strtr($template, '-', '_');
  195. if (isset($cache[$hook])) {
  196. $templates[$hook] = array(
  197. 'template' => $template,
  198. 'path' => dirname($file->filename),
  199. 'includes' => isset($cache[$hook]['includes']) ? $cache[$hook]['includes'] : NULL,
  200. );
  201. }
  202. // Ensure that the pattern is maintained from base themes to its sub-themes.
  203. // Each sub-theme will have their templates scanned so the pattern must be
  204. // held for subsequent runs.
  205. if (isset($cache[$hook]['pattern'])) {
  206. $templates[$hook]['pattern'] = $cache[$hook]['pattern'];
  207. }
  208. }
  209. $patterns = array_keys($files);
  210. foreach ($cache as $hook => $info) {
  211. if (!empty($info['pattern'])) {
  212. // Transform _ in pattern to - to match file naming scheme
  213. // for the purposes of searching.
  214. $pattern = strtr($info['pattern'], '_', '-');
  215. $matches = preg_grep('/^'. $pattern .'/', $patterns);
  216. if ($matches) {
  217. foreach ($matches as $match) {
  218. $file = substr($match, 0, strpos($match, '.'));
  219. // Put the underscores back in for the hook name and register this pattern.
  220. $templates[strtr($file, '-', '_')] = array(
  221. 'template' => $file,
  222. 'path' => dirname($files[$match]->uri),
  223. 'variables' => isset($info['variables']) ? $info['variables'] : NULL,
  224. 'render element' => isset($info['render element']) ? $info['render element'] : NULL,
  225. 'base hook' => $hook,
  226. 'includes' => isset($info['includes']) ? $info['includes'] : NULL,
  227. );
  228. }
  229. }
  230. }
  231. }
  232. return $templates;
  233. }
  234. /**
  235. * Returns a list of plugins and metadata about them.
  236. *
  237. * @return array
  238. * An array keyed by PLUGIN_TYPE:PLUGIN_NAME, like 'display:page' or
  239. * 'pager:full', containing an array with the following keys:
  240. * - title: The plugin's title.
  241. * - type: The plugin type.
  242. * - module: The module providing the plugin.
  243. * - views: An array of enabled Views that are currently using this plugin,
  244. * keyed by machine name.
  245. */
  246. function views_plugin_list() {
  247. $plugin_data = views_fetch_plugin_data();
  248. $plugins = array();
  249. foreach (views_get_enabled_views() as $view) {
  250. foreach ($view->display as $display_id => $display) {
  251. foreach ($plugin_data as $type => $info) {
  252. if ($type == 'display' && isset($display->display_plugin)) {
  253. $name = $display->display_plugin;
  254. }
  255. elseif (isset($display->display_options["{$type}_plugin"])) {
  256. $name = $display->display_options["{$type}_plugin"];
  257. }
  258. elseif (isset($display->display_options[$type]['type'])) {
  259. $name = $display->display_options[$type]['type'];
  260. }
  261. else {
  262. continue;
  263. }
  264. // Key first by the plugin type, then the name.
  265. $key = $type . ':' . $name;
  266. // Add info for this plugin.
  267. if (!isset($plugins[$key])) {
  268. $plugins[$key] = array(
  269. 'type' => $type,
  270. 'title' => check_plain($info[$name]['title']),
  271. 'module' => check_plain($info[$name]['module']),
  272. 'views' => array(),
  273. );
  274. }
  275. // Add this view to the list for this plugin.
  276. $plugins[$key]['views'][$view->name] = $view->name;
  277. }
  278. }
  279. }
  280. return $plugins;
  281. }
  282. /**
  283. * A theme preprocess function to automatically allow view-based node
  284. * templates if called from a view.
  285. *
  286. * The 'modules/node.views.inc' file is a better place for this, but
  287. * we haven't got a chance to load that file before Drupal builds the
  288. * node portion of the theme registry.
  289. */
  290. function views_preprocess_node(&$vars) {
  291. // The 'view' attribute of the node is added in views_preprocess_node()
  292. if (!empty($vars['node']->view) && !empty($vars['node']->view->name)) {
  293. $vars['view'] = $vars['node']->view;
  294. $vars['theme_hook_suggestions'][] = 'node__view__' . $vars['node']->view->name;
  295. if (!empty($vars['node']->view->current_display)) {
  296. $vars['theme_hook_suggestions'][] = 'node__view__' . $vars['node']->view->name . '__' . $vars['node']->view->current_display;
  297. // If a node is being rendered in a view, and the view does not have a path,
  298. // prevent drupal from accidentally setting the $page variable:
  299. if ($vars['page'] && $vars['view_mode'] == 'full' && !$vars['view']->display_handler->has_path()) {
  300. $vars['page'] = FALSE;
  301. }
  302. }
  303. }
  304. // Allow to alter comments and links based on the settings in the row plugin.
  305. if (!empty($vars['view']->style_plugin->row_plugin) && get_class($vars['view']->style_plugin->row_plugin) == 'views_plugin_row_node_view') {
  306. node_row_node_view_preprocess_node($vars);
  307. }
  308. }
  309. /**
  310. * A theme preprocess function to automatically allow view-based node
  311. * templates if called from a view.
  312. */
  313. function views_preprocess_comment(&$vars) {
  314. // The 'view' attribute of the node is added in template_preprocess_views_view_row_comment()
  315. if (!empty($vars['node']->view) && !empty($vars['node']->view->name)) {
  316. $vars['view'] = &$vars['node']->view;
  317. $vars['theme_hook_suggestions'][] = 'comment__view__' . $vars['node']->view->name;
  318. if (!empty($vars['node']->view->current_display)) {
  319. $vars['theme_hook_suggestions'][] = 'comment__view__' . $vars['node']->view->name . '__' . $vars['node']->view->current_display;
  320. }
  321. }
  322. }
  323. /**
  324. * Implement hook_permission().
  325. */
  326. function views_permission() {
  327. return array(
  328. 'administer views' => array(
  329. 'title' => t('Administer views'),
  330. 'description' => t('Access the views administration pages.'),
  331. 'restrict access' => TRUE,
  332. ),
  333. 'access all views' => array(
  334. 'title' => t('Bypass views access control'),
  335. 'description' => t('Bypass access control when accessing views.'),
  336. 'restrict access' => TRUE,
  337. ),
  338. );
  339. }
  340. /**
  341. * Implement hook_menu().
  342. */
  343. function views_menu() {
  344. $items = array();
  345. $items['views/ajax'] = array(
  346. 'title' => 'Views',
  347. 'page callback' => 'views_ajax',
  348. 'theme callback' => 'ajax_base_page_theme',
  349. 'delivery callback' => 'ajax_deliver',
  350. 'access callback' => TRUE,
  351. 'description' => 'Ajax callback for view loading.',
  352. 'type' => MENU_CALLBACK,
  353. 'file' => 'includes/ajax.inc',
  354. );
  355. // Path is not admin/structure/views due to menu complications with the wildcards from
  356. // the generic ajax callback.
  357. $items['admin/views/ajax/autocomplete/user'] = array(
  358. 'page callback' => 'views_ajax_autocomplete_user',
  359. 'theme callback' => 'ajax_base_page_theme',
  360. 'access callback' => 'user_access',
  361. 'access arguments' => array('access user profiles'),
  362. 'type' => MENU_CALLBACK,
  363. 'file' => 'includes/ajax.inc',
  364. );
  365. // Define another taxonomy autocomplete because the default one of drupal
  366. // does not support a vid a argument anymore.
  367. $items['admin/views/ajax/autocomplete/taxonomy'] = array(
  368. 'page callback' => 'views_ajax_autocomplete_taxonomy',
  369. 'theme callback' => 'ajax_base_page_theme',
  370. 'access callback' => 'user_access',
  371. 'access arguments' => array('access content'),
  372. 'type' => MENU_CALLBACK,
  373. 'file' => 'includes/ajax.inc',
  374. );
  375. return $items;
  376. }
  377. /**
  378. * Implement hook_menu_alter().
  379. */
  380. function views_menu_alter(&$callbacks) {
  381. $our_paths = array();
  382. $views = views_get_applicable_views('uses hook menu');
  383. foreach ($views as $data) {
  384. list($view, $display_id) = $data;
  385. $result = $view->execute_hook_menu($display_id, $callbacks);
  386. if (is_array($result)) {
  387. // The menu system doesn't support having two otherwise
  388. // identical paths with different placeholders. So we
  389. // want to remove the existing items from the menu whose
  390. // paths would conflict with ours.
  391. // First, we must find any existing menu items that may
  392. // conflict. We use a regular expression because we don't
  393. // know what placeholders they might use. Note that we
  394. // first construct the regex itself by replacing %views_arg
  395. // in the display path, then we use this constructed regex
  396. // (which will be something like '#^(foo/%[^/]*/bar)$#') to
  397. // search through the existing paths.
  398. $regex = '#^(' . preg_replace('#%views_arg#', '%[^/]*', implode('|', array_keys($result))) . ')$#';
  399. $matches = preg_grep($regex, array_keys($callbacks));
  400. // Remove any conflicting items that were found.
  401. foreach ($matches as $path) {
  402. // Don't remove the paths we just added!
  403. if (!isset($our_paths[$path])) {
  404. unset($callbacks[$path]);
  405. }
  406. }
  407. foreach ($result as $path => $item) {
  408. if (!isset($callbacks[$path])) {
  409. // Add a new item, possibly replacing (and thus effectively
  410. // overriding) one that we removed above.
  411. $callbacks[$path] = $item;
  412. }
  413. else {
  414. // This item already exists, so it must be one that we added.
  415. // We change the various callback arguments to pass an array
  416. // of possible display IDs instead of a single ID.
  417. $callbacks[$path]['page arguments'][1] = (array)$callbacks[$path]['page arguments'][1];
  418. $callbacks[$path]['page arguments'][1][] = $display_id;
  419. $callbacks[$path]['access arguments'][] = $item['access arguments'][0];
  420. $callbacks[$path]['load arguments'][1] = (array)$callbacks[$path]['load arguments'][1];
  421. $callbacks[$path]['load arguments'][1][] = $display_id;
  422. }
  423. $our_paths[$path] = TRUE;
  424. }
  425. }
  426. }
  427. // Save memory: Destroy those views.
  428. foreach ($views as $data) {
  429. list($view, $display_id) = $data;
  430. $view->destroy();
  431. }
  432. }
  433. /**
  434. * Helper function for menu loading. This will automatically be
  435. * called in order to 'load' a views argument; primarily it
  436. * will be used to perform validation.
  437. *
  438. * @param $value
  439. * The actual value passed.
  440. * @param $name
  441. * The name of the view. This needs to be specified in the 'load function'
  442. * of the menu entry.
  443. * @param $display_id
  444. * The display id that will be loaded for this menu item.
  445. * @param $index
  446. * The menu argument index. This counts from 1.
  447. */
  448. function views_arg_load($value, $name, $display_id, $index) {
  449. static $views = array();
  450. $display_ids = is_array($display_id) ? $display_id : array($display_id);
  451. $display_id = reset($display_ids);
  452. foreach ($display_ids as $id) {
  453. // Make sure we haven't already loaded this views argument for a similar
  454. // menu item elsewhere. Since access is always checked for the current user,
  455. // we are sure that the static cache contains valid entries.
  456. $key = $name . ':' . $id . ':' . $value . ':' . $index;
  457. if (isset($views[$key])) {
  458. return $views[$key];
  459. }
  460. // Lazy load the view object to avoid unnecessary work.
  461. if (!isset($view)) {
  462. $view = views_get_view($name);
  463. }
  464. // Pick the first display we have access to.
  465. if ($view && count($display_ids) > 1 && $view->access($id)) {
  466. $display_id = $id;
  467. break;
  468. }
  469. }
  470. if ($view) {
  471. $view->set_display($display_id);
  472. $view->init_handlers();
  473. $ids = array_keys($view->argument);
  474. $indexes = array();
  475. $path = explode('/', $view->get_path());
  476. foreach ($path as $id => $piece) {
  477. if ($piece == '%' && !empty($ids)) {
  478. $indexes[$id] = array_shift($ids);
  479. }
  480. }
  481. if (isset($indexes[$index])) {
  482. if (isset($view->argument[$indexes[$index]])) {
  483. $arg = $view->argument[$indexes[$index]]->validate_argument($value) ? $value : FALSE;
  484. $view->destroy();
  485. // Store the output in case we load this same menu item again.
  486. $views[$key] = $arg;
  487. return $arg;
  488. }
  489. }
  490. $view->destroy();
  491. }
  492. }
  493. /**
  494. * Page callback: Displays a page view, given a name and display id.
  495. *
  496. * @param $name
  497. * The name of a view.
  498. * @param $display_id
  499. * The display id of a view.
  500. *
  501. * @return
  502. * Either the HTML of a fully-executed view, or MENU_NOT_FOUND.
  503. */
  504. function views_page($name, $display_id) {
  505. $args = func_get_args();
  506. // Remove $name and $display_id from the arguments.
  507. array_shift($args);
  508. array_shift($args);
  509. // Load the view and render it.
  510. if ($view = views_get_view($name)) {
  511. return $view->execute_display($display_id, $args);
  512. }
  513. // Fallback; if we get here no view was found or handler was not valid.
  514. return MENU_NOT_FOUND;
  515. }
  516. /**
  517. * Implements hook_page_alter().
  518. */
  519. function views_page_alter(&$page) {
  520. // If the main content of this page contains a view, attach its contextual
  521. // links to the overall page array. This allows them to be rendered directly
  522. // next to the page title.
  523. $view = views_get_page_view();
  524. if (!empty($view)) {
  525. // If a module is still putting in the display like we used to, catch that.
  526. if (is_subclass_of($view, 'views_plugin_display')) {
  527. $view = $view->view;
  528. }
  529. views_add_contextual_links($page, 'page', $view, $view->current_display);
  530. }
  531. }
  532. /**
  533. * Implements MODULE_preprocess_HOOK() for html.tpl.php.
  534. */
  535. function views_preprocess_html(&$variables) {
  536. // If the page contains a view as its main content, contextual links may have
  537. // been attached to the page as a whole; for example, by views_page_alter().
  538. // This allows them to be associated with the page and rendered by default
  539. // next to the page title (which we want). However, it also causes the
  540. // Contextual Links module to treat the wrapper for the entire page (i.e.,
  541. // the <body> tag) as the HTML element that these contextual links are
  542. // associated with. This we don't want; for better visual highlighting, we
  543. // prefer a smaller region to be chosen. The region we prefer differs from
  544. // theme to theme and depends on the details of the theme's markup in
  545. // page.tpl.php, so we can only find it using JavaScript. We therefore remove
  546. // the "contextual-links-region" class from the <body> tag here and add
  547. // JavaScript that will insert it back in the correct place.
  548. if (!empty($variables['page']['#views_contextual_links_info'])) {
  549. $key = array_search('contextual-links-region', $variables['classes_array']);
  550. if ($key !== FALSE) {
  551. $variables['classes_array'] = array_diff($variables['classes_array'], array('contextual-links-region'));
  552. // Add the JavaScript, with a group and weight such that it will run
  553. // before modules/contextual/contextual.js.
  554. drupal_add_js(drupal_get_path('module', 'views') . '/js/views-contextual.js', array('group' => JS_LIBRARY, 'weight' => -1));
  555. }
  556. }
  557. }
  558. /**
  559. * Implements hook_preprocess_HOOK() for page.tpl.php.
  560. */
  561. function views_preprocess_page(&$variables) {
  562. // If the page contains a view as its main content, contextual links may have
  563. // been attached to the page as a whole; for example, by views_page_alter().
  564. // This allows them to be associated with the page and rendered by default
  565. // next to the page title (which we want). However, it also causes the
  566. // Contextual Links module to treat the wrapper for the entire page (i.e.,
  567. // the <body> tag) as the HTML element that these contextual links are
  568. // associated with. This we don't want; for better visual highlighting, we
  569. // prefer a smaller region to be chosen. The region we prefer differs from
  570. // theme to theme and depends on the details of the theme's markup in
  571. // page.tpl.php, so we can only find it using JavaScript. We therefore remove
  572. // the "contextual-links-region" class from the <body> tag here and add
  573. // JavaScript that will insert it back in the correct place.
  574. if (!empty($variables['page']['#views_contextual_links_info'])) {
  575. $variables['classes_array'] = array_diff($variables['classes_array'], array('contextual-links-region'));
  576. }
  577. }
  578. /**
  579. * Implements hook_contextual_links_view_alter().
  580. */
  581. function views_contextual_links_view_alter(&$element, $items) {
  582. // If we are rendering views-related contextual links attached to the overall
  583. // page array, add a class to the list of contextual links. This will be used
  584. // by the JavaScript added in views_preprocess_html().
  585. if (!empty($element['#element']['#views_contextual_links_info']) && !empty($element['#element']['#type']) && $element['#element']['#type'] == 'page') {
  586. $element['#attributes']['class'][] = 'views-contextual-links-page';
  587. }
  588. }
  589. /**
  590. * Implement hook_block_info().
  591. */
  592. function views_block_info() {
  593. // Try to avoid instantiating all the views just to get the blocks info.
  594. views_include('cache');
  595. $cache = views_cache_get('views_block_items', TRUE);
  596. if ($cache && is_array($cache->data)) {
  597. return $cache->data;
  598. }
  599. $items = array();
  600. $views = views_get_all_views();
  601. foreach ($views as $view) {
  602. // disabled views get nothing.
  603. if (!empty($view->disabled)) {
  604. continue;
  605. }
  606. $view->init_display();
  607. foreach ($view->display as $display_id => $display) {
  608. if (isset($display->handler) && !empty($display->handler->definition['uses hook block'])) {
  609. $result = $display->handler->execute_hook_block_list();
  610. if (is_array($result)) {
  611. $items = array_merge($items, $result);
  612. }
  613. }
  614. if (isset($display->handler) && $display->handler->get_option('exposed_block')) {
  615. $result = $display->handler->get_special_blocks();
  616. if (is_array($result)) {
  617. $items = array_merge($items, $result);
  618. }
  619. }
  620. }
  621. }
  622. // block.module has a delta length limit of 32, but our deltas can
  623. // unfortunately be longer because view names can be 32 and display IDs
  624. // can also be 32. So for very long deltas, change to md5 hashes.
  625. $hashes = array();
  626. // get the keys because we're modifying the array and we don't want to
  627. // confuse PHP too much.
  628. $keys = array_keys($items);
  629. foreach ($keys as $delta) {
  630. if (strlen($delta) >= 32) {
  631. $hash = md5($delta);
  632. $hashes[$hash] = $delta;
  633. $items[$hash] = $items[$delta];
  634. unset($items[$delta]);
  635. }
  636. }
  637. // Only save hashes if they have changed.
  638. $old_hashes = variable_get('views_block_hashes', array());
  639. if ($hashes != $old_hashes) {
  640. variable_set('views_block_hashes', $hashes);
  641. }
  642. // Save memory: Destroy those views.
  643. foreach ($views as $view) {
  644. $view->destroy();
  645. }
  646. views_cache_set('views_block_items', $items, TRUE);
  647. return $items;
  648. }
  649. /**
  650. * Implement hook_block_view().
  651. */
  652. function views_block_view($delta) {
  653. $start = microtime(TRUE);
  654. // if this is 32, this should be an md5 hash.
  655. if (strlen($delta) == 32) {
  656. $hashes = variable_get('views_block_hashes', array());
  657. if (!empty($hashes[$delta])) {
  658. $delta = $hashes[$delta];
  659. }
  660. }
  661. // This indicates it's a special one.
  662. if (substr($delta, 0, 1) == '-') {
  663. list($nothing, $type, $name, $display_id) = explode('-', $delta);
  664. // Put the - back on.
  665. $type = '-' . $type;
  666. if ($view = views_get_view($name)) {
  667. if ($view->access($display_id)) {
  668. $view->set_display($display_id);
  669. if (isset($view->display_handler)) {
  670. $output = $view->display_handler->view_special_blocks($type);
  671. // Before returning the block output, convert it to a renderable
  672. // array with contextual links.
  673. views_add_block_contextual_links($output, $view, $display_id, 'special_block_' . $type);
  674. $view->destroy();
  675. return $output;
  676. }
  677. }
  678. $view->destroy();
  679. }
  680. }
  681. // If the delta doesn't contain valid data return nothing.
  682. $explode = explode('-', $delta);
  683. if (count($explode) != 2) {
  684. return;
  685. }
  686. list($name, $display_id) = $explode;
  687. // Load the view
  688. if ($view = views_get_view($name)) {
  689. if ($view->access($display_id)) {
  690. $output = $view->execute_display($display_id);
  691. // Before returning the block output, convert it to a renderable array
  692. // with contextual links.
  693. views_add_block_contextual_links($output, $view, $display_id);
  694. $view->destroy();
  695. return $output;
  696. }
  697. $view->destroy();
  698. }
  699. }
  700. /**
  701. * Converts Views block content to a renderable array with contextual links.
  702. *
  703. * @param $block
  704. * An array representing the block, with the same structure as the return
  705. * value of hook_block_view(). This will be modified so as to force
  706. * $block['content'] to be a renderable array, containing the optional
  707. * '#contextual_links' property (if there are any contextual links associated
  708. * with the block).
  709. * @param $view
  710. * The view that was used to generate the block content.
  711. * @param $display_id
  712. * The ID of the display within the view that was used to generate the block
  713. * content.
  714. * @param $block_type
  715. * The type of the block. If it's block it's a regular views display,
  716. * but 'special_block_-exp' exist as well.
  717. */
  718. function views_add_block_contextual_links(&$block, $view, $display_id, $block_type = 'block') {
  719. // Do not add contextual links to an empty block.
  720. if (!empty($block['content'])) {
  721. // Contextual links only work on blocks whose content is a renderable
  722. // array, so if the block contains a string of already-rendered markup,
  723. // convert it to an array.
  724. if (is_string($block['content'])) {
  725. $block['content'] = array('#markup' => $block['content']);
  726. }
  727. // Add the contextual links.
  728. views_add_contextual_links($block['content'], $block_type, $view, $display_id);
  729. }
  730. }
  731. /**
  732. * Adds contextual links associated with a view display to a renderable array.
  733. *
  734. * This function should be called when a view is being rendered in a particular
  735. * location and you want to attach the appropriate contextual links (e.g.,
  736. * links for editing the view) to it.
  737. *
  738. * The function operates by checking the view's display plugin to see if it has
  739. * defined any contextual links that are intended to be displayed in the
  740. * requested location; if so, it attaches them. The contextual links intended
  741. * for a particular location are defined by the 'contextual links' and
  742. * 'contextual links locations' properties in hook_views_plugins() and
  743. * hook_views_plugins_alter(); as a result, these hook implementations have
  744. * full control over where and how contextual links are rendered for each
  745. * display.
  746. *
  747. * In addition to attaching the contextual links to the passed-in array (via
  748. * the standard #contextual_links property), this function also attaches
  749. * additional information via the #views_contextual_links_info property. This
  750. * stores an array whose keys are the names of each module that provided
  751. * views-related contextual links (same as the keys of the #contextual_links
  752. * array itself) and whose values are themselves arrays whose keys ('location',
  753. * 'view_name', and 'view_display_id') store the location, name of the view,
  754. * and display ID that were passed in to this function. This allows you to
  755. * access information about the contextual links and how they were generated in
  756. * a variety of contexts where you might be manipulating the renderable array
  757. * later on (for example, alter hooks which run later during the same page
  758. * request).
  759. *
  760. * @param $render_element
  761. * The renderable array to which contextual links will be added. This array
  762. * should be suitable for passing in to drupal_render() and will normally
  763. * contain a representation of the view display whose contextual links are
  764. * being requested.
  765. * @param $location
  766. * The location in which the calling function intends to render the view and
  767. * its contextual links. The core system supports three options for this
  768. * parameter:
  769. * - 'block': Used when rendering a block which contains a view. This
  770. * retrieves any contextual links intended to be attached to the block
  771. * itself.
  772. * - 'page': Used when rendering the main content of a page which contains a
  773. * view. This retrieves any contextual links intended to be attached to the
  774. * page itself (for example, links which are displayed directly next to the
  775. * page title).
  776. * - 'view': Used when rendering the view itself, in any context. This
  777. * retrieves any contextual links intended to be attached directly to the
  778. * view.
  779. * If you are rendering a view and its contextual links in another location,
  780. * you can pass in a different value for this parameter. However, you will
  781. * also need to use hook_views_plugins() or hook_views_plugins_alter() to
  782. * declare, via the 'contextual links locations' array key, which view
  783. * displays support having their contextual links rendered in the location
  784. * you have defined.
  785. * @param $view
  786. * The view whose contextual links will be added.
  787. * @param $display_id
  788. * The ID of the display within $view whose contextual links will be added.
  789. *
  790. * @see hook_views_plugins()
  791. * @see views_block_view()
  792. * @see views_page_alter()
  793. * @see template_preprocess_views_view()
  794. */
  795. function views_add_contextual_links(&$render_element, $location, $view, $display_id) {
  796. // Do not do anything if the view is configured to hide its administrative
  797. // links.
  798. if (empty($view->hide_admin_links)) {
  799. // Also do not do anything if the display plugin has not defined any
  800. // contextual links that are intended to be displayed in the requested
  801. // location.
  802. $plugin = views_fetch_plugin_data('display', $view->display[$display_id]->display_plugin);
  803. // If contextual links locations are not set, provide a sane default. (To
  804. // avoid displaying any contextual links at all, a display plugin can still
  805. // set 'contextual links locations' to, e.g., an empty array.)
  806. $plugin += array('contextual links locations' => array('view'));
  807. // On exposed_forms blocks contextual links should always be visible.
  808. $plugin['contextual links locations'][] = 'special_block_-exp';
  809. $has_links = !empty($plugin['contextual links']) && !empty($plugin['contextual links locations']);
  810. if ($has_links && in_array($location, $plugin['contextual links locations'])) {
  811. foreach ($plugin['contextual links'] as $module => $link) {
  812. $args = array();
  813. $valid = TRUE;
  814. if (!empty($link['argument properties'])) {
  815. foreach ($link['argument properties'] as $property) {
  816. // If the plugin is trying to create an invalid contextual link
  817. // (for example, "path/to/{$view->property}", where $view->property
  818. // does not exist), we cannot construct the link, so we skip it.
  819. if (!property_exists($view, $property)) {
  820. $valid = FALSE;
  821. break;
  822. }
  823. else {
  824. $args[] = $view->{$property};
  825. }
  826. }
  827. }
  828. // If the link was valid, attach information about it to the renderable
  829. // array.
  830. if ($valid) {
  831. $render_element['#contextual_links'][$module] = array($link['parent path'], $args);
  832. $render_element['#views_contextual_links_info'][$module] = array(
  833. 'location' => $location,
  834. 'view' => $view,
  835. 'view_name' => $view->name,
  836. 'view_display_id' => $display_id,
  837. );
  838. }
  839. }
  840. }
  841. }
  842. }
  843. /**
  844. * Returns an array of language names.
  845. *
  846. * This is a one to one copy of locale_language_list because we can't rely on enabled locale module.
  847. *
  848. * @param $field
  849. * 'name' => names in current language, localized
  850. * 'native' => native names
  851. * @param $all
  852. * Boolean to return all languages or only enabled ones
  853. *
  854. * @see locale_language_list()
  855. */
  856. function views_language_list($field = 'name', $all = FALSE) {
  857. if ($all) {
  858. $languages = language_list();
  859. }
  860. else {
  861. $languages = language_list('enabled');
  862. $languages = $languages[1];
  863. }
  864. $list = array();
  865. foreach ($languages as $language) {
  866. $list[$language->language] = ($field == 'name') ? t($language->name) : $language->$field;
  867. }
  868. return $list;
  869. }
  870. /**
  871. * Implements hook_flush_caches().
  872. */
  873. function views_flush_caches() {
  874. return array('cache_views', 'cache_views_data');
  875. }
  876. /**
  877. * Implements hook_field_create_instance.
  878. */
  879. function views_field_create_instance($instance) {
  880. cache_clear_all('*', 'cache_views', TRUE);
  881. cache_clear_all('*', 'cache_views_data', TRUE);
  882. }
  883. /**
  884. * Implements hook_field_update_instance.
  885. */
  886. function views_field_update_instance($instance, $prior_instance) {
  887. cache_clear_all('*', 'cache_views', TRUE);
  888. cache_clear_all('*', 'cache_views_data', TRUE);
  889. }
  890. /**
  891. * Implements hook_field_delete_instance.
  892. */
  893. function views_field_delete_instance($instance) {
  894. cache_clear_all('*', 'cache_views', TRUE);
  895. cache_clear_all('*', 'cache_views_data', TRUE);
  896. }
  897. /**
  898. * Invalidate the views cache, forcing a rebuild on the next grab of table data.
  899. */
  900. function views_invalidate_cache() {
  901. // Clear the views cache.
  902. cache_clear_all('*', 'cache_views', TRUE);
  903. // Clear the page and block cache.
  904. cache_clear_all();
  905. // Set the menu as needed to be rebuilt.
  906. variable_set('menu_rebuild_needed', TRUE);
  907. // Allow modules to respond to the Views cache being cleared.
  908. module_invoke_all('views_invalidate_cache');
  909. }
  910. /**
  911. * Access callback to determine if the user can import Views.
  912. *
  913. * View imports require an additional access check because they are PHP
  914. * code and PHP is more locked down than administer views.
  915. */
  916. function views_import_access() {
  917. return user_access('administer views') && user_access('use PHP for settings');
  918. }
  919. /**
  920. * Determine if the logged in user has access to a view.
  921. *
  922. * This function should only be called from a menu hook or some other
  923. * embedded source. Each argument is the result of a call to
  924. * views_plugin_access::get_access_callback() which is then used
  925. * to determine if that display is accessible. If *any* argument
  926. * is accessible, then the view is accessible.
  927. */
  928. function views_access() {
  929. $args = func_get_args();
  930. foreach ($args as $arg) {
  931. if ($arg === TRUE) {
  932. return TRUE;
  933. }
  934. if (!is_array($arg)) {
  935. continue;
  936. }
  937. list($callback, $arguments) = $arg;
  938. $arguments = $arguments ? $arguments : array();
  939. // Bring dynamic arguments to the access callback.
  940. foreach ($arguments as $key => $value) {
  941. if (is_int($value) && isset($args[$value])) {
  942. $arguments[$key] = $args[$value];
  943. }
  944. }
  945. if (function_exists($callback) && call_user_func_array($callback, $arguments)) {
  946. return TRUE;
  947. }
  948. }
  949. return FALSE;
  950. }
  951. /**
  952. * Access callback for the views_plugin_access_perm access plugin.
  953. *
  954. * Determine if the specified user has access to a view on the basis of
  955. * permissions. If the $account argument is omitted, the current user
  956. * is used.
  957. */
  958. function views_check_perm($perms, $account = NULL) {
  959. // Backward compatibility to ensure also a single permission string is
  960. // properly processed.
  961. $perms = is_array($perms) ? $perms : array($perms);
  962. if (user_access('access all views', $account)) {
  963. return TRUE;
  964. }
  965. // Perms are handled as OR, as soon one permission allows access TRUE is
  966. // returned.
  967. foreach ($perms as $perm) {
  968. if (user_access($perm, $account)) {
  969. return TRUE;
  970. }
  971. }
  972. return FALSE;
  973. }
  974. /**
  975. * Access callback for the views_plugin_access_role access plugin.
  976. * Determine if the specified user has access to a view on the basis of any of
  977. * the requested roles. If the $account argument is omitted, the current user
  978. * is used.
  979. */
  980. function views_check_roles($rids, $account = NULL) {
  981. global $user;
  982. $account = isset($account) ? $account : $user;
  983. $roles = array_keys($account->roles);
  984. $roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID;
  985. return user_access('access all views', $account) || array_intersect(array_filter($rids), $roles);
  986. }
  987. // ------------------------------------------------------------------
  988. // Functions to help identify views that are running or ran
  989. /**
  990. * Set the current 'page view' that is being displayed so that it is easy
  991. * for other modules or the theme to identify.
  992. */
  993. function &views_set_page_view($view = NULL) {
  994. static $cache = NULL;
  995. if (isset($view)) {
  996. $cache = $view;
  997. }
  998. return $cache;
  999. }
  1000. /**
  1001. * Find out what, if any, page view is currently in use. Please note that
  1002. * this returns a reference, so be careful! You can unintentionally modify the
  1003. * $view object.
  1004. *
  1005. * @return view
  1006. * A fully formed, empty $view object.
  1007. */
  1008. function &views_get_page_view() {
  1009. return views_set_page_view();
  1010. }
  1011. /**
  1012. * Set the current 'current view' that is being built/rendered so that it is
  1013. * easy for other modules or items in drupal_eval to identify
  1014. *
  1015. * @return view
  1016. */
  1017. function &views_set_current_view($view = NULL) {
  1018. static $cache = NULL;
  1019. if (isset($view)) {
  1020. $cache = $view;
  1021. }
  1022. return $cache;
  1023. }
  1024. /**
  1025. * Find out what, if any, current view is currently in use. Please note that
  1026. * this returns a reference, so be careful! You can unintentionally modify the
  1027. * $view object.
  1028. *
  1029. * @return view
  1030. */
  1031. function &views_get_current_view() {
  1032. return views_set_current_view();
  1033. }
  1034. // ------------------------------------------------------------------
  1035. // Include file helpers
  1036. /**
  1037. * Include views .inc files as necessary.
  1038. */
  1039. function views_include($file) {
  1040. ctools_include($file, 'views');
  1041. }
  1042. /**
  1043. * Load views files on behalf of modules.
  1044. */
  1045. function views_module_include($api, $reset = FALSE) {
  1046. if ($reset) {
  1047. $cache = &drupal_static('ctools_plugin_api_info');
  1048. if (isset($cache['views']['views'])) {
  1049. unset($cache['views']['views']);
  1050. }
  1051. }
  1052. ctools_include('plugins');
  1053. return ctools_plugin_api_include('views', $api, views_api_minimum_version(), views_api_version());
  1054. }
  1055. /**
  1056. * Get a list of modules that support the current views API.
  1057. */
  1058. function views_get_module_apis($api = 'views', $reset = FALSE) {
  1059. if ($reset) {
  1060. $cache = &drupal_static('ctools_plugin_api_info');
  1061. if (isset($cache['views']['views'])) {
  1062. unset($cache['views']['views']);
  1063. }
  1064. }
  1065. ctools_include('plugins');
  1066. return ctools_plugin_api_info('views', $api, views_api_minimum_version(), views_api_version());
  1067. }
  1068. /**
  1069. * Include views .css files.
  1070. */
  1071. function views_add_css($file) {
  1072. // We set preprocess to FALSE because we are adding the files conditionally,
  1073. // and we don't want to generate duplicate cache files.
  1074. // TODO: at some point investigate adding some files unconditionally and
  1075. // allowing preprocess.
  1076. drupal_add_css(drupal_get_path('module', 'views') . "/css/$file.css", array('preprocess' => FALSE));
  1077. }
  1078. /**
  1079. * Include views .js files.
  1080. */
  1081. function views_add_js($file) {
  1082. // If javascript has been disabled by the user, never add js files.
  1083. if (variable_get('views_no_javascript', FALSE)) {
  1084. return;
  1085. }
  1086. static $base = TRUE, $ajax = TRUE;
  1087. if ($base) {
  1088. drupal_add_js(drupal_get_path('module', 'views') . "/js/base.js");
  1089. $base = FALSE;
  1090. }
  1091. if ($ajax && in_array($file, array('ajax', 'ajax_view'))) {
  1092. drupal_add_library('system', 'drupal.ajax');
  1093. drupal_add_library('system', 'jquery.form');
  1094. $ajax = FALSE;
  1095. }
  1096. ctools_add_js($file, 'views');
  1097. }
  1098. /**
  1099. * Load views files on behalf of modules.
  1100. */
  1101. function views_include_handlers($reset = FALSE) {
  1102. static $finished = FALSE;
  1103. // Ensure this only gets run once.
  1104. if ($finished && !$reset) {
  1105. return;
  1106. }
  1107. views_include('base');
  1108. views_include('handlers');
  1109. views_include('cache');
  1110. views_include('plugins');
  1111. views_module_include('views', $reset);
  1112. $finished = TRUE;
  1113. }
  1114. // -----------------------------------------------------------------------
  1115. // Views handler functions
  1116. /**
  1117. * Fetch a handler from the data cache.
  1118. *
  1119. * @param $table
  1120. * The name of the table this handler is from.
  1121. * @param $field
  1122. * The name of the field this handler is from.
  1123. * @param $key
  1124. * The type of handler. i.e, sort, field, argument, filter, relationship
  1125. * @param $override
  1126. * Override the actual handler object with this class. Used for
  1127. * aggregation when the handler is redirected to the aggregation
  1128. * handler.
  1129. *
  1130. * @return views_handler
  1131. * An instance of a handler object. May be views_handler_broken.
  1132. */
  1133. function views_get_handler($table, $field, $key, $override = NULL) {
  1134. static $recursion_protection = array();
  1135. $data = views_fetch_data($table, FALSE);
  1136. $handler = NULL;
  1137. views_include('handlers');
  1138. // Support old views_data entries conversion.
  1139. // Support conversion on table level.
  1140. if (isset($data['moved to'])) {
  1141. $moved = array($data['moved to'], $field);
  1142. }
  1143. // Support conversion on datafield level.
  1144. if (isset($data[$field]['moved to'])) {
  1145. $moved = $data[$field]['moved to'];
  1146. }
  1147. // Support conversion on handler level.
  1148. if (isset($data[$field][$key]['moved to'])) {
  1149. $moved = $data[$field][$key]['moved to'];
  1150. }
  1151. if (isset($data[$field][$key]) || !empty($moved)) {
  1152. if (!empty($moved)) {
  1153. list($moved_table, $moved_field) = $moved;
  1154. if (!empty($recursion_protection[$moved_table][$moved_field])) {
  1155. // recursion detected!
  1156. return NULL;
  1157. }
  1158. $recursion_protection[$moved_table][$moved_field] = TRUE;
  1159. $handler = views_get_handler($moved_table, $moved_field, $key, $override);
  1160. $recursion_protection = array();
  1161. if ($handler) {
  1162. // store these values so we know what we were originally called.
  1163. $handler->original_table = $table;
  1164. $handler->original_field = $field;
  1165. if (empty($handler->actual_table)) {
  1166. $handler->actual_table = $moved_table;
  1167. $handler->actual_field = $moved_field;
  1168. }
  1169. }
  1170. return $handler;
  1171. }
  1172. // Set up a default handler:
  1173. if (empty($data[$field][$key]['handler'])) {
  1174. $data[$field][$key]['handler'] = 'views_handler_' . $key;
  1175. }
  1176. if ($override) {
  1177. $data[$field][$key]['override handler'] = $override;
  1178. }
  1179. $handler = _views_prepare_handler($data[$field][$key], $data, $field, $key);
  1180. }
  1181. if ($handler) {
  1182. return $handler;
  1183. }
  1184. // DEBUG -- identify missing handlers
  1185. vpr("Missing handler: @table @field @key", array('@table' => $table, '@field' => $field, '@key' => $key));
  1186. $broken = array(
  1187. 'title' => t('Broken handler @table.@field', array('@table' => $table, '@field' => $field)),
  1188. 'handler' => 'views_handler_' . $key . '_broken',
  1189. 'table' => $table,
  1190. 'field' => $field,
  1191. );
  1192. return _views_create_handler($broken, 'handler', $key);
  1193. }
  1194. /**
  1195. * Fetch Views' data from the cache
  1196. */
  1197. function views_fetch_data($table = NULL, $move = TRUE, $reset = FALSE) {
  1198. views_include('cache');
  1199. return _views_fetch_data($table, $move, $reset);
  1200. }
  1201. // -----------------------------------------------------------------------
  1202. // Views plugin functions
  1203. /**
  1204. * Fetch the plugin data from cache.
  1205. */
  1206. function views_fetch_plugin_data($type = NULL, $plugin = NULL, $reset = FALSE) {
  1207. views_include('cache');
  1208. return _views_fetch_plugin_data($type, $plugin, $reset);
  1209. }
  1210. /**
  1211. * Fetch a list of all base tables available
  1212. *
  1213. * @param $type
  1214. * Either 'display', 'style' or 'row'
  1215. * @param $key
  1216. * For style plugins, this is an optional type to restrict to. May be 'normal',
  1217. * 'summary', 'feed' or others based on the needs of the display.
  1218. * @param $base
  1219. * An array of possible base tables.
  1220. *
  1221. * @return
  1222. * A keyed array of in the form of 'base_table' => 'Description'.
  1223. */
  1224. function views_fetch_plugin_names($type, $key = NULL, $base = array()) {
  1225. $data = views_fetch_plugin_data();
  1226. $plugins[$type] = array();
  1227. foreach ($data[$type] as $id => $plugin) {
  1228. // Skip plugins that don't conform to our key.
  1229. if ($key && (empty($plugin['type']) || $plugin['type'] != $key)) {
  1230. continue;
  1231. }
  1232. if (empty($plugin['no ui']) && (empty($base) || empty($plugin['base']) || array_intersect($base, $plugin['base']))) {
  1233. $plugins[$type][$id] = $plugin['title'];
  1234. }
  1235. }
  1236. if (!empty($plugins[$type])) {
  1237. asort($plugins[$type]);
  1238. return $plugins[$type];
  1239. }
  1240. // fall-through
  1241. return array();
  1242. }
  1243. /**
  1244. * Get a handler for a plugin
  1245. *
  1246. * @return views_plugin
  1247. *
  1248. * The created plugin object.
  1249. */
  1250. function views_get_plugin($type, $plugin, $reset = FALSE) {
  1251. views_include('handlers');
  1252. $definition = views_fetch_plugin_data($type, $plugin, $reset);
  1253. if (!empty($definition)) {
  1254. return _views_create_handler($definition, $type);
  1255. }
  1256. }
  1257. /**
  1258. * Load the current enabled localization plugin.
  1259. *
  1260. * @return The name of the localization plugin.
  1261. */
  1262. function views_get_localization_plugin() {
  1263. $plugin = variable_get('views_localization_plugin', '');
  1264. // Provide sane default values for the localization plugin.
  1265. if (empty($plugin)) {
  1266. if (module_exists('locale')) {
  1267. $plugin = 'core';
  1268. }
  1269. else {
  1270. $plugin = 'none';
  1271. }
  1272. }
  1273. return $plugin;
  1274. }
  1275. // -----------------------------------------------------------------------
  1276. // Views database functions
  1277. /**
  1278. * Get all view templates.
  1279. *
  1280. * Templates are special in-code views that are never active, but exist only
  1281. * to be cloned into real views as though they were templates.
  1282. */
  1283. function views_get_all_templates() {
  1284. $templates = array();
  1285. $modules = views_module_include('views_template');
  1286. foreach ($modules as $module => $info) {
  1287. $function = $module . '_views_templates';
  1288. if (function_exists($function)) {
  1289. $new = $function();
  1290. if ($new && is_array($new)) {
  1291. $templates = array_merge($new, $templates);
  1292. }
  1293. }
  1294. }
  1295. return $templates;
  1296. }
  1297. /**
  1298. * Create an empty view to work with.
  1299. *
  1300. * @return view
  1301. * A fully formed, empty $view object. This object must be populated before
  1302. * it can be successfully saved.
  1303. */
  1304. function views_new_view() {
  1305. views_include('view');
  1306. $view = new view();
  1307. $view->vid = 'new';
  1308. $view->add_display('default');
  1309. return $view;
  1310. }
  1311. /**
  1312. * Return a list of all views and display IDs that have a particular
  1313. * setting in their display's plugin settings.
  1314. *
  1315. * @return
  1316. * @code
  1317. * array(
  1318. * array($view, $display_id),
  1319. * array($view, $display_id),
  1320. * );
  1321. * @endcode
  1322. */
  1323. function views_get_applicable_views($type) {
  1324. // @todo: Use a smarter flagging system so that we don't have to
  1325. // load every view for this.
  1326. $result = array();
  1327. $views = views_get_all_views();
  1328. foreach ($views as $view) {
  1329. // Skip disabled views.
  1330. if (!empty($view->disabled)) {
  1331. continue;
  1332. }
  1333. if (empty($view->display)) {
  1334. // Skip this view as it is broken.
  1335. vsm(t("Skipping broken view @view", array('@view' => $view->name)));
  1336. continue;
  1337. }
  1338. // Loop on array keys because something seems to muck with $view->display
  1339. // a bit in PHP4.
  1340. foreach (array_keys($view->display) as $id) {
  1341. $plugin = views_fetch_plugin_data('display', $view->display[$id]->display_plugin);
  1342. if (!empty($plugin[$type])) {
  1343. // This view uses hook menu. Clone it so that different handlers
  1344. // don't trip over each other, and add it to the list.
  1345. $v = $view->clone_view();
  1346. if ($v->set_display($id) && $v->display_handler->get_option('enabled')) {
  1347. $result[] = array($v, $id);
  1348. }
  1349. // In PHP 4.4.7 and presumably earlier, if we do not unset $v
  1350. // here, we will find that it actually overwrites references
  1351. // possibly due to shallow copying issues.
  1352. unset($v);
  1353. }
  1354. }
  1355. }
  1356. return $result;
  1357. }
  1358. /**
  1359. * Return an array of all views as fully loaded $view objects.
  1360. *
  1361. * @param $reset
  1362. * If TRUE, reset the static cache forcing views to be reloaded.
  1363. */
  1364. function views_get_all_views($reset = FALSE) {
  1365. ctools_include('export');
  1366. return ctools_export_crud_load_all('views_view', $reset);
  1367. }
  1368. /**
  1369. * Returns an array of all enabled views, as fully loaded $view objects.
  1370. */
  1371. function views_get_enabled_views() {
  1372. $views = views_get_all_views();
  1373. return array_filter($views, 'views_view_is_enabled');
  1374. }
  1375. /**
  1376. * Returns an array of all disabled views, as fully loaded $view objects.
  1377. */
  1378. function views_get_disabled_views() {
  1379. $views = views_get_all_views();
  1380. return array_filter($views, 'views_view_is_disabled');
  1381. }
  1382. /**
  1383. * Return an array of view as options array, that can be used by select,
  1384. * checkboxes and radios as #options.
  1385. *
  1386. * @param bool $views_only
  1387. * If TRUE, only return views, not displays.
  1388. * @param string $filter
  1389. * Filters the views on status. Can either be 'all' (default), 'enabled' or
  1390. * 'disabled'
  1391. * @param mixed $exclude_view
  1392. * view or current display to exclude
  1393. * either a
  1394. * - views object (containing $exclude_view->name and $exclude_view->current_display)
  1395. * - views name as string: e.g. my_view
  1396. * - views name and display id (separated by ':'): e.g. my_view:default
  1397. * @param bool $optgroup
  1398. * If TRUE, returns an array with optgroups for each view (will be ignored for
  1399. * $views_only = TRUE). Can be used by select
  1400. * @param bool $sort
  1401. * If TRUE, the list of views is sorted ascending.
  1402. *
  1403. * @return array
  1404. * an associative array for use in select.
  1405. * - key: view name and display id separated by ':', or the view name only
  1406. */
  1407. function views_get_views_as_options($views_only = FALSE, $filter = 'all', $exclude_view = NULL, $optgroup = FALSE, $sort = FALSE) {
  1408. // Filter the big views array.
  1409. switch ($filter) {
  1410. case 'all':
  1411. case 'disabled':
  1412. case 'enabled':
  1413. $func = "views_get_{$filter}_views";
  1414. $views = $func();
  1415. break;
  1416. default:
  1417. return array();
  1418. }
  1419. // Prepare exclude view strings for comparison.
  1420. if (empty($exclude_view)) {
  1421. $exclude_view_name = '';
  1422. $exclude_view_display = '';
  1423. }
  1424. elseif (is_object($exclude_view)) {
  1425. $exclude_view_name = $exclude_view->name;
  1426. $exclude_view_display = $exclude_view->current_display;
  1427. }
  1428. else {
  1429. list($exclude_view_name, $exclude_view_display) = explode(':', $exclude_view);
  1430. }
  1431. $options = array();
  1432. foreach ($views as $view) {
  1433. // Return only views.
  1434. if ($views_only && $view->name != $exclude_view_name) {
  1435. $options[$view->name] = $view->get_human_name();
  1436. }
  1437. // Return views with display ids.
  1438. else {
  1439. foreach ($view->display as $display_id => $display) {
  1440. if (!($view->name == $exclude_view_name && $display_id == $exclude_view_display)) {
  1441. if ($optgroup) {
  1442. $options[$view->name][$view->name . ':' . $display->id] = t('@view : @display', array('@view' => $view->name, '@display' => $display->id));
  1443. }
  1444. else {
  1445. $options[$view->name . ':' . $display->id] = t('View: @view - Display: @display', array('@view' => $view->name, '@display' => $display->id));
  1446. }
  1447. }
  1448. }
  1449. }
  1450. }
  1451. if ($sort) {
  1452. ksort($options);
  1453. }
  1454. return $options;
  1455. }
  1456. /**
  1457. * Returns TRUE if a view is enabled, FALSE otherwise.
  1458. */
  1459. function views_view_is_enabled($view) {
  1460. return empty($view->disabled);
  1461. }
  1462. /**
  1463. * Returns TRUE if a view is disabled, FALSE otherwise.
  1464. */
  1465. function views_view_is_disabled($view) {
  1466. return !empty($view->disabled);
  1467. }
  1468. /**
  1469. * Get a view from the database or from default views.
  1470. *
  1471. * This function is just a static wrapper around views::load(). This function
  1472. * isn't called 'views_load()' primarily because it might get a view
  1473. * from the default views which aren't technically loaded from the database.
  1474. *
  1475. * @param $name
  1476. * The name of the view.
  1477. * @param $reset
  1478. * If TRUE, reset this entry in the load cache.
  1479. * @return view
  1480. * A reference to the $view object. Use $reset if you're sure you want
  1481. * a fresh one.
  1482. */
  1483. function views_get_view($name, $reset = FALSE) {
  1484. if ($reset) {
  1485. $cache = &drupal_static('ctools_export_load_object');
  1486. if (isset($cache['views_view'][$name])) {
  1487. unset($cache['views_view'][$name]);
  1488. }
  1489. }
  1490. ctools_include('export');
  1491. $view = ctools_export_crud_load('views_view', $name);
  1492. if ($view) {
  1493. $view->update();
  1494. return $view->clone_view();
  1495. }
  1496. }
  1497. /**
  1498. * Find the real location of a table.
  1499. *
  1500. * If a table has moved, find the new name of the table so that we can
  1501. * change its name directly in options where necessary.
  1502. */
  1503. function views_move_table($table) {
  1504. $data = views_fetch_data($table, FALSE);
  1505. if (isset($data['moved to'])) {
  1506. $table = $data['moved to'];
  1507. }
  1508. return $table;
  1509. }
  1510. /**
  1511. * Export callback to load the view subrecords, which are the displays.
  1512. */
  1513. function views_load_display_records(&$views) {
  1514. // Get vids from the views.
  1515. $names = array();
  1516. foreach ($views as $view) {
  1517. if (empty($view->display)) {
  1518. $names[$view->vid] = $view->name;
  1519. }
  1520. }
  1521. if (empty($names)) {
  1522. return;
  1523. }
  1524. foreach (view::db_objects() as $key) {
  1525. $object_name = "views_$key";
  1526. $result = db_query("SELECT * FROM {{$object_name}} WHERE vid IN (:vids) ORDER BY vid, position",
  1527. array(':vids' => array_keys($names)));
  1528. foreach ($result as $data) {
  1529. $object = new $object_name(FALSE);
  1530. $object->load_row($data);
  1531. // Because it can get complicated with this much indirection,
  1532. // make a shortcut reference.
  1533. $location = &$views[$names[$object->vid]]->$key;
  1534. // If we have a basic id field, load the item onto the view based on
  1535. // this ID, otherwise push it on.
  1536. if (!empty($object->id)) {
  1537. $location[$object->id] = $object;
  1538. }
  1539. else {
  1540. $location[] = $object;
  1541. }
  1542. }
  1543. }
  1544. }
  1545. /**
  1546. * Export CRUD callback to save a view.
  1547. */
  1548. function views_save_view(&$view) {
  1549. return $view->save();
  1550. }
  1551. /**
  1552. * Export CRUD callback to delete a view.
  1553. */
  1554. function views_delete_view(&$view) {
  1555. return $view->delete(TRUE);
  1556. }
  1557. /**
  1558. * Export CRUD callback to export a view.
  1559. */
  1560. function views_export_view(&$view, $indent = '') {
  1561. return $view->export($indent);
  1562. }
  1563. /**
  1564. * Export callback to change view status.
  1565. */
  1566. function views_export_status($view, $status) {
  1567. ctools_export_set_object_status($view, $status);
  1568. views_invalidate_cache();
  1569. }
  1570. // ------------------------------------------------------------------
  1571. // Views debug helper functions
  1572. /**
  1573. * Provide debug output for Views.
  1574. *
  1575. * This relies on devel.module
  1576. * or on the debug() function if you use a simpletest.
  1577. *
  1578. * @param $message
  1579. * The message/variable which should be debugged.
  1580. * This either could be
  1581. * * an array/object which is converted to pretty output
  1582. * * a translation source string which is used together with the parameter placeholders.
  1583. *
  1584. * @param $placeholder
  1585. * The placeholders which are used for the translation source string.
  1586. */
  1587. function views_debug($message, $placeholders = array()) {
  1588. if (!is_string($message)) {
  1589. $output = '<pre>' . var_export($message, TRUE) . '</pre>';
  1590. }
  1591. if (module_exists('devel') && variable_get('views_devel_output', FALSE) && user_access('access devel information')) {
  1592. $devel_region = variable_get('views_devel_region', 'footer');
  1593. if ($devel_region == 'watchdog') {
  1594. $output = $message;
  1595. watchdog('views_logging', $output, $placeholders);
  1596. }
  1597. else if ($devel_region == 'drupal_debug') {
  1598. $output = empty($output) ? t($message, $placeholders) : $output;
  1599. dd($output);
  1600. }
  1601. else {
  1602. $output = empty($output) ? t($message, $placeholders) : $output;
  1603. dpm($output);
  1604. }
  1605. }
  1606. elseif (isset($GLOBALS['drupal_test_info'])) {
  1607. $output = empty($output) ? t($message, $placeholders) : $output;
  1608. debug($output);
  1609. }
  1610. }
  1611. /**
  1612. * Shortcut to views_debug()
  1613. */
  1614. function vpr($message, $placeholders = array()) {
  1615. views_debug($message, $placeholders);
  1616. }
  1617. /**
  1618. * Debug messages
  1619. */
  1620. function vsm($message) {
  1621. if (module_exists('devel')) {
  1622. dpm($message);
  1623. }
  1624. }
  1625. function views_trace() {
  1626. $message = '';
  1627. foreach (debug_backtrace() as $item) {
  1628. if (!empty($item['file']) && !in_array($item['function'], array('vsm_trace', 'vpr_trace', 'views_trace'))) {
  1629. $message .= basename($item['file']) . ": " . (empty($item['class']) ? '' : ($item['class'] . '->')) . "$item[function] line $item[line]" . "\n";
  1630. }
  1631. }
  1632. return $message;
  1633. }
  1634. function vsm_trace() {
  1635. vsm(views_trace());
  1636. }
  1637. function vpr_trace() {
  1638. dpr(views_trace());
  1639. }
  1640. // ------------------------------------------------------------------
  1641. // Views form (View with form elements)
  1642. /**
  1643. * Returns TRUE if the passed-in view contains handlers with views form
  1644. * implementations, FALSE otherwise.
  1645. */
  1646. function views_view_has_form_elements($view) {
  1647. foreach ($view->field as $field) {
  1648. if (property_exists($field, 'views_form_callback') || method_exists($field, 'views_form')) {
  1649. return TRUE;
  1650. }
  1651. }
  1652. $area_handlers = array_merge(array_values($view->header), array_values($view->footer));
  1653. $empty = empty($view->result);
  1654. foreach ($area_handlers as $area) {
  1655. if (method_exists($area, 'views_form') && !$area->views_form_empty($empty)) {
  1656. return TRUE;
  1657. }
  1658. }
  1659. return FALSE;
  1660. }
  1661. /**
  1662. * This is the entry function. Just gets the form for the current step.
  1663. * The form is always assumed to be multistep, even if it has only one
  1664. * step (the default 'views_form_views_form' step). That way it is actually
  1665. * possible for modules to have a multistep form if they need to.
  1666. */
  1667. function views_form($form, &$form_state, $view, $output) {
  1668. $form_state['step'] = isset($form_state['step']) ? $form_state['step'] : 'views_form_views_form';
  1669. // Cache the built form to prevent it from being rebuilt prior to validation
  1670. // and submission, which could lead to data being processed incorrectly,
  1671. // because the views rows (and thus, the form elements as well) have changed
  1672. // in the meantime.
  1673. $form_state['cache'] = TRUE;
  1674. $form = array();
  1675. $query = drupal_get_query_parameters($_GET, array('q'));
  1676. $form['#action'] = url($view->get_url(), array('query' => $query));
  1677. // Tell the preprocessor whether it should hide the header, footer, pager...
  1678. $form['show_view_elements'] = array(
  1679. '#type' => 'value',
  1680. '#value' => ($form_state['step'] == 'views_form_views_form') ? TRUE : FALSE,
  1681. );
  1682. $form = $form_state['step']($form, $form_state, $view, $output);
  1683. return $form;
  1684. }
  1685. /**
  1686. * Callback for the main step of a Views form.
  1687. * Invoked by views_form().
  1688. */
  1689. function views_form_views_form($form, &$form_state, $view, $output) {
  1690. $form['#prefix'] = '<div class="views-form">';
  1691. $form['#suffix'] = '</div>';
  1692. $form['#theme'] = 'views_form_views_form';
  1693. $form['#validate'][] = 'views_form_views_form_validate';
  1694. $form['#submit'][] = 'views_form_views_form_submit';
  1695. // Add the output markup to the form array so that it's included when the form
  1696. // array is passed to the theme function.
  1697. $form['output'] = array(
  1698. '#type' => 'markup',
  1699. '#markup' => $output,
  1700. // This way any additional form elements will go before the view
  1701. // (below the exposed widgets).
  1702. '#weight' => 50,
  1703. );
  1704. $substitutions = array();
  1705. foreach ($view->field as $field_name => $field) {
  1706. $form_element_name = $field_name;
  1707. if (method_exists($field, 'form_element_name')) {
  1708. $form_element_name = $field->form_element_name();
  1709. }
  1710. $method_form_element_row_id_exists = FALSE;
  1711. if (method_exists($field, 'form_element_row_id')) {
  1712. $method_form_element_row_id_exists = TRUE;
  1713. }
  1714. // If the field provides a views form, allow it to modify the $form array.
  1715. $has_form = FALSE;
  1716. if (property_exists($field, 'views_form_callback')) {
  1717. $callback = $field->views_form_callback;
  1718. $callback($view, $field, $form, $form_state);
  1719. $has_form = TRUE;
  1720. }
  1721. elseif (method_exists($field, 'views_form')) {
  1722. $field->views_form($form, $form_state);
  1723. $has_form = TRUE;
  1724. }
  1725. // Build the substitutions array for use in the theme function.
  1726. if ($has_form) {
  1727. foreach ($view->result as $row_id => $row) {
  1728. if ($method_form_element_row_id_exists) {
  1729. $form_element_row_id = $field->form_element_row_id($row_id);
  1730. }
  1731. else {
  1732. $form_element_row_id = $row_id;
  1733. }
  1734. $substitutions[] = array(
  1735. 'placeholder' => '<!--form-item-' . $form_element_name . '--' . $form_element_row_id . '-->',
  1736. 'field_name' => $form_element_name,
  1737. 'row_id' => $form_element_row_id,
  1738. );
  1739. }
  1740. }
  1741. }
  1742. // Give the area handlers a chance to extend the form.
  1743. $area_handlers = array_merge(array_values($view->header), array_values($view->footer));
  1744. $empty = empty($view->result);
  1745. foreach ($area_handlers as $area) {
  1746. if (method_exists($area, 'views_form') && !$area->views_form_empty($empty)) {
  1747. $area->views_form($form, $form_state);
  1748. }
  1749. }
  1750. $form['#substitutions'] = array(
  1751. '#type' => 'value',
  1752. '#value' => $substitutions,
  1753. );
  1754. $form['actions'] = array(
  1755. '#type' => 'container',
  1756. '#attributes' => array('class' => array('form-actions')),
  1757. '#weight' => 100,
  1758. );
  1759. $form['actions']['submit'] = array(
  1760. '#type' => 'submit',
  1761. '#value' => t('Save'),
  1762. );
  1763. return $form;
  1764. }
  1765. /**
  1766. * Validate handler for the first step of the views form.
  1767. * Calls any existing views_form_validate functions located
  1768. * on the views fields.
  1769. */
  1770. function views_form_views_form_validate($form, &$form_state) {
  1771. $view = $form_state['build_info']['args'][0];
  1772. // Call the validation method on every field handler that has it.
  1773. foreach ($view->field as $field_name => $field) {
  1774. if (method_exists($field, 'views_form_validate')) {
  1775. $field->views_form_validate($form, $form_state);
  1776. }
  1777. }
  1778. // Call the validate method on every area handler that has it.
  1779. foreach (array('header', 'footer') as $area) {
  1780. foreach ($view->{$area} as $area_name => $area_handler) {
  1781. if (method_exists($area_handler, 'views_form_validate')) {
  1782. $area_handler->views_form_validate($form, $form_state);
  1783. }
  1784. }
  1785. }
  1786. }
  1787. /**
  1788. * Submit handler for the first step of the views form.
  1789. * Calls any existing views_form_submit functions located
  1790. * on the views fields.
  1791. */
  1792. function views_form_views_form_submit($form, &$form_state) {
  1793. $view = $form_state['build_info']['args'][0];
  1794. // Call the submit method on every field handler that has it.
  1795. foreach ($view->field as $field_name => $field) {
  1796. if (method_exists($field, 'views_form_submit')) {
  1797. $field->views_form_submit($form, $form_state);
  1798. }
  1799. }
  1800. // Call the submit method on every area handler that has it.
  1801. foreach (array('header', 'footer') as $area) {
  1802. foreach ($view->{$area} as $area_name => $area_handler) {
  1803. if (method_exists($area_handler, 'views_form_submit')) {
  1804. $area_handler->views_form_submit($form, $form_state);
  1805. }
  1806. }
  1807. }
  1808. }
  1809. // ------------------------------------------------------------------
  1810. // Exposed widgets form
  1811. /**
  1812. * Form builder for the exposed widgets form.
  1813. *
  1814. * Be sure that $view and $display are references.
  1815. */
  1816. function views_exposed_form($form, &$form_state) {
  1817. // Don't show the form when batch operations are in progress.
  1818. if ($batch = batch_get() && isset($batch['current_set'])) {
  1819. return array(
  1820. // Set the theme callback to be nothing to avoid errors in template_preprocess_views_exposed_form().
  1821. '#theme' => '',
  1822. );
  1823. }
  1824. // Make sure that we validate because this form might be submitted
  1825. // multiple times per page.
  1826. $form_state['must_validate'] = TRUE;
  1827. $view = &$form_state['view'];
  1828. $display = &$form_state['display'];
  1829. $form_state['input'] = $view->get_exposed_input();
  1830. // Let form plugins know this is for exposed widgets.
  1831. $form_state['exposed'] = TRUE;
  1832. // Check if the form was already created
  1833. if ($cache = views_exposed_form_cache($view->name, $view->current_display)) {
  1834. return $cache;
  1835. }
  1836. $form['#info'] = array();
  1837. if (!variable_get('clean_url', FALSE)) {
  1838. $form['q'] = array(
  1839. '#type' => 'hidden',
  1840. '#value' => $view->get_url(),
  1841. );
  1842. }
  1843. // Go through each handler and let it generate its exposed widget.
  1844. foreach ($view->display_handler->handlers as $type => $value) {
  1845. foreach ($view->$type as $id => $handler) {
  1846. if ($handler->can_expose() && $handler->is_exposed()) {
  1847. // Grouped exposed filters have their own forms.
  1848. // Instead of render the standard exposed form, a new Select or
  1849. // Radio form field is rendered with the available groups.
  1850. // When an user choose an option the selected value is split
  1851. // into the operator and value that the item represents.
  1852. if ($handler->is_a_group()) {
  1853. $handler->group_form($form, $form_state);
  1854. $id = $handler->options['group_info']['identifier'];
  1855. }
  1856. else {
  1857. $handler->exposed_form($form, $form_state);
  1858. }
  1859. if ($info = $handler->exposed_info()) {
  1860. $form['#info']["$type-$id"] = $info;
  1861. }
  1862. }
  1863. }
  1864. }
  1865. $form['submit'] = array(
  1866. '#name' => '', // prevent from showing up in $_GET.
  1867. '#type' => 'submit',
  1868. '#value' => t('Apply'),
  1869. '#id' => drupal_html_id('edit-submit-' . $view->name),
  1870. );
  1871. $form['#action'] = url($view->display_handler->get_url());
  1872. $form['#theme'] = views_theme_functions('views_exposed_form', $view, $display);
  1873. $form['#id'] = drupal_clean_css_identifier('views_exposed_form-' . check_plain($view->name) . '-' . check_plain($display->id));
  1874. // $form['#attributes']['class'] = array('views-exposed-form');
  1875. // If using AJAX, we need the form plugin.
  1876. if ($view->use_ajax) {
  1877. drupal_add_library('system', 'jquery.form');
  1878. }
  1879. ctools_include('dependent');
  1880. $exposed_form_plugin = $form_state['exposed_form_plugin'];
  1881. $exposed_form_plugin->exposed_form_alter($form, $form_state);
  1882. // Save the form
  1883. views_exposed_form_cache($view->name, $view->current_display, $form);
  1884. return $form;
  1885. }
  1886. /**
  1887. * Implement hook_form_alter for the exposed form.
  1888. *
  1889. * Since the exposed form is a GET form, we don't want it to send a wide
  1890. * variety of information.
  1891. */
  1892. function views_form_views_exposed_form_alter(&$form, &$form_state) {
  1893. $form['form_build_id']['#access'] = FALSE;
  1894. $form['form_token']['#access'] = FALSE;
  1895. $form['form_id']['#access'] = FALSE;
  1896. }
  1897. /**
  1898. * Validate handler for exposed filters
  1899. */
  1900. function views_exposed_form_validate(&$form, &$form_state) {
  1901. foreach (array('field', 'filter') as $type) {
  1902. $handlers = &$form_state['view']->$type;
  1903. foreach ($handlers as $key => $handler) {
  1904. $handlers[$key]->exposed_validate($form, $form_state);
  1905. }
  1906. }
  1907. $exposed_form_plugin = $form_state['exposed_form_plugin'];
  1908. $exposed_form_plugin->exposed_form_validate($form, $form_state);
  1909. }
  1910. /**
  1911. * Submit handler for exposed filters
  1912. */
  1913. function views_exposed_form_submit(&$form, &$form_state) {
  1914. foreach (array('field', 'filter') as $type) {
  1915. $handlers = &$form_state['view']->$type;
  1916. foreach ($handlers as $key => $info) {
  1917. $handlers[$key]->exposed_submit($form, $form_state);
  1918. }
  1919. }
  1920. $form_state['view']->exposed_data = $form_state['values'];
  1921. $form_state['view']->exposed_raw_input = array();
  1922. $exclude = array('q', 'submit', 'form_build_id', 'form_id', 'form_token', 'exposed_form_plugin', '', 'reset');
  1923. $exposed_form_plugin = $form_state['exposed_form_plugin'];
  1924. $exposed_form_plugin->exposed_form_submit($form, $form_state, $exclude);
  1925. foreach ($form_state['values'] as $key => $value) {
  1926. if (!in_array($key, $exclude)) {
  1927. $form_state['view']->exposed_raw_input[$key] = $value;
  1928. }
  1929. }
  1930. }
  1931. /**
  1932. * Save the Views exposed form for later use.
  1933. *
  1934. * @param $views_name
  1935. * String. The views name.
  1936. * @param $display_name
  1937. * String. The current view display name.
  1938. * @param $form_output
  1939. * Array (optional). The form structure. Only needed when inserting the value.
  1940. * @return
  1941. * Array. The form structure, if any. Otherwise, return FALSE.
  1942. */
  1943. function views_exposed_form_cache($views_name, $display_name, $form_output = NULL) {
  1944. // When running tests for exposed filters, this cache should
  1945. // be cleared between each test.
  1946. $views_exposed = &drupal_static(__FUNCTION__);
  1947. // Save the form output
  1948. if (!empty($form_output)) {
  1949. $views_exposed[$views_name][$display_name] = $form_output;
  1950. return;
  1951. }
  1952. // Return the form output, if any
  1953. return empty($views_exposed[$views_name][$display_name]) ? FALSE : $views_exposed[$views_name][$display_name];
  1954. }
  1955. // ------------------------------------------------------------------
  1956. // Misc helpers
  1957. /**
  1958. * Build a list of theme function names for use most everywhere.
  1959. */
  1960. function views_theme_functions($hook, $view, $display = NULL) {
  1961. require_once DRUPAL_ROOT . '/' . drupal_get_path('module', 'views') . "/theme/theme.inc";
  1962. return _views_theme_functions($hook, $view, $display);
  1963. }
  1964. /**
  1965. * Substitute current time; this works with cached queries.
  1966. */
  1967. function views_views_query_substitutions($view) {
  1968. global $language_content;
  1969. return array(
  1970. '***CURRENT_VERSION***' => VERSION,
  1971. '***CURRENT_TIME***' => REQUEST_TIME,
  1972. '***CURRENT_LANGUAGE***' => $language_content->language,
  1973. '***DEFAULT_LANGUAGE***' => language_default('language'),
  1974. );
  1975. }
  1976. /**
  1977. * Implements hook_query_TAG_alter().
  1978. *
  1979. * This is the hook_query_alter() for queries tagged by Views and is used to
  1980. * add in substitutions from hook_views_query_substitutions().
  1981. */
  1982. function views_query_views_alter(QueryAlterableInterface $query) {
  1983. $substitutions = $query->getMetaData('views_substitutions');
  1984. $tables =& $query->getTables();
  1985. $where =& $query->conditions();
  1986. // Replaces substitions in tables.
  1987. foreach ($tables as $table_name => $table_metadata) {
  1988. foreach ($table_metadata['arguments'] as $replacement_key => $value) {
  1989. if (isset($substitutions[$value])) {
  1990. $tables[$table_name]['arguments'][$replacement_key] = $substitutions[$value];
  1991. }
  1992. }
  1993. }
  1994. // Replaces substitions in filter criterias.
  1995. _views_query_tag_alter_condition($query, $where, $substitutions);
  1996. }
  1997. /**
  1998. * Replaces the substitutions recursive foreach condition.
  1999. */
  2000. function _views_query_tag_alter_condition(QueryAlterableInterface $query, &$conditions, $substitutions) {
  2001. foreach ($conditions as $condition_id => &$condition) {
  2002. if (is_numeric($condition_id)) {
  2003. if (is_string($condition['field'])) {
  2004. $condition['field'] = str_replace(array_keys($substitutions), array_values($substitutions), $condition['field']);
  2005. }
  2006. elseif (is_object($condition['field'])) {
  2007. $sub_conditions =& $condition['field']->conditions();
  2008. _views_query_tag_alter_condition($query, $sub_conditions, $substitutions);
  2009. }
  2010. // $condition['value'] is a subquery so alter the subquery recursive.
  2011. // Therefore take sure to get the metadata of the main query.
  2012. if (is_object($condition['value'])) {
  2013. $subquery = $condition['value'];
  2014. $subquery->addMetaData('views_substitutions', $query->getMetaData('views_substitutions'));
  2015. views_query_views_alter($condition['value']);
  2016. }
  2017. elseif (isset($condition['value'])) {
  2018. $condition['value'] = str_replace(array_keys($substitutions), array_values($substitutions), $condition['value']);
  2019. }
  2020. }
  2021. }
  2022. }
  2023. /**
  2024. * Embed a view using a PHP snippet.
  2025. *
  2026. * This function is meant to be called from PHP snippets, should one wish to
  2027. * embed a view in a node or something. It's meant to provide the simplest
  2028. * solution and doesn't really offer a lot of options, but breaking the function
  2029. * apart is pretty easy, and this provides a worthwhile guide to doing so.
  2030. *
  2031. * Note that this function does NOT display the title of the view. If you want
  2032. * to do that, you will need to do what this function does manually, by
  2033. * loading the view, getting the preview and then getting $view->get_title().
  2034. *
  2035. * @param $name
  2036. * The name of the view to embed.
  2037. * @param $display_id
  2038. * The display id to embed. If unsure, use 'default', as it will always be
  2039. * valid. But things like 'page' or 'block' should work here.
  2040. * @param ...
  2041. * Any additional parameters will be passed as arguments.
  2042. */
  2043. function views_embed_view($name, $display_id = 'default') {
  2044. $args = func_get_args();
  2045. array_shift($args); // remove $name
  2046. if (count($args)) {
  2047. array_shift($args); // remove $display_id
  2048. }
  2049. $view = views_get_view($name);
  2050. if (!$view || !$view->access($display_id)) {
  2051. return;
  2052. }
  2053. return $view->preview($display_id, $args);
  2054. }
  2055. /**
  2056. * Get the result of a view.
  2057. *
  2058. * @param string $name
  2059. * The name of the view to retrieve the data from.
  2060. * @param string $display_id
  2061. * The display id. On the edit page for the view in question, you'll find
  2062. * a list of displays at the left side of the control area. "Master"
  2063. * will be at the top of that list. Hover your cursor over the name of the
  2064. * display you want to use. An URL will appear in the status bar of your
  2065. * browser. This is usually at the bottom of the window, in the chrome.
  2066. * Everything after #views-tab- is the display ID, e.g. page_1.
  2067. * @param ...
  2068. * Any additional parameters will be passed as arguments.
  2069. * @return array
  2070. * An array containing an object for each view item.
  2071. */
  2072. function views_get_view_result($name, $display_id = NULL) {
  2073. $args = func_get_args();
  2074. array_shift($args); // remove $name
  2075. if (count($args)) {
  2076. array_shift($args); // remove $display_id
  2077. }
  2078. $view = views_get_view($name);
  2079. if (is_object($view)) {
  2080. if (is_array($args)) {
  2081. $view->set_arguments($args);
  2082. }
  2083. if (is_string($display_id)) {
  2084. $view->set_display($display_id);
  2085. }
  2086. else {
  2087. $view->init_display();
  2088. }
  2089. $view->pre_execute();
  2090. $view->execute();
  2091. return $view->result;
  2092. }
  2093. else {
  2094. return array();
  2095. }
  2096. }
  2097. /**
  2098. * Export a field.
  2099. */
  2100. function views_var_export($var, $prefix = '', $init = TRUE) {
  2101. if (is_array($var)) {
  2102. if (empty($var)) {
  2103. $output = 'array()';
  2104. }
  2105. else {
  2106. $output = "array(\n";
  2107. foreach ($var as $key => $value) {
  2108. $output .= " " . views_var_export($key, '', FALSE) . " => " . views_var_export($value, ' ', FALSE) . ",\n";
  2109. }
  2110. $output .= ')';
  2111. }
  2112. }
  2113. elseif (is_bool($var)) {
  2114. $output = $var ? 'TRUE' : 'FALSE';
  2115. }
  2116. elseif (is_string($var) && strpos($var, "\n") !== FALSE) {
  2117. // Replace line breaks in strings with a token for replacement
  2118. // at the very end. This protects multi-line strings from
  2119. // unintentional indentation.
  2120. $var = str_replace("\n", "***BREAK***", $var);
  2121. $output = var_export($var, TRUE);
  2122. }
  2123. else {
  2124. $output = var_export($var, TRUE);
  2125. }
  2126. if ($prefix) {
  2127. $output = str_replace("\n", "\n$prefix", $output);
  2128. }
  2129. if ($init) {
  2130. $output = str_replace("***BREAK***", "\n", $output);
  2131. }
  2132. return $output;
  2133. }
  2134. /**
  2135. * Prepare a string for use as a valid CSS identifier (element, class or ID name).
  2136. * This function is similar to a core version but with more sane filter values.
  2137. *
  2138. * http://www.w3.org/TR/CSS21/syndata.html#characters shows the syntax for valid
  2139. * CSS identifiers (including element names, classes, and IDs in selectors.)
  2140. *
  2141. * @param $identifier
  2142. * The identifier to clean.
  2143. * @param $filter
  2144. * An array of string replacements to use on the identifier.
  2145. * @return
  2146. * The cleaned identifier.
  2147. *
  2148. * @see drupal_clean_css_identifier()
  2149. */
  2150. function views_clean_css_identifier($identifier, $filter = array(' ' => '-', '/' => '-', '[' => '-', ']' => '')) {
  2151. // By default, we filter using Drupal's coding standards.
  2152. $identifier = strtr($identifier, $filter);
  2153. // Valid characters in a CSS identifier are:
  2154. // - the hyphen (U+002D)
  2155. // - a-z (U+0030 - U+0039)
  2156. // - A-Z (U+0041 - U+005A)
  2157. // - the underscore (U+005F)
  2158. // - 0-9 (U+0061 - U+007A)
  2159. // - ISO 10646 characters U+00A1 and higher
  2160. // We strip out any character not in the above list.
  2161. $identifier = preg_replace('/[^\x{002D}\x{0030}-\x{0039}\x{0041}-\x{005A}\x{005F}\x{0061}-\x{007A}\x{00A1}-\x{FFFF}]/u', '', $identifier);
  2162. return $identifier;
  2163. }
  2164. /**
  2165. * Implement hook_views_exportables().
  2166. */
  2167. function views_views_exportables($op = 'list', $views = NULL, $name = 'foo') {
  2168. $all_views = views_get_all_views();
  2169. if ($op == 'list') {
  2170. foreach ($all_views as $name => $view) {
  2171. // in list, $views is a list of tags.
  2172. if (empty($views) || in_array($view->tag, $views)) {
  2173. $return[$name] = array(
  2174. 'name' => check_plain($name),
  2175. 'desc' => check_plain($view->description),
  2176. 'tag' => check_plain($view->tag)
  2177. );
  2178. }
  2179. }
  2180. return $return;
  2181. }
  2182. if ($op == 'export') {
  2183. $code = "/**\n";
  2184. $code .= " * Implement hook_views_default_views().\n";
  2185. $code .= " */\n";
  2186. $code .= "function " . $name . "_views_default_views() {\n";
  2187. foreach ($views as $view => $truth) {
  2188. $code .= " /*\n";
  2189. $code .= " * View " . var_export($all_views[$view]->name, TRUE) . "\n";
  2190. $code .= " */\n";
  2191. $code .= $all_views[$view]->export(' ');
  2192. $code .= ' $views[$view->name] = $view;' . "\n\n";
  2193. }
  2194. $code .= " return \$views;\n";
  2195. $code .= "}\n";
  2196. return $code;
  2197. }
  2198. }
  2199. /**
  2200. * #process callback to see if we need to check_plain() the options.
  2201. *
  2202. * Since FAPI is inconsistent, the #options are sanitized for you in all cases
  2203. * _except_ checkboxes. We have form elements that are sometimes 'select' and
  2204. * sometimes 'checkboxes', so we need decide late in the form rendering cycle
  2205. * if the options need to be sanitized before they're rendered. This callback
  2206. * inspects the type, and if it's still 'checkboxes', does the sanitation.
  2207. */
  2208. function views_process_check_options($element, &$form_state) {
  2209. if ($element['#type'] == 'checkboxes' || $element['#type'] == 'checkbox') {
  2210. $element['#options'] = array_map('check_plain', $element['#options']);
  2211. }
  2212. return $element;
  2213. }
  2214. /**
  2215. * Trim the field down to the specified length.
  2216. *
  2217. * @param $alter
  2218. * - max_length: Maximum length of the string, the rest gets truncated.
  2219. * - word_boundary: Trim only on a word boundary.
  2220. * - ellipsis: Show an ellipsis (...) at the end of the trimmed string.
  2221. * - html: Take sure that the html is correct.
  2222. *
  2223. * @param $value
  2224. * The string which should be trimmed.
  2225. */
  2226. function views_trim_text($alter, $value) {
  2227. if (drupal_strlen($value) > $alter['max_length']) {
  2228. $value = drupal_substr($value, 0, $alter['max_length']);
  2229. // TODO: replace this with cleanstring of ctools
  2230. if (!empty($alter['word_boundary'])) {
  2231. $regex = "(.*)\b.+";
  2232. if (function_exists('mb_ereg')) {
  2233. mb_regex_encoding('UTF-8');
  2234. $found = mb_ereg($regex, $value, $matches);
  2235. }
  2236. else {
  2237. $found = preg_match("/$regex/us", $value, $matches);
  2238. }
  2239. if ($found) {
  2240. $value = $matches[1];
  2241. }
  2242. }
  2243. // Remove scraps of HTML entities from the end of a strings
  2244. $value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value));
  2245. if (!empty($alter['ellipsis'])) {
  2246. $value .= t('...');
  2247. }
  2248. }
  2249. if (!empty($alter['html'])) {
  2250. $value = _filter_htmlcorrector($value);
  2251. }
  2252. return $value;
  2253. }
  2254. /**
  2255. * Adds one to each key of the array.
  2256. *
  2257. * For example array(0 => 'foo') would be array(1 => 'foo').
  2258. */
  2259. function views_array_key_plus($array) {
  2260. $keys = array_keys($array);
  2261. rsort($keys);
  2262. foreach ($keys as $key) {
  2263. $array[$key+1] = $array[$key];
  2264. unset($array[$key]);
  2265. }
  2266. asort($array);
  2267. return $array;
  2268. }
  2269. /**
  2270. * Report to CTools that we use hook_views_api instead of hook_ctools_plugin_api()
  2271. */
  2272. function views_ctools_plugin_api_hook_name() {
  2273. return 'views_api';
  2274. }
  2275. // Declare API compatibility on behalf of core modules:
  2276. /**
  2277. * Implements hook_views_api().
  2278. *
  2279. * This one is used as the base to reduce errors when updating.
  2280. */
  2281. function views_views_api() {
  2282. return array(
  2283. // in your modules do *not* use views_api_version()!!!
  2284. 'api' => views_api_version(),
  2285. 'path' => drupal_get_path('module', 'views') . '/modules',
  2286. );
  2287. }
  2288. if (!function_exists('aggregator_views_api')) {
  2289. function aggregator_views_api() { return views_views_api(); }
  2290. }
  2291. if (!function_exists('book_views_api')) {
  2292. function book_views_api() { return views_views_api(); }
  2293. }
  2294. if (!function_exists('comment_views_api')) {
  2295. function comment_views_api() { return views_views_api(); }
  2296. }
  2297. if (!function_exists('field_views_api')) {
  2298. function field_views_api() { return views_views_api(); }
  2299. }
  2300. if (!function_exists('file_views_api')) {
  2301. function file_views_api() { return views_views_api(); }
  2302. }
  2303. if (!function_exists('filter_views_api')) {
  2304. function filter_views_api() { return views_views_api(); }
  2305. }
  2306. if (!function_exists('image_views_api')) {
  2307. function image_views_api() { return views_views_api(); }
  2308. }
  2309. if (!function_exists('locale_views_api')) {
  2310. function locale_views_api() { return views_views_api(); }
  2311. }
  2312. if (!function_exists('node_views_api')) {
  2313. function node_views_api() { return views_views_api(); }
  2314. }
  2315. if (!function_exists('poll_views_api')) {
  2316. function poll_views_api() { return views_views_api(); }
  2317. }
  2318. if (!function_exists('profile_views_api')) {
  2319. function profile_views_api() { return views_views_api(); }
  2320. }
  2321. if (!function_exists('search_views_api')) {
  2322. function search_views_api() { return views_views_api(); }
  2323. }
  2324. if (!function_exists('statistics_views_api')) {
  2325. function statistics_views_api() { return views_views_api(); }
  2326. }
  2327. if (!function_exists('system_views_api')) {
  2328. function system_views_api() { return views_views_api(); }
  2329. }
  2330. if (!function_exists('tracker_views_api')) {
  2331. function tracker_views_api() { return views_views_api(); }
  2332. }
  2333. if (!function_exists('taxonomy_views_api')) {
  2334. function taxonomy_views_api() { return views_views_api(); }
  2335. }
  2336. if (!function_exists('translation_views_api')) {
  2337. function translation_views_api() { return views_views_api(); }
  2338. }
  2339. if (!function_exists('user_views_api')) {
  2340. function user_views_api() { return views_views_api(); }
  2341. }
  2342. if (!function_exists('contact_views_api')) {
  2343. function contact_views_api() { return views_views_api(); }
  2344. }