diff --git a/sites/all/modules/views/CHANGELOG.txt b/sites/all/modules/views/CHANGELOG.txt new file mode 100644 index 0000000..4243d34 --- /dev/null +++ b/sites/all/modules/views/CHANGELOG.txt @@ -0,0 +1,626 @@ +CHANGELOG for Views 2 for Drupal 6 + +Views 2.x-dev + Bugs fixed: + o #768060 by EmanueleQuinto: Better empty field replacement that continues to respect other rewriting rules. + o #781050 by lewisvance: Performance improvement in unpack_options(). + o #734706 by joachim: Use proper access control to prevent unregistered users from seeing links to inaccessible contact pages. + o #827188 by dereine: Comment ID field should be numeric, not the generic field handler. + o #827780 by dereine: Fix RSS feed live preview not getting proper PRE tags. + o #594402 by joachim: Clarify text on "Moderation" field. + o #839214 by AlexisWilke: Improve encoding on help text snippets. + o #792582 by ducktape: Validate that view names are not purely numeric, which cannot be loaded by views_get_view(). + o #848506 by dereine: Add aggregator item ID as an aggregator field. + o #798764 by setvik: Fix broken AJAX in some IE circumstances due to odd IE behavior. + o #827300 by dereine: Fix authenticated users showing up as "No role" in role summary view. + o #611728 by incrn8: Respect db_rewrite_sql when choosing taxonomy terms for taxonomy filter. + o #746846 by lavamind: url encoding on options could cause visual problems in jump menu. + o #859368 by dereine: Click sort using wrong add_orderby() line caused some click sorts to fail. + o #852854 by bojanz: Grammar fix on taxonomy default argument help text. + o #526106 by Blackice2999: Fix occasional off-by-one-day problem with date arguments. + o #863666 by dereine: Revert button redirects to wrong place after view is reverted. + o #703980 by jmiccolis: Custom date needs to better support "r". + o #692988 by joachim: Eliminate an unnecessary query in taxonomy filter. + o #812608 by drunken monkey: Views outputs unquoted version in exports. + o #402944 by drewish: Cache views block list to reduce overhead when listing blocks. + o #832954 by dww: Fixed bug that was modifying global user->roles inside argument_validate_user. + o #889770 by tim.plunkett: Empty fields not always hidden based on row settings. + o #894618 by gilgabarr: Date "is between" filter not properly handled. + o #762484 by master-of-magic: Link to node status could be lost between rows. + o #908272 by jaydub: Fix incorrect length of view description form field. + o #772782 by mstrelan: Menu normal item menu should default to system default menu rather than "navigation". + o #917916 by MyXelf: break delimiter not removed from formatted output. + o #571234 by dereine: Better handling of invalid exposed filters or other methods that cause a view to abort during the build process. + o #685554 by MyXelf: Illegal characters in View tag translated improperly when used in theming templates. + o #508832 by nick_vh: Documentation improvement on templates. + o #807540 by gfrenoy: Proper use of db_decode_blob() on serialized fields. + o #936828 by xjm: Empty field replacement not quite always working. + o #872000 by NaX: Comment edit field needs option to set destination so it can work like comment edit field. + o #799580 by dereine: api version of views exports should use views_api_version() not hardcoded number. + o #884440 by Amitaibu: Improve token encoding to eliminate double html entity encoding. + o #870828 by dereine: Typo in ajax form wrapper. + o #865482 by dereine: RSS options form does not include override. + o #366886 by Scott Reynolds: For "last comment time" if "count zero is empty" is set, use empty text for nodes with no comments. + o #611086 by dereine: add -url token to files that can fetch proper URLs with private filesystems. + o #635336 by dereine: Remove unused fields from views. + o #813422 by dereine and killes: Improved time-based caching expiration. + o #795270 by dereine: Remove unnecessary links to sections that will have no settings. + o #807540 Revert: Proper use of db_decode_blob() on serialized fields. + o #829550 by hefox: Better testing of batch form use by exposed filters. + o #570618 by dereine: Enforce denying access to disabled views more strongly. + o #667014 by dereine: Prevent notice with relationships and node row style if relationship has no endpoint node. + o #514128 by dylanvaughn: Use of for (i in foo) for arrays in javascript fails if other software is modifying the Array prototype. + o #755342 by jcmarco: Improve SQL date field handling. + o #338893 by dereine: Aggregator argument not always properly converted to title. + o #738172 by dereine: Fields rewritten to be links with just a fragment did not work. + o #514128 reverted. + o #787184 introduce the long awaited "Update and Override" button. + o #963382 by aidanlis: Fix typo in mathematical expression field help text. + o #713078 by achaux: Aggregator not properly using allowed tags from core. + o #944680 by rvilar: Properly t() untranslated string. + o #881680 by brianV and longwave: Avoid unnecessary invoking of view objects for argument validation when no argument validation is necessary. + o #767244 by Magnus: Fix some untranslatable strings due to less than and greater than characters. + o #881060 by benoit.borrel: Fix incorrect code sample on views_join documentation. + o #938806 by jenlampton: Node: title field should link to node by default. + o #956654 by mdupont: Translation for "offset" field in dates needed work. + o #931390 by dww: Optimize boolean logic by using "= 1" rather than "<> 0" for faster queries. + o #567918 by iamjon: Improve documentation for token replacement. + o #881468 by longwave: Improve performance by static caching results of argument validation because menu likes to double validate things. + o #964266 by dereine: cache_expire() missing $type. + o #477984 by demeritcowboy, fatstar415, mike dodd, dagmar: Properly handle value for "empty" and "not empty" special operators. + o #910864 by Bevan, dereine: exposed filter blocks should not be cached by core block caching. + o #970198 by kbk: Improve bulk export docs for handling PHP files. + o #741234 by voxpelli: Arguments should check for NULL along with empty string to find empty values. + o #768060 by EmmanueleQuinto, xjm, others: Make sure that render alter options do not accidentally get blown up for empty fields. + o #847724 by dereine: Allow jump menu "Summary" style to customize choose text, just like the regular summary style. + o #871578 by dereine: Comment "new" might not work right without a comment count field. + o #494380 by vaish: Problems with ajax and the same view displayed multiple times. + o #835544 by iamjon: export broke if key contained an apostrophe. + o #941990 by master-of-magic: Link to node when using relationships could occasionally lose track and create bad links. + o #965496 by ayalon: Update and Override broke validation of most views admin forms. + o #976200 by Bevan: [Edit View] links not always clickable. + o #979046 by travist: Fix PHP 5.3 problem in views_access with no arguments. + o #983606 by jonathan1055: Breadcrumb disappears on bulk export results. + o #769458 by anrikun: Fix double encoding of alt/title text on link rewriting. + o #318944 by dereine: Prevent warning in table view when user has no permission to view any fields. + o #416178 by dereine: Profile field checkboxes did not properly filter false values. + o #738792 by dereine: Delete button should be disabled when ajax form is open, just like save button. + o #898990 by dereine: Fix bad SQL generated on related terms relationship if no vocabularies selected. + o #684608 by dagmar: Default tid plugin was not properly backported from 3.x and so did not work. + o #468484 by dereine: Filter by unread not relationship safe. + o #909886: -Any- option shows up on boolean exposed filters even when not optional. + o #751308 by dereine: Provide an administrator warning when option_definition() data is incorrect. + o #817360 by John Morahan: Have Analyze button warn if view has no access control. + o #833220 by dereine: Properly validate value on date filter. + o #779668 by esteewhy: Fix not technically valid use of break statements. + o #751308 Revert: Provide an administrator warning when option_definition() data is incorrect. + o by dereine: Fix fatal error in the field term_node_tid handler. + o #995966 by dereine: Fix taxonomy field handler. + o #996634 by das-peter: Add missing rel to option_definition of the field handler. + o #808016 by dereine: Clarify short/medium/long date formats. + o #610418 by joachim: Add handler descriptions to handler edit forms. + o #759082 by dereine: Prevent invalid argument warning with no relationships. + o #946368 by dereine: User argument default ignoring node author checkbox in some cases. + o #777072 by Agileware: Option missing when using argument validator. + o #608926 by Longwave: Remove unused theme("nodate") functionality. + o #497936: Profile fields with dashes in their names cause bad queries. + o #759082 by dereine: Fix whitescreen due to incorrect relationship loop code. + o #1001542 by mikeytown2: view::set_display() has wrong return code when it fails. + o #996486 by geoffreyr: Improperly written SQL could crash when rewritten by tac_lite. + o #953718 by linclark: Register the special "broken" handlers for use with fields without handlers. + o #722330 by dereine: Views should include core version for updates. + o #1013170 by das-peter: Fix broken view::preview which was broken on #1001542. + o #452384 by sammys: Another PHP 5.3 fix. + o #696550: Taxonomy validator should always set title when it successfully validates. + o #839236: Fields named "buttons" would disappear from the rearrange UI due to conflict with the buttons on the form. + o #780768 by dereine: lack of clean URLs breaks some preview. + o #672864 by dboulet: cols- class incorrect on table, grid. + o #839810 by marcp: Get UID from URL argument default plugin should accept uids from Views pages. + o #1035168 by Ao: Fix strict warning in unread node filter. + o #988680 by mikeytown2: Fix Views memory leak with attachments. + o #1007376 by dereine: Jump menu was not correctly supporting offsets. + o #1019826 by penguin25: Respect contact page access overrides when displaying contact link. + o #534452 by dereine: Remove non-functional "optional" setting on string filters. + o #747782 by dereine: Improve jump menu grouping. + o #1096548 by dww: Fix convert of taxonomy fields. + o #1096366 by jamsilver: Role access plugin: Replacing array_unshift() with reset(). + + New features + o #841260: Introduce a field to evaluate math expressions. Relies on CTools 1.7 (not yet released). + o #727894 by stella: Give stronger classes on exposed widgets for easier theming. + o #464490 by dereine: Allow links to specify that they are absolute. + o #317653 by Steven Jones: Allow singular/plural formatting in numeric fields. + o #397252 by thekevinday: Allow "glossary" type views to do case insensitive searches. + o #843866 by dagmar: Allow summary views to specify their path rather than assuming the view path all the time. + o #348975 by dereine: Allow cloning of displays. + o #930714 by brad.bulger: Add aggregator GUID field. + o #785236 by e_log: Add aggregator field item id as a field. + o #835934 by dereine: Provide relationship from files to users. + o #935388 by infojunkie: Add post_build and post_execute hooks similar to post_render. + o #751970 by dereine: View list form auto submit on change. + o #868972 by dereine: Add a "summary" attribute for accessibility on table and grid styles. + o #607942 by dashton: Support "rel" attribute in link rewriting. + o #909332 by dereine: Add col-first and col-last classes to grid style. + o #368687 by dereine: Allow a relationship from node revision to master node. + o #867636 by chromix: Give jump menu an option to set default value to current path. + o #905712 by dagmar: Add Published/Not published as text options to published field. + o #970514 by moshe, dereine: Provide basic drush integration for views. + o #962564 by joshuajabbour: Allow link attributes to be rewritten (internally). + o #1054272 by dagmar: String filters are non optional anymore. + o #1079178 by Manuel Garcia: Provide a views revert drush command. + o #1096834 by dww: Allow importing views code that starts with 'roles. + o #723454 by dereine: Upgrade from 5.0 could cause blocks for views with long names to lose configuration. + o SA-CONTRIB-2010-067: Fix CSRF and XSS vulnerabilities. + +Views 2.10 (Apr 08, 2010) + Bug fixes: + o #765760 by crea: New setting for raw node type had wrong default. + o #682888 by jcmarco: With zen and zen subthemes, the new $classes array could fail for row styles. + o #765340 by dereine: token accidentally removed by html entity stripping from URLs. + o #765352: Fix for postgress versions prior to 8.3 which caused data loss in update.php. Note: This will not repair lost data. If you experienced this you must restore your views_display table from backup. + o #766046: Live preview broken right after adding new display. + o #740130: #561892 not applied correctly, caused the 'rewrite' checkbox to be ignored and rewrite always used. + o #765296: field IDs could get out of sync, causing render path to try to render a field that did not exist leading to whitescreens. + +Views 2.9 (Apr 07, 2010) + Bug fixes: + o #650152: Book: Top Level Book relationship broken by earlier patch and caused broken query. + o #651244 by dagmar: Other instances of are not translatable and should not be run trhough t(). + o #653628: init declaration for views_handler_filter_many_to_one() did not match parent init. + o #657700: Fixed 'Override normal sorting if click sorting is used' setting on the table style plugin that was broken by #622602. + o #473698 by jrglasgow: Fix error in help text regarding custom theming. + o #387448 by joachim: Provide better help text to describe how to use sticky sort. + o #652716 by dagmar: "no single" flag on filter objects not completely respected, causing improper default filters. + o #621780 by PaulMagrath: Even/Odd classes wrong with grouping due to row numbering no longer being sequential. + o #642328 by dboulet: Always include views.css since a site using Views probably uses it in blocks anyway. + o #629840 by fuerst: Search filter caused bad query on PostgreSQL. + o #329390: views_break_phrase could break under PHP4 due to reference error. + o #652742: Replacement pattern tokens for multiple fields did not work. + o #659510 by Souvent22 and dereine: glossary AJAX broken. + o #335599 by miro_dietiker: Remove the 95% width constraint on the admin hover links to be nicer to themes. + o #670308 by Mike Wacker: Make views_get_view() properly set disabled flag when retrieving default views. + o #536910 by dereine: Theme and language should be taken into account during caching. + o #627402 by dereine: Aggregator description needed more controllable input filtering. + o #416264 by bec: Dependency processing could cause exposed forms to disappear if used multiple times on the same page. + o #657442 by nicholasThompson and dagmar: Include "mail" field in user picture so that modules that need this do not break when rendering picture in Views. + o #329044 by gordon: Check to see if access plugin exists before using to prevent whitescreens. + o #455364 by sdrycroft: Prevent modules trying to define the same default view name from breaking everything. + o #422434 by BWPanda: Correct (NULL) to (NOT NULL) in varios operator descriptions for empty/not empty. + o #692428 by Roi Danton: Documentation typo fix. + o #713210 by dereine: Node language settings could persist for subsequent rows if they should not have had a language. + o #674772 by joachim: Unable to distinguish profile.module fields with same name in different profile categories. + o #727798 by SteveReher: Fix typo in overrides.html documentation. + o #621980 by yhahn: Namespace tabs.js to guarantee no conflicts with jQuery UI. + o #684656 by yhahn: Prevent Views from performing an unneeded variable_set() during block list. + o #455364 by iva2k: Default views were getting loaded twice. + o #737120 by james.williams: Fix help text for date offsets which gave incorrect information. + o #737118 by DeFr: Allow API calls to delete to not clear the views cache to facilitate batch operations. + o #673852 by yhahn: Allow access plugins to choose whether or not "access all views" should be used. + o #546586 by jeffschuler: String 0 values were being treated as empty therefore not displayed as fields. + o #651274 by dagmar: Show relationship labels in field lists for style config forms. + o #531686 by jweowu: Update process failed to properly track its history, causing errors when updating from really old sites. + o #638004 by stBorchert and BillyMG: If a field "Output as link" ends up with an empty path, do not actually print an empty link. + o #657384 by smoothify: Under rare circumstances, date default argument could get wrong value. + o #658842 by tomgf: Provide a proper ellipsis instead of "...". + o #662654 by dereine: Do not use query to load/validate a user if the user happens to be the logged in user. + o #640862 by dereine: Properly clear feed icon when cloning a view to prevent duplicate feed icons in attachments. + o #672044 by moshebeeri: Right-To-Left for views.css. + o #677936 by mr.baileys: "views-row-last" class accidentally omitted on grids with just one row. + o #673184 by markus petrux: Default views not always properly loaded by language. + o #433948 by dereine: "numeric" => FALSE not properly supported in handler definitions. + o #708618 by thsutton: Friendlier message when a handler is missing. + o #701588 by dereine: Delete button should say Revert on Overridden views. + o #508124 by dereine: "accept_null" should have been "accept null" in boolean filter definitions. + o #513396 by yhager: Attempt multi-byte safety for "trim at word boundary" setting. + o #418230 by Scott Reynolds: Views adds wrong nid with "Node: Has new content". + o #558602 by dboulet and Crashtest_: Summary views should provide "active" class on links properly. + o #496634 by dereine: Fix long-standing issue of "0" not being a valid argument for multiple integer CCK types. + o #521954 by Agileware: Allow taxonomy breadcrumbs to link to actual taxonomy page instead of back to view. + o #528838 by zzolo: If exposed form is in a block, and the form does not validate, ensure the form does not render twice. + o #727304 by mariusz.slonina: User edit link was disallowing users from editing themselves. + o #733142 by dereine: Link path field restricts input to too few characters for long links. + o #675264 by peck66: Freeform profile list field did not output properly. + o #663372 by dan.nsk: Allow tokens to work in the "target" field during link rewriting. + o #747418 by dereine: Fix taxonomy term ID bug introduced in #496634. + o #466250 by alex_b and dereine: Enlarge views_display field to prevent heavy displays from losing data. + o #689780 by deviantintegral: AJAX scrolling could go to wrong place. + + Other changes: + o #570558 by yhahn: Segment default views caching to conserve memory used by Views during normal operation. + o #661676 by dagmar: Improve error handling during AJAX failures. + o #685622 by dereine: Field to provide link to a node revision. + o #484600 by dereine: Ability to disable the automatic live preview. + o #716236 by jmiccolis: Allow default menu tabs to also have menu entries. + o #550132 by tha_sun: Allow plugins to better control the callbacks used for page type displays. + o #548292 by mikeker: Create a "Node: path" field that can be used to display the aliased path to a node. + o #666912 by dereine: Prevent imports of views created by newer, incompatible versions of Views. + o #672864 by dereine: Add a column count class to the table style for themers to more easily do generic targeting. + o #552498 by dereine: User email as an argument. + o #515324 by dereine: Make API documentation easier to find. + o #488314 by yhahn: Allow relationship to fetch nodes from terms. + o #685938 by dereine: Sync preview widget to current tab to reduce WTFs when previewing the wrong display. + o #739448 by brunodbo: Allow "Jump Menu" to set the "Choose" text in style options. + o #730454 by stella: Add "translate" link along with view/edit/delete links on nodes. + o #474174 by dereine: Analyze will now warn about "node/%" not being a valid path for Views. + o #619642 by dereine: Allow argument for user language. + o #675154 by dereine and Crashtest_: Improvements to rendering trim text and tag stripping. + o #730810 by alex_b: Add fields for authmap table. + o #666920 by dereine: Include actual API version in exports. + o #689446 by dereine: Allow use of l() in link rewriting to not check for aliases. + o #684608 by dereine: Default argument to acquire a taxonomy tid from the URL or a node in the URL. + o #496840 by dereine: Allow boolean filters to define additional output formats and provide an additional for Node: Sticky. + o #689260 by dereine: Allow "Node type" field to output the machine name as well as the human readable name. + o #740686 by jacine: Introduce $classes array in views-view.tpl.php. + o #582348 by dagmar: Allow UI setting a CSS class for views-view.tpl.php + o #682030 by killes: Add term relation table integration. + o #339758 by dereine: Better handling for display of set options in multiple choice filters. + o #330160 by aditya_kristanto: Improve text to make it easier to find where to edit the view description. + o #765022: SA-CONTRIB-2010-036: Fix XSS and PHP vulnerabilities. + +Views 2.8 (Dec 02, 2009) + Bug fixes: + o #622602: Missing ORDER BY in some views with tables due to incorrect test for default table sorting. + o #623498 by marcp: total_rows should be filled in if fetching all records. + o #535206: Attachment displays repeat exposed filters because exposed filters were left hanging around during cloning. + o #450346 by lefnire: Inherit Exposed Filters sometimes hides part of the parent exposed filters + o #550560 by donquixote: Fix unterminated string in views.help.ini that breaks under php 5.3 + o #592476 by Garrett Albright: Remove redundant CSS from views-list.css + o #366250 by Markus Petrux: Fix glitches with tabledrag and jQuery 1.3. + o #581616 by cangeceiro: Defend text color from themes in Views UI. + o #589484 by Markus Petrux: External styles could not properly provide advanced help files. + o #494490 by Niels Hackius: User picture incorrectly set as an inline element when it should be block. + o #616956 by neochief: Exposed form labels should have "for" keyword. + o #620046 by cedric: Date validate handler does not fallback properly causing sporadic improper validation. + o #628330 by dereine: Do not print n/a for empty formatted fields. + o #515564: Views UI would fail to rearrange with > 25 fields. + o #452384: Fix PHP 5.3 compatibility. + o #619884: Fix incorrect grouping for styles other than table. + o #539498: "Comments: Node link" did not work at all. Replaced with "Node: Add comment link" which is what that was supposed to do. + o #638916 by dereine: views.help.ini strings need quoting to continue to work in PHP 5.3 + o #636988 by Steve McKenzie: Wrong ajax data could be sent in rare circumstances when using AJAX paging. + o #576386 by jmorahan: Fix book sort help text to be more accurate by not telling you to do something that will not work. + o #348130 by dereine: "" should not be translatable since it looks like HTML. + o #630430 by cafuego: Fix typo in argument text. + o #370651: Make Views AJAX work with mod_security enabled. + o #648438 by dww: In rare circumstances, unnecessary term_node tables could be joined in when adding term_data relationships. + o #639430 by dagmar: theme.inc warning when comments are displayed without links. + + Other changes: + o #580320 by chaps2: Allow "always use more link" setting. + o #363516 by dagmar: Validate the uniqueness of exposed filter identifiers. + o #584880 by drewish: Wrong base field declarations fixed. + o #480162 by dereine: Count whitespace fields as empty for hiding labels. + o #623580 by dagmar: Move can_expose() method to base handler to deal with validation change made in previous commit. + o #626422 by vgarvardt: Static caching of validated taxonomy terms to improve taxonomy_term performance. + o #622608: Allow attachments to inherit pager data. + o #495606 by Roi Danton and dereine: Introduce views_get_view_result() as a fast way to get just the results of a view. + o #614040 by dereine: Introduce hook_views_plugins_alter() + +Views 2.7 (Nov 02, 2009) + Bug fixes: + o Table style when not overriding sorts put sorts in wrong order. + o #488908 by sl27257: "Node: Has new content" only worked when exposed. + o #451110 by wonder95: Fixed missing word in transform case help text. + o #385904 by JirkaRybka: Prevent duplication of id edit-submit on views exposed form. + o #489888 by TheRec: Remove erroneous "alt" attribute from when using link rewriting. + o #499078 by Darren Oh: Make sure theme is initialized for pre_render hook. + o #490516 by v_20q: Some fields not properly being marked as translatable due to option unpacking bug. + o #484222 by dereine: Attachment displays were ignoring access settings. + o #503098 by Davide Goode: Feed displays should have link displays since they link to a page display. + o #381346 by ayalon: Allow Taxonomy: Tid as a field, which is now needed for rewrites which may need tids. + o #485296 by overall and deekayen: Remove unnecessary t() call. + o #460838 by Darren Oh: Make DISTINCT more distinct. + o #503774 by dereine: Cache time failed to return the proper cutoff time. + o #506098: Table sorting with no default was overriding sorts even tho it was not supposed to. + o #407538: Ensure views_break_phrase() will stop providing warnings on empty strings. + o #420850 by dereine: Commas should not be used to separate items in a profile list field. + o #482162 by agentrickard: link path needed further sanitization to properly encode special characters. + o Tables would not accept 0 as having data so columns with zeroes would lose data when merging with other columns. + o #529164: Fatal typo in profile list field. + o #537870 by dww: Fixed a bug in the [uplodate_fid-size] token where format_size() was called on it twice. + o #510910 by mfb: Fixed bug where multiple fields sharing a column in a table was broken so only the final field would display. + o #546586 by dww: Fixed bugs that prevented '0' being a valid rewrite text or empty text for a view field. Also fixes a logic bug regarding the handling of the 'Count the number 0 as empty' setting. + o #507884 by TheRec: Removed matching title (alt) attribute on node links.\ + o #468370 by emackn: Proper timezone support on postgres. + o #508124 by voxpelli: Optionally allow boolean to treat NULL as FALSE. + o #487528 by dereine: Fix typo in 'Maximum length' field instructions. + o #303800 by Justin W Freeman: Improve dashes to spaces transformation. + o #538530 by elcuco: Views export textareas should be LTR. + o #538204 by dereine: User picture should be sortable. + o #540122 by stella: Attachment displays should attach even if arguments caused the primary display to abort. + o #544098 by joachim: Fix validation quirks with defaulted handlers. + o #485872 by dereine: Make sure views.css is always loaded for all users. + o #442982 by killes: Make destroy() method more robust so that views are more readily reused. + o #520558 by bdurbin: node access filter not properly checking 'view'. + o #535424 by Hugo Wetterberg: Download file link could provide empty a tag if no file is available. + o #554000 by killes: Preview checking wrong flag for preview state causes feeds to display incorrectly when embedded. + o #554016 by webchick: views_embed_view() should check view access. + o #523222 by gpk: Contact link should not be allowed for the anonymous user. + o #563540 by dereine: Fix description of cache plugin settings. + o #564536 by dereine: Node links should allow language setting from node data. + o #551752 by dereine: Clean up row counter code. + o #451208 by dereine and superbaloo: Fix grid style to not leave missing tds in bottom row. + o #561892 by dereine: Unchecking "rewrite this field" but leaving a value caused field to be rewritten anyway. + o #408894 by dereine: Views AJAX incorrectly used "access content" permission. + o #574150 by dereine: Remove user search because user.module does not store user keywords. + o #511908 by dww: Too many check plains in selects because of problems with checkboxes. + o #502348: Move advanced rendering up the chain a little bit to allow for non-standard uses of fields, such as grouping, to use advanced rendering features. + o #619884: Grouping fields ignored indexes (as a result of #502348) and appeared to group incorrectly. + o #411566: Fix warning when 0 given as a taxonomy tid to the validator. + o #607952 by markus_petrux: Need check plain on "additional" queries. + o #593910: Off by 1 error on Views row counter. + + Other changes: + o Implement a post_render hook (for themes too) and cache method. + o #501552 by neclimdul: Work around a core bug with DISTINCT on nodes. + o #430068 by overall and aclight: Improvements to the global "counter" field. + o #492002 by iterato: Allow "target" specification in field linking. + o #466454 by neclimdul: PHP strict fixes. + o Can now directly add a taxonomy term relationship to nodes, allowing more control by vocabulary. + o #472194: !1 can now be used with field rewriting to get the raw argument. + o #480162: Fields row style now contains option to hide empty fields. + o #433318: Special handling for empty fields, allowing them to avoid rewriting and not be displayed. + o #354457 by ausvalue: Example integrating node_example.module with Views API. + o #479728 by enboig: Allow "Does not start with" and "Does not end with" as string operators. + o #511468 by dereine: State which view was saved after saving a view. + o #520632 by DamZ: Add comment hostname and mail to available comment fields. + o #523580 by JirkaRybka: More documentation on Reduce Duplicates option. + o #510920 by apanag: Add set_current_page() method to view class. + o #337741 by joachim: Allow profile fields to have "link to user" option. + o #534680 by dagmar: Visual indicator if checkbox will expand options. + o #512650 by sdboyer: Multiple many to one arguments on the same relationship were not relationship safe. + o #536994 by dboulet: Store result in variables for use in unformatted style. + o #458194 by voxpelli: Add first and last row classes to table style. + o #254895: Add form to clean up Views 1 tables. + o If you have CTools 1.3 enabled, you can use a "Jump Menu" style for both summaries and normal Views. + +Views 2.6 (Jun 10, 2009) + Bugs fixed: + o #419226 by kelvincool: Respect admin theme during views ajax operations. + o #419270 by voxpelli: set_where_group() could fail if no previous groups. + o #422054 by yhahn: Protect exports from impropertly indenting multiline strings. + o #437070 by mikeryan: Base table formerly limited to 32 characters. + o #317271 by quicksketch: ensure_my_table() limited to one relationship per table. + o #441520 by jonathan1055: Allow the "time ago" date format to work on future dates as well. + o #445398 by casey: reduce_value_options() using wrong value array. + o #451370 by skwashd: base.js had some DOS line endings. + o #454754 by dww: Fix PGSQL related errors with comment author filtering. + o #384286 by dww: Make it possible to expose the filter for "Node: Has new content" + o #463634 by alienbrain: "Empty field name" incorrectly specified. + o #463580 by ximo: AJAX summary links broken in some displays. + o #468336 by psynaptic: Fix broken hook_views_admin_links_alter + o #422868 by mattman: Breadcrumbs not properly substuting % replacements. + o #440676 by dereine and Razorraser: View import form crashed on empty view input. + o #461842 by dereine: Use gmtime() instead of format_date() to prevent localization of dates in RSS feeds. + o #316556 by darrenoh and JirkaRybka: More 1.x upgrade fixes. + o #382398 by elcuco: Force LTR in the views admin. + o #461144: Fix trimming to correctly remove tags when they are trimmed in half. + o #330956: Theme: Information only scanned information from the default theme. + o SA-CONTRIB-2009-037: Filter checkboxes could be displayed unfiltered allowing XSS attacks. + + Other changes: + o #298616: Add argument for node updated time similar to node created time. + o #325607 by bangpound: Automatically sort exports from bulk export. + o #323049 by yched: Allow Empty/Not Empty on select many to one. + o #340701 by swentel: Restore allowing Views to set block caching mode. + o #347892 by dww: Allow option in Boolean filters. + o #358314 by brmassa: Catch the exposed filter form so it doesn't process twice on a single view. + o #154865 by Zack Rosen, josh_k and KarenS: Allow user contact form as a field. + o #411880 by fgm: Add "options callback" to items using in_operator handler. + o #360657 by yhahn: new hook_views_default_views_alter(). + o #430068 by dereine: New global counter field for displaying row number. + o #420340 by derine: Translate node type filter. + o #325796 by yang_yi_cn: Translate node type argument. + o #446726 by yhahn: Improved performance for js dependencies. + o #437760 by leeneman: Remove duplicate terms from taxonomy term argument title. + o #354270 by dereine: Allow "tag" to be added to the theme template suggestions. + o #408180 by joachim: Allow taxonomy term parent argument. + o #469456 by dereine: Automatically give .info file during views bulk export. + o #424460 by thePanz: Customizable breadcrumb title for arguments. + o #436398 by Pasqualle: Support for aggregator category table. + o #424648 by quicksketch and dereine: Allow format selection on filesize field. + o #478312 by yhahn: Provide specific node access filter. + o #479878 by dereine: User language field. + o #468824 by eaton: Pluggable caching mechanism which can cache both the query result and rendered result. + o #399534 by clemens.tolboom and drewish: Add fragment and query string as options when making fields into links. + o #315915 by dixon_: Add another base row class to rows. + o #353403 by agentrickard: Field to provide "more" text. + o #377896 by dereine: When ticked "link to node" show node title as a href title attribute. + o #386098 by dereine: Add "watchdog" as a debug logging options. + o #409428 by gpk: Missing field: node input format. + o #271833 by grugnog, agentrickard and others: Taxonomy depth in filter. + +Views 2.5 (Apr 11, 2009) + Bugs fixed: + o #363817 by thePanz: Empty fields in table could still trigger separators. + o #388952 by nikita@protsenko.com: Ensure taxonomy term validator sets the validated title when available. + o #392176: Trim on word boundary would stop at newlines. + o #415706 by dww: Fix broken relationship in search that caused SQL error. + o #428742 by fralenuvol: Fix broken relationship causing sql error with multiple taxonomy term arguments. + o #428102 with help from deviantintegral: Broken option_definition() causes warnings. + + Other changes: + o #379382 by neochief: Add option to strip tags during advanced rendering. + o #400914 by joachim: Add a link field to get to comments for a node that works just like the normal links. + o #402650 by drewish: Bulk export views alphabetically by view name. + o #349157 by yched: Support CCK build modes in node style. + +Views 2.4 (Apr 7, 2009) + Bugs fixed: + o #371466 by dereine: Fix incorrect link to comments. + o #371923 by noahb: Summaries could be distinct even when they should not be. + o #368764: Fix User ID validator to actually have proper dependencies. + o #375342 by dww: node_comment_statistics should be INNER joined because there is always 1:1 reference. + o #372959: Archive view should not use AJAX by default. + o #373155: Not clearing "many to one" data breaks some attachment displays. + o #375000 by elcuco: View name should always be LTR. + o #378534 by dww: Validators do not fire if argument === 0 due to PHP loose type conversions. + o #378164 by yched: Unexposed taxonomy filter could accidentally stop working. + o #371923 by David_Rothstein: Another DISTINCT fix related to summaries. + o #365831 by tomiyana: Fix typos in help. + o #357368 by Pasquale: schema descriptions should not be translated. + o #379602 by dww: Add a second "time ago" variant to dates to allow NOT printing the word "ago". + o #379354 by neochief: Add an extra regex to remove mangled HTML entities in output rewriting. + o #362830: Search was mostly broken, especially score but also searching on multiple terms. + o #350376 by pfournier: Missing "return" statement caused certain argument date validation to fail. + o #364082 by hass: Unique key missing on views_view table. + o #366250 by sirkitree: Fix deprecated jquery selectors so we can work with jquery 1.2.6 as well as 1.3.2. + o #386986: 2 or more relationships could block a normal table from being added. + o #371219 by aclight: Incorrect logic in views_many_to_one_helper::ensure_my_table() + o #376570 by yhahn: Better AJAX scrolling. + o #412576 by yhahn: Restore missing views_handler_filter_float class. + o #378710: Add strip_tags() to path when displaying a field as a link as a path can never have HTML in it. + o #380560: UI could suddenly cause errors with get_handlers() in certain situations with relationships. + o #342215: Occasional "holes" could appear in taxonomy term field causing query errors when relationship is used but not present. + o #414074 by dereine: Prevent fields becoming not editable by having just spaces in them in the Views UI. + o #378724: Displaying uploaded files as a link accidentally made the entire field a link rather than each one. + o #415672 by yhahn: Views inadvertently rounds negative numbers down instead of up when truncating. + o #408414 by rb7: Prevent empty links with the "has new comments" field. + o #406680 by Büke Beyond: Missing clear-block caused problems in IE for Views UI. + o #373771 by dropcube: Fix missing aggregator feed trying to use non-existing handlers. + o #341960 by sun: Clean up dependent.js javascript declarations which potentially caused .js errors. + o #372227: On Debian etch, tables would lose fields due to PHP bug. + + Other changes: + o #375182 by vaish: Allow a reset parameter to views_get_all_views(). + o #356276 by nedjo: Locale support. + o #316556 by Darren Oh: Better Views 1.x upgrades. + o #383242 by dww: Allow - Any - instead of as an option in the Views tools menu. + o #303800 by KarenS: Additional dashes to spaces option in taxonomy argument validator. + o #327366 by yched: Allow row styles to follow relationships too. + o #405130 by dereine: Make the output field rewrite a textfield rather than textarea. + +Views 2.3 (Feb 6, 2009) + Bugs fixed: + o #349739: Fix arguments not getting transmitted to attachment displays properly. + o #354707: Display attachment happened too early preventing default arguments from passing to the attachment. + o #277321 by nedjo: Use AJAX properly supports summaries in attachments. + o #291292 by sammys (reroll by jaydub): Proper use of DISTINCT on summary views on pgsql. + o #291079 by sammys (reroll by jaydub): Fix use of GROUP BY on pgsql. + o #295246 by webchick: Wrong table type on views object cache caused truncation of cached data and mysterious errors on large views. + o #315007 by Garrett Albright, Paul Kishimoto and catch: Take into account page count when using comment new link. + o #317562 by ingaro: Wrong date format for PGSQL. + o #327604 by mr.baileys: Fix improper use of multibyte library when mb library unavailable. + o #335926 by sapark and drewish: "January, 2009" should be "January 2009". + o #341263 by cdale: Prevent exposed filter forms from processing during batch operations. + o #342322 by drewish: Correct label for translation status. + o #343223 by alienbrain: Ensure path before join. + o #343284 by andypost: Fix odd/even reversed in table style compared to Drupal core. + o #345545 by mfb: Correct occasional Drupal.settings related javascript error. + o #345546: Fix Node: Created day argument off by 1 error. + o #345707 by aries: Do not display breadcrumb link if no link text. + o #355939 by yhager: Fix missing comment GUID in comment RSS style. + o #321332 with help from brahms: views_handler_field_markup only worked if format was named "format". + o #348322 by Darren Oh: Fix missing /code in api plugins help. + o #353090 by eaton: RSS feeds were not using all of the Drupal hooks to ensure full compatibility with core feeds. + o #293832 by drewish: Allow menu items to have administrative description. + o #345528: Mini-pager generated invalid HTML with empty li tags. + o #351745: Exposed taxonomy term autocomplete filter failed if term existed in multiple vocabularies. + o #353002: tracker view had wrong argument and was not picking up comments by the selected user. + o Case sensitivity on string filter checkmark was backward. + o #355919: views_theme() needed to include plugin theme files to detect functions. + o #353515: Many characters could get incorrectly translated in exposed filters combined with ajax tablesorting. + o #359818: Delete button should say Revert when reverting a view to default. + o #359132 by grugnog: CSS files should be marked conditional so they don't impact the CSS cache. + o #360637: Extra slash in theme includes could cause some systems to fail. + o #363081: Disabled views could still provide blocks. + o #366666 by Deadmonk also yched: File size field should not try to print a size on NULL values. + o #367203: Improper caching of default views caused incomplete handlers that could WSOD. + o #365283: views_handler_filter_ncs_last_updated improperly registered causing fatal errors trying to use it. + o #365712: select list exposed filters were trying to limit to list when selecting "All" even when "limit" was not selected. + o #357196 by Grugnog: hook_views_pre_view not getting $display_id sent properly. + + Other changes: + o #288801 by drewish and eaton: Aggregator item support! Make views of feeds! + o #335647 by markus_petrux: Add memory and a reset button to the Views list page. + o #343047 by alienbrain: Allow all handlers to participate in view validation. + o #339223 by greggles: Allow taxonomy term tid to be sortable. + o #324378 by eigentor: CSS improvements to the view list page. + o #354736 by Shai: Clarification on exposed filter text. + o #364637 by moshe and dww: Allow preprocessors to add row classes to table style. + o #349178 by agentrickard: Add generic link handling plus a custom text field. Also automatic trimming. + o #368234 by dww and neclimdul: Allow the "Anonymous" user to have a different (or no) name in User: name field. + o #368754 by dww: User ID validator, with role testing. + o #369505 by dww: Add helper function to get the value of a view argument. + o #353002 by neclimdul: Provide a filter for user posted or commented on to complement the argument with the same functionality. + + 2.3 API Notes: + A minor change in the API now requires that styles that render fields MUST + render them in order, first by row and then by field ID. Not doing so will + cause the token expansion to fail. + +Views 2.2 (Dec 16, 2008) + Bugs fixed: + o #305756: Number formatting caused illogical rounding. + o #324272 by neochief: hook_pre_render never called. + o #324058: Broken queries created by string values in multiple fields. + o #324726: "tag" fields should be autocomplete in View edit. + o #324058 by yched: Make aliases safer for many to one tables. + o #325765: Prevent key merge errors on query::add_where and query::add_having. + o #324378: Minor usability improvements to the list page. + o #326934: Need another check to make sure already added aliases do not get blown away. + o #324513: If a relationship table was added more than 1 hop away from the base, SQL errors resulted. + o #326129 by mindgame: Not between operator did not function. + o #326198: != mistakenly typod as = (display only) + o #326379: Provide a default title for the archive view. + o #327151: Add filter for node_counter.timestamp. + o #327113: Clean up error text when display will not validate. + o #307287: (Panels related) view::preview() would override previously set arguments if no arguments were sent. + o #321589: Comment template preprocessor misnamed so it would not fire. + o #329746: Comment rendering in the node row style was not working. + o #321109: view::destroy() needs to unset current_display or future init_displays won't work. + o #325115: If the block description is not set, show the display title as well as the view name in block administration. + o #327604 by henrrrik: should use multibyte string functions. + o #328933 by cmyers: views_handler_filter_date fails to use exposed operator. + o #332568 by Moonshine: Correct views performance timers. + o #332679 by yched: render_link() does not check for empty data. + o #333593: Incorrect reference to non-existent views_handler_join in help/api-tables.html. + o #334337 by miro_dietiker: Documentation clarification for arguments, blocks and PHP Code plugins. + o #336456 by dww: Date filter had trouble with NULL operators. + o #336125 by nedjo: Missing filter for node translation. + o #337360: Menu selection causes crash if menu module not active. + o #339295 by katbailey: AJAX paging could fail with the same view in multiple tabs. + o #339676 by nedjo: Source translation had wrong filter handler. + o #340002 by hass: Allow the "Add display" button to wrap for translations whose phrase is longer. + o #340033 by pancho: Clearer wording on some field help texts. + o #340515: views_perm() was incorrectly views_ui_perm(). + o #330897: Invalid displays causing 'path' lookup to crash. + o #339674 by nedjo: Translation code cleanup. + o #341897: views_perm() mistakenly declared in views_ui.module. + + Other changes: + o Reorganize the analysis code into analyze.inc to make it easier for people to find the code and use it externally. + o #298884 by neclimdul: Requested missing filter to filter for whether a user has a picture or not. + o #336531 by dww: Set boolean filter to not use a checkbox which is lesser UI. + o #338632 by drewish: Remove use of format_rss_channel and use proper templating instead. + o #326034 by yched: Allow short names in admin summaries via new "title short" definition. + o #335613 by swentel: Add hook_views_api() setting to bulk export. + o #339707 by nedjo: Add filter to show child translations. + o #284768 by drewish: Proper templates for RSS feeds rather than format_rss_item(). + + +Views 2.1 (Oct 20, 2008) + Bugs fixed: + o #322862: 1.0037 debug code left in. + o #322908: README.txt update. + o #323014 by yched: Typo in exposed filter text. + o #323033: Using empty/is not empty in string/numeric filters caused notices. + o #322874 by yched: Errors in summary for some filters. + o #323282: Taxonomy term default choice handled incorrectly. + o #323318: Exposed taxonomy term failed if not set force single. + +Views 2.0 (Oct 17, 2008) + o First 2.0 official release + diff --git a/sites/all/modules/views/LICENSE.txt b/sites/all/modules/views/LICENSE.txt new file mode 100644 index 0000000..d159169 --- /dev/null +++ b/sites/all/modules/views/LICENSE.txt @@ -0,0 +1,339 @@ + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 + + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to +your programs, too. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. + + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. + + For example, if you distribute copies of such a program, whether +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. + + The precise terms and conditions for copying, distribution and +modification follow. + + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to +this License. + + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will +be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along + with this program; if not, write to the Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +Also add information on how to contact you by electronic and paper mail. + +If the program is interactive, make it output a short notice like this +when it starts in an interactive mode: + + Gnomovision version 69, Copyright (C) year name of author + Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, the commands you use may +be called something other than `show w' and `show c'; they could even be +mouse-clicks or menu items--whatever suits your program. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the program, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the program + `Gnomovision' (which makes passes at compilers) written by James Hacker. + + , 1 April 1989 + Ty Coon, President of Vice + +This General Public License does not permit incorporating your program into +proprietary programs. If your program is a subroutine library, you may +consider it more useful to permit linking proprietary applications with the +library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. diff --git a/sites/all/modules/views/README.txt b/sites/all/modules/views/README.txt new file mode 100644 index 0000000..52dc458 --- /dev/null +++ b/sites/all/modules/views/README.txt @@ -0,0 +1,27 @@ + +Welcome to Views 2. Please see the advanced help for more information. + +If you're having trouble installing this module, please ensure that your +tar program is not flattening the directory tree, truncating filenames +or losing files. + +Installing Views: + +Place the entirety of this directory in sites/all/modules/views + +Navigate to administer >> build >> modules. Enable Views and Views UI. + +If upgrading from Drupal 5 and Views 1, your views need to be +converted manually. See administer >> build >> modules >> views >> tools >> convert. + +If you're new to Views, try the Simple Views module which can create some +often used Views for you, this might save you some time. + +Recommended modules for use with Views: + CCK + Voting API + Views Bonus Pack + Views Bulk Operations + +Experimental modules: + Views OR \ No newline at end of file diff --git a/sites/all/modules/views/css/views-admin.css b/sites/all/modules/views/css/views-admin.css new file mode 100644 index 0000000..9082493 --- /dev/null +++ b/sites/all/modules/views/css/views-admin.css @@ -0,0 +1,661 @@ + +/* + * Summary pad + */ +/* set up some defaults so weird themes don't override us too badly. */ +.views-tabset { + color: #494949; + background-color: white; +} + +.views-tabset a:visited, +.views-tabset a:hover, +.views-tabset a { + color: #027AC6; +} + +.views-tabset .views-tab fieldset { + margin-top: 0; +} + +/* + * First column: display drawers + */ +.views-tabset .views-tabs { + background: #F6F6F6; + border-top: #D6DBDE 1px solid; + border-bottom: #D6DBDE 1px solid; + border-left: #D6DBDE 1px solid; + float: left; + width: 117px; + margin-right: 0; +} + +* html .views-tabset .views-tabs { + width: 114px; + position: relative; + left: 4px; +} + +.views-tabset .views-tabs ul { + list-style-type: none !important; + list-style-image: none !important; + padding: 0; + margin: 0; + position: relative; +} + +.views-tabset .views-tabs ul li { + background: #efefef; + list-style-type: none; + list-style-image: none; + line-height: 100%; + border-bottom: #D6DBDE 1px solid; + margin: 0; + padding: 0; + position: relative; +} + +.views-tabset .views-tabs ul li.active { + background: #fff url(../images/arrow-active.png) no-repeat right; + position: relative; + width: 118px; + margin-right: -1px; +} + +.views-tabset .views-tabs ul li a { + display: block; + font-size: 90%; + color: #777; + font-weight: normal; + padding: 0.5em; +} + +.views-tabset .views-tabs ul li a:hover { + background-color: #f6f6f6; + text-decoration: none; +} + +.views-tabset .views-tabs ul li.active a { + color: #000; + font-weight: bold; +} + +.views-tabset .views-tabs ul li.active a:hover { + color: #000; + background: #fff url(../images/arrow-active.png) no-repeat right; +} + +.views-tabset .extra { + text-align: center; + margin-right: 0; +} + +.views-tabset .extra input { + margin-top: 0; + margin-right: 0; + white-space: normal; +} + +/* + * Three columns with setting-summaries + */ +.views-tabset .views-display { + border: #D6DBDE 1px solid; + margin-left: 118px; /* 118 -1 causes borders to overlap */ + min-height: 302px; + _height: 300px; /*stupid IE hack */ +} + +* html .views-tabset .views-display { + margin-left: 114px; +} + +div.views-display-deleted, +div.views-display-deleted div.top, +div.views-display-deleted div.tab-section { + background-color: #eee; +} + +.views-display { + background: #fff; +} + +.views-display div { + font-size: 8pt; + line-height: 12pt; +} + +.views-display .top { + padding: 0.5em 0em 0em 1em; + background: #fff; +} + +.views-display .top .display-title { + font-weight: bold; +} +.views-display .top .display-description { + margin-left: 1em; + font-style: italic; + overflow: hide; + white-space: nowrap; + font-size: 90%; +} + +.views-display .tab-section { + width: 32.5%; + padding: 0; + margin: 0; + float: left; + min-height: 273px; + _height: 274px; +} + +.views-display .tab-section .inside { + margin: 0.5em 0.5em 0.5em 1em; +} + +.views-display .tab-section .inside .views-category { + margin-bottom: 1em; + background: #f6f6f6; + border: 1px #efefef solid; +} + +.views-display .tab-section .inside .views-category-content { + padding: 0em 0em 0.5em 1em; +} + +.views-display .tab-section .inside .views-category-title { + padding: .1em .1em .1em .3em; + margin: 0 0 .1em 0; + font-size: 9pt; + font-weight: bold; + background-color: #efefef; + border-bottom: 1px #efefef solid; +} + +.views-display .tab-section .links { + float: right; + font-size: 6pt; + position: relative; + display: inline; +} + +.views-display .tab-section .links a { + font-size: 6pt; + font-style: italic; +} + +.views-display .form-submit, +#views-ajax-pad .form-submit { + margin: 0; +} + +.views-display .middle { + width: 34%; +} + +.views-basic-info { + margin: 0.5em 0em 0 0; + padding: 0.5em; +} + +/* + * AJAX pad, the bottom part where settings are edited. + */ +#views-ajax-pad { + background: transparent; + margin-top: 0px; +} + +#views-ajax-title { + background: #f6f6f6; + color: #000; + border-left: #D6DBDE 1px solid; + border-right: #D6DBDE 1px solid; + margin: 0 0 0 118px; + padding: 1em 1em 0em 1em; + font-weight: bold; +} + +#views-ajax-pad .message { + background: #f6f6f6; + color: #000; + margin-left: 118px; + border: #D6DBDE 1px solid; + border-top: 0; + /* padding: 3em 0em; */ + text-align: center; + font-style: italic; +} + +#views-ajax-pad form { + background: #fff; + color: #000; + margin-left: 118px; + border: #D6DBDE 1px solid; + padding-top: 3px; + border-top: 0; +} + +#views-ajax-pad .views-messages { + background: transparent; + margin-left: 118px; + padding: 5px; + border: #D6DBDE 1px solid; + border-top: 0; +} + +#views-ajax-pad .form-buttons { + margin: 0; + padding: 0.5em 1em; + background: #f6f6f6; + clear: left; +} + +#views-ajax-pad .clear { + clear: left; +} + +#views-ajax-pad .form-buttons .form-submit { + margin: 0 .5em 0 0; + padding: 0; +} + +#views-ajax-pad .form-item { + margin: 0.5em; + padding: 0em 0.5em; +} + +/* These put checkboxes closer together */ +#views-ajax-pad .form-checkboxes .form-item, +#views-ajax-pad .form-checkboxes .description, +#views-ajax-pad .form-checkboxes input, +#views-ajax-pad .form-radios .form-item, +#views-ajax-pad .form-radios label, +#views-ajax-pad .form-radios input { + margin-top: 0; + margin-bottom: 0; +} + +#views-ajax-pad .form-item .form-checkboxes, +#views-ajax-pad .form-checkboxes input, +#views-ajax-pad .form-checkboxes label, +#views-ajax-pad .form-item .form-checkboxes .form-item, +#views-ajax-pad .form-item .form-radios, +#views-ajax-pad .form-radios input, +#views-ajax-pad .form-radios label, +#views-ajax-pad .form-item .form-radios .form-item { + padding-left: 0; + margin-left: 0; +} + +#views-ajax-pad .form-checkboxes .description, +#views-ajax-pad .form-radios .description { + margin-left: 2em; +} + +#views-ajax-pad { + display: none; +} + +html.js #views-ajax-pad { + display: block; +} + +.views-override, +.views-expose { + padding: 0.5em 1em 0em 1em; +} + +#views-ajax-pad .views-override .form-submit, +#views-ajax-pad .views-expose .form-submit { + float: right; + margin: 0 .5em 0 1em; +} + +#views-ajax-pad .views-expose .description, +#views-ajax-pad .views-override .description { + margin-bottom: .25em; +} + +/* + * Some column widths for use within the ajax pad + */ +#views-ajax-pad .views-left-10 { + float: left; + width: 10%; +} + +#views-ajax-pad .views-left-20 { + float: left; + width: 20%; +} + +#views-ajax-pad .views-left-25 { + float: left; + width: 25%; +} + +#views-ajax-pad .views-left-30 { + float: left; + width: 30%; +} + +#views-ajax-pad .views-left-40 { + float: left; + width: 40%; +} + +#views-ajax-pad .views-left-50 { + float: left; + width: 49.5%; +} + +#views-ajax-pad .views-right-50 { + float: right; + width: 50%; +} + +#views-ajax-pad .views-right-60 { + float: right; + width: 60%; +} + +#views-ajax-pad .views-right-70 { + float: right; + width: 70%; +} + +#views-ajax-pad .views-left-75 { + float: left; + width: 75%; +} + +#views-ajax-pad .views-radio-box { + overflow: auto; + height: 22em; +} + +#views-ajax-pad fieldset { + margin: 0 .5em; +} + +#views-ajax-pad table td .form-item, +#views-ajax-pad table td .form-item input, +#views-ajax-pad table td .form-item select { + padding: 0; + margin: 0; +} + +#views-ajax-pad label.hidden-options { + background: transparent url(../images/arrow-active.png) no-repeat right; + height: 12px; + padding-right: 12px; +} + +#views-ajax-pad label.expanded-options { + background: transparent url(../images/expanded-options.png) no-repeat right; + height: 12px; + padding-right: 16px; +} + +#views-ajax-pad .dependent-options { + padding-left: 30px; +} + +/* + * Add, Rearrange and Configure buttons using sprites + */ +a.views-button-configure, +a.views-button-add, +a.views-button-rearrange, +a.views-button-remove { + background:transparent url(../images/sprites.png); + display: inline-block; + float: right; + height: 12px; + width: 16px; + margin: 2px 0px 1px 0px; + border-bottom: #C2C9CE 1px solid; + border-right: #C2C9CE 1px solid; + padding: 0px; +} + +a.views-button-remove { + background-position: 0px -72px; + position: relative; + top: -4px; +} +a.views-button-remove:hover { + background-position: 0px -84px; +} + +a.views-button-configure { + background-position: 0px -48px; + margin: 0; +} +a.views-button-configure:hover { + background-position: 0px -60px; +} + +a.views-button-add { + background-position: 0px -24px; +} +a.views-button-add:hover { + background-position: 0px -36px; +} + +a.views-button-rearrange { + background-position: 0px 0px; +} +a.views-button-rearrange:hover { + background-position: 0px -12px; +} + +a.views-button-remove span, +a.views-button-rearrange span, +a.views-button-configure span, +a.views-button-add span { + display: none; +} + +html.js #arrange thead { + display: none; +} + +html.js .views-remove-checkbox { + display: none; +} + +a.views-button-remove { + display: none; +} + +html.js a.views-button-remove { + display: inline; +} + +#arrange tr.even, +#arrange tr.odd, +#arrange td { + padding-top: 0; + padding-bottom: 0; +} + +#arrange .form-item { + padding: 0; +} + +div.changed { + background-color: #ffe; + font-weight: bold; +} + +div.view-changed { + display: none; + float: right; + font-style: italic; + color: #f93; + padding-left: 1em; +} + +div.views-tab div.changed a { + +} + +div.changed div.view-changed { + display: block; +} + +.views-display .tab-section .inside .overridden { + /* all this so we don't mess up background-color */ +/* background-image: url(../images/overridden.gif); + background-repeat: no-repeat; + background-position: left; + padding-left: 10px; */ +} + +.views-display .tab-section .views-category-content.overridden { + background-image: none; +} + +.views-display .tab-section .inside .defaulted { + color: #aaa; + font-style: italic; +} + +.views-display .tab-section .inside .defaulted a { + font-style: italic; +} + +.hilited { + color: #000; + font-weight: bold; + background-color: #ffd; + padding-left: 10px; +} + +#views-ajax-pad fieldset { + background: transparent; + padding-left: 10px; +} + +#views-ajax-pad pre { + overflow: auto; + border: 1px solid #333; + background-color: #f0f0f0; + padding: .5em; +} + +form#views-add-display-form { + margin-bottom: 0em; + border-bottom: 1px solid #ccc; +} + +form#views-add-display-form select { + width: 8.5em; +} + +#views-ui-edit-view-form { + margin: 0; + padding: 0; +} + +#views-live-preview { + padding-top: .5em; +} + +form#views-ui-preview-form, +#center form#views-ui-preview-form { + border: 1px solid #D6DBDE; + margin: 0 0 .5em 0; + padding: .5em; +} + +form#views-ui-preview-form div#preview-display-id-wrapper, +form#views-ui-preview-form div#preview-args-wrapper { + float: left; + margin: 0; + padding: 0 1em 0 0; +} + +form#views-ui-preview-form input#preview-submit { + margin: 1.7em 0 0 0; +} + +.view-locked { + color: red; + border: 1px solid red; + padding: 1em; +} + +/* Hide by default only with js */ +html.js .views-hidden { + display: none; +} + +.views-query-info { +/* overflow: auto; */ +} + +.views-query-info pre { + white-space: pre; /* CSS2 */ + white-space: -moz-pre-wrap; /* Mozilla */ + white-space: -hp-pre-wrap; /* HP printers */ + white-space: -o-pre-wrap; /* Opera 7 */ + white-space: -pre-wrap; /* Opera 4-6 */ + white-space: pre-wrap; /* CSS 2.1 */ + white-space: pre-line; /* CSS 3 (and 2.1 as well, actually) */ + word-wrap: break-word; /* IE */ + max-height: 200px; + overflow: scroll; +} + +.views-quick-links { + float: right; +} + +.views-quick-links ul.links li { + padding-left: 1em; +} + +.views-quick-links li.last { +} + +.views-edit-view .advanced-help-link { + padding-right: 3px; +} + +#views-ajax-title .advanced-help-link { + position: relative; + top: 2px; + padding-right: 3px; +} + +#views-ajax-pad input, +#views-ajax-pad textarea { + max-width: 95%; +} + +.clone-display, +.remove-display { + float: right; + margin: 0; + padding: .2em 1em 0 0; + position: relative; + top: .1em; +} + +.views-display .remove-display form, +.remove-display input, +.views-display .clone-display form, +.clone-display input { + margin: 0 !important; +} + +.views-validator-options { + padding: 0 1em; + margin: 0 1em; + border: 1px solid; +} diff --git a/sites/all/modules/views/css/views-list-rtl.css b/sites/all/modules/views/css/views-list-rtl.css new file mode 100644 index 0000000..1b62fc3 --- /dev/null +++ b/sites/all/modules/views/css/views-list-rtl.css @@ -0,0 +1,27 @@ + +table.views-entry { + clear: right; /* RTL */ +} + +table.views-entry td.view-ops { + text-align: left; /* RTL */ +} + +#views-ui-list-views-form .form-item { + padding-left: 1em; /* RTL */ + float: right; /* RTL */ +} + +#edit-order-wrapper { + clear: right; /* RTL */ +} + +#edit-views-apply, +#edit-views-reset { + float: right; /* RTL */ +} + +.views-entry .advanced-help-link { + padding-left: 3px; /* RTL */ +} + diff --git a/sites/all/modules/views/css/views-list.css b/sites/all/modules/views/css/views-list.css new file mode 100644 index 0000000..b043319 --- /dev/null +++ b/sites/all/modules/views/css/views-list.css @@ -0,0 +1,79 @@ + +table.views-entry { + margin: 3px 0; + border: 1px solid #ddd; + background-color: white; + color: #494949; /* matches garland */ + clear: left; /* LTR */ + width: 100%; +} + +table.views-entry tbody { + border: none; +} + +table.views-entry td.view-ops { + width: 45%; + text-align: right; /* LTR */ + background-color: #eee; +} + +table.views-entry td.view-name { + background-color: #eee; +} + +table.views-entry .description { + vertical-align: top; +} + +body form#views-ui-list-views-form { + margin: 0 0 1.5em 0; +} + +#views-ui-list-views-form .form-item { + padding-right: 1em; /* LTR */ + float: left; /* LTR */ + margin-top: 0; + margin-bottom: 0; +} + +#edit-order-wrapper { + clear: left; /* LTR */ +} + +#edit-views-apply, +#edit-views-reset { + margin-top: 1.65em; + float: left; /* LTR */ +} + +.views-entry .advanced-help-link { + position: relative; + top: 2px; + padding-right: 3px; /* LTR */ +} + +table.view-disabled { + color: #999; +} + +table.views-entry td { + line-height: 1.4; + padding-bottom: 10px; +} +table.view-disabled td { + line-height: 1.4; + padding-bottom: 10px; + background: none; +} +table.view-enabled td.view-name, +table.view-enabled td.view-ops, +table.view-disabled td.view-name, +table.view-disabled td.view-ops { + line-height: 1.6; + padding-bottom: 0.3em; +} +table.view-enabled td.view-name, +table.view-enabled td.view-ops { + background: #E4F0F8; +} diff --git a/sites/all/modules/views/css/views-rtl.css b/sites/all/modules/views/css/views-rtl.css new file mode 100644 index 0000000..fef2bd9 --- /dev/null +++ b/sites/all/modules/views/css/views-rtl.css @@ -0,0 +1,6 @@ + +.views-exposed-form .views-exposed-widget { + float: right; /* RTL */ + padding: .5em 1em 0 0; /* RTL */ +} + diff --git a/sites/all/modules/views/css/views-tabs.css b/sites/all/modules/views/css/views-tabs.css new file mode 100644 index 0000000..e884e07 --- /dev/null +++ b/sites/all/modules/views/css/views-tabs.css @@ -0,0 +1,5 @@ +/* $Id */ + +.ui-tabs-hide { + display: none; +} diff --git a/sites/all/modules/views/css/views.css b/sites/all/modules/views/css/views.css new file mode 100644 index 0000000..beb5782 --- /dev/null +++ b/sites/all/modules/views/css/views.css @@ -0,0 +1,98 @@ +.views-exposed-form .views-exposed-widget { + float: left; /* LTR */ + padding: .5em 1em 0 0; /* LTR */ +} + +.views-exposed-form .views-exposed-widget .form-submit { + margin-top: 1.6em; +} + +.views-exposed-form .form-item, +.views-exposed-form .form-submit { + margin-top: 0; + margin-bottom: 0; +} + +.views-exposed-form label { + font-weight: bold; +} + +.views-exposed-widgets { + margin-bottom: .5em; +} + +html.js a.views-throbbing, +html.js span.views-throbbing { + background:url(../images/status-active.gif) no-repeat right center; + padding-right:18px; +} + +/* administrative hover links */ + +div.view div.views-admin-links { + font-size: xx-small; + margin-right: 1em; + margin-top: 1em; +/* width: 95%; */ +} + +.block div.view div.views-admin-links { + margin-top: 0; +} + +div.view div.views-admin-links ul { + margin: 0; + padding: 0; +} + +div.view div.views-admin-links li { + margin: 0; + padding: 0 0 2px 0; + z-index: 201; +} + +div.view div.views-admin-links li a { + padding: 0; + margin: 0; + color: #ccc; +} + +div.view div.views-admin-links li a:before { + content: "["; +} +div.view div.views-admin-links li a:after { + content: "]"; +} + +div.view div.views-admin-links-hover a, +div.view div.views-admin-links:hover a { + color: #000; +} + +div.view div.views-admin-links-hover, +div.view div.views-admin-links:hover { + background: transparent; +} + +div.view div.views-hide { + display: none; +} + +/** For IE we add the class via js; for other browsers we rely on :hover **/ +div.view div.views-hide-hover, +div.view:hover div.views-hide { + display: block; + position: absolute; + z-index: 200; +} + +/* don't do this one in IE */ +div.view:hover div.views-hide { + margin-top: -1.5em; +} + +/* Remove the border on tbody that system puts in */ +.views-view-grid tbody { + border-top: none; +} + diff --git a/sites/all/modules/views/docs/docs.php b/sites/all/modules/views/docs/docs.php new file mode 100644 index 0000000..5c9cbf8 --- /dev/null +++ b/sites/all/modules/views/docs/docs.php @@ -0,0 +1,720 @@ + 'nid', + 'title' => t('Example table'), + 'help' => t("Example table contains example content and can be related to nodes."), + 'weight' => -10, + ); + + // This table references the {node} table. + // This creates an 'implicit' relationship to the node table, so that when 'Node' + // is the base table, the fields are automatically available. + $data['example_table']['table']['join'] = array( + // Index this array by the table name to which this table refers. + // 'left_field' is the primary key in the referenced table. + // 'field' is the foreign key in this table. + 'node' => array( + 'left_field' => 'nid', + 'field' => 'nid', + ), + ); + + // Next, describe each of the individual fields in this table to Views. For + // each field, you may define what field, sort, argument, and/or filter + // handlers it supports. This will determine where in the Views interface you + // may use the field. + + // Node ID field. + $data['example_table']['nid'] = array( + 'title' => t('Example content'), + 'help' => t('Some example content that references a node.'), + // Because this is a foreign key to the {node} table. This allows us to + // have, when the view is configured with this relationship, all the fields + // for the related node available. + 'relationship' => array( + 'base' => 'node', + 'field' => 'nid', + 'handler' => 'views_handler_relationship', + 'label' => t('Example node'), + ), + ); + + // Example plain text field. + $data['example_table']['plain_text_field'] = array( + 'title' => t('Plain text field'), + 'help' => t('Just a plain text field.'), + 'field' => array( + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // Example numeric text field. + $data['example_table']['numeric_field'] = array( + 'title' => t('Numeric field'), + 'help' => t('Just a numeric field.'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // Example boolean field. + $data['example_table']['boolean_field'] = array( + 'title' => t('Boolean field'), + 'help' => t('Just an on/off field.'), + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'label' => t('Published'), + 'type' => 'yes-no', + // use boolean_field = 1 instead of boolean_field <> 0 in WHERE statment + 'use equal' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // Example timestamp field. + $data['example_table']['timestamp_field'] = array( + 'title' => t('Timestamp field'), + 'help' => t('Just a timestamp field.'), + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + ); + + return $data; +} + +/** + * Alter table structure. + * + * You can add/edit/remove to existing tables defined by hook_views_data(). + * + * This hook should be placed in MODULENAME.views.inc and it will be auto-loaded. + * This must either be in the same directory as the .module file or in a subdirectory + * named 'includes'. + * + * The full documentation for this hook is in the advanced help. + * @link http://views-help.doc.logrus.com/help/views/api-tables @endlink + */ +function hook_views_data_alter(&$data) { + // This example alters the title of the node: nid field for the admin. + $data['node']['nid']['title'] = t('Node-Nid'); + + // This example adds a example field to the users table + $data['users']['example_field'] = array( + 'title' => t('Example field'), + 'help' => t('Some examüple content that references a user'), + 'handler' => 'hook_handlers_field_example_field', + ); + + // This example changes the handler of the node title field. + // In this handler you could do stuff, like preview of the node, when clicking the node title. + + $data['node']['title']['handler'] = 'modulename_handlers_field_node_title'; +} + + +/** + * The full documentation for this hook is now in the advanced help. + * + * This hook should be placed in MODULENAME.views.inc and it will be auto-loaded. + * This must either be in the same directory as the .module file or in a subdirectory + * named 'includes'. + * + * This is a stub list as a reminder that this needs to be doc'd and is not used + * in views anywhere so might not be remembered when this is formally documented: + * - style: 'even empty' + */ +function hook_views_plugins() { + // example code here +} + +/** + * Alter existing plugins data, defined by modules. + */ +function hook_views_plugins_alter(&$plugins) { + // Add apachesolr to the base of the node row plugin. + $plugins['row']['node']['base'][] = 'apachesolr'; +} + +/** + * Register handler, file and parent information so that handlers can be + * loaded only on request. + * + * The full documentation for this hook is in the advanced help. + */ +function hook_views_handlers() { + // example code here +} + +/** + * Register View API information. This is required for your module to have + * its include files loaded; for example, when implementing + * hook_views_default_views(). + * + * @return + * An array with the following possible keys: + * - api: (required) The version of the Views API the module implements. + * - path: (optional) If includes are stored somewhere other than within + * the root module directory or a subdirectory called includes, specify + * its path here. + */ +function hook_views_api() { + return array( + 'api' => 2, + 'path' => drupal_get_path('module', 'example') . '/includes/views', + ); +} + +/** + * This hook allows modules to provide their own views which can either be used + * as-is or as a "starter" for users to build from. + * + * This hook should be placed in MODULENAME.views_default.inc and it will be + * auto-loaded. This must either be in the same directory as the .module file + * or in a subdirectory named 'includes'. + * + * The $view->disabled boolean flag indicates whether the View should be + * enabled or disabled by default. + * + * @return + * An associative array containing the structures of views, as generated from + * the Export tab, keyed by the view name. A best practice is to go through + * and add t() to all title and label strings, with the exception of menu + * strings. + */ +function hook_views_default_views() { + // Begin copy and paste of output from the Export tab of a view. + $view = new view; + $view->name = 'frontpage'; + $view->description = t('Emulates the default Drupal front page; you may set the default home page path to this view to make it your front page.'); + $view->tag = t('default'); + $view->base_table = 'node'; + $view->api_version = 2; + $view->disabled = FALSE; // Edit this to true to make a default view disabled initially + $view->display = array(); + $display = new views_display; + $display->id = 'default'; + $display->display_title = t('Defaults'); + $display->display_plugin = 'default'; + $display->position = '1'; + $display->display_options = array ( + 'style_plugin' => 'default', + 'style_options' => + array ( + ), + 'row_plugin' => 'node', + 'row_options' => + array ( + 'teaser' => 1, + 'links' => 1, + ), + 'relationships' => + array ( + ), + 'fields' => + array ( + ), + 'sorts' => + array ( + 'sticky' => + array ( + 'id' => 'sticky', + 'table' => 'node', + 'field' => 'sticky', + 'order' => 'ASC', + ), + 'created' => + array ( + 'id' => 'created', + 'table' => 'node', + 'field' => 'created', + 'order' => 'ASC', + 'relationship' => 'none', + 'granularity' => 'second', + ), + ), + 'arguments' => + array ( + ), + 'filters' => + array ( + 'promote' => + array ( + 'id' => 'promote', + 'table' => 'node', + 'field' => 'promote', + 'operator' => '=', + 'value' => '1', + 'group' => 0, + 'exposed' => false, + 'expose' => + array ( + 'operator' => false, + 'label' => '', + ), + ), + 'status' => + array ( + 'id' => 'status', + 'table' => 'node', + 'field' => 'status', + 'operator' => '=', + 'value' => '1', + 'group' => 0, + 'exposed' => false, + 'expose' => + array ( + 'operator' => false, + 'label' => '', + ), + ), + ), + 'items_per_page' => 10, + 'use_pager' => '1', + 'pager_element' => 0, + 'title' => '', + 'header' => '', + 'header_format' => '1', + 'footer' => '', + 'footer_format' => '1', + 'empty' => '', + 'empty_format' => '1', + ); + $view->display['default'] = $display; + $display = new views_display; + $display->id = 'page'; + $display->display_title = t('Page'); + $display->display_plugin = 'page'; + $display->position = '2'; + $display->display_options = array ( + 'defaults' => + array ( + 'access' => true, + 'title' => true, + 'header' => true, + 'header_format' => true, + 'header_empty' => true, + 'footer' => true, + 'footer_format' => true, + 'footer_empty' => true, + 'empty' => true, + 'empty_format' => true, + 'items_per_page' => true, + 'offset' => true, + 'use_pager' => true, + 'pager_element' => true, + 'link_display' => true, + 'php_arg_code' => true, + 'exposed_options' => true, + 'style_plugin' => true, + 'style_options' => true, + 'row_plugin' => true, + 'row_options' => true, + 'relationships' => true, + 'fields' => true, + 'sorts' => true, + 'arguments' => true, + 'filters' => true, + 'use_ajax' => true, + 'distinct' => true, + ), + 'relationships' => + array ( + ), + 'fields' => + array ( + ), + 'sorts' => + array ( + ), + 'arguments' => + array ( + ), + 'filters' => + array ( + ), + 'path' => 'frontpage', + ); + $view->display['page'] = $display; + $display = new views_display; + $display->id = 'feed'; + $display->display_title = t('Feed'); + $display->display_plugin = 'feed'; + $display->position = '3'; + $display->display_options = array ( + 'defaults' => + array ( + 'access' => true, + 'title' => false, + 'header' => true, + 'header_format' => true, + 'header_empty' => true, + 'footer' => true, + 'footer_format' => true, + 'footer_empty' => true, + 'empty' => true, + 'empty_format' => true, + 'use_ajax' => true, + 'items_per_page' => true, + 'offset' => true, + 'use_pager' => true, + 'pager_element' => true, + 'use_more' => true, + 'distinct' => true, + 'link_display' => true, + 'php_arg_code' => true, + 'exposed_options' => true, + 'style_plugin' => false, + 'style_options' => false, + 'row_plugin' => false, + 'row_options' => false, + 'relationships' => true, + 'fields' => true, + 'sorts' => true, + 'arguments' => true, + 'filters' => true, + ), + 'relationships' => + array ( + ), + 'fields' => + array ( + ), + 'sorts' => + array ( + ), + 'arguments' => + array ( + ), + 'filters' => + array ( + ), + 'displays' => + array ( + 'default' => 'default', + 'page' => 'page', + ), + 'style_plugin' => 'rss', + 'style_options' => + array ( + 'mission_description' => 1, + 'description' => '', + ), + 'row_plugin' => 'node_rss', + 'row_options' => + array ( + 'item_length' => 'default', + ), + 'path' => 'rss.xml', + 'title' => t('Front page feed'), + ); + $view->display['feed'] = $display; + // End copy and paste of Export tab output. + + // Add view to list of views to provide. + $views[$view->name] = $view; + + // ...Repeat all of the above for each view the module should provide. + + // At the end, return array of default views. + return $views; +} + +/** + * This hook is called right before all default views are cached to the + * database. It takes a keyed array of views by reference. + */ +function hook_views_default_views_alter(&$views) { + if (isset($views['taxonomy_term'])) { + $views['taxonomy_term']->set_display('default'); + $views['taxonomy_term']->display_handler->set_option('title', 'Categories'); + } +} + +/** + * Stub hook documentation + * + * This hook should be placed in MODULENAME.views_convert.inc and it will be auto-loaded. + * This must either be in the same directory as the .module file or in a subdirectory + * named 'includes'. + */ +function hook_views_convert() { + // example code here +} + +/** + * Stub hook documentation + */ +function hook_views_query_substitutions() { + // example code here +} + +/** + * This hook is called at the very beginning of views processing, + * before anything is done. + * + * Adding output to the view can be accomplished by placing text on + * $view->attachment_before and $view->attachment_after. + */ +function hook_views_pre_view(&$view, &$display_id, &$args) { + // example code here +} + +/** + * This hook is called right before the build process, but after displays + * are attached and the display performs its pre_execute phase. + * + * Adding output to the view can be accomplished by placing text on + * $view->attachment_before and $view->attachment_after. + */ +function hook_views_pre_build(&$view) { + // example code here +} + +/** + * This hook is called right after the build process. The query is + * now fully built, but it has not yet been run through db_rewrite_sql. + * + * Adding output to the view can be accomplished by placing text on + * $view->attachment_before and $view->attachment_after. + */ +function hook_views_post_build(&$view) { + // example code here +} + +/** + * This hook is called right before the execute process. The query is + * now fully built, but it has not yet been run through db_rewrite_sql. + * + * Adding output to the view can be accomplished by placing text on + * $view->attachment_before and $view->attachment_after. + */ +function hook_views_pre_execute(&$view) { + // example code here +} + +/** + * This hook is called right after the execute process. The query has + * been executed, but the pre_render() phase has not yet happened for + * handlers. + * + * Adding output to the view can be accomplished by placing text on + * $view->attachment_before and $view->attachment_after. Altering the + * content can be achieved by editing the items of $view->result. + */ +function hook_views_post_execute(&$view) { + // example code here +} + +/** + * This hook is called right before the render process. The query has + * been executed, and the pre_render() phase has already happened for + * handlers, so all data should be available. + * + * Adding output to the view can be accomplished by placing text on + * $view->attachment_before and $view->attachment_after. Altering the + * content can be achieved by editing the items of $view->result. + * + * This hook can be utilized by themes. + */ +function hook_views_pre_render(&$view) { + // example code here +} + +/** + * Post process any rendered data. + * + * This can be valuable to be able to cache a view and still have some level of + * dynamic output. In an ideal world, the actual output will include HTML + * comment based tokens, and then the post process can replace those tokens. + * + * Example usage. If it is known that the view is a node view and that the + * primary field will be a nid, you can do something like this: + * + * + * + * And then in the post render, create an array with the text that should + * go there: + * + * strtr($output, array('', 'output for FIELD of nid 1'); + * + * All of the cached result data will be available in $view->result, as well, + * so all ids used in the query should be discoverable. + * + * This hook can be utilized by themes. + */ +function hook_views_post_render(&$view, &$output, &$cache) { + +} + +/** + * Stub hook documentation + * + * This hook should be placed in MODULENAME.views.inc and it will be auto-loaded. + * This must either be in the same directory as the .module file or in a subdirectory + * named 'includes'. + * + */ +function hook_views_query_alter(&$view, &$query) { + // example code here +} + +/** + * This hook should be placed in MODULENAME.views.inc and it will be auto-loaded. + * This must either be in the same directory as the .module file or in a subdirectory + * named 'includes'. + * + * Alter the links that appear over a view. They are in a format suitable for + * theme('links'). + * + * Warning: $view is not a reference in PHP4 and cannot be modified here. But it IS + * a reference in PHP5, and can be modified. Please be careful with it. + * + * @see theme_links + */ +function hook_views_admin_links_alter(&$links, $view) { + // example code here +} + +/** + * This hook should be placed in MODULENAME.views.inc and it will be auto-loaded. + * This must either be in the same directory as the .module file or in a subdirectory + * named 'includes'. + * + * Alter the rows that appear with a view, which includes path and query information. + * The rows are suitable for theme('table'). + * + * Warning: $view is not a reference in PHP4 and cannot be modified here. But it IS + * a reference in PHP5, and can be modified. Please be careful with it. + * + * @see theme_table + */ +function hook_views_preview_info_alter(&$rows, $view) { + // example code here +} + +/** + * @} + */ diff --git a/sites/all/modules/views/documentation-standards.txt b/sites/all/modules/views/documentation-standards.txt new file mode 100644 index 0000000..ea61135 --- /dev/null +++ b/sites/all/modules/views/documentation-standards.txt @@ -0,0 +1,6 @@ +- If the interface text is *bolded*, it got strong tags. +- If it's a button they need to click, that's *bold* too. +- If the text is not bolded (ex: links to click, options to check), it +got /italicized/. +- If it's user-entered text it got 'single quotes'. + diff --git a/sites/all/modules/views/handlers/views_handler_argument.inc b/sites/all/modules/views/handlers/views_handler_argument.inc new file mode 100644 index 0000000..27cfdf7 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_argument.inc @@ -0,0 +1,773 @@ +definition['name field'])) { + $this->name_field = $this->definition['name field']; + } + if (!empty($this->definition['name table'])) { + $this->name_table = $this->definition['name table']; + } + } + + function init(&$view, $options) { + parent::init($view, $options); + } + + /** + * Give an argument the opportunity to modify the breadcrumb, if it wants. + * This only gets called on displays where a breadcrumb is actually used. + * + * The breadcrumb will be in the form of an array, with the keys being + * the path and the value being the already sanitized title of the path. + */ + function set_breadcrumb(&$breadcrumb) { } + + /** + * Determine if the argument can generate a breadcrumb + * + * @return TRUE/FALSE + */ + function uses_breadcrumb() { + $info = $this->default_actions($this->options['default_action']); + return !empty($info['breadcrumb']); + } + + function is_wildcard($arg = NULL) { + if (!isset($arg)) { + $arg = $this->argument; + } + + return !empty($this->options['wildcard']) && $this->options['wildcard'] === $arg; + } + + function wildcard_title() { + return $this->options['wildcard_substitution']; + } + + /** + * Determine if the argument needs a style plugin. + * + * @return TRUE/FALSE + */ + function needs_style_plugin() { + $info = $this->default_actions($this->options['default_action']); + $validate_info = $this->default_actions($this->options['validate_fail']); + return !empty($info['style plugin']) || !empty($validate_info['style plugin']); + } + + function option_definition() { + $options = parent::option_definition(); + + $options['default_action'] = array('default' => 'ignore'); + $options['style_plugin'] = array('default' => 'default_summary'); + $options['style_options'] = array('default' => array()); + $options['wildcard'] = array('default' => 'all'); + $options['wildcard_substitution'] = array('default' => t('All'), 'translatable' => TRUE); + $options['title'] = array('default' => '', 'translatable' => TRUE); + $options['breadcrumb'] = array('default' => '', 'translatable' => TRUE); + $options['default_argument_type'] = array('default' => 'fixed'); + $options['default_argument'] = array('default' => ''); + $options['validate_type'] = array('default' => 'none'); + $options['validate_fail'] = array('default' => 'not found'); + + return $options; + } + + function options_form(&$form, &$form_state) { + $defaults = $this->default_actions(); + + $form['title'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'textfield', + '#title' => t('Title'), + '#default_value' => $this->options['title'], + '#description' => t('The title to use when this argument is present. It will override the title of the view and titles from previous arguments. You can use percent substitution here to replace with argument titles. Use "%1" for the first argument, "%2" for the second, etc.'), + ); + + $form['breadcrumb'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'textfield', + '#title' => t('Breadcrumb'), + '#default_value' => $this->options['breadcrumb'], + '#description' => t('The Breadcrumb title to use when this argument is present. If no breadcrumb is set here, default Title values will be used, see "Title" for percent substitutions.'), + ); + + $form['clear_start'] = array( + '#value' => '
', + ); + + $form['defaults_start'] = array( + '#value' => '
', + ); + + $form['default_action'] = array( + '#type' => 'radios', + '#title' => t('Action to take if argument is not present'), + '#default_value' => $this->options['default_action'], + ); + + $form['defaults_stop'] = array( + '#value' => '
', + ); + + $form['wildcard'] = array( + '#prefix' => '
', + // prefix and no suffix means these two items will be grouped together. + '#type' => 'textfield', + '#title' => t('Wildcard'), + '#size' => 20, + '#default_value' => $this->options['wildcard'], + '#description' => t('If this value is received as an argument, the argument will be ignored; i.e, "all values"'), + ); + + $form['wildcard_substitution'] = array( + '#suffix' => '
', + '#type' => 'textfield', + '#title' => t('Wildcard title'), + '#size' => 20, + '#default_value' => $this->options['wildcard_substitution'], + '#description' => t('The title to use for the wildcard in substitutions elsewhere.'), + ); + + $form['clear_stop'] = array( + '#value' => '
', + ); + + $options = array(); + $validate_options = array(); + foreach ($defaults as $id => $info) { + $options[$id] = $info['title']; + if (empty($info['default only'])) { + $validate_options[$id] = $info['title']; + } + if (!empty($info['form method'])) { + $this->{$info['form method']}($form, $form_state); + } + } + + $form['default_action']['#options'] = $options; + + $form['validate_options_div_prefix'] = array( + '#id' => 'views-validator-options', + '#value' => '
' . t('Validator options') . '', + ); + + $form['validate_type'] = array( + '#type' => 'select', + '#title' => t('Validator'), + '#default_value' => $this->options['validate_type'], + ); + + $validate_types = array('none' => t('- Basic validation -')); + $plugins = views_fetch_plugin_data('argument validator'); + foreach ($plugins as $id => $info) { + if (!empty($info['no ui'])) { + continue; + } + + $valid = TRUE; + if (!empty($info['type'])) { + $valid = FALSE; + if (empty($this->definition['validate type'])) { + continue; + } + foreach ((array) $info['type'] as $type) { + if ($type == $this->definition['validate type']) { + $valid = TRUE; + break; + } + } + } + + // If we decide this validator is ok, add it to the list. + if ($valid) { + $plugin = views_get_plugin('argument validator', $id); + if ($plugin) { + $plugin->init($this->view, $this, $id); + if ($plugin->access() || $this->options['validate_type'] == $id) { + $plugin->validate_form($form, $form_state, $id); + $validate_types[$id] = $info['title']; + } + } + } + } + + asort($validate_types); + $form['validate_type']['#options'] = $validate_types; + + $form['validate_fail'] = array( + '#type' => 'select', + '#title' => t('Action to take if argument does not validate'), + '#default_value' => $this->options['validate_fail'], + '#options' => $validate_options, + ); + + $form['validate_options_div_suffix'] = array( + '#value' => '
', + ); + } + + /** + * Provide a list of default behaviors for this argument if the argument + * is not present. + * + * Override this method to provide additional (or fewer) default behaviors. + */ + function default_actions($which = NULL) { + $defaults = array( + 'ignore' => array( + 'title' => t('Display all values'), + 'method' => 'default_ignore', + 'breadcrumb' => TRUE, // generate a breadcrumb to here + ), + 'not found' => array( + 'title' => t('Hide view / Page not found (404)'), + 'method' => 'default_not_found', + 'hard fail' => TRUE, // This is a hard fail condition + ), + 'empty' => array( + 'title' => t('Display empty text'), + 'method' => 'default_empty', + 'breadcrumb' => TRUE, // generate a breadcrumb to here + ), + 'summary asc' => array( + 'title' => t('Summary, sorted ascending'), + 'method' => 'default_summary', + 'method args' => array('asc'), + 'style plugin' => TRUE, + 'breadcrumb' => TRUE, // generate a breadcrumb to here + ), + 'summary desc' => array( + 'title' => t('Summary, sorted descending'), + 'method' => 'default_summary', + 'method args' => array('desc'), + 'style plugin' => TRUE, + 'breadcrumb' => TRUE, // generate a breadcrumb to here + ), + 'default' => array( + 'title' => t('Provide default argument'), + 'method' => 'default_default', + 'form method' => 'default_argument_form', + 'has default argument' => TRUE, + 'default only' => TRUE, // this can only be used for missing argument, not validation failure + ), + ); + + if ($which) { + if (!empty($defaults[$which])) { + return $defaults[$which]; + } + } + else { + return $defaults; + } + } + + /** + * Provide a form for selecting the default argument when the + * default action is set to provide default argument. + */ + function default_argument_form(&$form, &$form_state) { + $plugins = views_fetch_plugin_data('argument default'); + $options = array(); + + // This construct uses 'hidden' and not markup because process doesn't + // run. It also has an extra div because the dependency wants to hide + // the parent in situations like this, so we need a second div to + // make this work. + $form['default_options_div_prefix'] = array( + '#type' => 'hidden', + '#id' => 'views-default-options', + '#prefix' => '
' . t('Provide default argument options') . '', + '#process' => array('views_process_dependency'), + '#dependency' => array('radio:options[default_action]' => array('default')), + ); + + $form['default_argument_type'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#type' => 'radios', + '#id' => 'edit-options-default-argument-type', + '#title' => t('Default argument type'), + '#default_value' => $this->options['default_argument_type'], + '#process' => array('expand_radios', 'views_process_dependency'), + '#dependency' => array('radio:options[default_action]' => array('default')), + ); + + foreach ($plugins as $id => $info) { + $plugin = views_get_plugin('argument default', $id); + if ($plugin) { + $plugin->init($this->view, $this, $id); + + if ($plugin->access() || $this->options['default_argument_type'] == $id) { + $options[$id] = $info['title']; + $plugin->argument_form($form, $form_state); + } + } + } + + $form['default_options_div_suffix'] = array( + '#value' => '
', + ); + + asort($options); + $form['default_argument_type']['#options'] = $options; + } + + /** + * Handle the default action, which means our argument wasn't present. + * + * Override this method only with extreme care. + * + * @return + * A boolean value; if TRUE, continue building this view. If FALSE, + * building the view will be aborted here. + */ + function default_action($info = NULL) { + if (!isset($info)) { + $info = $this->default_actions($this->options['default_action']); + } + + if (!$info) { + return FALSE; + } + + if (!empty($info['method args'])) { + return call_user_func_array(array(&$this, $info['method']), $info['method args']); + } + else { + return $this->{$info['method']}(); + } + } + + /** + * How to act if validation failes + */ + function validate_fail() { + $info = $this->default_actions($this->options['validate_fail']); + return $this->default_action($info); + } + /** + * Default action: ignore. + * + * If an argument was expected and was not given, in this case, simply + * ignore the argument entirely. + */ + function default_ignore() { + return TRUE; + } + + /** + * Default action: not found. + * + * If an argument was expected and was not given, in this case, report + * the view as 'not found' or hide it. + */ + function default_not_found() { + // Set a failure condition and let the display manager handle it. + $this->view->build_info['fail'] = TRUE; + return FALSE; + } + + /** + * Default action: empty + * + * If an argument was expected and was not given, in this case, display + * the view's empty text + */ + function default_empty() { + // We return with no query; this will force the empty text. + $this->view->built = TRUE; + $this->view->executed = TRUE; + $this->view->result = array(); + return FALSE; + } + + /** + * This just returns true. The view argument builder will know where + * to find the argument from. + */ + function default_default() { + return TRUE; + } + + /** + * Determine if the argument is set to provide a default argument. + */ + function has_default_argument() { + $info = $this->default_actions($this->options['default_action']); + return !empty($info['has default argument']); + } + + /** + * Get a default argument, if available. + */ + function get_default_argument() { + $plugin = views_get_plugin('argument default', $this->options['default_argument_type']); + if ($plugin) { + $plugin->init($this->view, $this); + return $plugin->get_argument(); + } + } + + /** + * Default action: summary. + * + * If an argument was expected and was not given, in this case, display + * a summary query. + */ + function default_summary($order) { + $this->view->build_info['summary'] = TRUE; + $this->view->build_info['summary_level'] = $this->options['id']; + + // Change the display style to the summary style for this + // argument. + $this->view->plugin_name = $this->options['style_plugin']; + $this->view->style_options = $this->options['style_options']; + + // Clear out the normal primary field and whatever else may have + // been added and let the summary do the work. + $this->query->clear_fields(); + $this->summary_query(); + + $this->summary_sort($order); + + // Summaries have their own sorting and fields, so tell the View not + // to build these. + $this->view->build_sort = $this->view->build_fields = FALSE; + return TRUE; + } + + /** + * Build the info for the summary query. + * + * This must: + * - add_groupby: group on this field in order to create summaries. + * - add_field: add a 'num_nodes' field for the count. Usually it will + * be a count on $view->base_field + * - set_count_field: Reset the count field so we get the right paging. + * + * @return + * The alias used to get the number of records (count) for this entry. + */ + function summary_query() { + $this->ensure_my_table(); + // Add the field. + $this->base_alias = $this->query->add_field($this->table_alias, $this->real_field); + + $this->summary_name_field(); + return $this->summary_basics(); + } + + /** + * Add the name field, which is the field displayed in summary queries. + * This is often used when the argument is numeric. + */ + function summary_name_field() { + // Add the 'name' field. For example, if this is a uid argument, the + // name field would be 'name' (i.e, the username). + + if (isset($this->name_table)) { + // if the alias is different then we're probably added, not ensured, + // so look up the join and add it instead. + if ($this->table_alias != $this->table) { + $j = views_get_table_join($this->name_table, $this->table); + if ($j) { + $join = drupal_clone($j); + $join->left_table = $this->table_alias; + $this->name_table_alias = $this->query->add_table($this->name_table, $this->relationship, $join); + } + } + else { + $this->name_table_alias = $this->query->ensure_table($this->name_table, $this->relationship); + } + } + else { + $this->name_table_alias = $this->table_alias; + } + + if (isset($this->name_field)) { + $this->name_alias = $this->query->add_field($this->name_table_alias, $this->name_field); + } + else { + $this->name_alias = $this->base_alias; + } + } + + /** + * Some basic summary behavior that doesn't need to be repeated as much as + * code that goes into summary_query() + */ + function summary_basics($count_field = TRUE) { + // Add the number of nodes counter + $field = $this->query->base_table . '.' . $this->query->base_field; + $distinct = ($this->view->display_handler->get_option('distinct') && empty($this->query->no_distinct)); + + $count_alias = $this->query->add_field(NULL, $field, 'num_records', + array('count' => TRUE, 'distinct' => $distinct)); + $this->query->add_groupby($this->name_alias); + + if ($count_field) { + $this->query->set_count_field($this->table_alias, $this->real_field); + } + + $this->count_alias = $count_alias; + } + + /** + * Sorts the summary based upon the user's selection. The base variant of + * this is usually adequte. + * + * @param $order + * The order selected in the UI. + */ + function summary_sort($order) { + $this->query->add_orderby(NULL, NULL, $order, $this->name_alias); + } + + /** + * Provide the argument to use to link from the summary to the next level; + * this will be called once per row of a summary, and used as part of + * $view->get_url(). + * + * @param $data + * The query results for the row. + */ + function summary_argument($data) { + return $data->{$this->base_alias}; + } + + /** + * Provides the name to use for the summary. By default this is just + * the name field. + * + * @param $data + * The query results for the row. + */ + function summary_name($data) { + $value = $data->{$this->name_alias}; + if (empty($value) && !empty($this->definition['empty field name'])) { + $value = $this->definition['empty field name']; + } + return check_plain($value); + } + + /** + * Set up the query for this argument. + * + * The argument sent may be found at $this->argument. + */ + function query() { + $this->ensure_my_table(); + $placeholder = empty($this->definition['numeric']) ? "'%s'" : '%d'; + $this->query->add_where(0, "$this->table_alias.$this->real_field = $placeholder", $this->argument); + } + + /** + * Get the title this argument will assign the view, given the argument. + * + * This usually needs to be overridden to provide a proper title. + */ + function title() { + return check_plain($this->argument); + } + + /** + * Called by the view object to get the title. This may be set by a + * validator so we don't necessarily call through to title(). + */ + function get_title() { + if (isset($this->validated_title)) { + return $this->validated_title; + } + else { + return $this->title(); + } + } + + /** + * Validate that this argument works. By default, all arguments are valid. + */ + function validate_arg($arg) { + // By using % in URLs, arguments could be validated twice; this eases + // that pain. + if (isset($this->argument_validated)) { + return $this->argument_validated; + } + + if ($this->is_wildcard($arg)) { + return $this->argument_validated = TRUE; + } + + if ($this->options['validate_type'] == 'none') { + return $this->argument_validated = $this->validate_argument_basic($arg); + } + + $plugin = views_get_plugin('argument validator', $this->options['validate_type']); + if ($plugin) { + $plugin->init($this->view, $this, $this->options['validate_type']); + return $this->argument_validated = $plugin->validate_argument($arg); + } + + // If the plugin isn't found, fall back to the basic validation path: + return $this->argument_validated = $this->validate_argument_basic($arg); + } + + /** + * Called by the menu system to validate an argument. + * + * This checks to see if this is a 'soft fail', which means that if the + * argument fails to validate, but there is an action to take anyway, + * then validation cannot actually fail. + */ + function validate_argument($arg) { + $validate_info = $this->default_actions($this->options['validate_fail']); + if (empty($validate_info['hard fail'])) { + return TRUE; + } + + $rc = $this->validate_arg($arg); + + // If the validator has changed the validate fail condition to a + // soft fail, deal with that: + $validate_info = $this->default_actions($this->options['validate_fail']); + if (empty($validate_info['hard fail'])) { + return TRUE; + } + + return $rc; + } + + /** + * Provide a basic argument validation. + * + * This can be overridden for more complex types; the basic + * validator only checks to see if the argument is not NULL + * or is numeric if the definition says it's numeric. + */ + function validate_argument_basic($arg) { + if (!isset($arg) || $arg === '') { + return FALSE; + } + + if (!empty($this->definition['numeric']) && !isset($this->options['break_phrase']) && !is_numeric($arg)) { + return FALSE; + } + + return TRUE; + } + + /** + * Set the input for this argument + * + * @return TRUE if it successfully validates; FALSE if it does not. + */ + function set_argument($arg) { + $this->argument = $arg; + return $this->validate_arg($arg); + } + + /** + * Get the value of this argument. + */ + function get_value() { + // If we already processed this argument, we're done. + if (isset($this->argument)) { + return $this->argument; + } + + // Otherwise, we have to pretend to process ourself to find the value. + $value = NULL; + // Find the position of this argument within the view. + $position = 0; + foreach ($this->view->argument as $id => $argument) { + if ($id == $this->options['id']) { + break; + } + $position++; + } + + $arg = isset($this->view->args[$position]) ? $this->view->args[$position] : NULL; + $this->position = $position; + + // Clone ourselves so that we don't break things when we're really + // processing the arguments. + $argument = drupal_clone($this); + if (!isset($arg) && $argument->has_default_argument()) { + $arg = $argument->get_default_argument(); + } + // Set the argument, which will also validate that the argument can be set. + if ($argument->set_argument($arg)) { + $value = $argument->argument; + } + unset($argument); + return $value; + } +} + +/** + * A special handler to take the place of missing or broken handlers. + * + * @ingroup views_argument_handlers + */ +class views_handler_argument_broken extends views_handler_argument { + function ui_name($short = FALSE) { + return t('Broken/missing handler'); + } + + function ensure_my_table() { /* No table to ensure! */ } + function query() { /* No query to run */ } + function options_form(&$form, &$form_state) { + $form['markup'] = array( + '#prefix' => '
', + '#value' => t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.'), + ); + } + + /** + * Determine if the handler is considered 'broken' + */ + function broken() { return TRUE; } +} + +/** + * @} + */ diff --git a/sites/all/modules/views/handlers/views_handler_argument_date.inc b/sites/all/modules/views/handlers/views_handler_argument_date.inc new file mode 100644 index 0000000..23d2235 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_argument_date.inc @@ -0,0 +1,66 @@ + t('Current date')); + $form['default_argument_type']['#options'] += array('node_created' => t("Current node's creation time")); + $form['default_argument_type']['#options'] += array('node_changed' => t("Current node's update time")); } + + /** + * Set the empty argument value to the current date, + * formatted appropriately for this argument. + */ + function get_default_argument($raw = FALSE) { + if (!$raw && $this->options['default_argument_type'] == 'date') { + return date($this->arg_format, time()); + } + else if (!$raw && in_array($this->options['default_argument_type'], array('node_created', 'node_changed'))) { + foreach (range(1, 3) as $i) { + $node = menu_get_object('node', $i); + if (!empty($node)) { + continue; + } + } + + if (arg(0) == 'node' && is_numeric(arg(1))) { + $node = node_load(arg(1)); + } + + if (empty($node)) { + return parent::get_default_argument(); + } + else if ($this->options['default_argument_type'] == 'node_created') { + return date($this->arg_format, $node->created); + } + else if ($this->options['default_argument_type'] == 'node_changed') { + return date($this->arg_format, $node->changed); + } + } + + return parent::get_default_argument($raw); + + } +} diff --git a/sites/all/modules/views/handlers/views_handler_argument_formula.inc b/sites/all/modules/views/handlers/views_handler_argument_formula.inc new file mode 100644 index 0000000..67e0b39 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_argument_formula.inc @@ -0,0 +1,54 @@ +definition['formula'])) { + $this->formula = $this->definition['formula']; + } + } + + function get_formula() { + return str_replace('***table***', $this->table_alias, $this->formula); + } + + /** + * Build the summary query based on a formula + */ + function summary_query() { + $this->ensure_my_table(); + // Now that our table is secure, get our formula. + $formula = $this->get_formula(); + + // Add the field. + $this->base_alias = $this->name_alias = $this->query->add_field(NULL, $formula, $this->field); + $this->query->set_count_field(NULL, $formula, $this->field); + + return $this->summary_basics(FALSE); + } + + /** + * Build the query based upon the formula + */ + function query() { + $this->ensure_my_table(); + // Now that our table is secure, get our formula. + $formula = $this->get_formula(); + + $this->query->add_where(0, "$formula = '%s'", $this->argument); + } +} diff --git a/sites/all/modules/views/handlers/views_handler_argument_many_to_one.inc b/sites/all/modules/views/handlers/views_handler_argument_many_to_one.inc new file mode 100644 index 0000000..cc887d4 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_argument_many_to_one.inc @@ -0,0 +1,170 @@ +helper = new views_many_to_one_helper($this); + + // Ensure defaults for these, during summaries and stuff: + $this->operator = 'or'; + $this->value = array(); + } + + function option_definition() { + $options = parent::option_definition(); + + if (!empty($this->definition['numeric'])) { + $options['break_phrase'] = array('default' => FALSE); + } + + $options['add_table'] = array('default' => FALSE); + $options['require_value'] = array('default' => FALSE); + + views_many_to_one_helper::option_definition($options); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + // allow + for or, , for and + if (!empty($this->definition['numeric'])) { + $form['break_phrase'] = array( + '#type' => 'checkbox', + '#title' => t('Allow multiple terms per argument.'), + '#description' => t('If selected, users can enter multiple arguments in the form of 1+2+3 (for OR) or 1,2,3 (for AND).'), + '#default_value' => !empty($this->options['break_phrase']), + ); + } + + $form['add_table'] = array( + '#type' => 'checkbox', + '#title' => t('Allow multiple arguments to work together.'), + '#description' => t('If selected, multiple instances of this argument can work together, as though multiple terms were supplied to the same argument. This setting is not compatible with the "Reduce duplicates" setting.'), + '#default_value' => !empty($this->options['add_table']), + ); + + $form['require_value'] = array( + '#type' => 'checkbox', + '#title' => t('Do not display items with no value in summary'), + '#default_value' => !empty($this->options['require_value']), + ); + + $this->helper->options_form($form, $form_state); + } + + /** + * Override ensure_my_table so we can control how this joins in. + * The operator actually has influence over joining. + */ + function ensure_my_table() { + $this->helper->ensure_my_table(); + } + + function query() { + $empty = FALSE; + if (isset($this->definition['zero is null']) && $this->definition['zero is null']) { + if (empty($this->argument)) { + $empty = TRUE; + } + } + else { + if (!isset($this->argument)) { + $empty = TRUE; + } + } + if ($empty) { + parent::ensure_my_table(); + $this->query->add_where(0, "$this->table_alias.$this->real_field IS NULL"); + return; + } + + if (!empty($this->options['break_phrase'])) { + views_break_phrase($this->argument, $this); + } + else { + $this->value = array($this->argument); + $this->operator = 'or'; + } + + $this->helper->add_filter(); + } + + function title() { + if (!$this->argument) { + return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized'); + } + + if (!empty($this->options['break_phrase'])) { + views_break_phrase($this->argument, $this); + } + else { + $this->value = array($this->argument); + $this->operator = 'or'; + } + + // @todo -- both of these should check definition for alternate keywords. + + if (empty($this->value)) { + return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized'); + } + + if ($this->value === array(-1)) { + return !empty($this->definition['invalid input']) ? $this->definition['invalid input'] : t('Invalid input'); + } + + return implode($this->operator == 'or' ? ' + ' : ', ', $this->title_query()); + } + + function summary_query() { + $field = $this->table . '.' . $this->field; + $join = $this->get_join(); + + if (!empty($this->options['require_value'])) { + $join->type = 'INNER'; + } + + if (empty($this->options['add_table']) || empty($this->view->many_to_one_tables[$field])) { + $this->table_alias = $this->query->ensure_table($this->table, $this->relationship, $join); + } + else { + $this->table_alias = $this->helper->summary_join(); + } + + // Add the field. + $this->base_alias = $this->query->add_field($this->table_alias, $this->real_field); + + $this->summary_name_field(); + + return $this->summary_basics(); + } + + function summary_argument($data) { + $value = $data->{$this->base_alias}; + if (empty($value)) { + $value = 0; + } + + return $value; + } + + /** + * Override for specific title lookups. + */ + function title_query() { + return $this->value; + } +} + diff --git a/sites/all/modules/views/handlers/views_handler_argument_null.inc b/sites/all/modules/views/handlers/views_handler_argument_null.inc new file mode 100644 index 0000000..4010b84 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_argument_null.inc @@ -0,0 +1,59 @@ + FALSE); + return $options; + } + + /** + * Override options_form() so that only the relevant options + * are displayed to the user. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['must_not_be'] = array( + '#type' => 'checkbox', + '#title' => t('Fail basic validation if any argument is given'), + '#default_value' => !empty($this->options['must_not_be']), + '#description' => t('By checking this field, you can use this to make sure views with more arguments than necessary fail validation.'), + ); + + unset($form['wildcard']); + unset($form['wildcard_substitution']); + } + + /** + * Override default_actions() to remove actions that don't + * make sense for a null argument. + */ + function default_actions($which = NULL) { + if ($which) { + if (in_array($which, array('ignore', 'not found', 'empty', 'default'))) { + return parent::default_actions($which); + } + return; + } + $actions = parent::default_actions(); + unset($actions['summary asc']); + unset($actions['summary desc']); + return $actions; + } + + function validate_argument_basic($arg) { + if (!empty($this->options['must_not_be'])) { + return !isset($arg); + } + + return parent::validate_argument_basic($arg); + } + + /** + * Override the behavior of query() to prevent the query + * from being changed in any way. + */ + function query() {} +} diff --git a/sites/all/modules/views/handlers/views_handler_argument_numeric.inc b/sites/all/modules/views/handlers/views_handler_argument_numeric.inc new file mode 100644 index 0000000..235a392 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_argument_numeric.inc @@ -0,0 +1,95 @@ + FALSE); + $options['not'] = array('default' => FALSE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + // allow + for or, , for and + $form['break_phrase'] = array( + '#type' => 'checkbox', + '#title' => t('Allow multiple terms per argument.'), + '#description' => t('If selected, users can enter multiple arguments in the form of 1+2+3 or 1,2,3.'), + '#default_value' => !empty($this->options['break_phrase']), + ); + + $form['not'] = array( + '#type' => 'checkbox', + '#title' => t('Exclude the argument'), + '#description' => t('If selected, the numbers entered in the argument will be excluded rather than limiting the view.'), + '#default_value' => !empty($this->options['not']), + ); + } + + function title() { + if (!$this->argument) { + return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized'); + } + + if (!empty($this->options['break_phrase'])) { + views_break_phrase($this->argument, $this); + } + else { + $this->value = array($this->argument); + $this->operator = 'or'; + } + + if (empty($this->value)) { + return !empty($this->definition['empty field name']) ? $this->definition['empty field name'] : t('Uncategorized'); + } + + if ($this->value === array(-1)) { + return !empty($this->definition['invalid input']) ? $this->definition['invalid input'] : t('Invalid input'); + } + + return implode($this->operator == 'or' ? ' + ' : ', ', $this->title_query()); + } + + /** + * Override for specific title lookups. + */ + function title_query() { + return $this->value; + } + + function query() { + $this->ensure_my_table(); + + if (!empty($this->options['break_phrase'])) { + views_break_phrase($this->argument, $this); + } + else { + $this->value = array($this->argument); + } + + $null_check = empty($this->options['not']) ? '' : " OR $this->table_alias.$this->real_field IS NULL"; + + if (count($this->value) > 1) { + $operator = empty($this->options['not']) ? 'IN' : 'NOT IN'; + $placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d')); + $this->query->add_where(0, "$this->table_alias.$this->real_field $operator ($placeholders) $null_check", $this->value); + } + else { + $operator = empty($this->options['not']) ? '=' : '!='; + $this->query->add_where(0, "$this->table_alias.$this->real_field $operator %d $null_check", $this->argument); + } + } +} diff --git a/sites/all/modules/views/handlers/views_handler_argument_string.inc b/sites/all/modules/views/handlers/views_handler_argument_string.inc new file mode 100644 index 0000000..8dee6b9 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_argument_string.inc @@ -0,0 +1,240 @@ +definition['many to one'])) { + $this->helper = new views_many_to_one_helper($this); + + // Ensure defaults for these, during summaries and stuff: + $this->operator = 'or'; + $this->value = array(); + } + } + + function option_definition() { + $options = parent::option_definition(); + + $options['glossary'] = array('default' => FALSE); + $options['ignorecase'] = array('default' => FALSE); + $options['limit'] = array('default' => 0); + $options['case'] = array('default' => 'none'); + $options['path_case'] = array('default' => 'none'); + $options['transform_dash'] = array('default' => FALSE); + + if (!empty($this->definition['many to one'])) { + $options['add_table'] = array('default' => FALSE); + $options['require_value'] = array('default' => FALSE); + } + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['glossary'] = array( + '#type' => 'checkbox', + '#title' => t('Glossary mode'), + '#description' => t('Glossary mode applies a limit to the number of characters used in the argument, which allows the summary view to act as a glossary.'), + '#default_value' => $this->options['glossary'], + ); + + $form['ignorecase'] = array( + '#type' => 'checkbox', + '#title' => t('Ignore case'), + '#description' => t('Ignore case allows for doing database searches without case sensitivity. MySQL already works in lower-case mode, so MySQL users should leave this unchecked to improve performance.'), + '#default_value' => $this->options['ignorecase'], + ); + + $form['limit'] = array( + '#type' => 'textfield', + '#title' => t('Character limit'), + '#description' => t('How many characters of the argument to filter against. If set to 1, all fields starting with the letter in the argument would be matched.'), + '#default_value' => $this->options['limit'], + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-glossary' => array(TRUE)), + ); + + $form['case'] = array( + '#type' => 'select', + '#title' => t('Case'), + '#description' => t('When printing the argument result, how to transform the case.'), + '#options' => array( + 'none' => t('No transform'), + 'upper' => t('Upper case'), + 'lower' => t('Lower case'), + 'ucfirst' => t('Capitalize first letter'), + 'ucwords' => t('Capitalize each word'), + ), + '#default_value' => $this->options['case'], + ); + + $form['path_case'] = array( + '#type' => 'select', + '#title' => t('Case in path'), + '#description' => t('When printing url paths, how to transform the case of the argument. Do not use this unless with Postgres as it uses case sensitive comparisons.'), + '#options' => array( + 'none' => t('No transform'), + 'upper' => t('Upper case'), + 'lower' => t('Lower case'), + 'ucfirst' => t('Capitalize first letter'), + 'ucwords' => t('Capitalize each word'), + ), + '#default_value' => $this->options['path_case'], + ); + + $form['transform_dash'] = array( + '#type' => 'checkbox', + '#title' => t('Transform spaces to dashes in URL'), + '#default_value' => $this->options['transform_dash'], + ); + + if (!empty($this->definition['many to one'])) { + $form['add_table'] = array( + '#type' => 'checkbox', + '#title' => t('Allow multiple arguments to work together.'), + '#description' => t('If selected, multiple instances of this argument can work together, as though multiple terms were supplied to the same argument. This setting is not compatible with the "Reduce duplicates" setting.'), + '#default_value' => !empty($this->options['add_table']), + ); + + $form['require_value'] = array( + '#type' => 'checkbox', + '#title' => t('Do not display items with no value in summary'), + '#default_value' => !empty($this->options['require_value']), + ); + } + } + + /** + * Build the summary query based on a string + */ + function summary_query() { + if (empty($this->definition['many to one'])) { + $this->ensure_my_table(); + } + else { + $this->table_alias = $this->helper->summary_join(); + } + + if (empty($this->options['glossary'])) { + // Add the field. + if (empty($this->options['ignorecase'])){ + $this->base_alias = $this->name_alias = $this->query->add_field($this->table_alias, $this->real_field); + $this->query->set_count_field($this->table_alias, $this->real_field); + } + else { + $this->base_alias = $this->name_alias = $this->query->add_field($this->table_alias, 'LOWER(' . $this->real_field . ')'); + $this->query->set_count_field($this->table_alias, 'LOWER(' . $this->real_field . ')'); + } + } + else { + // Add the field. + $formula = $this->get_formula(); + if (empty($this->options['ignorecase'])){ + $this->base_alias = $this->name_alias = $this->query->add_field(NULL, $formula, $this->field . '_truncated'); + $this->query->set_count_field(NULL, $formula, $this->field, $this->field . '_truncated'); + } + else { + $this->base_alias = $this->name_alias = $this->query->add_field(NULL, 'LOWER(' . $formula . ')', $this->field . '_truncated'); + $this->query->set_count_field(NULL, $formula, $this->field, $this->field . '_truncated'); + } + } + + return $this->summary_basics(FALSE); + } + + /** + * Get the formula for this argument. + * + * $this->ensure_my_table() MUST have been called prior to this. + */ + function get_formula() { + return "SUBSTR($this->table_alias.$this->real_field, 1, " . intval($this->options['limit']) . ")"; + } + + /** + * Build the query based upon the formula + */ + function query() { + $argument = $this->argument; + if (!empty($this->options['transform_dash'])) { + $argument = strtr($argument, '-', ' '); + } + + if (!empty($this->definition['many to one'])) { + if (!empty($this->options['glossary'])) { + $this->helper->formula = TRUE; + } + $this->value = array($argument); + $this->helper->ensure_my_table(); + $this->helper->add_filter(); + return; + } + + $this->ensure_my_table(); + if (empty($this->options['glossary'])) { + $field = "$this->table_alias.$this->real_field"; + } + else { + $field = $this->get_formula(); + } + + if (empty($this->options['ignorecase'])){ + $this->query->add_where(0, "$field = '%s'", $argument); + } + else { + $this->query->add_where(0, "LOWER($field) = LOWER('%s')", $argument); + } + } + + function summary_argument($data) { + $value = $this->case_transform($data->{$this->base_alias}, 'path_case'); + if (!empty($this->options['transform_dash'])) { + $value = strtr($value, ' ', '-'); + } + return $value; + } + + function case_transform($string, $option) { + global $multibyte; + + switch ($this->options[$option]) { + default: + return $string; + case 'upper': + return drupal_strtoupper($string); + case 'lower': + return drupal_strtolower($string); + case 'ucfirst': + return drupal_strtoupper(drupal_substr($string, 0, 1)) . drupal_substr($string, 1); + case 'ucwords': + if ($multibyte == UNICODE_MULTIBYTE) { + return mb_convert_case($string, MB_CASE_TITLE); + } else { + return ucwords($string); + } + } + } + + function title() { + $title = $this->case_transform($this->argument, 'case'); + if (!empty($this->options['transform_dash'])) { + $title = strtr($title, '-', ' '); + } + + return check_plain($title); + } + + function summary_name($data) { + return $this->case_transform(parent::summary_name($data), 'case'); + } + +} + diff --git a/sites/all/modules/views/handlers/views_handler_field.inc b/sites/all/modules/views/handlers/views_handler_field.inc new file mode 100644 index 0000000..06c6f94 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_field.inc @@ -0,0 +1,859 @@ + array('table' => tablename, + * 'field' => fieldname); as many fields as are necessary + * may be in this array. + * - click sortable: If TRUE, this field may be click sorted. + */ +class views_handler_field extends views_handler { + var $field_alias = 'unknown'; + var $aliases = array(); + + /** + * Construct a new field handler. + */ + function construct() { + parent::construct(); + + $this->additional_fields = array(); + if (!empty($this->definition['additional fields'])) { + $this->additional_fields = $this->definition['additional fields']; + } + + if (!isset($this->options['exclude'])) { + $this->options['exclude'] = ''; + } + } + + /** + * Determine if this field can allow advanced rendering. + * + * Fields can set this to FALSE if they do not wish to allow + * token based rewriting or link-making. + */ + function allow_advanced_render() { + return TRUE; + } + + function init(&$view, $options) { + parent::init($view, $options); + + $this->options += array( + 'exclude' => FALSE, + ); + } + + /** + * Called to add the field to a query. + */ + function query() { + $this->ensure_my_table(); + // Add the field. + $this->field_alias = $this->query->add_field($this->table_alias, $this->real_field); + + $this->add_additional_fields(); + } + + /** + * Add 'additional' fields to the query. + * + * @param $fields + * An array of fields. The key is an identifier used to later find the + * field alias used. The value is either a string in which case it's + * assumed to be a field on this handler's table; or it's an array in the + * form of + * @code array('table' => $tablename, 'field' => $fieldname) @endcode + */ + function add_additional_fields($fields = NULL) { + if (!isset($fields)) { + // notice check + if (empty($this->additional_fields)) { + return; + } + $fields = $this->additional_fields; + } + if (!empty($fields) && is_array($fields)) { + foreach ($fields as $identifier => $info) { + if (is_array($info)) { + if (isset($info['table'])) { + $table_alias = $this->query->ensure_table($info['table'], $this->relationship); + } + else { + $table_alias = $this->table_alias; + } + if (empty($table_alias)) { + vpr(t('Handler @handler tried to add additional_field @identifier but @table could not be added!', array('@handler' => $this->definition['handler'], '@identifier' => $identifier, '@table' => $info['table']))); + $this->aliases[$identifier] = 'broken'; + continue; + } + $this->aliases[$identifier] = $this->query->add_field($table_alias, $info['field']); + } + else { + $this->aliases[$info] = $this->query->add_field($this->table_alias, $info); + } + } + } + } + + /** + * Called to determine what to tell the clicksorter. + */ + function click_sort($order) { + $this->query->add_orderby($this->table_alias, $this->real_field, $order, $this->field_alias); + } + + /** + * Determine if this field is click sortable. + */ + function click_sortable() { + return !empty($this->definition['click sortable']); + } + + /** + * Get this field's label. + */ + function label() { + if (!isset($this->options['label'])) { + return ''; + } + return $this->options['label']; + } + + /** + * Return DIV or SPAN based upon the field's element type. + */ + function element_type() { + if (isset($this->definition['element type'])) { + return $this->definition['element type']; + } + + return 'span'; + } + + function option_definition() { + $options = parent::option_definition(); + + $options['label'] = array('default' => $this->definition['title'], 'translatable' => TRUE); + $options['alter'] = array( + 'contains' => array( + 'alter_text' => array('default' => FALSE), + 'text' => array('default' => '', 'translatable' => TRUE), + 'make_link' => array('default' => FALSE), + 'path' => array('default' => '', 'translatable' => TRUE), + 'absolute' => array('default' => '', 'translatable' => FALSE), + 'alt' => array('default' => '', 'translatable' => TRUE), + 'rel' => array('default' => ''), + 'link_class' => array('default' => ''), + 'prefix' => array('default' => '', 'translatable' => TRUE), + 'suffix' => array('default' => '', 'translatable' => TRUE), + 'target' => array('default' => '', 'translatable' => TRUE), + 'trim' => array('default' => FALSE), + 'max_length' => array('default' => ''), + 'word_boundary' => array('default' => TRUE), + 'ellipsis' => array('default' => TRUE), + 'strip_tags' => array('default' => FALSE), + 'html' => array('default' => FALSE), + ), + ); + $options['empty'] = array('default' => '', 'translatable' => TRUE); + $options['hide_empty'] = array('default' => FALSE); + $options['empty_zero'] = array('default' => FALSE); + $options['hide_alter_empty'] = array('default' => TRUE); + + return $options; + } + + /** + * Default options form that provides the label widget that all fields + * should have. + */ + function options_form(&$form, &$form_state) { + $form['label'] = array( + '#type' => 'textfield', + '#title' => t('Label'), + '#default_value' => isset($this->options['label']) ? $this->options['label'] : '', + '#description' => t('The label for this field that will be displayed to end users if the style requires it.'), + ); + $form['exclude'] = array( + '#type' => 'checkbox', + '#title' => t('Exclude from display'), + '#default_value' => $this->options['exclude'], + '#description' => t('Check this box to not display this field, but still load it in the view. Use this option to not show a grouping field in each record, or when doing advanced theming.'), + ); + + if ($this->allow_advanced_render()) { + $form['alter']['#tree'] = TRUE; + $form['alter']['alter_text'] = array( + '#type' => 'checkbox', + '#title' => t('Rewrite the output of this field'), + '#description' => t('If checked, you can alter the output of this field by specifying a string of text with replacement tokens that can use any existing field output.'), + '#default_value' => $this->options['alter']['alter_text'], + ); + + $form['alter']['text'] = array( + '#title' => t('Text'), + '#type' => 'textarea', + '#default_value' => $this->options['alter']['text'], + '#description' => t('The text to display for this field. You may include HTML. You may enter data from this view as per the "Replacement patterns" below.'), + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-alter-alter-text' => array(1) + ), + ); + + $form['alter']['make_link'] = array( + '#type' => 'checkbox', + '#title' => t('Output this field as a link'), + '#description' => t('If checked, this field will be made into a link. The destination must be given below.'), + '#default_value' => $this->options['alter']['make_link'], + ); + $form['alter']['path'] = array( + '#title' => t('Link path'), + '#type' => 'textfield', + '#default_value' => $this->options['alter']['path'], + '#description' => t('The Drupal path or absolute URL for this link. You may enter data from this view as per the "Replacement patterns" below.'), + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-alter-make-link' => array(1) + ), + '#maxlength' => 255, + ); + $form['alter']['absolute'] = array( + '#type' => 'checkbox', + '#title' => t('Use absolute path'), + '#default_value' => $this->options['alter']['absolute'], + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-alter-make-link' => array(1) + ), + ); + + $form['alter']['link_class'] = array( + '#title' => t('Link class'), + '#type' => 'textfield', + '#default_value' => $this->options['alter']['link_class'], + '#description' => t('The CSS class to apply to the link.'), + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-alter-make-link' => array(1) + ), + ); + $form['alter']['alt'] = array( + '#title' => t('Alt text'), + '#type' => 'textfield', + '#default_value' => $this->options['alter']['alt'], + '#description' => t('Text to place as "alt" text which most browsers display as a tooltip when hovering over the link.'), + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-alter-make-link' => array(1) + ), + ); + $form['alter']['rel'] = array( + '#title' => t('Rel Text'), + '#type' => 'textfield', + '#default_value' => $this->options['alter']['rel'], + '#description' => t('Include Rel attribute for use in lightbox2 or other javascript utility.'), + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-alter-make-link' => array(1) + ), + ); + $form['alter']['prefix'] = array( + '#title' => t('Prefix text'), + '#type' => 'textfield', + '#default_value' => $this->options['alter']['prefix'], + '#description' => t('Any text to display before this link. You may include HTML.'), + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-alter-make-link' => array(1) + ), + ); + $form['alter']['suffix'] = array( + '#title' => t('Suffix text'), + '#type' => 'textfield', + '#default_value' => $this->options['alter']['suffix'], + '#description' => t('Any text to display after this link. You may include HTML.'), + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-alter-make-link' => array(1) + ), + ); + $form['alter']['target'] = array( + '#title' => t('Target'), + '#type' => 'textfield', + '#default_value' => $this->options['alter']['target'], + '#description' => t("Target of the link, such as _blank, _parent or an iframe's name. This field is rarely used."), + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-alter-make-link' => array(1) + ), + ); + + + // Get a list of the available fields and arguments for token replacement. + $options = array(); + foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) { + $options[t('Fields')]["[$field]"] = $handler->ui_name(); + // We only use fields up to (and including) this one. + if ($field == $this->options['id']) { + break; + } + } + $count = 0; // This lets us prepare the key as we want it printed. + foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) { + $options[t('Arguments')]['%' . ++$count] = t('@argument title', array('@argument' => $handler->ui_name())); + $options[t('Arguments')]['!' . $count] = t('@argument input', array('@argument' => $handler->ui_name())); + } + + $this->document_self_tokens($options[t('Fields')]); + + // Default text. + $output = t('

You must add some additional fields to this display before using this field. These fields may be marked as Exclude from display if you prefer. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields.

'); + // We have some options, so make a list. + if (!empty($options)) { + $output = t('

The following tokens are available for this field. Note that due to rendering order, you cannot use fields that come after this field; if you need a field not listed here, rearrange your fields. +If you would like to have the characters %5B and %5D please use the html entity codes \'%5B\' or \'%5D\' or they will get replaced with empty space.

'); + foreach (array_keys($options) as $type) { + if (!empty($options[$type])) { + $items = array(); + foreach ($options[$type] as $key => $value) { + $items[] = $key . ' == ' . $value; + } + $output .= theme('item_list', $items, $type); + } + } + } + // This construct uses 'hidden' and not markup because process doesn't + // run. It also has an extra div because the dependency wants to hide + // the parent in situations like this, so we need a second div to + // make this work. + $form['alter']['help'] = array( + '#type' => 'hidden', + '#id' => 'views-tokens-help', + '#prefix' => '
' . t('Replacement patterns') . '' . $output . '
', + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-alter-make-link' => array(1), + 'edit-options-alter-alter-text' => array(1), + ), + ); + + $form['alter']['trim'] = array( + '#type' => 'checkbox', + '#title' => t('Trim this field to a maximum length'), + '#description' => t('If checked, this field be trimmed to a maximum length in characters.'), + '#default_value' => $this->options['alter']['trim'], + ); + + $form['alter']['max_length'] = array( + '#title' => t('Maximum length'), + '#type' => 'textfield', + '#default_value' => $this->options['alter']['max_length'], + '#description' => t('The maximum number of characters this field can be.'), + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-alter-trim' => array(1) + ), + ); + + $form['alter']['word_boundary'] = array( + '#type' => 'checkbox', + '#title' => t('Trim only on a word boundary'), + '#description' => t('If checked, this field be trimmed only on a word boundary. This is guaranteed to be the maximum characters stated or less. If there are no word boundaries this could trim a field to nothing.'), + '#default_value' => $this->options['alter']['word_boundary'], + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-alter-trim' => array(1) + ), + ); + + $form['alter']['ellipsis'] = array( + '#type' => 'checkbox', + '#title' => t('Add an ellipsis'), + '#description' => t('If checked, a "..." will be added if a field was trimmed.'), + '#default_value' => $this->options['alter']['ellipsis'], + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-alter-trim' => array(1) + ), + ); + + $form['alter']['html'] = array( + '#type' => 'checkbox', + '#title' => t('Field can contain HTML'), + '#description' => t('If checked, HTML corrector will be run to ensure tags are properly closed after trimming.'), + '#default_value' => $this->options['alter']['html'], + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-alter-trim' => array(1) + ), + ); + + $form['alter']['strip_tags'] = array( + '#type' => 'checkbox', + '#title' => t('Strip HTML tags'), + '#description' => t('If checked, all HTML tags will be stripped.'), + '#default_value' => $this->options['alter']['strip_tags'], + '#process' => array('views_process_dependency'), + ); + } + + $form['empty'] = array( + '#type' => 'textfield', + '#title' => t('Empty text'), + '#default_value' => $this->options['empty'], + '#description' => t('If the field is empty, display this text instead.'), + ); + + $form['empty_zero'] = array( + '#type' => 'checkbox', + '#title' => t('Count the number 0 as empty'), + '#default_value' => $this->options['empty_zero'], + '#description' => t('If the field contains the number zero, display the empty text instead'), + ); + + $form['hide_empty'] = array( + '#type' => 'checkbox', + '#title' => t('Hide if empty'), + '#default_value' => $this->options['hide_empty'], + '#description' => t('Enable to hide this field if it is empty. Note that the field label or rewritten output may still be displayed. To hide labels, check the style or row style settings for empty fields. To hide rewritten content, check the Hide rewriting if empty checkbox.'), + ); + + $form['hide_alter_empty'] = array( + '#type' => 'checkbox', + '#title' => t('Do not rewrite if empty'), + '#default_value' => $this->options['hide_alter_empty'], + ); + } + + /** + * Provide extra data to the administration form + */ + function admin_summary() { + return $this->label(); + } + + /** + * Run before any fields are rendered. + * + * This gives the handlers some time to set up before any handler has + * been rendered. + * + * @param $values + * An array of all objects returned from the query. + */ + function pre_render($values) { } + + /** + * Render the field. + * + * @param $values + * The values retrieved from the database. + */ + function render($values) { + $value = $values->{$this->field_alias}; + return check_plain($value); + } + + /** + * Render a field using advanced settings. + * + * This renders a field normally, then decides if render-as-link and + * text-replacement rendering is necessary. + */ + function advanced_render($values) { + if ($this->allow_advanced_render() && method_exists($this, 'render_item')) { + $raw_items = $this->get_items($values); + } + else { + $this->last_render = $value = $this->render($values); + $this->original_value = $value; + } + + if ($this->allow_advanced_render()) { + $tokens = NULL; + if (method_exists($this, 'render_item')) { + $items = array(); + foreach ($raw_items as $count => $item) { + $this->last_render = $this->render_item($count, $item); + $this->original_value = $this->last_render; + + $alter = $item + $this->options['alter']; + $items[] = $this->render_text($alter); + } + + $value = $this->render_items($items); + } + else { + $value = $this->render_text($this->options['alter']); + } + + // This happens here so that render_as_link can get the unaltered value of + // this field as a token rather than the altered value. + $this->last_render = $value; + } + + if (empty($this->last_render)) { + if (($this->last_render !== 0 && $this->last_render !== '0') || !empty($this->options['empty_zero'])) { + $alter = $this->options['alter']; + $alter['alter_text'] = 1; + $alter['text'] = $this->options['empty']; + $this->last_render = $this->render_text($alter); + } + } + + return $this->last_render; + } + + /** + * Perform an advanced text render for the item. + * + * This is separated out as some fields may render lists, and this allows + * each item to be handled individually. + */ + function render_text($alter) { + $value = trim($this->last_render); + + if (!empty($alter['alter_text']) && $alter['text'] !== '') { + $tokens = $this->get_render_tokens($alter); + $value = $this->render_altered($alter, $tokens); + } + + if ((($this->options['hide_empty'] && empty($value)) || ($this->options['hide_alter_empty'] && empty($this->original_value))) && ($value !== 0 || $this->options['empty_zero'])) { + return ''; + } + + if (!empty($alter['strip_tags'])) { + $value = strip_tags($value); + } + + if (!empty($alter['trim']) && !empty($alter['max_length'])) { + $value = $this->render_trim_text($alter, $value); + } + + if (!empty($alter['make_link']) && !empty($alter['path'])) { + if (!isset($tokens)) { + $tokens = $this->get_render_tokens($alter); + } + $value = $this->render_as_link($alter, $value, $tokens); + } + + return $value; + } + + /** + * Render this field as altered text, from a fieldset set by the user. + */ + function render_altered($alter, $tokens) { + // Filter this right away as our substitutions are already sanitized. + $value = filter_xss_admin($alter['text']); + $value = strtr($value, $tokens); + + return $value; + } + + /** + * Trim the field down to the specified length. + */ + function render_trim_text($alter, $value) { + if (!empty($alter['strip_tags'])) { + // NOTE: It's possible that some external fields might override the + // element type so if someone from, say, CCK runs into a bug here, + // this may be why =) + $this->definition['element type'] = 'span'; + } + return views_trim_text($alter, $value); + } + + /** + * Render this field as a link, with the info from a fieldset set by + * the user. + */ + function render_as_link($alter, $text, $tokens) { + $value = ''; + + if (!empty($alter['prefix'])) { + $value .= filter_xss_admin(strtr($alter['prefix'], $tokens)); + } + + $options = array( + 'html' => TRUE, + 'absolute' => !empty($alter['absolute']) ? TRUE : FALSE, + ); + + // $path will be run through check_url() by l() so we do not need to + // sanitize it ourselves. + $path = $alter['path']; + + // html_entity_decode removes , so check whether its different to front. + if ($path != '') { + // Use strip tags as there should never be HTML in the path. + // However, we need to preserve special characters like " that + // were removed by check_plain(). + $path = strip_tags(html_entity_decode(strtr($path, $tokens))); + } + + // If the path is empty do not build a link around the given text and return + // it as is. + if (empty($path)) { + return $text; + } + + // Parse the URL and move any query and fragment parameters out of the path. + $url = parse_url($path); + if (isset($url['query'])) { + $path = strtr($path, array('?' . $url['query'] => '')); + $options['query'] = $url['query']; + } + if (isset($url['fragment'])) { + $path = strtr($path, array('#' . $url['fragment'] => '')); + // If the path is empty we want to have a fragment for the current site. + if ($path == '') { + $options['external'] = TRUE; + } + $options['fragment'] = $url['fragment']; + } + + $alt = strtr($alter['alt'], $tokens); + // Set the title attribute of the link only if it improves accessibility + if ($alt && $alt != $text) { + $options['attributes']['title'] = html_entity_decode($alt, ENT_QUOTES); + } + + $class = strtr($alter['link_class'], $tokens); + if ($class) { + $options['attributes']['class'] = $class; + } + + if (!empty($alter['rel']) && $rel = strtr($alter['rel'], $tokens)) { + $options['attributes']['rel'] = $rel; + } + + $target = check_plain(trim(strtr($alter['target'],$tokens))); + if (!empty($target)) { + $options['attributes']['target'] = $target; + } + + // Allow the addition of arbitrary attributes to links. Additional attributes + // currently can only be altered in preprocessors and not within the UI. + if (isset($alter['link_attributes']) && is_array($alter['link_attributes'])) { + foreach ($alter['link_attributes'] as $key => $attribute) { + if (!isset($options['attributes'][$key])) { + $options['attributes'][$key] = strtr($attribute, $tokens); + } + } + } + + // If the query and fragment were programatically assigned overwrite any + // parsed values. + if (isset($alter['query'])) { + $options['query'] = strtr($alter['query'], $tokens); + } + if (isset($alter['alias'])) { + // Alias is a boolean field, so no token. + $options['alias'] = $alter['alias']; + } + if (isset($alter['fragment'])) { + $options['fragment'] = strtr($alter['fragment'], $tokens); + } + if (isset($this->options['alter']['language'])) { + $options['language'] = $this->options['alter']['language']; + } + + $value .= l($text, $path, $options); + + if (!empty($alter['suffix'])) { + $value .= filter_xss_admin(strtr($alter['suffix'], $tokens)); + } + + return $value; + } + + /** + * Get the 'render' tokens to use for advanced rendering. + * + * This runs through all of the fields and arguments that + * are available and gets their values. This will then be + * used in one giant str_replace(). + */ + function get_render_tokens($item) { + $tokens = array(); + if (!empty($this->view->build_info['substitutions'])) { + $tokens = $this->view->build_info['substitutions']; + } + $count = 0; + foreach ($this->view->display_handler->get_handlers('argument') as $arg => $handler) { + $token = '%' . ++$count; + if (!isset($tokens[$token])) { + $tokens[$token] = ''; + } + + // Use strip tags as there should never be HTML in the path. + // However, we need to preserve special characters like " that + // were removed by check_plain(). + $tokens['!' . $count] = isset($this->view->args[$count - 1]) ? strip_tags(html_entity_decode($this->view->args[$count - 1])) : ''; + } + + // Now add replacements for our fields. + foreach ($this->view->display_handler->get_handlers('field') as $field => $handler) { + if (isset($handler->last_render)) { + $tokens["[$field]"] = $handler->last_render; + } + else { + $tokens["[$field]"] = ''; + } + $this->add_self_tokens($tokens, $item); + + // We only use fields up to (and including) this one. + if ($field == $this->options['id']) { + break; + } + } + + return $tokens; + } + + /** + * Add any special tokens this field might use for itself. + * + * This method is intended to be overridden by items that generate + * fields as a list. For example, the field that displays all terms + * on a node might have tokens for the tid and the term. + * + * By convention, tokens should follow the format of [token-subtoken] + * where token is the field ID and subtoken is the field. If the + * field ID is terms, then the tokens might be [terms-tid] and [terms-name]. + */ + function add_self_tokens(&$tokens, $item) { } + + /** + * Document any special tokens this field might use for itself. + * + * @see add_self_tokens() for details. + */ + function document_self_tokens(&$tokens) { } + + /** + * Call out to the theme() function, which probably just calls render() but + * allows sites to override output fairly easily. + */ + function theme($values) { + return theme($this->theme_functions(), $this->view, $this, $values); + } + + function theme_functions() { + $themes = array(); + $hook = 'views_view_field'; + + $display = $this->view->display[$this->view->current_display]; + + if (!empty($display)) { + $themes[] = $hook . '__' . $this->view->name . '__' . $display->id . '__' . $this->options['id']; + $themes[] = $hook . '__' . $this->view->name . '__' . $display->id; + $themes[] = $hook . '__' . $display->id . '__' . $this->options['id']; + $themes[] = $hook . '__' . $display->id; + if ($display->id != $display->display_plugin) { + $themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin . '__' . $this->options['id']; + $themes[] = $hook . '__' . $this->view->name . '__' . $display->display_plugin; + $themes[] = $hook . '__' . $display->display_plugin . '__' . $this->options['id']; + $themes[] = $hook . '__' . $display->display_plugin; + } + } + $themes[] = $hook . '__' . $this->view->name . '__' . $this->options['id']; + $themes[] = $hook . '__' . $this->view->name; + $themes[] = $hook . '__' . $this->options['id']; + $themes[] = $hook; + + return $themes; + } +} + +/** + * A special handler to take the place of missing or broken handlers. + */ +class views_handler_field_broken extends views_handler_field { + function ui_name($short = FALSE) { + return t('Broken/missing handler'); + } + + function ensure_my_table() { /* No table to ensure! */ } + function query() { /* No query to run */ } + function options_form(&$form, &$form_state) { + $form['markup'] = array( + '#prefix' => '
', + '#value' => t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.'), + ); + } + + /** + * Determine if the handler is considered 'broken' + */ + function broken() { return TRUE; } +} + +/** + * Render a numeric value as a size. + */ +class views_handler_field_file_size extends views_handler_field { + function option_definition() { + $options = parent::option_definition(); + + $options['file_size_display'] = array('default' => 'formatted'); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['file_size_display'] = array( + '#title' => t('File size display'), + '#type' => 'select', + '#options' => array( + 'formatted' => t('Formatted (in KB or MB)'), + 'bytes' => t('Raw bytes'), + ), + ); + } + + function render($values) { + if ($values->{$this->field_alias}) { + switch ($this->options['file_size_display']) { + case 'bytes': + return $values->{$this->field_alias}; + case 'formatted': + default: + return format_size($values->{$this->field_alias}); + } + } + else { + return ''; + } + } +} + +/** + * A handler to run a field through simple XSS filtering + */ +class views_handler_field_xss extends views_handler_field { + function render($values) { + $value = $values->{$this->field_alias}; + return filter_xss($value); + } +} + +/** + * @} + */ + diff --git a/sites/all/modules/views/handlers/views_handler_field_boolean.inc b/sites/all/modules/views/handlers/views_handler_field_boolean.inc new file mode 100644 index 0000000..16450f2 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_field_boolean.inc @@ -0,0 +1,73 @@ + array( + * 'sticky' => array(t('Sticky'), ''), + * ), + * @endcode + * + * @ingroup views_field_handlers + */ +class views_handler_field_boolean extends views_handler_field { + function option_definition() { + $options = parent::option_definition(); + $options['type'] = array('default' => 'yes-no'); + $options['not'] = array('definition bool' => 'reverse'); + + return $options; + } + + function init(&$view, $options) { + parent::init($view, $options); + + $default_formats = array( + 'yes-no' => array(t('Yes'), t('No')), + 'true-false' => array(t('True'), t('False')), + 'on-off' => array(t('On'), t('Off')), + ); + $output_formats = isset($this->definition['output formats']) ? $this->definition['output formats'] : array(); + $this->formats = array_merge($default_formats, $output_formats); + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + foreach ($this->formats as $key => $item) { + $options[$key] = implode('/', $item); + } + + $form['type'] = array( + '#type' => 'select', + '#title' => t('Output format'), + '#options' => $options, + '#default_value' => $this->options['type'], + ); + $form['not'] = array( + '#type' => 'checkbox', + '#title' => t('Reverse'), + '#description' => t('If checked, true will be displayed as false.'), + '#default_value' => $this->options['not'], + ); + } + + function render($values) { + $value = $values->{$this->field_alias}; + if (!empty($this->options['not'])) { + $value = !$value; + } + + if (isset($this->formats[$this->options['type']])) { + return $value ? $this->formats[$this->options['type']][0] : $this->formats[$this->options['type']][1]; + } + else { + return $value ? $this->formats['yes-no'][0] : $this->formats['yes-no'][1]; + } + } +} diff --git a/sites/all/modules/views/handlers/views_handler_field_counter.inc b/sites/all/modules/views/handlers/views_handler_field_counter.inc new file mode 100644 index 0000000..bc09ef1 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_field_counter.inc @@ -0,0 +1,41 @@ + 1); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['counter_start'] = array( + '#type' => 'textfield', + '#title' => t('Starting value'), + '#default_value' => $this->options['counter_start'], + '#description' => t('Specify the number the counter should start at.'), + //'#process' => array('views_process_dependency'), + '#size' => 2, + ); + } + + function query() { + // do nothing -- to override the parent query. + } + + function render($values) { + // Note: 1 is subtracted from the counter start value below because the + // counter value is incremented by 1 at the end of this function. + $count = is_numeric($this->options['counter_start']) ? $this->options['counter_start'] - 1 : 0; + $pager = $this->view->pager; + // Get the base count of the pager. + if ($pager['use_pager']) { + $count += ($pager['items_per_page'] * $pager['current_page']) + $pager['offset']; + } + // Add the counter for the current site. + $count += $this->view->row_index + 1; + + return $count; + } +} diff --git a/sites/all/modules/views/handlers/views_handler_field_custom.inc b/sites/all/modules/views/handlers/views_handler_field_custom.inc new file mode 100644 index 0000000..c6e687b --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_field_custom.inc @@ -0,0 +1,35 @@ + TRUE); + $options['hide_alter_empty'] = array('default' => FALSE); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + // Remove the checkbox + unset($form['alter']['alter_text']); + unset($form['alter']['text']['#dependency']); + unset($form['alter']['text']['#process']); + } + + function render($values) { + // Return the text, so the code never thinks the value is empty. + return $this->options['alter']['text']; + } +} diff --git a/sites/all/modules/views/handlers/views_handler_field_date.inc b/sites/all/modules/views/handlers/views_handler_field_date.inc new file mode 100644 index 0000000..7c2d51f --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_field_date.inc @@ -0,0 +1,74 @@ + 'small'); + $options['custom_date_format'] = array('default' => ''); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $time = time(); + + $form['date_format'] = array( + '#type' => 'select', + '#title' => t('Date format'), + '#options' => array( + 'small' => t('Short date format') . ' ' . format_date($time, 'small'), + 'medium' => t('Medium date format') . ' ' . format_date($time, 'medium'), + 'large' => t('Long date format') . ' ' . format_date($time, 'large'), + 'custom' => t('Custom'), + 'raw time ago' => t('Time ago'), + 'time ago' => t('Time ago (with "ago" appended)'), + 'raw time span' => t('Time span (future dates start with - )'), + 'time span' => t('Time span (with "ago/hence" appended)'), + ), + '#default_value' => isset($this->options['date_format']) ? $this->options['date_format'] : 'small', + ); + $form['custom_date_format'] = array( + '#type' => 'textfield', + '#title' => t('Custom date format'), + '#description' => t('If "Custom", see the PHP docs for date formats. If "Time ago", enter the number of different time units to display, which defaults to 2.'), + '#default_value' => isset($this->options['custom_date_format']) ? $this->options['custom_date_format'] : '', + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-date-format' => array('custom', 'raw time ago', 'time ago', 'raw time span', 'time span')), + ); + } + + function render($values) { + $value = $values->{$this->field_alias}; + $format = $this->options['date_format']; + if (in_array($format, array('custom', 'raw time ago', 'time ago', 'raw time span', 'time span'))) { + $custom_format = $this->options['custom_date_format']; + } + + if ($value) { + $time_diff = time() - $value; // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence) + switch ($format) { + case 'raw time ago': + return format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2); + case 'time ago': + return t('%time ago', array('%time' => format_interval($time_diff, is_numeric($custom_format) ? $custom_format : 2))); + case 'raw time span': + return ($time_diff < 0 ? '-' : '') . format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2); + case 'time span': + return t(($time_diff < 0 ? '%time hence' : '%time ago'), array('%time' => format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2))); + case 'custom': + if ($custom_format == 'r') { + return format_date($value, $format, $custom_format, null, 'en'); + } + return format_date($value, $format, $custom_format); + default: + return format_date($value, $format); + } + } + } +} diff --git a/sites/all/modules/views/handlers/views_handler_field_markup.inc b/sites/all/modules/views/handlers/views_handler_field_markup.inc new file mode 100644 index 0000000..b555ab8 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_field_markup.inc @@ -0,0 +1,44 @@ +format = $this->definition['format']; + + $this->additional_fields = array(); + if (!is_numeric($this->format)) { + $this->additional_fields['format'] = array('field' => $this->format); + } + } + + function render($values) { + $value = $values->{$this->field_alias}; + $format = is_numeric($this->format) ? $this->format : $values->{$this->aliases['format']}; + if ($value) { + $value = str_replace('', '', $value); + return check_markup($value, $format, FALSE); + } + } + + function element_type() { + if (isset($this->definition['element type'])) { + return $this->definition['element type']; + } + + return 'div'; + } +} diff --git a/sites/all/modules/views/handlers/views_handler_field_math.inc b/sites/all/modules/views/handlers/views_handler_field_math.inc new file mode 100644 index 0000000..933f2e8 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_field_math.inc @@ -0,0 +1,73 @@ + ''); + + return $options; + } + + function options_form(&$form, &$form_state) { + $form['expression'] = array( + '#type' => 'textarea', + '#title' => t('Expression'), + '#description' => t('Enter mathematical expressions such as 2 + 2 or sqrt(5). You my assign variables and create mathematical functions and evaluate them. Use the ; to separate these. For example: f(x) = x + 2; f(2).'), + '#default_value' => $this->options['expression'], + ); + + // Create a place for the help + $form['expression_help'] = array(); + parent::options_form($form, $form_state); + + // Then move the existing help: + $form['expression_help'] = $form['alter']['help']; + unset($form['expression_help']['#dependency']); + unset($form['expression_help']['#process']); + unset($form['alter']['help']); + } + + function render($values) { + ctools_include('math-expr'); + $value = strtr($this->options['expression'], $this->get_render_tokens(array())); + $expressions = explode(';', $value); + $math = new ctools_math_expr; + foreach ($expressions as $expression) { + if ($expression !== '') { + $value = $math->evaluate($expression); + } + } + + // The rest is directly from views_handler_field_numeric but because it + // does not allow the value to be passed in, it is copied. + if (!empty($this->options['set_precision'])) { + $value = number_format($value, $this->options['precision'], $this->options['decimal'], $this->options['separator']); + } + else { + $remainder = abs($value) - intval(abs($value)); + $value = $value > 0 ? floor($value) : ceil($value); + $value = number_format($value, 0, '', $this->options['separator']); + if ($remainder) { + // The substr may not be locale safe. + $value .= $this->options['decimal'] . substr($remainder, 2); + } + } + + // Check to see if hiding should happen before adding prefix and suffix. + if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) { + return ''; + } + + return check_plain($this->options['prefix'] . $value . $this->options['suffix']); + } + + function query() { } +} diff --git a/sites/all/modules/views/handlers/views_handler_field_numeric.inc b/sites/all/modules/views/handlers/views_handler_field_numeric.inc new file mode 100644 index 0000000..791747d --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_field_numeric.inc @@ -0,0 +1,125 @@ + FALSE); + $options['precision'] = array('default' => 0); + $options['decimal'] = array('default' => '.', 'translatable' => TRUE); + $options['separator'] = array('default' => ',', 'translatable' => TRUE); + $options['format_plural'] = array('default' => FALSE); + $options['format_plural_singular'] = array('default' => '1'); + $options['format_plural_plural'] = array('default' => '@count'); + $options['prefix'] = array('default' => '', 'translatable' => TRUE); + $options['suffix'] = array('default' => '', 'translatable' => TRUE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + if (!empty($this->definition['float'])) { + $form['set_precision'] = array( + '#type' => 'checkbox', + '#title' => t('Round'), + '#description' => t('If checked, the number will be rounded.'), + '#default_value' => $this->options['set_precision'], + ); + $form['precision'] = array( + '#type' => 'textfield', + '#title' => t('Precision'), + '#default_value' => $this->options['precision'], + '#description' => t('Specify how many digits to print after the decimal point.'), + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-set-precision' => array(TRUE)), + '#size' => 2, + ); + $form['decimal'] = array( + '#type' => 'textfield', + '#title' => t('Decimal point'), + '#default_value' => $this->options['decimal'], + '#description' => t('What single character to use as a decimal point.'), + '#size' => 2, + ); + } + $form['separator'] = array( + '#type' => 'textfield', + '#title' => t('Thousands separator'), + '#default_value' => $this->options['separator'], + '#description' => t('What single character to use as the thousands separator.'), + '#size' => 2, + ); + $form['format_plural'] = array( + '#type' => 'checkbox', + '#title' => t('Format plural'), + '#description' => t('If checked, special handling will be used for plurality.'), + '#default_value' => $this->options['format_plural'], + ); + $form['format_plural_singular'] = array( + '#type' => 'textfield', + '#title' => t('Singular form'), + '#default_value' => $this->options['format_plural_singular'], + '#description' => t('Text to use for the singular form.'), + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-format-plural' => array(TRUE)), + ); + $form['format_plural_plural'] = array( + '#type' => 'textfield', + '#title' => t('Plural form'), + '#default_value' => $this->options['format_plural_plural'], + '#description' => t('Text to use for the plural form, @count will be replaced with the value.'), + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-format-plural' => array(TRUE)), + ); + $form['prefix'] = array( + '#type' => 'textfield', + '#title' => t('Prefix'), + '#default_value' => $this->options['prefix'], + '#description' => t('Text to put before the number, such as currency symbol.'), + ); + $form['suffix'] = array( + '#type' => 'textfield', + '#title' => t('Suffix'), + '#default_value' => $this->options['suffix'], + '#description' => t('Text to put after the number, such as currency symbol.'), + ); + } + + function render($values) { + $value = $values->{$this->field_alias}; + if (!empty($this->options['set_precision'])) { + $value = number_format($value, $this->options['precision'], $this->options['decimal'], $this->options['separator']); + } + else { + $remainder = abs($value) - intval(abs($value)); + $value = $value > 0 ? floor($value) : ceil($value); + $value = number_format($value, 0, '', $this->options['separator']); + if ($remainder) { + // The substr may not be locale safe. + $value .= $this->options['decimal'] . substr($remainder, 2); + } + } + + // Check to see if hiding should happen before adding prefix and suffix. + if ($this->options['hide_empty'] && empty($value) && ($value !== 0 || $this->options['empty_zero'])) { + return ''; + } + + // Should we format as a plural. + if (!empty($this->options['format_plural'])) { + $value = format_plural($value, $this->options['format_plural_singular'], $this->options['format_plural_plural']); + } + + return filter_xss($this->options['prefix']) . check_plain($value) . filter_xss($this->options['suffix']); + } +} diff --git a/sites/all/modules/views/handlers/views_handler_field_prerender_list.inc b/sites/all/modules/views/handlers/views_handler_field_prerender_list.inc new file mode 100644 index 0000000..c04e3d1 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_field_prerender_list.inc @@ -0,0 +1,111 @@ +items + * + * @ingroup views_field_handlers + */ +class views_handler_field_prerender_list extends views_handler_field { + function option_definition() { + $options = parent::option_definition(); + + $options['type'] = array('default' => 'separator'); + $options['separator'] = array('default' => ', '); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['type'] = array( + '#type' => 'radios', + '#title' => t('Display type'), + '#options' => array( + 'ul' => t('Unordered list'), + 'ol' => t('Ordered list'), + 'separator' => t('Simple separator'), + ), + '#default_value' => $this->options['type'], + ); + + $form['separator'] = array( + '#type' => 'textfield', + '#title' => t('Separator'), + '#default_value' => $this->options['separator'], + '#process' => array('views_process_dependency'), + '#dependency' => array('radio:options[type]' => array('separator')), + ); + } + + /** + * Render the field. + * + * This function is deprecated, but left in for older systems that have not + * yet or won't update their prerender list fields. If a render_item method + * exists, this will not get used by advanced_render. + */ + function render($values) { + $field = $values->{$this->field_alias}; + if (!empty($this->items[$field])) { + if ($this->options['type'] == 'separator') { + return implode(check_plain($this->options['separator']), $this->items[$field]); + } + else { + return theme('item_list', $this->items[$field], NULL, $this->options['type']); + } + } + } + + /** + * Render all items in this field together. + * + * When using advanced render, each possible item in the list is rendered + * individually. Then the items are all pasted together. + */ + function render_items($items) { + if (!empty($items)) { + if ($this->options['type'] == 'separator') { + return implode(check_plain($this->options['separator']), $items); + } + else { + return theme('item_list', $items, NULL, $this->options['type']); + } + } + } + + /** + * Return an array of items for the field. + * + * Items should be stored in the result array, if possible, as an array + * with 'value' as the actual displayable value of the item, plus + * any items that might be found in the 'alter' options array for + * creating links, such as 'path', 'fragment', 'query' etc, such a thing + * is to be made. Additionally, items that might be turned into tokens + * should also be in this array. + */ + function get_items($values) { + $field = $values->{$this->field_alias}; + if (!empty($this->items[$field])) { + return $this->items[$field]; + } + + return array(); + } + + /** + * Determine if advanced rendering is allowed. + * + * By default, advanced rendering will NOT be allowed if the class + * inheriting from this does not implement a 'render_items' method. + */ + function allow_advanced_render() { + // Note that the advanced render bits also use the presence of + // this method to determine if it needs to render items as a list. + return method_exists($this, 'render_item'); + } +} diff --git a/sites/all/modules/views/handlers/views_handler_field_url.inc b/sites/all/modules/views/handlers/views_handler_field_url.inc new file mode 100644 index 0000000..2eb765b --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_field_url.inc @@ -0,0 +1,38 @@ + TRUE); + + return $options; + } + + /** + * Provide link to the page being visited. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['display_as_link'] = array( + '#title' => t('Display as link'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['display_as_link']), + ); + } + + function render($values) { + $value = $values->{$this->field_alias}; + if (!empty($this->options['display_as_link'])) { + return l(check_plain($value), $value, array('html' => TRUE)); + } + else { + return check_url($value); + } + } +} diff --git a/sites/all/modules/views/handlers/views_handler_filter.inc b/sites/all/modules/views/handlers/views_handler_filter.inc new file mode 100644 index 0000000..2718042 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_filter.inc @@ -0,0 +1,636 @@ +operator = $this->options['operator']; + $this->value = $this->options['value']; + + // Compatibility: Set use_operator to true if the old way of using + // the operator is set and use_operator is NULL (was never set). + if (!empty($options['exposed']) && !empty($options['expose']['operator']) && !isset($options['expose']['use_operator'])) { + $this->options['expose']['use_operator'] = TRUE; + } + + // If there are relationships in the view, allow empty should be true + // so that we can do IS NULL checks on items. Not all filters respect + // allow empty, but string and numeric do and that covers enough. + if ($this->view->display_handler->get_option('relationships')) { + $this->definition['allow empty'] = TRUE; + } + } + + function option_definition() { + $options = parent::option_definition(); + + $options['operator'] = array('default' => '='); + $options['value'] = array('default' => ''); + $options['group'] = array('default' => '0'); + $options['exposed'] = array('default' => FALSE); + $options['expose'] = array( + 'contains' => array( + 'operator' => array('default' => FALSE), + 'label' => array('default' => '', 'translatable' => TRUE), + ), + ); + + return $options; + } + + /** + * Display the filter on the administrative summary + */ + function admin_summary() { + return check_plain((string) $this->operator) . ' ' . check_plain((string) $this->value); + } + + /** + * Determine if a filter can be exposed. + */ + function can_expose() { return TRUE; } + + /** + * Provide the basic form which calls through to subforms. + * If overridden, it is best to call through to the parent, + * or to at least make sure all of the functions in this form + * are called. + */ + function options_form(&$form, &$form_state) { + if ($this->can_expose()) { + $this->show_expose_button($form, $form_state); + } + $form['op_val_start'] = array('#value' => '
'); + $this->show_operator_form($form, $form_state); + $this->show_value_form($form, $form_state); + $form['op_val_end'] = array('#value' => '
'); + if ($this->can_expose()) { + $this->show_expose_form($form, $form_state); + } + } + + /** + * Simple validate handler + */ + function options_validate($form, &$form_state) { + $this->operator_validate($form, $form_state); + $this->value_validate($form, $form_state); + if (!empty($this->options['exposed'])) { + $this->expose_validate($form, $form_state); + } + + } + + /** + * Simple submit handler + */ + function options_submit($form, &$form_state) { + unset($form_state['values']['expose_button']); // don't store this. + $this->operator_submit($form, $form_state); + $this->value_submit($form, $form_state); + if (!empty($this->options['exposed'])) { + $this->expose_submit($form, $form_state); + } + } + + /** + * Shortcut to display the operator form. + */ + function show_operator_form(&$form, &$form_state) { + $this->operator_form($form, $form_state); + $form['operator']['#prefix'] = '
'; + $form['operator']['#suffix'] = '
'; + } + + /** + * Provide a form for setting the operator. + * + * This may be overridden by child classes, and it must + * define $form['operator']; + */ + function operator_form(&$form, &$form_state) { + $options = $this->operator_options(); + if (!empty($options)) { + $form['operator'] = array( + '#type' => count($options) < 10 ? 'radios' : 'select', + '#title' => t('Operator'), + '#default_value' => $this->operator, + '#options' => $options, + ); + } + } + + /** + * Provide a list of options for the default operator form. + * Should be overridden by classes that don't override operator_form + */ + function operator_options() { return array(); } + + /** + * Validate the operator form. + */ + function operator_validate($form, &$form_state) { } + + /** + * Perform any necessary changes to the form values prior to storage. + * There is no need for this function to actually store the data. + */ + function operator_submit($form, &$form_state) { } + + /** + * Shortcut to display the value form. + */ + function show_value_form(&$form, &$form_state) { + $this->value_form($form, $form_state); + if (empty($this->no_operator)) { + $form['value']['#prefix'] = '
' . (isset($form['value']['#prefix']) ? $form['value']['#prefix'] : ''); + $form['value']['#suffix'] = (isset($form['value']['#suffix']) ? $form['value']['#suffix'] : '') . '
'; + } + } + + /** + * Provide a form for setting options. + * + * This should be overridden by all child classes and it must + * define $form['value'] + */ + function value_form(&$form, &$form_state) { $form['value'] = array(); } + + /** + * Validate the options form. + */ + function value_validate($form, &$form_state) { } + + /** + * Perform any necessary changes to the form values prior to storage. + * There is no need for this function to actually store the data. + */ + function value_submit($form, &$form_state) { } + + /** + * Shortcut to display the expose/hide button. + */ + function show_expose_button(&$form, &$form_state) { + $form['expose_button'] = array( + '#prefix' => '
', + '#suffix' => '
', + ); + if (empty($this->options['exposed'])) { + $form['expose_button']['button'] = array( + '#type' => 'submit', + '#value' => t('Expose'), + '#submit' => array('views_ui_config_item_form_expose'), + ); + $form['expose_button']['markup'] = array( + '#prefix' => '
', + '#value' => t('This item is currently not exposed. If you expose it, users will be able to change the filter as they view it.'), + '#suffix' => '
', + ); + } + else { + $form['expose_button']['button'] = array( + '#type' => 'submit', + '#value' => t('Hide'), + '#submit' => array('views_ui_config_item_form_expose'), + ); + $form['expose_button']['markup'] = array( + '#prefix' => '
', + '#value' => t('This item is currently exposed. If you hide it, users will not be able to change the filter as they view it.'), + '#suffix' => '
', + ); + } + } + + /** + * Shortcut to display the exposed options form. + */ + function show_expose_form(&$form, &$form_state) { + if (empty($this->options['exposed'])) { + return; + } + + $form['expose'] = array( + '#prefix' => '
', + '#suffix' => '
', + ); + $this->expose_form($form, $form_state); + + // When we click the expose button, we add new gadgets to the form but they + // have no data in $_POST so their defaults get wiped out. This prevents + // these defaults from getting wiped out. This setting will only be TRUE + // during a 2nd pass rerender. + if (!empty($form_state['force_expose_options'])) { + foreach (element_children($form['expose']) as $id) { + if (isset($form['expose'][$id]['#default_value']) && !isset($form['expose'][$id]['#value'])) { + $form['expose'][$id]['#value'] = $form['expose'][$id]['#default_value']; + } + } + } + } + + /** + * Overridable form for exposed filter options. + * + * If overridden, it is best to call the parent or re-implement + * the stuff here. + * + * Many filters will need to override this in order to provide options + * that are nicely tailored to the given filter. + */ + function expose_form(&$form, &$form_state) { + $form['expose']['start_left'] = array( + '#value' => '
', + ); + + $this->expose_form_left($form, $form_state); + + $form['expose']['end_left'] = array( + '#value' => '
', + ); + + $form['expose']['start_checkboxes'] = array( + '#value' => '
', + ); + + $this->expose_form_right($form, $form_state); + + $form['expose']['end_checkboxes'] = array( + '#value' => '
', + ); + } + + /** + * Handle the 'left' side fo the exposed options form. + */ + function expose_form_left(&$form, &$form_state) { + if (!empty($form['operator']['#type'])) { + $form['expose']['use_operator'] = array( + '#type' => 'checkbox', + '#title' => t('Unlock operator'), + '#description' => t('When checked, the operator will be exposed to the user'), + '#default_value' => !empty($this->options['expose']['use_operator']), + ); + $form['expose']['operator'] = array( + '#type' => 'textfield', + '#default_value' => $this->options['expose']['operator'], + '#title' => t('Operator identifier'), + '#size' => 40, + '#description' => t('This will appear in the URL after the ? to identify this operator.'), + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-expose-use-operator' => array(1) + ), + ); + } + else { + $form['expose']['operator'] = array( + '#type' => 'value', + '#value' => '', + ); + } + + $form['expose']['identifier'] = array( + '#type' => 'textfield', + '#default_value' => $this->options['expose']['identifier'], + '#title' => t('Filter identifier'), + '#size' => 40, + '#description' => t('This will appear in the URL after the ? to identify this filter. Cannot be blank.'), + ); + $form['expose']['label'] = array( + '#type' => 'textfield', + '#default_value' => $this->options['expose']['label'], + '#title' => t('Label'), + '#size' => 40, + ); + } + + /** + * Handle the 'right' side fo the exposed options form. + */ + function expose_form_right(&$form, &$form_state) { + if (empty($this->no_optional)) { + $form['expose']['optional'] = array( + '#type' => 'checkbox', + '#title' => t('Optional'), + '#description' => t('This exposed filter is optional and will have added options to allow it not to be set.'), + '#default_value' => $this->options['expose']['optional'], + ); + } + if (empty($this->no_single)) { + $form['expose']['single'] = array( + '#type' => 'checkbox', + '#title' => t('Force single'), + '#description' => t('Force this exposed filter to accept only one option.'), + '#default_value' => $this->options['expose']['single'], + ); + } + $form['expose']['remember'] = array( + '#type' => 'checkbox', + '#title' => t('Remember'), + '#description' => t('Remember the last setting the user gave this filter.'), + '#default_value' => $this->options['expose']['remember'], + ); + } + + /** + * Validate the options form. + */ + function expose_validate($form, &$form_state) { + if (empty($this->options['expose']['identifier'])) { + if (empty($form_state['values']['options']['expose']['identifier'])) { + form_error($form['expose']['identifier'], t('The identifier is required if the filter is exposed.')); + } + } + + if (!empty($form_state['values']['options']['expose']['identifier']) && $form_state['values']['options']['expose']['identifier'] == 'value') { + form_error($form['expose']['identifier'], t('This identifier is not allowed.')); + } + + if (!$this->view->display_handler->is_identifier_unique($form_state['id'], $form_state['values']['options']['expose']['identifier'])) { + form_error($form['expose']['identifier'], t('This identifier is used by another handler.')); + } + } + + /** + * Perform any necessary changes to the form exposes prior to storage. + * There is no need for this function to actually store the data. + */ + function expose_submit($form, &$form_state) { } + + /** + * Provide default options for exposed filters. + */ + function expose_options() { + $this->options['expose'] = array( + 'use_operator' => FALSE, + 'operator' => $this->options['id'] . '_op', + 'identifier' => $this->options['id'], + 'label' => $this->ui_name(), + 'remember' => FALSE, + 'single' => TRUE, + 'optional' => TRUE, + ); + } + + /** + * Render our chunk of the exposed filter form when selecting + * + * You can override this if it doesn't do what you expect. + */ + function exposed_form(&$form, &$form_state) { + if (empty($this->options['exposed'])) { + return; + } + + if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator'])) { + $operator = $this->options['expose']['operator']; + $this->operator_form($form, $form_state); + $form[$operator] = $form['operator']; + + if (isset($form[$operator]['#title'])) { + unset($form[$operator]['#title']); + } + + $this->exposed_translate($form[$operator], 'operator'); + + unset($form['operator']); + } + + if (!empty($this->options['expose']['identifier'])) { + $value = $this->options['expose']['identifier']; + $this->value_form($form, $form_state); + $form[$value] = $form['value']; + + if (isset($form[$value]['#title']) && !empty($form[$value]['#type']) && $form[$value]['#type'] != 'checkbox') { + unset($form[$value]['#title']); + } + + $this->exposed_translate($form[$value], 'value'); + + if (!empty($form['#type']) && ($form['#type'] == 'checkboxes' || ($form['#type'] == 'select' && !empty($form['#multiple'])))) { + unset($form[$value]['#default_value']); + } + + if (!empty($form['#type']) && $form['#type'] == 'select' && empty($form['#multiple'])) { + $form[$value]['#default_value'] = 'All'; + } + + if ($value != 'value') { + unset($form['value']); + } + } + } + + /** + * Make some translations to a form item to make it more suitable to + * exposing. + */ + function exposed_translate(&$form, $type) { + if (!isset($form['#type'])) { + return; + } + + if ($form['#type'] == 'radios') { + $form['#type'] = 'select'; + } + // Checkboxes don't work so well in exposed forms due to GET conversions. + if ($form['#type'] == 'checkboxes') { + if (empty($form['#no_convert']) || !empty($this->options['expose']['single'])) { + $form['#type'] = 'select'; + } + if (empty($this->options['expose']['single'])) { + $form['#multiple'] = TRUE; + } + } + if (!empty($this->options['expose']['single']) && isset($form['#multiple'])) { + unset($form['#multiple']); + $form['#size'] = NULL; + } + + if ($type == 'value' && empty($this->no_optional) && !empty($this->options['expose']['optional']) && $form['#type'] == 'select' && empty($form['#multiple'])) { + $any_label = variable_get('views_exposed_filter_any_label', 'old_any') == 'old_any' ? '' : t('- Any -'); + $form['#options'] = array('All' => $any_label) + $form['#options']; + $form['#default_value'] = 'All'; + } + } + + /** + * Tell the renderer about our exposed form. This only needs to be + * overridden for particularly complex forms. And maybe not even then. + */ + function exposed_info() { + if (empty($this->options['exposed'])) { + return; + } + + return array( + 'operator' => $this->options['expose']['operator'], + 'value' => $this->options['expose']['identifier'], + 'label' => $this->options['expose']['label'], + ); + } + + /** + * Check to see if input from the exposed filters should change + * the behavior of this filter. + */ + function accept_exposed_input($input) { + if (empty($this->options['exposed'])) { + return TRUE; + } + + + if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator']) && isset($input[$this->options['expose']['operator']])) { + $this->operator = $input[$this->options['expose']['operator']]; + } + + if (!empty($this->options['expose']['identifier'])) { + $value = $input[$this->options['expose']['identifier']]; + + // Various ways to check for the absence of optional input. + if (!empty($this->options['expose']['optional'])) { + + if (($this->operator == 'empty' || $this->operator == 'not empty') && $value === '') { + $value = ' '; + } + + if ($this->operator != 'empty' && $this->operator != 'not empty') { + if ($value == 'All' || $value === array()) { + return FALSE; + } + } + + if (!empty($this->no_single) && $value === '') { + return FALSE; + } + } + + + if (isset($value)) { + $this->value = $value; + if (empty($this->no_single) && !empty($this->options['expose']['single'])) { + $this->value = array($value); + } + } + else { + return FALSE; + } + } + + return TRUE; + } + + function store_exposed_input($input, $status) { + if (empty($this->options['exposed']) || empty($this->options['expose']['identifier'])) { + return TRUE; + } + + if (empty($this->options['expose']['remember'])) { + return; + } + + // Figure out which display id is responsible for the filters, so we + // know where to look for session stored values. + $display_id = ($this->view->display_handler->is_defaulted('filters')) ? 'default' : $this->view->current_display; + + // shortcut test. + $operator = !empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator']); + + // false means that we got a setting that means to recuse ourselves, + // so we should erase whatever happened to be there. + if (!$status && isset($_SESSION['views'][$this->view->name][$display_id])) { + $session = &$_SESSION['views'][$this->view->name][$display_id]; + if ($operator && isset($session[$this->options['expose']['operator']])) { + unset($session[$this->options['expose']['operator']]); + } + + if (isset($session[$this->options['expose']['identifier']])) { + unset($session[$this->options['expose']['identifier']]); + } + } + + if ($status) { + if (!isset($_SESSION['views'][$this->view->name][$display_id])) { + $_SESSION['views'][$this->view->name][$display_id] = array(); + } + + $session = &$_SESSION['views'][$this->view->name][$display_id]; + + if ($operator && isset($input[$this->options['expose']['operator']])) { + $session[$this->options['expose']['operator']] = $input[$this->options['expose']['operator']]; + } + + $session[$this->options['expose']['identifier']] = $input[$this->options['expose']['identifier']]; + } + } + + /** + * Add this filter to the query. + * + * Due to the nature of fapi, the value and the operator have an unintended + * level of indirection. You will find them in $this->operator + * and $this->value respectively. + */ + function query() { + $this->ensure_my_table(); + $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field " . $this->operator . " '%s'", $this->value); + } +} + + +/** + * A special handler to take the place of missing or broken handlers. + */ +class views_handler_filter_broken extends views_handler_filter { + function ui_name($short = FALSE) { + return t('Broken/missing handler'); + } + + function ensure_my_table() { /* No table to ensure! */ } + function query() { /* No query to run */ } + function options_form(&$form, &$form_state) { + $form['markup'] = array( + '#prefix' => '
', + '#value' => t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.'), + ); + } + + /** + * Determine if the handler is considered 'broken' + */ + function broken() { return TRUE; } +} + + +/** + * @} + */ diff --git a/sites/all/modules/views/handlers/views_handler_filter_boolean_operator.inc b/sites/all/modules/views/handlers/views_handler_filter_boolean_operator.inc new file mode 100644 index 0000000..ec9e415 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_filter_boolean_operator.inc @@ -0,0 +1,159 @@ +value_value = t('True'); + if (isset($this->definition['label'])) { + $this->value_value = $this->definition['label']; + } + if (isset($this->definition['accept null'])) { + $this->accept_null = (bool) $this->definition['accept null']; + } + else if (isset($this->definition['accept_null'])) { + $this->accept_null = (bool) $this->definition['accept_null']; + } + $this->value_options = NULL; + parent::construct(); + } + + /** + * Return the possible options for this filter. + * + * Child classes should override this function to set the possible values + * for the filter. Since this is a boolean filter, the array should have + * two possible keys: 1 for "True" and 0 for "False", although the labels + * can be whatever makes sense for the filter. These values are used for + * configuring the filter, when the filter is exposed, and in the admin + * summary of the filter. Normally, this should be static data, but if it's + * dynamic for some reason, child classes should use a guard to reduce + * database hits as much as possible. + */ + function get_value_options() { + if (isset($this->definition['type'])) { + if ($this->definition['type'] == 'yes-no') { + $this->value_options = array(1 => t('Yes'), 0 => t('No')); + } + if ($this->definition['type'] == 'on-off') { + $this->value_options = array(1 => t('On'), 0 => t('Off')); + } + } + + // Provide a fallback if the above didn't set anything. + if (!isset($this->value_options)) { + $this->value_options = array(1 => t('True'), 0 => t('False')); + } + } + + function option_definition() { + $options = parent::option_definition(); + + $options['value']['default'] = FALSE; + + return $options; + } + + function operator_form(&$form, &$form_state) { + $form['operator'] = array(); + } + + function value_form(&$form, &$form_state) { + if (empty($this->value_options)) { + // Initialize the array of possible values for this filter. + $this->get_value_options(); + } + if (!empty($form_state['exposed'])) { + // Exposed filter: use a select box to save space. + $filter_form_type = 'select'; + } + else { + // Configuring a filter: use radios for clarity. + $filter_form_type = 'radios'; + } + $form['value'] = array( + '#type' => $filter_form_type, + '#title' => $this->value_value, + '#options' => $this->value_options, + '#default_value' => $this->value, + ); + if (!empty($this->options['exposed'])) { + $identifier = $this->options['expose']['identifier']; + if (!isset($form_state['input'][$identifier])) { + $form_state['input'][$identifier] = $this->value; + } + // If we're configuring an exposed filter, add an option. + if (empty($form_state['exposed']) || !empty($this->options['optional'])) { + $any_label = variable_get('views_exposed_filter_any_label', 'old_any') == 'old_any' ? '' : t('- Any -'); + if ($form['value']['#type'] != 'select') { + $any_label = check_plain($any_label); + } + $form['value']['#options'] = array('All' => $any_label) + $form['value']['#options']; + } + } + } + + function value_validate($form, &$form_state) { + if ($form_state['values']['options']['value'] == 'All' && empty($form_state['values']['options']['expose']['optional'])) { + form_set_error('value', t('You must select a value unless this is an optional exposed filter.')); + } + } + + function admin_summary() { + if (!empty($this->options['exposed'])) { + return t('exposed'); + } + if (empty($this->value_options)) { + $this->get_value_options(); + } + // Now that we have the valid options for this filter, just return the + // human-readable label based on the current value. The value_options + // array is keyed with either 0 or 1, so if the current value is not + // empty, use the label for 1, and if it's empty, use the label for 0. + return $this->value_options[!empty($this->value)]; + } + + function expose_options() { + parent::expose_options(); + $this->options['expose']['operator'] = ''; + $this->options['expose']['label'] = $this->value_value; + $this->options['expose']['optional'] = FALSE; + } + + function query() { + $this->ensure_my_table(); + + $where = "$this->table_alias.$this->real_field "; + + if (empty($this->value)) { + $where .= '= 0'; + if ($this->accept_null) { + $where = '(' . $where . " OR $this->table_alias.$this->real_field IS NULL)"; + } + } + else { + if (!empty($this->definition['use equal'])) { + $where .= '= 1'; + } + else { + $where .= '<> 0'; + } + } + $this->query->add_where($this->options['group'], $where); + } +} diff --git a/sites/all/modules/views/handlers/views_handler_filter_boolean_operator_string.inc b/sites/all/modules/views/handlers/views_handler_filter_boolean_operator_string.inc new file mode 100644 index 0000000..bd7bd87 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_filter_boolean_operator_string.inc @@ -0,0 +1,27 @@ +ensure_my_table(); + $where = "$this->table_alias.$this->real_field "; + + if (empty($this->value)) { + $where .= "= ''"; + if ($this->accept_null) { + $where = '(' . $where . " OR $this->table_alias.$this->real_field IS NULL)"; + } + } + else { + $where .= "<> ''"; + } + $this->query->add_where($this->options['group'], $where); + } +} diff --git a/sites/all/modules/views/handlers/views_handler_filter_date.inc b/sites/all/modules/views/handlers/views_handler_filter_date.inc new file mode 100644 index 0000000..ab25862 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_filter_date.inc @@ -0,0 +1,157 @@ + 'radios', + '#title' => t('Value type'), + '#options' => array( + 'date' => t('A date in any machine readable format. CCYY-MM-DD HH:MM:SS is preferred.'), + 'offset' => t('An offset from the current time such as "!example1" or "!example2"', array('!example1' => '+1 day', '!example2' => '-2 hours -30 minutes')), + ), + '#default_value' => !empty($this->value['type']) ? $this->value['type'] : 'date', + ); + } + parent::value_form($form, $form_state); + } + + function options_validate($form, &$form_state) { + parent::options_validate($form, $form_state); + + if (!empty($form_state['values']['options']['expose']['optional'])) { + // Who cares what the value is if it's exposed and optional. + return; + } + + $this->validate_valid_time($form['value'], $form_state['values']['options']['operator'], $form_state['values']['options']['value']); + } + + function exposed_validate($form, &$form_state) { + if (empty($this->options['exposed'])) { + return; + } + + if (!empty($this->options['expose']['optional'])) { + // Who cares what the value is if it's exposed and optional. + return; + } + + $value = &$form_state['values'][$this->options['expose']['identifier']]; + if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator'])) { + $operator = $form_state['values'][$this->options['expose']['operator']]; + } + else { + $operator = $this->operator; + } + + $this->validate_valid_time($this->options['expose']['identifier'], $operator, $value); + + } + + /** + * Validate that the time values convert to something usable. + */ + function validate_valid_time(&$form, $operator, $value) { + $operators = $this->operators(); + + if ($operators[$operator]['values'] == 1) { + $convert = strtotime($value['value']); + if (!empty($form['value']) && ($convert == -1 || $convert === FALSE)) { + form_error($form['value'], t('Invalid date format.')); + } + } + elseif ($operators[$operator]['values'] == 2) { + $min = strtotime($value['min']); + if ($min == -1 || $min === FALSE) { + form_error($form['min'], t('Invalid date format.')); + } + $max = strtotime($value['max']); + if ($max == -1 || $max === FALSE) { + form_error($form['max'], t('Invalid date format.')); + } + } + } + + function accept_exposed_input($input) { + if (empty($this->options['exposed'])) { + return TRUE; + } + + // Store this because it will get overwritten. + $type = $this->value['type']; + $rc = parent::accept_exposed_input($input); + + // Don't filter if value(s) are empty. + $operators = $this->operators(); + if (!empty($this->options['expose']['use_operator']) && !empty($this->options['expose']['operator'])) { + $operator = $input[$this->options['expose']['operator']]; + } + else { + $operator = $this->operator; + } + + if ($operators[$operator]['values'] == 1) { + if ($this->value['value'] == '') { + return FALSE; + } + } + else { + if ($this->value['min'] == '' || $this->value['max'] == '') { + return FALSE; + } + } + + // restore what got overwritten by the parent. + $this->value['type'] = $type; + return $rc; + } + + function op_between($field) { + if ($this->operator == 'between') { + $a = intval(strtotime($this->value['min'], 0)); + $b = intval(strtotime($this->value['max'], 0)); + } + else { + $a = intval(strtotime($this->value['max'], 0)); + $b = intval(strtotime($this->value['min'], 0)); + } + + if ($this->value['type'] == 'offset') { + $a = '***CURRENT_TIME***' . sprintf('%+d', $a); // keep sign + $b = '***CURRENT_TIME***' . sprintf('%+d', $b); // keep sign + } + // %s is safe here because strtotime scrubbed the input and we might + // have a string if using offset. + if ($this->operator == 'between') { + $this->query->add_where($this->options['group'], "$field >= %s", $a); + $this->query->add_where($this->options['group'], "$field <= %s", $b); + } + else { + $this->query->add_where($this->options['group'], "$field >= %s OR $field <= %s", array($a, $b)); + } + } + + function op_simple($field) { + $value = intval(strtotime($this->value['value'], 0)); + if (!empty($this->value['type']) && $this->value['type'] == 'offset') { + $value = '***CURRENT_TIME***' . sprintf('%+d', $value); // keep sign + } + $this->query->add_where($this->options['group'], "$field $this->operator %s", $value); + } +} diff --git a/sites/all/modules/views/handlers/views_handler_filter_equality.inc b/sites/all/modules/views/handlers/views_handler_filter_equality.inc new file mode 100644 index 0000000..95ccaba --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_filter_equality.inc @@ -0,0 +1,38 @@ + t('Is equal to'), + '!=' => t('Is not equal to'), + ); + } + + /** + * Provide a simple textfield for equality + */ + function value_form(&$form, &$form_state) { + $form['value'] = array( + '#type' => 'textfield', + '#title' => t('Value'), + '#size' => 30, + '#default_value' => $this->value, + ); + + if (!empty($form_state['exposed'])) { + $identifier = $this->options['expose']['identifier']; + if (!isset($form_state['input'][$identifier])) { + $form_state['input'][$identifier] = $this->value; + } + } + } +} + diff --git a/sites/all/modules/views/handlers/views_handler_filter_float.inc b/sites/all/modules/views/handlers/views_handler_filter_float.inc new file mode 100644 index 0000000..d96f121 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_filter_float.inc @@ -0,0 +1,22 @@ +operator == 'between') { + $this->query->add_where($this->options['group'], "$field >= %f", $this->value['min']); + $this->query->add_where($this->options['group'], "$field <= %f", $this->value['max']); + } + else { + $this->query->add_where($this->options['group'], "$field <= %f OR $field >= %f", $this->value['min'], $this->value['max']); + } + } + + function op_simple($field) { + $this->query->add_where($this->options['group'], "$field $this->operator %f", $this->value['value']); + } +} diff --git a/sites/all/modules/views/handlers/views_handler_filter_in_operator.inc b/sites/all/modules/views/handlers/views_handler_filter_in_operator.inc new file mode 100644 index 0000000..c692dea --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_filter_in_operator.inc @@ -0,0 +1,364 @@ +value_title = t('Options'); + $this->value_options = NULL; + } + + /** + * Child classes should be used to override this function and set the + * 'value options', unless 'options callback' is defined as a valid function + * or static public method to generate these values. + * + * This can use a guard to be used to reduce database hits as much as + * possible. + */ + function get_value_options() { + if (isset($this->value_options)) { + return; + } + + if (isset($this->definition['options callback']) && is_callable($this->definition['options callback'])) { + $this->value_options = call_user_func($this->definition['options callback']); + } + else { + $this->value_options = array(t('Yes'), t('No')); + } + } + + function expose_options() { + parent::expose_options(); + $this->options['expose']['reduce'] = FALSE; + } + + function expose_form_right(&$form, &$form_state) { + parent::expose_form_right($form, $form_state); + $form['expose']['reduce'] = array( + '#type' => 'checkbox', + '#title' => t('Limit list to selected items'), + '#description' => t('If checked, the only items presented to the user will be the ones selected here.'), + '#default_value' => !empty($this->options['expose']['reduce']), // safety + ); + } + + function option_definition() { + $options = parent::option_definition(); + + $options['operator']['default'] = 'in'; + $options['value']['default'] = array(); + + return $options; + } + + /** + * This kind of construct makes it relatively easy for a child class + * to add or remove functionality by overriding this function and + * adding/removing items from this array. + */ + function operators() { + $operators = array( + 'in' => array( + 'title' => t('Is one of'), + 'short' => t('in'), + 'short_single' => t('='), + 'method' => 'op_simple', + 'values' => 1, + ), + 'not in' => array( + 'title' => t('Is not one of'), + 'short' => t('not in'), + 'short_single' => t('<>'), + 'method' => 'op_simple', + 'values' => 1, + ), + ); + // if the definition allows for the empty operator, add it. + if (!empty($this->definition['allow empty'])) { + $operators += array( + 'empty' => array( + 'title' => t('Is empty (NULL)'), + 'method' => 'op_empty', + 'short' => t('empty'), + 'values' => 0, + ), + 'not empty' => array( + 'title' => t('Is not empty (NOT NULL)'), + 'method' => 'op_empty', + 'short' => t('not empty'), + 'values' => 0, + ), + ); + } + + return $operators; + } + + /** + * Build strings from the operators() for 'select' options + */ + function operator_options($which = 'title') { + $options = array(); + foreach ($this->operators() as $id => $info) { + $options[$id] = $info[$which]; + } + + return $options; + } + + function operator_values($values = 1) { + $options = array(); + foreach ($this->operators() as $id => $info) { + if (isset($info['values']) && $info['values'] == $values) { + $options[] = $id; + } + } + + return $options; + } + + function value_form(&$form, &$form_state) { + $form['value'] = array(); + + $this->get_value_options(); + $options = $this->value_options; + $default_value = (array) $this->value; + + $which = 'all'; + if (!empty($form['operator'])) { + $source = ($form['operator']['#type'] == 'radios') ? 'radio:options[operator]' : 'edit-options-operator'; + } + if (!empty($form_state['exposed'])) { + $identifier = $this->options['expose']['identifier']; + + if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator'])) { + // exposed and locked. + $which = in_array($this->operator, $this->operator_values(1)) ? 'value' : 'none'; + } + else { + $source = 'edit-' . form_clean_id($this->options['expose']['operator']); + } + + if (!empty($this->options['expose']['reduce'])) { + $options = $this->reduce_value_options(); + + if (empty($this->options['expose']['single']) && !empty($this->options['expose']['optional'])) { + $default_value = array(); + } + } + + if (!empty($this->options['expose']['single'])) { + if (!empty($this->options['expose']['optional']) && (empty($default_value) || !empty($this->options['expose']['reduce']))) { + $default_value = 'All'; + } + else if (empty($default_value)) { + $keys = array_keys($options); + $default_value = array_shift($keys); + } + else { + $copy = $default_value; + $default_value = array_shift($copy); + } + } + } + + if ($which == 'all' || $which == 'value') { + $form['value'] = array( + '#type' => $this->value_form_type, + '#title' => $this->value_title, + '#options' => $options, + '#default_value' => $default_value, + // These are only valid for 'select' type, but do no harm to checkboxes. + '#multiple' => TRUE, + '#size' => count($options) > 8 ? 8 : count($options), + ); + if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) { + $form_state['input'][$identifier] = $default_value; + } + + $process = array(); + if ($this->value_form_type == 'checkboxes') { + // If this form element will use checkboxes in the UI, we need to + // check_plain() all the options ourselves since FAPI is inconsistent + // about this. However, instead of directly doing that to the #options + // right now, we define a #process callback since we might change our + // mind later and convert this into a 'select' form element, which + // would lead to double-escaping the options. + $process[] = 'views_process_check_options'; + } + if ($which == 'all') { + if (empty($form_state['exposed']) && ($this->value_form_type == 'checkboxes' || $this->value_form_type == 'radios')) { + $process[] = "expand_$this->value_form_type"; + $form['value']['#prefix'] = '
'; + $form['value']['#suffix'] = '
'; + } + $process[] = 'views_process_dependency'; + $form['value']['#dependency'] = array($source => $this->operator_values(1)); + } + if (!empty($process)) { + $form['value']['#process'] = $process; + } + } + } + + /** + * When using exposed filters, we may be required to reduce the set. + */ + function reduce_value_options($input = NULL) { + if (!isset($input)) { + $input = $this->value_options; + } + + // Because options may be an array of strings, or an array of mixed arrays + // and strings (optgroups) or an array of objects, we have to + // step through and handle each one individually. + $options = array(); + foreach ($input as $id => $option) { + if (is_array($option)) { + $options[$id] = $this->reduce_value_options($option); + continue; + } + else if (is_object($option)) { + $keys = array_keys($option->option); + $key = array_shift($keys); + if (isset($this->options['value'][$key])) { + $options[$id] = $option; + } + } + else if (isset($this->options['value'][$id])) { + $options[$id] = $option; + } + } + return $options; + } + + function accept_exposed_input($input) { + // A very special override because the All state for this type of + // filter could have a default: + if (empty($this->options['exposed'])) { + return TRUE; + } + + // If this is single and optional, this says that yes this filter will + // participate, but using the default settings, *if* 'limit is true. + if (!empty($this->options['expose']['single']) && !empty($this->options['expose']['optional']) && !empty($this->options['expose']['limit'])) { + $identifier = $this->options['expose']['identifier']; + if ($input[$identifier] == 'All') { + return TRUE; + } + } + + return parent::accept_exposed_input($input); + } + + function value_submit($form, &$form_state) { + // Drupal's FAPI system automatically puts '0' in for any checkbox that + // was not set, and the key to the checkbox if it is set. + // Unfortunately, this means that if the key to that checkbox is 0, + // we are unable to tell if that checkbox was set or not. + + // Luckily, the '#value' on the checkboxes form actually contains + // *only* a list of checkboxes that were set, and we can use that + // instead. + + $form_state['values']['options']['value'] = $form['value']['#value']; +// $form_state['values']['options']['value'] = array_filter($form_state['values']['options']['value']); + } + + function admin_summary() { + if (!empty($this->options['exposed'])) { + return t('exposed'); + } + $info = $this->operators(); + + $this->get_value_options(); + + if (!is_array($this->value)) { + return; + } + + $operator = check_plain($info[$this->operator]['short']); + $values = ''; + if (in_array($this->operator, $this->operator_values(1))) { + // Remove every element which is not known. + foreach ($this->value as $value) { + if (!isset($this->value_options[$value])) { + unset($this->value[$value]); + } + } + // Choose different kind of ouput for 0, a single and multiple values. + if (count($this->value) == 0) { + $values = t('Unknown'); + } + else if (count($this->value) == 1) { + // If any, use the 'single' short name of the operator instead. + if (isset($info[$this->operator]['short_single'])) { + $operator = check_plain($info[$this->operator]['short_single']); + } + + $keys = $this->value; + $value = array_shift($keys); + $values = check_plain($this->value_options[$value]); + } + else { + foreach ($this->value as $value) { + if ($values !== '') { + $values .= ', '; + } + if (strlen($values) > 8) { + $values .= '...'; + break; + } + $values .= check_plain($this->value_options[$value]); + } + } + } + + return $operator . (($values !== '') ? ' ' . $values : ''); + } + + function query() { + $info = $this->operators(); + if (!empty($info[$this->operator]['method'])) { + $this->{$info[$this->operator]['method']}(); + } + } + + function op_simple() { + if (empty($this->value)) { + return; + } + $this->ensure_my_table(); + $placeholder = !empty($this->definition['numeric']) ? '%d' : "'%s'"; + + $replace = array_fill(0, sizeof($this->value), $placeholder); + $in = ' (' . implode(", ", $replace) . ')'; + + // We use array_values() because the checkboxes keep keys and that can cause + // array addition problems. + $this->query->add_where($this->options['group'], "$this->table_alias.$this->real_field " . $this->operator . $in, array_values($this->value)); + } + + function op_empty() { + $this->ensure_my_table(); + $field = "$this->table_alias.$this->real_field"; + + if ($this->operator == 'empty') { + $operator = "IS NULL"; + } + else { + $operator = "IS NOT NULL"; + } + + $this->query->add_where($this->options['group'], "$field $operator"); + } +} diff --git a/sites/all/modules/views/handlers/views_handler_filter_many_to_one.inc b/sites/all/modules/views/handlers/views_handler_filter_many_to_one.inc new file mode 100644 index 0000000..b19ea3e --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_filter_many_to_one.inc @@ -0,0 +1,103 @@ +helper = new views_many_to_one_helper($this); + } + + function option_definition() { + $options = parent::option_definition(); + + $options['operator']['default'] = 'or'; + $options['value']['default'] = array(); + + return $options; + } + + function operators() { + $operators = array( + 'or' => array( + 'title' => t('Is one of'), + 'short' => t('or'), + 'short_single' => t('='), + 'method' => 'op_helper', + 'values' => 1, + 'ensure_my_table' => 'helper', + ), + 'and' => array( + 'title' => t('Is all of'), + 'short' => t('and'), + 'short_single' => t('='), + 'method' => 'op_helper', + 'values' => 1, + 'ensure_my_table' => 'helper', + ), + 'not' => array( + 'title' => t('Is none of'), + 'short' => t('not'), + 'short_single' => t('<>'), + 'method' => 'op_helper', + 'values' => 1, + 'ensure_my_table' => 'helper', + ), + ); + // if the definition allows for the empty operator, add it. + if (!empty($this->definition['allow empty'])) { + $operators += array( + 'empty' => array( + 'title' => t('Is empty (NULL)'), + 'method' => 'op_empty', + 'short' => t('empty'), + 'values' => 0, + ), + 'not empty' => array( + 'title' => t('Is not empty (NOT NULL)'), + 'method' => 'op_empty', + 'short' => t('not empty'), + 'values' => 0, + ), + ); + } + + return $operators; + } + + var $value_form_type = 'select'; + function value_form(&$form, &$form_state) { + parent::value_form($form, $form_state); + + if (empty($form_state['exposed'])) { + $this->helper->options_form($form, $form_state); + } + } + + /** + * Override ensure_my_table so we can control how this joins in. + * The operator actually has influence over joining. + */ + function ensure_my_table() { + // Defer to helper if the operator specifies it. + $info = $this->operators(); + if (isset($info[$this->operator]['ensure_my_table']) && $info[$this->operator]['ensure_my_table'] == 'helper') { + return $this->helper->ensure_my_table(); + } + + return parent::ensure_my_table(); + } + + function op_helper() { + if (empty($this->value)) { + return; + } + $this->helper->add_filter(); + } +} diff --git a/sites/all/modules/views/handlers/views_handler_filter_numeric.inc b/sites/all/modules/views/handlers/views_handler_filter_numeric.inc new file mode 100644 index 0000000..4ea8644 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_filter_numeric.inc @@ -0,0 +1,302 @@ + array( + 'min' => array('default' => ''), + 'max' => array('default' => ''), + 'value' => array('default' => ''), + ), + ); + + return $options; + } + + function operators() { + $operators = array( + '<' => array( + 'title' => t('Is less than'), + 'method' => 'op_simple', + 'short' => t('<'), + 'values' => 1, + ), + '<=' => array( + 'title' => t('Is less than or equal to'), + 'method' => 'op_simple', + 'short' => t('<='), + 'values' => 1, + ), + '=' => array( + 'title' => t('Is equal to'), + 'method' => 'op_simple', + 'short' => t('='), + 'values' => 1, + ), + '!=' => array( + 'title' => t('Is not equal to'), + 'method' => 'op_simple', + 'short' => t('!='), + 'values' => 1, + ), + '>=' => array( + 'title' => t('Is greater than or equal to'), + 'method' => 'op_simple', + 'short' => t('>='), + 'values' => 1, + ), + '>' => array( + 'title' => t('Is greater than'), + 'method' => 'op_simple', + 'short' => t('>'), + 'values' => 1, + ), + 'between' => array( + 'title' => t('Is between'), + 'method' => 'op_between', + 'short' => t('between'), + 'values' => 2, + ), + 'not between' => array( + 'title' => t('Is not between'), + 'method' => 'op_between', + 'short' => t('not between'), + 'values' => 2, + ), + ); + + // if the definition allows for the empty operator, add it. + if (!empty($this->definition['allow empty'])) { + $operators += array( + 'empty' => array( + 'title' => t('Is empty (NULL)'), + 'method' => 'op_empty', + 'short' => t('empty'), + 'values' => 0, + ), + 'not empty' => array( + 'title' => t('Is not empty (NOT NULL)'), + 'method' => 'op_empty', + 'short' => t('not empty'), + 'values' => 0, + ), + ); + } + + return $operators; + } + + /** + * Provide a list of all the numeric operators + */ + function operator_options($which = 'title') { + $options = array(); + foreach ($this->operators() as $id => $info) { + $options[$id] = $info[$which]; + } + + return $options; + } + + function operator_values($values = 1) { + $options = array(); + foreach ($this->operators() as $id => $info) { + if ($info['values'] == $values) { + $options[] = $id; + } + } + + return $options; + } + /** + * Provide a simple textfield for equality + */ + function value_form(&$form, &$form_state) { + $form['value']['#tree'] = TRUE; + + // We have to make some choices when creating this as an exposed + // filter form. For example, if the operator is locked and thus + // not rendered, we can't render dependencies; instead we only + // render the form items we need. + $which = 'all'; + if (!empty($form['operator'])) { + $source = ($form['operator']['#type'] == 'radios') ? 'radio:options[operator]' : 'edit-options-operator'; + } + + if (!empty($form_state['exposed'])) { + $identifier = $this->options['expose']['identifier']; + + if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator'])) { + // exposed and locked. + $which = in_array($this->operator, $this->operator_values(2)) ? 'minmax' : 'value'; + } + else { + $source = 'edit-' . form_clean_id($this->options['expose']['operator']); + } + } + + if ($which == 'all') { + $form['value']['value'] = array( + '#type' => 'textfield', + '#title' => empty($form_state['exposed']) ? t('Value') : '', + '#size' => 30, + '#default_value' => $this->value['value'], + '#process' => array('views_process_dependency'), + '#dependency' => array($source => $this->operator_values(1)), + ); + if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['value'])) { + $form_state['input'][$identifier]['value'] = $this->value['value']; + } + } + else if ($which == 'value') { + // When exposed we drop the value-value and just do value if + // the operator is locked. + $form['value'] = array( + '#type' => 'textfield', + '#title' => empty($form_state['exposed']) ? t('Value') : '', + '#size' => 30, + '#default_value' => $this->value['value'], + ); + if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) { + $form_state['input'][$identifier] = $this->value['value']; + } + } + + if ($which == 'all' || $which == 'minmax') { + $form['value']['min'] = array( + '#type' => 'textfield', + '#title' => empty($form_state['exposed']) ? t('Min') : '', + '#size' => 30, + '#default_value' => $this->value['min'], + ); + $form['value']['max'] = array( + '#type' => 'textfield', + '#title' => empty($form_state['exposed']) ? t('And max') : t('And'), + '#size' => 30, + '#default_value' => $this->value['max'], + ); + if ($which == 'all') { + $dependency = array( + '#process' => array('views_process_dependency'), + '#dependency' => array($source => $this->operator_values(2)), + ); + $form['value']['min'] += $dependency; + $form['value']['max'] += $dependency; + } + if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['min'])) { + $form_state['input'][$identifier]['min'] = $this->value['min']; + } + if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier]['max'])) { + $form_state['input'][$identifier]['max'] = $this->value['max']; + } + + if (!isset($form['value'])) { + // Ensure there is something in the 'value'. + $form['value'] = array( + '#type' => 'value', + '#value' => NULL + ); + } + } + } + + function query() { + $this->ensure_my_table(); + $field = "$this->table_alias.$this->real_field"; + + $info = $this->operators(); + if (!empty($info[$this->operator]['method'])) { + $this->{$info[$this->operator]['method']}($field); + } + } + + function op_between($field) { + if ($this->operator == 'between') { + $this->query->add_where($this->options['group'], "$field >= %d", $this->value['min']); + $this->query->add_where($this->options['group'], "$field <= %d", $this->value['max']); + } + else { + $this->query->add_where($this->options['group'], "$field <= %d OR $field >= %d", $this->value['min'], $this->value['max']); + } + } + + function op_simple($field) { + $this->query->add_where($this->options['group'], "$field $this->operator %d", $this->value['value']); + } + + function op_empty($field) { + if ($this->operator == 'empty') { + $operator = "IS NULL"; + } + else { + $operator = "IS NOT NULL"; + } + + $this->query->add_where($this->options['group'], "$field $operator"); + } + + function admin_summary() { + if (!empty($this->options['exposed'])) { + return t('exposed'); + } + + $options = $this->operator_options('short'); + $output = check_plain($options[$this->operator]); + if (in_array($this->operator, $this->operator_values(2))) { + $output .= ' ' . t('@min and @max', array('@min' => $this->value['min'], '@max' => $this->value['max'])); + } + elseif (in_array($this->operator, $this->operator_values(1))) { + $output .= ' ' . check_plain($this->value['value']); + } + return $output; + } + + /** + * Do some minor translation of the exposed input + */ + function accept_exposed_input($input) { + if (empty($this->options['exposed'])) { + return TRUE; + } + + // rewrite the input value so that it's in the correct format so that + // the parent gets the right data. + if (!empty($this->options['expose']['identifier'])) { + $value = &$input[$this->options['expose']['identifier']]; + if (!is_array($value)) { + $value = array( + 'value' => $value, + ); + } + } + + $rc = parent::accept_exposed_input($input); + + if (!empty($this->options['expose']['optional'])) { + // We have to do some of our own optional checking. + $info = $this->operators(); + if (!empty($info[$this->operator]['values'])) { + switch ($info[$this->operator]['values']) { + case 1: + if ($value['value'] === '') { + return FALSE; + } + break; + case 2: + if ($value['min'] === '' && $value['max'] === '') { + return FALSE; + } + break; + } + } + } + + return $rc; + } +} diff --git a/sites/all/modules/views/handlers/views_handler_filter_string.inc b/sites/all/modules/views/handlers/views_handler_filter_string.inc new file mode 100644 index 0000000..7cc7a51 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_filter_string.inc @@ -0,0 +1,303 @@ + FALSE); + $options['case'] = array('default' => TRUE); + + return $options; + } + + /** + * This kind of construct makes it relatively easy for a child class + * to add or remove functionality by overriding this function and + * adding/removing items from this array. + */ + function operators() { + $operators = array( + '=' => array( + 'title' => t('Is equal to'), + 'short' => t('='), + 'method' => 'op_equal', + 'values' => 1, + ), + '!=' => array( + 'title' => t('Is not equal to'), + 'short' => t('!='), + 'method' => 'op_equal', + 'values' => 1, + ), + 'contains' => array( + 'title' => t('Contains'), + 'short' => t('contains'), + 'method' => 'op_contains', + 'values' => 1, + ), + 'word' => array( + 'title' => t('Contains any word'), + 'short' => t('has word'), + 'method' => 'op_word', + 'values' => 1, + ), + 'allwords' => array( + 'title' => t('Contains all words'), + 'short' => t('has all'), + 'method' => 'op_word', + 'values' => 1, + ), + 'starts' => array( + 'title' => t('Starts with'), + 'short' => t('begins'), + 'method' => 'op_starts', + 'values' => 1, + ), + 'not_starts' => array( + 'title' => t('Does not start with'), + 'short' => t('not_begins'), + 'method' => 'op_not_starts', + 'values' => 1, + ), + 'ends' => array( + 'title' => t('Ends with'), + 'short' => t('ends'), + 'method' => 'op_ends', + 'values' => 1, + ), + 'not_ends' => array( + 'title' => t('Does not end with'), + 'short' => t('not_ends'), + 'method' => 'op_not_ends', + 'values' => 1, + ), + 'not' => array( + 'title' => t('Does not contain'), + 'short' => t('!has'), + 'method' => 'op_not', + 'values' => 1, + ), + ); + // if the definition allows for the empty operator, add it. + if (!empty($this->definition['allow empty'])) { + $operators += array( + 'empty' => array( + 'title' => t('Is empty (NULL)'), + 'method' => 'op_empty', + 'short' => t('empty'), + 'values' => 0, + ), + 'not empty' => array( + 'title' => t('Is not empty (NOT NULL)'), + 'method' => 'op_empty', + 'short' => t('not empty'), + 'values' => 0, + ), + ); + } + + return $operators; + } + + /** + * Build strings from the operators() for 'select' options + */ + function operator_options($which = 'title') { + $options = array(); + foreach ($this->operators() as $id => $info) { + $options[$id] = $info[$which]; + } + + return $options; + } + + function admin_summary() { + if (!empty($this->options['exposed'])) { + return t('exposed'); + } + + $options = $this->operator_options('short'); + $output = check_plain($options[$this->operator]); + if (in_array($this->operator, $this->operator_values(1))) { + $output .= ' ' . check_plain($this->value); + } + return $output; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['case'] = array( + '#type' => 'checkbox', + '#title' => t('Case sensitive'), + '#default_value' => $this->options['case'], + '#description' => t('Case sensitive filters may be faster. MySQL might ignore case sensitivity.'), + ); + } + + function operator_values($values = 1) { + $options = array(); + foreach ($this->operators() as $id => $info) { + if (isset($info['values']) && $info['values'] == $values) { + $options[] = $id; + } + } + + return $options; + } + + /** + * Provide a simple textfield for equality + */ + function value_form(&$form, &$form_state) { + // We have to make some choices when creating this as an exposed + // filter form. For example, if the operator is locked and thus + // not rendered, we can't render dependencies; instead we only + // render the form items we need. + $which = 'all'; + if (!empty($form['operator'])) { + $source = ($form['operator']['#type'] == 'radios') ? 'radio:options[operator]' : 'edit-options-operator'; + } + if (!empty($form_state['exposed'])) { + $identifier = $this->options['expose']['identifier']; + + if (empty($this->options['expose']['use_operator']) || empty($this->options['expose']['operator'])) { + // exposed and locked. + $which = in_array($this->operator, $this->operator_values(1)) ? 'value' : 'none'; + } + else { + $source = 'edit-' . form_clean_id($this->options['expose']['operator']); + } + } + + if ($which == 'all' || $which == 'value') { + $form['value'] = array( + '#type' => 'textfield', + '#title' => t('Value'), + '#size' => 30, + '#default_value' => $this->value, + ); + if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) { + $form_state['input'][$identifier] = $this->value; + } + + if ($which == 'all') { + $form['value'] += array( + '#process' => array('views_process_dependency'), + '#dependency' => array($source => $this->operator_values(1)), + ); + } + } + + if (!isset($form['value'])) { + // Ensure there is something in the 'value'. + $form['value'] = array( + '#type' => 'value', + '#value' => NULL + ); + } + } + + function case_transform() { + return !empty($this->options['case']) ? '' : 'UPPER'; + } + + /** + * Add this filter to the query. + * + * Due to the nature of fapi, the value and the operator have an unintended + * level of indirection. You will find them in $this->operator + * and $this->value respectively. + */ + function query() { + $this->ensure_my_table(); + $field = "$this->table_alias.$this->real_field"; + $upper = $this->case_transform(); + + $info = $this->operators(); + if (!empty($info[$this->operator]['method'])) { + $this->{$info[$this->operator]['method']}($field, $upper); + } + } + + function op_equal($field, $upper) { + // operator is either = or != + $this->query->add_where($this->options['group'], "$upper($field) $this->operator $upper('%s')", $this->value); + } + + function op_contains($field, $upper) { + $this->query->add_where($this->options['group'], "$upper($field) LIKE $upper('%%%s%%')", $this->value); + } + + function op_word($field, $upper) { + $where = array(); + preg_match_all('/ (-?)("[^"]+"|[^" ]+)/i', ' ' . $this->value, $matches, PREG_SET_ORDER); + foreach ($matches as $match) { + $phrase = false; + // Strip off phrase quotes + if ($match[2]{0} == '"') { + $match[2] = substr($match[2], 1, -1); + $phrase = true; + } + $words = trim($match[2], ',?!();:-'); + $words = $phrase ? array($words) : preg_split('/ /', $words, -1, PREG_SPLIT_NO_EMPTY); + foreach ($words as $word) { + $where[] = "$upper($field) LIKE $upper('%%%s%%')"; + $values[] = trim($word, " ,!?"); + } + } + + if (!$where) { + return; + } + + if ($this->operator == 'word') { + $where = '(' . implode(' OR ', $where) . ')'; + } + else { + $where = implode(' AND ', $where); + } + // previously this was a call_user_func_array but that's unnecessary + // as views will unpack an array that is a single arg. + $this->query->add_where($this->options['group'], $where, $values); + } + + function op_starts($field, $upper) { + $this->query->add_where($this->options['group'], "$upper($field) LIKE $upper('%s%%')", $this->value); + } + + function op_not_starts($field, $upper) { + $this->query->add_where($this->options['group'], "$upper($field) NOT LIKE $upper('%s%%')", $this->value); + } + + function op_ends($field, $upper) { + $this->query->add_where($this->options['group'], "$upper($field) LIKE $upper('%%%s')", $this->value); + } + + function op_not_ends($field, $upper) { + $this->query->add_where($this->options['group'], "$upper($field) NOT LIKE $upper('%%%s')", $this->value); + } + + function op_not($field, $upper) { + $this->query->add_where($this->options['group'], "$upper($field) NOT LIKE $upper('%%%s%%')", $this->value); + } + + function op_empty($field) { + if ($this->operator == 'empty') { + $operator = "IS NULL"; + } + else { + $operator = "IS NOT NULL"; + } + + $this->query->add_where($this->options['group'], "$field $operator"); + } + +} diff --git a/sites/all/modules/views/handlers/views_handler_relationship.inc b/sites/all/modules/views/handlers/views_handler_relationship.inc new file mode 100644 index 0000000..459ac7c --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_relationship.inc @@ -0,0 +1,152 @@ +definition['relationship table'])) { + $this->table = $this->definition['relationship table']; + } + if (isset($this->definition['relationship field'])) { + $this->field = $this->definition['relationship field']; + } + } + + /** + * Get this field's label. + */ + function label() { + if (!isset($this->options['label'])) { + return $this->ui_name(); + } + return $this->options['label']; + } + + function option_definition() { + $options = parent::option_definition(); + + $label = !empty($this->definition['label']) ? $this->definition['label'] : $this->definition['field']; + $options['label'] = array('default' => $label, 'translatable' => TRUE); + $options['required'] = array('default' => FALSE); + + return $options; + } + + /** + * Default options form that provides the label widget that all fields + * should have. + */ + function options_form(&$form, &$form_state) { + $form['label'] = array( + '#type' => 'textfield', + '#title' => t('Label'), + '#default_value' => isset($this->options['label']) ? $this->options['label'] : '', + '#description' => t('The label for this relationship that will be displayed only administratively.'), + ); + + $form['required'] = array( + '#type' => 'checkbox', + '#title' => t('Require this relationship'), + '#description' => t('If required, items that do not contain this relationship will not appear.'), + '#default_value' => !empty($this->options['required']), + ); + } + + /** + * Called to implement a relationship in a query. + */ + function query() { + // Figure out what base table this relationship brings to the party. + $table_data = views_fetch_data($this->definition['base']); + $base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field']; + + $this->ensure_my_table(); + + $def = $this->definition; + $def['table'] = $this->definition['base']; + $def['field'] = $base_field; + $def['left_table'] = $this->table_alias; + $def['left_field'] = $this->field; + if (!empty($this->options['required'])) { + $def['type'] = 'INNER'; + } + + if (!empty($def['join_handler']) && class_exists($def['join_handler'])) { + $join = new $def['join_handler']; + } + else { + $join = new views_join(); + } + + $join->definition = $def; + $join->construct(); + $join->adjusted = TRUE; + + // use a short alias for this: + $alias = $def['table'] . '_' . $this->table; + + $this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship); + } +} + +/** + * A special handler to take the place of missing or broken handlers. + */ +class views_handler_relationship_broken extends views_handler_relationship { + function ui_name($short = FALSE) { + return t('Broken/missing handler'); + } + + function ensure_my_table() { /* No table to ensure! */ } + function query() { /* No query to run */ } + function options_form(&$form, &$form_state) { + $form['markup'] = array( + '#prefix' => '
', + '#value' => t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.'), + ); + } + + /** + * Determine if the handler is considered 'broken' + */ + function broken() { return TRUE; } +} + +/** + * @} + */ diff --git a/sites/all/modules/views/handlers/views_handler_sort.inc b/sites/all/modules/views/handlers/views_handler_sort.inc new file mode 100644 index 0000000..ead0f5c --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_sort.inc @@ -0,0 +1,86 @@ +ensure_my_table(); + // Add the field. + $this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']); + } + + function option_definition() { + $options = parent::option_definition(); + + $options['order'] = array('default' => 'ASC'); + + return $options; + } + + /** + * Display whether or not the sort order is ascending or descending + */ + function admin_summary() { + switch ($this->options['order']) { + case 'ASC': + case 'asc': + default: + $type = t('asc'); + break; + case 'DESC'; + case 'desc'; + $type = t('desc'); + break; + } + return '' . $type . ''; + } + + /** + * Basic options for all sort criteria + */ + function options_form(&$form, &$form_state) { + $form['order'] = array( + '#type' => 'radios', + '#title' => t('Sort order'), + '#options' => array('ASC' => t('Ascending'), 'DESC' => t('Descending')), + '#default_value' => $this->options['order'], + ); + } +} + +/** + * A special handler to take the place of missing or broken handlers. + */ +class views_handler_sort_broken extends views_handler_sort { + function ui_name($short = FALSE) { + return t('Broken/missing handler'); + } + + function ensure_my_table() { /* No table to ensure! */ } + function query() { /* No query to run */ } + function options_form(&$form, &$form_state) { + $form['markup'] = array( + '#prefix' => '
', + '#value' => t('The handler for this item is broken or missing and cannot be used. If a module provided the handler and was disabled, re-enabling the module may restore it. Otherwise, you should probably delete this item.'), + ); + } + + /** + * Determine if the handler is considered 'broken' + */ + function broken() { return TRUE; } +} + + +/** + * @} + */ diff --git a/sites/all/modules/views/handlers/views_handler_sort_date.inc b/sites/all/modules/views/handlers/views_handler_sort_date.inc new file mode 100644 index 0000000..8101482 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_sort_date.inc @@ -0,0 +1,69 @@ + 'second'); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['granularity'] = array( + '#type' => 'radios', + '#title' => t('Granularity'), + '#options' => array( + 'second' => t('Second'), + 'minute' => t('Minute'), + 'hour' => t('Hour'), + 'day' => t('Day'), + 'month' => t('Month'), + 'year' => t('Year'), + ), + '#description' => t('The granularity is the smallest unit to use when determining whether two dates are the same; for example, if the granularity is "Year" then all dates in 1999, regardless of when they fall in 1999, will be considered the same date.'), + '#default_value' => $this->options['granularity'], + ); + } + + /** + * Called to add the sort to a query. + */ + function query() { + $this->ensure_my_table(); + switch ($this->options['granularity']) { + case 'second': + default: + $this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']); + return; + case 'minute': + $formula = views_date_sql_format('YmdHi', "$this->table_alias.$this->real_field"); + break; + case 'hour': + $formula = views_date_sql_format('YmdH', "$this->table_alias.$this->real_field"); + break; + case 'day': + $formula = views_date_sql_format('Ymd', "$this->table_alias.$this->real_field"); + break; + case 'month': + $formula = views_date_sql_format('Ym', "$this->table_alias.$this->real_field"); + break; + case 'year': + $formula = views_date_sql_format('Y', "$this->table_alias.$this->real_field"); + break; + } + + // Add the field. + $this->query->add_orderby(NULL, $formula, $this->options['order'], $this->table_alias . '_' . $this->field . '_' . $this->options['granularity']); + } +} diff --git a/sites/all/modules/views/handlers/views_handler_sort_formula.inc b/sites/all/modules/views/handlers/views_handler_sort_formula.inc new file mode 100644 index 0000000..30a6451 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_sort_formula.inc @@ -0,0 +1,47 @@ +formula = $this->definition['formula']; + if (is_array($this->formula) && !isset($this->formula['default'])) { + $this->error = t('views_handler_sort_formula missing default: @formula', array('@formula' => var_export($this->formula, TRUE))); + } + parent::construct(); + } + /** + * Called to add the sort to a query. + */ + function query() { + if (is_array($this->formula)) { + global $db_type; + if (isset($this->formula[$db_type])) { + $formula = $this->formula[$db_type]; + } + else { + $formula = $this->formula['default']; + } + } + else { + $formula = $this->formula; + } + $this->ensure_my_table(); + // Add the field. + $this->query->add_orderby(NULL, $formula, $this->options['order'], $this->table_alias . '_' . $this->field); + } +} diff --git a/sites/all/modules/views/handlers/views_handler_sort_menu_hierarchy.inc b/sites/all/modules/views/handlers/views_handler_sort_menu_hierarchy.inc new file mode 100644 index 0000000..294b3c4 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_sort_menu_hierarchy.inc @@ -0,0 +1,19 @@ +ensure_my_table(); + $max_depth = isset($this->definition['max depth']) ? $this->definition['max depth'] : MENU_MAX_DEPTH; + for ($i = 1; $i <= $max_depth; ++$i) { + $this->query->add_orderby($this->table_alias, $this->field . $i, $this->options['order']); + } + } +} diff --git a/sites/all/modules/views/handlers/views_handler_sort_random.inc b/sites/all/modules/views/handlers/views_handler_sort_random.inc new file mode 100644 index 0000000..0a926b3 --- /dev/null +++ b/sites/all/modules/views/handlers/views_handler_sort_random.inc @@ -0,0 +1,27 @@ +query->add_orderby(NULL, $formula, $this->options['order'], '_' . $this->field); + } + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['order']['#access'] = FALSE; + } +} diff --git a/sites/all/modules/views/help/about.html b/sites/all/modules/views/help/about.html new file mode 100644 index 0000000..1792053 --- /dev/null +++ b/sites/all/modules/views/help/about.html @@ -0,0 +1,17 @@ +The views module allows administrators and site designers to create, manage, and display lists of content. Each list managed by the views module is known as a "view", and the output of a view is known as a "display". Displays are provided in either block or page form, and a single view may have multiple displays. Optional navigation aids, including a system path and menu item, can be set for each page-based display of a view. By default, views may be created that list content (a Node view type), content revisions (a Node revisions view type) or users (a User view type). A view may be restricted to members of specific user roles, and may be added, edited or deleted at the views administration page + +The "building block" design of the views system provides power and flexibility, allowing parameters to be specified only when needed. While an advanced view may use all of available parameters to create complex and highly interactive applications, a simple content listing may specify only a few options. All views rely on a conceptual framework that includes: + +
    +
  • Fields, or the individual pieces of data being displayed. Adding the fields Node: Title, Node: Type, and Node: Post date to a node view, for example, includes the title, content type and creation date in the displayed results
  • + +
  • Relationships, or information about how data elements relate to one another. If relationship data is available, like that provided by a CCK nodereference field, items from a related node may be included in the view
  • + +
  • Arguments, or additional parameters that dynamically refine the view results, passed as part of the path. Adding an argument of Node: Type to a node view with a path of "content", for example, dynamically filters the displayed items by content type. In this example (shown with Clean URLs enabled), accessing the view through the path "http://www.example.com/content/page" displays all posts of the type "page", the path "http://www.example.com/content/story" displays all posts of the type "story", and "http://www.example.com/content" displays all posts regardless of type)
  • + +
  • Sort criteria, which determine the order of items displayed in the view results. Adding the sort criteria Node: Post date (in descending order) to a node view, for example, sorts the displayed posts in descending order by creation date
  • + +
  • Filters, which limit items displayed in the results. Adding the filter Node: Published (and setting it equal to "Published") to a node view, for example, prevents unpublished items from being displayed
  • + +
  • Displays, which control where the output will be seen. Every view has a default display, which doesn't actually display the view anywhere, but is used to hold the default settings for the view, and is used when the view is called programmatically if another display is not specified. Much more useful to users are the page display, which gives a view a path and allows it to be the primary content of a page, or the block display which allows it to appear as secondary content on other pages.
  • +
diff --git a/sites/all/modules/views/help/analyze-theme.html b/sites/all/modules/views/help/analyze-theme.html new file mode 100644 index 0000000..30bb871 --- /dev/null +++ b/sites/all/modules/views/help/analyze-theme.html @@ -0,0 +1,23 @@ +

You may use any of the following possible theme files to modify individual parts of your view. In total, there are four parts to theming a view.

+
    +
  • The display theme is usually views-view.tpl.php and it largely controls the decorations around a view; where the header, footer, pager, more link, feed icon, etc, will be placed.
  • + +
  • The style will control how all of the results of the display are put together. It may be as simple as just displaying all of the rows, or it may be a complex table generator or something in between.
  • + +
  • The row style controls each individual row; not all styles utilize the row style (notably the table), but most others do. + +
  • Finally, field themes allow you to override the look and even the data of each individual field, if the style uses fields. The actual template the system will use should be hilighted in bold.
  • +
+ +
+ +A breakdown of View output +
+ +

The link to the left of each type will give you information about the default template used for that type. You may cut and paste this and place it in your theme with the appropriate template, or you may copy the base file from the views/theme directory (or, if provided by a module, from the module's directory). It is important that you clear the theme registry cache every time you add a new template, or the new template will not be picked up.

+ +

Important note: You place your custom template files in your theme directory, not views/theme. This is always true of theming with Drupal. + +

In addition to this tool, the very useful devel module contains a tool called the "Theme developer" which does a good job of visually showing you which areas of your site use which themes. Be careful with it, though, as the theme developer causes the Views edit page to break.

+ +

Also, this feature will only work properly with Drupal 6.3 and later; prior to Drupal 6.3 this patch will be required.

diff --git a/sites/all/modules/views/help/api-default-views.html b/sites/all/modules/views/help/api-default-views.html new file mode 100644 index 0000000..e1cdc2a --- /dev/null +++ b/sites/all/modules/views/help/api-default-views.html @@ -0,0 +1,105 @@ +Views can be stored in the database, which is typical of smaller sites and hobby sites. However, Views may also be stored directly in the code as "default" views, (which simply means they're available by default). Modules often come with views that are specific to the module data, but it's also possible -- and highly recommended -- that sites which have separate "development" and "production" sites export their views into default views in a site-specific module. This makes it very easy to transfer views from dev to production without making database changes. + +

Creating a module

+First, create a directory in sites/all/modules for your new module. Call it whatever you like, but for this example we will call it mymodule. + +In this directory, create a mymodule.module file. It can be empty for now, but it should at least contain an opening PHP tag: +
<?php
+// $Id $
+
+ +It should not contain a closing ?> tag, as the closing ?> tag is not required and anything AFTER the closing tag, such as a space or a linefeed, will be displayed directly to the browser and can potentially cause problems. + +The .module file will contain functions and drupal hooks. Hooks are specially named functions that Drupal will call in order to get your module's response at certain times while generating pages. The only function you will need for this exercise is the 'views_api' hook that tells Views that this module supports the Views API and what version: + +
function mymodule_views_api() {
+  return array('api' => 2.0);
+}
+
+ +For other uses you may well add additional functions. + +Second, you need to create a mymodule.info file: + +
; $Id $
+name = My module
+description = My site specific module.
+core = 6.x
+
+ +Once you have these two files set up, you should be able to activate your new module at the Administer >> Site building >> Modules page. +

Exporting your views

+ +The easiest way to do this is to activate the 'views_export' module, and navigate to Administer >> Views >> Tools >> Bulk export Place a check next to each view that you want in your module, type the module name into the text field, and click export. This will create the entire hook_views_default_views() function for you. + +You can also export individual views. If you do this, keep in mind that this export does not include the line that adds the exported $view into the larger $views array: + +
$views[$view->name] = $view
+ +To place this into your hook_views_default_views() you will need to place that after the view, and make sure the function returns $views at the end. + +

Placing your exported views into your module

+Cut and paste the entire output of the bulk export tool into mymodule.views_default.inc -- and be sure to put a <?php at the top of the file so that the webserver knows that it's PHP code! Then visit the Views tools page and clear the Views cache. Your views should now be listed as Overridden on the view list page. If you revert these views, they will be removed from the database, but will remain in code. + +

Theming your views in your module

+You can theme these views in the module and not need to rely on the theme to do this at all; and in fact, the theme can continue to override these just like it ordinarily would, even if your module provides a theme. This is very useful for distributing a module where the view needs to look "just so." + +To do this, you need to implement hook_theme() in your module: +
function mymodule_theme($existing) {
+  return array(
+    'views_view__viewname__displayid' => array (
+      'arguments' => array('view' => NULL),
+      'template' => 'views-view--viewname--displayid',
+      'original hook' => 'views_view',
+      'path' => drupal_get_path('module', 'mymodule'),
+    ),
+  );
+}
+
+ +There are a small number of gotchas in doing this that you must be aware of. + +
    +
  1. When referring to a template filename, you always use dashes in the name. i.e, views-view--viewname--displayid.tpl.php. However, when referring to the hook or function names, you use underscores instead of dashes. i.e, views_view and views_view__viewname__displayid
  2. + +
  3. The 'arguments' change based upon which of the 3 types you're overriding. There's the 'display', the 'style' and the 'row' style. The above code is assuming the display, which is usually just views_view. Here are the possibilities: + +
    display: array('view' => NULL),
    +style: array('view' => NULL, 'options' => NULL, 'rows' => NULL, 'title' => NULL),
    +row style: array('view' => NULL, 'options' => NULL, 'row' => NULL),
    +
    + +Be sure to use the right arguments line or the theme system will not properly translate. +
  4. +
  5. The 'template' line should never include the extension, so drop the .tpl.php from it.
  6. + +
  7. You need to make sure that the Views preprocess functions get registered. The 'original hook' line in the definition does that, but it can only do it if it comes after the Views registration, which actually happens very late in theme building. 99% of the time, your module will come before Views. You have two choices to deal with this: +
      +
    1. Set your module's weight to 11 or higher in the database. Views' weight is 10. You can make this happen automatically when the module is first installed by creating a mymodule.install file and using this code: +
      function mymodule_install() {
      +  db_query("UPDATE {system} SET weight = 11 WHERE name = 'mymodule'");
      +}
      +
      + If you use this method, the original hook should be set to the name of the original template being used. i.e, if this is a variate of views-view-list.tpl.php, this should be 'views_view_list'. +
    2. +
    3. You can also just force it to list the preprocessors without actually having to detect them. This doesn't require modifying your module's weight, which is not always possible, you can insert this code into the array: +
            'preprocess functions' => array(
      +        'template_preprocess',
      +        'template_preprocess_views_view',
      +        'mymodule_preprocess_views_view__viewname_displayid',
      +      ),
      +
      + + The first one is the global 'template_preprocess' function which all templates utilize. It does some basic things such as setting up $zebra and a few other items. See api.drupal.org for specifics. + + The second one is the plugin specific preprocess. Like 'original hook' it should conform to the name used by the original template. i.e, if the original template was views-view-list.tpl.php then that preprocess function would be named template_preprocess_views_view_list. + + The third one is your module's preprocess function, if it needs one. In general, you probably will not need one, and you should only attempt to use one if you are reasonably familiar with the concept of preprocess functions and Drupal's theme system in general. See Drupal's theme documentation for more information. +
    4. +
    +
  8. +
  9. + If you leave the path blank the template file will be searched for in "./" which is the Drupal install base path. +
  10. +
+ diff --git a/sites/all/modules/views/help/api-example.html b/sites/all/modules/views/help/api-example.html new file mode 100644 index 0000000..61852bb --- /dev/null +++ b/sites/all/modules/views/help/api-example.html @@ -0,0 +1,179 @@ + +For the new table defined by the Node example module to be understood by the views module you need to create a node_example.views.inc file that describes the table and its relationships to the rest of the database. In order for views to know that this file is to be loaded you need to implement hook_views_api. This is done by adding the following function into your node_example.module file + +
+<?php
+/**
+ * Implementation of hook_views_api().
+ *
+ * This tells drupal that there is Views integration file named 
+ * module-name.views.inc 
+ */
+function node_example_views_api() {
+  // Note that you can include 'path' in this array so that your views.inc 
+  // file can be stored in a different location.
+  return array(
+    'api' => 2.0
+  );
+}
+?>
+
+ +Below is the contents of a simple node_example.views.inc file that allows you to create views that include the new color and quantity information. + +
+<?php
+
+/**
+ * This file is used to tell the views module about the new node_example table.
+ *
+ * Database definition:
+ * @code
+ *   CREATE TABLE node_example (
+ *     vid int(10) unsigned NOT NULL default '0',
+ *     nid int(10) unsigned NOT NULL default '0',
+ *     color varchar(255) NOT NULL default '',
+ *     quantity int(10) unsigned NOT NULL default '0',
+ *     PRIMARY KEY (vid, nid),
+ *     KEY `node_example_nid` (nid)
+ *   )
+ * @endcode
+ */
+
+function node_example_views_data()  {
+  // Basic table information.
+
+  // ----------------------------------------------------------------
+  // node_example table
+  //  New group within Views called 'Example'
+  //  The group will appear in the UI in the dropdown tha allows you
+  //  to narrow down which fields and filters are available.
+
+  $data = array();
+  $data['node_example']['table']['group']  = t('Example');
+
+  // Let Views know that our example table joins to the 'node'
+  // base table. This means it will be available when listing
+  // nodes and automatically make its fields appear.
+  //
+  // We also show up for node revisions.
+  $data['node_example']['table']['join'] = array(
+    'node_revisions' => array(
+      'left_field' => 'vid',
+      'field' => 'vid',
+    ),
+    'node' => array(
+      'left_field' => 'vid',
+      'field' => 'vid',
+    ),
+  );
+
+  // quantity
+  $data['node_example']['quantity'] = array(
+    'title' => t('Quantity'),
+    'help' => t('Quantity of items.'),
+    'field' => array(
+      'handler' => 'views_handler_field_numeric',
+      'click sortable' => TRUE,
+     ),
+    'filter' => array(
+      'handler' => 'views_handler_filter_numeric',
+    ),
+    'sort' => array(
+      'handler' => 'views_handler_sort',
+    ),
+  );
+
+  // Color		
+  $data['node_example']['color'] = array(
+    'title' => t('Color'),
+    'help' => t('Color of item.'),
+
+    'field' => array(
+      'handler' => 'views_handler_field',
+      'click sortable' => TRUE,
+     ),
+     'filter' => array(
+      'handler' => 'views_handler_filter_string',
+     ),
+     'argument' => array(
+       'handler' => 'views_handler_argument_string',
+     ),
+     'sort' => array(
+      'handler' => 'views_handler_sort',
+     ),
+  );
+
+  return $data;
+}
+
+?>
+
+ +Some notes on usage: + +Within Views, click on the Add tab. You have a number of type options here. Normally you would select either 'Node' (if you only want to display information on current nodes) or 'Node revision' (if you want to display information on all revisions of the nodes) + +With this configuration you always pull out of the database, data for every single node, whether or not it has color and quantity information. To display information on just those nodes that have color and quantity information you can use a filter so that only nodes which don't have a NULL color or a NULL quantity are displayed. + +

Type/relationship extension

+ +When your tables have first class data, you will often need to have own View types and View relationships defined. With the current node_example table this isn't required although I try to justify it below on an efficiency basis. See [[http://groups.drupal.org/node/17236#comment-58980|this discussion]] as to why it isn't justified. + +Pulling data out of the database for every node when you only want data for the new Example node type is inefficient. To reduce the initial data extraction to just that relating to the new Example nodes requires that you make the node_example table the base table. This can be done by adding the following code into the node_example.views.inc file just before the 'return $data;' + +
+<?php
+
+//  **** Begin optional extra for type and relationships ****
+
+  //  Use node_example as a new base table
+  //     by creating a new views type called 'Node example'
+  //  This allows it to be selected as the 'view type'
+  //          when you initially add a new view. 
+  $data['node_example']['table']['base'] = array(
+    'field' => 'vid',
+    'title' => t('Node example'),
+    'help' => t("Node example type with color and quantity information."),
+    'weight' => -9,
+  );
+
+  // When using the new 'Node example' type you need to use relationships
+  //   to access fields in other tables.
+
+  // Relationship to the 'Node revision' table
+  $data['node_example']['vid'] = array(
+    'title' => t('Node revision'),
+    'help' => t('The particular node revision the color and quantity is attached to'),
+    'relationship' => array(
+      'label' => t('Node revision'),
+      'base' => 'node_revisions',
+      'base field' => 'vid',
+      // This allows us to not show this relationship if the base is already
+      // node_revisions so users won't create circular relationships.
+      'skip base' => array('node', 'node_revisions'),
+    ),
+  );
+
+  // Relationship to the 'Node' table
+  $data['node_example']['nid'] = array(
+    'title' => t('Node'),
+    'help' => t('The particular node the color and quantity is attached to'),
+    'relationship' => array(
+      'label' => t('Node'),
+      'base' => 'node',
+      'base field' => 'nid',
+      // This allows us to not show this relationship if the base is already
+      // node so users won't create circular relationships.
+      'skip base' => array('node', 'node_revisions'),
+    ),
+  );
+
+//  **** End optional extra for type and relationships ****
+
+?>
+
+ +The above code adds a new 'Node example' to the view types that can be selected within the Add tab window of views. Selecting this sets the node_example table to be the base table. + +If you select 'Node example' as view type, when you initially go into the edit window of views you will find the only fields available are the color and quantity fields. To get fields from other tables you need to add a relationship. Relationships may be found at the top in the same column as the fields. diff --git a/sites/all/modules/views/help/api-handlers.html b/sites/all/modules/views/help/api-handlers.html new file mode 100644 index 0000000..0c51fc5 --- /dev/null +++ b/sites/all/modules/views/help/api-handlers.html @@ -0,0 +1,70 @@ +In Views, a handler is an object that is part of the view and is part of the query building flow. + +Handlers are objects; much of the time, the base handlers will work, but often you'll need to override the handler for something. One typical handler override will be views_handler_filter_operator_in which allows you to have a filter select from a list of options; you'll need to override this to provide your list. + +Handlers have two distint code flows; the UI flow and the view building flow. + +For the query flow: + +
+
handler->construct()
+
Create the initial handler; at this time it is not yet attached to a view. It is here that you can set basic defaults if needed, but there will be no knowledge of the environment yet.
+
handler->set_definition()
+
Set the data from hook_views_data() relevant to the handler.
+
handler->init()
+
Attach the handler to a view, and usually provides the options from the display.
+
handler->pre_query()
+
Run prior to the query() stage to do early processing.
+
handler->query()
+
Do the bulk of the work this handler needs to do to add itself to the query.
+
+ +Fields, being the only handlers concerned with output, also have an extended piece of the flow: +
+
handler->pre_render()
+
Called prior to the actual rendering, this allows handlers to query for extra data; the entire resultset is available here, and this is where items that have "multiple values" per record can do their extra query for all of the records available. There are several examples of this at work in the code.
+
handler->render()
+
This does the actual work of rendering the field.
+
+ +Most handlers are just extensions of existing classes with a few tweaks that are specific to the field in question. For example: + +
+/**
+ * Filter by node type
+ */
+class views_handler_filter_node_type extends views_handler_filter_in_operator {
+  function get_value_options() {
+    if (!isset($this->value_options)) {
+      $this->value_title = t('Node type');
+      $types = node_get_types();
+      foreach ($types as $type => $info) {
+        $options[$type] = $info->name;
+      }
+      $this->value_options = $options;
+    }
+  }
+}
+
+ +views_handler_filter_in_operator provides a simple mechanism to set the list used and the rest of the handler is perfectly fine for this. + +Handlers are stored in their own files; for these files to be loaded by Views on demand, they must first be registered. Since Views core handlers are also loaded this way, it's imperative that your module also implement this pattern in order to prevent code crashes when your handler's parent class is not yet available. + +To register handlers, you must implement hook_views_handlers(). This hook returns an array with two keys; the first key is info which contains the modulename (which is only necessary if you're registering handlers on behalf of another module, such as what Views does) and path, which is the search path to find the files. This path is only necessary if your files will not be stored in the same directory as the .module file. + +The other key is handlers which contains a full array of handlers and the information for each handler. The key to each handler array is the name of the handler class. It can contain: +
+
parent
+
The class that this handler extends. This is important to make sure that the parent class is included before your handler class. Without this, you may cause people's sites to crash in a difficult to recover state. Be sure you get this right!
+
file
+
The filename the handler is in. By default, this will be classname.inc -- however, you can have multiple similar handlers together in one file. However, because there is only one parent, please be sure that the parentage on these handlers matches! Otherwise you will run into whitescreens as not all parents will be loaded.
+
+ +You can see examples of this function in any of the various module.views.inc files in the views modules directory. + +The best place to learn more about handlers and how they work is to explore the views API site and use existing handlers as a guide and a model. Understanding how views_handler and its child classes work is handy but you can do a lot just following these models. You can also explore the views module directory, particularly node.views.inc. + +Please note that while all handler names in views are prefixed with views_, you should use your own module's name to prefix your handler names in order to ensure namespace safety. Note that the basic pattern for handler naming goes like this: + +[module]_handler_[type]_[tablename]_[fieldname]. Sometimes table and fieldname are not appropriate, but something that resembles what the table/field would be can be used. \ No newline at end of file diff --git a/sites/all/modules/views/help/api-plugins.html b/sites/all/modules/views/help/api-plugins.html new file mode 100644 index 0000000..c0185b7 --- /dev/null +++ b/sites/all/modules/views/help/api-plugins.html @@ -0,0 +1,79 @@ +In Views, a plugin is a bit like a handler, but plugins are not directly responsible for building the query. Instead, they are objects that are used to display the view or make other modifications. + +There are 6 types of plugins in Views: +
+
Display
+
Display plugins are responsible for controlling where a view lives. Page and block are the most common displays, as well as the ubiquitous 'default' display which is likely what will be embedded.
+
Style
+
Style plugins control how a view is displayed. For the most part they are object wrappers around theme templates. +
Row style
+
Row styles handle each individual record from a node.
+
Argument default
+
Argument default plugins allow pluggable ways of providing arguments for blocks. Views includes plugins to extract node and user IDs from the URL; additional plugins could be used for a wide variety of tasks.
+
Argument validator
+
Validator plugins can ensure arguments are valid, and even do transformations on the arguments.
+
Access
+
Access plugins are responsible for controlling access to the view.
+
+ +Plugins are registered by implementing hook_views_plugins() in your modulename.views.inc file and returning an array of data. + +The array will look something like this: +
+  return array(
+    'display' => array(
+      // ... list of display plugins,
+     ),
+    'style' => array(
+      // ... list of style plugins,
+     ),
+    'row' => array(
+      // ... list of row style plugins,
+     ),
+    'argument default' => array(
+      // ... list of argument default plugins,
+     ),
+    'argument validator' => array(
+      // ... list of argument validator plugins,
+     ),
+     'access' => array(
+      // ... list of access plugins,
+     ),
+  );
+
+ +Each plugin will be registered with an identifier for the plugin, plus a fairly lengthy list of items that can define how and where the plugin is used. Here is an example from Views core: + +
+      'node' => array(
+        'title' => t('Node'),
+        'help' => t('Display the node with standard node view.'),
+        'handler' => 'views_plugin_row_node_view',
+        'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules
+        'theme' => 'views_view_row_node',
+        'base' => array('node'), // only works with 'node' as base.
+        'uses options' => TRUE,
+        'type' => 'normal',
+      ),
+
+ +Of particular interest is the path directive, which works a little differently from handler registration; each plugin must define its own path, rather than relying on a global info for the paths. Also, there is an optional parent directive which is automatically filled in to be the base parent for the plugin type. Usually this is enough, but if your plugin derives from something other than the base, it must be filled in. For example: + +
+      'feed' => array(
+        'title' => t('Feed'),
+        'help' => t('Display the view as a feed, such as an RSS feed.'),
+        'handler' => 'views_plugin_display_feed',
+        'parent' => 'page', // so it knows to load the page plugin .inc file
+        'uses hook menu' => TRUE,
+        'use ajax' => FALSE,
+        'use pager' => FALSE,
+        'accept attachments' => FALSE,
+        'admin' => t('Feed'),
+        'help topic' => 'display-feed',
+      ),
+
+ +Note that unlike handler registration, where parentage is referred to by object name, with plugins it is referred to by the unique plugin identifier. Please be sure to prefix your plugin identifiers with your module name to ensure namespace safety; after all, two different modules could try to implement the 'grid2' plugin, and that would cause one plugin to completely fail. + +...TODO: Finish this document.... diff --git a/sites/all/modules/views/help/api-tables.html b/sites/all/modules/views/help/api-tables.html new file mode 100644 index 0000000..c4e9f8c --- /dev/null +++ b/sites/all/modules/views/help/api-tables.html @@ -0,0 +1,236 @@ +Tables are described to Views via hook_views_data(), which returns an array of table information, keyed by the name of the table. For example, if your module is describing three tables, 'foo', 'bar' and 'baz', your array will look like this: +
$data = array(
+  'foo' => array(
+    // ...info here...
+  ),
+  'bar' => array(
+    // ...info here...
+  ),
+  'baz' => array(
+    // ...info here...
+  ),
+);
+
+ +The key should be the actual database name of the table (not including prefix), but it can be an alias as long as the join information (explained later) contains the real name of the table. + +Each item in the array should be a field in the table, with the exception of a special information section called 'table'. Example: + +
$data['foo'] = array(
+  'table' => array(
+    // ... info about the table, described later ...
+  ),
+  'bar' => array(
+    // ... info about the field named 'bar', i.e, foo.bar,
+  ),
+  'baz' => array(
+    // ... info about the field named 'baz', i.e, foo.baz,
+  ),
+);
+
+ +Once you get down to an array that contains actual data, that piece of the array will often be referred to as the definition. + +

The 'table' section

+Each table should have a 'table' section in it, which is used to set default information for the table, such as the group, as well as the very important joins and whether or not this is a base table. + +First, there are several items that are actually for fields but can be placed here so that all fields within the table inherit them: +
+
group
+
The name of the group this item will be with. In the UI, this is displayed as Group: Title. For example, "Node: Node ID", "Taxonomy: Term description", etc. It is important to be consistent with groups, because the UI sorts by group, and allows filtering by group to find fields as well.
+
title
+
The actual name of the field; it should be concise and descriptive.
+
help
+
A longer description to help describe what the field is or does. It should try to be only a line or two so as not to clutter the UI.
+
+ +In general, having 'title' and 'help' at the table level doesn't make a lot of sense, but usually every item in a table is in the same group. Thus it is very common to define the 'group': + +
+  $data['foo']['table']['group'] = t('Foo');
+
+ +The other items in the 'table' section are described in the following sections. + +

'base': Base table

+If your table is a base table -- meaning it can be the primary, central table for a View to use, you can declare it to be a base table. This primarily provides UI information so that it can be selected. +For example: +
+  // Advertise this table as a possible base table
+  $data['node']['table']['base'] = array(
+    'field' => 'nid',
+    'title' => t('Node'),
+    'help' => t("Nodes are a Drupal site's primary content."),
+    'weight' => -10,
+  );
+
+ +The following items are available in the base section : +
+
field
+
The primary key field for this table. For Views to treat any table as a base table, it must have a primary field. For node this is the 'nid', for users this is the 'uid', etc. Without a single primary key field (i.e. not a composite key), Views will not be able to utilize the table as a base table. If your table does not have a primary key field, it is not too difficult to just add a serial field to it, usually.
+
title
+
The title of this table in the UI. It should be singular and describe the object that this table contains from the perspective of the user.
+
help
+
A short piece of text to describe what object this table contains.
+
database
+
If this table is held in a different database from your Drupal database, specify it as a string in the exact same format as the settings.php file. This is a special purpose variable that will probably be only used in site specific code, and it must be the same database type as your Drupal database. Also, don't try to join it to any table that isn't in the same database. That'll just create all kinds of silly errors. For example: +
+  // In settings.php for your site
+  // Your drupal (site) database needs to be called 'default'
+  $db_url['default'] = 'mysqli://user:pass@host/drupal_db';
+  $db_url['budget'] = 'mysqli://user:pass@host/other_db';
+
+Then when you are describing the external database in your base table you would write something like this: +
+  $data[$table]['table']['base'] = array(
+    'field' => 'Primary key',
+    'title' => t('Field name'),
+    'help' => t('Field description'),
+    'database' => 'budget',
+    'weight' => -10,
+    );
+
+
+
+ +

'join': Linking your table to existing base tables

+For Views to use your table, it has to either be a base table, or know how to link to an existing base table. Or sometimes both. Views uses this information to create a path to the base table; when the table is added to the query, Views will walk along this path, adding all tables required into the query. + +
+ +How term_data joins to node +
+ +In the above example, to use these with 'node' as the base table, both 'term_data' and 'term_node' need to be defined, and they each need a join handler for node: + +
+$data['term_data']['table']['join']['node'] = array(
+  'left_table' => 'term_node',
+  'left_field' => 'tid',
+  'field' => 'tid',
+);
+
+ +The above can be read as "In order to join to the node table, the term_data table must first link to the term_node table, and they join on the 'tid' field.". When adding this table to the query for a node view, Views will look at this and then look for the term_node table. + +
+$data['term_node']['table']['join']['node'] = array(
+  'left_field' => 'nid',
+  'field' => 'nid',
+);
+
+ +Above, the fact that 'left_table' is left out lets us know that term_node links directly to the node table, using the 'nid' field on both sides of the join. + +Quite a few more fields are available in this definition: +
+
handler
+
The name of the handler object to use. Defaults to 'views_join'. You may create custom join handlers that may or may not use any of the data below, as they see fit.
+
table
+
Table to join. This is optional, and should only be used if the table being referenced is an alias.
+
field
+
Field to join on. This is required.
+
left_table
+
The next step toward the final destination. If this is the final destination it may be omitted.
+
left_field
+
The field to join to on the left side. This is required.
+
type
+
Either LEFT (default) or INNER.
+
extra
+
Either a string that's directly added, or an array of items. Each item is, itself, an array: +
+
field
+
Field or formula
+
operator
+
Similar to filters, this is the operator, such as >, <, =, etc. Defaults to = or IN.
+
value
+
Must be set. If an array, operator will be defaulted to IN.
+
numeric
+
If true, the value will not be surrounded in quotes, and %d will be used for its placeholder.
+
+
+
extra type
+
How all the extras will be combined. Either AND or OR. Defaults to AND.
+
+ +

Describing fields on tables

+Aside from the special table tag, each table can also have an unlimited number of field designations; these correspond roughly to fields on the table, though it is very common to use non-fields to display data that isn't directly in a field, such as data arrived from formulae, or special links related to the object the table is part of. + +Each field is described in the view data with an array, keyed to the database name of the field. This array may contain some information fields, plus an entry in each of the five types of items Views has per field: argument, field, filter, relationship, sort. For example: + +
+$data['node']['nid'] = array(
+  'title' => t('Nid'),
+  'help' => t('The node ID of the node.'), // The help that appears on the UI,
+  // Information for displaying the nid
+  'field' => array(
+    'handler' => 'views_handler_field_node',
+    'click sortable' => TRUE,
+  ),
+  // Information for accepting a nid as an argument
+  'argument' => array(
+    'handler' => 'views_handler_argument_node_nid',
+    'name field' => 'title', // the field to display in the summary.
+    'numeric' => TRUE,
+    'validate type' => 'nid',
+  ),
+  // Information for accepting a nid as a filter
+  'filter' => array(
+    'handler' => 'views_handler_filter_numeric',
+  ),
+  // Information for sorting on a nid.
+  'sort' => array(
+    'handler' => 'views_handler_sort',
+  ),
+);
+
+ +The above example describes the 'nid' field on the 'node' table, providing 4 of the 5 handlers. Note that while field is normally expected to be the database name of the field, it doesn't have to be; you can use an alias (which is how you get multiple handlers per field) or something completely made up for items that aren't tied to the database. For example: + +
+$data['node']['edit_node'] = array(
+  'field' => array(
+    'title' => t('Edit link'),
+    'help' => t('Provide a simple link to edit the node.'),
+    'handler' => 'views_handler_field_node_link_edit',
+  ),
+);
+
+ +The above handler definition an edit link to a node, but this isn't a field in and of itself. For aliased fields, here is another example: + +
+$data['users']['uid_current'] = array(
+  'real field' => 'uid',
+  'title' => t('Current'),
+  'help' => t('Filter the view to the currently logged in user.'),
+  'filter' => array(
+    'handler' => 'views_handler_filter_user_current',
+  ),
+);
+
+ +The above definition provides an alternate filter handler on the uid field for the current user. + +The following items are allowed in the field definition: + +
+
group, title, help
+
As above, these fields are for the UI. If placed here, any of these fields will override a setting on the base table.
+
real field
+
If this field is an alias, the "real field" may be placed here, and the handler will never know the difference.
+ +
field
+
A handler definition for the "Field" section, which is a field that may be displayed in a view. The definition is an array; the contents of the array are completely up to the handler, other than the 'handler' definition. If omitted, handler will default to 'views_handler_field'.
+
filter
+
A handler definition for the "Filters" section, which will be used to apply WHERE clauses to the view. The definition is an array; the contents of the array are completely up to the handler, other than the 'handler' definition. If omitted, handler will default to 'views_handler_filter'.
+
sort
+
A handler definition for the "Sort criteria" section, which will be used to add an ORDER BY clause to the view. The definition is an array; the contents of the array are completely up to the handler, other than the 'handler' definition. If omitted, handler will default to 'views_handler_sort'.
+
relationship
+
A handler definition for the "Field" section, which is a way to bring in new or alternative base tables in the view. The definition is an array; the contents of the array are completely up to the handler, other than the 'handler' definition. If omitted, handler will default to 'views_handler_relationship'. The basic relationship handler requires 'base' and 'base field' to be set; 'base' and 'base field' represent the "right" half of the join that will use this field as the left side.
+
argument
+
A handler definition for the "Field" section, which is method of accepting user input from the URL or some other source. The definition is an array; the contents of the array are completely up to the handler, other than the 'handler' definition. If omitted, handler will default to 'views_handler_argument'.
+
+ +For more information about what handlers need/use what data, visit the Views API site and check out the available handlers. diff --git a/sites/all/modules/views/help/api.html b/sites/all/modules/views/help/api.html new file mode 100644 index 0000000..66e3f87 --- /dev/null +++ b/sites/all/modules/views/help/api.html @@ -0,0 +1,22 @@ +Views allows modules to describe their tables relationships to each other, as well as fields, filters, sort criteria and arguments via hook_views_data(). Whenever Views deems it necessary, this hook is called, the data aggregated together and cached. hook_views_data_alter() may also be used to modify existing data, changing other module's handlers or adding handlers to other module's tables. + +Views also allows modules to create new display types, style types, row styles, argument default handlers and argument validators via hook_views_handlers() and hook_views_plugins(). + +These hooks are kept in a file named MODULENAME.views.inc. This file is automatically included upon need, so there is no need to try and include this in hook_init or any other method of including .inc files. This file should store hook_views_data, hook_views_data_alter(), hook_views_plugins(), hook_views_handlers(), as well as any other hooks and subsidiary data that will only be used by your module when Views is active. All handlers and plugins provided by your module should be in separate .inc files. + +There are two similar files, MODULENAME.views_default.inc and MODULENAME.views_convert.inc which contain default views and views 1 to views 2 convert helpers, respectively. + +

hook_views_api()

+In order for your files to be included, your module must first implement hook_views_api() in the main .module file. This module should return array of information. The following items may be returned: + +
+
api
+
This must appear; it should be the oldest API version that your module can work with. If Views is currently running an older version of the API, it will ignore your module's views integration. This is a good thing, as it will prevent code crashes, at the expense of your module's functionality disappearing. +
+You may find the current Views API version by calling views_api_version() which is implemented at the top of views.module. This version numbering starts at 2.0. Every time changes are made to the Views handlers and plugins or other aspects of the Views API, the number will tick up (by either .001, .01 .1 or 1 depending upon how major the changes are). Note that views_api_version() was introduced in Views 2.0-rc2 and may not exist prior to that version. You may use function_exists() to test to see if this function is there. +
+Often these versions are basically compatible with each other and Views won't care if your module implements 2.000, 2.001, 2.002, etc. Your module can request that it won't work with any version older than a given version, however. Views will determine, itself, if a newer version will work. +
+
path
+
If your *.views*.inc files are not in the same directory as the .module file, then return the full path here. You should probably use something like drupal_get_path('module', 'yourmodulename') . '/includepath'.
+
diff --git a/sites/all/modules/views/help/argument.html b/sites/all/modules/views/help/argument.html new file mode 100644 index 0000000..c4bdf2b --- /dev/null +++ b/sites/all/modules/views/help/argument.html @@ -0,0 +1,57 @@ +Arguments are input. While they often come from the URL, they don't always so please don't be shocked when they don't. Each display type may have its own source for arguments. Block displays have no source of arguments at all; they cannot pull arguments from the URL, and often require use of the default argument PHP code in order to get arguments. The argument default plugins can be used to get arguments into a block view. See "Provide default", below. + +In general, arguments are used to filter the view, and in that sense they have a very close relationship to filters, but that isn't necessarily true for every argument. Arguments can be used for any purpose, really; the extent of what the argument does is up to the developer of the argument, but the arguments that come with Views are almost entirely filters. + +A typical use of an argument might be to reduce a view to a single node, a single user, or nodes with a given taxonomy term. + +

Action to take if argument is not present

+
+
Ignore
+
The argument is removed from the view as though it weren't there and all results will be displayed.
+ +
Hide view / Page not found
+
The view will remove itself entirely if the argument is not present; for a block this means it simply won't appear. For page views the View will return a 404 and present a "Page not found" error.
+ +
Display empty text
+
The value of the empty text will be displayed.
+ +
Summary
+
The view will attempt to display a summary of arguments available, based upon the view, and provide links to the view with those arguments. Summaries have their own style handlers as well as options. The default summary style simply displays a list of arguments with a count of entries found per argument. This special mode is a very powerful part of Views.
+ +
Provide default
+
If no argument is given, a default argument can be selected. The method of choosing the default argument is selectable and pluggable.
+
+ +

Wildcards

+All arguments have a 'wildcard', which is an argument that means to use all values. In practice, it is the same as 'Ignore' above, where the argument is simply removed and the view is created without the argument. The wildcard title is used in titles and breadcrumb trails. +

Default arguments

+Default argument selection is available only if the action to take is "Provide default". When that is selected, a new fieldset will appear letting you choose what the default argument will be. Views provides the following default selectors by default (but other modules may add more): +
+
Fixed entry
+
You may directly enter what the argument will be. This is not a variable, it will always be the same argument.
+
Node ID from URL
+
This will attempt to find a Node ID from the URL, and is primarily useful for the Node: ID argument (though other arguments that use Node IDs, such as the CCK Node Reference argument, will find it useful too). For example, when visiting the path 'node/1' or 'node/1/edit' it will know that the '1' in that path is a node ID and use it.
+
User ID from URL
+
Like Node ID from URL, this will attempt to find a user ID from the path. It also includes an option to look for a node and use the node author as the user ID.
+
User ID from logged in user
+
You can use this to easily default a menu item to the logged in user. For example, if you created the path 'blogs' and gave it a User: ID argument with this default, 'blogs' would go to the user's own blogs, and blogs/1 would go to User ID 1's blogs.
+
+ +Please bear in mind that the selection of default argument happens only if an argument is not provided. If using a display that has no argument source, such as a block, this will always be used. However, if using a display that reads arguments from the URL, this will happen only if the URL did not contain an argument. +

Argument validation

+Arguments can also have validators, which are pluggable systems used to ensure that arguments fit within certain parameters. When a validator is chosen, it may provide some settings for the validator, including the action to take if an argument is presented, but it fails to validate. These actions are generally the same as the default actions above, excluding the ability to provide another default. + +If a view provides a menu option, such as a tab, if the argument does not validate the tab will not appear. + +This sytem can have other validators plugged in; by default, Views provides: +
+
Basic validation
+
Ensures that the argument is present. A PHP NULL value (from eg. PHP default argument code) will invalidate.
+
Node
+
Ensure that the argument is a valid Node ID. You may select which types of node the validator will accept.
+
Taxonomy term
+
Ensure that the argument is a valid taxonomy term. This includes options to limit to specific vocabularies and can transform the argument to the right type depending upon the actual argument. Set the Argument Type option to the actual type of data that the argument being used is expecting.
+
PHP Code
+
You may enter arbitrary PHP code, similar to the php block visibility code, to determine if the argument is valid or not.
+ +
diff --git a/sites/all/modules/views/help/display-attachment.html b/sites/all/modules/views/help/display-attachment.html new file mode 100644 index 0000000..9963b25 --- /dev/null +++ b/sites/all/modules/views/help/display-attachment.html @@ -0,0 +1 @@ +Attachment displays are 'attached' to another display in the same view. When the display is visited, the attached display will also be rendered and may be placed before, after or both before and after the original display. Attachment displays are often useful for displaying an argument summary view along with a page display that accepts arguments. This can be used to provide a kind of glossary. \ No newline at end of file diff --git a/sites/all/modules/views/help/display-block.html b/sites/all/modules/views/help/display-block.html new file mode 100644 index 0000000..158cad0 --- /dev/null +++ b/sites/all/modules/views/help/display-block.html @@ -0,0 +1,10 @@ +Block displays will show up on your blocks administration page. Once a block display is created and saved, it can be enabled and positioned in your theme by visiting administer >> site building >> blocks and selecting it from the list. + +Blocks do not accept arguments from any source; the only way to get arguments to a block is to provide defaults to it, possibly via the PHP Code default setting. + +
    +
  • Edit the argument in question; you may want to override this argument if you have multiple displays using it.
  • +
  • Change the "Action to take if argument is not present" to "Provide default argument". This will bring up a new box called "Provide default argument options".
  • +
  • The most common default argument type used for blocks is Node from URL, where it attempts to determine if the URL refers to a node, for example if visiting 'node/1' or 'node/1/edit'. User ID from URL is also very common.
  • +
  • If you change the default argument type to 'PHP Code' (note: You must have permission to use PHP code on your site) you can enter PHP to define the argument needed. Simply return the argument.
  • +
diff --git a/sites/all/modules/views/help/display-default.html b/sites/all/modules/views/help/display-default.html new file mode 100644 index 0000000..309690a --- /dev/null +++ b/sites/all/modules/views/help/display-default.html @@ -0,0 +1,4 @@ +The default display is primarily a display to store settings, and isn't actually used anywhere within the Views system. It is possible for external programs to use the default display, but if they do they will (hopefully) tell you which display they will be working with. The default display is also a convenient display to use to embed into your site using PHP snippets; this is useful, for example, in node content, but this is something that should generally only be done by administrators. + +In general, you probably want to add either a page display or a block display. + diff --git a/sites/all/modules/views/help/display-feed.html b/sites/all/modules/views/help/display-feed.html new file mode 100644 index 0000000..a5c0a65 --- /dev/null +++ b/sites/all/modules/views/help/display-feed.html @@ -0,0 +1 @@ +A feed display allows you to attach an RSS feed to a view. \ No newline at end of file diff --git a/sites/all/modules/views/help/display-page.html b/sites/all/modules/views/help/display-page.html new file mode 100644 index 0000000..a23c3a0 --- /dev/null +++ b/sites/all/modules/views/help/display-page.html @@ -0,0 +1,5 @@ +Page displays have a path and an optional menu component. Page displays will be the primary content for the page, meaning they will be displayed in the main content area when you visit the URL that corresponds to the path. + +Page displays take their arguments from the URL. You can embed arguments into the URL using %; in previous versions of Views, this was '$arg'. For example, 'node/%/foo' will accept URLs such as 'node/1/foo'. + +Please remember that using a % placeholder makes the argument required. If you wish to have an optional argument, simply omit the % from the path. I.e. using "page/%" as the path requires an argument and visiting 'http://www.example.com/page' will not trigger the view. \ No newline at end of file diff --git a/sites/all/modules/views/help/display.html b/sites/all/modules/views/help/display.html new file mode 100644 index 0000000..836a324 --- /dev/null +++ b/sites/all/modules/views/help/display.html @@ -0,0 +1,7 @@ +Displays tell Views where the output should go. By adding a display to a View, you can have your view appear as a page, or as a block, or even as an attachment to a different display on the view. + +Each display can have its own settings, but when it's created, a display will take all of its basic settings from the default display which all Views must have. For most settings, there is an override button that will override that single setting for the current display. Overridden settings will have a mark in the summary for that display. All 'default display settings' are shown in the other displays 'italic'. When you override a setting, than it is shown 'normal'. + +Please keep in mind that when you are editing a setting on a display that is not overridden, then by default you are editing that for all displays. + +For fields, arguments, sorts, filters and relationships, you can only override all of them or none of them. To do this, click on the header for the filters or the rearrange button. Once you override, the display will then have its own copies of the fields/filters/etc and changes to the defaults will not be reflected on your display. \ No newline at end of file diff --git a/sites/all/modules/views/help/embed.html b/sites/all/modules/views/help/embed.html new file mode 100644 index 0000000..e39fbf5 --- /dev/null +++ b/sites/all/modules/views/help/embed.html @@ -0,0 +1,24 @@ +You can easily embed the results of a view into other parts of your site; +either with code as a module, or in nodes or blocks as snippets. The +easiest way is to use the function views_embed_view(): + +/** + * Embed a view using a PHP snippet. + * + * This function is meant to be called from PHP snippets, should one wish to + * embed a view in a node or something. It's meant to provide the simplest + * solution and doesn't really offer a lot of options, but breaking the function + * apart is pretty easy, and this provides a worthwhile guide to doing so. + * + * @param $name + * The name of the view to embed. + * @param $display_id + * The display id to embed. If unsure, use 'default', as it will always be + * valid. But things like 'page' or 'block' should work here. + * @param ... + * Any additional parameters will be passed as arguments. + */ +function views_embed_view($name, $display_id = 'default') { + + +To figure out the id of a display, hover your mouse over the tab to select that display. Everything after the '#views-tab-' is the id of that display. This ID is guaranteed never to change unless you delete the display and create a new one. diff --git a/sites/all/modules/views/help/example-author-block.html b/sites/all/modules/views/help/example-author-block.html new file mode 100644 index 0000000..c85e443 --- /dev/null +++ b/sites/all/modules/views/help/example-author-block.html @@ -0,0 +1,77 @@ +

In this example you will create a context-sensitive block that shows the titles of recent blog entries by an author when viewing one of their posts. This will demonstrate using Views arguments to dynamically filter a view's contents at display time.

+ +

Before working through this example, enable the Blog module and populate some entries from a few different users.

+ +

Creating the View

+

The first step is creating a view for our recent blog entries block. Because the block will show the titles of blog entries, this view is considered a "Node" type. Go to add new view, enter the following properties, and click Next:

+ +
+
View name
+
recent_blog_entries
+
View description
+
List of recent blog entries for a given author.
+
View tag
+
blog
+
View type
+
Node
+
+ +

Generating a list of blog entries

+

It will be much easier to see the view progress if we can see it doing something. In this section, we will create a basic view displaying blog entry titles.

+ +
    +
  1. In the third column, locate the Fields area. Generally speaking, fields are the pieces of information that you want to display in the view (in this case, node title). Click the + icon to add a field.
  2. +
  3. Scroll down to Defaults: Add fields, below the settings table. A large selection of fields will be available.
  4. +
  5. In the Groups drop-down menu, select Node. This will limit the list to only the default fields exposed by Node module.
  6. +
  7. Scroll down the list, select the Node: Title field, and click Add.
  8. +
  9. You will now be presented with settings for the Node: Title field. Delete the label from the Label field, so that each individual node title is not prefixed with the word "Title." Additionally, check the Link this field to its node box so that visitors who see an interesting title can click directly on it to read the blog entry to which it belongs.
  10. +
  11. When finished, click Update. If you scroll down to the Live Preview section, you should now see a list of several node titles; however both blog entries and other node types will be in the list. Let's fix that.
  12. +
  13. In the fourth column, locate the Filters area. Filters limit the results displayed in the view, and we can use this to our advantage here by showing node titles only from blog entries and not every type of node. Click the + icon to add a filter.
  14. +
  15. As before, scroll down to the Defaults: Add filters section, select Node from the Groups select box to limit the list of options to only those exposed by Node module.
  16. +
  17. Scroll down and select the Node: Type field and click Add. In the settings page that appears, leave Operator as Is one of and select Blog entry under Node type. Click Update when finished.
  18. +
  19. Now, by scrolling down to Live preview, you'll see that the list only shows blog entries.
  20. +
+ +

Adding context with arguments

+

While filters are very useful for limiting the results of a view when the condition is always consistent (for example, a view of blog entry nodes should always be filtered by the blog entry type), something filters can't do is smart decision-making based on the page context. In our case, we want the view to display a different list of blog entries when looking at a post by user 'admin' than we do when looking at a post by user 'member', and filters won't be able to help.

+ +

Luckily, there's another way to filter a view's content: arguments. Through arguments, Views are able to obtain additional context (typically via dynamic URLs with IDs in them) and can take this context into consideration when displaying the view.

+ +

Let's walk through adding and configuring an argument to our view so that we can change its contents based on post author.

+ +
    +
  1. In the third column, locate the Arguments area. Click the + icon to add an argument.
  2. +
  3. Because we are basing the view around content authors, this time under Groups select User. Check User: Uid and click Add.
  4. +
  5. The Defaults: Configure Argument User: Uid settings page has a lot going on, but only a few things that need our attention.
  6. +
  7. The Title field here, unlike the Title field under Basic Settings, can be based upon the context that the view is being displayed in. Change the title to 'Recent entries by %1.' %1 will later be expanded to the user's name (based on the User: Uid argument) when the view is displayed.
  8. +
  9. Under Action to take if argument is not present, there are a variety of options, ranging from displaying a 404 or a 403 page to simply displaying all values in the view. In our case, if an argument isn't specified (which it won't be, since this view will be displayed in a sidebar block, not as a page with its own URL), we want to give it a default one to act on. Select Provide default argument.
  10. +
  11. Assuming JavaScript is enabled in your browser, you should now get another selection for Default argument type. Select User ID from URL, which will then provide a new option, Also look for a node and use the node author. Select it. This will cause Views to first see if it can figure out a user ID from the current URL (for example, user/1). If it can't, it will instead check to see if the current page is a node page (such as node/42) and, if so, take the user ID from the node's author field instead.
  12. +
  13. Validator options provide a useful way to control what kind of arguments your view will accept. Select User as the Validator. By default, changing this setting will check the incoming argument and ensure it's a valid user ID; if not, the view will be hidden from the page.
  14. +
  15. Once you have changed the argument's title, default argument, and validator options, click Update to save your changes.
  16. +
  17. You'll notice that now the Live preview no longer shows anything. Did we just break the view? Fortunately, no. It's merely abiding by our wishes to hide itself if there is no valid user ID given to it. Try entering a '1' in the Arguments box and clicking Preview. You should now see a list of only user 1's blog entries.
  18. +
+ +

Creating the block

+

So the live preview is now showing basically what we want. There's just one problem: we have no way to stick what we've done so far into a sidebar block! Let's fix that by adding a new Display.

+ +
    +
  1. In the first column, under Defaults, there is a select box containing entries such as Page, Feed, and, yes, Block! Select Block and click Add display.
  2. +
  3. There's not much else to do here as far as Views is concerned. Under Block settings, click the None link next to Admin and fill in a description for the block in the administrative interface, such as: 'Recent blog entries by author.' and click Update.
  4. +
  5. Save your work by clicking the Save button at the bottom of the Views interface. You should receive a message that the view has been saved.
  6. +
  7. Next, navigate to the blocks interface and drag the 'Recent blog entries by author' block to the right sidebar region (or similar) and click Save blocks.
  8. +
  9. You'll notice this appeared to do nothing. No block shows in the sidebar. But remember, we are looking at an adminitrative page; we are not looking at a page that would provide a user ID context. Navigate to the main blog listing and click on an entry there. You should now see a sidebar block, titled something like "Recent entries by admin," with a list of blog entries beneath it.
  10. +
+ +

Finishing touches

+

There are still a few remaining things to do before our view is complete. For example, we said that the block was to show recent blog entries, but instead it's showing them in the order they were entered, with oldest on top. Additionally, even unpublished entries are showing in the list currently.

+ +
    +
  1. Return to the recent_blog_entries view edit page.
  2. +
  3. Add an additional filter by clicking the + icon in the Filters section in the fourth column.
  4. +
  5. Change Groups to Node and select Node: Published. Click Add.
  6. +
  7. Under the Published selection, choose Yes and click Update.
  8. +
  9. To handle sorting, locate the Sort criteria area, just above filters, and click the + icon there.
  10. +
  11. Under Groups, again select Node. From the list of options, check Node: Post date and click Add.
  12. +
  13. In the settings page, change Sort order to Descending. This will place the newer posts on top of the older ones. Click Update when finished.
  14. +
  15. Finally, Save the view for your new settings to take effect.
  16. +
diff --git a/sites/all/modules/views/help/example-recent-stories.html b/sites/all/modules/views/help/example-recent-stories.html new file mode 100644 index 0000000..ef8dd6a --- /dev/null +++ b/sites/all/modules/views/help/example-recent-stories.html @@ -0,0 +1,57 @@ +In this example you will create a list of nodes of the content type "story", to be shown in a block. Through this step-by-step process, you will become familiar with some basic steps in creating a view, and familiarize yourself with the Views User Interface. + +
    +
  1. Creating a new view

    +

    Go to add new view. Give your new view the name 'recent_stories', description 'Recent Stories', tag 'story', type 'Node' and click Next.

  2. +
  3. About the interface

    +

    You have been brought to Views User Interface. As you start, you are editing the "Default" options for the view. In the 1st column on the left you can see the drop-down menu offers 'block', for example, to select settings specific only to block views. In the remaining columns, you will be able to add or change options by clicking on links or icons. These options will then appear below this main area. Most likely, you will need to scroll a bit to see the options appear.

  4. +
  5. Selecting the fields to display

    +
      +
    1. In 3rd column locate the Fields options. Click the + icon to add fields.
    2. +
    3. Scroll down to Defaults: Add fields. In the Groups drop-down menu select 'Node', then check the following two fields: Node: Post date, Node: Title. Then click Add.
    4. +
    5. You will be taken through the fields you added one at a time. Make the changes specified below. +
        +
      • For the Post date field: Delete the 'Post date' label. Change the Date format to Custom, and the Custom date format to 'F j, Y, g:i a' (do not type the single quotes; for the meaning of these letter codes, click on the PHP docs link under that box to arrive at the explanation). Click Update.
      • +
      • For the Title field: Delete the 'Title' label. Select Link this field to its node. Click Update.
      • +
      +
    6. +
    7. Scroll back up to Fields and click the ↑↓ icon to rearrange fields.
    8. +
    9. Drag the four-sided arrow next to Node: Title so that it appears above Node: Post date. Click Update to save the new field order.
    10. +
    +
  6. +
  7. Filtering to story nodes only

    +
      +
    1. Click the + icon next to Filters.
    2. +
    3. In the Groups drop-down menu select 'Node', then check the Node: Published and Node: Type filters, and click Add.
    4. +
    5. Select the Published checkbox. Click Update
    6. +
    7. Select Is one of and check Story in the Node Type field. Click Update.
    8. +
    +
  8. +
  9. Sorting to show most recent first

    +
      +
    1. Scroll up to Sort criteria and click the + icon.
    2. +
    3. In the Groups drop-down menu below, select 'Node', then check Node: Post date, and click Add. Alternatively, you may instead check Node: Last comment time, or Node: Updated/commented date, or Node: Updated date.
    4. +
    5. Select Descending Sort order. Click Update.
    6. +
    +
  10. +
  11. Refining the basic settings

    +
      +
    • In 1st column under Basic settings locate these options: +
        +
      • Items to Display setting, click 10. Change the '10' to '4'. Click Update
      • +
      • Style setting, click Unformatted. Change to List. Click Update.
      • +
      +
    • +
    +
  12. +
  13. Adding a block display for custom options

    +
      +
    1. In the dropdown on the left, ensure that Block is selected, and click Add Display.
    2. +
    3. Under Block settings, click the None link next to the Admin setting. Change Block: Block admin description to 'Recent Stories'.
    4. +
    +
  14. +
  15. Saving the view

    +

    Click Save to save your work.

  16. +
  17. Instructing Drupal to show the block

    +

    Finally, you should tell Drupal to show this block. Configure your block by going to admin/build/block. Locate the block in the list: it is labeled Recent Stories. Place this block in a region and click Save. You may click Configure to set a different title, to determine which roles can view the block, and on which pages it appears; If you want your block on the front page only, enter '<front>'.

  18. +
diff --git a/sites/all/modules/views/help/example-user-feed.html b/sites/all/modules/views/help/example-user-feed.html new file mode 100644 index 0000000..613bd91 --- /dev/null +++ b/sites/all/modules/views/help/example-user-feed.html @@ -0,0 +1,73 @@ +

In this example you will create a Feed display to show nodes by individual users, dynamically selected through the URL. You will become familiar with the Views 2 interface, as well as learn how to use an argument to pull in a user name and use it in a dynamically created path.

+

A feed is a data format that places your site's content into a file that can be read and displayed by news reader programs. When visiting a site, you may notice a small RSS transmission icon, whereby clicking on it, you can subscribe to the site's most recent content. This makes it easier for your visitors to keep up to date with your website. You can also use this format to aggregate information into other sites. For more information, please watch a video from Common Craft about RSS in plain English.

+

Note, Drupal automatically creates a feed for your website, but you may want to create feeds with specific information. In this case, a list per user.

+
    +
  1. +

    Creating a new view

    +
      +
    1. Go to add new view. Give it the name 'user_feed', description 'A feed of user nodes.', tag 'users', type 'Node' and click Next.
    2. +
    +
  2. +
  3. About the Interface. You have been brought to the Views User Interface. As you start, you are editing the "Default" options for the view. In the 1st column on the left- you can see the pull-down menu offers 'Feed', for example, to select settings specific only to RSS views. In the remaining columns, you will be able to add or change options by clicking on links or icons. These options appear below this main area. Most likely, you will need to scroll to see the options appear. As you make changes, these options will appear in bold until you save your view.
  4. +
  5. +

    Change default display

    +
      +
    1. Under Basic Settings in the 2nd column, click Row style: Fields
    2. +
    3. A menu loads below, Defaults: How should each row in this view be styled, check the Node option, and click Update.
    4. +
    5. This loads another options menu, Defaults: Row style options click Update.
    6. +
    +
  6. +
  7. +

    Create the RSS view

    +
      +
    1. In the 1st column, select 'Feed' in the drop-down menu, and click Add Display.
    2. +
    3. Under Basic Settings in the 2nd column, click Row style:Missing style plugin
    4. +
    5. Note, options appear below the Views Interface, you may need to scroll to see Feed: How should each row in this view be styled
      + tick Node, then Update
    6. +
    7. This loads the next options menu- Display type: select "Use default RSS settings", click Update.
    8. +
    +
  8. +
  9. +

    Set the path for accessing your feed

    +
      +
    1. In the 2nd column under Feed settings, click Path: None
    2. +
    3. In options below Feed: The menu path or URL of this view enter in the path with an argument feeds/%/rss.xml
    4. +
    5. Click Update
    6. +
    +
  10. +
  11. +

    Set up your arguments to say which user's nodes to display

    +
      +
    1. To the right of Arguments, click the + sign to add and argument
    2. +
    3. In the Feed: Add arguments menu that loads below, select User in the pull-down menu
    4. +
    5. Check the box User: Name, click Add
    6. +
    7. Scroll down to options to find Case in path: select Lower case
    8. +
    9. Check the box Transform spaces to dashes in URL
    10. +
    11. Click Update default display
    12. +
    +
  12. +
  13. +

    Sort to show most recent at top of feed

    +
      +
    1. Scroll up to Sort criteria in the right most column and click the + icon.
    2. +
    3. In the Groups drop-down menu below, select 'Node', then check Node: Post date, and click Add.
    4. +
    5. Select Descending Sort order. Click Update.
    6. +
    +
  14. +
  15. +

    Set filters to hide unpublished entries

    +
      +
    1. Click the + icon next to Filters. In the options below, select Node under Groups drop-down menu, choose the Node: Published filter, and click Add.
    2. +
    3. Check the box Published. Click Update default display
    4. +
    +
  16. +
  17. +

    Test

    +
      +
    1. Click Save
    2. +
    3. Under Live preview type in the name of a user, in lowercase, replacing spaces with dashes, click Preview.
    4. +
    5. You should test and find your feeds at URLs like http://yoursite.com/feeds/user-name/rss.xml
    6. +
    7. You can use this path for aggregating on another site. You can also attach the RSS feed to another display of view to make the feed link appear on that display.
    8. +
    +
  18. +
\ No newline at end of file diff --git a/sites/all/modules/views/help/example-users-by-role.html b/sites/all/modules/views/help/example-users-by-role.html new file mode 100644 index 0000000..ae9e1c6 --- /dev/null +++ b/sites/all/modules/views/help/example-users-by-role.html @@ -0,0 +1,47 @@ +In this example you will create a page view listing users on your site. Through this step-by-step process, you will become familiar with some basic steps in creating a view, and familiarize yourself with the Views User Interface. + +
    +
  1. Creating a new view

    +

    Go to add new view. Give your new view the name 'user_list', description 'A simple user listing.', tag 'users', type 'User' and click Next.

  2. +
  3. About the Interface

    +

    You have been brought to the Views User Interface. As you start, you are editing the "Default" options for the view. In the 1st column on the left you can see the drop-down menu offers 'block', for example, to select settings specific only to block views. In the remaining columns, you will be able to add or change options by clicking on links or icons. These options will then appear below this main area. Most likely, you will need to scroll to see the options appear. As you make changes, these options will appear in bold until you save your view.

  4. +
  5. Creating a page display; choosing a URL and creating a menu link

    +
      +
    1. In the 1st column, ensure that 'Page' is selected in the drop-down menu, and click Add Display.
    2. +
    3. Next we'll define the path for this page. A page must have a path, and we define it early so that Views doesn't warn us "Display Page uses path but path is undefined." Locate the Page settings in the 2nd column, and click the None link next to the Path setting. In the options editing area that appears below, set the path to 'user_list' (or something else if you prefer) and click Update.
    4. +
    5. Next to Menu setting, Click the No menu link. In the options which appear below, select Normal menu entry, and set the title to 'User list' and click Update.
    6. +
    7. Scroll up to Basic settings, in that same 2nd column, and click the No link next to Use pager. Below, in the options, select Full pager and click Update default display.
    8. +
    +
  6. +
  7. Selecting the fields to display

    +
      +
    1. In 3rd column locate the Fields options. Click the + icon to add fields.
    2. +
    3. Scroll down to Defaults: Add fields. In the Groups drop-down menu select 'User', then check the following fields: User: Created date, User: Delete link, User: Edit link, User: Last access, User: Name and User: Picture. Then click Add.
    4. +
    5. You will be taken through the fields you added one at a time. Click Update default display to go to each next field. Leave the default options on all fields except Delete link; change that field's label to 'Operations'.
    6. +
    7. Scroll back up to Fields and click the ↑↓ icon to rearrange fields. Down below, drag the Name field, by dragging its four-sided arrow, to the top. Drag the Delete link (Operations) field to the bottom, and the Edit link field just above it. Then click Update.
    8. +
    +
  8. +
  9. Seeing what we've done so far

    +

    At this point, you have done enough to create a valid view. If you scroll down, you will see a preview of your view. If it doesn't show already, click the Preview button; but generally this display updates automatically whenever you finish working in one of the mini forms.

  10. +
  11. Styling the view as a table; combining related fields into columns

    +
      +
    1. Under Basic settings, in the 1st column, click the Unformatted link next to the Style setting. In the options below, under Page: How should this view be styled, choose Table and click Update default display.
    2. +
    3. You will be taken to a Page: Style options form to edit the table settings. Locate our Edit link field in this mini form, and notice the Column drop-down. Change this drop-down to show Operations. In the Separator column next to the Operations field, type ' | ' (note the spaces around the | symbol). Check all of the Sortable checkboxes, and set Default sort to Name. When finished, click Update default display.
    4. +
    +
  12. +
  13. Filtering the user list to exclude unwanted entries

    +
      +
    1. Click the + icon next to Filters.
    2. +
    3. In the Groups drop-down menu select 'User', then check the User: Name filter, and click Add.
    4. +
    5. Select Is not one of and enter 'Anonymous' in the Usernames box. Click Update default display.
    6. +
    +
  14. +
  15. Adding an argument to list users by role dynamically

    +
      +
    1. Scroll up to Arguments, and click its + icon.
    2. +
    3. Check the User: Roles argument, and click Add. Set the title to '%1' (don't type the quotes), and under Action to take if argument is not present select Summary, sorted ascending. Leave the other settings as they are. Click Update default display, and click Update through the prompts that follow to accept their default values.
    4. +
    +
  16. +
  17. Saving the view

    +

    Finally, click the Save button to save your work. At the very top, click View "Page" to go to your new view!

  18. +
diff --git a/sites/all/modules/views/help/field.html b/sites/all/modules/views/help/field.html new file mode 100644 index 0000000..e563176 --- /dev/null +++ b/sites/all/modules/views/help/field.html @@ -0,0 +1,5 @@ +Fields are the individual pieces of data being displayed. Adding the fields Node: Title, Node: Type, and Node: Post date to a node view, for example, includes the title, content type and creation date in the displayed results). + +Fields may not appear on every display, because not all style plugins actually use fields. For example, the 'node' row plugin simply displays the node through Drupal's normal mechanisms, and fields are not involved. + +For the most part, the field settings should be self explanatory. Fields will appear in the order that they are arranged in, and they will usually appear with the label they are given. \ No newline at end of file diff --git a/sites/all/modules/views/help/filter.html b/sites/all/modules/views/help/filter.html new file mode 100644 index 0000000..b4cb5a0 --- /dev/null +++ b/sites/all/modules/views/help/filter.html @@ -0,0 +1,12 @@ +Filters are used to reduce the data set that Views provides. That is to say, without any filters applied, Views will return all of your content. You don't want that, so at least some filters must be used. + +Some very commonly used filters: +
    +
  • The 'Node: Published' filter is used to restrict a node View to only nodes that are are have the 'published' box checked. This can be very important to prevent users from viewing content they should not have access to.
  • +
  • The 'Node: Promoted to front page' filter can be used to show only nodes that have the 'promote to front page' turned on.
  • +
  • The 'Node: Type' filter is useful for showing only certain types of nodes. Let's say you wanted users to see only nodes that were 'book' nodes, or a combination of 'book' nodes and 'staff-blog' nodes. This filter allows you to select exactly that.
  • +
  • The 'User: Current' filter will show only nodes that the logged in user has authored.
  • +
  • The 'Node: Post date' filter can be used to show only nodes posted before, after, or between a range of dates.
  • +
+ +The above list is only a tiny fraction of the filters available in Views, referenced here to give an idea of the kinds of tasks filters can accomplish. diff --git a/sites/all/modules/views/help/getting-started.html b/sites/all/modules/views/help/getting-started.html new file mode 100644 index 0000000..eb28c46 --- /dev/null +++ b/sites/all/modules/views/help/getting-started.html @@ -0,0 +1,26 @@ +Module Developers: +The Views' API help pages can be found here. + +New Users: +For those new to Views, it can be a complex system that appears totally overwhelming. The good news is that the UI is designed to compartmentalize everything; this means that for the most part, you can ignore the parts you're not interested in. Start small and build your way up. + +Because of this, the edit UI can seem overwhelming at first, but there are really just a few things you have to know. The rest you can find through exploration. The Views Edit UI image, below, gives an overview of what you'll find on the edit UI. + +
+ +The Views Edit UI +
+ +Notes: +1) Every view has a number of displays which represent where output will be placed. If you're familiar with the original Views 1, you could set a view to be a 'page', with a URL (path), or a block that could show up in a sidebar. With Views 2, you can add as many displays as you like. In addition, you have the default display which contains the basic settings, but doesn't actually show up anywhere. + +2) When you click on the link for an item, a form will open up. For browsers with smaller resolutions, you may have to scroll down a little to see this form. If a form is open, the item its attached to will be highlighted. + +3) Overrides mean that a particular display is not using default settings. When you create a new display, many of its settings will start off using default values. This will be indicated by italics and a lighter color. If you change these values without first overriding them, you will change the default value for all displays that use them. + +4) Some items, particularly styles, have additional settings. Ordinarily when you update a style, if it has additional settings you will automatically see that form next. Often, you will need to go directly to those settings. + +5) You can safely leave a view page to go and do other things. If you come back, the view will still be there, stored in a cache. Keep in mind, however, that while you do this, that view is locked, meaning another user cannot edit this view without breaking the lock. Breaking the lock will discard your changes. + +It helps to have something particular in mind that you want to accomplish when using Views. Here are a couple of ideas and a brief sketch of how to accomplish what you want. + diff --git a/sites/all/modules/views/help/images/node-term_node-term_data-large.png b/sites/all/modules/views/help/images/node-term_node-term_data-large.png new file mode 100644 index 0000000..4fcd191 Binary files /dev/null and b/sites/all/modules/views/help/images/node-term_node-term_data-large.png differ diff --git a/sites/all/modules/views/help/images/node-term_node-term_data.png b/sites/all/modules/views/help/images/node-term_node-term_data.png new file mode 100644 index 0000000..de1273c Binary files /dev/null and b/sites/all/modules/views/help/images/node-term_node-term_data.png differ diff --git a/sites/all/modules/views/help/images/overview-ui-large.png b/sites/all/modules/views/help/images/overview-ui-large.png new file mode 100644 index 0000000..04fbe90 Binary files /dev/null and b/sites/all/modules/views/help/images/overview-ui-large.png differ diff --git a/sites/all/modules/views/help/images/overview-ui-small.png b/sites/all/modules/views/help/images/overview-ui-small.png new file mode 100644 index 0000000..ed7595f Binary files /dev/null and b/sites/all/modules/views/help/images/overview-ui-small.png differ diff --git a/sites/all/modules/views/help/images/style-breakdown-large.png b/sites/all/modules/views/help/images/style-breakdown-large.png new file mode 100644 index 0000000..698b8cc Binary files /dev/null and b/sites/all/modules/views/help/images/style-breakdown-large.png differ diff --git a/sites/all/modules/views/help/images/style-breakdown.png b/sites/all/modules/views/help/images/style-breakdown.png new file mode 100644 index 0000000..d7513a8 Binary files /dev/null and b/sites/all/modules/views/help/images/style-breakdown.png differ diff --git a/sites/all/modules/views/help/images/views1-admin-large.png b/sites/all/modules/views/help/images/views1-admin-large.png new file mode 100644 index 0000000..06744bd Binary files /dev/null and b/sites/all/modules/views/help/images/views1-admin-large.png differ diff --git a/sites/all/modules/views/help/images/views1-admin.png b/sites/all/modules/views/help/images/views1-admin.png new file mode 100644 index 0000000..398c145 Binary files /dev/null and b/sites/all/modules/views/help/images/views1-admin.png differ diff --git a/sites/all/modules/views/help/images/views1-changeviewtype-large.png b/sites/all/modules/views/help/images/views1-changeviewtype-large.png new file mode 100644 index 0000000..5c58d81 Binary files /dev/null and b/sites/all/modules/views/help/images/views1-changeviewtype-large.png differ diff --git a/sites/all/modules/views/help/images/views1-changeviewtype.png b/sites/all/modules/views/help/images/views1-changeviewtype.png new file mode 100644 index 0000000..6b1798a Binary files /dev/null and b/sites/all/modules/views/help/images/views1-changeviewtype.png differ diff --git a/sites/all/modules/views/help/images/views2-addaview-large.png b/sites/all/modules/views/help/images/views2-addaview-large.png new file mode 100644 index 0000000..bbad1b1 Binary files /dev/null and b/sites/all/modules/views/help/images/views2-addaview-large.png differ diff --git a/sites/all/modules/views/help/images/views2-addaview.png b/sites/all/modules/views/help/images/views2-addaview.png new file mode 100644 index 0000000..546ea16 Binary files /dev/null and b/sites/all/modules/views/help/images/views2-addaview.png differ diff --git a/sites/all/modules/views/help/images/views2-adddisplay-large.png b/sites/all/modules/views/help/images/views2-adddisplay-large.png new file mode 100644 index 0000000..51c3675 Binary files /dev/null and b/sites/all/modules/views/help/images/views2-adddisplay-large.png differ diff --git a/sites/all/modules/views/help/images/views2-adddisplay.png b/sites/all/modules/views/help/images/views2-adddisplay.png new file mode 100644 index 0000000..dff143e Binary files /dev/null and b/sites/all/modules/views/help/images/views2-adddisplay.png differ diff --git a/sites/all/modules/views/help/images/views2-addfields-large.png b/sites/all/modules/views/help/images/views2-addfields-large.png new file mode 100644 index 0000000..b7c1ba5 Binary files /dev/null and b/sites/all/modules/views/help/images/views2-addfields-large.png differ diff --git a/sites/all/modules/views/help/images/views2-addfields.png b/sites/all/modules/views/help/images/views2-addfields.png new file mode 100644 index 0000000..e70c758 Binary files /dev/null and b/sites/all/modules/views/help/images/views2-addfields.png differ diff --git a/sites/all/modules/views/help/images/views2-addfieldsajax-large.png b/sites/all/modules/views/help/images/views2-addfieldsajax-large.png new file mode 100644 index 0000000..a9308a0 Binary files /dev/null and b/sites/all/modules/views/help/images/views2-addfieldsajax-large.png differ diff --git a/sites/all/modules/views/help/images/views2-addfieldsajax.png b/sites/all/modules/views/help/images/views2-addfieldsajax.png new file mode 100644 index 0000000..3043d04 Binary files /dev/null and b/sites/all/modules/views/help/images/views2-addfieldsajax.png differ diff --git a/sites/all/modules/views/help/images/views2-admin-large.png b/sites/all/modules/views/help/images/views2-admin-large.png new file mode 100644 index 0000000..d262bc5 Binary files /dev/null and b/sites/all/modules/views/help/images/views2-admin-large.png differ diff --git a/sites/all/modules/views/help/images/views2-admin.png b/sites/all/modules/views/help/images/views2-admin.png new file mode 100644 index 0000000..c273363 Binary files /dev/null and b/sites/all/modules/views/help/images/views2-admin.png differ diff --git a/sites/all/modules/views/help/images/views2-changedisplaystyle-large.png b/sites/all/modules/views/help/images/views2-changedisplaystyle-large.png new file mode 100644 index 0000000..09925df Binary files /dev/null and b/sites/all/modules/views/help/images/views2-changedisplaystyle-large.png differ diff --git a/sites/all/modules/views/help/images/views2-changedisplaystyle.png b/sites/all/modules/views/help/images/views2-changedisplaystyle.png new file mode 100644 index 0000000..5a82ea5 Binary files /dev/null and b/sites/all/modules/views/help/images/views2-changedisplaystyle.png differ diff --git a/sites/all/modules/views/help/images/views2-fieldspreview-large.png b/sites/all/modules/views/help/images/views2-fieldspreview-large.png new file mode 100644 index 0000000..e2730b4 Binary files /dev/null and b/sites/all/modules/views/help/images/views2-fieldspreview-large.png differ diff --git a/sites/all/modules/views/help/images/views2-fieldspreview.png b/sites/all/modules/views/help/images/views2-fieldspreview.png new file mode 100644 index 0000000..5a41ab2 Binary files /dev/null and b/sites/all/modules/views/help/images/views2-fieldspreview.png differ diff --git a/sites/all/modules/views/help/images/views2-newview-large.png b/sites/all/modules/views/help/images/views2-newview-large.png new file mode 100644 index 0000000..498627a Binary files /dev/null and b/sites/all/modules/views/help/images/views2-newview-large.png differ diff --git a/sites/all/modules/views/help/images/views2-newview.png b/sites/all/modules/views/help/images/views2-newview.png new file mode 100644 index 0000000..b522d2c Binary files /dev/null and b/sites/all/modules/views/help/images/views2-newview.png differ diff --git a/sites/all/modules/views/help/images/views2-rearrangefields-large.png b/sites/all/modules/views/help/images/views2-rearrangefields-large.png new file mode 100644 index 0000000..acfed4c Binary files /dev/null and b/sites/all/modules/views/help/images/views2-rearrangefields-large.png differ diff --git a/sites/all/modules/views/help/images/views2-rearrangefields.png b/sites/all/modules/views/help/images/views2-rearrangefields.png new file mode 100644 index 0000000..562df08 Binary files /dev/null and b/sites/all/modules/views/help/images/views2-rearrangefields.png differ diff --git a/sites/all/modules/views/help/images/views2-tablestyle-large.png b/sites/all/modules/views/help/images/views2-tablestyle-large.png new file mode 100644 index 0000000..67e9e6b Binary files /dev/null and b/sites/all/modules/views/help/images/views2-tablestyle-large.png differ diff --git a/sites/all/modules/views/help/images/views2-tablestyle.png b/sites/all/modules/views/help/images/views2-tablestyle.png new file mode 100644 index 0000000..f899740 Binary files /dev/null and b/sites/all/modules/views/help/images/views2-tablestyle.png differ diff --git a/sites/all/modules/views/help/menu.html b/sites/all/modules/views/help/menu.html new file mode 100644 index 0000000..9fd34b5 --- /dev/null +++ b/sites/all/modules/views/help/menu.html @@ -0,0 +1,21 @@ +Page displays can hook into the Drupal menu system and provide menu links that will appear in the Navigation system as well as tabs that can be used to keep Views next to each other. + +For simple menu links, there is very little you need to do; simply select 'Normal menu entry' and fill in the text for the title. This will appear in the Navigation menu by default; you will need to visit the menu administration page to move this to another menu. + +Tabs are not quite so simple; there are some complex rules for using tabs in Drupal. +
    +
  1. All tabs must have a parent, which is the next level up in the path hierarchy. For example, if the view path is 'example/taba' then the parent must be 'example'. +
  2. All tabs must have one and only one default tab; this is usually the same content as the parent. +
  3. If a parent does not exist, when creating the 'default' tab, Views will allow you to also create a parent item. It will automatically set up the URL for you when it does this. +
  4. Tab weight is used to control what order the tabs are displayed in. Lower numbers will display more to the left. For tabs whose numbers are the same, they will be displayed alphabetically. +
  5. Drupal only supports 2 levels of tabs, so be careful about trying to put tabs within tabs within tabs. That won't work. +
+ +For example, if you have two views that you want to be tabs, you could set it up like this: +
    +
  • In the first view, set the path to 'tabs/tab1'. Set it to be the 'default tab', set the title to 'Tab 1' and the weight to 0. +
  • Click update and you will be taken to a form that lets you define the parent. Since 'tabs' doesn't already exist in the system, select 'Normal menu item', and set the title to 'Tabs'. +
  • On the second view, set the path to 'tabs/tab2'; set it to be a 'Menu tab', and set the title to 'Tab 2'. +
+ +With this done, you will now have a Navigation link named 'Tabs' and when you click on it, you will go to the tabs, with 'Tab 1' being the default tab that appears. You can then click between Tab 1 and Tab 2. diff --git a/sites/all/modules/views/help/new.html b/sites/all/modules/views/help/new.html new file mode 100644 index 0000000..f33bb8f --- /dev/null +++ b/sites/all/modules/views/help/new.html @@ -0,0 +1,113 @@ +Views 2 is the newest major release of Views and it is specifically coded for Drupal 6. Views 2 retains all of the core functionality of Views 1, together with a completely revamped user interface and a large set of new features which greatly expand upon the original feature-set of Views 1. This document is a side-by-side comparison of Views 1 versus Views 2 from a user's perspective, detailing the UI changes, some new ways to perform old tasks, the cool new features of Views 2 and how these features can be used to address some of the shortcomings of Views 1. + +

Admin interface

+The first thing that pops out after you install Views 2 is the radically different admin interface: +
+ +Views 2 admin interface +
+ +compared to the old comfy Views 1 interface: + +
+ +Views 1 admin interface +
+ +The new admin interface performs the same functions as the old -- listing all the views in the system, providing links to add or import views and a link to Views Tools -- but has been compacted, with each view displayed as a paragraph style-row compared to the table of Views 1 and set of filters on top to ease locating views among a large list. + +Context-help is available by clicking the small blue question-mark icon. Context-help in Views 2 is provided by the Advanced Help module, so make sure to install that together with installing Views 2. The small blue help icons will be available in various parts of the Views UI. In particular, look for them as part of the description of a display, when setting style options, and in various editing sections such as path, menu and the like. + +Several new attributes of each view are visible in the filter header: +
    +
  1. Tag - This is just another label for organizing and sorting views. Tags can be any text. Views that are provided by modules will often be tagged together to make it easy to find them. Tags are also added to your template suggestions, so take care what you set here. For example setting the tag Page will give all your views the Page template.
  2. +
  3. Display - In Views 1 each view query was tied to its display; in other words your fields, sorts, filters, and arguments could only be displayed in the single page or block display provided in the view definition. In Views 2, view displays have been decoupled from view queries - it is now possible to have multiple page, block, and feed displays from a single view. More on view displays later.
  4. +
  5. Type - Views 2 view types are radically different from Views 1 types. Views 1 types basically defined how the node list displays were styled - you had Full Nodes, Teaser List, Table View, and so on. In Views 2 view display styles have been broken out into the separate Style attribute. View types now refer to the primary table on which information for the query will be retrieved which controls what arguments, fields, sort criteria and filters are available. Views 2 view types are discussed later. +
  6. +
+ +

Adding a view

+So let's jump in and add a view. For this example, we're going to create a user view, which will display a list of users. +
+ +Adding a view +
+ +The first step in adding a view is simply entering a name (only alphanumeric characters, no spaces) a description, tag, and the view type. To get the user view, we selected the User radio button. + +
+ +Configuring the new view +
+ +This might be the 2nd whoa moment as the interface here is also completely revamped from Views 1.x. The best way to summarize is to say all the pieces from the Views 1.x interface are still there...just in different places. Fields, arguments, sort critera and filters are all still there there, just in new AJAXY-flavours. + +Let's start by adding some fields: + +
+ +Adding fields +
+ +Clicking on the [+] icon next to the word Fields unfurls a section beneath the view information with all the available fields grouped by Comment, File, Node, Node revision, Taxonomy and User, and probably a few others. This is a general paradigm for the Views 2 interface -- clicking on a widget or link unfurls a section beneath the view information with the relevant interface. Usually, what is being edited will be hilited in yellow, as well. + +When adding items, you can use the Groups drop-down box to show only a subset of the fields available according to the above groups, or select All to see all fields available, which is what was selected when the section unfurled. For our example, we're selecting the 'User' group and adding the User: E-mail, User: Name and User: Picture fields. + +
+ +Adding fields +
+ +Once we add our fields they show up in the Fields section of the interface. We will be walked through each field we added, so keep clicking update, even if you don't make changes to the field and you will see the next one. + +The fields we added can be rearranged by clicking the up/down icon, right next to the add icon we used earlier. We can also remove a field using the same interface. + +
+ +Rearranging fields +
+ +From here, the fields can be dragged up and down by grabbing the little drag handle on the left and moving them where you like. Making a change to any part of the view by clicking update usually triggers a refresh of the view preview which is conveniently located right below the main interface. + +
+ +Views preview +
+ +Now that we have some fields set up we can turn our attention to Basic Settings for the view. + +It's important to note that all the interface elements pertain to the current Display selected for the view. As mentioned before a view can have multiple displays. The first time you create a view you'll be manipulating the Default display. You can add displays using the Add Display button, whose Basic Settings are completely different from each other; this lets you have as many displays of a view as you would like all sharing items such as Sort Criteria, Filters and Arguments but different display settings like Title, Style, Fields, and Pager settings. Also, any display you add automatically inherits display settings from the default display initially, so you can keep a core of common settings in your default display and add additional settings for every other display. + +
+ +Adding a Page display +
+Let's stick with the Default display and twiddle some settings. We can set the Title to "User View 1" and the Style to Table. As mentioned earlier, view styles in Views 2 correspond more to view types in Views 1 (remember, List, Table, Teasers, Full nodes). + +
+ +Selecting a Views 1 View Type +
+ +In Views 2, view styles control how a view display looks. These styles are significantly different from the Types in Views 1; in particular, types have been 'broken up'; there is now the style as well as the row style which focus on different parts of the output. + +
+ +A breakdown of View output +
+ +We change the style by clicking on the current style on the left hand side of the View information area. + +
+ +Selecting a Views 2 Display Style +
+ +We're given the style options of Grid, List, Table and Unformatted. Additional display styles can be added by modules which have Views style plugins. Choosing a style reveals a "settings" button which you can click to configure the style you've chosen. In the shot below we've selected and are configuring the Table style, which we're using to produce a more compact output than we had earlier. + +
+ +Selecting and configuring the table style +
+ +... TODO: Finish this document ... diff --git a/sites/all/modules/views/help/overrides.html b/sites/all/modules/views/help/overrides.html new file mode 100644 index 0000000..c6ff531 --- /dev/null +++ b/sites/all/modules/views/help/overrides.html @@ -0,0 +1,6 @@ + +If an item is using defaults then it is using values from the default display. IMPORTANT NOTE: If you modify this value, you are modifying the default display and thus modifying for all displays that are using default values. + +If that is not what you intend, you must click the override button. Once overridden, that display now has its own version of the value; modifying it will not modify it for other displays. + +For Relationships, arguments, fields, sort criteria, and filters, each of these must be overridden as a group! In other words, you cannot override a single filter, but instead must override all filters. A message will appear on the item to let you know what its status is, but you can only change the status by clicking on the header or the rearrange button for that item. diff --git a/sites/all/modules/views/help/path.html b/sites/all/modules/views/help/path.html new file mode 100644 index 0000000..142534c --- /dev/null +++ b/sites/all/modules/views/help/path.html @@ -0,0 +1,7 @@ +If a display has a path that means that it can be retrieved directly by calling a URL as a first class page on your Drupal site. Any items after the path will be passed into the view as arguments. For example, if the path is foo/bar and a user visits http://www.example.com/foo/bar/baz/beta, 'baz' and 'beta' will be given as arguments to the view. These can be handled by adding items to the arguments section. + +You may also use placeholders in your path to represent arguments that come in the middle. For example, the path node/%/someview would expect the first argument to be the second part of the path. For example, node/21/someview would have an argument of '21'. + +Note: Views 1 used $arg for this kind of thing. $arg is no longer allowed as part of the path. You must use % instead. + +If multiple displays within the same view have the same path, the user will get the first display they have access to. This means you can create successfuly less restricted displays in order to give administrators and privileged users different content at the same path. \ No newline at end of file diff --git a/sites/all/modules/views/help/relationship.html b/sites/all/modules/views/help/relationship.html new file mode 100644 index 0000000..0f89184 --- /dev/null +++ b/sites/all/modules/views/help/relationship.html @@ -0,0 +1,13 @@ +Relationships allow you to expand the query to include objects other than the base query. This is actually made more difficult to understand by the fact that Views actually includes a few relationships by default, and doesn't tell you they're there. For historical reasons, it would be inconvenient to remove these default relationships. When relationships are present, all fields (including relationships) will gain a new form item to let you select which relationship they will use. They will default to using no relationship at all. + +The main example of the relationship that is there by default is the node --> user relationship; every node has an author, and if a node is in the query, the user who wrote that node is automatically made available. [Note: the author considers it an error that this relationship is automatic, but by the time it was realized this was in error, it was too late to change it.] + +A similar relationship that is not automatically made available is for node revisions. Each revision has its own author, which is the user who made the revision. By adding the "Node revision: User" relationship, all of the 'user' fields, sorts, filters and arguments available to a user will now be available for the revision author. + +When a relationship is added to the view, all applicable items will gain a "Relationship" select box, where you can choose which version of that particular item you wish to use. This can be illustrated with an example: + +A 'comment' view contains the relationships 'Comment: node' and 'Comment: user'. This means that all the fields for the node that a comment is attached to are available, and all the user fields for that node author also become available. The other relationship makes fields for the author of the comment available -- very often not the author of the node! + +When you add the "User: name" field, you will be presented with a select box. Either the node relationship or the user relationship must be selected, because there are two possible user names in the view to choose from. + +Another example of relationships involves the Files table. In Drupal, files are related to users, but files are not necessarily related to nodes. However, the upload.module allows some files to be attached to nodes. The only way for Views to deal with this discrepancy is with relationships. When creating a 'node' view, it's possible to add an uploaded files relationship to get file data for nodes that were attached with the upload module. It is also possible to go the other way; from a files view you may add a relationship via the Upload table to view information about the node. diff --git a/sites/all/modules/views/help/sort.html b/sites/all/modules/views/help/sort.html new file mode 100644 index 0000000..9a5640f --- /dev/null +++ b/sites/all/modules/views/help/sort.html @@ -0,0 +1,24 @@ +Sort criteria determine what order the records are retrieved from the database and displayed in; generally, all you need to do is pick a field and choose ascending (1, 2, 3, 4) or descending (4, 3, 2, 1) and it will be done. If you have multiple sort criteria, the second (and later) items only come into play if the first item is the same. + +Different data types sort just a little bit differently from others: +
+
Number fields
+
Number fields sort like you would expect. 1 comes before 2 which comes before 10 which comes before 100 which comes before 200, etc.
+
Text fields
+
Text fields always sort alphabetically, even if the text contains numbers. This can have some odd effects if you have numbers stored in text, because the values 1, 3, 7, 10, 12, 20, 100, 120 will sort like this: +
    +
  • 1
  • +
  • 10
  • +
  • 100
  • +
  • 12
  • +
  • 120
  • +
  • 200
  • +
  • 3
  • +
  • 7
  • +
+ +This is because these fields sort purely by characters, and not numeric value. i.e, comparing 200 and 3, the '2' comes before the '3', therefore, '200' is "smaller" than '3'. +
+
Date fields
+
Date fields often can have a 'granularity', which is a way of making similar dates actually be the same date. Take two dates that are close to each other: May 1, 2007 5:30 am and May 1, 2007 9:45am. Without granularity, the two dates are compared and the first date comes before the second date. However, if the granularity is set to 'day' it only looks at the parts of the date up to the day: May 1, 2007 and May 1, 2007. At that point, they are the same, and the sort would move on to the next sort criterion.
+
diff --git a/sites/all/modules/views/help/style-comment-rss.html b/sites/all/modules/views/help/style-comment-rss.html new file mode 100644 index 0000000..c047ee7 --- /dev/null +++ b/sites/all/modules/views/help/style-comment-rss.html @@ -0,0 +1 @@ +This row style is only available to RSS styles. It produces XML necessary for an RSS feed for the comment. \ No newline at end of file diff --git a/sites/all/modules/views/help/style-fields.html b/sites/all/modules/views/help/style-fields.html new file mode 100644 index 0000000..0afde7a --- /dev/null +++ b/sites/all/modules/views/help/style-fields.html @@ -0,0 +1,5 @@ +The fields row style displays each field defined in the view, one after another. Each field defines its own output. + +By default, each field is put in a <div> unless it is selected to be inline. If it is inline, it is put in a <span>. Two items in <div>s will be displayed one after another, with the second one below the first. Two items in <span>s will be displayed on the same line. One item in a <span> next to <div>s is the same as two items in <div>s. This means that for the inline setting to do anything, at least two consecutive items must be set inline. + +You may define a separator which will be placed between each item. This separator may be html. You can use &nbsp; to print blank space. \ No newline at end of file diff --git a/sites/all/modules/views/help/style-grid.html b/sites/all/modules/views/help/style-grid.html new file mode 100644 index 0000000..8667d0a --- /dev/null +++ b/sites/all/modules/views/help/style-grid.html @@ -0,0 +1,20 @@ +The grid style will display each row of your view within a grid. You may customize the number of columns, though it defaults to 4. A grid looks like this: + + + + + + +
row 1row 2row 3row 4
row 5row 6row 7row 8
row 9row 10row 11row 12
row 13row 14row 15row 16
+ +The above uses the 'horizontal' alignment, where rows are added into the grid from left to right. + +With a vertical alignment, rows will be placed from top to bottom, like this: + + + + + +
row 1row 5row 9row 13
row 2row 6row 10row 14
row 3row 7row 11row 15
row 4row 8row 12row 16
+ +This style uses a row style to determine what each row will look like. \ No newline at end of file diff --git a/sites/all/modules/views/help/style-list.html b/sites/all/modules/views/help/style-list.html new file mode 100644 index 0000000..0884338 --- /dev/null +++ b/sites/all/modules/views/help/style-list.html @@ -0,0 +1,20 @@ +The List view style will display every row of the view as part of an HTML list construct. For example: +
    +
  • Row 1
  • +
  • Row 2
  • +
  • Row 3
  • +
  • Row 4
  • +
+ +You may select whether or not the list is ordered which just means whether or not it uses numbers instead of the bullet: + +
    +
  1. Row 1
  2. +
  3. Row 2
  4. +
  5. Row 3
  6. +
  7. Row 4
  8. +
+ +The list style also uses a row style which means that it doesn't care what the actual output for each row of the view is. + +If you need information about using CSS to style list views, you may find this A list apart guide to styling lists useful. \ No newline at end of file diff --git a/sites/all/modules/views/help/style-node-rss.html b/sites/all/modules/views/help/style-node-rss.html new file mode 100644 index 0000000..9cce414 --- /dev/null +++ b/sites/all/modules/views/help/style-node-rss.html @@ -0,0 +1 @@ +This row style is only available to RSS styles. It produces XML necessary for an RSS feed for the node record. \ No newline at end of file diff --git a/sites/all/modules/views/help/style-node.html b/sites/all/modules/views/help/style-node.html new file mode 100644 index 0000000..393d1ca --- /dev/null +++ b/sites/all/modules/views/help/style-node.html @@ -0,0 +1,9 @@ +The node row style will display each item of the view through Drupal's standard node_view() function. Views has very little control over this output, except for the options you see. Instead, the output is run through the standard node template mechanism (typically node.tpl.php or a variant thereof) and any decisions about what is output may be done there. + +Views does add an extra 'suggestion' to the list of possible node templates: node-view-VIEWNAME.tpl.php -- you may use this to theme a node specifically for the view. This can be handy for creating very small teasers and the like. + +You may opt to display the full node body or the node teaser, and you may add the node links (such as he 'comment' links that appear after a node) or not. + +Because of this behavior, the node row style does not utilize fields and the Fields section will not be displayed. + +Please note that this row style performs a node_load() for every row, and as such can produce a lot of extra queries. Sometimes this is necessary, but it can have a negative impact on your site's performance! \ No newline at end of file diff --git a/sites/all/modules/views/help/style-row.html b/sites/all/modules/views/help/style-row.html new file mode 100644 index 0000000..3eae5ac --- /dev/null +++ b/sites/all/modules/views/help/style-row.html @@ -0,0 +1,3 @@ +A row style is an individual style to display only an individual record within a view. For example, a node type view would display one node per row; a user type view would display one user per row. + +Some row styles use fields which means you select from the available fields to display; others do not; they are able to use the base type and create a display. Usually, row styles that do not use fields produce less efficient (slower) views, so bear this in mind when contemplating the performance of your site. \ No newline at end of file diff --git a/sites/all/modules/views/help/style-rss.html b/sites/all/modules/views/help/style-rss.html new file mode 100644 index 0000000..0b18443 --- /dev/null +++ b/sites/all/modules/views/help/style-rss.html @@ -0,0 +1,3 @@ +The RSS output style is only available for Feed display types. It will display the view as an RSS feed, which is a specialized XML output. This output is not user visible, but can be parsed by feed readers for aggregation. + +You may supply a description for the RSS feed; most feed readers will display this description along with the contents of the feed. You may also select to use the site's mission statement for the description. \ No newline at end of file diff --git a/sites/all/modules/views/help/style-summary-unformatted.html b/sites/all/modules/views/help/style-summary-unformatted.html new file mode 100644 index 0000000..258acf5 --- /dev/null +++ b/sites/all/modules/views/help/style-summary-unformatted.html @@ -0,0 +1,3 @@ +The unformatted summary style is only available for summary styles, which are when an argument has been set to provide a summary if it was not provided with a value. This summary provides the possible candidates for the argument one after another with no special formatting. If inline is selected, the summary items will be enclosed within <span> tags. Otherwise the items will be in <div> tags. + +You can also elect to display the number of matching records for the argument, plus change the number of items per page for the summary. This is often useful because summary views are often quite small, but other views quite space intensive. It is very common to have far more records available in the summary view than in the more normal view. \ No newline at end of file diff --git a/sites/all/modules/views/help/style-summary.html b/sites/all/modules/views/help/style-summary.html new file mode 100644 index 0000000..f5b01ec --- /dev/null +++ b/sites/all/modules/views/help/style-summary.html @@ -0,0 +1,3 @@ +The list summary style is only available for summary styles, which are when an argument has been set to provide a summary if it was not provided with a value. This summary provides a list of possible candidates for the argument in a standard HTML list. Like the normal list style, you may set this list to be ordered or not. + +You can also elect to display the number of matching records for the argument, plus change the number of items per page for the summary. This is often useful because summary views are often quite small, but other views quite space intensive. It is very common to have far more records available in the summary view than in the more normal view. \ No newline at end of file diff --git a/sites/all/modules/views/help/style-table.html b/sites/all/modules/views/help/style-table.html new file mode 100644 index 0000000..b8ade8a --- /dev/null +++ b/sites/all/modules/views/help/style-table.html @@ -0,0 +1,13 @@ +The table style will display the View results as a table; each row of the table will correspond to a row from the view result. + +When setting the table options, each field in the view will be presented with some information next to each field: +
+
Column
+
By default, each field is its own column. However, you can place multiple fields in the same column. To do this, pick which field you want to represent the column, then pick another field and set the 'column' value to that field. You can place as many fields as you like in a single column, but only the main field in a column can be click-sorted.
+
Separator
+
If you have multiple fields in the same column, the separator will be placed between each one. At the very least, &nbsp; should be used, as without the separator the fields will be placed very close to each other. Common separators are a bullet, the | symbol, and a comma. If there are no other fields in the column, the separator will have no effect.
+
Sortable
+
If checked, the header for the column will be clickable, and the user may re-sort the table by clicking on this to sort by that field. At this time Views does not support click-sorting to sort by multiple columns at the same time.
+
Default sort
+
You may select a column which will be sorted by default when the table is first viewed. This column will be highlighted to the user. You may also select whether the default sort is ascending or descending.
+
\ No newline at end of file diff --git a/sites/all/modules/views/help/style-unformatted.html b/sites/all/modules/views/help/style-unformatted.html new file mode 100644 index 0000000..99fa3de --- /dev/null +++ b/sites/all/modules/views/help/style-unformatted.html @@ -0,0 +1 @@ +The unformatted output style simply places each row of the view, one after another, with no additional formatting. diff --git a/sites/all/modules/views/help/style.html b/sites/all/modules/views/help/style.html new file mode 100644 index 0000000..01dffed --- /dev/null +++ b/sites/all/modules/views/help/style.html @@ -0,0 +1,14 @@ +The Views' style system is how you customize the output produced by your view. A view style is basically a smart theme template that processes the view data and then outputs it. All styles in Views can be overridden by placing copies of the templates in your theme directory and then modifying them. See the theme: information link available on all views to get hints for which templates a given view is using. + +
+ +A breakdown of View output +
+By default, the style is unformatted, which means that there is very little style actually used; the records are simply displayed one after another, enclosed in a <div> tag so that you can use CSS to manipulate the view. + +Some styles use a separate row style to determine how each row of the View looks. This is useful for mixing and matching styles to more readily produce exactly the kind of output you need. + +Many styles can be grouped. For styles that can, there will be a 'grouping field' option; pick one of the fields to group by. This grouping field will be displayed as a header, and all rows will be displayed beneath it. +With the Theme Developer module enabled, the field grouping in Views does not work. Disable the Theme Developer module before grouping by fields. + +Each style is its own entity. diff --git a/sites/all/modules/views/help/theme-css.html b/sites/all/modules/views/help/theme-css.html new file mode 100644 index 0000000..3be998f --- /dev/null +++ b/sites/all/modules/views/help/theme-css.html @@ -0,0 +1,75 @@ +Views uses a wide array of CSS classes on all of its content to ensure that you can easily and accurately select exactly the content you need in order to manipulate it with CSS. + +Typically, every view is wrapped in a div with the name of the view as part of its class (for all these examples, we will assume the name of the view is myview), as well as the generic class 'view': + +
+<div class="view view-myview">
+...
+</div>
+
+ +In your CSS, you can modify all views: + +
+div.view {
+  border: 1px solid black;
+}
+
+ +Or just your view: + +
+div.view-myview {
+  background: yellow;
+}
+
+ +By default, the general view template also provides the following classes to easily style other areas of the view: +
    +
  • .view-header
  • +
  • .view-filters
  • +
  • .view-content
  • +
  • .view-empty (if an "empty" text is used when the view has no results)
  • +
  • .view-footer
  • +
  • .feed-icon
  • +
  • .attachment-before (if using an "attachment" display)
  • +
  • .attachment-after (if using an "attachment" display)
  • +
+ +So for example: +
+div.view-myview div.view-header {
+  /* make the header stand out */
+  font-size: 120%;
+  font-weight: bold;
+}
+
+div.view-myview div.view-footer {
+  /* Make the footer less important */
+  font-size: 80%;
+  font-style: italic;
+  color: #CCC;
+}
+
+ +In the above example, we whimsically made the header bold and in a bigger font, and the footer smaller, italicized, and greyish. + +

Views with fields

+If your view has fields, each field is uniquely tagged with its ID. A field's ID may be gleaned from the Theme: Information page. Note that due to CSS rules, any _ in the id will be converted to - automatically, so if you have a field whose id is 'edit_node' (this is the field used to provide an "edit" link to a node), it will be 'edit-node'. Additionally, to make sure that the view IDs don't conflict with other css classes in the system, they will be pretended with 'views-field-'; thus, the final CSS class for the field with the id 'edit_node' will be views-field-edit-node. + +Exactly how this appears is going to depend upon the style you're using. For example, the 'unformatted' style uses div.views-field-edit-node and div.views-label-edit-node to access that particular field, but a table would use td.views-field-edit-node and th.views-field-edit-node to access the table header; or just .views-field-edit-node to affect both. + +
+.view-myview th {
+  color: red; /* make all headers red */
+}
+
+.view-myview .views-field-title {
+  font-weight: bold; /* Make the 'title' field bold */
+}
+
+.view-myview td.views-field-body {
+  font-size: 60%; /* Make the text in the body field small */
+}
+
+ diff --git a/sites/all/modules/views/help/updating.html b/sites/all/modules/views/help/updating.html new file mode 100644 index 0000000..844c46c --- /dev/null +++ b/sites/all/modules/views/help/updating.html @@ -0,0 +1,2 @@ +TODO: This document needs to be fleshed out. + diff --git a/sites/all/modules/views/help/using-theme.html b/sites/all/modules/views/help/using-theme.html new file mode 100644 index 0000000..f80d71c --- /dev/null +++ b/sites/all/modules/views/help/using-theme.html @@ -0,0 +1,50 @@ +Views theme templates are straightforward to use with the Drupal theming system. If you are unfamiliar with the theming system at all, you should probably at least read drupal.org theming documentation. That said, these are the important things you need to know: + +
    +
  1. Copy a base Views template to one of the names provided from the Theme: Information section of the View. Copy this template right into your theme directory.
  2. +
  3. Clear the theme registry. See the instructions for how to do this.
  4. +
  5. Your new template should now operate; assuming you picked a nicely named template that includes the view name, that template should now be active for your view. A good example is views-view-list--foobar.tpl.php which would work for a view named 'foobar'.
  6. +
  7. You can now modify this template all you like.
  8. +
+ +For any template that uses fields, the fields will be in array. In order to use this effectively, you will need to understand enough PHP to fetch data from an array. This is a place where the devel module can really help you, because you can use its dsm() function right in your template to see what variables it uses. There is an alternative to dsm() that works without devel module, but it's a bit longer to use. + +For example, I placed the following code inside a loop in views-view-table.php.php: + <?php drupal_set_message('<pre>' . var_export($row, true) . '</pre>'); ?> + + +And it produced this output: + array ( + 'nid' => '97', + 'title' => 'Scisco Ideo Vicis Feugiat Qui', + 'name' => 'luwrepuslan', + ) + + +My view had three fields: +Node: Nid +Node: Title +User: Name + + +The contents of the $row variable included these fields, in precisely the order that I had arranged them to using the Views rearrange link. Also worth noting, though, is that each field also has an identifier so it can easily be pulled out of the row should I want to display it differently. Using +<?php print $row['title']; ?> + + +Would print just the title for that row. Please remember that I'm doing this inside the loop, so this will get repeated for every row of the view. + +The IDs used to fetch items from the array, id $row['title'] can be quickly and easily looked up on the Theme: Information page. Once a field has been added to the view, its ID will not change, but note that if there are two "title" fields in a view, one will be 'title' and the other will be 'title1', in order to prevent namespace collisions. + +The important thing here is that Views does provide IDs. Views doesn't tell you what these IDs are, but it's easy to get them by dumping the row data and doing a simple visual inspection. Views does guarantee that these IDs will not change, unless you actually add a new field and remove the existing one (in which case 'title', above, would become 'title1'). + +

The basic fields template

+ +The most common template people will need to rewrite is the "simple" views-view-fields.tpl.php, which is the template used by the Fields row style and all it does is display a simple list of fields. However, it is not that simple to the user. Because the template can't inherently know what the fields are, it has to go through an array in a loop. + +This loop isn't very handy when you really want to have fine control over the template by placing your fields precisely where and how you want. Relax, though; if you know what your fields are, you can rewrite this. If you end up writing your own HTML, the only part that is really important is the content for each field. We know from above that you can get the ID for each field on the Theme: Information page from the view. In the header for the template, we can see that the fields are all in the $fields array, and each field is an object. That leads us to this: + +<?php print $fields['some_id']->content; ?> + +Assuming you replace some_id with an id found on the theme: information page, this code will print the content for that field. You can also get the label and some other data about the field, as well as the raw information. Complete details for what is available are documented directly in views-view-fields.tpl.php. + +Keep in mind that if you rewrite your templates using this, you'll need to maintain this template whenever changes are made to the fields of the view; while this isn't generally recommend, sometimes it's necessary to get the kind of control you might ultimately need. diff --git a/sites/all/modules/views/help/view-type.html b/sites/all/modules/views/help/view-type.html new file mode 100644 index 0000000..bdb80fc --- /dev/null +++ b/sites/all/modules/views/help/view-type.html @@ -0,0 +1,21 @@ +

The view type describes how this view is stored; Views is capable of having Views entirely in code that are not in the database. This allows modules to easily ship with Views built in, and it allows you to create a module to store your views for easy deployment between development and production servers.

+ +
+
Normal
+
Normal views are stored in your database and are completely local to your system.
+ +
Default
+
Default views are stored only in code and are not anywhere in your database. They may be enabled or disabled but you may not completely remove them from your system. You can override the view which will create a local copy of your view. If you do this, future updates to the version in code will not affect your view.
+ +
Overridden
+
Overridden views are stored both in code and in the database; while overridden, the version that is in code is completely dormant. If you revert the view, the version in the database will be deleted, and the version that is in code will once again be used.
+
+ +You may store your views in code with the following procedure: +
    +
  1. Create a module to store the views.
  2. +
  3. Add the function MODULENAME_views_default_views() to this module.
  4. +
  5. Export the view you wish to store in your module in code. Cut and paste that into the abovenamed function. Make sure the last line of the view is: $views[$view->name] = $view;
  6. +
  7. Make sure the last line of the function is return $views;
  8. +
  9. After you make any changes, be sure to clear the Views' cache. You may do this from the Tools menu.
  10. +
diff --git a/sites/all/modules/views/help/views.help.ini b/sites/all/modules/views/help/views.help.ini new file mode 100644 index 0000000..51a7264 --- /dev/null +++ b/sites/all/modules/views/help/views.help.ini @@ -0,0 +1,203 @@ +[advanced help settings] +line break = TRUE + +[about] +title = "What is Views?" +weight = -40 + +[getting-started] +title = "Getting started" +weight = -45 + +[example-users-by-role] +title = "Create a page to list users by role" +parent = getting-started +weight = -10 + +[example-recent-stories] +title = "Create a block of recent stories" +parent = getting-started +weight = 0 + +[example-user-feed] +title = "Create an RSS feed of user posts" +parent = getting-started +weight = 30 + +[example-author-block] +title = "Create a block of author's recent blog posts" +parent = getting-started +weight = 40 + +[view-type] +title = "View types" + +[display] +title = "Displays" +weight = -30 + +[display-default] +title = "Default display" +parent = display +weight = -20 + +[display-page] +title = "Page display" +parent = display +weight = -15 + +[display-block] +title = "Block display" +parent = display +weight = -10 + +[display-attachment] +title = "Attachment display" +parent = display + +[display-feed] +title = "Feed display" +parent = display + +[argument] +title = "Arguments" +parent = about + +[field] +title = "Fields" +parent = about + +[sort] +title = "Sorts" +parent = about + +[filter] +title = "Filters" +parent = about + +[relationship] +title = "Relationships" +parent = about + +[style] +title = "Output styles (View styles)" +weight = -20 + +[style-row] +title = "View row styles" +parent = style +weight = 10 + +[style-list] +title = "List output style" +parent = style + +[style-unformatted] +title = "Unformatted output style" +parent = style +weight = -6 + +[style-table] +title = "Table output style" +parent = style +weight = -5 + +[style-grid] +title = "Grid output style" +parent = style +weight = -5 + +[style-rss] +title = "RSS output style" +parent = style +weight = -5 + +[style-fields] +title = "Fields row style" +parent = style-row + +[style-node] +title = "Node row style" +parent = style-row + +[style-node-rss] +title = "Node RSS item row style" +parent = style-row + +[style-comment-rss] +title = "Comment RSS item row style" +parent = style-row + +[style-summary-unformatted] +title = "Unformatted summary style" +parent = "style" +weight = 10 + +[style-summary] +title = "List summary style" +parent = "style" +weight = 10 + +[menu] +title = "Menu options (page display)" + +[path] +title = "Path options (page display)" + +[analyze-theme] +title = "Theme information" + +[using-theme] +title = "Using Views templates" +parent = analyze-theme + +[theme-css] +title = "Using CSS with Views" +parent = analyze-theme + +[overrides] +title = "What are overrides?" + +[embed] +title = "Embedding a view into other parts of your site" + +[new] +title = "What's new in Views 2" +weight = -42 + +[updating] +title = "Updating your views from Views 1 to Views 2" + +; API related +[api] +title = "Views' API" +weight = 100 + +[api-tables] +title = "Describing tables to Views" +weight = -100 +parent = api + +[api-default-views] +title = "Using default views in your module" +weight = -90 +parent = api + +[api-handlers] +title = "How Views handlers work" +weight = -50 +parent = api + +[api-plugins] +title = "How Views plugins work" +weight = -40 +parent = api + +[api-upgrading] +title = "Upgrading your module Views 1 to Views 2" +parent = api + +[api-example] +title = "Integrating the Node Example module" +parent = api +weight = 100 diff --git a/sites/all/modules/views/images/arrow-active.png b/sites/all/modules/views/images/arrow-active.png new file mode 100644 index 0000000..3bbd3c2 Binary files /dev/null and b/sites/all/modules/views/images/arrow-active.png differ diff --git a/sites/all/modules/views/images/expanded-options.png b/sites/all/modules/views/images/expanded-options.png new file mode 100644 index 0000000..b7b755c Binary files /dev/null and b/sites/all/modules/views/images/expanded-options.png differ diff --git a/sites/all/modules/views/images/overridden.gif b/sites/all/modules/views/images/overridden.gif new file mode 100644 index 0000000..b781191 Binary files /dev/null and b/sites/all/modules/views/images/overridden.gif differ diff --git a/sites/all/modules/views/images/sprites.png b/sites/all/modules/views/images/sprites.png new file mode 100644 index 0000000..9083622 Binary files /dev/null and b/sites/all/modules/views/images/sprites.png differ diff --git a/sites/all/modules/views/images/status-active.gif b/sites/all/modules/views/images/status-active.gif new file mode 100644 index 0000000..207e95c Binary files /dev/null and b/sites/all/modules/views/images/status-active.gif differ diff --git a/sites/all/modules/views/includes/admin.inc b/sites/all/modules/views/includes/admin.inc new file mode 100644 index 0000000..71b68c6 --- /dev/null +++ b/sites/all/modules/views/includes/admin.inc @@ -0,0 +1,3237 @@ +enable the advanced help module, Views will provide more and better help. Hide this message.', array('@modules' => url('admin/build/modules'),'@hide' => url('admin/build/views/tools')))); + } + else { + drupal_set_message(t('If you install the advanced help module from !href, Views will provide more and better help. Hide this message.', array('!href' => l('http://drupal.org/project/advanced_help', 'http://drupal.org/project/advanced_help'), '@hide' => url('admin/build/views/tools')))); + } + } +} + +/** + * Preprocess the list views theme + */ +function template_preprocess_views_ui_list_views(&$vars) { + $items = array(); + $sorts = array(); + + // Add some js for easier gui. + views_add_js('view-list'); + + $views = views_get_all_views(); + + $token_enable = drupal_get_token('views-enable'); + $token_disable = drupal_get_token('views-disable'); + + // Respond to a reset command by clearing session and doing a drupal goto + // back to the base URL. + if (isset($_GET['op']) && $_GET['op'] == t('Reset')) { + unset($_SESSION['views']['#admin']); + drupal_goto('admin/build/views'); + } + if (count($_GET) <= 1) { + if (isset($_SESSION['views']['#admin']) && is_array($_SESSION['views']['#admin'])) { + $_GET += $_SESSION['views']['#admin']; + } + } + else { + $_SESSION['views']['#admin'] = $_GET; + unset($_SESSION['views']['#admin']['q']); + } + + $form_state = array( + 'views' => $views, + 'input' => $_GET, + 'method' => 'get', + 'rerender' => TRUE, + 'no_redirect' => TRUE, + ); + + $vars['widgets'] = drupal_build_form('views_ui_list_views_form', $form_state); + + $vars['help_type_icon'] = theme('advanced_help_topic', 'views', 'view-type'); + + $base_tables = views_fetch_base_tables(); + + foreach ($views as $view) { + if ($form_state['values']['tag'] != 'all') { + if ($form_state['values']['tag'] == 'none') { + if (!empty($view->tag)) { + continue; + } + } + else if ($form_state['values']['tag'] != $view->tag) { + continue; + } + } + if ($form_state['values']['type'] != 'all' && $form_state['values']['type'] != $view->type) { + continue; + } + + if ($form_state['values']['base'] != 'all' && $form_state['values']['base'] != $view->base_table) { + continue; + } + + if ($form_state['values']['display'] != 'all' && empty($view->display[$form_state['values']['display']])) { + continue; + } + + $item = new stdClass(); + $item->ops = array(); + if (empty($view->disabled)) { + $item->ops[] = l(t('Edit'), "admin/build/views/edit/$view->name"); + $item->ops[] = l(t('Export'), "admin/build/views/export/$view->name"); + $item->ops[] = l(t('Clone'), "admin/build/views/clone/$view->name"); + } + if ($view->type != t('Default')) { + $text = $view->type == t('Overridden') ? t('Revert') : t('Delete'); + $item->ops[] = l($text, "admin/build/views/delete/$view->name"); + } + else { + if (empty($view->disabled)) { + $item->ops[] = l(t('Disable'), "admin/build/views/disable/$view->name", array('query' => drupal_get_destination() . '&token=' . $token_disable)); + } + else { + $item->ops[] = l(t('Enable'), "admin/build/views/enable/$view->name", array('query' => drupal_get_destination() . '&token=' . $token_enable)); + } + } + + $item->ops = implode(' | ', $item->ops); + if (empty($view->display)) { + $item->path = t('Warning! Broken view!'); + } + else { + $item->path = $raw_path = $view->get_path(); + $item->path = $item->path && empty($view->disabled) && strpos($item->path, '%') === FALSE ? l($item->path, $item->path) : check_plain($item->path); + } + + $item->type = $view->type; + $item->name = $view->name; + + if (!empty($view->tag)) { + $item->tag = check_plain($view->tag); + } + + $item->title = $view->get_title(); + $item->base = !empty($base_tables[$view->base_table]['title']) ? $base_tables[$view->base_table]['title'] : t('Broken'); + + $item->displays = array(); + foreach ($view->display as $display) { + if (!empty($display->handler->definition['admin'])) { + $item->displays[$display->handler->definition['admin']] = TRUE; + } + } + + if ($item->displays) { + ksort($item->displays); + $item->displays = implode(', ', array_keys($item->displays)); + } + + $item->description = check_plain($view->description); + $item->classes = empty($view->disabled) ? 'view-enabled' : 'view-disabled'; + $items[] = $item; + + $sort = intval(empty($view->disabled) xor $form_state['values']['sort'] == 'asc'); + + switch ($form_state['values']['order']) { + case 'name': + default: + $sort .= strtolower($view->name); + break; + case 'title': + $sort .= strtolower($item->title); + break; + case 'path': + $sort .= strtolower($raw_path); // $path; + break; + case 'type': + $sort .= $view->type . $view->name; + break; + case 'tag': + $sort .= strtolower($view->tag); + break; + case 'desc': + $sort .= strtolower($view->description); + break; + } + + $sorts[] = $sort; + } + + if ($form_state['values']['sort'] == 'desc') { + arsort($sorts); + } + else { + asort($sorts); + } + + $i = array(); + foreach ($sorts as $id => $title) { + $i[] = $items[$id]; + } + + views_add_css('views-list'); + $vars['views'] = $i; + + $getting_started = theme('advanced_help_topic', 'views', 'getting-started', 'title'); + if (!$getting_started) { + $getting_started = t('Install the advanced help module for the getting started'); + } + + $vars['help'] = t('Not sure what to do? Try the "!getting-started" page.', array('!getting-started' => $getting_started)); +} + +/** + * Provide a form for sorting and filtering the list of views. + */ +function views_ui_list_views_form(&$form_state) { + if (!variable_get('clean_url', FALSE)) { + $form['q'] = array( + '#type' => 'hidden', + '#value' => $_GET['q'], + ); + } + + $all = array('all' => t('- All -')); + $none = array('none' => t('- None -')); + + $form['type'] = array( + '#type' => 'select', + '#title' => t('Storage'), + '#options' => array( + 'all' => t('- All -'), + t('Normal') => t('Normal'), + t('Default') => t('Default'), + t('Overridden') => t('Overridden'), + ), + '#default_value' => 'all', + ); + + $bases = array(); + foreach (views_fetch_base_tables() as $table => $info) { + $bases[$table] = $info['title']; + } + + $form['base'] = array( + '#type' => 'select', + '#title' => t('Type'), + '#options' => array_merge($all, $bases), + '#default_value' => 'all', + ); + + $tags = array(); + + $extras = array(); + foreach ($form_state['views'] as $name => $view) { + if (!empty($view->tag)) { + $tags[$view->tag] = $view->tag; + } + } + + asort($tags); + + $form['tag'] = array( + '#type' => 'select', + '#title' => t('Tag'), + '#options' => array_merge($all, $none, $tags), + '#default_value' => 'all', + ); + + $displays = array(); + foreach (views_fetch_plugin_data('display') as $id => $info) { + if (!empty($info['admin'])) { + $displays[$id] = $info['admin']; + } + } + + asort($displays); + + $form['display'] = array( + '#type' => 'select', + '#title' => t('Displays'), + '#options' => array_merge($all, $displays), + '#default_value' => 'all', + ); + + $form['order'] = array( + '#type' => 'select', + '#title' => t('Sort by'), + '#options' => array( + 'name' => t('Name'), + 'title' => t('Title'), + 'tag' => t('Tag'), + 'path' => t('Path'), + 'type' => t('Type'), + 'desc' => t('Description'), + ), + '#default_value' => 'name', + ); + + $form['sort'] = array( + '#type' => 'select', + '#title' => t('Order'), + '#options' => array( + 'asc' => t('Up'), + 'desc' => t('Down'), + ), + '#default_value' => 'asc', + ); + + $form['submit'] = array( + '#name' => '', // so it won't in the $_GET args + '#type' => 'submit', + '#id' => 'edit-views-apply', + '#value' => t('Apply'), + ); + + if (!empty($_SESSION['views']['#admin'])) { + $form['reset'] = array( + '#type' => 'submit', + '#id' => 'edit-views-reset', + '#value' => t('Reset'), + ); + } + + $form['#theme'] = array('views_ui_list_views_form'); + return $form; +} + +function theme_views_ui_list_views_form($form) { + // Don't render these: + unset($form['form_id']); + unset($form['form_build_id']); + unset($form['form_token']); + return drupal_render($form); +} + +/** + * Page callback for the live preview. + * + * @todo make this use a template + */ +function views_ui_preview($js, $view) { + // Take off the items we know so that we can have just the args passed + // in for later use. + $func_args = func_get_args(); + array_shift($func_args); // $js + array_shift($func_args); // $view + $display_id = (count($func_args)) ? array_shift($func_args) : 'default'; + + $form_state = array( + 'display_id' => $display_id, + 'view_args' => $func_args ? implode('/', $func_args) : '', + 'rerender' => TRUE, + 'no_redirect' => TRUE, + 'view' => &$view, + 'ajax' => $js + ); + + $output = drupal_build_form('views_ui_preview_form', $form_state); + $args = array(); + if (isset($form_state['view_args']) && $form_state['view_args'] !== '') { + $args = explode('/', $form_state['view_args']); + } + + $errors = $view->validate(); + if ($errors === TRUE) { + $view->ajax = $js; + $view->live_preview = TRUE; + + // Store the current view URL for later use: + $view->set_display($form_state['display_id']); + $view->set_arguments($args); + + if ($view->display_handler->get_option('path')) { + $path = $view->get_url(); + } + + // Make view links come back to preview. + $view->override_path = 'admin/build/views/nojs/preview/' . $view->name . '/' . $form_state['display_id']; + + // also override $_GET['q'] so we get the pager + $_GET['q'] = $view->override_path; + if ($form_state['view_args']) { + $_GET['q'] .= '/' . $form_state['view_args']; + } + + $preview = $view->preview($form_state['display_id'], $args); + + // Get information from the preview for display. + if (!empty($view->build_info['query'])) { + $rows = array(); + $query = db_prefix_tables($view->build_info['query']); + if ($view->build_info['query_args']) { + _db_query_callback($view->build_info['query_args'], TRUE); + $query = preg_replace_callback(DB_QUERY_REGEXP, '_db_query_callback', $query); + } + $rows[] = array('' . t('Query') . '', '
' . check_plain($query) . '
'); + if (!empty($view->additional_queries)) { + $queries = '' . t('These queries were run during view rendering:') . ''; + foreach ($view->additional_queries as $query) { + if ($queries) { + $queries .= "\n"; + } + $queries .= t('[@time ms]', array('@time' => intval($query[1] * 100000) / 100)) . ' ' . check_plain($query[0]); + } + + $rows[] = array('' . t('Other queries') . '', '
' . $queries . '
'); + } + + $rows[] = array('' . t('Title') . '', filter_xss_admin($view->get_title())); + if (isset($path)) { + $path = l($path, $path); + } + else { + $path = t('This display has no path.'); + } + + $rows[] = array('' . t('Path') . '', $path); + + $rows[] = array('' . t('Query build time') . '', t('@time ms', array('@time' => intval($view->build_time * 100000) / 100))); + $rows[] = array('' . t('Query execute time') . '', t('@time ms', array('@time' => intval($view->execute_time * 100000) / 100))); + $rows[] = array('' . t('View render time') . '', t('@time ms', array('@time' => intval($view->render_time * 100000) / 100))); + drupal_alter('views_preview_info', $rows, $view); + + $info = theme('table', array(), $rows); + } + else { + $info = theme('table', array(), array(array('' . t('Query') . '', t('No query was run')))); + } + } + else { + foreach ($errors as $error) { + drupal_set_message($error, 'error'); + } + $preview = t('Unable to preview due to validation errors.'); + $info = ''; + } + + $info = '
' . $info . '
'; + + if (variable_get('views_ui_query_on_top', FALSE)) { + $output .= $info . $preview; + } + else { + $output .= $preview . $info; + } + + if (!$js) { + views_add_css('views-admin'); + drupal_set_title($view->get_title()); + return $output; + } + else { + views_include('ajax'); + $object = new stdClass(); + if (!empty($view->js_settings)) { + $object->js = $view->js_settings; + } + $object->display = ''; + if ($messages = theme('status_messages')) { + $object->display = '
' . $messages . '
'; + } + $object->display .= $output; + $object->title = $view->get_title(); + views_ajax_render($object); + } +} + +/** + * Form for generating argument information for the live preview. + */ +function views_ui_preview_form(&$form_state) { + $view = &$form_state['view']; + $view->init_display(); + $options = array(); + foreach ($view->display as $id => $display) { + $options[$id] = $display->display_title; + } + + $form['#attributes'] = array( + 'class' => 'clear-block', + ); + + $form['display_id'] = array( + '#type' => 'select', + '#title' => t('Display'), + '#options' => $options, + '#default_value' => $form_state['display_id'], + '#id' => 'preview-display-id', + ); + + $form['args'] = array( + '#type' => 'textfield', + '#title' => t('Arguments'), + '#default_value' => $form_state['view_args'], + '#description' => t('Separate arguments with a / as though they were a URL path.'), + '#id' => 'preview-args', + ); + + $form['preview'] = array( + '#type' => 'submit', + '#value' => t('Preview'), + '#id' => 'preview-submit', + ); + + + $form['live_preview'] = array( + '#type' => 'checkbox', + '#title' => t('Automatic live preview'), + '#default_value' => !variable_get('views_ui_disable_live_preview', 0), + ); + + $form['#action'] = url("admin/build/views/nojs/preview/$view->name"); + return $form; +} + +/** + * Submit the preview form. + * + * This just takes the data and stores it on the form state in a + * known location. The caller will be responsible for using it. + */ +function views_ui_preview_form_submit(&$form, &$form_state) { + $form_state['display_id'] = $form_state['values']['display_id']; + $form_state['view_args'] = $form_state['values']['args']; +} + +/** + * Page callback to add a new view. + */ +function views_ui_add_page() { + $form_state = array( + 'view' => NULL + ); + + return drupal_build_form('views_ui_add_form', $form_state); +} + +/** + * Page callback to add a new view. + */ +function views_ui_clone_page($view) { + $form_state = array( + 'view' => $view->copy(), + ); + + drupal_set_title(t('Clone view %view', array('%view' => $view->name))); + return drupal_build_form('views_ui_add_form', $form_state); +} + +/** + * Form constructor callback to create the views Add Form, phase 1. + */ +function views_ui_add_form(&$form_state) { + $view = $form_state['view']; + $form = array(); + + $form['name'] = array( + '#type' => 'textfield', + '#title' => t('View name'), + '#description' => t('This is the unique name of the view. It must contain only alphanumeric characters and underscores; it is used to identify the view internally and to generate unique theming template names for this view. If overriding a module provided view, the name must not be changed or instead a new view will be created.'), + '#required' => TRUE, + '#maxlength' => 32, + '#default_value' => $view ? $view->name : '', + '#attributes' => array('dir'=>'ltr'), + ); + + $form['description'] = array( + '#type' => 'textfield', + '#title' => t('View description'), + '#description' => t('This description will appear on the Views administrative UI to tell you what the view is about.'), + '#default_value' => $view ? $view->description : '', + '#maxlength' => 255, + ); + + $form['tag'] = array( + '#type' => 'textfield', + '#title' => t('View tag'), + '#description' => t('Enter an optional tag for this view; it is used only to help sort views on the administrative page.'), + '#default_value' => $view ? $view->tag : '', + '#autocomplete_path' => 'admin/views/ajax/autocomplete/tag', + ); + + $base_tables = array(); + foreach (views_fetch_base_tables() as $table => $info) { + $base_tables[$table] = $info['title'] . '
' . $info['description'] . '
'; + } + + $form['base_table'] = array( + '#type' => 'radios', + '#title' => t('View type'), + '#description' => t('The view type is the primary table for which information is being retrieved. The view type controls what arguments, fields, sort criteria and filters are available, so once this is set it cannot be changed.'), + '#default_value' => $view ? $view->base_table : 'node', + '#options' => $base_tables, + ); + + if ($view) { + $form['base_table']['#disabled'] = TRUE; + } + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Next'), + '#validate' => array('views_ui_add_form_validate'), + '#submit' => array('views_ui_add_form_submit'), + ); + + return $form; +} + +/** + * Validate the add view form. + */ +function views_ui_add_form_validate($form, &$form_state) { + $name = $form_state['values']['name']; + + // View name must be alphanumeric or underscores, no other punctuation. + if (preg_match('/[^a-zA-Z0-9_]/', $name) || is_numeric($name)) { + form_error($form['name'], t('View name must be alphanumeric or underscores only, but cannot be numeric.')); + } + + // View name must already exist. + $view = views_get_view($form_state['values']['name']); + if ($view && $view->type != t('Default')) { + form_error($form['name'], t('You must use a unique name for this view.')); + } +} + +/** + * Process the add view form + */ +function views_ui_add_form_submit($form, &$form_state) { + $view = $form_state['view'] ? $form_state['view'] : views_new_view(); + $view->name = $form_state['values']['name']; + $view->description = $form_state['values']['description']; + $view->tag = $form_state['values']['tag']; + $view->core = VERSION; + if (empty($form['base_table']['#disabled'])) { + $view->base_table = $form_state['values']['base_table']; + } + + views_ui_cache_set($view); + $form_state['redirect'] ='admin/build/views/edit/' . $view->name; +} + +/** + * Page to delete a view. + */ +function views_ui_delete_confirm(&$form_state, $view) { + $form_state['view'] = &$view; + $form = array(); + + $cancel = 'admin/build/views'; + if (!empty($_REQUEST['cancel'])) { + $cancel = $_REQUEST['cancel']; + } + + if ($view->type == t('Overridden')) { + $title = t('Are you sure you want to revert the view %name?', array('%name' => $view->name)); + $desc = t('Reverting the view will delete the view that is in the database, reverting it to the original default view. Any changes you have made will be lost and cannot be recovered.'); + $button = t('Revert'); + } + else { + $title = t('Are you sure you want to delete the view %name?', array('%name' => $view->name)); + $desc = t('Deleting a view cannot be undone.'); + $button = t('Delete'); + } + + return confirm_form($form, + $title, + $cancel, + $desc, + $button, + t('Cancel')); +} + +/** + * Submit handler to delete a view. + */ +function views_ui_delete_confirm_submit(&$form, &$form_state) { + $form_state['view']->delete(); + views_object_cache_clear('view', $form_state['view']->name); + drupal_set_message(t('The view has been deleted.')); + $form_state['redirect'] = 'admin/build/views'; +} + +/** + * Page to delete a view. + */ +function views_ui_break_lock_confirm(&$form_state, $view) { + $form_state['view'] = &$view; + $form = array(); + + if (empty($view->locked)) { + return t('There is no lock on view %view to break.', array('%name' => $view->name)); + } + + $cancel = 'admin/build/views/edit/' . $view->name; + + $account = user_load($view->locked->uid); + return confirm_form($form, + t('Are you sure you want to break the lock on view %name?', + array('%name' => $view->name)), + $cancel, + t('By breaking this lock, any unsaved changes made by !user will be lost!', array('!user' => theme('username', $account))), + t('Break lock'), + t('Cancel')); +} + +/** + * Submit handler to break_lock a view. + */ +function views_ui_break_lock_confirm_submit(&$form, &$form_state) { + db_query("DELETE FROM {views_object_cache} WHERE obj = 'view' AND name = '%s'", $form_state['view']->name); + $form_state['redirect'] = 'admin/build/views/edit/' . $form_state['view']->name; + drupal_set_message(t('The lock has been broken and you may now edit this view.')); +} + +/** + * The main view edit page + */ +function views_ui_edit_page($view) { + drupal_set_title(t('Edit view %view', array('%view' => $view->name))); + $output = theme('views_ui_edit_view', $view); + views_ui_check_advanced_help(); + return $output; +} + +/** + * Export a view for cut & paste. + */ +function views_ui_export_page(&$form_state, $view) { + $code = $view->export(); + $lines = substr_count($code, "\n"); + $form['code'] = array( + '#type' => 'textarea', + '#title' => $view->name, + '#default_value' => $code, + '#rows' => $lines, + ); + return $form; +} + +/** + * Import a view from cut & paste + */ +function views_ui_import_page(&$form_state) { + $form['name'] = array( + '#type' => 'textfield', + '#title' => t('View name'), + '#description' => t('Enter the name to use for this view if it is different from the source view. Leave blank to use the name of the view.'), + ); + + $form['view'] = array( + '#type' => 'textarea', + '#title' => t('Paste view code here'), + '#required' => TRUE, + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Import'), + '#submit' => array('views_ui_import_submit'), + '#validate' => array('views_ui_import_validate'), + ); + return $form; +} + +/** + * Validate handler to import a view + */ +function views_ui_import_validate($form, &$form_state) { + $view = ''; + views_include('view'); + // Be forgiving if someone pastes views code that starts with 'api_version) || $view->api_version < 2) { + // Check for some value that would only exist on a Views 1 view. + if (isset($view->url) || isset($view->page) || isset($view->block)) { + views_include('convert'); + $view = views1_import($view); + drupal_set_message(t('You are importing a view created in Views version 1. You may need to adjust some parameters to work correctly in version 2.'), 'warning'); + } + else { + form_error($form['view'], t('That view is not compatible with this version of Views.')); + } + } + elseif ($view->api_version > views_api_version()) { + form_error($form['view'], t('That view is created for the version @import_version of views, but you only have @api_version', array( + '@import_version' => $view->api_version, + '@api_version' => views_api_version()))); + } + + // View name must be alphanumeric or underscores, no other punctuation. + if (!empty($form_state['values']['name']) && preg_match('/[^a-zA-Z0-9_]/', $form_state['values']['name'])) { + form_error($form['name'], t('View name must be alphanumeric or underscores only.')); + } + + if ($form_state['values']['name']) { + $view->name = $form_state['values']['name']; + } + + $test = views_get_view($view->name); + if ($test && $test->type != t('Default')) { + form_set_error('', t('A view by that name already exists; please choose a different name')); + } + + $view->init_display(); + + $broken = FALSE; + // Make sure that all plugins and handlers needed by this view actually exist. + foreach ($view->display as $id => $display) { + if (empty($display->handler) || !empty($display->handler->broken)) { + drupal_set_message(t('Display plugin @plugin is not available.', array('@plugin' => $display->display_plugin)), 'error'); + $broken = TRUE; + continue; + } + + $plugin = views_get_plugin('style', $display->handler->get_option('style_plugin')); + if (!$plugin) { + drupal_set_message(t('Style plugin @plugin is not available.', array('@plugin' => $display->handler->get_option('style_plugin'))), 'error'); + $broken = TRUE; + } + else if ($plugin->uses_row_plugin()) { + $plugin = views_get_plugin('row', $display->handler->get_option('row_plugin')); + if (!$plugin) { + drupal_set_message(t('Row plugin @plugin is not available.', array('@plugin' => $display->handler->get_option('row_plugin'))), 'error'); + $broken = TRUE; + } + } + + foreach (views_object_types() as $type => $info) { + $handlers = $display->handler->get_handlers($type); + if ($handlers) { + foreach ($handlers as $id => $handler) { + if ($handler->broken()) { + drupal_set_message(t('@type handler @table.@field is not available.', array( + '@type' => $info['stitle'], + '@table' => $handler->table, + '@field' => $handler->field, + )), 'error'); + $broken = TRUE; + } + } + } + } + } + + if ($broken) { + form_set_error('', t('Unable to import view.')); + } + + $form_state['view'] = &$view; +} + +/** + * Submit handler for view import + */ +function views_ui_import_submit($form, &$form_state) { + // Store in cache and then go to edit. + views_ui_cache_set($form_state['view']); + $form_state['redirect'] = 'admin/build/views/edit/' . $form_state['view']->name; +} + +/** + * The main edit view form, which is really just a save/cancel/delete button. + */ +function views_ui_edit_view_form(&$form_state, $view) { + $form['buttons']['save'] = array( + '#type' => 'submit', + '#value' => t('Save'), + '#validate' => array('views_ui_edit_view_form_validate'), + '#submit' => array('views_ui_edit_view_form_submit'), + ); + + $form['buttons']['cancel'] = array( + '#type' => 'submit', + '#value' => t('Cancel'), + '#submit' => array('views_ui_edit_view_form_cancel'), + ); + + if (is_numeric($view->vid)) { + $form['buttons']['delete'] = array( + '#type' => 'submit', + '#value' => $view->type == t('Overridden') ? t('Revert') : t('Delete'), + '#submit' => array('views_ui_edit_view_form_delete'), + ); + } + + $form_state['view'] = &$view; + return $form; +} + +/** + * Validate that a view is complete and whole. + */ +function views_ui_edit_view_form_validate($form, &$form_state) { + // Do not validate cancel or delete or revert. + if (empty($form_state['clicked_button']['#value']) || $form_state['clicked_button']['#value'] != t('Save')) { + return; + } + + $errors = $form_state['view']->validate(); + if ($errors !== TRUE) { + foreach ($errors as $error) { + form_set_error('', $error); + } + } +} + +/** + * Submit handler for the edit view form. + */ +function views_ui_edit_view_form_submit($form, &$form_state) { + // Go through and remove displayed scheduled for removal. + foreach ($form_state['view']->display as $id => $display) { + if (!empty($display->deleted)) { + unset($form_state['view']->display[$id]); + } + } + + $form_state['view']->save(); + drupal_set_message(t('The view %name has been saved.', array('%name' => $form_state['view']->name))); + + // Make sure menu items get rebuilt as neces + menu_rebuild(); + + // Clear the views cache. + cache_clear_all('*', 'cache_views'); + + // Clear the page cache. + cache_clear_all(); + + // Remove this view from cache so we can edit it properly. + views_object_cache_clear('view', $form_state['view']->name); +} + +/** + * Submit handler for the edit view form. + */ +function views_ui_edit_view_form_cancel($form, &$form_state) { + // Remove this view from cache so edits will be lost. + views_object_cache_clear('view', $form_state['view']->name); + if (empty($form['view']->vid)) { + // I seem to have to drupal_goto here because I can't get fapi to + // honor the redirect target. Not sure what I screwed up here. + drupal_goto('admin/build/views'); + } +} + +function views_ui_edit_view_form_delete($form, &$form_state) { + unset($_REQUEST['destination']); + // Redirect to the delete confirm page + $form_state['redirect'] = array('admin/build/views/delete/' . $form_state['view']->name, 'cancel=admin/build/views/edit/' . $form_state['view']->name . '&' . drupal_get_destination()); +} + +/** + * Preprocess the view edit page. + */ +function template_preprocess_views_ui_edit_view(&$vars) { + $view = &$vars['view']; + + $vars['save_button'] = drupal_get_form('views_ui_edit_view_form', $view); + + $table = views_fetch_data($view->base_table); + $vars['base_table'] = !empty($table['table']['base']['title']) ? + $table['table']['base']['title'] : t('Unknown or missing table name'); + + views_include('tabs'); + $tabs = new views_tabset; + + $vars['message'] = '
' . t("Click on an item to edit that item's details.") . '
'; + + if (!$view->set_display('default')) { + drupal_set_message(t('This view has a broken default display and cannot be used.'), 'error'); + } + + foreach ($view->display as $display) { + list($title, $body) = views_ui_display_tab($view, $display); + // The first display is the default. + $tabs->set($display->id, $title, $body); + } + + // This is the area that will render beneath the links + $form_state = array( + 'view' => &$view, + 'ajax' => FALSE, + ); + + $display_button = drupal_build_form('views_ui_add_display_form', $form_state); + $analyze_button = drupal_get_form('views_ui_analyze_view_button', $view); + $tabs->add_extra($display_button . $analyze_button); + + $vars['tabs'] = $tabs->render(); + + $form_state = array( + 'display_id' => 'default', + 'view_args' => '', + 'rerender' => FALSE, + 'no_redirect' => TRUE, + 'view' => &$view, + 'input' => array(), + ); + $vars['preview'] = drupal_build_form('views_ui_preview_form', $form_state); + + $vars['locked'] = NULL; + if (isset($view->locked) && is_object($view->locked)) { + $account = user_load($view->locked->uid); + $vars['locked'] = theme('username', $account); + $vars['lock_age'] = format_interval(time() - $view->locked->updated); + $vars['break'] = url('admin/build/views/break-lock/' . $view->name); + } + + $vars['quick_links_raw'] = array( + array( + 'title' => t('Export'), + 'alt' => t("Export this view"), + 'href' => "admin/build/views/export/$view->name", + ), + array( + 'title' => t('Clone'), + 'alt' => t("Create a copy of this view"), + 'href' => "admin/build/views/clone/$view->name", + ), + ); + + $paths = array(); + foreach ($view->display as $id => $display) { + if (!empty($display->handler) && $display->handler->has_path()) { + $path = $display->handler->get_path(); + if (strpos($path, '%') === FALSE && !isset($paths[$path])) { + $vars['quick_links_raw'][] = array( + 'title' => t('View "@display"', array('@display' => $display->display_title)), + 'alt' => t("Go to the real page for this display"), + 'href' => $path, + ); + // Displays can have the same path; no point in showing more than one link. + $paths[$path] = TRUE; + } + } + } + + $vars['quick_links'] = theme('links', $vars['quick_links_raw']); + views_add_css('views-admin'); + views_add_js('ajax'); + drupal_add_js('misc/jquery.form.js'); + + // Also add any js files required by plugins: + $plugins = views_fetch_plugin_data(); + foreach ($plugins as $type => $type_plugins) { + foreach ($type_plugins as $name => $plugin) { + if (!empty($plugin['js'])) { + foreach ($plugin['js'] as $file) { + drupal_add_js($file); + } + } + } + } + + $settings = array('views' => array('ajax' => array( + 'id' => '#views-ajax-pad', + 'title' => '#views-ajax-title', + 'defaultForm' => $vars['message'], + ))); + + drupal_add_js($settings, 'setting'); +} + +function template_preprocess_views_ui_edit_tab(&$vars) { + $view = $vars['view']; + $display = $vars['display']; + $plugin = $display->handler->definition; + + $top = $left = $middle = $right = ''; + + // If this form was submitted it was already handled, so force it not to + // submit again. + + $vars['remove'] = ''; + $vars['clone'] = ''; + if (empty($plugin['no remove'])) { + if (!empty($_POST['form_id']) && in_array($_POST['form_id'], array('views_ui_remove_display_form', 'views_ui_clone_display_form'))) { + unset($_POST['form_id']); + } + $form_state = array('view' => &$view, 'display_id' => $display->id, 'ajax' => FALSE); + $vars['remove'] = drupal_build_form('views_ui_remove_display_form', $form_state); + $vars['clone'] = drupal_build_form('views_ui_clone_display_form', $form_state); + } + + // basic fields + $vars['title'] = check_plain($display->display_title); + $vars['description'] = check_plain($plugin['help']); + + // Special fields if tihs is the default display. + $vars['default'] = ($display->id == 'default'); + $vars['details_class'] = views_ui_item_css('details'); + if (!empty($view->changed_sections['details'])) { + $vars['details_changed'] = TRUE; + } + + $tag = empty($view->tag) ? t('None') : $view->tag; + $vars['details'] = t('Description') . '/' . t('Tag') . ': ' . l($tag, "admin/build/views/nojs/details/$view->name", array('attributes' => array('class' => 'views-ajax-link'))); + + // Calculate options from display plugin. + $options = $categories = array(); + $display->handler->options_summary($categories, $options); + + // Build all of the options we were returned and put them into the + // category data fields. + foreach ($options as $id => $option) { + if (empty($categories[$option['category']]['data'])) { + $categories[$option['category']]['data'] = array(); + } + $categories[$option['category']]['data'][$id] = array(); + $data = &$categories[$option['category']]['data'][$id]; + $data['content'] = ''; + $data['links'] = ''; + $data['overridden'] = FALSE; + $data['defaulted'] = FALSE; + + // If there are optional links, build them first so they float properly. + if (!empty($option['links'])) { + foreach ($option['links'] as $link_id => $link_value) { + $data['links'] .= $display->handler->option_link($link_value, $link_id, 'views-button-configure'); + } + } + if (!empty($option['title'])) { + $data['content'] .= $option['title'] . ': '; + } + + $data['content'] .= $display->handler->option_link($option['value'], $id, '', empty($option['desc']) ? '' : $option['desc']); + if (!empty($display->handler->options['defaults'][$id])) { + $display_id = 'default'; + $data['defaulted'] = TRUE; + } + else { + $display_id = $display->id; + if (!$display->handler->is_default_display()) { + if ($display->handler->defaultable_sections($id)) { + $data['overridden'] = TRUE; + } + } + } + $data['class'] = views_ui_item_css($display_id . '-' . $id); + if (!empty($view->changed_sections[$display_id . '-' . $id])) { + $data['changed'] = TRUE; + } + } + + $vars['categories'] = $categories; + + // Add a help icon + if (isset($plugin['help topic'])) { + $vars['display_help_icon'] = theme('advanced_help_topic', $plugin['module'], $plugin['help topic']); + } + else { + $vars['display_help_icon'] = ''; + } + + // Fetch style plugin info because it has some effect on how/what we render. + $style_plugin = $display->handler->get_plugin(); + + $vars['fields'] = ''; + $vars['fields'] = theme('views_ui_edit_item', 'field', $view, $display, !($style_plugin && $style_plugin->uses_fields())); + $vars['relationships'] = theme('views_ui_edit_item', 'relationship', $view, $display); + $vars['arguments'] = theme('views_ui_edit_item', 'argument', $view, $display); + $vars['filters'] = theme('views_ui_edit_item', 'filter', $view, $display); + $vars['sorts'] = theme('views_ui_edit_item', 'sort', $view, $display); +} + +/** + * Generate the summary output for a single display to render in a tab. + */ +function views_ui_display_tab($view, $display) { + if (isset($display->handler)) { + $plugin = $display->handler->definition; + } + if (empty($plugin)) { + $title = isset($display->display_title) ? $display->display_title : t('Invalid'); + return array($title, t("Error: Display @display refers to a plugin named '@plugin', but that plugin doesn't exist!", array('@display' => $display->id, '@plugin' => $display->display_plugin))); + + // @todo We can do a better 'plugin does not exist' tab. + } + + // The display should always be initialized prior to this call. + if (empty($display->handler)) { + return FALSE; + } + + $body = theme('views_ui_edit_tab', $view, $display); + return array($display->display_title, $body); +} + +/** + * Add information about a section to a display. + */ +function template_preprocess_views_ui_edit_item(&$vars) { + $type = $vars['type']; + $view = $vars['view']; + $display = $vars['display']; + + $types = views_object_types(); + + $vars['overridden'] = FALSE; + $vars['defaulted'] = FALSE; + + if ($vars['no_fields']) { + $vars['title'] = $types[$type]['title']; + $vars['item_help_icon'] = theme('advanced_help_topic', 'views', $type); + $vars['rearrange'] = NULL; + $vars['add'] = NULL; + return; + } + + $vars['rearrange'] = l('' . t('Rearrange') . '', "admin/build/views/nojs/rearrange/$view->name/$display->id/$type", array('attributes' => array('class' => 'views-button-rearrange views-ajax-link', 'title' => t('Rearrange')), 'html' => true)); + + $vars['add'] = l('' . t('Add') . '', "admin/build/views/nojs/add-item/$view->name/$display->id/$type", array('attributes' => array('class' => 'views-button-add views-ajax-link', 'title' => t('Add')), 'html' => true)); + + if (!$display->handler->is_default_display()) { + if (!$display->handler->is_defaulted($types[$type]['plural'])) { + $vars['overridden'] = TRUE; + } + else { + $vars['defaulted'] = TRUE; + } + } + + if ($display->display_plugin != 'default') { + $vars['title'] = l($types[$type]['title'], "admin/build/views/nojs/config-type/$view->name/$display->id/$type", array('attributes' => array('class' => 'views-ajax-link'))); + } + else { + $vars['title'] = $types[$type]['title']; + } + + $fields = array(); + + static $relationships = NULL; + if (!isset($relationships)) { + // Get relationship labels + $relationships = array(); + // @todo: get_handlers() + $handlers = $display->handler->get_option('relationships'); + if ($handlers) { + foreach ($handlers as $id => $relationship) { + $handler = views_get_handler($relationship['table'], $relationship['field'], 'relationship'); + if (empty($handler)) { + continue; + } + $handler->init($view, $relationship); + $relationships[$id] = $handler->label(); + } + } + } + + // @todo: get_handlers() + foreach ($display->handler->get_option($types[$type]['plural']) as $id => $field) { + $fields[$id] = array(); + + $handler = views_get_handler($field['table'], $field['field'], $type); + if (empty($handler)) { + $fields[$id]['class'] = 'broken'; + $field_name = t('Broken/missing handler: @table > @field', array('@table' => $field['table'], '@field' => $field['field'])); + $fields[$id]['title'] = l($field_name, "admin/build/views/nojs/config-item/$view->name/$display->id/$type/$id", array('attributes' => array('class' => 'views-ajax-link'), 'html' => TRUE)); + $fields[$id]['info'] = ''; + continue; + } + $handler->init($view, $field); + + $field_name = $handler->ui_name(TRUE); + if (!empty($field['relationship']) && !empty($relationships[$field['relationship']])) { + $field_name = '(' . $relationships[$field['relationship']] . ') ' . $field_name; + } + + $fields[$id]['title'] = l($field_name, "admin/build/views/nojs/config-item/$view->name/$display->id/$type/$id", array('attributes' => array('class' => 'views-ajax-link'), 'html' => TRUE)); + $fields[$id]['class'] = views_ui_item_css($display->id . '-' . $type . '-' . $id); + if (!empty($view->changed_sections[$display->id . '-' . $type . '-' . $id])) { + $fields[$id]['changed'] = TRUE; + } + $fields[$id]['info'] = $handler->admin_summary(); + + if ($handler->has_extra_options()) { + $fields[$id]['links'] = l('' . t('Settings') . '', "admin/build/views/nojs/config-item-extra/$view->name/$display->id/$type/$id", array('attributes' => array('class' => 'views-button-configure views-ajax-link', 'title' => t('Settings')), 'html' => true)); + } + + if ($handler->needs_style_plugin()) { + $style_plugin = views_fetch_plugin_data('style', $handler->options['style_plugin']); + $style_title = empty($style_plugin['title']) ? t('Missing style plugin') : $style_plugin['title']; + $pid = $id . '-style-plugin'; + + if (!empty($style_plugin['uses options'])) { + $fields[$pid]['links'] = l('' . t('Change settings for this style') . '', "admin/build/views/nojs/config-style/$view->name/$display->id/$type/$id", array('attributes' => array('class' => 'views-button-configure views-ajax-link', 'title' => t('Settings')), 'html' => true)); + } + + $fields[$pid]['title'] = ' ' . t('  Style: !style', array('!style' => l($style_title, "admin/build/views/nojs/change-style/$view->name/$display->id/$type/$id", array('attributes' => array('class' => 'views-ajax-link'))))); + $fields[$pid]['class'] = views_ui_item_css($display->id . '-' . $type . '-' . $pid); + if (!empty($view->changed_sections[$display->id . '-' . $type . '-' . $pid])) { + $fields[$pid]['changed'] = TRUE; + } + $fields[$pid]['info'] = ''; + } + } + + $vars['fields'] = $fields; + $vars['item_help_icon'] = theme('advanced_help_topic', 'views', $type); +} + +/** + * Regenerate the tabs for AJAX updates. + */ +function views_ui_regenerate_tabs(&$view, $display_id = NULL, $object = NULL) { + if (empty($display_id)) { + $displays = array_keys($view->display); + } + elseif (!is_array($display_id)) { + $displays = array($display_id); + if ($display_id != 'default') { + $displays[] = 'default'; + } + } + else { + $displays = $display_id; + } + + if (!$view->set_display('default')) { + views_ajax_render(t('Invalid display id found while regenerating tabs')); + } + + if (!is_object($object)) { + $object = new stdClass(); + } + + $object->replace = array(); + foreach ($displays as $id) { + list($title, $body) = views_ui_display_tab($view, $view->display[$id]); + $object->replace['#views-tab-' . $id] = $body; + $object->replace['#views-tab-title-' . $id] = check_plain($title); + } + + if (!empty($view->changed)) { + $object->changed = TRUE; + } + + views_ajax_render($object); +} + +/** + * Provide standard buttons for the forms to make it easy. Also provide + * a hidden op operator because the forms plugin doesn't seem to properly + * provide which button was clicked. + */ +function views_ui_standard_form_buttons(&$form, &$form_state, $form_id, $name = NULL, $third = NULL, $submit = NULL) { + $form['buttons'] = array( + '#prefix' => '
', + '#suffix' => '
', + ); + + if (empty($name)) { + $name = t('Update'); + } + + // Add the override and update button + if ($name == t('Update default display')) { + $form['buttons']['override_update'] = array( + '#type' => 'submit', + '#value' => t('Update and override'), + '#submit' => array( + 'views_ui_edit_display_form_override_update_section', + 'views_ui_standard_submit', + 'views_ui_edit_display_form_override_update', + ), + ); + } + + if (empty($form_state['ok_button'])) { + // but be sure submit button validates! + $form['buttons']['submit'] = array( + '#type' => 'submit', + '#value' => $name, + '#submit' => array('views_ui_standard_submit', $form_id . '_submit'), + ); + } + + $cancel_submit = function_exists($form_id . '_cancel') ? $form_id . '_cancel' : 'views_ui_standard_cancel'; + $form['buttons']['cancel'] = array( + '#type' => 'submit', + '#value' => empty($form_state['ok_button']) ? t('Cancel') : t('Ok'), + '#submit' => array($cancel_submit), + '#validate' => array(), + ); + + if ($third) { + if (empty($submit)) { + $submit = 'third'; + } + $third_submit = function_exists($form_id . '_' . $submit) ? $form_id . '_' . $submit : 'views_ui_standard_cancel'; + + $form['buttons'][$submit] = array( + '#type' => 'submit', + '#value' => $third, + '#validate' => array(), + '#submit' => array($third_submit), + ); + } + + // Compatibility, to be removed later: + // We used to set these items on the form, but now we want them on the $form_state: + if (isset($form['#title'])) { + $form_state['title'] = $form['#title']; + } + if (isset($form['#help_topic'])) { + $form_state['help_topic'] = $form['#help_topic']; + } + if (isset($form['#help_module'])) { + $form_state['help_module'] = $form['#help_module']; + } + if (isset($form['#url'])) { + $form_state['url'] = $form['#url']; + } + if (isset($form['#js'])) { + if (!empty($form_state['js settings']) && is_array($form_state['js settings'])) { + $form_state['js settings'] = array_merge($form_state['js settings'], $form['#js']); + } + else { + $form_state['js settings'] = $form['#js']; + } + } + if (isset($form['#section'])) { + $form_state['#section'] = $form['#section']; + } + // Finally, we never want these cached -- our object cache does that for us. + $form['#no_cache'] = TRUE; + + // If this isn't an ajaxy form, then we want to set the title. + if (!empty($form['#title'])) { + drupal_set_title($form['#title']); + } + views_add_css('views-admin'); +} + +/** + * Basic submit handler applicable to all 'standard' forms + */ +function views_ui_standard_submit($form, &$form_state) { + if (!empty($form['#section'])) { + $form_state['view']->changed_sections[$form['#section']] = TRUE; + } +} + +/** + * Submit handler for cancel button + */ +function views_ui_standard_cancel($form, &$form_state) { + $form_state['redirect'] = 'admin/build/views/edit/' . $form_state['view']->name; +} + +// -------------------------------------------------------------------------- +// Various subforms for editing the pieces of a view. + +function views_ui_ajax_forms($key = NULL) { + $forms = array( + 'display' => array( + 'form_id' => 'views_ui_edit_display_form', + 'args' => array('section'), + ), + 'remove-display' => array( + 'form_id' => 'views_ui_remove_display_form', + 'args' => array(), + ), + 'config-type' => array( + 'form_id' => 'views_ui_config_type_form', + 'args' => array('type'), + ), + 'rearrange' => array( + 'form_id' => 'views_ui_rearrange_form', + 'args' => array('type'), + ), + 'add-item' => array( + 'form_id' => 'views_ui_add_item_form', + 'args' => array('type'), + ), + 'config-item' => array( + 'form_id' => 'views_ui_config_item_form', + 'args' => array('type', 'id'), + ), + 'config-item-extra' => array( + 'form_id' => 'views_ui_config_item_extra_form', + 'args' => array('type', 'id'), + ), + 'change-style' => array( + 'form_id' => 'views_ui_change_style_form', + 'args' => array('type', 'id'), + ), + 'config-style' => array( + 'form_id' => 'views_ui_config_style_form', + 'args' => array('type', 'id'), + ), + ); + + if ($key) { + return !empty($forms[$key]) ? $forms[$key] : NULL; + } + + return $forms; +} + +/** + * Build a form identifier that we can use to see if one form + * is the same as another. Since the arguments differ slightly + * we do a lot of spiffy concenation here. + */ +function views_ui_build_identifier($key, $view, $display_id, $args) { + $form = views_ui_ajax_forms($key); + $identifier = implode('-', array($key, $view->name, $display_id)); + + foreach ($form['args'] as $id) { + $arg = (!empty($args)) ? array_shift($args) : NULL; + $identifier .= '-' . $arg; + } + return $identifier; +} + +/** + * Build up a $form_state object suitable for use with drupal_build_form + * based on known information about a form. + */ +function views_ui_build_form_state($js, $key, &$view, $display_id, $args) { + $form = views_ui_ajax_forms($key); + // Build up form state + $form_state = array( + 'form_key' => $key, + 'form_id' => $form['form_id'], + 'view' => &$view, + 'ajax' => $js, + 'display_id' => $display_id, + 'no_redirect' => TRUE, + ); + + foreach ($form['args'] as $id) { + $form_state[$id] = (!empty($args)) ? array_shift($args) : NULL; + } + + return $form_state; +} + +/** + * Create the URL for one of our standard AJAX forms based upon known + * information about the form. + */ +function views_ui_build_form_url($form_state) { + $form = views_ui_ajax_forms($form_state['form_key']); + $ajax = empty($form_state['ajax']) ? 'nojs' : 'ajax'; + $name = $form_state['view']->name; + $url = "admin/build/views/$ajax/$form_state[form_key]/$name/$form_state[display_id]"; + foreach ($form['args'] as $arg) { + $url .= '/' . $form_state[$arg]; + } + return $url; +} + +/** + * Add another form to the stack; clicking 'update' will go to this form + * rather than closing the ajax pad. + */ +function views_ui_add_form_to_stack($key, &$view, $display_id, $args, $top = FALSE) { + if (empty($view->stack)) { + $view->stack = array(); + } + + $stack = array(views_ui_build_identifier($key, $view, $display_id, $args), $key, &$view, $display_id, $args); + if ($top) { + array_unshift($view->stack, $stack); + } + else { + $view->stack[] = $stack; + } +} + +/** + * Generic entry point to handle forms. + * + * We do this for consistency and to make it easy to chain forms + * together. This only works for forms that use both $view + * and $display_id, so we have a couple of ajax forms that we don't + * use with this system. + */ +function views_ui_ajax_form($js, $key, $view, $display_id) { + $form = views_ui_ajax_forms($key); + if (empty($form)) { + return drupal_not_found(); + } + + views_include('ajax'); + $args = func_get_args(); + // Remove the known args + array_splice($args, 0, 4); + + $form_state = views_ui_build_form_state($js, $key, $view, $display_id, $args); + // check to see if this is the top form of the stack. If it is, pop + // it off; if it isn't, the user clicked somewhere else and the stack is + // now irrelevant. + if (!empty($view->stack)) { + $identifier = views_ui_build_identifier($key, $view, $display_id, $args); + $top = array_shift($view->stack); + if (array_shift($top) != $identifier) { + $view->stack = array(); + } + } + + $output = views_ajax_form_wrapper($form_state['form_id'], $form_state); + + if (!$output) { + // Sometimes we need to re-generate the form for multi-step type operations. + $object = NULL; + if (!empty($view->stack)) { + $stack = $view->stack; // copy so the next shift doesn't break the array + $top = array_shift($stack); + $top[0] = $js; // change identifier into $js setting + $stepview = $top[2]; // Change view into a reference [#452384] + $top[2] = &$stepview; + $form_state = call_user_func_array('views_ui_build_form_state', $top); + $form_state['input'] = array(); // this is a new form, make sure it + // doesn't try to inherit $_POST info. + if (!$js) { + return drupal_goto(views_ui_build_form_url($form_state)); + } + $object = views_ajax_form_wrapper($form_state['form_id'], $form_state); + $object->url = url(views_ui_build_form_url($form_state)); + } + else if (!$js) { + // if nothing on the stack, non-js forms just go back to the main view editor. + return drupal_goto("admin/build/views/edit/$view->name"); + } + // regenerate all tabs because changes to the default tab could ripple. + return views_ui_regenerate_tabs($view, NULL, $object); + } + + return ($js) ? views_ajax_render($output) : $output; +} + +/** + * AJAX callback to add a display. + */ +function views_ui_add_display($js, $view) { + views_include('ajax'); + $form_state = array( + 'view' => &$view, + 'ajax' => $js, + ); + + $output = views_ajax_form_wrapper('views_ui_add_display_form', $form_state); + + if ($js) { + // If we don't have an output object, it was submitted. Set up the submission. + if (empty($output)) { + $id = $form_state['id']; + + // Make sure the new display is active + if (!$view->set_display('default')) { + views_ajax_render(t('Unable to initialize default display')); + } + + // Render the new display + list($title, $body) = views_ui_display_tab($view, $view->display[$id]); + + // Instruct the javascript on the browser to render the new tab. + $output = new stdClass; + $output->tab = array('#views-tab-' . $id => array('title' => $title, 'body' => $body)); + } + // Render the command object. This automatically exits. + views_ajax_render($output); + } + + // But the non-js variant will return output if it didn't redirect us. + return $output; +} + +/** + * Form to add a display to a view. + */ +function views_ui_add_display_form(&$form_state) { + $view = &$form_state['view']; + + $form['display']['display'] = array( + '#type' => 'select', + '#options' => views_fetch_plugin_names('display'), + '#default_value' => 'page', + ); + + $form['display']['add_display'] = array( + '#type' => 'submit', + '#value' => t('Add display'), + '#submit' => array('views_ui_add_display_form_submit'), + ); + + $form['#id'] = 'views-add-display-form'; + $form['#attributes'] = array('class' => 'views-ajax-form'); + $form['#action'] = url("admin/build/views/nojs/add-display/$view->name"); + + return $form; +} + +/** + * Submit handler to add a display to a view. + */ +function views_ui_add_display_form_submit($form, &$form_state) { + // Create the new display + $plugin = $form_state['values']['display']; + $form_state['id'] = $form_state['view']->add_display($plugin); + + // Store in cache + views_ui_cache_set($form_state['view']); + + // Send it back + $form_state['redirect'] = array('admin/build/views/edit/' . $form_state['view']->name, NULL, 'views-tab-' . $form_state['id']); +} + +/** + * AJAX callback to add a display. + */ +function views_ui_clone_display($js, $view, $id) { + views_include('ajax'); + $form_state = array( + 'view' => &$view, + 'ajax' => $js, + 'display_id' => $id, + ); + + $output = views_ajax_form_wrapper('views_ui_clone_display_form', $form_state); + + if ($js) { + // If we don't have an output object, it was submitted. Set up the submission. + if (empty($output)) { + $id = $form_state['id']; + + // Make sure the new display is active + if (!$view->set_display('default')) { + views_ajax_render(t('Unable to initialize default display')); + } + + // Render the new display + list($title, $body) = views_ui_display_tab($view, $view->display[$id]); + + // Instruct the javascript on the browser to render the new tab. + $output = new stdClass; + $output->tab = array('#views-tab-' . $id => array('title' => $title, 'body' => $body)); + } + // Render the command object. This automatically exits. + views_ajax_render($output); + } + + // But the non-js variant will return output if it didn't redirect us. + return $output; +} + +/** + * From to clone a display from a view. + */ +function views_ui_clone_display_form(&$form_state) { + $view = &$form_state['view']; + $display_id = $form_state['display_id']; + + $form['clone_display'] = array( + '#type' => 'submit', + '#value' => t('Clone display'), + '#submit' => array('views_ui_clone_display_form_submit'), + ); + + $form['#id'] = 'views-clone-display-form'; + $form['#action'] = url("admin/build/views/nojs/clone-display/$view->name/$display_id"); + $form['#attributes'] = array('class' => 'views-ajax-form'); + + return $form; +} + +/** + * Submit handler to add a clone to a display from a view. + */ +function views_ui_clone_display_form_submit($form, &$form_state) { + // Create the new display + $id = $form_state['display_id']; + $display = $form_state['view']->display[$id]; + + $new_id = $form_state['view']->add_display($display->display_plugin); + $form_state['id'] = $new_id; + + // Replace the new display by a copy of the old + $form_state['view']->display[$new_id] = drupal_clone($display); + $form_state['view']->display[$new_id]->id = $new_id; + + // Store in cache + views_ui_cache_set($form_state['view']); + + // Send it back + $form_state['redirect'] = array('admin/build/views/edit/' . $form_state['view']->name, NULL, 'views-tab-' . $new_id); +} + +/** + * Form to remove a display from a view. + */ +function views_ui_remove_display_form(&$form_state) { + $view = &$form_state['view']; + $display_id = $form_state['display_id']; + + if (empty($view->display[$display_id]->deleted)) { + $form['display'] = array( + '#prefix' => '
', + '#suffix' => '
', + ); + $form['remove_display'] = array( + '#type' => 'submit', + '#value' => t('Remove display'), + '#submit' => array('views_ui_remove_display_form_submit'), + ); + } + else { + $form['display'] = array( + '#prefix' => '
', + '#suffix' => '
', + ); + $form['restore_display'] = array( + '#type' => 'submit', + '#value' => t('Restore display'), + '#submit' => array('views_ui_remove_display_form_restore'), + ); + } + $form['#action'] = url("admin/build/views/nojs/remove-display/$view->name/$display_id"); + $form['#attributes'] = array('class' => 'views-ajax-form'); + + return $form; +} + +/** + * Submit handler to add a remove to a display from a view. + */ +function views_ui_remove_display_form_submit($form, &$form_state) { + // Create the new display + $plugin = views_fetch_plugin_data('display', $form_state['view']->display[$form_state['display_id']]->display_plugin); + if (empty($plugin['no remove'])) { + $id = $form_state['display_id']; + $form_state['view']->display[$id]->deleted = TRUE; + + // Store in cache + views_ui_cache_set($form_state['view']); + } +} + +/** + * Submit handler to add a restore a removed display to a view. + */ +function views_ui_remove_display_form_restore($form, &$form_state) { + // Create the new display + $id = $form_state['display_id']; + $form_state['view']->display[$id]->deleted = FALSE; + + // Store in cache + views_ui_cache_set($form_state['view']); +} + +/** + * Page callback to display analysis information on a view. + */ +function views_ui_analyze_view($js, $view) { + views_include('ajax'); + $form_state = array( + 'view' => &$view, + 'ajax' => $js, + ); + + $output = views_ajax_form_wrapper('views_ui_analyze_view_form', $form_state); + + if ($js) { + // If we don't have an output object, it was submitted. Set up the submission. + if (empty($output)) { + return views_ui_regenerate_tabs($view); + } + return views_ajax_render($output); + + } + return $output; +} + +/** + * This form doesn't particularly do much; it's really just providing a link + * but a button seems like it would be nicer here. + * + * It has no submit or anything, as we will never actually submit this form + * where the form is placed. + */ +function views_ui_analyze_view_button(&$form_state, $view) { + $form['#action'] = url("admin/build/views/nojs/analyze/$view->name"); + $form['#attributes'] = array('class' => 'views-ajax-form'); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Analyze'), + ); + + return $form; +} + +/** + * Form constructor callback to display analysis information on a view + */ +function views_ui_analyze_view_form(&$form_state) { + $view = &$form_state['view']; + + $form['#title'] = t('View analysis'); + $form['#section'] = 'analyze'; + + views_include('analyze'); + $messages = views_analyze_view($view); + + $form['analysis'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#value' => views_analyze_format_result($view, $messages), + ); + + // Inform the standard button function that we want an OK button. + $form_state['ok_button'] = TRUE; + views_ui_standard_form_buttons($form, $form_state, 'views_ui_analyze_view_form'); + return $form; +} + +/** + * Submit handler for views_ui_analyze_view_form + */ +function views_ui_analyze_view_form_submit($form, &$form_state) { + $form_state['redirect'] = 'admin/build/views/edit/' . $form_state['view']->name; +} + +/** + * Page callback to edit details of a view. + */ +function views_ui_edit_details($js, $view) { + views_include('ajax'); + $form_state = array( + 'view' => &$view, + 'ajax' => $js, + ); + + $output = views_ajax_form_wrapper('views_ui_edit_details_form', $form_state); + + if ($js) { + // If we don't have an output object, it was submitted. Set up the submission. + if (empty($output)) { + return views_ui_regenerate_tabs($view); + } + return views_ajax_render($output); + + } + return $output; +} + +/** + * Form constructor callback to edit details of a view + */ +function views_ui_edit_details_form(&$form_state) { + $view = &$form_state['view']; + + $form['#title'] = t('View details'); + $form['#section'] = 'details'; + + $form['description'] = array( + '#type' => 'textfield', + '#title' => t('View description'), + '#description' => t('This description will appear on the Views administrative UI to tell you what the view is about.'), + '#default_value' => $view->description, + ); + + $form['tag'] = array( + '#type' => 'textfield', + '#title' => t('View tag'), + '#description' => t('Enter an optional tag for this view; it is used only to help sort views on the administrative page.'), + '#default_value' => $view->tag, + '#autocomplete_path' => 'admin/views/ajax/autocomplete/tag', + ); + + views_ui_standard_form_buttons($form, $form_state, 'views_ui_edit_details_form'); + return $form; +} + +/** + * Submit handler for views_ui_edit_details_form + */ +function views_ui_edit_details_form_submit($form, &$form_state) { + $form_state['view']->description = $form_state['values']['description']; + $form_state['view']->tag = $form_state['values']['tag']; + views_ui_cache_set($form_state['view']); + $form_state['redirect'] = 'admin/build/views/edit/' . $form_state['view']->name; +} + +/** + * Form constructor callback to edit display of a view + */ +function views_ui_edit_display_form(&$form_state) { + $view = &$form_state['view']; + $display_id = $form_state['display_id']; + $section = $form_state['section']; + + if (!$view->set_display($display_id)) { + views_ajax_render(t('Invalid display id @display', array('@display' => $display_id))); + } + $display = &$view->display[$display_id]; + + // Get form from the handler. + $display->handler->options_form($form, $form_state); + $name = NULL; + if (isset($form_state['update_name'])) { + $name = $form_state['update_name']; + } + + views_ui_standard_form_buttons($form, $form_state, 'views_ui_edit_display_form', $name); + return $form; +} + +/** + * Validate handler for views_ui_edit_display_form + */ +function views_ui_edit_display_form_validate($form, &$form_state) { + $display = &$form_state['view']->display[$form_state['display_id']]; + $display->handler->options_validate($form, $form_state); +} + +/** + * Submit handler for views_ui_edit_display_form + */ +function views_ui_edit_display_form_submit($form, &$form_state) { + $display = &$form_state['view']->display[$form_state['display_id']]; + $display->handler->options_submit($form, $form_state); + + views_ui_cache_set($form_state['view']); +} + +/** + * Override handler for views_ui_edit_display_form + */ +function views_ui_edit_display_form_override($form, &$form_state) { + $display = &$form_state['view']->display[$form_state['display_id']]; + $display->handler->options_override($form, $form_state); + + views_ui_cache_set($form_state['view']); + $form_state['rerender'] = TRUE; + $form_state['rebuild'] = TRUE; +} +/** + * Override handler and submit views_ui_edit_display_form + */ +function views_ui_edit_display_form_override_update(&$form, &$form_state) { + $display = &$form_state['view']->display[$form_state['display_id']]; + $display->handler->options_override($form, $form_state); + $display->handler->options_submit($form, $form_state); + views_ui_cache_set($form_state['view']); +} + +/** + * Override handler and submit views_ui_edit_display_form + */ +function views_ui_edit_display_form_override_update_section(&$form, &$form_state) { + // Update the #section so it knows what to mark changed. + $form['#section'] = str_replace('default-', $form_state['display_id'] . '-', $form['#section']); +} + +/** + * Form to config items in the views UI. + */ +function views_ui_config_type_form(&$form_state) { + $view = &$form_state['view']; + $display_id = $form_state['display_id']; + $type = $form_state['type']; + + $types = views_object_types(); + if (!$view->set_display($display_id)) { + views_ajax_render(t('Invalid display id @display', array('@display' => $display_id))); + } + $display = &$view->display[$display_id]; + $form['#title'] = check_plain($display->display_title) . ': '; + $form['#title'] .= t('Configure @type', array('@type' => $types[$type]['ltitle'])); + $form['#section'] = $display_id . 'config-item'; + + if ($display->handler->defaultable_sections($types[$type]['plural'])) { + $form_state['section'] = $types[$type]['plural']; + $display->handler->add_override_button($form, $form_state, $form_state['section']); + } + + if (!empty($types[$type]['options']) && function_exists($types[$type]['options'])) { + $options = $type . '_options'; + $form[$options] = array('#tree' => TRUE); + $types[$type]['options']($form, $form_state); + } + + $name = NULL; + if (isset($form_state['update_name'])) { + $name = $form_state['update_name']; + } + + views_ui_standard_form_buttons($form, $form_state, 'views_ui_config_type_form', $name); + return $form; +} + +/** + * Submit handler for type configuration form + */ +function views_ui_config_type_form_submit($form, &$form_state) { + $types = views_object_types(); + $display = &$form_state['view']->display[$form_state['display_id']]; + + // Store in cache + views_ui_cache_set($form_state['view']); +} + +/** + * Configure settings particular to filters. + */ +function views_ui_config_filters_form(&$form, &$form_state) { + +} + +/** + * Form to rearrange items in the views UI. + */ +function views_ui_rearrange_form(&$form_state) { + $view = &$form_state['view']; + $display_id = $form_state['display_id']; + $type = $form_state['type']; + + $types = views_object_types(); + if (!$view->set_display($display_id)) { + views_ajax_render(t('Invalid display id @display', array('@display' => $display_id))); + } + $display = &$view->display[$display_id]; + $form['#title'] = check_plain($display->display_title) . ': '; + $form['#title'] .= t('Rearrange @type', array('@type' => $types[$type]['ltitle'])); + $form['#section'] = $display_id . 'rearrange-item'; + + if ($display->handler->defaultable_sections($types[$type]['plural'])) { + $form_state['section'] = $types[$type]['plural']; + $display->handler->add_override_button($form, $form_state, $form_state['section']); + } + + $count = 0; + + // Get relationship labels + $relationships = array(); + // @todo: get_handlers() + foreach ($display->handler->get_option('relationships') as $id => $relationship) { + $handler = views_get_handler($relationship['table'], $relationship['field'], 'relationship'); + if (empty($handler)) { + continue; + } + $handler->init($view, $relationship); + $relationships[$id] = $handler->label(); + } + + // @todo: get_handlers() + $form['fields'] = array('#tree' => TRUE); + foreach ($display->handler->get_option($types[$type]['plural']) as $id => $field) { + $form['fields'][$id] = array('#tree' => TRUE); + $form['fields'][$id]['weight'] = array( + '#type' => 'weight', + '#delta' => 200, + '#default_value' => ++$count, + ); + $handler = views_get_handler($field['table'], $field['field'], $type); + if ($handler) { + $handler->init($view, $field); + $name = $handler->ui_name() . ' ' . $handler->admin_summary(); + if (!empty($field['relationship']) && !empty($relationships[$field['relationship']])) { + $name = '(' . $relationships[$field['relationship']] . ') ' . $name; + } + + $form['fields'][$id]['name'] = array( + '#value' => $name, + ); + } + else { + $form['fields'][$id]['name'] = array('#value' => t('Broken field @id', array('@id' => $id))); + } + $form['fields'][$id]['removed'] = array( + '#type' => 'checkbox', + '#id' => 'views-removed-' . $id, + '#attributes' => array('class' => 'views-remove-checkbox'), + '#default_value' => 0, + ); + } + + // Add javascript settings that will be added via $.extend for tabledragging + $form['#js']['tableDrag']['arrange']['weight'][0] = array( + 'target' => 'weight', + 'source' => NULL, + 'relationship' => 'sibling', + 'action' => 'order', + 'hidden' => TRUE, + 'limit' => 0, + ); + + $name = NULL; + if (isset($form_state['update_name'])) { + $name = $form_state['update_name']; + } + + views_ui_standard_form_buttons($form, $form_state, 'views_ui_rearrange_form'); + return $form; +} + +/** + * Turn the rearrange form into a proper table + */ +function theme_views_ui_rearrange_form($form) { + $rows = array(); + foreach (element_children($form['fields']) as $id) { + if (isset($form['fields'][$id]['name'])) { + $row = array(); + $row[] = drupal_render($form['fields'][$id]['name']); + $form['fields'][$id]['weight']['#attributes']['class'] = 'weight'; + $row[] = drupal_render($form['fields'][$id]['weight']); + $row[] = drupal_render($form['fields'][$id]['removed']) . l('' . t('Remove') . '', 'javascript:void()', array('attributes' => array('id' => 'views-remove-link-' . $id, 'class' => 'views-button-remove views-remove-link', 'alt' => t('Remove this item'), 'title' => t('Remove this item')), 'html' => true)); + + $rows[] = array('data' => $row, 'class' => 'draggable', 'id' => 'views-row-' . $id); + } + } + if (empty($rows)) { + $rows[] = array(array('data' => t('No fields available.'), 'colspan' => '2')); + } + + $header = array('', t('Weight'), t('Remove')); + drupal_add_tabledrag('arrange', 'order', 'sibling', 'weight'); + $output = drupal_render($form['override']); + $output .= theme('table', $header, $rows, array('id' => 'arrange')); + $output .= drupal_render($form); + return $output; + +} + +/** + * Submit handler for rearranging form + */ +function views_ui_rearrange_form_submit($form, &$form_state) { + $types = views_object_types(); + $display = &$form_state['view']->display[$form_state['display_id']]; + + $old_fields = $display->handler->get_option($types[$form_state['type']]['plural']); + $new_fields = $order = array(); + + // Make an array with the weights + foreach ($form_state['values']['fields'] as $field => $info) { + // add each value that is a field with a weight to our list, but only if + // it has had its 'removed' checkbox checked. + if (is_array($info) && isset($info['weight']) && empty($info['removed'])) { + $order[$field] = $info['weight']; + } + } + + // Sort the array + asort($order); + + // Create a new list of fields in the new order. + foreach (array_keys($order) as $field) { + $new_fields[$field] = $old_fields[$field]; + } + $display->handler->set_option($types[$form_state['type']]['plural'], $new_fields); + + // Store in cache + views_ui_cache_set($form_state['view']); +} + +/** + * Form to add_item items in the views UI. + */ +function views_ui_add_item_form(&$form_state) { + $view = &$form_state['view']; + $display_id = $form_state['display_id']; + $type = $form_state['type']; + + if (!$view->set_display($display_id)) { + views_ajax_render(t('Invalid display id @display', array('@display' => $display_id))); + } + $display = &$view->display[$display_id]; + + $types = views_object_types(); + $form['#title'] = check_plain($display->display_title) . ': '; + $form['#title'] .= t('Add @type', array('@type' => $types[$type]['ltitle'])); + $form['#section'] = $display_id . 'add-item'; + + // Figure out all the base tables allowed based upon what the relationships provide. + $base_tables = $view->get_base_tables(); + $options = views_fetch_fields(array_keys($base_tables), $type); + + if (!empty($options)) { + $groups = array('all' => t('- All -')); + $form['group'] = array( + '#type' => 'select', + '#title' => t('Groups'), + '#options' => array(), + '#attributes' => array('class' => 'views-master-dependent'), + ); + + $form['name'] = array( + '#prefix' => '
', + '#suffix' => '
', + '#tree' => TRUE, + '#default_value' => 'all', + ); + + // Group options first to simplify the DOM objects that Views + // dependent JS will act upon. + $grouped_options = array(); + foreach ($options as $key => $option) { + $group = preg_replace('/[^a-z0-9]/', '-', strtolower($option['group'])); + $groups[$group] = $option['group']; + $grouped_options[$group][$key] = $option; + } + + foreach ($grouped_options as $group => $group_options) { + $form['name'][$group . '_start'] = array('#type' => 'markup', '#value' => '
'); + foreach ($group_options as $key => $option) { + $form['name'][$key] = array( + '#type' => 'checkbox', + '#title' => t('!group: !field', array('!group' => $option['group'], '!field' => $option['title'])), + '#description' => $option['help'], + '#return_value' => $key, + ); + } + $form['name'][$group . '_end'] = array('#type' => 'markup', '#value' => '
'); + } + + $form['group']['#options'] = $groups; + } + else { + $form['markup'] = array( + '#value' => '
' . t('There are no @types available to add.', array('@types' => $types[$type]['ltitle'])) . '
', + ); + } + views_ui_standard_form_buttons($form, $form_state, 'views_ui_add_item_form', t('Add')); + + return $form; +} + +/** + * Submit handler for adding new item(s) to a view. + */ +function views_ui_add_item_form_submit($form, &$form_state) { + $type = $form_state['type']; + $types = views_object_types(); + + if (!empty($form_state['values']['name']) && is_array($form_state['values']['name'])) { + // Loop through each of the items that were checked and add them to the view. + foreach (array_keys(array_filter($form_state['values']['name'])) as $field) { + list($table, $field) = explode('.', $field, 2); + $id = $form_state['view']->add_item($form_state['display_id'], $type, $table, $field); + + // check to see if this type has settings, if so add the settings form first + $handler = views_get_handler($table, $field, $type); + if ($handler && $handler->has_extra_options()) { + views_ui_add_form_to_stack('config-item-extra', $form_state['view'], $form_state['display_id'], array($type, $id)); + } + // Then add the form to the stack + views_ui_add_form_to_stack('config-item', $form_state['view'], $form_state['display_id'], array($type, $id)); + } + } + + // Store in cache + views_ui_cache_set($form_state['view']); +} + + +/** + * Form to config_item items in the views UI. + */ +function views_ui_config_item_form(&$form_state) { + $view = &$form_state['view']; + $display_id = $form_state['display_id']; + $type = $form_state['type']; + $id = $form_state['id']; + + $form = array('options' => array('#tree' => TRUE)); + if (!$view->set_display($display_id)) { + views_ajax_render(t('Invalid display id @display', array('@display' => $display_id))); + } + $item = $view->get_item($display_id, $type, $id); + + if ($item) { + $handler = views_get_handler($item['table'], $item['field'], $type); + if (empty($handler)) { + $form['markup'] = array('#value' => t("Error: handler for @table > @field doesn't exist!", array('@table' => $item['table'], '@field' => $item['field']))); + } + else { + $handler->init($view, $item); + $types = views_object_types(); + + if ($view->display_handler->defaultable_sections($types[$type]['plural'])) { + $form_state['section'] = $types[$type]['plural']; + $view->display_handler->add_override_button($form['options'], $form_state, $form_state['section']); + } + + // A whole bunch of code to figure out what relationships are valid for + // this item. + $relationships = $view->display_handler->get_option('relationships'); + $relationship_options = array(); + + foreach ($relationships as $relationship) { + // relationships can't link back to self. But also, due to ordering, + // relationships can only link to prior relationships. + if ($type == 'relationship' && $id == $relationship['id']) { + break; + } + $relationship_handler = views_get_handler($relationship['table'], $relationship['field'], 'relationship'); + // ignore invalid/broken relationships. + if (empty($relationship_handler)) { + continue; + } + + // If this relationship is valid for this type, add it to the list. + $data = views_fetch_data($relationship['table']); + $base = $data[$relationship['field']]['relationship']['base']; + $base_fields = views_fetch_fields($base, $form_state['type']); + if (isset($base_fields[$item['table'] . '.' . $item['field']])) { + $relationship_handler->init($view, $relationship); + $relationship_options[$relationship['id']] = $relationship_handler->label(); + } + } + + if (!empty($relationship_options)) { + // Make sure the existing relationship is even valid. If not, force + // it to none. + $base_fields = views_fetch_fields($view->base_table, $form_state['type']); + if (isset($base_fields[$item['table'] . '.' . $item['field']])) { + $relationship_options = array_merge(array('none' => t('Do not use a relationship')), $relationship_options); + } + $rel = empty($item['relationship']) ? 'none' : $item['relationship']; + if (empty($relationship_options[$rel])) { + // Pick the first relationship. + $rel = key($relationship_options); + // We want this relationship option to get saved even if the user + // skips submitting the form. + $view->set_item_option($display_id, $type, $id, 'relationship', $rel); + $temp_view = $view->clone_view(); + views_ui_cache_set($temp_view); + } + + $form['options']['relationship'] = array( + '#type' => 'select', + '#title' => t('Relationship'), + '#options' => $relationship_options, + '#default_value' => $rel, + ); + } + else { + $form['options']['relationship'] = array( + '#type' => 'value', + '#value' => 'none', + ); + } + + $form['#title'] = check_plain($view->display[$display_id]->display_title) . ': '; + $form['#title'] .= t('Configure @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->ui_name())); + + $form['form_description'] = array( + '#type' => 'markup', + '#weight' => -1000, + '#prefix' => '
', + '#suffix' => '
', + '#value' => $handler->definition['help'], + ); + + $form['#section'] = $display_id . '-' . $type . '-' . $id; + + // Get form from the handler. + $handler->options_form($form['options'], $form_state); + $form_state['handler'] = &$handler; + } + + $name = NULL; + if (isset($form_state['update_name'])) { + $name = $form_state['update_name']; + } + + views_ui_standard_form_buttons($form, $form_state, 'views_ui_config_item_form', $name, t('Remove'), 'remove'); + } + return $form; +} + +/** + * Submit handler for configing new item(s) to a view. + */ +function views_ui_config_item_form_validate($form, &$form_state) { + $form_state['handler']->options_validate($form['options'], $form_state); +} + +/** + * Submit handler for configing new item(s) to a view. + */ +function views_ui_config_item_form_submit($form, &$form_state) { + // Run it through the handler's submit function. + $form_state['handler']->options_submit($form['options'], $form_state); + $item = $form_state['handler']->options; + + // Unset a button + unset($form_state['values']['options']['expose_button']); + + // Store the data we're given. + foreach ($form_state['values']['options'] as $key => $value) { + $item[$key] = $value; + } + + // Store the item back on the view + $form_state['view']->set_item($form_state['display_id'], $form_state['type'], $form_state['id'], $item); + + $handler = views_get_handler($item['table'], $item['field'], $form_state['type']); + $handler->init($form_state['view'], $item); + if ($handler && $handler->needs_style_plugin()) { + views_ui_add_form_to_stack('change-style', $form_state['view'], $form_state['display_id'], array($form_state['type'], $form_state['id']), TRUE); + } + + // Write to cache + views_ui_cache_set($form_state['view']); +} + +/** + * Submit handler for removing an item from a view + */ +function views_ui_config_item_form_remove($form, &$form_state) { + // Store the item back on the view + $form_state['view']->set_item($form_state['display_id'], $form_state['type'], $form_state['id'], NULL); + + // Write to cache + views_ui_cache_set($form_state['view']); +} + +/** + * Override handler for views_ui_edit_display_form + */ +function views_ui_config_item_form_expose($form, &$form_state) { + $item = &$form_state['handler']->options; + // flip + $item['exposed'] = empty($item['exposed']); + + // If necessary, set new defaults: + if ($item['exposed']) { + $form_state['handler']->expose_options(); + } + + $form_state['view']->set_item($form_state['display_id'], $form_state['type'], $form_state['id'], $item); + + views_ui_cache_set($form_state['view']); + $form_state['rerender'] = TRUE; + $form_state['rebuild'] = TRUE; + $form_state['force_expose_options'] = TRUE; +} + +/** + * Form to config_item items in the views UI. + */ +function views_ui_config_item_extra_form(&$form_state) { + $view = &$form_state['view']; + $display_id = $form_state['display_id']; + $type = $form_state['type']; + $id = $form_state['id']; + + $form = array('options' => array('#tree' => TRUE)); + if (!$view->set_display($display_id)) { + views_ajax_render(t('Invalid display id @display', array('@display' => $display_id))); + } + $item = $view->get_item($display_id, $type, $id); + + if ($item) { + $handler = views_get_handler($item['table'], $item['field'], $type); + if (empty($handler)) { + $form['markup'] = array('#value' => t("Error: handler for @table > @field doesn't exist!", array('@table' => $item['table'], '@field' => $item['field']))); + } + else { + $handler->init($view, $item); + $types = views_object_types(); + + $form['#title'] = check_plain($view->display[$display_id]->display_title) . ': '; + $form['#title'] .= t('Configure extra settings for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->ui_name())); + + $form['#section'] = $display_id . '-' . $type . '-' . $id; + + // Get form from the handler. + $handler->extra_options_form($form['options'], $form_state); + $form_state['handler'] = &$handler; + + } + + views_ui_standard_form_buttons($form, $form_state, 'views_ui_config_item_extra_form'); + } + return $form; +} + +/** + * Submit handler for configing new item(s) to a view. + */ +function views_ui_config_item_extra_form_validate($form, &$form_state) { + $form_state['handler']->extra_options_validate($form['options'], $form_state); +} + +/** + * Submit handler for configing new item(s) to a view. + */ +function views_ui_config_item_extra_form_submit($form, &$form_state) { + // Run it through the handler's submit function. + $form_state['handler']->extra_options_submit($form['options'], $form_state); + $item = $form_state['handler']->options; + + // Store the data we're given. + foreach ($form_state['values']['options'] as $key => $value) { + $item[$key] = $value; + } + + // Store the item back on the view + $form_state['view']->set_item($form_state['display_id'], $form_state['type'], $form_state['id'], $item); + + // Write to cache + views_ui_cache_set($form_state['view']); +} + +/** + * Form to change_style items in the views UI. + */ +function views_ui_change_style_form(&$form_state) { + $view = &$form_state['view']; + $display_id = $form_state['display_id']; + $type = $form_state['type']; + $id = $form_state['id']; + + $form = array('options' => array('#tree' => TRUE)); + if (!$view->set_display($display_id)) { + views_ajax_render(t('Invalid display id @display', array('@display' => $display_id))); + } + $item = $view->get_item($display_id, $type, $id); + + if ($item) { + $handler = views_get_handler($item['table'], $item['field'], $type); + if (empty($handler)) { + $form['markup'] = array('#value' => t("Error: handler for @table > @field doesn't exist!", array('@table' => $item['table'], '@field' => $item['field']))); + } + else { + $handler->init($view, $item); + $types = views_object_types(); + $form['#title'] = t('Change summary style for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->ui_name())); + + $form['#section'] = $display_id . '-' . $type . '-' . $id . '-style-plugin'; + + $form['style_plugin'] = array( + '#type' => 'radios', + '#options' => views_fetch_plugin_names('style', 'summary'), + '#default_value' => $item['style_plugin'], + ); + + $form_state['handler'] = &$handler; + } + views_ui_standard_form_buttons($form, $form_state, 'views_ui_change_style_form'); + } + return $form; +} + +function views_ui_change_style_form_validate($form, &$form_state) { + // Run it through the handler's submit function. + $form_state['handler']->options_validate($form['options'], $form_state); + + $plugin = views_get_plugin('style', $form_state['values']['style_plugin']); + if (!$plugin) { + form_error($form['style_plugin'], t('Internal error: broken plugin.')); + } +} + +/** + * Submit handler for configing new item(s) to a view. + */ +function views_ui_change_style_form_submit($form, &$form_state) { + // Run it through the handler's submit function. + $form_state['handler']->options_submit($form['options'], $form_state); + $item = $form_state['handler']->options; + + $plugin = views_get_plugin('style', $form_state['values']['style_plugin']); + if (!$plugin) { + drupal_set_message(t('Internal error: broken plugin.'), 'error'); + return; + } + + $plugin->init($form_state['view'], $form_state['view']->display[$form_state['display_id']]); + + // If changing style plugin, reset options to defaults. + if (empty($item['style_plugin']) || $item['style_plugin'] != $form_state['values']['style_plugin']) { + $item['style_options'] = $plugin->options; + } + + // Store the data we're given. + $item['style_plugin'] = $form_state['values']['style_plugin']; + + // Store the item back on the view + $form_state['view']->set_item($form_state['display_id'], $form_state['type'], $form_state['id'], $item); + + if (!empty($plugin->definition['uses options'])) { + views_ui_add_form_to_stack('config-style', $form_state['view'], $form_state['display_id'], array($form_state['type'], $form_state['id']), TRUE); + } + + // Write to cache + views_ui_cache_set($form_state['view']); +} + +/** + * Form to config_style items in the views UI. + */ +function views_ui_config_style_form(&$form_state) { + $view = &$form_state['view']; + $display_id = $form_state['display_id']; + $type = $form_state['type']; + $id = $form_state['id']; + + $form = array('options' => array('#tree' => TRUE)); + if (!$view->set_display($display_id)) { + views_ajax_render(t('Invalid display id @display', array('@display' => $display_id))); + } + $item = $view->get_item($display_id, $type, $id); + + if ($item) { + $handler = views_get_handler($item['table'], $item['field'], $type); + if (empty($handler)) { + $form['markup'] = array('#value' => t("Error: handler for @table > @field doesn't exist!", array('@table' => $item['table'], '@field' => $item['field']))); + } + else { + $handler->init($view, $item); + $types = views_object_types(); + + $form['#title'] = check_plain($view->display[$display_id]->display_title) . ': '; + $form['#title'] .= t('Configure summary style for @type %item', array('@type' => $types[$type]['lstitle'], '%item' => $handler->ui_name())); + + $form['#section'] = $display_id . '-' . $type . '-style-options'; + + $plugin = views_get_plugin('style', $item['style_plugin']); + if ($plugin) { + $form['style_options'] = array( + '#tree' => TRUE, + ); + $plugin->init($view, $view->display[$display_id], $item['style_options']); + + $plugin->options_form($form['style_options'], $form_state); + } + + $form_state['handler'] = &$handler; + } + views_ui_standard_form_buttons($form, $form_state, 'views_ui_config_style_form'); + } + return $form; +} + +/** + * Submit handler for configing new item(s) to a view. + */ +function views_ui_config_style_form_submit($form, &$form_state) { + // Run it through the handler's submit function. + $form_state['handler']->options_submit($form['style_options'], $form_state); + $item = $form_state['handler']->options; + + // Store the data we're given. + $item['style_options'] = $form_state['values']['style_options']; + + // Store the item back on the view + $form_state['view']->set_item($form_state['display_id'], $form_state['type'], $form_state['id'], $item); + + // Write to cache + views_ui_cache_set($form_state['view']); +} + +/** + * Get a list of roles in the system. + */ +function views_ui_get_roles() { + static $roles = NULL; + if (!isset($roles)) { + $roles = array(); + $result = db_query("SELECT r.rid, r.name FROM {role} r ORDER BY r.name"); + while ($obj = db_fetch_object($result)) { + $roles[$obj->rid] = $obj->name; + } + } + + return $roles; +} + +/** + * Get a css safe id for a particular section. + */ +function views_ui_item_css($item) { + return views_css_safe('views-item-' . $item); +} + +/** + * Page callback for the Views enable page. + */ +function views_ui_enable_page($view) { + if (isset($_GET['token']) && drupal_valid_token($_GET['token'], 'views-enable')) { + $views_status = variable_get('views_defaults', array()); + $views_status[$view->name] = FALSE; // false is enabled + variable_set('views_defaults', $views_status); + views_invalidate_cache(); + menu_rebuild(); + drupal_goto('admin/build/views'); + } + else { + return drupal_access_denied(); + } +} + +/** + * Page callback for the Views enable page + */ +function views_ui_disable_page($view) { + if (isset($_GET['token']) && drupal_valid_token($_GET['token'], 'views-disable')) { + $views_status = variable_get('views_defaults', array()); + $views_status[$view->name] = TRUE; // True is disabled + variable_set('views_defaults', $views_status); + views_invalidate_cache(); + menu_rebuild(); + drupal_goto('admin/build/views'); + } + else { + return drupal_access_denied(); + } +} + +/** + * Page callback for the tools - other page + */ +function views_ui_admin_tools() { + $form['clear_cache'] = array( + '#type' => 'submit', + '#value' => t("Clear Views' cache"), + '#submit' => array('views_ui_tools_clear_cache'), + ); + + $form['views_sql_signature'] = array( + '#type' => 'checkbox', + '#title' => t('Add Views signature to all SQL queries'), + '#description' => t("All Views-generated queries will include a special 'VIEWS' = 'VIEWS' string in the WHERE clause. This makes identifying Views queries in database server logs simpler, but should only be used when troubleshooting."), + '#default_value' => variable_get('views_sql_signature', FALSE), + ); + + $form['views_skip_cache'] = array( + '#type' => 'checkbox', + '#title' => t('Disable views data caching'), + '#description' => t("Views caches data about tables, modules and views available, to increase performance. By checking this box, Views will skip this cache and always rebuild this data when needed. This can have a serious performance impact on your site."), + '#default_value' => variable_get('views_skip_cache', FALSE), + ); + + $form['views_hide_help_message'] = array( + '#type' => 'checkbox', + '#title' => t('Ignore missing advanced help module'), + '#description' => t("Views uses the advanced help module to provide help text; if this module is not present Views will complain, unless this setting is checked."), + '#default_value' => variable_get('views_hide_help_message', FALSE), + ); + + $form['views_ui_query_on_top'] = array( + '#type' => 'checkbox', + '#title' => t('Show query above live preview'), + '#description' => t("The live preview feature will show you the output of the view you're creating, as well as the view. Check here to show the query and other information above the view; leave this unchecked to show that information below the view."), + '#default_value' => variable_get('views_ui_query_on_top', FALSE), + ); + + $form['views_ui_disable_live_preview'] = array( + '#type' => 'checkbox', + '#title' => t('Disable automatic live preview'), + '#description' => t("Don't automatically update the preview. This can speed up the editing of views a bit.'"), + '#default_value' => variable_get('views_ui_disable_live_preview', 0), + ); + + $form['views_show_additional_queries'] = array( + '#type' => 'checkbox', + '#title' => t('Show other queries run during render during live preview'), + '#description' => t("Drupal has the potential to run many queries while a view is being rendered. Checking this box will display every query run during view render as part of the live preview."), + '#default_value' => variable_get('views_show_additional_queries', FALSE), + ); + + $form['views_no_hover_links'] = array( + '#type' => 'checkbox', + '#title' => t('Do not show hover links over views'), + '#description' => t("To make it easier to administrate your views, Views provides 'hover' links to take you to the edit and export screen of a view whenever the view is used. This can be distracting on some themes, though; if it is problematic, you can turn it off here."), + '#default_value' => variable_get('views_no_hover_links', FALSE), + ); + + $form['views_devel_output'] = array( + '#type' => 'checkbox', + '#title' => t('Enable views performance statistics via the Devel module'), + '#description' => t("Check this to enable some Views query and performance statistics if Devel is installed."), + '#default_value' => variable_get('views_devel_output', FALSE), + ); + + $form['views_no_javascript'] = array( + '#type' => 'checkbox', + '#title' => t('Disable javascript with Views'), + '#description' => t("If you are having problems with the javascript, you can disable it here; the Views UI should degrade and still be usable without javascript, it just not as good."), + '#default_value' => variable_get('views_no_javascript', FALSE), + ); + + $regions = system_region_list(variable_get('theme_default', 'garland')); + $regions['watchdog'] = t('Watchdog'); + + $form['views_devel_region'] = array( + '#type' => 'select', + '#title' => t('Page region to output performance statistics'), + '#default_value' => variable_get('views_devel_region', 'footer'), + '#options' => $regions, + ); + + $form['views_exposed_filter_any_label'] = array( + '#type' => 'select', + '#title' => t('Label for "Any" value on optional single-select exposed filters'), + '#options' => array('old_any' => '', 'new_any' => t('- Any -')), + '#default_value' => variable_get('views_exposed_filter_any_label', 'old_any'), + ); + + return system_settings_form($form); +} + +/** + * Submit hook to clear the views cache. + */ +function views_ui_tools_clear_cache() { + views_invalidate_cache(); + drupal_set_message(t('The cache has been cleared.')); +} + +/** + * Submit hook to clear Drupal's theme registry (thereby triggering + * a templates rescan). + */ +function views_ui_config_item_form_rescan($form, &$form_state) { + drupal_rebuild_theme_registry(); + + // The 'Theme: Information' page is about to be shown again. That page + // analyzes the output of theme_get_registry(). However, this latter + // function uses an internal cache (which was initialized before we + // called drupal_rebuild_theme_registry()) so it won't reflect the + // current state of our theme registry. The only way to clear that cache + // is to re-initialize the theme system: + unset($GLOBALS['theme']); + init_theme(); + + $form_state['rerender'] = TRUE; + $form_state['rebuild'] = TRUE; +} + +/** + * Override handler for views_ui_edit_display_form + */ +function views_ui_edit_display_form_change_theme($form, &$form_state) { + // This is just a temporary variable. + $form_state['view']->theme = $form_state['values']['theme']; + + views_ui_cache_set($form_state['view']); + $form_state['rerender'] = TRUE; + $form_state['rebuild'] = TRUE; +} + +/** + * Page callback for views tag autocomplete + */ +function views_ui_autocomplete_tag($string = '') { + $matches = array(); + // get matches from default views: + views_include('view'); + $views = views_discover_default_views(); + foreach ($views as $view) { + if (!empty($view->tag) && strpos($view->tag, $string) === 0) { + $matches[$view->tag] = $view->tag; + } + } + + if ($string) { + $result = db_query_range("SELECT DISTINCT tag FROM {views_view} WHERE LOWER(tag) LIKE LOWER('%s%%')", $string, 0, 10 - count($matches)); + while ($view = db_fetch_object($result)) { + $matches[$view->tag] = check_plain($view->tag); + } + } + + drupal_json($matches); +} + +// ------------------------------------------------------------------ +// Get information from the Views data + +function _views_weight_sort($a, $b) { + if ($a['weight'] != $b['weight']) { + return $a['weight'] < $b['weight'] ? -1 : 1; + } + if ($a['title'] != $b['title']) { + return $a['title'] < $b['title'] ? -1 : 1; + } + + return 0; +} + +/** + * Fetch a list of all base tables available + * + * @return + * A keyed array of in the form of 'base_table' => 'Description'. + */ +function views_fetch_base_tables() { + static $base_tables = array(); + if (empty($base_tables)) { + $weights = array(); + $tables = array(); + $data = views_fetch_data(); + foreach ($data as $table => $info) { + if (!empty($info['table']['base'])) { + $tables[$table] = array( + 'title' => $info['table']['base']['title'], + 'description' => $info['table']['base']['help'], + 'weight' => !empty($info['table']['base']['weight']) ? $info['table']['base']['weight'] : 0, + ); + } + } + uasort($tables, '_views_weight_sort'); + $base_tables = $tables; + } + + return $base_tables; +} + +function _views_sort_types($a, $b) { + if ($a['group'] != $b['group']) { + return $a['group'] < $b['group'] ? -1 : 1; + } + + if ($a['title'] != $b['title']) { + return $a['title'] < $b['title'] ? -1 : 1; + } + + return 0; +} + +/** + * Fetch a list of all fields available for a given base type. + * + * @return + * A keyed array of in the form of 'base_table' => 'Description'. + */ +function views_fetch_fields($base, $type) { + static $fields = array(); + if (empty($fields)) { + $data = views_fetch_data(); + $start = views_microtime(); + // This constructs this ginormous multi dimensional array to + // collect the important data about fields. In the end, + // the structure looks a bit like this (using nid as an example) + // $strings['nid']['filter']['title'] = 'string'. + // + // This is constructed this way because the above referenced strings + // can appear in different places in the actual data structure so that + // the data doesn't have to be repeated a lot. This essentially lets + // each field have a cheap kind of inheritance. + + foreach ($data as $table => $table_data) { + $bases = array(); + $strings = array(); + $skip_bases = array(); + foreach ($table_data as $field => $info) { + // Collect table data from this table + if ($field == 'table') { + // calculate what tables this table can join to. + if (!empty($info['join'])) { + $bases = array_keys($info['join']); + } + // And it obviously joins to itself. + $bases[] = $table; + continue; + } + foreach (array('field', 'sort', 'filter', 'argument', 'relationship') as $key) { + if (!empty($info[$key])) { + if (!empty($info[$key]['skip base'])) { + foreach ((array) $info[$key]['skip base'] as $base_name) { + $skip_bases[$field][$key][$base_name] = TRUE; + } + } + elseif (!empty($info['skip base'])) { + foreach ((array) $info['skip base'] as $base_name) { + $skip_bases[$field][$key][$base_name] = TRUE; + } + } + foreach (array('title', 'group', 'help', 'base') as $string) { + // First, try the lowest possible level + if (!empty($info[$key][$string])) { + $strings[$field][$key][$string] = $info[$key][$string]; + } + // Then try the field level + elseif (!empty($info[$string])) { + $strings[$field][$key][$string] = $info[$string]; + } + // Finally, try the table level + elseif (!empty($table_data['table'][$string])) { + $strings[$field][$key][$string] = $table_data['table'][$string]; + } + else { + if ($string != 'base') { + $strings[$field][$key][$string] = t("Error: missing @component", array('@component' => $string)); + } + } + } + } + } + } + foreach ($bases as $base_name) { + foreach ($strings as $field => $field_strings) { + foreach ($field_strings as $type_name => $type_strings) { + if (empty($skip_bases[$field][$type_name][$base_name])) { + $fields[$base_name][$type_name]["$table.$field"] = $type_strings; + } + } + } + } + } +// vsm('Views UI data build time: ' . (views_microtime() - $start) * 1000 . ' ms'); + } + + // If we have an array of base tables available, go through them + // all and add them together. Duplicate keys will be lost and that's + // Just Fine. + if (is_array($base)) { + $strings = array(); + foreach ($base as $base_table) { + if (isset($fields[$base_table][$type])) { + $strings += $fields[$base_table][$type]; + } + } + uasort($strings, '_views_sort_types'); + return $strings; + } + + if (isset($fields[$base][$type])) { + uasort($fields[$base][$type], '_views_sort_types'); + return $fields[$base][$type]; + } + return array(); +} + +/** + * Fetch a list of all base tables available + * + * @param $type + * Either 'display', 'style' or 'row' + * @param $key + * For style plugins, this is an optional type to restrict to. May be 'normal', + * 'summary', 'feed' or others based on the neds of the display. + * @param $base + * An array of possible base tables. + * + * @return + * A keyed array of in the form of 'base_table' => 'Description'. + */ +function views_fetch_plugin_names($type, $key = NULL, $base = array()) { + $data = views_fetch_plugin_data(); + + $plugins[$type] = array(); + + foreach ($data[$type] as $id => $plugin) { + // Skip plugins that don't conform to our key. + if ($key && (empty($plugin['type']) || $plugin['type'] != $key)) { + continue; + } + if (empty($plugin['no ui']) && (empty($base) || empty($plugin['base']) || array_intersect($base, $plugin['base']))) { + $plugins[$type][$id] = $plugin['title']; + } + } + + if (!empty($plugins[$type])) { + asort($plugins[$type]); + return $plugins[$type]; + } + // fall-through + return array(); +} + + +/** + * Theme the form for the table style plugin + */ +function theme_views_ui_style_plugin_table($form) { + $output = drupal_render($form['description_markup']); + + $header = array( + t('Field'), + t('Column'), + t('Separator'), + array( + 'data' => t('Sortable'), + 'align' => 'center', + ), + array( + 'data' => t('Default sort'), + 'align' => 'center', + ), + ); + $rows = array(); + foreach (element_children($form['columns']) as $id) { + $row = array(); + $row[] = drupal_render($form['info'][$id]['name']); + $row[] = drupal_render($form['columns'][$id]); + $row[] = drupal_render($form['info'][$id]['separator']); + if (!empty($form['info'][$id]['sortable'])) { + $row[] = array( + 'data' => drupal_render($form['info'][$id]['sortable']), + 'align' => 'center', + ); + $row[] = array( + 'data' => drupal_render($form['default'][$id]), + 'align' => 'center', + ); + } + else { + $row[] = ''; + $row[] = ''; + } + $rows[] = $row; + } + + // Add the special 'None' row. + $rows[] = array(t('None'), '', '', '', array('align' => 'center', 'data' => drupal_render($form['default'][-1]))); + + $output .= theme('table', $header, $rows); + $output .= drupal_render($form); + return $output; +} + diff --git a/sites/all/modules/views/includes/ajax.inc b/sites/all/modules/views/includes/ajax.inc new file mode 100644 index 0000000..9915863 --- /dev/null +++ b/sites/all/modules/views/includes/ajax.inc @@ -0,0 +1,178 @@ +status = FALSE; + $object->display = ''; + + $arg = explode('/', $_REQUEST['view_path']); + + if ($arg[0] == 'admin' || (variable_get('node_admin_theme', '0') && $arg[0] == 'node' && ($arg[1] == 'add' || $arg[2] == 'edit'))) { + global $custom_theme; + $custom_theme = variable_get('admin_theme', '0'); + drupal_add_css(drupal_get_path('module', 'system') .'/admin.css', 'module'); + } + // Load the view. + if ($view = views_get_view($name)) { + if ($view->access($display_id)) { + + // Fix 'q' for paging. + if (!empty($path)) { + $_GET['q'] = $path; + } + + // Override the display's pager_element with the one actually used. + if (isset($pager_element)) { + $view->display[$display_id]->handler->set_option('pager_element', $pager_element); + } + // Reuse the same DOM id so it matches that in Drupal.settings. + $view->dom_id = $dom_id; + + $object->status = TRUE; + $object->display .= $view->preview($display_id, $args); + // Get the title after the preview call, to let it set + // up both the view's current display and arguments + $object->title = $view->get_title(); + // Register the standard JavaScript callback. + $object->__callbacks = array('Drupal.Views.Ajax.ajaxViewResponse'); + // Allow other modules to extend the data returned. + drupal_alter('ajax_data', $object, 'views', $view); + } + } + $messages = theme('status_messages'); + $object->messages = $messages ? '
' . $messages . '
' : ''; + + views_ajax_render($object); + } +} + +/** + * Simple render function to make sure output is what we want. + * + * This function renders an object into JSON, and that object contains + * commands to the ajax response parser on the other side. The actual + * commands that can be sent are completely dependent upon the client + * javascript parser, which can be anything, but this function assumes + * that 'display', at least, will be displayed in some kind of ajax + * spot or popup. + */ +function views_ajax_render($output = NULL, $title = NULL, $url = NULL, $js = NULL) { + if (empty($output)) { + $output->display = t('Server reports invalid input error.'); + $output->title = t('Error'); + } + elseif (!is_object($output)) { + $temp = new stdClass(); + $temp->display = $output; + $temp->title = $title; + $temp->url = $url; + $output = $temp; + } + if (!empty($js)) { + $output->js = $js; + } + + drupal_json($output); + exit; +} + +/** + * Wrapper around drupal_build_form to handle some AJAX stuff automatically. + * This makes some assumptions about the client. + */ +function views_ajax_form_wrapper($form_id, &$form_state) { + // This won't override settings already in. + $form_state += array( + 'rerender' => FALSE, + 'no_redirect' => !empty($form_state['ajax']), + ); + + $output = drupal_build_form($form_id, $form_state); + if (!empty($form_state['ajax']) && empty($form_state['executed'])) { + // If the form didn't execute and we're using ajax, build up a + // json command object to render. + $object = new stdClass(); + $object->display = ''; + if ($messages = theme('status_messages')) { + $object->display = '
' . $messages . '
'; + } + $object->display .= $output; + + $object->title = empty($form_state['title']) ? '' : $form_state['title']; + if (!empty($form_state['help_topic'])) { + $module = !empty($form_state['help_module']) ? $form_state['help_module'] : 'views'; + $object->title = theme('advanced_help_topic', $module, $form_state['help_topic']) . $object->title; + } + $object->url = empty($form_state['url']) ? url($_GET['q'], array('absolute' => TRUE)) : $form_state['url']; + $object->js = empty($form_state['js settings']) ? NULL : $form_state['js settings']; + if (!empty($form_state['#section'])) { + $object->hilite = '.' . views_ui_item_css($form_state['#section']); + } + + $output = $object; + } + + // These forms have the title built in, so set the title here: + if (empty($form_state['ajax']) && !empty($form_state['title'])) { + drupal_set_title($form_state['title']); + } + + return $output; +} + + +/** + * Page callback for views user autocomplete + */ +function views_ajax_autocomplete_user($string = '') { + // The user enters a comma-separated list of tags. We only autocomplete the last tag. + $array = drupal_explode_tags($string); + + // Fetch last tag + $last_string = trim(array_pop($array)); + $matches = array(); + if ($last_string != '') { + $prefix = count($array) ? implode(', ', $array) . ', ' : ''; + + if (strpos('anonymous', strtolower($last_string)) !== FALSE) { + $matches[$prefix . 'Anonymous'] = 'Anonymous'; + } + $result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER('%s%%')", $last_string, 0, 10); + + while ($account = db_fetch_object($result)) { + $n = $account->name; + // Commas and quotes in terms are special cases, so encode 'em. + if (strpos($account->name, ',') !== FALSE || strpos($account->name, '"') !== FALSE) { + $n = '"' . str_replace('"', '""', $account->name) . '"'; + } + $matches[$prefix . $n] = check_plain($account->name); + } + } + + drupal_json($matches); +} + +/** + * @} + */ diff --git a/sites/all/modules/views/includes/analyze.inc b/sites/all/modules/views/includes/analyze.inc new file mode 100644 index 0000000..450efb2 --- /dev/null +++ b/sites/all/modules/views/includes/analyze.inc @@ -0,0 +1,108 @@ +init_display(); + $messages = module_invoke_all('views_analyze', $view); + + return $messages; +} + +/** + * Format the analyze result into a message string. + * + * This is based upon the format of drupal_set_message which uses separate + * boxes for "ok", "warning" and "error". + */ +function views_analyze_format_result($view, $messages) { + if (empty($messages)) { + $messages = array(views_ui_analysis(t('View analysis can find nothing to report.'), 'ok')); + } + + $types = array('ok' => array(), 'warning' => array(), 'error' => array()); + foreach ($messages as $message) { + if (empty($types[$message['type']])) { + $types[$message['type']] = array(); + } + $types[$message['type']][] = $message['message']; + } + + $output = ''; + foreach ($types as $type => $messages) { + $message = ''; + if (count($messages) > 1) { + $message = theme('item_list', $messages); + } + else if ($messages) { + $message = array_shift($messages); + } + + if ($message) { + $output .= "
$message
"; + } + } + + return $output; +} + +/** + * Format an analysis message. + * + * This tool should be called by any module responding to the analyze hook + * to properly format the message. It is usually used in the form: + * @code + * $ret[] = views_ui_analysis(t('This is the message'), 'ok'); + * @endcode + * + * The 'ok' status should be used to provide information about things + * that are acceptable. In general analysis isn't interested in 'ok' + * messages, but instead the 'warning', which is a category for items + * that may be broken unless the user knows what he or she is doing, + * and 'error' for items that are definitely broken are much more useful. + * + * @param $messages + * The message to report. + * @param $type + * The type of message. This should be "ok", "warning" or "error". Other + * values can be used but how they are treated by the output routine + * is undefined. + */ +function views_ui_analysis($message, $type = 'error') { + return array('message' => $message, 'type' => $type); +} + +/** + * Implementation of hook_views_analyze(). + * + * This is the basic views analysis that checks for very minimal problems. + * There are other analysis tools in core specific sections, such as + * node.views.inc as well. + */ +function views_ui_views_analyze($view) { + $ret = array(); + // Check for something other than the default display: + if (count($view->display) < 2) { + $ret[] = views_ui_analysis(t('This view has only a default display and therefore will not be placed anywhere on your site; perhaps you want to add a page or a block display.'), 'warning'); + } + + return $ret; +} + diff --git a/sites/all/modules/views/includes/base.inc b/sites/all/modules/views/includes/base.inc new file mode 100644 index 0000000..7522d9f --- /dev/null +++ b/sites/all/modules/views/includes/base.inc @@ -0,0 +1,127 @@ + array( + * - 'default' => default value, + * - 'translatable' => TRUE/FALSE (wrap in t() on export if true), + * - 'contains' => array of items this contains, with its own defaults, etc. + * If contains is set, the default will be ignored and assumed to + * be array() + * + * ), + * @endcode + * Each option may have any of the following functions: + * - export_option_OPTIONNAME -- Special export handling if necessary. + * - translate_option_OPTIONNAME -- Special handling for translating data + * within the option, if necessary. + */ + function option_definition() { return array(); } + + /** + * Views handlers use a special construct function so that we can more + * easily construct them with variable arguments. + */ + function construct() { $this->set_default_options(); } + + /** + * Set default options on this object. Called by the constructor in a + * complex chain to deal with backward compatibility. + */ + function options() { } + + /** + * Set default options. + * For backward compatibility, it sends the options array; this is a + * feature that will likely disappear at some point. + */ + function set_default_options() { + $this->_set_option_defaults($this->options, $this->option_definition()); + + // Retained for complex defaults plus backward compatibility. + $this->options($this->options); + } + + function _set_option_defaults(&$storage, $options, $level = 0) { + foreach ($options as $option => $definition) { + if (isset($definition['contains']) && is_array($definition['contains'])) { + $storage[$option] = array(); + $this->_set_option_defaults($storage[$option], $definition['contains'], $level++); + } + elseif (!empty($definition['translatable']) && !empty($definition['default'])) { + $storage[$option] = t($definition['default']); + } + else { + $storage[$option] = isset($definition['default']) ? $definition['default'] : NULL; + } + } + } + + /** + * Unpack options over our existing defaults, drilling down into arrays + * so that defaults don't get totally blown away. + */ + function unpack_options(&$storage, $options, $definition = NULL, $check = TRUE) { + if ($check && !is_array($options)) { + return; + } + + if (!isset($definition)) { + $definition = $this->option_definition(); + } + + foreach ($options as $key => $value) { + if (is_array($value)) { + if (!isset($storage[$key]) || !is_array($storage[$key])) { + $storage[$key] = array(); + } + + $this->unpack_options($storage[$key], $value, isset($definition[$key]['contains']) ? $definition[$key]['contains'] : array(), FALSE); + } + else if (!empty($definition[$key]['translatable']) && !empty($value)) { + $storage[$key] = t($value); + } + else { + $storage[$key] = $value; + } + } + } + + /** + * Let the handler know what its full definition is. + */ + function set_definition($definition) { + $this->definition = $definition; + if (isset($definition['field'])) { + $this->real_field = $definition['field']; + } + } + + function destroy() { + if (isset($this->view)) { + unset($this->view); + } + + if (isset($this->display)) { + unset($this->display); + } + + if (isset($this->query)) { + unset($this->query); + } + } +} diff --git a/sites/all/modules/views/includes/cache.inc b/sites/all/modules/views/includes/cache.inc new file mode 100644 index 0000000..2323ad4 --- /dev/null +++ b/sites/all/modules/views/includes/cache.inc @@ -0,0 +1,293 @@ +data)) { + $cache = $data->data; + } + + if (empty($cache)) { + $cache = module_invoke_all('views_data'); + foreach (module_implements('views_data_alter') as $module) { + $function = $module . '_views_data_alter'; + $function($cache); + } + + views_cache_set('views_data', $cache, TRUE); + } + + vpr('Views data build time: ' . (views_microtime() - $start) * 1000 . ' ms'); + } + + if (!$table) { + return $cache; + } + if (isset($cache[$table])) { + return $cache[$table]; + } + + // Return an empty array if there is no match. + return array(); +} + +/** + * Fetch the plugin data from cache. + */ +function _views_fetch_plugin_data($type = NULL, $plugin = NULL) { + static $cache = NULL; + if (!isset($cache)) { + $start = views_microtime(); + views_include_handlers(); + + $cache = views_discover_plugins(); + + vpr('Views plugins build time: ' . (views_microtime() - $start) * 1000 . ' ms'); + } + + if (!$type && !$plugin) { + return $cache; + } + else if (!$plugin) { + // Not in the if above so the else below won't run + if (isset($cache[$type])) { + return $cache[$type]; + } + } + else if (isset($cache[$type][$plugin])) { + return $cache[$type][$plugin]; + } + + // Return an empty array if there is no match. + return array(); +} + +/** + * Scan all modules for default views and rebuild the default views cache. + * + * @return An associative array of all known default views. + */ +function _views_discover_default_views() { + static $cache = NULL; + + if (!isset($cache)) { + $index = views_cache_get('views_default_views_index', TRUE); + + // Retrieve each cached default view + if (isset($index->data) && is_array($index->data)) { + $cache = array(); + foreach ($index->data as $view_name) { + $data = views_cache_get('views_default:' . $view_name, TRUE); + if (isset($data->data) && is_object($data->data)) { + $cache[$view_name] = $data->data; + } + } + } + // If missing index, rebuild the cache + else { + views_include_default_views(); + $cache = array(); + + foreach(module_implements('views_default_views') as $module) { + $results = call_user_func($module . "_views_default_views"); + if (!empty($results) && is_array($results)) { + foreach($results as $name => $view) { + // Only views with a sufficiently high api version are eligible. + if (!empty($view->api_version) && $view->api_version >= 2) { + // Do not cache dead handlers. + $view->destroy(); + if (!isset($cache[$name])) { + $cache[$name] = $view; + } + else { + watchdog('view', "View name '@name' is already taken", array('@name' => $name), WATCHDOG_ERROR); + } + } + } + } + } + + // Allow modules to modify default views before they are cached. + drupal_alter('views_default_views', $cache); + + // Cache the index + $index = array_keys($cache); + views_cache_set('views_default_views_index', $index, TRUE); + + // Cache each view + foreach ($cache as $name => $view) { + views_cache_set('views_default:' . $name, $view, TRUE); + } + } + } + + return $cache; +} + +/** + * Set a cached item in the views cache. + * + * This is just a convenience wrapper around cache_set(). + * + * @param $cid + * The cache ID of the data to store. + * @param $data + * The data to store in the cache. Complex data types will be automatically serialized before insertion. + * Strings will be stored as plain text and not serialized. + * @param $use_language + * If TRUE, the data will be cached specific to the currently active language. + */ +function views_cache_set($cid, $data, $use_language = FALSE) { + global $language; + + if (variable_get('views_skip_cache', FALSE)) { + return; + } + if ($use_language) { + $cid .= ':' . $language->language; + } + + cache_set($cid, $data, 'cache_views'); +} + +/** + * Return data from the persistent views cache. + * + * This is just a convenience wrapper around cache_get(). + * + * @param $cid + * The cache ID of the data to retrieve. + * @param $use_language + * If TRUE, the data will be requested specific to the currently active language. + */ +function views_cache_get($cid, $use_language = FALSE) { + global $language; + + if (variable_get('views_skip_cache', FALSE)) { + return 0; + } + if ($use_language) { + $cid .= ':' . $language->language; + } + + return cache_get($cid, 'cache_views'); +} + +/** + * @defgroup views_object_cache Non-volatile cache storage + * @{ + * The non-volatile object cache is used to store an object while it is + * being edited, so that we don't have to save until we're completely + * done. The cache should be 'cleaned' on a regular basis, meaning to + * remove old objects from the cache, but otherwise the data in this + * cache must remain stable, as it includes unsaved changes. + */ + +/** + * Get an object from the non-volatile Views cache. + * + * This function caches in memory as well, so that multiple calls to this + * will not result in multiple database reads. + * + * @param $obj + * A 32 character or less string to define what kind of object is being + * stored; primarily this is used to prevent collisions. + * @param $name + * The name of the view (or other object) being stored. + * @param $skip_cache + * Skip the memory cache, meaning this must be read from the db again. + * + * @return + * The data that was cached. + */ +function views_object_cache_get($obj, $name, $skip_cache = FALSE) { + static $cache = array(); + $key = "$obj:$name"; + if ($skip_cache) { + unset($cache[$key]); + } + + if (!array_key_exists($key, $cache)) { + $data = db_fetch_object(db_query("SELECT * FROM {views_object_cache} WHERE sid = '%s' AND obj = '%s' AND name = '%s'", session_id(), $obj, $name)); + if ($data) { + $cache[$key] = unserialize($data->data); + } + } + return isset($cache[$key]) ? $cache[$key] : NULL; +} + +/** + * Store an object in the non-volatile Views cache. + * + * @param $obj + * A 32 character or less string to define what kind of object is being + * stored; primarily this is used to prevent collisions. + * @param $name + * The name of the view (or other object) being stored. + * @param $cache + * The object to be cached. This will be serialized prior to writing. + */ +function views_object_cache_set($obj, $name, $cache) { + views_object_cache_clear($obj, $name); + db_query("INSERT INTO {views_object_cache} (sid, obj, name, data, updated) VALUES ('%s', '%s', '%s', '%s', %d)", session_id(), $obj, $name, serialize($cache), time()); +} + +/** + * Remove an object from the non-volatile Views cache + * + * @param $obj + * A 32 character or less string to define what kind of object is being + * stored; primarily this is used to prevent collisions. + * @param $name + * The name of the view (or other object) being stored. + */ +function views_object_cache_clear($obj, $name) { + db_query("DELETE FROM {views_object_cache} WHERE sid = '%s' AND obj = '%s' AND name = '%s'", session_id(), $obj, $name); +} + +/** + * Remove all objects in the object cache that are older than the + * specified age. + * + * @param $age + * The minimum age of objects to remove, in seconds. For example, 86400 is + * one day. Defaults to 7 days. + */ +function views_object_cache_clean($age = NULL) { + if (empty($age)) { + $age = 86400 * 7; // 7 days + } + db_query("DELETE FROM {views_object_cache} WHERE updated < %d", time() - $age); +} + +/** + * @} + */ diff --git a/sites/all/modules/views/includes/convert.inc b/sites/all/modules/views/includes/convert.inc new file mode 100644 index 0000000..590e58d --- /dev/null +++ b/sites/all/modules/views/includes/convert.inc @@ -0,0 +1,548 @@ + t('View name'), 'field' => 'name', 'sort' => 'asc'), + array('data' => t('Description')), + array('data' => t('Operations')), + ); + $current_views = views_get_all_views(); + + $result = db_query("SELECT v.* FROM {view_view} v"); + while ($view = db_fetch_object($result)) { + $ops = array(); + if (!isset($current_views[$view->name])) { + $ops[] = l(t('Convert'), "admin/build/views1/convert/$view->name"); + } + else { + $ops[] = t('Converted'); + } + $ops[] = l(t('Delete'), "admin/build/views1/delete/$view->name"); + + $item = array(); + $item[] = check_plain($view->name); + $item[] = check_plain($view->description); + $item[] = implode(' | ', $ops); + $items[] = $item; + + $ts = tablesort_init($header); + switch ($ts['sql']) { + case 'name': + default: + $sorts[] = $item[0]; + break; + case 'title': + $sorts[] = $item[1]; + break; + } + } + + if (!empty($ts)) { + if (strtolower($ts['sort']) == 'desc') { + arsort($sorts); + } + else { + asort($sorts); + } + } + + $i = array(); + foreach ($sorts as $id => $title) { + $i[] = $items[$id]; + } + $output = t('The table below lists Views version 1 views that are stored in the database. You can either convert them to work in Views version 2, or delete them. The views are convertible only if there is no Views 2 view with the same name.'); + $output .= theme('table', $header, $i); + + $output .= drupal_get_form('views_ui_convert_cleanup_form'); + return $output; +} + +/** + * Provide form to clean up Views 1 tables. + */ +function views_ui_convert_cleanup_form() { + $form['verify'] = array( + '#type' => 'checkbox', + '#title' => t('Remove all Views 1 tables'), + '#description' => t('Check this box and then click clean up to drop all Views 1 tables. Warning: this operation will not be reversible! Do this only if you are sure you no longer need this data.'), + '#required' => TRUE, + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Clean up'), + ); + + return $form; +} + +function views_ui_convert_cleanup_form_submit($form, $form_state) { + if (empty($form_state['values']['verify'])) { + drupal_set_message('Please check the box to verify you want to destroy your Views 1 table data.'); + return; + } + + $ret = array(); + if (db_table_exists('view_view')) { + db_drop_table($ret, 'view_view'); + } + if (db_table_exists('view_sort')) { + db_drop_table($ret, 'view_sort'); + } + if (db_table_exists('view_argument')) { + db_drop_table($ret, 'view_argument'); + } + if (db_table_exists('view_tablefield')) { + db_drop_table($ret, 'view_tablefield'); + } + if (db_table_exists('view_filter')) { + db_drop_table($ret, 'view_filter'); + } + if (db_table_exists('view_exposed_filter')) { + db_drop_table($ret, 'view_exposed_filter'); + } + + drupal_set_message(t('All Views 1 tables have been removed.')); +} + +/** + * Page callback for the tools - Views 1 convert page + */ +function views_ui_convert1($name) { + $old = views1_load($name); + if (!$old) { + return t('Unable to find view.'); + } + + $view = views1_import($old); + + if ($view) { + views_ui_cache_set($view); + drupal_goto('admin/build/views/edit/' . $view->name); + } + else { + return t('Unable to convert view.'); + } +} + +/** + * Page to delete a Views 1 view. + */ +function views_ui_delete1_confirm(&$form_state, $vid) { + $form_state['vid'] = $vid; + $form = array(); + + $cancel = 'admin/build/views/tools/convert'; + if (!empty($_REQUEST['cancel'])) { + $cancel = $_REQUEST['cancel']; + } + return confirm_form($form, + t('Are you sure you want to delete the view %name?', array('%name' => $view->name)), + $cancel, + t('This action cannot be undone.'), + t('Delete'), + t('Cancel')); +} + +/** + * Submit handler to delete a view. + */ +function views_ui_delete1_confirm_submit(&$form, &$form_state) { + views1_delete($form_state['vid']); + drupal_set_message(t('The view has been deleted')); + $form_state['redirect'] = 'admin/build/views/tools/convert'; +} + +/** + * Convert a Views 1 view to a Views 2 view. + */ +function views1_import($imported) { + views_include_handlers(); + views_module_include('views_convert.inc'); + + $view = views_new_view(); + + $view->name = $imported->name; + $view->description = $imported->description; + + if (!empty($imported->page) && !empty($imported->url)) { + $page_display = $view->add_display('page'); + } + if (!empty($imported->block)) { + $block_display = $view->add_display('block'); + } + $view->init_display(); + + $handler = &$view->display['default']->handler; + $handler->set_option('title', $imported->page_title); + $handler->set_option('header', $imported->page_header); + $handler->set_option('header_format', $imported->page_header_format); + $handler->set_option('footer', $imported->page_footer); + $handler->set_option('footer_format', $imported->page_footer_format); + $handler->set_option('empty', $imported->page_empty); + $handler->set_option('empty_format', $imported->page_empty_format); + + $handler->set_option('use_pager', $imported->use_pager); + $handler->set_option('items_per_page', $imported->nodes_per_page); + $handler->set_option('pager_element', 0); + $handler->set_option('offset', 0); + + $access = array('type' => 'none', 'role' => array(), 'perm' => ''); + if ($imported->access) { + $access['type'] = 'role'; + $access['role'] = drupal_map_assoc($imported->access); + } + + $handler->set_option('access', $access); + if (!empty($imported->page) && !empty($imported->url)) { + $handler = &$view->display[$page_display]->handler; + $url = str_replace('$arg', '%', $imported->url); + $handler->set_option('path', $url); + if ($imported->menu) { + $menu = array('type' => 'normal'); + if ($imported->menu_tab) { + $menu['type'] = 'tab'; + } + if ($imported->menu_tab_default) { + $menu['type'] = 'default tab'; + } + $menu['title'] = $imported->menu_title ? $imported->menu_title : $imported->page_title; + $handler->set_option('menu', $menu); + + if ($menu['type'] == 'default tab') { + $tab_options = array('type' => 'none'); + switch ($imported->menu_tab_default_parent_type) { + case 'tab': + case 'normal': + $tab_options['type'] = $imported->menu_tab_default_parent_type; + break; + } + } + $tab_options['title'] = $imported->menu_parent_title; + $tab_options['weight'] = $imported->menu_parent_tab_weight; + $handler->set_option('tab_options', $tab_options); + } + } + + views1_convert_style($view, $handler, $imported->page_type); + + if (!empty($imported->block)) { + $handler = &$view->display[$block_display]->handler; + + if (!empty($imported->block_title)) { + if (!empty($imported->page)) { + $handler->set_override('title'); + } + $handler->set_option('title', $imported->block_title); + } + + if (!empty($imported->page)) { + $handler->set_override('use_pager'); + } + $handler->set_option('use_pager', FALSE); + + if ($imported->nodes_per_block != $imported->nodes_per_page) { + $handler->set_option('items_per_page', $imported->nodes_per_block); + $handler->set_option('offset', 0); + } + + if (empty($imported->block_use_page_header)) { + if (!empty($imported->page)) { + $handler->set_override('header'); + } + if (!empty($imported->block_header)) { + $handler->set_option('header', $imported->block_header); + $handler->set_option('header_format', $imported->block_header_format); + } + } + if (empty($imported->block_use_page_footer)) { + if (!empty($imported->page)) { + $handler->set_override('footer'); + } + if (!empty($imported->block_footer)) { + $handler->set_option('footer', $imported->block_footer); + $handler->set_option('footer_format', $imported->block_footer_format); + } + } + if (empty($imported->block_use_page_empty)) { + if (!empty($imported->page)) { + $handler->set_override('empty'); + } + if (!empty($imported->block_empty)) { + $handler->set_option('empty', $imported->block_empty); + $handler->set_option('empty_format', $imported->block_empty_format); + } + } + + $handler->set_option('use_more', $imported->block_more); + + if (!empty($imported->page)) { + $handler->set_override('style_plugin'); + } + views1_convert_style($view, $handler, $imported->block_type); + } + + // For each of the fields, arguments, filters, and sorts in the old view, + // check if a handler for this item exists in Views 2 and add it, + // then see if any other modules want to adapt it using hook_views_convert(). + + foreach ($imported->field as $field) { + $id = $view->add_item('default', 'field', $field['tablename'], $field['field'], array('label' => $field['label'])); + if ($view->display_handler->get_option('style_plugin') == 'table') { + $options = $view->display_handler->get_option('style_options'); + if (!empty($field['sortable'])) { + $options['info'][$id]['sortable'] = TRUE; + if (!empty($field['defaultsort'])) { + $options['default'] = $id; + } + } + $view->display_handler->set_option('style_options', $options); + } + foreach (module_implements('views_convert') as $module) { + module_invoke($module, 'views_convert', 'default', 'field', $view, $field, $id); + } + } + foreach ($imported->sort as $field) { + $id = $view->add_item('default', 'sort', $field['tablename'], $field['field'], array('order' => $field['sortorder'])); + foreach (module_implements('views_convert') as $module) { + module_invoke($module, 'views_convert', 'default', 'sort', $view, $field, $id); + } + } + $actions = array('ignore', 'not found', 'ignore', 'summary asc', 'summary asc', 'summary desc', 'summary asc', 'empty'); + foreach ($imported->argument as $id => $field) { + if (!empty($imported->view_args_php)) { + $field['argoptions']['default_action'] = 'default'; + $field['argoptions']['default_argument_type'] = 'php'; + $field['argoptions']['default_argument_php'] = '$args = eval(\''. str_replace("'", "\\'", $imported->view_args_php) .'\');'."\n"; + $field['argoptions']['default_argument_php'] .= 'if (isset($args['. $field['position'] .'])) {'."\n"; + $field['argoptions']['default_argument_php'] .= ' return $args['. $field['position'] .'];'."\n"; + $field['argoptions']['default_argument_php'] .= '}'; + $field['argoptions']['validate_fail'] = $actions[$field['argdefault']]; + } + else { + $field['argoptions']['default_action'] = $actions[$field['argdefault']]; + } + if (!empty($field['title'])) { + $field['argoptions']['title'] = $field['title']; + } + if (!empty($field['wildcard'])) { + $field['argoptions']['wildcard'] = $field['wildcard']; + } + if (!empty($field['wildcard_substitution'])) { + $field['argoptions']['wildcard_substitution'] = $field['wildcard_substitution']; + } + // Arguments didn't used to be identified by table.name so we just have to + // leave that out. + foreach (module_implements('views_convert') as $module) { + module_invoke($module, 'views_convert', 'default', 'argument', $view, $field, NULL); + } + } + foreach ($imported->filter as $key => $field) { + $options = $field['value'] == '' ? array() : array('value' => $field['value']); + $id = $view->add_item('default', 'filter', $field['tablename'], $field['field'], $options); + foreach (module_implements('views_convert') as $module) { + module_invoke($module, 'views_convert', 'default', 'filter', $view, $field, $id); + } + // Store the id in the exposed filter if there is one. + foreach ($imported->exposed_filter as $key => $filter) { + if ($field['tablename'] == $filter['tablename'] && $field['field'] == $filter['field']) { + $imported->exposed_filter[$key]['id'] = $id; + } + } + } + // Exposed filters now get added to the filter array, not as a separate array. + $count = 0; + foreach ($imported->exposed_filter as $field) { + $id = $field['id']; + $item = $view->get_item('default', 'filter', $id); + if (views_get_handler($item['table'], $item['field'], 'filter')) { + $item['exposed'] = TRUE; + + // Use the count to emulate the old, hardcoded filter naming. + $item['expose']['identifier'] = 'filter' . $count; + $item['expose']['label'] = $field['label']; + $item['expose']['operator'] = $field['operator'] ? 'op' . $count : ''; + $item['expose']['optional'] = $field['optional']; + $item['expose']['single'] = $field['single']; + $view->set_item('default', 'filter', $id, $item); + } + $count++; + foreach (module_implements('views_convert') as $module) { + module_invoke($module, 'views_convert', 'default', 'exposed_filter', $view, $field, $id); + } + } + + return $view; +} + +function views1_convert_style(&$view, &$handler, $type) { + switch ($type) { + case 'list': + $handler->set_option('style_plugin', 'list'); + $handler->set_option('style_options', array('type' => 'ul')); + $handler->set_option('row_plugin', 'fields'); + break; + case 'node': + $handler->set_option('row_plugin', 'node'); + $handler->set_option('row_options', array('teaser' => FALSE, 'links' => TRUE)); + break; + case 'teaser': + $handler->set_option('row_plugin', 'node'); + $handler->set_option('row_options', array('teaser' => TRUE, 'links' => TRUE)); + break; + case 'table': + $options = array(); + $options['columns'] = array(); + $options['default'] = ''; + $options['info'] = array(); + $options['override'] = FALSE; + $options['order'] = 'asc'; + + $handler->set_option('style_plugin', 'table'); + $handler->set_option('style_options', $options); + break; + default: + // Ask around if anybody else knows. + foreach (module_implements('views_convert') as $module) { + module_invoke($module, 'views_convert', $handler->display->id, 'style', $view, $type); + } + } +} +/** + * Load a version 1 view from the database. + * + */ +function views1_load($arg) { + static $cache = array(); + $which = is_numeric($arg) ? 'vid' : 'name'; + if (isset($cache[$which][$arg])) { + return $cache[$which][$arg]; + } + + $where = (is_numeric($arg) ? "v.vid = %d" : "v.name = '%s'"); + $view = db_fetch_object(db_query("SELECT v.* FROM {view_view} v WHERE $where", $arg)); + + if (!$view->name) { + return NULL; + } + + $view->access = ($view->access ? explode(', ', $view->access) : array()); + + // load the sorting criteria too. + $result = db_query("SELECT * FROM {view_sort} vs WHERE vid = $view->vid ORDER BY position ASC"); + + $view->sort = array(); + while ($sort = db_fetch_array($result)) { + if (substr($sort['field'], 0, 2) == 'n.') { + $sort['field'] = 'node' . substr($sort['field'], 1); + } + $sort['id'] = $sort['field']; + $bits = explode('.', $sort['field']); + $sort['tablename'] = $bits[0]; + $sort['field'] = $bits[1]; + $view->sort[$sort['position']] = $sort; + } + + $result = db_query("SELECT * FROM {view_argument} WHERE vid = $view->vid ORDER BY position ASC"); + + $view->argument = array(); + while ($arg = db_fetch_array($result)) { + $arg['id'] = $arg['type']; + $view->argument[$arg['position']] = $arg; + } + + $result = db_query("SELECT * FROM {view_tablefield} WHERE vid = $view->vid ORDER BY position ASC"); + + $view->field = array(); + while ($arg = db_fetch_array($result)) { + if ($arg['tablename'] == 'n') { + $arg['tablename'] = 'node'; + } + $arg['id'] = $arg['fullname'] = "$arg[tablename].$arg[field]"; + $arg['queryname'] = "$arg[tablename]_$arg[field]"; + $view->field[] = $arg; + } + + $result = db_query("SELECT * FROM {view_filter} WHERE vid = $view->vid ORDER BY position ASC"); + + // TODO - Is it safe to ignore this $filters variable? This function depends + // on lots of additional code needed to call hook_implements and construct + // all the views tables, so using it will add a lot of code to this file. + //$filters = _views_get_filters(); + $view->filter = array(); + while ($filter = db_fetch_array($result)) { + if (substr($filter['field'], 0, 2) == 'n.') { + $filter['field'] = 'node' . substr($filter['field'], 1); + } + + if ($filter['operator'] == 'AND' || + $filter['operator'] == 'OR' || + $filter['operator'] == 'NOR') { + // TODO - need another way to identify this type of filter + // without being able to call hook_implements(). + //|| $filters[$filter['field']]['value-type'] == 'array' ) { + if ($filter['value'] !== NULL && $filter['value'] !== '') { + $filter['value'] = explode(',', $filter['value']); + } + else { + $filter['value'] = array(); + } + } + $filter['id'] = $filter['field']; + $bits = explode('.', $filter['field']); + $filter['tablename'] = $bits[0]; + $filter['field'] = $bits[1]; + $view->filter[$filter['position']] = $filter; + } + + $result = db_query("SELECT * FROM {view_exposed_filter} WHERE vid = $view->vid ORDER BY position ASC"); + + $view->exposed_filter = array(); + while ($arg = db_fetch_array($result)) { + $arg['id'] = $arg['field']; + $view->exposed_filter[] = $arg; + } + + $cache['vid'][$view->vid] = $view; + $cache['name'][$view->name] = $view; + + return $view; +} + +/** + * Delete a version 1 view from the database. + * + */ +function views1_delete($arg) { + static $cache = array(); + $where = (is_numeric($arg) ? "v.vid = %d" : "v.name = '%s'"); + $view = db_fetch_object(db_query("SELECT v.* FROM {view_view} v WHERE $where", $arg)); + + if (!$view->name) { + return NULL; + } + + + + $result = db_query("DELETE FROM {view_sort} WHERE vid = $view->vid"); + $result = db_query("DELETE FROM {view_argument} WHERE vid = $view->vid"); + $result = db_query("DELETE FROM {view_tablefield} WHERE vid = $view->vid"); + $result = db_query("DELETE FROM {view_filter} WHERE vid = $view->vid"); + $result = db_query("DELETE FROM {view_exposed_filter} WHERE vid = $view->vid"); + $result = db_query("DELETE FROM {view_view} WHERE vid = $view->vid"); +} + diff --git a/sites/all/modules/views/includes/form.inc b/sites/all/modules/views/includes/form.inc new file mode 100644 index 0000000..e7c2b88 --- /dev/null +++ b/sites/all/modules/views/includes/form.inc @@ -0,0 +1,300 @@ + NULL, 'submitted' => FALSE, 'input' => $_POST, 'method' => 'post'); + + $args = isset($form_state['args']) ? $form_state['args'] : array(); + $cacheable = FALSE; + + if (isset($_SESSION['batch_form_state'])) { + // We've been redirected here after a batch processing : the form has + // already been processed, so we grab the post-process $form_state value + // and move on to form display. See _batch_finished() function. + $form_state = $_SESSION['batch_form_state']; + unset($_SESSION['batch_form_state']); + } + else { + // If the incoming $_POST contains a form_build_id, we'll check the + // cache for a copy of the form in question. If it's there, we don't + // have to rebuild the form to proceed. In addition, if there is stored + // form_state data from a previous step, we'll retrieve it so it can + // be passed on to the form processing code. + if (isset($_POST['form_id']) && $_POST['form_id'] == $form_id && !empty($_POST['form_build_id'])) { + $form = form_get_cache($_POST['form_build_id'], $form_state); + if (!empty($form['#no_cache']) || empty($form)) { + unset($form); + } + } + + // If the previous bit of code didn't result in a populated $form + // object, we're hitting the form for the first time and we need + // to build it from scratch. + if (!isset($form)) { + $form_state['post'] = $form_state['input']; + // Use a copy of the function's arguments for manipulation + $args_temp = $args; + $args_temp[0] = &$form_state; + array_unshift($args_temp, $form_id); + + $form = call_user_func_array('drupal_retrieve_form', $args_temp); + $form_build_id = 'form-' . md5(mt_rand()); + $form['#build_id'] = $form_build_id; + + if ($form_state['method'] == 'get' && !isset($form['#method'])) { + $form['#method'] = 'get'; + } + + drupal_prepare_form($form_id, $form, $form_state); + // Store a copy of the unprocessed form for caching and indicate that it + // is cacheable if #cache will be set. + $original_form = $form; + $cacheable = TRUE; + unset($form_state['post']); + } + $form['#post'] = $form_state['input']; + + // Now that we know we have a form, we'll process it (validating, + // submitting, and handling the results returned by its submission + // handlers. Submit handlers accumulate data in the form_state by + // altering the $form_state variable, which is passed into them by + // reference. + drupal_process_form_new($form_id, $form, $form_state); + + // If we were told not to redirect, but not told to re-render, return + // here. + if (!empty($form_state['executed']) && empty($form_state['rerender'])) { + return; + } + + if ($cacheable && !empty($form['#cache']) && empty($form['#no_cache'])) { + // Caching is done past drupal_process_form so #process callbacks can + // set #cache. By not sending the form state, we avoid storing + // $form_state['storage']. + form_set_cache($form_build_id, $original_form, NULL); + } + } + + // Most simple, single-step forms will be finished by this point -- + // drupal_process_form() usually redirects to another page (or to + // a 'fresh' copy of the form) once processing is complete. If one + // of the form's handlers has set $form_state['redirect'] to FALSE, + // the form will simply be re-rendered with the values still in its + // fields. + // + // If $form_state['storage'] or $form_state['rebuild'] have been + // set by any submit or validate handlers, however, we know that + // we're in a complex multi-part process of some sort and the form's + // workflow is NOT complete. We need to construct a fresh copy of + // the form, passing in the latest $form_state in addition to any + // other variables passed into drupal_get_form(). + + if (!empty($form_state['rebuild']) || !empty($form_state['storage'])) { + $form = drupal_rebuild_form_new($form_id, $form_state, $args); + } + + // If we haven't redirected to a new location by now, we want to + // render whatever form array is currently in hand. + return drupal_render_form($form_id, $form); +} + +/** + * Views' replacement of drupal_rebuild_form. + * + * This change merely respects a form's wishes not to be cached. + */ +function drupal_rebuild_form_new($form_id, &$form_state, $args, $form_build_id = NULL) { + // Remove the first argument. This is $form_id.when called from + // drupal_get_form and the original $form_state when called from some AHAH + // callback. Neither is needed. After that, put in the current state. + $args[0] = &$form_state; + // And the form_id. + array_unshift($args, $form_id); + $form = call_user_func_array('drupal_retrieve_form', $args); + + if (!isset($form_build_id)) { + // We need a new build_id for the new version of the form. + $form_build_id = 'form-' . md5(mt_rand()); + } + $form['#build_id'] = $form_build_id; + drupal_prepare_form($form_id, $form, $form_state); + + if (empty($form['#no_cache'])) { + // Now, we cache the form structure so it can be retrieved later for + // validation. If $form_state['storage'] is populated, we'll also cache + // it so that it can be used to resume complex multi-step processes. + form_set_cache($form_build_id, $form, $form_state); + } + + // Originally this called drupal_process_form, but all that happens there + // is form_builder and then submission; and the rebuilt form is not + // allowed to submit. Therefore, just do this: + $form['#post'] = $form_state['input']; + $form = form_builder($form_id, $form, $form_state); + + return $form; +} + +/** + * Views' replacement for drupal_process_form that accepts commands + * not to redirect, as well as forcing processing of 'get' method forms. + */ +function drupal_process_form_new($form_id, &$form, &$form_state) { + // submitting, and handling the results returned by its submission + // handlers. Submit handlers accumulate data in the form_state by + // altering the $form_state variable, which is passed into them by + // reference. + $form_state['values'] = array(); + + // With $_GET, these forms are always submitted. + if ($form_state['method'] == 'get') { + if (!isset($form['#post']['form_build_id'])) { + $form['#post']['form_build_id'] = $form['#build_id']; + } + if (!isset($form['#post']['form_id'])) { + $form['#post']['form_id'] = $form_id; + } + if (!isset($form['#post']['form_token']) && isset($form['#token'])) { + $form['#post']['form_token'] = drupal_get_token($form['#token']); + } + } + + $form = form_builder($form_id, $form, $form_state); + // Only process the form if it is programmed or the form_id coming + // from the POST data is set and matches the current form_id. + + if ((!empty($form['#programmed'])) || (!empty($form['#post']) && (isset($form['#post']['form_id']) && ($form['#post']['form_id'] == $form_id)))) { + drupal_validate_form_new($form_id, $form, $form_state); + + // form_clean_id() maintains a cache of element IDs it has seen, + // so it can prevent duplicates. We want to be sure we reset that + // cache when a form is processed, so scenerios that result in + // the form being built behind the scenes and again for the + // browser don't increment all the element IDs needlessly. + form_clean_id(NULL, TRUE); + + if ((!empty($form_state['submitted'])) && !form_get_errors() && empty($form_state['rebuild'])) { + $form_state['redirect'] = NULL; + form_execute_handlers('submit', $form, $form_state); + + // We'll clear out the cached copies of the form and its stored data + // here, as we've finished with them. The in-memory copies are still + // here, though. + if (variable_get('cache', CACHE_DISABLED) == CACHE_DISABLED && !empty($form_state['values']['form_build_id'])) { + cache_clear_all('form_' . $form_state['values']['form_build_id'], 'cache_form'); + cache_clear_all('storage_' . $form_state['values']['form_build_id'], 'cache_form'); + } + + // If batches were set in the submit handlers, we process them now, + // possibly ending execution. We make sure we do not react to the batch + // that is already being processed (if a batch operation performs a + // drupal_execute). + if ($batch =& batch_get() && !isset($batch['current_set'])) { + // The batch uses its own copies of $form and $form_state for + // late execution of submit handers and post-batch redirection. + $batch['form'] = $form; + $batch['form_state'] = $form_state; + $batch['progressive'] = !$form['#programmed']; + batch_process(); + // Execution continues only for programmatic forms. + // For 'regular' forms, we get redirected to the batch processing + // page. Form redirection will be handled in _batch_finished(), + // after the batch is processed. + } + + // If no submit handlers have populated the $form_state['storage'] + // bundle, and the $form_state['rebuild'] flag has not been set, + // we're finished and should redirect to a new destination page + // if one has been set (and a fresh, unpopulated copy of the form + // if one hasn't). If the form was called by drupal_execute(), + // however, we'll skip this and let the calling function examine + // the resulting $form_state bundle itself. + if (!$form['#programmed'] && empty($form_state['rebuild']) && empty($form_state['storage'])) { + if (!empty($form_state['no_redirect'])) { + $form_state['executed'] = TRUE; + } + else { + drupal_redirect_form($form, $form_state['redirect']); + } + } + } + } +} + +/** + * The original version of drupal_validate_form does not have an override for + * the static check to only validate a form id once. Unfortunately, we need + * to be able to overridet his. + */ +function drupal_validate_form_new($form_id, $form, &$form_state) { + static $validated_forms = array(); + + if (isset($validated_forms[$form_id]) && empty($form_state['must_validate'])) { + return; + } + + // If the session token was set by drupal_prepare_form(), ensure that it + // matches the current user's session. + if (isset($form['#token'])) { + if (!drupal_valid_token($form_state['values']['form_token'], $form['#token'])) { + // Setting this error will cause the form to fail validation. + form_set_error('form_token', t('Validation error, please try again. If this error persists, please contact the site administrator.')); + } + } + + _form_validate($form, $form_state, $form_id); + $validated_forms[$form_id] = TRUE; +} + +/** + * Process callback to add dependency to form items. + * + * Usage: + * + * On any form item, add + * - @code '#process' => 'views_process_dependency' @endcode + * - @code '#dependency' => array('id-of-form-without-the-#' => array(list, of, values, that, make, this, gadget, visible)); @endcode + */ +function views_process_dependency($element, $edit, &$form_state, &$form) { + static $dependencies; + if (isset($element['#dependency']) && !isset($dependencies[$element['#id']])) { + if (!isset($element['#dependency_count'])) { + $element['#dependency_count'] = 1; + } + if (!empty($form_state['ajax'])) { + $form_state['js settings']['viewsAjax']['formRelationships'][$element['#id']] = array('num' => $element['#dependency_count'], 'values' => $element['#dependency']); + } + else { + views_add_js('dependent'); + $options['viewsAjax']['formRelationships'][$element['#id']] = array('num' => $element['#dependency_count'], 'values' => $element['#dependency']); + drupal_add_js($options, 'setting'); + } + $dependencies[$element['#id']] = TRUE; + } + + return $element; +} + +/** + * #process callback to see if we need to check_plain() the options. + * + * Since FAPI is inconsistent, the #options are sanitized for you in all cases + * _except_ checkboxes. We have form elements that are sometimes 'select' and + * sometimes 'checkboxes', so we need decide late in the form rendering cycle + * if the options need to be sanitized before they're rendered. This callback + * inspects the type, and if it's still 'checkboxes', does the sanitation. + */ +function views_process_check_options($element, $edit, &$form_state, &$form) { + if ($element['#type'] == 'checkboxes' || $element['#type'] == 'checkbox') { + $element['#options'] = array_map('check_plain', $element['#options']); + } + return $element; +} + diff --git a/sites/all/modules/views/includes/handlers.inc b/sites/all/modules/views/includes/handlers.inc new file mode 100644 index 0000000..091e625 --- /dev/null +++ b/sites/all/modules/views/includes/handlers.inc @@ -0,0 +1,1483 @@ +set_definition($definition); + // let the handler have something like a constructor. + $handler->construct(); + + return $handler; +} + +/** + * Attempt to find the include file for a given handler from its definition. + * + * This will also attempt to include all parents, though we're maxing the + * parent chain to 10 to prevent infinite loops. + */ +function views_include_handler($definition, $type, $count = 0) { + // Do not proceed if the class already exists. + if (isset($definition['handler']) && class_exists($definition['handler'])) { + return TRUE; + } + + // simple infinite loop prevention. + if ($count > 10) { + vpr(t('Handler @handler include tried to loop infinitely!', array('@handler' => $definition['handler']))); + return FALSE; + } + + if (!isset($definition['path'])) { + if ($type == 'handler') { + $definition += views_fetch_handler_data($definition['handler']); + } + else { + $definition += views_fetch_plugin_data($type, $definition['handler']); + } + } + + if (!empty($definition['parent'])) { + if ($type == 'handler') { + $parent = views_fetch_handler_data($definition['parent']); + } + else { + $parent = views_fetch_plugin_data($type, $definition['parent']); + } + + if ($parent) { + $rc = views_include_handler($parent, $type, $count + 1); + // If the parent chain cannot be included, don't try; this will + // help alleviate problems with modules with cross dependencies. + if (!$rc) { + return FALSE; + } + } + } + + if (isset($definition['path']) && $definition['file']) { + $filename = './' . $definition['path'] . '/' . $definition['file']; + if (file_exists($filename)) { + require_once $filename; + } + } + + return class_exists($definition['handler']); +} + +/** + * Prepare a handler's data by checking defaults and such. + */ +function _views_prepare_handler($definition, $data, $field) { + foreach (array('group', 'title', 'title short', 'help', 'real field') as $key) { + if (!isset($definition[$key])) { + // First check the field level + if (!empty($data[$field][$key])) { + $definition[$key] = $data[$field][$key]; + } + // Then if that doesn't work, check the table level + else if (!empty($data['table'][$key])) { + $definition[$key] = $data['table'][$key]; + } + } + } + + return _views_create_handler($definition); +} + +/** + * Fetch the handler data from cache. + */ +function views_fetch_handler_data($handler = NULL) { + static $cache = NULL; + if (!isset($cache)) { + $start = views_microtime(); + + $cache = views_discover_handlers(); + + vpr('Views handlers build time: ' . (views_microtime() - $start) * 1000 . ' ms'); + } + + if (!$handler) { + return $cache; + } + else if (isset($cache[$handler])) { + return $cache[$handler]; + } + + // Return an empty array if there is no match. + return array(); +} + +/** + * Builds and return a list of all handlers available in the system. + * + * @return Nested array of handlers + */ +function views_discover_handlers() { + $cache = array(); + // Get handlers from all modules. + foreach (module_implements('views_handlers') as $module) { + $function = $module . '_views_handlers'; + $result = $function(); + if (!is_array($result)) { + continue; + } + + $module_dir = isset($result['info']['module']) ? $result['info']['module'] : $module; + $path = isset($result['info']['path']) ? $result['info']['path'] : drupal_get_path('module', $module_dir); + + foreach ($result['handlers'] as $handler => $def) { + if (!isset($def['module'])) { + $def['module'] = $module_dir; + } + if (!isset($def['path'])) { + $def['path'] = $path; + } + if (!isset($def['file'])) { + $def['file'] = "$handler.inc"; + } + if (!isset($def['handler'])) { + $def['handler'] = $handler; + } + // merge the new data in + $cache[$handler] = $def; + } + } + return $cache; +} + +/** + * Fetch a handler to join one table to a primary table from the data cache + */ +function views_get_table_join($table, $base_table) { + $data = views_fetch_data($table); + if (isset($data['table']['join'][$base_table])) { + $h = $data['table']['join'][$base_table]; + if (!empty($h['handler']) && class_exists($h['handler'])) { + $handler = new $h['handler']; + } + else { + $handler = new views_join(); + } + + // Fill in some easy defaults + $handler->definition = $h; + if (empty($handler->definition['table'])) { + $handler->definition['table'] = $table; + } + // If this is empty, it's a direct link. + if (empty($handler->definition['left_table'])) { + $handler->definition['left_table'] = $base_table; + } + + if (isset($h['arguments'])) { + call_user_func_array(array(&$handler, 'construct'), $h['arguments']); + } + else { + $handler->construct(); + } + + return $handler; + } + // DEBUG -- identify missing handlers + vpr("Missing join: $table $base_table"); +} + +/** + * Base handler, from which all the other handlers are derived. + * It creates a common interface to create consistency amongst + * handlers and data. + * + * This class would be abstract in PHP5, but PHP4 doesn't understand that. + * + * Definition terms: + * - table: The actual table this uses; only specify if different from + * the table this is attached to. + * - real field: The actual field this uses; only specify if different from + * the field this item is attached to. + * - group: A text string representing the 'group' this item is attached to, + * for display in the UI. Examples: "Node", "Taxonomy", "Comment", + * "User", etc. This may be inherited from the parent definition or + * the 'table' definition. + * - title: The title for this handler in the UI. This may be inherited from + * the parent definition or the 'table' definition. + * - help: A more informative string to give to the user to explain what this + * field/handler is or does. + * - access callback: If this field should have access control, this could + * be a function to use. 'user_access' is a common + * function to use here. If not specified, no access + * control is provided. + * - access arguments: An array of arguments for the access callback. + */ +class views_handler extends views_object { + /** + * init the handler with necessary data. + * @param $view + * The $view object this handler is attached to. + * @param $options + * The item from the database; the actual contents of this will vary + * based upon the type of handler. + */ + function init(&$view, $options) { + $this->view = &$view; + $this->unpack_options($this->options, $options); + + // This exist on most handlers, but not all. So they are still optional. + if (isset($options['table'])) { + $this->table = $options['table']; + } + + if (isset($this->definition['real field'])) { + $this->real_field = $this->definition['real field']; + } + + if (isset($this->definition['field'])) { + $this->real_field = $this->definition['field']; + } + + if (isset($options['field'])) { + $this->field = $options['field']; + if (!isset($this->real_field)) { + $this->real_field = $options['field']; + } + } + + $this->query = &$view->query; + } + + /** + * Return a string representing this handler's name in the UI. + */ + function ui_name($short = FALSE) { + $title = ($short && isset($this->definition['title short'])) ? $this->definition['title short'] : $this->definition['title']; + return t('!group: !title', array('!group' => $this->definition['group'], '!title' => $title)); + } + + /** + * Provide a form for setting options. + */ + function options_form(&$form, &$form_state) { } + + /** + * Validate the options form. + */ + function options_validate($form, &$form_state) { } + + /** + * Perform any necessary changes to the form values prior to storage. + * There is no need for this function to actually store the data. + */ + function options_submit($form, &$form_state) { } + + /** + * If a handler has 'extra options' it will get a little settings widget and + * another form called extra_options. + */ + function has_extra_options() { return FALSE; } + + /** + * Provide defaults for the handler. + */ + function extra_options(&$option) { } + + /** + * Provide a form for setting options. + */ + function extra_options_form(&$form, &$form_state) { } + + /** + * Validate the options form. + */ + function extra_options_validate($form, &$form_state) { } + + /** + * Perform any necessary changes to the form values prior to storage. + * There is no need for this function to actually store the data. + */ + function extra_options_submit($form, &$form_state) { } + + /** + * Set new exposed option defaults when exposed setting is flipped + * on. + */ + function expose_options() { } + /** + * Render our chunk of the exposed filter form when selecting + */ + function exposed_form(&$form, &$form_state) { } + + /** + * Validate the exposed filter form + */ + function exposed_validate(&$form, &$form_state) { } + + /** + * Submit the exposed filter form + */ + function exposed_submit(&$form, &$form_state) { } + + /** + * Get information about the exposed form for the form renderer. + * + * @return + * An array with the following keys: + * - operator: The $form key of the operator. Set to NULL if no operator. + * - value: The $form key of the value. Set to NULL if no value. + * - label: The label to use for this piece. + */ + function exposed_info() { } + + /** + * Determine if a handler can be exposed. + */ + function can_expose() { return FALSE; } + + /** + * Check whether current user has access to this handler. + * + * @return boolean + */ + function access() { + if (isset($this->definition['access callback']) && function_exists($this->definition['access callback'])) { + if (isset($this->definition['access arguments']) && is_array($this->definition['access arguments'])) { + return call_user_func_array($this->definition['access callback'], $this->definition['access arguments']); + } + return $this->definition['access callback'](); + } + + return TRUE; + } + + /** + * Run before the view is built. + * + * This gives all the handlers some time to set up before any handler has + * been fully run. + */ + function pre_query() { } + + /** + * Called just prior to query(), this lets a handler set up any relationship + * it needs. + */ + function set_relationship() { + // Ensure this gets set to something. + $this->relationship = NULL; + + // Don't process non-existant relationships. + if (empty($this->options['relationship']) || $this->options['relationship'] == 'none') { + return; + } + + $relationship = $this->options['relationship']; + + // Ignore missing/broken relationships. + if (empty($this->view->relationship[$relationship])) { + return; + } + + // Check to see if the relationship has already processed. If not, then we + // cannot process it. + if (empty($this->view->relationship[$relationship]->alias)) { + return; + } + + // Finally! + $this->relationship = $this->view->relationship[$relationship]->alias; + } + + /** + * Add this handler into the query. + * + * If we were using PHP5, this would be abstract. + */ + function query() { } + + /** + * Ensure the main table for this handler is in the query. This is used + * a lot. + */ + function ensure_my_table() { + if (!isset($this->table_alias)) { + $this->table_alias = $this->query->ensure_table($this->table, $this->relationship); + } + return $this->table_alias; + } + + /** + * Provide text for the administrative summary + */ + function admin_summary() { } + + /** + * Determine if the argument needs a style plugin. + * + * @return TRUE/FALSE + */ + function needs_style_plugin() { return FALSE; } + + /** + * Determine if this item is 'exposed', meaning it provides form elements + * to let users modify the view. + * + * @return TRUE/FALSE + */ + function is_exposed() { + return !empty($this->options['exposed']); + } + + /** + * Take input from exposed filters and assign to this handler, if necessary. + */ + function accept_exposed_input($input) { return TRUE; } + + /** + * If set to remember exposed input in the session, store it there. + */ + function store_exposed_input($input, $status) { return TRUE; } + + /** + * Get the join object that should be used for this handler. + * + * This method isn't used a great deal, but it's very handy for easily + * getting the join if it is necessary to make some changes to it, such + * as adding an 'extra'. + */ + function get_join() { + // get the join from this table that links back to the base table. + // Determine the primary table to seek + if (empty($this->query->relationships[$this->relationship])) { + $base_table = $this->query->base_table; + } + else { + $base_table = $this->query->relationships[$this->relationship]['base']; + } + + $join = views_get_table_join($this->table, $base_table); + if ($join) { + return drupal_clone($join); + } + } + + /** + * Validates the handler against the complete View. + * + * This is called when the complete View is being validated. For validating + * the handler options form use options_validate(). + * + * @see views_handler::options_validate() + * + * @return + * Empty array if the handler is valid; an array of error strings if it is not. + */ + function validate() { return array(); } + + /** + * Determine if the handler is considered 'broken', meaning it's a + * a placeholder used when a handler can't be found. + */ + function broken() { } +} + +/** + * This many to one helper object is used on both arguments and filters. + * + * @todo This requires extensive documentation on how this class is to + * be used. For now, look at the arguments and filters that use it. Lots + * of stuff is just pass-through but there are definitely some interesting + * areas where they interact. + * + * Any handler that uses this can have the following possibly additional + * definition terms: + * - numeric: If true, treat this field as numeric, using %d instead of %s in + * queries. + * + */ +class views_many_to_one_helper { + function views_many_to_one_helper(&$handler) { + $this->handler = &$handler; + } + + public static function option_definition(&$options) { + $options['reduce_duplicates'] = array('default' => FALSE); + } + + function options_form(&$form, &$form_state) { + $form['reduce_duplicates'] = array( + '#type' => 'checkbox', + '#title' => t('Reduce duplicates'), + '#description' => t('This filter can cause items that have more than one of the selected options to appear as duplicate results. If this filter causes duplicate results to occur, this checkbox can reduce those duplicates; however, the more terms it has to search for, the less performant the query will be, so use this with caution. Shouldn\'t be set on single-value fields, as it may cause values to disappear from display, if used on an incompatible field.'), + '#default_value' => !empty($this->handler->options['reduce_duplicates']), + ); + } + + /** + * Sometimes the handler might want us to use some kind of formula, so give + * it that option. If it wants us to do this, it must set $helper->formula = TRUE + * and implement handler->get_formula(); + */ + function get_field() { + if (!empty($this->formula)) { + return $this->handler->get_formula(); + } + else { + return $this->handler->table_alias . '.' . $this->handler->real_field; + } + } + + /** + * Add a table to the query. + * + * This is an advanced concept; not only does it add a new instance of the table, + * but it follows the relationship path all the way down to the relationship + * link point and adds *that* as a new relationship and then adds the table to + * the relationship, if necessary. + */ + function add_table($join = NULL, $alias = NULL) { + // This is used for lookups in the many_to_one table. + $field = $this->handler->table . '.' . $this->handler->field; + + if (empty($join)) { + $join = $this->get_join(); + } + + // See if there's a chain between us and the base relationship. If so, we need + // to create a new relationship to use. + $relationship = $this->handler->relationship; + + // Determine the primary table to seek + if (empty($this->handler->query->relationships[$relationship])) { + $base_table = $this->handler->query->base_table; + } + else { + $base_table = $this->handler->query->relationships[$relationship]['base']; + } + + // Cycle through the joins. This isn't as error-safe as the normal + // ensure_path logic. Perhaps it should be. + $r_join = drupal_clone($join); + while ($r_join->left_table != $base_table) { + $r_join = views_get_table_join($r_join->left_table, $base_table); + } + // If we found that there are tables in between, add the relationship. + if ($r_join->table != $join->table) { + $relationship = $this->handler->query->add_relationship($this->handler->table . '_' . $r_join->table, $r_join, $r_join->table, $this->handler->relationship); + } + + // And now add our table, using the new relationship if one was used. + $alias = $this->handler->query->add_table($this->handler->table, $relationship, $join, $alias); + + // Store what values are used by this table chain so that other chains can + // automatically discard those values. + if (empty($this->handler->view->many_to_one_tables[$field])) { + $this->handler->view->many_to_one_tables[$field] = $this->handler->value; + } + else { + $this->handler->view->many_to_one_tables[$field] = array_merge($this->handler->view->many_to_one_tables[$field], $this->handler->value); + } + + return $alias; + } + + function get_join() { + return $this->handler->get_join(); + } + + /** + * Provide the proper join for summary queries. This is important in part because + * it will cooperate with other arguments if possible. + */ + function summary_join() { + $field = $this->handler->table . '.' . $this->handler->field; + $join = $this->get_join(); + + // shortcuts + $options = $this->handler->options; + $view = &$this->handler->view; + $query = &$this->handler->query; + + if (!empty($options['require_value'])) { + $join->type = 'INNER'; + } + + if (empty($options['add_table']) || empty($view->many_to_one_tables[$field])) { + return $query->ensure_table($this->handler->table, $this->handler->relationship, $join); + } + else { + if (!empty($view->many_to_one_tables[$field])) { + foreach ($view->many_to_one_tables[$field] as $value) { + $join->extra = array( + array( + 'field' => $this->handler->real_field, + 'operator' => '!=', + 'value' => $value, + 'numeric' => !empty($this->definition['numeric']), + ), + ); + } + } + return $this->add_table($join); + } + } + + /** + * Override ensure_my_table so we can control how this joins in. + * The operator actually has influence over joining. + */ + function ensure_my_table() { + if (!isset($this->handler->table_alias)) { + // For 'or' if we're not reducing duplicates, we get the absolute simplest: + $field = $this->handler->table . '.' . $this->handler->field; + if ($this->handler->operator == 'or' && empty($this->handler->options['reduce_duplicates'])) { + if (empty($this->handler->options['add_table']) && empty($this->handler->view->many_to_one_tables[$field])) { + // query optimization, INNER joins are slightly faster, so use them + // when we know we can. + $join = $this->get_join(); + $join->type = 'INNER'; + $this->handler->table_alias = $this->handler->query->ensure_table($this->handler->table, $this->handler->relationship, $join); + $this->handler->view->many_to_one_tables[$field] = $this->handler->value; + } + else { + $join = $this->get_join(); + $join->type = 'LEFT'; + if (!empty($this->handler->view->many_to_one_tables[$field])) { + foreach ($this->handler->view->many_to_one_tables[$field] as $value) { + $join->extra = array( + array( + 'field' => $this->handler->real_field, + 'operator' => '!=', + 'value' => $value, + 'numeric' => !empty($this->handler->definition['numeric']), + ), + ); + } + } + + $this->handler->table_alias = $this->add_table($join); + } + + return $this->handler->table_alias; + } + + if ($this->handler->operator != 'not') { + // If it's an and or an or, we do one join per selected value. + // Clone the join for each table: + $this->handler->table_aliases = array(); + foreach ($this->handler->value as $value) { + $join = $this->get_join(); + if ($this->handler->operator == 'and') { + $join->type = 'INNER'; + } + $join->extra = array( + array( + 'field' => $this->handler->real_field, + 'value' => $value, + 'numeric' => !empty($this->handler->definition['numeric']), + ), + ); + + // The table alias needs to be unique to this value across the + // multiple times the filter or argument is called by the view. + if (!isset($this->handler->view->many_to_one_aliases[$field][$value])) { + if (!isset($this->handler->view->many_to_one_count[$this->handler->table])) { + $this->handler->view->many_to_one_count[$this->handler->table] = 0; + } + $this->handler->view->many_to_one_aliases[$field][$value] = $this->handler->table . '_value_' . ($this->handler->view->many_to_one_count[$this->handler->table]++); + } + $alias = $this->handler->table_aliases[$value] = $this->add_table($join, $this->handler->view->many_to_one_aliases[$field][$value]); + + // and set table_alias to the first of these. + if (empty($this->handler->table_alias)) { + $this->handler->table_alias = $alias; + } + } + } + else { + // For not, we just do one join. We'll add a where clause during + // the query phase to ensure that $table.$field IS NULL. + $join = $this->get_join(); + $join->type = 'LEFT'; + $join->extra = array(); + $join->extra_type = 'OR'; + foreach ($this->handler->value as $value) { + $join->extra[] = array( + 'field' => $this->handler->real_field, + 'value' => $value, + 'numeric' => !empty($this->handler->definition['numeric']), + ); + } + + $this->handler->table_alias = $this->add_table($join); + } + } + return $this->handler->table_alias; + } + + function add_filter() { + if (empty($this->handler->value)) { + return; + } + $this->handler->ensure_my_table(); + + // Shorten some variables: + $field = $this->get_field(); + $options = $this->handler->options; + $operator = $this->handler->operator; + if (empty($options['group'])) { + $options['group'] = 0; + } + + $placeholder = !empty($this->handler->definition['numeric']) ? '%d' : "'%s'"; + + if ($operator == 'not') { + $this->handler->query->add_where($options['group'], "$field IS NULL"); + } + else if ($operator == 'or' && empty($options['reduce_duplicates'])) { + if (count($this->handler->value) > 1) { + $replace = array_fill(0, sizeof($this->handler->value), $placeholder); + $in = '(' . implode(", ", $replace) . ')'; + $this->handler->query->add_where($options['group'], "$field IN $in", $this->handler->value); + } + else { + $this->handler->query->add_where($options['group'], "$field = $placeholder", $this->handler->value); + } + } + else { + $field = $this->handler->real_field; + $clauses = array(); + foreach ($this->handler->table_aliases as $value => $alias) { + $clauses[] = "$alias.$field = $placeholder"; + } + + $group = empty($options['group']) ? 0 : $options['group']; + + // implode on either AND or OR. + $this->handler->query->add_where($group, implode(' ' . strtoupper($operator) . ' ', $clauses), $this->handler->value); + } + } +} + +/* + * Break x,y,z and x+y+z into an array. Numeric only. + * + * @param $str + * The string to parse. + * @param $filter + * The filter object to use as a base. + * + * @return $filter + * The new filter object. + */ +function views_break_phrase($str, &$filter) { + if (!$filter) { + $filter = new stdClass(); + } + + // Set up defaults: + if (!isset($filter->value)) { + $filter->value = array(); + } + + if (!isset($filter->operator)) { + $filter->operator = 'or'; + } + + if ($str == '') { + return $filter; + } + + if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str)) { + // The '+' character in a query string may be parsed as ' '. + $filter->operator = 'or'; + $filter->value = preg_split('/[+ ]/', $str); + } + else if (preg_match('/^([0-9]+,)*[0-9]+$/', $str)) { + $filter->operator = 'and'; + $filter->value = explode(',', $str); + } + + // Keep an 'error' value if invalid strings were given. + if (!empty($str) && (empty($filter->value) || !is_array($filter->value))) { + $filter->value = array(-1); + return $filter; + } + + // Doubly ensure that all values are numeric only. + foreach ($filter->value as $id => $value) { + $filter->value[$id] = intval($value); + } + + return $filter; +} + +// -------------------------------------------------------------------------- +// Date helper functions + +/** + * Figure out what timezone we're in; needed for some date manipulations. + */ +function views_get_timezone() { + global $user; + if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) { + $timezone = $user->timezone; + } + else { + $timezone = variable_get('date_default_timezone', 0); + } + + // set up the database timezone + if (in_array($GLOBALS['db_type'], array('mysql', 'mysqli', 'pgsql'))) { + $offset = '+00:00'; + static $already_set = false; + if (!$already_set) { + if ($GLOBALS['db_type'] == 'pgsql') { + db_query("SET TIME ZONE INTERVAL '$offset' HOUR TO MINUTE"); + } + elseif ($GLOBALS['db_type'] == 'mysqli') { + db_query("SET @@session.time_zone = '$offset'"); + } + elseif ($GLOBALS['db_type'] == 'mysql' && version_compare(db_version(), '4.1.3', '>=')) { + db_query("SET @@session.time_zone = '$offset'"); + } + + $already_set = true; + } + } + + return $timezone; +} + +/** + * Helper function to create cross-database SQL dates. + * + * @param $field + * The real table and field name, like 'tablename.fieldname'. + * @param $field_type + * The type of date field, 'int' or 'datetime'. + * @param $set_offset + * The name of a field that holds the timezone offset or a fixed timezone + * offset value. If not provided, the normal Drupal timezone handling + * will be used, i.e. $set_offset = 0 will make no timezone adjustment. + * @return + * An appropriate SQL string for the db type and field type. + */ +function views_date_sql_field($field, $field_type = 'int', $set_offset = NULL) { + $db_type = $GLOBALS['db_type']; + $offset = $set_offset !== NULL ? $set_offset : views_get_timezone(); + switch ($db_type) { + case 'mysql': + case 'mysqli': + switch ($field_type) { + case 'int': + $field = "FROM_UNIXTIME($field)"; + break; + case 'datetime': + break; + } + if (!empty($offset)) { + $field = "($field + INTERVAL $offset SECOND)"; + } + return $field; + case 'pgsql': + switch ($field_type) { + case 'int': + $field = "$field::ABSTIME"; + break; + case 'datetime': + break; + } + if (!empty($offset)) { + $field = "($field + INTERVAL '$offset SECONDS')"; + } + return $field; + } +} + +/** + * Helper function to create cross-database SQL date formatting. + * + * @param $format + * A format string for the result, like 'Y-m-d H:i:s'. + * @param $field + * The real table and field name, like 'tablename.fieldname'. + * @param $field_type + * The type of date field, 'int' or 'datetime'. + * @param $set_offset + * The name of a field that holds the timezone offset or a fixed timezone + * offset value. If not provided, the normal Drupal timezone handling + * will be used, i.e. $set_offset = 0 will make no timezone adjustment. + * @return + * An appropriate SQL string for the db type and field type. + */ +function views_date_sql_format($format, $field, $field_type = 'int', $set_offset = NULL) { + $db_type = $GLOBALS['db_type']; + $field = views_date_sql_field($field, $field_type, $set_offset); + switch ($db_type) { + case 'mysql': + case 'mysqli': + $replace = array( + 'Y' => '%Y', + 'y' => '%y', + 'M' => '%%b', + 'm' => '%m', + 'n' => '%c', + 'F' => '%M', + 'D' => '%a', + 'd' => '%%d', + 'l' => '%W', + 'j' => '%e', + 'W' => '%v', + 'H' => '%H', + 'h' => '%h', + 'i' => '%i', + 's' => '%%s', + 'A' => '%p', + ); + $format = strtr($format, $replace); + return "DATE_FORMAT($field, '$format')"; + case 'pgsql': + $replace = array( + 'Y' => 'YYYY', + 'y' => 'YY', + 'M' => 'Mon', + 'm' => 'MM', + 'n' => 'MM', // no format for Numeric representation of a month, without leading zeros + 'F' => 'Month', + 'D' => 'Dy', + 'd' => 'DD', + 'l' => 'Day', + 'j' => 'DD', // no format for Day of the month without leading zeros + 'W' => 'WW', + 'H' => 'HH24', + 'h' => 'HH12', + 'i' => 'MI', + 's' => 'SS', + 'A' => 'AM', + ); + $format = strtr($format, $replace); + return "TO_CHAR($field, '$format')"; + } +} + +/** + * Helper function to create cross-database SQL date extraction. + * + * @param $extract_type + * The type of value to extract from the date, like 'MONTH'. + * @param $field + * The real table and field name, like 'tablename.fieldname'. + * @param $field_type + * The type of date field, 'int' or 'datetime'. + * @param $set_offset + * The name of a field that holds the timezone offset or a fixed timezone + * offset value. If not provided, the normal Drupal timezone handling + * will be used, i.e. $set_offset = 0 will make no timezone adjustment. + * @return + * An appropriate SQL string for the db type and field type. + */ +function views_date_sql_extract($extract_type, $field, $field_type = 'int', $set_offset = NULL) { + $db_type = $GLOBALS['db_type']; + $field = views_date_sql_field($field, $field_type, $set_offset); + + // Note there is no space after FROM to avoid db_rewrite problems + // see http://drupal.org/node/79904. + switch ($extract_type) { + case('DATE'): + return $field; + case('YEAR'): + return "EXTRACT(YEAR FROM($field))"; + case('MONTH'): + return "EXTRACT(MONTH FROM($field))"; + case('DAY'): + return "EXTRACT(DAY FROM($field))"; + case('HOUR'): + return "EXTRACT(HOUR FROM($field))"; + case('MINUTE'): + return "EXTRACT(MINUTE FROM($field))"; + case('SECOND'): + return "EXTRACT(SECOND FROM($field))"; + case('WEEK'): // ISO week number for date + switch ($db_type) { + case('mysql'): + case('mysqli'): + // WEEK using arg 3 in mysql should return the same value as postgres EXTRACT + return "WEEK($field, 3)"; + case('pgsql'): + return "EXTRACT(WEEK FROM($field))"; + } + case('DOW'): + switch ($db_type) { + case('mysql'): + case('mysqli'): + // mysql returns 1 for Sunday through 7 for Saturday + // php date functions and postgres use 0 for Sunday and 6 for Saturday + return "INTEGER(DAYOFWEEK($field) - 1)"; + case('pgsql'): + return "EXTRACT(DOW FROM($field))"; + } + case('DOY'): + switch ($db_type) { + case('mysql'): + case('mysqli'): + return "DAYOFYEAR($field)"; + case('pgsql'): + return "EXTRACT(DOY FROM($field))"; + } + } +} + +/** + * Implementation of hook_views_handlers() to register all of the basic handlers + * views uses. + */ +function views_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/handlers', + ), + 'handlers' => array( + // argument handlers + 'views_handler_argument' => array( + 'parent' => 'views_handler', + ), + 'views_handler_argument_numeric' => array( + 'parent' => 'views_handler_argument', + ), + 'views_handler_argument_formula' => array( + 'parent' => 'views_handler_argument', + ), + 'views_handler_argument_date' => array( + 'parent' => 'views_handler_argument_formula', + ), + 'views_handler_argument_string' => array( + 'parent' => 'views_handler_argument', + ), + 'views_handler_argument_many_to_one' => array( + 'parent' => 'views_handler_argument', + ), + 'views_handler_argument_null' => array( + 'parent' => 'views_handler_argument', + ), + 'views_handler_argument_broken' => array( + 'parent' => 'views_handler_argument', + ), + + // field handlers + 'views_handler_field' => array( + 'parent' => 'views_handler', + ), + 'views_handler_field_date' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_boolean' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_markup' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_xss' => array( + 'parent' => 'views_handler_field', + 'file' => 'views_handler_field.inc', + ), + 'views_handler_field_url' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_file_size' => array( + 'parent' => 'views_handler_field', + 'file' => 'views_handler_field.inc', + ), + 'views_handler_field_prerender_list' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_numeric' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_custom' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_counter' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_math' => array( + 'parent' => 'views_handler_field_numeric', + ), + 'views_handler_field_broken' => array( + 'parent' => 'views_handler_field', + ), + + // filter handlers + 'views_handler_filter' => array( + 'parent' => 'views_handler', + ), + 'views_handler_filter_equality' => array( + 'parent' => 'views_handler_filter', + ), + 'views_handler_filter_string' => array( + 'parent' => 'views_handler_filter', + ), + 'views_handler_filter_boolean_operator' => array( + 'parent' => 'views_handler_filter', + ), + 'views_handler_filter_boolean_operator_string' => array( + 'parent' => 'views_handler_filter_boolean_operator', + ), + 'views_handler_filter_in_operator' => array( + 'parent' => 'views_handler_filter', + ), + 'views_handler_filter_numeric' => array( + 'parent' => 'views_handler_filter', + ), + 'views_handler_filter_float' => array( + 'parent' => 'views_handler_filter_numeric', + ), + 'views_handler_filter_date' => array( + 'parent' => 'views_handler_filter_numeric', + ), + 'views_handler_filter_many_to_one' => array( + 'parent' => 'views_handler_filter_in_operator', + ), + 'views_handler_filter_broken' => array( + 'parent' => 'views_handler_filter', + ), + + // relationship handlers + 'views_handler_relationship' => array( + 'parent' => 'views_handler', + ), + 'views_handler_relationship_broken' => array( + 'parent' => 'views_handler_relationship', + ), + + + // sort handlers + 'views_handler_sort' => array( + 'parent' => 'views_handler', + ), + 'views_handler_sort_formula' => array( + 'parent' => 'views_handler_sort', + ), + 'views_handler_sort_date' => array( + 'parent' => 'views_handler_sort', + ), + 'views_handler_sort_menu_hierarchy' => array( + 'parent' => 'views_handler_sort', + ), + 'views_handler_sort_random' => array( + 'parent' => 'views_handler_sort', + ), + 'views_handler_sort_broken' => array( + 'parent' => 'views_handler_sort', + ), + ), + ); +} + + +/** + * @} + */ + +/** + * @defgroup views_join_handlers Views' join handlers + * @{ + * Handlers to tell Views how to join tables together. + + * Here is how you do complex joins: + * + * @code + * class views_join_complex extends views_join { + * // PHP 4 doesn't call constructors of the base class automatically from a + * // constructor of a derived class. It is your responsibility to propagate + * // the call to constructors upstream where appropriate. + * function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT') { + * parent::construct($table, $left_table, $left_field, $field, $extra, $type); + * } + * + * function join($table, &$query) { + * $output = parent::join($table, $query); + * $output .= "AND foo.bar = baz.boing"; + * return $output; + * } + * } + * @endcode + */ +/** + * A function class to represent a join and create the SQL necessary + * to implement the join. + * + * This is the Delegation pattern. If we had PHP5 exclusively, we would + * declare this an interface. + * + * Extensions of this class can be used to create more interesting joins. + * + * join definition + * - table: table to join (right table) + * - field: field to join on (right field) + * - left_table: The table we join to + * - left_field: The field we join to + * - type: either LEFT (default) or INNER + * - extra: Either a string that's directly added, or an array of items: + * - - table: if not set, current table; if NULL, no table. This field can't + * be set in the cached definition because it can't know aliases; this field + * can only be used by realtime joins. + * - - field: Field or formula + * - - operator: defaults to = + * - - value: Must be set. If an array, operator will be defaulted to IN. + * - - numeric: If true, the value will not be surrounded in quotes. + * - - raw: If you specify raw the value will be used as it is, so you can have field to field conditions. + * - extra type: How all the extras will be combined. Either AND or OR. Defaults to AND. + */ +class views_join { + /** + * Construct the views_join object. + */ + function construct($table = NULL, $left_table = NULL, $left_field = NULL, $field = NULL, $extra = array(), $type = 'LEFT') { + $this->extra_type = 'AND'; + if (!empty($table)) { + $this->table = $table; + $this->left_table = $left_table; + $this->left_field = $left_field; + $this->field = $field; + $this->extra = $extra; + $this->type = strtoupper($type); + } + else if (!empty($this->definition)) { + // if no arguments, construct from definition. + // These four must exist or it will throw notices. + $this->table = $this->definition['table']; + $this->left_table = $this->definition['left_table']; + $this->left_field = $this->definition['left_field']; + $this->field = $this->definition['field']; + if (!empty($this->definition['extra'])) { + $this->extra = $this->definition['extra']; + } + if (!empty($this->definition['extra type'])) { + $this->extra_type = strtoupper($this->definition['extra type']); + } + + $this->type = !empty($this->definition['type']) ? strtoupper($this->definition['type']) : 'LEFT'; + } + } + + /** + * Build the SQL for the join this object represents. + */ + function join($table, &$query) { + if (empty($this->definition['table formula'])) { + $right_table = "{" . $this->table . "}"; + } + else { + $right_table = $this->definition['table formula']; + } + + if ($this->left_table) { + $left = $query->get_table_info($this->left_table); + $left_field = "$left[alias].$this->left_field"; + } + else { + // This can be used if left_field is a formula or something. It should be used only *very* rarely. + $left_field = $this->left_field; + } + + $output = " $this->type JOIN $right_table $table[alias] ON $left_field = $table[alias].$this->field"; + + // Load query tokens replacements. + $view = views_get_current_view(); + $replacements = array(); + if (!empty($view)) { + $replacements = $view->substitutions(); + } + else { + vpr('The current view is not set, maybe some code missed to execute $view->pre_execute()'); + } + + // Tack on the extra. + if (isset($this->extra)) { + if (is_array($this->extra)) { + $extras = array(); + foreach ($this->extra as $info) { + $extra = ''; + // Figure out the table name. Remember, only use aliases provided + // if at all possible. + $join_table = ''; + if (!array_key_exists('table', $info)) { + $join_table = $table['alias'] . '.'; + } + elseif (isset($info['table'])) { + $join_table = $info['table'] . '.'; + } + + // Apply query token replacements. + $info['value'] = str_replace(array_keys($replacements), $replacements, $info['value']); + + // And now deal with the value and the operator. Set $q to + // a single-quote for non-numeric values and the + // empty-string for numeric values, then wrap all values in $q. + if (empty($info['raw'])) { + $raw_value = $this->db_safe($info['value'], $info); + $q = (empty($info['numeric']) ? "'" : ''); + } + else { + $raw_value = $info['value']; + $q = ''; + } + + if (is_array($raw_value)) { + $operator = !empty($info['operator']) ? $info['operator'] : 'IN'; + // Transform from IN() notation to = notation if just one value. + if (count($raw_value) == 1) { + $value = $q . array_shift($raw_value) . $q; + $operator = $operator == 'NOT IN' ? '!=' : '='; + } + else { + $value = "($q" . implode("$q, $q", $raw_value) . "$q)"; + } + } + else { + $operator = !empty($info['operator']) ? $info['operator'] : '='; + $value = "$q$raw_value$q"; + } + $extras[] = "$join_table$info[field] $operator $value"; + } + + if ($extras) { + if (count($extras) == 1) { + $output .= ' AND ' . array_shift($extras); + } + else { + $output .= ' AND (' . implode(' ' . $this->extra_type . ' ', $extras) . ')'; + } + } + } + else if ($this->extra && is_string($this->extra)) { + $output .= " AND ($this->extra)"; + } + } + return $output; + } + + /** + * Ensure that input is db safe. We only check strings and ints tho + * so something that needs floats in their joins needs to do their + * own type checking. + */ + function db_safe($input, $info) { + if (is_array($input)) { + $output = array(); + foreach ($input as $value) { + if (empty($info['numeric'])) { + $output[] = db_escape_string($value); + } + else { + $output[] = intval($value); + } + } + } + else if (empty($info['numeric'])) { + $output = db_escape_string($input); + } + else { + $output = intval($input); + } + + return $output; + } +} + +/** + * @} + */ + +// Declare API compatibility on behalf of core modules: + +/** + * Implementation of hook_views_api(). + * + * This one is used as the base to reduce errors when updating. + */ +function views_views_api() { + return array( + 'api' => 2, + 'path' => drupal_get_path('module', 'views') . '/modules', + ); +} + +if (!function_exists('aggregator_views_api')) { + function aggregator_views_api() { return views_views_api(); } +} + +if (!function_exists('book_views_api')) { + function book_views_api() { return views_views_api(); } +} + +if (!function_exists('comment_views_api')) { + function comment_views_api() { return views_views_api(); } +} + +if (!function_exists('locale_views_api')) { + function locale_views_api() { return views_views_api(); } +} + +if (!function_exists('filter_views_api')) { + function filter_views_api() { return views_views_api(); } +} + +if (!function_exists('node_views_api')) { + function node_views_api() { return views_views_api(); } +} + +if (!function_exists('poll_views_api')) { + function poll_views_api() { return views_views_api(); } +} + +if (!function_exists('profile_views_api')) { + function profile_views_api() { return views_views_api(); } +} + +if (!function_exists('search_views_api')) { + function search_views_api() { return views_views_api(); } +} + +if (!function_exists('statistics_views_api')) { + function statistics_views_api() { return views_views_api(); } +} + +if (!function_exists('system_views_api')) { + function system_views_api() { return views_views_api(); } +} + +if (!function_exists('taxonomy_views_api')) { + function taxonomy_views_api() { return views_views_api(); } +} + +if (!function_exists('translation_views_api')) { + function translation_views_api() { return views_views_api(); } +} + +if (!function_exists('upload_views_api')) { + function upload_views_api() { return views_views_api(); } +} + +if (!function_exists('user_views_api')) { + function user_views_api() { return views_views_api(); } +} + +if (!function_exists('contact_views_api')) { + function contact_views_api() { return views_views_api(); } +} diff --git a/sites/all/modules/views/includes/plugins.inc b/sites/all/modules/views/includes/plugins.inc new file mode 100644 index 0000000..2d010c5 --- /dev/null +++ b/sites/all/modules/views/includes/plugins.inc @@ -0,0 +1,407 @@ + 'views', // This just tells our themes are elsewhere. + 'display' => array( + 'parent' => array( + // this isn't really a display but is necessary so the file can + // be included. + 'no ui' => TRUE, + 'handler' => 'views_plugin_display', + 'parent' => '', + ), + 'default' => array( + 'title' => t('Defaults'), + 'help' => t('Default settings for this view.'), + 'handler' => 'views_plugin_display_default', + 'theme' => 'views_view', + 'no ui' => TRUE, + 'no remove' => TRUE, + 'js' => array('misc/collapse.js', 'misc/textarea.js', 'misc/tabledrag.js', 'misc/autocomplete.js', "$path/dependent.js"), + 'use ajax' => TRUE, + 'use pager' => TRUE, + 'use more' => TRUE, + 'accept attachments' => TRUE, + 'help topic' => 'display-default', + ), + 'page' => array( + 'title' => t('Page'), + 'help' => t('Display the view as a page, with a URL and menu links.'), + 'handler' => 'views_plugin_display_page', + 'theme' => 'views_view', + 'uses hook menu' => TRUE, + 'use ajax' => TRUE, + 'use pager' => TRUE, + 'accept attachments' => TRUE, + 'admin' => t('Page'), + 'help topic' => 'display-page', + ), + 'block' => array( + 'title' => t('Block'), + 'help' => t('Display the view as a block.'), + 'handler' => 'views_plugin_display_block', + 'theme' => 'views_view', + 'uses hook block' => TRUE, + 'use ajax' => TRUE, + 'use pager' => TRUE, + 'use more' => TRUE, + 'accept attachments' => TRUE, + 'admin' => t('Block'), + 'help topic' => 'display-block', + ), + 'attachment' => array( + 'title' => t('Attachment'), + 'help' => t('Attachments added to other displays to achieve multiple views in the same view.'), + 'handler' => 'views_plugin_display_attachment', + 'theme' => 'views_view', + 'use ajax' => TRUE, + 'help topic' => 'display-attachment', + ), + 'feed' => array( + 'title' => t('Feed'), + 'help' => t('Display the view as a feed, such as an RSS feed.'), + 'handler' => 'views_plugin_display_feed', + 'parent' => 'page', // so it knows to load the page plugin .inc file + 'uses hook menu' => TRUE, + 'use ajax' => FALSE, + 'use pager' => FALSE, + 'accept attachments' => FALSE, + 'admin' => t('Feed'), + 'help topic' => 'display-feed', + ), + ), + 'style' => array( + 'parent' => array( + // this isn't really a display but is necessary so the file can + // be included. + 'no ui' => TRUE, + 'handler' => 'views_plugin_style', + 'parent' => '', + ), + 'default' => array( + 'title' => t('Unformatted'), + 'help' => t('Displays rows one after another.'), + 'handler' => 'views_plugin_style_default', + 'theme' => 'views_view_unformatted', + 'uses row plugin' => TRUE, + 'uses grouping' => TRUE, + 'uses options' => TRUE, + 'type' => 'normal', + 'help topic' => 'style-unformatted', + ), + 'list' => array( + 'title' => t('HTML List'), + 'help' => t('Displays rows as an HTML list.'), + 'handler' => 'views_plugin_style_list', + 'theme' => 'views_view_list', + 'uses row plugin' => TRUE, + 'uses options' => TRUE, + 'type' => 'normal', + 'help topic' => 'style-list', + ), + 'grid' => array( + 'title' => t('Grid'), + 'help' => t('Displays rows in a grid.'), + 'handler' => 'views_plugin_style_grid', + 'theme' => 'views_view_grid', + 'uses row plugin' => TRUE, + 'uses options' => TRUE, + 'type' => 'normal', + 'help topic' => 'style-grid', + ), + 'table' => array( + 'title' => t('Table'), + 'help' => t('Displays rows in a table.'), + 'handler' => 'views_plugin_style_table', + 'theme' => 'views_view_table', + 'uses row plugin' => FALSE, + 'uses fields' => TRUE, + 'uses options' => TRUE, + 'type' => 'normal', + 'help topic' => 'style-table', + ), + 'default_summary' => array( + 'title' => t('List'), + 'help' => t('Displays the default summary as a list.'), + 'handler' => 'views_plugin_style_summary', + 'theme' => 'views_view_summary', + 'type' => 'summary', // only shows up as a summary style + 'uses options' => TRUE, + 'help topic' => 'style-summary', + ), + 'unformatted_summary' => array( + 'title' => t('Unformatted'), + 'help' => t('Displays the summary unformatted, with option for one after another or inline.'), + 'handler' => 'views_plugin_style_summary_unformatted', + 'parent' => 'default_summary', + 'theme' => 'views_view_summary_unformatted', + 'type' => 'summary', // only shows up as a summary style + 'uses options' => TRUE, + 'help topic' => 'style-summary-unformatted', + ), + 'rss' => array( + 'title' => t('RSS Feed'), + 'help' => t('Generates an RSS feed from a view.'), + 'handler' => 'views_plugin_style_rss', + 'theme' => 'views_view_rss', + 'uses row plugin' => TRUE, + 'uses options' => TRUE, + 'type' => 'feed', + 'help topic' => 'style-rss', + ), + ), + 'row' => array( + 'parent' => array( + // this isn't really a display but is necessary so the file can + // be included. + 'no ui' => TRUE, + 'handler' => 'views_plugin_row', + 'parent' => '', + ), + 'fields' => array( + 'title' => t('Fields'), + 'help' => t('Displays the fields with an optional template.'), + 'handler' => 'views_plugin_row_fields', + 'theme' => 'views_view_fields', + 'uses fields' => TRUE, + 'uses options' => TRUE, + 'type' => 'normal', + 'help topic' => 'style-row-fields', + ), + ), + 'argument default' => array( + // This type of plugin does not conform to the standard and + // uses 'fixed' as the parent rather than having a separate parent. + 'fixed' => array( + 'title' => t('Fixed entry'), + 'handler' => 'views_plugin_argument_default', + ), + 'php' => array( + 'title' => t('PHP Code'), + 'handler' => 'views_plugin_argument_default_php', + 'parent' => 'fixed', + ), + ), + 'argument validator' => array( + 'parent' => array( + 'no ui' => TRUE, + 'handler' => 'views_plugin_argument_validate', + 'parent' => '', + ), + 'php' => array( + 'title' => t('PHP Code'), + 'handler' => 'views_plugin_argument_validate_php', + ), + 'numeric' => array( + 'title' => t('Numeric'), + 'handler' => 'views_plugin_argument_validate_numeric', + ), + ), + 'access' => array( + 'parent' => array( + 'no ui' => TRUE, + 'handler' => 'views_plugin_access', + 'parent' => '', + ), + 'none' => array( + 'title' => t('None'), + 'help' => t('Will be available to all users.'), + 'handler' => 'views_plugin_access_none', + 'help topic' => 'access-none', + ), + 'role' => array( + 'title' => t('Role'), + 'help' => t('Access will be granted to users with any of the specified roles.'), + 'handler' => 'views_plugin_access_role', + 'uses options' => TRUE, + 'help topic' => 'access-role', + ), + 'perm' => array( + 'title' => t('Permission'), + 'help' => t('Access will be granted to users with the specified permission string.'), + 'handler' => 'views_plugin_access_perm', + 'uses options' => TRUE, + 'help topic' => 'access-perm', + ), + ), + 'cache' => array( + 'parent' => array( + 'no ui' => TRUE, + 'handler' => 'views_plugin_cache', + 'parent' => '', + ), + 'none' => array( + 'title' => t('None'), + 'help' => t('No caching of Views data.'), + 'handler' => 'views_plugin_cache_none', + 'help topic' => 'cache-none', + ), + 'time' => array( + 'title' => t('Time-based'), + 'help' => t('Simple time-based caching of data.'), + 'handler' => 'views_plugin_cache_time', + 'uses options' => TRUE, + 'help topic' => 'cache-time', + ), + ), + ); + + if (module_invoke('ctools', 'api_version', '1.3')) { + $plugins['style']['jump_menu_summary'] = array( + 'title' => t('Jump menu'), + 'help' => t('Puts all of the results into a select box and allows the user to go to a different page based upon the results.'), + 'handler' => 'views_plugin_style_summary_jump_menu', + 'theme' => 'views_view_summary_jump_menu', + 'type' => 'summary', // only shows up as a summary style + 'uses options' => TRUE, + 'help topic' => 'style-summary-jump-menu', + ); + $plugins['style']['jump_menu'] = array( + 'title' => t('Jump menu'), + 'help' => t('Puts all of the results into a select box and allows the user to go to a different page based upon the results.'), + 'handler' => 'views_plugin_style_jump_menu', + 'theme' => 'views_view_jump_menu', + 'uses row plugin' => TRUE, + 'uses fields' => TRUE, + 'uses options' => TRUE, + 'type' => 'normal', + 'help topic' => 'style-jump-menu', + ); + } + + return $plugins; +} + +/** + * Builds and return a list of all plugins available in the system. + * + * @return Nested array of plugins, grouped by type. + */ +function views_discover_plugins() { + $cache = array('display' => array(), 'style' => array(), 'row' => array(), 'argument default' => array(), 'argument validator' => array(), 'access' => array(), 'cache' => array()); + // Get plugins from all mdoules. + foreach (module_implements('views_plugins') as $module) { + $function = $module . '_views_plugins'; + $result = $function(); + if (!is_array($result)) { + continue; + } + + $module_dir = isset($result['module']) ? $result['module'] : $module; + // Setup automatic path/file finding for theme registration + if ($module_dir == 'views') { + $theme_path = drupal_get_path('module', $module_dir) . '/theme'; + $theme_file = 'theme.inc'; + $path = drupal_get_path('module', $module_dir) . '/plugins'; + } + else { + $theme_path = $path = drupal_get_path('module', $module_dir); + $theme_file = "$module.views.inc"; + } + + foreach ($result as $type => $info) { + if ($type == 'module') { + continue; + } + foreach ($info as $plugin => $def) { + $def['module'] = $module_dir; + if (!isset($def['theme path'])) { + $def['theme path'] = $theme_path; + } + if (!isset($def['theme file'])) { + $def['theme file'] = $theme_file; + } + if (!isset($def['path'])) { + $def['path'] = $path; + } + if (!isset($def['file'])) { + $def['file'] = $def['handler'] . '.inc'; + } + if (!isset($def['parent'])) { + $def['parent'] = 'parent'; + } + // merge the new data in + $cache[$type][$plugin] = $def; + } + } + } + + // Let other modules modify the plugins. + drupal_alter('views_plugins', $cache); + return $cache; +} + +/** + * Abstract base class to provide interface common to all plugins. + */ +class views_plugin extends views_object { + /** + * Init will be called after construct, when the plugin is attached to a + * view and a display. + */ + function init(&$view, &$display) { + $this->view = &$view; + $this->display = &$display; + } + + /** + * Provide a form to edit options for this plugin. + */ + function options_form(&$form, &$form_state) { } + + /** + * Validate the options form. + */ + function options_validate(&$form, &$form_state) { } + + /** + * Handle any special handling on the validate form. + */ + function options_submit(&$form, &$form_state) { } + + /** + * Add anything to the query that we might need to. + */ + function query() { } + + /** + * Provide a full list of possible theme templates used by this style. + */ + function theme_functions() { + return views_theme_functions($this->definition['theme'], $this->view, $this->display); + } + + /** + * Provide a list of additional theme functions for the theme information page + */ + function additional_theme_functions() { + $funcs = array(); + if (!empty($this->definition['additional themes'])) { + foreach ($this->definition['additional themes'] as $theme => $type) { + $funcs[] = views_theme_functions($theme, $this->view, $this->display); + } + } + return $funcs; + } + + /** + * Validate that the plugin is correct and can be saved. + * + * @return + * An array of error strings to tell the user what is wrong with this + * plugin. + */ + function validate() { return array(); } +} + diff --git a/sites/all/modules/views/includes/query.inc b/sites/all/modules/views/includes/query.inc new file mode 100644 index 0000000..a25fb9d --- /dev/null +++ b/sites/all/modules/views/includes/query.inc @@ -0,0 +1,1011 @@ +base_table = $base_table; // Predefine these above, for clarity. + $this->base_field = $base_field; + $this->relationships[$base_table] = array( + 'link' => NULL, + 'table' => $base_table, + 'alias' => $base_table, + 'base' => $base_table + ); + + // init the table queue with our primary table. + $this->table_queue[$base_table] = array( + 'alias' => $base_table, + 'table' => $base_table, + 'relationship' => $base_table, + 'join' => NULL, + ); + + // init the tables with our primary table + $this->tables[$base_table][$base_table] = array( + 'count' => 1, + 'alias' => $base_table, + ); + + if ($base_field) { + $this->fields[$base_field] = array( + 'table' => $base_table, + 'field' => $base_field, + 'alias' => $base_field, + ); + } + + $this->count_field = array( + 'table' => $base_table, + 'field' => $base_field, + 'alias' => $base_field, + 'count' => TRUE, + ); + } + + // ---------------------------------------------------------------- + // Utility methods to set flags and data. + + /** + * Set the base field to be distinct. + */ + function set_distinct($value = TRUE) { + if (!(isset($this->no_distinct) && $value)) { + $this->distinct = $value; + } + } + + /** + * Set what field the query will count() on for paging. + */ + function set_count_field($table, $field, $alias = NULL) { + if (empty($alias)) { + $alias = $table . '_' . $field; + } + $this->count_field = array( + 'table' => $table, + 'field' => $field, + 'alias' => $alias, + 'count' => TRUE, + ); + } + + /** + * Set the table header; used for click-sorting because it's needed + * info to modify the ORDER BY clause. + */ + function set_header($header) { + $this->header = $header; + } + + // ---------------------------------------------------------------- + // Table/join adding + + /** + * A relationship is an alternative endpoint to a series of table + * joins. Relationships must be aliases of the primary table and + * they must join either to the primary table or to a pre-existing + * relationship. + * + * An example of a relationship would be a nodereference table. + * If you have a nodereference named 'book_parent' which links to a + * parent node, you could set up a relationship 'node_book_parent' + * to 'node'. Then, anything that links to 'node' can link to + * 'node_book_parent' instead, thus allowing all properties of + * both nodes to be available in the query. + * + * @param $alias + * What this relationship will be called, and is also the alias + * for the table. + * @param $join + * A views_join object (or derived object) to join the alias in. + * @param $base + * The name of the 'base' table this relationship represents; this + * tells the join search which path to attempt to use when finding + * the path to this relationship. + * @param $link_point + * If this relationship links to something other than the primary + * table, specify that table here. For example, a 'track' node + * might have a relationship to an 'album' node, which might + * have a relationship to an 'artist' node. + */ + function add_relationship($alias, $join, $base, $link_point = NULL) { + if (empty($link_point)) { + $link_point = $this->base_table; + } + else if (!array_key_exists($link_point, $this->relationships)) { + return FALSE; + } + + // Make sure $alias isn't already used; if it, start adding stuff. + $alias_base = $alias; + $count = 1; + while (!empty($this->relationships[$alias])) { + $alias = $alias_base . '_' . $count++; + } + + // Make sure this join is adjusted for our relationship. + if ($link_point && isset($this->relationships[$link_point])) { + $join = $this->adjust_join($join, $link_point); + } + + // Add the table directly to the queue to avoid accidentally marking + // it. + $this->table_queue[$alias] = array( + 'table' => $join->table, + 'num' => 1, + 'alias' => $alias, + 'join' => $join, + 'relationship' => $link_point, + ); + + $this->relationships[$alias] = array( + 'link' => $link_point, + 'table' => $join->table, + 'base' => $base, + ); + + $this->tables[$this->base_table][$alias] = array( + 'count' => 1, + 'alias' => $alias, + ); + + return $alias; + } + + /** + * Add a table to the query, ensuring the path exists. + * + * This function will test to ensure that the path back to the primary + * table is valid and exists; if you do not wish for this testing to + * occur, use $query->queue_table() instead. + * + * @param $table + * The name of the table to add. It needs to exist in the global table + * array. + * @param $relationship + * An alias of a table; if this is set, the path back to this table will + * be tested prior to adding the table, making sure that all intermediary + * tables exist and are properly aliased. If set to NULL the path to + * the primary table will be ensured. If the path cannot be made, the + * table will NOT be added. + * @param $join + * In some join configurations this table may actually join back through + * a different method; this is most likely to be used when tracing + * a hierarchy path. (node->parent->parent2->parent3). This parameter + * will specify how this table joins if it is not the default. + * @param $alias + * A specific alias to use, rather than the default alias. + * + * @return $alias + * The alias of the table; this alias can be used to access information + * about the table and should always be used to refer to the table when + * adding parts to the query. Or FALSE if the table was not able to be + * added. + */ + function add_table($table, $relationship = NULL, $join = NULL, $alias = NULL) { + if (!$this->ensure_path($table, $relationship, $join)) { + return FALSE; + } + + if ($join && $relationship) { + $join = $this->adjust_join($join, $relationship); + } + + return $this->queue_table($table, $relationship, $join, $alias); + } + + /** + * Add a table to the query without ensuring the path. + * + * This is a pretty internal function to Views and add_table() or + * ensure_table() should be used instead of this one, unless you are + * absolutely sure this is what you want. + * + * @param $table + * The name of the table to add. It needs to exist in the global table + * array. + * @param $relationship + * The primary table alias this table is related to. If not set, the + * primary table will be used. + * @param $join + * In some join configurations this table may actually join back through + * a different method; this is most likely to be used when tracing + * a hierarchy path. (node->parent->parent2->parent3). This parameter + * will specify how this table joins if it is not the default. + * @param $alias + * A specific alias to use, rather than the default alias. + * + * @return $alias + * The alias of the table; this alias can be used to access information + * about the table and should always be used to refer to the table when + * adding parts to the query. Or FALSE if the table was not able to be + * added. + */ + function queue_table($table, $relationship = NULL, $join = NULL, $alias = NULL) { + // If the alias is set, make sure it doesn't already exist. + if (isset($this->table_queue[$alias])) { + return $alias; + } + + if (empty($relationship)) { + $relationship = $this->base_table; + } + + if (!array_key_exists($relationship, $this->relationships)) { + return FALSE; + } + + if (!$alias && $join && $relationship && !empty($join->adjusted) && $table != $join->table) { + if ($relationship == $this->base_table) { + $alias = $table; + } + else { + $alias = $relationship . '_' . $table; + } + } + + // Check this again to make sure we don't blow up existing aliases for already + // adjusted joins. + if (isset($this->table_queue[$alias])) { + return $alias; + } + + $alias = $this->mark_table($table, $relationship, $alias); + + // If no alias is specified, give it the default. + if (!isset($alias)) { + $alias = $this->tables[$relationship][$table]['alias'] . $this->tables[$relationship][$table]['count']; + } + + // If this is a relationship based table, add a marker with + // the relationship as a primary table for the alias. + if ($table != $alias) { + $this->mark_table($alias, $this->base_table, $alias); + } + + // If no join is specified, pull it from the table data. + if (!isset($join)) { + $join = $this->get_join_data($table, $this->relationships[$relationship]['base']); + if (empty($join)) { + return FALSE; + } + + $join = $this->adjust_join($join, $relationship); + } + + $this->table_queue[$alias] = array( + 'table' => $table, + 'num' => $this->tables[$relationship][$table]['count'], + 'alias' => $alias, + 'join' => $join, + 'relationship' => $relationship, + ); + + return $alias; + } + + function mark_table($table, $relationship, $alias) { + // Mark that this table has been added. + if (empty($this->tables[$relationship][$table])) { + if (!isset($alias)) { + $alias = ''; + if ($relationship != $this->base_table) { + // double underscore will help prevent accidental name + // space collisions. + $alias = $relationship . '__'; + } + $alias .= $table; + } + $this->tables[$relationship][$table] = array( + 'count' => 1, + 'alias' => $alias, + ); + } + else { + $this->tables[$relationship][$table]['count']++; + } + + return $alias; + } + + /** + * Ensure a table exists in the queue; if it already exists it won't + * do anything, but if it doesn't it will add the table queue. It will ensure + * a path leads back to the relationship table. + * + * @param $table + * The unaliased name of the table to ensure. + * @param $relationship + * The relationship to ensure the table links to. Each relationship will + * get a unique instance of the table being added. If not specified, + * will be the primary table. + * @param $join + * A views_join object (or derived object) to join the alias in. + * + * @return + * The alias used to refer to this specific table, or NULL if the table + * cannot be ensured. + */ + function ensure_table($table, $relationship = NULL, $join = NULL) { + // ensure a relationship + if (empty($relationship)) { + $relationship = $this->base_table; + } + + // If the relationship is the primary table, this actually be a relationship + // link back from an alias. We store all aliases along with the primary table + // to detect this state, because eventually it'll hit a table we already + // have and that's when we want to stop. + if ($relationship == $this->base_table && !empty($this->tables[$relationship][$table])) { + return $this->tables[$relationship][$table]['alias']; + } + + if (!array_key_exists($relationship, $this->relationships)) { + return FALSE; + } + + if ($table == $this->relationships[$relationship]['base']) { + return $relationship; + } + + // If we do not have join info, fetch it. + if (!isset($join)) { + $join = $this->get_join_data($table, $this->relationships[$relationship]['base']); + } + + // If it can't be fetched, this won't work. + if (empty($join)) { + return; + } + + // Adjust this join for the relationship, which will ensure that the 'base' + // table it links to is correct. Tables adjoined to a relationship + // join to a link point, not the base table. + $join = $this->adjust_join($join, $relationship); + + if ($this->ensure_path($table, $relationship, $join)) { + // Attempt to eliminate redundant joins. If this table's + // relationship and join exactly matches an existing table's + // relationship and join, we do not have to join to it again; + // just return the existing table's alias. See + // http://groups.drupal.org/node/11288 for details. + // + // This can be done safely here but not lower down in + // queue_table(), because queue_table() is also used by + // add_table() which requires the ability to intentionally add + // the same table with the same join multiple times. For + // example, a view that filters on 3 taxonomy terms using AND + // needs to join term_data 3 times with the same join. + + // scan through the table queue to see if a matching join and + // relationship exists. If so, use it instead of this join. + + // TODO: Scanning through $this->table_queue results in an + // O(N^2) algorithm, and this code runs every time the view is + // instantiated (Views 2 does not currently cache queries). + // There are a couple possible "improvements" but we should do + // some performance testing before picking one. + foreach ($this->table_queue as $queued_table) { + // In PHP 4 and 5, the == operation returns TRUE for two objects + // if they are instances of the same class and have the same + // attributes and values. + if ($queued_table['relationship'] == $relationship && $queued_table['join'] == $join) { + return $queued_table['alias']; + } + } + + return $this->queue_table($table, $relationship, $join); + } + } + + /** + * Make sure that the specified table can be properly linked to the primary + * table in the JOINs. This function uses recursion. If the tables + * needed to complete the path back to the primary table are not in the + * query they will be added, but additional copies will NOT be added + * if the table is already there. + */ + function ensure_path($table, $relationship = NULL, $join = NULL, $traced = array(), $add = array()) { + if (!isset($relationship)) { + $relationship = $this->base_table; + } + + if (!array_key_exists($relationship, $this->relationships)) { + return FALSE; + } + + // If we do not have join info, fetch it. + if (!isset($join)) { + $join = $this->get_join_data($table, $this->relationships[$relationship]['base']); + } + + // If it can't be fetched, this won't work. + if (empty($join)) { + return FALSE; + } + + // Does a table along this path exist? + if (isset($this->tables[$relationship][$table]) || + ($join && $join->left_table == $relationship) || + ($join && $join->left_table == $this->relationships[$relationship]['table'])) { + + // Make sure that we're linking to the correct table for our relationship. + foreach (array_reverse($add) as $table => $path_join) { + $this->queue_table($table, $relationship, $this->adjust_join($path_join, $relationship)); + } + return TRUE; + } + + // Have we been this way? + if (isset($traced[$join->left_table])) { + // we looped. Broked. + return FALSE; + } + + // Do we have to add this table? + $left_join = $this->get_join_data($join->left_table, $this->relationships[$relationship]['base']); + if (!isset($this->tables[$relationship][$join->left_table])) { + $add[$join->left_table] = $left_join; + } + + // Keep looking. + $traced[$join->left_table] = TRUE; + return $this->ensure_path($join->left_table, $relationship, $left_join, $traced, $add); + } + + /** + * Fix a join to adhere to the proper relationship; the left table can vary + * based upon what relationship items are joined in on. + */ + function adjust_join($join, $relationship) { + if (!empty($join->adjusted)) { + return $join; + } + + if (empty($relationship) || empty($this->relationships[$relationship])) { + return $join; + } + + // Adjusts the left table for our relationship. + if ($relationship != $this->base_table) { + // If we're linking to the primary table, the relationship to use will + // be the prior relationship. Unless it's a direct link. + + // Safety! Don't modify an original here. + $join = drupal_clone($join); + + // Do we need to try to ensure a path? + if ($join->left_table != $this->relationships[$relationship]['table'] && + $join->left_table != $this->relationships[$relationship]['base'] && + !isset($this->tables[$relationship][$join->left_table]['alias'])) { + $this->ensure_table($join->left_table, $relationship); + } + + // First, if this is our link point/anchor table, just use the relationship + if ($join->left_table == $this->relationships[$relationship]['table']) { + $join->left_table = $relationship; + } + // then, try the base alias. + else if (isset($this->tables[$relationship][$join->left_table]['alias'])) { + $join->left_table = $this->tables[$relationship][$join->left_table]['alias']; + } + // But if we're already looking at an alias, use that instead. + else if (isset($this->table_queue[$relationship]['alias'])) { + $join->left_table = $this->table_queue[$relationship]['alias']; + } + } + + $join->adjusted = TRUE; + return $join; + } + + /** + * Retrieve join data from the larger join data cache. + * + * @param $table + * The table to get the join information for. + * @param $base_table + * The path we're following to get this join. + * + * @return + * A views_join object or child object, if one exists. + */ + function get_join_data($table, $base_table) { + // Check to see if we're linking to a known alias. If so, get the real + // table's data instead. + if (!empty($this->table_queue[$table])) { + $table = $this->table_queue[$table]['table']; + } + return views_get_table_join($table, $base_table); + + } + + /** + * Get the information associated with a table. + * + * If you need the alias of a table with a particular relationship, use + * ensure_table(). + */ + function get_table_info($table) { + if (!empty($this->table_queue[$table])) { + return $this->table_queue[$table]; + } + + // In rare cases we might *only* have aliased versions of the table. + if (!empty($this->tables[$this->base_table][$table])) { + $alias = $this->tables[$this->base_table][$table]['alias']; + if (!empty($this->table_queue[$alias])) { + return $this->table_queue[$alias]; + } + } + } + + /** + * Add a field to the query table, possibly with an alias. This will + * automatically call ensure_table to make sure the required table + * exists, *unless* $table is unset. + * + * @param $table + * The table this field is attached to. If NULL, it is assumed this will + * be a formula; otherwise, ensure_table is used to make sure the + * table exists. + * @param $field + * The name of the field to add. This may be a real field or a formula. + * @param $alias + * The alias to create. If not specified, the alias will be $table_$field + * unless $table is NULL. When adding formulae, it is recommended that an + * alias be used. + * + * @return $name + * The name that this field can be referred to as. Usually this is the alias. + */ + function add_field($table, $field, $alias = '', $params = NULL) { + // We check for this specifically because it gets a special alias. + if ($table == $this->base_table && $field == $this->base_field && empty($alias)) { + $alias = $this->base_field; + } + + if ($table && empty($this->table_queue[$table])) { + $this->ensure_table($table); + } + + if (!$alias && $table) { + $alias = $table . '_' . $field; + } + + $name = $alias ? $alias : $field; + + // @todo FIXME -- $alias, then $name is inconsistent + if (empty($this->fields[$alias])) { + $this->fields[$name] = array( + 'field' => $field, + 'table' => $table, + 'alias' => $alias, + ); + } + + foreach ((array)$params as $key => $value) { + $this->fields[$name][$key] = $value; + } + + return $name; + } + + /** + * Remove all fields that may've been added; primarily used for summary + * mode where we're changing the query because we didn't get data we needed. + */ + function clear_fields() { + $this->fields = array(); + } + + /** + * Create a new grouping for the WHERE or HAVING clause. + * + * @param $type + * Either 'AND' or 'OR'. All items within this group will be added + * to the WHERE clause with this logical operator. + * @param $group + * An ID to use for this group. If unspecified, an ID will be generated. + * @param $where + * 'where' or 'having'. + * + * @return $group + * The group ID generated. + */ + function set_where_group($type = 'AND', $group = NULL, $where = 'where') { + // Set an alias. + $groups = &$this->$where; + + if (!isset($group)) { + $group = empty($groups) ? 1 : max(array_keys($groups)) + 1; + } + + // Create an empty group + if (empty($groups[$group])) { + $groups[$group] = array('clauses' => array(), 'args' => array()); + } + + $groups[$group]['type'] = strtoupper($type); + return $group; + } + + /** + * Control how all WHERE and HAVING groups are put together. + * + * @param $type + * Either 'AND' or 'OR' + */ + function set_group_operator($type = 'AND') { + $this->group_operator = strtoupper($type); + } + + /** + * Add a simple WHERE clause to the query. The caller is responsible for + * ensuring that all fields are fully qualified (TABLE.FIELD) and that + * the table already exists in the query. + * + * @param $group + * The WHERE group to add these to; groups are used to create AND/OR + * sections. Groups cannot be nested. Use 0 as the default group. + * If the group does not yet exist it will be created as an AND group. + * @param $clause + * The actual clause to add. When adding a where clause it is important + * that all tables are addressed by the alias provided by add_table or + * ensure_table and that all fields are addressed by their alias wehn + * possible. Please use %d and %s for arguments. + * @param ... + * A number of arguments as used in db_query(). May be many args or one + * array full of args. + */ + function add_where($group, $clause) { + $args = func_get_args(); + array_shift($args); // ditch $group + array_shift($args); // ditch $clause + + // Expand an array of args if it came in. + if (count($args) == 1 && is_array(reset($args))) { + $args = current($args); + } + + // Ensure all variants of 0 are actually 0. Thus '', 0 and NULL are all + // the default group. + if (empty($group)) { + $group = 0; + } + + // Check for a group. + if (!isset($this->where[$group])) { + $this->set_where_group('AND', $group); + } + + // Add the clause and the args. + if (is_array($args)) { + $this->where[$group]['clauses'][] = $clause; + // we use array_values() here to prevent array_merge errors as keys from multiple + // sources occasionally collide. + $this->where[$group]['args'] = array_merge($this->where[$group]['args'], array_values($args)); + } + } + + /** + * Add a simple HAVING clause to the query. The caller is responsible for + * ensuring that all fields are fully qualified (TABLE.FIELD) and that + * the table and an appropriate GROUP BY already exist in the query. + * + * @param $group + * The HAVING group to add these to; groups are used to create AND/OR + * sections. Groups cannot be nested. Use 0 as the default group. + * If the group does not yet exist it will be created as an AND group. + * @param $clause + * The actual clause to add. When adding a having clause it is important + * that all tables are addressed by the alias provided by add_table or + * ensure_table and that all fields are addressed by their alias wehn + * possible. Please use %d and %s for arguments. + * @param ... + * A number of arguments as used in db_query(). May be many args or one + * array full of args. + */ + function add_having($group, $clause) { + $args = func_get_args(); + array_shift($args); // ditch $group + array_shift($args); // ditch $clause + + // Expand an array of args if it came in. + if (count($args) == 1 && is_array(reset($args))) { + $args = current($args); + } + + // Ensure all variants of 0 are actually 0. Thus '', 0 and NULL are all + // the default group. + if (empty($group)) { + $group = 0; + } + + // Check for a group. + if (!isset($this->having[$group])) { + $this->set_where_group('AND', $group, 'having'); + } + + // Add the clause and the args. + if (is_array($args)) { + $this->having[$group]['clauses'][] = $clause; + $this->having[$group]['args'] = array_merge($this->having[$group]['args'], array_values($args)); + } + } + + /** + * Add an ORDER BY clause to the query. + * + * @param $table + * The table this field is part of. If a formula, enter NULL. + * @param $field + * The field or formula to sort on. If already a field, enter NULL + * and put in the alias. + * @param $order + * Either ASC or DESC. + * @param $alias + * The alias to add the field as. In SQL, all fields in the order by + * must also be in the SELECT portion. If an $alias isn't specified + * one will be generated for from the $field; however, if the + * $field is a formula, this alias will likely fail. + */ + function add_orderby($table, $field, $order, $alias = '') { + if ($table) { + $this->ensure_table($table); + } + + // Only fill out this aliasing if there is a table; + // otherwise we assume it is a formula. + if (!$alias && $table) { + $as = $table . '_' . $field; + } + else { + $as = $alias; + } + + if ($field) { + $this->add_field($table, $field, $as); + } + + $this->orderby[] = "$as " . strtoupper($order); + + // If grouping, all items in the order by must also be in the + // group by clause. Check $table to ensure that this is not a + // formula. + if ($this->groupby && $table) { + $this->add_groupby($as); + } + } + + /** + * Add a simple GROUP BY clause to the query. The caller is responsible + * for ensuring that the fields are fully qualified and the table is properly + * added. + */ + function add_groupby($clause) { + // Only add it if it's not already in there. + if (!in_array($clause, $this->groupby)) { + $this->groupby[] = $clause; + } + } + + /** + * Construct the "WHERE" or "HAVING" part of the query. + * + * @param $where + * 'where' or 'having'. + */ + function condition_sql($where = 'where') { + $clauses = array(); + foreach ($this->$where as $group => $info) { + $clause = implode(") " . $info['type'] . " (", $info['clauses']); + if (count($info['clauses']) > 1) { + $clause = '(' . $clause . ')'; + } + $clauses[] = $clause; + } + + if ($clauses) { + $keyword = drupal_strtoupper($where); + if (count($clauses) > 1) { + return "$keyword (" . implode(")\n " . $this->group_operator . ' (', $clauses) . ")\n"; + } + else { + return "$keyword " . array_shift($clauses) . "\n"; + } + } + return ""; + } + + /** + * Generate a query and a countquery from all of the information supplied + * to the object. + * + * @param $get_count + * Provide a countquery if this is true, otherwise provide a normal query. + */ + function query($get_count = FALSE) { + // Check query distinct value. + if (empty($this->no_distinct) && $this->distinct && !empty($this->fields)) { + if (!empty($this->fields[$this->base_field])) { + $this->fields[$this->base_field]['distinct'] = TRUE; + $this->add_groupby($this->base_field); + } + } + + /** + * An optimized count query includes just the base field instead of all the fields. + * Determine of this query qualifies by checking for a groupby or distinct. + */ + $fields_array = $this->fields; + if ($get_count && !$this->groupby) { + foreach ($fields_array as $field) { + if (!empty($field['distinct'])) { + $get_count_optimized = FALSE; + break; + } + } + } + else { + $get_count_optimized = FALSE; + } + if (!isset($get_count_optimized)) { + $get_count_optimized = TRUE; + } + + $joins = $fields = $where = $having = $orderby = $groupby = ''; + // Add all the tables to the query via joins. We assume all LEFT joins. + foreach ($this->table_queue as $table) { + if (is_object($table['join'])) { + $joins .= $table['join']->join($table, $this) . "\n"; + } + } + + $has_aggregate = FALSE; + $non_aggregates = array(); + + foreach ($fields_array as $field) { + if ($fields) { + $fields .= ",\n "; + } + $string = ''; + if (!empty($field['table'])) { + $string .= $field['table'] . '.'; + } + $string .= $field['field']; + + // store for use with non-aggregates below + $fieldname = (!empty($field['alias']) ? $field['alias'] : $string); + + if (!empty($field['distinct'])) { + $string = "DISTINCT($string)"; + } + if (!empty($field['count'])) { + $string = "COUNT($string)"; + $has_aggregate = TRUE; + } + else if (!empty($field['aggregate'])) { + $has_aggregate = TRUE; + } + elseif ($this->distinct && !in_array($fieldname, $this->groupby)) { + $string = $GLOBALS['db_type'] == 'pgsql' ? "FIRST($string)" : $string; + } + else { + $non_aggregates[] = $fieldname; + } + if ($field['alias']) { + $string .= " AS $field[alias]"; + } + $fields .= $string; + + if ($get_count_optimized) { + // We only want the first field in this case. + break; + } + } + + if ($has_aggregate || $this->groupby) { + $groupby = "GROUP BY " . implode(', ', array_unique(array_merge($this->groupby, $non_aggregates))) . "\n"; + if ($this->having) { + $having = $this->condition_sql('having'); + } + } + + if (!$get_count_optimized) { + // we only add the groupby if we're not counting. + if ($this->orderby) { + $orderby = "ORDER BY " . implode(', ', $this->orderby) . "\n"; + } + } + + $where = $this->condition_sql(); + + $query = "SELECT $fields\n FROM {" . $this->base_table . "} $this->base_table \n$joins $where $groupby $having $orderby"; + + $replace = array('>' => '>', '<' => '<'); + $query = strtr($query, $replace); + + return $query; + } + + /** + * Get the arguments attached to the WHERE and HAVING clauses of this query. + */ + function get_where_args() { + $args = array(); + foreach ($this->where as $group => $where) { + $args = array_merge($args, $where['args']); + } + foreach ($this->having as $group => $having) { + $args = array_merge($args, $having['args']); + } + return $args; + } +} + diff --git a/sites/all/modules/views/includes/tabs.inc b/sites/all/modules/views/includes/tabs.inc new file mode 100644 index 0000000..c602f2d --- /dev/null +++ b/sites/all/modules/views/includes/tabs.inc @@ -0,0 +1,192 @@ +set(). This will be the link to click on to + * view the tab. + * @param $body + * If given, this is the body of the tab itself. It will display + * when the tab title is clicked on. + */ + function add($name, $title = '', $body = '') { + if (is_object($name) && is_subclass_of($name, 'views_tab')) { + $this->add_tab($name); + } + elseif (is_array($name)) { + foreach ($name as $real_tab) { + $this->add($real_tab); + } + } + else { + $this->add_tab(new views_tab($name, $title, $body)); + } + } + + /** + * Add a fully realized tab object to the tabset. + * + * @param $tab + * A fully populated views_tab object. + */ + function add_tab($tab) { + $this->tabs[$tab->name] = $tab; + } + + /** + * Set the values of a tab. + * + * @param $name + * The unique identifier of the tab to set. + * @param $title + * The title of the tab; this will be clickable. + * @param $body + * The HTML body of the tab. + */ + function set($name, $title, $body = NULL) { + if (empty($this->tabs[$name])) { + return $this->add($name, $title, $body); + } + $this->tabs[$name]->title = $title; + if (isset($body)) { + $this->tabs[$name]->body = $body; + } + } + + /** + * Set the body of a tab. + */ + function set_body($name, $body) { + if (empty($this->tabs[$name])) { + return $this->add($name, '', $body); + } + $this->tabs[$name]->body = $body; + } + + /** + * Add text to the 'extra' region of the tabset. + */ + function add_extra($text) { + $this->extra .= $text; + } + + /** + * Remove a tab. + * + * @param $tab + * May be the name of the tab or a views_tab object. + */ + function remove($tab) { + if (is_string($tab)) { + unset($this->tabs[$tab]); + } + else { + unset($this->tabs[$tab->name]); + } + } + + /** + * Control which tab will be selected when it is rendered. + */ + function set_selected($name) { + $this->selected = $name; + } + + /** + * Output the HTML for the tabs. + * + * @return + * HTML representation of the tabs. + */ + function render() { + views_add_js('tabs'); + views_add_css('views-tabs'); + + if (empty($this->selected)) { + $keys = array_keys($this->tabs); + $this->selected = array_shift($keys); + } + + drupal_alter('views_tabset', $this); + return theme('views_tabset', $this->tabs, $this->extra, $this->selected); + } +} + +/** + * An object to represent an individual tab within a tabset. + */ +class views_tab { + var $title; + var $body; + var $name; + + /** + * Construct a new tab. + */ + function views_tab($name, $title, $body = NULL) { + $this->name = $name; + $this->title = $title; + $this->body = $body; + } + + /** + * Generate HTML output for a tab. + */ + function render() { + return theme('views_tab', $this->body); + } +} + +/** + * Render a tabset. + * + * @todo Turn this into a template. + */ +function theme_views_tabset($tabs, $extra = NULL, $selected = NULL) { + $link_output = "
    \n"; + $tab_output = "
    \n"; + + foreach ($tabs as $name => $tab) { + $link_output .= '' . check_plain($tab->title) . '' . "\n"; + $tab_output .= '
    ' . $tab->render() . "
    \n"; + } + $link_output .= "
\n"; + + if ($extra) { + $link_output .= "
$extra
\n"; + } + + $link_output .= "
\n"; + $tab_output .= "
\n"; + return '
' . $link_output . $tab_output . '
'; +} + +/** + * Theme a simple tab. + */ +function theme_views_tab($body) { + return $body; +} diff --git a/sites/all/modules/views/includes/view.inc b/sites/all/modules/views/includes/view.inc new file mode 100644 index 0000000..57a4fde --- /dev/null +++ b/sites/all/modules/views/includes/view.inc @@ -0,0 +1,2123 @@ + FALSE, + 'items_per_page' => 10, + 'element' => 0, + 'offset' => 0, + 'current_page' => 0, + ); + + // Places to put attached renderings: + var $attachment_before = ''; + var $attachment_after = ''; + + // Exposed widget input + var $exposed_data = array(); + var $exposed_input = array(); + + // Used to store views that were previously running if we recurse. + var $old_view = array(); + + /** + * Identifier of the current display. + * + * @var string + */ + var $current_display; + + /** + * Stores all the views substitutions. + */ + var $substitutions = array(); + + /** + * Constructor + */ + function view() { + parent::init(); + // Make sure all of our sub objects are arrays. + foreach ($this->db_objects() as $object) { + $this->$object = array(); + } + + $this->query = new stdClass(); + } + + /** + * Returns a list of the sub-object types used by this view. These types are + * stored on the display, and are used in the build process. + */ + function display_objects() { + return array('argument', 'field', 'sort', 'filter', 'relationship'); + } + + /** + * Returns the complete list of dependent objects in a view, for the purpose + * of initialization and loading/saving to/from the database. + */ + public static function db_objects() { + return array('display'); + } + + /** + * Set the arguments that come to this view. Usually from the URL + * but possibly from elsewhere. + */ + function set_arguments($args) { + $this->args = $args; + } + + /** + * Set the page size for ranged or pager queries + */ + function set_items_per_page($items_per_page) { + $this->pager['items_per_page'] = $items_per_page; + if (empty($items_per_page)) { + $this->pager['use_pager'] = FALSE; + } + } + + /** + * Change/Set the current page for the pager. + */ + function set_current_page($page) { + $this->pager['current_page'] = $page; + } + + /** + * Whether or not the pager should be used. + */ + function set_use_pager($use_pager) { + $this->pager['use_pager'] = $use_pager; + } + + /** + * The pager element id to use if use_apger is on + */ + function set_pager_element($pager_element) { + $this->pager['element'] = $pager_element; + } + + /** + * Synchronize views pager with global pager variables + * + */ + function synchronize_pager() { + if (!empty($this->pager['use_pager'])) { + // dump information about what we already know into the globals + global $pager_page_array, $pager_total, $pager_total_items; + // total rows in query + $pager_total_items[$this->pager['element']] = $this->total_rows; + // total pages + $pager_total[$this->pager['element']] = ceil($pager_total_items[$this->pager['element']] / $this->pager['items_per_page']); + + // What page was requested: + $pager_page_array = isset($_GET['page']) ? explode(',', $_GET['page']) : array(); + + // If the requested page was within range. $this->pager['current_page'] + // defaults to 0 so we don't need to set it in an out-of-range condition. + if (!empty($pager_page_array[$this->pager['element']])) { + $page = intval($pager_page_array[$this->pager['element']]); + if ($page > 0 && $page < $pager_total[$this->pager['element']]) { + $this->pager['current_page'] = $page; + } + } + $pager_page_array[$this->pager['element']] = $this->pager['current_page']; + } + } + + /** + * How many records to skip. This does not function if use_pager is + * set. + */ + function set_offset($offset) { + $this->pager['offset'] = $offset; + } + + /** + * Whether or not AJAX should be used. If AJAX is used, paging, + * tablesorting and exposed filters will be fetched via an AJAX call + * rather than a page refresh. + */ + function set_use_ajax($use_ajax) { + $this->use_ajax = $use_ajax; + } + + /** + * Set the exposed filters input to an array. If unset they will be taken + * from $_GET when the time comes. + */ + function set_exposed_input($filters) { + $this->exposed_input = $filters; + } + + /** + * Figure out what the exposed input for this view is. + */ + function get_exposed_input() { + // Fill our input either from $_GET or from something previously set on the + // view. + if (empty($this->exposed_input)) { + $this->exposed_input = $_GET; + // unset items that are definitely not our input: + foreach (array('page', 'q') as $key) { + if (isset($this->exposed_input[$key])) { + unset($this->exposed_input[$key]); + } + } + + // If we have no input at all, check for remembered input via session. + + // If filters are not overridden, store the 'remember' settings on the + // default display. If they are, store them on this display. This way, + // multiple displays in the same view can share the same filters and + // remember settings. + $display_id = ($this->display_handler->is_defaulted('filters')) ? 'default' : $this->current_display; + + if (empty($this->exposed_input) && !empty($_SESSION['views'][$this->name][$display_id])) { + $this->exposed_input = $_SESSION['views'][$this->name][$display_id]; + } + } + + return $this->exposed_input; + } + + /** + * Set the display for this view and initialize the display handler. + */ + function init_display($reset = FALSE) { + // The default display is always the first one in the list. + if (isset($this->current_display)) { + return TRUE; + } + + // Instantiate all displays + foreach (array_keys($this->display) as $id) { + // Correct for shallow cloning + // Often we'll have a cloned view so we don't mess up each other's + // displays, but the clone is pretty shallow and doesn't necessarily + // clone the displays. We can tell this by looking to see if a handler + // has already been set; if it has, but $this->current_display is not + // set, then something is dreadfully wrong. + if (!empty($this->display[$id]->handler)) { + $this->display[$id] = drupal_clone($this->display[$id]); + unset($this->display[$id]->handler); + } + $this->display[$id]->handler = views_get_plugin('display', $this->display[$id]->display_plugin); + if (!empty($this->display[$id]->handler)) { + // Initialize the new display handler with data. + $this->display[$id]->handler->init($this, $this->display[$id]); + // If this is NOT the default display handler, let it know which is + // since it may well utilize some data from the default. + // This assumes that the 'default' handler is always first. It always + // is. Make sure of it. + if ($id != 'default') { + $this->display[$id]->handler->default_display = &$this->display['default']->handler; + } + } + } + + $this->current_display = 'default'; + $this->display_handler = &$this->display['default']->handler; + + return TRUE; + } + + /** + * Get the first display that is accessible to the user. + * + * @param $displays + * Either a single display id or an array of display ids. + */ + function choose_display($displays) { + if (!is_array($displays)) { + return $displays; + } + + $this->init_display(); + + foreach ($displays as $display_id) { + if ($this->display[$display_id]->handler->access()) { + return $display_id; + } + } + + return 'default'; + } + + /** + * Set the display as current. + * + * @param $display_id + * The id of the display to mark as current. + */ + function set_display($display_id = NULL) { + // If we have not already initialized the display, do so. But be careful. + if (empty($this->current_display)) { + $this->init_display(); + + // If handlers were not initialized, and no argument was sent, set up + // to the default display. + if (empty($display_id)) { + $display_id = 'default'; + } + } + + $display_id = $this->choose_display($display_id); + + // If no display id sent in and one wasn't chosen above, we're finished. + if (empty($display_id)) { + return FALSE; + } + + // Ensure the requested display exists. + if (empty($this->display[$display_id])) { + $display_id = 'default'; + if (empty($this->display[$display_id])) { + vpr(t('set_display() called with invalid display id @display.', array('@display' => $display_id))); + return FALSE; + } + } + + // Set the current display. + $this->current_display = $display_id; + + // Ensure requested display has a working handler. + if (empty($this->display[$display_id]->handler)) { + return FALSE; + } + + // Set a shortcut + $this->display_handler = &$this->display[$display_id]->handler; + + return TRUE; + } + + /** + * Find and initialize the style plugin. + * + * Note that arguments may have changed which style plugin we use, so + * check the view object first, then ask the display handler. + */ + function init_style() { + if (isset($this->style_plugin)) { + return is_object($this->style_plugin); + } + + if (!isset($this->plugin_name)) { + $this->plugin_name = $this->display_handler->get_option('style_plugin'); + $this->style_options = $this->display_handler->get_option('style_options'); + } + + $this->style_plugin = views_get_plugin('style', $this->plugin_name); + + if (empty($this->style_plugin)) { + return FALSE; + } + + // init the new style handler with data. + $this->style_plugin->init($this, $this->display[$this->current_display], $this->style_options); + return TRUE; + } + + /** + * Acquire and attach all of the handlers. + */ + function init_handlers() { + if (empty($this->inited)) { + foreach (views_object_types() as $key => $info) { + $this->_init_handler($key, $info); + } + $this->inited = TRUE; + } + } + + /** + * Create a list of base tables eligible for this view. Used primarily + * for the UI. Display must be already initialized. + */ + function get_base_tables() { + $base_tables = array( + $this->base_table => TRUE, + '#global' => TRUE, + ); + + foreach ($this->display_handler->get_handlers('relationship') as $handler) { + $base_tables[$handler->definition['base']] = TRUE; + } + return $base_tables; + } + + /** + * Run the pre_query() on all active handlers. + */ + function _pre_query() { + foreach (views_object_types() as $key => $info) { + $handlers = &$this->$key; + $position = 0; + foreach ($handlers as $id => $handler) { + $handlers[$id]->position = $position; + $handlers[$id]->pre_query(); + $position++; + } + } + } + + /** + * Get's all the substitutions and store them. + */ + function substitutions($reset = FALSE) { + if ($reset || empty($this->substitutions)) { + $this->substitutions = module_invoke_all('views_query_substitutions', $this); + } + return $this->substitutions; + } + + /** + * Attach all of the handlers for each type. + * + * @param $key + * One of 'argument', 'field', 'sort', 'filter', 'relationship' + * @param $info + * The $info from views_object_types for this object. + */ + function _init_handler($key, $info) { + // Load the requested items from the display onto the object. + $this->$key = $this->display_handler->get_handlers($key); + + // This reference deals with difficult PHP indirection. + $handlers = &$this->$key; + + // Run through and test for accessibility. + foreach ($handlers as $id => $handler) { + if (!$handler->access()) { + unset($handlers[$id]); + } + } + } + + /** + * Render the exposed filter form. + * + * This actually does more than that; because it's using FAPI, the form will + * also assign data to the appropriate handlers for use in building the + * query. + */ + function render_exposed_form($block = FALSE) { + // Deal with any exposed filters we may have, before building. + $form_state = array( + 'view' => &$this, + 'display' => &$this->display_handler->display, + 'method' => 'get', + 'rerender' => TRUE, + 'no_redirect' => TRUE, + ); + + // Some types of displays (eg. attachments) may wish to use the exposed + // filters of their parent displays instead of showing an additional + // exposed filter form for the attachment as well as that for the parent. + if (!$this->display_handler->displays_exposed() || (!$block && $this->display_handler->get_option('exposed_block'))) { + unset($form_state['rerender']); + } + + if (!empty($this->ajax)) { + $form_state['ajax'] = TRUE; + } + + $output = drupal_build_form('views_exposed_form', $form_state); + if (!empty($form_state['js settings'])) { + $this->js_settings = $form_state['js settings']; + } + + // Don't render exposed filter form when there's form errors. + // Applies when filters are in a block ("exposed_block" option). + if (form_get_errors() && empty($form_state['rerender'])) { + return NULL; + } + + return $output; + } + + /** + * Build all the arguments. + */ + function _build_arguments() { + // Initially, we want to build sorts and fields. This can change, though, + // if we get a summary view. + if (empty($this->argument)) { + return TRUE; + } + + // build arguments. + $position = -1; + + // Create a title for use in the breadcrumb trail. + $title = $this->display_handler->get_option('title'); + + $this->build_info['breadcrumb'] = array(); + $breadcrumb_args = array(); + $substitutions = array(); + + $status = TRUE; + + // Iterate through each argument and process. + foreach ($this->argument as $id => $arg) { + $position++; + $argument = &$this->argument[$id]; + + if ($argument->broken()) { + continue; + } + + $argument->set_relationship(); + + $arg = isset($this->args[$position]) ? $this->args[$position] : NULL; + $argument->position = $position; + + if (isset($arg) || $argument->has_default_argument()) { + if (!isset($arg)) { + $arg = $argument->get_default_argument(); + // make sure default args get put back. + if (isset($arg)) { + $this->args[$position] = $arg; + } + } + + // Set the argument, which will also validate that the argument can be set. + if (!$argument->set_argument($arg)) { + $status = $argument->validate_fail($arg); + break; + } + + if ($argument->is_wildcard()) { + $arg_title = $argument->wildcard_title(); + } + else { + $arg_title = $argument->get_title(); + $argument->query(); + } + + // Add this argument's substitution + $substitutions['%' . ($position + 1)] = $arg_title; + + // Since we're really generating the breadcrumb for the item above us, + // check the default action of this argument. + if ($this->display_handler->uses_breadcrumb() && $argument->uses_breadcrumb()) { + $path = $this->get_url($breadcrumb_args); + if (strpos($path, '%') === FALSE) { + $breadcrumb = !empty($argument->options['breadcrumb'])? $argument->options['breadcrumb'] : $title; + $this->build_info['breadcrumb'][$path] = str_replace(array_keys($substitutions), $substitutions, $breadcrumb); + } + } + + // Allow the argument to muck with this breadcrumb. + $argument->set_breadcrumb($this->build_info['breadcrumb']); + + // Test to see if we should use this argument's title + if (!empty($argument->options['title'])) { + $title = $argument->options['title']; + } + + $breadcrumb_args[] = $arg; + } + else { + // determine default condition and handle. + $status = $argument->default_action(); + break; + } + + // Be safe with references and loops: + unset($argument); + } + + // set the title in the build info. + if (!empty($title)) { + $this->build_info['title'] = str_replace(array_keys($substitutions), $substitutions, $title); + } + + // Store the arguments for later use. + $this->build_info['substitutions'] = $substitutions; + + return $status; + } + + /** + * Do some common building initialization. + */ + function init_query() { + // Create and initialize the query object. + $views_data = views_fetch_data($this->base_table); + $this->base_field = $views_data['table']['base']['field']; + if (!empty($views_data['table']['base']['database'])) { + $this->base_database = $views_data['table']['base']['database']; + } + views_include('query'); + $this->query = new views_query($this->base_table, $this->base_field); + } + + /** + * Build the query for the view. + */ + function build($display_id = NULL) { + if (!empty($this->built)) { + return; + } + + if (empty($this->current_display) || $display_id) { + if (!$this->set_display($display_id)) { + return FALSE; + } + } + + // Let modules modify the view just prior to building it. + foreach (module_implements('views_pre_build') as $module) { + $function = $module . '_views_pre_build'; + $function($this); + } + + // Attempt to load from cache. + // @todo Load a build_info from cache. + + $start = views_microtime(); + // If that fails, let's build! + $this->build_info = array( + 'query' => '', + 'count_query' => '', + 'query_args' => array(), + ); + + $this->init_query(); + + // Call a module hook and see if it wants to present us with a + // pre-built query or instruct us not to build the query for + // some reason. + // @todo: Implement this. Use the same mechanism Panels uses. + + // Run through our handlers and ensure they have necessary information. + $this->init_handlers(); + + // Let the handlers interact with each other if they really want. + $this->_pre_query(); + + if ($this->display_handler->uses_exposed()) { + $this->exposed_widgets = $this->render_exposed_form(); + if (form_set_error() || !empty($this->build_info['abort'])) { + $this->built = TRUE; + // Don't execute the query, but rendering will still be executed to display the empty text. + $this->executed = TRUE; + return empty($this->build_info['fail']); + } + } + + // Build all the relationships first thing. + $this->_build('relationship'); + + // Build all the filters. + $this->_build('filter'); + + $this->build_sort = TRUE; + + // Arguments can, in fact, cause this whole thing to abort. + if (!$this->_build_arguments()) { + $this->build_time = views_microtime() - $start; + $this->attach_displays(); + return $this->built; + } + + // Initialize the style; arguments may have changed which style we use, + // so waiting as long as possible is important. But we need to know + // about the style when we go to build fields. + if (!$this->init_style()) { + $this->build_info['fail'] = TRUE; + return FALSE; + } + + if ($this->style_plugin->uses_fields()) { + $this->_build('field'); + } + + // Build our sort criteria if we were instructed to do so. + if (!empty($this->build_sort)) { + // Allow the style handler to deal with sorting. + if ($this->style_plugin->build_sort()) { + $this->_build('sort'); + } + // allow the plugin to build second sorts as well. + $this->style_plugin->build_sort_post(); + } + + // Allow display handler to affect the query: + $this->display_handler->query(); + + // Allow style handler to affect the query: + $this->style_plugin->query(); + + if (variable_get('views_sql_signature', FALSE)) { + $this->query->add_field(NULL, "'" . $this->name . ':' . $this->current_display . "'", 'view_name'); + } + + // Let modules modify the query just prior to finalizing it. + foreach (module_implements('views_query_alter') as $module) { + $function = $module . '_views_query_alter'; + $function($this, $this->query); + } + + $this->build_info['query'] = $this->query->query(); + $this->build_info['count_query'] = $this->query->query(TRUE); + $this->build_info['query_args'] = $this->query->get_where_args(); + $this->built = TRUE; + $this->build_time = views_microtime() - $start; + + // Attach displays + $this->attach_displays(); + + // Let modules modify the view just after building it. + foreach (module_implements('views_post_build') as $module) { + $function = $module . '_views_post_build'; + $function($this); + } + + return TRUE; + } + + /** + * Internal method to build an individual set of handlers. + */ + function _build($key) { + $handlers = &$this->$key; + foreach ($handlers as $id => $data) { + if (!empty($handlers[$id]) && is_object($handlers[$id])) { + // Give this handler access to the exposed filter input. + if (!empty($this->exposed_data)) { + $rc = $handlers[$id]->accept_exposed_input($this->exposed_data); + $handlers[$id]->store_exposed_input($this->exposed_data, $rc); + if (!$rc) { + continue; + } + } + $handlers[$id]->set_relationship(); + $handlers[$id]->query(); + } + } + } + + /** + * Execute the view's query. + */ + function execute($display_id = NULL) { + if (empty($this->built)) { + if (!$this->build($display_id)) { + return FALSE; + } + } + + if (!empty($this->executed)) { + return TRUE; + } + + // Let modules modify the view just prior to executing it. + foreach (module_implements('views_pre_execute') as $module) { + $function = $module . '_views_pre_execute'; + $function($this); + } + + $query = db_rewrite_sql($this->build_info['query'], $this->base_table, $this->base_field, array('view' => &$this)); + $count_query = db_rewrite_sql($this->build_info['count_query'], $this->base_table, $this->base_field, array('view' => &$this)); + + $args = $this->build_info['query_args']; + + vpr($query); + + + // Check for already-cached results. + if (!empty($this->live_preview)) { + $cache = FALSE; + } + else { + $cache = $this->display_handler->get_cache_plugin(); + } + if ($cache && $cache->cache_get('results')) { + $this->synchronize_pager(); + vpr('Used cached results'); + } + else { + $items = array(); + if ($query) { + $replacements = $this->substitutions(); + $query = str_replace(array_keys($replacements), $replacements, $query); + $count_query = 'SELECT COUNT(*) FROM (' . str_replace(array_keys($replacements), $replacements, $count_query) . ') count_alias'; + + if (is_array($args)) { + foreach ($args as $id => $arg) { + $args[$id] = str_replace(array_keys($replacements), $replacements, $arg); + } + } + + // Allow for a view to query an external database. + if (isset($this->base_database)) { + db_set_active($this->base_database); + $external = TRUE; + } + + $start = views_microtime(); + if (!empty($this->pager['items_per_page'])) { + // We no longer use pager_query() here because pager_query() does not + // support an offset. This is fine as we don't actually need pager + // query; we've already been doing most of what it does, and we + // just need to do a little more playing with globals. + if (!empty($this->pager['use_pager']) || !empty($this->get_total_rows)) { + $this->total_rows = db_result(db_query($count_query, $args)) - $this->pager['offset']; + } + + $this->synchronize_pager(); + $offset = $this->pager['current_page'] * $this->pager['items_per_page'] + $this->pager['offset']; + $result = db_query_range($query, $args, $offset, $this->pager['items_per_page']); + + } + else { + $result = db_query($query, $args); + } + + $this->result = array(); + while ($item = db_fetch_object($result)) { + $this->result[] = $item; + } + + // If we already know how many items we have even if we did not run the + // count query, go ahead and set that value: + if (empty($this->pager['items_per_page'])) { + $this->total_rows = count($this->result); + } + + if (!empty($external)) { + db_set_active(); + } + $this->execute_time = views_microtime() - $start; + } + if ($cache) { + $cache->cache_set('results'); + } + } + + // Let modules modify the view just after executing it. + foreach (module_implements('views_post_execute') as $module) { + $function = $module . '_views_post_execute'; + $function($this); + } + + $this->executed = TRUE; + } + + /** + * Render this view for display. + */ + function render($display_id = NULL) { + $this->execute($display_id); + + // Check to see if the build failed. + if (!empty($this->build_info['fail'])) { + return; + } + + init_theme(); + + $start = views_microtime(); + if (!empty($this->live_preview) && variable_get('views_show_additional_queries', FALSE)) { + $this->start_query_capture(); + } + + // Check for already-cached output. + if (!empty($this->live_preview)) { + $cache = FALSE; + } + else { + $cache = $this->display_handler->get_cache_plugin(); + } + if ($cache && $cache->cache_get('output')) { + vpr('Used cached output'); + } + else { + if ($cache) { + $cache->cache_start(); + } + + // Initialize the style plugin. + $this->init_style(); + + $this->style_plugin->pre_render($this->result); + + // Let modules modify the view just prior to rendering it. + foreach (module_implements('views_pre_render') as $module) { + $function = $module . '_views_pre_render'; + $function($this); + } + + // Let the theme play too, because pre render is a very themey thing. + $function = $GLOBALS['theme'] . '_views_pre_render'; + if (function_exists($function)) { + $function($this); + } + + // Give field handlers the opportunity to perform additional queries + // using the entire resultset prior to rendering. + if ($this->style_plugin->uses_fields()) { + foreach ($this->field as $id => $handler) { + if (!empty($this->field[$id])) { + $this->field[$id]->pre_render($this->result); + } + } + } + $this->display_handler->output = $this->display_handler->render(); + if ($cache) { + $cache->cache_set('output'); + } + } + + if ($cache) { + $cache->post_render($this->display_handler->output); + } + + // Let modules modify the view output after it is rendered. + foreach (module_implements('views_post_render') as $module) { + $function = $module . '_views_post_render'; + $function($this, $this->display_handler->output, $cache); + } + + // Let the theme play too, because post render is a very themey thing. + $function = $GLOBALS['theme'] . '_views_post_render'; + if (function_exists($function)) { + $function($this, $this->display_handler->output, $cache); + } + + if (!empty($this->live_preview) && variable_get('views_show_additional_queries', FALSE)) { + $this->end_query_capture(); + } + $this->render_time = views_microtime() - $start; + + return $this->display_handler->output; + } + + /** + * Render a specific field via the field ID and the row #. + */ + function render_field($field, $row) { + if (isset($this->field[$field]) && isset($this->result[$row])) { + return $this->field[$field]->advanced_render($this->result[$row]); + } + } + + /** + * Execute the given display, with the given arguments. + * To be called externally by whatever mechanism invokes the view, + * such as a page callback, hook_block, etc. + * + * This function should NOT be used by anything external as this + * returns data in the format specified by the display. It can also + * have other side effects that are only intended for the 'proper' + * use of the display, such as setting page titles and breadcrumbs. + * + * If you simply want to view the display, use view::preview() instead. + */ + function execute_display($display_id = NULL, $args = array()) { + if (empty($this->current_display) || $this->current_display != $this->choose_display($display_id)) { + if (!$this->set_display($display_id)) { + return FALSE; + } + } + + $this->pre_execute($args); + + // Execute the view + $output = $this->display_handler->execute(); + + $this->post_execute(); + return $output; + } + + /** + * Preview the given display, with the given arguments. + * + * To be called externally, probably by an AJAX handler of some flavor. + * Can also be called when views are embedded, as this guarantees + * normalized output. + */ + function preview($display_id = NULL, $args = array()) { + if (empty($this->current_display) || ((!empty($display_id)) && $this->current_display != $display_id)) { + if (!$this->set_display($display_id)) { + return FALSE; + } + } + + $this->preview = TRUE; + $this->pre_execute($args); + // Preview the view. + $output = $this->display_handler->preview(); + + $this->post_execute(); + return $output; + } + + /** + * Run attachments and let the display do what it needs to do prior + * to running. + */ + function pre_execute($args = array()) { + $this->old_view[] = views_get_current_view(); + views_set_current_view($this); + $display_id = $this->current_display; + + // Let modules modify the view just prior to executing it. + foreach (module_implements('views_pre_view') as $module) { + $function = $module . '_views_pre_view'; + $function($this, $display_id, $args); + } + + // Prepare the view with the information we have, but only if we were + // passed arguments, as they may have been set previously. + if ($args) { + $this->set_arguments($args); + } + +// $this->attach_displays(); + + // Allow the display handler to set up for execution + $this->display_handler->pre_execute(); + } + + /** + * Unset the current view, mostly. + */ + function post_execute() { + // unset current view so we can be properly destructed later on. + // Return the previous value in case we're an attachment. + + if ($this->old_view) { + $old_view = array_pop($this->old_view); + } + + views_set_current_view(isset($old_view) ? $old_view : FALSE); + } + + /** + * Run attachment displays for the view. + */ + function attach_displays() { + if (!empty($this->is_attachment)) { + return; + } + + if (!$this->display_handler->accept_attachments()) { + return; + } + + $this->is_attachment = TRUE; + // Give other displays an opportunity to attach to the view. + foreach ($this->display as $id => $display) { + if (!empty($this->display[$id]->handler)) { + $this->display[$id]->handler->attach_to($this->current_display); + } + } + $this->is_attachment = FALSE; + } + + /** + * Called to get hook_menu() information from the view and the named display handler. + * + * @param $display_id + * A display id. + * @param $callbacks + * A menu callback array passed from views_menu_alter(). + */ + function execute_hook_menu($display_id = NULL, $callbacks = array()) { + // Prepare the view with the information we have. + + // This was probably already called, but it's good to be safe. + if (!$this->set_display($display_id)) { + return FALSE; + } + + // Execute the view + if (isset($this->display_handler)) { + return $this->display_handler->execute_hook_menu($callbacks); + } + } + + /** + * Called to get hook_block information from the view and the + * named display handler. + */ + function execute_hook_block($display_id = NULL) { + // Prepare the view with the information we have. + + // This was probably already called, but it's good to be safe. + if (!$this->set_display($display_id)) { + return FALSE; + } + + // Execute the view + if (isset($this->display_handler)) { + return $this->display_handler->execute_hook_block(); + } + } + + /** + * Determine if the given user has access to the view. Note that + * this sets the display handler if it hasn't been. + */ + function access($displays = NULL, $account = NULL) { + // Noone should have access to disabled views. + if (!empty($this->disabled)) { + return FALSE; + } + + if (!isset($this->current_display)) { + $this->init_display(); + } + + if (!$account) { + $account = $GLOBALS['user']; + } + + // We can't use choose_display() here because that function + // calls this one. + $displays = (array)$displays; + foreach ($displays as $display_id) { + if (!empty($this->display[$display_id]->handler)) { + if ($this->display[$display_id]->handler->access($account)) { + return TRUE; + } + } + } + + return FALSE; + } + + /** + * Get the view's current title. This can change depending upon how it + * was built. + */ + function get_title() { + if (empty($this->display_handler)) { + if (!$this->set_display('default')) { + return FALSE; + } + } + + // During building, we might find a title override. If so, use it. + if (!empty($this->build_info['title'])) { + $title = $this->build_info['title']; + } + else { + $title = $this->display_handler->get_option('title'); + } + + return $title; + } + + /** + * Force the view to build a title. + */ + function build_title() { + $this->init_display(); + if (empty($this->built)) { + $this->init_query(); + } + $this->init_handlers(); + + $this->_build_arguments(); + } + + /** + * Get the URL for the current view. + * + * This URL will be adjusted for arguments. + */ + function get_url($args = NULL, $path = NULL) { + if (!isset($path)) { + $path = $this->get_path(); + } + if (!isset($args)) { + $args = $this->args; + } + // Don't bother working if there's nothing to do: + if (empty($path) || (empty($args) && strpos($path, '%') === FALSE)) { + return $path; + } + + $pieces = array(); + $arguments = isset($arguments) ? $arguments : $this->display_handler->get_option('arguments'); + $argument_keys = isset($arguments) ? array_keys($arguments) : array(); + $id = current($argument_keys); + foreach (explode('/', $path) as $piece) { + if ($piece != '%') { + $pieces[] = $piece; + } + else { + if (empty($args)) { + // Try to never put % in a url; use the wildcard instead. + if ($id && !empty($arguments[$id]['wildcard'])) { + $pieces[] = $arguments[$id]['wildcard']; + } + else { + $pieces[] = '*'; // gotta put something if there just isn't one. + } + + } + else { + $pieces[] = array_shift($args); + } + + if ($id) { + $id = next($argument_keys); + } + } + } + + if (!empty($args)) { + $pieces = array_merge($pieces, $args); + } + return implode('/', $pieces); + } + + /** + * Get the base path used for this view. + */ + function get_path() { + if (!empty($this->override_path)) { + return $this->override_path; + } + + if (empty($this->display_handler)) { + if (!$this->set_display('default')) { + return FALSE; + } + } + return $this->display_handler->get_path(); + } + + /** + * Get the breadcrumb used for this view. + * + * @param $set + * If true, use drupal_set_breadcrumb() to install the breadcrumb. + */ + function get_breadcrumb($set = FALSE) { + // Now that we've built the view, extract the breadcrumb. + $base = TRUE; + $breadcrumb = array(); + + if (!empty($this->build_info['breadcrumb'])) { + foreach ($this->build_info['breadcrumb'] as $path => $title) { + // Check to see if the frontpage is in the breadcrumb trail; if it + // is, we'll remove that from the actual breadcrumb later. + if ($path == variable_get('site_frontpage', 'node')) { + $base = FALSE; + $title = t('Home'); + } + if ($title) { + $breadcrumb[] = l($title, $path, array('html' => true)); + } + } + + if ($set) { + if ($base) { + $breadcrumb = array_merge(drupal_get_breadcrumb(), $breadcrumb); + } + drupal_set_breadcrumb($breadcrumb); + } + } + return $breadcrumb; + } + + /** + * Is this view cacheable? + */ + function is_cacheable() { + return $this->is_cacheable; + } + + /** + * Set up query capturing. + * + * db_query() stores the queries that it runs in global $queries, + * bit only if dev_query is set to true. In this case, we want + * to temporarily override that setting if it's not and we + * can do that without forcing a db rewrite by just manipulating + * $conf. This is kind of evil but it works. + */ + function start_query_capture() { + global $conf, $queries; + if (empty($conf['dev_query'])) { + $this->fix_dev_query = TRUE; + $conf['dev_query'] = TRUE; + } + + // Record the last query key used; anything already run isn't + // a query that we are interested in. + $this->last_query_key = NULL; + + if (!empty($queries)) { + $keys = array_keys($queries); + $this->last_query_key = array_pop($keys); + } + } + + /** + * Add the list of queries run during render to buildinfo. + * + * @see view::start_query_capture() + */ + function end_query_capture() { + global $conf, $queries; + if (!empty($this->fix_dev_query)) { + $conf['dev_query'] = FALSE; + } + + // make a copy of the array so we can manipulate it with array_splice. + $temp = $queries; + + // Scroll through the queries until we get to our last query key. + // Unset anything in our temp array. + if (isset($this->last_query_key)) { + while (list($id, $query) = each($queries)) { + if ($id == $this->last_query_key) { + break; + } + + unset($temp[$id]); + } + } + + $this->additional_queries = $temp; + } + + /** + * Load a view from the database based upon either vid or name. + * + * This is a static factory method that implements internal caching for + * view objects. + * + * @param $arg + * The name of the view or its internal view id (vid) + * @param $reset + * If TRUE, reset this entry in the load cache. + * @return A view object or NULL if it was not available. + */ + public static function &load($arg, $reset = FALSE) { + static $cache = array(); + + // We want a NULL value to return TRUE here, so we can't use isset() or empty(). + if (!array_key_exists($arg, $cache) || $reset) { + $where = (is_numeric($arg) ? "vid = %d" : "name = '%s'"); + $data = db_fetch_object(db_query("SELECT * FROM {views_view} WHERE $where", $arg)); + if (empty($data)) { + $cache[$arg] = NULL; + } + else { + $view = new view(); + $view->load_row($data); + $view->type = t('Normal'); + // Load all of our subtables. + foreach ($view->db_objects() as $key) { + $object_name = "views_$key"; + $result = db_query("SELECT * FROM {{$object_name}} WHERE vid = %d ORDER BY position", $view->vid); + + while ($data = db_fetch_object($result)) { + $object = new $object_name(FALSE); + $object->load_row($data); + + // Because it can get complicated with this much indirection, + // make a shortcut reference. + $location = &$view->$key; + + // If we have a basic id field, load the item onto the view based on + // this ID, otherwise push it on. + if (!empty($object->id)) { + $location[$object->id] = $object; + } + else { + $location[] = $object; + } + } + } + + $view->loaded = TRUE; + $cache[$arg] = $view; + } + } + + return $cache[$arg]; + } + + /** + * Static factory method to load a list of views based upon a $where clause. + * + * Although this method could be implemented to simply iterate over views::load(), + * that would be very slow. Buiding the views externally from unified queries is + * much faster. + */ + public static function load_views() { + $result = db_query("SELECT DISTINCT v.* FROM {views_view} v"); + $views = array(); + $vids = array(); + + // Load all the views. + while ($data = db_fetch_object($result)) { + $view = new view; + $view->load_row($data); + $view->loaded = TRUE; + $view->type = t('Normal'); + $views[$view->name] = $view; + $names[$view->vid] = $view->name; + } + + // Stop if we didn't get any views. + if (!$views) { + return array(); + } + + $vids = implode(', ', array_keys($names)); + // Now load all the subtables: + foreach (view::db_objects() as $key) { + $object_name = "views_$key"; + $result = db_query("SELECT * FROM {{$object_name}} WHERE vid IN ($vids) ORDER BY vid, position"); + + while ($data = db_fetch_object($result)) { + $object = new $object_name(FALSE); + $object->load_row($data); + + // Because it can get complicated with this much indirection, + // make a shortcut reference. + $location = &$views[$names[$object->vid]]->$key; + + // If we have a basic id field, load the item onto the view based on + // this ID, otherwise push it on. + if (!empty($object->id)) { + $location[$object->id] = $object; + } + else { + $location[] = $object; + } + } + } + return $views; + } + + /** + * Save the view to the database. If the view does not already exist, + * A vid will be assigned to the view and also returned from this function. + */ + function save() { + if ($this->vid == 'new') { + $this->vid = NULL; + } + + // If we have no vid or our vid is a string, this is a new view. + if (!empty($this->vid)) { + // remove existing table entries + foreach ($this->db_objects() as $key) { + db_query("DELETE from {views_" . $key . "} WHERE vid = %d", $this->vid); + } + } + + $this->save_row(!empty($this->vid) ? 'vid' : FALSE); + + // Save all of our subtables. + foreach ($this->db_objects() as $key) { + $this->_save_rows($key); + } + + cache_clear_all('views_urls', 'cache_views'); + cache_clear_all(); // clear the page cache as well. + } + + /** + * Save a row to the database for the given key, which is one of the + * keys from view::db_objects() + */ + function _save_rows($key) { + $count = 0; + foreach ($this->$key as $position => $object) { + $object->position = ++$count; + $object->vid = $this->vid; + $object->save_row(); + } + } + + /** + * Delete the view from the database. + */ + function delete($clear = TRUE) { + if (empty($this->vid)) { + return; + } + + db_query("DELETE FROM {views_view} WHERE vid = %d", $this->vid); + // Delete from all of our subtables as well. + foreach ($this->db_objects() as $key) { + db_query("DELETE from {views_" . $key . "} WHERE vid = %d", $this->vid); + } + + cache_clear_all('views_query:' . $this->name, 'cache_views'); + + if ($clear) { + cache_clear_all(); // this clears the block and page caches only. + menu_rebuild(); // force a menu rebuild when a view is deleted. + } + } + + /** + * Export a view as PHP code. + */ + function export($indent = '') { + $this->init_display(); + $output = ''; + $output .= $this->export_row('view', $indent); + // Set the API version + $output .= $indent . '$view->api_version = \'' . views_api_version() . "';\n"; + $output .= $indent . '$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */' . "\n"; + + foreach ($this->display as $id => $display) { + $output .= $indent . '$handler = $view->new_display(' . views_var_export($display->display_plugin, $indent) . ', ' . views_var_export($display->display_title, $indent) . ', \'' . $id . "');\n"; + if (empty($display->handler)) { + // @todo -- probably need a method of exporting broken displays as + // they may simply be broken because a module is not installed. That + // does not invalidate the display. + continue; + } + + foreach ($display->handler->option_definition() as $option => $definition) { + // Special handling for some items + switch ($option) { + case 'defaults': + // skip these + break; + default: + if (!$display->handler->is_defaulted($option)) { + $value = $display->handler->get_option($option); + if ($id == 'default') { + $default = isset($definition['default']) ? $definition['default'] : NULL; + } + else { + $default = $this->display['default']->handler->get_option($option); + } + + if ($value !== $default) { + $output .= $indent . '$handler->override_option(\'' . $option . '\', ' . views_var_export($value, $indent) . ");\n"; + } + } + } + } + } + + return $output; + } + + /** + * Make a copy of this view that has been sanitized of all database IDs + * and handlers and other stuff. + * + * I'd call this clone() but it's reserved. + */ + function copy() { + $code = $this->export(); + eval($code); + return $view; + } + + /** + * Safely clone a view. + * + * Because views are complicated objects within objects, and PHP loves to + * do references to everything, if a View is not properly and safely + * cloned it will still have references to the original view, and can + * actually cause the original view to point to objects in the cloned + * view. This gets ugly fast. + * + * This will completely wipe a view clean so it can be considered fresh. + */ + function clone_view() { + $clone = version_compare(phpversion(), '5.0') < 0 ? $this : clone($this); + + $keys = array('current_display', 'display_handler', 'build_info', 'built', 'executed', 'attachment_before', 'attachment_after', 'field', 'argument', 'filter', 'sort', 'relationship', 'query', 'inited', 'style_plugin', 'plugin_name', 'exposed_data', 'exposed_input', 'exposed_widgets', 'many_to_one_tables', 'feed_icon'); + foreach ($keys as $key) { + if (isset($clone->$key)) { + unset($clone->$key); + } + } + $clone->built = $clone->executed = FALSE; + $clone->build_info = array(); + $clone->attachment_before = ''; + $clone->attachment_after = ''; + $clone->result = array(); + + // shallow cloning means that all the display objects + // *were not cloned*. We must clone them ourselves. + $displays = array(); + foreach ($clone->display as $id => $display) { + $displays[$id] = drupal_clone($display); + if (isset($displays[$id]->handler)) { + unset($displays[$id]->handler); + } + } + $clone->display = $displays; + + return $clone; + } + + /** + * Unset references so that a $view object may be properly garbage + * collected. + */ + function destroy() { + foreach (array_keys($this->display) as $display_id) { + if (isset($this->display[$display_id]->handler)) { + $this->display[$display_id]->handler->destroy(); + unset($this->display[$display_id]->handler); + } + } + + foreach (views_object_types() as $type => $info) { + if (isset($this->$type)) { + $handlers = &$this->$type; + foreach ($handlers as $id => $item) { + $handlers[$id]->destroy(); + } + unset($handlers); + } + } + + if (isset($this->style_plugin)) { + $this->style_plugin->destroy(); + unset($this->style_plugin); + } + + // Clear these to make sure the view can be processed/used again. + if (isset($this->display_handler)) { + unset($this->display_handler); + } + + if (isset($this->current_display)) { + unset($this->current_display); + } + + if (isset($this->query)) { + unset($this->query); + } + } + + /** + * Make sure the view is completely valid. + * + * @return + * TRUE if the view is valid; an array of error strings if it is not. + */ + function validate() { + $this->init_display(); + + $errors = array(); + + $current_display = $this->current_display; + foreach ($this->display as $id => $display) { + if ($display->handler) { + if (!empty($display->deleted)) { + continue; + } + $this->set_display($id); + + $result = $this->display[$id]->handler->validate(); + if (!empty($result) && is_array($result)) { + $errors = array_merge($errors, $result); + } + } + } + + $this->set_display($current_display); + return $errors ? $errors : TRUE; + } +} + +/** + * Base class for views' database objects. + */ +class views_db_object { + /** + * Initialize this object, setting values from schema defaults. + * + * @param $init + * If an array, this is a set of values from db_fetch_object to + * load. Otherwse, if TRUE values will be filled in from schema + * defaults. + */ + function init($init = TRUE) { + if (is_array($init)) { + return $this->load_row($init); + } + + if (!$init) { + return; + } + + $schema = drupal_get_schema($this->db_table); + + if (!$schema) { + return; + } + + // Go through our schema and build correlations. + foreach ($schema['fields'] as $field => $info) { + if ($info['type'] == 'serial') { + $this->$field = NULL; + } + if (!isset($this->$field)) { + if (!empty($info['serialize']) && isset($info['serialized default'])) { + $this->$field = unserialize($info['serialized default']); + } + else if (isset($info['default'])) { + $this->$field = $info['default']; + } + else { + $this->$field = ''; + } + } + } + } + + /** + * Write the row to the database. + * + * @param $update + * If true this will be an UPDATE query. Otherwise it will be an INSERT. + */ + function save_row($update = NULL) { + $schema = drupal_get_schema($this->db_table); + $fields = $defs = $values = $serials = array(); + + // Go through our schema and build correlations. + foreach ($schema['fields'] as $field => $info) { + // special case -- skip serial types if we are updating. + if ($info['type'] == 'serial') { + $serials[] = $field; + continue; + } + $fields[] = $field; + switch ($info['type']) { + case 'blob': + $defs[] = '%b'; + break; + case 'int': + $defs[] = '%d'; + break; + case 'float': + case 'numeric': + $defs[] = '%f'; + break; + default: + $defs[] = "'%s'"; + } + if (empty($info['serialize'])) { + $values[] = $this->$field; + } + else { + $values[] = serialize($this->$field); + } + } + $query = ''; + if (!$update) { + $query = "INSERT INTO {" . $this->db_table . "} (" . implode(', ', $fields) . ') VALUES (' . implode(', ', $defs) . ')'; + } + else { + $query = ''; + foreach ($fields as $id => $field) { + if ($query) { + $query .= ', '; + } + $query .= $field . ' = ' . $defs[$id]; + } + $query = "UPDATE {" . $this->db_table . "} SET " . $query . " WHERE $update = " . $this->$update; + } + db_query($query, $values); + + if ($serials && !$update) { + // get last insert ids and fill them in. + foreach ($serials as $field) { + $this->$field = db_last_insert_id($this->db_table, $field); + } + } + } + + /** + * Load the object with a row from the database. + * + * This method is separate from the constructor in order to give us + * more flexibility in terms of how the view object is built in different + * contexts. + * + * @param $data + * An object from db_fetch_object. It should contain all of the fields + * that are in the schema. + */ + function load_row($data) { + $schema = drupal_get_schema($this->db_table); + + // Go through our schema and build correlations. + foreach ($schema['fields'] as $field => $info) { + $this->$field = empty($info['serialize']) ? $data->$field : unserialize(db_decode_blob($data->$field)); + } + } + + /** + * Export a loaded row, such as an argument, field or the view itself to PHP code. + * + * @param $identifier + * The variable to assign the PHP code for this object to. + * @param $indent + * An optional indentation for prettifying nested code. + */ + function export_row($identifier = NULL, $indent = '') { + if (!$identifier) { + $identifier = $this->db_table; + } + $schema = drupal_get_schema($this->db_table); + + $output = $indent . '$' . $identifier . ' = new ' . get_class($this) . ";\n"; + // Go through our schema and build correlations. + foreach ($schema['fields'] as $field => $info) { + if (!empty($info['no export'])) { + continue; + } + if (!isset($this->$field)) { + if (isset($info['default'])) { + $this->$field = $info['default']; + } + else { + $this->$field = ''; + } + + // serialized defaults must be set as serialized. + if (isset($info['serialize'])) { + $this->$field = unserialize(db_decode_blob($this->$field)); + } + } + $value = $this->$field; + if ($info['type'] == 'int') { + $value = ($info['size'] == 'tiny') ? (bool) $value : (int) $value; + } + + $output .= $indent . '$' . $identifier . '->' . $field . ' = ' . views_var_export($value, $indent) . ";\n"; + } + return $output; + } + + /** + * Add a new display handler to the view, automatically creating an id. + * + * @param $type + * The plugin type from the views plugin data. Defaults to 'page'. + * @param $title + * The title of the display; optional, may be filled in from default. + * @param $id + * The id to use. + * @return + * The key to the display in $view->display, so that the new display + * can be easily located. + */ + function add_display($type = 'page', $title = NULL, $id = NULL) { + if (empty($type)) { + return FALSE; + } + + $plugin = views_fetch_plugin_data('display', $type); + if (empty($plugin)) { + $plugin['title'] = t('Broken'); + } + + + if (empty($id)) { + $title = $plugin['title']; + + $id = $this->generate_display_id($type); + $count = str_replace($type . '_', '', $id); + if (empty($title)) { + $title = $plugin['title'] . ' ' . $count; + } + } + + // Create the new display object + $display = new views_display; + $display->options($type, $id, $title); + + // Add the new display object to the view. + $this->display[$id] = $display; + return $id; + } + + /** + * Generate a display id of a certain plugin type. + * + * @param $type + * Which plugin should be used for the new display id. + */ + function generate_display_id($type) { + // 'default' is singular and is unique, so just go with 'default' + // for it. For all others, start counting. + if ($type == 'default') { + return 'default'; + } + // Initial id. + $id = $type . '_1'; + $count = 1; + + // Loop through IDs based upon our style plugin name until + // we find one that is unused. + while (!empty($this->display[$id])) { + $id = $type . '_' . ++$count; + } + + return $id; + } + + /** + * Create a new display and a display handler for it. + * @param $type + * The plugin type from the views plugin data. Defaults to 'page'. + * @param $title + * The title of the display; optional, may be filled in from default. + * @param $id + * The id to use. + * @return + * A reference to the new handler object. + */ + function &new_display($type = 'page', $title = NULL, $id = NULL) { + $id = $this->add_display($type, $title, $id); + + // Create a handler + $this->display[$id]->handler = views_get_plugin('display', $this->display[$id]->display_plugin); + if (empty($this->display[$id]->handler)) { + // provide a 'default' handler as an emergency. This won't work well but + // it will keep things from crashing. + $this->display[$id]->handler = views_get_plugin('display', 'default'); + } + + if (!empty($this->display[$id]->handler)) { + // Initialize the new display handler with data. + $this->display[$id]->handler->init($this, $this->display[$id]); + // If this is NOT the default display handler, let it know which is + if ($id != 'default') { + $this->display[$id]->handler->default_display = &$this->display['default']->handler; + } + } + + return $this->display[$id]->handler; + } + + /** + * Add an item with a handler to the view. + * + * These items may be fields, filters, sort criteria, or arguments. + */ + function add_item($display_id, $type, $table, $field, $options = array(), $id = NULL) { + $types = views_object_types(); + $this->set_display($display_id); + + $fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']); + + if (empty($id)) { + $count = 0; + $id = $field; + while (!empty($fields[$id])) { + $id = $field . '_' . ++$count; + } + } + + $new_item = array( + 'id' => $id, + 'table' => $table, + 'field' => $field, + ) + $options; + + $handler = views_get_handler($table, $field, $type); + + $fields[$id] = $new_item; + $this->display[$display_id]->handler->set_option($types[$type]['plural'], $fields); + + return $id; + } + + /** + * Get an array of items for the current display. + */ + function get_items($type, $display_id = NULL) { + $this->set_display($display_id); + + if (!isset($display_id)) { + $display_id = $this->current_display; + } + + // Get info about the types so we can get the right data. + $types = views_object_types(); + return $this->display[$display_id]->handler->get_option($types[$type]['plural']); + } + + /** + * Get the configuration of an item (field/sort/filter/etc) on a given + * display. + */ + function get_item($display_id, $type, $id) { + // Get info about the types so we can get the right data. + $types = views_object_types(); + // Initialize the display + $this->set_display($display_id); + + // Get the existing configuration + $fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']); + + return isset($fields[$id]) ? $fields[$id] : NULL; + } + + /** + * Get the configuration of an item (field/sort/filter/etc) on a given + * display. + * + * Pass in NULL for the $item to remove an item. + */ + function set_item($display_id, $type, $id, $item) { + // Get info about the types so we can get the right data. + $types = views_object_types(); + // Initialize the display + $this->set_display($display_id); + + // Get the existing configuration + $fields = $this->display[$display_id]->handler->get_option($types[$type]['plural']); + if (isset($item)) { + $fields[$id] = $item; + } + else { + unset($fields[$id]); + } + + // Store. + $this->display[$display_id]->handler->set_option($types[$type]['plural'], $fields); + } + + /** + * Set an option on an item. + * + * Use this only if you have just 1 or 2 options to set; if you have + * many, consider getting the item, adding the options and doing + * set_item yourself. + */ + function set_item_option($display_id, $type, $id, $option, $value) { + $item = $this->get_item($display_id, $type, $id); + $item[$option] = $value; + $this->set_item($display_id, $type, $id, $item); + } +} + +/** + * A display type in a view. + * + * This is just the database storage mechanism, and isn't terribly important + * to the behavior of the display at all. + */ +class views_display extends views_db_object { + var $db_table = 'views_display'; + function views_display($init = TRUE) { + parent::init($init); + } + + function options($type, $id, $title) { + $this->display_plugin = $type; + $this->id = $id; + $this->display_title = $title; + } +} + +/** + * Provide a list of views object types used in a view, with some information + * about them. + */ +function views_object_types() { + static $retval = NULL; + + // statically cache this so t() doesn't run a bajillion times. + if (!isset($retval)) { + $retval = array( + 'field' => array( + 'title' => t('Fields'), // title + 'ltitle' => t('fields'), // lowercase title for mid-sentence + 'stitle' => t('Field'), // singular title + 'lstitle' => t('field'), // singular lowercase title for mid sentence + 'plural' => 'fields', + ), + 'argument' => array( + 'title' => t('Arguments'), + 'ltitle' => t('arguments'), + 'stitle' => t('Argument'), + 'lstitle' => t('Argument'), + 'plural' => 'arguments', + ), + 'sort' => array( + 'title' => t('Sort criteria'), + 'ltitle' => t('sort criteria'), + 'stitle' => t('Sort criterion'), + 'lstitle' => t('sort criterion'), + 'plural' => 'sorts', + ), + 'filter' => array( + 'title' => t('Filters'), + 'ltitle' => t('filters'), + 'stitle' => t('Filter'), + 'lstitle' => t('filter'), + 'plural' => 'filters', + 'options' => 'views_ui_config_filters_form', + ), + 'relationship' => array( + 'title' => t('Relationships'), + 'ltitle' => t('relationships'), + 'stitle' => t('Relationship'), + 'lstitle' => t('Relationship'), + 'plural' => 'relationships', + ), + ); + } + + return $retval; +} + +/** + * @} + */ diff --git a/sites/all/modules/views/js/ajax.js b/sites/all/modules/views/js/ajax.js new file mode 100644 index 0000000..6669c85 --- /dev/null +++ b/sites/all/modules/views/js/ajax.js @@ -0,0 +1,365 @@ +/** + * @file ajax_admin.js + * + * Handles AJAX submission and response in Views UI. + */ + +Drupal.Views.Ajax = Drupal.Views.Ajax || {}; + +/** + * Handles the simple process of setting the ajax form area with new data. + */ +Drupal.Views.Ajax.setForm = function(title, output) { + $(Drupal.settings.views.ajax.title).html(title); + $(Drupal.settings.views.ajax.id).html(output); +} + +/** + * An ajax responder that accepts a packet of JSON data and acts appropriately. + * + * The following fields control behavior. + * - 'display': Display the associated data in the form area; bind the new + * form to 'url' if appropriate. The 'title' field may also be used. + * - 'add': This is a keyed array of HTML output to add via append. The key is + * the id to append via $(key).append(value) + * - 'replace': This is a keyed array of HTML output to add via replace. The key is + * the id to append via $(key).html(value) + * + */ +Drupal.Views.Ajax.ajaxResponse = function(data) { + $('a.views-throbbing').removeClass('views-throbbing'); + $('span.views-throbbing').remove(); + + if (data.debug) { + alert(data.debug); + } + + // See if we have any settings to extend. Do this first so that behaviors + // can access the new settings easily. + + if (Drupal.settings.viewsAjax) { + Drupal.settings.viewsAjax = {}; + } + if (data.js) { + $.extend(Drupal.settings, data.js); + } + + // Check the 'display' for data. + if (data.display) { + Drupal.Views.Ajax.setForm(data.title, data.display); + + // if a URL was supplied, bind the form to it. + if (data.url) { + var ajax_area = Drupal.settings.views.ajax.id; + var ajax_title = Drupal.settings.views.ajax.title; + + // Bind a click to the button to set the value for the button. + $('input[type=submit], button', ajax_area).unbind('click'); + $('input[type=submit], button', ajax_area).click(function() { + $('form', ajax_area).append(''); + $(this).after(' '); + }); + + // Bind forms to ajax submit. + $('form', ajax_area).unbind('submit'); // be safe here. + $('form', ajax_area).submit(function(arg) { + $(this).ajaxSubmit({ + url: data.url, + data: { 'js': 1 }, + type: 'POST', + success: Drupal.Views.Ajax.ajaxResponse, + error: function(xhr) { $('span.views-throbbing').remove(); Drupal.Views.Ajax.handleErrors(xhr, data.url); }, + dataType: 'json' + }); + return false; + }); + } + + Drupal.attachBehaviors(ajax_area); + } + else if (!data.tab) { + // If no display, reset the form. + Drupal.Views.Ajax.setForm('', Drupal.settings.views.ajax.defaultForm); + //Enable the save and delete button. + $('#edit-save').removeAttr('disabled'); + $('#edit-delete').removeAttr('disabled'); + // Trigger an update for the live preview when we reach this state: + if ($('#views-ui-preview-form input#edit-live-preview').is(':checked')) { + $('#views-ui-preview-form').trigger('submit'); + } + } + + // Go through the 'add' array and add any new content we're instructed to add. + if (data.add) { + for (id in data.add) { + var newContent = $(id).append(data.add[id]); + Drupal.attachBehaviors(newContent); + } + } + + // Go through the 'replace' array and replace any content we're instructed to. + if (data.replace) { + for (id in data.replace) { + $(id).html(data.replace[id]); + Drupal.attachBehaviors(id); + } + } + + // Go through and add any requested tabs + if (data.tab) { + for (id in data.tab) { + // Retrieve the tabset instance by stored ID. + var instance = Drupal.Views.Tabs.instances[$('#views-tabset').data('UI_TABS_UUID')]; + instance.add(id, data.tab[id]['title'], 0); + instance.click(instance.$tabs.length); + + $(id).html(data.tab[id]['body']); + $(id).addClass('views-tab'); + + // Update the preview widget to preview the new tab. + var display_id = id.replace('#views-tab-', ''); + $("#preview-display-id").append(''); + + Drupal.attachBehaviors(id); + } + } + + if (data.hilite) { + $('.hilited').removeClass('hilited'); + $(data.hilite).addClass('hilited'); + } + + if (data.changed) { + $('div.views-basic-info').addClass('changed'); + } +} + +/** + * An ajax responder that accepts a packet of JSON data and acts appropriately. + * This one specifically responds to the Views live preview area, so it's + * hardcoded and specialized. + */ +Drupal.Views.Ajax.previewResponse = function(data) { + $('a.views-throbbing').removeClass('views-throbbing'); + $('span.views-throbbing').remove(); + + if (data.debug) { + alert(data.debug); + } + + // See if we have any settings to extend. Do this first so that behaviors + // can access the new settings easily. + + // Clear any previous viewsAjax settings. + if (Drupal.settings.viewsAjax) { + Drupal.settings.viewsAjax = {}; + } + if (data.js) { + $.extend(Drupal.settings, data.js); + } + + // Check the 'display' for data. + if (data.display) { + var ajax_area = 'div#views-live-preview'; + $(ajax_area).html(data.display); + + var url = $(ajax_area, 'form').attr('action'); + + // if a URL was supplied, bind the form to it. + if (url) { + // Bind a click to the button to set the value for the button. + $('input[type=submit], button', ajax_area).unbind('click'); + $('input[type=submit], button', ajax_area).click(function() { + $('form', ajax_area).append(''); + $(this).after(' '); + }); + + // Bind forms to ajax submit. + $('form', ajax_area).unbind('submit'); // be safe here. + $('form', ajax_area).submit(function() { + $(this).ajaxSubmit({ + url: url, + data: { 'js': 1 }, + type: 'POST', + success: Drupal.Views.Ajax.previewResponse, + error: function(xhr) { $('span.views-throbbing').remove(); Drupal.Views.Ajax.handleErrors(xhr, url); }, + dataType: 'json' + }); + return false; + }); + } + + Drupal.attachBehaviors(ajax_area); + } +} + +Drupal.Views.updatePreviewForm = function() { + var url = $(this).attr('action'); + url = url.replace('nojs', 'ajax'); + + $('input[type=submit], button', this).after(' '); + $(this).ajaxSubmit({ + url: url, + data: { 'js': 1 }, + type: 'POST', + success: Drupal.Views.Ajax.previewResponse, + error: function(xhr) { $('span.views-throbbing').remove(); Drupal.Views.Ajax.handleErrors(xhr, url); }, + dataType: 'json' + }); + + return false; +} + +Drupal.Views.updatePreviewFilterForm = function() { + var url = $(this).attr('action'); + url = url.replace('nojs', 'ajax'); + + $('input[type=submit], button', this).after(' '); + $('input[name=q]', this).remove(); // remove 'q' for live preview. + $(this).ajaxSubmit({ + url: url, + data: { 'js': 1 }, + type: 'GET', + success: Drupal.Views.Ajax.previewResponse, + error: function(xhr) { $('span.views-throbbing').remove(); Drupal.Views.Ajax.handleErrors(xhr, url); }, + dataType: 'json' + }); + + return false; +} + +Drupal.Views.updatePreviewLink = function() { + var url = $(this).attr('href'); + url = url.replace('nojs', 'ajax'); + var intern_url = Drupal.Views.getPath(url); + + if (intern_url.substring(0, 17) != 'admin/build/views') { + return true; + } + + $(this).addClass('views-throbbing'); + $.ajax({ + url: url, + data: 'js=1', + type: 'POST', + success: Drupal.Views.Ajax.previewResponse, + error: function(xhr) { $(this).removeClass('views-throbbing'); Drupal.Views.Ajax.handleErrors(xhr, url); }, + dataType: 'json' + }); + + return false; +} + +Drupal.behaviors.ViewsAjaxLinks = function() { + // Make specified links ajaxy. + $('a.views-ajax-link:not(.views-processed)').addClass('views-processed').click(function() { + // Translate the href on the link to the ajax href. That way this degrades + // into a nice, normal link. + var url = $(this).attr('href'); + url = url.replace('nojs', 'ajax'); + + // Turn on the hilite to indicate this is in use. + $(this).addClass('hilite'); + + // Disable the save and delete button. + $('#edit-save').attr('disabled', 'true'); + $('#edit-delete').attr('disabled', 'true'); + + $(this).addClass('views-throbbing'); + $.ajax({ + type: "POST", + url: url, + data: 'js=1', + success: Drupal.Views.Ajax.ajaxResponse, + error: function(xhr) { $(this).removeClass('views-throbbing'); Drupal.Views.Ajax.handleErrors(xhr, url); }, + dataType: 'json' + }); + + return false; + }); + + $('form.views-ajax-form:not(.views-processed)').addClass('views-processed').submit(function(arg) { + // Translate the href on the link to the ajax href. That way this degrades + // into a nice, normal link. + var url = $(this).attr('action'); + url = url.replace('nojs', 'ajax'); + +// $('input[@type=submit]', this).after(' '); + $(this).ajaxSubmit({ + url: url, + data: { 'js': 1 }, + type: 'POST', + success: Drupal.Views.Ajax.ajaxResponse, + error: function(xhr) { $('span.views-throbbing').remove(); Drupal.Views.Ajax.handleErrors(xhr, url); }, + dataType: 'json' + }); + + return false; + }); + + // Bind the live preview to where it's supposed to go. + + $('form#views-ui-preview-form:not(.views-processed)') + .addClass('views-processed') + .submit(Drupal.Views.updatePreviewForm); + + $('div#views-live-preview form:not(.views-processed)') + .addClass('views-processed') + .submit(Drupal.Views.updatePreviewFilterForm); + + $('div#views-live-preview a:not(.views-processed)') + .addClass('views-processed') + .click(Drupal.Views.updatePreviewLink); +} + +/** + * Sync preview display. + */ +Drupal.behaviors.syncPreviewDisplay = function() { + $("#views-tabset a").click(function() { + var href = $(this).attr('href'); + // Cut of #views-tabset. + var display_id = href.substr(11); + // Set the form element. + $("#views-live-preview #preview-display-id").val(display_id); + }); +} + +/** + * Get rid of irritating tabledrag messages + */ +Drupal.theme.tableDragChangedWarning = function () { + return '
'; +} + +/** + * Display error in a more fashion way + */ +Drupal.Views.Ajax.handleErrors = function (xhr, path) { + var error_text = ''; + + if ((xhr.status == 500 && xhr.responseText) || xhr.status == 200) { + error_text = xhr.responseText; + + // Replace all < and > by < and > + error_text = error_text.replace("/&(lt|gt);/g", function (m, p) { + return (p == "lt")? "<" : ">"; + }); + + // Now, replace all html tags by empty spaces + error_text = error_text.replace(/<("[^"]*"|'[^']*'|[^'">])*>/gi,""); + + // Fix end lines + error_text = error_text.replace(/[\n]+\s+/g,"\n"); + } + else if (xhr.status == 500) { + error_text = xhr.status + ': ' + Drupal.t("Internal server error. Please see server or PHP logs for error information."); + } + else { + error_text = xhr.status + ': ' + xhr.statusText; + } + + alert(Drupal.t("An error occurred at @path.\n\nError Description: @error", {'@path': path, '@error': error_text})); +} diff --git a/sites/all/modules/views/js/ajax_view.js b/sites/all/modules/views/js/ajax_view.js new file mode 100644 index 0000000..e56e73a --- /dev/null +++ b/sites/all/modules/views/js/ajax_view.js @@ -0,0 +1,167 @@ + +/** + * @file ajaxView.js + * + * Handles AJAX fetching of views, including filter submission and response. + */ + +Drupal.Views.Ajax = Drupal.Views.Ajax || {}; + +/** + * An ajax responder that accepts a packet of JSON data and acts appropriately. + * + * The following fields control behavior. + * - 'display': Display the associated data in the view area. + */ +Drupal.Views.Ajax.ajaxViewResponse = function(target, response) { + + if (response.debug) { + alert(response.debug); + } + + var $view = $(target); + + // Check the 'display' for data. + if (response.status && response.display) { + var $newView = $(response.display); + $view.replaceWith($newView); + $view = $newView; + Drupal.attachBehaviors($view.parent()); + } + + if (response.messages) { + // Show any messages (but first remove old ones, if there are any). + $view.find('.views-messages').remove().end().prepend(response.messages); + } +}; + +/** + * Ajax behavior for views. + */ +Drupal.behaviors.ViewsAjaxView = function() { + if (Drupal.settings && Drupal.settings.views && Drupal.settings.views.ajaxViews) { + var ajax_path = Drupal.settings.views.ajax_path; + // If there are multiple views this might've ended up showing up multiple times. + if (ajax_path.constructor.toString().indexOf("Array") != -1) { + ajax_path = ajax_path[0]; + } + $.each(Drupal.settings.views.ajaxViews, function(i, settings) { + if (settings.view_dom_id) { + var view = '.view-dom-id-' + settings.view_dom_id; + if (!$(view).size()) { + // Backward compatibility: if 'views-view.tpl.php' is old and doesn't + // contain the 'view-dom-id-#' class, we fall back to the old way of + // locating the view: + view = '.view-id-' + settings.view_name + '.view-display-id-' + settings.view_display_id; + } + } + + + // Process exposed filter forms. + $('form#views-exposed-form-' + settings.view_name.replace(/_/g, '-') + '-' + settings.view_display_id.replace(/_/g, '-')) + .filter(':not(.views-processed)') + .each(function () { + // remove 'q' from the form; it's there for clean URLs + // so that it submits to the right place with regular submit + // but this method is submitting elsewhere. + $('input[name=q]', this).remove(); + var form = this; + // ajaxSubmit doesn't accept a data argument, so we have to + // pass additional fields this way. + $.each(settings, function(key, setting) { + $(form).append(''); + }); + }) + .addClass('views-processed') + .submit(function () { + $('input[type=submit], button', this).after(' '); + var object = this; + $(this).ajaxSubmit({ + url: ajax_path, + type: 'GET', + success: function(response) { + // Call all callbacks. + if (response.__callbacks) { + $.each(response.__callbacks, function(i, callback) { + eval(callback)(view, response); + }); + $('.views-throbbing', object).remove(); + } + }, + error: function(xhr) { Drupal.Views.Ajax.handleErrors(xhr, ajax_path); $('.views-throbbing', object).remove(); }, + dataType: 'json' + }); + + return false; + }); + + $(view).filter(':not(.views-processed)') + // Don't attach to nested views. Doing so would attach multiple behaviors + // to a given element. + .filter(function() { + // If there is at least one parent with a view class, this view + // is nested (e.g., an attachment). Bail. + return !$(this).parents('.view').size(); + }) + .each(function() { + // Set a reference that will work in subsequent calls. + var target = this; + $(this) + .addClass('views-processed') + // Process pager, tablesort, and attachment summary links. + .find('ul.pager > li > a, th.views-field a, .attachment .views-summary a') + .each(function () { + var viewData = { 'js': 1 }; + // Construct an object using the settings defaults and then overriding + // with data specific to the link. + $.extend( + viewData, + Drupal.Views.parseQueryString($(this).attr('href')), + // Extract argument data from the URL. + Drupal.Views.parseViewArgs($(this).attr('href'), settings.view_base_path), + // Settings must be used last to avoid sending url aliases to the server. + settings + ); + $(this).click(function () { + $.extend(viewData, Drupal.Views.parseViewArgs($(this).attr('href'), settings.view_base_path)); + $(this).addClass('views-throbbing'); + $.ajax({ + url: ajax_path, + type: 'GET', + data: viewData, + success: function(response) { + $(this).removeClass('views-throbbing'); + // Scroll to the top of the view. This will allow users + // to browse newly loaded content after e.g. clicking a pager + // link. + var offset = $(target).offset(); + // We can't guarantee that the scrollable object should be + // the body, as the view could be embedded in something + // more complex such as a modal popup. Recurse up the DOM + // and scroll the first element that has a non-zero top. + var scrollTarget = target; + while ($(scrollTarget).scrollTop() == 0 && $(scrollTarget).parent()) { + scrollTarget = $(scrollTarget).parent() + } + // Only scroll upward + if (offset.top - 10 < $(scrollTarget).scrollTop()) { + $(scrollTarget).animate({scrollTop: (offset.top - 10)}, 500); + } + // Call all callbacks. + if (response.__callbacks) { + $.each(response.__callbacks, function(i, callback) { + eval(callback)(target, response); + }); + } + }, + error: function(xhr) { $(this).removeClass('views-throbbing'); Drupal.Views.Ajax.handleErrors(xhr, ajax_path); }, + dataType: 'json' + }); + + return false; + }); + }); // .each function () { + }); // $view.filter().each + }); // .each Drupal.settings.views.ajaxViews + } // if +}; diff --git a/sites/all/modules/views/js/base.js b/sites/all/modules/views/js/base.js new file mode 100644 index 0000000..66171e6 --- /dev/null +++ b/sites/all/modules/views/js/base.js @@ -0,0 +1,122 @@ +/** + * @file base.js + * + * Some basic behaviors and utility functions for Views. + */ + +Drupal.Views = {}; + +/** + * jQuery UI tabs, Views integration component + */ +Drupal.behaviors.viewsTabs = function (context) { + $('#views-tabset:not(.views-processed)').addClass('views-processed').each(function() { + new Drupal.Views.Tabs($(this), {selectedClass: 'active'}); + }); + + $('a.views-remove-link') + .addClass('views-processed') + .click(function() { + var id = $(this).attr('id').replace('views-remove-link-', ''); + $('#views-row-' + id).hide(); + $('#views-removed-' + id).attr('checked', true); + return false; + }); +} + +/** + * For IE, attach some javascript so that our hovers do what they're supposed + * to do. + */ +Drupal.behaviors.viewsHoverlinks = function() { + if ($.browser.msie) { + // If IE, attach a hover event so we can see our admin links. + $("div.view:not(.views-hover-processed)").addClass('views-hover-processed').hover( + function() { + $('div.views-hide', this).addClass("views-hide-hover"); return true; + }, + function(){ + $('div.views-hide', this).removeClass("views-hide-hover"); return true; + } + ); + $("div.views-admin-links:not(.views-hover-processed)") + .addClass('views-hover-processed') + .hover( + function() { + $(this).addClass("views-admin-links-hover"); return true; + }, + function(){ + $(this).removeClass("views-admin-links-hover"); return true; + } + ); + } +} + +/** + * Helper function to parse a querystring. + */ +Drupal.Views.parseQueryString = function (query) { + var args = {}; + var pos = query.indexOf('?'); + if (pos != -1) { + query = query.substring(pos + 1); + } + var pairs = query.split('&'); + for(var i in pairs) { + if (typeof(pairs[i]) == 'string') { + var pair = pairs[i].split('='); + // Ignore the 'q' path argument, if present. + if (pair[0] != 'q' && pair[1]) { + args[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' ')); + } + } + } + return args; +}; + +/** + * Helper function to return a view's arguments based on a path. + */ +Drupal.Views.parseViewArgs = function (href, viewPath) { + var returnObj = {}; + var path = Drupal.Views.getPath(href); + // Ensure we have a correct path. + if (viewPath && path.substring(0, viewPath.length + 1) == viewPath + '/') { + var args = decodeURIComponent(path.substring(viewPath.length + 1, path.length)); + returnObj.view_args = args; + returnObj.view_path = path; + } + return returnObj; +}; + +/** + * Strip off the protocol plus domain from an href. + */ +Drupal.Views.pathPortion = function (href) { + // Remove e.g. http://example.com if present. + var protocol = window.location.protocol; + if (href.substring(0, protocol.length) == protocol) { + // 2 is the length of the '//' that normally follows the protocol + href = href.substring(href.indexOf('/', protocol.length + 2)); + } + return href; +}; + +/** + * Return the Drupal path portion of an href. + */ +Drupal.Views.getPath = function (href) { + href = Drupal.Views.pathPortion(href); + href = href.substring(Drupal.settings.basePath.length, href.length); + // 3 is the length of the '?q=' added to the url without clean urls. + if (href.substring(0, 3) == '?q=') { + href = href.substring(3, href.length); + } + var chars = ['#', '?', '&']; + for (i in chars) { + if (href.indexOf(chars[i]) > -1) { + href = href.substr(0, href.indexOf(chars[i])); + } + } + return href; +}; diff --git a/sites/all/modules/views/js/dependent.js b/sites/all/modules/views/js/dependent.js new file mode 100644 index 0000000..7683fdd --- /dev/null +++ b/sites/all/modules/views/js/dependent.js @@ -0,0 +1,195 @@ +/** + * @file dependent.js + * + * Written by dmitrig01 (Dmitri Gaskin) for Views; this provides dependent + * visibility for form items in Views' ajax forms. + * + * To your $form item definition add: + * - '#process' => array('views_process_dependency'), + * - Add '#dependency' => array('id-of-form-item' => array(list, of, values, that, + make, this, item, show), + * + * Special considerations: + * - radios are harder. Because Drupal doesn't give radio groups individual ids, + * use 'radio:name-of-radio' + * + * - Checkboxes don't have their own id, so you need to add one in a div + * around the checkboxes via #prefix and #suffix. You actually need to add TWO + * divs because it's the parent that gets hidden. Also be sure to retain the + * 'expand_checkboxes' in the #process array, because the views process will + * override it. + */ + +Drupal.Views = Drupal.Views || {}; + +Drupal.Views.dependent = { bindings: {}, activeBindings: {}, activeTriggers: [] }; + +Drupal.Views.dependent.inArray = function(array, search_term) { + var i = array.length; + if (i > 0) { + do { + if (array[i] == search_term) { + return true; + } + } while (i--); + } + return false; +} + + +Drupal.Views.dependent.autoAttach = function() { + // Clear active bindings and triggers. + for (i in Drupal.Views.dependent.activeTriggers) { + jQuery(Drupal.Views.dependent.activeTriggers[i]).unbind('change'); + } + Drupal.Views.dependent.activeTriggers = []; + Drupal.Views.dependent.activeBindings = {}; + Drupal.Views.dependent.bindings = {}; + + if (!Drupal.settings.viewsAjax) { + return; + } + + // Iterate through all relationships + for (id in Drupal.settings.viewsAjax.formRelationships) { + + // Drupal.Views.dependent.activeBindings[id] is a boolean, + // whether the binding is active or not. Defaults to no. + Drupal.Views.dependent.activeBindings[id] = 0; + // Iterate through all possible values + for(bind_id in Drupal.settings.viewsAjax.formRelationships[id].values) { + // This creates a backward relationship. The bind_id is the ID + // of the element which needs to change in order for the id to hide or become shown. + // The id is the ID of the item which will be conditionally hidden or shown. + // Here we're setting the bindings for the bind + // id to be an empty array if it doesn't already have bindings to it + if (!Drupal.Views.dependent.bindings[bind_id]) { + Drupal.Views.dependent.bindings[bind_id] = []; + } + // Add this ID + Drupal.Views.dependent.bindings[bind_id].push(id); + // Big long if statement. + // Drupal.settings.viewsAjax.formRelationships[id].values[bind_id] holds the possible values + + if (bind_id.substring(0, 6) == 'radio:') { + var trigger_id = "input[name='" + bind_id.substring(6) + "']"; + } + else { + var trigger_id = '#' + bind_id; + } + + Drupal.Views.dependent.activeTriggers.push(trigger_id); + + if (jQuery(trigger_id).attr('type') == 'checkbox') { + $(trigger_id).parent().addClass('hidden-options'); + } + + var getValue = function(item, trigger) { + if (item.substring(0, 6) == 'radio:') { + var val = jQuery(trigger + ':checked').val(); + } + else { + switch (jQuery(trigger).attr('type')) { + case 'checkbox': + var val = jQuery(trigger).attr('checked') || 0; + + if (val) { + $(trigger).parent().removeClass('hidden-options').addClass('expanded-options'); + } + else { + $(trigger).parent().removeClass('expanded-options').addClass('hidden-options'); + } + + break; + default: + var val = jQuery(trigger).val(); + } + } + return val; + } + + var setChangeTrigger = function(trigger_id, bind_id) { + // Triggered when change() is clicked. + var changeTrigger = function() { + var val = getValue(bind_id, trigger_id); + + for (i in Drupal.Views.dependent.bindings[bind_id]) { + var id = Drupal.Views.dependent.bindings[bind_id][i]; + + // Fix numerous errors + if (typeof id != 'string') { + continue; + } + + // This bit had to be rewritten a bit because two properties on the + // same set caused the counter to go up and up and up. + if (!Drupal.Views.dependent.activeBindings[id]) { + Drupal.Views.dependent.activeBindings[id] = {}; + } + + if (Drupal.Views.dependent.inArray(Drupal.settings.viewsAjax.formRelationships[id].values[bind_id], val)) { + Drupal.Views.dependent.activeBindings[id][bind_id] = 'bind'; + } + else { + delete Drupal.Views.dependent.activeBindings[id][bind_id]; + } + + var len = 0; + for (i in Drupal.Views.dependent.activeBindings[id]) { + len++; + } + + var object = jQuery('#' + id + '-wrapper'); + if (!object.size()) { + object = jQuery('#' + id).parent(); + } + + var rel_num = Drupal.settings.viewsAjax.formRelationships[id].num; + if (typeof rel_num === 'object') { + rel_num = Drupal.settings.viewsAjax.formRelationships[id].num[0]; + } + + if (rel_num <= len) { + // Show if the element if criteria is matched + object.show(0); + object.addClass('dependent-options'); + } + else { + // Otherwise hide + object.hide(0); + } + } + } + + jQuery(trigger_id).change(function() { + // Trigger the internal change function + // the attr('id') is used because closures are more confusing + changeTrigger(trigger_id, bind_id); + }); + // Trigger initial reaction + changeTrigger(trigger_id, bind_id); + } + setChangeTrigger(trigger_id, bind_id); + } + } +} + +Drupal.behaviors.viewsDependent = function (context) { + Drupal.Views.dependent.autoAttach(); + + // Really large sets of fields are too slow with the above method, so this + // is a sort of hacked one that's faster but much less flexible. + $("select.views-master-dependent:not(.views-processed)") + .addClass('views-processed') + .change(function() { + var val = $(this).val(); + if (val == 'all') { + $('.views-dependent-all').show(0); + } + else { + $('.views-dependent-all').hide(0); + $('.views-dependent-' + val).show(0); + } + }) + .trigger('change'); +} diff --git a/sites/all/modules/views/js/tabs.js b/sites/all/modules/views/js/tabs.js new file mode 100644 index 0000000..4e7e762 --- /dev/null +++ b/sites/all/modules/views/js/tabs.js @@ -0,0 +1,401 @@ + +/** + * @file tabs.js + * jQuery UI Tabs (Tabs 3) + * + * This is nothing more than the pure jquery UI tabs implementation. + * It has been implemented under the Drupal.Views.Tabs namespace to + * avoid conflicts with alternatve versions of jquery, jquery UI. + */ + +Drupal.Views = Drupal.Views || {}; + +Drupal.Views.Tabs = function(el, options) { + + this.source = el; + + this.options = $.extend({ + + // basic setup + initial: 0, + event: 'click', + disabled: [], + // TODO bookmarkable: $.ajaxHistory ? true : false, + unselected: false, + toggle: options.unselected ? true : false, + + // Ajax + spinner: 'Loading…', + cache: false, + hashPrefix: 'tab-', + + // animations + /*fxFade: null, + fxSlide: null, + fxShow: null, + fxHide: null,*/ + fxSpeed: 'normal', + /*fxShowSpeed: null, + fxHideSpeed: null,*/ + + // callbacks + add: function() {}, + remove: function() {}, + enable: function() {}, + disable: function() {}, + click: function() {}, + hide: function() {}, + show: function() {}, + load: function() {}, + + // CSS classes + navClass: 'ui-tabs-nav', + selectedClass: 'ui-tabs-selected', + disabledClass: 'ui-tabs-disabled', + containerClass: 'ui-tabs-container', + hideClass: 'ui-tabs-hide', + loadingClass: 'ui-tabs-loading' + + }, options); + + this.tabify(true); + + // save instance for later + var uuid = 'instance-' + Drupal.Views.Tabs.prototype.count++; + Drupal.Views.Tabs.instances[uuid] = this; + this.source.data('UI_TABS_UUID', uuid); + +}; + +// static +Drupal.Views.Tabs.instances = {}; + +$.extend(Drupal.Views.Tabs.prototype, { + animating: false, + count: 0, + tabify: function(init) { + + this.$tabs = $('a:first-child', this.source); + this.$containers = $([]); + + var self = this, o = this.options; + + this.$tabs.each(function(i, a) { + // inline tab + if (a.hash && a.hash.replace('#', '')) { // safari 2 reports '#' for an empty hash + self.$containers = self.$containers.add(a.hash); + } + // remote tab + else { + var id = a.title && a.title.replace(/\s/g, '_') || o.hashPrefix + (self.count + 1) + '-' + (i + 1), url = a.href; + a.href = '#' + id; + a.url = url; + self.$containers = self.$containers.add( + $('#' + id)[0] || $('
') + .insertAfter( self.$containers[i - 1] || self.source ) + ); + } + }); + + if (init) { + + // Try to retrieve initial tab from fragment identifier in url if present, + // otherwise try to find selected class attribute on
  • . + this.$tabs.each(function(i, a) { + if (location.hash) { + if (a.hash == location.hash) { + o.initial = i; + // prevent page scroll to fragment + //if (($.browser.msie || $.browser.opera) && !o.remote) { + if ($.browser.msie || $.browser.opera) { + var $toShow = $(location.hash), toShowId = $toShow.attr('id'); + $toShow.attr('id', ''); + setTimeout(function() { + $toShow.attr('id', toShowId); // restore id + }, 500); + } + scrollTo(0, 0); + return false; // break + } + } else if ( $(a).parents('li:eq(0)').is('li.' + o.selectedClass) ) { + o.initial = i; + return false; // break + } + }); + + // attach necessary classes for styling if not present + $(this.source).is('.' + o.navClass) || $(this.source).addClass(o.navClass); + this.$containers.each(function() { + var $this = $(this); + $this.is('.' + o.containerClass) || $this.addClass(o.containerClass); + }); + + // highlight tab accordingly + var $lis = $('li', this.source); + this.$containers.addClass(o.hideClass); + $lis.removeClass(o.selectedClass); + if (!o.unselected) { + this.$containers.slice(o.initial, o.initial + 1).show(); + $lis.slice(o.initial, o.initial + 1).addClass(o.selectedClass); + } + + // trigger load of initial tab is remote tab + if (this.$tabs[o.initial].url) { + this.load(o.initial + 1, this.$tabs[o.initial].url); + if (o.cache) { + this.$tabs[o.initial].url = null; // if loaded once do not load them again + } + } + + // disabled tabs + for (var i = 0, position; position = o.disabled[i]; i++) { + this.disable(position); + } + + } + + // setup animations + var showAnim = {}, hideAnim = {}, showSpeed = o.fxShowSpeed || o.fxSpeed, + hideSpeed = o.fxHideSpeed || o.fxSpeed; + if (o.fxSlide || o.fxFade) { + if (o.fxSlide) { + showAnim['height'] = 'show'; + hideAnim['height'] = 'hide'; + } + if (o.fxFade) { + showAnim['opacity'] = 'show'; + hideAnim['opacity'] = 'hide'; + } + } else { + if (o.fxShow) { + showAnim = o.fxShow; + } else { // use some kind of animation to prevent browser scrolling to the tab + showAnim['min-width'] = 0; // avoid opacity, causes flicker in Firefox + showSpeed = 1; // as little as 1 is sufficient + } + if (o.fxHide) { + hideAnim = o.fxHide; + } else { // use some kind of animation to prevent browser scrolling to the tab + hideAnim['min-width'] = 0; // avoid opacity, causes flicker in Firefox + hideSpeed = 1; // as little as 1 is sufficient + } + } + + // callbacks + var click = o.click, hide = o.hide, show = o.show; + + // reset some styles to maintain print style sheets etc. + var resetCSS = { display: '', overflow: '', height: '' }; + if (!$.browser.msie) { // not in IE to prevent ClearType font issue + resetCSS['opacity'] = ''; + } + + // hide a tab, animation prevents browser scrolling to fragment + function hideTab(clicked, $hide, $show) { + $hide.animate(hideAnim, hideSpeed, function() { // + $hide.addClass(o.hideClass).css(resetCSS); // maintain flexible height and accessibility in print etc. + hide(clicked, $show, $hide[0]); + if ($show) { + showTab(clicked, $hide, $show); + } + }); + } + + // show a tab, animation prevents browser scrolling to fragment + function showTab(clicked, $hide, $show) { + // show next tab + if (!(o.fxSlide || o.fxFade || o.fxShow)) { + $show.css('display', 'block'); // prevent occasionally occuring flicker in Firefox cause by gap between showing and hiding the tab containers + } + $show.animate(showAnim, showSpeed, function() { + $show.removeClass(o.hideClass).css(resetCSS); // maintain flexible height and accessibility in print etc. + if ($.browser.msie) { + $hide[0].style.filter = ''; + $show[0].style.filter = ''; + } + show(clicked, $show[0], $hide[0]); + self.animating = false; + }); + + } + + // switch a tab + function switchTab(clicked, $hide, $show) { + /*if (o.bookmarkable && trueClick) { // add to history only if true click occured, not a triggered click + $.ajaxHistory.update(clicked.hash); + }*/ + $(clicked).parents('li:eq(0)').addClass(o.selectedClass) + .siblings().removeClass(o.selectedClass); + hideTab(clicked, $hide, $show); + } + + // tab click handler + function tabClick(e) { + + //var trueClick = e.clientX; // add to history only if true click occured, not a triggered click + var $li = $(this).parents('li:eq(0)'), $hide = self.$containers.filter(':visible'), $show = $(this.hash); + + // if tab may be closed + if (o.toggle && !$li.is('.' + o.disabledClass) && !self.animating) { + if ($li.is('.' + o.selectedClass)) { + $li.removeClass(o.selectedClass); + hideTab(this, $hide); + this.blur(); + return false; + } else if (!$hide.length) { + $li.addClass(o.selectedClass); + showTab(this, $hide, $show); + this.blur(); + return false; + } + } + + // If tab is already selected or disabled, animation is still running or click callback + // returns false stop here. + // Check if click handler returns false last so that it is not executed for a disabled tab! + if ($li.is('.' + o.selectedClass + ', .' + o.disabledClass) + || self.animating || click(this, $show[0], $hide[0]) === false) { + this.blur(); + return false; + } + + self.animating = true; + + // show new tab + if ($show.length) { + + // prevent scrollbar scrolling to 0 and than back in IE7, happens only if bookmarking/history is enabled + /*if ($.browser.msie && o.bookmarkable) { + var showId = this.hash.replace('#', ''); + $show.attr('id', ''); + setTimeout(function() { + $show.attr('id', showId); // restore id + }, 0); + }*/ + + if (this.url) { // remote tab + var a = this; + self.load(self.$tabs.index(this) + 1, this.url, function() { + switchTab(a, $hide, $show); + }); + if (o.cache) { + this.url = null; // if loaded once do not load them again + } + } else { + switchTab(this, $hide, $show); + } + + // Set scrollbar to saved position - need to use timeout with 0 to prevent browser scroll to target of hash + /*var scrollX = window.pageXOffset || document.documentElement && document.documentElement.scrollLeft || document.body.scrollLeft || 0; + var scrollY = window.pageYOffset || document.documentElement && document.documentElement.scrollTop || document.body.scrollTop || 0; + setTimeout(function() { + scrollTo(scrollX, scrollY); + }, 0);*/ + + } else { + throw Drupal.t('jQuery UI Tabs: Mismatching fragment identifier.'); + } + + this.blur(); // prevent IE from keeping other link focussed when using the back button + + //return o.bookmarkable && !!trueClick; // convert trueClick == undefined to Boolean required in IE + return false; + + } + + // attach click event, avoid duplicates from former tabifying + this.$tabs.unbind(o.event, tabClick).bind(o.event, tabClick); + + }, + add: function(url, text, position) { + if (url && text) { + var o = this.options; + position = position || this.$tabs.length; // append by default + if (position >= this.$tabs.length) { + var method = 'insertAfter'; + position = this.$tabs.length; + } else { + var method = 'insertBefore'; + } + if (url.indexOf('#') == 0) { // ajax container is created by tabify automatically + var $container = $(url); + // try to find an existing element before creating a new one + ($container.length && $container || $('
    ')) + [method](this.$containers[position - 1]); + } + $('
  • ' + text + '
  • ') + [method](this.$tabs.slice(position - 1, position).parents('li:eq(0)')); + this.tabify(); + o.add(this.$tabs[position - 1], this.$containers[position - 1]); // callback + } else { + throw Drupal.t('jQuery UI Tabs: Not enough arguments to add tab.'); + } + }, + remove: function(position) { + if (position && position.constructor == Number) { + this.$tabs.slice(position - 1, position).parents('li:eq(0)').remove(); + this.$containers.slice(position - 1, position).remove(); + this.tabify(); + } + this.options.remove(); // callback + }, + enable: function(position) { + var $li = this.$tabs.slice(position - 1, position).parents('li:eq(0)'), o = this.options; + $li.removeClass(o.disabledClass); + if ($.browser.safari) { // fix disappearing tab after enabling in Safari... TODO check Safari 3 + $li.animate({ opacity: 1 }, 1, function() { + $li.css({ opacity: '' }); + }); + } + o.enable(this.$tabs[position - 1], this.$containers[position - 1]); // callback + }, + disable: function(position) { + var $li = this.$tabs.slice(position - 1, position).parents('li:eq(0)'), o = this.options; + if ($.browser.safari) { // fix opacity of tab after disabling in Safari... TODO check Safari 3 + $li.animate({ opacity: 0 }, 1, function() { + $li.css({ opacity: '' }); + }); + } + $li.addClass(this.options.disabledClass); + o.disable(this.$tabs[position - 1], this.$containers[position - 1]); // callback + }, + click: function(position) { + this.$tabs.slice(position - 1, position).trigger('click'); + }, + load: function(position, url, callback) { + var self = this, + o = this.options, + $a = this.$tabs.slice(position - 1, position).addClass(o.loadingClass), + $span = $('span', $a), + text = $span.html(); + + // shift arguments + if (url && url.constructor == Function) { + callback = url; + } + + // set new URL + if (url) { + $a[0].url = url; + } + + // load + if (o.spinner) { + $span.html('' + o.spinner + ''); + } + setTimeout(function() { // timeout is again required in IE, "wait" for id being restored + $($a[0].hash).load(url, function() { + if (o.spinner) { + $span.html(text); + } + $a.removeClass(o.loadingClass); + // This callback is needed because the switch has to take place after loading + // has completed. + if (callback && callback.constructor == Function) { + callback(); + } + o.load(self.$tabs[position - 1], self.$containers[position - 1]); // callback + }); + }, 0); + } +}); diff --git a/sites/all/modules/views/js/view-list.js b/sites/all/modules/views/js/view-list.js new file mode 100644 index 0000000..01ae24a --- /dev/null +++ b/sites/all/modules/views/js/view-list.js @@ -0,0 +1,13 @@ +/** + * @file view-list.js + * + * Handles JS things for view listing. + */ +Drupal.behaviors.ViewsList = function() { + var timeoutID = 0; + $('form#views-ui-list-views-form select:not(.views-processed)') + .addClass('views-processed') + .change(function() { + $('#edit-views-apply').click(); + }); +}; diff --git a/sites/all/modules/views/modules/aggregator.views.inc b/sites/all/modules/views/modules/aggregator.views.inc new file mode 100644 index 0000000..9bc1da1 --- /dev/null +++ b/sites/all/modules/views/modules/aggregator.views.inc @@ -0,0 +1,456 @@ + 'iid', + 'title' => t('Aggregator item'), + 'help' => t("Aggregator items are imported from external RSS and Atom news feeds."), + ); + + // ---------------------------------------------------------------- + // Fields + + // item id. + $data['aggregator_item']['iid'] = array( + 'title' => t('Feed Item ID'), + 'help' => t('The unique ID of the aggregator item.'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + 'numeric' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // iid + $data['aggregator_item']['iid'] = array( + 'title' => t('Item ID'), + 'help' => t('The unique ID of the aggregator item.'), // The help that appears on the UI, + // Information for displaying the iid + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + // Information for accepting a iid as an argument + 'argument' => array( + 'handler' => 'views_handler_argument_aggregator_iid', + 'name field' => 'title', // the field to display in the summary. + 'numeric' => TRUE, + ), + // Information for accepting a nid as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + // Information for sorting on a nid. + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // title + $data['aggregator_item']['title'] = array( + 'title' => t('Title'), // The item it appears as on the UI, + 'help' => t('The title of the aggregator item.'), + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_aggregator_title_link', + 'extra' => array('link'), + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + // link + $data['aggregator_item']['link'] = array( + 'title' => t('Link'), // The item it appears as on the UI, + 'help' => t('The link to the original source URL of the item.'), + 'field' => array( + 'handler' => 'views_handler_field_url', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + // author + $data['aggregator_item']['author'] = array( + 'title' => t('Author'), // The item it appears as on the UI, + 'help' => t('The author of the original imported item.'), + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_aggregator_xss', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // guid + $data['aggregator_item']['guid'] = array( + 'title' => t('GUID'), // The item it appears as on the UI, + 'help' => t('The guid of the original imported item.'), + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_xss', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // feed body + $data['aggregator_item']['description'] = array( + 'title' => t('Body'), // The item it appears as on the UI, + 'help' => t('The actual content of the imported item.'), + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_aggregator_xss', + 'click sortable' => FALSE, + ), + // Information for accepting a title as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + // item timestamp + $data['aggregator_item']['timestamp'] = array( + 'title' => t('Timestamp'), // The item it appears as on the UI, + 'help' => t('The date the original feed item was posted. (With some feeds, this will be the date it was imported.)'), + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_date', + ), + ); + + + // ---------------------------------------------------------------------- + // Aggregator feed table + + $data['aggregator_feed']['table']['group'] = t('Aggregator feed'); + + // Explain how this table joins to others. + $data['aggregator_feed']['table']['join'] = array( + 'aggregator_item' => array( + 'left_field' => 'fid', + 'field' => 'fid', + ), + ); + + // fid + $data['aggregator_feed']['fid'] = array( + 'title' => t('Feed ID'), + 'help' => t('The unique ID of the aggregator feed.'), // The help that appears on the UI, + // Information for displaying the fid + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + // Information for accepting a fid as an argument + 'argument' => array( + 'handler' => 'views_handler_argument_aggregator_fid', + 'name field' => 'title', // the field to display in the summary. + 'numeric' => TRUE, + ), + // Information for accepting a nid as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + // Information for sorting on a fid. + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // title + $data['aggregator_feed']['title'] = array( + 'title' => t('Title'), // The item it appears as on the UI, + 'help' => t('The title of the aggregator feed.'), + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_aggregator_title_link', + 'extra' => array('link'), + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + // link + $data['aggregator_feed']['link'] = array( + 'title' => t('Link'), // The item it appears as on the UI, + 'help' => t('The link to the source URL of the feed.'), + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_url', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + // feed last updated + $data['aggregator_feed']['checked'] = array( + 'title' => t('Last checked'), // The item it appears as on the UI, + 'help' => t('The date the feed was last checked for new content.'), + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_date', + ), + ); + + // feed description + $data['aggregator_feed']['description'] = array( + 'title' => t('Description'), // The item it appears as on the UI, + 'help' => t('The description of the aggregator feed.'), + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_xss', + 'click sortable' => FALSE, + ), + // Information for accepting a title as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + // feed last updated + $data['aggregator_feed']['modified'] = array( + 'title' => t('Last modified'), // The item it appears as on the UI, + 'help' => t('The date of the most recent new content onf the feed.'), + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_date', + ), + ); + + // ---------------------------------------------------------------------- + // Aggregator category feed table + + $data['aggregator_category_feed']['table']['join'] = array( + 'aggregator_item' => array( + 'left_field' => 'fid', + 'field' => 'fid', + ), + ); + + // ---------------------------------------------------------------------- + // Aggregator category table + + $data['aggregator_category']['table']['group'] = t('Aggregator category'); + + $data['aggregator_category']['table']['join'] = array( + 'aggregator_item' => array( + 'left_table' => 'aggregator_category_feed', + 'left_field' => 'cid', + 'field' => 'cid', + ), + ); + + // cid + $data['aggregator_category']['cid'] = array( + 'title' => t('Category ID'), + 'help' => t('The unique ID of the aggregator category.'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'handler' => 'views_handler_argument_aggregator_category_cid', + 'name field' => 'title', + 'numeric' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_aggregator_category_cid', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // title + $data['aggregator_category']['title'] = array( + 'title' => t('Category'), + 'help' => t('The title of the aggregator category.'), + 'field' => array( + 'handler' => 'views_handler_field_aggregator_category', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + return $data; +} + +/** + * Implementation of hook_views_handlers() to register all of the basic handlers + * views uses. + */ +function aggregator_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/modules/aggregator', + ), + 'handlers' => array( + // field handlers + 'views_handler_field_aggregator_title_link' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_aggregator_category' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_aggregator_xss' => array( + 'parent' => 'views_handler_field', + ), + + // argument handlers + 'views_handler_argument_aggregator_iid' => array( + 'parent' => 'views_handler_argument_numeric', + ), + 'views_handler_argument_aggregator_fid' => array( + 'parent' => 'views_handler_argument_numeric', + ), + 'views_handler_argument_aggregator_category_cid' => array( + 'parent' => 'views_handler_argument_numeric', + ), + + // filter handlers + 'views_handler_filter_aggregator_category_cid' => array( + 'parent' => 'views_handler_filter_in_operator', + ), + ), + ); +} + + +/** + * Implementation of hook_views_plugins + */ +function aggregator_views_plugins() { + return array( + 'module' => 'views', // This just tells our themes are elsewhere. + 'row' => array( + 'aggregator_rss' => array( + 'title' => t('Aggregator item'), + 'help' => t('Display the aggregator item using the data from the original source.'), + 'handler' => 'views_plugin_row_aggregator_rss', + 'path' => drupal_get_path('module', 'views') . '/modules/aggregator', // not necessary for most modules + 'theme' => 'views_view_row_rss', + 'base' => array('aggregator_item'), // only works with 'node' as base. + 'uses options' => TRUE, + 'type' => 'feed', + 'help topic' => 'style-aggregator-rss', + ), + ), + ); +} +/** + * @} + */ diff --git a/sites/all/modules/views/modules/aggregator/views_handler_argument_aggregator_category_cid.inc b/sites/all/modules/views/modules/aggregator/views_handler_argument_aggregator_category_cid.inc new file mode 100644 index 0000000..7955ac4 --- /dev/null +++ b/sites/all/modules/views/modules/aggregator/views_handler_argument_aggregator_category_cid.inc @@ -0,0 +1,20 @@ +value), '%d')); + + $result = db_query("SELECT c.title FROM {aggregator_category} c WHERE c.cid IN ($placeholders)", $this->value); + while ($term = db_fetch_object($result)) { + $titles[] = check_plain($term->title); + } + return $titles; + } +} diff --git a/sites/all/modules/views/modules/aggregator/views_handler_argument_aggregator_fid.inc b/sites/all/modules/views/modules/aggregator/views_handler_argument_aggregator_fid.inc new file mode 100644 index 0000000..906e5e1 --- /dev/null +++ b/sites/all/modules/views/modules/aggregator/views_handler_argument_aggregator_fid.inc @@ -0,0 +1,21 @@ +value), '%d')); + + $result = db_query("SELECT f.title FROM {aggregator_feed} f WHERE f.fid IN ($placeholders)", $this->value); + while ($term = db_fetch_object($result)) { + $titles[] = check_plain($term->title); + } + return $titles; + } +} + diff --git a/sites/all/modules/views/modules/aggregator/views_handler_argument_aggregator_iid.inc b/sites/all/modules/views/modules/aggregator/views_handler_argument_aggregator_iid.inc new file mode 100644 index 0000000..2861202 --- /dev/null +++ b/sites/all/modules/views/modules/aggregator/views_handler_argument_aggregator_iid.inc @@ -0,0 +1,20 @@ +value), '%d')); + + $result = db_query("SELECT i.title FROM {aggregator_item} i WHERE i.iid IN ($placeholders)", $this->value); + while ($term = db_fetch_object($result)) { + $titles[] = check_plain($term->title); + } + return $titles; + } +} diff --git a/sites/all/modules/views/modules/aggregator/views_handler_field_aggregator_category.inc b/sites/all/modules/views/modules/aggregator/views_handler_field_aggregator_category.inc new file mode 100644 index 0000000..b1f5a01 --- /dev/null +++ b/sites/all/modules/views/modules/aggregator/views_handler_field_aggregator_category.inc @@ -0,0 +1,52 @@ +additional_fields['cid'] = 'cid'; + } + + function option_definition() { + $options = parent::option_definition(); + $options['link_to_category'] = array('default' => FALSE); + return $options; + } + + /** + * Provide link to category option + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_category'] = array( + '#title' => t('Link this field to its aggregator category page'), + '#description' => t('This will override any other link you have set.'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['link_to_category']), + ); + } + + /** + * Render whatever the data is as a link to the category. + * + * Data should be made XSS safe prior to calling this function. + */ + function render_link($data, $values) { + if (!empty($this->options['link_to_category']) && !empty($values->{$this->aliases['cid']}) && $data !== NULL && $data !== '') { + $cid = $values->{$this->aliases['cid']}; + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = "aggregator/category/$cid"; + } + return $data; + } + + function render($values) { + return $this->render_link(check_plain($values->{$this->field_alias}), $values); + } +} diff --git a/sites/all/modules/views/modules/aggregator/views_handler_field_aggregator_title_link.inc b/sites/all/modules/views/modules/aggregator/views_handler_field_aggregator_title_link.inc new file mode 100644 index 0000000..6e76526 --- /dev/null +++ b/sites/all/modules/views/modules/aggregator/views_handler_field_aggregator_title_link.inc @@ -0,0 +1,43 @@ +additional_fields['link'] = 'link'; + } + + function option_definition() { + $options = parent::option_definition(); + + $options['display_as_link'] = array('default' => TRUE); + + return $options; + } + + /** + * Provide link to the page being visited. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['display_as_link'] = array( + '#title' => t('Display as link'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['display_as_link']), + ); + } + + function render($values) { + $value = $values->{$this->field_alias}; + $link = $values->{$this->table_alias . '_link'}; + if (!empty($this->options['display_as_link'])) { + return l(check_plain($value), $link, array('html' => TRUE)); + } + else { + return check_plain($value); + } + } +} diff --git a/sites/all/modules/views/modules/aggregator/views_handler_field_aggregator_xss.inc b/sites/all/modules/views/modules/aggregator/views_handler_field_aggregator_xss.inc new file mode 100644 index 0000000..dc32b34 --- /dev/null +++ b/sites/all/modules/views/modules/aggregator/views_handler_field_aggregator_xss.inc @@ -0,0 +1,13 @@ +{$this->field_alias}; + return aggregator_filter_xss($value); + } + +} \ No newline at end of file diff --git a/sites/all/modules/views/modules/aggregator/views_handler_filter_aggregator_category_cid.inc b/sites/all/modules/views/modules/aggregator/views_handler_filter_aggregator_category_cid.inc new file mode 100644 index 0000000..9afb90f --- /dev/null +++ b/sites/all/modules/views/modules/aggregator/views_handler_filter_aggregator_category_cid.inc @@ -0,0 +1,19 @@ +value_options)) { + return; + } + + $this->value_options = array(); + + $result = db_query('SELECT * FROM {aggregator_category} ORDER BY title'); + while ($category = db_fetch_object($result)) { + $this->value_options[$category->cid] = $category->title; + } + } +} diff --git a/sites/all/modules/views/modules/aggregator/views_plugin_row_aggregator_rss.inc b/sites/all/modules/views/modules/aggregator/views_plugin_row_aggregator_rss.inc new file mode 100644 index 0000000..30ddff6 --- /dev/null +++ b/sites/all/modules/views/modules/aggregator/views_plugin_row_aggregator_rss.inc @@ -0,0 +1,64 @@ + 'default'); + + return $options; + } + + function options_form(&$form, &$form_state) { + $form['item_length'] = array( + '#type' => 'select', + '#title' => t('Display type'), + '#options' => array( + 'fulltext' => t('Full text'), + 'teaser' => t('Title plus teaser'), + 'title' => t('Title only'), + 'default' => t('Use default RSS settings'), + ), + '#default_value' => $this->options['item_length'], + ); + } + + function render($row) { + $sql = "SELECT ai.iid, ai.fid, ai.title, ai.link, ai.author, ai.description, "; + $sql .= "ai.timestamp, ai.guid, af.title AS feed_title, ai.link AS feed_LINK "; + $sql .= "FROM {aggregator_item} ai LEFT JOIN {aggregator_feed} af ON ai.fid = af.fid "; + $sql .= "WHERE ai.iid = %d"; + + $item = db_fetch_object(db_query($sql, $row->iid)); + + $item->elements = array( + array('key' => 'pubDate', 'value' => gmdate('r', $item->timestamp)), + array( + 'key' => 'dc:creator', + 'value' => $item->author, + 'namespace' => array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/'), + ), + array( + 'key' => 'guid', + 'value' => $item->guid, + 'attributes' => array('isPermaLink' => 'false') + ), + ); + + foreach ($item->elements as $element) { + if (isset($element['namespace'])) { + $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $element['namespace']); + } + } + + return theme($this->theme_functions(), $this->view, $this->options, $item); + } +} + diff --git a/sites/all/modules/views/modules/book.views.inc b/sites/all/modules/views/modules/book.views.inc new file mode 100644 index 0000000..0f73282 --- /dev/null +++ b/sites/all/modules/views/modules/book.views.inc @@ -0,0 +1,123 @@ + array( + 'left_field' => 'nid', + 'field' => 'nid', + ), + ); + + $data['book']['bid'] = array( + 'title' => t('Top level book'), + 'help' => t('The book the node is in.'), + 'relationship' => array( + 'base' => 'node', + 'handler' => 'views_handler_relationship', + 'label' => t('Book'), + ), + // There is no argument here; if you need an argument, add the relationship + // and use the node: nid argument. + ); + + // ---------------------------------------------------------------------- + // menu_links table -- this is aliased so we can get just book relations + + // Book hierarchy and weight data are now in {menu_links}. + $data['book_menu_links']['table']['group'] = t('Book'); + $data['book_menu_links']['table']['join'] = array( + 'node' => array( + 'table' => 'menu_links', + 'left_table' => 'book', + 'left_field' => 'mlid', + 'field' => 'mlid', + ), + ); + + $data['book_menu_links']['weight'] = array( + 'title' => t('Weight'), + 'help' => t('The weight of the book page.'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + $data['book_menu_links']['depth'] = array( + 'title' => t('Depth'), + 'help' => t('The depth of the book page in the hierarchy; top level books have a depth of 1.'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'argument' => array( + 'handler' => 'views_handler_argument', + ), + ); + + $data['book_menu_links']['p'] = array( + 'title' => t('Hierarchy'), + 'help' => t('The order of pages in the book hierarchy.'), + 'sort' => array( + 'handler' => 'views_handler_sort_menu_hierarchy', + ), + ); + + // ---------------------------------------------------------------------- + // book_parent table -- this is an alias of the book table which + // represents the parent book. + + // The {book} record for the parent node. + $data['book_parent']['table']['group'] = t('Book'); + $data['book_parent']['table']['join'] = array( + 'node' => array( + 'table' => 'book', + 'left_table' => 'book_menu_links', + 'left_field' => 'plid', + 'field' => 'mlid', + ), + ); + + $data['book_parent']['nid'] = array( + 'title' => t('Parent'), + 'help' => t('The parent book node.'), + 'relationship' => array( + 'base' => 'node', + 'base field' => 'nid', + 'handler' => 'views_handler_relationship', + 'label' => t('Book parent'), + ), + ); + + return $data; +} + +/** + * @} + */ diff --git a/sites/all/modules/views/modules/book.views_convert.inc b/sites/all/modules/views/modules/book.views_convert.inc new file mode 100644 index 0000000..45cb3f1 --- /dev/null +++ b/sites/all/modules/views/modules/book.views_convert.inc @@ -0,0 +1,80 @@ +get_item($display, 'field', $id); + if ($field['handler'] == 'views_handler_field_book_parent_title') { + $item['link_to_node'] = TRUE; + } + $item['relationship'] = $view->add_item($display, 'relationship', 'book_parent', 'nid', array(), 'book_parent_nid'); + $item['table'] = 'node'; + $item['field'] = 'title'; + $view->set_item($display, 'field', $id, $item); + break; + } + break; + } + break; + case 'filter': + switch ($field['tablename']) { + case 'book': + switch ($field['field']) { + case 'parent': + $operators = array('AND' => '=', 'OR' => '=', 'NOT' => '!='); + $item = $view->get_item($display, 'filter', $id); + $item['operator'] = $operators[$field['operator']]; + $item['relationship'] = $view->add_item($display, 'relationship', 'book_parent', 'nid', array(), 'book_parent_nid'); + $item['table'] = 'node'; + $item['field'] = 'nid'; + $view->set_item($display, 'filter', $id, $item); + break; + } + break; + } + break; + case 'sort': + switch ($field['tablename']) { + case 'book': + switch ($field['field']) { + case 'weight': + $view->set_item_option($display, 'sort', $id, 'table', 'book_menu_links'); + break; + } + break; + case 'book_parent_node': + switch ($field['field']) { + case 'title': + $item = $view->get_item($display, 'sort', $id); + $item['relationship'] = $view->add_item($display, 'relationship', 'book_parent', 'nid', array(), 'book_parent_nid'); + $item['table'] = 'node'; + $item['field'] = 'title'; + $view->set_item($display, 'sort', $id, $item); + break; + } + break; + } + break; + case 'argument': + $options = $field['argoptions']; + switch ($field['type']) { + case 'book_parent': + $options['relationship'] = $view->add_item($display, 'relationship', 'book_parent', 'nid', array(), 'book_parent_nid'); + $view->add_item($display, 'argument', 'node', 'nid', $options, $field['id']); + break; + } + break; + } +} diff --git a/sites/all/modules/views/modules/comment.views.inc b/sites/all/modules/views/modules/comment.views.inc new file mode 100644 index 0000000..505cf86 --- /dev/null +++ b/sites/all/modules/views/modules/comment.views.inc @@ -0,0 +1,564 @@ + 'cid', + 'title' => t('Comment'), + 'help' => t("Comments are responses to node content."), + ); + + //joins + $data['comments']['table']['join'] = array( + //...to the node table + 'node' => array( + 'left_field' => 'nid', + 'field' => 'nid', + ), + ); + + // ---------------------------------------------------------------- + // Fields + + // subject + $data['comments']['subject'] = array( + 'title' => t('Title'), + 'help' => t('The title of the comment.'), + 'field' => array( + 'handler' => 'views_handler_field_comment', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // comment (the comment body) + $data['comments']['comment'] = array( + 'title' => t('Body'), + 'help' => t('The text of the comment.'), + 'field' => array( + 'handler' => 'views_handler_field_markup', + 'format' => 'format', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + // cid + $data['comments']['cid'] = array( + 'title' => t('ID'), + 'help' => t('The comment ID of the field'), + 'field' => array( + 'handler' => 'views_handler_field_comment', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + ), + ); + + // name (of comment author) + $data['comments']['name'] = array( + 'title' => t('Author'), + 'help' => t("The name of the comment's author. Can be rendered as a link to the author's homepage."), + 'field' => array( + 'handler' => 'views_handler_field_comment_username', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // homepage + $data['comments']['homepage'] = array( + 'title' => t("Author's website"), + 'help' => t("The website address of the comment's author. Can be rendered as a link. Will be empty if the author is a registered user."), + 'field' => array( + 'handler' => 'views_handler_field_url', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // hostname + $data['comments']['hostname'] = array( + 'title' => t('Hostname'), + 'help' => t('Hostname of user that posted the comment.'), + 'field' => array( + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // mail + $data['comments']['mail'] = array( + 'title' => t('Mail'), + 'help' => t('Email of user that posted the comment. Will be empty if the author is a registered user.'), + 'field' => array( + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // timestamp (when comment was posted) + $data['comments']['timestamp'] = array( + 'title' => t('Post date'), + 'help' => t('Date and time of when the comment was posted.'), + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + ); + + // status (approved or not) + $data['comments']['status'] = array( + 'title' => t('In moderation'), + 'help' => t('Whether or not the comment is currently in the moderation queue.'), + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'label' => t('In the moderation queue'), + 'type' => 'yes-no', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // link to view comment + $data['comments']['view_comment'] = array( + 'field' => array( + 'title' => t('View link'), + 'help' => t('Provide a simple link to view the comment.'), + 'handler' => 'views_handler_field_comment_link', + ), + ); + + // link to edit comment + $data['comments']['edit_comment'] = array( + 'field' => array( + 'title' => t('Edit link'), + 'help' => t('Provide a simple link to edit the comment.'), + 'handler' => 'views_handler_field_comment_link_edit', + ), + ); + + // link to delete comment + $data['comments']['delete_comment'] = array( + 'field' => array( + 'title' => t('Delete link'), + 'help' => t('Provide a simple link to delete the comment.'), + 'handler' => 'views_handler_field_comment_link_delete', + ), + ); + + // link to reply to comment + $data['comments']['replyto_comment'] = array( + 'field' => array( + 'title' => t('Reply-to link'), + 'help' => t('Provide a simple link to reply to the comment.'), + 'handler' => 'views_handler_field_comment_link_reply', + ), + ); + + $data['comments']['thread'] = array( + 'field' => array( + 'title' => t('Depth'), + 'help' => t('Display the depth of the comment if it is threaded.'), + 'handler' => 'views_handler_field_comment_depth', + ), + 'sort' => array( + 'title' => t('Thread'), + 'help' => t('Sort by the threaded order. This will keep child comments together with their parents.'), + 'handler' => 'views_handler_sort_comment_thread', + ), + ); + + $data['comments']['nid'] = array( + 'title' => t('Node'), + 'help' => t('The node the comment is a reply to.'), + 'relationship' => array( + 'base' => 'node', + 'base field' => 'nid', + 'handler' => 'views_handler_relationship', + 'label' => t('Node'), + ), + ); + + $data['comments']['uid'] = array( + 'title' => t('User'), + 'help' => t("The User ID of the comment's author."), + 'relationship' => array( + 'base' => 'users', + 'base field' => 'uid', + 'handler' => 'views_handler_relationship', + 'label' => t('User'), + ), + ); + + $data['comments']['pid'] = array( + 'title' => t('Parent CID'), + 'help' => t('The Comment ID of the parent comment.'), + 'field' => array( + 'handler' => 'views_handler_field', + ), + 'relationship' => array( + 'title' => t('Parent comment'), + 'help' => t('The parent comment.'), + 'base' => 'comments', + 'base field' => 'cid', + 'handler' => 'views_handler_relationship', + 'label' => t('Parent comment'), + ), + ); + + // ---------------------------------------------------------------------- + // node_comment_statistics table + + // define the group + $data['node_comment_statistics']['table']['group'] = t('Node'); + + // joins + $data['node_comment_statistics']['table']['join'] = array( + //...to the node table + 'node' => array( + 'type' => 'INNER', + 'left_field' => 'nid', + 'field' => 'nid', + ), + ); + + // last_comment_timestamp + $data['node_comment_statistics']['last_comment_timestamp'] = array( + 'title' => t('Last comment time'), + 'help' => t('Date and time of when the last comment was posted.'), + 'field' => array( + 'handler' => 'views_handler_field_last_comment_timestamp', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + ); + + // last_comment_name (author's name) + $data['node_comment_statistics']['last_comment_name'] = array( + 'title' => t("Last comment author"), + 'help' => t('The name of the author of the last posted comment.'), + 'field' => array( + 'handler' => 'views_handler_field_ncs_last_comment_name', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_ncs_last_comment_name', + ), + ); + + // comment_count + $data['node_comment_statistics']['comment_count'] = array( + 'title' => t('Comment count'), + 'help' => t('The number of comments a node has.'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument', + ), + ); + + // last_comment_timestamp + $data['node_comment_statistics']['last_updated'] = array( + 'title' => t('Updated/commented date'), + 'help' => t('The most recent of last comment posted or node updated time.'), + 'field' => array( + 'handler' => 'views_handler_field_ncs_last_updated', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_ncs_last_updated', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_ncs_last_updated', + ), + ); + + return $data; +} + +/** + * Use views_data_alter to add items to the node table that are + * relevant to comments. + */ +function comment_views_data_alter(&$data) { + // new comments + $data['node']['new_comments'] = array( + 'title' => t('New comments'), + 'help' => t('The number of new comments on the node.'), + 'field' => array( + 'handler' => 'views_handler_field_node_new_comments', + ), + ); + + $data['node']['comments_link'] = array( + 'field' => array( + 'title' => t('Add comment link'), + 'help' => t('Display the standard add comment link used on regular nodes, which will only display if the viewing user has access to add a comment.'), + 'handler' => 'views_handler_field_comment_node_link', + ), + ); + + // Comment status of the node + $data['node']['comment'] = array( + 'title' => t('Comment status'), + 'help' => t('Whether comments are enabled or disabled on the node.'), + 'field' => array( + 'handler' => 'views_handler_field_node_comment', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_node_comment', + ), + ); + + $data['node']['uid_touch'] = array( + 'title' => t('User posted or commented'), + 'help' => t('Display nodes only if a user posted the node or commented on the node.'), + 'argument' => array( + 'field' => 'uid', + 'name table' => 'users', + 'name field' => 'name', + 'handler' => 'views_handler_argument_comment_user_uid', + ), + 'filter' => array( + 'field' => 'uid', + 'name table' => 'users', + 'name field' => 'name', + 'handler' => 'views_handler_filter_comment_user_uid' + ), + ); + +} + +/** + * Implementation of hook_views_plugins + */ +function comment_views_plugins() { + return array( + 'module' => 'views', // This just tells views our themes are in Views. + 'row' => array( + 'comment' => array( + 'title' => t('Comment'), + 'help' => t('Display the comment with standard comment view.'), + 'handler' => 'views_plugin_row_comment_view', + 'path' => drupal_get_path('module', 'views') . '/modules/comment', // not necessary for most modules + 'theme' => 'views_view_row_comment', + 'base' => array('comments'), // only works with 'comment' as base. + 'uses options' => TRUE, + 'type' => 'normal', + 'help topic' => 'style-comment', + ), + 'comment_rss' => array( + 'title' => t('Comment'), + 'help' => t('Display the comment as RSS.'), + 'handler' => 'views_plugin_row_comment_rss', + 'path' => drupal_get_path('module', 'views') . '/modules/comment', // not necessary for most modules + 'theme' => 'views_view_row_rss', + 'base' => array('comments'), // only works with 'comment' as base. + 'type' => 'feed', + 'help topic' => 'style-comment-rss', + ), + ), + ); +} + +/** + * Implementation of hook_views_handlers() to register all of the basic handlers + * views uses. + */ +function comment_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/modules/comment', + ), + 'handlers' => array( + 'views_handler_field_comment' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_comment_username' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_comment_depth' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_comment_link' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_comment_link_edit' => array( + 'parent' => 'views_handler_field_comment_link', + ), + 'views_handler_field_comment_link_delete' => array( + 'parent' => 'views_handler_field_comment_link', + ), + 'views_handler_field_comment_link_reply' => array( + 'parent' => 'views_handler_field_comment_link', + ), + 'views_handler_field_comment_node_link' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_ncs_last_comment_name' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_ncs_last_updated' => array( + 'parent' => 'views_handler_field_date', + ), + 'views_handler_field_node_new_comments' => array( + 'parent' => 'views_handler_field_numeric', + ), + 'views_handler_field_node_comment' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_last_comment_timestamp' => array( + 'parent' => 'views_handler_field_date', + ), + + // sort handlers + 'views_handler_sort_comment_thread' => array( + 'parent' => 'views_handler_sort', + ), + 'views_handler_sort_ncs_last_comment_name' => array( + 'parent' => 'views_handler_sort', + ), + 'views_handler_sort_ncs_last_updated' => array( + 'parent' => 'views_handler_sort_date', + ), + + // filter handlers + 'views_handler_filter_ncs_last_updated' => array( + 'parent' => 'views_handler_filter_date', + ), + 'views_handler_filter_node_comment' => array( + 'parent' => 'views_handler_filter_in_operator', + ), + 'views_handler_filter_comment_user_uid' => array( + 'parent' => 'views_handler_filter_user_name', + ), + + // argument handlers + 'views_handler_argument_comment_user_uid' => array( + 'parent' => 'views_handler_argument', + ), + ), + ); +} + +/** + * Template helper for theme_views_view_row_comment + */ +function template_preprocess_views_view_row_comment(&$vars) { + $options = $vars['options']; + $view = &$vars['view']; + $plugin = &$view->style_plugin->row_plugin; + $comment = $plugin->comments[$vars['row']->cid]; + $node = node_load($comment->nid); + // Put the view on the node so we can retrieve it in the preprocess. + $node->view = &$view; + + $links = array(); + if (!empty($options['links'])) { + $links = module_invoke_all('link', 'comment', $comment, 0); + drupal_alter('link', $links, $node); + } + + $vars['comment'] = theme('comment_view', $comment, $node, $links); +} + +/** + * @} + */ diff --git a/sites/all/modules/views/modules/comment.views_convert.inc b/sites/all/modules/views/modules/comment.views_convert.inc new file mode 100644 index 0000000..2c981d9 --- /dev/null +++ b/sites/all/modules/views/modules/comment.views_convert.inc @@ -0,0 +1,131 @@ +add_item() won't produce + * the right results, usually needed to set field options or values. + */ +function comment_views_convert($display, $type, &$view, $field, $id = NULL) { + switch ($type) { + case 'field': + switch ($field['tablename']) { + case 'comments': + switch ($field['field']) { + case 'subject': + if ($field['options'] = 'nolink') { + $view->set_item_option($display, 'field', $id, 'link_to_comment', FALSE); + } + break; + case 'cid': + $view->set_item_option($display, 'field', $id, 'link_to_comment', FALSE); + break; + case 'timestamp': + $handlers = array( + 'views_handler_field_date_small' => 'small', + 'views_handler_field_date' => 'medium', + 'views_handler_field_date_large' => 'large', + 'views_handler_field_date_custom' => 'custom', + 'views_handler_field_since' => 'time ago', + ); + $view->set_item_option($display, 'field', $id, 'date_format', $handlers[$field['handler']]); + if (!empty($field['options'])) { + $view->set_item_option($display, 'field', $id, 'custom_date_format', $field['options']); + } + break; + case 'add': + $view->set_item_option($display, 'field', $id, 'field', 'replyto_comment'); + break; + } + break; + case 'node_comment_statistics': + switch ($field['field']) { + case 'last_comment_timestamp': + $handlers = array( + 'views_handler_field_date_small' => 'small', + 'views_handler_field_date' => 'medium', + 'views_handler_field_date_large' => 'large', + 'views_handler_field_date_custom' => 'custom', + 'views_handler_field_since' => 'time ago', + ); + $view->set_item_option($display, 'field', $id, 'date_format', $handlers[$field['handler']]); + if (!empty($field['options'])) { + $view->set_item_option($display, 'field', $id, 'custom_date_format', $field['options']); + } + break; + case 'last_changed': + $handlers = array( + 'views_handler_field_date_small' => 'small', + 'views_handler_field_date' => 'medium', + 'views_handler_field_date_large' => 'large', + 'views_handler_field_date_custom' => 'custom', + 'views_handler_field_since' => 'time ago', + ); + $item = $view->get_item($display, 'field', $id); + $item['date_format'] = $handlers[$field['handler']]; + if (!empty($field['options'])) { + $item['custom_date_format'] = $field['options']; + } + $item['field'] = 'last_updated'; + $view->set_item($display, 'field', $id, $item); + break; + } + break; + } + break; + case 'filter': + switch ($field['tablename']) { + case 'node_comment_statistics': + switch ($field['field']) { + case 'comment_count': + $view->set_item_option($display, 'filter', $id, 'operator', $field['operator']); + break; + case 'last_changed': + $field['field'] = 'last_updated'; + case 'last_comment_timestamp': + $item = $view->get_item($display, 'filter', $id); + $item['operator'] = $field['operator']; + $item['value'] = array( + 'type' => $field['value'] == 'now' ? 'offset' : 'date', + 'value' => $field['value'], + ); + if (!empty($field['options'])) { + $item['value']['value'] = intval($field['options']) .' seconds'; + } + $item['field'] = $field['field']; + $view->set_item($display, 'filter', $id, $item); + break; + } + break; + } + break; + case 'sort': + switch ($field['tablename']) { + case 'comments': + switch ($field['field']) { + case 'timestamp': + $field['options'] = $field['options'] == 'normal' ? 'second' : $field['options']; + $view->set_item_option($display, 'sort', $id, 'granularity', $field['options']); + break; + } + break; + case 'node_comment_statistics': + switch ($field['field']) { + case 'last_changed': + $view->set_item_option($display, 'sort', $id, 'field', 'last_updated'); + case 'last_comment_timestamp': + $field['options'] = $field['options'] == 'normal' ? 'second' : $field['options']; + $view->set_item_option($display, 'sort', $id, 'granularity', $field['options']); + break; + } + break; + } + break; + } +} diff --git a/sites/all/modules/views/modules/comment.views_default.inc b/sites/all/modules/views/modules/comment.views_default.inc new file mode 100644 index 0000000..83860b0 --- /dev/null +++ b/sites/all/modules/views/modules/comment.views_default.inc @@ -0,0 +1,356 @@ +name = 'comments_recent'; + $view->description = 'Contains a block and a page to list recent comments; the block will automatically link to the page, which displays the comment body as well as a link to the node.'; + $view->tag = 'default'; + $view->base_table = 'comments'; + $view->api_version = 2; + $view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */ + $handler = $view->new_display('default', 'Defaults', 'default'); + $handler->override_option('relationships', array( + 'nid' => array( + 'id' => 'nid', + 'table' => 'comments', + 'field' => 'nid', + 'label' => 'Node', + 'required' => FALSE, + ), + )); + $handler->override_option('fields', array( + 'subject' => array( + 'id' => 'subject', + 'table' => 'comments', + 'field' => 'subject', + 'label' => '', + 'link_to_comment' => 1, + 'relationship' => 'none', + ), + 'timestamp' => array( + 'id' => 'timestamp', + 'table' => 'comments', + 'field' => 'timestamp', + 'label' => '', + 'date_format' => 'time ago', + 'custom_date_format' => '', + 'relationship' => 'none', + ), + )); + $handler->override_option('sorts', array( + 'timestamp' => array( + 'id' => 'timestamp', + 'table' => 'comments', + 'field' => 'timestamp', + 'order' => 'DESC', + 'granularity' => 'second', + 'relationship' => 'none', + ), + )); + $handler->override_option('filters', array( + 'status_extra' => array( + 'id' => 'status_extra', + 'table' => 'node', + 'field' => 'status_extra', + 'operator' => '=', + 'value' => '', + 'group' => 0, + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + 'relationship' => 'nid', + ), + )); + $handler->override_option('access', array( + 'type' => 'perm', + 'role' => array(), + 'perm' => 'access comments', + )); + $handler->override_option('title', 'Recent comments'); + $handler->override_option('items_per_page', 5); + $handler->override_option('use_more', 1); + $handler->override_option('style_plugin', 'list'); + $handler->override_option('style_options', array( + 'type' => 'ul', + )); + $handler = $view->new_display('page', 'Page', 'page'); + $handler->override_option('fields', array( + 'title' => array( + 'id' => 'title', + 'table' => 'node', + 'field' => 'title', + 'label' => 'Reply to', + 'relationship' => 'nid', + 'link_to_node' => 1, + ), + 'timestamp' => array( + 'id' => 'timestamp', + 'table' => 'comments', + 'field' => 'timestamp', + 'label' => '', + 'date_format' => 'time ago', + 'custom_date_format' => '', + 'relationship' => 'none', + ), + 'subject' => array( + 'id' => 'subject', + 'table' => 'comments', + 'field' => 'subject', + 'label' => '', + 'link_to_comment' => 1, + 'relationship' => 'none', + ), + 'comment' => array( + 'id' => 'comment', + 'table' => 'comments', + 'field' => 'comment', + 'label' => '', + 'relationship' => 'none', + ), + )); + $handler->override_option('items_per_page', 25); + $handler->override_option('use_pager', '1'); + $handler->override_option('row_options', array( + 'inline' => array( + 'title' => 'title', + 'timestamp' => 'timestamp', + ), + 'separator' => ' ', + )); + $handler->override_option('path', 'comments/recent'); + $handler->override_option('menu', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler->override_option('tab_options', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler = $view->new_display('block', 'Block', 'block'); + $handler->override_option('block_description', 'Recent comments view'); + $views[$view->name] = $view; + + $view = new view; + $view->name = 'tracker'; + $view->description = 'Shows all new activity on system.'; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->api_version = 2; + $view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */ + $handler = $view->new_display('default', 'Defaults', 'default'); + $handler->override_option('fields', array( + 'type' => array( + 'id' => 'type', + 'table' => 'node', + 'field' => 'type', + 'label' => 'Type', + ), + 'title' => array( + 'id' => 'title', + 'table' => 'node', + 'field' => 'title', + 'label' => 'Title', + 'link_to_node' => TRUE, + ), + 'name' => array( + 'id' => 'name', + 'table' => 'users', + 'field' => 'name', + 'label' => 'Author', + 'link_to_user' => TRUE, + ), + 'comment_count' => array( + 'id' => 'comment_count', + 'table' => 'node_comment_statistics', + 'field' => 'comment_count', + 'label' => 'Replies', + 'set_precision' => FALSE, + 'precision' => 0, + 'decimal' => '.', + 'separator' => ',', + 'prefix' => '', + 'suffix' => '', + ), + 'last_comment_timestamp' => array( + 'id' => 'last_comment_timestamp', + 'table' => 'node_comment_statistics', + 'field' => 'last_comment_timestamp', + 'label' => 'Last Post', + 'date_format' => 'small', + 'custom_date_format' => '', + ), + 'timestamp' => array( + 'id' => 'timestamp', + 'table' => 'history_user', + 'field' => 'timestamp', + 'label' => '', + 'comments' => 1, + 'relationship' => 'none', + 'link_to_node' => 0, + 'comment' => 1, + ), + 'new_comments' => array( + 'id' => 'new_comments', + 'table' => 'node', + 'field' => 'new_comments', + 'label' => '', + 'set_precision' => FALSE, + 'precision' => 0, + 'decimal' => '.', + 'separator' => ',', + 'prefix' => '', + 'suffix' => ' new', + 'link_to_comment' => 1, + 'no_empty' => 1, + 'relationship' => 'none', + ), + )); + $handler->override_option('sorts', array( + 'last_comment_timestamp' => array( + 'id' => 'last_comment_timestamp', + 'table' => 'node_comment_statistics', + 'field' => 'last_comment_timestamp', + 'order' => 'ASC', + 'granularity' => 'second', + ), + )); + $handler->override_option('arguments', array( + 'uid_touch' => array( + 'id' => 'uid_touch', + 'table' => 'node', + 'field' => 'uid_touch', + 'default_action' => 'ignore', + 'style_plugin' => 'default_summary', + 'style_options' => array( + 'count' => TRUE, + 'override' => FALSE, + 'items_per_page' => 25, + ), + 'wildcard' => 'all', + 'wildcard_substitution' => 'All', + 'title' => 'Recent posts for %1', + 'default_argument_type' => 'fixed', + 'default_argument' => '', + 'validate_type' => 'none', + 'validate_fail' => 'not found', + 'relationship' => 'none', + 'default_argument_fixed' => '', + 'default_argument_php' => '', + 'validate_argument_node_type' => array( + 'album' => 0, + 'artist' => 0, + 'book' => 0, + 'page' => 0, + 'story' => 0, + 'track' => 0, + ), + 'validate_argument_php' => '', + ), + )); + $handler->override_option('filters', array( + 'status' => array( + 'id' => 'status', + 'table' => 'node', + 'field' => 'status', + 'operator' => '=', + 'value' => '1', + 'group' => 0, + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + 'status' => array( + 'id' => 'status', + 'table' => 'comments', + 'field' => 'status', + 'operator' => '=', + 'value' => 0, + 'group' => 0, + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + 'relationship' => 'none', + ), + ), + )); + $handler->override_option('access', array( + 'type' => 'perm', + 'role' => array(), + 'perm' => 'access content', + )); + $handler->override_option('title', 'Recent posts'); + $handler->override_option('items_per_page', '25'); + $handler->override_option('use_pager', TRUE); + $handler->override_option('style_plugin', 'table'); + $handler->override_option('style_options', array( + 'override' => 1, + 'order' => 'desc', + 'columns' => array( + 'type' => 'type', + 'title' => 'title', + 'name' => 'name', + 'comment_count' => 'comment_count', + 'last_comment_timestamp' => 'last_comment_timestamp', + 'timestamp' => 'title', + 'new_comments' => 'comment_count', + ), + 'info' => array( + 'type' => array( + 'sortable' => 1, + 'separator' => '', + ), + 'title' => array( + 'sortable' => 1, + 'separator' => ' ', + ), + 'name' => array( + 'sortable' => 1, + 'separator' => '', + ), + 'comment_count' => array( + 'sortable' => 1, + 'separator' => '
    ', + ), + 'last_comment_timestamp' => array( + 'sortable' => 1, + 'separator' => ' ', + ), + 'timestamp' => array( + 'separator' => '', + ), + 'new_comments' => array( + 'separator' => '', + ), + ), + 'default' => 'last_comment_timestamp', + )); + $handler = $view->new_display('page', 'Page', 'page'); + $handler->override_option('path', 'tracker'); + $handler->override_option('menu', array( + 'type' => 'normal', + 'title' => 'Recent posts', + 'weight' => 0, + )); + $handler->override_option('tab_options', array( + 'type' => 'none', + 'title' => NULL, + 'weight' => NULL, + )); + $views[$view->name] = $view; + + return $views; +} diff --git a/sites/all/modules/views/modules/comment/views_handler_argument_comment_user_uid.inc b/sites/all/modules/views/modules/comment/views_handler_argument_comment_user_uid.inc new file mode 100644 index 0000000..edc2980 --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_argument_comment_user_uid.inc @@ -0,0 +1,40 @@ +argument) { + $title = variable_get('anonymous', t('Anonymous')); + } + else { + $title = db_result(db_query("SELECT u.name FROM {users} u WHERE u.uid = %d", $this->argument)); + } + if (empty($title)) { + return t('No user'); + } + + return check_plain($title); + } + + function default_actions($which = NULL) { + // Disallow summary views on this argument. + if (!$which) { + $actions = parent::default_actions(); + unset($actions['summary asc']); + unset($actions['summary desc']); + return $actions; + } + + if ($which != 'summary asc' && $which != 'summary desc') { + return parent::default_actions($which); + } + } + + function query() { + $this->ensure_my_table(); + $this->query->add_where(0, "$this->table_alias.uid = %d OR ((SELECT COUNT(*) FROM {comments} c WHERE c.uid = %d AND c.nid = $this->table_alias.nid) > 0)", $this->argument, $this->argument); + } +} diff --git a/sites/all/modules/views/modules/comment/views_handler_field_comment.inc b/sites/all/modules/views/modules/comment/views_handler_field_comment.inc new file mode 100644 index 0000000..95edf0e --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_field_comment.inc @@ -0,0 +1,49 @@ +options['link_to_comment'])) { + $this->additional_fields['cid'] = 'cid'; + $this->additional_fields['nid'] = 'nid'; + } + } + + function option_definition() { + $options = parent::option_definition(); + $options['link_to_comment'] = array('default' => TRUE); + return $options; + } + + /** + * Provide link-to-comment option + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_comment'] = array( + '#title' => t('Link this field to its comment'), + '#description' => t('This will override any other link you have set.'), + '#type' => 'checkbox', + '#default_value' => $this->options['link_to_comment'], + ); + } + + function render_link($data, $values) { + if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') { + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = "node/". $values->{$this->aliases['nid']}; + $this->options['alter']['fragment'] = "comment-" . $values->{$this->aliases['cid']}; + } + + return $data; + } + + function render($values) { + return $this->render_link(check_plain($values->{$this->field_alias}), $values); + } +} diff --git a/sites/all/modules/views/modules/comment/views_handler_field_comment_depth.inc b/sites/all/modules/views/modules/comment/views_handler_field_comment_depth.inc new file mode 100644 index 0000000..e86cdda --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_field_comment_depth.inc @@ -0,0 +1,13 @@ +comments_thread)) - 1; + } +} + diff --git a/sites/all/modules/views/modules/comment/views_handler_field_comment_link.inc b/sites/all/modules/views/modules/comment/views_handler_field_comment_link.inc new file mode 100644 index 0000000..95a61e2 --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_field_comment_link.inc @@ -0,0 +1,37 @@ +additional_fields['cid'] = 'cid'; + $this->additional_fields['nid'] = 'nid'; + } + + function option_definition() { + $options = parent::option_definition(); + $options['text'] = array('default' => '', 'translatable' => TRUE); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['text'] = array( + '#type' => 'textfield', + '#title' => t('Text to display'), + '#default_value' => $this->options['text'], + ); + } + + function query() { + $this->ensure_my_table(); + $this->add_additional_fields(); + } + + function render($values) { + $text = !empty($this->options['text']) ? $this->options['text'] : t('view'); + return l($text, "node/" . $values->{$this->aliases['nid']}, array('html' => TRUE, 'fragment' => "comment-" . $values->{$this->aliases['cid']})); + } +} + diff --git a/sites/all/modules/views/modules/comment/views_handler_field_comment_link_delete.inc b/sites/all/modules/views/modules/comment/views_handler_field_comment_link_delete.inc new file mode 100644 index 0000000..e5853cf --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_field_comment_link_delete.inc @@ -0,0 +1,14 @@ +options['text']) ? $this->options['text'] : t('delete'); + return l($text, "comment/delete/" . $values->{$this->aliases['cid']}, array('query' => drupal_get_destination())); + } +} diff --git a/sites/all/modules/views/modules/comment/views_handler_field_comment_link_edit.inc b/sites/all/modules/views/modules/comment/views_handler_field_comment_link_edit.inc new file mode 100644 index 0000000..3a13b42 --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_field_comment_link_edit.inc @@ -0,0 +1,47 @@ +additional_fields['uid'] = 'uid'; + } + + function option_definition() { + $options = parent::option_definition(); + $options['destination'] = array('default' => FALSE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['destination'] = array( + '#type' => 'checkbox', + '#title' => t('Use destination'), + '#description' => t('Add destination to the link'), + '#default_value' => $this->options['destination'], + ); + } + + function render($values) { + // ensure user has access to edit this comment. + $comment = new stdClass(); + $comment->cid = $values->{$this->aliases['cid']}; + $comment->uid = $values->{$this->aliases['uid']}; + if (!comment_access('edit', $comment)) { + return; + } + + $text = !empty($this->options['text']) ? $this->options['text'] : t('edit'); + if (!$this->options['destination']) { + return l($text, "comment/edit/" . $values->{$this->aliases['cid']}); + } + else { + return l($text, "comment/edit/" . $values->{$this->aliases['cid']}, array('query' => drupal_get_destination())); + } + } +} + diff --git a/sites/all/modules/views/modules/comment/views_handler_field_comment_link_reply.inc b/sites/all/modules/views/modules/comment/views_handler_field_comment_link_reply.inc new file mode 100644 index 0000000..c7d9d7a --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_field_comment_link_reply.inc @@ -0,0 +1,15 @@ +options['text']) ? $this->options['text'] : t('reply'); + return l($text, "comment/reply/" . $values->{$this->aliases['nid']} . '/' . $values->{$this->aliases['cid']}); + } +} diff --git a/sites/all/modules/views/modules/comment/views_handler_field_comment_node_link.inc b/sites/all/modules/views/modules/comment/views_handler_field_comment_node_link.inc new file mode 100644 index 0000000..f7ee168 --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_field_comment_node_link.inc @@ -0,0 +1,59 @@ +additional_fields['nid'] = array( + 'field' => 'nid', + ); + $this->additional_fields['type'] = array( + 'field' => 'type', + ); + $this->additional_fields['comment'] = array( + 'field' => 'comment', + ); + } + + function option_definition() { + $options = parent::option_definition(); + $options['teaser'] = array('default' => 0); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['teaser'] = array( + '#type' => 'checkbox', + '#title' => t('Show teaser-style link'), + '#default_value' => $this->options['teaser'], + '#description' => t('Show the comment link in the form used on standard node teasers, rather than the full node form.'), + ); + + } + + function query() { + $this->ensure_my_table(); + $this->add_additional_fields(); + } + + function render($values) { + // Build fake $node. + $node = new stdClass(); + $node->nid = $values->{$this->aliases['nid']}; + $node->type = $values->{$this->aliases['type']}; + $node->comment = $values->{$this->aliases['comment']}; + + // Call comment.module's hook_link: comment_link($type, $node = NULL, $teaser = FALSE) + $links = comment_link('node', $node, $this->options['teaser']); + // question: should we run these through: drupal_alter('link', $links, $node); + // might this have unexpected consequences if these hooks expect items in $node that we don't have? + + return !empty($links) ? theme('links', $links, array('class' => 'links inline')) : ''; + } +} + diff --git a/sites/all/modules/views/modules/comment/views_handler_field_comment_username.inc b/sites/all/modules/views/modules/comment/views_handler_field_comment_username.inc new file mode 100644 index 0000000..7b0a92f --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_field_comment_username.inc @@ -0,0 +1,47 @@ +additional_fields['uid'] = 'uid'; + $this->additional_fields['homepage'] = 'homepage'; + } + + function option_definition() { + $options = parent::option_definition(); + $options['link_to_user'] = array('default' => TRUE); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_user'] = array( + '#title' => t("Link this field to its user or an author's homepage"), + '#type' => 'checkbox', + '#default_value' => $this->options['link_to_user'], + ); + } + + function render_link($data, $values) { + if (!empty($this->options['link_to_user'])) { + $account->uid = $values->{$this->aliases['uid']}; + $account->name = $values->{$this->field_alias}; + $account->homepage = $values->{$this->aliases['homepage']}; + + return theme('username', $account); + } + else { + return $data; + } + } + + function render($values) { + return $this->render_link(check_plain($values->{$this->field_alias}), $values); + } + +} diff --git a/sites/all/modules/views/modules/comment/views_handler_field_last_comment_timestamp.inc b/sites/all/modules/views/modules/comment/views_handler_field_last_comment_timestamp.inc new file mode 100644 index 0000000..93340a5 --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_field_last_comment_timestamp.inc @@ -0,0 +1,17 @@ +additional_fields['comment_count'] = 'comment_count'; + } + + function render($values) { + if (empty($this->options['empty_zero']) || $values->{$this->aliases['comment_count']}) { + return parent::render($values); + } + else { + return NULL; + } + } +} diff --git a/sites/all/modules/views/modules/comment/views_handler_field_ncs_last_comment_name.inc b/sites/all/modules/views/modules/comment/views_handler_field_ncs_last_comment_name.inc new file mode 100644 index 0000000..f9c892b --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_field_ncs_last_comment_name.inc @@ -0,0 +1,45 @@ +ensure_my_table(); + // join 'users' to this table via vid + $join = new views_join(); + $join->construct('users', $this->table_alias, 'last_comment_uid', 'uid'); + $join->extra = array(array('field' => 'uid', 'operator' => '!=', 'value' => '0')); + + // ncs_user alias so this can work with the sort handler, below. +// $this->user_table = $this->query->add_relationship(NULL, $join, 'users', $this->relationship); + $this->user_table = $this->query->ensure_table('ncs_users', $this->relationship, $join); + + $this->field_alias = $this->query->add_field(NULL, "COALESCE($this->user_table.name, $this->table_alias.$this->field)", $this->table_alias . '_' . $this->field); + + $this->user_field = $this->query->add_field($this->user_table, 'name'); + $this->uid = $this->query->add_field($this->table_alias, 'last_comment_uid'); + } + + function option_definition() { + $options = parent::option_definition(); + + $options['link_to_user'] = array('default' => TRUE); + + return $options; + } + + function render($values) { + if (!empty($this->options['link_to_user'])) { + $account = new stdClass(); + $account->name = $values->{$this->field_alias}; + $account->uid = $values->{$this->uid}; + return theme('username', $account); + } + else { + return check_plain($values->{$this->field_alias}); + } + } +} diff --git a/sites/all/modules/views/modules/comment/views_handler_field_ncs_last_updated.inc b/sites/all/modules/views/modules/comment/views_handler_field_ncs_last_updated.inc new file mode 100644 index 0000000..6c3e139 --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_field_ncs_last_updated.inc @@ -0,0 +1,11 @@ +ensure_my_table(); + $this->node_table = $this->query->ensure_table('node', $this->relationship); + $this->field_alias = $this->query->add_field(NULL, "GREATEST(" . $this->node_table . ".changed, " . $this->table_alias . ".last_comment_timestamp)", $this->table_alias . '_' . $this->field); + } +} diff --git a/sites/all/modules/views/modules/comment/views_handler_field_node_comment.inc b/sites/all/modules/views/modules/comment/views_handler_field_node_comment.inc new file mode 100644 index 0000000..4cf3430 --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_field_node_comment.inc @@ -0,0 +1,18 @@ +{$this->field_alias}) { + case COMMENT_NODE_DISABLED: + default: + return t('Disabled'); + case COMMENT_NODE_READ_ONLY: + return t('Read only'); + case COMMENT_NODE_READ_WRITE: + return t('Read/Write'); + } + } +} diff --git a/sites/all/modules/views/modules/comment/views_handler_field_node_new_comments.inc b/sites/all/modules/views/modules/comment/views_handler_field_node_new_comments.inc new file mode 100644 index 0000000..11daebe --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_field_node_new_comments.inc @@ -0,0 +1,100 @@ +options['hide_empty'] = TRUE; + unset($this->options['no_empty']); + } + } + + function construct() { + parent::construct(); + $this->additional_fields['nid'] = 'nid'; + $this->additional_fields['type'] = 'type'; + $this->additional_fields['comment_count'] = array('table' => 'node_comment_statistics', 'field' => 'comment_count'); + } + + function option_definition() { + $options = parent::option_definition(); + + $options['link_to_comment'] = array('default' => TRUE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_comment'] = array( + '#title' => t('Link this field to new comments'), + '#description' => t('This will override any other link you have set.'), + '#type' => 'checkbox', + '#default_value' => $this->options['link_to_comment'], + ); + } + + function query() { + $this->ensure_my_table(); + $this->add_additional_fields(); + $this->field_alias = $this->table . '_' . $this->field; + } + + function pre_render($values) { + global $user; + if (!$user->uid || empty($values)) { + return; + } + + $nids = array(); + $ids = array(); + foreach ($values as $id => $result) { + $nids[] = $result->{$this->aliases['nid']}; + $values[$id]->{$this->field_alias} = 0; + // Create a reference so we can find this record in the values again. + if (empty($ids[$result->{$this->aliases['nid']}])) { + $ids[$result->{$this->aliases['nid']}] = array(); + } + $ids[$result->{$this->aliases['nid']}][] = $id; + } + + if ($nids) { + $result = db_query("SELECT n.nid, COUNT(c.cid) as num_comments FROM {node} n INNER JOIN {comments} c ON n.nid = c.nid LEFT JOIN {history} h ON h.nid = n.nid AND h.uid = %d WHERE n.nid IN (" . implode(', ', $nids) . ") AND c.timestamp > GREATEST(COALESCE(h.timestamp, %d), %d) AND c.status = %d GROUP BY n.nid ", $user->uid, NODE_NEW_LIMIT, NODE_NEW_LIMIT, COMMENT_PUBLISHED); + + while ($node = db_fetch_object($result)) { + foreach ($ids[$node->nid] as $id) { + $values[$id]->{$this->field_alias} = $node->num_comments; + } + } + + } + } + + function render_link($data, $values) { + if (!empty($this->options['link_to_comment']) && $data !== NULL && $data !== '') { + $node = new stdClass(); + $node->nid = $values->{$this->aliases['nid']}; + $node->type = $values->{$this->aliases['type']}; + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = 'node/' . $node->nid; + $this->options['alter']['query'] = comment_new_page_count($values->{$this->aliases['comment_count']}, $values->{$this->field_alias}, $node); + $this->options['alter']['fragment'] = 'new'; + } + + return $data; + } + + function render($values) { + if (!empty($values->{$this->field_alias})) { + return $this->render_link(parent::render($values), $values); + } + else { + $this->options['alter']['make_link'] = FALSE; + } + } +} diff --git a/sites/all/modules/views/modules/comment/views_handler_filter_comment_user_uid.inc b/sites/all/modules/views/modules/comment/views_handler_filter_comment_user_uid.inc new file mode 100644 index 0000000..0330a00 --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_filter_comment_user_uid.inc @@ -0,0 +1,22 @@ +ensure_my_table(); + $replace = array_fill(0, sizeof($this->value), '%d'); + $condition = $this->operator . ' (' . implode(", ", $replace) . ')'; + + // We include the WHERE condition twice in the query, so we need two + // copies of these argument values. + $args = array_values($this->value); + $args = array_merge($args, $args); + + $this->query->add_where($this->options['group'], "$this->table_alias.uid " . $condition . " OR + ((SELECT COUNT(*) FROM {comments} c WHERE c.uid " . $condition . " AND c.nid = $this->table_alias.nid) > 0)", + $args); + } +} diff --git a/sites/all/modules/views/modules/comment/views_handler_filter_ncs_last_updated.inc b/sites/all/modules/views/modules/comment/views_handler_filter_ncs_last_updated.inc new file mode 100644 index 0000000..f931fe9 --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_filter_ncs_last_updated.inc @@ -0,0 +1,17 @@ +ensure_my_table(); + $this->node_table = $this->query->ensure_table('node', $this->relationship); + + $field = "GREATEST(" . $this->node_table . ".changed, " . $this->table_alias . ".last_comment_timestamp)"; + + $info = $this->operators(); + if (!empty($info[$this->operator]['method'])) { + $this->{$info[$this->operator]['method']}($field); + } + } +} diff --git a/sites/all/modules/views/modules/comment/views_handler_filter_node_comment.inc b/sites/all/modules/views/modules/comment/views_handler_filter_node_comment.inc new file mode 100644 index 0000000..34a70a3 --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_filter_node_comment.inc @@ -0,0 +1,14 @@ +value_options = array( + COMMENT_NODE_DISABLED => t('Disabled'), + COMMENT_NODE_READ_ONLY => t('Read only'), + COMMENT_NODE_READ_WRITE => t('Read/Write'), + ); + } +} diff --git a/sites/all/modules/views/modules/comment/views_handler_sort_comment_thread.inc b/sites/all/modules/views/modules/comment/views_handler_sort_comment_thread.inc new file mode 100644 index 0000000..e529b2a --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_sort_comment_thread.inc @@ -0,0 +1,20 @@ +ensure_my_table(); + + //Read comment_render() in comment.module for an explanation of the + //thinking behind this sort. + if ($this->options['order'] == 'DESC') { + $this->query->add_orderby($this->table_alias, $this->real_field, $this->options['order']); + } + else { + $alias = $this->table_alias . '_' . $this->real_field . 'asc'; + //@todo is this secure? + $this->query->add_orderby(NULL, "SUBSTRING({$this->table_alias}.{$this->real_field}, 1, (LENGTH({$this->table_alias}.{$this->real_field}) - 1))", $this->options['order'], $alias); + } + } +} diff --git a/sites/all/modules/views/modules/comment/views_handler_sort_ncs_last_comment_name.inc b/sites/all/modules/views/modules/comment/views_handler_sort_ncs_last_comment_name.inc new file mode 100644 index 0000000..397bb6c --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_sort_ncs_last_comment_name.inc @@ -0,0 +1,22 @@ +ensure_my_table(); + $join = new views_join(); + $join->construct('users', $this->table_alias, 'last_comment_uid', 'uid'); + + // @todo this might be safer if we had an ensure_relationship rather than guessing + // the table alias. Though if we did that we'd be guessing the relationship name + // so that doesn't matter that much. +// $this->user_table = $this->query->add_relationship(NULL, $join, 'users', $this->relationship); + $this->user_table = $this->query->ensure_table('ncs_users', $this->relationship, $join); + $this->user_field = $this->query->add_field($this->user_table, 'name'); + + // Add the field. + $this->query->add_orderby(NULL, "LOWER(COALESCE($this->user_table.name, $this->table_alias.$this->field))", $this->options['order'], $this->table_alias . '_' . $this->field); + } +} diff --git a/sites/all/modules/views/modules/comment/views_handler_sort_ncs_last_updated.inc b/sites/all/modules/views/modules/comment/views_handler_sort_ncs_last_updated.inc new file mode 100644 index 0000000..fd788ec --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_handler_sort_ncs_last_updated.inc @@ -0,0 +1,12 @@ +ensure_my_table(); + $this->node_table = $this->query->ensure_table('node', $this->relationship); + $this->field_alias = $this->query->add_orderby(NULL, "GREATEST(" . $this->node_table . ".changed, " . $this->table_alias . ".last_comment_timestamp)", $this->options['order'], $this->table_alias . '_' . $this->field); + } +} + diff --git a/sites/all/modules/views/modules/comment/views_plugin_row_comment_rss.inc b/sites/all/modules/views/modules/comment/views_plugin_row_comment_rss.inc new file mode 100644 index 0000000..58ce92a --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_plugin_row_comment_rss.inc @@ -0,0 +1,41 @@ +cid); + + $item = new stdClass(); + $item->title = $comment->subject; + $item->link = url('node/' . $comment->nid, array('absolute' => TRUE, 'fragment' => 'comment-' . $comment->cid)); + $item->description = check_markup($comment->comment, $comment->format, FALSE); + $item->elements = array( + array('key' => 'pubDate', 'value' => gmdate('r', $comment->timestamp)), + array('key' => 'dc:creator', 'value' => $comment->name), + array( + 'key' => 'guid', + 'value' => 'comment ' . $row->cid . ' at ' . $base_url, + 'attributes' => array('isPermaLink' => 'false'), + 'namespace' => array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/'), + ), + ); + + foreach ($item->elements as $element) { + if (isset($element['namespace'])) { + $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $element['namespace']); + } + } + + return theme($this->theme_functions(), $this->view, $this->options, $item); + } +} diff --git a/sites/all/modules/views/modules/comment/views_plugin_row_comment_view.inc b/sites/all/modules/views/modules/comment/views_plugin_row_comment_view.inc new file mode 100644 index 0000000..f3f58dc --- /dev/null +++ b/sites/all/modules/views/modules/comment/views_plugin_row_comment_view.inc @@ -0,0 +1,49 @@ + TRUE); + return $options; + } + + function options_form(&$form, &$form_state) { + $form['links'] = array( + '#type' => 'checkbox', + '#title' => t('Display links'), + '#default_value' => $this->options['links'], + ); + } + + function pre_render($result) { + $cids = array(); + $this->comments = array(); + + foreach ($result as $row) { + $cids[] = $row->cid; + } + + if (count($cids) > 1) { + $placeholder = " IN (" . implode(', ', array_fill(0, sizeof($cids), '%d')) . ")"; + } + else { + $placeholder = " = %d"; + } + + $cresult = db_query("SELECT c.cid as cid, c.pid, c.nid, c.subject, c.comment, c.format, c.timestamp, c.name, c.mail, c.homepage, u.uid, u.name AS registered_name, u.signature, u.picture, u.data, c.thread, c.status FROM {comments} c INNER JOIN {users} u ON c.uid = u.uid WHERE c.cid $placeholder", $cids); + while ($comment = db_fetch_object($cresult)) { + $comment = drupal_unpack($comment); + $comment->name = $comment->uid ? $comment->registered_name : $comment->name; + $comment->depth = count(explode('.', $comment->thread)) - 1; + $this->comments[$comment->cid] = $comment; + } + } +} + diff --git a/sites/all/modules/views/modules/contact.views.inc b/sites/all/modules/views/modules/contact.views.inc new file mode 100644 index 0000000..c3c69f3 --- /dev/null +++ b/sites/all/modules/views/modules/contact.views.inc @@ -0,0 +1,32 @@ + array( + 'title' => t('Link to contact page'), + 'help' => t('Provide a simple link to the user contact page.'), + 'handler' => 'views_handler_field_contact_link', + ), + ); + return $data; +} +/** + * Implementation of hook_views_handlers() to register all of the basic handlers + * views uses. + */ +function contact_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/modules/contact', + ), + 'handlers' => array( + 'views_handler_field_contact_link' => array( + 'parent' => 'views_handler_field_user_link', + ), + ), + ); +} diff --git a/sites/all/modules/views/modules/contact/views_handler_field_contact_link.inc b/sites/all/modules/views/modules/contact/views_handler_field_contact_link.inc new file mode 100644 index 0000000..ff23cd4 --- /dev/null +++ b/sites/all/modules/views/modules/contact/views_handler_field_contact_link.inc @@ -0,0 +1,71 @@ + 'link', 'translatable' => FALSE); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_display'] = array( + '#title' => t('Type of link'), + '#default_value' => $this->options['link_display'], + '#type' => 'select', + '#options' => array( + 'link' => t('Link'), + 'icon' => t('Icon'), + ), + ); + $form['text']['#title'] = t('Link label'); + $form['text']['#required'] = TRUE; + $form['text']['#default_value'] = empty($this->options['text']) ? t('contact') : $this->options['text']; + } + + // An example of field level access control. + // We must override the access method in the parent class, as that requires + // the 'access user profiles' permission, which the contact form does not. + function access() { + global $user; + + // Only registered users can view other registered user's contact page. + if (empty($user->uid)) { + return FALSE; + } + + return TRUE; + } + + function render($values) { + global $user; + $uid = $values->{$this->aliases['uid']}; + + if (empty($uid)) { + return; + } + + $account = user_load($uid); + if (empty($account)) { + return; + } + + // Check access when we pull up the user account so we know + // if the user has made the contact page available. + $menu_item = menu_get_item("user/$uid/contact"); + if (!$menu_item['access'] || empty($account->contact)) { + return; + } + + if ($this->options['link_display'] == 'icon') { + return l(theme('image', 'misc/forum-new.png'), 'user/'. $account->uid .'/contact', array('html' => TRUE, 'attributes' => array('title' => t('Contact %user', array('%user' => $account->name))))); + } + else { + return l($this->options['text'], 'user/'. $account->uid .'/contact', array('attributes' => array('title' => t('Contact %user', array('%user' => $account->name))))); + } + } +} + diff --git a/sites/all/modules/views/modules/filter.views.inc b/sites/all/modules/views/modules/filter.views.inc new file mode 100644 index 0000000..abfb2d1 --- /dev/null +++ b/sites/all/modules/views/modules/filter.views.inc @@ -0,0 +1,54 @@ + array( + 'left_field' => 'format', + 'field' => 'format', + ), + 'node' => array( + 'left_table' => 'node_revisions', + 'left_field' => 'format', + 'field' => 'format', + ), + ); + + return $data; +} + +function filter_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/modules/filter', + ), + 'handlers' => array( + // field handlers + 'views_handler_field_filter_format_name' => array( + 'parent' => 'views_handler_field', + ), + ), + ); +} + +/** + * @} + */ diff --git a/sites/all/modules/views/modules/filter/views_handler_field_filter_format_name.inc b/sites/all/modules/views/modules/filter/views_handler_field_filter_format_name.inc new file mode 100644 index 0000000..5e075e0 --- /dev/null +++ b/sites/all/modules/views/modules/filter/views_handler_field_filter_format_name.inc @@ -0,0 +1,28 @@ +additional_fields['name'] = array('table' => 'filter_formats', 'field' => 'name'); + } + + function query() { + $this->ensure_my_table(); + $this->add_additional_fields(); + } + + function render($values) { + $format_name = $values->{$this->aliases['name']}; + if (!$format_name) { + // Default or invalid input format. + // filter_formats() will reliably return the default format even if the + // current user is unprivileged. + $format = filter_formats(variable_get('filter_default_format', 1)); + return check_plain($format->name); + } + return check_plain($format_name); + } +} diff --git a/sites/all/modules/views/modules/locale.views.inc b/sites/all/modules/views/modules/locale.views.inc new file mode 100644 index 0000000..264ffa4 --- /dev/null +++ b/sites/all/modules/views/modules/locale.views.inc @@ -0,0 +1,246 @@ + 'lid', + 'title' => t('Locale source'), + 'help' => t('A source string for translation, in English or the default site language.'), + ); + + // lid + $data['locales_source']['lid'] = array( + 'title' => t('LID'), + 'help' => t('The ID of the source string.'), + 'field' => array( + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + 'numeric' => TRUE, + 'validate type' => 'lid', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // location + $data['locales_source']['location'] = array( + 'group' => t('Locale source'), + 'title' => t('Location'), + 'help' => t('A description of the location or context of the string.'), + 'field' => array( + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // Group field + $data['locales_source']['textgroup'] = array( + 'group' => t('Locale source'), + 'title' => t('Group'), + 'help' => t('The group the translation is in.'), + 'field' => array( + 'handler' => 'views_handler_field_locale_group', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_locale_group', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_locale_group', + ), + ); + + // Source field + $data['locales_source']['source'] = array( + 'group' => t('Locale source'), + 'title' => t('Source'), + 'help' => t('The full original string.'), + 'field' => array( + 'handler' => 'views_handler_field', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + // Version field + $data['locales_source']['version'] = array( + 'group' => t('Locale source'), + 'title' => t('Version'), + 'help' => t('The version of Drupal core that this string is for.'), + 'field' => array( + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_locale_version', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + $data['locales_source']['edit_lid'] = array( + 'group' => t('Locale source'), + 'field' => array( + 'title' => t('Edit link'), + 'help' => t('Provide a simple link to edit the translations.'), + 'handler' => 'views_handler_field_locale_link_edit', + ), + ); + + // ---------------------------------------------------------------------- + // Locales target table + + // Define the base group of this table. Fields that don't + // have a group defined will go into this field by default. + $data['locales_target']['table']['group'] = t('Locale target'); + + // Join information + $data['locales_target']['table']['join'] = array( + 'locales_source' => array( + 'left_field' => 'lid', + 'field' => 'lid', + ), + ); + + // Translation field + $data['locales_target']['translation'] = array( + 'group' => t('Locale target'), + 'title' => t('Translation'), + 'help' => t('The full translation string.'), + 'field' => array( + 'handler' => 'views_handler_field', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + // Language field + $data['locales_target']['language'] = array( + 'group' => t('Locale target'), + 'title' => t('Language'), + 'help' => t('The language this translation is in.'), + 'field' => array( + 'handler' => 'views_handler_field_locale_language', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_locale_language', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_locale_language', + ), + ); + + $data['locales_target']['plid'] = array( + 'group' => t('Locale target'), + 'title' => t('Singular LID'), + 'help' => t('The ID of the parent translation.'), + 'field' => array( + 'handler' => 'views_handler_field', + ), + ); + + // Plural + $data['locales_target']['plural'] = array( + 'group' => t('Locale target'), + 'title' => t('Plural'), + 'help' => t('Whether or not the translation is plural.'), + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'label' => t('Plural'), + 'type' => 'yes-no', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + return $data; +} + +/** + * Implementation of hook_views_handlers(). + */ +function locale_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/modules/locale', + ), + 'handlers' => array( + // Field handlers. + 'views_handler_field_locale_group' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_locale_language' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_locale_link_edit' => array( + 'parent' => 'views_handler_field', + ), + // Argument handlers. + 'views_handler_argument_locale_group' => array( + 'parent' => 'views_handler_argument', + ), + 'views_handler_argument_locale_language' => array( + 'parent' => 'views_handler_argument', + ), + // Filters. + 'views_handler_filter_locale_group' => array( + 'parent' => 'views_handler_filter_in_operator', + ), + 'views_handler_filter_locale_language' => array( + 'parent' => 'views_handler_filter_in_operator', + ), + 'views_handler_filter_locale_version' => array( + 'parent' => 'views_handler_filter_in_operator', + ), + ), + ); +} + +/** + * @} + */ diff --git a/sites/all/modules/views/modules/locale/views_handler_argument_locale_group.inc b/sites/all/modules/views/modules/locale/views_handler_argument_locale_group.inc new file mode 100644 index 0000000..199c7d1 --- /dev/null +++ b/sites/all/modules/views/modules/locale/views_handler_argument_locale_group.inc @@ -0,0 +1,34 @@ +locale_group($data->{$this->name_alias}); + } + + /** + * Override the behavior of title(). Get the user friendly version + * of the language. + */ + function title() { + return $this->locale_group($this->argument); + } + + function locale_group($group) { + $groups = module_invoke_all('locale', 'groups'); + // Sort the list. + asort($groups); + return isset($groups[$group]) ? $groups[$group] : t('Unknown group'); + } +} + diff --git a/sites/all/modules/views/modules/locale/views_handler_argument_locale_language.inc b/sites/all/modules/views/modules/locale/views_handler_argument_locale_language.inc new file mode 100644 index 0000000..00fafdc --- /dev/null +++ b/sites/all/modules/views/modules/locale/views_handler_argument_locale_language.inc @@ -0,0 +1,32 @@ +locale_language($data->{$this->name_alias}); + } + + /** + * Override the behavior of title(). Get the user friendly version + * of the language. + */ + function title() { + return $this->locale_language($this->argument); + } + + function locale_language($langcode) { + $languages = locale_language_list(); + return isset($languages[$langcode]) ? $languages[$langcode] : t('Unknown language'); + } +} + diff --git a/sites/all/modules/views/modules/locale/views_handler_field_locale_group.inc b/sites/all/modules/views/modules/locale/views_handler_field_locale_group.inc new file mode 100644 index 0000000..a39ac8d --- /dev/null +++ b/sites/all/modules/views/modules/locale/views_handler_field_locale_group.inc @@ -0,0 +1,13 @@ +{$this->field_alias}]) ? $groups[$values->{$this->field_alias}] : ''; + } +} diff --git a/sites/all/modules/views/modules/locale/views_handler_field_locale_language.inc b/sites/all/modules/views/modules/locale/views_handler_field_locale_language.inc new file mode 100644 index 0000000..93ab613 --- /dev/null +++ b/sites/all/modules/views/modules/locale/views_handler_field_locale_language.inc @@ -0,0 +1,28 @@ + FALSE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['native_language'] = array( + '#title' => t('Native language'), + '#type' => 'checkbox', + '#default_value' => $this->options['native_language'], + '#description' => t('If enabled, the native name of the language will be displayed'), + ); + } + + function render($values) { + $languages = locale_language_list(empty($this->$options['native_language']) ? 'name' : 'native'); + return isset($languages[$values->{$this->field_alias}]) ? $languages[$values->{$this->field_alias}] : ''; + } +} diff --git a/sites/all/modules/views/modules/locale/views_handler_field_locale_link_edit.inc b/sites/all/modules/views/modules/locale/views_handler_field_locale_link_edit.inc new file mode 100644 index 0000000..ab50844 --- /dev/null +++ b/sites/all/modules/views/modules/locale/views_handler_field_locale_link_edit.inc @@ -0,0 +1,44 @@ +additional_fields['lid'] = 'lid'; + } + + function option_definition() { + $options = parent::option_definition(); + + $options['text'] = array('default' => '', 'translatable' => TRUE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['text'] = array( + '#type' => 'textfield', + '#title' => t('Text to display'), + '#default_value' => $this->options['text'], + ); + } + + function query() { + $this->ensure_my_table(); + $this->add_additional_fields(); + } + + function render($values) { + // Ensure user has access to edit translations. + if (!user_access('translate interface')) { + return; + } + + $text = !empty($this->options['text']) ? $this->options['text'] : t('edit'); + return l($text, 'admin/build/translate/edit/' . $values->{$this->aliases['lid']}, array('query' => drupal_get_destination())); + } +} + diff --git a/sites/all/modules/views/modules/locale/views_handler_filter_locale_group.inc b/sites/all/modules/views/modules/locale/views_handler_filter_locale_group.inc new file mode 100644 index 0000000..d46426f --- /dev/null +++ b/sites/all/modules/views/modules/locale/views_handler_filter_locale_group.inc @@ -0,0 +1,17 @@ +value_options)) { + $this->value_title = t('Group'); + $groups = module_invoke_all('locale', 'groups'); + // Sort the list. + asort($groups); + $this->value_options = $groups; + } + } +} + diff --git a/sites/all/modules/views/modules/locale/views_handler_filter_locale_language.inc b/sites/all/modules/views/modules/locale/views_handler_filter_locale_language.inc new file mode 100644 index 0000000..fe49688 --- /dev/null +++ b/sites/all/modules/views/modules/locale/views_handler_filter_locale_language.inc @@ -0,0 +1,16 @@ +value_options)) { + $this->value_title = t('Language'); + $languages = array('***CURRENT_LANGUAGE***' => t("Current user's language"), '***DEFAULT_LANGUAGE***' => t("Default site language"), '***NO_LANGUAGE***' => t('No language')); + $languages = array_merge($languages, locale_language_list()); + $this->value_options = $languages; + } + } +} + diff --git a/sites/all/modules/views/modules/locale/views_handler_filter_locale_version.inc b/sites/all/modules/views/modules/locale/views_handler_filter_locale_version.inc new file mode 100644 index 0000000..5598648 --- /dev/null +++ b/sites/all/modules/views/modules/locale/views_handler_filter_locale_version.inc @@ -0,0 +1,21 @@ +value_options)) { + $this->value_title = t('Version'); + // Enable filtering by the current installed Drupal version. + $versions = array('***CURRENT_VERSION***' => t('Current installed version')); + $result = db_query('SELECT DISTINCT(version) FROM {locales_source} ORDER BY version'); + while ($row = db_fetch_array($result)) { + if (!empty($row['version'])) { + $versions[$row['version']] = $row['version']; + } + } + $this->value_options = $versions; + } + } +} diff --git a/sites/all/modules/views/modules/node.views.inc b/sites/all/modules/views/modules/node.views.inc new file mode 100644 index 0000000..9499741 --- /dev/null +++ b/sites/all/modules/views/modules/node.views.inc @@ -0,0 +1,886 @@ + 'nid', + 'title' => t('Node'), + 'help' => t("Nodes are a Drupal site's primary content."), + 'weight' => -10, + ); + + // For other base tables, explain how we join + $data['node']['table']['join'] = array( + // this explains how the 'node' table (named in the line above) + // links toward the node_revisions table. + 'node_revisions' => array( + 'handler' => 'views_join', // this is actually optional + 'left_table' => 'node_revisions', // Because this is a direct link it could be left out. + 'left_field' => 'nid', + 'field' => 'nid', + // also supported: + // 'type' => 'INNER', + // 'extra' => array(array('field' => 'fieldname', 'value' => 'value', 'operator' => '=')) + // Unfortunately, you can't specify other tables here, but you can construct + // alternative joins in the handlers that can do that. + // 'table' => 'the actual name of this table in the database', + ), + ); + + // ---------------------------------------------------------------- + // node table -- fields + + // nid + $data['node']['nid'] = array( + 'title' => t('Nid'), + 'help' => t('The node ID of the node.'), // The help that appears on the UI, + // Information for displaying the nid + 'field' => array( + 'handler' => 'views_handler_field_node', + 'click sortable' => TRUE, + ), + // Information for accepting a nid as an argument + 'argument' => array( + 'handler' => 'views_handler_argument_node_nid', + 'parent' => 'views_handler_argument_numeric', // make sure parent is included + 'name field' => 'title', // the field to display in the summary. + 'numeric' => TRUE, + 'validate type' => 'nid', + ), + // Information for accepting a nid as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + // Information for sorting on a nid. + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // title + // This definition has more items in it than it needs to as an example. + $data['node']['title'] = array( + 'title' => t('Title'), // The item it appears as on the UI, + 'help' => t('The title of the node.'), // The help that appears on the UI, + // Information for displaying a title as a field + 'field' => array( + 'field' => 'title', // the real field. This could be left out since it is the same. + 'group' => t('Node'), // The group it appears in on the UI. Could be left out. + 'handler' => 'views_handler_field_node', + 'click sortable' => TRUE, + 'link_to_node default' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + // Information for accepting a title as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // created field + $data['node']['created'] = array( + 'title' => t('Post date'), // The item it appears as on the UI, + 'help' => t('The date the node was posted.'), // The help that appears on the UI, + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + ); + + // changed field + $data['node']['changed'] = array( + 'title' => t('Updated date'), // The item it appears as on the UI, + 'help' => t('The date the node was last updated.'), // The help that appears on the UI, + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + ); + + // Node type + $data['node']['type'] = array( + 'title' => t('Type'), // The item it appears as on the UI, + 'help' => t('The type of a node (for example, "blog entry", "forum post", "story", etc).'), // The help that appears on the UI, + 'field' => array( + 'handler' => 'views_handler_field_node_type', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_node_type', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_node_type', + ), + ); + + // published status + $data['node']['status'] = array( + 'title' => t('Published'), + 'help' => t('Whether or not the node is published.'), + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + 'output formats' => array( + 'published-notpublished' => array(t('Published'), t('Not published')), + ), + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'label' => t('Published'), + 'type' => 'yes-no', + 'use equal' => TRUE, // Use status = 1 instead of status <> 0 in WHERE statment + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // published status + extra + $data['node']['status_extra'] = array( + 'title' => t('Published or admin'), + 'help' => t('Filters out unpublished nodes if the current user cannot view them.'), + 'filter' => array( + 'field' => 'status', + 'handler' => 'views_handler_filter_node_status', + 'label' => t('Published or admin'), + ), + ); + + // promote status + $data['node']['promote'] = array( + 'title' => t('Promoted to front page'), + 'help' => t('Whether or not the node is promoted to the front page.'), + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'label' => t('Promoted to front page'), + 'type' => 'yes-no', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // moderate + $data['node']['moderate'] = array( + 'title' => t('In moderation'), // The item it appears as on the UI, + 'help' => t('Whether or not the node is currently in the moderation queue.'), // The help that appears on the UI, + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'label' => t('In the moderation queue'), + 'type' => 'yes-no', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // sticky + $data['node']['sticky'] = array( + 'title' => t('Sticky'), // The item it appears as on the UI, + 'help' => t('Whether or not the node is sticky.'), // The help that appears on the UI, + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + 'output formats' => array( + 'sticky' => array(t('Sticky'), ''), + ), + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'label' => t('Sticky'), + 'type' => 'yes-no', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + 'help' => t('Whether or not the node is sticky. To list sticky nodes first, set this to descending.'), + ), + ); + + // links to operate on the node + + $data['node']['view_node'] = array( + 'field' => array( + 'title' => t('Link'), + 'help' => t('Provide a simple link to the node.'), + 'handler' => 'views_handler_field_node_link', + ), + ); + + $data['node']['edit_node'] = array( + 'field' => array( + 'title' => t('Edit link'), + 'help' => t('Provide a simple link to edit the node.'), + 'handler' => 'views_handler_field_node_link_edit', + ), + ); + + $data['node']['delete_node'] = array( + 'field' => array( + 'title' => t('Delete link'), + 'help' => t('Provide a simple link to delete the node.'), + 'handler' => 'views_handler_field_node_link_delete', + ), + ); + + $data['node']['path'] = array( + 'field' => array( + 'title' => t('Path'), + 'help' => t('The aliased path to this node.'), + 'handler' => 'views_handler_field_node_path', + ), + ); + + + // Bogus fields for aliasing purposes. + + $data['node']['created_fulldate'] = array( + 'title' => t('Created date'), + 'help' => t('In the form of CCYYMMDD.'), + 'argument' => array( + 'field' => 'created', + 'handler' => 'views_handler_argument_node_created_fulldate', + ), + ); + + $data['node']['created_year_month'] = array( + 'title' => t('Created year + month'), + 'help' => t('In the form of YYYYMM.'), + 'argument' => array( + 'field' => 'created', + 'handler' => 'views_handler_argument_node_created_year_month', + ), + ); + + $data['node']['created_year'] = array( + 'title' => t('Created year'), + 'help' => t('In the form of YYYY.'), + 'argument' => array( + 'field' => 'created', + 'handler' => 'views_handler_argument_node_created_year', + ), + ); + + $data['node']['created_month'] = array( + 'title' => t('Created month'), + 'help' => t('In the form of MM (01 - 12).'), + 'argument' => array( + 'field' => 'created', + 'handler' => 'views_handler_argument_node_created_month', + ), + ); + + $data['node']['created_day'] = array( + 'title' => t('Created day'), + 'help' => t('In the form of DD (01 - 31).'), + 'argument' => array( + 'field' => 'created', + 'handler' => 'views_handler_argument_node_created_day', + ), + ); + + $data['node']['created_week'] = array( + 'title' => t('Created week'), + 'help' => t('In the form of WW (01 - 53).'), + 'argument' => array( + 'field' => 'created', + 'handler' => 'views_handler_argument_node_created_week', + ), + ); + + $data['node']['changed_fulldate'] = array( + 'title' => t('Updated date'), + 'help' => t('In the form of CCYYMMDD.'), + 'argument' => array( + 'field' => 'changed', + 'handler' => 'views_handler_argument_node_created_fulldate', + ), + ); + + $data['node']['changed_year_month'] = array( + 'title' => t('Updated year + month'), + 'help' => t('In the form of YYYYMM.'), + 'argument' => array( + 'field' => 'changed', + 'handler' => 'views_handler_argument_node_created_year_month', + ), + ); + + $data['node']['changed_year'] = array( + 'title' => t('Updated year'), + 'help' => t('In the form of YYYY.'), + 'argument' => array( + 'field' => 'changed', + 'handler' => 'views_handler_argument_node_created_year', + ), + ); + + $data['node']['changed_month'] = array( + 'title' => t('Updated month'), + 'help' => t('In the form of MM (01 - 12).'), + 'argument' => array( + 'field' => 'changed', + 'handler' => 'views_handler_argument_node_created_month', + ), + ); + + $data['node']['changed_day'] = array( + 'title' => t('Updated day'), + 'help' => t('In the form of DD (01 - 31).'), + 'argument' => array( + 'field' => 'changed', + 'handler' => 'views_handler_argument_node_created_day', + ), + ); + + $data['node']['changed_week'] = array( + 'title' => t('Updated week'), + 'help' => t('In the form of WW (01 - 53).'), + 'argument' => array( + 'field' => 'changed', + 'handler' => 'views_handler_argument_node_created_week', + ), + ); + + // ---------------------------------------------------------------------- + // Node revisions table + + // Define the base group of this table. Fields that don't + // have a group defined will go into this field by default. + $data['node_revisions']['table']['group'] = t('Node revision'); + + // Advertise this table as a possible base table + $data['node_revisions']['table']['base'] = array( + 'field' => 'vid', + 'title' => t('Node revision'), + 'help' => t('Node revisions are a history of changes to nodes.'), + ); + + // For other base tables, explain how we join + $data['node_revisions']['table']['join'] = array( + // Directly links to node table. + 'node' => array( + 'left_field' => 'vid', + 'field' => 'vid', + ), + ); + + // uid field + $data['node_revisions']['uid'] = array( + 'title' => t('User'), + 'help' => t('Relate a node revision to the user who created the revision.'), + 'relationship' => array( + 'handler' => 'views_handler_relationship', + 'base' => 'users', + 'base field' => 'uid', + 'label' => t('user'), + ), + ); + + // Body field + $data['node_revisions']['body'] = array( + 'group' => t('Node'), + 'title' => t('Body'), // The item it appears as on the UI, + 'help' => t('The actual, full data in the body field; this may not be valid data on all node types.'), // The help that appears on the UI, + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_markup', + 'format' => 'format', // The name of the format field + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + // Teaser field + $data['node_revisions']['teaser'] = array( + 'group' => t('Node'), + 'title' => t('Teaser'), // The item it appears as on the UI, + 'help' => t('The stored teaser field. This may not be valid or useful data on all node types.'), // The help that appears on the UI, + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_markup', + 'format' => 'format', // The name of the format field + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + // nid + $data['node_revisions']['vid'] = array( + 'title' => t('Vid'), + 'help' => t('The revision ID of the node revision.'), // The help that appears on the UI, + // Information for displaying the nid + 'field' => array( +// 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + // Information for accepting a nid as an argument + 'argument' => array( + 'handler' => 'views_handler_argument_node_vid', + 'parent' => 'views_handler_argument_numeric', // make sure parent is included + 'click sortable' => TRUE, + 'numeric' => TRUE, + ), + // Information for accepting a nid as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + // Information for sorting on a nid. + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'relationship' => array( + 'handler' => 'views_handler_relationship', + 'base' => 'node', + 'base field' => 'nid', + 'title' => t('Node'), + 'label' => t('Get the actual node from a node revision.'), + ), + ); + + // title + $data['node_revisions']['title'] = array( + 'title' => t('Title'), // The item it appears as on the UI, + 'help' => t('The title of the node.'), // The help that appears on the UI, + // Information for displaying a title as a field + 'field' => array( + 'field' => 'title', // the real field + 'handler' => 'views_handler_field_node_revision', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // log field + $data['node_revisions']['log'] = array( + 'title' => t('Log message'), // The item it appears as on the UI, + 'help' => t('The log message entered when the revision was created.'), // The help that appears on the UI, + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_xss', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + // revision timestamp + // changed field + $data['node_revisions']['timestamp'] = array( + 'title' => t('Updated date'), // The item it appears as on the UI, + 'help' => t('The date the node was last updated.'), // The help that appears on the UI, + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + ); + + // input format id + $data['node_revisions']['format'] = array( + 'title' => t('Input format id'), // The item it appears as on the UI, + 'help' => t('The numeric input format of the node revision. !default means the default input format.', array('!default' => FILTER_FORMAT_DEFAULT)), // The help that appears on the UI, + // Information for displaying an input format as a field + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + // Information for sorting on input format + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + // Information for accepting input format as a filter + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + ); + + // input format name + // A (numeric) format of 0 means the default; Drupal also applies the default + // if the format specifed for a node revision has been deleted. + // This complexity makes sorting and filtering by format name tricky, + // hence these are not yet supported. + $data['node_revisions']['format_name'] = array( + 'title' => t('Input format'), // The item it appears as on the UI, + 'help' => t('The name of the input format of the node revision.'), // The help that appears on the UI, + // Information for displaying an input format as a field + 'field' => array( + 'handler' => 'views_handler_field_filter_format_name', + ), + ); + + $data['node_revisions']['revert_revision'] = array( + 'field' => array( + 'title' => t('Revert link'), + 'help' => t('Provide a simple link to revert to the revision.'), + 'handler' => 'views_handler_field_node_revision_link_revert', + ), + ); + + $data['node_revisions']['delete_revision'] = array( + 'field' => array( + 'title' => t('Delete link'), + 'help' => t('Provide a simple link to delete the node revision.'), + 'handler' => 'views_handler_field_node_revision_link_delete', + ), + ); + + // ---------------------------------------------------------------------- + // Node access table + + // Define the base group of this table. Fields that don't + // have a group defined will go into this field by default. + $data['node_access']['table']['group'] = t('Node access'); + + // For other base tables, explain how we join + $data['node_access']['table']['join'] = array( + // Directly links to node table. + 'node' => array( + 'left_field' => 'nid', + 'field' => 'nid', + ), + ); + // nid field + $data['node_access']['nid'] = array( + 'title' => t('Access'), + 'help' => t('Filter by access.'), + 'filter' => array( + 'handler' => 'views_handler_filter_node_access', + 'help' => t('Filter for nodes by view access. Not necessary if you are using node as your base table.'), + ), + ); + + // ---------------------------------------------------------------------- + // History table + + // We're actually defining a specific instance of the table, so let's + // alias it so that we can later add the real table for other purposes if we + // need it. + $data['history_user']['table']['group'] = t('Node'); + + // Explain how this table joins to others. + $data['history_user']['table']['join'] = array( + // Directly links to node table. + 'node' => array( + 'table' => 'history', + 'left_field' => 'nid', + 'field' => 'nid', + 'extra' => array( + array('field' => 'uid', 'value' => '***CURRENT_USER***', 'numeric' => TRUE), + ), + ), + ); + + $data['history_user']['timestamp'] = array( + 'title' => t('Has new content'), + 'field' => array( + 'handler' => 'views_handler_field_history_user_timestamp', + 'help' => t('Show a marker if the node has new or updated content.'), + ), + 'filter' => array( + 'help' => t('Show only nodes that have new content.'), + 'handler' => 'views_handler_filter_history_user_timestamp', + ), + ); + return $data; +} + +/** + * Implementation of hook_views_handlers() to register all of the basic handlers + * views uses. + */ +function node_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/modules/node', + ), + 'handlers' => array( + // field handlers + 'views_handler_field_node' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_node_type' => array( + 'parent' => 'views_handler_field_node', + ), + 'views_handler_field_node_link' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_node_path' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_node_link_edit' => array( + 'parent' => 'views_handler_field_node_link', + ), + 'views_handler_field_node_link_delete' => array( + 'parent' => 'views_handler_field_node_link', + ), + 'views_handler_field_node_revision_link_revert' => array( + 'parent' => 'views_handler_field_node_link', + ), + 'views_handler_field_node_revision_link_delete' => array( + 'parent' => 'views_handler_field_node_link', + ), + 'views_handler_field_history_user_timestamp' => array( + 'parent' => 'views_handler_field_node', + ), + 'views_handler_field_node_revision' => array( + 'parent' => 'views_handler_field_node', + ), + // argument handlers + 'views_handler_argument_node_type' => array( + 'parent' => 'views_handler_argument', + ), + 'views_handler_argument_node_nid' => array( + 'parent' => 'views_handler_argument_numeric', + ), + 'views_handler_argument_node_vid' => array( + 'parent' => 'views_handler_argument_numeric', + ), + 'views_handler_argument_node_created_fulldate' => array( + // put several handlers in the same file + 'file' => 'views_handler_argument_dates_various.inc', + 'parent' => 'views_handler_argument_date', + ), + 'views_handler_argument_node_created_year' => array( + // put several handlers in the same file + 'file' => 'views_handler_argument_dates_various.inc', + 'parent' => 'views_handler_argument_date', + ), + 'views_handler_argument_node_created_year_month' => array( + // put several handlers in the same file + 'file' => 'views_handler_argument_dates_various.inc', + 'parent' => 'views_handler_argument_date', + ), + 'views_handler_argument_node_created_month' => array( + // put several handlers in the same file + 'file' => 'views_handler_argument_dates_various.inc', + 'parent' => 'views_handler_argument_date', + ), + 'views_handler_argument_node_created_day' => array( + // put several handlers in the same file + 'file' => 'views_handler_argument_dates_various.inc', + 'parent' => 'views_handler_argument_date', + ), + 'views_handler_argument_node_created_week' => array( + // put several handlers in the same file + 'file' => 'views_handler_argument_dates_various.inc', + 'parent' => 'views_handler_argument_date', + ), + + // filters + 'views_handler_filter_node_type' => array( + 'parent' => 'views_handler_filter_in_operator', + ), + 'views_handler_filter_history_user_timestamp' => array( + 'parent' => 'views_handler_filter', + ), + 'views_handler_filter_node_status' => array( + 'parent' => 'views_handler_filter', + ), + 'views_handler_filter_node_access' => array( + 'parent' => 'views_handler_filter', + ), + ), + ); +} + +/** + * Implementation of hook_views_plugins + */ +function node_views_plugins() { + return array( + 'module' => 'views', // This just tells our themes are elsewhere. + 'row' => array( + 'node' => array( + 'title' => t('Node'), + 'help' => t('Display the node with standard node view.'), + 'handler' => 'views_plugin_row_node_view', + 'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules + 'theme' => 'views_view_row_node', + 'base' => array('node'), // only works with 'node' as base. + 'uses options' => TRUE, + 'type' => 'normal', + 'help topic' => 'style-node', + ), + 'node_rss' => array( + 'title' => t('Node'), + 'help' => t('Display the node with standard node view.'), + 'handler' => 'views_plugin_row_node_rss', + 'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules + 'theme' => 'views_view_row_rss', + 'base' => array('node'), // only works with 'node' as base. + 'uses options' => TRUE, + 'type' => 'feed', + 'help topic' => 'style-node-rss', + ), + ), + 'argument validator' => array( + 'node' => array( + 'title' => t('Node'), + 'handler' => 'views_plugin_argument_validate_node', + 'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules + ), + ), + 'argument default' => array( + 'node' => array( + 'title' => t('Node ID from URL'), + 'handler' => 'views_plugin_argument_default_node', + 'path' => drupal_get_path('module', 'views') . '/modules/node', // not necessary for most modules + 'parent' => 'fixed', // so that the parent class is included + ), + ), + ); +} + +/** + * Template helper for theme_views_view_row_node + */ +function template_preprocess_views_view_row_node(&$vars) { + $options = $vars['options']; + + // Make sure the variables are defined. + $vars['node'] = ''; + $vars['comments'] = ''; + + if (!empty($vars['row']->{$vars['field_alias']})) { + $nid = $vars['row']->{$vars['field_alias']}; + } + if (!is_numeric($nid)) { + return; + } + + $node = node_load($nid); + + if (empty($node)) { + return; + } + + $node->view = $vars['view']; + $node->build_mode = ($options['build_mode'] == 'teaser' || $options['build_mode'] == 'full') ? NODE_BUILD_NORMAL : $options['build_mode']; + $vars['node'] = node_view($node, $options['build_mode'] == 'teaser', FALSE, $options['links']); + + if (!empty($options['comments']) && function_exists('comment_render')) { + $vars['comments'] = comment_render($node); + } +} + +/** + * Implementation of hook_views_query_substitutions(). + */ +function node_views_query_substitutions() { + return array( + '***ADMINISTER_NODES***' => intval(user_access('administer nodes')), + ); +} + +/** + * Implementation of hook_views_analyze(). + */ +function node_views_analyze($view) { + $ret = array(); + // Check for something other than the default display: + if ($view->base_table == 'node') { + foreach ($view->display as $id => $display) { + if (!$display->handler->is_defaulted('access') || !$display->handler->is_defaulted('filters')) { + // check for no access control + $access = $display->handler->get_option('access'); + if (empty($access['type']) || $access['type'] == 'none') { + $result = db_query("SELECT r.name, p.perm FROM {role} r INNER JOIN {permission} p ON p.rid = r.rid WHERE r.name IN ('anonymous user', 'authenticated user')"); + while ($role = db_fetch_object($result)) { + $role->perm = explode(', ', $role->perm); + $role->safe = in_array('access content', $role->perm); + $roles[$role->name] = $role; + } + if (!($roles['anonymous user']->safe && $roles['authenticated user']->safe)) { + $ret[] = views_ui_analysis(t('Some roles lack permission to access content, but display %display has no access control.', array('%display' => $display->display_title)), 'warning'); + } + $filters = $display->handler->get_option('filters'); + foreach ($filters as $filter) { + if ($filter['table'] == 'node' && ($filter['field'] == 'status' || $filter['field'] == 'status_extra')) { + continue 2; + } + } + $ret[] = views_ui_analysis(t('Display %display has no access control but does not contain a filter for published nodes.', array('%display' => $display->display_title)), 'warning'); + } + } + } + } + foreach ($view->display as $id => $display) { + if ($display->display_plugin == 'page') { + if ($display->handler->get_option('path') == 'node/%') { + $ret[] = views_ui_analysis(t('Display %display has set node/% as path. This will not produce what you want. If you want to have multiple versions of the node view, use panels.', array('%display' => $display->display_title)), 'warning'); + } + } + } + + return $ret; +} + +/** + * @} + */ diff --git a/sites/all/modules/views/modules/node.views_convert.inc b/sites/all/modules/views/modules/node.views_convert.inc new file mode 100644 index 0000000..71406a7 --- /dev/null +++ b/sites/all/modules/views/modules/node.views_convert.inc @@ -0,0 +1,181 @@ +add_item() won't produce + * the right results, usually needed to set field options or values. + */ +function node_views_convert($display, $type, &$view, $field, $id = NULL) { + switch ($type) { + case 'field': + switch ($field['tablename']) { + case 'node': + switch ($field['field']) { + case 'title': + if ($field['options'] != 'no_link') { + $view->set_item_option($display, 'field', $id, 'link_to_node', TRUE); + } + break; + case 'created': + case 'changed': + $handlers = array( + 'views_handler_field_date_small' => 'small', + 'views_handler_field_date' => 'medium', + 'views_handler_field_date_large' => 'large', + 'views_handler_field_date_custom' => 'custom', + 'views_handler_field_since' => 'time ago', + ); + $view->set_item_option($display, 'field', $id, 'date_format', $handlers[$field['handler']]); + if (!empty($field['options'])) { + $view->set_item_option($display, 'field', $id, 'custom_date_format', $field['options']); + } + break; + case 'body': + $field['field'] = $field['handler'] == 'views_handler_field_teaser' ? 'teaser' : $field['field']; + $view->set_item_option($display, 'field', $id, 'field', $field['field']); + $view->set_item_option($display, 'field', $id, 'table', 'node_revisions'); + break; + case 'link': + case 'edit': + case 'delete': + case 'view': + $field['field'] = $field['field'] == 'link' ? 'view_node' : "$field[field]_node"; + $view->set_item_option($display, 'field', $id, 'field', $field['field']); + if (!empty($field['options'])) { + $view->set_item_option($display, 'field', $id, 'text', $field['options']); + } + break; + } + break; + } + break; + case 'filter': + switch ($field['tablename']) { + case 'node': + switch ($field['field']) { + case 'type': + $operators = array('OR' => 'in', 'NOR' => 'not in'); + $view->set_item_option($display, 'filter', $id, 'operator', $operators[$field['operator']]); + break; + case 'anon': + $item = $view->get_item($display, 'filter', $id); + $item['value'] = array(0); + $item['table'] = 'users'; + $item['field'] = 'uid'; + $view->set_item($display, 'filter', $id, $item); + break; + case 'currentuid': + $operators = array('=' => TRUE, '!=' => FALSE); + $item = $view->get_item($display, 'filter', $id); + $item['value'] = $operators[$field['operator']]; + $item['table'] = 'users'; + $item['field'] = 'uid_current'; + $view->set_item($display, 'filter', $id, $item); + break; + case 'currentuidtouched': + $view->set_item_option($display, 'filter', $id, 'value', '='); + $view->set_item_option($display, 'filter', $id, 'field', 'uid_touch'); + break; + case 'distinct': + $view->display_handler->set_option('distinct', $field['operator'] == '=' && $field['value'] == 'distinct'); + $view->set_item($display, 'filter', $id, NULL); + break; + case 'title': + $item = $view->get_item($display, 'filter', $id); + $item['operator'] = $field['operator']; + $item['case'] = FALSE; + $view->set_item($display, 'filter', $id, $item); + break; + case 'created': + case 'changed': + $item = $view->get_item($display, 'filter', $id); + $item['operator'] = $field['operator']; + $item['value'] = array( + 'type' => $field['value'] == 'now' ? 'offset' : 'date', + 'value' => $field['value'], + ); + if (!empty($field['options'])) { + $item['value']['value'] = intval($field['options']) .' seconds'; + } + $view->set_item($display, 'filter', $id, $item); + break; + case 'body': + $item = $view->get_item($display, 'filter', $id); + $item['operator'] = $field['operator']; + $item['case'] = FALSE; + $item['table'] = 'node_revisions'; + $view->set_item($display, 'filter', $id, $item); + break; + } + break; + case 'history': + switch ($field['field']) { + case 'timestamp': + $view->set_item_option($display, 'filter', $id, 'table', 'history_user'); + break; + } + break; + } + break; + case 'sort': + switch ($field['tablename']) { + case 'node': + switch ($field['field']) { + case 'created': + case 'changed': + $field['options'] = $field['options'] == 'normal' ? 'second' : $field['options']; + $view->set_item_option($display, 'sort', $id, 'granularity', $field['options']); + break; + case 'random': + $view->set_item_option($display, 'sort', $id, 'table', 'views'); + break; + } + break; + } + break; + case 'argument': + $options = $field['argoptions']; + switch ($field['type']) { + case 'nodetype': + $view->add_item($display, 'argument', 'node', 'type', $options, $field['id']); + break; + case 'nodeletter': + if (!empty($field['options'])) { + $options['glossary'] = TRUE; + $options['limit'] = $field['options']; + } + $options['case'] = 'upper'; + $view->add_item($display, 'argument', 'node', 'title', $options, $field['id']); + break; + case 'year': + $view->add_item($display, 'argument', 'node', 'created_year', $options, $field['id']); + break; + case 'month': + $view->add_item($display, 'argument', 'node', 'created_month', $options, $field['id']); + break; + case 'week': + $view->add_item($display, 'argument', 'node', 'created_week', $options, $field['id']); + break; + case 'monthyear': + $view->add_item($display, 'argument', 'node', 'created_year_month', $options, $field['id']); + break; + case 'fulldate': + $view->add_item($display, 'argument', 'node', 'created_fulldate', $options, $field['id']); + break; + case 'nid': + if (!empty($field['options'])) { + $options['not'] = TRUE; + } + $view->add_item($display, 'argument', 'node', 'nid', $options, $field['id']); + break; + } + break; + } +} diff --git a/sites/all/modules/views/modules/node.views_default.inc b/sites/all/modules/views/modules/node.views_default.inc new file mode 100644 index 0000000..89cf1eb --- /dev/null +++ b/sites/all/modules/views/modules/node.views_default.inc @@ -0,0 +1,377 @@ +name = 'frontpage'; + $view->description = 'Emulates the default Drupal front page; you may set the default home page path to this view to make it your front page.'; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->api_version = 2; + $view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */ + $handler = $view->new_display('default', 'Defaults', 'default'); + $handler->override_option('sorts', array( + 'sticky' => array( + 'id' => 'sticky', + 'table' => 'node', + 'field' => 'sticky', + 'order' => 'DESC', + ), + 'created' => array( + 'id' => 'created', + 'table' => 'node', + 'field' => 'created', + 'order' => 'DESC', + 'relationship' => 'none', + 'granularity' => 'second', + ), + )); + $handler->override_option('filters', array( + 'promote' => array( + 'id' => 'promote', + 'table' => 'node', + 'field' => 'promote', + 'operator' => '=', + 'value' => '1', + 'group' => 0, + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + ), + 'status' => array( + 'id' => 'status', + 'table' => 'node', + 'field' => 'status', + 'operator' => '=', + 'value' => '1', + 'group' => 0, + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + ), + )); + $handler->override_option('access', array( + 'type' => 'perm', + 'role' => array(), + 'perm' => 'access content', + )); + $handler->override_option('header_format', '1'); + $handler->override_option('footer_format', '1'); + $handler->override_option('empty_format', '1'); + $handler->override_option('use_pager', '1'); + $handler->override_option('row_plugin', 'node'); + $handler->override_option('row_options', array( + 'teaser' => 1, + 'links' => 1, + )); + $handler = $view->new_display('page', 'Page', 'page'); + $handler->override_option('path', 'frontpage'); + $handler->override_option('menu', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler->override_option('tab_options', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler = $view->new_display('feed', 'Feed', 'feed'); + $handler->override_option('sitename_title', '1'); + $handler->override_option('title', 'Front page feed'); + $handler->override_option('style_options', array( + 'mission_description' => 1, + 'description' => '', + )); + $handler->override_option('row_plugin', 'node_rss'); + $handler->override_option('row_options', array( + 'item_length' => 'default', + )); + $handler->override_option('path', 'rss.xml'); + $handler->override_option('menu', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler->override_option('tab_options', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler->override_option('displays', array( + 'default' => 'default', + 'page' => 'page', + )); + $views[$view->name] = $view; + + $view = new view; + $view->name = 'glossary'; + $view->description = 'A list of all content, by letter.'; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->api_version = 2; + $view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */ + $handler = $view->new_display('default', 'Defaults', 'default'); + $handler->override_option('fields', array( + 'title' => array( + 'label' => 'Title', + 'link_to_node' => 1, + 'exclude' => 0, + 'id' => 'title', + 'table' => 'node', + 'field' => 'title', + 'relationship' => 'none', + ), + 'name' => array( + 'label' => 'Author', + 'link_to_user' => 1, + 'exclude' => 0, + 'id' => 'name', + 'table' => 'users', + 'field' => 'name', + 'relationship' => 'none', + ), + 'changed' => array( + 'label' => 'Last update', + 'date_format' => 'large', + 'custom_date_format' => '', + 'exclude' => 0, + 'id' => 'changed', + 'table' => 'node', + 'field' => 'changed', + 'relationship' => 'none', + ), + )); + $handler->override_option('arguments', array( + 'title' => array( + 'default_action' => 'default', + 'style_plugin' => 'default_summary', + 'style_options' => array(), + 'wildcard' => 'all', + 'wildcard_substitution' => 'All', + 'title' => '', + 'default_argument_type' => 'fixed', + 'default_argument' => '', + 'validate_type' => 'none', + 'validate_fail' => 'not found', + 'glossary' => 1, + 'limit' => '1', + 'case' => 'upper', + 'path_case' => 'lower', + 'transform_dash' => 0, + 'id' => 'title', + 'table' => 'node', + 'field' => 'title', + 'relationship' => 'none', + 'default_argument_user' => 0, + 'default_argument_fixed' => 'a', + 'default_argument_php' => '', + 'validate_argument_vocabulary' => array(), + 'validate_argument_type' => 'tid', + 'validate_argument_php' => '', + ), + )); + $handler->override_option('access', array( + 'type' => 'perm', + 'role' => array(), + 'perm' => 'access content', + )); + $handler->override_option('use_ajax', '1'); + $handler->override_option('items_per_page', 36); + $handler->override_option('use_pager', '1'); + $handler->override_option('style_plugin', 'table'); + $handler->override_option('style_options', array( + 'grouping' => '', + 'override' => 1, + 'sticky' => 0, + 'order' => 'asc', + 'columns' => array( + 'title' => 'title', + 'name' => 'name', + 'changed' => 'changed', + ), + 'info' => array( + 'title' => array( + 'sortable' => 1, + 'separator' => '', + ), + 'name' => array( + 'sortable' => 1, + 'separator' => '', + ), + 'changed' => array( + 'sortable' => 1, + 'separator' => '', + ), + ), + 'default' => 'title', + )); + $handler = $view->new_display('page', 'Page', 'page'); + $handler->override_option('path', 'glossary'); + $handler->override_option('menu', array( + 'type' => 'normal', + 'title' => 'Glossary', + 'weight' => '0', + )); + $handler->override_option('tab_options', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler = $view->new_display('attachment', 'Attachment', 'attachment'); + $handler->override_option('arguments', array( + 'title' => array( + 'default_action' => 'summary asc', + 'style_plugin' => 'unformatted_summary', + 'style_options' => array( + 'count' => 1, + 'override' => 0, + 'items_per_page' => '25', + 'inline' => 1, + 'separator' => ' | ', + ), + 'wildcard' => 'all', + 'wildcard_substitution' => 'All', + 'title' => '', + 'default_argument_type' => 'fixed', + 'default_argument' => '', + 'validate_type' => 'none', + 'validate_fail' => 'not found', + 'glossary' => 1, + 'limit' => '1', + 'case' => 'upper', + 'path_case' => 'lower', + 'transform_dash' => 0, + 'id' => 'title', + 'table' => 'node', + 'field' => 'title', + 'relationship' => 'none', + 'default_argument_user' => 0, + 'default_argument_fixed' => 'a', + 'validate_argument_vocabulary' => array(), + 'validate_argument_php' => '', + ), + )); + $handler->override_option('inherit_arguments', 0); + $handler->override_option('displays', array( + 'default' => 'default', + 'page' => 'page', + )); + $views[$view->name] = $view; + + $view = new view; + $view->name = 'archive'; + $view->description = 'Display a list of months that link to content for that month.'; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->api_version = 2; + $view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */ + $handler = $view->new_display('default', 'Defaults', 'default'); + $handler->override_option('title', 'Monthly archive'); + $handler->override_option('sorts', array( + 'created' => array( + 'id' => 'created', + 'table' => 'node', + 'field' => 'created', + 'order' => 'DESC', + 'granularity' => 'second', + 'relationship' => 'none', + ), + )); + $handler->override_option('arguments', array( + 'created_year_month' => array( + 'id' => 'created_year_month', + 'table' => 'node', + 'field' => 'created_year_month', + 'default_action' => 'summary desc', + 'style_plugin' => 'default_summary', + 'style_options' => array( + 'count' => 1, + 'override' => 1, + 'items_per_page' => '30', + ), + 'wildcard' => 'all', + 'wildcard_substitution' => 'All', + 'title' => '%1', + 'relationship' => 'none', + 'validate_type' => 'none', + 'validate_fail' => 'not found', + 'default_argument_type' => 'fixed', + ), + )); + $handler->override_option('filters', array( + 'status' => array( + 'id' => 'status', + 'table' => 'node', + 'field' => 'status', + 'operator' => '=', + 'value' => 1, + 'group' => 0, + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + 'relationship' => 'none', + ), + )); + $handler->override_option('access', array( + 'type' => 'perm', + 'role' => array(), + 'perm' => 'access content', + )); + $handler->override_option('use_pager', '1'); + $handler->override_option('row_plugin', 'node'); + $handler->override_option('row_options', array( + 'teaser' => TRUE, + 'links' => TRUE, + )); + $handler = $view->new_display('page', 'Page', 'page'); + $handler->override_option('path', 'archive'); + $handler->override_option('menu', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler->override_option('tab_options', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler = $view->new_display('block', 'Block', 'block'); + $handler->override_option('arguments', array( + 'created_year_month' => array( + 'id' => 'created_year_month', + 'table' => 'node', + 'field' => 'created_year_month', + 'default_action' => 'summary asc', + 'style_plugin' => 'default_summary', + 'style_options' => array( + 'count' => 1, + 'override' => 0, + 'items_per_page' => '30', + ), + 'wildcard' => 'all', + 'wildcard_substitution' => 'All', + 'title' => '%1', + 'relationship' => 'none', + 'validate_type' => 'none', + 'validate_fail' => 'not found', + 'default_argument_type' => 'fixed', + ), + )); + $handler->override_option('block_description', 'Archive list'); + $views[$view->name] = $view; + + return $views; +} diff --git a/sites/all/modules/views/modules/node/views_handler_argument_dates_various.inc b/sites/all/modules/views/modules/node/views_handler_argument_dates_various.inc new file mode 100644 index 0000000..4ec49db --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_argument_dates_various.inc @@ -0,0 +1,169 @@ +format = 'F j, Y'; + $this->arg_format = 'Ymd'; + $this->formula = views_date_sql_format($this->arg_format, "***table***.$this->real_field"); + } + + /** + * Provide a link to the next level of the view + */ + function summary_name($data) { + $created = $data->{$this->name_alias}; + return format_date(strtotime($created), 'custom', $this->format, 0); + } + + /** + * Provide a link to the next level of the view + */ + function title() { + return format_date(strtotime($this->argument), 'custom', $this->format, 0); + } +} + +/** + * Argument handler for a year (CCYY) + */ +class views_handler_argument_node_created_year extends views_handler_argument_date { + /** + * Constructor implementation + */ + function construct() { + parent::construct(); + $this->arg_format = 'Y'; + $this->formula = views_date_sql_extract('YEAR', "***table***.$this->real_field"); + } +} + +/** + * Argument handler for a year plus month (CCYYMM) + */ +class views_handler_argument_node_created_year_month extends views_handler_argument_date { + /** + * Constructor implementation + */ + function construct() { + parent::construct(); + $this->format = 'F Y'; + $this->arg_format = 'Ym'; + $this->formula = views_date_sql_format($this->arg_format, "***table***.$this->real_field"); + } + + /** + * Provide a link to the next level of the view + */ + function summary_name($data) { + $created = $data->{$this->name_alias}; + return format_date(strtotime($created . "15" . " 00:00:00 UTC"), 'custom', $this->format, 0); + } + + /** + * Provide a link to the next level of the view + */ + function title() { + return format_date(strtotime($this->argument . "15" . " 00:00:00 UTC"), 'custom', $this->format, 0); + } +} + +/** + * Argument handler for a month (MM) + */ +class views_handler_argument_node_created_month extends views_handler_argument_date { + /** + * Constructor implementation + */ + function construct() { + parent::construct(); + $this->formula = views_date_sql_extract('MONTH', "***table***.$this->real_field"); + $this->format = 'F'; + $this->arg_format = 'm'; + } + + /** + * Provide a link to the next level of the view + */ + function summary_name($data) { + $month = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT); + return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC" ), 'custom', $this->format); + } + + /** + * Provide a link to the next level of the view + */ + function title() { + $month = str_pad($this->argument, 2, '0', STR_PAD_LEFT); + return format_date(strtotime("2005" . $month . "15" . " 00:00:00 UTC"), 'custom', $this->format, 0); + } + + function summary_argument($data) { + // Make sure the argument contains leading zeroes. + return str_pad($data->{$this->base_alias}, 2, '0', STR_PAD_LEFT); + } +} + +/** + * Argument handler for a day (DD) + */ +class views_handler_argument_node_created_day extends views_handler_argument_date { + /** + * Constructor implementation + */ + function construct() { + parent::construct(); + $this->formula = views_date_sql_extract('DAY', "***table***.$this->real_field"); + $this->format = 'j'; + $this->arg_format = 'd'; + } + + /** + * Provide a link to the next level of the view + */ + function summary_name($data) { + $day = str_pad($data->{$this->name_alias}, 2, '0', STR_PAD_LEFT); + // strtotime respects server timezone, so we need to set the time fixed as utc time + return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->format, 0); + } + + /** + * Provide a link to the next level of the view + */ + function title() { + $day = str_pad($this->argument, 2, '0', STR_PAD_LEFT); + return format_date(strtotime("2005" . "05" . $day . " 00:00:00 UTC"), 'custom', $this->format, 0); + } + + function summary_argument($data) { + // Make sure the argument contains leading zeroes. + return str_pad($data->{$this->base_alias}, 2, '0', STR_PAD_LEFT); + } +} + +/** + * Argument handler for a week. + */ +class views_handler_argument_node_created_week extends views_handler_argument_date { + /** + * Constructor implementation + */ + function construct() { + parent::construct(); + $this->arg_format = 'w'; + $this->formula = views_date_sql_extract('WEEK', "***table***.$this->real_field"); + } + + /** + * Provide a link to the next level of the view + */ + function summary_name($data) { + $created = $data->{$this->name_alias}; + return t('Week @week', array('@week' => $created)); + } +} diff --git a/sites/all/modules/views/modules/node/views_handler_argument_node_language.inc b/sites/all/modules/views/modules/node/views_handler_argument_node_language.inc new file mode 100644 index 0000000..85ff6c8 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_argument_node_language.inc @@ -0,0 +1,31 @@ +node_language($data->{$this->name_alias}); + } + + /** + * Override the behavior of title(). Get the user friendly version of the + * node type. + */ + function title() { + return $this->node_language($this->argument); + } + + function node_language($langcode) { + $languages = locale_language_list(); + return isset($languages[$langcode]) ? $languages[$langcode] : t('Unknown language'); + } +} + diff --git a/sites/all/modules/views/modules/node/views_handler_argument_node_nid.inc b/sites/all/modules/views/modules/node/views_handler_argument_node_nid.inc new file mode 100644 index 0000000..ef811ac --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_argument_node_nid.inc @@ -0,0 +1,25 @@ +value), '%d')); + + $result = db_query("SELECT n.title FROM {node} n WHERE n.nid IN ($placeholders)", $this->value); + while ($term = db_fetch_object($result)) { + $titles[] = check_plain($term->title); + } + return $titles; + } +} + diff --git a/sites/all/modules/views/modules/node/views_handler_argument_node_type.inc b/sites/all/modules/views/modules/node/views_handler_argument_node_type.inc new file mode 100644 index 0000000..b186a0c --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_argument_node_type.inc @@ -0,0 +1,35 @@ +node_type($data->{$this->name_alias}); + } + + /** + * Override the behavior of title(). Get the user friendly version of the + * node type. + */ + function title() { + return $this->node_type($this->argument); + } + + function node_type($type) { + $output = node_get_types('name', $type); + if (empty($output)) { + return t('Unknown node type'); + } + else { + return check_plain(t($output)); + } + } +} diff --git a/sites/all/modules/views/modules/node/views_handler_argument_node_vid.inc b/sites/all/modules/views/modules/node/views_handler_argument_node_vid.inc new file mode 100644 index 0000000..a142ce0 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_argument_node_vid.inc @@ -0,0 +1,27 @@ +value), '%d')); + + $result = db_query("SELECT n.title FROM {node_revisions} n WHERE n.nid IN ($placeholders)", $this->value); + while ($term = db_fetch_object($result)) { + $titles[] = check_plain($term->title); + } + return $titles; + } +} + diff --git a/sites/all/modules/views/modules/node/views_handler_field_history_user_timestamp.inc b/sites/all/modules/views/modules/node/views_handler_field_history_user_timestamp.inc new file mode 100644 index 0000000..21b0466 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_field_history_user_timestamp.inc @@ -0,0 +1,71 @@ +uid) { + $this->additional_fields['created'] = array('table' => 'node', 'field' => 'created'); + $this->additional_fields['changed'] = array('table' => 'node', 'field' => 'changed'); + if (module_exists('comment') && !empty($this->options['comments'])) { + $this->additional_fields['last_comment'] = array('table' => 'node_comment_statistics', 'field' => 'last_comment_timestamp'); + } + } + } + + function option_definition() { + $options = parent::option_definition(); + + $options['comments'] = array('default' => FALSE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + if (module_exists('comment')) { + $form['comments'] = array( + '#type' => 'checkbox', + '#title' => t('Check for new comments as well'), + '#default_value' => !empty($this->options['comments']), + ); + } + } + + function query() { + // Only add ourselves to the query if logged in. + global $user; + if (!$user->uid) { + return; + } + parent::query(); + } + + function render($values) { + // Let's default to 'read' state. + // This code shadows node_mark, but it reads from the db directly and + // we already have that info. + $mark = MARK_READ; + global $user; + if ($user->uid) { + $last_read = $values->{$this->field_alias}; + $created = $values->{$this->aliases['created']}; + $changed = $values->{$this->aliases['changed']}; + + $last_comment = module_exists('comment') && !empty($this->options['comments']) ? $values->{$this->aliases['last_comment']} : 0; + + if (!$last_read && $created > NODE_NEW_LIMIT) { + $mark = MARK_NEW; + } + elseif ($changed > $last_read && $changed > NODE_NEW_LIMIT) { + $mark = MARK_UPDATED; + } + elseif ($last_comment > $last_read && $last_comment > NODE_NEW_LIMIT) { + $mark = MARK_UPDATED; + } + return $this->render_link(theme('mark', $mark), $values); + } + } +} diff --git a/sites/all/modules/views/modules/node/views_handler_field_node.inc b/sites/all/modules/views/modules/node/views_handler_field_node.inc new file mode 100644 index 0000000..001fe9b --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_field_node.inc @@ -0,0 +1,73 @@ +additional_fields['nid'] = array('table' => 'node', 'field' => 'nid'); + if (module_exists('translation')) { + $this->additional_fields['language'] = array('table' => 'node', 'field' => 'language'); + } + } + + function option_definition() { + $options = parent::option_definition(); + $options['link_to_node'] = array('default' => isset($this->definition['link_to_node default']) ? $this->definition['link_to_node default'] : FALSE); + return $options; + } + + /** + * Provide link to node option + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_node'] = array( + '#title' => t('Link this field to its node'), + '#description' => t('This will override any other link you have set.'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['link_to_node']), + ); + } + + /** + * Render whatever the data is as a link to the node. + * + * Data should be made XSS safe prior to calling this function. + */ + function render_link($data, $values) { + if (!empty($this->options['link_to_node'])) { + if ($data !== NULL && $data !== '') { + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = "node/" . $values->{$this->aliases['nid']}; + if (isset($this->aliases['language'])) { + $languages = language_list(); + if (isset($languages[$values->{$this->aliases['language']}])) { + $this->options['alter']['language'] = $languages[$values->{$this->aliases['language']}]; + } + else { + unset($this->options['alter']['language']); + } + } + } + else { + $this->options['alter']['make_link'] = FALSE; + } + } + return $data; + } + + function render($values) { + return $this->render_link(check_plain($values->{$this->field_alias}), $values); + } +} diff --git a/sites/all/modules/views/modules/node/views_handler_field_node_link.inc b/sites/all/modules/views/modules/node/views_handler_field_node_link.inc new file mode 100644 index 0000000..8b97743 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_field_node_link.inc @@ -0,0 +1,38 @@ +additional_fields['nid'] = 'nid'; + } + + function option_definition() { + $options = parent::option_definition(); + + $options['text'] = array('default' => '', 'translatable' => TRUE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['text'] = array( + '#type' => 'textfield', + '#title' => t('Text to display'), + '#default_value' => $this->options['text'], + ); + } + + function query() { + $this->ensure_my_table(); + $this->add_additional_fields(); + } + + function render($values) { + $text = !empty($this->options['text']) ? $this->options['text'] : t('view'); + $nid = $values->{$this->aliases['nid']}; + return l($text, "node/$nid"); + } +} diff --git a/sites/all/modules/views/modules/node/views_handler_field_node_link_delete.inc b/sites/all/modules/views/modules/node/views_handler_field_node_link_delete.inc new file mode 100644 index 0000000..555c104 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_field_node_link_delete.inc @@ -0,0 +1,29 @@ +additional_fields['type'] = 'type'; + $this->additional_fields['uid'] = 'uid'; + $this->additional_fields['format'] = array('table' => 'node_revisions', 'field' => 'format'); + } + + function render($values) { + // ensure user has access to edit this node. + $node = new stdClass(); + $node->nid = $values->{$this->aliases['nid']}; + $node->uid = $values->{$this->aliases['uid']}; + $node->type = $values->{$this->aliases['type']}; + $node->format = $values->{$this->aliases['format']}; + $node->status = 1; // unpublished nodes ignore access control + if (!node_access('delete', $node)) { + return; + } + + $text = !empty($this->options['text']) ? $this->options['text'] : t('delete'); + return l($text, "node/$node->nid/delete", array('query' => drupal_get_destination())); + } +} + diff --git a/sites/all/modules/views/modules/node/views_handler_field_node_link_edit.inc b/sites/all/modules/views/modules/node/views_handler_field_node_link_edit.inc new file mode 100644 index 0000000..1548776 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_field_node_link_edit.inc @@ -0,0 +1,29 @@ +additional_fields['uid'] = 'uid'; + $this->additional_fields['type'] = 'type'; + $this->additional_fields['format'] = array('table' => 'node_revisions', 'field' => 'format'); + } + + function render($values) { + // ensure user has access to edit this node. + $node = new stdClass(); + $node->nid = $values->{$this->aliases['nid']}; + $node->uid = $values->{$this->aliases['uid']}; + $node->type = $values->{$this->aliases['type']}; + $node->format = $values->{$this->aliases['format']}; + $node->status = 1; // unpublished nodes ignore access control + if (!node_access('update', $node)) { + return; + } + + $text = !empty($this->options['text']) ? $this->options['text'] : t('edit'); + return l($text, "node/$node->nid/edit", array('query' => drupal_get_destination())); + } +} + diff --git a/sites/all/modules/views/modules/node/views_handler_field_node_path.inc b/sites/all/modules/views/modules/node/views_handler_field_node_path.inc new file mode 100644 index 0000000..6deff88 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_field_node_path.inc @@ -0,0 +1,39 @@ + FALSE); + + return $options; + } + + function construct() { + parent::construct(); + $this->additional_fields['nid'] = 'nid'; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['absolute'] = array( + '#type' => 'checkbox', + '#title' => t('Use absolute link (begins with "http://")'), + '#default_value' => $this->options['absolute'], + '#description' => t('If you want to use this as in "output this field as link" in "link path", you must enable this option.'), + ); + } + + function query() { + $this->ensure_my_table(); + $this->add_additional_fields(); + } + + function render($values) { + $nid = $values->{$this->aliases['nid']}; + return url("node/$nid", array('absolute' => $this->options['absolute'])); + } +} diff --git a/sites/all/modules/views/modules/node/views_handler_field_node_revision.inc b/sites/all/modules/views/modules/node/views_handler_field_node_revision.inc new file mode 100644 index 0000000..d2b7023 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_field_node_revision.inc @@ -0,0 +1,59 @@ +options['link_to_node_revision'])) { + $this->additional_fields['vid'] = 'vid'; + $this->additional_fields['nid'] = 'nid'; + if (module_exists('translation')) { + $this->additional_fields['language'] = array('table' => 'node', 'field' => 'language'); + } + } + } + function option_definition() { + $options = parent::option_definition(); + $options['link_to_node_revision'] = array('default' => FALSE); + return $options; + } + + /** + * Provide link to revision option. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_node_revision'] = array( + '#title' => t('Link this field to its node revision'), + '#description' => t('This will override any other link you have set.'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['link_to_node_revision']), + ); + } + + /** + * Render whatever the data is as a link to the node. + * + * Data should be made XSS safe prior to calling this function. + */ + function render_link($data, $values) { + if (!empty($this->options['link_to_node_revision']) && $data !== NULL && $data !== '') { + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = "node/" . $values->{$this->aliases['nid']} . '/revisions/' . $values->{$this->aliases['vid']} .'/view'; + if (isset($this->aliases['language'])) { + $languages = language_list(); + if (isset($languages[$values->{$this->aliases['language']}])) { + $this->options['alter']['language'] = $languages[$values->{$this->aliases['language']}]; + } + } + } + else { + return parent::render_link($data, $values); + } + return $data; + } +} + diff --git a/sites/all/modules/views/modules/node/views_handler_field_node_revision_link_delete.inc b/sites/all/modules/views/modules/node/views_handler_field_node_revision_link_delete.inc new file mode 100644 index 0000000..a766368 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_field_node_revision_link_delete.inc @@ -0,0 +1,37 @@ +additional_fields['uid'] = array('table' => 'node', 'field' => 'uid'); + $this->additional_fields['node_vid'] = array('table' => 'node', 'field' => 'vid'); + $this->additional_fields['vid'] = 'vid'; + $this->additional_fields['format'] = 'format'; + } + + function access() { + return user_access('delete revisions') || user_access('administer nodes'); + } + + function render($values) { + // ensure user has access to edit this node. + $node = new stdClass(); + $node->nid = $values->{$this->aliases['nid']}; + $node->vid = $values->{$this->aliases['vid']}; + $node->uid = $values->{$this->aliases['uid']}; + $node->format = $values->{$this->aliases['format']}; + $node->status = 1; // unpublished nodes ignore access control + if (!node_access('delete', $node)) { + return; + } + + // Current revision cannot be deleted. + if ($node->vid == $values->{$this->aliases['node_vid']}) { + return; + } + $text = !empty($this->options['text']) ? $this->options['text'] : t('delete'); + return l($text, "node/$node->nid/revisions/$node->vid/delete", array('query' => drupal_get_destination())); + } +} diff --git a/sites/all/modules/views/modules/node/views_handler_field_node_revision_link_revert.inc b/sites/all/modules/views/modules/node/views_handler_field_node_revision_link_revert.inc new file mode 100644 index 0000000..33cfc74 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_field_node_revision_link_revert.inc @@ -0,0 +1,38 @@ +additional_fields['uid'] = array('table' => 'node', 'field' => 'uid'); + $this->additional_fields['node_vid'] = array('table' => 'node', 'field' => 'vid'); + $this->additional_fields['vid'] = 'vid'; + $this->additional_fields['format'] = 'format'; + } + + function access() { + return user_access('revert revisions') || user_access('administer nodes'); + } + + function render($values) { + // ensure user has access to edit this node. + $node = new stdClass(); + $node->nid = $values->{$this->aliases['nid']}; + $node->vid = $values->{$this->aliases['vid']}; + $node->uid = $values->{$this->aliases['uid']}; + $node->format = $values->{$this->aliases['format']}; + $node->status = 1; // unpublished nodes ignore access control + if (!node_access('update', $node)) { + return; + } + + // Current revision cannot be reverted. + if ($node->vid == $values->{$this->aliases['node_vid']}) { + return; + } + + $text = !empty($this->options['text']) ? $this->options['text'] : t('revert'); + return l($text, "node/$node->nid/revisions/$node->vid/revert", array('query' => drupal_get_destination())); + } +} diff --git a/sites/all/modules/views/modules/node/views_handler_field_node_type.inc b/sites/all/modules/views/modules/node/views_handler_field_node_type.inc new file mode 100644 index 0000000..e5afb39 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_field_node_type.inc @@ -0,0 +1,42 @@ + FALSE); + + return $options; + } + + /** + * Provide machine_name option for to node type display. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['machine_name'] = array( + '#title' => t('Output machine name'), + '#description' => t('Display field as the node type machine name.'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['machine_name']), + ); + } + + /** + * Render node type as human readable name, unless using machine_name option. + */ + function render_name($data, $values) { + if ($this->options['machine_name'] != 1 && $data !== NULL && $data !== '') { + return t(check_plain(node_get_types('name', $data))); + } + return check_plain($data); + } + + function render($values) { + return $this->render_link($this->render_name($values->{$this->field_alias}, $values), $values); + } +} + diff --git a/sites/all/modules/views/modules/node/views_handler_filter_history_user_timestamp.inc b/sites/all/modules/views/modules/node/views_handler_filter_history_user_timestamp.inc new file mode 100644 index 0000000..a131cf1 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_filter_history_user_timestamp.inc @@ -0,0 +1,71 @@ +options['expose']['label'])) { + $label = $this->options['expose']['label']; + } + else { + $label = t('Has new content'); + } + $form['value'] = array( + '#type' => 'checkbox', + '#title' => $label, + '#default_value' => $this->value, + ); + } + } + + function query() { + global $user; + // This can only work if we're logged in. + if (!$user || !$user->uid) { + return; + } + + // Don't filter if we're exposed and the checkbox isn't selected. + if ((!empty($this->options['exposed'])) && empty($this->value)) { + return; + } + + // Hey, Drupal kills old history, so nodes that haven't been updated + // since NODE_NEW_LIMIT are bzzzzzzzt outta here! + + $limit = time() - NODE_NEW_LIMIT; + + $this->ensure_my_table(); + $field = "$this->table_alias.$this->real_field"; + $node = $this->query->ensure_table('node', $this->relationship); + + if (module_exists('comment')) { + $ncs = $this->query->ensure_table('node_comment_statistics', $this->relationship); + $clause = ("OR $ncs.last_comment_timestamp > (***CURRENT_TIME*** - $limit)"); + $clause2 = "OR $field < $ncs.last_comment_timestamp"; + } + + // NULL means a history record doesn't exist. That's clearly new content. + // Unless it's very very old content. Everything in the query is already + // type safe cause none of it is coming from outside here. + $this->query->add_where($this->options['group'], "($field IS NULL AND ($node.changed > (***CURRENT_TIME*** - $limit) $clause)) OR $field < $node.changed $clause2"); + } + + function admin_summary() { + if (!empty($this->options['exposed'])) { + return t('exposed'); + } + } +} + diff --git a/sites/all/modules/views/modules/node/views_handler_filter_node_access.inc b/sites/all/modules/views/modules/node/views_handler_filter_node_access.inc new file mode 100644 index 0000000..f787aee --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_filter_node_access.inc @@ -0,0 +1,32 @@ +ensure_my_table(); + $grants = array(); + foreach (node_access_grants('view') as $realm => $gids) { + foreach ($gids as $gid) { + $grants[] = "($table.gid = $gid AND $table.realm = '$realm')"; + } + } + $grants_sql = ''; + if (count($grants)) { + $grants_sql = implode(' OR ', $grants); + } + $this->query->add_where('AND', $grants_sql); + $this->query->add_where('AND', "$table.grant_view >= 1"); + } + } +} diff --git a/sites/all/modules/views/modules/node/views_handler_filter_node_status.inc b/sites/all/modules/views/modules/node/views_handler_filter_node_status.inc new file mode 100644 index 0000000..7047caa --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_filter_node_status.inc @@ -0,0 +1,13 @@ +ensure_my_table(); + $this->query->add_where($this->options['group'], "$table.status = 1 OR ($table.uid = ***CURRENT_USER*** AND ***CURRENT_USER*** <> 0) OR ***ADMINISTER_NODES*** = 1"); + } +} diff --git a/sites/all/modules/views/modules/node/views_handler_filter_node_type.inc b/sites/all/modules/views/modules/node/views_handler_filter_node_type.inc new file mode 100644 index 0000000..1f460f6 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_handler_filter_node_type.inc @@ -0,0 +1,17 @@ +value_options)) { + $this->value_title = t('Node type'); + $types = node_get_types(); + foreach ($types as $type => $info) { + $options[$type] = t($info->name); + } + asort($options); + $this->value_options = $options; + } + } +} diff --git a/sites/all/modules/views/modules/node/views_plugin_argument_default_node.inc b/sites/all/modules/views/modules/node/views_plugin_argument_default_node.inc new file mode 100644 index 0000000..68f8809 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_plugin_argument_default_node.inc @@ -0,0 +1,27 @@ +nid; + } + } + + if (arg(0) == 'node' && is_numeric(arg(1))) { + return arg(1); + } + } +} + diff --git a/sites/all/modules/views/modules/node/views_plugin_argument_validate_node.inc b/sites/all/modules/views/modules/node/views_plugin_argument_validate_node.inc new file mode 100644 index 0000000..eb9b373 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_plugin_argument_validate_node.inc @@ -0,0 +1,122 @@ + $info) { + $options[$type] = check_plain(t($info->name)); + } + + $arg = $this->get_argument(); + if (empty($arg)) { + $arg = array(); + } + + $form[$this->option_name] = array( + '#type' => 'checkboxes', + '#prefix' => '
    ', + '#suffix' => '
    ', + '#title' => t('Types'), + '#options' => $options, + '#default_value' => $arg, + '#description' => t('If you wish to validate for specific node types, check them; if none are checked, all nodes will pass.'), + '#process' => array('expand_checkboxes', 'views_process_dependency'), + '#dependency' => array('edit-options-validate-type' => array($this->id)), + ); + + $form['validate_argument_node_access'] = array( + '#type' => 'checkbox', + '#title' => t('Validate user has access to the node'), + '#default_value' => !empty($this->argument->options['validate_argument_node_access']), + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-validate-type' => array($this->id)), + ); + + $form['validate_argument_nid_type'] = array( + '#type' => 'select', + '#title' => t('Argument type'), + '#options' => array( + 'nid' => t('Node ID'), + 'nids' => t('Node IDs separated by , or +'), + ), + '#default_value' => isset($this->argument->options['validate_argument_nid_type']) ? $this->argument->options['validate_argument_nid_type'] : 'nid', + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-validate-type' => array($this->id)), + ); + } + + function validate_argument($argument) { + $types = array_filter($this->argument->options[$this->option_name]); + + $type = isset($this->argument->options['validate_argument_nid_type']) ? $this->argument->options['validate_argument_nid_type'] : 'nid'; + + switch ($type) { + case 'nid': + if (!is_numeric($argument)) { + return FALSE; + } + $node = node_load($argument); + if (!$node) { + return FALSE; + } + + if (!empty($this->argument->options['validate_argument_node_access'])) { + if (!node_access('view', $node)) { + return FALSE; + } + } + + // Save the title() handlers some work. + $this->argument->validated_title = check_plain($node->title); + + if (empty($types)) { + return TRUE; + } + + return isset($types[$node->type]); + break; + case 'nids': + $nids = new stdClass(); + $nids->value = array($argument); + $nids = views_break_phrase($argument, $nids); + if ($nids->value == -1) { + return FALSE; + } + + $placeholders = implode(', ', array_fill(0, sizeof($nids->value), '%d')); + + $test = drupal_map_assoc($nids->value); + $titles = array(); + + $result = db_query("SELECT * FROM {node} WHERE nid IN ($placeholders)", $nids->value); + while ($node = db_fetch_object($result)) { + if ($types && empty($types[$node->type])) { + return FALSE; + } + + if (!empty($this->argument->options['validate_argument_node_access'])) { + if (!node_access('view', $node)) { + return FALSE; + } + } + + $titles[] = check_plain($node->title); + unset($test[$node->nid]); + } + + $this->argument->validated_title = implode($nids->operator == 'or' ? ' + ' : ', ', $titles); + // If this is not empty, we did not find a nid. + return empty($test); + } + } +} + diff --git a/sites/all/modules/views/modules/node/views_plugin_row_node_rss.inc b/sites/all/modules/views/modules/node/views_plugin_row_node_rss.inc new file mode 100644 index 0000000..79bb3bd --- /dev/null +++ b/sites/all/modules/views/modules/node/views_plugin_row_node_rss.inc @@ -0,0 +1,141 @@ + 'default'); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['item_length'] = array( + '#type' => 'select', + '#title' => t('Display type'), + '#options' => array( + 'fulltext' => t('Full text'), + 'teaser' => t('Title plus teaser'), + 'title' => t('Title only'), + 'default' => t('Use default RSS settings'), + ), + '#default_value' => $this->options['item_length'], + ); + } + + function render($row) { + // For the most part, this code is taken from node_feed() in node.module + global $base_url; + + $nid = $row->{$this->field_alias}; + if (!is_numeric($nid)) { + return; + } + + $item_length = $this->options['item_length']; + if ($item_length == 'default') { + $item_length = variable_get('feed_item_length', 'teaser'); + } + + // Load the specified node: + $node = node_load($nid); + if (empty($node)) { + return; + } + + $node->build_mode = NODE_BUILD_RSS; + + if ($item_length != 'title') { + $teaser = ($item_length == 'teaser') ? TRUE : FALSE; + + // Filter and prepare node teaser + if (node_hook($node, 'view')) { + $node = node_invoke($node, 'view', $teaser, FALSE); + } + else { + $node = node_prepare($node, $teaser); + } + + // Allow modules to change $node->teaser before viewing. + node_invoke_nodeapi($node, 'view', $teaser, FALSE); + } + + // Set the proper node part, then unset unused $node part so that a bad + // theme can not open a security hole. + $content = drupal_render($node->content); + if ($teaser) { + $node->teaser = $content; + unset($node->body); + } + else { + $node->body = $content; + unset($node->teaser); + } + + // Allow modules to modify the fully-built node. + node_invoke_nodeapi($node, 'alter', $teaser, FALSE); + + $item = new stdClass(); + $item->title = $node->title; + $item->link = url("node/$row->nid", array('absolute' => TRUE)); + $item->nid = $node->nid; + $item->readmore = $node->readmore; + + // Allow modules to add additional item fields and/or modify $item + $extra = node_invoke_nodeapi($node, 'rss item'); + $item->elements = array_merge($extra, + array( + array('key' => 'pubDate', 'value' => gmdate('r', $node->created)), + array( + 'key' => 'dc:creator', + 'value' => $node->name, + 'namespace' => array('xmlns:dc' => 'http://purl.org/dc/elements/1.1/'), + ), + array( + 'key' => 'guid', + 'value' => $node->nid . ' at ' . $base_url, + 'attributes' => array('isPermaLink' => 'false') + ), + ) + ); + + foreach ($item->elements as $element) { + if (isset($element['namespace'])) { + $this->view->style_plugin->namespaces = array_merge($this->view->style_plugin->namespaces, $element['namespace']); + } + } + + // Prepare the item description + switch ($item_length) { + case 'fulltext': + $item->description = $node->body; + break; + case 'teaser': + $item->description = $node->teaser; + if (!empty($item->readmore)) { + $item->description .= '

    ' . l(t('read more'), 'node/' . $item->nid, array('absolute' => TRUE, 'attributes' => array('target' => '_blank'))) . '

    '; + } + break; + case 'title': + $item->description = ''; + break; + } + + return theme($this->theme_functions(), $this->view, $this->options, $item); + } +} + diff --git a/sites/all/modules/views/modules/node/views_plugin_row_node_view.inc b/sites/all/modules/views/modules/node/views_plugin_row_node_view.inc new file mode 100644 index 0000000..100e8b3 --- /dev/null +++ b/sites/all/modules/views/modules/node/views_plugin_row_node_view.inc @@ -0,0 +1,72 @@ +options['teaser'])) { + $this->options['build_mode'] = $this->options['teaser'] ? 'teaser' : 'full'; + } + } + + function option_definition() { + $options = parent::option_definition(); + + $options['build_mode'] = array('default' => 'teaser'); + $options['links'] = array('default' => TRUE); + $options['comments'] = array('default' => FALSE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + // CCK holds the registry of available build modes, but can hardly + // push them as options for the node row style, so we break the normal + // rule of not directly relying on non-core modules. + if ($modes = module_invoke('content', 'build_modes')) { + $options = array(); + foreach ($modes as $key => $value) { + if (isset($value['views style']) && $value['views style']) { + $options[$key] = $value['title']; + } + } + } + else { + $options = array( + 'teaser' => t('Teaser'), + 'full' => t('Full node') + ); + } + $form['build_mode'] = array( + '#type' => 'select', + '#options' => $options, + '#title' => t('Build mode'), + '#default_value' => $this->options['build_mode'], + ); + $form['links'] = array( + '#type' => 'checkbox', + '#title' => t('Display links'), + '#default_value' => $this->options['links'], + ); + $form['comments'] = array( + '#type' => 'checkbox', + '#title' => t('Display node comments'), + '#default_value' => $this->options['comments'], + ); + } +} diff --git a/sites/all/modules/views/modules/poll.views.inc b/sites/all/modules/views/modules/poll.views.inc new file mode 100644 index 0000000..1e93ce1 --- /dev/null +++ b/sites/all/modules/views/modules/poll.views.inc @@ -0,0 +1,55 @@ + array( + 'left_field' => 'nid', + 'field' => 'nid', + ), + ); + + // ---------------------------------------------------------------- + // Fields + + // poll active status + $data['poll']['active'] = array( + 'title' => t('Active'), + 'help' => t('Whether the poll is open for voting.'), + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'label' => t('Active'), + 'type' => 'yes-no', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + return $data; +} + +/** + * @} + */ diff --git a/sites/all/modules/views/modules/profile.views.inc b/sites/all/modules/views/modules/profile.views.inc new file mode 100644 index 0000000..14037f9 --- /dev/null +++ b/sites/all/modules/views/modules/profile.views.inc @@ -0,0 +1,245 @@ + array( + 'left_table' => 'profile_values', + 'left_field' => 'uid', + 'field' => 'uid', + ), + 'users' => array( + 'left_table' => 'profile_values', + 'left_field' => 'uid', + 'field' => 'uid', + ), + ); + + $fields = profile_views_get_fields(); + foreach ($fields as $field) { + $table_name = 'profile_values_' . str_replace('-', '_', $field->name); + $data[$table_name] = array( + 'table' => array( + 'group' => t('Profile'), + 'join' => array( + 'node' => array( + 'table' => 'profile_values', + 'left_table' => 'users', + 'left_field' => 'uid', + 'field' => 'uid', + 'extra' => array(array('field' => 'fid', 'value' => $field->fid)), + ), + 'users' => array( + 'table' => 'profile_values', + 'left_field' => 'uid', + 'field' => 'uid', + 'extra' => array(array('field' => 'fid', 'value' => $field->fid)), + ), + ), + ), + ); + // All fields in the table are named 'value'. + $data[$table_name]['value'] = profile_views_fetch_field($field); + } + + return $data; +} + +/** + * Get all profile fields + */ +function profile_views_get_fields() { + static $fields = NULL; + + if (!isset($fields)) { + $fields = array(); + $results = db_query("SELECT * FROM {profile_fields} ORDER BY category, weight"); + + while ($row = db_fetch_object($results)) { + if (!empty($row->options)) { + if (!in_array(substr($row->options, 0, 2), array('a:', 'b:', 'i:', 'f:', 'o:', 's:', ))) { + // unserialized fields default version + $options = $row->options; + unset($row->options); + $row->options = $options; + } + else { + // serialized fields or modified version + $row->options = unserialize(db_decode_blob($row->options)); + } + } + $fields[$row->fid] = $row; + } + } + return $fields; +} + + +/** + * Add profile fields to view table + */ +function profile_views_fetch_field($field) { + $data = array( + 'title' => t('@category: @field-name', array('@category' => $field->category, '@field-name' => $field->title)), + ); + + // Add fields specific to the profile type. + switch ($field->type) { + case 'textfield': + $data += array( + 'help' => t('Profile textfield'), + 'field' => array( + 'handler' => 'views_handler_field_user', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + break; + case 'textarea': + $data += array( + 'help' => t('Profile textarea'), + 'field' => array( + 'handler' => 'views_handler_field_markup', + 'format' => FILTER_FORMAT_DEFAULT, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + break; + case 'checkbox': + $data += array( + 'help' => t('Profile checkbox'), + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'accept null' => TRUE, + ), + // @todo there ought to be a boolean argument handler + ); + + break; + case 'url': + $data += array( + 'help' => t('Profile URL'), + 'field' => array( + 'handler' => 'views_handler_field_url', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + break; + case 'selection': + $data += array( + 'help' => t('Profile selection'), + 'field' => array( + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_profile_selection', + 'fid' => $field->fid, + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + break; + case 'list': + $data += array( + 'help' => t('Profile freeform list %field-name.', array('%field-name' => $field->title)), + 'field' => array( + 'handler' => 'views_handler_field_profile_list', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + break; + case 'date': + $data += array( + 'help' => t('Profile date %field-name.', array('%field-name' => $field->title)), + 'field' => array( + 'handler' => 'views_handler_field_profile_date', + ), + ); + + break; + } + + // @todo: add access control to hidden fields. + return $data; +} + +/** + * Implementation of hook_views_handlers() to register all of the basic handlers + * views uses. + */ +function profile_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/modules/profile', + ), + 'handlers' => array( + 'views_handler_field_profile_date' => array( + 'parent' => 'views_handler_field_date', + ), + 'views_handler_field_profile_list' => array( + 'parent' => 'views_handler_field_prerender_list', + ), + 'views_handler_filter_profile_selection' => array( + 'parent' => 'views_handler_filter_in_operator', + ), + ), + ); +} + +/** + * @} + */ diff --git a/sites/all/modules/views/modules/profile.views_convert.inc b/sites/all/modules/views/modules/profile.views_convert.inc new file mode 100644 index 0000000..ee3557e --- /dev/null +++ b/sites/all/modules/views/modules/profile.views_convert.inc @@ -0,0 +1,39 @@ +add_item() won't produce + * the right results, usually needed to set field options or values. + */ +function profile_views_convert($display, $type, &$view, $field, $id = NULL) { + static $profile_fields; + if (!isset($profile_fields)) { + $profile_fields = array(); + foreach (profile_views_get_fields() as $profile_field) { + $profile_fields['profile_values_'. $profile_field->name] = $profile_field; + } + } + switch ($type) { + case 'filter': + if (isset($tables[$field['tablename']])) { + switch ($profile_fields[$field['tablename']]->type) { + case 'vocabulary': + case 'selection': + $operators = array('AND' => 'in', 'OR' => 'in', 'NOR' => 'not in'); + $view->set_item_option($display, 'filter', $id, 'operator', $operators[$field['operator']]); + break; + default: + $view->set_item_option($display, 'filter', $id, 'operator', $field['operator']); + break; + } + } + break; + } +} \ No newline at end of file diff --git a/sites/all/modules/views/modules/profile/views_handler_field_profile_date.inc b/sites/all/modules/views/modules/profile/views_handler_field_profile_date.inc new file mode 100644 index 0000000..a17981a --- /dev/null +++ b/sites/all/modules/views/modules/profile/views_handler_field_profile_date.inc @@ -0,0 +1,81 @@ +{$this->field_alias}) { + return; + } + $value = unserialize($value->{$this->field_alias}); + $format = $this->options['date_format']; + switch ($format) { + case 'custom': + $format = $this->options['custom_date_format']; + break; + case 'small': + $format = variable_get('date_format_short', 'm/d/Y - H:i'); + break; + case 'medium': + $format = variable_get('date_format_medium', 'D, m/d/Y - H:i'); + break; + case 'large': + $format = variable_get('date_format_long', 'l, F j, Y - H:i'); + break; + } + + // Note: Avoid PHP's date() because it does not handle dates before + // 1970 on Windows. This would make the date field useless for e.g. + // birthdays. + + // But we *can* deal with non-year stuff: + $date = gmmktime(0, 0, 0, $value['month'], $value['day'], 1970); + $replace = array( + // day + 'd' => sprintf('%02d', $value['day']), + 'D' => NULL, + 'l' => NULL, + 'N' => NULL, + 'S' => date('S', $date), + 'w' => NULL, + 'j' => $value['day'], + // month + 'F' => date('F', $date), + 'm' => sprintf('%02d', $value['month']), + 'M' => date('M', $date), + 'n' => date('n', $date), + + 'Y' => $value['year'], + 'y' => substr($value['year'], 2, 2), + + // kill time stuff + 'a' => NULL, + 'A' => NULL, + 'g' => NULL, + 'G' => NULL, + 'h' => NULL, + 'H' => NULL, + 'i' => NULL, + 's' => NULL, + ':' => NULL, + 'T' => NULL, + ' - ' => NULL, + ':' => NULL, + ); + + return strtr($format, $replace); + } +} + diff --git a/sites/all/modules/views/modules/profile/views_handler_field_profile_list.inc b/sites/all/modules/views/modules/profile/views_handler_field_profile_list.inc new file mode 100644 index 0000000..df0f6d3 --- /dev/null +++ b/sites/all/modules/views/modules/profile/views_handler_field_profile_list.inc @@ -0,0 +1,33 @@ +items = array(); + foreach ($values as $value) { + $field = $value->{$this->field_alias}; + $this->items[$field] = array(); + foreach (split("[,\n\r]", $field) as $item) { + if ($item != '' && $item !== NULL) { + $this->items[$field][] = array('item' => $item); + } + } + } + } + + function render_item($count, $item) { + return $item['item']; + } + + function document_self_tokens(&$tokens) { + $tokens['[' . $this->options['id'] . '-item' . ']'] = t('The text of the profile item.'); + } + + function add_self_tokens(&$tokens, $item) { + $tokens['[' . $this->options['id'] . '-item' . ']'] = $item['item']; + } +} diff --git a/sites/all/modules/views/modules/profile/views_handler_filter_profile_selection.inc b/sites/all/modules/views/modules/profile/views_handler_filter_profile_selection.inc new file mode 100644 index 0000000..bf76ec7 --- /dev/null +++ b/sites/all/modules/views/modules/profile/views_handler_filter_profile_selection.inc @@ -0,0 +1,23 @@ +value_options)) { + return; + } + + $this->value_options = array(); + $all_options = profile_views_get_fields(); + $field = $all_options[$this->definition['fid']]; + + $lines = split("[,\n\r]", $field->options); + foreach ($lines as $line) { + if ($line = trim($line)) { + $this->value_options[$line] = $line; + } + } + } +} diff --git a/sites/all/modules/views/modules/search.views.inc b/sites/all/modules/views/modules/search.views.inc new file mode 100644 index 0000000..a2dddcb --- /dev/null +++ b/sites/all/modules/views/modules/search.views.inc @@ -0,0 +1,223 @@ + array( + 'left_field' => 'nid', + 'field' => 'sid', + ), + ); + + $data['search_total']['table']['join'] = array( + 'node' => array( + 'left_table' => 'search_index', + 'left_field' => 'word', + 'field' => 'word', + ), + 'users' => array( + 'left_table' => 'search_index', + 'left_field' => 'word', + 'field' => 'word', + ) + ); + + $data['search_dataset']['table']['join'] = array( + 'node' => array( + 'left_table' => 'search_index', + 'left_field' => 'sid', + 'field' => 'sid', + 'extra' => 'search_index.type = search_dataset.type', + 'type' => 'INNER', + ), + 'users' => array( + 'left_table' => 'search_index', + 'left_field' => 'sid', + 'field' => 'sid', + 'extra' => 'search_index.type = search_dataset.type', + 'type' => 'INNER', + ), + ); + + // ---------------------------------------------------------------- + // Fields + + // score + $data['search_index']['score'] = array( + 'title' => t('Score'), + 'help' => t('The score of the search item. This will not be used if the search filter is not also present.'), + 'field' => array( + 'handler' => 'views_handler_field_search_score', + 'click sortable' => TRUE, + 'float' => TRUE, + ), + // Information for sorting on a search score. + 'sort' => array( + 'handler' => 'views_handler_sort_search_score', + ), + ); + + // Search node links: forward links. + $data['search_node_links_from']['table']['group'] = t('Search'); + $data['search_node_links_from']['table']['join'] = array( + 'node' => array( + 'arguments' => array('search_node_links', 'node', 'nid', 'nid', NULL, 'INNER'), + ), + ); + $data['search_node_links_from']['sid'] = array( + 'title' => t('Links from'), + 'help' => t('Other nodes that are linked from the node.'), + 'argument' => array( + 'handler' => 'views_handler_argument_node_nid', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_equality', + ), + ); + + // Search node links: backlinks. + $data['search_node_links_to']['table']['group'] = t('Search'); + $data['search_node_links_to']['table']['join'] = array( + 'node' => array( + 'arguments' => array('search_node_links', 'node', 'nid', 'sid', NULL, 'INNER'), + ), + ); + $data['search_node_links_to']['nid'] = array( + 'title' => t('Links to'), + 'help' => t('Other nodes that link to the node.'), + 'argument' => array( + 'handler' => 'views_handler_argument_node_nid', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_equality', + ), + ); + + // search filter + $data['search_index']['keys'] = array( + 'title' => t('Search Terms'), // The item it appears as on the UI, + 'help' => t('The terms to search for.'), // The help that appears on the UI, + // Information for searching terms using the full search syntax + 'filter' => array( + 'handler' => 'views_handler_filter_search', + ), + ); + + return $data; +} + +/** + * Implementation of hook_views_handlers() to register all of the basic handlers + * views uses. + */ +function search_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/modules/search', + ), + 'handlers' => array( + 'views_handler_field_search_score' => array( + 'parent' => 'views_handler_field_numeric', + ), + 'views_handler_sort_search_score' => array( + 'parent' => 'views_handler_sort', + ), + 'views_handler_filter_search' => array( + 'parent' => 'views_handler_filter', + ), + ), + ); +} + +/** + * Implementation of hook_views_plugins + */ +function search_views_plugins() { + return; + // DISABLED. This currently doesn't work. + return array( + 'module' => 'views', // This just tells our themes are elsewhere. + 'row' => array( + 'search' => array( + 'title' => t('Search'), + 'help' => t('Display the results with standard search view.'), + 'handler' => 'views_plugin_row_search_view', + 'path' => drupal_get_path('module', 'views') . '/modules/search', // not necessary for most modules + 'theme' => 'views_view_row_search', + 'base' => array('node'), // only works with 'node' as base. + 'type' => 'normal', + ), + ), + ); +} + +/** + * Template helper for theme_views_view_row_search + */ +function template_preprocess_views_view_row_search(&$vars) { + $vars['node'] = ''; // make sure var is defined. + $nid = $vars['row']->nid; + if (!is_numeric($nid)) { + return; + } + + $node = node_load($nid); + + if (empty($node)) { + return; + } + + // Build the node body. + $node = node_build_content($node, FALSE, FALSE); + $node->body = drupal_render($node->content); + + // Fetch comments for snippet + $node->body .= module_invoke('comment', 'nodeapi', $node, 'update index'); + + // Fetch terms for snippet + $node->body .= module_invoke('taxonomy', 'nodeapi', $node, 'update index'); + + $vars['url'] = url('node/' . $nid); + $vars['title'] = check_plain($node->title); + + $info = array(); + $info['type'] = node_get_types('name', $node); + $info['user'] = theme('username', $node); + $info['date'] = format_date($node->changed, 'small'); + $extra = node_invoke_nodeapi($node, 'search result'); + if (isset($extra) && is_array($extra)) { + $info = array_merge($info, $extra); + } + $vars['info_split'] = $info; + $vars['info'] = implode(' - ', $info); + + $vars['node'] = $node; + // @todo: get score from ??? +//$vars['score'] = $item->score; + $vars['snippet'] = search_excerpt($vars['view']->value, $node->body); +} + + +/** + * @} + */ diff --git a/sites/all/modules/views/modules/search.views_convert.inc b/sites/all/modules/views/modules/search.views_convert.inc new file mode 100644 index 0000000..ef8c456 --- /dev/null +++ b/sites/all/modules/views/modules/search.views_convert.inc @@ -0,0 +1,23 @@ +set_item_option($display, 'filter', $id, 'table', 'search_index'); + $view->set_item_option($display, 'filter', $id, 'field', 'keys'); + break; + } + break; + } + break; + } +} diff --git a/sites/all/modules/views/modules/search.views_default.inc b/sites/all/modules/views/modules/search.views_default.inc new file mode 100644 index 0000000..6f69fab --- /dev/null +++ b/sites/all/modules/views/modules/search.views_default.inc @@ -0,0 +1,149 @@ +name = 'backlinks'; + $view->description = 'Displays a list of nodes that link to the node, using the search backlinks table.'; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->api_version = 2; + $view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */ + $handler = $view->new_display('default', 'Defaults', 'default'); + $handler->override_option('fields', array( + 'title' => array( + 'id' => 'title', + 'table' => 'node', + 'field' => 'title', + 'label' => '', + 'relationship' => 'none', + 'link_to_node' => 1, + ), + )); + $handler->override_option('arguments', array( + 'nid' => array( + 'id' => 'nid', + 'table' => 'search_node_links_to', + 'field' => 'nid', + 'default_action' => 'not found', + 'style_plugin' => 'default_summary', + 'style_options' => array( + 'count' => TRUE, + 'override' => FALSE, + 'items_per_page' => 25, + ), + 'wildcard' => '', + 'wildcard_substitution' => '', + 'title' => 'Pages that link to %1', + 'default_argument_type' => 'fixed', + 'default_argument' => '', + 'validate_type' => 'node', + 'validate_fail' => 'not found', + 'relationship' => 'none', + 'default_argument_fixed' => '', + 'default_argument_php' => '', + 'validate_argument_node_type' => array(), + 'validate_argument_php' => '', + ), + )); + $handler->override_option('filters', array( + 'status' => array( + 'id' => 'status', + 'table' => 'node', + 'field' => 'status', + 'operator' => '=', + 'value' => 1, + 'group' => 0, + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + 'relationship' => 'none', + ), + )); + $handler->override_option('access', array( + 'type' => 'perm', + 'role' => array(), + 'perm' => 'access content', + )); + $handler->override_option('empty', 'No backlinks found.'); + $handler->override_option('empty_format', '1'); + $handler->override_option('items_per_page', 30); + $handler->override_option('use_pager', '1'); + $handler->override_option('style_plugin', 'list'); + $handler->override_option('style_options', array( + 'type' => 'ol', + )); + $handler = $view->new_display('page', 'Page', 'page'); + $handler->override_option('path', 'node/%/backlinks'); + $handler->override_option('menu', array( + 'type' => 'tab', + 'title' => 'What links here', + 'weight' => '0', + )); + $handler->override_option('tab_options', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler = $view->new_display('block', 'Block', 'block'); + $handler->override_option('arguments', array( + 'nid' => array( + 'id' => 'nid', + 'table' => 'search_node_links_to', + 'field' => 'nid', + 'default_action' => 'default', + 'style_plugin' => 'default_summary', + 'style_options' => array( + 'count' => TRUE, + 'override' => FALSE, + 'items_per_page' => 25, + ), + 'wildcard' => '', + 'wildcard_substitution' => '', + 'title' => 'What links here', + 'default_argument_type' => 'node', + 'default_argument' => '', + 'validate_type' => 'node', + 'validate_fail' => 'not found', + 'relationship' => 'none', + 'default_argument_fixed' => '', + 'default_argument_php' => 'return ($node = menu_get_object()) ? $node->nid : FALSE;', + 'validate_argument_node_type' => array( + 'album' => 0, + 'artist' => 0, + 'book' => 0, + 'page' => 0, + 'story' => 0, + 'track' => 0, + ), + 'validate_argument_php' => '', + 'default_argument_user' => 0, + 'validate_argument_vocabulary' => array( + '3' => 0, + '4' => 0, + '1' => 0, + '5' => 0, + '2' => 0, + ), + 'validate_argument_type' => 'tid', + ), + )); + $handler->override_option('items_per_page', 6); + $handler->override_option('use_more', 1); + $handler->override_option('style_plugin', 'list'); + $handler->override_option('style_options', array( + 'type' => 'ul', + )); + $handler->override_option('block_description', 'What links here'); + $views[$view->name] = $view; + + return $views; +} diff --git a/sites/all/modules/views/modules/search/views_handler_field_search_score.inc b/sites/all/modules/views/modules/search/views_handler_field_search_score.inc new file mode 100644 index 0000000..2667a04 --- /dev/null +++ b/sites/all/modules/views/modules/search/views_handler_field_search_score.inc @@ -0,0 +1,81 @@ + ''); + $options['alternate_order'] = array('default' => 'asc'); + + return $options; + } + + function options_form(&$form, &$form_state) { + $style_options = $this->view->display_handler->get_option('style_options'); + if (isset($style_options['default']) && $style_options['default'] == $this->options['id']) { + $handlers = $this->view->display_handler->get_handlers('field'); + $options = array('' => t('No alternate')); + foreach ($handlers as $id => $handler) { + $options[$id] = $handler->ui_name(); + } + + $form['alternate_sort'] = array( + '#type' => 'select', + '#title' => t('Alternative sort'), + '#description' => t('Pick an alternative default table sort field to use when the search score field is unavailable.'), + '#options' => $options, + '#default_value' => $this->options['alternate_sort'], + ); + + $form['alternate_order'] = array( + '#type' => 'select', + '#title' => t('Alternate sort order'), + '#options' => array('asc' => t('Ascending'), 'desc' => t('Descending')), + '#default_value' => $this->options['alternate_order'], + ); + } + + parent::options_form($form, $form_state); + } + + function query() { + // Check to see if the search filter added 'score' to the table. + // Our filter stores it as $handler->search_score -- and we also + // need to check its relationship to make sure that we're using the same + // one or obviously this won't work. + foreach ($this->view->filter as $handler) { + if (isset($handler->search_score) && $handler->relationship == $this->relationship) { + $this->field_alias = $handler->search_score; + $this->table_alias = $handler->table_alias; + return; + } + } + + // Hide this field if no search filter is in place. + $this->options['exclude'] = TRUE; + if (!empty($this->options['alternate_sort'])) { + if (isset($this->view->style_plugin->options['default']) && $this->view->style_plugin->options['default'] == $this->options['id']) { + // Since the style handler initiates fields, we plug these values right into the active handler. + $this->view->style_plugin->options['default'] = $this->options['alternate_sort']; + $this->view->style_plugin->options['order'] = $this->options['alternate_order']; + } + } + } + + function click_sort($order) { + if (isset($this->table_alias)) { + $this->query->add_orderby(NULL, NULL, $order, $this->field_alias); + } + } + + function render($values) { + // Only render if we exist. + if (isset($this->table_alias)) { + return parent::render($values); + } + } + +} diff --git a/sites/all/modules/views/modules/search/views_handler_filter_search.inc b/sites/all/modules/views/modules/search/views_handler_filter_search.inc new file mode 100644 index 0000000..630c259 --- /dev/null +++ b/sites/all/modules/views/modules/search/views_handler_filter_search.inc @@ -0,0 +1,112 @@ + 'radios', + '#title' => t('On empty input'), + '#default_value' => $this->operator, + '#options' => array( + 'optional' => t('Show All'), + 'required' => t('Show None'), + ), + ); + } + + /** + * Provide a simple textfield for equality + */ + function exposed_form(&$form, &$form_state) { + if (isset($this->options['expose']['identifier'])) { + $key = $this->options['expose']['identifier']; + $form[$key] = array( + '#type' => 'textfield', + '#size' => 15, + '#default_value' => $this->value, + '#attributes' => array('title' => t('Enter the terms you wish to search for.')), + ); + } + } + + /** + * Validate the options form. + */ + function exposed_validate(&$form, &$form_state) { + if (!isset($this->options['expose']['identifier'])) { + return; + } + + $key = $this->options['expose']['identifier']; + if (!empty($form_state['values'][$key])) { + $this->search_query = search_parse_query($form_state['values'][$key]); + + if ($this->search_query[2] == '') { + form_set_error($key, t('You must include at least one positive keyword with @count characters or more.', array('@count' => variable_get('minimum_word_size', 3)))); + } + if ($this->search_query[6]) { + if ($this->search_query[6] == 'or') { + drupal_set_message(t('Search for either of the two terms with uppercase OR. For example, cats OR dogs.')); + } + } + } + } + + /** + * Add this filter to the query. + * + * Due to the nature of fapi, the value and the operator have an unintended + * level of indirection. You will find them in $this->operator + * and $this->value respectively. + */ + function query() { + if (!isset($this->search_query) || empty($this->search_query[3])) { + if ($this->operator == 'required') { + $this->query->add_where($this->options['group'], 'FALSE'); + } + } + else { + $search_index = $this->ensure_my_table(); + $this->search_query[2] = str_replace('i.', "$search_index.", $this->search_query[2]); + + // Create a new join to relate the 'serach_total' table to our current 'search_index' table. + $join = new views_join; + $join->construct('search_total', $search_index, 'word', 'word'); + $search_total = $this->query->add_relationship('search_total', $join, $search_index); + + $this->search_score = $this->query->add_field('', "SUM($search_index.score * $search_total.count)", 'score', array('aggregate' => TRUE)); + + $this->query->add_where($this->options['group'], $this->search_query[2], $this->search_query[3]); + + if (empty($this->query->relationships[$this->relationship])) { + $base_table = $this->query->base_table; + } + else { + $base_table = $this->query->relationships[$this->relationship]['base']; + } + $this->query->add_where($this->options['group'], "$search_index.type = '%s'", $base_table); + if (!$this->search_query[5]) { + $search_dataset = $this->query->add_table('search_dataset'); + $this->search_query[0] = str_replace('d.', "$search_dataset.", $this->search_query[0]); + $this->query->add_where($this->options['group'], $this->search_query[0], $this->search_query[1]); + } + + $this->query->add_groupby("$search_index.sid"); + $this->query->add_having($this->options['group'], 'COUNT(*) >= %d', $this->search_query[4]); + } + } +} diff --git a/sites/all/modules/views/modules/search/views_handler_sort_search_score.inc b/sites/all/modules/views/modules/search/views_handler_sort_search_score.inc new file mode 100644 index 0000000..90c99ea --- /dev/null +++ b/sites/all/modules/views/modules/search/views_handler_sort_search_score.inc @@ -0,0 +1,24 @@ +search_score -- and we also + // need to check its relationship to make sure that we're using the same + // one or obviously this won't work. + foreach ($this->view->filter as $handler) { + if (isset($handler->search_score) && $handler->relationship == $this->relationship) { + $this->query->add_orderby(NULL, NULL, $this->options['order'], $handler->search_score); + $this->table_alias = $handler->table_alias; + return; + } + } + + // Do absolutely nothing if there is no filter in place; there is no reason to + // sort on the raw scores with this handler. + } +} + diff --git a/sites/all/modules/views/modules/search/views_plugin_row_search_view.inc b/sites/all/modules/views/modules/search/views_plugin_row_search_view.inc new file mode 100644 index 0000000..f95540a --- /dev/null +++ b/sites/all/modules/views/modules/search/views_plugin_row_search_view.inc @@ -0,0 +1,33 @@ + TRUE); + + return $options; + } + + function options_form(&$form, &$form_state) { + $form['score'] = array( + '#type' => 'checkbox', + '#title' => t('Display score'), + '#default_value' => $this->options['score'], + ); + } + + /** + * Override the behavior of the render() function. + */ + function render($row) { + return theme($this->theme_functions(), $this->view, $this->options, $row); + } +} diff --git a/sites/all/modules/views/modules/statistics.views.inc b/sites/all/modules/views/modules/statistics.views.inc new file mode 100644 index 0000000..2148f8b --- /dev/null +++ b/sites/all/modules/views/modules/statistics.views.inc @@ -0,0 +1,267 @@ + array( + 'left_field' => 'nid', + 'field' => 'nid', + ), + ); + + // totalcount + $data['node_counter']['totalcount'] = array( + 'title' => t('Total views'), + 'help' => t('The total number of times the node has been viewed.'), + + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // daycount + $data['node_counter']['daycount'] = array( + 'title' => t('Views today'), + 'help' => t('The total number of times the node has been viewed today.'), + + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // timestamp + $data['node_counter']['timestamp'] = array( + 'title' => t('Most recent view'), + 'help' => t('The most recent time the node has been viewed.'), + + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + + // ---------------------------------------------------------------- + // accesslog table + + $data['accesslog']['table']['group'] = t('Access log'); + + // Advertise this table as a possible base table + $data['accesslog']['table']['base'] = array( + 'field' => 'aid', + 'title' => t('Access log'), + 'help' => t('Stores site access information.'), + 'weight' => 10, + ); + + // For other base tables, explain how we join + $data['accesslog']['table']['join'] = array( + 'users' => array( + 'field' => 'uid', + 'left_field' => 'uid', + ), + ); + + // session id + $data['accesslog']['sid'] = array( + 'title' => t('Session ID'), + 'help' => t('Browser session ID of user that visited page.'), + + 'field' => array( + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // title + $data['accesslog']['title'] = array( + 'title' => t('Page title'), + 'help' => t('Title of page visited.'), + + 'field' => array( + 'handler' => 'views_handler_field_accesslog_path', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // path + $data['accesslog']['path'] = array( + 'title' => t('Path'), + 'help' => t('Internal path to page visited (relative to Drupal root.)'), + + 'field' => array( + 'handler' => 'views_handler_field_accesslog_path', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + //No argument here. Can't send forward slashes as arguments. + //Can be worked around by node ID. + //(but what about aliases?) + ); + + // referrer + $data['accesslog']['url'] = array( + 'title' => t('Referrer'), + 'help' => t('Referrer URI.'), + 'field' => array( + 'handler' => 'views_handler_field_url', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // hostname + $data['accesslog']['hostname'] = array( + 'title' => t('Hostname'), + 'help' => t('Hostname of user that visited the page.'), + 'field' => array( + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // user + $data['accesslog']['uid'] = array( + 'title' => t('User'), + 'help' => t('The user who visited the site.'), + 'relationship' => array( + 'handler' => 'views_handler_relationship', + 'base' => 'users', + 'base field' => 'uid', + ), + ); + + // timer + $data['accesslog']['timer'] = array( + 'title' => t('Timer'), + 'help' => t('Time in milliseconds that the page took to load.'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // timestamp + $data['accesslog']['timestamp'] = array( + 'title' => t('Timestamp'), + 'help' => t('Timestamp of when the page was visited.'), + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + ); + + + return $data; +} + +/** + * Implementation of hook_views_handlers() to register all of the basic handlers + * views uses. + */ +function statistics_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/modules/statistics', + ), + 'handlers' => array( + 'views_handler_field_accesslog_path' => array( + 'parent' => 'views_handler_field', + ), + ), + ); +} + +/** + * @} + */ diff --git a/sites/all/modules/views/modules/statistics.views_convert.inc b/sites/all/modules/views/modules/statistics.views_convert.inc new file mode 100644 index 0000000..35007b9 --- /dev/null +++ b/sites/all/modules/views/modules/statistics.views_convert.inc @@ -0,0 +1,51 @@ +add_item() won't produce + * the right results, usually needed to set field options or values. + */ +function statistics_views_convert($display, $type, &$view, $field, $id = NULL) { + switch ($type) { + case 'field': + switch ($field['tablename']) { + case 'node_counter': + switch ($field['field']) { + case 'timestamp': + $handlers = array( + 'views_handler_field_date_small' => 'small', + 'views_handler_field_date' => 'medium', + 'views_handler_field_date_large' => 'large', + 'views_handler_field_date_custom' => 'custom', + 'views_handler_field_since' => 'time ago', + ); + $view->set_item_option($display, 'field', $id, 'date_format', $handlers[$field['handler']]); + if (!empty($field['options'])) { + $view->set_item_option($display, 'field', $id, 'custom_date_format', $field['options']); + } + break; + } + break; + } + break; + case 'sort': + switch ($field['tablename']) { + case 'node_counter': + switch ($field['field']) { + case 'timestamp': + $field['options'] = $field['options'] == 'normal' ? 'second' : $field['options']; + $view->set_item_option($display, 'sort', $id, 'granularity', $field['options']); + break; + } + break; + } + break; + } +} diff --git a/sites/all/modules/views/modules/statistics.views_default.inc b/sites/all/modules/views/modules/statistics.views_default.inc new file mode 100644 index 0000000..7283033 --- /dev/null +++ b/sites/all/modules/views/modules/statistics.views_default.inc @@ -0,0 +1,302 @@ +name = 'popular'; + $view->description = 'Shows the most-viewed nodes on the site. This requires the statistics to be enabled at administer >> reports >> access log settings.'; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->api_version = 2; + $view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */ + $handler = $view->new_display('default', 'Defaults', 'default'); + $handler->override_option('fields', array( + 'type' => array( + 'id' => 'type', + 'table' => 'node', + 'field' => 'type', + 'label' => 'Type', + ), + 'title' => array( + 'id' => 'title', + 'table' => 'node', + 'field' => 'title', + 'label' => 'Title', + 'link_to_node' => TRUE, + ), + 'name' => array( + 'id' => 'name', + 'table' => 'users', + 'field' => 'name', + 'label' => 'Author', + 'link_to_user' => TRUE, + ), + 'timestamp' => array( + 'id' => 'timestamp', + 'table' => 'history_user', + 'field' => 'timestamp', + 'label' => '', + 'comments' => 1, + 'relationship' => 'none', + 'link_to_node' => 0, + 'comment' => 1, + ), + )); + $handler->override_option('sorts', array( + 'totalcount' => array( + 'id' => 'totalcount', + 'table' => 'node_counter', + 'field' => 'totalcount', + 'order' => 'DESC', + 'relationship' => 'none', + ), + )); + $handler->override_option('filters', array( + 'status' => array( + 'id' => 'status', + 'table' => 'node', + 'field' => 'status', + 'operator' => '=', + 'value' => '1', + 'group' => 0, + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + ), + 'totalcount' => array( + 'id' => 'totalcount', + 'table' => 'node_counter', + 'field' => 'totalcount', + 'operator' => '>', + 'value' => array( + 'value' => '0', + 'min' => '', + 'max' => '', + ), + 'group' => 0, + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + 'relationship' => 'none', + ), + )); + $handler->override_option('access', array( + 'type' => 'perm', + 'role' => array(), + 'perm' => 'access content', + )); + $handler->override_option('title', 'Popular content'); + $handler->override_option('items_per_page', '25'); + $handler->override_option('use_pager', TRUE); + $handler->override_option('use_more', 1); + $handler->override_option('style_plugin', 'table'); + $handler->override_option('style_options', array( + 'override' => 0, + 'order' => 'desc', + 'columns' => array( + 'type' => 'type', + 'title' => 'title', + 'name' => 'name', + 'timestamp' => 'title', + 'totalcount' => 'totalcount', + ), + 'info' => array( + 'type' => array( + 'sortable' => 0, + 'separator' => '', + ), + 'title' => array( + 'sortable' => 0, + 'separator' => '', + ), + 'name' => array( + 'sortable' => 0, + 'separator' => '', + ), + 'timestamp' => array( + 'separator' => '', + ), + 'totalcount' => array( + 'sortable' => 0, + 'separator' => '', + ), + ), + 'default' => '-1', + )); + $handler = $view->new_display('page', 'Popular (page)', 'page'); + $handler->override_option('path', 'popular/all'); + $handler->override_option('menu', array( + 'type' => 'default tab', + 'title' => 'Popular content', + 'weight' => '-1', + )); + $handler->override_option('tab_options', array( + 'type' => 'normal', + 'title' => 'Popular content', + 'weight' => '', + )); + $handler = $view->new_display('page', 'Today (page)', 'page_1'); + $handler->override_option('fields', array( + 'type' => array( + 'id' => 'type', + 'table' => 'node', + 'field' => 'type', + 'label' => 'Type', + ), + 'title' => array( + 'id' => 'title', + 'table' => 'node', + 'field' => 'title', + 'label' => 'Title', + 'link_to_node' => TRUE, + ), + 'name' => array( + 'id' => 'name', + 'table' => 'users', + 'field' => 'name', + 'label' => 'Author', + 'link_to_user' => TRUE, + ), + 'timestamp' => array( + 'id' => 'timestamp', + 'table' => 'history_user', + 'field' => 'timestamp', + 'label' => '', + 'comments' => 1, + 'relationship' => 'none', + 'link_to_node' => 0, + 'comment' => 1, + ), + 'daycount' => array( + 'id' => 'daycount', + 'table' => 'node_counter', + 'field' => 'daycount', + 'label' => 'Views today', + 'set_precision' => FALSE, + 'precision' => 0, + 'decimal' => '.', + 'separator' => ',', + 'prefix' => '', + 'suffix' => '', + 'relationship' => 'none', + ), + )); + $handler->override_option('sorts', array( + 'daycount' => array( + 'id' => 'daycount', + 'table' => 'node_counter', + 'field' => 'daycount', + 'order' => 'DESC', + 'relationship' => 'none', + ), + )); + $handler->override_option('path', 'popular/today'); + $handler->override_option('menu', array( + 'type' => 'tab', + 'title' => 'Today\'s popular content', + 'weight' => '0', + )); + $handler->override_option('tab_options', array( + 'type' => 'normal', + 'title' => 'Popular content', + 'weight' => '0', + )); + $handler = $view->new_display('block', 'Popular (block)', 'block'); + $handler->override_option('fields', array( + 'title' => array( + 'id' => 'title', + 'table' => 'node', + 'field' => 'title', + 'label' => '', + 'link_to_node' => 1, + 'relationship' => 'none', + ), + 'totalcount' => array( + 'id' => 'totalcount', + 'table' => 'node_counter', + 'field' => 'totalcount', + 'label' => '', + 'set_precision' => FALSE, + 'precision' => 0, + 'decimal' => '.', + 'separator' => ',', + 'prefix' => ' (', + 'suffix' => ')', + 'relationship' => 'none', + ), + )); + $handler->override_option('items_per_page', 5); + $handler->override_option('style_plugin', 'list'); + $handler->override_option('style_options', array( + 'type' => 'ul', + )); + $handler->override_option('row_options', array( + 'inline' => array( + 'title' => 'title', + 'totalcount' => 'totalcount', + ), + 'separator' => '', + )); + $handler->override_option('block_description', 'Popular content'); + $handler = $view->new_display('block', 'Today (block)', 'block_1'); + $handler->override_option('fields', array( + 'title' => array( + 'id' => 'title', + 'table' => 'node', + 'field' => 'title', + 'label' => '', + 'link_to_node' => 1, + 'relationship' => 'none', + ), + 'daycount' => array( + 'id' => 'daycount', + 'table' => 'node_counter', + 'field' => 'daycount', + 'label' => '', + 'set_precision' => FALSE, + 'precision' => 0, + 'decimal' => '.', + 'separator' => ',', + 'prefix' => ' (', + 'suffix' => ')', + 'relationship' => 'none', + ), + )); + $handler->override_option('sorts', array( + 'daycount' => array( + 'id' => 'daycount', + 'table' => 'node_counter', + 'field' => 'daycount', + 'order' => 'DESC', + 'relationship' => 'none', + ), + )); + $handler->override_option('title', 'Today\'s popular content'); + $handler->override_option('items_per_page', 5); + $handler->override_option('link_display', 'page_1'); + $handler->override_option('style_plugin', 'list'); + $handler->override_option('style_options', array( + 'type' => 'ul', + )); + $handler->override_option('row_options', array( + 'inline' => array( + 'title' => 'title', + 'daycount' => 'daycount', + ), + 'separator' => '', + )); + $handler->override_option('block_description', 'Today\'s popular content'); + $views[$view->name] = $view; + + return $views; +} diff --git a/sites/all/modules/views/modules/statistics/views_handler_field_accesslog_path.inc b/sites/all/modules/views/modules/statistics/views_handler_field_accesslog_path.inc new file mode 100644 index 0000000..5a2cd42 --- /dev/null +++ b/sites/all/modules/views/modules/statistics/views_handler_field_accesslog_path.inc @@ -0,0 +1,45 @@ +options['display_as_link'])) { + $this->additional_fields['path'] = 'path'; + } + } + + function option_definition() { + $options = parent::option_definition(); + + $options['display_as_link'] = array('default' => TRUE); + + return $options; + } + + /** + * Provide link to the page being visited. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['display_as_link'] = array( + '#title' => t('Display as link'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['display_as_link']), + ); + } + + function render($values) { + $title = check_plain($values->{$this->field_alias}); + if (!empty($this->options['display_as_link'])) { + return l($title, $values->{$this->aliases['path']}, array('html' => TRUE)); + } + else { + return $title; + } + } +} diff --git a/sites/all/modules/views/modules/system.views.inc b/sites/all/modules/views/modules/system.views.inc new file mode 100644 index 0000000..1894d41 --- /dev/null +++ b/sites/all/modules/views/modules/system.views.inc @@ -0,0 +1,229 @@ + 'fid', + 'title' => t('File'), + 'help' => t("Files maintained by Drupal and various modules."), + ); + + // The files table does not inherently join to the node table, + // but may things (such as upload.module) can add relationships + // that allow file fields to be used. + + // For other base tables, explain how we join + $data['files']['table']['join'] = array( + 'users' => array( + // direct join to the users table via 'uid' field. + 'left_field' => 'uid', + 'field' => 'uid', + ), + ); + + // fid + $data['files']['fid'] = array( + 'title' => t('File ID'), + 'help' => t('The ID of the file.'), + 'field' => array( + 'handler' => 'views_handler_field_file', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'handler' => 'views_handler_argument_file_fid', + 'name field' => 'filename', // the field to display in the summary. + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // filename + $data['files']['filename'] = array( + 'title' => t('Name'), + 'help' => t('The name of the file.'), + 'field' => array( + 'handler' => 'views_handler_field_file', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // filepath + $data['files']['filepath'] = array( + 'title' => t('Path'), + 'help' => t('The path of the file.'), + 'field' => array( + 'handler' => 'views_handler_field_file', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // filemime + $data['files']['filemime'] = array( + 'title' => t('Mime type'), + 'help' => t('The mime type of the file.'), + 'field' => array( + 'handler' => 'views_handler_field_file', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // filesize + $data['files']['filesize'] = array( + 'title' => t('Size'), + 'help' => t('The size of the file.'), + 'field' => array( + 'handler' => 'views_handler_field_file_size', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + ); + + // status + $data['files']['status'] = array( + 'title' => t('Status'), + 'help' => t('The status of the file.'), + 'field' => array( + 'handler' => 'views_handler_field_file_status', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_file_status', + ), + ); + + // timestamp field + $data['files']['timestamp'] = array( + 'title' => t('Upload date'), + 'help' => t('The date the file was uploaded.'), + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + ); + + // uid field + $data['files']['uid'] = array( + 'title' => t('User'), + 'help' => t('The user, who uploaded the file.'), + 'relationship' => array( + 'base' => 'users', + 'base field' => 'uid', + 'handler' => 'views_handler_relationship', + 'label' => t('User'), + ), + ); + + + return $data; +} + +/** + * Implementation of hook_views_handlers() to register all of the basic handlers + * views uses. + */ +function system_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/modules/system', + ), + 'handlers' => array( + 'views_handler_field_file' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_file_status' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_filter_file_status' => array( + 'parent' => 'views_handler_filter_in_operator', + ), + 'views_handler_argument_file_fid' => array( + 'parent' => 'views_handler_argument', + ), + ), + ); +} + +function _views_file_status($choice = NULL) { + $status = array( + FILE_STATUS_TEMPORARY => t('Temporary'), + FILE_STATUS_PERMANENT => t('Permanent'), + ); + + if (isset($choice)) { + return isset($status[$choice]) ? $status[$choice] : t('Unknown'); + } + + return $status; +} + + +/** + * @} + */ diff --git a/sites/all/modules/views/modules/system/views_handler_argument_file_fid.inc b/sites/all/modules/views/modules/system/views_handler_argument_file_fid.inc new file mode 100644 index 0000000..755e0a3 --- /dev/null +++ b/sites/all/modules/views/modules/system/views_handler_argument_file_fid.inc @@ -0,0 +1,17 @@ +argument))); + if (empty($title)) { + return t('No title'); + } + + return check_plain($title); + } +} diff --git a/sites/all/modules/views/modules/system/views_handler_field_file.inc b/sites/all/modules/views/modules/system/views_handler_field_file.inc new file mode 100644 index 0000000..0c5f4b2 --- /dev/null +++ b/sites/all/modules/views/modules/system/views_handler_field_file.inc @@ -0,0 +1,52 @@ +additional_fields['filepath'] = 'filepath'; + } + } + + function option_definition() { + $options = parent::option_definition(); + $options['link_to_file'] = array('default' => FALSE); + return $options; + } + + /** + * Provide link to file option + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_file'] = array( + '#title' => t('Link this field to download the file'), + '#description' => t('This will override any other link you have set.'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['link_to_file']), + ); + } + + /** + * Render whatever the data is as a link to the file. + * + * Data should be made XSS safe prior to calling this function. + */ + function render_link($data, $values) { + if (!empty($this->options['link_to_file']) && $data !== NULL && $data !== '') { + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = file_create_url($values->{$this->aliases['filepath']}); + } + + return $data; + } + + function render($values) { + return $this->render_link(check_plain($values->{$this->field_alias}), $values); + } +} diff --git a/sites/all/modules/views/modules/system/views_handler_field_file_status.inc b/sites/all/modules/views/modules/system/views_handler_field_file_status.inc new file mode 100644 index 0000000..e4bbcc8 --- /dev/null +++ b/sites/all/modules/views/modules/system/views_handler_field_file_status.inc @@ -0,0 +1,10 @@ +{$this->field_alias}); + } +} + diff --git a/sites/all/modules/views/modules/system/views_handler_filter_file_status.inc b/sites/all/modules/views/modules/system/views_handler_filter_file_status.inc new file mode 100644 index 0000000..16dce1b --- /dev/null +++ b/sites/all/modules/views/modules/system/views_handler_filter_file_status.inc @@ -0,0 +1,12 @@ +value_options)) { + $this->value_options = _views_file_status(); + } + } +} + diff --git a/sites/all/modules/views/modules/taxonomy.views.inc b/sites/all/modules/views/modules/taxonomy.views.inc new file mode 100644 index 0000000..5a243b2 --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy.views.inc @@ -0,0 +1,499 @@ + array( + 'left_field' => 'vid', + 'field' => 'vid', + ), + // vocabulary links to node through term_data via vid + 'node' => array( + 'left_table' => 'term_data', + 'left_field' => 'vid', + 'field' => 'vid', + ), + // vocabulary links to node_revision via term_data + 'node_revision' => array( + 'left_table' => 'term_data', + 'left_field' => 'vid', + 'field' => 'vid', + ), + ); + + // vocabulary name + $data['vocabulary']['name'] = array( + 'title' => t('Vocabulary name'), // The item it appears as on the UI, + 'field' => array( + 'help' => t('Name of the vocabulary a term is a member of. This will be the vocabulary that whichever term the "Taxonomy: Term" field is; and can similarly cause duplicates.'), + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + ); + $data['vocabulary']['vid'] = array( + 'title' => t('Vocabulary ID'), // The item it appears as on the UI, + 'help' => t('The taxonomy vocabulary ID'), + 'argument' => array( + 'handler' => 'views_handler_argument_vocabulary_vid', + 'name field' => 'name', + ), + ); + + // ---------------------------------------------------------------------- + // term_data table + + $data['term_data']['table']['group'] = t('Taxonomy'); + $data['term_data']['table']['base'] = array( + 'field' => 'tid', + 'title' => t('Term'), + 'help' => t('Taxonomy terms are attached to nodes.'), + ); + + + // The term data table + $data['term_data']['table']['join'] = array( + 'node' => array( + 'left_table' => 'term_node', + 'left_field' => 'tid', + 'field' => 'tid', + ), + 'node_revision' => array( + 'left_table' => 'term_node', + 'left_field' => 'tid', + 'field' => 'tid', + ), + // This is provided for many_to_one argument + 'term_node' => array( + 'field' => 'tid', + 'left_field' => 'tid', + ), + ); + + // tid field + $data['term_data']['tid'] = array( + 'title' => t('Term ID'), + 'help' => t('The taxonomy term ID'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + 'name field' => 'name', + 'skip base' => array('node', 'node_revision'), + 'zero is null' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_term_node_tid', + 'hierarchy table' => 'term_hierarchy', + 'numeric' => TRUE, + 'skip base' => array('node', 'node_revision'), + ), + ); + + // Term name field + $data['term_data']['name'] = array( + 'title' => t('Term'), + 'help' => t('Taxonomy terms. Note that using this can cause duplicate nodes to appear in views; you must add filters to reduce the result set.'), + 'field' => array( + 'handler' => 'views_handler_field_taxonomy', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + 'help' => t('Taxonomy term name.'), + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + 'help' => t('Taxonomy term name.'), + 'many to one' => TRUE, + 'empty field name' => t('Uncategorized'), + ), + ); + + // taxonomy weight + $data['term_data']['weight'] = array( + 'title' => t('Weight'), + 'help' => t('The term weight field'), + 'field' => array( + 'handler' => 'views_handler_field', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // Term description + $data['term_data']['description'] = array( + 'title' => t('Term description'), // The item it appears as on the UI, + 'help' => t('The description associated with a taxonomy term.'), + 'field' => array( + 'field' => 'description', // the real field + 'group' => t('Taxonomy'), // The group it appears in on the UI, + 'handler' => 'views_handler_field_markup', + 'format' => FILTER_FORMAT_DEFAULT, + ), + ); + + // Term vocabulary + $data['term_data']['vid'] = array( + 'title' => t('Vocabulary'), + 'help' => t('Filter the results of "Taxonomy: Term" to a particular vocabulary.'), + 'filter' => array( + 'handler' => 'views_handler_filter_vocabulary_vid', + ), + ); + + // ---------------------------------------------------------------------- + // term_node table + + $data['term_node']['table']['group'] = t('Taxonomy'); + + $data['term_node']['table']['join'] = array( + 'term_data' => array( + // links directly to term_data via tid + 'left_field' => 'tid', + 'field' => 'tid', + ), + 'node' => array( + // links directly to node via vid + 'left_field' => 'vid', + 'field' => 'vid', + ), + 'node_revisions' => array( + // links directly to node_revisions via vid + 'left_field' => 'vid', + 'field' => 'vid', + ), + 'term_hierarchy' => array( + 'left_field' => 'tid', + 'field' => 'tid', + ), + ); + + $data['term_node']['vid'] = array( + 'title' => t('Node'), + 'help' => t('Get all nodes tagged with a term.'), + 'relationship' => array( + 'handler' => 'views_handler_relationship', + 'base' => 'node', + 'base field' => 'vid', + 'label' => t('node'), + ), + ); + + // tid field + $data['term_node']['tid'] = array( + 'title' => t('Term ID'), + 'help' => t('The taxonomy term ID'), + 'field' => array( + 'title' => t('All terms'), + 'help' => t('Display all taxonomy terms associated with a node from specified vocabularies.'), + 'handler' => 'views_handler_field_term_node_tid', + 'skip base' => 'term_data', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_term_node_tid', + 'name table' => 'term_data', + 'name field' => 'name', + 'empty field name' => t('Uncategorized'), + 'numeric' => TRUE, + 'skip base' => 'term_data', + ), + 'filter' => array( + 'title' => t('Term'), + 'handler' => 'views_handler_filter_term_node_tid', + 'hierarchy table' => 'term_hierarchy', + 'numeric' => TRUE, + 'skip base' => 'term_data', + 'allow empty' => TRUE, + ), + ); + + // term_relation + + $data['term_relation']['table']['group'] = t('Taxonomy'); + + $data['term_relation']['table']['join'] = array( + 'term_data' => array( + // links directly to term_data via tid + 'left_field' => 'tid', + 'field' => 'tid1', + ), + 'term_relation' => array( + // links to self through left.tid1 = right.tid2 + 'left_field' => 'tid1', + 'field' => 'tid2', + ), + 'node' => array( + 'left_table' => 'term_node', + 'left_field' => 'tid', + 'field' => 'tid1', + ), + 'node_revisions' => array( + 'left_table' => 'term_node', + 'left_field' => 'tid', + 'field' => 'tid1', + ), + ); + + $data['term_relation']['tid2'] = array( + 'title' => t('Related terms'), + 'help' => t('The related terms of the term. This can produce duplicate entries if there is more than one related term.'), + 'relationship' => array( + 'base' => 'term_data', + 'field' => 'tid2', + 'label' => t('Related term'), + ), + 'argument' => array( + 'help' => t('A related term of the term.'), + 'handler' => 'views_handler_argument_numeric', + ), + ); + + // ---------------------------------------------------------------------- + // term_hierarchy table + + $data['term_hierarchy']['table']['group'] = t('Taxonomy'); + + $data['term_hierarchy']['table']['join'] = array( + 'term_hierarchy' => array( + // links to self through left.parent = right.tid (going down in depth) + 'left_field' => 'tid', + 'field' => 'parent', + ), + 'term_data' => array( + // links directly to term_data via tid + 'left_field' => 'tid', + 'field' => 'tid', + ), + 'node' => array( + // links to node thorugh term_data + 'left_table' => 'term_data', + 'left_field' => 'tid', + 'field' => 'tid', + ), + 'node_revisions' => array( + // links to node_revisions thorugh term_data + 'left_table' => 'term_data', + 'left_field' => 'tid', + 'field' => 'tid', + ), + ); + + $data['term_hierarchy']['parent'] = array( + 'title' => t('Parent term'), + 'help' => t('The parent term of the term. This can produce duplicate entries if you are using a vocabulary that allows multiple parents.'), + 'relationship' => array( + 'base' => 'term_data', + 'field' => 'parent', + 'label' => t('Parent'), + ), + 'argument' => array( + 'help' => t('The parent term of the term.'), + 'handler' => 'views_handler_argument_numeric', + ), + ); + + // ---------------------------------------------------------------------- + // term_synonym table + + $data['term_synonym']['table']['group'] = t('Taxonomy'); + + $data['term_synonym']['table']['join'] = array( + 'term_data' => array( + // links directly to term_data via tid + 'left_field' => 'tid', + 'field' => 'tid', + ), + 'node' => array( + 'left_table' => 'term_node', + 'left_field' => 'tid', + 'field' => 'tid', + ), + 'node_revisions' => array( + 'left_table' => 'term_node', + 'left_field' => 'tid', + 'field' => 'tid', + ), + ); + + $data['term_synonym']['name'] = array( + 'title' => t('Term synonym'), + 'help' => t('Term synonyms may be used to find terms by alternate names.'), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + 'many to one' => TRUE, + 'empty field name' => t('Uncategorized'), + ), + ); + return $data; +} + +/** + * Implementation of hook_views_data_alter(). + */ +function taxonomy_views_data_alter(&$data) { + $data['node']['term_node_tid'] = array( + 'group' => t('Taxonomy'), + 'title' => t('Terms on node'), + 'help' => t('Relate nodes to taxonomy terms, specifiying which vocabulary or vocabularies to use. This relationship will cause duplicated records if there are multiple terms.'), + 'relationship' => array( + 'handler' => 'views_handler_relationship_node_term_data', + 'label' => t('term'), + 'base' => 'term_data', + ), + ); + + $data['node']['term_node_tid_depth'] = array( + 'group' => t('Taxonomy'), + 'title' => t('Term ID (with depth)'), + 'help' => t('The depth filter is more complex, so provides fewer options.'), + 'real field' => 'vid', + 'argument' => array( + 'handler' => 'views_handler_argument_term_node_tid_depth', + 'accept depth modifier' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_term_node_tid_depth', + ), + ); + + $data['node']['term_node_tid_depth_modifier'] = array( + 'group' => t('Taxonomy'), + 'title' => t('Term ID depth modifier'), + 'help' => t('Allows the "depth" for Taxonomy: Term ID (with depth) to be modified via an additional argument.'), + 'argument' => array( + 'handler' => 'views_handler_argument_term_node_tid_depth_modifier', + ), + ); +} + +/** + * Implementation of hook_views_handlers() to register all of the basic handlers + * views uses. + */ +function taxonomy_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy', + ), + 'handlers' => array( + 'views_handler_argument_term_node_tid_depth' => array( + 'parent' => 'views_handler_argument', + ), + 'views_handler_argument_term_node_tid_depth_modifier' => array( + 'parent' => 'views_handler_argument', + ), + 'views_handler_argument_taxonomy' => array( + 'parent' => 'views_handler_argument', + ), + 'views_handler_argument_vocabulary_vid' => array( + 'parent' => 'views_handler_argument', + ), + 'views_handler_argument_term_node_tid' => array( + 'parent' => 'views_handler_argument_many_to_one', + ), + 'views_handler_field_term_node_tid' => array( + 'parent' => 'views_handler_field_prerender_list', + ), + 'views_handler_field_taxonomy' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_filter_vocabulary_vid' => array( + 'parent' => 'views_handler_filter_in_operator', + ), + 'views_handler_filter_term_node_tid' => array( + 'parent' => 'views_handler_filter_many_to_one', + ), + 'views_handler_filter_term_node_tid_depth' => array( + 'parent' => 'views_handler_filter_term_node_tid', + ), + 'views_handler_relationship_node_term_data' => array( + 'parent' => 'views_handler_relationship', + ), + ), + ); +} + +/** + * Implementation of hook_views_plugins + */ +function taxonomy_views_plugins() { + return array( + 'module' => 'views', // This just tells our themes are elsewhere. + 'argument validator' => array( + 'taxonomy_term' => array( + 'title' => t('Taxonomy term'), + 'handler' => 'views_plugin_argument_validate_taxonomy_term', + 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy', + ), + ), + 'argument default' => array( + 'taxonomy_tid' => array( + 'title' => t('Taxonomy Term ID from URL'), + 'handler' => 'views_plugin_argument_default_taxonomy_tid', + 'path' => drupal_get_path('module', 'views') . '/modules/taxonomy', + 'parent' => 'fixed', + ), + ), + ); +} + +/** + * Helper function to set a breadcrumb for taxonomy. + */ +function views_taxonomy_set_breadcrumb(&$breadcrumb, &$argument) { + if (empty($argument->options['set_breadcrumb'])) { + return; + } + + $args = $argument->view->args; + $parents = taxonomy_get_parents_all($argument->argument); + foreach (array_reverse($parents) as $parent) { + // Unfortunately parents includes the current argument. Skip. + if ($parent->tid == $argument->argument) { + continue; + } + if ($argument->options['use_taxonomy_term_path']) { + $path = taxonomy_term_path($parent); + } + else { + $args[$argument->position] = $parent->tid; + $path = $argument->view->get_url($args); + } + $breadcrumb[$path] = check_plain($parent->name); + } +} + +/** + * @} + */ diff --git a/sites/all/modules/views/modules/taxonomy.views_convert.inc b/sites/all/modules/views/modules/taxonomy.views_convert.inc new file mode 100644 index 0000000..5272a43 --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy.views_convert.inc @@ -0,0 +1,102 @@ +add_item() won't produce + * the right results, usually needed to set field options or values. + */ +function taxonomy_views_convert($display, $type, &$view, $field, $id = NULL) { + switch ($type) { + case 'field': + $matches = array(); + if (preg_match('/term_node(_(\d+))?/', $field['tablename'], $matches)) { + switch ($field['field']) { + case 'name': + $item = $view->get_item($display, 'field', $id); + $item['table'] = 'term_node'; + $item['field'] = 'tid'; + if ($field['options'] != 'nolink') { + $item['link_to_taxonomy'] = TRUE; + } + if (!empty($field['vocabulary'])) { + $item['limit'] = TRUE; + $item['vids'] = array($field['vocabulary']); + } + // The vocabulary ID might be embedded in the table name. + elseif (!empty($matches[2])) { + $item['limit'] = TRUE; + $item['vids'] = array($matches[2]); + } + $view->set_item($display, 'field', $id, $item); + break; + } + } + elseif ($field['tablename'] == 'term_data') { + switch ($field['field']) { + case 'name': + if ($field['field'] == 'views_handler_field_tid_link') { + $view->set_item_option($display, 'field', $id, 'link_to_taxonomy', TRUE); + } + break; + } + } + break; + case 'filter': + if ($field['tablename'] == 'term_node' || !strncmp($field['tablename'], 'term_node_', 10)) { + switch ($field['field']) { + case 'tid': + $operators = array('AND' => 'and', 'OR' => 'or', 'NOR' => 'not'); + $item = $view->get_item($display, 'filter', $id); + if ($vid = (integer) substr($field['tablename'], 10)) { + $item['table'] = 'term_node'; + $item['vid'] = $vid; + } + else { + $item['limit'] = FALSE; + } + $item['operator'] = $operators[$field['operator']]; + $item['type'] = 'select'; + $view->set_item($display, 'filter', $id, $item); + break; + } + } + elseif ($field['tablename'] == 'term_data') { + switch ($field['field']) { + case 'vid': + $operators = array('AND' => 'in', 'OR' => 'in', 'NOR' => 'not in'); + $view->set_item_option($display, 'filter', $id, 'operator', $operators[$field['operator']]); + break; + } + } + break; + case 'argument': + $options = $field['argoptions']; + switch ($field['type']) { + case 'taxid': + if (!empty($field['options'])) { + $options['depth'] = $field['options']; + } + $options['break_phrase'] = TRUE; + $view->add_item($display, 'argument', 'node', 'term_node_tid_depth', $options, $field['id']); + break; + case 'taxletter': + if (!empty($field['options'])) { + $options['glossary'] = TRUE; + $options['limit'] = $field['options']; + } + $view->add_item($display, 'argument', 'term_data', 'name', $options, $field['id']); + break; + case 'vocid': + $view->add_item($display, 'argument', 'vocabulary', 'vid', $options, $field['id']); + break; + } + break; + } +} diff --git a/sites/all/modules/views/modules/taxonomy.views_default.inc b/sites/all/modules/views/modules/taxonomy.views_default.inc new file mode 100644 index 0000000..1313240 --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy.views_default.inc @@ -0,0 +1,182 @@ +name = 'taxonomy_term'; + $view->description = 'A view to emulate Drupal core\'s handling of taxonomy/term; it also emulates Views 1\'s handling by having two possible feeds.'; + $view->tag = 'default'; + $view->base_table = 'node'; + $view->api_version = 2; + $view->disabled = TRUE; /* Edit this to true to make a default view disabled initially */ + $handler = $view->new_display('default', 'Defaults', 'default'); + $handler->override_option('sorts', array( + 'sticky' => array( + 'id' => 'sticky', + 'table' => 'node', + 'field' => 'sticky', + 'order' => 'DESC', + 'relationship' => 'none', + ), + 'created' => array( + 'id' => 'created', + 'table' => 'node', + 'field' => 'created', + 'order' => 'DESC', + 'granularity' => 'second', + 'relationship' => 'none', + ), + )); + $handler->override_option('arguments', array( + 'term_node_tid_depth' => array( + 'id' => 'term_node_tid_depth', + 'table' => 'node', + 'field' => 'term_node_tid_depth', + 'default_action' => 'not found', + 'style_plugin' => 'default_summary', + 'style_options' => array( + 'count' => TRUE, + 'override' => FALSE, + 'items_per_page' => 25, + ), + 'wildcard' => 'all', + 'wildcard_substitution' => 'All', + 'title' => '%1', + 'default_argument_type' => 'fixed', + 'default_argument' => '', + 'validate_type' => 'taxonomy_term', + 'validate_fail' => 'not found', + 'depth' => '0', + 'break_phrase' => 1, + 'relationship' => 'none', + 'default_argument_fixed' => '', + 'default_argument_php' => '', + 'validate_argument_node_type' => array( + 'album' => 0, + 'artist' => 0, + 'book' => 0, + 'page' => 0, + 'story' => 0, + 'track' => 0, + ), + 'validate_argument_vocabulary' => array( + '3' => 0, + '4' => 0, + '1' => 0, + '5' => 0, + '2' => 0, + ), + 'validate_argument_type' => 'tids', + 'validate_argument_php' => '', + ), + 'term_node_tid_depth_modifier' => array( + 'id' => 'term_node_tid_depth_modifier', + 'table' => 'node', + 'field' => 'term_node_tid_depth_modifier', + 'default_action' => 'ignore', + 'style_plugin' => 'default_summary', + 'style_options' => array( + 'count' => TRUE, + 'override' => FALSE, + 'items_per_page' => 25, + ), + 'wildcard' => 'all', + 'wildcard_substitution' => 'All', + 'title' => '', + 'default_argument_type' => 'fixed', + 'default_argument' => '', + 'validate_type' => 'none', + 'validate_fail' => 'not found', + ), + )); + $handler->override_option('filters', array( + 'status_extra' => array( + 'id' => 'status_extra', + 'table' => 'node', + 'field' => 'status_extra', + 'operator' => '=', + 'value' => '', + 'group' => 0, + 'exposed' => FALSE, + 'expose' => array( + 'operator' => FALSE, + 'label' => '', + ), + 'relationship' => 'none', + ), + )); + $handler->override_option('access', array( + 'type' => 'perm', + 'role' => array(), + 'perm' => 'access content', + )); + $handler->override_option('use_pager', '1'); + $handler->override_option('row_plugin', 'node'); + $handler->override_option('row_options', array( + 'teaser' => TRUE, + 'links' => TRUE, + )); + $handler = $view->new_display('page', 'Page', 'page'); + $handler->override_option('path', 'taxonomy/term/%'); + $handler->override_option('menu', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler->override_option('tab_options', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler = $view->new_display('feed', 'Core feed', 'feed'); + $handler->override_option('items_per_page', 15); + $handler->override_option('use_pager', '1'); + $handler->override_option('row_plugin', 'node_rss'); + $handler->override_option('row_options', array( + 'item_length' => 'default', + )); + $handler->override_option('path', 'taxonomy/term/%/%/feed'); + $handler->override_option('menu', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler->override_option('tab_options', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler->override_option('displays', array( + 'page' => 'page', + 'default' => 0, + )); + $handler = $view->new_display('feed', 'Views 1 feed', 'feed_1'); + $handler->override_option('items_per_page', 15); + $handler->override_option('use_pager', '1'); + $handler->override_option('row_plugin', 'node_rss'); + $handler->override_option('row_options', array( + 'item_length' => 'default', + )); + $handler->override_option('path', 'taxonomy/term/%/feed'); + $handler->override_option('menu', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $handler->override_option('tab_options', array( + 'type' => 'none', + 'title' => '', + 'weight' => 0, + )); + $views[$view->name] = $view; + + return $views; +} + + diff --git a/sites/all/modules/views/modules/taxonomy/views_handler_argument_taxonomy.inc b/sites/all/modules/views/modules/taxonomy/views_handler_argument_taxonomy.inc new file mode 100644 index 0000000..9c9cf3e --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy/views_handler_argument_taxonomy.inc @@ -0,0 +1,19 @@ +argument); + if (!empty($term)) { + return check_plain($term->name); + } + // TODO review text + return t('No name'); + } +} diff --git a/sites/all/modules/views/modules/taxonomy/views_handler_argument_term_node_tid.inc b/sites/all/modules/views/modules/taxonomy/views_handler_argument_term_node_tid.inc new file mode 100644 index 0000000..966ff98 --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy/views_handler_argument_term_node_tid.inc @@ -0,0 +1,41 @@ + FALSE); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['set_breadcrumb'] = array( + '#type' => 'checkbox', + '#title' => t("Set the breadcrumb for the term parents"), + '#description' => t('If selected, the breadcrumb trail will include all parent terms, each one linking to this view. Note that this only works if just one term was received.'), + '#default_value' => !empty($this->options['set_breadcrumb']), + ); + } + + function set_breadcrumb(&$breadcrumb) { + if (empty($this->options['set_breadcrumb']) || !is_numeric($this->argument)) { + return; + } + + return views_taxonomy_set_breadcrumb($breadcrumb, $this); + } + + function title_query() { + $titles = array(); + $placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d')); + + $result = db_query("SELECT name FROM {term_data} WHERE tid IN ($placeholders)", $this->value); + while ($term = db_fetch_object($result)) { + $titles[] = check_plain($term->name); + } + return $titles; + } +} + diff --git a/sites/all/modules/views/modules/taxonomy/views_handler_argument_term_node_tid_depth.inc b/sites/all/modules/views/modules/taxonomy/views_handler_argument_term_node_tid_depth.inc new file mode 100644 index 0000000..50f993d --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy/views_handler_argument_term_node_tid_depth.inc @@ -0,0 +1,136 @@ + 0); + $options['break_phrase'] = array('default' => FALSE); + $options['set_breadcrumb'] = array('default' => FALSE); + $options['use_taxonomy_term_path'] = array('default' => FALSE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['depth'] = array( + '#type' => 'weight', + '#title' => t('Depth'), + '#default_value' => $this->options['depth'], + '#description' => t('The depth will match nodes tagged with terms in the hierarchy. For example, if you have the term "fruit" and a child term "apple", with a depth of 1 (or higher) then filtering for the term "fruit" will get nodes that are tagged with "apple" as well as "fruit". If negative, the reverse is true; searching for "apple" will also pick up nodes tagged with "fruit" if depth is -1 (or lower).'), + ); + + $form['break_phrase'] = array( + '#type' => 'checkbox', + '#title' => t('Allow multiple terms per argument'), + '#description' => t('If selected, users can enter multiple arguments in the form of 1+2+3. Due to the number of JOINs it would require, AND will be treated as OR with this argument.'), + '#default_value' => !empty($this->options['break_phrase']), + ); + + $form['set_breadcrumb'] = array( + '#type' => 'checkbox', + '#title' => t("Set the breadcrumb for the term parents"), + '#description' => t('If selected, the breadcrumb trail will include all parent terms, each one linking to this view. Note that this only works if just one term was received.'), + '#default_value' => !empty($this->options['set_breadcrumb']), + ); + + $form['use_taxonomy_term_path'] = array( + '#type' => 'checkbox', + '#title' => t("Use Drupal's taxonomy term path to create breadcrumb links"), + '#description' => t('If selected, the links in the breadcrumb trail will be created using the standard drupal method instead of the custom views method. This is useful if you are using modules like taxonomy redirect to modify your taxonomy term links.'), + '#default_value' => !empty($this->options['use_taxonomy_term_path']), + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-set-breadcrumb' => array(TRUE)), + ); + } + + function set_breadcrumb(&$breadcrumb) { + if (empty($this->options['set_breadcrumb']) || !is_numeric($this->argument)) { + return; + } + + return views_taxonomy_set_breadcrumb($breadcrumb, $this); + } + + /** + * Override default_actions() to remove summary actions. + */ + function default_actions($which = NULL) { + if ($which) { + if (in_array($which, array('ignore', 'not found', 'empty', 'default'))) { + return parent::default_actions($which); + } + return; + } + $actions = parent::default_actions(); + unset($actions['summary asc']); + unset($actions['summary desc']); + return $actions; + } + + function query() { + $this->ensure_my_table(); + + if (!empty($this->options['break_phrase'])) { + $tids = new stdClass(); + $tids->value = $this->argument; + $tids = views_break_phrase($this->argument, $tids); + if ($tids->value == -1) { + return FALSE; + } + + if (count($tids->value) > 1) { + $placeholder = " IN (" . implode(', ', array_fill(0, sizeof($tids->value), '%d')) . ")"; + } + else { + $placeholder = " = %d"; + } + + $tids = $tids->value; + } + else { + $placeholder = "= %d"; + $tids = array($this->argument); + } + $subquery = "\n SELECT tn.vid FROM {term_node} tn\n"; + $where = " WHERE tn.tid $placeholder\n"; + $args = $tids; + $last = "tn"; + + if ($this->options['depth'] > 0) { + $subquery .= " LEFT JOIN {term_hierarchy} th ON th.tid = tn.tid\n"; + $last = "th"; + foreach (range(1, abs($this->options['depth'])) as $count) { + $subquery .= " LEFT JOIN {term_hierarchy} th$count ON $last.parent = th$count.tid\n"; + $where .= " OR th$count.tid $placeholder\n"; + $args = array_merge($args, $tids); + $last = "th$count"; + } + } + else if ($this->options['depth'] < 0) { + foreach (range(1, abs($this->options['depth'])) as $count) { + $subquery .= " LEFT JOIN {term_hierarchy} th$count ON $last.tid = th$count.parent\n"; + $where .= " OR th$count.tid $placeholder\n"; + $args = array_merge($args, $tids); + $last = "th$count"; + } + } + + $this->query->add_where(0, "$this->table_alias.$this->real_field IN ($subquery$where )", $args); + } + + function title() { + $term = taxonomy_get_term($this->argument); + if (!empty($term)) { + return check_plain($term->name); + } + // TODO review text + return t('No name'); + } +} diff --git a/sites/all/modules/views/modules/taxonomy/views_handler_argument_term_node_tid_depth_modifier.inc b/sites/all/modules/views/modules/taxonomy/views_handler_argument_term_node_tid_depth_modifier.inc new file mode 100644 index 0000000..139bae2 --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy/views_handler_argument_term_node_tid_depth_modifier.inc @@ -0,0 +1,58 @@ +view->args[$this->position]) ? $this->view->args[$this->position] : NULL; + if (!is_numeric($argument)) { + return; + } + + if ($argument > 10) { + $argument = 10; + } + + if ($argument < -10) { + $argument = -10; + } + + // figure out which argument preceded us. + $keys = array_reverse(array_keys($this->view->argument)); + $skip = TRUE; + foreach ($keys as $key) { + if ($key == $this->options['id']) { + $skip = FALSE; + continue; + } + + if ($skip) { + continue; + } + + if (empty($this->view->argument[$key])) { + continue; + } + + if (isset($handler)) { + unset($handler); + } + + $handler = &$this->view->argument[$key]; + if (empty($handler->definition['accept depth modifier'])) { + continue; + } + + // Finally! + $handler->options['depth'] = $argument; + } + } +} + diff --git a/sites/all/modules/views/modules/taxonomy/views_handler_argument_vocabulary_vid.inc b/sites/all/modules/views/modules/taxonomy/views_handler_argument_vocabulary_vid.inc new file mode 100644 index 0000000..b76b0a1 --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy/views_handler_argument_vocabulary_vid.inc @@ -0,0 +1,19 @@ +argument)); + + if (empty($title)) { + return t('No vocabulary'); + } + + return check_plain($title); + } +} diff --git a/sites/all/modules/views/modules/taxonomy/views_handler_field_taxonomy.inc b/sites/all/modules/views/modules/taxonomy/views_handler_field_taxonomy.inc new file mode 100644 index 0000000..26ec74b --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy/views_handler_field_taxonomy.inc @@ -0,0 +1,58 @@ +additional_fields['vid'] = 'vid'; + $this->additional_fields['tid'] = 'tid'; + } + + function option_definition() { + $options = parent::option_definition(); + $options['link_to_taxonomy'] = array('default' => FALSE); + return $options; + } + + /** + * Provide link to taxonomy option + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_taxonomy'] = array( + '#title' => t('Link this field to its taxonomy term page'), + '#description' => t('This will override any other link you have set.'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['link_to_taxonomy']), + ); + } + + /** + * Render whatever the data is as a link to the taxonomy. + * + * Data should be made XSS safe prior to calling this function. + */ + function render_link($data, $values) { + if (!empty($this->options['link_to_taxonomy']) && !empty($values->{$this->aliases['tid']}) && $data !== NULL && $data !== '') { + $term = new stdClass(); + $term->tid = $values->{$this->aliases['tid']}; + $term->vid = $values->{$this->aliases['vid']}; + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = taxonomy_term_path($term); + } + return $data; + } + + function render($values) { + return $this->render_link(check_plain($values->{$this->field_alias}), $values); + } +} diff --git a/sites/all/modules/views/modules/taxonomy/views_handler_field_term_node_tid.inc b/sites/all/modules/views/modules/taxonomy/views_handler_field_term_node_tid.inc new file mode 100644 index 0000000..bc8fc92 --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy/views_handler_field_term_node_tid.inc @@ -0,0 +1,119 @@ +base_table == 'node_revisions') { + $this->additional_fields['vid'] = array('table' => 'node_revisions', 'field' => 'vid'); + } + else { + $this->additional_fields['vid'] = array('table' => 'node', 'field' => 'vid'); + } + } + + function option_definition() { + $options = parent::option_definition(); + + $options['link_to_taxonomy'] = array('default' => TRUE); + $options['limit'] = array('default' => FALSE); + $options['vids'] = array('default' => array()); + + return $options; + } + + /** + * Provide "link to term" option. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_taxonomy'] = array( + '#title' => t('Link this field to its term page'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['link_to_taxonomy']), + ); + + $form['limit'] = array( + '#type' => 'checkbox', + '#title' => t('Limit terms by vocabulary'), + '#default_value'=> $this->options['limit'], + ); + + $options = array(); + $vocabularies = taxonomy_get_vocabularies(); + foreach ($vocabularies as $voc) { + $options[$voc->vid] = check_plain($voc->name); + } + + $form['vids'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#type' => 'checkboxes', + '#title' => t('Vocabularies'), + '#options' => $options, + '#default_value' => $this->options['vids'], + '#process' => array('expand_checkboxes', 'views_process_dependency'), + '#dependency' => array('edit-options-limit' => array(TRUE)), + ); + } + + /** + * Add this term to the query + */ + function query() { + $this->add_additional_fields(); + } + + function pre_render($values) { + $this->field_alias = $this->aliases['vid']; + $vids = array(); + foreach ($values as $result) { + if (!empty($result->{$this->aliases['vid']})) { + $vids[] = $result->{$this->aliases['vid']}; + } + } + + if ($vids) { + $voc = ''; + $voc_ids = array_filter($this->options['vids']); + if (!empty($this->options['limit']) && !empty($voc_ids)) { + $voc = " AND td.vid IN (" . implode(', ', array_keys($voc_ids)) . ")"; + } + + $result = db_query("SELECT tn.vid AS node_vid, td.*, v.name as vocabulary FROM {term_data} td INNER JOIN {term_node} tn ON td.tid = tn.tid INNER JOIN {vocabulary} v ON v.vid = td.vid WHERE tn.vid IN (" . implode(', ', $vids) . ")$voc ORDER BY td.weight, td.name"); + + while ($term = db_fetch_object($result)) { + $this->items[$term->node_vid][$term->tid]['name'] = check_plain($term->name); + $this->items[$term->node_vid][$term->tid]['tid'] = $term->tid; + $this->items[$term->node_vid][$term->tid]['vid'] = $term->vid; + $this->items[$term->node_vid][$term->tid]['vocabulary'] = check_plain($term->vocabulary); + + if (!empty($this->options['link_to_taxonomy'])) { + $this->items[$term->node_vid][$term->tid]['make_link'] = TRUE; + $this->items[$term->node_vid][$term->tid]['path'] = taxonomy_term_path($term); + } + } + } + } + + function render_item($count, $item) { + return $item['name']; + } + + function document_self_tokens(&$tokens) { + $tokens['[' . $this->options['id'] . '-tid' . ']'] = t('The taxonomy term ID for the term.'); + $tokens['[' . $this->options['id'] . '-name' . ']'] = t('The taxonomy term name for the term.'); + $tokens['[' . $this->options['id'] . '-vid' . ']'] = t('The vocabulary ID for the vocabulary the term belongs to.'); + $tokens['[' . $this->options['id'] . '-vocabulary' . ']'] = t('The name for the vocabulary the term belongs to.'); + } + + function add_self_tokens(&$tokens, $item) { + $tokens['[' . $this->options['id'] . '-tid' . ']'] = $item['tid']; + $tokens['[' . $this->options['id'] . '-name' . ']'] = $item['name']; + $tokens['[' . $this->options['id'] . '-vid' . ']'] = $item['vid']; + $tokens['[' . $this->options['id'] . '-vocabulary' . ']'] = $item['vocabulary']; + } +} + diff --git a/sites/all/modules/views/modules/taxonomy/views_handler_filter_term_node_tid.inc b/sites/all/modules/views/modules/taxonomy/views_handler_filter_term_node_tid.inc new file mode 100644 index 0000000..ceb8ea5 --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy/views_handler_filter_term_node_tid.inc @@ -0,0 +1,302 @@ + 'textfield'); + $options['limit'] = array('default' => TRUE); + $options['vid'] = array('default' => 0); + + return $options; + } + + function extra_options_form(&$form, &$form_state) { + $vocabularies = taxonomy_get_vocabularies(); + foreach ($vocabularies as $voc) { + $options[$voc->vid] = check_plain($voc->name); + } + + if ($this->options['limit']) { + // We only do this when the form is displayed. + if ($this->options['vid'] == 0) { + $first_vocabulary = reset($vocabularies); + $this->options['vid'] = $first_vocabulary->vid; + } + + $form['vid'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#type' => 'radios', + '#title' => t('Vocabulary'), + '#options' => $options, + '#description' => t('Select which vocabulary to show terms for in the regular options.'), + '#default_value' => $this->options['vid'], + ); + } + + $form['markup_start'] = array( + '#value' => '
    ', + ); + + $form['type'] = array( + '#type' => 'radios', + '#title' => t('Selection type'), + '#options' => array('select' => t('Dropdown'), 'textfield' => t('Autocomplete')), + '#default_value' => $this->options['type'], + ); + + $form['hierarchy'] = array( + '#type' => 'checkbox', + '#title' => t('Show hierarchy in dropdown'), + '#default_value' => !empty($this->options['hierarchy']), + '#process' => array('views_process_dependency'), + '#dependency' => array('radio:options[type]' => array('select')), + ); + + $form['markup_end'] = array( + '#value' => '
    ', + ); + } + + function value_form(&$form, &$form_state) { + $vocabulary = taxonomy_vocabulary_load($this->options['vid']); + if (empty($vocabulary) && $this->options['limit']) { + $form['markup'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => t('An invalid vocabulary is selected. Please change it in the options.'), + ); + return; + } + + if ($this->options['type'] == 'textfield') { + $default = ''; + if ($this->value) { + $result = db_query("SELECT * FROM {term_data} td WHERE td.tid IN (" . implode(', ', $this->value) . ')'); + while ($term = db_fetch_object($result)) { + if ($default) { + $default .= ', '; + } + $default .= $term->name; + } + } + + $form['value'] = array( + '#title' => $this->options['limit'] ? t('Select terms from vocabulary @voc', array('@voc' => $vocabulary->name)) : t('Select terms'), + '#type' => 'textfield', + '#default_value' => $default, + ); + + if ($this->options['limit']) { + $form['value']['#autocomplete_path'] = 'taxonomy/autocomplete/' . $vocabulary->vid; + } + } + else { + if (!empty($this->options['hierarchy']) && $this->options['limit']) { + $tree = taxonomy_get_tree($vocabulary->vid); + $options = array(); + + if ($tree) { + foreach ($tree as $term) { + $choice = new stdClass(); + $choice->option = array($term->tid => str_repeat('-', $term->depth) . $term->name); + $options[] = $choice; + } + } + } + else { + $options = array(); + if ($this->options['limit']) { + $result = db_query(db_rewrite_sql("SELECT t.* FROM {term_data} t WHERE t.vid = %d ORDER BY t.weight, t.name", 't', 'tid'), $vocabulary->vid); + } + else { + $result = db_query(db_rewrite_sql("SELECT td.* FROM {term_data} td INNER JOIN {vocabulary} v ON td.vid = v.vid ORDER BY v.weight, v.name, td.weight, td.name", 'td', 'tid')); + } + while ($term = db_fetch_object($result)) { + $options[$term->tid] = $term->name; + } + } + + $default_value = (array) $this->value; + + if (!empty($form_state['exposed'])) { + $identifier = $this->options['expose']['identifier']; + + if (!empty($this->options['expose']['reduce'])) { + $options = $this->reduce_value_options($options); + + if (empty($this->options['expose']['single']) && !empty($this->options['expose']['optional'])) { + $default_value = array(); + } + } + + if (!empty($this->options['expose']['single'])) { + if (!empty($this->options['expose']['optional']) && (empty($default_value) || !empty($this->options['expose']['reduce']))) { + $default_value = 'All'; + } + else if (empty($default_value)) { + $keys = array_keys($options); + $default_value = array_shift($keys); + } + else { + $copy = $default_value; + $default_value = array_shift($copy); + } + } + } + $form['value'] = array( + '#type' => 'select', + '#title' => $this->options['limit'] ? t('Select terms from vocabulary @voc', array('@voc' => $vocabulary->name)) : t('Select terms'), + '#multiple' => TRUE, + '#options' => $options, + '#size' => min(9, count($options)), + '#default_value' => $default_value, + ); + + if (!empty($form_state['exposed']) && !isset($form_state['input'][$identifier])) { + $form_state['input'][$identifier] = $default_value; + } + } + + + if (empty($form_state['exposed'])) { + // Retain the helper option + $this->helper->options_form($form, $form_state); + } + } + + function value_validate($form, &$form_state) { + // We only validate if they've chosen the text field style. + if ($this->options['type'] != 'textfield') { + return; + } + + $values = drupal_explode_tags($form_state['values']['options']['value']); + $tids = $this->validate_term_strings($form['value'], $values); + + if ($tids) { + $form_state['values']['options']['value'] = $tids; + } + } + + function accept_exposed_input($input) { + if (empty($this->options['exposed'])) { + return TRUE; + } + + // If it's optional and there's no value don't bother filtering. + if ($this->options['expose']['optional'] && empty($this->validated_exposed_input)) { + return FALSE; + } + + $rc = parent::accept_exposed_input($input); + if ($rc) { + // If we have previously validated input, override. + if (isset($this->validated_exposed_input)) { + $this->value = $this->validated_exposed_input; + } + } + + return $rc; + } + + function exposed_validate(&$form, &$form_state) { + if (empty($this->options['exposed'])) { + return; + } + + $identifier = $this->options['expose']['identifier']; + + // We only validate if they've chosen the text field style. + if ($this->options['type'] != 'textfield') { + if ($form_state['values'][$identifier] != 'All') { + $this->validated_exposed_input = (array) $form_state['values'][$identifier]; + } + return; + } + + if (empty($this->options['expose']['identifier'])) { + return; + } + + $values = drupal_explode_tags($form_state['values'][$identifier]); + + $tids = $this->validate_term_strings($form[$identifier], $values); + if ($tids) { + $this->validated_exposed_input = $tids; + } + } + + /** + * Validate the user string. Since this can come from either the form + * or the exposed filter, this is abstracted out a bit so it can + * handle the multiple input sources. + */ + function validate_term_strings(&$form, $values) { + if (empty($values)) { + return array(); + } + + $tids = array(); + $placeholders = array(); + $args = array(); + $results = array(); + foreach ($values as $value) { + $missing[strtolower($value)] = TRUE; + $args[] = $value; + $placeholders[] = "'%s'"; + } + + if (!$args) { + return; + } + + // add the taxonomy vid to the argument list. + $args[] = $this->options['vid']; + + $result = db_query("SELECT * FROM {term_data} td WHERE td.name IN (" . implode(', ', $placeholders) . ") AND td.vid = %d", $args); + while ($term = db_fetch_object($result)) { + unset($missing[strtolower($term->name)]); + $tids[] = $term->tid; + } + + if ($missing) { + form_error($form, format_plural(count($missing), 'Unable to find term: @terms', 'Unable to find terms: @terms', array('@terms' => implode(', ', array_keys($missing))))); + } + + return $tids; + } + + function value_submit($form, &$form_state) { + // prevent array_filter from messing up our arrays in parent submit. + } + + function expose_form_right(&$form, &$form_state) { + parent::expose_form_right($form, $form_state); + if ($this->options['type'] != 'select') { + unset($form['expose']['reduce']); + } + } + + function admin_summary() { + // set up $this->value_options for the parent summary + $this->value_options = array(); + + if ($this->value) { + $result = db_query("SELECT * FROM {term_data} td WHERE td.tid IN (" . implode(', ', $this->value) . ")"); + + while ($term = db_fetch_object($result)) { + $this->value_options[$term->tid] = $term->name; + } + } + return parent::admin_summary(); + } +} diff --git a/sites/all/modules/views/modules/taxonomy/views_handler_filter_term_node_tid_depth.inc b/sites/all/modules/views/modules/taxonomy/views_handler_filter_term_node_tid_depth.inc new file mode 100644 index 0000000..5593fe6 --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy/views_handler_filter_term_node_tid_depth.inc @@ -0,0 +1,89 @@ + t('Is one of'), + ); + } + + function option_definition() { + $options = parent::option_definition(); + + $options['depth'] = array('default' => 0); + + return $options; + } + + function extra_options_form(&$form, &$form_state) { + parent::extra_options_form($form, $form_state); + + $form['depth'] = array( + '#type' => 'weight', + '#title' => t('Depth'), + '#default_value' => $this->options['depth'], + '#description' => t('The depth will match nodes tagged with terms in the hierarchy. For example, if you have the term "fruit" and a child term "apple", with a depth of 1 (or higher) then filtering for the term "fruit" will get nodes that are tagged with "apple" as well as "fruit". If negative, the reverse is true; searching for "apple" will also pick up nodes tagged with "fruit" if depth is -1 (or lower).'), + ); + } + + function query() { + // If no filter values are present, then do nothing. + if (count($this->value) == 0) { + return; + } + else if (count($this->value) == 1) { + $placeholder = " = %d"; + } + else { + $placeholder = " IN (" . implode(', ', array_fill(0, sizeof($this->value), '%d')) . ")"; + } + + // The normal use of ensure_my_table() here breaks Views. + // So instead we trick the filter into using the alias of the base table. + // See http://drupal.org/node/271833 + // If a relationship is set, we must use the alias it provides. + if (!empty($this->relationship)) { + $this->table_alias = $this->relationship; + } + // If no relationship, then use the alias of the base table. + else if (isset($this->query->table_queue[$this->query->base_table]['alias'])) { + $this->table_alias = $this->query->table_queue[$this->query->base_table]['alias']; + } + // This should never happen, but if it does, we fail quietly. + else { + return; + } + + // Now build the subqueries. + $subquery = "\n SELECT tn.vid FROM {term_node} tn\n"; + $where = " WHERE tn.tid $placeholder\n"; + $args = $this->value; + $last = "tn"; + + if ($this->options['depth'] > 0) { + $subquery .= " LEFT JOIN {term_hierarchy} th ON th.tid = tn.tid\n"; + $last = "th"; + foreach (range(1, abs($this->options['depth'])) as $count) { + $subquery .= " LEFT JOIN {term_hierarchy} th$count ON $last.parent = th$count.tid\n"; + $where .= " OR th$count.tid $placeholder\n"; + $args = array_merge($args, $this->value); + $last = "th$count"; + } + } + else if ($this->options['depth'] < 0) { + foreach (range(1, abs($this->options['depth'])) as $count) { + $subquery .= " LEFT JOIN {term_hierarchy} th$count ON $last.tid = th$count.parent\n"; + $where .= " OR th$count.tid $placeholder\n"; + $args = array_merge($args, $this->value); + $last = "th$count"; + } + } + + $this->query->add_where(0, "$this->table_alias.$this->real_field IN ($subquery$where )", $args); + } +} diff --git a/sites/all/modules/views/modules/taxonomy/views_handler_filter_vocabulary_vid.inc b/sites/all/modules/views/modules/taxonomy/views_handler_filter_vocabulary_vid.inc new file mode 100644 index 0000000..cb624dc --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy/views_handler_filter_vocabulary_vid.inc @@ -0,0 +1,18 @@ +value_options)) { + return; + } + + $this->value_options = array(); + $vocabularies = taxonomy_get_vocabularies(); + foreach ($vocabularies as $voc) { + $this->value_options[$voc->vid] = $voc->name; + } + } +} diff --git a/sites/all/modules/views/modules/taxonomy/views_handler_relationship_node_term_data.inc b/sites/all/modules/views/modules/taxonomy/views_handler_relationship_node_term_data.inc new file mode 100644 index 0000000..873fa20 --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy/views_handler_relationship_node_term_data.inc @@ -0,0 +1,74 @@ + array()); + return $options; + } + + /** + * Default options form that provides the label widget that all fields + * should have. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $vocabularies = taxonomy_get_vocabularies(); + $options = array(); + foreach ($vocabularies as $voc) { + $options[$voc->vid] = check_plain($voc->name); + } + + $form['vids'] = array( + '#type' => 'checkboxes', + '#title' => t('Vocabularies'), + '#options' => $options, + '#default_value' => $this->options['vids'], + '#description' => t('Choose which vocabularies you wish to relate. Remember that every term found will create a new record, so this relationship is best used on just one vocabulary that has only one term per node.'), + ); + } + + /** + * Called to implement a relationship in a query. + */ + function query() { + $this->ensure_my_table(); + + $def = $this->definition; + $def['table'] = 'term_data'; + + if (!empty($this->options['required']) || !array_filter($this->options['vids'])) { + $term_node = $this->query->add_table('term_node', $this->relationship); + $def['left_table'] = $term_node; + $def['left_field'] = 'tid'; + $def['field'] = 'tid'; + if (!empty($this->options['required'])) { + $def['type'] = 'INNER'; + } + } + else { + // If the join is optional, join a subselect that will emulate term_data table instead + $def['left_table'] = $this->table_alias; + $def['left_field'] = 'vid'; + $def['field'] = 'revision'; + // fapi ensures vids are safe here. + $vids = implode(', ', array_filter($this->options['vids'])); + $def['table formula'] = "(SELECT td.*, tn.vid AS revision FROM {term_data} td INNER JOIN {term_node} tn ON tn.tid = td.tid WHERE td.vid IN ($vids))"; + } + + $join = new views_join(); + + $join->definition = $def; + $join->construct(); + $join->adjusted = TRUE; + + // use a short alias for this: + $alias = $def['table'] . '_' . $this->table; + + $this->alias = $this->query->add_relationship($alias, $join, 'term_data', $this->relationship); + } +} diff --git a/sites/all/modules/views/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc b/sites/all/modules/views/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc new file mode 100644 index 0000000..4e27aba --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy/views_plugin_argument_default_taxonomy_tid.inc @@ -0,0 +1,124 @@ +option_name . '_term_page'] = array('default' => TRUE); + $options[$this->option_name . '_node'] = array('default' => FALSE); + $options[$this->option_name . '_limit'] = array('default' => FALSE); + $options[$this->option_name . '_vids'] = array('default' => array()); + + return $options; + } + + function argument_form(&$form, &$form_state) { + $form[$this->option_name . '_term_page'] = array( + '#type' => 'checkbox', + '#title' => t('Load default argument from term page'), + '#default_value' => $this->argument->options[$this->option_name . '_term_page'], + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'radio:options[default_action]' => array('default'), + 'radio:options[default_argument_type]' => array($this->id) + ), + '#dependency_count' => 2, + ); + $form[$this->option_name . '_node'] = array( + '#type' => 'checkbox', + '#title' => t('Load default argument from node page, thats good for related taxonomy blocks'), + '#default_value' => $this->argument->options[$this->option_name . '_node'], + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'radio:options[default_action]' => array('default'), + 'radio:options[default_argument_type]' => array($this->id) + ), + '#dependency_count' => 2, + ); + + $form[$this->option_name . '_limit'] = array( + '#type' => 'checkbox', + '#title' => t('Limit terms by vocabulary'), + '#default_value'=> $this->argument->options[$this->option_name . '_limit'], + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'radio:options[default_action]' => array('default'), + 'radio:options[default_argument_type]' => array($this->id), + 'edit-options-default-taxonomy-tid-node' => array(1), + ), + '#dependency_count' => 3, + ); + + $options = array(); + $vocabularies = taxonomy_get_vocabularies(); + foreach ($vocabularies as $voc) { + $options[$voc->vid] = check_plain($voc->name); + } + + $form[$this->option_name . '_vids'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#type' => 'checkboxes', + '#title' => t('Vocabularies'), + '#description' => t('If you wish to limit terms for specific vocabularies, check them; if none are checked, all terms will be included.'), + '#options' => $options, + '#default_value' => isset($this->argument->options[$this->option_name . '_vids']) ? $this->argument->options[$this->option_name . '_vids'] : array(), + '#process' => array('expand_checkboxes', 'views_process_dependency'), + '#dependency' => array( + 'radio:options[default_action]' => array('default'), + 'radio:options[default_argument_type]' => array($this->id), + 'edit-options-default-taxonomy-tid-limit' => array(1), + 'edit-options-default-taxonomy-tid-node' => array(1), + ), + '#dependency_count' => 4, + ); + } + + function get_argument() { + // Load default argument from taxonomy page. + if (!empty($this->argument->options[$this->option_name . '_term_page'])) { + if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2))) { + return arg(2); + } + } + // Load default argument from node. + if (!empty($this->argument->options[$this->option_name . '_node'])) { + foreach (range(1, 3) as $i) { + $node = menu_get_object('node', $i); + if (!empty($node)) { + break; + } + } + // Just check, if a node could be detected. + if ($node) { + if (!empty($this->argument->options[$this->option_name . '_limit'])) { + $tids = array(); + // Filter by vid. + foreach ($node->taxonomy as $tid => $term) { + if (!empty($this->argument->options[$this->option_name . '_vids'][$term->vid])) { + $tids[] = $tid; + } + } + return implode(",", $tids); + } + // Return all tids. + else { + return implode(",", array_keys($node->taxonomy)); + } + } + } + + // If the current page is a view that takes tid as an argument, + // find the tid argument and return it. + $views_page = views_get_page_view(); + if ($views_page && isset($views_page->view->argument['tid'])) { + return $views_page->view->argument['tid']->argument; + } + } +} + diff --git a/sites/all/modules/views/modules/taxonomy/views_plugin_argument_validate_taxonomy_term.inc b/sites/all/modules/views/modules/taxonomy/views_plugin_argument_validate_taxonomy_term.inc new file mode 100644 index 0000000..6903aa8 --- /dev/null +++ b/sites/all/modules/views/modules/taxonomy/views_plugin_argument_validate_taxonomy_term.inc @@ -0,0 +1,148 @@ +vid] = check_plain($voc->name); + } + + $form['validate_argument_vocabulary'] = array( + '#type' => 'checkboxes', + '#prefix' => '
    ', + '#suffix' => '
    ', + '#title' => t('Vocabularies'), + '#options' => $options, + '#default_value' => isset($this->argument->options['validate_argument_vocabulary']) ? $this->argument->options['validate_argument_vocabulary'] : array(), + '#description' => t('If you wish to validate for specific vocabularies, check them; if none are checked, all terms will pass.'), + '#process' => array('expand_checkboxes', 'views_process_dependency'), + '#dependency' => array('edit-options-validate-type' => array($this->id)), + ); + + $form['validate_argument_type'] = array( + '#type' => 'select', + '#title' => t('Argument type'), + '#options' => array( + 'tid' => t('Term ID'), + 'tids' => t('Term IDs separated by , or +'), + 'name' => t('Term name or synonym'), + 'convert' => t('Term name/synonym converted to Term ID'), + ), + '#default_value' => isset($this->argument->options['validate_argument_type']) ? $this->argument->options['validate_argument_type'] : 'tid', + '#description' => t('Select the form of this argument; if using term name, it is generally more efficient to convert it to a term ID and use Taxonomy: Term ID rather than Taxonomy: Term Name" as an argument.'), + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-validate-type' => array($this->id)), + ); + + $form['validate_argument_transform'] = array( + '#type' => 'checkbox', + '#title' => t('Transform dashes in URL to spaces in term name arguments'), + '#default_value' => isset($this->argument->options['validate_argument_transform']) ? $this->argument->options['validate_argument_transform'] : FALSE, + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-validate-argument-type' => array('convert', 'name')), + ); + } + + function validate_argument($argument) { + $vids = isset($this->argument->options['validate_argument_vocabulary']) ? array_filter($this->argument->options['validate_argument_vocabulary']) : array(); + $type = isset($this->argument->options['validate_argument_type']) ? $this->argument->options['validate_argument_type'] : 'tid'; + $transform = isset($this->argument->options['validate_argument_transform']) ? $this->argument->options['validate_argument_transform'] : FALSE; + + switch ($type) { + case 'tid': + if (!is_numeric($argument)) { + return FALSE; + } + + $result = db_fetch_object(db_query("SELECT * FROM {term_data} WHERE tid = %d", $argument)); + if (!$result) { + return FALSE; + } + + return empty($vids) || !empty($vids[$result->vid]); + case 'tids': + // An empty argument is not a term so doesn't pass. + if (empty($argument)) { + return FALSE; + } + + $tids = new stdClass(); + $tids->value = $argument; + $tids = views_break_phrase($argument, $tids); + if ($tids->value == array(-1)) { + return FALSE; + } + + $test = drupal_map_assoc($tids->value); + $titles = array(); + + // check, if some tids already verified + static $validated_cache = array(); + foreach ($test as $tid) { + if (isset($validated_cache[$tid])) { + if ($validated_cache[$tid] === FALSE) { + return FALSE; + } + else { + $titles[] = $validated_cache[$tid]; + unset($test[$tid]); + } + } + } + + + // if unverified tids left - verify them and cache results + if (count($test)) { + $placeholders = implode(', ', array_fill(0, count($test), '%d')); + + $result = db_query("SELECT * FROM {term_data} WHERE tid IN ($placeholders)", $test); + while ($term = db_fetch_object($result)) { + if ($vids && empty($vids[$term->vid])) { + $validated_cache[$term->tid] = FALSE; + return FALSE; + } + + $titles[] = $validated_cache[$term->tid] = check_plain($term->name); + unset($test[$term->tid]); + } + } + + // Remove duplicate titles + $titles = array_unique($titles); + + $this->argument->validated_title = implode($tids->operator == 'or' ? ' + ' : ', ', $titles); + // If this is not empty, we did not find a tid. + return empty($test); + case 'name': + case 'convert': + $and = ''; + if (!empty($vids)) { + $and = " AND td.vid IN(" . implode(', ', $vids) . ')'; + } + if ($transform) { + $result = db_fetch_object(db_query("SELECT td.* FROM {term_data} td LEFT JOIN {term_synonym} ts ON ts.tid = td.tid WHERE (replace(td.name, ' ', '-') = '%s' OR replace(ts.name, ' ', '-') = '%s')$and", $argument, $argument)); + } + else { + $result = db_fetch_object(db_query("SELECT td.* FROM {term_data} td LEFT JOIN {term_synonym} ts ON ts.tid = td.tid WHERE (td.name = '%s' OR ts.name = '%s')$and", $argument, $argument)); + } + if (!$result) { + return FALSE; + } + + if ($type == 'convert') { + $this->argument->argument = $result->tid; + } + $this->argument->validated_title = check_plain($result->name); + + return TRUE; + } + } +} diff --git a/sites/all/modules/views/modules/translation.views.inc b/sites/all/modules/views/modules/translation.views.inc new file mode 100644 index 0000000..0b9f9d2 --- /dev/null +++ b/sites/all/modules/views/modules/translation.views.inc @@ -0,0 +1,191 @@ + 'tnid', + 'field' => 'tnid', + ); + + // Language field + $data['node']['language'] = array( + 'group' => t('Node translation'), + 'title' => t('Language'), + 'help' => t('The language the content is in.'), + 'field' => array( + 'handler' => 'views_handler_field_node_language', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_node_language', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_node_language', + ), + ); + + // The translation ID (nid of the "source" translation) + $data['node']['tnid'] = array( + 'group' => t('Node translation'), + 'title' => t('Translation set node ID'), + 'help' => t('The ID of the translation set the content belongs to.'), + 'field' => array( + 'handler' => 'views_handler_field_node', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_node_tnid', + 'parent' => 'views_handler_argument_numeric', // make sure parent is included + 'name field' => 'title', // the field to display in the summary. + 'numeric' => TRUE, + 'validate type' => 'tnid', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'relationship' => array( + 'title' => t('Source translation'), + 'help' => t('The source that this content was translated from.'), + 'base' => 'node', + 'base field' => 'nid', + 'handler' => 'views_handler_relationship', + 'label' => t('Source translation'), + ), + ); + + // The source translation. + $data['node']['translation'] = array( + 'group' => t('Node translation'), + 'title' => t('Translations'), + 'help' => t('Versions of content in different languages.'), + 'relationship' => array( + 'title' => t('Translations'), + 'help' => t('Versions of content in different languages.'), + 'base' => 'node', + 'base field' => 'tnid', + 'relationship table' => 'node', + 'relationship field' => 'nid', + 'handler' => 'views_handler_relationship_translation', + 'label' => t('Translations'), + ), + ); + + // The source translation. + $data['node']['source_translation'] = array( + 'group' => t('Node translation'), + 'title' => t('Source translation'), + 'help' => t('Nodes that are either untranslated or are the original versions of a translation set.'), + 'filter' => array( + 'handler' => 'views_handler_filter_node_tnid', + ), + ); + + // The source translation. + $data['node']['child_translation'] = array( + 'group' => t('Node translation'), + 'title' => t('Child translation'), + 'help' => t('Nodes that are translations of a source translation.'), + 'filter' => array( + 'handler' => 'views_handler_filter_node_tnid_child', + ), + ); + + // Translation status + $data['node']['translate'] = array( + 'group' => t('Node translation'), + 'title' => t('Translation status'), + 'help' => t('The translation status of the node--whether or not the translation needs to be updated.'), + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'label' => t('Outdated'), + 'type' => 'yes-no', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // Translate node link. + $data['node']['translate_node'] = array( + 'group' => t('Node translation'), + 'title' => t('Translate link'), + 'help' => t('Provide a simple link to translate the node.'), + 'field' => array( + 'handler' => 'views_handler_field_node_link_translate', + ), + ); + + +} + +/** + * Implementation of hook_views_handlers() to register all of the basic handlers + * views uses. + */ +function translation_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/modules/translation', + ), + 'handlers' => array( + // field handlers + 'views_handler_field_node_language' => array( + 'parent' => 'views_handler_field_node', + ), + 'views_handler_field_node_link_translate' => array( + 'parent' => 'views_handler_field_node_link', + ), + // argument handlers + 'views_handler_argument_node_language' => array( + 'parent' => 'views_handler_argument', + ), + 'views_handler_argument_node_tnid' => array( + 'parent' => 'views_handler_argument', + ), + // filters + 'views_handler_filter_node_language' => array( + 'parent' => 'views_handler_filter_in_operator', + ), + 'views_handler_filter_node_tnid' => array( + 'parent' => 'views_handler_filter', + ), + // relationships + 'views_handler_relationship_translation' => array( + 'parent' => 'views_handler_relationship', + ), + 'views_handler_filter_node_tnid_child' => array( + 'parent' => 'views_handler_filter', + ), + + ), + ); +} + +/** + * @} + */ diff --git a/sites/all/modules/views/modules/translation/views_handler_argument_node_language.inc b/sites/all/modules/views/modules/translation/views_handler_argument_node_language.inc new file mode 100644 index 0000000..85ff6c8 --- /dev/null +++ b/sites/all/modules/views/modules/translation/views_handler_argument_node_language.inc @@ -0,0 +1,31 @@ +node_language($data->{$this->name_alias}); + } + + /** + * Override the behavior of title(). Get the user friendly version of the + * node type. + */ + function title() { + return $this->node_language($this->argument); + } + + function node_language($langcode) { + $languages = locale_language_list(); + return isset($languages[$langcode]) ? $languages[$langcode] : t('Unknown language'); + } +} + diff --git a/sites/all/modules/views/modules/translation/views_handler_argument_node_tnid.inc b/sites/all/modules/views/modules/translation/views_handler_argument_node_tnid.inc new file mode 100644 index 0000000..c30bf38 --- /dev/null +++ b/sites/all/modules/views/modules/translation/views_handler_argument_node_tnid.inc @@ -0,0 +1,25 @@ +value), '%d')); + + $result = db_query("SELECT n.title FROM {node} n WHERE n.tnid IN ($placeholders)", $this->value); + while ($term = db_fetch_object($result)) { + $titles[] = check_plain($term->title); + } + return $titles; + } +} + diff --git a/sites/all/modules/views/modules/translation/views_handler_field_node_language.inc b/sites/all/modules/views/modules/translation/views_handler_field_node_language.inc new file mode 100644 index 0000000..cae2f79 --- /dev/null +++ b/sites/all/modules/views/modules/translation/views_handler_field_node_language.inc @@ -0,0 +1,29 @@ + FALSE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['native_language'] = array( + '#title' => t('Native language'), + '#type' => 'checkbox', + '#default_value' => $this->options['native_language'], + '#description' => t('If enabled, the native name of the language will be displayed'), + ); + } + + function render($values) { + $languages = locale_language_list(empty($this->options['native_language']) ? 'name' : 'native'); + $value = isset($languages[$values->{$this->field_alias}]) ? $languages[$values->{$this->field_alias}] : ''; + return $this->render_link($value, $values); + } +} diff --git a/sites/all/modules/views/modules/translation/views_handler_field_node_link_translate.inc b/sites/all/modules/views/modules/translation/views_handler_field_node_link_translate.inc new file mode 100644 index 0000000..e754493 --- /dev/null +++ b/sites/all/modules/views/modules/translation/views_handler_field_node_link_translate.inc @@ -0,0 +1,31 @@ +additional_fields['uid'] = 'uid'; + $this->additional_fields['type'] = 'type'; + $this->additional_fields['language'] = 'language'; + $this->additional_fields['format'] = array('table' => 'node_revisions', 'field' => 'format'); + } + + function render($values) { + // ensure user has access to edit this node. + $node = new stdClass(); + $node->nid = $values->{$this->aliases['nid']}; + $node->uid = $values->{$this->aliases['uid']}; + $node->type = $values->{$this->aliases['type']}; + $node->format = $values->{$this->aliases['format']}; + $node->language = $values->{$this->aliases['language']}; + $node->status = 1; // unpublished nodes ignore access control + if (empty($node->language) || !translation_supported_type($node->type) || !node_access('view', $node) || !user_access('translate content')) { + return; + } + + $text = !empty($this->options['text']) ? $this->options['text'] : t('translate'); + return l($text, "node/$node->nid/translate", array('query' => drupal_get_destination())); + } +} + diff --git a/sites/all/modules/views/modules/translation/views_handler_field_node_translation_link.inc b/sites/all/modules/views/modules/translation/views_handler_field_node_translation_link.inc new file mode 100644 index 0000000..5fe947f --- /dev/null +++ b/sites/all/modules/views/modules/translation/views_handler_field_node_translation_link.inc @@ -0,0 +1,32 @@ +additional_fields['nid'] = 'nid'; + $this->additional_fields['tnid'] = 'tnid'; + $this->additional_fields['title'] = 'title'; + $this->additional_fields['language'] = 'language'; + } + + function query() { + $this->ensure_my_table(); + $this->add_additional_fields(); + } + + function render($values) { + global $language; + $tnid = $values->{$this->aliases['tnid']}; + // Only load translations if the node isn't in the current language. + if ($values->{$this->aliases['language']} != $language->language) { + $translations = translation_node_get_translations($tnid); + if (isset($translations[$language->language])) { + $values->{$this->aliases['nid']} = $translations[$language->language]->nid; + $values->{$this->aliases['title']} = $translations[$language->language]->title; + } + } + return l($values->{$this->aliases['title']}, "node/" . $values->{$this->aliases['nid']}); + } +} diff --git a/sites/all/modules/views/modules/translation/views_handler_filter_node_language.inc b/sites/all/modules/views/modules/translation/views_handler_filter_node_language.inc new file mode 100644 index 0000000..27e8cae --- /dev/null +++ b/sites/all/modules/views/modules/translation/views_handler_filter_node_language.inc @@ -0,0 +1,15 @@ +value_options)) { + $this->value_title = t('Language'); + $languages = array('***CURRENT_LANGUAGE***' => t("Current user's language"), '***DEFAULT_LANGUAGE***' => t("Default site language"), '***NO_LANGUAGE***' => t('No language')); + $languages = array_merge($languages, locale_language_list()); + $this->value_options = $languages; + } + } +} + diff --git a/sites/all/modules/views/modules/translation/views_handler_filter_node_tnid.inc b/sites/all/modules/views/modules/translation/views_handler_filter_node_tnid.inc new file mode 100644 index 0000000..b06dbd0 --- /dev/null +++ b/sites/all/modules/views/modules/translation/views_handler_filter_node_tnid.inc @@ -0,0 +1,38 @@ + 'radios', + '#title' => t('Include untranslated nodes'), + '#default_value' => $this->operator, + '#options' => array( + 1 => t('Yes'), + 0 => t('No'), + ), + ); + } + + function can_expose() { return FALSE; } + + function query() { + $table = $this->ensure_my_table(); + // Select for source translations (tnid = nid). Conditionally, also accept either untranslated nodes (tnid = 0). + $this->query->add_where($this->options['group'], "$table.tnid = $table.nid" . ($this->operator ? " OR $table.tnid = 0" : '')); + } +} + diff --git a/sites/all/modules/views/modules/translation/views_handler_filter_node_tnid_child.inc b/sites/all/modules/views/modules/translation/views_handler_filter_node_tnid_child.inc new file mode 100644 index 0000000..d35aff7 --- /dev/null +++ b/sites/all/modules/views/modules/translation/views_handler_filter_node_tnid_child.inc @@ -0,0 +1,15 @@ +ensure_my_table(); + $this->query->add_where($this->options['group'], "$table.tnid <> $table.nid AND $table.tnid > 0"); + } +} + diff --git a/sites/all/modules/views/modules/translation/views_handler_relationship_translation.inc b/sites/all/modules/views/modules/translation/views_handler_relationship_translation.inc new file mode 100644 index 0000000..ab47132 --- /dev/null +++ b/sites/all/modules/views/modules/translation/views_handler_relationship_translation.inc @@ -0,0 +1,96 @@ + 'current'); + + return $options; + } + + /** + * Add a translation selector. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $options = array( + 'all' => t('All'), + 'current' => t('Current language'), + 'default' => t('Default language'), + ); + $options = array_merge($options, locale_language_list()); + $form['language'] = array( + '#type' => 'select', + '#options' => $options, + '#default_value' => $this->options['language'], + '#title' => t('Translation option'), + '#description' => t('The translation options allows you to select which translation or translations in a translation set join on. Select "Current language" or "Default language" to join on the translation in the current or default language respectively. Select a specific language to join on a translation in that language. If you select "All", each translation will create a new row, which may appear to cause duplicates.'), + ); + } + + /** + * Called to implement a relationship in a query. + */ + function query() { + // Figure out what base table this relationship brings to the party. + $table_data = views_fetch_data($this->definition['base']); + $base_field = empty($this->definition['base field']) ? $table_data['table']['base']['field'] : $this->definition['base field']; + + $this->ensure_my_table(); + + $def = $this->definition; + $def['table'] = $this->definition['base']; + $def['field'] = $base_field; + $def['left_table'] = $this->table_alias; + $def['left_field'] = $this->field; + if (!empty($this->options['required'])) { + $def['type'] = 'INNER'; + } + + $def['extra'] = array(); + if ($this->options['language'] != 'all') { + switch ($this->options['language']) { + case 'current': + $def['extra'][] = array( + 'field' => 'language', + 'value' => '***CURRENT_LANGUAGE***', + ); + break; + case 'default': + $def['extra'][] = array( + 'field' => 'language', + 'value' => '***DEFAULT_LANGUAGE***', + ); + break; + // Other values will be the language codes. + default: + $def['extra'][] = array( + 'field' => 'language', + 'value' => $this->options['language'], + ); + break; + } + } + + if (!empty($def['join_handler']) && class_exists($def['join_handler'])) { + $join = new $def['join_handler']; + } + else { + $join = new views_join(); + } + + $join->definition = $def; + $join->construct(); + $join->adjusted = TRUE; + + // use a short alias for this: + $alias = $def['table'] . '_' . $this->table; + + $this->alias = $this->query->add_relationship($alias, $join, $this->definition['base'], $this->relationship); + } +} diff --git a/sites/all/modules/views/modules/upload.views.inc b/sites/all/modules/views/modules/upload.views.inc new file mode 100644 index 0000000..7107e41 --- /dev/null +++ b/sites/all/modules/views/modules/upload.views.inc @@ -0,0 +1,163 @@ + array( + 'left_field' => 'vid', + 'field' => 'vid', + ), + 'node_revisions' => array( + 'left_field' => 'vid', + 'field' => 'vid', + ), + 'files' => array( + 'left_field' => 'fid', + 'field' => 'fid', + ), + ); + + $data['upload']['vid'] = array( + 'title' => t('Node'), + 'help' => t('The node the uploaded file is attached to'), + 'relationship' => array( + 'label' => t('upload'), + 'base' => 'node', + 'base field' => 'vid', + // This allows us to not show this relationship if the base is already + // node so users won't create circular relationships. + 'skip base' => array('node', 'node_revisions'), + ), + ); + + $data['upload']['description'] = array( + 'title' => t('Description'), + 'help' => t('The description of the uploaded file.'), + 'field' => array( + 'handler' => 'views_handler_field_upload_description', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + $data['upload']['list'] = array( + 'title' => t('Listed'), + 'help' => t('Whether or not the file is marked to be listed.'), + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'label' => t('Published'), + 'type' => 'yes-no', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + $data['upload']['weight'] = array( + 'title' => t('Weight'), + 'help' => t('The weight, used for sorting.'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + ), + ); + + return $data; +} + +/** + * Implementation of hook_views_data_alter() + */ +function upload_views_data_alter(&$data) { + $data['node']['upload_fid'] = array( + 'group' => t('Upload'), + 'title' => t('Attached files'), + 'help' => t('All files attached to a node with upload.module.'), + 'real field' => 'vid', + 'field' => array( + 'handler' => 'views_handler_field_upload_fid', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_upload_fid', + 'title' => t('Has attached files'), + 'type' => 'yes-no', + 'help' => t('Only display items with attached files. This can cause duplicates if there are multiple attached files.'), + ), + 'relationship' => array( + 'title' => t('Attached files'), + 'help' => t('Add a relationship to gain access to more file data for files uploaded by upload.module. Note that this relationship will cause duplicate nodes if there are multiple files attached to the node.'), + 'relationship table' => 'upload', + 'relationship field' => 'fid', + 'base' => 'files', + 'base field' => 'fid', + 'handler' => 'views_handler_relationship', + 'label' => t('Files'), + ), + ); +} + +/** + * Implementation of hook_views_handlers() to register all of the basic handlers + * views uses. + */ +function upload_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/modules/upload', + ), + 'handlers' => array( + 'views_handler_field_upload_fid' => array( + 'parent' => 'views_handler_field_prerender_list', + ), + 'views_handler_field_upload_description' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_filter_upload_fid' => array( + 'parent' => 'views_handler_filter_boolean_operator', + ), + ), + ); +} + +/** + * @} + */ diff --git a/sites/all/modules/views/modules/upload.views_convert.inc b/sites/all/modules/views/modules/upload.views_convert.inc new file mode 100644 index 0000000..7a1662a --- /dev/null +++ b/sites/all/modules/views/modules/upload.views_convert.inc @@ -0,0 +1,107 @@ +add_item() won't produce + * the right results, usually needed to set field options or values. + */ +function upload_views_convert($display, $type, &$view, $field, $id = NULL) { + switch ($type) { + case 'field': + switch ($field['tablename']) { + case 'file_revisions': + switch ($field['field']) { + case 'fid': + $relationship = $view->add_item($display, 'relationship', 'node', 'upload_fid', array(), 'node_upload_fid'); + $view->set_item_option($display, 'field', $id, 'relationship', $relationship); + $view->set_item_option($display, 'field', $id, 'table', 'files'); + break; + } + break; + case 'files': + switch ($field['field']) { + case 'all_files': + $item = $view->get_item($display, 'field', $id); + switch ($field['options']) { + case 'link': + $item['link_to_file'] = TRUE; + break; + case 'linkdesc': + $item['link_to_file'] = TRUE; + case 'nolinkdesc': + $item['alter']['alter_text'] = TRUE; + $item['alter']['text'] = '['. $view->add_item($display, 'field', 'upload', 'description', array('exclude' => TRUE)) .']'; + break; + } + if ($field['handler'] == 'views_handler_file_listed_files') { + $item['only_listed'] = TRUE; + } + $item['table'] = 'node'; + $item['field'] = 'upload_fid'; + $view->set_item($display, 'field', $id, $item); + break; + case 'filename': + if ($field['handler'] == 'views_handler_file_filename_download') { + $view->set_item_option($display, 'field', $id, 'link_to_file', TRUE); + } + $relationship = $view->add_item($display, 'relationship', 'node', 'upload_fid', array(), 'node_upload_fid'); + $view->set_item_option($display, 'field', $id, 'relationship', $relationship); + break; + } + break; + } + break; + case 'filter': + switch ($field['tablename']) { + case 'file_revisions': + switch ($field['field']) { + case 'fid': + $view->set_item_option($display, 'filter', $id, 'table', 'node'); + $view->set_item_option($display, 'filter', $id, 'field', 'upload_fid'); + break; + case 'list': + $view->set_item_option($display, 'filter', $id, 'table', 'upload'); + break; + } + break; + case 'files': + switch ($field['field']) { + case 'filename': + case 'filemime': + $item = $view->get_item($display, 'filter', $id); + $item['operator'] = $field['operator']; + $item['case'] = FALSE; + $item['relationship'] = $view->add_item($display, 'relationship', 'node', 'upload_fid', array(), 'node_upload_fid'); + $view->set_item($display, 'filter', $id, $item); + break; + case 'filesize': + $relationship = $view->add_item($display, 'relationship', 'node', 'upload_fid', array(), 'node_upload_fid'); + $view->set_item_option($display, 'filter', $id, 'relationship', $relationship); + $view->set_item_option($display, 'filter', $id, 'operator', $field['operator']); + break; + } + break; + } + break; + case 'sorts': + switch ($field['tablename']) { + case 'file_revisions': + switch ($field['field']) { + case 'fid': + $relationship = $view->add_item($display, 'relationship', 'node', 'upload_fid', array(), 'node_upload_fid'); + $view->set_item_option($display, 'field', $id, 'relationship', $relationship); + $view->set_item_option($display, 'field', $id, 'table', 'files'); + break; + } + break; + } + break; + } +} diff --git a/sites/all/modules/views/modules/upload/views_handler_field_upload_description.inc b/sites/all/modules/views/modules/upload/views_handler_field_upload_description.inc new file mode 100644 index 0000000..2b0ac18 --- /dev/null +++ b/sites/all/modules/views/modules/upload/views_handler_field_upload_description.inc @@ -0,0 +1,72 @@ +additional_fields['fid'] = 'fid'; + } + } + + function option_definition() { + $options = parent::option_definition(); + $options['link_to_file'] = array('default' => FALSE); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_file'] = array( + '#title' => t('Link this field to download the file'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['link_to_file']), + ); + } + + function pre_render($values) { + if (empty($this->options['link_to_file'])) { + return; + } + + $fids = array(); + $this->items = array(); + + $data = array(); + foreach ($values as $result) { + if ($result->{$this->aliases['fid']}) { + $fids[] = $result->{$this->aliases['fid']}; + } + } + + if ($fids) { + $result = db_query("SELECT f.fid, f.filepath FROM {files} f WHERE f.fid IN (" . implode(', ', $fids) . ")"); + while ($file = db_fetch_object($result)) { + $this->items[$file->fid] = $file; + } + } + } + + function render($values) { + return $this->render_link(check_plain($values->{$this->field_alias}), $values); + } + + /** + * Render whatever the data is as a link to the file. + * + * Data should be made XSS safe prior to calling this function. + */ + function render_link($data, $value) { + if (!empty($this->options['link_to_file']) && $value->{$this->aliases['fid']} && $data !== NULL && $data !== '') { + $values = $this->items[$value->{$this->aliases['fid']}]; + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = file_create_url($values->filepath); + } + else { + $this->options['alter']['make_link'] = FALSE; + } + return $data; + } +} diff --git a/sites/all/modules/views/modules/upload/views_handler_field_upload_fid.inc b/sites/all/modules/views/modules/upload/views_handler_field_upload_fid.inc new file mode 100644 index 0000000..32356c7 --- /dev/null +++ b/sites/all/modules/views/modules/upload/views_handler_field_upload_fid.inc @@ -0,0 +1,85 @@ + FALSE); + $options['only_listed'] = array('default' => FALSE); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_file'] = array( + '#title' => t('Link this field to download the file'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['link_to_file']), + ); + + $form['only_listed'] = array( + '#title' => t('Only show "listed" file attachments'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['only_listed']), + ); + } + + function pre_render($values) { + $vids = array(); + $this->items = array(); + + foreach ($values as $result) { + $vids[] = $result->{$this->field_alias}; + } + + if ($vids) { + // Support "only listed files" option. + $where = ''; + if (!empty($this->options['only_listed'])) { + $where = " AND u.list <> 0"; + } + $result = db_query("SELECT u.vid, u.fid, f.filename, f.filepath, f.filesize, f.filemime, u.description FROM {upload} u LEFT JOIN {files} f ON f.fid = u.fid WHERE u.vid IN (" . implode(', ', $vids) . ")$where ORDER BY u.weight"); + while ($file = db_fetch_array($result)) { + $file['filename'] = check_plain($file['filename']); + $file['filemime'] = check_plain($file['filemime']); + $file['description'] = check_plain($file['description']); + $file['filesize'] = format_size($file['filesize']); + $file['filepath'] = file_create_url($file['filepath']); + if (!empty($this->options['link_to_file']) ) { + $file['make_link'] = TRUE; + $file['path'] = $file['filepath']; + } + $this->items[$file['vid']][$file['fid']] = $file; + } + } + } + + function render_item($count, $item) { + return $item['description']; + } + + function document_self_tokens(&$tokens) { + $tokens['[' . $this->options['id'] . '-fid' . ']'] = t('The file ID for the file.'); + $tokens['[' . $this->options['id'] . '-name' . ']'] = t('The name of the attached file.'); + $tokens['[' . $this->options['id'] . '-type' . ']'] = t('The MIME type of the attached file.'); + $tokens['[' . $this->options['id'] . '-description' . ']'] = t('The name of the attached file.'); + $tokens['[' . $this->options['id'] . '-path' . ']'] = t('The path of the attached file.'); + $tokens['[' . $this->options['id'] . '-url' . ']'] = t('The url of the attached file.'); + $tokens['[' . $this->options['id'] . '-size' . ']'] = t('The size of the attached file.'); + } + + function add_self_tokens(&$tokens, $item) { + $tokens['[' . $this->options['id'] . '-fid' . ']'] = $item['fid']; + $tokens['[' . $this->options['id'] . '-name' . ']'] = $item['filename']; + $tokens['[' . $this->options['id'] . '-type' . ']'] = $item['filemime']; + $tokens['[' . $this->options['id'] . '-description' . ']'] = $item['description']; + $tokens['[' . $this->options['id'] . '-path' . ']'] = $item['filepath']; + $tokens['[' . $this->options['id'] . '-url' . ']'] = url($item['filepath']); + $tokens['[' . $this->options['id'] . '-size' . ']'] = $item['filesize']; + } +} diff --git a/sites/all/modules/views/modules/upload/views_handler_filter_upload_fid.inc b/sites/all/modules/views/modules/upload/views_handler_filter_upload_fid.inc new file mode 100644 index 0000000..31a9570 --- /dev/null +++ b/sites/all/modules/views/modules/upload/views_handler_filter_upload_fid.inc @@ -0,0 +1,17 @@ +value_value = t('Has attached files'); + } + + function query() { + $this->ensure_my_table(); + $this->query->add_where($this->options['group'], "(SELECT COUNT(*) FROM {upload} u WHERE u.vid = $this->table_alias.$this->real_field) " . (empty($this->value) ? '=' : '<>') . " 0"); + } +} + diff --git a/sites/all/modules/views/modules/user.views.inc b/sites/all/modules/views/modules/user.views.inc new file mode 100644 index 0000000..2795ec0 --- /dev/null +++ b/sites/all/modules/views/modules/user.views.inc @@ -0,0 +1,481 @@ + 'uid', + 'title' => t('User'), + 'help' => t('Users who have created accounts on your site.'), + ); + + $data['users']['table']['join'] = array( + 'node' => array( + 'left_field' => 'uid', + 'field' => 'uid', + 'type' => 'INNER', // all nodes have an author. + ), + // This goes to the node so that we have consistent authorship. + 'node_revisions' => array( + 'left_table' => 'node', + 'left_field' => 'uid', + 'field' => 'uid', + 'type' => 'INNER', // all nodes have an author. + ), + ); + + // uid + $data['users']['uid'] = array( + 'title' => t('Uid'), + 'help' => t('The user ID'), // The help that appears on the UI, + 'field' => array( + 'handler' => 'views_handler_field_user', + 'click sortable' => TRUE, + ), + 'argument' => array( + 'handler' => 'views_handler_argument_user_uid', + 'name field' => 'name', // display this field in the summary + ), + 'filter' => array( + 'title' => t('Name'), + 'handler' => 'views_handler_filter_user_name', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // uid + $data['users']['uid_current'] = array( + 'real field' => 'uid', + 'title' => t('Current'), + 'help' => t('Filter the view to the currently logged in user.'), + 'filter' => array( + 'handler' => 'views_handler_filter_user_current', + 'type' => 'yes-no', + ), + ); + + // name + $data['users']['name'] = array( + 'title' => t('Name'), // The item it appears as on the UI, + 'help' => t('The user or author name.'), // The help that appears on the UI, + 'field' => array( + 'handler' => 'views_handler_field_user_name', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + 'title' => t('User raw name'), + 'help' => t('The user or author name. This filter do not check if the user exists. Only useful for string comparisons.') + ), + ); + + // mail + // Note that this field implements field level access control. + $data['users']['mail'] = array( + 'title' => t('E-mail'), // The item it appears as on the UI, + 'help' => t('Email address for a given user. This field is normally not shown to users, so be cautious when using it.'), // The help that appears on the UI, + 'field' => array( + 'handler' => 'views_handler_field_user_mail', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + // language + $data['users']['language'] = array( + 'title' => t('Language'), // The item it appears as on the UI, + 'help' => t('Language of the user'), + 'field' => array( + 'handler' => 'views_handler_field_user_language', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_node_language', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_node_language', + ), + ); + + // picture + $data['users']['picture'] = array( + 'title' => t('Picture'), + 'help' => t("The user's picture, if allowed."), // The help that appears on the UI, + // Information for displaying the uid + 'field' => array( + 'handler' => 'views_handler_field_user_picture', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator_string', + 'label' => t('Has Avatar'), + 'type' => 'yes-no', + ), + ); + + // created field + $data['users']['created'] = array( + 'title' => t('Created date'), // The item it appears as on the UI, + 'help' => t('The date the user was created.'), // The help that appears on the UI, + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + ); + + // access field + $data['users']['access'] = array( + 'title' => t('Last access'), // The item it appears as on the UI, + 'help' => t("The user's last access date."), // The help that appears on the UI, + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + ); + + // login field + $data['users']['login'] = array( + 'title' => t('Last login'), // The item it appears as on the UI, + 'help' => t("The user's last login date."), // The help that appears on the UI, + 'field' => array( + 'handler' => 'views_handler_field_date', + 'click sortable' => TRUE, + ), + 'sort' => array( + 'handler' => 'views_handler_sort_date', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_date', + ), + ); + + // active status + $data['users']['status'] = array( + 'title' => t('Active'), // The item it appears as on the UI, + 'help' => t('Whether a user is active or blocked.'), // The help that appears on the UI, + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_boolean', + 'click sortable' => TRUE, + ), + 'filter' => array( + 'handler' => 'views_handler_filter_boolean_operator', + 'label' => t('Active'), + 'type' => 'yes-no', + ), + 'sort' => array( + 'handler' => 'views_handler_sort', + ), + ); + + // log field + $data['users']['signature'] = array( + 'title' => t('Signature'), // The item it appears as on the UI, + 'help' => t("The user's signature."), // The help that appears on the UI, + // Information for displaying a title as a field + 'field' => array( + 'handler' => 'views_handler_field_xss', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + ); + + $data['users']['edit_node'] = array( + 'field' => array( + 'title' => t('Edit link'), + 'help' => t('Provide a simple link to edit the user.'), + 'handler' => 'views_handler_field_user_link_edit', + ), + ); + + $data['users']['delete_node'] = array( + 'field' => array( + 'title' => t('Delete link'), + 'help' => t('Provide a simple link to delete the user.'), + 'handler' => 'views_handler_field_user_link_delete', + ), + ); + + // ---------------------------------------------------------------------- + // users_roles table + + $data['users_roles']['table']['group'] = t('User'); + + // Explain how this table joins to others. + $data['users_roles']['table']['join'] = array( + // Directly links to users table. + 'users' => array( + 'left_field' => 'uid', + 'field' => 'uid', + ), + 'node' => array( + 'left_field' => 'uid', + 'field' => 'uid', + ), + 'node_revisions' => array( + 'left_table' => 'node', + 'left_field' => 'uid', + 'field' => 'uid', + ), + ); + + $data['users_roles']['rid'] = array( + 'title' => t('Roles'), + 'help' => t('Roles that a user belongs to.'), + 'field' => array( + 'handler' => 'views_handler_field_user_roles', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_user_roles', + 'numeric' => TRUE, + 'allow empty' => TRUE, + ), + 'argument' => array( + 'handler' => 'views_handler_argument_users_roles_rid', + 'name table' => 'role', + 'name field' => 'name', + 'empty field name' => t('No role'), + 'zero is null' => TRUE, + 'numeric' => TRUE, + ), + ); + + // ---------------------------------------------------------------------- + // role table + + $data['role']['table']['join'] = array( + // Directly links to users table. + 'users' => array( + 'left_table' => 'users_roles', + 'left_field' => 'rid', + 'field' => 'rid', + ), + // needed for many to one helper sometimes + 'users_roles' => array( + 'left_field' => 'rid', + 'field' => 'rid', + ), + 'node' => array( + 'left_table' => 'users_roles', + 'left_field' => 'rid', + 'field' => 'rid', + ), + 'node_revisions' => array( + 'left_table' => 'users_roles', + 'left_field' => 'rid', + 'field' => 'rid', + ), + ); + + // ---------------------------------------------------------------------- + // authmap table + + $data['authmap']['table']['group'] = t('User'); + $data['authmap']['table']['join'] = array( + // Directly links to users table. + 'users' => array( + 'left_field' => 'uid', + 'field' => 'uid', + ), + 'node' => array( + 'left_table' => 'users', + 'left_field' => 'uid', + 'field' => 'uid', + ), + ); + $data['authmap']['aid'] = array( + 'title' => t('Authmap ID'), + 'help' => t('The Authmap ID.'), + 'field' => array( + 'handler' => 'views_handler_field_numeric', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_numeric', + 'numeric' => TRUE, + ), + 'argument' => array( + 'handler' => 'views_handler_argument_numeric', + 'numeric' => TRUE, + ), + ); + $data['authmap']['authname'] = array( + 'title' => t('Authentication name'), + 'help' => t('The unique authentication name.'), + 'field' => array( + 'handler' => 'views_handler_field', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + $data['authmap']['module'] = array( + 'title' => t('Authentication module'), + 'help' => t('The name of the module managing the authentication entry.'), + 'field' => array( + 'handler' => 'views_handler_field', + ), + 'filter' => array( + 'handler' => 'views_handler_filter_string', + ), + 'argument' => array( + 'handler' => 'views_handler_argument_string', + ), + ); + + return $data; +} + +/** + * Implementation of hook_views_plugins + */ +function user_views_plugins() { + return array( + 'module' => 'views', // This just tells our themes are elsewhere. + 'argument default' => array( + 'user' => array( + 'title' => t('User ID from URL'), + 'handler' => 'views_plugin_argument_default_user', + 'path' => drupal_get_path('module', 'views') . '/modules/user', // not necessary for most modules + 'parent' => 'fixed', // so that the parent class is included + ), + 'current_user' => array( + 'title' => t('User ID from logged in user'), + 'handler' => 'views_plugin_argument_default_current_user', + 'path' => drupal_get_path('module', 'views') . '/modules/user', // not necessary for most modules + 'parent' => 'fixed', // so that the parent class is included + ), + ), + 'argument validator' => array( + 'user' => array( + 'title' => t('User'), + 'handler' => 'views_plugin_argument_validate_user', + 'path' => drupal_get_path('module', 'views') . '/modules/user', // not necessary for most modules + ), + ), + ); +} + +/** + * Implementation of hook_views_handlers() to register all of the basic handlers + * views uses. + */ +function user_views_handlers() { + return array( + 'info' => array( + 'path' => drupal_get_path('module', 'views') . '/modules/user', + ), + 'handlers' => array( + 'views_handler_argument_user_uid' => array( + 'parent' => 'views_handler_argument_numeric', + ), + 'views_handler_field_user' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_user_name' => array( + 'parent' => 'views_handler_field_user', + ), + 'views_handler_field_user_link' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_user_link_edit' => array( + 'parent' => 'views_handler_field_user_link', + ), + 'views_handler_field_user_link_delete' => array( + 'parent' => 'views_handler_field_user_link', + ), + 'views_handler_field_user_mail' => array( + 'parent' => 'views_handler_field_user', + ), + 'views_handler_field_user_language' => array( + 'parent' => 'views_handler_field_user', + ), + 'views_handler_field_user_picture' => array( + 'parent' => 'views_handler_field', + ), + 'views_handler_field_user_roles' => array( + 'parent' => 'views_handler_field_prerender_list', + ), + 'views_handler_filter_user_name' => array( + 'parent' => 'views_handler_filter_in_operator', + ), + 'views_handler_filter_user_current' => array( + 'parent' => 'views_handler_filter_boolean_operator', + ), + 'views_handler_filter_user_roles' => array( + 'parent' => 'views_handler_filter_many_to_one', + ), + 'views_handler_argument_users_roles_rid' => array( + 'parent' => 'views_handler_argument_many_to_one', + ), + ), + ); +} + + +/** + * Allow replacement of current userid so we can cache these queries + */ +function user_views_query_substitutions($view) { + global $user; + return array('***CURRENT_USER***' => intval($user->uid)); +} + +/** + * @} + */ diff --git a/sites/all/modules/views/modules/user.views_convert.inc b/sites/all/modules/views/modules/user.views_convert.inc new file mode 100644 index 0000000..1486fca --- /dev/null +++ b/sites/all/modules/views/modules/user.views_convert.inc @@ -0,0 +1,60 @@ +set_item_option($display, 'field', $id, 'field', 'picture'); + break; + } + break; + } + break; + case 'filter': + if ($field['tablename'] == 'users' || !strncmp($field['tablename'], 'users_role_', 11)) { + switch ($field['field']) { + case 'uid': + $operators = array('OR' => 'in', 'NOR' => 'not in'); + $view->set_item_option($display, 'filter', $id, 'operator', $operators[$field['operator']]); + if ($rid = (integer) substr($field['tablename'], 11)) { + $view->add_item($display, 'filter', 'users_roles', 'rid', array('value' => $rid)); + } + break; + } + } + elseif ($field['tablename'] == 'users_roles') { + switch ($field['field']) { + case 'rid': + $operators = array('AND' => 'and', 'OR' => 'or', 'NOR' => 'not'); + $view->set_item_option($display, 'filter', $id, 'operator', $operators[$field['operator']]); + break; + } + } + break; + case 'argument': + $options = $field['argoptions']; + switch ($field['type']) { + case 'uid': + $view->add_item($display, 'argument', 'users', 'uid', $options, $field['id']); + break; + case 'uidtouch': + $view->add_item($display, 'argument', 'node', 'uid_touch', $options, $field['id']); + break; + case 'username': + $view->add_item($display, 'argument', 'users', 'name', $options, $field['id']); + break; + } + break; + } +} diff --git a/sites/all/modules/views/modules/user/views_handler_argument_user_uid.inc b/sites/all/modules/views/modules/user/views_handler_argument_user_uid.inc new file mode 100644 index 0000000..13f7a8f --- /dev/null +++ b/sites/all/modules/views/modules/user/views_handler_argument_user_uid.inc @@ -0,0 +1,29 @@ +argument) { + return array(variable_get('anonymous', t('Anonymous'))); + } + + $titles = array(); + $placeholders = implode(', ', array_fill(0, sizeof($this->value), '%d')); + + $result = db_query("SELECT u.name FROM {users} u WHERE u.uid IN ($placeholders)", $this->value); + while ($term = db_fetch_object($result)) { + $titles[] = check_plain($term->name); + } + return $titles; + } +} + diff --git a/sites/all/modules/views/modules/user/views_handler_argument_users_roles_rid.inc b/sites/all/modules/views/modules/user/views_handler_argument_users_roles_rid.inc new file mode 100644 index 0000000..0c6626c --- /dev/null +++ b/sites/all/modules/views/modules/user/views_handler_argument_users_roles_rid.inc @@ -0,0 +1,17 @@ +value), '%d')); + + $result = db_query("SELECT name FROM {role} WHERE rid IN ($placeholders)", $this->value); + while ($term = db_fetch_object($result)) { + $titles[] = check_plain($term->name); + } + return $titles; + } +} + diff --git a/sites/all/modules/views/modules/user/views_handler_field_user.inc b/sites/all/modules/views/modules/user/views_handler_field_user.inc new file mode 100644 index 0000000..0c62556 --- /dev/null +++ b/sites/all/modules/views/modules/user/views_handler_field_user.inc @@ -0,0 +1,47 @@ +options['link_to_user'])) { + $this->additional_fields['uid'] = 'uid'; + } + } + + function option_definition() { + $options = parent::option_definition(); + $options['link_to_user'] = array('default' => TRUE); + return $options; + } + + /** + * Provide link to node option + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_user'] = array( + '#title' => t('Link this field to its user'), + '#description' => t('This will override any other link you have set.'), + '#type' => 'checkbox', + '#default_value' => $this->options['link_to_user'], + ); + } + + function render_link($data, $values) { + if (!empty($this->options['link_to_user']) && user_access('access user profiles') && $values->{$this->aliases['uid']} && $data !== NULL && $data !== '') { + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = "user/" . $values->{$this->aliases['uid']}; + } + return $data; + } + + function render($values) { + return $this->render_link(check_plain($values->{$this->field_alias}), $values); + } +} diff --git a/sites/all/modules/views/modules/user/views_handler_field_user_language.inc b/sites/all/modules/views/modules/user/views_handler_field_user_language.inc new file mode 100644 index 0000000..4a63be1 --- /dev/null +++ b/sites/all/modules/views/modules/user/views_handler_field_user_language.inc @@ -0,0 +1,28 @@ +options['link_to_user']) && user_access('access user profiles') && $values->{$this->aliases['uid']}) { + $this->options['alter']['make_link'] = TRUE; + $this->options['alter']['path'] = 'user/' . $values->{$this->aliases['uid']}; + } + if (empty($data)) { + $lang = language_default(); + } + else { + $lang = language_list(); + $lang = $lang[$data]; + } + + return check_plain($lang->name); + } + + function render($values) { + return $this->render_link(check_plain($values->{$this->field_alias}), $values); + } +} diff --git a/sites/all/modules/views/modules/user/views_handler_field_user_link.inc b/sites/all/modules/views/modules/user/views_handler_field_user_link.inc new file mode 100644 index 0000000..ea20aee --- /dev/null +++ b/sites/all/modules/views/modules/user/views_handler_field_user_link.inc @@ -0,0 +1,42 @@ +additional_fields['uid'] = 'uid'; + } + + function option_definition() { + $options = parent::option_definition(); + $options['text'] = array('default' => '', 'translatable' => TRUE); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['text'] = array( + '#type' => 'textfield', + '#title' => t('Text to display'), + '#default_value' => $this->options['text'], + ); + } + + // An example of field level access control. + function access() { + return user_access('access user profiles'); + } + + function query() { + $this->ensure_my_table(); + $this->add_additional_fields(); + } + + function render($values) { + $text = !empty($this->options['text']) ? $this->options['text'] : t('view'); + $uid = $values->{$this->aliases['uid']}; + return l($text, "user/$uid"); + } +} + diff --git a/sites/all/modules/views/modules/user/views_handler_field_user_link_delete.inc b/sites/all/modules/views/modules/user/views_handler_field_user_link_delete.inc new file mode 100644 index 0000000..aada6b6 --- /dev/null +++ b/sites/all/modules/views/modules/user/views_handler_field_user_link_delete.inc @@ -0,0 +1,17 @@ +options['text']) ? $this->options['text'] : t('delete'); + $uid = $values->{$this->aliases['uid']}; + return l($text, "user/$uid/delete", array('query' => drupal_get_destination())); + } +} + diff --git a/sites/all/modules/views/modules/user/views_handler_field_user_link_edit.inc b/sites/all/modules/views/modules/user/views_handler_field_user_link_edit.inc new file mode 100644 index 0000000..d14c709 --- /dev/null +++ b/sites/all/modules/views/modules/user/views_handler_field_user_link_edit.inc @@ -0,0 +1,17 @@ +options['text']) ? $this->options['text'] : t('edit'); + $uid = $values->{$this->aliases['uid']}; + // Fake object to check access. + $account = new stdClass(); + $account->uid = $uid; + if (user_edit_access($account)) { + return l($text, "user/$uid/edit", array('query' => drupal_get_destination())); + } + } +} + diff --git a/sites/all/modules/views/modules/user/views_handler_field_user_mail.inc b/sites/all/modules/views/modules/user/views_handler_field_user_mail.inc new file mode 100644 index 0000000..1967481 --- /dev/null +++ b/sites/all/modules/views/modules/user/views_handler_field_user_mail.inc @@ -0,0 +1,32 @@ + 'mailto'); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['link_to_user'] = array( + '#title' => t('Link this field'), + '#type' => 'radios', + '#options' => array( + 0 => t('No link'), + 'user' => t('To the user'), + 'mailto' => t("With a mailto:"), + ), + '#default_value' => $this->options['link_to_user'], + ); + } + + function render($values) { + if ($this->options['link_to_user'] == 'mailto') { + return l($values->{$this->field_alias}, "mailto:" . $values->{$this->field_alias}); + } + return $this->render_link(check_plain($values->{$this->field_alias}), $values); + } +} diff --git a/sites/all/modules/views/modules/user/views_handler_field_user_name.inc b/sites/all/modules/views/modules/user/views_handler_field_user_name.inc new file mode 100644 index 0000000..42ff1c8 --- /dev/null +++ b/sites/all/modules/views/modules/user/views_handler_field_user_name.inc @@ -0,0 +1,62 @@ +options['overwrite_anonymous'])) { + $this->additional_fields['uid'] = 'uid'; + } + } + + function option_definition() { + $options = parent::option_definition(); + + $options['overwrite_anonymous'] = array('default' => FALSE); + $options['anonymous_text'] = array('default' => '', 'translatable' => TRUE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['overwrite_anonymous'] = array( + '#title' => t('Overwrite the value to display for anonymous users'), + '#type' => 'checkbox', + '#default_value' => !empty($this->options['overwrite_anonymous']), + '#description' => t('If selected, you will see a field to enter the text to use for anonymous users.'), + ); + $form['anonymous_text'] = array( + '#title' => t('Text to display for anonymous users'), + '#type' => 'textfield', + '#default_value' => $this->options['anonymous_text'], + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'edit-options-overwrite-anonymous' => array(1), + ), + ); + } + + function render_link($data, $values) { + if (!empty($this->options['link_to_user']) || !empty($this->options['overwrite_anonymous'])) { + $account = new stdClass(); + $account->uid = $values->{$this->aliases['uid']}; + if (!empty($this->options['overwrite_anonymous']) && !$account->uid) { + // This is an anonymous user, and we're overriting the text. + return check_plain($this->options['anonymous_text']); + } + elseif (!empty($this->options['link_to_user'])) { + $account->name = $values->{$this->field_alias}; + return theme('username', $account); + } + } + // Otherwise, there's no special handling, so return the data directly. + return $data; + } +} + diff --git a/sites/all/modules/views/modules/user/views_handler_field_user_picture.inc b/sites/all/modules/views/modules/user/views_handler_field_user_picture.inc new file mode 100644 index 0000000..44b39e7 --- /dev/null +++ b/sites/all/modules/views/modules/user/views_handler_field_user_picture.inc @@ -0,0 +1,28 @@ +additional_fields['uid'] = 'uid'; + $this->additional_fields['name'] = 'name'; + $this->additional_fields['mail'] = 'mail'; + } + + function element_type() { + return 'div'; + } + + function render($values) { + // Fake an account object. + $account = new stdClass(); + $account->uid = $values->{$this->aliases['uid']}; + $account->name = $values->{$this->aliases['name']}; + $account->mail = $values->{$this->aliases['mail']}; + $account->picture = $values->{$this->field_alias}; + + return theme('user_picture', $account); + } +} diff --git a/sites/all/modules/views/modules/user/views_handler_field_user_roles.inc b/sites/all/modules/views/modules/user/views_handler_field_user_roles.inc new file mode 100644 index 0000000..c664630 --- /dev/null +++ b/sites/all/modules/views/modules/user/views_handler_field_user_roles.inc @@ -0,0 +1,46 @@ +additional_fields['uid'] = array('table' => 'users', 'field' => 'uid'); + } + + function query() { + $this->add_additional_fields(); + $this->field_alias = $this->aliases['uid']; + } + + function pre_render($values) { + $uids = array(); + $this->items = array(); + + foreach ($values as $result) { + $uids[] = $result->{$this->aliases['uid']}; + } + + if ($uids) { + $result = db_query("SELECT u.uid, u.rid, r.name FROM {role} r INNER JOIN {users_roles} u ON u.rid = r.rid WHERE u.uid IN (" . implode(', ', $uids) . ") ORDER BY r.name"); + while ($role = db_fetch_object($result)) { + $this->items[$role->uid][$role->rid]['role'] = check_plain($role->name); + $this->items[$role->uid][$role->rid]['rid'] = $role->rid; + } + } + } + + function render_item($count, $item) { + return $item['role']; + } + + function document_self_tokens(&$tokens) { + $tokens['[' . $this->options['id'] . '-role' . ']'] = t('The name of the role.'); + $tokens['[' . $this->options['id'] . '-rid' . ']'] = t('The role ID of the role.'); + } + + function add_self_tokens(&$tokens, $item) { + $tokens['[' . $this->options['id'] . '-role' . ']'] = $item['role']; + $tokens['[' . $this->options['id'] . '-rid' . ']'] = $item['rid']; + } +} diff --git a/sites/all/modules/views/modules/user/views_handler_filter_user_current.inc b/sites/all/modules/views/modules/user/views_handler_filter_user_current.inc new file mode 100644 index 0000000..7b94f8e --- /dev/null +++ b/sites/all/modules/views/modules/user/views_handler_filter_user_current.inc @@ -0,0 +1,27 @@ +value_value = t('Is the logged in user'); + } + + function query() { + $this->ensure_my_table(); + $where = "$this->table_alias.$this->real_field "; + + if (empty($this->value)) { + $where .= '<> ***CURRENT_USER***'; + if ($this->accept_null) { + $where = '(' . $where . " OR $this->table_alias.$this->real_field IS NULL)"; + } + } + else { + $where .= '= ***CURRENT_USER***'; + } + $this->query->add_where($this->options['group'], $where); + } +} diff --git a/sites/all/modules/views/modules/user/views_handler_filter_user_name.inc b/sites/all/modules/views/modules/user/views_handler_filter_user_name.inc new file mode 100644 index 0000000..8bf1a88 --- /dev/null +++ b/sites/all/modules/views/modules/user/views_handler_filter_user_name.inc @@ -0,0 +1,143 @@ +value) { + $result = db_query("SELECT * FROM {users} u WHERE uid IN (" . implode(', ', $this->value) . ")"); + while ($account = db_fetch_object($result)) { + if ($account->uid) { + $values[] = $account->name; + } + else { + $values[] = 'Anonymous'; // Intentionally NOT translated. + } + } + } + + sort($values); + $default_value = implode(', ', $values); + $form['value'] = array( + '#type' => 'textfield', + '#title' => t('Usernames'), + '#description' => t('Enter a comma separated list of user names.'), + '#default_value' => $default_value, + '#autocomplete_path' => 'admin/views/ajax/autocomplete/user', + ); + + if (!empty($form_state['exposed']) && !isset($form_state['input'][$this->options['expose']['identifier']])) { + $form_state['input'][$this->options['expose']['identifier']] = $default_value; + } + } + + function value_validate(&$form, &$form_state) { + $values = drupal_explode_tags($form_state['values']['options']['value']); + $uids = $this->validate_user_strings($form['value'], $values); + + if ($uids) { + $form_state['values']['options']['value'] = $uids; + } + } + + function accept_exposed_input($input) { + $rc = parent::accept_exposed_input($input); + + if ($rc) { + // If we have previously validated input, override. + if (isset($this->validated_exposed_input)) { + $this->value = $this->validated_exposed_input; + } + } + + return $rc; + } + + function exposed_validate(&$form, &$form_state) { + if (empty($this->options['exposed'])) { + return; + } + + if (empty($this->options['expose']['identifier'])) { + return; + } + + $identifier = $this->options['expose']['identifier']; + $values = drupal_explode_tags($form_state['values'][$identifier]); + + $uids = $this->validate_user_strings($form[$identifier], $values); + + if ($uids) { + $this->validated_exposed_input = $uids; + } + } + + /** + * Validate the user string. Since this can come from either the form + * or the exposed filter, this is abstracted out a bit so it can + * handle the multiple input sources. + */ + function validate_user_strings(&$form, $values) { + $uids = array(); + $placeholders = array(); + $args = array(); + $results = array(); + foreach ($values as $value) { + if (strtolower($value) == 'anonymous') { + $uids[] = 0; + } + else { + $missing[strtolower($value)] = TRUE; + $args[] = $value; + $placeholders[] = "'%s'"; + } + } + + if (!$args) { + return $uids; + } + + $result = db_query("SELECT * FROM {users} WHERE name IN (" . implode(', ', $placeholders) . ")", $args); + while ($account = db_fetch_object($result)) { + unset($missing[strtolower($account->name)]); + $uids[] = $account->uid; + } + + if ($missing) { + form_error($form, format_plural(count($missing), 'Unable to find user: @users', 'Unable to find users: @users', array('@users' => implode(', ', array_keys($missing))))); + } + + return $uids; + } + + function value_submit() { + // prevent array filter from removing our anonymous user. + } + + // Override to do nothing. + function get_value_options() { } + + function admin_summary() { + // set up $this->value_options for the parent summary + $this->value_options = array(); + + if ($this->value) { + $result = db_query("SELECT * FROM {users} u WHERE uid IN (" . implode(', ', $this->value) . ")"); + + while ($account = db_fetch_object($result)) { + if ($account->uid) { + $this->value_options[$account->uid] = $account->name; + } + else { + $this->value_options[$account->uid] = 'Anonymous'; // Intentionally NOT translated. + } + } + } + + return parent::admin_summary(); + } +} diff --git a/sites/all/modules/views/modules/user/views_handler_filter_user_roles.inc b/sites/all/modules/views/modules/user/views_handler_filter_user_roles.inc new file mode 100644 index 0000000..0b6720f --- /dev/null +++ b/sites/all/modules/views/modules/user/views_handler_filter_user_roles.inc @@ -0,0 +1,20 @@ +value_options = user_roles(TRUE); + unset($this->value_options[DRUPAL_AUTHENTICATED_RID]); + } + + /** + * Override empty and not empty operator labels to be clearer for user roles. + */ + function operators() { + $operators = parent::operators(); + $operators['empty']['title'] = t("Only has the 'authenticated user' role"); + $operators['not empty']['title'] = t("Has roles in addition to 'authenticated user'"); + return $operators; + } +} diff --git a/sites/all/modules/views/modules/user/views_plugin_argument_default_current_user.inc b/sites/all/modules/views/modules/user/views_plugin_argument_default_current_user.inc new file mode 100644 index 0000000..6eac18b --- /dev/null +++ b/sites/all/modules/views/modules/user/views_plugin_argument_default_current_user.inc @@ -0,0 +1,16 @@ +uid; + } +} + diff --git a/sites/all/modules/views/modules/user/views_plugin_argument_default_user.inc b/sites/all/modules/views/modules/user/views_plugin_argument_default_user.inc new file mode 100644 index 0000000..71a20bc --- /dev/null +++ b/sites/all/modules/views/modules/user/views_plugin_argument_default_user.inc @@ -0,0 +1,72 @@ +option_name] = array( + '#type' => 'checkbox', + '#title' => t('Also look for a node and use the node author'), + '#default_value' => !empty($this->argument->options[$this->option_name]), + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'radio:options[default_action]' => array('default'), + 'radio:options[default_argument_type]' => array($this->id) + ), + '#dependency_count' => 2, + ); + } + + function get_argument() { + foreach (range(1, 3) as $i) { + $user = menu_get_object('user', $i); + if (!empty($user)) { + return $user->uid; + } + } + + foreach (range(1, 3) as $i) { + $user = menu_get_object('user_uid_optional', $i); + if (!empty($user)) { + return $user->uid; + } + } + + if (!empty($this->argument->options[$this->option_name])) { + foreach (range(1, 3) as $i) { + $node = menu_get_object('node', $i); + if (!empty($node)) { + return $node->uid; + } + } + } + + if (arg(0) == 'user' && is_numeric(arg(1))) { + return arg(1); + } + + if (!empty($this->argument->options[$this->option_name])) { + if (arg(0) == 'node' && is_numeric(arg(1))) { + $node = node_load(arg(1)); + if ($node) { + return $node->uid; + } + } + } + + // If the current page is a view that takes uid as an argument, return the uid. + $views_page = views_get_page_view(); + + if ($views_page && isset($views_page->view->argument['uid'])) { + return $views_page->view->argument['uid']->argument; + } + } +} + diff --git a/sites/all/modules/views/modules/user/views_plugin_argument_validate_user.inc b/sites/all/modules/views/modules/user/views_plugin_argument_validate_user.inc new file mode 100644 index 0000000..78a9df3 --- /dev/null +++ b/sites/all/modules/views/modules/user/views_plugin_argument_validate_user.inc @@ -0,0 +1,117 @@ +argument->options['validate_user_argument_type'])) { + $this->argument->options['validate_user_argument_type'] = 'uid'; + $this->argument->options['validate_user_roles'] = array(); + } + + $form['validate_user_argument_type'] = array( + '#type' => 'radios', + '#title' => t('Type of user argument to allow'), + '#options' => array( + 'uid' => t('Only allow numeric UIDs'), + 'name' => t('Only allow string usernames'), + 'either' => t('Allow both numeric UIDs and string usernames'), + ), + '#default_value' => $this->argument->options['validate_user_argument_type'], + '#process' => array('expand_radios', 'views_process_dependency'), + '#dependency' => array('edit-options-validate-type' => array($this->id)), + '#prefix' => '
    ', + '#suffix' => '
    ', + ); + + $form['validate_user_restrict_roles'] = array( + '#type' => 'checkbox', + '#title' => t('Restrict user based on role'), + '#default_value' => !empty($this->argument->options['validate_user_restrict_roles']), + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-validate-type' => array($this->id)), + ); + + $form['validate_user_roles'] = array( + '#type' => 'checkboxes', + '#prefix' => '
    ', + '#suffix' => '
    ', + '#title' => t('Restrict to the selected roles'), + '#options' => user_roles(TRUE), + '#default_value' => $this->argument->options['validate_user_roles'], + '#description' => t('If no roles are selected, users from any role will be allowed.'), + '#process' => array('expand_checkboxes', 'views_process_dependency'), + '#dependency' => array( + 'edit-options-validate-type' => array($this->id), + 'edit-options-validate-user-restrict-roles' => array(1), + ), + '#dependency_count' => 2, + ); + } + + function validate_argument($argument) { + $type = $this->argument->options['validate_user_argument_type']; + // is_numeric() can return false positives, so we ensure it's an integer. + // However, is_integer() will always fail, since $argument is a string. + if (is_numeric($argument) && $argument == (int)$argument) { + if ($type == 'uid' || $type == 'either') { + if ($argument == $GLOBALS['user']->uid) { + // If you assign an object to a variable in PHP, the variable + // automatically acts as a reference, not a copy, so we use + // drupal_clone() to ensure that we don't actually mess with the + // real global $user object. + $account = drupal_clone($GLOBALS['user']); + } + $where = 'uid = %d'; + } + } + else { + if ($type == 'name' || $type == 'either') { + if ($argument == $GLOBALS['user']->name) { + $account = drupal_clone($GLOBALS['user']); + } + $where = "name = '%s'"; + } + } + + // If we don't have a WHERE clause, the argument is invalid. + if (empty($where)) { + return FALSE; + } + + if (!isset($account)) { + $query = "SELECT uid, name FROM {users} WHERE $where"; + $account = db_fetch_object(db_query($query, $argument)); + } + if (empty($account)) { + // User not found. + return FALSE; + } + + // See if we're filtering users based on roles. + if (!empty($this->argument->options['validate_user_restrict_roles']) && !empty($this->argument->options['validate_user_roles'])) { + $roles = $this->argument->options['validate_user_roles']; + $account->roles = array(); + $account->roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID; + $result = db_query('SELECT rid FROM {users_roles} WHERE uid = %d', $account->uid); + while ($role = db_fetch_object($result)) { + $account->roles[] = $role->rid; + } + if (!(bool)array_intersect($account->roles, $roles)) { + return FALSE; + } + } + + $this->argument->argument = $account->uid; + $this->argument->validated_title = check_plain($account->name); + return TRUE; + } +} + diff --git a/sites/all/modules/views/modules/views.views.inc b/sites/all/modules/views/modules/views.views.inc new file mode 100644 index 0000000..799a7f9 --- /dev/null +++ b/sites/all/modules/views/modules/views.views.inc @@ -0,0 +1,69 @@ + array(), + ); + + $data['views']['random'] = array( + 'title' => t('Random'), + 'help' => t('Randomize the display order.'), + 'sort' => array( + 'handler' => 'views_handler_sort_random', + ), + ); + + $data['views']['null'] = array( + 'title' => t('Null'), + 'help' => t('Allow an argument to be ignored. The query will not be altered by this argument.'), + 'argument' => array( + 'handler' => 'views_handler_argument_null', + ), + ); + + $data['views']['nothing'] = array( + 'title' => t('Custom text'), + 'help' => t('Provide custom text or link.'), + 'field' => array( + 'handler' => 'views_handler_field_custom', + ), + ); + + $data['views']['counter'] = array( + 'title' => t('View result counter'), + 'help' => t('Displays the actual position of the view result'), + 'field' => array( + 'handler' => 'views_handler_field_counter', + ), + ); + + if (module_invoke('ctools', 'api_version', '1.7.1')) { + $data['views']['expression'] = array( + 'title' => t('Math expression'), + 'help' => t('Evaluates a mathematical expression and displays it.'), + 'field' => array( + 'handler' => 'views_handler_field_math', + ), + ); + } + + return $data; +} + +/** + * @} + */ diff --git a/sites/all/modules/views/plugins/views_plugin_access.inc b/sites/all/modules/views/plugins/views_plugin_access.inc new file mode 100644 index 0000000..fe70823 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_access.inc @@ -0,0 +1,81 @@ +view = &$view; + $this->display = &$display; + $this->options = array(); + + if (is_object($display->handler)) { + // Note: The below is read only. + $this->options = $display->handler->get_option('access'); + } + } + + /** + * Retrieve the default options when this is a new access + * control plugin + */ + function option_defaults(&$options) { } + + /** + * Provide the default form for setting options. + */ + function options_form(&$form, &$form_state) { } + + /** + * Provide the default form form for validating options + */ + function options_validate(&$form, &$form_state) { } + + /** + * Provide the default form form for submitting options + */ + function options_submit(&$form, &$form_state) { } + + /** + * Return a string to display as the clickable title for the + * access control. + */ + function summary_title() { + return t('Unknown'); + } + + /** + * Determine if the current user has access or not. + */ + function access($account) { + // default to no access control. + return TRUE; + } + + /** + * Determine the access callback and arguments. + * + * This information will be embedded in the menu in order to reduce + * performance hits during menu item access testing, which happens + * a lot. + * + * @return an array; the first item should be the function to call, + * and the second item should be an array of arguments. The first + * item may also be TRUE (bool only) which will indicate no + * access control.) + */ + function get_access_callback() { + // default to no access control. + return TRUE; + } +} diff --git a/sites/all/modules/views/plugins/views_plugin_access_none.inc b/sites/all/modules/views/plugins/views_plugin_access_none.inc new file mode 100644 index 0000000..be563a2 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_access_none.inc @@ -0,0 +1,10 @@ +options['perm'], $account); + } + + function get_access_callback() { + return array('views_check_perm', array($this->options['perm'])); + } + + function summary_title() { + return t($this->options['perm']); + } + + function option_defaults(&$options) { + $options['perm'] = 'access content'; + } + + function options_form(&$form, &$form_state) { + $perms = array(); + // Get list of permissions + foreach (module_list(FALSE, FALSE, TRUE) as $module) { + if ($permissions = module_invoke($module, 'perm')) { + $perms[$module] = drupal_map_assoc($permissions); + } + } + $form['perm'] = array( + '#type' => 'select', + '#options' => $perms, + '#title' => t('Permission'), + '#default_value' => $this->options['perm'], + '#description' => t('Only users with the selected permission flag will be able to access this display. Note that users with "access all views" can see any view, regardless of other permissions.'), + ); + } +} diff --git a/sites/all/modules/views/plugins/views_plugin_access_role.inc b/sites/all/modules/views/plugins/views_plugin_access_role.inc new file mode 100644 index 0000000..edd0b07 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_access_role.inc @@ -0,0 +1,54 @@ +options['role']), $account); + } + + function get_access_callback() { + return array('views_check_roles', array(array_filter($this->options['role']))); + } + + function summary_title() { + $count = count($this->options['role']); + if ($count < 1) { + return t('No role(s) selected'); + } + else if ($count > 1) { + return t('Multiple roles'); + } + else { + $rids = views_ui_get_roles(); + $rid = reset($this->options['role']); + return $rids[$rid]; + } + } + + function option_defaults(&$options) { + $options['role'] = array(); + } + + function options_form(&$form, &$form_state) { + $form['role'] = array( + '#type' => 'checkboxes', + '#title' => t('Role'), + '#default_value' => $this->options['role'], + '#options' => views_ui_get_roles(), + '#description' => t('Only the checked roles will be able to access this display. Note that users with "access all views" can see any view, regardless of role.'), + ); + } + + function options_validate(&$form, &$form_state) { + if (!array_filter($form_state['values']['access_options']['role'])) { + form_error($form['role'], t('You must select at least one role if type is "by role"')); + } + } + + function options_submit(&$form, &$form_state) { + // I hate checkboxes. + $form_state['values']['access_options']['role'] = array_filter($form_state['values']['access_options']['role']); + } +} diff --git a/sites/all/modules/views/plugins/views_plugin_argument_default.inc b/sites/all/modules/views/plugins/views_plugin_argument_default.inc new file mode 100644 index 0000000..1715ef2 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_argument_default.inc @@ -0,0 +1,78 @@ +view = &$view; + $this->argument = &$argument; + $this->id = $id; + } + + /** + * Determine if the administrator has the privileges to use this + * plugin + */ + function access() { return TRUE; } + + function argument_form(&$form, &$form_state) { + $form[$this->option_name] = array( + '#type' => 'textfield', + '#title' => t('Default argument'), + '#default_value' => $this->get_argument(), + '#process' => array('views_process_dependency'), + '#dependency' => array( + 'radio:options[default_action]' => array('default'), + 'radio:options[default_argument_type]' => array($this->id) + ), + '#dependency_count' => 2, + ); + + // Only do this if using one simple standard form gadget + $this->check_access($form); + } + + /** + * If we don't have access to the form but are showing it anyway, ensure that + * the form is safe and cannot be changed from user input. + */ + function check_access(&$form) { + if (!$this->access()) { + $form[$this->option_name]['#disabled'] = TRUE; + $form[$this->option_name]['#value'] = $form[$this->option_name]['#default_value']; + $form[$this->option_name]['#description'] .= ' ' . t('Note: you do not have permission to modify this. If you change the default argument type, this setting will be lost and you will NOT be able to get it back.') . ''; + } + } + + /** + * Return the default argument. + */ + function get_argument() { + return isset($this->argument->options[$this->option_name]) ? $this->argument->options[$this->option_name] : ''; + } +} + +/** + * @} + */ + diff --git a/sites/all/modules/views/plugins/views_plugin_argument_default_php.inc b/sites/all/modules/views/plugins/views_plugin_argument_default_php.inc new file mode 100644 index 0000000..a480899 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_argument_default_php.inc @@ -0,0 +1,51 @@ +option_name] = array( + '#type' => 'textarea', + '#title' => t('PHP argument code'), + '#default_value' => $this->get_argument(TRUE), // the true forces it raw. + '#process' => array('views_process_dependency'), + '#description' => t('Enter PHP code that returns a value to use for this argument. Do not use <?php ?>. You must return only a single value for just this argument.'), + '#dependency' => array( + 'radio:options[default_action]' => array('default'), + 'radio:options[default_argument_type]' => array($this->id) + ), + '#dependency_count' => 2, + ); + + $this->check_access($form); + } + + /** + * Only let users with PHP block visibility permissions set/modify this + * default plugin. + */ + function access() { + return user_access('use PHP for block visibility'); + } + + function get_argument($raw = FALSE) { + if ($raw) { + return parent::get_argument(); + } + + // set up variables to make it easier to reference during the argument. + $view = &$this->view; + $argument = &$this->argument; + ob_start(); + $result = eval($this->argument->options[$this->option_name]); + ob_end_clean(); + return $result; + } +} diff --git a/sites/all/modules/views/plugins/views_plugin_argument_validate.inc b/sites/all/modules/views/plugins/views_plugin_argument_validate.inc new file mode 100644 index 0000000..3971bad --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_argument_validate.inc @@ -0,0 +1,70 @@ +view = &$view; + $this->argument = &$argument; + $this->id = $id; + } + + /** + * Determine if the administrator has the privileges to use this + * plugin + */ + function access() { return TRUE; } + + function argument_form(&$form, &$form_state) { + } + + /** + * If we don't have access to the form but are showing it anyway, ensure that + * the form is safe and cannot be changed from user input. + */ + function check_access(&$form) { + if (!$this->access()) { + $form[$this->option_name]['#disabled'] = TRUE; + $form[$this->option_name]['#value'] = $form[$this->option_name]['#default_value']; + $form[$this->option_name]['#description'] .= ' ' . t('Note: you do not have permission to modify this. If you change the validator, this setting will be lost and you will NOT be able to get it back.') . ''; + } + } + + /** + * Return the validate argument. + */ + function get_argument() { + return isset($this->argument->options[$this->option_name]) ? $this->argument->options[$this->option_name] : ''; + } + + function validate_form(&$form, &$form_state) { } + + function validate_argument($arg) { return TRUE; } +} + +/** + * @} + */ + diff --git a/sites/all/modules/views/plugins/views_plugin_argument_validate_numeric.inc b/sites/all/modules/views/plugins/views_plugin_argument_validate_numeric.inc new file mode 100644 index 0000000..80d440f --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_argument_validate_numeric.inc @@ -0,0 +1,27 @@ +argument->definition['numeric']); + } + + function validate_argument($argument) { + return is_numeric($argument); + } +} + diff --git a/sites/all/modules/views/plugins/views_plugin_argument_validate_php.inc b/sites/all/modules/views/plugins/views_plugin_argument_validate_php.inc new file mode 100644 index 0000000..3233112 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_argument_validate_php.inc @@ -0,0 +1,47 @@ +option_name] = array( + '#type' => 'textarea', + '#title' => t('PHP validate code'), + '#default_value' => $this->get_argument(), + '#description' => t('Enter PHP code that returns TRUE or FALSE. No return is the same as FALSE, so be SURE to return something if you do not want to declare the argument invalid. Do not use <?php ?>. The argument to validate will be "$argument" and the view will be "$view". You may change the argument by setting "$handler->argument".'), + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-options-validate-type' => array($this->id)), + ); + + $this->check_access($form); + } + + /** + * Only let users with PHP block visibility permissions set/modify this + * validate plugin. + */ + function access() { + return user_access('use PHP for block visibility'); + } + + function validate_argument($argument) { + // set up variables to make it easier to reference during the argument. + $view = &$this->view; + $handler = &$this->argument; + + ob_start(); + $result = eval($this->argument->options[$this->option_name]); + ob_end_clean(); + return $result; + } +} + diff --git a/sites/all/modules/views/plugins/views_plugin_cache.inc b/sites/all/modules/views/plugins/views_plugin_cache.inc new file mode 100644 index 0000000..34e4d91 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_cache.inc @@ -0,0 +1,299 @@ +view = &$view; + $this->display = &$display; + $this->options = array(); + + if (is_object($display->handler)) { + // Note: The below is read only. + $this->options = $display->handler->get_option('cache'); + } + } + + /** + * Retrieve the default options when this is a new access + * control plugin + */ + function option_defaults(&$options) { } + + /** + * Return a string to display as the clickable title for the + * access control. + */ + function summary_title() { + return t('Unknown'); + } + + /** + * Determine the expiration time of the cache type, or NULL if no expire. + * + * Plugins must override this to implement expiration. + * + * @param $type + * The cache type, either 'query', 'result' or 'output'. + */ + function cache_expire($type) { } + + /** + * Determine expiration time in the cache table of the cache type + * or CACHE_PERMANENT if item shouldn't be removed automatically from cache. + * + * Plugins must override this to implement expiration in the cache table. + * + * @param $type + * The cache type, either 'query', 'result' or 'output'. + */ + function cache_set_expire($type) { + return CACHE_PERMANENT; + } + + + /** + * Save data to the cache. + * + * A plugin should override this to provide specialized caching behavior. + */ + function cache_set($type) { + switch ($type) { + case 'query': + // Not supported currently, but this is certainly where we'd put it. + break; + case 'results': + $data = array( + 'result' => $this->view->result, + 'total_rows' => $this->view->total_rows, + 'pager' => $this->view->pager, + ); + cache_set($this->get_results_key(), $data, $this->table, $this->cache_set_expire($type)); + break; + case 'output': + $this->gather_headers(); + $this->storage['output'] = $this->view->display_handler->output; + cache_set($this->get_output_key(), $this->storage, $this->table, $this->cache_set_expire($type)); + break; + } + } + + + /** + * Retrieve data from the cache. + * + * A plugin should override this to provide specialized caching behavior. + */ + function cache_get($type) { + $cutoff = $this->cache_expire($type); + switch ($type) { + case 'query': + // Not supported currently, but this is certainly where we'd put it. + return FALSE; + case 'results': + // Values to set: $view->result, $view->total_rows, $view->execute_time, + // $view->pager['current_page']. + if ($cache = cache_get($this->get_results_key(), $this->table)) { + if (!$cutoff || $cache->created > $cutoff) { + $this->view->result = $cache->data['result']; + $this->view->total_rows = $cache->data['total_rows']; + $this->view->pager = $cache->data['pager']; + $this->view->execute_time = 0; + return TRUE; + } + } + return FALSE; + case 'output': + if ($cache = cache_get($this->get_output_key(), $this->table)) { + if (!$cutoff || $cache->created > $cutoff) { + $this->storage = $cache->data; + $this->view->display_handler->output = $cache->data['output']; + $this->restore_headers(); + return TRUE; + } + } + return FALSE; + } + } + + /** + * Clear out cached data for a view. + * + * We're just going to nuke anything related to the view, regardless of display, + * to be sure that we catch everything. Maybe that's a bad idea. + */ + function cache_flush() { + cache_clear_all($this->view->name . ':', $this->table, TRUE); + } + + /** + * Post process any rendered data. + * + * This can be valuable to be able to cache a view and still have some level of + * dynamic output. In an ideal world, the actual output will include HTML + * comment based tokens, and then the post process can replace those tokens. + * + * Example usage. If it is known that the view is a node view and that the + * primary field will be a nid, you can do something like this: + * + * + * + * And then in the post render, create an array with the text that should + * go there: + * + * strtr($output, array('', 'output for FIELD of nid 1'); + * + * All of the cached result data will be available in $view->result, as well, + * so all ids used in the query should be discoverable. + */ + function post_render(&$output) { } + + /** + * Start caching javascript, css and other out of band info. + * + * This takes a snapshot of the current system state so that we don't + * duplicate it. Later on, when gather_headers() is run, this information + * will be removed so that we don't hold onto it. + */ + function cache_start() { + $this->storage['head'] = drupal_set_html_head(); + $this->storage['css'] = drupal_add_css(); + + foreach (array('header', 'footer') as $scope) { + $this->storage['js'][$scope] = drupal_add_js(NULL, NULL, $scope); + } + } + + /** + * Gather out of band data, compare it to what we started with and store the difference. + */ + function gather_headers() { + // Simple replacement for head + $this->storage['head'] = str_replace($this->storage['head'], '', drupal_set_html_head()); + + // Slightly less simple for CSS: + $css = drupal_add_css(); + $start = $this->storage['css']; + $this->storage['css'] = array(); + + foreach ($css as $media => $medias) { + foreach ($medias as $type => $types) { + foreach ($types as $path => $preprocess) { + if (!isset($start[$media][$type][$path])) { + $this->storage['css'][] = array($path, $type, $media, $preprocess); + } + } + } + } + + $js = array(); + // A little less simple for js + foreach (array('header', 'footer') as $scope) { + $js[$scope] = drupal_add_js(NULL, NULL, $scope); + } + + $start = $this->storage['js']; + $this->storage['js'] = array(); + + foreach ($js as $scope => $scopes) { + foreach ($scopes as $type => $types) { + foreach ($types as $id => $info) { + if (!isset($start[$scope][$type][$id])) { + switch ($type) { + case 'setting': + $this->storage['js'][] = array($info, $type, $scope); + break; + + case 'inline': + $this->storage['js'][] = array($info['code'], $type, $scope, $info['defer']); + break; + + default: + $this->storage['js'][] = array($id, $type, $scope, $info['defer'], $info['cache']); + } + } + } + } + } + } + + /** + * Restore out of band data saved to cache. Copied from Panels. + */ + function restore_headers() { + if (!empty($this->storage['head'])) { + drupal_set_html_head($this->storage['head']); + } + if (!empty($this->storage['css'])) { + foreach ($this->storage['css'] as $args) { + call_user_func_array('drupal_add_css', $args); + } + } + if (!empty($this->storage['js'])) { + foreach ($this->storage['js'] as $args) { + call_user_func_array('drupal_add_js', $args); + } + } + } + + function get_results_key() { + global $user; + + if (!isset($this->_results_key)) { + $key_data = array( + 'build_info' => $this->view->build_info, + 'roles' => array_keys($user->roles), + 'super-user' => $user->uid == 1, // special caching for super user. + 'language' => $GLOBALS['language'], + ); + foreach (array('exposed_info', 'page', 'sort', 'order') as $key) { + if (isset($_GET[$key])) { + $key_data[$key] = $_GET[$key]; + } + } + + $this->_results_key = $this->view->name . ':' . $this->display->id . ':results:' . md5(serialize($key_data)); + } + + return $this->_results_key; + } + + function get_output_key() { + global $user; + if (!isset($this->_output_key)) { + $key_data = array( + 'result' => $this->view->result, + 'roles' => array_keys($user->roles), + 'super-user' => $user->uid == 1, // special caching for super user. + 'theme' => $GLOBALS['theme'], + 'language' => $GLOBALS['language'], + ); + + $this->_output_key = $this->view->name . ':' . $this->display->id . ':output:' . md5(serialize($key_data)); + } + + return $this->_output_key; + } + +} diff --git a/sites/all/modules/views/plugins/views_plugin_cache_none.inc b/sites/all/modules/views/plugins/views_plugin_cache_none.inc new file mode 100644 index 0000000..9cc2757 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_cache_none.inc @@ -0,0 +1,18 @@ + t('Never cache')) + $options; + + $form['results_lifespan'] = array( + '#type' => 'select', + '#title' => t('Query results'), + '#description' => t('The length of time raw query results should be cached.'), + '#options' => $options, + '#default_value' => $this->options['results_lifespan'], + ); + $form['output_lifespan'] = array( + '#type' => 'select', + '#title' => t('Rendered output'), + '#description' => t('The length of time rendered HTML output should be cached.'), + '#options' => $options, + '#default_value' => $this->options['output_lifespan'], + ); + } + + function summary_title() { + return format_interval($this->options['results_lifespan'], 1) . '/' . format_interval($this->options['output_lifespan'], 1); + } + + function cache_expire($type) { + if ($lifespan = $this->options[$type . '_lifespan']) { + $cutoff = time() - $lifespan; + return $cutoff; + } + else { + return FALSE; + } + } + + function cache_set_expire($type) { + if ($lifespan = $this->options[$type . '_lifespan']) { + return time() + $lifespan; + } + else { + return CACHE_PERMANENT; + } + } +} diff --git a/sites/all/modules/views/plugins/views_plugin_display.inc b/sites/all/modules/views/plugins/views_plugin_display.inc new file mode 100644 index 0000000..3c47037 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_display.inc @@ -0,0 +1,1995 @@ +view = &$view; + $this->display = &$display; + + // Make some modifications: + if (!isset($options)) { + $options = $display->display_options; + } + + if ($this->is_default_display() && isset($options['defaults'])) { + unset($options['defaults']); + } + + $this->unpack_options($this->options, $options); + } + + function destroy() { + parent::destroy(); + + foreach ($this->handlers as $type => $handlers) { + foreach ($handlers as $id => $handler) { + if (is_object($handler)) { + $this->handlers[$type][$id]->destroy(); + } + } + } + + if (isset($this->default_display)) { + unset($this->default_display); + } + } + + /** + * Determine if this display is the 'default' display which contains + * fallback settings + */ + function is_default_display() { return FALSE; } + + /** + * Determine if this display uses exposed filters, so the view + * will know whether or not to build them. + */ + function uses_exposed() { + if (!isset($this->has_exposed)) { + foreach (array('field', 'filter') as $type) { + foreach ($this->view->$type as $key => $handler) { + if ($handler->is_exposed()) { + // one is all we need; if we find it, return true. + $this->has_exposed = TRUE; + return TRUE; + } + } + } + $this->has_exposed = FALSE; + } + + return $this->has_exposed; + } + + /** + * Determine if this display should display the exposed + * filters widgets, so the view will know whether or not + * to render them. + * + * Regardless of what this function + * returns, exposed filters will not be used nor + * displayed unless uses_exposed() returns TRUE. + */ + function displays_exposed() { + return TRUE; + } + + /** + * Does the display use AJAX? + */ + function use_ajax() { + if (!empty($this->definition['use ajax'])) { + return $this->get_option('use_ajax'); + } + return FALSE; + } + + /** + * Does the display have a pager enabled? + */ + function use_pager() { + if (!empty($this->definition['use pager'])) { + return $this->get_option('use_pager'); + } + return FALSE; + } + + /** + * Does the display render the pager if it has it enabled? + */ + function render_pager() { + return $this->use_pager(); + } + + /** + * Does the display have a more link enabled? + */ + function use_more() { + if (!empty($this->definition['use more'])) { + return $this->get_option('use_more'); + } + return FALSE; + } + + /** + * Should the enabled display more link be shown when no more items? + */ + function use_more_always() { + if (!empty($this->definition['use more'])) { + return $this->get_option('use_more_always'); + } + return FALSE; + } + + /** + * Does the display have custom link text? + */ + function use_more_text() { + if (!empty($this->definition['use more'])) { + return $this->get_option('use_more_text'); + } + return FALSE; + } + + /** + * Can this display accept attachments? + */ + function accept_attachments() { + return !empty($this->definition['accept attachments']); + } + + /** + * Allow displays to attach to other views. + */ + function attach_to($display_id) { } + + /** + * Static member function to list which sections are defaultable + * and what items each section contains. + */ + function defaultable_sections($section = NULL) { + $sections = array( + 'access' => array('access'), + 'cache' => array('cache'), + 'title' => array('title'), + 'css_class' => array('css_class'), + 'header' => array('header', 'header_format', 'header_empty'), + 'footer' => array('footer', 'footer_format', 'footer_empty'), + 'empty' => array('empty', 'empty_format'), + 'use_ajax' => array('use_ajax'), + 'items_per_page' => array('items_per_page', 'offset', 'use_pager', 'pager_element'), + 'use_pager' => array('items_per_page', 'offset', 'use_pager', 'pager_element'), + 'use_more' => array('use_more', 'use_more_always', 'use_more_text'), + 'link_display' => array('link_display'), + 'distinct' => array('distinct'), + 'exposed_block' => array('exposed_block'), + + // Force these to cascade properly. + 'style_plugin' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'), + 'style_options' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'), + 'row_plugin' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'), + 'row_options' => array('style_plugin', 'style_options', 'row_plugin', 'row_options'), + + // These guys are special + 'relationships' => array('relationships'), + 'fields' => array('fields'), + 'sorts' => array('sorts'), + 'arguments' => array('arguments'), + 'filters' => array('filters'), + ); + if ($section) { + if (!empty($sections[$section])) { + return $sections[$section]; + } + } + else { + return $sections; + } + } + + /** + * Set default options. + * + * Displays put their options in a different place than everything else; also + * displays spread their options out. We don't want to set defaults for + * items that are normally defaulted elsewhere. + */ + function _set_option_defaults(&$storage, $options, $level = 0) { + foreach ($options as $option => $definition) { + // If defaulted to elsewhere and we're not the default display, skip. + if ($level == 0 && !$this->is_default_display() && !empty($options['defaults']['default'][$option])) { + continue; + } + + if (isset($definition['contains']) && is_array($definition['contains'])) { + $storage[$option] = array(); + $this->_set_option_defaults($storage[$option], $definition['contains'], $level++); + } + else { + $storage[$option] = isset($definition['default']) ? $definition['default'] : NULL; + } + } + } + + function option_definition() { + $options = array( + 'defaults' => array( + 'default' => array( + 'access' => TRUE, + 'cache' => TRUE, + 'title' => TRUE, + 'css_class' => TRUE, + 'header' => TRUE, + 'header_format' => TRUE, + 'header_empty' => TRUE, + 'footer' => TRUE, + 'footer_format' => TRUE, + 'footer_empty' => TRUE, + 'empty' => TRUE, + 'empty_format' => TRUE, + + 'use_ajax' => TRUE, + 'items_per_page' => TRUE, + 'offset' => TRUE, + 'use_pager' => TRUE, + 'pager_element' => TRUE, + 'use_more' => TRUE, + 'use_more_always' => TRUE, + 'use_more_text' => TRUE, + 'distinct' => TRUE, + 'exposed_block' => TRUE, + + 'link_display' => TRUE, + + 'style_plugin' => TRUE, + 'style_options' => TRUE, + 'row_plugin' => TRUE, + 'row_options' => TRUE, + + 'relationships' => TRUE, + 'fields' => TRUE, + 'sorts' => TRUE, + 'arguments' => TRUE, + 'filters' => TRUE, + ), + ), + 'relationships' => array( + 'default' => array(), + 'export' => 'export_item', + ), + 'fields' => array( + 'default' => array(), + 'export' => 'export_item', + ), + 'sorts' => array( + 'default' => array(), + 'export' => 'export_item', + ), + 'arguments' => array( + 'default' => array(), + 'export' => 'export_item', + ), + 'filters' => array( + 'default' => array(), + 'export' => 'export_item', + ), + 'access' => array( + 'contains' => array( + 'type' => array('default' => 'none'), + ), + ), + 'cache' => array( + 'contains' => array( + 'type' => array('default' => 'none'), + ), + ), + 'title' => array( + 'default' => '', + 'translatable' => TRUE, + ), + 'css_class' => array( + 'default' => '', + 'translatable' => FALSE, + ), + 'header' => array( + 'default' => '', + 'translatable' => TRUE, + ), + 'header_format' => array( + 'default' => FILTER_FORMAT_DEFAULT, + ), + 'header_empty' => array( + 'default' => FALSE, + ), + 'footer' => array( + 'default' => '', + 'translatable' => TRUE, + ), + 'footer_format' => array( + 'default' => FILTER_FORMAT_DEFAULT, + ), + 'footer_empty' => array( + 'default' => FALSE, + ), + 'empty' => array( + 'default' => '', + 'translatable' => TRUE, + ), + 'empty_format' => array( + 'default' => FILTER_FORMAT_DEFAULT, + ), + 'use_ajax' => array( + 'default' => FALSE, + ), + 'items_per_page' => array( + 'default' => 10, + ), + 'offset' => array( + 'default' => 0, + ), + 'use_pager' => array( + 'default' => FALSE, + ), + 'pager_element' => array( + 'default' => 0, + ), + 'use_more' => array( + 'default' => FALSE, + ), + 'use_more_always' => array( + 'default' => FALSE, + ), + 'use_more_text' => array( + 'default' => 'more', + 'translatable' => TRUE, + ), + 'link_display' => array( + 'default' => '', + ), + 'distinct' => array( + 'default' => FALSE, + ), + + 'style_plugin' => array( + 'default' => 'default', + ), + 'style_options' => array( + 'default' => array(), + ), + 'row_plugin' => array( + 'default' => 'fields', + ), + 'row_options' => array( + 'default' => array(), + ), + + 'exposed_block' => array( + 'default' => FALSE, + ), + ); + + if ($this->is_default_display()) { + unset($options['defaults']); + } + return $options; + } + + /** + * Check to see if the display has a 'path' field. + * + * This is a pure function and not just a setting on the definition + * because some displays (such as a panel pane) may have a path based + * upon configuration. + * + * By default, displays do not have a path. + */ + function has_path() { return FALSE; } + + /** + * Check to see if the display has some need to link to another display. + * + * For the most part, displays without a path will use a link display. However, + * sometimes displays that have a path might also need to link to another display. + * This is true for feeds. + */ + function uses_link_display() { return !$this->has_path(); } + + /** + * Check to see which display to use when creating links within + * a view using this display. + */ + function get_link_display() { + $display_id = $this->get_option('link_display'); + // If unknown, pick the first one. + if (empty($display_id) || empty($this->view->display[$display_id])) { + foreach ($this->view->display as $display_id => $display) { + if (!empty($display->handler) && $display->handler->has_path()) { + return $display_id; + } + } + } + else { + return $display_id; + } + // fall-through returns NULL + } + + /** + * Return the base path to use for this display. + * + * This can be overridden for displays that do strange things + * with the path. + */ + function get_path() { + if ($this->has_path()) { + return $this->get_option('path'); + } + + $display_id = $this->get_link_display(); + if ($display_id && !empty($this->view->display[$display_id]) && is_object($this->view->display[$display_id]->handler)) { + return $this->view->display[$display_id]->handler->get_path(); + } + } + + /** + * Check to see if the display needs a breadcrumb + * + * By default, displays do not need breadcrumbs + */ + function uses_breadcrumb() { return FALSE; } + + /** + * Determine if a given option is set to use the default display or the + * current display + * + * @return + * TRUE for the default display + */ + function is_defaulted($option) { + return !$this->is_default_display() && !empty($this->default_display) && !empty($this->options['defaults'][$option]); + } + + /** + * Intelligently get an option either from this display or from the + * default display, if directed to do so. + */ + function get_option($option) { + if ($this->is_defaulted($option)) { + return $this->default_display->get_option($option); + } + + if (array_key_exists($option, $this->options)) { + return $this->options[$option]; + } + } + + /** + * Determine if the display's style uses fields. + */ + function uses_fields() { + $plugin = $this->get_plugin(); + if ($plugin) { + return $plugin->uses_fields(); + } + } + + /** + * Get the display or row plugin, if it exists. + */ + function get_plugin($type = 'style', $name = NULL) { + if (!$name) { + $name = $this->get_option($type . '_plugin'); + } + + $plugin = views_get_plugin($type, $name); + if ($plugin) { + $options = $this->get_option($type . '_options'); + $plugin->init($this->view, $this->display, $options); + return $plugin; + } + } + + /** + * Get the access plugin + */ + function get_access_plugin($name = NULL) { + if (!$name) { + $access = $this->get_option('access'); + $name = $access['type']; + } + + $plugin = views_get_plugin('access', $name); + if ($plugin) { + $plugin->init($this->view, $this->display); + return $plugin; + } + } + + /** + * Get the cache plugin + */ + function get_cache_plugin($name = NULL) { + if (!$name) { + $cache = $this->get_option('cache'); + $name = $cache['type']; + } + + $plugin = views_get_plugin('cache', $name); + if ($plugin) { + $plugin->init($this->view, $this->display); + return $plugin; + } + } + + /** + * Get the handler object for a single handler. + */ + function &get_handler($type, $id) { + if (!isset($this->handlers[$type])) { + $this->get_handlers($type); + } + + if (isset($this->handlers[$type][$id])) { + return $this->handlers[$type][$id]; + } + + // So we can return a reference. + $null = NULL; + return $null; + } + + /** + * Get a full array of handlers for $type. This caches them. + */ + function get_handlers($type) { + if (!isset($this->handlers[$type])) { + $this->handlers[$type] = array(); + $types = views_object_types(); + $plural = $types[$type]['plural']; + foreach ($this->get_option($plural) as $id => $info) { + if ($info['id'] != $id) { + $info['id'] = $id; + } + + $handler = views_get_handler($info['table'], $info['field'], $type); + if ($handler) { + $handler->init($this->view, $info); + $this->handlers[$type][$id] = &$handler; + } + + // Prevent reference problems. + unset($handler); + } + } + + return $this->handlers[$type]; + } + + /** + * Retrieve a list of fields for the current display with the + * relationship associated if it exists. + */ + function get_field_labels() { + $options = array(); + foreach ($this->get_handlers('relationship') as $relationship => $handler) { + if ($label = $handler->label()) { + $relationships[$relationship] = $label; + } + else { + $relationships[$relationship] = $handler->ui_name(); + } + } + + foreach ($this->get_handlers('field') as $id => $handler) { + if ($label = $handler->label()) { + $options[$id] = $label; + } + else { + $options[$id] = $handler->ui_name(); + } + if (!empty($handler->options['relationship']) && !empty($relationships[$handler->options['relationship']])) { + $options[$id] = '(' . $relationships[$handler->options['relationship']] . ') ' . $options[$id]; + } + } + return $options; + } + + /** + * Intelligently set an option either from this display or from the + * default display, if directed to do so. + */ + function set_option($option, $value) { + if ($this->is_defaulted($option)) { + return $this->default_display->set_option($option, $value); + } + + // Set this in two places: On the handler where we'll notice it + // but also on the display object so it gets saved. This should + // only be a temporary fix. + $this->display->display_options[$option] = $value; + return $this->options[$option] = $value; + } + + /** + * Set an option and force it to be an override. + */ + function override_option($option, $value) { + $this->set_override($option, FALSE); + $this->set_option($option, $value); + } + + /** + * Because forms may be split up into sections, this provides + * an easy URL to exactly the right section. Don't override this. + */ + function option_link($text, $section, $class = '', $title = '') { + if (!empty($class)) { + $text = '' . $text . ''; + } + + if (!trim($text)) { + $text = t('Broken field'); + } + + if (empty($title)) { + $title = $text; + } + + return l($text, 'admin/build/views/nojs/display/' . $this->view->name . '/' . $this->display->id . '/' . $section, array('attributes' => array('class' => 'views-ajax-link ' . $class, 'title' => $title), 'html' => TRUE)); + } + + /** + * Provide the default summary for options in the views UI. + * + * This output is returned as an array. + */ + function options_summary(&$categories, &$options) { + $categories['basic'] = array( + 'title' => t('Basic settings'), + ); + + $options['display_title'] = array( + 'category' => 'basic', + 'title' => t('Name'), + 'value' => check_plain($this->display->display_title), + 'desc' => t('Change the name of this display.'), + ); + + $title = strip_tags($this->get_option('title')); + if (!$title) { + $title = t('None'); + } + + $options['title'] = array( + 'category' => 'basic', + 'title' => t('Title'), + 'value' => $title, + 'desc' => t('Change the title that this display will use.'), + ); + + $style_plugin = views_fetch_plugin_data('style', $this->get_option('style_plugin')); + $style_title = empty($style_plugin['title']) ? t('Missing style plugin') : $style_plugin['title']; + + $style = ''; + + $options['style_plugin'] = array( + 'category' => 'basic', + 'title' => t('Style'), + 'value' => $style_title, + 'desc' => t('Change the style plugin.'), + ); + + // This adds a 'Settings' link to the style_options setting if the style has options. + if (!empty($style_plugin['uses options'])) { + $options['style_plugin']['links']['style_options'] = t('Change settings for this style'); + } + + if (!empty($style_plugin['uses row plugin'])) { + $row_plugin = views_fetch_plugin_data('row', $this->get_option('row_plugin')); + $row_title = empty($row_plugin['title']) ? t('Missing style plugin') : $row_plugin['title']; + + $options['row_plugin'] = array( + 'category' => 'basic', + 'title' => t('Row style'), + 'value' => $row_title, + 'desc' => t('Change the row plugin.'), + ); + // This adds a 'Settings' link to the row_options setting if the row style has options. + if (!empty($row_plugin['uses options'])) { + $options['row_plugin']['links']['row_options'] = t('Change settings for this style'); + } + } + if (!empty($this->definition['use ajax'])) { + $options['use_ajax'] = array( + 'category' => 'basic', + 'title' => t('Use AJAX'), + 'value' => $this->get_option('use_ajax') ? t('Yes') : t('No'), + 'desc' => t('Change whether or not this display will use AJAX.'), + ); + } + + if (!empty($this->definition['use pager'])) { + $options['use_pager'] = array( + 'category' => 'basic', + 'title' => t('Use pager'), + 'value' => $this->get_option('use_pager') ? ($this->get_option('use_pager') === 'mini' ? t('Mini') : t('Yes')) : t('No'), + 'desc' => t("Change this display's pager setting."), + ); + } + + $items = intval($this->get_option('items_per_page')); + $options['items_per_page'] = array( + 'category' => 'basic', + 'title' => $this->use_pager() ? t('Items per page') : t('Items to display'), + 'value' => $items ? $items : t('Unlimited'), + 'desc' => t('Change how many items to display.'), + ); + + if (!empty($this->definition['use more'])) { + $options['use_more'] = array( + 'category' => 'basic', + 'title' => t('More link'), + 'value' => $this->get_option('use_more') ? t('Yes') : t('No'), + 'desc' => t('Specify whether this display will provide a "more" link.'), + ); + } + + $options['distinct'] = array( + 'category' => 'basic', + 'title' => t('Distinct'), + 'value' => $this->get_option('distinct') ? t('Yes') : t('No'), + 'desc' => t('Display only distinct items, without duplicates.'), + ); + + $access_plugin = $this->get_access_plugin(); + if (!$access_plugin) { + // default to the no access control plugin. + $access_plugin = views_get_plugin('access', 'none'); + } + + $access_str = $access_plugin->summary_title(); + + $options['access'] = array( + 'category' => 'basic', + 'title' => t('Access'), + 'value' => $access_str, + 'desc' => t('Specify access control type for this display.'), + ); + + if (!empty($access_plugin->definition['uses options'])) { + $options['access']['links']['access_options'] = t('Change settings for this access type.'); + } + + $cache_plugin = $this->get_cache_plugin(); + if (!$cache_plugin) { + // default to the no cache control plugin. + $cache_plugin = views_get_plugin('cache', 'none'); + } + + $cache_str = $cache_plugin->summary_title(); + + $options['cache'] = array( + 'category' => 'basic', + 'title' => t('Caching'), + 'value' => $cache_str, + 'desc' => t('Specify caching type for this display.'), + ); + + if (!empty($cache_plugin->definition['uses options'])) { + $options['cache']['links']['cache_options'] = t('Change settings for this caching type.'); + } + + if ($this->uses_link_display()) { + // Only show the 'link display' if there is more than one option. + $count = 0; + foreach ($this->view->display as $display_id => $display) { + if (is_object($display->handler) && $display->handler->has_path()) { + $count++; + } + if ($count > 1) { + break; + } + } + + if ($count > 1) { + $display_id = $this->get_link_display(); + $link_display = empty($this->view->display[$display_id]) ? t('None') : check_plain($this->view->display[$display_id]->display_title); + $options['link_display'] = array( + 'category' => 'basic', + 'title' => t('Link display'), + 'value' => $link_display, + 'desc' => t('Specify which display this display will link to.'), + ); + } + } + + $options['exposed_block'] = array( + 'category' => 'basic', + 'title' => t('Exposed form in block'), + 'value' => $this->get_option('exposed_block') ? t('Yes') : t('No'), + 'desc' => t('Allow the exposed form to appear in a block instead of the view.'), + ); + + foreach (array('header' => t('Header'), 'footer' => t('Footer'), 'empty' => t('Empty text')) as $type => $name) { + if (!$this->get_option($type)) { + $field = t('None'); + } + else { + // A lot of code to get the name of the filter format. + $fmt_string = $this->get_option($type . '_format'); + if (empty($fmt_string)) { + $fmt_string = FILTER_FORMAT_DEFAULT; + } + $format_val = filter_resolve_format($fmt_string); + $format = filter_formats($format_val); + if ($format) { + $field = check_plain($format->name); + } + else { + $field = t('Unknown/missing format'); + } + } + + $options[$type] = array( + 'category' => 'basic', + 'title' => $name, + 'value' => $field, + 'desc' => t("Change this display's !name.", array('!name' => strtolower($name))), + ); + } + + $css_class = check_plain(trim($this->get_option('css_class'))); + if (!$css_class) { + $css_class = t('None'); + } + + $options['css_class'] = array( + 'category' => 'basic', + 'title' => t('CSS class'), + 'value' => $css_class, + 'desc' => t('Change the CSS class name(s) that will be added to this display.'), + ); + + $options['analyze-theme'] = array( + 'category' => 'basic', + 'title' => t('Theme'), + 'value' => t('Information'), + 'desc' => t('Get information on how to theme this display'), + ); + } + + /** + * Provide the default form for setting options. + */ + function options_form(&$form, &$form_state) { + if ($this->defaultable_sections($form_state['section'])) { + $this->add_override_button($form, $form_state, $form_state['section']); + } + $form['#title'] = check_plain($this->display->display_title) . ': '; + + // Set the 'section' to hilite on the form. + // If it's the item we're looking at is pulling from the default display, + // reflect that. Don't use is_defaulted since we want it to show up even + // on the default display. + if (!empty($this->options['defaults'][$form_state['section']])) { + $form['#section'] = 'default-' . $form_state['section']; + } + else { + $form['#section'] = $this->display->id . '-' . $form_state['section']; + } + + switch ($form_state['section']) { + case 'display_title': + $form['#title'] .= t('The name of this display'); + $form['display_title'] = array( + '#type' => 'textfield', + '#description' => t('This title will appear only in the administrative interface for the View.'), + '#default_value' => $this->display->display_title, + ); + break; + case 'title': + $form['#title'] .= t('The title of this view'); + $form['title'] = array( + '#type' => 'textfield', + '#description' => t('This title will be displayed with the view, wherever titles are normally displayed; i.e, as the page title, block title, etc.'), + '#default_value' => $this->get_option('title'), + ); + break; + case 'css_class': + $form['#title'] .= t('CSS class'); + $form['css_class'] = array( + '#type' => 'textfield', + '#description' => t('The CSS class names will be added to the view. This enables you to use specific CSS code for each view. You may define multiples classes separated by spaces.'), + '#default_value' => $this->get_option('css_class'), + ); + break; + case 'use_ajax': + $form['#title'] .= t('Use AJAX when available to load this view'); + $form['description'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => t('If set, this view will use an AJAX mechanism for paging, table sorting and exposed filters. This means the entire page will not refresh. It is not recommended that you use this if this view is the main content of the page as it will prevent deep linking to specific pages, but it is very useful for side content.'), + ); + $form['use_ajax'] = array( + '#type' => 'radios', + '#options' => array(1 => t('Yes'), 0 => t('No')), + '#default_value' => $this->get_option('use_ajax') ? 1 : 0, + ); + break; + case 'use_pager': + $form['#title'] .= t('Use a pager for this view'); + $form['use_pager'] = array( + '#type' => 'radios', + '#options' => array(TRUE => t('Full pager'), 'mini' => t('Mini pager'), 0 => t('No')), + '#default_value' => $this->get_option('use_pager'), + ); + $form['pager_element'] = array( + '#type' => 'textfield', + '#title' => t('Pager element'), + '#description' => t("Unless you're experiencing problems with pagers related to this view, you should leave this at 0. If using multiple pagers on one page you may need to set this number to a higher value so as not to conflict within the ?page= array. Large values will add a lot of commas to your URLs, so avoid if possible."), + '#default_value' => intval($this->get_option('pager_element')), + ); + break; + case 'items_per_page': + $form['#title'] .= $this->use_pager() ? t('Items per page') : t('Items to display'); + + $form['items_per_page'] = array( + '#type' => 'textfield', + '#description' => t('The number of items to display per page. Enter 0 for no limit.'), + '#default_value' => intval($this->get_option('items_per_page')), + ); + $form['offset'] = array( + '#type' => 'textfield', + '#title' => t('Offset'), + '#description' => t('The number of items to skip. For example, if this field is 3, the first 3 items will be skipped and not displayed. Offset can not be used if items to display is 0; instead use a very large number there.'), + '#default_value' => intval($this->get_option('offset')), + ); + break; + case 'use_more': + $form['#title'] .= t('Add a more link to the bottom of the display.'); + $form['use_more'] = array( + '#type' => 'checkbox', + '#title' => t('Create more link'), + '#description' => t("This will add a more link to the bottom of this view, which will link to the page view. If you have more than one page view, the link will point to the display specified in 'Link display' above."), + '#default_value' => $this->get_option('use_more'), + ); + $form['use_more_always'] = array( + '#type' => 'checkbox', + '#title' => t('Always display more link'), + '#description' => t("This will display the more link even if there are no more items to display."), + '#default_value' => $this->get_option('use_more_always'), + ); + $form['use_more_text'] = array( + '#type' => 'textfield', + '#title' => t('More link text'), + '#description' => t("The text to display for the more link."), + '#default_value' => $this->get_option('use_more_text'), + ); + break; + case 'distinct': + $form['#title'] .= t('Display only distinct items, without duplicates.'); + $form['distinct'] = array( + '#type' => 'checkbox', + '#title' => t('Distinct'), + '#description' => t('This will make the view display only distinct items. If there are multiple identical items, each will be displayed only once. You can use this to try and remove duplicates from a view, though it does not always work. Note that this can slow queries down, so use it with caution.'), + '#default_value' => $this->get_option('distinct'), + ); + break; + case 'access': + $form['#title'] .= t('Access restrictions'); + $form['access'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#tree' => TRUE, + ); + + $access = $this->get_option('access'); + $form['access']['type'] = array( + '#type' => 'radios', + '#options' => views_fetch_plugin_names('access'), + '#default_value' => $access['type'], + ); + + $access_plugin = views_fetch_plugin_data('access', $access['type']); + if (!empty($access_plugin['uses options'])) { + $form['markup'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => t('You may also adjust the !settings for the currently selected access restriction by clicking on the icon.', array('!settings' => $this->option_link(t('settings'), 'access_options'))), + ); + } + + break; + case 'access_options': + $access = $this->get_option('access'); + $plugin = $this->get_access_plugin(); + $form['#title'] .= t('Access options'); + if ($plugin) { + $form['#help_topic'] = $plugin->definition['help topic']; + $form['#help_module'] = $plugin->definition['module']; + + $form['access_options'] = array( + '#tree' => TRUE, + ); + $form['access_options']['type'] = array( + '#type' => 'value', + '#value' => $access['type'], + ); + $plugin->options_form($form['access_options'], $form_state); + } + break; + case 'cache': + $form['#title'] .= t('Caching'); + $form['cache'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#tree' => TRUE, + ); + + $cache = $this->get_option('cache'); + $form['cache']['type'] = array( + '#type' => 'radios', + '#options' => views_fetch_plugin_names('cache'), + '#default_value' => $cache['type'], + ); + + $cache_plugin = views_fetch_plugin_data('cache', $cache['type']); + if (!empty($cache_plugin['uses options'])) { + $form['markup'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => t('You may also adjust the !settings for the currently selected cache mechanism by clicking on the icon.', array('!settings' => $this->option_link(t('settings'), 'cache_options'))), + ); + } + break; + case 'cache_options': + $cache = $this->get_option('cache'); + $plugin = $this->get_cache_plugin(); + $form['#title'] .= t('Caching options'); + if ($plugin) { + $form['#help_topic'] = $plugin->definition['help topic']; + $form['#help_module'] = $plugin->definition['module']; + + $form['cache_options'] = array( + '#tree' => TRUE, + ); + $form['cache_options']['type'] = array( + '#type' => 'value', + '#value' => $cache['type'], + ); + $plugin->options_form($form['cache_options'], $form_state); + } + break; + case 'header': + $form['#title'] .= t('Header'); + $form['header_empty'] = array( + '#type' => 'checkbox', + '#title' => t('Display even if view has no result'), + '#default_value' => $this->get_option('header_empty'), + ); + $form['header'] = array( + '#type' => 'textarea', + '#default_value' => $this->get_option('header'), + '#rows' => 6, + '#description' => t('Text to display at the top of the view. May contain an explanation or links or whatever you like. Optional.'), + ); + + $form['header_format'] = filter_form($this->get_option('header_format'), NULL, array('header_format')); + break; + case 'footer': + $form['#title'] .= t('Footer'); + $form['footer_empty'] = array( + '#type' => 'checkbox', + '#title' => t('Display even if view has no result'), + '#default_value' => $this->get_option('footer_empty'), + ); + $form['footer'] = array( + '#type' => 'textarea', + '#default_value' => $this->get_option('footer'), + '#rows' => 6, + '#description' => t('Text to display beneath the view. May contain an explanation or links or whatever you like. Optional.'), + ); + + $form['footer_format'] = filter_form($this->get_option('footer_format'), NULL, array('footer_format')); + break; + case 'empty': + $form['#title'] .= t('Empty text'); + $form['empty'] = array( + '#type' => 'textarea', + '#default_value' => $this->get_option('empty'), + '#rows' => 6, + '#description' => t('Text to display if the view has no results. Optional.'), + ); + + $form['empty_format'] = filter_form($this->get_option('empty_format'), NULL, array('empty_format')); + break; + case 'style_plugin': + $form['#title'] .= t('How should this view be styled'); + $form['#help_topic'] = 'style'; + $form['style_plugin'] = array( + '#type' => 'radios', + '#options' => views_fetch_plugin_names('style', $this->get_style_type(), array($this->view->base_table)), + '#default_value' => $this->get_option('style_plugin'), + '#description' => t('If the style you choose has settings, be sure to click the settings button that will appear next to it in the View summary.'), + ); + + $style_plugin = views_fetch_plugin_data('style', $this->get_option('style_plugin')); + if (!empty($style_plugin['uses options'])) { + $form['markup'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => t('You may also adjust the !settings for the currently selected style by clicking on the icon.', array('!settings' => $this->option_link(t('settings'), 'style_options'))), + ); + } + + break; + case 'style_options': + $form['#title'] .= t('Style options'); + $style = TRUE; + $type = 'style_plugin'; + $name = $this->get_option('style_plugin'); + + case 'row_options': + if (!isset($name)) { + $name = $this->get_option('row_plugin'); + } + // if row, $style will be empty. + if (empty($style)) { + $form['#title'] .= t('Row style options'); + $type = 'row_plugin'; + } + $plugin = $this->get_plugin(empty($style) ? 'row' : 'style'); + if ($plugin) { + if (isset($plugin->definition['help topic'])) { + $form['#help_topic'] = $plugin->definition['help topic']; + $form['#help_module'] = $plugin->definition['module']; + } + $form[$form_state['section']] = array( + '#tree' => TRUE, + ); + $plugin->options_form($form[$form_state['section']], $form_state); + } + break; + case 'row_plugin': + $form['#title'] .= t('How should each row in this view be styled'); + $form['#help_topic'] = 'style-row'; + $form['row_plugin'] = array( + '#type' => 'radios', + '#options' => views_fetch_plugin_names('row', $this->get_style_type(), array($this->view->base_table)), + '#default_value' => $this->get_option('row_plugin'), + ); + + $row_plugin = views_fetch_plugin_data('row', $this->get_option('row_plugin')); + if (!empty($row_plugin['uses options'])) { + $form['markup'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => t('You may also adjust the !settings for the currently selected row style by clicking on the icon.', array('!settings' => $this->option_link(t('settings'), 'row_options'))), + ); + } + + break; + case 'link_display': + $form['#title'] .= t('Which display to use for path'); + foreach ($this->view->display as $display_id => $display) { + if ($display->handler->has_path()) { + $options[$display_id] = $display->display_title; + } + } + $form['link_display'] = array( + '#type' => 'radios', + '#options' => $options, + '#description' => t("Which display to use to get this display's path for things like summary links, rss feed links, more links, etc."), + '#default_value' => $this->get_link_display(), + ); + break; + case 'analyze-theme': + $form['#title'] .= t('Theming information'); + $form['#help_topic'] = 'analyze-theme'; + + if (isset($_POST['theme'])) { + $this->view->theme = $_POST['theme']; + } + else if (empty($this->view->theme)) { + $this->view->theme = variable_get('theme_default', 'garland'); + } + + global $custom_theme; + $custom_theme = $this->view->theme; + init_theme(); + + $funcs = array(); + // Get theme functions for the display. Note that some displays may + // not have themes. The 'feed' display, for example, completely + // delegates to the style. + if (!empty($this->definition['theme'])) { + $funcs[] = $this->option_link(t('Display output'), 'analyze-theme-display') . ': ' . $this->format_themes($this->theme_functions()); + $themes = $this->additional_theme_functions(); + if ($themes) { + foreach ($themes as $theme) { + $funcs[] = $this->option_link(t('Alternative display output'), 'analyze-theme-display') . ': ' . $this->format_themes($theme); + } + } + } + + $plugin = $this->get_plugin(); + if ($plugin) { + $funcs[] = $this->option_link(t('Style output'), 'analyze-theme-style') . ': ' . $this->format_themes($plugin->theme_functions(), $plugin->additional_theme_functions()); + $themes = $plugin->additional_theme_functions(); + if ($themes) { + foreach ($themes as $theme) { + $funcs[] = $this->option_link(t('Alternative style'), 'analyze-theme-style') . ': ' . $this->format_themes($theme); + } + } + + if ($plugin->uses_row_plugin()) { + $row_plugin = $this->get_plugin('row'); + if ($row_plugin) { + $funcs[] = $this->option_link(t('Row style output'), 'analyze-theme-row') . ': ' . $this->format_themes($row_plugin->theme_functions()); + $themes = $row_plugin->additional_theme_functions(); + if ($themes) { + foreach ($themes as $theme) { + $funcs[] = $this->option_link(t('Alternative row style'), 'analyze-theme-row') . ': ' . $this->format_themes($theme); + } + } + } + } + + if ($plugin->uses_fields()) { + foreach ($this->get_handlers('field') as $id => $handler) { + $funcs[] = $this->option_link(t('Field @field (ID: @id)', array('@field' => $handler->ui_name(), '@id' => $id)), 'analyze-theme-field') . ': ' . $this->format_themes($handler->theme_functions()); + } + } + } + + $form['important'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => '

    ' . t('This section lists all possible templates for the display plugin and for the style plugins, ordered roughly from the least specific to the most specific. The active template for each plugin -- which is the most specific template found on the system -- is highlighted in bold.') . '

    ', + ); + + foreach (list_themes() as $key => $theme) { + $options[$key] = $theme->info['name']; + } + + $form['box'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + ); + $form['box']['theme'] = array( + '#type' => 'select', + '#options' => $options, + '#default_value' => $this->view->theme, + ); + + $form['box']['change'] = array( + '#type' => 'submit', + '#value' => t('Change theme'), + '#submit' => array('views_ui_edit_display_form_change_theme'), + ); + + $form['analysis'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => theme('item_list', $funcs), + ); + + $form['rescan_button'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + ); + $form['rescan_button']['button'] = array( + '#type' => 'submit', + '#value' => t('Rescan template files'), + '#submit' => array('views_ui_config_item_form_rescan'), + ); + $form['rescan_button']['markup'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => t("Important! When adding, removing, or renaming template files, it is necessary to make Drupal aware of the changes by making it rescan the files on your system. By clicking this button you clear Drupal's theme registry and thereby trigger this rescanning process. The highlighted templates above will then reflect the new state of your system."), + ); + + $form_state['ok_button'] = TRUE; + break; + case 'analyze-theme-display': + $form['#title'] .= t('Theming information (display)'); + $output = '

    ' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '

    '; + + if (empty($this->definition['theme'])) { + $output .= t('This display has no theming information'); + } + else { + $output .= '

    ' . t('This is the default theme template used for this display.') . '

    '; + $output .= '
    ' . check_plain(file_get_contents('./' . $this->definition['theme path'] . '/' . strtr($this->definition['theme'], '_', '-') . '.tpl.php')) . '
    '; + } + + if (!empty($this->definition['additional themes'])) { + foreach ($this->definition['additional themes'] as $theme => $type) { + $output .= '

    ' . t('This is an alternative template for this display.') . '

    '; + $output .= '
    ' . check_plain(file_get_contents('./' . $this->definition['theme path'] . '/' . strtr($theme, '_', '-') . '.tpl.php')) . '
    '; + } + } + + $form['analysis'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => $output, + ); + + $form_state['ok_button'] = TRUE; + break; + case 'analyze-theme-style': + $form['#title'] .= t('Theming information (style)'); + $output = '

    ' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '

    '; + + $plugin = $this->get_plugin(); + + if (empty($plugin->definition['theme'])) { + $output .= t('This display has no style theming information'); + } + else { + $output .= '

    ' . t('This is the default theme template used for this style.') . '

    '; + $output .= '
    ' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($plugin->definition['theme'], '_', '-') . '.tpl.php')) . '
    '; + } + + if (!empty($plugin->definition['additional themes'])) { + foreach ($plugin->definition['additional themes'] as $theme => $type) { + $output .= '

    ' . t('This is an alternative template for this style.') . '

    '; + $output .= '
    ' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($theme, '_', '-') . '.tpl.php')) . '
    '; + } + } + + $form['analysis'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => $output, + ); + + $form_state['ok_button'] = TRUE; + break; + case 'analyze-theme-row': + $form['#title'] .= t('Theming information (row style)'); + $output = '

    ' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '

    '; + + $plugin = $this->get_plugin('row'); + + if (empty($plugin->definition['theme'])) { + $output .= t('This display has no row style theming information'); + } + else { + $output .= '

    ' . t('This is the default theme template used for this row style.') . '

    '; + $output .= '
    ' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($plugin->definition['theme'], '_', '-') . '.tpl.php')) . '
    '; + } + + if (!empty($plugin->definition['additional themes'])) { + foreach ($plugin->definition['additional themes'] as $theme => $type) { + $output .= '

    ' . t('This is an alternative template for this row style.') . '

    '; + $output .= '
    ' . check_plain(file_get_contents('./' . $plugin->definition['theme path'] . '/' . strtr($theme, '_', '-') . '.tpl.php')) . '
    '; + } + } + + $form['analysis'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => $output, + ); + + $form_state['ok_button'] = TRUE; + break; + case 'analyze-theme-field': + $form['#title'] .= t('Theming information (row style)'); + $output = '

    ' . t('Back to !info.', array('!info' => $this->option_link(t('theming information'), 'analyze-theme'))) . '

    '; + + $output .= '

    ' . t('This is the default theme template used for this row style.') . '

    '; + + // Field templates aren't registered the normal way...and they're always + // this one, anyhow. + $output .= '
    ' . check_plain(file_get_contents(drupal_get_path('module', 'views') . '/theme/views-view-field.tpl.php')) . '
    '; + + $form['analysis'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => $output, + ); + $form_state['ok_button'] = TRUE; + break; + + case 'exposed_block': + $form['#title'] .= t('Put the exposed form in a block'); + $form['description'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => t('If set, any exposed widgets will not appear with this view. Instead, a block will be made available to the Drupal block administration system, and the exposed form will appear there. Note that this block must be enabled manually, Views will not enable it for you.'), + ); + $form['exposed_block'] = array( + '#type' => 'radios', + '#options' => array(1 => t('Yes'), 0 => t('No')), + '#default_value' => $this->get_option('exposed_block') ? 1 : 0, + ); + break; + } + } + + /** + * Format a list of theme templates for output by the theme info helper. + */ + function format_themes($themes) { + $registry = theme_get_registry(); + + // Run through the theme engine variables, if necessary + global $theme_engine; + $extension = '.tpl.php'; + if (isset($theme_engine)) { + $extension_function = $theme_engine . '_extension'; + if (function_exists($extension_function)) { + $extension = $extension_function(); + } + } + + $output = ''; + $picked = FALSE; + foreach ($themes as $theme) { + $template = strtr($theme, '_', '-') . $extension; + if (!$picked && !empty($registry[$theme])) { + $template_path = isset($registry[$theme]['path']) ? $registry[$theme]['path'] . '/' : './'; + if (file_exists($template_path . $template)) { + $hint = t('File found in folder @template-path', array('@template-path' => $template_path)); + $template = '' . $template . ''; + } + else { + $template = '' . $template . ' ' . t('(File not found, in folder @template-path)', array('@template-path' => $template_path)) . ''; + } + $picked = TRUE; + } + $fixed[] = $template; + } + + return implode(', ', array_reverse($fixed)); + } + + /** + * Validate the options form. + */ + function options_validate(&$form, &$form_state) { + switch ($form_state['section']) { + case 'display_title': + if (empty($form_state['values']['display_title'])) { + form_error($form['display_title'], t('Display title may not be empty.')); + } + break; + case 'css_class': + $css_class = $form_state['values']['css_class']; + if (preg_match('/[^a-zA-Z0-9- ]/', $css_class)) { + form_error($form['css_class'], t('CSS classes must be alphanumeric or dashes only.')); + } + break; + case 'style_options': + $style = TRUE; + case 'row_options': + // if row, $style will be empty. + $plugin = $this->get_plugin(empty($style) ? 'row' : 'style'); + if ($plugin) { + $plugin->options_validate($form[$form_state['section']], $form_state); + } + break; + case 'access_options': + $plugin = $this->get_access_plugin(); + if ($plugin) { + $plugin->options_validate($form['access_options'], $form_state); + } + break; + case 'cache_options': + $plugin = $this->get_cache_plugin(); + if ($plugin) { + $plugin->options_validate($form['cache_options'], $form_state); + } + break; + } + } + + /** + * Perform any necessary changes to the form values prior to storage. + * There is no need for this function to actually store the data. + */ + function options_submit(&$form, &$form_state) { + // Not sure I like this being here, but it seems (?) like a logical place. + $cache_plugin = $this->get_cache_plugin(); + if ($cache_plugin) { + $cache_plugin->cache_flush(); + } + + $section = $form_state['section']; + switch ($section) { + case 'display_title': + $this->display->display_title = $form_state['values']['display_title']; + break; + case 'access': + $access = $this->get_option('access'); + if ($access['type'] != $form_state['values']['access']['type']) { + $plugin = views_get_plugin('access', $form_state['values']['access']['type']); + if ($plugin) { + $access = array('type' => $form_state['values']['access']['type']); + $plugin->option_defaults($access); + $this->set_option('access', $access); + if (!empty($plugin->definition['uses options'])) { + views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('access_options')); + } + } + } + + break; + case 'access_options': + $plugin = views_get_plugin('access', $form_state['values'][$section]['type']); + if ($plugin) { + $plugin->options_submit($form['access_options'], $form_state); + $this->set_option('access', $form_state['values'][$section]); + } + break; + case 'cache': + $cache = $this->get_option('cache'); + if ($cache['type'] != $form_state['values']['cache']['type']) { + $plugin = views_get_plugin('cache', $form_state['values']['cache']['type']); + if ($plugin) { + $cache = array('type' => $form_state['values']['cache']['type']); + $plugin->option_defaults($cache); + $this->set_option('cache', $cache); + if (!empty($plugin->definition['uses options'])) { + views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('cache_options')); + } + } + } + + break; + case 'cache_options': + $plugin = views_get_plugin('cache', $form_state['values'][$section]['type']); + if ($plugin) { + $plugin->options_submit($form['cache_options'], $form_state); + $this->set_option('cache', $form_state['values'][$section]); + } + break; + case 'title': + case 'css_class': + case 'link_display': + $this->set_option($section, $form_state['values'][$section]); + break; + case 'use_ajax': + $this->set_option($section, (bool)$form_state['values'][$section]); + break; + case 'use_pager': + $this->set_option($section, $form_state['values'][$section]); + $this->set_option('pager_element', intval($form_state['values']['pager_element'])); + break; + case 'items_per_page': + $this->set_option($section, intval($form_state['values'][$section])); + $this->set_option('offset', intval($form_state['values']['offset'])); + break; + case 'use_more': + $this->set_option($section, intval($form_state['values'][$section])); + $this->set_option('use_more_always', intval($form_state['values']['use_more_always'])); + $this->set_option('use_more_text', $form_state['values']['use_more_text']); + case 'distinct': + $this->set_option($section, $form_state['values'][$section]); + break; + case 'row_plugin': + // This if prevents resetting options to default if they don't change + // the plugin. + if ($this->get_option($section) != $form_state['values'][$section]) { + $plugin = views_get_plugin('row', $form_state['values'][$section]); + if ($plugin) { + $this->set_option($section, $form_state['values'][$section]); + $this->set_option('row_options', array()); + + // send ajax form to options page if we use it. + if (!empty($plugin->definition['uses options'])) { + views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('row_options')); + } + } + } + break; + case 'style_plugin': + // This if prevents resetting options to default if they don't change + // the plugin. + if ($this->get_option($section) != $form_state['values'][$section]) { + $plugin = views_get_plugin('style', $form_state['values'][$section]); + if ($plugin) { + $this->set_option($section, $form_state['values'][$section]); + $this->set_option('style_options', array()); + // send ajax form to options page if we use it. + if (!empty($plugin->definition['uses options'])) { + views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('style_options')); + } + } + } + break; + case 'style_options': + $style = TRUE; + case 'row_options': + // if row, $style will be empty. + $plugin = $this->get_plugin(empty($style) ? 'row' : 'style'); + if ($plugin) { + $plugin->options_submit($form[$section], $form_state); + } + $this->set_option($section, $form_state['values'][$section]); + break; + case 'header': + case 'footer': + case 'empty': + $this->set_option($section, $form_state['values'][$section]); + $this->set_option($section . '_format', $form_state['values'][$section . '_format']); + if ($section != 'empty') { + $this->set_option($section . '_empty', $form_state['values'][$section . '_empty']); + } + break; + case 'exposed_block': + $this->set_option($section, (bool) $form_state['values'][$section]); + break; + } + } + + /** + * Add an override button for a given section, allowing the user to + * change whether this info is stored on the default display or on + * the current display. + */ + function add_override_button(&$form, &$form_state, $section) { + if ($this->is_default_display()) { + return; + } + + $form['override'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + ); + if ($this->is_defaulted($section)) { + $form['override']['button'] = array( + '#type' => 'submit', + '#value' => t('Override'), + '#submit' => array('views_ui_edit_display_form_override'), + ); + $form['override']['markup'] = array( + '#prefix' => '
    ', + '#value' => theme('advanced_help_topic', 'views', 'overrides') . t('Status: using default values.'), + '#suffix' => '
    ', + ); + + $form_state['update_name'] = t('Update default display'); + } + else { + $form['override']['button'] = array( + '#type' => 'submit', + '#value' => t('Use default'), + '#submit' => array('views_ui_edit_display_form_override'), + ); + $form['override']['markup'] = array( + '#prefix' => '
    ', + '#value' => theme('advanced_help_topic', 'views', 'overrides') . t('Status: using overridden values.'), + '#suffix' => '
    ', + ); + + $form_state['update_name'] = NULL; + } + } + + /** + * If override/revert was clicked, perform the proper toggle. + */ + function options_override($form, &$form_state) { + $this->set_override($form_state['section']); + } + + /** + * Flip the override setting for the given section. + */ + function set_override($section, $new_state = NULL) { + $options = $this->defaultable_sections($section); + if (!$options) { + return; + } + + if (!isset($new_state)) { + $new_state = empty($this->options['defaults'][$section]); + } + + // For each option that is part of this group, fix our settings. + foreach ($options as $option) { + if ($new_state) { + // Revert to defaults. + unset($this->options[$option]); + unset($this->display->display_options[$option]); + } + else { + // copy existing values into our display. + $this->options[$option] = $this->get_option($option); + $this->display->display_options[$option] = $this->options[$option]; + } + $this->options['defaults'][$option] = $new_state; + $this->display->display_options['defaults'][$option] = $new_state; + } + } + + /** + * Inject anything into the query that the display handler needs. + */ + function query() { + // Make the query distinct if the option was set. + if ($this->get_option('distinct')) { + $this->view->query->set_distinct(); + } + } + + /** + * Not all display plugins will support filtering + */ + function render_filters() { } + + /** + * Render the 'more' link + */ + function render_more_link() { + if ($this->use_more() && ($this->use_more_always() || !isset($this->view->total_rows) || $this->view->total_rows > $this->view->pager['items_per_page'])) { + $path = $this->get_path(); + if ($path) { + $path = $this->view->get_url(NULL, $path); + $url_options = array(); + if (!empty($this->view->exposed_raw_input)) { + $url_options['query'] = $this->view->exposed_raw_input; + } + $theme = views_theme_functions('views_more', $this->view, $this->display); + $path = check_url(url($path, $url_options)); + return theme($theme, $path, check_plain($this->use_more_text())); + } + } + } + + /** + * Render a text area, using the proper format. + */ + function render_textarea($area) { + static $formats = array(); + + $value = $this->get_option($area); + // Check to make sure the filter format exists; if not, we don't + // display anything. + $format = filter_resolve_format($this->get_option($area . '_format')); + + if (!array_key_exists($format, $formats)) { + $formats[$format] = db_result(db_query("SELECT name FROM {filter_formats} WHERE format = %d", $format)); + } + + if (!$formats[$format]) { + return; + } + + if ($value) { + return check_markup($value, $format, FALSE); + } + } + + /** + * Render the header of the view. + */ + function render_header() { + if (!empty($this->view->result) || $this->get_option('header_empty')) { + return $this->render_textarea('header'); + } + } + + /** + * Render the footer of the view. + */ + function render_footer() { + if (!empty($this->view->result) || $this->get_option('footer_empty')) { + return $this->render_textarea('footer'); + } + } + + /** + * Render the empty text of the view. + */ + function render_empty() { return $this->render_textarea('empty'); } + /** + * If this display creates a block, implement one of these. + */ + function hook_block($op = 'list', $delta = 0, $edit = array()) { return array(); } + + /** + * If this display creates a page with a menu item, implement it here. + */ + function hook_menu() { return array(); } + + /** + * Render this display. + */ + function render() { + return theme($this->theme_functions(), $this->view); + } + + /** + * Determine if the user has access to this display of the view. + */ + function access($account = NULL) { + if (!isset($account)) { + global $user; + $account = $user; + } + + // Full override. + if (user_access('access all views', $account)) { + return TRUE; + } + + $plugin = $this->get_access_plugin(); + if ($plugin) { + return $plugin->access($account); + } + + // fallback to all access if no plugin. + return TRUE; + } + + /** + * Set up any variables on the view prior to execution. These are separated + * from execute because they are extremely common and unlikely to be + * overridden on an individual display. + */ + function pre_execute() { + $this->view->set_use_ajax($this->use_ajax()); + // Copy pager information from the display. + $this->view->set_use_pager($this->use_pager()); + $this->view->set_pager_element($this->get_option('pager_element')); + $this->view->set_items_per_page($this->get_option('items_per_page')); + $this->view->set_offset($this->get_option('offset')); + if ($this->use_more() && !$this->use_more_always()) { + $this->view->get_total_rows = TRUE; + } + } + + /** + * When used externally, this is how a view gets run and returns + * data in the format required. + * + * The base class cannot be executed. + */ + function execute() { } + + /** + * Fully render the display for the purposes of a live preview or + * some other AJAXy reason. + */ + function preview() { return $this->view->render(); } + + /** + * Displays can require a certain type of style plugin. By default, they will + * be 'normal'. + */ + function get_style_type() { return 'normal'; } + + /** + * Make sure the display and all associated handlers are valid. + * + * @return + * Empty array if the display is valid; an array of error strings if it is not. + */ + function validate() { + $errors = array(); + // Make sure displays that use fields HAVE fields. + if ($this->uses_fields()) { + $fields = FALSE; + foreach ($this->get_handlers('field') as $field) { + if (empty($field->options['exclude'])) { + $fields = TRUE; + } + } + + if (!$fields) { + $errors[] = t('Display "@display" uses fields but there are none defined for it or all are excluded.', array('@display' => $this->display->display_title)); + } + } + + if ($this->has_path() && !$this->get_option('path')) { + $errors[] = t('Display "@display" uses a path but the path is undefined.', array('@display' => $this->display->display_title)); + } + + // Validate style plugin + $style = $this->get_plugin(); + if (empty($style)) { + $errors[] = t('Display "@display" has an invalid style plugin.', array('@display' => $this->display->display_title)); + } + else { + $result = $style->validate(); + if (!empty($result) && is_array($result)) { + $errors = array_merge($errors, $result); + } + } + + // Validate handlers + foreach (views_object_types() as $type => $info) { + foreach ($this->get_handlers($type) as $handler) { + $result = $handler->validate(); + if (!empty($result) && is_array($result)) { + $errors = array_merge($errors, $result); + } + } + } + + return $errors; + } + + /** + * Check if the provided identifier is unique. + */ + function is_identifier_unique($id, $identifier) { + foreach (views_object_types() as $type => $info) { + foreach ($this->get_handlers($type) as $key => $handler) { + if ($handler->can_expose() && $handler->is_exposed()) { + if ($id != $key && $identifier == $handler->options['expose']['identifier']) { + return FALSE; + } + } + } + } + return TRUE; + } + + /** + * Provide the block system with any exposed widget blocks for this display. + */ + function get_special_blocks() { + $delta = '-exp-' . $this->view->name . '-' . $this->display->id; + $desc = t('Exposed form: @view-@display_id', array('@view' => $this->view->name, '@display_id' => $this->display->id)); + + return array( + $delta => array( + 'info' => $desc, + 'cache' => BLOCK_NO_CACHE, + ) + ); + } + + /** + * Render any special blocks provided for this display. + */ + function view_special_blocks($type) { + if ($type == '-exp') { + // avoid interfering with the admin forms. + if (arg(0) == 'admin' && arg(1) == 'build' && arg(2) == 'views') { + return; + } + $this->view->init_handlers(); + return array( + 'content' => $this->view->render_exposed_form(TRUE), + ); + } + } + +} + + +/** + * @} + */ + diff --git a/sites/all/modules/views/plugins/views_plugin_display_attachment.inc b/sites/all/modules/views/plugins/views_plugin_display_attachment.inc new file mode 100644 index 0000000..e59ba62 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_display_attachment.inc @@ -0,0 +1,278 @@ + 'before'); + $options['inherit_arguments'] = array('default' => TRUE); + $options['inherit_exposed_filters'] = array('default' => FALSE); + $options['inherit_pager'] = array('default' => FALSE); + $options['render_pager'] = array('default' => TRUE); + $options['displays'] = array('default' => array()); + + return $options; + } + + function execute() { + return $this->view->render($this->display->id); + } + + function attachment_positions($position = NULL) { + $positions = array( + 'before' => t('Before'), + 'after' => t('After'), + 'both' => t('Both'), + ); + + if ($position) { + return $positions[$position]; + } + + return $positions; + } + + /** + * Provide the summary for attachment options in the views UI. + * + * This output is returned as an array. + */ + function options_summary(&$categories, &$options) { + // It is very important to call the parent function here: + parent::options_summary($categories, $options); + + $categories['attachment'] = array( + 'title' => t('Attachment settings'), + ); + + $options['inherit_arguments'] = array( + 'category' => 'attachment', + 'title' => t('Inherit arguments'), + 'value' => $this->get_option('inherit_arguments') ? t('Yes') : t('No'), + ); + + $options['inherit_exposed_filters'] = array( + 'category' => 'attachment', + 'title' => t('Inherit exposed filters'), + 'value' => $this->get_option('inherit_exposed_filters') ? t('Yes') : t('No'), + ); + + $options['inherit_pager'] = array( + 'category' => 'attachment', + 'title' => t('Inherit pager'), + 'value' => $this->get_option('inherit_pager') ? t('Yes') : t('No'), + ); + + $options['render_pager'] = array( + 'category' => 'attachment', + 'title' => t('Render pager'), + 'value' => $this->get_option('render_pager') ? t('Yes') : t('No'), + ); + + $options['attachment_position'] = array( + 'category' => 'attachment', + 'title' => t('Position'), + 'value' => $this->attachment_positions($this->get_option('attachment_position')), + ); + + $displays = array_filter($this->get_option('displays')); + if (count($displays) > 1) { + $attach_to = t('Multiple displays'); + } + else if (count($displays) == 1) { + $display = array_shift($displays); + if (!empty($this->view->display[$display])) { + $attach_to = check_plain($this->view->display[$display]->display_title); + } + } + + if (!isset($attach_to)) { + $attach_to = t('None'); + } + + $options['displays'] = array( + 'category' => 'attachment', + 'title' => t('Attach to'), + 'value' => $attach_to, + ); + } + + /** + * Provide the default form for setting options. + */ + function options_form(&$form, &$form_state) { + // It is very important to call the parent function here: + parent::options_form($form, $form_state); + + switch ($form_state['section']) { + case 'inherit_arguments': + $form['#title'] .= t('Inherit arguments'); + $form['inherit_arguments'] = array( + '#type' => 'checkbox', + '#title' => t('Inherit'), + '#description' => t('Should this display inherit its arguments from the parent display to which it is attached?'), + '#default_value' => $this->get_option('inherit_arguments'), + ); + break; + case 'inherit_exposed_filters': + $form['#title'] .= t('Inherit exposed filters'); + $form['inherit_exposed_filters'] = array( + '#type' => 'checkbox', + '#title' => t('Inherit'), + '#description' => t('Should this display inherit its exposed filter values from the parent display to which it is attached?'), + '#default_value' => $this->get_option('inherit_exposed_filters'), + ); + break; + case 'inherit_pager': + $form['#title'] .= t('Inherit pager'); + $form['inherit_pager'] = array( + '#type' => 'checkbox', + '#title' => t('Inherit'), + '#description' => t('Should this display inherit its paging values from the parent display to which it is attached? Note that this will provide unexpected results if the number of items to display do not match.'), + '#default_value' => $this->get_option('inherit_pager'), + ); + break; + case 'render_pager': + $form['#title'] .= t('Render pager'); + $form['render_pager'] = array( + '#type' => 'checkbox', + '#title' => t('Render'), + '#description' => t('Should this display render the pager values? If not it can inherit from the parent...'), + '#default_value' => $this->get_option('render_pager'), + ); + break; + case 'attachment_position': + $form['#title'] .= t('Position'); + $form['attachment_position'] = array( + '#type' => 'radios', + '#description' => t('Attach before or after the parent display?'), + '#options' => $this->attachment_positions(), + '#default_value' => $this->get_option('attachment_position'), + ); + break; + case 'displays': + $form['#title'] .= t('Attach to'); + $displays = array(); + foreach ($this->view->display as $display_id => $display) { + if (!empty($display->handler) && $display->handler->accept_attachments()) { + $displays[$display_id] = $display->display_title; + } + } + $form['displays'] = array( + '#type' => 'checkboxes', + '#description' => t('Select which display or displays this should attach to.'), + '#options' => $displays, + '#default_value' => $this->get_option('displays'), + ); + break; + } + } + + /** + * Perform any necessary changes to the form values prior to storage. + * There is no need for this function to actually store the data. + */ + function options_submit(&$form, &$form_state) { + // It is very important to call the parent function here: + parent::options_submit($form, $form_state); + switch ($form_state['section']) { + case 'inherit_arguments': + case 'inherit_pager': + case 'render_pager': + case 'inherit_exposed_filters': + case 'attachment_position': + case 'displays': + $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]); + break; + } + } + + /** + * Attach to another view. + */ + function attach_to($display_id) { + $displays = $this->get_option('displays'); + + if (empty($displays[$display_id])) { + return; + } + + if (!$this->access()) { + return; + } + + // Get a fresh view because our current one has a lot of stuff on it because it's + // already been executed. + $view = $this->view->clone_view(); + $view->original_args = $view->args; + + $args = $this->get_option('inherit_arguments') ? $this->view->args : array(); + $view->set_arguments($args); + $view->set_display($this->display->id); + if ($this->get_option('inherit_pager')) { + $view->display_handler->use_pager = $this->view->display[$display_id]->handler->use_pager(); + $view->display_handler->set_option('pager_element', $this->view->display[$display_id]->handler->get_option('pager_element')); + } + + // because of this, it is very very important that displays that can accept + // attachments not also be attachments, or this could explode messily. + $attachment = $view->execute_display($this->display->id, $args); + + switch ($this->get_option('attachment_position')) { + case 'before': + $this->view->attachment_before .= $attachment; + break; + case 'after': + $this->view->attachment_after .= $attachment; + break; + case 'both': + $this->view->attachment_before .= $attachment; + $this->view->attachment_after .= $attachment; + break; + } + + $view->destroy(); + } + + /** + * Attachment displays only use exposed widgets if + * they are set to inherit the exposed filter settings + * of their parent display. + */ + function uses_exposed() { + if (!empty($this->options['inherit_exposed_filters']) && parent::uses_exposed()) { + return TRUE; + } + return FALSE; + } + + /** + * If an attachment is set to inherit the exposed filter + * settings from its parent display, then don't render and + * display a second set of exposed filter widgets. + */ + function displays_exposed() { + return $this->options['inherit_exposed_filters'] ? FALSE : TRUE; + } + + function use_pager() { + return !empty($this->use_pager); + } + + function render_pager() { + return !empty($this->use_pager) && $this->get_option('render_pager'); + } +} diff --git a/sites/all/modules/views/plugins/views_plugin_display_block.inc b/sites/all/modules/views/plugins/views_plugin_display_block.inc new file mode 100644 index 0000000..f27b23c --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_display_block.inc @@ -0,0 +1,192 @@ + '', 'translatable' => TRUE); + $options['block_caching'] = array('default' => BLOCK_NO_CACHE); + + return $options; + } + + /** + * The default block handler doesn't support configurable items, + * but extended block handlers might be able to do interesting + * stuff with it. + */ + function execute_hook_block($op = 'list', $delta = 0, $edit = array()) { + if ($op == 'list') { + $delta = $this->view->name . '-' . $this->display->id; + $desc = $this->get_option('block_description'); + + if (empty($desc)) { + $desc = t('@view: @display', array('@view' => $this->view->name, '@display' => $this->display->display_title)); + } + return array( + $delta => array( + 'info' => $desc, + 'cache' => $this->get_cache_type() + ) + ); + } + } + + /** + * The display block handler returns the structure necessary for a block. + */ + function execute() { + // Prior to this being called, the $view should already be set to this + // display, and arguments should be set on the view. + $info['content'] = $this->view->render(); + $info['subject'] = filter_xss_admin($this->view->get_title()); + if (!empty($this->view->result) || $this->get_option('empty') || !empty($this->view->style_plugin->definition['even empty'])) { + return $info; + } + } + + /** + * Provide the summary for page options in the views UI. + * + * This output is returned as an array. + */ + function options_summary(&$categories, &$options) { + // It is very important to call the parent function here: + parent::options_summary($categories, $options); + + $categories['block'] = array( + 'title' => t('Block settings'), + ); + + $block_description = strip_tags($this->get_option('block_description')); + if (empty($block_description)) { + $block_description = t('None'); + } + + if (strlen($block_description) > 16) { + $block_description = drupal_substr($block_description, 0, 16) . '...'; + } + + $options['block_description'] = array( + 'category' => 'block', + 'title' => t('Admin'), + 'value' => $block_description, + ); + + $cache_type = $this->get_option('block_caching'); + if (empty($cache_type)) { + $cache_type = BLOCK_NO_CACHE; + } + + $types = $this->block_caching_modes(); + $options['block_caching'] = array( + 'category' => 'block', + 'title' => t('Caching'), + 'value' => $types[$this->get_cache_type()], + ); + } + + /** + * Provide a list of core's block caching modes. + */ + function block_caching_modes() { + return array( + BLOCK_NO_CACHE => t('Do not cache'), + BLOCK_CACHE_GLOBAL => t('Cache once for everything (global)'), + BLOCK_CACHE_PER_PAGE => t('Per page'), + BLOCK_CACHE_PER_ROLE => t('Per role'), + BLOCK_CACHE_PER_ROLE | BLOCK_CACHE_PER_PAGE => t('Per role per page'), + BLOCK_CACHE_PER_USER => t('Per user'), + BLOCK_CACHE_PER_USER | BLOCK_CACHE_PER_PAGE => t('Per user per page'), + ); + } + + /** + * Provide a single method to figure caching type, keeping a sensible default + * for when it's unset. + */ + function get_cache_type() { + $cache_type = $this->get_option('block_caching'); + if (empty($cache_type)) { + $cache_type = BLOCK_NO_CACHE; + } + return $cache_type; + } + + /** + * Provide the default form for setting options. + */ + function options_form(&$form, &$form_state) { + // It is very important to call the parent function here: + parent::options_form($form, $form_state); + + switch ($form_state['section']) { + case 'block_description': + $form['#title'] .= t('Block admin description'); + $form['block_description'] = array( + '#type' => 'textfield', + '#description' => t('This will appear as the name of this block in administer >> site building >> blocks.'), + '#default_value' => $this->get_option('block_description'), + ); + break; + case 'block_caching': + $form['#title'] .= t('Block caching type'); + + $form['block_caching'] = array( + '#type' => 'radios', + '#description' => t("This sets the default status for Drupal's built-in block caching method; this requires that caching be turned on in block administration, and be careful because you have little control over when this cache is flushed."), + '#options' => $this->block_caching_modes(), + '#default_value' => $this->get_cache_type(), + ); + break; + } + } + + /** + * Perform any necessary changes to the form values prior to storage. + * There is no need for this function to actually store the data. + */ + function options_submit(&$form, &$form_state) { + // It is very important to call the parent function here: + parent::options_submit($form, $form_state); + switch ($form_state['section']) { + case 'block_description': + $this->set_option('block_description', $form_state['values']['block_description']); + break; + case 'block_caching': + $this->set_option('block_caching', $form_state['values']['block_caching']); + $this->save_block_cache($form_state['view']->name.'-'.$form_state['display_id'], $form_state['values']['block_caching']); + break; + } + } + + /** + * Block views use exposed widgets only if AJAX is set. + */ + function uses_exposed() { + if ($this->use_ajax()) { + return parent::uses_exposed(); + } + + return FALSE; + } + + /** + * Save the block cache setting in the blocks table if this block allready + * exists in the blocks table. Dirty fix untill http://drupal.org/node/235673 gets in. + */ + function save_block_cache($delta, $cache_setting) { + if ($bid = db_fetch_object(db_query("SELECT bid, cache FROM {blocks} WHERE module = 'views' AND delta = '%s'", $delta))) { + db_query("UPDATE {blocks} set cache = %d WHERE module = 'views' AND delta = '%s'", $cache_setting, $delta); + } + } +} diff --git a/sites/all/modules/views/plugins/views_plugin_display_default.inc b/sites/all/modules/views/plugins/views_plugin_display_default.inc new file mode 100644 index 0000000..0d518e7 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_display_default.inc @@ -0,0 +1,55 @@ +execute_display('default', $args); + * @endcode + * + * For more complex usages, a view can be partially built: + * @code + * $view->set_arguments($args); + * $view->build('default'); // Build the query + * $view->execute(); // Run the query + * $output = $view->render(); // Render the view + * @endcode + * + * If short circuited at any point, look in $view->build_info for + * information about the query. After execute, look in $view->result + * for the array of objects returned from db_query. + * + * You can also do: + * @code + * $view->set_arguments($args); + * $output = $view->render('default'); // Render the view + * @endcode + * + * This illustrates that render is smart enough to call build and execute + * if these items have not already been accomplished. + * + * Note that execute also must accomplish other tasks, such + * as setting page titles, breadcrumbs, and generating exposed filter + * data if necessary. + */ + function execute() { + return $this->view->render($this->display->id); + } +} \ No newline at end of file diff --git a/sites/all/modules/views/plugins/views_plugin_display_feed.inc b/sites/all/modules/views/plugins/views_plugin_display_feed.inc new file mode 100644 index 0000000..91e975d --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_display_feed.inc @@ -0,0 +1,205 @@ +view->render(); + if (empty($output)) { + return drupal_not_found(); + } + print $output; + } + + function preview() { + if (!empty($this->view->live_preview)) { + return '
    ' . check_plain($this->view->render()) . '
    '; + } + return $this->view->render(); + } + + /** + * Instead of going through the standard views_view.tpl.php, delegate this + * to the style handler. + */ + function render() { + return $this->view->style_plugin->render($this->view->result); + } + + function defaultable_sections($section = NULL) { + if (in_array($section, array('style_options', 'style_plugin', 'row_options', 'row_plugin',))) { + return FALSE; + } + + $sections = parent::defaultable_sections($section); + + // Tell views our sitename_title option belongs in the title section. + if ($section == 'title') { + $sections[] = 'sitename_title'; + } + elseif (!$section) { + $sections['title'][] = 'sitename_title'; + } + return $sections; + } + + function option_definition() { + $options = parent::option_definition(); + + $options['displays'] = array('default' => array()); + + // Overrides for standard stuff: + $options['style_plugin']['default'] = 'rss'; + $options['style_options']['default'] = array('mission_description' => FALSE, 'description' => ''); + $options['sitename_title']['default'] = FALSE; + $options['row_plugin']['default'] = ''; + $options['defaults']['default']['style_plugin'] = FALSE; + $options['defaults']['default']['style_options'] = FALSE; + $options['defaults']['default']['row_plugin'] = FALSE; + $options['defaults']['default']['row_options'] = FALSE; + + return $options; + } + + function options_summary(&$categories, &$options) { + // It is very important to call the parent function here: + parent::options_summary($categories, $options); + + // Since we're childing off the 'page' type, we'll still *call* our + // category 'page' but let's override it so it says feed settings. + $categories['page'] = array( + 'title' => t('Feed settings'), + ); + + if ($this->get_option('sitename_title')) { + $options['title']['value'] = t('Using the site name'); + } + + // I don't think we want to give feeds menus directly. + unset($options['menu']); + + $displays = array_filter($this->get_option('displays')); + if (count($displays) > 1) { + $attach_to = t('Multiple displays'); + } + else if (count($displays) == 1) { + $display = array_shift($displays); + if (!empty($this->view->display[$display])) { + $attach_to = check_plain($this->view->display[$display]->display_title); + } + } + + if (!isset($attach_to)) { + $attach_to = t('None'); + } + + $options['displays'] = array( + 'category' => 'page', + 'title' => t('Attach to'), + 'value' => $attach_to, + ); + } + + /** + * Provide the default form for setting options. + */ + function options_form(&$form, &$form_state) { + // It is very important to call the parent function here. + parent::options_form($form, $form_state); + + switch ($form_state['section']) { + case 'title': + $title = $form['title']; + // A little juggling to move the 'title' field beyond our checkbox. + unset($form['title']); + $form['sitename_title'] = array( + '#type' => 'checkbox', + '#title' => t('Use the site name for the title'), + '#default_value' => $this->get_option('sitename_title'), + ); + $form['title'] = $title; + $form['title']['#process'] = array('views_process_dependency'); + $form['title']['#dependency'] = array('edit-sitename-title' => array(FALSE)); + break; + case 'displays': + $form['#title'] .= t('Attach to'); + $displays = array(); + foreach ($this->view->display as $display_id => $display) { + if (!empty($display->handler) && $display->handler->accept_attachments()) { + $displays[$display_id] = $display->display_title; + } + } + $form['displays'] = array( + '#type' => 'checkboxes', + '#description' => t('The feed icon will be available only to the selected displays.'), + '#options' => $displays, + '#default_value' => $this->get_option('displays'), + ); + break; + case 'path': + $form['path']['#description'] = t('This view will be displayed by visiting this path on your site. It is recommended that the path be something like "path/%/%/feed" or "path/%/%/rss.xml", putting one % in the path for each argument you have defined in the view.'); + } + } + + /** + * Perform any necessary changes to the form values prior to storage. + * There is no need for this function to actually store the data. + */ + function options_submit(&$form, &$form_state) { + // It is very important to call the parent function here: + parent::options_submit($form, $form_state); + switch ($form_state['section']) { + case 'title': + $this->set_option('sitename_title', $form_state['values']['sitename_title']); + break; + case 'displays': + $this->set_option($form_state['section'], $form_state['values'][$form_state['section']]); + break; + } + } + + /** + * Attach to another view. + */ + function attach_to($display_id) { + $displays = $this->get_option('displays'); + if (empty($displays[$display_id])) { + return; + } + + // Defer to the feed style; it may put in meta information, and/or + // attach a feed icon. + $plugin = $this->get_plugin(); + if ($plugin) { + $clone = $this->view->clone_view(); + $clone->set_display($this->display->id); + $clone->build_title(); + $plugin->attach_to($display_id, $this->get_path(), $clone->get_title()); + + // Clean up + $clone->destroy(); + unset($clone); + } + } + + function uses_link_display() { + return TRUE; + } +} diff --git a/sites/all/modules/views/plugins/views_plugin_display_page.inc b/sites/all/modules/views/plugins/views_plugin_display_page.inc new file mode 100644 index 0000000..9637fdb --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_display_page.inc @@ -0,0 +1,509 @@ + ''); + $options['menu'] = array( + 'contains' => array( + 'type' => array('default' => 'none'), + // Do not translate menu and title as menu system will. + 'title' => array('default' => '', 'translatable' => FALSE), + 'description' => array('default' => '', 'translatable' => FALSE), + 'weight' => array('default' => 0), + 'name' => array('default' => variable_get('menu_default_node_menu', 'navigation')), + ), + ); + $options['tab_options'] = array( + 'contains' => array( + 'type' => array('default' => 'none'), + // Do not translate menu and title as menu system will. + 'title' => array('default' => '', 'translatable' => FALSE), + 'description' => array('default' => '', 'translatable' => FALSE), + 'weight' => array('default' => 0), + 'name' => array('default' => 'navigation'), + ), + ); + + return $options; + } + + /** + * Add this display's path information to Drupal's menu system. + */ + function execute_hook_menu($callbacks) { + $items = array(); + // Replace % with the link to our standard views argument loader + // views_arg_load -- which lives in views.module + + $bits = explode('/', $this->get_option('path')); + $page_arguments = array($this->view->name, $this->display->id); + $view_arguments = $this->get_option('arguments'); + + // Replace % with %views_arg for menu autoloading and add to the + // page arguments so the argument actually comes through. + foreach($bits as $pos => $bit) { + if ($bit == '%') { + $argument = array_shift($view_arguments); + if ($argument['validate_type'] != 'none') { + $bits[$pos] = '%views_arg'; + } + $page_arguments[] = $pos; + } + } + + $path = implode('/', $bits); + + $access_plugin = $this->get_access_plugin(); + if (!isset($access_plugin)) { + $access_plugin = views_get_plugin('access', 'none'); + } + if ($path) { + $items[$path] = array( + // default views page entry + 'page callback' => 'views_page', + 'page arguments' => $page_arguments, + // Default access check (per display) + 'access callback' => 'views_access', + 'access arguments' => array($access_plugin->get_access_callback()), + // Identify URL embedded arguments and correlate them to a handler + 'load arguments' => array($this->view->name, $this->display->id, '%index'), + ); + $menu = $this->get_option('menu'); + if (empty($menu)) { + $menu = array('type' => 'none'); + } + // Set the title and description if we have one. + if ($menu['type'] != 'none') { + $items[$path]['title'] = $menu['title']; + $items[$path]['description'] = $menu['description']; + } + + if (isset($menu['weight'])) { + $items[$path]['weight'] = intval($menu['weight']); + } + + switch ($menu['type']) { + case 'none': + default: + $items[$path]['type'] = MENU_CALLBACK; + break; + case 'normal': + $items[$path]['type'] = MENU_NORMAL_ITEM; + // Insert item into the proper menu + $items[$path]['menu_name'] = $menu['name']; + break; + case 'tab': + $items[$path]['type'] = MENU_LOCAL_TASK; + break; + case 'default tab': + $items[$path]['type'] = MENU_DEFAULT_LOCAL_TASK; + break; + } + + // If this is a 'default' tab, check to see if we have to create teh + // parent menu item. + if ($menu['type'] == 'default tab') { + $tab_options = $this->get_option('tab_options'); + if (!empty($tab_options['type']) && $tab_options['type'] != 'none') { + $bits = explode('/', $path); + // Remove the last piece. + $bit = array_pop($bits); + + // we can't do this if they tried to make the last path bit variable. + // @todo: We can validate this. + if ($bit != '%views_arg' && !empty($bits)) { + $default_path = implode('/', $bits); + $items[$default_path] = array( + // default views page entry + 'page callback' => 'views_page', + 'page arguments' => $page_arguments, + // Default access check (per display) + 'access callback' => 'views_access', + 'access arguments' => array($access_plugin->get_access_callback()), + // Identify URL embedded arguments and correlate them to a handler + 'load arguments' => array($this->view->name, $this->display->id, '%index'), + 'title' => $tab_options['title'], + 'description' => $tab_options['description'], + 'menu_name' => $tab_options['name'], + ); + switch ($tab_options['type']) { + default: + case 'normal': + $items[$default_path]['type'] = MENU_NORMAL_ITEM; + break; + case 'tab': + $items[$default_path]['type'] = MENU_LOCAL_TASK; + break; + } + if (isset($tab_options['weight'])) { + $items[$default_path]['weight'] = intval($tab_options['weight']); + } + } + } + } + } + + return $items; + } + + /** + * The display page handler returns a normal view, but it also does + * a drupal_set_title for the page, and does a views_set_page_view + * on the view. + */ + function execute() { + // Let the world know that this is the page view we're using. + views_set_page_view($this); + + // Prior to this being called, the $view should already be set to this + // display, and arguments should be set on the view. + $this->view->build(); + if (!empty($this->view->build_info['fail'])) { + return drupal_not_found(); + } + + $this->view->get_breadcrumb(TRUE); + + // And the title, which is much easier. + drupal_set_title(filter_xss_admin($this->view->get_title())); + + // And now render the view. + return $this->view->render(); + } + + /** + * Provide the summary for page options in the views UI. + * + * This output is returned as an array. + */ + function options_summary(&$categories, &$options) { + // It is very important to call the parent function here: + parent::options_summary($categories, $options); + + $categories['page'] = array( + 'title' => t('Page settings'), + ); + + $path = strip_tags($this->get_option('path')); + if (empty($path)) { + $path = t('None'); + } + + if (strlen($path) > 16) { + $path = substr($path, 0, 16) . '...'; + } + + $options['path'] = array( + 'category' => 'page', + 'title' => t('Path'), + 'value' => $path, + ); + + $menu = $this->get_option('menu'); + if (!is_array($menu)) { + $menu = array('type' => 'none'); + } + switch($menu['type']) { + case 'none': + default: + $menu_str = t('No menu'); + break; + case 'normal': + $menu_str = t('Normal: @title', array('@title' => $menu['title'])); + break; + case 'tab': + case 'default tab': + $menu_str = t('Tab: @title', array('@title' => $menu['title'])); + break; + } + + if (strlen($menu_str) > 16) { + $menu_str = substr($menu_str, 0, 16) . '...'; + } + + $options['menu'] = array( + 'category' => 'page', + 'title' => t('Menu'), + 'value' => $menu_str, + ); + + // This adds a 'Settings' link to the style_options setting if the style has options. + if ($menu['type'] == 'default tab') { + $options['menu']['links']['tab_options'] = t('Change settings for the parent menu'); + } + } + + /** + * Provide the default form for setting options. + */ + function options_form(&$form, &$form_state) { + // It is very important to call the parent function here: + parent::options_form($form, $form_state); + + switch ($form_state['section']) { + case 'path': + $form['#title'] .= t('The menu path or URL of this view'); + $form['#help_topic'] = 'path'; + $form['path'] = array( + '#type' => 'textfield', + '#description' => t('This view will be displayed by visiting this path on your site. You may use "%" in your URL to represent values that will be used for arguments: For example, "node/%/feed".'), + '#default_value' => $this->get_option('path'), + '#field_prefix' => '' . url(NULL, array('absolute' => TRUE)) . (variable_get('clean_url', 0) ? '' : '?q='), + '#field_suffix' => '‎', + '#attributes' => array('dir'=>'ltr'), + ); + break; + case 'menu': + $form['#title'] .= t('Menu item entry'); + $form['#help_topic'] = 'menu'; + $form['menu'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#tree' => TRUE, + ); + $menu = $this->get_option('menu'); + if (empty($menu)) { + $menu = array('type' => 'none', 'title' => '', 'weight' => 0); + } + $form['menu']['type'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#title' => t('Type'), + '#type' => 'radios', + '#options' => array( + 'none' => t('No menu entry'), + 'normal' => t('Normal menu entry'), + 'tab' => t('Menu tab'), + 'default tab' => t('Default menu tab') + ), + '#default_value' => $menu['type'], + ); + $form['menu']['title'] = array( + '#prefix' => '
    ', + '#title' => t('Title'), + '#type' => 'textfield', + '#default_value' => $menu['title'], + '#description' => t('If set to normal or tab, enter the text to use for the menu item.'), + '#process' => array('views_process_dependency'), + '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')), + ); + $form['menu']['description'] = array( + '#title' => t('Description'), + '#type' => 'textfield', + '#default_value' => $menu['description'], + '#description' => t("If set to normal or tab, enter the text to use for the menu item's description."), + '#process' => array('views_process_dependency'), + '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')), + ); + $form['menu']['name-warning'] = array( + '#type' => 'markup', + '#prefix' => '
    ', + '#value' => t("Warning: Changing this item's menu will not work reliably in Drupal 6.4 or earlier. Please upgrade your copy of Drupal at !url.", array('!url' => l('drupal.org', 'http://drupal.org/project/Drupal+project'))), + '#suffix' => '
    ', + '#process' => array('views_process_dependency'), + '#dependency' => array('radio:menu[type]' => array('normal')), + '#access' => version_compare(VERSION, '6.5', '<'), + ); + + // Only display the menu selector if menu module is enabled. + if (module_exists('menu')) { + $form['menu']['name'] = array( + '#title' => t('Menu'), + '#type' => 'select', + '#options' => menu_get_menus(), + '#default_value' => $menu['name'], + '#description' => t('Insert item into an available menu.'), // + '#process' => array('views_process_dependency'), + '#dependency' => array('radio:menu[type]' => array('normal')), + ); + } + else { + $form['menu']['name'] = array( + '#type' => 'value', + '#value' => $menu['name'], + ); + $form['menu']['markup'] = array( + '#value' => t('Menu selection requires the activation of menu module.'), + ); + } + $form['menu']['weight'] = array( + '#suffix' => '
    ', + '#title' => t('Weight'), + '#type' => 'textfield', + '#default_value' => isset($menu['weight']) ? $menu['weight'] : 0, + '#description' => t('The lower the weight the higher/further left it will appear.'), + '#process' => array('views_process_dependency'), + '#dependency' => array('radio:menu[type]' => array('normal', 'tab', 'default tab')), + ); + break; + case 'tab_options': + $form['#title'] .= t('Default tab options'); + $tab_options = $this->get_option('tab_options'); + if (empty($tab_options)) { + $tab_options = array('type' => 'none', 'title' => '', 'weight' => 0); + } + + $form['tab_markup'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => t('When providing a menu item as a tab, Drupal needs to know what the parent menu item of that tab will be. Sometimes the parent will already exist, but other times you will need to have one created. The path of a parent item will always be the same path with the last part left off. i.e, if the path to this view is foo/bar/baz, the parent path would be foo/bar.'), + ); + + $form['tab_options'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#tree' => TRUE, + ); + $form['tab_options']['type'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#title' => t('Parent menu item'), + '#type' => 'radios', + '#options' => array('none' => t('Already exists'), 'normal' => t('Normal menu item'), 'tab' => t('Menu tab')), + '#default_value' => $tab_options['type'], + ); + $form['tab_options']['title'] = array( + '#prefix' => '
    ', + '#title' => t('Title'), + '#type' => 'textfield', + '#default_value' => $tab_options['title'], + '#description' => t('If creating a parent menu item, enter the title of the item.'), + '#process' => array('views_process_dependency'), + '#dependency' => array('radio:tab_options[type]' => array('normal', 'tab')), + ); + $form['tab_options']['description'] = array( + '#title' => t('Description'), + '#type' => 'textfield', + '#default_value' => $tab_options['description'], + '#description' => t('If creating a parent menu item, enter the description of the item.'), + '#process' => array('views_process_dependency'), + '#dependency' => array('radio:tab_options[type]' => array('normal', 'tab')), + ); + // Only display the menu selector if menu module is enabled. + if (module_exists('menu')) { + $form['tab_options']['name'] = array( + '#title' => t('Menu'), + '#type' => 'select', + '#options' => menu_get_menus(), + '#default_value' => $tab_options['name'], + '#description' => t('Insert item into an available menu.'), + '#process' => array('views_process_dependency'), + '#dependency' => array('radio:tab_options[type]' => array('normal')), + ); + } + else { + $form['tab_options']['name'] = array( + '#type' => 'value', + '#value' => $tab_options['name'], + ); + $form['tab_options']['markup'] = array( + '#value' => t('Menu selection requires the activation of menu module.'), + ); + } + $form['tab_options']['weight'] = array( + '#suffix' => '
    ', + '#title' => t('Tab weight'), + '#type' => 'textfield', + '#default_value' => $tab_options['weight'], + '#size' => 5, + '#description' => t('If the parent menu item is a tab, enter the weight of the tab. The lower the number, the more to the left it will be.'), + '#process' => array('views_process_dependency'), + '#dependency' => array('radio:tab_options[type]' => array('tab')), + ); + break; + } + } + + function options_validate(&$form, &$form_state) { + // It is very important to call the parent function here: + parent::options_validate($form, $form_state); + switch ($form_state['section']) { + case 'path': + if (strpos($form_state['values']['path'], '$arg') !== FALSE) { + form_error($form['path'], t('"$arg" is no longer supported. Use % instead.')); + } + + if (strpos($form_state['values']['path'], '%') === 0) { + form_error($form['path'], t('"%" may not be used for the first segment of a path.')); + } + + // automatically remove '/' from path. + $form_state['values']['path'] = trim($form_state['values']['path'], '/'); + + break; + case 'menu': + $path = $this->get_option('path'); + if ($form_state['values']['menu']['type'] == 'normal' && strpos($path, '%') !== FALSE) { + form_error($form['menu']['type'], t('Views cannot create normal menu items for paths with a % in them.')); + } + + if ($form_state['values']['menu']['type'] == 'default tab' || $form_state['values']['menu']['type'] == 'tab') { + $bits = explode('/', $path); + $last = array_pop($bits); + if ($last == '%') { + form_error($form['menu']['type'], t('A display whose path ends with a % cannot be a tab.')); + } + } + + if ($form_state['values']['menu']['type'] != 'none' && empty($form_state['values']['menu']['title'])) { + form_error($form['menu']['title'], t('Title is required for this menu type.')); + } + break; + } + } + + function options_submit(&$form, &$form_state) { + // It is very important to call the parent function here: + parent::options_submit($form, $form_state); + switch ($form_state['section']) { + case 'path': + $this->set_option('path', $form_state['values']['path']); + break; + case 'menu': + $this->set_option('menu', $form_state['values']['menu']); + // send ajax form to options page if we use it. + if ($form_state['values']['menu']['type'] == 'default tab') { + views_ui_add_form_to_stack('display', $this->view, $this->display->id, array('tab_options')); + } + break; + case 'tab_options': + $this->set_option('tab_options', $form_state['values']['tab_options']); + break; + } + } + + function validate() { + $errors = parent::validate(); + + $menu = $this->get_option('menu'); + if (!empty($menu['type']) && $menu['type'] != 'none' && empty($menu['title'])) { + $errors[] = t('Display @display is set to use a menu but the menu title is not set.', array('@display' => $this->display->display_title)); + } + + if ($menu['type'] == 'default tab') { + $tab_options = $this->get_option('tab_options'); + if (!empty($tab_options['type']) && $tab_options['type'] != 'none' && empty($tab_options['title'])) { + $errors[] = t('Display @display is set to use a parent menu but the parent menu title is not set.', array('@display' => $this->display->display_title)); + } + } + + return $errors; + } +} diff --git a/sites/all/modules/views/plugins/views_plugin_row.inc b/sites/all/modules/views/plugins/views_plugin_row.inc new file mode 100644 index 0000000..2fe3ae4 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_row.inc @@ -0,0 +1,139 @@ +view = &$view; + $this->display = &$display; + + // Overlay incoming options on top of defaults + $this->unpack_options($this->options, isset($options) ? $options : $display->handler->get_option('row_options')); + } + + function uses_fields() { + return !empty($this->definition['uses fields']); + } + + + function option_definition() { + $options = parent::option_definition(); + if (isset($this->base_table)) { + $options['relationship'] = array('default' => 'none'); + } + + return $options; + } + + /** + * Provide a form for setting options. + */ + function options_form(&$form, &$form_state) { + if (isset($this->base_table)) { + $view = &$form_state['view']; + + // A whole bunch of code to figure out what relationships are valid for + // this item. + $relationships = $view->display_handler->get_option('relationships'); + $relationship_options = array(); + + foreach ($relationships as $relationship) { + $relationship_handler = views_get_handler($relationship['table'], $relationship['field'], 'relationship'); + + // If this relationship is valid for this type, add it to the list. + $data = views_fetch_data($relationship['table']); + $base = $data[$relationship['field']]['relationship']['base']; + if ($base == $this->base_table) { + $relationship_handler->init($view, $relationship); + $relationship_options[$relationship['id']] = $relationship_handler->label(); + } + } + + if (!empty($relationship_options)) { + $relationship_options = array_merge(array('none' => t('Do not use a relationship')), $relationship_options); + $rel = empty($this->options['relationship']) ? 'none' : $this->options['relationship']; + if (empty($relationship_options[$rel])) { + // Pick the first relationship. + $rel = key($relationship_options); + } + + $form['relationship'] = array( + '#type' => 'select', + '#title' => t('Relationship'), + '#options' => $relationship_options, + '#default_value' => $rel, + ); + } + else { + $form['relationship'] = array( + '#type' => 'value', + '#value' => 'none', + ); + } + } + } + + /** + * Validate the options form. + */ + function options_validate(&$form, &$form_state) { } + + /** + * Perform any necessary changes to the form values prior to storage. + * There is no need for this function to actually store the data. + */ + function options_submit(&$form, &$form_state) { } + + function query() { + if (isset($this->base_table) && isset($this->options['relationship']) && isset($this->view->relationship[$this->options['relationship']])) { + $relationship = $this->view->relationship[$this->options['relationship']]; + $this->field_alias = $this->view->query->add_field($relationship->alias, $this->base_field); + } + else { + $this->field_alias = $this->view->base_field; + } + } + + /** + * Allow the style to do stuff before each row is rendered. + * + * @param $result + * The full array of results from the query. + */ + function pre_render($result) { } + + /** + * Render a row object. This usually passes through to a theme template + * of some form, but not always. + */ + function render($row) { + return theme($this->theme_functions(), $this->view, $this->options, $row, $this->field_alias); + } +} + +/** + * @} + */ + diff --git a/sites/all/modules/views/plugins/views_plugin_row_fields.inc b/sites/all/modules/views/plugins/views_plugin_row_fields.inc new file mode 100644 index 0000000..bd66b42 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_row_fields.inc @@ -0,0 +1,67 @@ + array()); + $options['separator'] = array('default' => ''); + $options['hide_empty'] = array('default' => FALSE); + return $options; + } + + /** + * Provide a form for setting options. + */ + function options_form(&$form, &$form_state) { + $options = $this->display->handler->get_field_labels(); + + if (empty($this->options['inline'])) { + $this->options['inline'] = array(); + } + + $form['inline'] = array( + '#type' => 'checkboxes', + '#title' => t('Inline fields'), + '#options' => $options, + '#default_value' => $this->options['inline'], + '#description' => t('Inline fields will be displayed next to each other rather than one after another.'), + ); + + $form['separator'] = array( + '#title' => t('Separator'), + '#type' => 'textfield', + '#size' => 10, + '#default_value' => isset($this->options['separator']) ? $this->options['separator'] : '', + '#description' => t('The separator may be placed between inline fields to keep them from squishing up next to each other. You can use HTML in this field.'), + ); + + $form['hide_empty'] = array( + '#type' => 'checkbox', + '#title' => t('Hide empty fields'), + '#default_value' => $this->options['hide_empty'], + '#description' => t('Do not display fields, labels or markup for fields that are empty.'), + ); + } + + /** + * Perform any necessary changes to the form values prior to storage. + * There is no need for this function to actually store the data. + */ + function options_submit(&$form, &$form_state) { + $form_state['values']['row_options']['inline'] = array_filter($form_state['values']['row_options']['inline']); + } +} + diff --git a/sites/all/modules/views/plugins/views_plugin_style.inc b/sites/all/modules/views/plugins/views_plugin_style.inc new file mode 100644 index 0000000..39c4abb --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_style.inc @@ -0,0 +1,274 @@ +view = &$view; + $this->display = &$display; + + // Overlay incoming options on top of defaults + $this->unpack_options($this->options, isset($options) ? $options : $display->handler->get_option('style_options')); + + if ($this->uses_row_plugin() && $display->handler->get_option('row_plugin')) { + $this->row_plugin = $display->handler->get_plugin('row'); + } + + $this->options += array( + 'grouping' => '', + ); + + $this->definition += array( + 'uses grouping' => TRUE, + ); + } + + function destroy() { + parent::destroy(); + + if (isset($this->row_plugin)) { + $this->row_plugin->destroy(); + } + } + + /** + * Return TRUE if this style also uses a row plugin. + */ + function uses_row_plugin() { + return !empty($this->definition['uses row plugin']); + } + + /** + * Return TRUE if this style also uses fields. + */ + function uses_fields() { + // If we use a row plugin, ask the row plugin. Chances are, we don't + // care, it does. + if ($this->uses_row_plugin() && !empty($this->row_plugin)) { + return $this->row_plugin->uses_fields(); + } + // Otherwise, maybe we do. + return !empty($this->definition['uses fields']); + } + + function option_definition() { + $options = parent::option_definition(); + $options['grouping'] = array('default' => ''); + return $options; + } + + function options_form(&$form, &$form_state) { + // Only fields-based views can handle grouping. Style plugins can also exclude + // themselves from being groupable by setting their "use grouping" definiton + // key to FALSE. + // @TODO: Document "uses grouping" in docs.php when docs.php is written. + if ($this->uses_fields() && $this->definition['uses grouping']) { + $options = array('' => t('- None -')); + $options += $this->display->handler->get_field_labels(); + + // If there are no fields, we can't group on them. + if (count($options) > 1) { + $form['grouping'] = array( + '#type' => 'select', + '#title' => t('Grouping field'), + '#options' => $options, + '#default_value' => $this->options['grouping'], + '#description' => t('You may optionally specify a field by which to group the records. Leave blank to not group.'), + ); + } + } + } + + /** + * Called by the view builder to see if this style handler wants to + * interfere with the sorts. If so it should build; if it returns + * any non-TRUE value, normal sorting will NOT be added to the query. + */ + function build_sort() { return TRUE; } + + /** + * Called by the view builder to let the style build a second set of + * sorts that will come after any other sorts in the view. + */ + function build_sort_post() { } + + /** + * Allow the style to do stuff before each row is rendered. + * + * @param $result + * The full array of results from the query. + */ + function pre_render($result) { + if (!empty($this->row_plugin)) { + $this->row_plugin->pre_render($result); + } + } + + /** + * Render the display in this style. + */ + function render() { + if ($this->uses_row_plugin() && empty($this->row_plugin)) { + vpr('views_plugin_style_default: Missing row plugin'); + return; + } + + // Group the rows according to the grouping field, if specified. + $sets = $this->render_grouping($this->view->result, $this->options['grouping']); + + // Render each group separately and concatenate. Plugins may override this + // method if they wish some other way of handling grouping. + $output = ''; + foreach ($sets as $title => $records) { + if ($this->uses_row_plugin()) { + $rows = array(); + foreach ($records as $row_index => $row) { + $this->view->row_index = $row_index; + $rows[] = $this->row_plugin->render($row); + } + } + else { + $rows = $records; + } + + $output .= theme($this->theme_functions(), $this->view, $this->options, $rows, $title); + } + unset($this->view->row_index); + return $output; + } + + /** + * Group records as needed for rendering. + * + * @param $records + * An array of records from the view to group. + * @param $grouping_field + * The field id on which to group. If empty, the result set will be given + * a single group with an empty string as a label. + * @return + * The grouped record set. + */ + function render_grouping($records, $grouping_field = '') { + // Make sure fields are rendered + $this->render_fields($this->view->result); + $sets = array(); + if ($grouping_field) { + foreach ($records as $index => $row) { + $grouping = ''; + // Group on the rendered version of the field, not the raw. That way, + // we can control any special formatting of the grouping field through + // the admin or theme layer or anywhere else we'd like. + if (isset($this->view->field[$grouping_field])) { + $grouping = $this->get_field($index, $grouping_field); + if ($this->view->field[$grouping_field]->options['label']) { + $grouping = $this->view->field[$grouping_field]->options['label'] . ': ' . $grouping; + } + } + $sets[$grouping][$index] = $row; + } + } + else { + // Create a single group with an empty grouping field. + $sets[''] = $records; + } + return $sets; + } + + /** + * Render all of the fields for a given style and store them on the object. + * + * @param $result + * The result array from $view->result + */ + function render_fields($result) { + if (!$this->uses_fields()) { + return; + } + + if (isset($this->rendered_fields)) { + return $this->rendered_fields; + } + + $this->view->row_index = 0; + $keys = array_keys($this->view->field); + foreach ($result as $count => $row) { + $this->view->row_index = $count; + foreach ($keys as $id) { + $this->rendered_fields[$count][$id] = $this->view->field[$id]->theme($row); + } + } + unset($this->view->row_index); + } + + /** + * Get a rendered field. + * + * @param $index + * The index count of the row. + * @param $field + * The id of the field. + */ + function get_field($index, $field) { + if (!isset($this->rendered_fields)) { + $this->render_fields($this->view->result); + } + + if (isset($this->rendered_fields[$index][$field])) { + return $this->rendered_fields[$index][$field]; + } + } + + function validate() { + $errors = parent::validate(); + + if ($this->uses_row_plugin()) { + $plugin = $this->display->handler->get_plugin('row'); + if (empty($plugin)) { + $errors[] = t('Style @style requires a row style but the row plugin is invalid.', array('@style' => $this->definition['title'])); + } + else { + $result = $plugin->validate(); + if (!empty($result) && is_array($result)) { + $errors = array_merge($errors, $result); + } + } + } + return $errors; + } + + function query() { + parent::query(); + if (isset($this->row_plugin)) { + $this->row_plugin->query(); + } + } +} + +/** + * @} + */ + diff --git a/sites/all/modules/views/plugins/views_plugin_style_default.inc b/sites/all/modules/views/plugins/views_plugin_style_default.inc new file mode 100644 index 0000000..e8c9db8 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_style_default.inc @@ -0,0 +1,24 @@ + '4'); + $options['alignment'] = array('default' => 'horizontal'); + $options['fill_single_line'] = array('default' => TRUE); + $options['summary'] = array('default' => ''); + + return $options; + } + + /** + * Render the given style. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['columns'] = array( + '#type' => 'textfield', + '#title' => t('Number of columns'), + '#default_value' => $this->options['columns'], + ); + $form['alignment'] = array( + '#type' => 'radios', + '#title' => t('Alignment'), + '#options' => array('horizontal' => t('Horizontal'), 'vertical' => t('Vertical')), + '#default_value' => $this->options['alignment'], + '#description' => t('Horizontal alignment will place items starting in the upper left and moving right. Vertical alignment will place items starting in the upper left and moving down.'), + ); + + $form['fill_single_line'] = array( + '#type' => 'checkbox', + '#title' => t('Fill up single line'), + '#description' => t('If you disable this option a grid with only one row will have the amount of items as tds. If you disable it this can cause problems with your css.'), + '#default_value' => !empty($this->options['fill_single_line']), + ); + + $form['summary'] = array( + '#type' => 'textfield', + '#title' => t('Table summary'), + '#description' => t('This value will be displayed as table-summary attribute in the html. Set this for better accessiblity of your site.'), + '#default_value' => $this->options['summary'], + ); + } +} + diff --git a/sites/all/modules/views/plugins/views_plugin_style_jump_menu.inc b/sites/all/modules/views/plugins/views_plugin_style_jump_menu.inc new file mode 100644 index 0000000..3662553 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_style_jump_menu.inc @@ -0,0 +1,155 @@ + FALSE); + $options['path'] = array('default' => ''); + $options['text'] = array('default' => 'Go', 'translatable' => TRUE); + $options['choose'] = array('default' => '- Choose -', 'translatable' => TRUE); + $options['default_value'] = array('default' => FALSE); + + return $options; + } + + /** + * Render the given style. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $handlers = $this->display->handler->get_handlers('field'); + if (empty($handlers)) { + $form['error_markup'] = array( + '#value' => t('You need at least one field before you can configure your jump menu settings'), + '#prefix' => '
    ', + '#suffix' => '
    ', + ); + return; + } + + $form['markup'] = array( + '#value' => t('To properly configure a jump menu, you must select one field that will represent the path to utilize. You should then set that field to exclude. All other displayed fields will be part of the menu. Please note that all HTML will be stripped from this output as select boxes cannot show HTML.'), + '#prefix' => '
    ', + '#suffix' => '
    ', + ); + + foreach ($handlers as $id => $handler) { + $options[$id] = $handler->ui_name(); + } + + $form['path'] = array( + '#type' => 'select', + '#title' => t('Path field'), + '#options' => $options, + '#default_value' => $this->options['path'], + ); + + $form['hide'] = array( + '#type' => 'checkbox', + '#title' => t('Hide the "Go" button.'), + '#default_value' => !empty($this->options['hide']), + '#description' => t('If hidden, this button will only be hidden for users with javascript and the page will automatically jump when the select is changed.'), + ); + + $form['text'] = array( + '#type' => 'textfield', + '#title' => t('Button text'), + '#default_value' => $this->options['text'], + ); + + $form['choose'] = array( + '#type' => 'textfield', + '#title' => t('Choose text'), + '#default_value' => $this->options['choose'], + '#description' => t('The text that will appear as the selected option in the jump menu.'), + ); + + $form['default_value'] = array( + '#type' => 'checkbox', + '#title' => t('Select the current argument.'), + '#default_value' => !empty($this->options['default_value']), + '#description' => t('If checked, the current path will be displayed as the default option in the jump menu, if applicable.'), + ); + } + + /** + * Render the display in this style. + * + * This is overridden so that we can render our grouping specially. + */ + function render() { + $sets = $this->render_grouping($this->view->result, $this->options['grouping']); + + // Turn this all into an $options array for the jump menu. + $this->view->row_index = 0; + $options = array(); + $paths = array(); + + foreach ($sets as $title => $records) { + foreach ($records as $row_index => $row) { + $this->view->row_index = $row_index; + $path = html_entity_decode(strip_tags($this->get_field($this->view->row_index, $this->options['path'])), ENT_QUOTES); + // Putting a '/' in front messes up url() so let's take that out + // so users don't shoot themselves in the foot. + if (strpos($path, '/') === 0) { + $path = substr($path, 1); + } + + // use parse_url() to preserve query and fragment in case the user + // wants to do fun tricks. + $url = parse_url($path); + $url_options = array(); + if (isset($url['query'])) { + $path = strtr($path, array('?' . $url['query'] => '')); + $url_options['query'] = $url['query']; + } + if (isset($url['fragment'])) { + $path = strtr($path, array('#' . $url['fragment'] => '')); + $url_options['fragment'] = $url['fragment']; + } + + $path = url($path, $url_options); + $field = html_entity_decode(strip_tags($this->row_plugin->render($row)), ENT_QUOTES); + if ($title) { + $options[$title][$path] = $field; + } + else { + $options[$path] = $field; + } + $paths[$path] = $path; + $this->view->row_index++; + } + } + unset($this->view->row_index); + + $default_value = ''; + if ($this->options['default_value'] && !empty($paths[url($_GET['q'])])) { + $default_value = url($_GET['q']); + } + + ctools_include('jump-menu'); + $settings = array( + 'hide' => $this->options['hide'], + 'button' => $this->options['text'], + 'choose' => $this->options['choose'], + 'default_value' => $default_value, + ); + + return drupal_get_form('ctools_jump_menu', $options, $settings); + } + + function render_set($title, $records) { + $options = array(); + $fields = $this->rendered_fields; + } +} diff --git a/sites/all/modules/views/plugins/views_plugin_style_list.inc b/sites/all/modules/views/plugins/views_plugin_style_list.inc new file mode 100644 index 0000000..cee39eb --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_style_list.inc @@ -0,0 +1,37 @@ + 'ul'); + + return $options; + } + + /** + * Render the given style. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['type'] = array( + '#type' => 'radios', + '#title' => t('List type'), + '#options' => array('ul' => t('Unordered list'), 'ol' => t('Ordered list')), + '#default_value' => $this->options['type'], + ); + } +} + diff --git a/sites/all/modules/views/plugins/views_plugin_style_rss.inc b/sites/all/modules/views/plugins/views_plugin_style_rss.inc new file mode 100644 index 0000000..59dd89b --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_style_rss.inc @@ -0,0 +1,109 @@ +view->display[$display_id]->handler; + $url_options = array(); + $input = $this->view->get_exposed_input(); + if ($input) { + $url_options['query'] = $input; + } + + $url = url($this->view->get_url(NULL, $path), $url_options); + if ($display->has_path()) { + if (empty($this->preview)) { + drupal_add_feed($url, $title); + } + } + else { + if (empty($this->view->feed_icon)) { + $this->view->feed_icon = ''; + } + + $this->view->feed_icon .= theme('feed_icon', $url, $title); + drupal_add_link(array( + 'rel' => 'alternate', + 'type' => 'application/rss+xml', + 'title' => $title, + 'href' => $url + )); + } + } + + function option_definition() { + $options = parent::option_definition(); + + $options['description'] = array('default' => '', 'translatable' => TRUE); + $options['mission_description'] = array('default' => '', 'translatable' => TRUE); + + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + + $form['mission_description'] = array( + '#type' => 'checkbox', + '#default_value' => !empty($this->options['mission_description']), + '#title' => t('Use the site mission for the description'), + ); + $form['description'] = array( + '#type' => 'textfield', + '#title' => t('RSS description'), + '#default_value' => $this->options['description'], + '#description' => t('This will appear in the RSS feed itself.'), + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-style-options-override' => array(FALSE)), + ); + } + + /** + * Return an array of additional XHTML elements to add to the channel. + * + * @return + * An array that can be passed to format_xml_elements(). + */ + function get_channel_elements() { + return array(); + } + + function render() { + if (empty($this->row_plugin)) { + vpr('views_plugin_style_default: Missing row plugin'); + return; + } + $rows = ''; + + // This will be filled in by the row plugin and is used later on in the + // theming output. + $this->namespaces = array(); + + // Fetch any additional elements for the channel and merge in their + // namespaces. + $this->channel_elements = $this->get_channel_elements(); + foreach ($this->channel_elements as $element) { + if (isset($element['namespace'])) { + $this->namespaces = array_merge($this->namespaces, $element['namespace']); + } + } + + foreach ($this->view->result as $row_index => $row) { + $this->view->row_index = $row_index; + $rows .= $this->row_plugin->render($row); + } + + $output = theme($this->theme_functions(), $this->view, $this->options, $rows); + unset($this->view->row_index); + + return $output; + } +} diff --git a/sites/all/modules/views/plugins/views_plugin_style_summary.inc b/sites/all/modules/views/plugins/views_plugin_style_summary.inc new file mode 100644 index 0000000..706d5d3 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_style_summary.inc @@ -0,0 +1,69 @@ + ''); + $options['count'] = array('default' => TRUE); + $options['override'] = array('default' => FALSE); + $options['items_per_page'] = array('default' => 25); + + return $options; + } + + function query() { + if (!empty($this->options['override'])) { + $this->view->set_items_per_page(intval($this->options['items_per_page'])); + } + } + + function options_form(&$form, &$form_state) { + $form['base_path'] = array( + '#type' => 'textfield', + '#title' => t('Base path'), + '#default_value' => $this->options['base_path'], + '#description' => t('Define the base path for links in this summary + view, i.e. http://example.com/your_view_path/archive. + Do not include beginning and ending forward slash. If this value + is empty, views will use the first path found as the base path, + in page displays, or / if no path could be found.'), + ); + $form['count'] = array( + '#type' => 'checkbox', + '#default_value' => !empty($this->options['count']), + '#title' => t('Display record count with link'), + ); + $form['override'] = array( + '#type' => 'checkbox', + '#default_value' => !empty($this->options['override']), + '#title' => t('Override number of items to display'), + ); + $form['items_per_page'] = array( + '#type' => 'textfield', + '#title' => t('Items to display'), + '#default_value' => $this->options['items_per_page'], + '#process' => array('views_process_dependency'), + '#dependency' => array('edit-style-options-override' => array(TRUE)), + ); + } + + function render() { + $rows = array(); + foreach ($this->view->result as $row) { + // @todo: Include separator as an option. + $rows[] = $row; + } + return theme($this->theme_functions(), $this->view, $this->options, $rows); + } +} + diff --git a/sites/all/modules/views/plugins/views_plugin_style_summary_jump_menu.inc b/sites/all/modules/views/plugins/views_plugin_style_summary_jump_menu.inc new file mode 100644 index 0000000..e4c199e --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_style_summary_jump_menu.inc @@ -0,0 +1,123 @@ + ''); + $options['count'] = array('default' => TRUE); + $options['hide'] = array('default' => FALSE); + $options['text'] = array('default' => 'Go', 'translatable' => TRUE); + $options['choose'] = array('default' => '- Choose -', 'translatable' => TRUE); + $options['default_value'] = array('default' => FALSE); + + return $options; + } + + function query() { + // We can't have an offset without a limit, so provide a very large limit instead. + if (!empty($this->display->handler->options['offset'])) { + $this->view->set_items_per_page(999999); + } + else { + $this->view->set_items_per_page(0); + $this->view->set_use_pager(0); + } + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['base_path'] = array( + '#type' => 'textfield', + '#title' => t('Base path'), + '#default_value' => $this->options['base_path'], + '#description' => t('Define the base path for links in this summary + view, i.e. http://example.com/your_view_path/archive. + Do not include beginning and ending forward slash. If this value + is empty, views will use the first path found as the base path, + in page displays, or / if no path could be found.'), + ); + $form['count'] = array( + '#type' => 'checkbox', + '#default_value' => !empty($this->options['count']), + '#title' => t('Display record count with link'), + ); + + $form['hide'] = array( + '#type' => 'checkbox', + '#title' => t('Hide the "Go" button.'), + '#default_value' => !empty($this->options['hide']), + '#description' => t('If hidden, this button will only be hidden for users with javascript and the page will automatically jump when the select is changed.'), + ); + + $form['text'] = array( + '#type' => 'textfield', + '#title' => t('Button text'), + '#default_value' => $this->options['text'], + ); + + $form['choose'] = array( + '#type' => 'textfield', + '#title' => t('Choose text'), + '#default_value' => $this->options['choose'], + '#description' => t('The text that will appear as the selected option in the jump menu.'), + ); + + $form['default_value'] = array( + '#type' => 'checkbox', + '#title' => t('Select the current argument.'), + '#default_value' => !empty($this->options['default_value']), + '#description' => t('If checked, the current argument setting will be displayed as the default option in the jump menu, if applicable.'), + ); + } + + function render() { + $argument = $this->view->argument[$this->view->build_info['summary_level']]; + + $url_options = array(); + + if (!empty($this->view->exposed_raw_input)) { + $url_options['query'] = $this->view->exposed_raw_input; + } + + $options = array(); + $default_value = ''; + foreach ($this->view->result as $id => $row) { + $args = $this->view->args; + $args[$argument->position] = $argument->summary_argument($row); + $base_path = NULL; + if (!empty($argument->options['style_options']['base_path'])) { + $base_path = $argument->options['style_options']['base_path']; + } + $path = url($this->view->get_url($args, $base_path), $url_options); + + $options[$path] = strip_tags($argument->summary_name($row)); + if (!empty($this->options['count'])) { + $options[$path] .= ' (' . intval($row->{$argument->count_alias}) . ')'; + } + if ($this->options['default_value'] && $_GET['q'] == $this->view->get_url($args)) { + $default_value = $path; + } + } + + ctools_include('jump-menu'); + $settings = array( + 'hide' => $this->options['hide'], + 'button' => $this->options['text'], + 'choose' => $this->options['choose'], + 'default_value' => $default_value, + ); + + return drupal_get_form('ctools_jump_menu', $options, $settings); + } +} + diff --git a/sites/all/modules/views/plugins/views_plugin_style_summary_unformatted.inc b/sites/all/modules/views/plugins/views_plugin_style_summary_unformatted.inc new file mode 100644 index 0000000..69a8d72 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_style_summary_unformatted.inc @@ -0,0 +1,34 @@ + FALSE); + $options['separator'] = array('default' => ''); + return $options; + } + + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $form['inline'] = array( + '#type' => 'checkbox', + '#default_value' => !empty($this->options['inline']), + '#title' => t('Display items inline'), + ); + $form['separator'] = array( + '#type' => 'textfield', + '#title' => t('Separator'), + '#default_value' => $this->options['separator'], + ); + } +} + diff --git a/sites/all/modules/views/plugins/views_plugin_style_table.inc b/sites/all/modules/views/plugins/views_plugin_style_table.inc new file mode 100644 index 0000000..0454fd1 --- /dev/null +++ b/sites/all/modules/views/plugins/views_plugin_style_table.inc @@ -0,0 +1,254 @@ + array()); + $options['default'] = array('default' => ''); + $options['info'] = array('default' => array()); + $options['override'] = array('default' => TRUE); + $options['sticky'] = array('default' => FALSE); + $options['order'] = array('default' => 'asc'); + $options['summary'] = array('default' => ''); + + return $options; + } + + /** + * Determine if we should provide sorting based upon $_GET inputs. + */ + function build_sort() { + if (!isset($_GET['order']) && ($this->options['default'] == -1 || empty($this->view->field[$this->options['default']]))) { + return TRUE; + } + + // If a sort we don't know anything about gets through, exit gracefully. + if (isset($_GET['order']) && empty($this->view->field[$_GET['order']])) { + return TRUE; + } + + // Let the builder know whether or not we're overriding the default sorts. + return empty($this->options['override']); + } + + /** + * Add our actual sort criteria + */ + function build_sort_post() { + if (!isset($_GET['order'])) { + // check for a 'default' clicksort. If there isn't one, exit gracefully. + if (empty($this->options['default'])) { + return; + } + $sort = $this->options['default']; + $this->order = !empty($this->options['order']) ? $this->options['order'] : 'asc'; + } + else { + $sort = $_GET['order']; + // Store the $order for later use. + $this->order = !empty($_GET['sort']) ? strtolower($_GET['sort']) : 'asc'; + } + + // If a sort we don't know anything about gets through, exit gracefully. + if (empty($this->view->field[$sort])) { + return; + } + + // Ensure $this->order is valid. + if ($this->order != 'asc' && $this->order != 'desc') { + $this->order = 'asc'; + } + + // Store the $sort for later use. + $this->active = $sort; + + // Tell the field to click sort. + $this->view->field[$sort]->click_sort($this->order); + } + + /** + * Normalize a list of columns based upon the fields that are + * available. This compares the fields stored in the style handler + * to the list of fields actually in the view, removing fields that + * have been removed and adding new fields in their own column. + * + * - Each field must be in a column. + * - Each column must be based upon a field, and that field + * is somewhere in the column. + * - Any fields not currently represented must be added. + * - Columns must be re-ordered to match the fields. + * + * @param $columns + * An array of all fields; the key is the id of the field and the + * value is the id of the column the field should be in. + * @param $fields + * The fields to use for the columns. If not provided, they will + * be requested from the current display. The running render should + * send the fields through, as they may be different than what the + * display has listed due to access control or other changes. + */ + function sanitize_columns($columns, $fields = NULL) { + $sanitized = array(); + if ($fields === NULL) { + $fields = $this->display->handler->get_option('fields'); + } + + // Preconfigure the sanitized array so that the order is retained. + foreach ($fields as $field => $info) { + // Set to itself so that if it isn't touched, it gets column + // status automatically. + $sanitized[$field] = $field; + } + + foreach ($columns as $field => $column) { + // first, make sure the field still exists. + if (!isset($sanitized[$field])) { + continue; + } + + // If the field is the column, mark it so, or the column + // it's set to is a column, that's ok + if ($field == $column || $columns[$column] == $column && !empty($sanitized[$column])) { + $sanitized[$field] = $column; + } + // Since we set the field to itself initially, ignoring + // the condition is ok; the field will get its column + // status back. + } + + return $sanitized; + } + + /** + * Render the given style. + */ + function options_form(&$form, &$form_state) { + parent::options_form($form, $form_state); + $handlers = $this->display->handler->get_handlers('field'); + if (empty($handlers)) { + $form['error_markup'] = array( + '#value' => t('You need at least one field before you can configure your table settings'), + '#prefix' => '
    ', + '#suffix' => '
    ', + ); + return; + } + + $form['override'] = array( + '#type' => 'checkbox', + '#title' => t('Override normal sorting if click sorting is used'), + '#default_value' => !empty($this->options['override']), + ); + + $form['sticky'] = array( + '#type' => 'checkbox', + '#title' => t('Enable Drupal style "sticky" table headers (Javascript)'), + '#default_value' => !empty($this->options['sticky']), + '#description' => t('(Sticky header effects will not be active for preview below, only on live output.)'), + ); + + $form['order'] = array( + '#type' => 'select', + '#title' => t('Default sort order'), + '#options' => array('asc' => t('Ascending'), 'desc' => t('Descending')), + '#default_value' => $this->options['order'], + '#description' => t('If a default sort order is selected, what order should it use by default.'), + ); + + $form['summary'] = array( + '#type' => 'textfield', + '#title' => t('Table summary'), + '#description' => t('This value will be displayed as table-summary attribute in the html. Set this for better accessiblity of your site.'), + '#default_value' => $this->options['summary'], + ); + + // Note: views UI registers this theme handler on our behalf. Your module + // will have to register your theme handlers if you do stuff like this. + $form['#theme'] = 'views_ui_style_plugin_table'; + + $columns = $this->sanitize_columns($this->options['columns']); + + // Create an array of allowed columns from the data we know: + $field_names = $this->display->handler->get_field_labels(); + + if (isset($this->options['default'])) { + $default = $this->options['default']; + if (!isset($columns[$default])) { + $default = -1; + } + } + else { + $default = -1; + } + + foreach ($columns as $field => $column) { + $safe = str_replace(array('][', '_', ' '), '-', $field); + // the $id of the column for dependency checking. + $id = 'edit-style-options-columns-' . $safe; + + $form['columns'][$field] = array( + '#type' => 'select', + '#options' => $field_names, + '#default_value' => $column, + ); + if ($handlers[$field]->click_sortable()) { + $form['info'][$field]['sortable'] = array( + '#type' => 'checkbox', + '#default_value' => !empty($this->options['info'][$field]['sortable']), + '#process' => array('views_process_dependency'), + '#dependency' => array($id => array($field)), + ); + // Provide an ID so we can have such things. + $radio_id = form_clean_id('edit-default-' . $field); + $form['default'][$field] = array( + '#type' => 'radio', + '#return_value' => $field, + '#parents' => array('style_options', 'default'), + '#id' => $radio_id, + // because 'radio' doesn't fully support '#id' =( + '#attributes' => array('id' => $radio_id), + '#default_value' => $default, + '#process' => array('views_process_dependency'), + '#dependency' => array($id => array($field)), + ); + } + $form['info'][$field]['separator'] = array( + '#type' => 'textfield', + '#size' => 10, + '#default_value' => isset($this->options['info'][$field]['separator']) ? $this->options['info'][$field]['separator'] : '', + '#process' => array('views_process_dependency'), + '#dependency' => array($id => array($field)), + ); + + // markup for the field name + $form['info'][$field]['name'] = array( + '#value' => $field_names[$field], + ); + } + + // Provide a radio for no default sort + $form['default'][-1] = array( + '#type' => 'radio', + '#return_value' => -1, + '#parents' => array('style_options', 'default'), + '#id' => 'edit-default-0', + '#default_value' => $default, + ); + + $form['description_markup'] = array( + '#prefix' => '
    ', + '#suffix' => '
    ', + '#value' => t('Place fields into columns; you may combine multiple fields into the same column. If you do, the separator in the column specified will be used to separate the fields. Check the sortable box to make that column click sortable, and check the default sort radio to determine which column will be sorted by default, if any. You may control column order and field labels in the fields section.'), + ); + } +} diff --git a/sites/all/modules/views/theme/theme.inc b/sites/all/modules/views/theme/theme.inc new file mode 100644 index 0000000..0ce0a20 --- /dev/null +++ b/sites/all/modules/views/theme/theme.inc @@ -0,0 +1,756 @@ +name . '__' . $display->id; + $themes[] = $hook . '__' . $display->id; + $themes[] = $hook . '__' . preg_replace('/[^a-z0-9]/', '_', strtolower($view->tag)); + if ($display->id != $display->display_plugin) { + $themes[] = $hook . '__' . $view->name . '__' . $display->display_plugin; + $themes[] = $hook . '__' . $display->display_plugin; + } + } + $themes[] = $hook . '__' . $view->name; + $themes[] = $hook; + return $themes; +} + +/** + * Preprocess the primary theme implementation for a view. + */ +function template_preprocess_views_view(&$vars) { + global $base_path; + + $view = $vars['view']; + + $vars['rows'] = !empty($view->result) || !empty($view->style_plugin->definition['even empty']) ? $view->style_plugin->render($view->result) : ''; + + $vars['css_name'] = views_css_safe($view->name); + $vars['name'] = $view->name; + $vars['display_id'] = $view->current_display; + + // Basic classes + $vars['classes_array'] = array(); + $vars['classes_array'][] = 'view'; + $vars['classes_array'][] = 'view-' . views_css_safe($vars['name']); + $vars['classes_array'][] = 'view-id-' . $vars['name']; + $vars['classes_array'][] = 'view-display-id-' . $vars['display_id']; + + $css_class = $view->display_handler->get_option('css_class'); + if (!empty($css_class)) { + $vars['css_class'] = preg_replace('/[^a-zA-Z0-9- ]/', '-', $css_class); + $vars['classes_array'][] = $vars['css_class']; + } + + if (!$vars['rows']) { + $vars['empty'] = $view->display_handler->render_empty(); + if (!$view->display_handler->get_option('header_empty')) { + $vars['header'] = ''; + } + if (!$view->display_handler->get_option('footer_empty')) { + $vars['footer'] = ''; + } + } + else { + $vars['empty'] = ''; + $header = TRUE; + } + + $vars['exposed'] = !empty($view->exposed_widgets) ? $view->exposed_widgets : ''; + if (!isset($vars['header'])) { + $vars['header'] = $view->display_handler->render_header(); + } + if (!isset($vars['footer'])) { + $vars['footer'] = $view->display_handler->render_footer(); + } + $vars['more'] = $view->display_handler->render_more_link(); + $vars['feed_icon'] = !empty($view->feed_icon) ? $view->feed_icon : ''; + + $vars['attachment_before'] = !empty($view->attachment_before) ? $view->attachment_before : ''; + $vars['attachment_after'] = !empty($view->attachment_after) ? $view->attachment_after : ''; + + $vars['pager'] = ''; + + $exposed_input = isset($view->exposed_raw_input) ? $view->exposed_raw_input: NULL; + if ($view->display_handler->render_pager()) { + $pager_type = ($view->pager['use_pager'] === 'mini' ? 'views_mini_pager' : 'pager'); + $pager_theme = views_theme_functions($pager_type, $view, $view->display_handler->display); + $vars['pager'] = theme($pager_theme, $exposed_input, $view->pager['items_per_page'], $view->pager['element']); + } + + // if administrator, add some links. These used to be tabs, but this is better. + if (user_access('administer views') && module_exists('views_ui') && empty($view->hide_admin_links) && !variable_get('views_no_hover_links', FALSE)) { + $vars['admin_links_raw'] = array( + array( + 'title' => t('Edit'), + 'alt' => t("Edit this view"), + 'href' => "admin/build/views/edit/$view->name", + 'fragment' => 'views-tab-' . $view->current_display, + 'query' => drupal_get_destination(), + ), + array( + 'title' => t('Export'), + 'alt' => t("Export this view"), + 'href' => "admin/build/views/export/$view->name", + ), + array( + 'title' => t('Clone'), + 'alt' => t("Create a copy of this view"), + 'href' => "admin/build/views/clone/$view->name", + ), + ); + + drupal_alter('views_admin_links', $vars['admin_links_raw'], $view); + $vars['admin_links'] = theme('links', $vars['admin_links_raw']); + } + else { + $vars['admin_links'] = ''; + $vars['admin_links_raw'] = array(); + } + + // Our JavaScript needs to have some means to find the HTML belonging to this + // view. + // + // It is true that the DIV wrapper has classes denoting the name of the view + // and its display ID, but this is not enough to unequivocally match a view + // with its HTML, because one view may appear several times on the page. So + // we set up a running counter, $dom_id, to issue a "unique" identifier for + // each view. This identifier is written to both Drupal.settings and the DIV + // wrapper. + static $dom_id = 1; + $vars['dom_id'] = !empty($view->dom_id) ? $view->dom_id : $dom_id++; + $vars['classes_array'][] = 'view-dom-id-' . $vars['dom_id']; + + // If using AJAX, send identifying data about this view. + if ($view->use_ajax) { + $settings = array( + 'views' => array( + 'ajax_path' => url('views/ajax'), + 'ajaxViews' => array( + array( + 'view_name' => $view->name, + 'view_display_id' => $view->current_display, + 'view_args' => check_plain(implode('/', $view->args)), + 'view_path' => check_plain($_GET['q']), + // Pass through URL to ensure we get e.g. language prefixes. +// 'view_base_path' => isset($view->display['page']) ? substr(url($view->display['page']->display_options['path']), strlen($base_path)) : '', + 'view_base_path' => $view->get_path(), + 'view_dom_id' => $vars['dom_id'], + // To fit multiple views on a page, the programmer may have + // overridden the display's pager_element. + 'pager_element' => $view->pager['element'], + ), + ), + ), + ); + + drupal_add_js($settings, 'setting'); + views_add_js('ajax_view'); + } + // Flatten the classes to a string for the template file. + $vars['classes'] = implode(' ', $vars['classes_array']); +} + +/** + * Preprocess theme function to print a single record from a row, with fields + */ +function template_preprocess_views_view_fields(&$vars) { + $view = $vars['view']; + + // Loop through the fields for this view. + $inline = FALSE; + $vars['fields'] = array(); // ensure it's at least an empty array. + foreach ($view->field as $id => $field) { + // render this even if set to exclude so it can be used elsewhere. + $field_output = $view->style_plugin->get_field($view->row_index, $id); + $empty = $field_output !== 0 && empty($field_output); + if (empty($field->options['exclude']) && (!$empty || (empty($field->options['hide_empty']) && empty($vars['options']['hide_empty'])))) { + $object = new stdClass(); + + $object->content = $field_output; + if (isset($view->field[$id]->field_alias) && isset($vars['row']->{$view->field[$id]->field_alias})) { + $object->raw = $vars['row']->{$view->field[$id]->field_alias}; + } + else { + $object->raw = NULL; // make sure it exists to reduce NOTICE + } + $object->inline = !empty($vars['options']['inline'][$id]); + $object->inline_html = $object->inline ? 'span' : 'div'; + if (!empty($vars['options']['separator']) && $inline && $object->inline && $object->content) { + $object->separator = filter_xss_admin($vars['options']['separator']); + } + + $inline = $object->inline; + + $object->handler = &$view->field[$id]; + $object->element_type = $object->handler->element_type(); + + $object->class = views_css_safe($id); + $object->label = check_plain($view->field[$id]->label()); + $vars['fields'][$id] = $object; + } + } + +} + +/** + * Display a single views field. + * + * Interesting bits of info: + * $field->field_alias says what the raw value in $row will be. Reach it like + * this: @code { $row->{$field->field_alias} @endcode + */ +function theme_views_view_field($view, $field, $row) { + // Reference safe for PHP 4: + return $view->field[$field->options['id']]->advanced_render($row); +} + +/** + * Process a single field within a view. + * + * This preprocess function isn't normally run, as a function is used by + * default, for performance. However, by creating a template, this + * preprocess should get picked up. + */ +function template_preprocess_views_view_field(&$vars) { + $vars['output'] = $vars['field']->advanced_render($vars['row']); +} + +/** + * Preprocess theme function to print a single record from a row, with fields + */ +function template_preprocess_views_view_summary(&$vars) { + $view = $vars['view']; + $argument = $view->argument[$view->build_info['summary_level']]; + + $url_options = array(); + + if (!empty($view->exposed_raw_input)) { + $url_options['query'] = $view->exposed_raw_input; + } + $vars['classes'] = array(); + foreach ($vars['rows'] as $id => $row) { + $vars['rows'][$id]->link = $argument->summary_name($row); + $args = $view->args; + $args[$argument->position] = $argument->summary_argument($row); + + $base_path = NULL; + if (!empty($argument->options['style_options']['base_path'])) { + $base_path = $argument->options['style_options']['base_path']; + } + $vars['rows'][$id]->url = url($view->get_url($args, $base_path), $url_options); + $vars['rows'][$id]->count = intval($row->{$argument->count_alias}); + if ($vars['rows'][$id]->url == base_path() . $_GET['q'] || $vars['rows'][$id]->url == base_path() . drupal_get_path_alias($_GET['q'])) { + $vars['classes'][$id] = 'active'; + } + } +} + +/** + * Template preprocess theme function to print summary basically + * unformatted. + */ +function template_preprocess_views_view_summary_unformatted(&$vars) { + $view = $vars['view']; + $argument = $view->argument[$view->build_info['summary_level']]; + $vars['classes'] = array(); + + $url_options = array(); + + if (!empty($view->exposed_raw_input)) { + $url_options['query'] = $view->exposed_raw_input; + } + + $count = 0; + foreach ($vars['rows'] as $id => $row) { + // only false on first time: + if ($count++) { + $vars['rows'][$id]->separator = filter_xss_admin($vars['options']['separator']); + } + $vars['rows'][$id]->link = $argument->summary_name($row); + $args = $view->args; + $args[$argument->position] = $argument->summary_argument($row); + + $base_path = NULL; + if (!empty($argument->options['style_options']['base_path'])) { + $base_path = $argument->options['style_options']['base_path']; + } + $vars['rows'][$id]->url = url($view->get_url($args, $base_path), $url_options); + $vars['rows'][$id]->count = intval($row->{$argument->count_alias}); + if ($vars['rows'][$id]->url == base_path() . $_GET['q'] || $vars['rows'][$id]->url == base_path() . drupal_get_path_alias($_GET['q'])) { + $vars['classes'][$id] = 'active'; + } + } +} + +/** + * Display a view as a table style. + */ +function template_preprocess_views_view_table(&$vars) { + $view = $vars['view']; + + // We need the raw data for this grouping, which is passed in as $vars['rows']. + // However, the template also needs to use for the rendered fields. We + // therefore swap the raw data out to a new variable and reset $vars['rows'] + // so that it can get rebuilt. + // Store rows so that they may be used by further preprocess functions. + $result = $vars['result'] = $vars['rows']; + $vars['rows'] = array(); + + $options = $view->style_plugin->options; + $handler = $view->style_plugin; + + $fields = &$view->field; + $columns = $handler->sanitize_columns($options['columns'], $fields); + + $active = !empty($handler->active) ? $handler->active : ''; + $order = !empty($handler->order) ? $handler->order : 'asc'; + + parse_str(tablesort_get_querystring(), $query); + if (isset($view->exposed_raw_input)) { + $query += $view->exposed_raw_input; + } + $query = empty($query) ? '' : '&' . http_build_query($query, '', '&'); + + $header = array(); + + // Fields must be rendered in order as of Views 2.3, so we will pre-render + // everything. + $renders = $handler->render_fields($result); + + foreach ($columns as $field => $column) { + // render the header labels + if ($field == $column && empty($fields[$field]->options['exclude'])) { + $label = check_plain(!empty($fields[$field]) ? $fields[$field]->label() : ''); + if (empty($options['info'][$field]['sortable']) || !$fields[$field]->click_sortable()) { + $vars['header'][$field] = $label; + } + else { + // @todo -- make this a setting + $initial = 'asc'; + + if ($active == $field && $order == 'asc') { + $initial = 'desc'; + } + + $title = t('sort by @s', array('@s' => $label)); + if ($active == $field) { + $label .= theme('tablesort_indicator', $initial); + } + $link_options = array( + 'html' => true, + 'attributes' => array('title' => $title), + 'query' => 'order=' . urlencode($field) . '&sort=' . $initial . $query, + ); + $vars['header'][$field] = l($label, $_GET['q'], $link_options); + } + } + + // Create a second variable so we can easily find what fields we have and what the + // CSS classes should be. + $vars['fields'][$field] = views_css_safe($field); + if ($active == $field) { + $vars['fields'][$field] .= ' active'; + } + + // Render each field into its appropriate column. + foreach ($result as $num => $row) { + if (!empty($fields[$field]) && empty($fields[$field]->options['exclude'])) { + $field_output = $renders[$num][$field]; + + if (!isset($vars['rows'][$num][$column])) { + $vars['rows'][$num][$column] = ''; + } + + // Don't bother with separators and stuff if the field does not show up. + if ($field_output === '') { + continue; + } + + // Place the field into the column, along with an optional separator. + if ($vars['rows'][$num][$column] !== '') { + if (!empty($options['info'][$column]['separator'])) { + $vars['rows'][$num][$column] .= filter_xss_admin($options['info'][$column]['separator']); + } + } + + $vars['rows'][$num][$column] .= $field_output; + } + } + } + + $count = 0; + foreach ($vars['rows'] as $num => $row) { + $vars['row_classes'][$num][] = ($count++ % 2 == 0) ? 'odd' : 'even'; + } + + $vars['row_classes'][0][] = 'views-row-first'; + $vars['row_classes'][count($vars['row_classes']) - 1][] = 'views-row-last'; + + $vars['class'] = 'views-table'; + if (!empty($options['sticky'])) { + drupal_add_js('misc/tableheader.js'); + $vars['class'] .= " sticky-enabled"; + } + $vars['class'] .= ' cols-' . count($vars['header']); + + $vars['attributes'] = ''; + if (!empty($handler->options['summary'])) { + $vars['attributes'] = drupal_attributes(array('summary' => $handler->options['summary'])); + } +} + +/** + * Display a view as a grid style. + */ +function template_preprocess_views_view_grid(&$vars) { + $view = $vars['view']; + $result = $view->result; + $options = $view->style_plugin->options; + $handler = $view->style_plugin; + + $columns = $options['columns']; + + $rows = array(); + + if ($options['alignment'] == 'horizontal') { + $row = array(); + $row_count = 0; + foreach ($vars['rows'] as $count => $item) { + $row[] = $item; + $row_count++; + if (($count + 1) % $columns == 0) { + $rows[] = $row; + $row = array(); + $row_count = 0; + } + } + if ($row) { + // Fill up the last line only if it's configured, but this is default. + if (!empty($handler->options['fill_single_line']) || count($rows)) { + for ($i = 0; $i < ($columns - $row_count); $i++) { + $row[] = ''; + } + } + $rows[] = $row; + } + } + else { + $num_rows = floor(count($vars['rows']) / $columns); + // The remainders are the 'odd' columns that are slightly longer. + $remainders = count($vars['rows']) % $columns; + $row = 0; + $col = 0; + foreach ($vars['rows'] as $count => $item) { + $rows[$row][$col] = $item; + $row++; + + if (!$remainders && $row == $num_rows) { + $row = 0; + $col++; + } + else if ($remainders && $row == $num_rows + 1) { + $row = 0; + $col++; + $remainders--; + } + } + for ($i = 0; $i < count($rows[0]); $i++) { + // This should be string so that's okay :) + if (!isset($rows[count($rows) - 1][$i])) { + $rows[count($rows) - 1][$i] = ''; + } + } + } + // Add first/last column class + foreach ($rows as $row_number => $row) { + foreach ($row as $column_number => $column) { + $column_classes[$row_number][$column_number] = 'col-' . ($column_number + 1); + if ($column_number == 0) { + $column_classes[$row_number][$column_number] .= ' col-first'; + } + elseif (count($rows[$row_number]) == ($column_number + 1)) { + $column_classes[$row_number][$column_number] .= ' col-last'; + } + } + } + $vars['column_classes'] = $column_classes; + $vars['rows'] = $rows; + $vars['class'] = 'views-view-grid col-' . $columns; + $vars['attributes'] = ''; + if (!empty($handler->options['summary'])) { + $vars['attributes'] = drupal_attributes(array('summary' => $handler->options['summary'])); + } +} + +/** + * Display the simple view of rows one after another + */ +function template_preprocess_views_view_unformatted(&$vars) { + $view = $vars['view']; + $rows = $vars['rows']; + + $vars['classes'] = array(); + // Set up striping values. + foreach ($rows as $id => $row) { + $row_classes = array(); + $row_classes[] = 'views-row'; + $row_classes[] = 'views-row-' . ($id + 1); + $row_classes[] = 'views-row-' . ($id % 2 ? 'even' : 'odd'); + if ($id == 0) { + $row_classes[] = 'views-row-first'; + } + if ($id == count($rows) -1) { + $row_classes[] = 'views-row-last'; + } + // Flatten the classes to a string for each row for the template file. + $vars['classes'][$id] = implode(' ', $row_classes); + } +} + +/** + * Display the view as an HTML list element + */ +function template_preprocess_views_view_list(&$vars) { + template_preprocess_views_view_unformatted($vars); +} + +/** + * Preprocess an RSS feed + */ +function template_preprocess_views_view_rss(&$vars) { + global $base_url; + global $language; + + $view = &$vars['view']; + $options = &$vars['options']; + $items = &$vars['rows']; + + $style = &$view->style_plugin; + + if (!empty($options['mission_description'])) { + $description = variable_get('site_mission', ''); + } + else { + $description = $options['description']; + } + // The RSS 2.0 "spec" doesn't indicate HTML can be used in the description. + // We strip all HTML tags, but need to prevent double encoding from properly + // escaped source data (such as & becoming &amp;). + $vars['description'] = check_plain(decode_entities(strip_tags($description))); + + if ($view->display_handler->get_option('sitename_title')) { + $title = variable_get('site_name', 'Drupal'); + if ($slogan = variable_get('site_slogan', '')) { + $title .= ' - ' . $slogan; + } + } + else { + $title = $view->get_title(); + } + $vars['title'] = check_plain($title); + + // Figure out which display which has a path we're using for this feed. If there isn't + // one, use the global $base_url + $link_display_id = $view->display_handler->get_link_display(); + if ($link_display_id && !empty($view->display[$link_display_id])) { + $path = $view->display[$link_display_id]->handler->get_path(); + } + + if ($path) { + $path = $view->get_url(NULL, $path); + $url_options = array('absolute' => TRUE); + if (!empty($view->exposed_raw_input)) { + $url_options['query'] = $view->exposed_raw_input; + } + + // Compare the link to the default home page; if it's the default home page, just use $base_url. + if ($path == variable_get('site_frontpage', 'node')) { + $path = ''; + } + + $vars['link'] = check_url(url($path, $url_options)); + } + + $vars['langcode'] = check_plain($language->language); + $vars['namespaces'] = drupal_attributes($style->namespaces); + $vars['items'] = $items; + $vars['channel_elements'] = format_xml_elements($style->channel_elements); + + drupal_set_header('Content-Type: application/rss+xml; charset=utf-8'); +} + +/** + * Default theme function for all RSS rows. + */ +function template_preprocess_views_view_row_rss(&$vars) { + $view = &$vars['view']; + $options = &$vars['options']; + $item = &$vars['row']; + + $vars['title'] = check_plain($item->title); + $vars['link'] = check_url($item->link); + $vars['description'] = check_plain($item->description); + $vars['item_elements'] = empty($item->elements) ? '' : format_xml_elements($item->elements); +} + +/** + * Default theme function for all filter forms. + */ +function template_preprocess_views_exposed_form(&$vars) { + $form = &$vars['form']; + + // Put all single checkboxes together in the last spot. + $checkboxes = ''; + + if (!empty($form['q'])) { + $vars['q'] = drupal_render($form['q']); + } + + $vars['widgets'] = array(); + foreach ($form['#info'] as $id => $info) { + // Set aside checkboxes. + if (isset($form[$info['value']]['#type']) && $form[$info['value']]['#type'] == 'checkbox') { + $checkboxes .= drupal_render($form[$info['value']]); + continue; + } + $widget = new stdClass; + // set up defaults so that there's always something there. + $widget->label = $widget->operator = $widget->widget = NULL; + + $widget->id = $form[$info['value']]['#id']; + if (!empty($info['label'])) { + $widget->label = $info['label']; + } + if (!empty($info['operator'])) { + $widget->operator = drupal_render($form[$info['operator']]); + } + $widget->widget = drupal_render($form[$info['value']]); + $vars['widgets'][$id] = $widget; + } + + // Wrap up all the checkboxes we set aside into a widget. + if ($checkboxes) { + $widget = new stdClass; + // set up defaults so that there's always something there. + $widget->label = $widget->operator = $widget->widget = NULL; + $widget->widget = $checkboxes; + $vars['widgets']['checkboxes'] = $widget; + } + + // Don't render these: + unset($form['form_id']); + unset($form['form_build_id']); + unset($form['form_token']); + + // This includes the submit button. + $vars['button'] = drupal_render($form); +} + +function theme_views_mini_pager($tags = array(), $limit = 10, $element = 0, $parameters = array(), $quantity = 9) { + global $pager_page_array, $pager_total; + + // Calculate various markers within this pager piece: + // Middle is used to "center" pages around the current page. + $pager_middle = ceil($quantity / 2); + // current is the page we are currently paged to + $pager_current = $pager_page_array[$element] + 1; + // max is the maximum page number + $pager_max = $pager_total[$element]; + // End of marker calculations. + + + $li_previous = theme('pager_previous', (isset($tags[1]) ? $tags[1] : t('‹‹')), $limit, $element, 1, $parameters); + if (empty($li_previous)) { + $li_previous = " "; + } + + $li_next = theme('pager_next', (isset($tags[3]) ? $tags[3] : t('››')), $limit, $element, 1, $parameters); + if (empty($li_next)) { + $li_next = " "; + } + + if ($pager_total[$element] > 1) { + $items[] = array( + 'class' => 'pager-previous', + 'data' => $li_previous, + ); + + $items[] = array( + 'class' => 'pager-current', + 'data' => t('@current of @max', array('@current' => $pager_current, '@max' => $pager_max)), + ); + + $items[] = array( + 'class' => 'pager-next', + 'data' => $li_next, + ); + return theme('item_list', $items, NULL, 'ul', array('class' => 'pager')); + } +} + +/** + * @defgroup views_templates Views' template files + * @{ + * All views templates can be overridden with a variety of names, using + * the view, the display ID of the view, the display type of the view, + * or some combination thereof. + * + * For each view, there will be a minimum of two templates used. The first + * is used for all views: views-view.tpl.php. + * + * The second template is determined by the style selected for the view. Note + * that certain aspects of the view can also change which style is used; for + * example, arguments which provide a summary view might change the style to + * one of the special summary styles. + * + * The default style for all views is views-view-unformatted.tpl.php + * + * Many styles will then farm out the actual display of each row to a row + * style; the default row style is views-view-fields.tpl.php. + * + * Here is an example of all the templates that will be tried in the following + * case: + * + * View, named foobar. Style: unformatted. Row style: Fields. Display: Page. + * + * - views-view--foobar--page.tpl.php + * - views-view--page.tpl.php + * - views-view--foobar.tpl.php + * - views-view.tpl.php + * + * - views-view-unformatted--foobar--page.tpl.php + * - views-view-unformatted--page.tpl.php + * - views-view-unformatted--foobar.tpl.php + * - views-view-unformatted.tpl.php + * + * - views-view-fields--foobar--page.tpl.php + * - views-view-fields--page.tpl.php + * - views-view-fields--foobar.tpl.php + * - views-view-fields.tpl.php + * + * Important! When adding a new template to your theme, be sure to flush the + * theme registry cache! + * + * @see _views_theme_functions + * @} + */ diff --git a/sites/all/modules/views/theme/views-exposed-form.tpl.php b/sites/all/modules/views/theme/views-exposed-form.tpl.php new file mode 100644 index 0000000..51f52a7 --- /dev/null +++ b/sites/all/modules/views/theme/views-exposed-form.tpl.php @@ -0,0 +1,47 @@ +label: The visible label to print. May be optional. + * - $widget->operator: The operator for the widget. May be optional. + * - $widget->widget: The widget itself. + * - $button: The submit button for the form. + * + * @ingroup views_templates + */ +?> + + + +
    +
    + $widget): ?> +
    + label)): ?> + + + operator)): ?> +
    + operator; ?> +
    + +
    + widget; ?> +
    +
    + +
    + +
    +
    +
    diff --git a/sites/all/modules/views/theme/views-more.tpl.php b/sites/all/modules/views/theme/views-more.tpl.php new file mode 100644 index 0000000..f002514 --- /dev/null +++ b/sites/all/modules/views/theme/views-more.tpl.php @@ -0,0 +1,16 @@ + + + diff --git a/sites/all/modules/views/theme/views-ui-edit-item.tpl.php b/sites/all/modules/views/theme/views-ui-edit-item.tpl.php new file mode 100644 index 0000000..a82aca9 --- /dev/null +++ b/sites/all/modules/views/theme/views-ui-edit-item.tpl.php @@ -0,0 +1,45 @@ + + + +
    + + +
    + +
    + +
    + +
    + + $field): ?> + + + +
    + + +
    + + +
    diff --git a/sites/all/modules/views/theme/views-ui-edit-tab.tpl.php b/sites/all/modules/views/theme/views-ui-edit-tab.tpl.php new file mode 100644 index 0000000..cac06bb --- /dev/null +++ b/sites/all/modules/views/theme/views-ui-edit-tab.tpl.php @@ -0,0 +1,98 @@ + +
    + + +
    + + +
    + +
    +
    + + + + + + + +
    +
    + + +
    +
    + + +
    +
    +
    +
    + +
    +
    +
    + + + $category): ?> +
    +
    + +
    +
    + +
    + +
    + +
    +
    + +
    +
    + + +
    +
    +
    + +
    +
    + +
    + +
    + +
    + +
    +
    + + +
    +
    +
    + +
    +
    + +
    +
    +
    + +
    \ No newline at end of file diff --git a/sites/all/modules/views/theme/views-ui-edit-view.tpl.php b/sites/all/modules/views/theme/views-ui-edit-view.tpl.php new file mode 100644 index 0000000..457b9c9 --- /dev/null +++ b/sites/all/modules/views/theme/views-ui-edit-view.tpl.php @@ -0,0 +1,45 @@ + +
    + +
    + break this lock.', array('!user' => $locked, '!age' => $lock_age, '!break' => $break)); ?> +
    + +
    "> + vid)): ?> +
    + +
    + + + @base.', + array('%name' => $view->name, '@base' => $base_table)); ?> +
    + + + +
    +
    + +
    +
    + + +
    +
    + + + +

    +
    + +
    +
    diff --git a/sites/all/modules/views/theme/views-ui-list-views.tpl.php b/sites/all/modules/views/theme/views-ui-list-views.tpl.php new file mode 100644 index 0000000..1377f21 --- /dev/null +++ b/sites/all/modules/views/theme/views-ui-list-views.tpl.php @@ -0,0 +1,41 @@ + +

    + + + + + + + + + + + + + +
    + + @type @base view: @view', array('@type' => $view->type, '@view' => $view->name, '@base' => $view->base)); ?> + tag)): ?> +  (tag; ?>) + + ops ?>
    + title): ?> + $view->title)); ?>
    + + path): ?> + $view->path)); ?>
    + + displays): ?> + displays; ?>
    + +
    + description; ?> +
    + diff --git a/sites/all/modules/views/theme/views-view-field.tpl.php b/sites/all/modules/views/theme/views-view-field.tpl.php new file mode 100644 index 0000000..6aebd27 --- /dev/null +++ b/sites/all/modules/views/theme/views-view-field.tpl.php @@ -0,0 +1,22 @@ +{$field->field_alias} + * + * The above will guarantee that you'll always get the correct data, + * regardless of any changes in the aliasing that might happen if + * the view is modified. + */ +?> + \ No newline at end of file diff --git a/sites/all/modules/views/theme/views-view-fields.tpl.php b/sites/all/modules/views/theme/views-view-fields.tpl.php new file mode 100644 index 0000000..7775c91 --- /dev/null +++ b/sites/all/modules/views/theme/views-view-fields.tpl.php @@ -0,0 +1,38 @@ +content: The output of the field. + * - $field->raw: The raw data for the field, if it exists. This is NOT output safe. + * - $field->class: The safe class id to use. + * - $field->handler: The Views field handler object controlling this field. Do not use + * var_export to dump this object, as it can't handle the recursion. + * - $field->inline: Whether or not the field should be inline. + * - $field->inline_html: either div or span based on the above flag. + * - $field->separator: an optional separator that may appear before a field. + * - $row: The raw result object from the query, with all data it fetched. + * + * @ingroup views_templates + */ +?> + $field): ?> + separator)): ?> + separator; ?> + + + <inline_html;?> class="views-field-class; ?>"> + label): ?> + + + element_type is either SPAN or DIV depending upon whether or not + // the field is a 'block' element type or 'inline' element type. + ?> + <element_type; ?> class="field-content">content; ?>element_type; ?>> + inline_html;?>> + diff --git a/sites/all/modules/views/theme/views-view-grid.tpl.php b/sites/all/modules/views/theme/views-view-grid.tpl.php new file mode 100644 index 0000000..9fe5e97 --- /dev/null +++ b/sites/all/modules/views/theme/views-view-grid.tpl.php @@ -0,0 +1,37 @@ + + +

    + +> + + $columns): ?> + + + $item): ?> + + + + + +
    + +
    diff --git a/sites/all/modules/views/theme/views-view-list.tpl.php b/sites/all/modules/views/theme/views-view-list.tpl.php new file mode 100644 index 0000000..7851ba5 --- /dev/null +++ b/sites/all/modules/views/theme/views-view-list.tpl.php @@ -0,0 +1,20 @@ + +
    + +

    + + <> + $row): ?> +
  • + + > +
    \ No newline at end of file diff --git a/sites/all/modules/views/theme/views-view-row-comment.tpl.php b/sites/all/modules/views/theme/views-view-row-comment.tpl.php new file mode 100644 index 0000000..b6fa85c --- /dev/null +++ b/sites/all/modules/views/theme/views-view-row-comment.tpl.php @@ -0,0 +1,17 @@ + + \ No newline at end of file diff --git a/sites/all/modules/views/theme/views-view-row-node.tpl.php b/sites/all/modules/views/theme/views-view-row-node.tpl.php new file mode 100644 index 0000000..cb6f1bf --- /dev/null +++ b/sites/all/modules/views/theme/views-view-row-node.tpl.php @@ -0,0 +1,20 @@ + + + + + \ No newline at end of file diff --git a/sites/all/modules/views/theme/views-view-row-rss.tpl.php b/sites/all/modules/views/theme/views-view-row-rss.tpl.php new file mode 100644 index 0000000..03c6acf --- /dev/null +++ b/sites/all/modules/views/theme/views-view-row-rss.tpl.php @@ -0,0 +1,14 @@ + + + <?php print $title; ?> + + + + diff --git a/sites/all/modules/views/theme/views-view-rss.tpl.php b/sites/all/modules/views/theme/views-view-rss.tpl.php new file mode 100644 index 0000000..54e4dc9 --- /dev/null +++ b/sites/all/modules/views/theme/views-view-rss.tpl.php @@ -0,0 +1,19 @@ + + version="1.0" encoding="utf-8" "; ?> +> + + <?php print $title; ?> + + + + + + + \ No newline at end of file diff --git a/sites/all/modules/views/theme/views-view-summary-unformatted.tpl.php b/sites/all/modules/views/theme/views-view-summary-unformatted.tpl.php new file mode 100644 index 0000000..1e7de02 --- /dev/null +++ b/sites/all/modules/views/theme/views-view-summary-unformatted.tpl.php @@ -0,0 +1,19 @@ + + $row): ?> + '; ?> + separator)) { print $row->separator; } ?> + >link; ?> + + (count; ?>) + + ' : '
    '; ?> + diff --git a/sites/all/modules/views/theme/views-view-summary.tpl.php b/sites/all/modules/views/theme/views-view-summary.tpl.php new file mode 100644 index 0000000..2d910dc --- /dev/null +++ b/sites/all/modules/views/theme/views-view-summary.tpl.php @@ -0,0 +1,19 @@ + +
    +
      + $row): ?> +
    • >link; ?> + + (count?>) + +
    • + +
    +
    diff --git a/sites/all/modules/views/theme/views-view-table.tpl.php b/sites/all/modules/views/theme/views-view-table.tpl.php new file mode 100644 index 0000000..f1ce270 --- /dev/null +++ b/sites/all/modules/views/theme/views-view-table.tpl.php @@ -0,0 +1,41 @@ + +> + + + + + + $label): ?> + + + + + + $row): ?> + + $content): ?> + + + + + +
    + +
    + +
    diff --git a/sites/all/modules/views/theme/views-view-unformatted.tpl.php b/sites/all/modules/views/theme/views-view-unformatted.tpl.php new file mode 100644 index 0000000..e927e49 --- /dev/null +++ b/sites/all/modules/views/theme/views-view-unformatted.tpl.php @@ -0,0 +1,16 @@ + + +

    + + $row): ?> +
    + +
    + diff --git a/sites/all/modules/views/theme/views-view.tpl.php b/sites/all/modules/views/theme/views-view.tpl.php new file mode 100644 index 0000000..be1840a --- /dev/null +++ b/sites/all/modules/views/theme/views-view.tpl.php @@ -0,0 +1,91 @@ + +
    + + + + +
    + +
    + + + +
    + +
    + + + +
    + +
    + + + +
    + +
    + +
    + +
    + + + + + + + +
    + +
    + + + + + + + + + + + +
    + +
    + + +
    diff --git a/sites/all/modules/views/views.drush.inc b/sites/all/modules/views/views.drush.inc new file mode 100644 index 0000000..4a4c7a3 --- /dev/null +++ b/sites/all/modules/views/views.drush.inc @@ -0,0 +1,13 @@ +, for the highest available . + if ($schema = array_pop($schemas)) { + $function = 'views_schema_'. $schema; + return $function(); + } + + return array(); +} + +/** + * Views 2's initial schema. + * Called directly by views_update_6000() for updates from Drupal 5. + * + * Important: Do not edit this schema! + * + * Updates to the views schema must be provided as views_schema_6xxx() functions, + * which views_schema() automatically sees and applies. See below for examples. + * + * Please do document updates with comments in this function, however. + */ +function views_schema_6000() { + $schema['views_view'] = array( + 'description' => 'Stores the general data for a view.', + 'fields' => array( + 'vid' => array( + 'type' => 'serial', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'description' => 'The view ID of the field, defined by the database.', + 'no export' => TRUE, + ), + 'name' => array( + 'type' => 'varchar', + 'length' => '32', + 'default' => '', + 'not null' => TRUE, + 'description' => 'The unique name of the view. This is the primary field views are loaded from, and is used so that views may be internal and not necessarily in the database. May only be alphanumeric characters plus underscores.', + ), + 'description' => array( + 'type' => 'varchar', + 'length' => '255', + 'default' => '', + 'description' => 'A description of the view for the admin interface.', + ), + 'tag' => array( + 'type' => 'varchar', + 'length' => '255', + 'default' => '', + 'description' => 'A tag used to group/sort views in the admin interface', + ), + 'view_php' => array( + 'type' => 'blob', + 'description' => 'A chunk of PHP code that can be used to provide modifications to the view prior to building.', + ), + 'base_table' => array( + 'type' => 'varchar', + 'length' => '32', // Updated to '64' in views_schema_6005() + 'default' => '', + 'not null' => TRUE, + 'description' => 'What table this view is based on, such as node, user, comment, or term.', + ), + 'is_cacheable' => array( + 'type' => 'int', + 'default' => 0, + 'size' => 'tiny', + 'description' => 'A boolean to indicate whether or not this view may have its query cached.', + ), + ), + 'primary key' => array('vid'), + 'unique key' => array('name' => array('name')), // Updated to 'unique keys' in views_schema_6003() + ); + + $schema['views_display'] = array( + 'description' => 'Stores information about each display attached to a view.', + 'fields' => array( + 'vid' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => 'The view this display is attached to.', + 'no export' => TRUE, + ), + 'id' => array( + 'type' => 'varchar', + 'length' => '64', + 'default' => '', + 'not null' => TRUE, + 'description' => 'An identifier for this display; usually generated from the display_plugin, so should be something like page or page_1 or block_2, etc.', + ), + 'display_title' => array( + 'type' => 'varchar', + 'length' => '64', + 'default' => '', + 'not null' => TRUE, + 'description' => 'The title of the display, viewable by the administrator.', + ), + 'display_plugin' => array( + 'type' => 'varchar', + 'length' => '64', + 'default' => '', + 'not null' => TRUE, + 'description' => 'The type of the display. Usually page, block or embed, but is pluggable so may be other things.', + ), + 'position' => array( + 'type' => 'int', + 'default' => 0, + 'description' => 'The order in which this display is loaded.', + ), + 'display_options' => array( + // Type corrected in update 6009 + 'type' => 'blob', + 'description' => 'A serialized array of options for this display; it contains options that are generally only pertinent to that display plugin type.', + 'serialize' => TRUE, + 'serialized default' => 'a:0:{}', + ), + ), + 'indexes' => array('vid' => array('vid', 'position')), + ); + + $schema['cache_views'] = drupal_get_schema_unprocessed('system', 'cache'); + + $schema['views_object_cache'] = array( + 'description' => 'A special cache used to store objects that are being edited; it serves to save state in an ordinarily stateless environment.', + 'fields' => array( + 'sid' => array( + 'type' => 'varchar', + 'length' => '64', + 'description' => 'The session ID this cache object belongs to.', + ), + 'name' => array( + 'type' => 'varchar', + 'length' => '32', + 'description' => 'The name of the view this cache is attached to.', + ), + 'obj' => array( + 'type' => 'varchar', + 'length' => '32', + 'description' => 'The name of the object this cache is attached to; this essentially represents the owner so that several sub-systems can use this cache.', + ), + 'updated' => array( + 'type' => 'int', + 'unsigned' => TRUE, + 'not null' => TRUE, + 'default' => 0, + 'description' => 'The time this cache was created or updated.', + ), + 'data' => array( + 'type' => 'blob', // Updated to 'text' (with size => 'big') in views_schema_6004() + 'description' => 'Serialized data being stored.', + 'serialize' => TRUE, + ), + ), + 'indexes' => array( + 'sid_obj_name' => array('sid', 'obj', 'name'), + 'updated' => array('updated'), + ), + ); + + // $schema['cache_views_data'] added in views_schema_6006() + + return $schema; +} + +/** + * Update a site to Drupal 6! Contains a bit of special code to detect + * if you've been running a beta version or something. + */ +function views_update_6000() { + $ret = array(); + if (db_table_exists('views_view')) { + return $ret; + } + + // This has the beneficial effect of wiping out any Views 1 cache at the + // same time; not wiping that cache could easily cause problems with Views 2. + if (db_table_exists('cache_views')) { + db_drop_table($ret, 'cache_views'); + } + + // This is mostly the same as drupal_install_schema, but it forces + // views_schema_6000() rather than the default views_schema(). + // This is important for processing subsequent table updates. + $schema = views_schema_6000(); + _drupal_initialize_schema('views', $schema); + + foreach ($schema as $name => $table) { + db_create_table($ret, $name, $table); + } + return $ret; +} + +/** + * Remove '$' symbol in special blocks, as it is invalid for theming. + */ +function views_update_6001() { + $ret = array(); + $result = db_query("SELECT * FROM {blocks} WHERE module = 'views' AND delta LIKE '\$exp%'"); + while ($block = db_fetch_object($result)) { + $new = strtr($block->delta, '$', '-'); + $ret[] = update_sql("UPDATE {blocks} SET delta = '" . db_escape_string($new) . "' WHERE module = 'views' AND delta = '" . db_escape_string($block->delta) . "'"); + } + $result = db_query("SELECT * FROM {blocks} WHERE module = 'views'"); + while ($block = db_fetch_object($result)) { + $new = $block->delta .= '-block_1'; + if (strlen($new) >= 32) { + $new = md5($new); + } + $ret[] = update_sql("UPDATE {blocks} SET delta = '$new' WHERE bid = $block->bid"); + } + + return $ret; +} + +// NOTE: Update 6002 removed because it did not always work. +// Update 6004 implements the change correctly. + +/** + * Add missing unique key. + */ +function views_schema_6003() { + $schema = views_schema(__FUNCTION__); + $schema['views_view']['unique keys'] = array('name' => array('name')); + unset($schema['views_view']['unique key']); + return $schema; +} +function views_update_6003() { + $ret = array(); + db_add_unique_key($ret, 'views_view', 'name', array('name')); + return $ret; +} + +/** + * Enlarge the views_object_cache.data column to prevent truncation and JS + * errors. + */ +function views_schema_6004() { + $schema = views_schema(__FUNCTION__); + $schema['views_object_cache']['fields']['data']['type'] = 'text'; + $schema['views_object_cache']['fields']['data']['size'] = 'big'; + return $schema; +} +function views_update_6004() { + $ret = array(); + + $new_field = array( + 'type' => 'text', + 'size' => 'big', + 'description' => 'Serialized data being stored.', + 'serialize' => TRUE, + ); + + // Drop and re-add this field because there is a bug in + // db_change_field that causes this to fail when trying to cast the data. + db_drop_field($ret, 'views_object_cache', 'data'); + db_add_field($ret, 'views_object_cache', 'data', $new_field); + + return $ret; +} + +/** + * Enlarge the base_table column + */ +function views_schema_6005() { + $schema = views_schema(__FUNCTION__); + $schema['views_view']['fields']['base_table']['length'] = 64; + return $schema; +} +function views_update_6005() { + $ret = array(); + + $new_field = array( + 'type' => 'varchar', + 'length' => '64', + 'default' => '', + 'not null' => TRUE, + 'description' => 'What table this view is based on, such as node, user, comment, or term.', + ); + db_change_field($ret, 'views_view', 'base_table', 'base_table', $new_field); + return $ret; +} + +/** + * Add the cache_views_data table to support standard caching. + */ +function views_schema_6006() { + $schema = views_schema(__FUNCTION__); + $schema['cache_views_data'] = drupal_get_schema_unprocessed('system', 'cache'); + $schema['cache_views_data']['description'] = 'Cache table for views to store pre-rendered queries, results, and display output.'; + $schema['cache_views_data']['fields']['serialized']['default'] = 1; + return $schema; +} +function views_update_6006() { + $ret = array(); + + $table = drupal_get_schema_unprocessed('system', 'cache'); + $table['description'] = 'Cache table for views to store pre-rendered queries, results, and display output.'; + $table['fields']['serialized']['default'] = 1; + + db_create_table($ret, 'cache_views_data', $table); + + return $ret; +} + +/** + * Add aggregate function to PostgreSQL so GROUP BY can be used to force only + * one result to be returned for each item. + */ +function views_update_6007() { + $ret = array(); + if ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql('CREATE OR REPLACE FUNCTION first(anyelement, anyelement) RETURNS anyelement AS \'SELECT COALESCE($1, $2);\' LANGUAGE \'sql\';'); + $ret[] = update_sql("DROP AGGREGATE IF EXISTS first(anyelement)"); + $ret[] = update_sql("CREATE AGGREGATE first(sfunc = first, basetype = anyelement, stype = anyelement);"); + } + return $ret; +} + +/** + * Add the primary key to views_display table. + */ +function views_schema_6008() { + $schema = views_schema(__FUNCTION__); + $schema['views_display']['primary key'] = array('vid', 'id'); + return $schema; +} + +/** + * Add the primary key to the views_display table. + */ +function views_update_6008() { + $ret = array(); + + db_add_primary_key($ret, 'views_display', array('vid', 'id')); + + return $ret; +} + +/** + * Enlarge the views_display.display_options field to accomodate a larger set + * of configurations (e. g. fields, filters, etc.) on a display. + */ +function views_schema_6009() { + $schema = views_schema(__FUNCTION__); + $schema['views_display']['fields']['display_options'] = array( + 'type' => 'text', + 'size' => 'big', + 'description' => 'A serialized array of options for this display; it contains options that are generally only pertinent to that display plugin type.', + 'serialize' => TRUE, + 'serialized default' => 'a:0:{}', + ); + return $schema; +} + +function views_update_6009() { + $ret = array(); + + $schema = views_schema_6009(); + + if ($GLOBALS['db_type'] == 'pgsql') { + $ret[] = update_sql('ALTER TABLE {views_display} RENAME "display_options" TO "display_options_old"'); + db_add_field($ret, 'views_display', 'display_options', $schema['views_display']['fields']['display_options']); + + $sql = "SELECT vid, id, display_options_old FROM {views_display}"; + $result = db_query($sql); + while ($row = db_fetch_array($result)) { + $row['display_options_old'] = db_decode_blob($row['display_options_old']); + $sql = "UPDATE {views_display} SET display_options = '%s' WHERE vid = %d AND id = '%s'"; + db_query($sql, $row['display_options_old'], $row['vid'], $row['id']); + } + + db_drop_field($ret, 'views_display', 'display_options_old'); + } + else { + db_change_field($ret, 'views_display', 'display_options', 'display_options', $schema['views_display']['fields']['display_options']); + } + + return $ret; +} + +/** + * Remove the view_php field + */ +function views_schema_6010() { + $schema = views_schema(__FUNCTION__); + unset($schema['views_view']['fields']['view_php']); + unset($schema['views_view']['fields']['is_cacheable']); + return $schema; +} + +/** + * Remove the view_php and is_cacheable field + */ +function views_update_6010() { + $ret = array(); + + db_drop_field($ret, 'views_view', 'view_php'); + db_drop_field($ret, 'views_view', 'is_cacheable'); + + + return $ret; +} + +/** + * Correct the cache setting for exposed filter blocks. + * + * @see http://drupal.org/node/910864 + */ +function views_update_6011() { + $ret = array(); + + // There is only one simple query to run. + $ret[] = update_sql("UPDATE {blocks} SET cache = " . BLOCK_NO_CACHE . " WHERE module = 'views' AND delta LIKE '-exp-%'"); + + return $ret; +} + +function views_schema_6013() { + $schema = views_schema(__FUNCTION__); + $schema['views_view']['fields']['core'] = array( + 'type' => 'int', + 'default' => 0, + 'description' => 'Stores the drupal core version of the view.', + ); + return $schema; +} + +/** + * Add a drupal core version field. + */ +function views_update_6013() { + $ret = array(); + $new_field = array( + 'type' => 'int', + 'default' => 0, + 'description' => 'Stores the drupal core version of the view.', + ); + + db_add_field($ret, 'views_view', 'core', $new_field); + + return $ret; +} + diff --git a/sites/all/modules/views/views.module b/sites/all/modules/views/views.module new file mode 100644 index 0000000..4a587f4 --- /dev/null +++ b/sites/all/modules/views/views.module @@ -0,0 +1,1374 @@ + 'theme.inc', + 'path' => "$path/theme", + ); + + // Our extra version of pager from pager.inc + $hooks['views_mini_pager'] = $base + array( + 'arguments' => array('tags' => array(), 'limit' => 10, 'element' => 0, 'parameters' => array()), + 'pattern' => 'views_mini_pager__', + ); + + $arguments = array( + 'display' => array('view' => NULL), + 'style' => array('view' => NULL, 'options' => NULL, 'rows' => NULL, 'title' => NULL), + 'row' => array('view' => NULL, 'options' => NULL, 'row' => NULL, 'field_alias' => NULL), + ); + + // Default view themes + $hooks['views_view_field'] = $base + array( + 'pattern' => 'views_view_field__', + 'arguments' => array('view' => NULL, 'field' => NULL, 'row' => NULL), + ); + + $plugins = views_fetch_plugin_data(); + + // Register theme functions for all style plugins + foreach ($plugins as $type => $info) { + foreach ($info as $plugin => $def) { + if (isset($def['theme'])) { + $hooks[$def['theme']] = array( + 'pattern' => $def['theme'] . '__', + 'file' => $def['theme file'], + 'path' => $def['theme path'], + 'arguments' => $arguments[$type], + ); + + $include = './' . $def['theme path'] . '/' . $def['theme file']; + if (file_exists($include)) { + require_once $include; + } + + if (!function_exists('theme_' . $def['theme'])) { + $hooks[$def['theme']]['template'] = views_css_safe($def['theme']); + } + } + if (isset($def['additional themes'])) { + foreach ($def['additional themes'] as $theme => $theme_type) { + if (empty($theme_type)) { + $theme = $theme_type; + $theme_type = $type; + } + + $hooks[$theme] = array( + 'pattern' => $theme . '__', + 'file' => $def['theme file'], + 'path' => $def['theme path'], + 'arguments' => $arguments[$theme_type], + ); + + if (!function_exists('theme_' . $theme)) { + $hooks[$theme]['template'] = views_css_safe($theme); + } + } + } + } + } + + $hooks['views_exposed_form'] = $base + array( + 'template' => 'views-exposed-form', + 'pattern' => 'views_exposed_form__', + 'arguments' => array('form' => NULL), + ); + + $hooks['views_more'] = $base + array( + 'template' => 'views-more', + 'pattern' => 'views_more__', + 'arguments' => array('more_url' => NULL, 'link_text' => 'more'), + ); + return $hooks; +} + +/** + * A theme preprocess function to automatically allow view-based node + * templates if called from a view. + * + * The 'modules/node.views.inc' file is a better place for this, but + * we haven't got a chance to load that file before Drupal builds the + * node portion of the theme registry. + */ +function views_preprocess_node(&$vars) { + // The 'view' attribute of the node is added in template_preprocess_views_view_row_node() + if (!empty($vars['node']->view) && !empty($vars['node']->view->name)) { + $vars['view'] = &$vars['node']->view; + $vars['template_files'][] = 'node-view-' . $vars['node']->view->name; + if(!empty($vars['node']->view->current_display)) { + $vars['template_files'][] = 'node-view-' . $vars['node']->view->name . '-' . $vars['node']->view->current_display; + } + } +} + +/** + * A theme preprocess function to automatically allow view-based node + * templates if called from a view. + */ +function views_preprocess_comment(&$vars) { + // The 'view' attribute of the node is added in template_preprocess_views_view_row_comment() + if (!empty($vars['node']->view) && !empty($vars['node']->view->name)) { + $vars['view'] = &$vars['node']->view; + $vars['template_files'][] = 'comment-view-' . $vars['node']->view->name; + if(!empty($vars['node']->view->current_display)) { + $vars['template_files'][] = 'comment-view-' . $vars['node']->view->name . '-' . $vars['node']->view->current_display; + } + } +} + +/* + * Implementation of hook_perm() + */ +function views_perm() { + return array('access all views', 'administer views'); +} + +/** + * Implementation of hook_menu(). + */ +function views_menu() { + // Any event which causes a menu_rebuild could potentially mean that the + // Views data is updated -- module changes, profile changes, etc. + views_invalidate_cache(); + $items = array(); + $items['views/ajax'] = array( + 'title' => 'Views', + 'page callback' => 'views_ajax', + 'access callback' => TRUE, + 'description' => 'Ajax callback for view loading.', + 'file' => 'includes/ajax.inc', + 'type' => MENU_CALLBACK, + ); + // Path is not admin/build/views due to menu complications with the wildcards from + // the generic ajax callback. + $items['admin/views/ajax/autocomplete/user'] = array( + 'page callback' => 'views_ajax_autocomplete_user', + 'access callback' => 'user_access', + 'access arguments' => array('access content'), + 'file' => 'includes/ajax.inc', + 'type' => MENU_CALLBACK, + ); + return $items; +} + +/** + * Implementation of hook_menu_alter(). + */ +function views_menu_alter(&$callbacks) { + $our_paths = array(); + $views = views_get_applicable_views('uses hook menu'); + foreach ($views as $data) { + list($view, $display_id) = $data; + $result = $view->execute_hook_menu($display_id, $callbacks); + if (is_array($result)) { + // The menu system doesn't support having two otherwise + // identical paths with different placeholders. So we + // want to remove the existing items from the menu whose + // paths would conflict with ours. + + // First, we must find any existing menu items that may + // conflict. We use a regular expression because we don't + // know what placeholders they might use. Note that we + // first construct the regex itself by replacing %views_arg + // in the display path, then we use this constructed regex + // (which will be something like '#^(foo/%[^/]*/bar)$#') to + // search through the existing paths. + $regex = '#^(' . preg_replace('#%views_arg#', '%[^/]*', implode('|', array_keys($result))) . ')$#'; + $matches = preg_grep($regex, array_keys($callbacks)); + + // Remove any conflicting items that were found. + foreach ($matches as $path) { + // Don't remove the paths we just added! + if (!isset($our_paths[$path])) { + unset($callbacks[$path]); + } + } + foreach ($result as $path => $item) { + if (!isset($callbacks[$path])) { + // Add a new item, possibly replacing (and thus effectively + // overriding) one that we removed above. + $callbacks[$path] = $item; + } + else { + // This item already exists, so it must be one that we added. + // We change the various callback arguments to pass an array + // of possible display IDs instead of a single ID. + $callbacks[$path]['page arguments'][1] = (array)$callbacks[$path]['page arguments'][1]; + $callbacks[$path]['page arguments'][1][] = $display_id; + $callbacks[$path]['access arguments'][] = $item['access arguments'][0]; + $callbacks[$path]['load arguments'][1] = (array)$callbacks[$path]['load arguments'][1]; + $callbacks[$path]['load arguments'][1][] = $display_id; + } + $our_paths[$path] = TRUE; + } + } + } + + // Save memory: Destroy those views. + foreach ($views as $data) { + list($view, $display_id) = $data; + $view->destroy(); + } +} + +/** + * Helper function for menu loading. This will automatically be + * called in order to 'load' a views argument; primarily it + * will be used to perform validation. + * + * @param $value + * The actual value passed. + * @param $name + * The name of the view. This needs to be specified in the 'load function' + * of the menu entry. + * @param $display_id + * The display id that will be loaded for this menu item. + * @param $index + * The menu argument index. This counts from 1. + */ +function views_arg_load($value, $name, $display_id, $index) { + static $views = array(); + + // Make sure we haven't already loaded this views argument for a similar menu + // item elsewhere. + $key = $name . ':' . $display_id . ':' . $value . ':' . $index; + if (isset($views[$key])) { + return $views[$key]; + } + + if ($view = views_get_view($name)) { + $view->set_display($display_id); + $view->init_handlers(); + + $ids = array_keys($view->argument); + + $indexes = array(); + $path = explode('/', $view->get_path()); + + foreach ($path as $id => $piece) { + if ($piece == '%' && !empty($ids)) { + $indexes[$id] = array_shift($ids); + } + } + + if (isset($indexes[$index])) { + if (isset($view->argument[$indexes[$index]])) { + $arg = $view->argument[$indexes[$index]]->validate_argument($value) ? $value : FALSE; + $view->destroy(); + + // Store the output in case we load this same menu item again. + $views[$key] = $arg; + return $arg; + } + } + $view->destroy(); + } +} + +/** + * Page callback entry point; requires a view and a display id, then + * passes control to the display handler. + */ +function views_page() { + $args = func_get_args(); + $name = array_shift($args); + $display_id = array_shift($args); + + // Load the view + if ($view = views_get_view($name)) { + return $view->execute_display($display_id, $args); + } + + // Fallback; if we get here no view was found or handler was not valid. + return drupal_not_found(); +} + +/** + * Implementation of hook_block + */ +function views_block($op = 'list', $delta = 0, $edit = array()) { + switch ($op) { + case 'list': + // Try to avoid instantiating all the views just to get the blocks info. + views_include('cache'); + $cache = views_cache_get('views_block_items', TRUE); + if ($cache && is_array($cache->data)) { + return $cache->data; + } + + $items = array(); + $views = views_get_all_views(); + foreach ($views as $view) { + // disabled views get nothing. + if (!empty($view->disabled)) { + continue; + } + + $view->init_display(); + foreach ($view->display as $display_id => $display) { + + if (isset($display->handler) && !empty($display->handler->definition['uses hook block'])) { + $result = $display->handler->execute_hook_block(); + if (is_array($result)) { + $items = array_merge($items, $result); + } + } + + if (isset($display->handler) && $display->handler->get_option('exposed_block')) { + $result = $display->handler->get_special_blocks(); + if (is_array($result)) { + $items = array_merge($items, $result); + } + } + } + } + + // block.module has a delta length limit of 32, but our deltas can + // unfortunately be longer because view names can be 32 and display IDs + // can also be 32. So for very long deltas, change to md5 hashes. + $hashes = array(); + + // get the keys because we're modifying the array and we don't want to + // confuse PHP too much. + $keys = array_keys($items); + foreach ($keys as $delta) { + if (strlen($delta) >= 32) { + $hash = md5($delta); + $hashes[$hash] = $delta; + $items[$hash] = $items[$delta]; + unset($items[$delta]); + } + } + + // Only save hashes if they have changed. + $old_hashes = variable_get('views_block_hashes', array()); + if ($hashes != $old_hashes) { + variable_set('views_block_hashes', $hashes); + } + // Save memory: Destroy those views. + foreach ($views as $view) { + $view->destroy(); + } + + views_cache_set('views_block_items', $items, TRUE); + + return $items; + case 'view': + $start = views_microtime(); + // if this is 32, this should be an md5 hash. + if (strlen($delta) == 32) { + $hashes = variable_get('views_block_hashes', array()); + if (!empty($hashes[$delta])) { + $delta = $hashes[$delta]; + } + } + + // This indicates it's a special one. + if (substr($delta, 0, 1) == '-') { + list($nothing, $type, $name, $display_id) = explode('-', $delta); + // Put the - back on. + $type = '-' . $type; + if ($view = views_get_view($name)) { + if ($view->access($display_id)) { + $view->set_display($display_id); + if (isset($view->display_handler)) { + $output = $view->display_handler->view_special_blocks($type); + $view->destroy(); + return $output; + } + } + $view->destroy(); + } + } + + list($name, $display_id) = explode('-', $delta); + // Load the view + if ($view = views_get_view($name)) { + if ($view->access($display_id)) { + $output = $view->execute_display($display_id); + vpr("Block $view->name execute time: " . (views_microtime() - $start) * 1000 . "ms"); + $view->destroy(); + return $output; + } + $view->destroy(); + } + break; + } +} + +/** + * Implementation of hook_flush_caches(). + */ +function views_flush_caches() { + return array('cache_views', 'cache_views_data'); +} + +/** + * Invalidate the views cache, forcing a rebuild on the next grab of table data. + */ +function views_invalidate_cache() { + cache_clear_all('*', 'cache_views', true); +} + +/** + * Access callback to determine if the user can import Views. + * + * View imports require an additional access check because they are PHP + * code and PHP is more locked down than administer views. + */ +function views_import_access() { + return user_access('administer views') && user_access('use PHP for block visibility'); +} + +/** + * Determine if the logged in user has access to a view. + * + * This function should only be called from a menu hook or some other + * embedded source. Each argument is the result of a call to + * views_plugin_access::get_access_callback() which is then used + * to determine if that display is accessible. If *any* argument + * is accessible, then the view is accessible. + */ +function views_access() { + $args = func_get_args(); + foreach ($args as $arg) { + if ($arg === TRUE) { + return TRUE; + } + + if (!is_array($arg)) { + continue; + } + + list($callback, $arguments) = $arg; + $arguments = $arguments ? $arguments : array(); + if (function_exists($callback) && call_user_func_array($callback, $arguments)) { + return TRUE; + } + } + + return FALSE; +} + +/** + * Access callback for the views_plugin_access_perm access plugin. + * + * Determine if the specified user has access to a view on the basis of + * permissions. If the $account argument is omitted, the current user + * is used. + */ +function views_check_perm($perm, $account = NULL) { + return user_access($perm, $account) || user_access('access all views', $account); +} + +/** + * Access callback for the views_plugin_access_role access plugin. + + * Determine if the specified user has access to a view on the basis of any of + * the requested roles. If the $account argument is omitted, the current user + * is used. + */ +function views_check_roles($rids, $account = NULL) { + global $user; + $account = isset($account) ? $account : $user; + $roles = array_keys($account->roles); + $roles[] = $account->uid ? DRUPAL_AUTHENTICATED_RID : DRUPAL_ANONYMOUS_RID; + return user_access('access all views', $account) || array_intersect(array_filter($rids), $roles); +} +// ------------------------------------------------------------------ +// Functions to help identify views that are running or ran + +/** + * Set the current 'page view' that is being displayed so that it is easy + * for other modules or the theme to identify. + */ +function &views_set_page_view($view = NULL) { + static $cache = NULL; + if (isset($view)) { + $cache = $view; + } + + return $cache; +} + +/** + * Find out what, if any, page view is currently in use. Please note that + * this returns a reference, so be careful! You can unintentionally modify the + * $view object. + */ +function &views_get_page_view() { + return views_set_page_view(); +} + +/** + * Set the current 'current view' that is being built/rendered so that it is + * easy for other modules or items in drupal_eval to identify + */ +function &views_set_current_view($view = NULL) { + static $cache = NULL; + if (isset($view)) { + $cache = $view; + } + + return $cache; +} + +/** + * Find out what, if any, current view is currently in use. Please note that + * this returns a reference, so be careful! You can unintentionally modify the + * $view object. + */ +function &views_get_current_view() { + return views_set_current_view(); +} + +// ------------------------------------------------------------------ +// Include file helpers + +/** + * Include views .inc files as necessary. + */ +function views_include($file) { + static $used = array(); + if (!isset($used[$file])) { + require_once './' . drupal_get_path('module', 'views') . "/includes/$file.inc"; + } + + $used[$file] = TRUE; +} + +/** + * Load views files on behalf of modules. + */ +function views_module_include($file) { + foreach (views_get_module_apis() as $module => $info) { + if (file_exists("./$info[path]/$module.$file")) { + require_once "./$info[path]/$module.$file"; + } + } +} + +/** + * Get a list of modules that support the current views API. + */ +function views_get_module_apis() { + static $cache = NULL; + if (!isset($cache)) { + $cache = array(); + foreach (module_implements('views_api') as $module) { + $function = $module . '_views_api'; + $info = $function(); + if (isset($info['api']) && $info['api'] == 2.000) { + if (!isset($info['path'])) { + $info['path'] = drupal_get_path('module', $module); + } + $cache[$module] = $info; + } + } + } + + return $cache; +} + +/** + * Include views .css files. + */ +function views_add_css($file) { + // We set preprocess to FALSE because we are adding the files conditionally, + // and we don't want to generate duplicate cache files. + // TODO: at some point investigate adding some files unconditionally and + // allowing preprocess. + drupal_add_css(drupal_get_path('module', 'views') . "/css/$file.css", 'module', 'all', FALSE); +} + +/** + * Include views .js files. + */ +function views_add_js($file) { + // If javascript has been disabled by the user, never add js files. + if (variable_get('views_no_javascript', FALSE)) { + return; + } + + static $base = TRUE; + if ($base) { + drupal_add_js(drupal_get_path('module', 'views') . "/js/base.js"); + $base = FALSE; + } + drupal_add_js(drupal_get_path('module', 'views') . "/js/$file.js"); +} + +/** + * Load views files on behalf of modules. + */ +function views_include_handlers() { + static $finished = FALSE; + // Ensure this only gets run once. + if ($finished) { + return; + } + + views_include('base'); + views_include('handlers'); + views_include('cache'); + views_include('plugins'); + _views_include_handlers(); + $finished = TRUE; +} + +/** + * Load default views files on behalf of modules. + */ +function views_include_default_views() { + static $finished = FALSE; + // Ensure this only gets run once. + if ($finished) { + return; + } + + // Default views hooks may be in the normal handler file, + // or in a separate views_default file at the discretion of + // the module author. + views_include_handlers(); + + _views_include_default_views(); + $finished = TRUE; +} + +// ----------------------------------------------------------------------- +// Views handler functions + +/** + * Fetch a handler from the data cache. + * + * @param $table + * The name of the table this handler is from. + * @param $field + * The name of the field this handler is from. + * @param $key + * The type of handler. i.e, sort, field, argument, filter, relationship + * + * @return views_handler + * An instance of a handler object. May be views_handler_broken. + */ +function views_get_handler($table, $field, $key) { + $data = views_fetch_data($table); + if (isset($data[$field][$key])) { + // Set up a default handler: + if (empty($data[$field][$key]['handler'])) { + $data[$field][$key]['handler'] = 'views_handler_' . $key; + } + return _views_prepare_handler($data[$field][$key], $data, $field); + } + // DEBUG -- identify missing handlers + vpr("Missing handler: $table $field $key"); + $broken = array( + 'title' => t('Broken handler @table.@field', array('@table' => $table, '@field' => $field)), + 'handler' => 'views_handler_' . $key . '_broken', + 'table' => $table, + 'field' => $field, + ); + return _views_create_handler($broken); +} + +/** + * Fetch Views' data from the cache + */ +function views_fetch_data($table = NULL) { + views_include('cache'); + return _views_fetch_data($table); +} + +// ----------------------------------------------------------------------- +// Views plugin functions + +/** + * Fetch the plugin data from cache. + */ +function views_fetch_plugin_data($type = NULL, $plugin = NULL) { + views_include('cache'); + return _views_fetch_plugin_data($type, $plugin); +} + +/** + * Get a handler for a plugin + * + * @return views_plugin + * + * The created plugin object. + */ +function views_get_plugin($type, $plugin) { + $definition = views_fetch_plugin_data($type, $plugin); + if (!empty($definition)) { + return _views_create_handler($definition, $type); + } +} + +// ----------------------------------------------------------------------- +// Views database functions + +/** + * Get a view from the default views defined by modules. + * + * Default views are cached per-language. This function will rescan the + * default_views hook if necessary. + * + * @param $view_name + * The name of the view to load. + * @return + * A view object or NULL if it is not available. + */ +function &views_get_default_view($view_name) { + $null = NULL; + + // Attempt to load individually cached view from cache. + views_include('cache'); + $data = views_cache_get("views_default:{$view_name}", TRUE); + if (isset($data->data) && is_object($data->data)) { + return $data->data; + } + + // Otherwise, allow entire cache to be rebuilt. + $cache = views_discover_default_views(); + if (isset($cache[$view_name])) { + return $cache[$view_name]; + } + return $null; +} + +/** + * Create an empty view to work with. + * + * @return view + * A fully formed, empty $view object. This object must be populated before + * it can be successfully saved. + */ +function views_new_view() { + views_include('view'); + $view = new view(); + $view->vid = 'new'; + $view->add_display('default'); + + return $view; +} + +/** + * Scan all modules for default views and rebuild the default views cache. + * + * @return An associative array of all known default views. + */ +function views_discover_default_views() { + static $cache = array(); + + if (empty($cache)) { + views_include('cache'); + $cache = _views_discover_default_views(); + } + return $cache; +} + +/** + * Return a list of all views and display IDs that have a particular + * setting in their display's plugin settings. + * + * @return + * @code + * array( + * array($view, $display_id), + * array($view, $display_id), + * ); + * @endcode + */ +function views_get_applicable_views($type) { + // @todo: Use a smarter flagging system so that we don't have to + // load every view for this. + $result = array(); + $views = views_get_all_views(); + + foreach ($views as $view) { + // Skip disabled views. + if (!empty($view->disabled)) { + continue; + } + + if (empty($view->display)) { + // Skip this view as it is broken. + vsm(t("Skipping broken view @view", array('@view' => $view->name))); + continue; + } + + // Loop on array keys because something seems to muck with $view->display + // a bit in PHP4. + foreach (array_keys($view->display) as $id) { + $plugin = views_fetch_plugin_data('display', $view->display[$id]->display_plugin); + if (!empty($plugin[$type])) { + // This view uses hook menu. Clone it so that different handlers + // don't trip over each other, and add it to the list. + $v = $view->clone_view(); + if ($v->set_display($id)) { + $result[] = array($v, $id); + } + // In PHP 4.4.7 and presumably earlier, if we do not unset $v + // here, we will find that it actually overwrites references + // possibly due to shallow copying issues. + unset($v); + } + } + } + return $result; +} + +/** + * Return an array of all views as fully loaded $view objects. + * + * @param $reset + * If TRUE, reset the static cache forcing views to be reloaded. + */ +function views_get_all_views($reset = FALSE) { + static $views = array(); + + if (empty($views) || $reset) { + $views = array(); + + // First, get all applicable views. + views_include('view'); + $views = view::load_views(); + + // Get all default views. + $status = variable_get('views_defaults', array()); + + foreach (views_discover_default_views() as $view) { + // Determine if default view is enabled or disabled. + if (isset($status[$view->name])) { + $view->disabled = $status[$view->name]; + } + + // If overridden, also say so. + if (!empty($views[$view->name])) { + $views[$view->name]->type = t('Overridden'); + } + else { + $view->type = t('Default'); + $views[$view->name] = $view; + } + } + + } + return $views; +} + +/** + * Get a view from the database or from default views. + * + * This function is just a static wrapper around views::load(). This function + * isn't called 'views_load()' primarily because it might get a view + * from the default views which aren't technically loaded from the database. + * + * @param $name + * The name of the view. + * @param $reset + * If TRUE, reset this entry in the load cache. + * @return view + * A reference to the $view object. Use $reset if you're sure you want + * a fresh one. + */ +function views_get_view($name, $reset = FALSE) { + views_include('view'); + $view = view::load($name, $reset); + $default_view = views_get_default_view($name); + + // The view does not exist. + if (empty($view) && empty($default_view)) { + return; + } + // The view is defined in code. + elseif (empty($view) && !empty($default_view)) { + $status = variable_get('views_defaults', array()); + if (isset($status[$default_view->name])) { + $default_view->disabled = $status[$default_view->name]; + } + $default_view->type = t('Default'); + return $default_view->clone_view(); + } + // The view is overriden/defined in the database. + elseif (!empty($view) && !empty($default_view)) { + $view->type = t('Overridden'); + } + + return $view->clone_view(); +} + +// ------------------------------------------------------------------ +// Views debug helper functions + +/** + * Provide debug output for Views. This relies on devel.module + */ +function views_debug($message) { + if (module_exists('devel') && variable_get('views_devel_output', FALSE) && user_access('access devel information')) { + if (is_string($message)) { + $output = $message; + } + else { + $output = var_export($message, TRUE); + } + if (variable_get('views_devel_region', 'footer') != 'watchdog') { + drupal_set_content(variable_get('views_devel_region', 'footer'), '
    ' . $output . '
    '); + } + else { + watchdog('views_logging', '
    ' . $output . '
    '); + } + } +} + +/** + * Shortcut to views_debug() + */ +function vpr($message) { + views_debug($message); +} + +/** + * Debug messages + */ +function vsm($message) { + if (module_exists('devel')) { + dsm($message); + } +} + +function views_trace() { + $message = ''; + foreach (debug_backtrace() as $item) { + if (!empty($item['file']) && !in_array($item['function'], array('vsm_trace', 'vpr_trace', 'views_trace'))) { + $message .= basename($item['file']) . ": " . (empty($item['class']) ? '' : ($item['class'] . '->')) . "$item[function] line $item[line]" . "\n"; + } + } + return $message; +} + +function vsm_trace() { + vsm(views_trace()); +} + +function vpr_trace() { + dpr(views_trace()); +} + +// ------------------------------------------------------------------ +// Exposed widgets form + +/** + * Form builder for the exposed widgets form. + * + * Be sure that $view and $display are references. + */ +function views_exposed_form(&$form_state) { + // Don't show the form when batch operations are in progress. + if ($batch = batch_get() && isset($batch['current_set'])) { + return array( + // Set the theme callback to be nothing to avoid errors in template_preprocess_views_exposed_form(). + '#theme' => '', + ); + } + + // Make sure that we validate because this form might be submitted + // multiple times per page. + $form_state['must_validate'] = TRUE; + $view = &$form_state['view']; + $display = &$form_state['display']; + + $form_state['input'] = $view->get_exposed_input(); + + // Let form plugins know this is for exposed widgets. + $form_state['exposed'] = TRUE; + // Check if the form was already created + if ($cache = views_exposed_form_cache($view->name, $view->current_display)) { + return $cache; + } + + $form['#info'] = array(); + + if (!variable_get('clean_url', FALSE)) { + $form['q'] = array( + '#type' => 'hidden', + '#value' => $view->get_url(), + ); + } + + // Go through each filter and let it generate its info. + foreach ($view->filter as $id => $filter) { + $view->filter[$id]->exposed_form($form, $form_state); + if ($info = $view->filter[$id]->exposed_info()) { + $form['#info']['filter-' . $id] = $info; + } + } + + // @todo deal with exposed sorts + + $form['submit'] = array( + '#name' => '', // prevent from showing up in $_GET. + '#type' => 'submit', + '#value' => t('Apply'), + '#id' => form_clean_id('edit-submit-' . $view->name), + ); + + $form['#action'] = url($view->get_url()); + $form['#theme'] = views_theme_functions('views_exposed_form', $view, $display); + $form['#id'] = views_css_safe('views_exposed_form-' . check_plain($view->name) . '-' . check_plain($display->id)); +// $form['#attributes']['class'] = array('views-exposed-form'); + + // If using AJAX, we need the form plugin. + if ($view->use_ajax) { + drupal_add_js('misc/jquery.form.js'); + } + views_add_js('dependent'); + + // Save the form + views_exposed_form_cache($view->name, $view->current_display, $form); + + return $form; +} + +/** + * Validate handler for exposed filters + */ +function views_exposed_form_validate(&$form, &$form_state) { + foreach (array('field', 'filter') as $type) { + $handlers = &$form_state['view']->$type; + foreach ($handlers as $key => $handler) { + $handlers[$key]->exposed_validate($form, $form_state); + } + } +} + +/** + * Submit handler for exposed filters + */ +function views_exposed_form_submit(&$form, &$form_state) { + foreach (array('field', 'filter') as $type) { + $handlers = &$form_state['view']->$type; + foreach ($handlers as $key => $info) { + $handlers[$key]->exposed_submit($form, $form_state); + } + } + $form_state['view']->exposed_data = $form_state['values']; + $form_state['view']->exposed_raw_input = array(); + + foreach ($form_state['values'] as $key => $value) { + if (!in_array($key, array('q', 'submit', 'form_build_id', 'form_id', 'form_token', ''))) { + $form_state['view']->exposed_raw_input[$key] = $value; + } + } +} + +/** + * Save the Views exposed form for later use. + * + * @param $views_name + * String. The views name. + * @param $display_name + * String. The current view display name. + * @param $form_output + * Array (optional). The form structure. Only needed when inserting the value. + * @return + * Array. The form structure, if any. Otherwise, return FALSE. + */ +function views_exposed_form_cache($views_name, $display_name, $form_output = NULL) { + static $views_exposed; + + // Save the form output + if (!empty($form_output)) { + $views_exposed[$views_name][$display_name] = $form_output; + return; + } + + // Return the form output, if any + return empty($views_exposed[$views_name][$display_name]) ? FALSE : $views_exposed[$views_name][$display_name]; +} + +// ------------------------------------------------------------------ +// Misc helpers + +/** + * Build a list of theme function names for use most everywhere. + */ +function views_theme_functions($hook, $view, $display = NULL) { + require_once './' . drupal_get_path('module', 'views') . "/theme/theme.inc"; + return _views_theme_functions($hook, $view, $display); +} + +/** + * Views' replacement for drupal_get_form so that we can do more with + * less. + * + * Items that can be set on the form_state include: + * - input: The source of input. If unset this will be $_POST. + * - no_redirect: Absolutely do not redirect the form even if instructed + * to do so. + * - rerender: If no_redirect is set and the form was successfully submitted, + * rerender the form. Otherwise it will just return. + * + */ +function drupal_build_form($form_id, &$form_state) { + views_include('form'); + return _drupal_build_form($form_id, $form_state); +} + +/** + * Substitute current time; this works with cached queries. + */ +function views_views_query_substitutions($view) { + global $language; + return array( + '***CURRENT_VERSION***' => VERSION, + '***CURRENT_TIME***' => time(), + '***CURRENT_LANGUAGE***' => $language->language, + '***DEFAULT_LANGUAGE***' => language_default('language'), + '***NO_LANGUAGE***' => '', + ); +} + +/** + * Embed a view using a PHP snippet. + * + * This function is meant to be called from PHP snippets, should one wish to + * embed a view in a node or something. It's meant to provide the simplest + * solution and doesn't really offer a lot of options, but breaking the function + * apart is pretty easy, and this provides a worthwhile guide to doing so. + * + * Note that this function does NOT display the title of the view. If you want + * to do that, you will need to do what this function does manually, by + * loading the view, getting the preview and then getting $view->get_title(). + * + * @param $name + * The name of the view to embed. + * @param $display_id + * The display id to embed. If unsure, use 'default', as it will always be + * valid. But things like 'page' or 'block' should work here. + * @param ... + * Any additional parameters will be passed as arguments. + */ +function views_embed_view($name, $display_id = 'default') { + $args = func_get_args(); + array_shift($args); // remove $name + if (count($args)) { + array_shift($args); // remove $display_id + } + + $view = views_get_view($name); + if (!$view || !$view->access($display_id)) { + return; + } + + return $view->preview($display_id, $args); +} + +/** +* Get the result of a view. +* +* @param string $name +* The name of the view to retrieve the data from. +* @param string $display_id +* The display id. On the edit page for the view in question, you'll find +* a list of displays at the left side of the control area. "Defaults" +* will be at the top of that list. Hover your cursor over the name of the +* display you want to use. An URL will appear in the status bar of your +* browser. This is usually at the bottom of the window, in the chrome. +* Everything after #views-tab- is the display ID, e.g. page_1. + * @param ... + * Any additional parameters will be passed as arguments. +* @return +* array +* An array containing an object for each view item. +*/ +function views_get_view_result($name, $display_id = NULL) { + $args = func_get_args(); + array_shift($args); // remove $name + if (count($args)) { + array_shift($args); // remove $display_id + } + + $view = views_get_view($name); + if (is_object($view)) { + if (is_array($args)) { + $view->set_arguments($args); + } + if (is_string($display_id)) { + $view->set_display($display_id); + } + else { + $view->init_display(); + } + $view->pre_execute(); + $view->execute(); + return $view->result; + } + else { + return array(); + } +} + +/** + * Export a field. + */ +function views_var_export($var, $prefix = '', $init = TRUE) { + if (is_array($var)) { + if (empty($var)) { + $output = 'array()'; + } + else { + $output = "array(\n"; + foreach ($var as $key => $value) { + $output .= " " . views_var_export($key, '', FALSE) . " => " . views_var_export($value, ' ', FALSE) . ",\n"; + } + $output .= ')'; + } + } + else if (is_bool($var)) { + $output = $var ? 'TRUE' : 'FALSE'; + } + else if (is_string($var) && strpos($var, "\n") !== FALSE) { + // Replace line breaks in strings with a token for replacement + // at the very end. This protects multi-line strings from + // unintentional indentation. + $var = str_replace("\n", "***BREAK***", $var); + $output = var_export($var, TRUE); + } + else { + $output = var_export($var, TRUE); + } + + if ($prefix) { + $output = str_replace("\n", "\n$prefix", $output); + } + + if ($init) { + $output = str_replace("***BREAK***", "\n", $output); + } + + return $output; +} + +/** + * Prepare the specified string for use as a CSS identifier. + */ +function views_css_safe($string) { + return str_replace('_', '-', $string); +} + +/** + * Implementation of hook_views_exportables(). + */ +function views_views_exportables($op = 'list', $views = NULL, $name = 'foo') { + $all_views = views_get_all_views(); + if ($op == 'list') { + + foreach ($all_views as $name => $view) { + // in list, $views is a list of tags. + if (empty($views) || in_array($view->tag, $views)) { + $return[$name] = array( + 'name' => check_plain($name), + 'desc' => check_plain($view->description), + 'tag' => check_plain($view->tag) + ); + } + } + return $return; + } + + if ($op == 'export') { + $code = "/**\n"; + $code .= " * Implementation of hook_views_default_views().\n"; + $code .= " */\n"; + $code .= "function " . $name . "_views_default_views() {\n"; + foreach ($views as $view => $truth) { + $code .= " /*\n"; + $code .= " * View ". var_export($all_views[$view]->name, TRUE) ."\n"; + $code .= " */\n"; + $code .= $all_views[$view]->export(' '); + $code .= ' $views[$view->name] = $view;' . "\n\n"; + } + $code .= " return \$views;\n"; + $code .= "}\n"; + + return $code; + } +} + +/** + * Microtime helper function to return a float time value (php4 & php5 safe). + */ +function views_microtime() { + list($usec, $sec) = explode(' ', microtime()); + return (float)$sec + (float)$usec; +} + +/** + * Trim the field down to the specified length. + * + * @param $alter + * - max_length: Maximum lenght of the string, the rest gets truncated. + * - word_boundary: Trim only on a word boundary. + * - ellipsis: Trim only on a word boundary. + * - html: Take sure that the html is correct. + */ +function views_trim_text($alter, $value) { + if (drupal_strlen($value) > $alter['max_length']) { + $value = drupal_substr($value, 0, $alter['max_length']); + // TODO: replace this with cleanstring of ctools + if (!empty($alter['word_boundary'])) { + $regex = "(.*)\b.+"; + if (function_exists('mb_ereg')) { + mb_regex_encoding('UTF-8'); + $found = mb_ereg($regex, $value, $matches); + } + else { + $found = preg_match("/$regex/us", $value, $matches); + } + if ($found) { + $value = $matches[1]; + } + } + // Remove scraps of HTML entities from the end of a strings + $value = rtrim(preg_replace('/(?:<(?!.+>)|&(?!.+;)).*$/us', '', $value)); + + if (!empty($alter['ellipsis'])) { + $value .= '...'; + } + } + if (!empty($alter['html'])) { + $value = _filter_htmlcorrector($value); + } + + return $value; +} diff --git a/sites/all/modules/views/views2.doxy b/sites/all/modules/views/views2.doxy new file mode 100644 index 0000000..7d95c1a --- /dev/null +++ b/sites/all/modules/views/views2.doxy @@ -0,0 +1,1252 @@ +# Doxyfile 1.4.7 + +# This file describes the settings to be used by the documentation system +# doxygen (www.doxygen.org) for a project +# +# All text after a hash (#) is considered a comment and will be ignored +# The format is: +# TAG = value [value, ...] +# For lists items can also be appended using: +# TAG += value [value, ...] +# Values that contain spaces should be placed between quotes (" ") + +#--------------------------------------------------------------------------- +# Project related configuration options +#--------------------------------------------------------------------------- + +# The PROJECT_NAME tag is a single word (or a sequence of words surrounded +# by quotes) that should identify the project. + +PROJECT_NAME = Views + +# The PROJECT_NUMBER tag can be used to enter a project or revision number. +# This could be handy for archiving the generated documentation or +# if some version control system is used. + +PROJECT_NUMBER = 2.0 + +# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) +# base path where the generated documentation will be put. +# If a relative path is entered, it will be relative to the location +# where doxygen was started. If left blank the current directory will be used. + +OUTPUT_DIRECTORY = doc + +# If the CREATE_SUBDIRS tag is set to YES, then doxygen will create +# 4096 sub-directories (in 2 levels) under the output directory of each output +# format and will distribute the generated files over these directories. +# Enabling this option can be useful when feeding doxygen a huge amount of +# source files, where putting all generated files in the same directory would +# otherwise cause performance problems for the file system. + +CREATE_SUBDIRS = NO + +# The OUTPUT_LANGUAGE tag is used to specify the language in which all +# documentation generated by doxygen is written. Doxygen will use this +# information to generate all constant output in the proper language. +# The default language is English, other supported languages are: +# Brazilian, Catalan, Chinese, Chinese-Traditional, Croatian, Czech, Danish, +# Dutch, Finnish, French, German, Greek, Hungarian, Italian, Japanese, +# Japanese-en (Japanese with English messages), Korean, Korean-en, Norwegian, +# Polish, Portuguese, Romanian, Russian, Serbian, Slovak, Slovene, Spanish, +# Swedish, and Ukrainian. + +OUTPUT_LANGUAGE = English + +# This tag can be used to specify the encoding used in the generated output. +# The encoding is not always determined by the language that is chosen, +# but also whether or not the output is meant for Windows or non-Windows users. +# In case there is a difference, setting the USE_WINDOWS_ENCODING tag to YES +# forces the Windows encoding (this is the default for the Windows binary), +# whereas setting the tag to NO uses a Unix-style encoding (the default for +# all platforms other than Windows). + +USE_WINDOWS_ENCODING = NO + +# If the BRIEF_MEMBER_DESC tag is set to YES (the default) Doxygen will +# include brief member descriptions after the members that are listed in +# the file and class documentation (similar to JavaDoc). +# Set to NO to disable this. + +BRIEF_MEMBER_DESC = YES + +# If the REPEAT_BRIEF tag is set to YES (the default) Doxygen will prepend +# the brief description of a member or function before the detailed description. +# Note: if both HIDE_UNDOC_MEMBERS and BRIEF_MEMBER_DESC are set to NO, the +# brief descriptions will be completely suppressed. + +REPEAT_BRIEF = YES + +# This tag implements a quasi-intelligent brief description abbreviator +# that is used to form the text in various listings. Each string +# in this list, if found as the leading text of the brief description, will be +# stripped from the text and the result after processing the whole list, is +# used as the annotated text. Otherwise, the brief description is used as-is. +# If left blank, the following values are used ("$name" is automatically +# replaced with the name of the entity): "The $name class" "The $name widget" +# "The $name file" "is" "provides" "specifies" "contains" +# "represents" "a" "an" "the" + +ABBREVIATE_BRIEF = + +# If the ALWAYS_DETAILED_SEC and REPEAT_BRIEF tags are both set to YES then +# Doxygen will generate a detailed section even if there is only a brief +# description. + +ALWAYS_DETAILED_SEC = YES + +# If the INLINE_INHERITED_MEMB tag is set to YES, doxygen will show all +# inherited members of a class in the documentation of that class as if those +# members were ordinary class members. Constructors, destructors and assignment +# operators of the base classes will not be shown. + +INLINE_INHERITED_MEMB = YES + +# If the FULL_PATH_NAMES tag is set to YES then Doxygen will prepend the full +# path before files name in the file list and in the header files. If set +# to NO the shortest path that makes the file name unique will be used. + +FULL_PATH_NAMES = YES + +# If the FULL_PATH_NAMES tag is set to YES then the STRIP_FROM_PATH tag +# can be used to strip a user-defined part of the path. Stripping is +# only done if one of the specified strings matches the left-hand part of +# the path. The tag can be used to show relative paths in the file list. +# If left blank the directory from which doxygen is run is used as the +# path to strip. + +STRIP_FROM_PATH = + +# The STRIP_FROM_INC_PATH tag can be used to strip a user-defined part of +# the path mentioned in the documentation of a class, which tells +# the reader which header file to include in order to use a class. +# If left blank only the name of the header file containing the class +# definition is used. Otherwise one should specify the include paths that +# are normally passed to the compiler using the -I flag. + +STRIP_FROM_INC_PATH = + +# If the SHORT_NAMES tag is set to YES, doxygen will generate much shorter +# (but less readable) file names. This can be useful is your file systems +# doesn't support long names like on DOS, Mac, or CD-ROM. + +SHORT_NAMES = NO + +# If the JAVADOC_AUTOBRIEF tag is set to YES then Doxygen +# will interpret the first line (until the first dot) of a JavaDoc-style +# comment as the brief description. If set to NO, the JavaDoc +# comments will behave just like the Qt-style comments (thus requiring an +# explicit @brief command for a brief description. + +JAVADOC_AUTOBRIEF = YES + +# The MULTILINE_CPP_IS_BRIEF tag can be set to YES to make Doxygen +# treat a multi-line C++ special comment block (i.e. a block of //! or /// +# comments) as a brief description. This used to be the default behaviour. +# The new default is to treat a multi-line C++ comment block as a detailed +# description. Set this tag to YES if you prefer the old behaviour instead. + +MULTILINE_CPP_IS_BRIEF = NO + +# If the DETAILS_AT_TOP tag is set to YES then Doxygen +# will output the detailed description near the top, like JavaDoc. +# If set to NO, the detailed description appears after the member +# documentation. + +DETAILS_AT_TOP = YES + +# If the INHERIT_DOCS tag is set to YES (the default) then an undocumented +# member inherits the documentation from any documented member that it +# re-implements. + +INHERIT_DOCS = YES + +# If the SEPARATE_MEMBER_PAGES tag is set to YES, then doxygen will produce +# a new page for each member. If set to NO, the documentation of a member will +# be part of the file/class/namespace that contains it. + +SEPARATE_MEMBER_PAGES = NO + +# The TAB_SIZE tag can be used to set the number of spaces in a tab. +# Doxygen uses this value to replace tabs by spaces in code fragments. + +TAB_SIZE = 2 + +# This tag can be used to specify a number of aliases that acts +# as commands in the documentation. An alias has the form "name=value". +# For example adding "sideeffect=\par Side Effects:\n" will allow you to +# put the command \sideeffect (or @sideeffect) in the documentation, which +# will result in a user-defined paragraph with heading "Side Effects:". +# You can put \n's in the value part of an alias to insert newlines. + +ALIASES = + +# Set the OPTIMIZE_OUTPUT_FOR_C tag to YES if your project consists of C +# sources only. Doxygen will then generate output that is more tailored for C. +# For instance, some of the names that are used will be different. The list +# of all members will be omitted, etc. + +OPTIMIZE_OUTPUT_FOR_C = NO + +# Set the OPTIMIZE_OUTPUT_JAVA tag to YES if your project consists of Java +# sources only. Doxygen will then generate output that is more tailored for Java. +# For instance, namespaces will be presented as packages, qualified scopes +# will look different, etc. + +OPTIMIZE_OUTPUT_JAVA = NO + +# If you use STL classes (i.e. std::string, std::vector, etc.) but do not want to +# include (a tag file for) the STL sources as input, then you should +# set this tag to YES in order to let doxygen match functions declarations and +# definitions whose arguments contain STL classes (e.g. func(std::string); v.s. +# func(std::string) {}). This also make the inheritance and collaboration +# diagrams that involve STL classes more complete and accurate. + +BUILTIN_STL_SUPPORT = NO + +# If member grouping is used in the documentation and the DISTRIBUTE_GROUP_DOC +# tag is set to YES, then doxygen will reuse the documentation of the first +# member in the group (if any) for the other members of the group. By default +# all members of a group must be documented explicitly. + +DISTRIBUTE_GROUP_DOC = NO + +# Set the SUBGROUPING tag to YES (the default) to allow class member groups of +# the same type (for instance a group of public functions) to be put as a +# subgroup of that type (e.g. under the Public Functions section). Set it to +# NO to prevent subgrouping. Alternatively, this can be done per class using +# the \nosubgrouping command. + +SUBGROUPING = YES + +#--------------------------------------------------------------------------- +# Build related configuration options +#--------------------------------------------------------------------------- + +# If the EXTRACT_ALL tag is set to YES doxygen will assume all entities in +# documentation are documented, even if no documentation was available. +# Private class members and static file members will be hidden unless +# the EXTRACT_PRIVATE and EXTRACT_STATIC tags are set to YES + +EXTRACT_ALL = NO + +# If the EXTRACT_PRIVATE tag is set to YES all private members of a class +# will be included in the documentation. + +EXTRACT_PRIVATE = NO + +# If the EXTRACT_STATIC tag is set to YES all static members of a file +# will be included in the documentation. + +EXTRACT_STATIC = NO + +# If the EXTRACT_LOCAL_CLASSES tag is set to YES classes (and structs) +# defined locally in source files will be included in the documentation. +# If set to NO only classes defined in header files are included. + +EXTRACT_LOCAL_CLASSES = YES + +# This flag is only useful for Objective-C code. When set to YES local +# methods, which are defined in the implementation section but not in +# the interface are included in the documentation. +# If set to NO (the default) only methods in the interface are included. + +EXTRACT_LOCAL_METHODS = NO + +# If the HIDE_UNDOC_MEMBERS tag is set to YES, Doxygen will hide all +# undocumented members of documented classes, files or namespaces. +# If set to NO (the default) these members will be included in the +# various overviews, but no documentation section is generated. +# This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_MEMBERS = NO + +# If the HIDE_UNDOC_CLASSES tag is set to YES, Doxygen will hide all +# undocumented classes that are normally visible in the class hierarchy. +# If set to NO (the default) these classes will be included in the various +# overviews. This option has no effect if EXTRACT_ALL is enabled. + +HIDE_UNDOC_CLASSES = NO + +# If the HIDE_FRIEND_COMPOUNDS tag is set to YES, Doxygen will hide all +# friend (class|struct|union) declarations. +# If set to NO (the default) these declarations will be included in the +# documentation. + +HIDE_FRIEND_COMPOUNDS = NO + +# If the HIDE_IN_BODY_DOCS tag is set to YES, Doxygen will hide any +# documentation blocks found inside the body of a function. +# If set to NO (the default) these blocks will be appended to the +# function's detailed documentation block. + +HIDE_IN_BODY_DOCS = NO + +# The INTERNAL_DOCS tag determines if documentation +# that is typed after a \internal command is included. If the tag is set +# to NO (the default) then the documentation will be excluded. +# Set it to YES to include the internal documentation. + +INTERNAL_DOCS = NO + +# If the CASE_SENSE_NAMES tag is set to NO then Doxygen will only generate +# file names in lower-case letters. If set to YES upper-case letters are also +# allowed. This is useful if you have classes or files whose names only differ +# in case and if your file system supports case sensitive file names. Windows +# and Mac users are advised to set this option to NO. + +CASE_SENSE_NAMES = YES + +# If the HIDE_SCOPE_NAMES tag is set to NO (the default) then Doxygen +# will show members with their full class and namespace scopes in the +# documentation. If set to YES the scope will be hidden. + +HIDE_SCOPE_NAMES = NO + +# If the SHOW_INCLUDE_FILES tag is set to YES (the default) then Doxygen +# will put a list of the files that are included by a file in the documentation +# of that file. + +SHOW_INCLUDE_FILES = YES + +# If the INLINE_INFO tag is set to YES (the default) then a tag [inline] +# is inserted in the documentation for inline members. + +INLINE_INFO = YES + +# If the SORT_MEMBER_DOCS tag is set to YES (the default) then doxygen +# will sort the (detailed) documentation of file and class members +# alphabetically by member name. If set to NO the members will appear in +# declaration order. + +SORT_MEMBER_DOCS = YES + +# If the SORT_BRIEF_DOCS tag is set to YES then doxygen will sort the +# brief documentation of file, namespace and class members alphabetically +# by member name. If set to NO (the default) the members will appear in +# declaration order. + +SORT_BRIEF_DOCS = NO + +# If the SORT_BY_SCOPE_NAME tag is set to YES, the class list will be +# sorted by fully-qualified names, including namespaces. If set to +# NO (the default), the class list will be sorted only by class name, +# not including the namespace part. +# Note: This option is not very useful if HIDE_SCOPE_NAMES is set to YES. +# Note: This option applies only to the class list, not to the +# alphabetical list. + +SORT_BY_SCOPE_NAME = NO + +# The GENERATE_TODOLIST tag can be used to enable (YES) or +# disable (NO) the todo list. This list is created by putting \todo +# commands in the documentation. + +GENERATE_TODOLIST = YES + +# The GENERATE_TESTLIST tag can be used to enable (YES) or +# disable (NO) the test list. This list is created by putting \test +# commands in the documentation. + +GENERATE_TESTLIST = YES + +# The GENERATE_BUGLIST tag can be used to enable (YES) or +# disable (NO) the bug list. This list is created by putting \bug +# commands in the documentation. + +GENERATE_BUGLIST = YES + +# The GENERATE_DEPRECATEDLIST tag can be used to enable (YES) or +# disable (NO) the deprecated list. This list is created by putting +# \deprecated commands in the documentation. + +GENERATE_DEPRECATEDLIST= YES + +# The ENABLED_SECTIONS tag can be used to enable conditional +# documentation sections, marked by \if sectionname ... \endif. + +ENABLED_SECTIONS = + +# The MAX_INITIALIZER_LINES tag determines the maximum number of lines +# the initial value of a variable or define consists of for it to appear in +# the documentation. If the initializer consists of more lines than specified +# here it will be hidden. Use a value of 0 to hide initializers completely. +# The appearance of the initializer of individual variables and defines in the +# documentation can be controlled using \showinitializer or \hideinitializer +# command in the documentation regardless of this setting. + +MAX_INITIALIZER_LINES = 30 + +# Set the SHOW_USED_FILES tag to NO to disable the list of files generated +# at the bottom of the documentation of classes and structs. If set to YES the +# list will mention the files that were used to generate the documentation. + +SHOW_USED_FILES = YES + +# If the sources in your project are distributed over multiple directories +# then setting the SHOW_DIRECTORIES tag to YES will show the directory hierarchy +# in the documentation. The default is NO. + +SHOW_DIRECTORIES = NO + +# The FILE_VERSION_FILTER tag can be used to specify a program or script that +# doxygen should invoke to get the current version for each file (typically from the +# version control system). Doxygen will invoke the program by executing (via +# popen()) the command , where is the value of +# the FILE_VERSION_FILTER tag, and is the name of an input file +# provided by doxygen. Whatever the program writes to standard output +# is used as the file version. See the manual for examples. + +FILE_VERSION_FILTER = + +#--------------------------------------------------------------------------- +# configuration options related to warning and progress messages +#--------------------------------------------------------------------------- + +# The QUIET tag can be used to turn on/off the messages that are generated +# by doxygen. Possible values are YES and NO. If left blank NO is used. + +QUIET = YES + +# The WARNINGS tag can be used to turn on/off the warning messages that are +# generated by doxygen. Possible values are YES and NO. If left blank +# NO is used. + +WARNINGS = YES + +# If WARN_IF_UNDOCUMENTED is set to YES, then doxygen will generate warnings +# for undocumented members. If EXTRACT_ALL is set to YES then this flag will +# automatically be disabled. + +WARN_IF_UNDOCUMENTED = NO + +# If WARN_IF_DOC_ERROR is set to YES, doxygen will generate warnings for +# potential errors in the documentation, such as not documenting some +# parameters in a documented function, or documenting parameters that +# don't exist or using markup commands wrongly. + +WARN_IF_DOC_ERROR = YES + +# This WARN_NO_PARAMDOC option can be abled to get warnings for +# functions that are documented, but have no documentation for their parameters +# or return value. If set to NO (the default) doxygen will only warn about +# wrong or incomplete parameter documentation, but not about the absence of +# documentation. + +WARN_NO_PARAMDOC = NO + +# The WARN_FORMAT tag determines the format of the warning messages that +# doxygen can produce. The string should contain the $file, $line, and $text +# tags, which will be replaced by the file and line number from which the +# warning originated and the warning text. Optionally the format may contain +# $version, which will be replaced by the version of the file (if it could +# be obtained via FILE_VERSION_FILTER) + +WARN_FORMAT = "$file:$line: $text" + +# The WARN_LOGFILE tag can be used to specify a file to which warning +# and error messages should be written. If left blank the output is written +# to stderr. + +WARN_LOGFILE = + +#--------------------------------------------------------------------------- +# configuration options related to the input files +#--------------------------------------------------------------------------- + +# The INPUT tag can be used to specify the files and/or directories that contain +# documented source files. You may enter file names like "myfile.cpp" or +# directories like "/usr/src/myproject". Separate the files or directories +# with spaces. + +INPUT = + +# If the value of the INPUT tag contains directories, you can use the +# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank the following patterns are tested: +# *.c *.cc *.cxx *.cpp *.c++ *.java *.ii *.ixx *.ipp *.i++ *.inl *.h *.hh *.hxx +# *.hpp *.h++ *.idl *.odl *.cs *.php *.php3 *.inc *.m *.mm *.py + +FILE_PATTERNS = *.module *.inc *.php + +# The RECURSIVE tag can be used to turn specify whether or not subdirectories +# should be searched for input files as well. Possible values are YES and NO. +# If left blank NO is used. + +RECURSIVE = YES + +# The EXCLUDE tag can be used to specify files and/or directories that should +# excluded from the INPUT source files. This way you can easily exclude a +# subdirectory from a directory tree whose root is specified with the INPUT tag. + +EXCLUDE = + +# The EXCLUDE_SYMLINKS tag can be used select whether or not files or +# directories that are symbolic links (a Unix filesystem feature) are excluded +# from the input. + +EXCLUDE_SYMLINKS = NO + +# If the value of the INPUT tag contains directories, you can use the +# EXCLUDE_PATTERNS tag to specify one or more wildcard patterns to exclude +# certain files from those directories. Note that the wildcards are matched +# against the file with absolute path, so to exclude all test directories +# for example use the pattern */test/* + +EXCLUDE_PATTERNS = + +# The EXAMPLE_PATH tag can be used to specify one or more files or +# directories that contain example code fragments that are included (see +# the \include command). + +EXAMPLE_PATH = + +# If the value of the EXAMPLE_PATH tag contains directories, you can use the +# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp +# and *.h) to filter out the source-files in the directories. If left +# blank all files are included. + +EXAMPLE_PATTERNS = + +# If the EXAMPLE_RECURSIVE tag is set to YES then subdirectories will be +# searched for input files to be used with the \include or \dontinclude +# commands irrespective of the value of the RECURSIVE tag. +# Possible values are YES and NO. If left blank NO is used. + +EXAMPLE_RECURSIVE = NO + +# The IMAGE_PATH tag can be used to specify one or more files or +# directories that contain image that are included in the documentation (see +# the \image command). + +IMAGE_PATH = + +# The INPUT_FILTER tag can be used to specify a program that doxygen should +# invoke to filter for each input file. Doxygen will invoke the filter program +# by executing (via popen()) the command , where +# is the value of the INPUT_FILTER tag, and is the name of an +# input file. Doxygen will then use the output that the filter program writes +# to standard output. If FILTER_PATTERNS is specified, this tag will be +# ignored. + +INPUT_FILTER = + +# The FILTER_PATTERNS tag can be used to specify filters on a per file pattern +# basis. Doxygen will compare the file name with each pattern and apply the +# filter if there is a match. The filters are a list of the form: +# pattern=filter (like *.cpp=my_cpp_filter). See INPUT_FILTER for further +# info on how filters are used. If FILTER_PATTERNS is empty, INPUT_FILTER +# is applied to all files. + +FILTER_PATTERNS = + +# If the FILTER_SOURCE_FILES tag is set to YES, the input filter (if set using +# INPUT_FILTER) will be used to filter the input files when producing source +# files to browse (i.e. when SOURCE_BROWSER is set to YES). + +FILTER_SOURCE_FILES = NO + +#--------------------------------------------------------------------------- +# configuration options related to source browsing +#--------------------------------------------------------------------------- + +# If the SOURCE_BROWSER tag is set to YES then a list of source files will +# be generated. Documented entities will be cross-referenced with these sources. +# Note: To get rid of all source code in the generated output, make sure also +# VERBATIM_HEADERS is set to NO. + +SOURCE_BROWSER = YES + +# Setting the INLINE_SOURCES tag to YES will include the body +# of functions and classes directly in the documentation. + +INLINE_SOURCES = YES + +# Setting the STRIP_CODE_COMMENTS tag to YES (the default) will instruct +# doxygen to hide any special comment blocks from generated source code +# fragments. Normal C and C++ comments will always remain visible. + +STRIP_CODE_COMMENTS = YES + +# If the REFERENCED_BY_RELATION tag is set to YES (the default) +# then for each documented function all documented +# functions referencing it will be listed. + +REFERENCED_BY_RELATION = YES + +# If the REFERENCES_RELATION tag is set to YES (the default) +# then for each documented function all documented entities +# called/used by that function will be listed. + +REFERENCES_RELATION = YES + +# If the REFERENCES_LINK_SOURCE tag is set to YES (the default) +# and SOURCE_BROWSER tag is set to YES, then the hyperlinks from +# functions in REFERENCES_RELATION and REFERENCED_BY_RELATION lists will +# link to the source code. Otherwise they will link to the documentstion. + +REFERENCES_LINK_SOURCE = YES + +# If the USE_HTAGS tag is set to YES then the references to source code +# will point to the HTML generated by the htags(1) tool instead of doxygen +# built-in source browser. The htags tool is part of GNU's global source +# tagging system (see http://www.gnu.org/software/global/global.html). You +# will need version 4.8.6 or higher. + +USE_HTAGS = NO + +# If the VERBATIM_HEADERS tag is set to YES (the default) then Doxygen +# will generate a verbatim copy of the header file for each class for +# which an include is specified. Set to NO to disable this. + +VERBATIM_HEADERS = YES + +#--------------------------------------------------------------------------- +# configuration options related to the alphabetical class index +#--------------------------------------------------------------------------- + +# If the ALPHABETICAL_INDEX tag is set to YES, an alphabetical index +# of all compounds will be generated. Enable this if the project +# contains a lot of classes, structs, unions or interfaces. + +ALPHABETICAL_INDEX = NO + +# If the alphabetical index is enabled (see ALPHABETICAL_INDEX) then +# the COLS_IN_ALPHA_INDEX tag can be used to specify the number of columns +# in which this list will be split (can be a number in the range [1..20]) + +COLS_IN_ALPHA_INDEX = 5 + +# In case all classes in a project start with a common prefix, all +# classes will be put under the same header in the alphabetical index. +# The IGNORE_PREFIX tag can be used to specify one or more prefixes that +# should be ignored while generating the index headers. + +IGNORE_PREFIX = + +#--------------------------------------------------------------------------- +# configuration options related to the HTML output +#--------------------------------------------------------------------------- + +# If the GENERATE_HTML tag is set to YES (the default) Doxygen will +# generate HTML output. + +GENERATE_HTML = YES + +# The HTML_OUTPUT tag is used to specify where the HTML docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `html' will be used as the default path. + +HTML_OUTPUT = html + +# The HTML_FILE_EXTENSION tag can be used to specify the file extension for +# each generated HTML page (for example: .htm,.php,.asp). If it is left blank +# doxygen will generate files with .html extension. + +HTML_FILE_EXTENSION = .html + +# The HTML_HEADER tag can be used to specify a personal HTML header for +# each generated HTML page. If it is left blank doxygen will generate a +# standard header. + +HTML_HEADER = + +# The HTML_FOOTER tag can be used to specify a personal HTML footer for +# each generated HTML page. If it is left blank doxygen will generate a +# standard footer. + +HTML_FOOTER = + +# The HTML_STYLESHEET tag can be used to specify a user-defined cascading +# style sheet that is used by each HTML page. It can be used to +# fine-tune the look of the HTML output. If the tag is left blank doxygen +# will generate a default style sheet. Note that doxygen will try to copy +# the style sheet file to the HTML output directory, so don't put your own +# stylesheet in the HTML output directory as well, or it will be erased! + +HTML_STYLESHEET = + +# If the HTML_ALIGN_MEMBERS tag is set to YES, the members of classes, +# files or namespaces will be aligned in HTML using tables. If set to +# NO a bullet list will be used. + +HTML_ALIGN_MEMBERS = YES + +# If the GENERATE_HTMLHELP tag is set to YES, additional index files +# will be generated that can be used as input for tools like the +# Microsoft HTML help workshop to generate a compressed HTML help file (.chm) +# of the generated HTML documentation. + +GENERATE_HTMLHELP = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the CHM_FILE tag can +# be used to specify the file name of the resulting .chm file. You +# can add a path in front of the file if the result should not be +# written to the html output directory. + +CHM_FILE = + +# If the GENERATE_HTMLHELP tag is set to YES, the HHC_LOCATION tag can +# be used to specify the location (absolute path including file name) of +# the HTML help compiler (hhc.exe). If non-empty doxygen will try to run +# the HTML help compiler on the generated index.hhp. + +HHC_LOCATION = + +# If the GENERATE_HTMLHELP tag is set to YES, the GENERATE_CHI flag +# controls if a separate .chi index file is generated (YES) or that +# it should be included in the master .chm file (NO). + +GENERATE_CHI = NO + +# If the GENERATE_HTMLHELP tag is set to YES, the BINARY_TOC flag +# controls whether a binary table of contents is generated (YES) or a +# normal table of contents (NO) in the .chm file. + +BINARY_TOC = NO + +# The TOC_EXPAND flag can be set to YES to add extra items for group members +# to the contents of the HTML help documentation and to the tree view. + +TOC_EXPAND = NO + +# The DISABLE_INDEX tag can be used to turn on/off the condensed index at +# top of each HTML page. The value NO (the default) enables the index and +# the value YES disables it. + +DISABLE_INDEX = NO + +# This tag can be used to set the number of enum values (range [1..20]) +# that doxygen will group on one line in the generated HTML documentation. + +ENUM_VALUES_PER_LINE = 4 + +# If the GENERATE_TREEVIEW tag is set to YES, a side panel will be +# generated containing a tree-like index structure (just like the one that +# is generated for HTML Help). For this to work a browser that supports +# JavaScript, DHTML, CSS and frames is required (for instance Mozilla 1.0+, +# Netscape 6.0+, Internet explorer 5.0+, or Konqueror). Windows users are +# probably better off using the HTML help feature. + +GENERATE_TREEVIEW = YES + +# If the treeview is enabled (see GENERATE_TREEVIEW) then this tag can be +# used to set the initial width (in pixels) of the frame in which the tree +# is shown. + +TREEVIEW_WIDTH = 250 + +#--------------------------------------------------------------------------- +# configuration options related to the LaTeX output +#--------------------------------------------------------------------------- + +# If the GENERATE_LATEX tag is set to YES (the default) Doxygen will +# generate Latex output. + +GENERATE_LATEX = NO + +# The LATEX_OUTPUT tag is used to specify where the LaTeX docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `latex' will be used as the default path. + +LATEX_OUTPUT = latex + +# The LATEX_CMD_NAME tag can be used to specify the LaTeX command name to be +# invoked. If left blank `latex' will be used as the default command name. + +LATEX_CMD_NAME = latex + +# The MAKEINDEX_CMD_NAME tag can be used to specify the command name to +# generate index for LaTeX. If left blank `makeindex' will be used as the +# default command name. + +MAKEINDEX_CMD_NAME = makeindex + +# If the COMPACT_LATEX tag is set to YES Doxygen generates more compact +# LaTeX documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_LATEX = NO + +# The PAPER_TYPE tag can be used to set the paper type that is used +# by the printer. Possible values are: a4, a4wide, letter, legal and +# executive. If left blank a4wide will be used. + +PAPER_TYPE = a4wide + +# The EXTRA_PACKAGES tag can be to specify one or more names of LaTeX +# packages that should be included in the LaTeX output. + +EXTRA_PACKAGES = + +# The LATEX_HEADER tag can be used to specify a personal LaTeX header for +# the generated latex document. The header should contain everything until +# the first chapter. If it is left blank doxygen will generate a +# standard header. Notice: only use this tag if you know what you are doing! + +LATEX_HEADER = + +# If the PDF_HYPERLINKS tag is set to YES, the LaTeX that is generated +# is prepared for conversion to pdf (using ps2pdf). The pdf file will +# contain links (just like the HTML output) instead of page references +# This makes the output suitable for online browsing using a pdf viewer. + +PDF_HYPERLINKS = NO + +# If the USE_PDFLATEX tag is set to YES, pdflatex will be used instead of +# plain latex in the generated Makefile. Set this option to YES to get a +# higher quality PDF documentation. + +USE_PDFLATEX = NO + +# If the LATEX_BATCHMODE tag is set to YES, doxygen will add the \\batchmode. +# command to the generated LaTeX files. This will instruct LaTeX to keep +# running if errors occur, instead of asking the user for help. +# This option is also used when generating formulas in HTML. + +LATEX_BATCHMODE = NO + +# If LATEX_HIDE_INDICES is set to YES then doxygen will not +# include the index chapters (such as File Index, Compound Index, etc.) +# in the output. + +LATEX_HIDE_INDICES = NO + +#--------------------------------------------------------------------------- +# configuration options related to the RTF output +#--------------------------------------------------------------------------- + +# If the GENERATE_RTF tag is set to YES Doxygen will generate RTF output +# The RTF output is optimized for Word 97 and may not look very pretty with +# other RTF readers or editors. + +GENERATE_RTF = NO + +# The RTF_OUTPUT tag is used to specify where the RTF docs will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `rtf' will be used as the default path. + +RTF_OUTPUT = rtf + +# If the COMPACT_RTF tag is set to YES Doxygen generates more compact +# RTF documents. This may be useful for small projects and may help to +# save some trees in general. + +COMPACT_RTF = NO + +# If the RTF_HYPERLINKS tag is set to YES, the RTF that is generated +# will contain hyperlink fields. The RTF file will +# contain links (just like the HTML output) instead of page references. +# This makes the output suitable for online browsing using WORD or other +# programs which support those fields. +# Note: wordpad (write) and others do not support links. + +RTF_HYPERLINKS = NO + +# Load stylesheet definitions from file. Syntax is similar to doxygen's +# config file, i.e. a series of assignments. You only have to provide +# replacements, missing definitions are set to their default value. + +RTF_STYLESHEET_FILE = + +# Set optional variables used in the generation of an rtf document. +# Syntax is similar to doxygen's config file. + +RTF_EXTENSIONS_FILE = + +#--------------------------------------------------------------------------- +# configuration options related to the man page output +#--------------------------------------------------------------------------- + +# If the GENERATE_MAN tag is set to YES (the default) Doxygen will +# generate man pages + +GENERATE_MAN = NO + +# The MAN_OUTPUT tag is used to specify where the man pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `man' will be used as the default path. + +MAN_OUTPUT = man + +# The MAN_EXTENSION tag determines the extension that is added to +# the generated man pages (default is the subroutine's section .3) + +MAN_EXTENSION = .3 + +# If the MAN_LINKS tag is set to YES and Doxygen generates man output, +# then it will generate one additional man file for each entity +# documented in the real man page(s). These additional files +# only source the real man page, but without them the man command +# would be unable to find the correct page. The default is NO. + +MAN_LINKS = NO + +#--------------------------------------------------------------------------- +# configuration options related to the XML output +#--------------------------------------------------------------------------- + +# If the GENERATE_XML tag is set to YES Doxygen will +# generate an XML file that captures the structure of +# the code including all documentation. + +GENERATE_XML = NO + +# The XML_OUTPUT tag is used to specify where the XML pages will be put. +# If a relative path is entered the value of OUTPUT_DIRECTORY will be +# put in front of it. If left blank `xml' will be used as the default path. + +XML_OUTPUT = xml + +# The XML_SCHEMA tag can be used to specify an XML schema, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_SCHEMA = + +# The XML_DTD tag can be used to specify an XML DTD, +# which can be used by a validating XML parser to check the +# syntax of the XML files. + +XML_DTD = + +# If the XML_PROGRAMLISTING tag is set to YES Doxygen will +# dump the program listings (including syntax highlighting +# and cross-referencing information) to the XML output. Note that +# enabling this will significantly increase the size of the XML output. + +XML_PROGRAMLISTING = YES + +#--------------------------------------------------------------------------- +# configuration options for the AutoGen Definitions output +#--------------------------------------------------------------------------- + +# If the GENERATE_AUTOGEN_DEF tag is set to YES Doxygen will +# generate an AutoGen Definitions (see autogen.sf.net) file +# that captures the structure of the code including all +# documentation. Note that this feature is still experimental +# and incomplete at the moment. + +GENERATE_AUTOGEN_DEF = NO + +#--------------------------------------------------------------------------- +# configuration options related to the Perl module output +#--------------------------------------------------------------------------- + +# If the GENERATE_PERLMOD tag is set to YES Doxygen will +# generate a Perl module file that captures the structure of +# the code including all documentation. Note that this +# feature is still experimental and incomplete at the +# moment. + +GENERATE_PERLMOD = NO + +# If the PERLMOD_LATEX tag is set to YES Doxygen will generate +# the necessary Makefile rules, Perl scripts and LaTeX code to be able +# to generate PDF and DVI output from the Perl module output. + +PERLMOD_LATEX = NO + +# If the PERLMOD_PRETTY tag is set to YES the Perl module output will be +# nicely formatted so it can be parsed by a human reader. This is useful +# if you want to understand what is going on. On the other hand, if this +# tag is set to NO the size of the Perl module output will be much smaller +# and Perl will parse it just the same. + +PERLMOD_PRETTY = YES + +# The names of the make variables in the generated doxyrules.make file +# are prefixed with the string contained in PERLMOD_MAKEVAR_PREFIX. +# This is useful so different doxyrules.make files included by the same +# Makefile don't overwrite each other's variables. + +PERLMOD_MAKEVAR_PREFIX = + +#--------------------------------------------------------------------------- +# Configuration options related to the preprocessor +#--------------------------------------------------------------------------- + +# If the ENABLE_PREPROCESSING tag is set to YES (the default) Doxygen will +# evaluate all C-preprocessor directives found in the sources and include +# files. + +ENABLE_PREPROCESSING = NO + +# If the MACRO_EXPANSION tag is set to YES Doxygen will expand all macro +# names in the source code. If set to NO (the default) only conditional +# compilation will be performed. Macro expansion can be done in a controlled +# way by setting EXPAND_ONLY_PREDEF to YES. + +MACRO_EXPANSION = NO + +# If the EXPAND_ONLY_PREDEF and MACRO_EXPANSION tags are both set to YES +# then the macro expansion is limited to the macros specified with the +# PREDEFINED and EXPAND_AS_DEFINED tags. + +EXPAND_ONLY_PREDEF = NO + +# If the SEARCH_INCLUDES tag is set to YES (the default) the includes files +# in the INCLUDE_PATH (see below) will be search if a #include is found. + +SEARCH_INCLUDES = YES + +# The INCLUDE_PATH tag can be used to specify one or more directories that +# contain include files that are not input files but should be processed by +# the preprocessor. + +INCLUDE_PATH = + +# You can use the INCLUDE_FILE_PATTERNS tag to specify one or more wildcard +# patterns (like *.h and *.hpp) to filter out the header-files in the +# directories. If left blank, the patterns specified with FILE_PATTERNS will +# be used. + +INCLUDE_FILE_PATTERNS = + +# The PREDEFINED tag can be used to specify one or more macro names that +# are defined before the preprocessor is started (similar to the -D option of +# gcc). The argument of the tag is a list of macros of the form: name +# or name=definition (no spaces). If the definition and the = are +# omitted =1 is assumed. To prevent a macro definition from being +# undefined via #undef or recursively expanded use the := operator +# instead of the = operator. + +PREDEFINED = + +# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then +# this tag can be used to specify a list of macro names that should be expanded. +# The macro definition that is found in the sources will be used. +# Use the PREDEFINED tag if you want to use a different macro definition. + +EXPAND_AS_DEFINED = + +# If the SKIP_FUNCTION_MACROS tag is set to YES (the default) then +# doxygen's preprocessor will remove all function-like macros that are alone +# on a line, have an all uppercase name, and do not end with a semicolon. Such +# function macros are typically used for boiler-plate code, and will confuse +# the parser if not removed. + +SKIP_FUNCTION_MACROS = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to external references +#--------------------------------------------------------------------------- + +# The TAGFILES option can be used to specify one or more tagfiles. +# Optionally an initial location of the external documentation +# can be added for each tagfile. The format of a tag file without +# this location is as follows: +# TAGFILES = file1 file2 ... +# Adding location for the tag files is done as follows: +# TAGFILES = file1=loc1 "file2 = loc2" ... +# where "loc1" and "loc2" can be relative or absolute paths or +# URLs. If a location is present for each tag, the installdox tool +# does not have to be run to correct the links. +# Note that each tag file must have a unique name +# (where the name does NOT include the path) +# If a tag file is not located in the directory in which doxygen +# is run, you must also specify the path to the tagfile here. + +TAGFILES = + +# When a file name is specified after GENERATE_TAGFILE, doxygen will create +# a tag file that is based on the input files it reads. + +GENERATE_TAGFILE = + +# If the ALLEXTERNALS tag is set to YES all external classes will be listed +# in the class index. If set to NO only the inherited external classes +# will be listed. + +ALLEXTERNALS = NO + +# If the EXTERNAL_GROUPS tag is set to YES all external groups will be listed +# in the modules index. If set to NO, only the current project's groups will +# be listed. + +EXTERNAL_GROUPS = YES + +# The PERL_PATH should be the absolute path and name of the perl script +# interpreter (i.e. the result of `which perl'). + +PERL_PATH = /usr/bin/perl + +#--------------------------------------------------------------------------- +# Configuration options related to the dot tool +#--------------------------------------------------------------------------- + +# If the CLASS_DIAGRAMS tag is set to YES (the default) Doxygen will +# generate a inheritance diagram (in HTML, RTF and LaTeX) for classes with base +# or super classes. Setting the tag to NO turns the diagrams off. Note that +# this option is superseded by the HAVE_DOT option below. This is only a +# fallback. It is recommended to install and use dot, since it yields more +# powerful graphs. + +CLASS_DIAGRAMS = YES + +# If set to YES, the inheritance and collaboration graphs will hide +# inheritance and usage relations if the target is undocumented +# or is not a class. + +HIDE_UNDOC_RELATIONS = YES + +# If you set the HAVE_DOT tag to YES then doxygen will assume the dot tool is +# available from the path. This tool is part of Graphviz, a graph visualization +# toolkit from AT&T and Lucent Bell Labs. The other options in this section +# have no effect if this option is set to NO (the default) + +HAVE_DOT = NO + +# If the CLASS_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect inheritance relations. Setting this tag to YES will force the +# the CLASS_DIAGRAMS tag to NO. + +CLASS_GRAPH = YES + +# If the COLLABORATION_GRAPH and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for each documented class showing the direct and +# indirect implementation dependencies (inheritance, containment, and +# class references variables) of the class with other documented classes. + +COLLABORATION_GRAPH = YES + +# If the GROUP_GRAPHS and HAVE_DOT tags are set to YES then doxygen +# will generate a graph for groups, showing the direct groups dependencies + +GROUP_GRAPHS = YES + +# If the UML_LOOK tag is set to YES doxygen will generate inheritance and +# collaboration diagrams in a style similar to the OMG's Unified Modeling +# Language. + +UML_LOOK = NO + +# If set to YES, the inheritance and collaboration graphs will show the +# relations between templates and their instances. + +TEMPLATE_RELATIONS = NO + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDE_GRAPH, and HAVE_DOT +# tags are set to YES then doxygen will generate a graph for each documented +# file showing the direct and indirect include dependencies of the file with +# other documented files. + +INCLUDE_GRAPH = YES + +# If the ENABLE_PREPROCESSING, SEARCH_INCLUDES, INCLUDED_BY_GRAPH, and +# HAVE_DOT tags are set to YES then doxygen will generate a graph for each +# documented header file showing the documented files that directly or +# indirectly include this file. + +INCLUDED_BY_GRAPH = YES + +# If the CALL_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a call dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable call graphs for selected +# functions only using the \callgraph command. + +CALL_GRAPH = NO + +# If the CALLER_GRAPH and HAVE_DOT tags are set to YES then doxygen will +# generate a caller dependency graph for every global function or class method. +# Note that enabling this option will significantly increase the time of a run. +# So in most cases it will be better to enable caller graphs for selected +# functions only using the \callergraph command. + +CALLER_GRAPH = NO + +# If the GRAPHICAL_HIERARCHY and HAVE_DOT tags are set to YES then doxygen +# will graphical hierarchy of all classes instead of a textual one. + +GRAPHICAL_HIERARCHY = YES + +# If the DIRECTORY_GRAPH, SHOW_DIRECTORIES and HAVE_DOT tags are set to YES +# then doxygen will show the dependencies a directory has on other directories +# in a graphical way. The dependency relations are determined by the #include +# relations between the files in the directories. + +DIRECTORY_GRAPH = YES + +# The DOT_IMAGE_FORMAT tag can be used to set the image format of the images +# generated by dot. Possible values are png, jpg, or gif +# If left blank png will be used. + +DOT_IMAGE_FORMAT = png + +# The tag DOT_PATH can be used to specify the path where the dot tool can be +# found. If left blank, it is assumed the dot tool can be found in the path. + +DOT_PATH = + +# The DOTFILE_DIRS tag can be used to specify one or more directories that +# contain dot files that are included in the documentation (see the +# \dotfile command). + +DOTFILE_DIRS = + +# The MAX_DOT_GRAPH_WIDTH tag can be used to set the maximum allowed width +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_WIDTH = 1024 + +# The MAX_DOT_GRAPH_HEIGHT tag can be used to set the maximum allows height +# (in pixels) of the graphs generated by dot. If a graph becomes larger than +# this value, doxygen will try to truncate the graph, so that it fits within +# the specified constraint. Beware that most browsers cannot cope with very +# large images. + +MAX_DOT_GRAPH_HEIGHT = 1024 + +# The MAX_DOT_GRAPH_DEPTH tag can be used to set the maximum depth of the +# graphs generated by dot. A depth value of 3 means that only nodes reachable +# from the root by following a path via at most 3 edges will be shown. Nodes +# that lay further from the root node will be omitted. Note that setting this +# option to 1 or 2 may greatly reduce the computation time needed for large +# code bases. Also note that a graph may be further truncated if the graph's +# image dimensions are not sufficient to fit the graph (see MAX_DOT_GRAPH_WIDTH +# and MAX_DOT_GRAPH_HEIGHT). If 0 is used for the depth value (the default), +# the graph is not depth-constrained. + +MAX_DOT_GRAPH_DEPTH = 0 + +# Set the DOT_TRANSPARENT tag to YES to generate images with a transparent +# background. This is disabled by default, which results in a white background. +# Warning: Depending on the platform used, enabling this option may lead to +# badly anti-aliased labels on the edges of a graph (i.e. they become hard to +# read). + +DOT_TRANSPARENT = NO + +# Set the DOT_MULTI_TARGETS tag to YES allow dot to generate multiple output +# files in one run (i.e. multiple -o and -T options on the command line). This +# makes dot run faster, but since only newer versions of dot (>1.8.10) +# support this, this feature is disabled by default. + +DOT_MULTI_TARGETS = NO + +# If the GENERATE_LEGEND tag is set to YES (the default) Doxygen will +# generate a legend page explaining the meaning of the various boxes and +# arrows in the dot generated graphs. + +GENERATE_LEGEND = YES + +# If the DOT_CLEANUP tag is set to YES (the default) Doxygen will +# remove the intermediate dot files that are used to generate +# the various graphs. + +DOT_CLEANUP = YES + +#--------------------------------------------------------------------------- +# Configuration::additions related to the search engine +#--------------------------------------------------------------------------- + +# The SEARCHENGINE tag specifies whether or not a search engine should be +# used. If set to NO the values of all tags below this one will be ignored. + +SEARCHENGINE = NO diff --git a/sites/all/modules/views/views_export/views_export.css b/sites/all/modules/views/views_export/views_export.css new file mode 100644 index 0000000..4887ad3 --- /dev/null +++ b/sites/all/modules/views/views_export/views_export.css @@ -0,0 +1,12 @@ + +div.export-container table input, +div.export-container table th, +div.export-container table td { + padding: 0 0 0 .5em; + margin: 0; + vertical-align: top; +} + +div.export-container table td input { + margin-top: .25em; +} diff --git a/sites/all/modules/views/views_export/views_export.info b/sites/all/modules/views/views_export/views_export.info new file mode 100644 index 0000000..01f9cb8 --- /dev/null +++ b/sites/all/modules/views/views_export/views_export.info @@ -0,0 +1,13 @@ + +name = Views exporter +description = Allows exporting multiple views at once. +package = "Views" +dependencies[] = views +core = 6.x + +; Information added by Drupal.org packaging script on 2015-02-11 +version = "6.x-2.18" +core = "6.x" +project = "views" +datestamp = "1423647793" + diff --git a/sites/all/modules/views/views_export/views_export.module b/sites/all/modules/views/views_export/views_export.module new file mode 100644 index 0000000..28efc42 --- /dev/null +++ b/sites/all/modules/views/views_export/views_export.module @@ -0,0 +1,256 @@ + 'Bulk export', + 'access arguments' => array('use views exporter'), + 'page callback' => 'views_export_export', + 'type' => MENU_LOCAL_TASK, + ); + + $items['admin/build/views/tools/export/results'] = array( + 'title' => 'Bulk export results', + 'access arguments' => array('use views exporter'), + 'page callback' => 'views_export_export', + 'type' => MENU_LOCAL_TASK, + ); + + return $items; +} + +function views_export_theme() { + return array( + 'views_export_export_form' => array( + 'args' => array('form' => NULL), + ), + ); +} + +/** + * Implementation of hook_perm(). + */ +function views_export_perm() { + return array('use views exporter'); +} + +/** + * Page callback to export views in bulk. + */ +function views_export_export() { + $tags = array(); + if (!empty($_GET['tags'])) { + $tags = explode(',', $_GET['tags']); + } + + $exportables = array(); + foreach (module_implements('views_exportables') as $module) { + $function = $module . '_views_exportables'; + $exportables[$module] = $function('list', $tags); + asort($exportables[$module]); + } + + if ($exportables) { + $form_state = array( + 'no_redirect' => TRUE, + 'exportables' => $exportables, + 'tags' => $tags, + ); + + $output = drupal_build_form('views_export_export_form', $form_state); + if (!$output) { + $output = $form_state['output']; + } + return $output; + } + else { + return t('There are no views to be exported at this time.'); + } +} + +/** + * Form to choose a group of views to export. + */ +function views_export_export_form(&$form_state) { + foreach ($form_state['exportables'] as $module => $views) { + foreach ($views as $name => $data) { + $options[$name] = $data['name']; + } + + $form['modules']['#tree'] = TRUE; + $form['modules'][$module] = array( + '#type' => 'checkboxes', + '#options' => $options, + '#default_value' => array(), + ); + } + + $tags = array(); + foreach (views_get_all_views() as $name => $view) { + if (!empty($view->tag)) { + $tags[$view->tag] = $view->tag; + } + } + + asort($tags); + + $form['tags'] = array( + '#type' => 'select', + '#title' => t('Show only these tags'), + '#options' => $tags, + '#default_value' => $form_state['tags'], + '#multiple' => TRUE, + ); + + $form['apply'] = array( + '#type' => 'submit', + '#value' => t('Apply'), + '#submit' => array('views_export_export_form_apply'), + ); + + $form['name'] = array( + '#type' => 'textfield', + '#title' => t('Module name'), + '#description' => t('Enter the module name to export code to.'), + ); + + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Export'), + ); + + $form['#action'] = url('admin/build/views/tools/export/results'); + $form['#redirect'] = FALSE; + $form['#exportables'] = $form_state['exportables']; + return $form; +} + +function theme_views_export_export_form($form) { + $output = ''; + $files = module_rebuild_cache(); + $exportables = $form['#exportables']; + $output .= drupal_render($form['tags']); + $output .= drupal_render($form['apply']); + $output .= '
    '; + + foreach ($exportables as $module => $views) { + $header = array(theme('table_select_header_cell'), $files[$module]->info['name'], t('Tag'), t('Description')); + $rows = array(); + foreach ($views as $name => $view) { + $title = $form['modules'][$module][$name]['#title']; + unset($form['modules'][$module][$name]['#title']); + $rows[] = array(drupal_render($form['modules'][$module][$name]), $title, $view['tag'], '
    ' . $view['desc'] . '
    '); + } + $output .= '
    '; + $output .= theme('table', $header, $rows); + $output .= "
    \n"; + } + $output .= '
    '; + drupal_add_css(drupal_get_path('module', 'views_export') . '/views_export.css'); + $output .= drupal_render($form); + return $output; +} + +function views_export_export_form_apply(&$form, &$form_state) { + $tags = $form_state['values']['tags']; + if ($tags) { + drupal_goto('admin/build/views/tools/export', array('tags' => implode(',', $tags))); + } + else { + drupal_goto('admin/build/views/tools/export'); + } +} + +function views_export_export_form_submit(&$form, &$form_state) { + $code = ''; + if (empty($form_state['values']['name'])) { + $form_state['values']['name'] = 'foo'; + } + + foreach ($form_state['values']['modules'] as $module => $views) { + $views = array_filter($views); + asort($views); + if ($views) { + $code .= module_invoke($module, 'views_exportables', 'export', $views, $form_state['values']['name']) . "\n\n"; + } + } + + $lines = substr_count($code, "\n"); + + $types = system_elements(); + + $info = "; \$Id" . ": $\n"; // The break in the string prevents CVS. + $info .= "\n"; + $info .= strtr("name = @module Export Module\n", array('@module' => $form_state['values']['name'])); + $info .= strtr("description = Exports some views of @module\n", array('@module' => $form_state['values']['name'])); + $info .= "dependencies[] = views\n"; + $info .= "core = 6.x\n"; + + + $element_info = array( + '#title' => t('Put this in @module.info in your modules/@module directory', array('@module' => $form_state['values']['name'])), + '#type' => 'textarea', + '#id' => 'export-info-textarea', + '#name' => 'export-info-textarea', + '#attributes' => array(), + '#rows' => 9, + '#cols' => 60, + '#value' => $info, + '#parents' => array('dummy'), + '#required' => FALSE, + ) + $types['textarea']; + + $api = "/**\n"; + $api .= " * Implementation of hook_views_api().\n"; + $api .= " */\n"; + $api .= "function @module_views_api() {\n"; + $api .= " return array(\n"; + $api .= " 'api' => '" . views_api_version() . "',\n"; + $api .= " 'path' => drupal_get_path('module', '@module'),\n"; + $api .= " //'path' => drupal_get_path('module', '@module') . '/includes',\n"; + $api .= " );\n"; + $api .= "}"; + + $api = strtr($api, array('@module' => check_plain($form_state['values']['name']))); + + $element_api = array( + '#title' => t('Put this in @module.module in your modules/@module directory (place a <?php at the top of the file so the webserver knows that it is PHP code)', array('@module' => $form_state['values']['name'])), + '#type' => 'textarea', + '#id' => 'export-api-textarea', + '#name' => 'export-api-textarea', + '#attributes' => array( 'dir' => 'ltr' ), + '#rows' => 9, + '#cols' => 60, + '#value' => $api, + '#parents' => array('dummy'), + '#required' => FALSE, + ) + $types['textarea']; + + $element_hook = array( + '#title' => t('Put this in @module.views_default.inc in your modules/@module directory or modules/@module/includes directory (place a <?php at the top of the file so the webserver knows that it is PHP code)', array('@module' => $form_state['values']['name'])), + '#type' => 'textarea', + '#id' => 'export-textarea', + '#name' => 'export-textarea', + '#attributes' => array( 'dir' => 'ltr' ), + '#rows' => min($lines, 150), + '#value' => $code, + '#parents' => array('dummy'), + '#required' => FALSE, + ) + $types['textarea']; + + + $form_state['output'] = theme('textarea', $element_info); + $form_state['output'] .= theme('textarea', $element_api); + $form_state['output'] .= theme('textarea', $element_hook); +} + diff --git a/sites/all/modules/views/views_revert.drush.inc b/sites/all/modules/views/views_revert.drush.inc new file mode 100644 index 0000000..b72fcc0 --- /dev/null +++ b/sites/all/modules/views/views_revert.drush.inc @@ -0,0 +1,154 @@ + 'views_revert_views', + 'drupal dependencies' => array('views'), + 'description' => dt('Revert overridden views to their default state. Make sure to backup first.'), + 'bootstrap' => DRUSH_BOOTSTRAP_DRUPAL_FULL, + 'aliases' => array('vr'), + ); + + return $items; +} + +/** + * Callback function for views-revert command. + */ +function views_revert_views() { + $views = views_get_all_views(); + $i = 0; + // The provided view names specified in the command. + $viewnames = _convert_csv_to_array(func_get_args()); + + // Find all overridden views. + foreach ($views as $view) { + if ($view->disabled) { + continue; + } + if ($view->type == dt('Overridden')) { + $overridden[$view->name] = $view->name; + } + } + + // Return early if there are no views overridden in the system. + if (empty($overridden)) { + return drush_set_error(dt('There are no overridden views in the system.')); + } + + // If the user specified in the command the views to be overridden. + if (!empty($viewnames)) { + foreach ($viewnames as $key => $viewname) { + $is_overridden = key_exists($viewname, $overridden); + // Check if the provided view name is in the system + if ($viewname && !key_exists($viewname, $views)) { + drush_set_error(dt("'@viewname' view is not present in the system.", array('@viewname' => $viewname))); + } + // Check if the provided view is overridden. + elseif (!$is_overridden) { + drush_set_error(dt("The view specified '@viewname' is not overridden.", array('@viewname' => $viewname))); + } + // If the view is overriden, revert it. + elseif ($is_overridden){ + views_revert_view($views[$viewname]); + $i++; + } + // We should never get here but well... + else { + drush_set_error(dt("The view specified '@viewname' is not provided in code, and thus cannot be reverted.", array('@viewname' => $viewname))); + } + } + } + + // The user did not specify any views in the command, prompt the user + else { + // list of choices for the user + $overridden['all'] = dt('Revert all overridden views'); // add a choice at the end + $choice = drush_choice($overridden, 'Enter a number to choose which view to revert.', '!key'); // prompt the user + + if ($choice !== FALSE) { + // revert all views option + if ($choice == 'all') { + $i = views_revert_allviews($views); + } + // else the user specified a single view + else { + views_revert_view($views[$choice]); + $i++; + } + } + + } + + // final results output + if ($i == 0) { + drush_log(dt('No views were reverted.'), 'ok'); + } + else { + drush_log(dt('Reverted a total of @count views.', array('@count' => $i)), 'ok'); + } +} + +/** + * Reverts all views + * @param $views + * All views in the system as provided by views_get_all_views(). + */ +function views_revert_allviews($views) { + $i = 0; + foreach ($views as $view) { + if ($view->disabled) { + continue; + } + + if ($view->type == t('Overridden')) { + views_revert_view($view); + $i++; + } + } + return $i; +} + +/** + * Revert a specified view + * @param $view + * The view object to be reverted + * + * Checks on wether or not the view is overridden is handled in views_revert_views_revert() + * We perform a check here anyway in case someone somehow calls this function on their own... + */ +function views_revert_view($view) { + // check anyway just in case + if ($view->type == t('Overridden')) { + // Revert the view. + $view->delete(); + // Clear its cache. + views_object_cache_clear('view', $view->name); + // Give feedback. + $message = dt("Reverted the view '@viewname'", array('@viewname' => $view->name)); + drush_log($message, 'success'); + // Reverted one more view. + } + else { + drush_set_error(dt("The view '@viewname' is not overridden.", array('@viewname' => $view->name))); + } +} diff --git a/sites/all/modules/views/views_ui.info b/sites/all/modules/views/views_ui.info new file mode 100644 index 0000000..b58fdbe --- /dev/null +++ b/sites/all/modules/views/views_ui.info @@ -0,0 +1,12 @@ +name = Views UI +description = Administrative interface to views. Without this module, you cannot create or edit your views. +package = Views +core = 6.x +dependencies[] = views + +; Information added by Drupal.org packaging script on 2015-02-11 +version = "6.x-2.18" +core = "6.x" +project = "views" +datestamp = "1423647793" + diff --git a/sites/all/modules/views/views_ui.module b/sites/all/modules/views/views_ui.module new file mode 100644 index 0000000..a8b719e --- /dev/null +++ b/sites/all/modules/views/views_ui.module @@ -0,0 +1,301 @@ + 'user_access', + 'access arguments' => array('administer views'), + 'file' => 'includes/admin.inc', + ); + + $callback = $base + array('type' => MENU_CALLBACK); + + $convert = array('file' => 'includes/convert.inc') + $base; + + $items['admin/build/views'] = $base + array( + 'title' => 'Views', + 'page callback' => 'views_ui_list_views', + 'description' => 'Views are customized lists of content on your system; they are highly configurable and give you control over how lists of content are presented.', + 'type' => MENU_NORMAL_ITEM + ); + $items['admin/build/views/list'] = $base + array( + 'title' => 'List', + 'page callback' => 'views_ui_list_views', + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => '-1' + ); + $items['admin/build/views/add'] = $base + array( + 'title' => 'Add', + 'page callback' => 'views_ui_add_page', + 'type' => MENU_LOCAL_TASK + ); + $items['admin/build/views/import'] = array( + 'title' => 'Import', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('views_ui_import_page'), + 'access callback' => 'views_import_access', + 'type' => MENU_LOCAL_TASK + ) + $base; + $items['admin/build/views/tools'] = $base + array( + 'title' => 'Tools', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('views_ui_admin_tools'), + 'type' => MENU_LOCAL_TASK + ); + $items['admin/build/views/tools/basic'] = $base + array( + 'title' => 'Basic', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('views_ui_admin_tools'), + 'type' => MENU_DEFAULT_LOCAL_TASK, + 'weight' => -10, + ); + + $items['admin/build/views/tools/convert'] = $convert + array( + 'title' => 'Convert', + 'description' => 'Convert stored Views 1 views.', + 'page callback' => 'views_ui_admin_convert', + 'type' => MENU_LOCAL_TASK, + 'weight' => 1, + ); + $items['admin/build/views1/delete'] = $convert + array( + 'title' => 'Delete view', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('views_ui_delete1_confirm', 4), + 'type' => MENU_CALLBACK, + ); + $items['admin/build/views1/convert'] = $convert + array( + 'title' => 'Convert view', + 'page callback' => 'views_ui_convert1', + 'page arguments' => array(4), + 'type' => MENU_CALLBACK, + ); + + $items['admin/build/views/delete/%views_ui_cache'] = $callback + array( + 'title' => 'Delete view', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('views_ui_delete_confirm', 4), + ); + $items['admin/build/views/break-lock/%views_ui_cache'] = $callback + array( + 'title' => 'Delete view', + 'page callback' => 'drupal_get_form', + 'page arguments' => array('views_ui_break_lock_confirm', 4), + ); + $items['admin/build/views/export/%views_ui_cache'] = $callback + array( + 'page callback' => 'drupal_get_form', + 'page arguments' => array('views_ui_export_page', 4), + 'type' => MENU_LOCAL_TASK + ); + $items['admin/build/views/clone/%views_ui_cache'] = $callback + array( + 'page callback' => 'views_ui_clone_page', + 'page arguments' => array(4), + 'type' => MENU_LOCAL_TASK + ); + $items['admin/build/views/enable/%views_ui_default'] = $callback + array( + 'page callback' => 'views_ui_enable_page', + 'page arguments' => array(4), + ); + $items['admin/build/views/disable/%views_ui_default'] = $callback + array( + 'page callback' => 'views_ui_disable_page', + 'page arguments' => array(4), + ); + + // Many line items for editing a view. + $items['admin/build/views/edit/%views_ui_cache'] = $base + array( + 'title' => 'Edit', + 'page callback' => 'views_ui_edit_page', + 'page arguments' => array(4), + 'type' => MENU_LOCAL_TASK + ); + // lots of little edit form pieces. + $items['admin/build/views/%views_ui_js/analyze/%views_ui_cache'] = $callback + array( + 'page callback' => 'views_ui_analyze_view', + 'page arguments' => array(3, 5), + ); + $items['admin/build/views/%views_ui_js/details/%views_ui_cache'] = $callback + array( + 'page callback' => 'views_ui_edit_details', + 'page arguments' => array(3, 5), + ); + $items['admin/build/views/%views_ui_js/add-display/%views_ui_cache'] = $callback + array( + 'page callback' => 'views_ui_add_display', + 'page arguments' => array(3, 5), + ); + $items['admin/build/views/%views_ui_js/clone-display/%views_ui_cache'] = $callback + array( + 'page callback' => 'views_ui_clone_display', + 'page arguments' => array(3, 5, 6), + ); + // Live preview + $items['admin/build/views/%views_ui_js/preview/%views_ui_cache'] = $callback + array( + 'page callback' => 'views_ui_preview', + 'page arguments' => array(3, 5), + ); + + // autocompletes for handlers and such + $items['admin/views/ajax/autocomplete/tag'] = $callback + array( + 'page callback' => 'views_ui_autocomplete_tag', + ); + + + // Generic ajax callback + // display specific parameters + $items['admin/build/views/%views_ui_js/%/%views_ui_cache'] = $callback + array( + 'page callback' => 'views_ui_ajax_form', + 'page arguments' => array(3, 4, 5), + ); + + return $items; +} + +/* + * Implementation of hook_help() + */ +function views_ui_help($path, $arg = '') { + switch ($path) { + case 'admin/build/views/tools/convert': + return '

    ' . t('The converter will make a best-effort attempt to convert a Views 1 view to Views 2. This conversion is not reliable; you will very likely have to make adjustments to your view to get it to match. You can import Views 1 views through the normal Import tab.') . '

    '; + } +} + +/* + * Implementation of hook_theme() + */ +function views_ui_theme() { + $path = drupal_get_path('module', 'views'); + require_once "./$path/includes/admin.inc"; + + return array( + // edit a view + 'views_ui_edit_view' => array( + 'arguments' => array('view' => NULL), + 'template' => 'views-ui-edit-view', + 'path' => "$path/theme", + ), + 'views_ui_edit_tab' => array( + 'arguments' => array('view' => NULL, 'display' => NULL), + 'template' => 'views-ui-edit-tab', + 'path' => "$path/theme", + ), + 'views_ui_edit_item' => array( + 'arguments' => array('type' => NULL, 'view' => NULL, 'display' => NULL, 'no_fields' => FALSE), + 'template' => 'views-ui-edit-item', + 'path' => "$path/theme", + ), + 'views_ui_rearrange_form' => array( + 'arguments' => array('form' => NULL), + 'file' => 'includes/admin.inc', + ), + + // list views + 'views_ui_list_views' => array( + 'template' => 'views-ui-list-views', + 'path' => "$path/theme", + ), + 'views_ui_list_views_form' => array( + 'file' => 'includes/admin.inc', + 'arguments' => array('form' => NULL), + ), + + // tab themes + 'views_tabset' => array( + 'arguments' => array('tabs' => NULL), + 'file' => 'includes/tabs.inc', + ), + 'views_tab' => array( + 'arguments' => array('body' => NULL), + 'file' => 'includes/tabs.inc', + ), + + // On behalf of a plugin + 'views_ui_style_plugin_table' => array( + 'arguments' => array('form' => NULL), + 'file' => 'includes/admin.inc', + ), + ); +} + +/** + * Specialized menu callback to load a view either out of the cache or just + * load it. + */ +function views_ui_cache_load($name) { + views_include('cache'); + views_include('view'); + $view = views_object_cache_get('view', $name); + + if (empty($view)) { + $view = views_get_view($name); + + if (!empty($view)) { + // Check to see if someone else is already editing this view. + global $user; + $view->locked = db_fetch_object(db_query("SELECT s.uid, v.updated FROM {views_object_cache} v INNER JOIN {sessions} s ON v.sid = s.sid WHERE s.sid != '%s' and v.name = '%s' and v.obj = 'view' ORDER BY v.updated ASC", session_id(), $view->name)); + } + } + + if (empty($view)) { + return FALSE; + } + + else { + return $view; + } +} + +function views_ui_check_lock($view) { + +} + +/** + * Specialized cache function to add a flag to our view, include an appropriate + * include, and cache more easily. + */ +function views_ui_cache_set(&$view) { + if (!empty($view->locked)) { + drupal_set_message(t('Changes cannot be made to a locked view.'), 'error'); + return; + } + views_include('cache'); + $view->changed = TRUE; // let any future object know that this view has changed. + + // Unset handlers; we don't want to write these into the cache + unset($view->display_handler); + unset($view->current_display); + unset($view->default_display); + foreach (array_keys($view->display) as $id) { + unset($view->display[$id]->handler); + unset($view->display[$id]->default_display); + } + views_object_cache_set('view', $view->name, $view); +} + + +/** + * Specialized menu callback to load a view that is only a default + * view. + */ +function views_ui_default_load($name) { + $view = views_get_view($name); + if ($view->type == t('Default')) { + return $view; + } + + return FALSE; +} + +/** + * Check to see if the incoming menu item is js capable or not. + */ +function views_ui_js_load($js) { + if ($js == 'ajax') { + return TRUE; + } + return 0; +}